feat(linkedin-studio): N12 — editions-register CLI + phaseLog-telemetri (TDD) [skip-docs]
Two things were structurally invisible: WHICH editions are in flight (readable
only by opening every series folder's edition-state.json by hand) and HOW LONG an
edition takes (not recorded anywhere). At two editions a week both are
load-bearing — a production line cannot be dimensioned on numbers never collected.
Register (scripts/editions, new module beside distillate.ts): one row per edition
in ${LINKEDIN_STUDIO_DATA}/editions/register.json — series, edition, title, series
path, current phase, next action, slot, startedAt/completedAt. Data-dir placement
(M0) because the register spans ALL series; the distillate is per-series and stays
in the series root. Verbs: register-upsert / register-list / register-complete.
phaseLog: articles.NN.phaseLog[{phase, completedAt}] in edition-state, additive so
schemaVersion stays 1 — pre-N12 editions load unchanged and their absence reads as
"not measured", never as zero. Per-article, mirroring articles.NN.phase: lead time
is a property of an edition.
One call per transition, both writes: newsletter.md gains a phase-transition
protocol defined once beside the resumption table, and all 16 canonical phases
invoke it. register-upsert appends the phase-log entry AND mirrors the register
row. Deliberately one command, not two — telemetry the command layer must remember
to write separately is incomplete inside a week, and an incomplete log measures
nothing. Step 10 closes the row and prints the measured lead time.
Mirror discipline: resumption still reads edition-state.json and only that. Delete
the register and the next transition rebuilds it; a failed upsert is reported, never
a reason to stop the pipeline. startedAt is the one unrecoverable value, so it never
moves — re-upserting a completed edition reactivates the same row (what
/linkedin:pivot does), keeping the clock on real elapsed production time.
Deterministic: no clock in the core (now passed in, --at/--now at the edge, as the
distillate takes lockedAt). Idempotent where a re-run is legitimate (repeated
transition logs once; completing twice keeps the first completedAt), not where it is
real work (a phase recurring after another one is logged again — a pivot back through
cleared gates is production time that happened). Missing facts are refused at the
edge, not defaulted: a row naming the wrong phase is worse than no row.
TDD (Iron Law): all three test files written first and verified red before any
implementation existed (register.test.ts + editionState.test.ts failed on missing
modules, cli-register.test.ts on "unknown command: register-upsert").
Suites: editions 27 -> 72 (floor raised) · test-runner 173 -> 184 (Section 16s: 11
unconditional greps incl. a 16-phase coverage sweep + non-vacuity self-test;
anti-erosion floor 155 -> 166) · trends 300/0 · brain 134/0 · specifics-bank 45/0 ·
hooks 140/0 · tests 35/0 · render 60/0. tsc --noEmit clean.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QxvWAjte7vPcF79QeSRvRJ
This commit is contained in:
parent
b54e450c3e
commit
657539ef09
13 changed files with 1454 additions and 20 deletions
194
scripts/editions/tests/cli-register.test.ts
Normal file
194
scripts/editions/tests/cli-register.test.ts
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
import { describe, test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync, readFileSync, existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
|
||||
// Resolve the package root (scripts/editions) so the subprocess `src/cli.ts` path +
|
||||
// the `tsx` loader resolve regardless of the runner's cwd.
|
||||
const editionsDir = fileURLToPath(new URL("..", import.meta.url));
|
||||
|
||||
function run(args: string[], dataRoot?: string): { status: number | null; stdout: string; stderr: string } {
|
||||
const res = spawnSync("node", ["--import", "tsx", "src/cli.ts", ...args], {
|
||||
encoding: "utf8",
|
||||
cwd: editionsDir,
|
||||
env: dataRoot ? { ...process.env, LINKEDIN_STUDIO_DATA: dataRoot } : process.env,
|
||||
});
|
||||
return { status: res.status, stdout: res.stdout, stderr: res.stderr };
|
||||
}
|
||||
|
||||
const T1 = "2026-07-21T09:30:00.000Z";
|
||||
const T2 = "2026-07-24T09:30:00.000Z";
|
||||
|
||||
/** A scratch series root with a realistic edition-state.json, plus a scratch data dir. */
|
||||
function fixture(): { dir: string; statePath: string; dataRoot: string; seriesRoot: string } {
|
||||
const dir = mkdtempSync(join(tmpdir(), "editions-cli-register-"));
|
||||
const seriesRoot = join(dir, "series", "seres");
|
||||
const statePath = join(seriesRoot, "linkedin", "edition-state.json");
|
||||
mkdirSync(join(seriesRoot, "linkedin"), { recursive: true });
|
||||
writeFileSync(
|
||||
statePath,
|
||||
JSON.stringify(
|
||||
{
|
||||
schemaVersion: 1,
|
||||
series: { slug: "seres", title: "Seres" },
|
||||
currentArticle: "05",
|
||||
currentPhase: "skeleton-pitch",
|
||||
articles: { "05": { title: "Da pipelinen brøt sammen", phase: "skeleton-pitch", phaseLog: [] } },
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
"utf8",
|
||||
);
|
||||
return { dir, statePath, dataRoot: join(dir, "data"), seriesRoot };
|
||||
}
|
||||
|
||||
describe("editions CLI — register upsert/list/complete round-trip (N12 AC)", () => {
|
||||
test("upsert -> list -> complete round-trips through a real register in a scratch data dir", () => {
|
||||
const { dir, statePath, dataRoot, seriesRoot } = fixture();
|
||||
try {
|
||||
// 1. a phase transition mirrors the edition into the register
|
||||
const up = run(
|
||||
["register-upsert", "--edition-state", statePath, "--next", "Step 3a — spine prose", "--at", T1],
|
||||
dataRoot,
|
||||
);
|
||||
assert.equal(up.status, 0, up.stderr);
|
||||
|
||||
const registerPath = join(dataRoot, "editions", "register.json");
|
||||
assert.ok(existsSync(registerPath), "register-upsert must create the register under ${DATA}/editions/");
|
||||
|
||||
// 2. list surfaces it without opening a single edition-state.json
|
||||
const listed = run(["register-list", "--json"], dataRoot);
|
||||
assert.equal(listed.status, 0, listed.stderr);
|
||||
const rows = JSON.parse(listed.stdout);
|
||||
assert.equal(rows.length, 1);
|
||||
assert.equal(rows[0].series, "seres");
|
||||
assert.equal(rows[0].editionId, "05");
|
||||
assert.equal(rows[0].title, "Da pipelinen brøt sammen");
|
||||
assert.equal(rows[0].currentPhase, "skeleton-pitch");
|
||||
assert.equal(rows[0].nextAction, "Step 3a — spine prose");
|
||||
assert.equal(rows[0].path, seriesRoot, "the series root is derived from the state-file path");
|
||||
assert.equal(rows[0].startedAt, T1);
|
||||
assert.equal(rows[0].status, "active");
|
||||
|
||||
// 3. complete closes the row and takes it out of the in-flight view
|
||||
const done = run(["register-complete", "--series", "seres", "--edition", "05", "--at", T2], dataRoot);
|
||||
assert.equal(done.status, 0, done.stderr);
|
||||
assert.equal(JSON.parse(run(["register-list", "--json"], dataRoot).stdout).length, 0);
|
||||
|
||||
const all = JSON.parse(run(["register-list", "--json", "--all"], dataRoot).stdout);
|
||||
assert.equal(all.length, 1);
|
||||
assert.equal(all[0].status, "complete");
|
||||
assert.equal(all[0].completedAt, T2);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("the same upsert also appends the phaseLog entry — telemetry is not a separate step", () => {
|
||||
const { dir, statePath, dataRoot } = fixture();
|
||||
try {
|
||||
assert.equal(run(["register-upsert", "--edition-state", statePath, "--at", T1], dataRoot).status, 0);
|
||||
const state = JSON.parse(readFileSync(statePath, "utf8"));
|
||||
assert.deepEqual(state.articles["05"].phaseLog, [{ phase: "skeleton-pitch", completedAt: T1 }]);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("a repeated transition is idempotent in both the log and the register", () => {
|
||||
const { dir, statePath, dataRoot } = fixture();
|
||||
try {
|
||||
run(["register-upsert", "--edition-state", statePath, "--at", T1], dataRoot);
|
||||
run(["register-upsert", "--edition-state", statePath, "--at", T2], dataRoot);
|
||||
const state = JSON.parse(readFileSync(statePath, "utf8"));
|
||||
assert.equal(state.articles["05"].phaseLog.length, 1);
|
||||
const rows = JSON.parse(run(["register-list", "--json"], dataRoot).stdout);
|
||||
assert.equal(rows.length, 1);
|
||||
assert.equal(rows[0].startedAt, T1, "lead time is anchored at the first transition");
|
||||
assert.equal(rows[0].updatedAt, T2);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("the human view shows phase, next action and days in flight — the WIP answer without opening files", () => {
|
||||
const { dir, statePath, dataRoot } = fixture();
|
||||
try {
|
||||
run(["register-upsert", "--edition-state", statePath, "--next", "Step 3a — spine prose", "--at", T1], dataRoot);
|
||||
const out = run(["register-list", "--now", T2], dataRoot);
|
||||
assert.equal(out.status, 0, out.stderr);
|
||||
assert.match(out.stdout, /seres/);
|
||||
assert.match(out.stdout, /05/);
|
||||
assert.match(out.stdout, /skeleton-pitch/);
|
||||
assert.match(out.stdout, /Step 3a — spine prose/);
|
||||
assert.match(out.stdout, /3(\.0)? day/, "days in flight is the lead-time signal (T1 -> T2 = 3 days)");
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("an empty register says so plainly instead of printing nothing", () => {
|
||||
const { dir, dataRoot } = fixture();
|
||||
try {
|
||||
const out = run(["register-list"], dataRoot);
|
||||
assert.equal(out.status, 0, out.stderr);
|
||||
assert.match(out.stdout, /no editions in flight/i);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("--register overrides the data-dir default", () => {
|
||||
const { dir, statePath, dataRoot } = fixture();
|
||||
try {
|
||||
const elsewhere = join(dir, "elsewhere", "register.json");
|
||||
assert.equal(
|
||||
run(["register-upsert", "--edition-state", statePath, "--register", elsewhere, "--at", T1], dataRoot).status,
|
||||
0,
|
||||
);
|
||||
assert.ok(existsSync(elsewhere));
|
||||
assert.ok(!existsSync(join(dataRoot, "editions", "register.json")));
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("register-upsert without --edition-state is a usage error (exit 2)", () => {
|
||||
const { dir, dataRoot } = fixture();
|
||||
try {
|
||||
const out = run(["register-upsert", "--next", "Step 3a"], dataRoot);
|
||||
assert.equal(out.status, 2);
|
||||
assert.match(out.stderr, /--edition-state/);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("register-complete on an unknown edition fails loudly instead of silently succeeding", () => {
|
||||
const { dir, statePath, dataRoot } = fixture();
|
||||
try {
|
||||
run(["register-upsert", "--edition-state", statePath, "--at", T1], dataRoot);
|
||||
const out = run(["register-complete", "--series", "seres", "--edition", "99", "--at", T2], dataRoot);
|
||||
assert.notEqual(out.status, 0);
|
||||
assert.match(out.stderr, /99/);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("a malformed edition-state is refused at the edge, not mirrored", () => {
|
||||
const { dir, statePath, dataRoot } = fixture();
|
||||
try {
|
||||
writeFileSync(statePath, JSON.stringify({ schemaVersion: 1, series: { slug: "seres" } }), "utf8");
|
||||
const out = run(["register-upsert", "--edition-state", statePath, "--at", T1], dataRoot);
|
||||
assert.equal(out.status, 2);
|
||||
assert.match(out.stderr, /currentArticle/);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
139
scripts/editions/tests/editionState.test.ts
Normal file
139
scripts/editions/tests/editionState.test.ts
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
import { describe, test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtempSync, rmSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
|
||||
import {
|
||||
appendPhase,
|
||||
editionFacts,
|
||||
readEditionState,
|
||||
saveEditionState,
|
||||
seriesRootFromStatePath,
|
||||
} from "../src/editionState.js";
|
||||
import type { EditionStateFile } from "../src/types.js";
|
||||
|
||||
const tmp = () => mkdtempSync(join(tmpdir(), "editions-state-"));
|
||||
|
||||
const AT = "2026-07-21T09:30:00.000Z";
|
||||
|
||||
function state(): EditionStateFile {
|
||||
return {
|
||||
schemaVersion: 1,
|
||||
series: { slug: "seres", title: "Seres" },
|
||||
currentArticle: "05",
|
||||
currentPhase: "skeleton-pitch",
|
||||
articles: {
|
||||
"04": { title: "Forrige", phase: "scheduling", phaseLog: [{ phase: "scheduling", completedAt: AT }] },
|
||||
"05": { title: "Da pipelinen brøt sammen", phase: "skeleton-pitch", phaseLog: [] },
|
||||
},
|
||||
} as unknown as EditionStateFile;
|
||||
}
|
||||
|
||||
describe("editionState — facts", () => {
|
||||
test("reads series, edition id, title and phase from the state file", () => {
|
||||
const facts = editionFacts(state());
|
||||
assert.deepEqual(facts, {
|
||||
series: "seres",
|
||||
editionId: "05",
|
||||
title: "Da pipelinen brøt sammen",
|
||||
currentPhase: "skeleton-pitch",
|
||||
});
|
||||
});
|
||||
|
||||
test("a missing currentArticle is an error, not a guess", () => {
|
||||
const broken = { ...state(), currentArticle: undefined } as unknown as EditionStateFile;
|
||||
assert.throws(() => editionFacts(broken), /currentArticle/);
|
||||
});
|
||||
|
||||
test("a currentArticle with no matching articles entry is an error", () => {
|
||||
const broken = { ...state(), currentArticle: "99" } as unknown as EditionStateFile;
|
||||
assert.throws(() => editionFacts(broken), /99/);
|
||||
});
|
||||
|
||||
test("a missing currentPhase is an error — the register must never mirror a guessed phase", () => {
|
||||
const broken = { ...state(), currentPhase: undefined } as unknown as EditionStateFile;
|
||||
assert.throws(() => editionFacts(broken), /currentPhase/);
|
||||
});
|
||||
|
||||
test("an untitled article still resolves — the title is telemetry, not a gate", () => {
|
||||
const s = state();
|
||||
delete (s.articles["05"] as Record<string, unknown>).title;
|
||||
assert.equal(editionFacts(s).title, "");
|
||||
});
|
||||
});
|
||||
|
||||
describe("editionState — phaseLog", () => {
|
||||
test("appends {phase, completedAt} to the article's log", () => {
|
||||
const { state: next, appended } = appendPhase(state(), "05", "skeleton-pitch", AT);
|
||||
assert.equal(appended, true);
|
||||
assert.deepEqual(next.articles["05"].phaseLog, [{ phase: "skeleton-pitch", completedAt: AT }]);
|
||||
});
|
||||
|
||||
test("re-running the same transition does not double-log", () => {
|
||||
const once = appendPhase(state(), "05", "skeleton-pitch", AT).state;
|
||||
const { state: twice, appended } = appendPhase(once, "05", "skeleton-pitch", "2026-07-21T10:00:00.000Z");
|
||||
assert.equal(appended, false);
|
||||
assert.equal(twice.articles["05"].phaseLog?.length, 1);
|
||||
assert.equal(twice.articles["05"].phaseLog?.[0].completedAt, AT, "the first stamp is the real one");
|
||||
});
|
||||
|
||||
test("a phase repeated AFTER another phase is logged again — /linkedin:pivot re-runs cleared gates", () => {
|
||||
let s = appendPhase(state(), "05", "factcheck-sweep", AT).state;
|
||||
s = appendPhase(s, "05", "editorial-review", "2026-07-21T11:00:00.000Z").state;
|
||||
const { state: pivoted, appended } = appendPhase(s, "05", "factcheck-sweep", "2026-07-22T08:00:00.000Z");
|
||||
assert.equal(appended, true);
|
||||
assert.equal(pivoted.articles["05"].phaseLog?.length, 3);
|
||||
assert.deepEqual(
|
||||
pivoted.articles["05"].phaseLog?.map((e) => e.phase),
|
||||
["factcheck-sweep", "editorial-review", "factcheck-sweep"],
|
||||
);
|
||||
});
|
||||
|
||||
test("an article written before phaseLog existed gets the field created", () => {
|
||||
const s = state();
|
||||
delete (s.articles["05"] as Record<string, unknown>).phaseLog;
|
||||
const { state: next } = appendPhase(s, "05", "research", AT);
|
||||
assert.deepEqual(next.articles["05"].phaseLog, [{ phase: "research", completedAt: AT }]);
|
||||
});
|
||||
|
||||
test("other articles are left alone", () => {
|
||||
const next = appendPhase(state(), "05", "research", AT).state;
|
||||
assert.equal(next.articles["04"].phaseLog?.length, 1);
|
||||
assert.equal(next.articles["04"].phaseLog?.[0].phase, "scheduling");
|
||||
});
|
||||
|
||||
test("an unknown article is an error, not a silently created one", () => {
|
||||
assert.throws(() => appendPhase(state(), "99", "research", AT), /99/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("editionState — io", () => {
|
||||
test("save then read round-trips, pretty-printed with a trailing newline", () => {
|
||||
const dir = tmp();
|
||||
try {
|
||||
const path = join(dir, "linkedin", "edition-state.json");
|
||||
saveEditionState(path, appendPhase(state(), "05", "research", AT).state);
|
||||
const raw = readFileSync(path, "utf8");
|
||||
assert.ok(raw.endsWith("\n"));
|
||||
assert.ok(raw.includes('\n "schemaVersion"'), "must stay human-diffable (2-space indent)");
|
||||
const back = readEditionState(path);
|
||||
assert.equal(back.articles["05"].phaseLog?.[0].phase, "research");
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("reading a missing state file is an error — the register mirrors state, it never invents it", () => {
|
||||
const dir = tmp();
|
||||
try {
|
||||
assert.throws(() => readEditionState(join(dir, "absent.json")));
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("the series root is derived from the conventional <serie>/linkedin/edition-state.json path", () => {
|
||||
assert.equal(seriesRootFromStatePath("/series/seres/linkedin/edition-state.json"), "/series/seres");
|
||||
});
|
||||
});
|
||||
277
scripts/editions/tests/register.test.ts
Normal file
277
scripts/editions/tests/register.test.ts
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
import { describe, test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtempSync, rmSync, writeFileSync, existsSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir, homedir } from "node:os";
|
||||
|
||||
import {
|
||||
REGISTER_SCHEMA_VERSION,
|
||||
completeEdition,
|
||||
defaultRegisterPath,
|
||||
elapsedDays,
|
||||
emptyRegister,
|
||||
listEditions,
|
||||
loadRegister,
|
||||
saveRegister,
|
||||
upsertEdition,
|
||||
} from "../src/register.js";
|
||||
import type { EditionRegister } from "../src/types.js";
|
||||
|
||||
const tmp = () => mkdtempSync(join(tmpdir(), "editions-register-"));
|
||||
|
||||
const T0 = "2026-07-20T08:00:00.000Z";
|
||||
const T1 = "2026-07-21T08:00:00.000Z";
|
||||
const T2 = "2026-07-24T20:00:00.000Z";
|
||||
|
||||
function seed(): EditionRegister {
|
||||
return upsertEdition(
|
||||
emptyRegister(),
|
||||
{
|
||||
series: "seres",
|
||||
editionId: "05",
|
||||
title: "Da pipelinen brøt sammen",
|
||||
path: "/series/seres",
|
||||
currentPhase: "research",
|
||||
nextAction: "Step 2.5 — skeleton",
|
||||
},
|
||||
T0,
|
||||
).register;
|
||||
}
|
||||
|
||||
describe("register — store shape", () => {
|
||||
test("emptyRegister carries the schema version and no rows", () => {
|
||||
const reg = emptyRegister();
|
||||
assert.equal(reg.schemaVersion, REGISTER_SCHEMA_VERSION);
|
||||
assert.deepEqual(reg.editions, []);
|
||||
});
|
||||
|
||||
test("a missing register file loads as an empty one — the first edition is not an error", () => {
|
||||
const dir = tmp();
|
||||
try {
|
||||
const reg = loadRegister(join(dir, "nope", "register.json"));
|
||||
assert.equal(reg.schemaVersion, REGISTER_SCHEMA_VERSION);
|
||||
assert.deepEqual(reg.editions, []);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("save creates the parent directory and round-trips the rows", () => {
|
||||
const dir = tmp();
|
||||
try {
|
||||
const path = join(dir, "editions", "register.json");
|
||||
saveRegister(path, seed());
|
||||
assert.ok(existsSync(path), "saveRegister must create the parent dir");
|
||||
assert.ok(readFileSync(path, "utf8").endsWith("\n"), "file must end with a newline");
|
||||
const back = loadRegister(path);
|
||||
assert.equal(back.editions.length, 1);
|
||||
assert.equal(back.editions[0].editionId, "05");
|
||||
assert.equal(back.editions[0].startedAt, T0);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("a malformed register degrades to empty rows instead of throwing", () => {
|
||||
const dir = tmp();
|
||||
try {
|
||||
const path = join(dir, "register.json");
|
||||
writeFileSync(path, JSON.stringify({ schemaVersion: 1, editions: "not-an-array" }), "utf8");
|
||||
assert.deepEqual(loadRegister(path).editions, []);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("register — upsert", () => {
|
||||
test("a new edition is created as active, with startedAt == updatedAt", () => {
|
||||
const { register, row, created } = upsertEdition(
|
||||
emptyRegister(),
|
||||
{ series: "seres", editionId: "05", title: "T", path: "/p", currentPhase: "load-context" },
|
||||
T0,
|
||||
);
|
||||
assert.equal(created, true);
|
||||
assert.equal(register.editions.length, 1);
|
||||
assert.equal(row.status, "active");
|
||||
assert.equal(row.startedAt, T0);
|
||||
assert.equal(row.updatedAt, T0);
|
||||
assert.equal(row.completedAt, null);
|
||||
});
|
||||
|
||||
test("the same (series, editionId) is updated in place — never duplicated", () => {
|
||||
const { register, row, created } = upsertEdition(
|
||||
seed(),
|
||||
{ series: "seres", editionId: "05", title: "T", path: "/p", currentPhase: "skeleton-pitch" },
|
||||
T1,
|
||||
);
|
||||
assert.equal(created, false);
|
||||
assert.equal(register.editions.length, 1);
|
||||
assert.equal(row.currentPhase, "skeleton-pitch");
|
||||
assert.equal(row.startedAt, T0, "startedAt is the lead-time anchor — it must survive every update");
|
||||
assert.equal(row.updatedAt, T1);
|
||||
});
|
||||
|
||||
test("omitted nextAction/slot/title are PRESERVED, not blanked", () => {
|
||||
const withSlot = upsertEdition(
|
||||
seed(),
|
||||
{ series: "seres", editionId: "05", path: "/p", currentPhase: "draft", slot: "2026-07-28 07:45" },
|
||||
T1,
|
||||
).register;
|
||||
const { row } = upsertEdition(
|
||||
withSlot,
|
||||
{ series: "seres", editionId: "05", path: "/p", currentPhase: "consistency-quality" },
|
||||
T2,
|
||||
);
|
||||
assert.equal(row.slot, "2026-07-28 07:45");
|
||||
assert.equal(row.nextAction, "Step 2.5 — skeleton");
|
||||
assert.equal(row.title, "Da pipelinen brøt sammen");
|
||||
});
|
||||
|
||||
test("supplied nextAction/slot overwrite the previous values", () => {
|
||||
const { row } = upsertEdition(
|
||||
seed(),
|
||||
{
|
||||
series: "seres",
|
||||
editionId: "05",
|
||||
path: "/p",
|
||||
currentPhase: "draft",
|
||||
nextAction: "Step 4 — consistency",
|
||||
slot: "2026-07-28 07:45",
|
||||
},
|
||||
T1,
|
||||
);
|
||||
assert.equal(row.nextAction, "Step 4 — consistency");
|
||||
assert.equal(row.slot, "2026-07-28 07:45");
|
||||
});
|
||||
|
||||
test("two editions of the same series are two rows", () => {
|
||||
const { register } = upsertEdition(
|
||||
seed(),
|
||||
{ series: "seres", editionId: "06", title: "Neste", path: "/series/seres", currentPhase: "load-context" },
|
||||
T1,
|
||||
);
|
||||
assert.equal(register.editions.length, 2);
|
||||
});
|
||||
|
||||
test("the same edition number in a different series is a different row", () => {
|
||||
const { register } = upsertEdition(
|
||||
seed(),
|
||||
{ series: "annen", editionId: "05", title: "Annen 05", path: "/series/annen", currentPhase: "load-context" },
|
||||
T1,
|
||||
);
|
||||
assert.equal(register.editions.length, 2);
|
||||
assert.equal(register.editions[1].series, "annen");
|
||||
});
|
||||
|
||||
test("re-upserting a completed edition reactivates it — a pivot re-opens the row it already has", () => {
|
||||
const done = completeEdition(seed(), { series: "seres", editionId: "05" }, T1).register;
|
||||
const { register, row } = upsertEdition(
|
||||
done,
|
||||
{ series: "seres", editionId: "05", path: "/p", currentPhase: "factcheck-sweep" },
|
||||
T2,
|
||||
);
|
||||
assert.equal(register.editions.length, 1);
|
||||
assert.equal(row.status, "active");
|
||||
assert.equal(row.completedAt, null);
|
||||
assert.equal(row.startedAt, T0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("register — complete", () => {
|
||||
test("complete stamps completedAt and flips the status", () => {
|
||||
const { register, row } = completeEdition(seed(), { series: "seres", editionId: "05" }, T1);
|
||||
assert.equal(row?.status, "complete");
|
||||
assert.equal(row?.completedAt, T1);
|
||||
assert.equal(register.editions[0].updatedAt, T1);
|
||||
});
|
||||
|
||||
test("completing twice keeps the FIRST completedAt — lead time must not drift on a re-run", () => {
|
||||
const once = completeEdition(seed(), { series: "seres", editionId: "05" }, T1).register;
|
||||
const { row } = completeEdition(once, { series: "seres", editionId: "05" }, T2);
|
||||
assert.equal(row?.completedAt, T1);
|
||||
});
|
||||
|
||||
test("completing an unknown edition returns null and leaves the register untouched", () => {
|
||||
const reg = seed();
|
||||
const { register, row } = completeEdition(reg, { series: "seres", editionId: "99" }, T1);
|
||||
assert.equal(row, null);
|
||||
assert.equal(register.editions[0].status, "active");
|
||||
});
|
||||
});
|
||||
|
||||
describe("register — list", () => {
|
||||
function twoActiveOneDone(): EditionRegister {
|
||||
let reg = seed();
|
||||
reg = upsertEdition(
|
||||
reg,
|
||||
{ series: "annen", editionId: "02", title: "A", path: "/p", currentPhase: "draft" },
|
||||
T1,
|
||||
).register;
|
||||
reg = upsertEdition(
|
||||
reg,
|
||||
{ series: "seres", editionId: "04", title: "Eldre", path: "/p", currentPhase: "scheduling" },
|
||||
T1,
|
||||
).register;
|
||||
return completeEdition(reg, { series: "seres", editionId: "04" }, T2).register;
|
||||
}
|
||||
|
||||
test("list shows only the editions in flight by default", () => {
|
||||
const rows = listEditions(twoActiveOneDone());
|
||||
assert.equal(rows.length, 2);
|
||||
assert.ok(rows.every((r) => r.status === "active"));
|
||||
});
|
||||
|
||||
test("includeComplete lists the whole history", () => {
|
||||
assert.equal(listEditions(twoActiveOneDone(), { includeComplete: true }).length, 3);
|
||||
});
|
||||
|
||||
test("ordering is deterministic — active first, then series, then edition id", () => {
|
||||
const rows = listEditions(twoActiveOneDone(), { includeComplete: true });
|
||||
assert.deepEqual(
|
||||
rows.map((r) => `${r.status}:${r.series}/${r.editionId}`),
|
||||
["active:annen/02", "active:seres/05", "complete:seres/04"],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("register — lead time", () => {
|
||||
test("elapsedDays measures the span between two ISO stamps", () => {
|
||||
assert.equal(elapsedDays(T0, T1), 1);
|
||||
assert.equal(elapsedDays(T0, T0), 0);
|
||||
});
|
||||
|
||||
test("elapsedDays keeps sub-day precision — a two-editions-a-week cadence is measured in hours", () => {
|
||||
assert.equal(elapsedDays("2026-07-20T00:00:00.000Z", "2026-07-20T12:00:00.000Z"), 0.5);
|
||||
});
|
||||
|
||||
test("an unparseable stamp yields null rather than NaN", () => {
|
||||
assert.equal(elapsedDays("ikke-en-dato", T1), null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("register — default path (M0 data-path convention)", () => {
|
||||
test("LINKEDIN_STUDIO_DATA relocates the register", () => {
|
||||
const prev = process.env.LINKEDIN_STUDIO_DATA;
|
||||
process.env.LINKEDIN_STUDIO_DATA = "/scratch/data";
|
||||
try {
|
||||
assert.equal(defaultRegisterPath(), join("/scratch/data", "editions", "register.json"));
|
||||
} finally {
|
||||
if (prev === undefined) delete process.env.LINKEDIN_STUDIO_DATA;
|
||||
else process.env.LINKEDIN_STUDIO_DATA = prev;
|
||||
}
|
||||
});
|
||||
|
||||
test("without the env-var it falls back to the per-user data dir", () => {
|
||||
const prev = process.env.LINKEDIN_STUDIO_DATA;
|
||||
delete process.env.LINKEDIN_STUDIO_DATA;
|
||||
try {
|
||||
assert.equal(
|
||||
defaultRegisterPath(),
|
||||
join(homedir(), ".claude", "linkedin-studio", "editions", "register.json"),
|
||||
);
|
||||
} finally {
|
||||
if (prev !== undefined) process.env.LINKEDIN_STUDIO_DATA = prev;
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue