fix(continue): run the arg-parser, find the master prompt at the repo root, and let the consistency check read the state file

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-10-23 15:05:19 +02:00
commit f32baf50ad
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
6 changed files with 204 additions and 20 deletions

View file

@ -8,7 +8,8 @@ import assert from 'node:assert/strict';
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { execFileSync } from 'node:child_process';
import { execFileSync, spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import {
validateNextSessionPromptContent,
@ -133,3 +134,73 @@ test('CLI shim — consistency mode flags producer mismatch', () => {
rmSync(dir, { recursive: true, force: true });
}
});
// --- #102: the consistency call reads the state file -----------------------
// The CLI counted the --state-file value as a third positional and exited 2,
// so the state-anchored staleness check never ran from the command line; and
// an invalid B still gave valid: true. These tests use spawnSync so they reach
// an assertion on exit 2 too.
const CLI = fileURLToPath(new URL('../../lib/validators/next-session-prompt-validator.mjs', import.meta.url));
function runCli(args) {
return spawnSync(process.execPath, [CLI, ...args], { encoding: 'utf-8' });
}
/** A stale master (older than the state's updated_at) and a fresh sibling by another producer. */
function stalePair(dir) {
const a = join(dir, 'a.md');
const b = join(dir, 'b.md');
const s = join(dir, '.session-state.local.json');
writeFileSync(a, frontmatter('graceful-handoff', '2026-05-03T10:00:00.000Z'));
writeFileSync(b, frontmatter('trekexecute', '2026-05-04T16:05:00.000Z'));
writeFileSync(s, JSON.stringify({ schema_version: 1, updated_at: '2026-05-04T16:00:00.000Z' }));
return { a, b, s };
}
test('[#102] CLI --json --consistency a b --state-file s: the state-anchored case exits 0 with a STALE_IGNORED warning', () => {
const dir = mkdtempSync(join(tmpdir(), 'nspv-cli-'));
try {
const { a, b, s } = stalePair(dir);
const r = runCli(['--json', '--consistency', a, b, '--state-file', s]);
assert.equal(r.status, 0, `exit ${r.status}: ${r.stdout}${r.stderr}`);
const parsed = JSON.parse(r.stdout);
assert.equal(parsed.valid, true, JSON.stringify(parsed.errors));
assert.ok(parsed.warnings.find((w) => w.code === 'NEXT_SESSION_PROMPT_STALE_IGNORED'),
'the stale candidate was not ignored');
assert.equal(parsed.errors.find((e) => e.code === 'NEXT_SESSION_PROMPT_PRODUCER_MISMATCH'), undefined);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test('control: the same pair without --state-file is a producer mismatch (exit 1)', () => {
const dir = mkdtempSync(join(tmpdir(), 'nspv-cli-'));
try {
const { a, b } = stalePair(dir);
const r = runCli(['--json', '--consistency', a, b]);
assert.equal(r.status, 1, `exit ${r.status}: ${r.stdout}${r.stderr}`);
const parsed = JSON.parse(r.stdout);
assert.equal(parsed.valid, false);
assert.ok(parsed.errors.find((e) => e.code === 'NEXT_SESSION_PROMPT_PRODUCER_MISMATCH'));
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test('[#102] sibling: rb.valid counts: an invalid B makes the consistency result invalid (exit 1)', () => {
const dir = mkdtempSync(join(tmpdir(), 'nspv-cli-'));
try {
const a = join(dir, 'a.md');
const b = join(dir, 'b.md');
writeFileSync(a, frontmatter('trekexecute', '2026-05-04T16:00:00.000Z'));
writeFileSync(b, '---\nproduced_by: trekexecute\n---\n\n# B, no produced_at\n');
const r = runCli(['--json', '--consistency', a, b]);
assert.equal(r.status, 1, `an invalid B still passed: exit ${r.status}: ${r.stdout}${r.stderr}`);
const parsed = JSON.parse(r.stdout);
assert.equal(parsed.valid, false);
assert.ok(parsed.errors.find((e) => e.code === 'NEXT_SESSION_PROMPT_MISSING_FIELD' && /produced_at/.test(e.message)));
} finally {
rmSync(dir, { recursive: true, force: true });
}
});