fix(linkedin-studio): N1 — prune-regex no-op + dato-uavhengige kalender-fixtures (TDD) [skip-docs]

B-F1 (prod-bug, prune de facto no-op): fjernet `m`-flagget fra Recent Posts-
regexen i `state-updater.mjs`. Med `/m` matchet `$`-alternativet i lookahead
slutten av hver linje, så den late capturen stoppet etter FØRSTE entry-linje;
gamle entries under en fersk (nye prepender øverst) ble aldri skannet/prunet.
Ny regresjonstest (old-under-fresh) rød->grønn beviser mekanismen.

B-F2 (kalender-flake): `pruneContentHistory` fikk valgfri `today = new Date()`-
param (deterministisk rotårsak-fix; CLI/hook-kall uendret via default). Prune-
testene injiserer fast syntetisk today og asserter kun på Recent Posts-seksjonen
(ikke helinnhold/frontmatter), så today-100d aldri kolliderer med SAMPLE_STATE-
datoer. Samme grep i `scripts/check-replace-safety.mjs`.

Suiter (alle grønne): test-runner 138/0 · hooks 140/0 (+1 regresjonstest) ·
trends 245/0 · brain 134/0 · tests 35/0 · render 20/0.

Utført av Fable 5 (high) subagent, orkestrert + verifisert av Opus-hovedkontekst.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: a814039f-da8b-41b1-8d7c-60abe1e03c5a
This commit is contained in:
Kjell Tore Guttormsen 2026-07-16 20:03:05 +02:00
commit 776d728d7d
3 changed files with 91 additions and 51 deletions

View file

@ -118,25 +118,34 @@ const BATTERY = [
{
path: "section rewrite of KEPT entries (:171)",
run: () => {
const today = new Date();
const old = new Date(today); old.setDate(old.getDate() - 100);
const recent = new Date(today); recent.setDate(recent.getDate() - 10);
// Fixed injectable "today" (third param): with the real clock, on some
// calendar days today-100d collides with a hardcoded SAMPLE date (e.g.
// 2026-04-05), making the whole-content assertion flake. A fixed date far
// from every SAMPLE date removes the collision class.
const fixedToday = new Date("2027-01-01T00:00:00Z");
const old = new Date(fixedToday); old.setDate(old.getDate() - 100);
const recent = new Date(fixedToday); recent.setDate(recent.getDate() - 10);
const oldDate = old.toISOString().slice(0, 10);
const recentDate = recent.toISOString().slice(0, 10);
// Plant the payload via a FUNCTION replace so the fixture itself is not
// pre-corrupted by the very expansion under test.
// Replace the WHOLE section (heading + hardcoded entry) so no SAMPLE entry
// falls under the cutoff, via a FUNCTION replace so the fixture itself is
// not pre-corrupted by the very expansion under test.
const state = SAMPLE.replace(
"## Recent Posts\n\n",
() => `## Recent Posts\n\n- [${oldDate}] "drop" (1000) - drop me\n- [${recentDate}] "${PAYLOAD}" (1200) - ${PAYLOAD}\n`
/## Recent Posts\n\n[\s\S]*?(?=## Milestone Log)/,
() => `## Recent Posts\n\n- [${oldDate}] "drop" (1000) - drop me\n- [${recentDate}] "${PAYLOAD}" (1200) - ${PAYLOAD}\n\n`
);
const r = mod.pruneContentHistory(state, 90);
const r = mod.pruneContentHistory(state, 90, fixedToday);
return { ...r, _recentDate: recentDate, _oldDate: oldDate };
},
assert: (r) => {
assert.notEqual(r, null, "prune returned null");
assert.equal(r.pruned, 1, "exactly the old entry pruned");
assert.ok(!r.content.includes(r._oldDate), "old entry pruned");
assert.ok(r.content.includes(`- [${r._recentDate}] "${PAYLOAD}" (1200) - ${PAYLOAD}`), "kept $-entry survives verbatim");
// Assert on the Recent Posts section only, not the whole content, so
// frontmatter/other-section dates can never satisfy or break the check.
const section = (r.content.match(/## Recent Posts\n([\s\S]*?)\n## Milestone Log/) || [])[1];
assert.ok(section, "Recent Posts section present");
assert.ok(!section.includes(r._oldDate), "old entry pruned");
assert.ok(section.includes(`- [${r._recentDate}] "${PAYLOAD}" (1200) - ${PAYLOAD}`), "kept $-entry survives verbatim");
},
once: [/^## Recent Posts$/gm],
},