graceful-handoff/tests/plugin-manifest.test.mjs
Kjell Tore Guttormsen 5334097c84 fix(graceful-handoff): two defects found by the first real smoke test (v3.2.1)
The pipeline had never been run against an actual repository — every test in
the suite is either a prose-grep over SKILL.md or a unit test that asserts key
presence. Running it against scratch repos (private remote, and public `open/`
remote with and without a gitignored STATE.md) found two defects living under
a 42/42-green suite.

1. dirty_files truncated the first path. gitOk() trims every command's output,
   but `git status --porcelain` puts the worktree status in column 2, so a
   modified-but-unstaged file is " M path". The trim ate the leading space and
   the fixed slice(3) then ate the first character: app.js was reported as
   pp.js. Only the first line is affected, which is why it survived — no test
   asserted dirty_files VALUES, only that the key existed. Porcelain now goes
   through a non-trimming gitOkRaw().

2. The commit message claimed a STATE.md update it did not contain. The
   message was hardcoded to "oppdater STATE.md" regardless of what was staged.
   On every `open/` repo STATE.md is gitignored, so the handoff commit carries
   only the --also paths. Git history is the regime's long-term log; it was
   systematically wrong about its own contents.

Also promotes the leak condition from advisory to hard gate. A public remote
whose STATE.md is not yet gitignored is the state a FRESH open/ repo starts
in, and should_commit_state was true there — the ritual only mentioned
leak_warning, then committed. It now lands in errors[] (step 2 stops on a
non-empty errors[]), should_commit_state is false, and --commit refuses to
stage STATE.md. Explicit --also paths are still honoured: the gate protects
STATE.md, not the commit as a whole.

And corrects SKILL.md's justification for the single-line rule. It claimed a
wrapped rationale= replaces the board's next step with garbage; board.sh in
repo-mailbox 0.20.3 tracks a comment to its closer, so that no longer follows.
The rule stands, restated with the risk that is still real: a rationale
containing the closer sequence ends its own comment early.

Tests 42 -> 48, all six written failing first.

Still unverified: that /graceful-handoff loads as a user command (#26251), and
that a cross-plugin Skill invocation of repo-mailbox:route passes from a
sub-scoped skill. Both need the catalog ref bumped so the version is installed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RvLY4FwbzY157oVqwnkHD8
2026-08-09 21:49:08 +02:00

54 lines
2.1 KiB
JavaScript

// plugin-manifest.test.mjs — verify plugin.json schema + CHANGELOG for v3.0.
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const MANIFEST = join(__dirname, '..', '.claude-plugin', 'plugin.json');
const CHANGELOG = join(__dirname, '..', 'CHANGELOG.md');
test('plugin.json version is 3.2.1', () => {
const m = JSON.parse(readFileSync(MANIFEST, 'utf-8'));
assert.equal(m.version, '3.2.1');
});
test('CHANGELOG has a [3.2.0] entry describing the ritual sync', () => {
const c = readFileSync(CHANGELOG, 'utf-8');
const match = c.match(/## \[3\.2\.0\][\s\S]*?(?=## \[3\.1\.0\]|$)/);
assert.ok(match, '[3.2.0] section missing');
assert.match(match[0], /route/);
});
test('plugin.json description mentions STATE.md', () => {
const m = JSON.parse(readFileSync(MANIFEST, 'utf-8'));
assert.match(m.description, /STATE\.md/);
});
test('plugin.json does NOT include auto_discover (not in documented schema)', () => {
const m = JSON.parse(readFileSync(MANIFEST, 'utf-8'));
assert.ok(!('auto_discover' in m), 'auto_discover field should be removed');
});
test('CHANGELOG has [3.0.0] entry with BREAKING section mentioning STATE.md', () => {
const c = readFileSync(CHANGELOG, 'utf-8');
const match = c.match(/## \[3\.0\.0\][\s\S]*?(?=## \[2\.1\.0\]|$)/);
assert.ok(match, '[3.0.0] section missing');
assert.match(match[0], /### BREAKING/);
assert.match(match[0], /STATE\.md/);
});
test('CHANGELOG preserves [2.1.0] and [2.0.0] history', () => {
const c = readFileSync(CHANGELOG, 'utf-8');
assert.match(c, /## \[2\.1\.0\]/);
assert.match(c, /## \[2\.0\.0\]/);
const v20 = c.match(/## \[2\.0\.0\][\s\S]*?(?=## \[1\.0\.0\]|$)/);
assert.ok(v20 && /### BREAKING/.test(v20[0]), '[2.0.0] BREAKING section should remain');
});
test('No source files reference version 1.0.0 / 2.x as current', () => {
const raw = readFileSync(MANIFEST, 'utf-8');
assert.doesNotMatch(raw, /"version":\s*"[12]\./);
});