A1-10 + D-5. The queue answers "what is scheduled"; nothing answered "is the week covered, and what is still being written". N13 makes both readable at session start. - Publishing slots are operator config: profile/publishing-slots.json in the per-user data dir, schema + OPT-IN template in config/publishing-slots.template.json. The plugin ships no publishing times and writes the grid for nobody; absent config means every slot surface stays silent (same never-nag discipline as the trend/brain nudges). Data dir rather than the state file, which is machine-written and whose frontmatter reader does not parse lists. - hooks/scripts/slots.mjs (new): one implementation behind four surfaces. Zero-dep (a SessionStart hook must not spawn tsx), pure core (dates in as strings, no clock), imported by the commands exactly as queue-manager.mjs already is — so session-start's vacancy warning and Step 10's slot default cannot drift apart. - Coverage counts the short-form queue (scheduled/published; cancelled frees the slot) AND editions-register rows claiming that date, counted per date, so long-form and short-form cannot be double-booked and a two-slot day needs two posts. - Session start gains "## Editions in Flight" (series, phase, next action, claimed slot, days in flight) and "## Publishing Slots" (next open slot, open count in 14 days, and how to fill it when the gap is <=3 days). The existing discovery nudge is untouched. - /linkedin router + /linkedin:calendar surface the same roll-up; calendar documents the opt-in copy. /linkedin:newsletter Step 10 defaults to the next open slot (one confirmation, not an interview) and writes --slot onto the register row. - D-5: references/scheduling-strategy.md marked "confidence: low / directional" per the algorithm reference's own standard, deferring to the operator's grid and their own analytics. Neutral example time replaces the operator-specific one in the N12 docs. TDD: red proven first (module absent; 5 session-start behaviours failing). hooks 140 -> 174 · test-runner 184 -> 197 (Section 16t: 13 unconditional greps incl. a de-niche check that no publishing time is hardcoded in the slot path and no operator grid is committed, + non-vacuity self-test; anti-erosion floor 166 -> 179). Suites green: trends 300/0 · brain 134/0 · editions 72/0 · specifics-bank 45/0 · tests 35/0 · render 60/0. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QxvWAjte7vPcF79QeSRvRJ
277 lines
9.5 KiB
TypeScript
277 lines
9.5 KiB
TypeScript
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 08:30" },
|
|
T1,
|
|
).register;
|
|
const { row } = upsertEdition(
|
|
withSlot,
|
|
{ series: "seres", editionId: "05", path: "/p", currentPhase: "consistency-quality" },
|
|
T2,
|
|
);
|
|
assert.equal(row.slot, "2026-07-28 08:30");
|
|
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 08:30",
|
|
},
|
|
T1,
|
|
);
|
|
assert.equal(row.nextAction, "Step 4 — consistency");
|
|
assert.equal(row.slot, "2026-07-28 08:30");
|
|
});
|
|
|
|
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;
|
|
}
|
|
});
|
|
});
|