mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-20 23:23:26 +01:00
test(free): split files over the 60 s seed ceiling and the Windows doctor file
Eight free test files the fresh recordings put over the seed ratchet's 60 s ceiling, and test/gstack-doctor.test.ts (343 s on Windows), are split by describe block or test with shared helpers moved to test/helpers/. Test bodies are unchanged. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
4729f4752b
commit
edb9870ed2
35 files changed
+3038
-2657
No files matched your search
@@ -5,42 +5,13 @@
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { join } from 'node:path';
|
||||
import { MARKER, failableBun, setup, config, defaultRender, record, served } from './helpers/claude-overlay-fixture';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, put, registryRows, runSetup } from './helpers/install-fixture';
|
||||
import { MARKER, setup, config, defaultRender, record, served } from './helpers/claude-overlay-fixture';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, runSetup } from './helpers/install-fixture';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('nondefault installs, refresh and status', () => {
|
||||
test('a project install keeps its own per-install render: pinned, back to claude, failure keeps the previous render', () => {
|
||||
const f = makeFixture();
|
||||
failableBun(f);
|
||||
const project = join(f.home, 'proj');
|
||||
const vendored = makeSource(f, join(project, '.claude/skills/gstack'));
|
||||
const skills = join(project, '.claude/skills');
|
||||
const renderOf = () => registryRows(f).find(row => row[0] === 'claude')?.[8] ?? '';
|
||||
|
||||
expect(setup(f, vendored, ['--claude-model', 'claude-opus-4-7'], project).status).toBe(0);
|
||||
const render = renderOf();
|
||||
expect(render).toContain('/render/installs/claude-');
|
||||
expect(record(render)).toMatchObject({ overlay: 'opus-4-7', source: 'explicit' });
|
||||
expect(served(skills)).toContain(MARKER);
|
||||
expect(served(skills)).toContain(`${vendored}/bin/gstack-skill-start`);
|
||||
|
||||
expect(setup(f, vendored, ['--claude-model', 'claude'], project).status).toBe(0);
|
||||
expect(renderOf()).toBe(render);
|
||||
expect(record(render).overlay).toBe('claude');
|
||||
expect(served(skills)).not.toContain(MARKER);
|
||||
expect(served(skills)).toContain(`${vendored}/bin/gstack-skill-start`);
|
||||
|
||||
put(join(f.home, 'fail-render'), '1');
|
||||
const failed = setup(f, vendored, ['--claude-model', 'claude-opus-4-8'], project);
|
||||
expect(failed.status, failed.out).toBe(0);
|
||||
expect(failed.out).toContain('the previous render stays in use');
|
||||
expect(served(skills)).toContain(`${vendored}/bin/gstack-skill-start`);
|
||||
expect(served(skills)).not.toContain(MARKER);
|
||||
}, 240_000);
|
||||
|
||||
test('--refresh-registered persists the overlay before refreshing; later refreshes honor it with no flag', () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, join(f.home, '.claude/skills/gstack'));
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
* Shared fixture and overlay helpers: test/helpers/claude-overlay-fixture.ts.
|
||||
*/
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
||||
import { existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { MARKER, failableBun, fakeDetect, setup, config, defaultRender, record, served } from './helpers/claude-overlay-fixture';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, put, setVersion } from './helpers/install-fixture';
|
||||
import { MARKER, fakeDetect, setup, config, defaultRender, record, served } from './helpers/claude-overlay-fixture';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, put } from './helpers/install-fixture';
|
||||
import { readSkillStartup } from './helpers/skill-startup';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
@@ -57,49 +56,4 @@ describe.skipIf(process.platform === 'win32')('overlay render lifecycle with gbr
|
||||
expect(existsSync(`${defaultRender(f)}.overlay`)).toBe(false);
|
||||
expect(served(join(f.home, '.claude/skills'))).toBe(readSkillStartup(join(src, 'autoplan/SKILL.md')));
|
||||
}, 180_000);
|
||||
|
||||
test('a failed render keeps the previous render; after an upgrade it serves the committed files', () => {
|
||||
const f = makeFixture();
|
||||
failableBun(f);
|
||||
const src = makeSource(f, join(f.home, '.claude/skills/gstack'));
|
||||
const skills = join(f.home, '.claude/skills');
|
||||
expect(setup(f, src, ['--claude-model', 'claude-sonnet-5']).status).toBe(0);
|
||||
expect(record(defaultRender(f)).overlay).toBe('sonnet-5');
|
||||
|
||||
put(join(f.home, 'fail-render'), '1');
|
||||
const kept = setup(f, src);
|
||||
expect(kept.status, kept.out).toBe(0);
|
||||
expect(kept.out).toContain('the previous render (sonnet-5 overlay) stays in use');
|
||||
expect(existsSync(join(defaultRender(f), 'autoplan/SKILL.md'))).toBe(true);
|
||||
|
||||
setVersion(src, '9.9.9.9');
|
||||
const upgraded = setup(f, src);
|
||||
expect(upgraded.status, upgraded.out).toBe(0);
|
||||
expect(upgraded.out).toContain('the committed claude render is served');
|
||||
expect(upgraded.out).toContain('Claude skill overlay: claude (was sonnet-5).');
|
||||
expect(existsSync(defaultRender(f))).toBe(false);
|
||||
expect(record(defaultRender(f))).toMatchObject({ overlay: 'claude', source: 'explicit', render: 'committed', version: '9.9.9.9' });
|
||||
expect(served(skills)).toBe(readSkillStartup(join(src, 'autoplan/SKILL.md')));
|
||||
}, 240_000);
|
||||
|
||||
test('concurrent gbrain-refresh runs leave one valid render and no temp, old or lock dirs', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, join(f.home, '.claude/skills/gstack'));
|
||||
fakeDetect(src);
|
||||
expect(setup(f, src, ['--claude-model', 'claude-opus-4-7']).status).toBe(0);
|
||||
put(join(f.home, 'gbrain-mode'), 'ok');
|
||||
const run = () => new Promise<{ code: number | null; err: string }>(resolve => {
|
||||
const child = spawn('bash', [join(src, 'bin/gstack-config'), 'gbrain-refresh'], { env: f.env, stdio: ['ignore', 'ignore', 'pipe'] });
|
||||
let err = '';
|
||||
child.stderr.on('data', chunk => { err += chunk; });
|
||||
child.on('exit', code => resolve({ code, err }));
|
||||
});
|
||||
const runs = await Promise.all([run(), run(), run()]);
|
||||
expect(runs).toEqual([{ code: 0, err: '' }, { code: 0, err: '' }, { code: 0, err: '' }]);
|
||||
const renderParent = join(f.home, '.gstack/render');
|
||||
expect(readdirSync(renderParent).sort()).toEqual(['claude', 'claude.overlay']);
|
||||
expect(readdirSync(defaultRender(f)).filter(name => name.startsWith('claude'))).toEqual([]);
|
||||
expect(readSkillStartup(join(defaultRender(f), 'autoplan/SKILL.md'))).toContain(MARKER);
|
||||
expect(record(defaultRender(f))).toMatchObject({ overlay: 'opus-4-7', gbrain: 'ok' });
|
||||
}, 240_000);
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* W7 Claude overlay opt-in (`./setup --claude-model <id>`): a project install keeps its own per-install render. Split from test/claude-overlay-setup-installs.test.ts so the free-suite packer can balance it (60 s seed ceiling). Shared fixture and overlay helpers: test/helpers/claude-overlay-fixture.ts.
|
||||
*/
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { join } from 'node:path';
|
||||
import { MARKER, failableBun, setup, record, served } from './helpers/claude-overlay-fixture';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, put, registryRows } from './helpers/install-fixture';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('nondefault installs, refresh and status', () => {
|
||||
test('a project install keeps its own per-install render: pinned, back to claude, failure keeps the previous render', () => {
|
||||
const f = makeFixture();
|
||||
failableBun(f);
|
||||
const project = join(f.home, 'proj');
|
||||
const vendored = makeSource(f, join(project, '.claude/skills/gstack'));
|
||||
const skills = join(project, '.claude/skills');
|
||||
const renderOf = () => registryRows(f).find(row => row[0] === 'claude')?.[8] ?? '';
|
||||
|
||||
expect(setup(f, vendored, ['--claude-model', 'claude-opus-4-7'], project).status).toBe(0);
|
||||
const render = renderOf();
|
||||
expect(render).toContain('/render/installs/claude-');
|
||||
expect(record(render)).toMatchObject({ overlay: 'opus-4-7', source: 'explicit' });
|
||||
expect(served(skills)).toContain(MARKER);
|
||||
expect(served(skills)).toContain(`${vendored}/bin/gstack-skill-start`);
|
||||
|
||||
expect(setup(f, vendored, ['--claude-model', 'claude'], project).status).toBe(0);
|
||||
expect(renderOf()).toBe(render);
|
||||
expect(record(render).overlay).toBe('claude');
|
||||
expect(served(skills)).not.toContain(MARKER);
|
||||
expect(served(skills)).toContain(`${vendored}/bin/gstack-skill-start`);
|
||||
|
||||
put(join(f.home, 'fail-render'), '1');
|
||||
const failed = setup(f, vendored, ['--claude-model', 'claude-opus-4-8'], project);
|
||||
expect(failed.status, failed.out).toBe(0);
|
||||
expect(failed.out).toContain('the previous render stays in use');
|
||||
expect(served(skills)).toContain(`${vendored}/bin/gstack-skill-start`);
|
||||
expect(served(skills)).not.toContain(MARKER);
|
||||
}, 240_000);
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* W7 Claude overlay opt-in (`./setup --claude-model <id>`): a failed render and an upgrade keep a valid render, and concurrent refreshes leave one. Split from test/claude-overlay-setup-lifecycle.test.ts so the free-suite packer can balance it (60 s seed ceiling). Shared fixture and overlay helpers: test/helpers/claude-overlay-fixture.ts.
|
||||
*/
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { existsSync, readdirSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { MARKER, failableBun, fakeDetect, setup, config, defaultRender, record, served } from './helpers/claude-overlay-fixture';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, put, setVersion } from './helpers/install-fixture';
|
||||
import { readSkillStartup } from './helpers/skill-startup';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('overlay render lifecycle with gbrain and failures', () => {
|
||||
test('a failed render keeps the previous render; after an upgrade it serves the committed files', () => {
|
||||
const f = makeFixture();
|
||||
failableBun(f);
|
||||
const src = makeSource(f, join(f.home, '.claude/skills/gstack'));
|
||||
const skills = join(f.home, '.claude/skills');
|
||||
expect(setup(f, src, ['--claude-model', 'claude-sonnet-5']).status).toBe(0);
|
||||
expect(record(defaultRender(f)).overlay).toBe('sonnet-5');
|
||||
|
||||
put(join(f.home, 'fail-render'), '1');
|
||||
const kept = setup(f, src);
|
||||
expect(kept.status, kept.out).toBe(0);
|
||||
expect(kept.out).toContain('the previous render (sonnet-5 overlay) stays in use');
|
||||
expect(existsSync(join(defaultRender(f), 'autoplan/SKILL.md'))).toBe(true);
|
||||
|
||||
setVersion(src, '9.9.9.9');
|
||||
const upgraded = setup(f, src);
|
||||
expect(upgraded.status, upgraded.out).toBe(0);
|
||||
expect(upgraded.out).toContain('the committed claude render is served');
|
||||
expect(upgraded.out).toContain('Claude skill overlay: claude (was sonnet-5).');
|
||||
expect(existsSync(defaultRender(f))).toBe(false);
|
||||
expect(record(defaultRender(f))).toMatchObject({ overlay: 'claude', source: 'explicit', render: 'committed', version: '9.9.9.9' });
|
||||
expect(served(skills)).toBe(readSkillStartup(join(src, 'autoplan/SKILL.md')));
|
||||
}, 240_000);
|
||||
|
||||
test('concurrent gbrain-refresh runs leave one valid render and no temp, old or lock dirs', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, join(f.home, '.claude/skills/gstack'));
|
||||
fakeDetect(src);
|
||||
expect(setup(f, src, ['--claude-model', 'claude-opus-4-7']).status).toBe(0);
|
||||
put(join(f.home, 'gbrain-mode'), 'ok');
|
||||
const run = () => new Promise<{ code: number | null; err: string }>(resolve => {
|
||||
const child = spawn('bash', [join(src, 'bin/gstack-config'), 'gbrain-refresh'], { env: f.env, stdio: ['ignore', 'ignore', 'pipe'] });
|
||||
let err = '';
|
||||
child.stderr.on('data', chunk => { err += chunk; });
|
||||
child.on('exit', code => resolve({ code, err }));
|
||||
});
|
||||
const runs = await Promise.all([run(), run(), run()]);
|
||||
expect(runs).toEqual([{ code: 0, err: '' }, { code: 0, err: '' }, { code: 0, err: '' }]);
|
||||
const renderParent = join(f.home, '.gstack/render');
|
||||
expect(readdirSync(renderParent).sort()).toEqual(['claude', 'claude.overlay']);
|
||||
expect(readdirSync(defaultRender(f)).filter(name => name.startsWith('claude'))).toEqual([]);
|
||||
expect(readSkillStartup(join(defaultRender(f), 'autoplan/SKILL.md'))).toContain(MARKER);
|
||||
expect(record(defaultRender(f))).toMatchObject({ overlay: 'opus-4-7', gbrain: 'ok' });
|
||||
}, 240_000);
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
// Split from test/docsync-fault-interface.test.ts (GSTA-151): the fault-control callback replays.
|
||||
import { expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { docsFaultCallbackScript } from './helpers/docsync-fault-callbacks';
|
||||
|
||||
const CALLBACK_SPLITS = [
|
||||
['fault controls', '^ship-docsync-(?!failure )[a-z-]+ rejects ', 14],
|
||||
] as const;
|
||||
|
||||
for (const [split, pattern, count] of CALLBACK_SPLITS) test(`registered fault callbacks execute actual transport and hook commands, consume results, and reject controls without model calls (${split})`, () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'docs-fault-callback-'));
|
||||
const root = path.resolve(import.meta.dir, '..');
|
||||
try {
|
||||
const script = path.join(dir, 'callbacks.test.ts');
|
||||
fs.writeFileSync(script, docsFaultCallbackScript(root));
|
||||
const home = path.join(dir, 'home');
|
||||
fs.mkdirSync(home);
|
||||
const result = Bun.spawnSync([process.execPath, 'test', script, '--test-name-pattern', pattern], {
|
||||
env: { ...process.env, EVALS: '', EVALS_TIER: '', EVALS_ALL: '', EVALS_RUN_ID: 'free-docsync-faults',
|
||||
HOME: home, USERPROFILE: home,
|
||||
GSTACK_EVAL_DIR: path.join(dir, 'evidence'), GSTACK_HOME: path.join(dir, 'state') },
|
||||
stdout: 'pipe', stderr: 'pipe', timeout: 120_000,
|
||||
});
|
||||
const output = result.stdout.toString() + result.stderr.toString();
|
||||
expect(result.exitCode, output).toBe(0);
|
||||
expect(output).toContain(`${count} pass`);
|
||||
expect(output).toContain(`${36 - count} filtered out`);
|
||||
expect(output).toContain('0 fail');
|
||||
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
||||
}, 120_000);
|
||||
@@ -0,0 +1,32 @@
|
||||
// Split from test/docsync-fault-interface.test.ts (GSTA-151): the legacy-control callback replays.
|
||||
import { expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { docsFaultCallbackScript } from './helpers/docsync-fault-callbacks';
|
||||
|
||||
const CALLBACK_SPLITS = [
|
||||
['legacy controls', '^ship-docsync-failure rejects ', 12],
|
||||
] as const;
|
||||
|
||||
for (const [split, pattern, count] of CALLBACK_SPLITS) test(`registered fault callbacks execute actual transport and hook commands, consume results, and reject controls without model calls (${split})`, () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'docs-fault-callback-'));
|
||||
const root = path.resolve(import.meta.dir, '..');
|
||||
try {
|
||||
const script = path.join(dir, 'callbacks.test.ts');
|
||||
fs.writeFileSync(script, docsFaultCallbackScript(root));
|
||||
const home = path.join(dir, 'home');
|
||||
fs.mkdirSync(home);
|
||||
const result = Bun.spawnSync([process.execPath, 'test', script, '--test-name-pattern', pattern], {
|
||||
env: { ...process.env, EVALS: '', EVALS_TIER: '', EVALS_ALL: '', EVALS_RUN_ID: 'free-docsync-faults',
|
||||
HOME: home, USERPROFILE: home,
|
||||
GSTACK_EVAL_DIR: path.join(dir, 'evidence'), GSTACK_HOME: path.join(dir, 'state') },
|
||||
stdout: 'pipe', stderr: 'pipe', timeout: 120_000,
|
||||
});
|
||||
const output = result.stdout.toString() + result.stderr.toString();
|
||||
expect(result.exitCode, output).toBe(0);
|
||||
expect(output).toContain(`${count} pass`);
|
||||
expect(output).toContain(`${36 - count} filtered out`);
|
||||
expect(output).toContain('0 fail');
|
||||
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
||||
}, 120_000);
|
||||
@@ -8,6 +8,7 @@ import { DOC_PATH, docsSnapshotArgv, fixtureDocs, gitAt, gitBlobId, repoSnapshot
|
||||
import { DOCS_CHECKPOINT_MARKER, DOCS_SEEDED_AUDIT_ID, docsActorCommand, docsActorHook, docsActorSeeded, installDocsActor, seedDocsFirstAttempt, type DocsActorState } from './helpers/docsync-fault-actor';
|
||||
import { docsActorVerdict } from './helpers/docsync-fault-eval';
|
||||
import { extractDocsDispatch, parseDocsCompletion } from './helpers/docsync-contract';
|
||||
import { docsFaultCallbackScript } from './helpers/docsync-fault-callbacks';
|
||||
import { docsNativeInterface, docsWriteFailures, observeDocsWrites } from './helpers/docsync-observer';
|
||||
|
||||
test.skipIf(process.platform !== 'linux')('actor CLI validates owned state before creating even transient locks', async () => {
|
||||
@@ -470,8 +471,6 @@ test('legacy verdict permits early blocking or one evidenced changed-input re-au
|
||||
|
||||
const CALLBACK_SPLITS = [
|
||||
['adapter results', 'consumes actual adapter results|accepts its remaining changed-input audit', 10],
|
||||
['legacy controls', '^ship-docsync-failure rejects ', 12],
|
||||
['fault controls', '^ship-docsync-(?!failure )[a-z-]+ rejects ', 14],
|
||||
] as const;
|
||||
|
||||
for (const [split, pattern, count] of CALLBACK_SPLITS) test(`registered fault callbacks execute actual transport and hook commands, consume results, and reject controls without model calls (${split})`, () => {
|
||||
@@ -479,382 +478,7 @@ for (const [split, pattern, count] of CALLBACK_SPLITS) test(`registered fault ca
|
||||
const root = path.resolve(import.meta.dir, '..');
|
||||
try {
|
||||
const script = path.join(dir, 'callbacks.test.ts');
|
||||
fs.writeFileSync(script, `
|
||||
import { expect, mock, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import type { SkillTestResult } from ${JSON.stringify(path.join(root, 'test/helpers/session-runner'))};
|
||||
const root = ${JSON.stringify(root)};
|
||||
const fixtureModule = path.join(root, 'test/helpers/docsync-fixture.ts');
|
||||
const observerModule = path.join(root, 'test/helpers/docsync-observer.ts');
|
||||
const fixtures = { ...await import(fixtureModule) };
|
||||
const observers = { ...await import(observerModule) };
|
||||
const { CAPTURE_MS, CAPTURE_LONG_MS } = await import(path.join(root, 'test/helpers/eval-budgets.ts'));
|
||||
const { parseDocsCompletion } = await import(path.join(root, 'test/helpers/docsync-contract.ts'));
|
||||
const { docsActorSeeded, DOCS_SEEDED_AUDIT_ID } = await import(path.join(root, 'test/helpers/docsync-fault-actor.ts'));
|
||||
const callbacks = new Map();
|
||||
let fixture, control = '', launches = 0, recorded, legacyReaudit = false;
|
||||
let returnedResult: SkillTestResult | undefined;
|
||||
let consumers: string[] = [];
|
||||
function expectResult(result: SkillTestResult) {
|
||||
expect(result).toBe(returnedResult);
|
||||
expect(result).toEqual({
|
||||
toolCalls: expect.any(Array), browseErrors: [], exitReason: 'success', duration: 0,
|
||||
output: 'Bounded callback replay complete', transcript: [], model: 'free-callback-replay',
|
||||
firstResponseMs: 0, maxInterTurnMs: 0,
|
||||
costEstimate: { inputChars: 0, outputChars: 0, estimatedTokens: 0, estimatedCost: 0, turnsUsed: 1 },
|
||||
});
|
||||
expect(result.toolCalls.length).toBeGreaterThan(0);
|
||||
}
|
||||
mock.module(fixtureModule, () => ({ ...fixtures,
|
||||
fixtureDocs(...args) { fixture = fixtures.fixtureDocs(...args); return fixture; },
|
||||
}));
|
||||
mock.module(observerModule, () => ({ ...observers,
|
||||
docsBoundedStageInterface(...args) { return observers.docsBoundedStageInterface(...args) + '\\nBOUNDED_CALLBACK_USED'; },
|
||||
}));
|
||||
mock.module(path.join(root, 'test/helpers/e2e-gate.ts'), () => ({ describeE2ETier: () => (_name, body) => body() }));
|
||||
mock.module(path.join(root, 'test/helpers/e2e-helpers.ts'), () => ({
|
||||
runId: 'free-docsync-faults', describeIfSelected: (_name, _names, body) => body(),
|
||||
testConcurrentIfSelected: (name, body, budget) => callbacks.set(name, { body, budget }),
|
||||
createEvalCollector: () => ({}), finalizeEvalCollector() {},
|
||||
logCost(_name, result) {
|
||||
expectResult(result);
|
||||
consumers.push('logCost');
|
||||
},
|
||||
recordE2E(_collector, _name, _label, result, verdict) {
|
||||
expectResult(result);
|
||||
expect(verdict).toEqual({ passed: control === '' });
|
||||
consumers.push('recordE2E');
|
||||
recorded = verdict;
|
||||
},
|
||||
}));
|
||||
mock.module(path.join(root, 'test/helpers/session-runner.ts'), () => ({ async runSkillTest(options) {
|
||||
launches++;
|
||||
const legacy = options.testName === 'ship-docsync-failure';
|
||||
const scenario = legacy ? 'legacy-completion' : options.testName.slice('ship-docsync-'.length);
|
||||
expect(options.maxTurns).toBe(legacy ? 30 : 24);
|
||||
expect(options.timeout).toBeGreaterThan((legacy ? CAPTURE_LONG_MS : CAPTURE_MS) - 20_000);
|
||||
expect(options.timeout).toBeLessThanOrEqual((legacy ? CAPTURE_LONG_MS : CAPTURE_MS) - 15_000);
|
||||
expect(options.tools).toEqual(['Bash', 'Read', 'Write', 'Edit', 'Glob', 'Grep']);
|
||||
expect(options.allowedTools).toEqual(options.tools);
|
||||
expect(options.prompt).toContain('BOUNDED_CALLBACK_USED');
|
||||
expect(options.prompt).toContain(fixture.invocation);
|
||||
expect(options.prompt).toContain('only you apply the loaded workflow');
|
||||
expect(options.prompt).toContain('do not probe invented ids');
|
||||
expect(options.prompt).toContain('Save each actual completion/rejected output once');
|
||||
expect(options.prompt).toContain('Private artifact filenames must end in .json, .md or .markdown');
|
||||
expect(options.prompt).toContain('.txt and .log filenames are not supported');
|
||||
expect(options.prompt).toContain('in a .md file without changing its bytes or reconstructing JSON');
|
||||
expect(options.prompt).toContain('the parent must not manufacture it');
|
||||
const repairable = ['recovery', 'late-result'].includes(scenario);
|
||||
const actor = path.join(root, 'test/helpers/docsync-fault-actor.ts');
|
||||
const stateFile = path.join(fixture.home, 'actor-state.json');
|
||||
expect(options.prompt.includes('bun ' + actor + ' repair ' + stateFile)).toBe(repairable);
|
||||
expect(options.prompt.includes('returns no result within the Collect deadline')).toBe(repairable);
|
||||
expect(options.prompt.includes('This launcher has no repair operation')).toBe(!repairable);
|
||||
expect(options.prompt.includes('bun ' + actor + ' inspect ' + stateFile)).toBe(true);
|
||||
expect(options.prompt).toContain('batched read-only observation');
|
||||
expect(options.prompt).toContain('Parent output handling');
|
||||
expect(options.prompt).toContain('as its own standalone Bash call with no redirect, pipe, wrapper, substitution or other composition');
|
||||
expect(options.prompt).toContain('Native Read, Glob and Grep stay available for file reads and are not Bash commands');
|
||||
expect(options.prompt).toContain('Never redirect a command into a file and never re-run a command merely to save its output');
|
||||
expect(options.prompt).toContain('Keep inspect observations in their original tool results in context and compare those returned values directly');
|
||||
expect(options.prompt).toContain('Do not transcribe or reserialize inspect JSON into duplicate snapshot files; prepare already saves the required candidate and prompt');
|
||||
expect(options.prompt).toContain('preserve each actual child completion/rejected output once in Markdown');
|
||||
expect(options.prompt).toContain('Persist each required checkpoint as one short appended journal entry');
|
||||
expect(options.prompt).toContain('use native Edit with old_string exactly ' + ${JSON.stringify(JSON.stringify(DOCS_CHECKPOINT_MARKER))});
|
||||
expect(options.prompt).toContain('new_string containing only the new entry followed by that same marker, and replace_all=false');
|
||||
expect(options.prompt).toContain('if missing or duplicated, stop rather than guessing an edit');
|
||||
expect(options.prompt).toContain('Preserve unrelated sections and every earlier entry byte-for-byte');
|
||||
expect(options.prompt).toContain("retaining each earlier attempt's id, count, evidence paths and outcome");
|
||||
expect(options.prompt).toContain('The latest stated value is current; do not recopy previous entries');
|
||||
expect(options.prompt).toContain('Reference saved candidate/prompt/completion artifacts instead of repeating their contents or prior narration');
|
||||
expect(options.prompt).toContain('Before dispatch, save the incremented attempt count, fresh audit id and candidate/prompt paths together');
|
||||
expect(options.prompt).toContain('Save the returned child handle before polling');
|
||||
expect(options.prompt).toContain('consolidation must never postpone the pre-launch count or child-settlement checks');
|
||||
expect(options.prompt).toContain('If recovery is authorized, save the intermediate result in one checkpoint before continuing it');
|
||||
expect(options.prompt).toContain('After the loaded Continue or recover / Blocked recovery steps reach a final outcome');
|
||||
expect(options.prompt).toContain('Append the finishing checkpoint and Write the complete report in the same response using separate native file calls');
|
||||
expect(options.prompt).toContain('Never omit the final report or final response, even when publication is blocked');
|
||||
expect(options.prompt).toContain('when it requires stopping, write the required invocation state and report, then stop rather than continuing later preparation to fill optional artifacts');
|
||||
expect(options.prompt).toContain('do not introduce any undeclared comparison or processing program to compare or transform observations');
|
||||
expect(options.prompt).toContain('Use only the transport commands above and the commands permitted by the Fixture observation interface below');
|
||||
expect(options.prompt).toContain('inspect takes no arguments beyond the state path shown above');
|
||||
expect(options.prompt).not.toContain('inspect call below');
|
||||
expect(options.prompt).not.toContain('inspect receipt');
|
||||
const calls = [];
|
||||
const config = JSON.parse(fs.readFileSync(path.join(fixture.env.CLAUDE_CONFIG_DIR, 'settings.json'), 'utf8'));
|
||||
const hook = config.hooks.PreToolUse.flatMap(entry => entry.hooks).find(entry => entry.command.includes('docsync-fault-actor.ts'));
|
||||
expect(hook).toBeDefined();
|
||||
const record = (tool, input, output) => calls.push({ tool, input, output });
|
||||
const pretool = (tool, input) => {
|
||||
const result = Bun.spawnSync(['bash', '-c', hook.command], { cwd: fixture.repo,
|
||||
stdin: Buffer.from(JSON.stringify({ hook_event_name: 'PreToolUse', cwd: fixture.repo, tool_name: tool, tool_input: input })),
|
||||
stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
|
||||
expect(result.exitCode, result.stderr.toString()).toBe(0);
|
||||
};
|
||||
const read = file_path => {
|
||||
pretool('Read', { file_path });
|
||||
const output = fs.readFileSync(file_path, 'utf8');
|
||||
record('Read', { file_path }, output);
|
||||
return output;
|
||||
};
|
||||
const write = (file_path, content) => {
|
||||
pretool('Write', { file_path, content });
|
||||
fs.writeFileSync(file_path, content);
|
||||
record('Write', { file_path, content }, 'File written');
|
||||
};
|
||||
const invoke = (action, args = {}) => {
|
||||
const argv = [actor, action, stateFile, ...Object.entries(args).map(([key, value]) => key + '=' + value)];
|
||||
const command = 'bun ' + argv.join(' ');
|
||||
pretool('Bash', { command });
|
||||
const result = Bun.spawnSync([process.execPath, ...argv], { cwd: fixture.repo, stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
|
||||
const text = result.stdout.toString().trimEnd();
|
||||
const output = (result.exitCode ? 'Exit code ' + result.exitCode + '\\n' : '') + text;
|
||||
record('Bash', { command }, output);
|
||||
return { text, output, exit: result.exitCode };
|
||||
};
|
||||
read(path.join(fixture.home, 'phase.md'));
|
||||
read(path.join(fixture.skills, 'ship/sections/documentation.md'));
|
||||
const initialRecord = read(fixture.invocation);
|
||||
expect(initialRecord).toContain('Attempts used: 0');
|
||||
expect(initialRecord).toContain('synthetic prior-stage state');
|
||||
const marker = ${JSON.stringify(DOCS_CHECKPOINT_MARKER)};
|
||||
expect(initialRecord.split(marker)).toHaveLength(2);
|
||||
const recordPrefix = initialRecord.split(marker)[0];
|
||||
let checkpointCount = 0;
|
||||
const seeded = docsActorSeeded(scenario);
|
||||
let attemptsUsed = seeded ? 1 : 0;
|
||||
let seedOutput = '';
|
||||
if (seeded) {
|
||||
expect(initialRecord).toContain('Attempts used: 1');
|
||||
read(path.join(fixture.home, 'candidate-' + DOCS_SEEDED_AUDIT_ID + '.json'));
|
||||
const saved = path.join(fixture.home, 'completion-' + DOCS_SEEDED_AUDIT_ID + '.md');
|
||||
seedOutput = control === 'skip-seeded-output' ? fs.readFileSync(saved, 'utf8') : read(saved);
|
||||
}
|
||||
const checkpoint = (details, finished = false) => {
|
||||
const before = fs.readFileSync(fixture.invocation, 'utf8');
|
||||
expect(before.split(marker)).toHaveLength(2);
|
||||
const entry = '### Checkpoint ' + (++checkpointCount) + '\\nAttempts used: ' + attemptsUsed + '.\\n'
|
||||
+ details + '\\nNext: ' + (finished ? 'Documentation gate finished; see ship-report.md. STOP before Step 15.' : 'Continue the actual documentation gate; STOP before Step 15.') + '\\n';
|
||||
const input = { file_path: fixture.invocation, old_string: marker, new_string: entry + marker, replace_all: false };
|
||||
pretool('Edit', input);
|
||||
const after = before.replace(input.old_string, input.new_string);
|
||||
fs.writeFileSync(fixture.invocation, after);
|
||||
record('Edit', input, 'File edited');
|
||||
expect(after.startsWith(recordPrefix)).toBe(true);
|
||||
expect(after.replace(input.new_string, marker)).toBe(before);
|
||||
expect(after.split(marker)).toHaveLength(2);
|
||||
expect(input.new_string).not.toContain(recordPrefix);
|
||||
};
|
||||
const inspectResult = invoke('inspect');
|
||||
const observed = JSON.parse(inspectResult.text);
|
||||
expect(observed.operation).toBe('inspect');
|
||||
expect(observed.files[fixtures.DOC_PATH].exists).toBe(true);
|
||||
expect(observed.pre_existing_dirty).toContain(String.fromCharCode(0));
|
||||
expect(inspectResult.text).not.toContain(String.fromCharCode(0));
|
||||
expect(calls.at(-1).output).toBe(inspectResult.text);
|
||||
if (control === 'tampered-inspect') calls[calls.length - 1].output = inspectResult.text.replace('"operation":"inspect"', '"operation":"tampered"');
|
||||
const prepare = id => {
|
||||
const result = invoke('prepare', { audit_id: id });
|
||||
expect(result.exit).toBe(0);
|
||||
const prepared = JSON.parse(result.text);
|
||||
read(prepared.candidate);
|
||||
read(prepared.prompt);
|
||||
return prepared;
|
||||
};
|
||||
const dispatch = prepared => {
|
||||
attemptsUsed++;
|
||||
checkpoint('Audit: ' + prepared.audit_id + '; candidate: ' + prepared.candidate + '; prompt: ' + prepared.prompt);
|
||||
const result = invoke('dispatch', { audit_id: prepared.audit_id, candidate: prepared.candidate, prompt: prepared.prompt, run_in_background: 'false' });
|
||||
const saved = calls.at(-2);
|
||||
expect(saved.tool).toBe('Edit');
|
||||
expect(saved.input.file_path).toBe(fixture.invocation);
|
||||
expect(saved.input.old_string).toBe(marker);
|
||||
expect(saved.input.new_string).toContain('Attempts used: ' + attemptsUsed);
|
||||
expect(saved.input.new_string).toContain(prepared.audit_id);
|
||||
expect(saved.input.new_string).toContain(prepared.candidate);
|
||||
expect(saved.input.new_string).toContain(prepared.prompt);
|
||||
return result;
|
||||
};
|
||||
let output = '', accepted = null, first;
|
||||
if (scenario !== 'missing-asset') {
|
||||
first = seeded ? { audit_id: DOCS_SEEDED_AUDIT_ID, candidate: path.join(fixture.home, 'candidate-' + DOCS_SEEDED_AUDIT_ID + '.json'),
|
||||
prompt: path.join(fixture.home, 'prompt-' + DOCS_SEEDED_AUDIT_ID + '.md') } : prepare('ship-docs-20260926-a1');
|
||||
const initial = seeded ? { text: seedOutput, output: seedOutput } : dispatch(first);
|
||||
output = initial.text;
|
||||
if (scenario === 'missing-marker') {
|
||||
expect(initial.output).toBe('SESSION_KIND: interactive\\n{"schema_version":1,"audit_id":"' + first.audit_id + '","status":"blocked","files_updated":[],"files_reviewed":[],"documentation_section":"blocked — fixture child audit ' + first.audit_id + '; Missing spawned marker.","blockers":["Missing spawned marker"],"decisions":[]}');
|
||||
}
|
||||
if (scenario === 'launch-failure') {
|
||||
expect(initial.text).toBe('Child launch failed: injected unavailable worker. No child was started.');
|
||||
expect(seeded ? initialRecord.includes('dispatch exit code 23') : initial.output.startsWith('Exit code 23\\n')).toBe(true);
|
||||
const attempts = JSON.parse(fs.readFileSync(stateFile, 'utf8')).tasks;
|
||||
expect(attempts).toHaveLength(1);
|
||||
expect(attempts[0].id).toBeNull();
|
||||
expect(attempts[0].candidate).toBe(fs.readFileSync(first.candidate, 'utf8'));
|
||||
}
|
||||
if (['timeout-unsettled', 'late-result'].includes(scenario)) {
|
||||
expect(initial.output).toBe('{"task_id":"fixture-child-1","status":"running","elapsed_ms":0,"virtual_clock":true}');
|
||||
const task_id = JSON.parse(output).task_id;
|
||||
if (seeded) expect(initialRecord).toContain('Returned child handle: ' + task_id + '.');
|
||||
else checkpoint('Running child handle: ' + task_id);
|
||||
expect(invoke('status', { task_id }).output).toBe('{"task_id":"fixture-child-1","status":"running","settled":false,"elapsed_ms":600001,"virtual_clock":true}');
|
||||
const stop = invoke('stop', { task_id });
|
||||
expect(JSON.parse(stop.text).settled).toBe(scenario === 'late-result');
|
||||
if (control !== 'skip-post-stop-status') {
|
||||
const status = invoke('status', { task_id });
|
||||
if (scenario === 'timeout-unsettled') expect(status.output).toBe('{"task_id":"fixture-child-1","status":"running","settled":false,"elapsed_ms":900002,"virtual_clock":true}');
|
||||
}
|
||||
}
|
||||
if (repairable) expect(invoke('repair').exit).toBe(0);
|
||||
if (repairable || scenario.startsWith('stale-') || legacy && legacyReaudit) {
|
||||
read(path.join(fixture.repo, 'app.ts'));
|
||||
const second = prepare('ship-docs-20260926-a2');
|
||||
if (control === 'stale-candidate' || control === 'legacy-stale') {
|
||||
const old = JSON.parse(fs.readFileSync(first.candidate, 'utf8'));
|
||||
old.audit_id = second.audit_id;
|
||||
write(second.candidate, JSON.stringify(old));
|
||||
}
|
||||
output = dispatch(second).text;
|
||||
if (scenario === 'late-result') expect(() => parseDocsCompletion(output, second.audit_id)).toThrow('completion identity');
|
||||
else if (legacy) expect(() => parseDocsCompletion(output, second.audit_id)).toThrow('completion fields');
|
||||
else accepted = parseDocsCompletion(output, second.audit_id);
|
||||
if (control === 'legacy-third') {
|
||||
const third = prepare('ship-docs-20260926-a3');
|
||||
output = dispatch(third).text;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
expect(fs.existsSync(path.join(fixture.skills, 'document-release/sections/audit-scope.md'))).toBe(false);
|
||||
}
|
||||
if (control === 'invalid-repair') expect(invoke('repair').output).toBe('Exit code 24\\nError: repair not available');
|
||||
if (control === 'invented-handle') expect(invoke('status', { task_id: 'ship-docs-20260926-a1' }).output).toBe('Exit code 24\\nError: unknown fixture child');
|
||||
if (control === 'restore-partial') write(path.join(fixture.repo, fixtures.DOC_PATH), Buffer.from(fixture.before.contents[fixtures.DOC_PATH], 'base64').toString());
|
||||
if (control === 'user-content') write(path.join(fixture.repo, 'personal-note.txt'), 'clobbered');
|
||||
if (control === 'private-state') read(stateFile);
|
||||
if (control === 'git-mutation') record('Bash', { command: 'git add ' + fixtures.DOC_PATH }, '');
|
||||
const runShell = (command) => {
|
||||
pretool('Bash', { command });
|
||||
const r = Bun.spawnSync(['bash', '-c', command], { cwd: fixture.repo, stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
|
||||
record('Bash', { command }, (r.exitCode ? 'Exit code ' + r.exitCode + '\\n' : '') + r.stdout.toString().trimEnd());
|
||||
return r.exitCode;
|
||||
};
|
||||
if (control === 'redirect-transport') {
|
||||
const snapshot = path.join(fixture.home, 'snapshot.json');
|
||||
expect(runShell('bun ' + actor + ' inspect ' + stateFile + ' > ' + snapshot)).toBe(0);
|
||||
expect(calls.at(-1).output).toBe('');
|
||||
expect(JSON.parse(fs.readFileSync(snapshot, 'utf8')).head).toBe(observed.head);
|
||||
}
|
||||
if (control === 'compare-program') expect(runShell('diff ' + path.join(fixture.repo, fixtures.DOC_PATH) + ' ' + path.join(fixture.repo, fixtures.DOC_PATH))).toBe(0);
|
||||
if (control === 'mutate-index') {
|
||||
const staged = Bun.spawnSync(['git', 'add', fixtures.DOC_PATH], { cwd: fixture.repo, stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
|
||||
expect(staged.exitCode).toBe(0);
|
||||
}
|
||||
if (['legacy-unchanged', 'legacy-unsettled', 'legacy-fake-repair'].includes(control)) {
|
||||
const state = JSON.parse(fs.readFileSync(stateFile, 'utf8'));
|
||||
if (control === 'legacy-unchanged') {
|
||||
state.tasks[1].observed_candidate.hashes = { ...state.tasks[0].observed_candidate.hashes };
|
||||
state.tasks[1].candidate = JSON.stringify(state.tasks[1].observed_candidate);
|
||||
}
|
||||
if (control === 'legacy-unsettled') state.tasks[0].settled = false;
|
||||
if (control === 'legacy-fake-repair') { state.repaired = true; state.events.push({ action: 'repair' }); }
|
||||
fs.writeFileSync(stateFile, JSON.stringify(state));
|
||||
}
|
||||
const outside = path.join(path.dirname(import.meta.path), 'outside.md');
|
||||
if (control === 'outside-artifact') record('Write', { file_path: outside, content: output }, 'attempted write');
|
||||
if (control === 'protected-artifact') record('Write', { file_path: path.join(fixture.skills, 'private.md'), content: output }, 'attempted write');
|
||||
if (control === 'script-artifact') record('Write', { file_path: actor, content: output }, 'attempted write');
|
||||
if (control === 'symlink-artifact') {
|
||||
fs.writeFileSync(outside, 'outside fixture control');
|
||||
const link = path.join(fixture.home, 'linked.md');
|
||||
fs.symlinkSync(outside, link);
|
||||
record('Write', { file_path: link, content: output }, 'attempted write');
|
||||
}
|
||||
write(path.join(fixture.home, control === 'raw-text-artifact' ? 'completion.txt' : 'completion.md'), output);
|
||||
expect(fs.readFileSync(path.join(fixture.home, control === 'raw-text-artifact' ? 'completion.txt' : 'completion.md'), 'utf8')).toBe(output);
|
||||
if (control === '') expect(fs.readdirSync(fixture.home).filter(name => /inspect|snapshot/.test(name))).toEqual([]);
|
||||
const report = path.join(fixture.home, 'ship-report.md');
|
||||
const finalReport = control === 'false-current' ? 'Documentation: current' : accepted
|
||||
? 'Documentation: ' + accepted.status + '\\n' + accepted.documentation_section
|
||||
: 'Documentation: blocked\\n' + (legacy ? 'Invalid legacy completion; partial edit retained: ' + fixtures.DOC_PATH : 'Actual child result did not clear the gate') + '\\nEvidence: completion.md';
|
||||
checkpoint(finalReport, true);
|
||||
if (control !== 'missing-report') write(report, finalReport);
|
||||
expect(fs.readFileSync(fixture.invocation, 'utf8')).toContain(finalReport);
|
||||
expect(fs.readFileSync(fixture.invocation, 'utf8')).toContain('Attempts used: ' + attemptsUsed);
|
||||
if (attemptsUsed > 1) expect(fs.readFileSync(fixture.invocation, 'utf8')).toContain(first.audit_id);
|
||||
if (control === '') {
|
||||
expect(calls.slice(-2).map(call => [call.tool, call.input.file_path])).toEqual([
|
||||
['Edit', fixture.invocation], ['Write', report],
|
||||
]);
|
||||
expect(fs.readFileSync(report, 'utf8')).toBe(finalReport);
|
||||
}
|
||||
if (accepted) expect(invoke('publish', { audit_id: accepted.audit_id, report }).exit).toBe(0);
|
||||
if (control === 'invalid-publication') expect(invoke('publish', { audit_id: 'ship-docs-20260926-a1', report }).exit).toBe(24);
|
||||
returnedResult = { exitReason: 'success', output: 'Bounded callback replay complete', toolCalls: calls, transcript: [],
|
||||
browseErrors: [], duration: 0, model: 'free-callback-replay', firstResponseMs: 0, maxInterTurnMs: 0,
|
||||
costEstimate: { inputChars: 0, outputChars: 0, estimatedTokens: 0, estimatedCost: 0, turnsUsed: 1 } } satisfies SkillTestResult;
|
||||
return returnedResult;
|
||||
} }));
|
||||
await import(path.join(root, 'test/skill-e2e-ship-docsync.test.ts'));
|
||||
expect(callbacks.size).toBe(12);
|
||||
const names = ['ship-docsync-failure', 'ship-docsync-missing-marker', 'ship-docsync-missing-asset',
|
||||
'ship-docsync-launch-failure', 'ship-docsync-timeout-unsettled', 'ship-docsync-late-result',
|
||||
'ship-docsync-stale-before', 'ship-docsync-stale-after', 'ship-docsync-recovery'];
|
||||
for (const name of names) test(name + ' consumes actual adapter results', async () => {
|
||||
control = '';
|
||||
legacyReaudit = false;
|
||||
recorded = undefined;
|
||||
returnedResult = undefined;
|
||||
consumers = [];
|
||||
const before = launches;
|
||||
expect(callbacks.get(name).budget).toBe(name === 'ship-docsync-failure' ? CAPTURE_LONG_MS : CAPTURE_MS);
|
||||
await callbacks.get(name).body();
|
||||
expect(launches).toBe(before + 1);
|
||||
expect(recorded).toEqual({ passed: true });
|
||||
expect(consumers).toEqual(['logCost', 'recordE2E']);
|
||||
expect(fs.existsSync(fixture.home)).toBe(false);
|
||||
});
|
||||
test('ship-docsync-failure accepts its remaining changed-input audit and preserves raw output in Markdown', async () => {
|
||||
control = '';
|
||||
legacyReaudit = true;
|
||||
recorded = undefined;
|
||||
returnedResult = undefined;
|
||||
consumers = [];
|
||||
await callbacks.get('ship-docsync-failure').body();
|
||||
expect(recorded).toEqual({ passed: true });
|
||||
expect(consumers).toEqual(['logCost', 'recordE2E']);
|
||||
expect(fs.existsSync(fixture.home)).toBe(false);
|
||||
});
|
||||
for (const [name, mutation] of [
|
||||
['ship-docsync-failure', 'false-current'], ['ship-docsync-failure', 'invalid-publication'],
|
||||
['ship-docsync-failure', 'restore-partial'], ['ship-docsync-failure', 'user-content'],
|
||||
['ship-docsync-failure', 'private-state'], ['ship-docsync-failure', 'git-mutation'],
|
||||
['ship-docsync-failure', 'mutate-index'], ['ship-docsync-missing-marker', 'invalid-repair'],
|
||||
['ship-docsync-missing-marker', 'redirect-transport'], ['ship-docsync-missing-marker', 'compare-program'],
|
||||
['ship-docsync-launch-failure', 'invented-handle'], ['ship-docsync-timeout-unsettled', 'skip-post-stop-status'],
|
||||
['ship-docsync-late-result', 'missing-report'],
|
||||
['ship-docsync-stale-before', 'stale-candidate'],
|
||||
['ship-docsync-recovery', 'skip-seeded-output'],
|
||||
['ship-docsync-failure', 'legacy-unchanged'], ['ship-docsync-failure', 'legacy-unsettled'],
|
||||
['ship-docsync-failure', 'legacy-stale'], ['ship-docsync-failure', 'legacy-third'],
|
||||
['ship-docsync-failure', 'legacy-fake-repair'],
|
||||
['ship-docsync-missing-marker', 'tampered-inspect'],
|
||||
['ship-docsync-missing-marker', 'raw-text-artifact'], ['ship-docsync-missing-marker', 'outside-artifact'],
|
||||
['ship-docsync-missing-marker', 'protected-artifact'], ['ship-docsync-missing-marker', 'symlink-artifact'],
|
||||
['ship-docsync-missing-marker', 'script-artifact'],
|
||||
]) test(name + ' rejects ' + mutation, async () => {
|
||||
control = mutation;
|
||||
legacyReaudit = name === 'ship-docsync-failure';
|
||||
recorded = undefined;
|
||||
returnedResult = undefined;
|
||||
consumers = [];
|
||||
await expect(callbacks.get(name).body()).rejects.toThrow();
|
||||
expect(recorded).toEqual({ passed: false });
|
||||
expect(consumers).toEqual(['logCost', 'recordE2E']);
|
||||
expect(fs.existsSync(fixture.home)).toBe(false);
|
||||
});
|
||||
`);
|
||||
fs.writeFileSync(script, docsFaultCallbackScript(root));
|
||||
const home = path.join(dir, 'home');
|
||||
fs.mkdirSync(home);
|
||||
const result = Bun.spawnSync([process.execPath, 'test', script, '--test-name-pattern', pattern], {
|
||||
|
||||
@@ -0,0 +1,373 @@
|
||||
// Split from test/gstack-doctor.test.ts: the `gstack-doctor --check` verdict rows, trailer and JSON.
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { useDoctorCleanup, REPO, BROWSE_BIN, EXE, write, script, bashPath, probeCalls, makeFixture, doctor, type Fixture } from './helpers/doctor-fixture';
|
||||
|
||||
useDoctorCleanup();
|
||||
|
||||
// A1: `--check` is the one-line verdict a parent agent greps. Rows are
|
||||
// `PASS | FAIL | SKIP <id>` from lib/doctor-components.ts; the trailer is
|
||||
// `gstack: ok <revision> for=<what>` (exit 0) or `gstack: fail <ids>` (exit 1).
|
||||
// Pinned on tokens, ids, exit codes and the JSON shape, not prose.
|
||||
describe('gstack-doctor --check', () => {
|
||||
const VERSION = fs.readFileSync(path.join(REPO, 'VERSION'), 'utf8').trim();
|
||||
const row = (f: Fixture, args: string[], extra: Record<string, string> = {}) => {
|
||||
const r = doctor(f, ['--check', ...args], extra);
|
||||
const lines = r.out.split('\n');
|
||||
const rows = Object.fromEntries(lines.filter(l => /^(PASS|FAIL|SKIP|WARN) /.test(l)).map(l => {
|
||||
const m = l.match(/^(PASS|FAIL|SKIP|WARN) ([a-z-]+)(?:\s(.*))?$/)!;
|
||||
return [m[2], { status: m[1], rest: m[3] ?? '' }];
|
||||
}));
|
||||
const trailer = lines.filter(l => l.startsWith('gstack: ')).at(-1) ?? '';
|
||||
const required = lines.find(l => l.startsWith('required: '))?.slice(10).split(' ') ?? [];
|
||||
return { status: r.status, out: r.out, rows, trailer, required, trailers: lines.filter(l => l.startsWith('gstack: ')).length };
|
||||
};
|
||||
/** Register a Codex install from this checkout and render a review skill, with or without the Astra patch. */
|
||||
const installCodex = (f: Fixture, patch = true) => {
|
||||
const dest = path.join(f.home, '.codex/skills');
|
||||
fs.appendFileSync(path.join(f.state, 'installs.tsv'),
|
||||
['codex', 'global', '-', dest, path.join(dest, 'gstack'), f.root, VERSION, 'true', 'committed', '2026-10-07T00:00:00Z'].join('\t') + '\n');
|
||||
fs.mkdirSync(path.join(dest, 'gstack'), { recursive: true });
|
||||
write(path.join(dest, 'gstack-review/SKILL.md'), `---\nname: gstack-review\n---\n# Review\n${patch ? '\n## Model-Specific Behavioral Patch (gpt-6-astra)\n' : ''}`);
|
||||
return dest;
|
||||
};
|
||||
const installPlaywrightStub = (f: Fixture, launches: boolean) => write(path.join(f.root, 'node_modules/playwright/index.js'),
|
||||
launches
|
||||
? 'module.exports.chromium = { launch: async () => ({ version: () => "141.0.1", close: async () => {}, newPage: async () => ({ setContent: async () => {}, title: async () => "gstack smoke test" }) }) };'
|
||||
: 'module.exports.chromium = { launch: async () => { throw new Error("browserType.launch: Executable doesn\'t exist"); } };');
|
||||
|
||||
test('healthy Claude + Codex installs: every required row PASS, exactly one trailer, exit 0, no paid probe', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
const r = row(f, []);
|
||||
expect(r.status, r.out).toBe(0);
|
||||
expect(r.required).toEqual(['claude', 'codex', 'runtime', 'pins', 'state-root', 'privacy', 'cores', 'revision', 'floor', 'wrapper']);
|
||||
for (const id of r.required.filter(x => x !== 'pins' && x !== 'floor' && x !== 'wrapper')) expect(r.rows[id]?.status, `${id}\n${r.out}`).toBe('PASS');
|
||||
// The work dir is not a git repository, so there is no project to read pins or a floor from: SKIP with the reason, never silent.
|
||||
expect(r.rows.pins).toEqual({ status: 'SKIP', rest: expect.stringContaining('no project') });
|
||||
expect(r.rows.floor).toEqual({ status: 'SKIP', rest: expect.stringContaining('no project to read .gstack/ship-policy.json from') });
|
||||
// No ~/.capy/drive skill copy and no active wrapper: not a Capy machine.
|
||||
expect(r.rows.wrapper).toEqual({ status: 'SKIP', rest: expect.stringContaining('not a Capy machine') });
|
||||
expect(r.rows.patch.status).toBe('PASS');
|
||||
expect(r.rows['codex-cli'].status).toBe('PASS');
|
||||
expect(r.rows.browser).toEqual({ status: 'SKIP', rest: '(lazy; gstack-browser-ensure installs on first use)' });
|
||||
expect(r.rows.cso.status).toBe('SKIP');
|
||||
expect(r.trailer).toBe(`gstack: ok ${VERSION} for=installed-hosts:claude,codex`);
|
||||
expect(r.trailers).toBe(1);
|
||||
expect(r.rows.runtime.rest).toContain('floor 1.3.3, supported minimum 1.4.2');
|
||||
expect(r.rows.privacy.rest).toBe('telemetry=off artifacts_sync=off codex_reviews=enabled update_check=true');
|
||||
expect(r.rows['state-root'].rest).toContain('durable=yes');
|
||||
expect(probeCalls(f)).not.toContain('probe-model');
|
||||
});
|
||||
|
||||
// Value: protects=the --check state-root row names the variable that selected the root, after earlier rows read config;
|
||||
// fails_when=an in-process config read reselects the root from the doctor's own GSTACK_STATE_ROOT;
|
||||
// why_new=every other fixture sets GSTACK_STATE_ROOT itself, so a wrong "selected by" still reads GSTACK_STATE_ROOT; seam=none;
|
||||
// no_claim=CLAUDE_PLUGIN_DATA and default selection (GSTACK_HOME stands in for every selector other than GSTACK_STATE_ROOT)
|
||||
test('the state-root row names GSTACK_HOME when GSTACK_HOME selected the root, in text and JSON', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
const byHome = { GSTACK_STATE_ROOT: '', GSTACK_HOME: f.state };
|
||||
const r = row(f, [], byHome);
|
||||
expect(r.rows['state-root'].rest, r.out).toContain('(selected by GSTACK_HOME;');
|
||||
const json = JSON.parse(doctor(f, ['--json'], byHome).out);
|
||||
expect(json.rows.find((x: { id: string }) => x.id === 'state-root').detail).toContain('(selected by GSTACK_HOME;');
|
||||
});
|
||||
|
||||
test('--for autoplan: healthy Capy machine with Claude subagents as the outside voice and no Codex CLI passes', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
fs.rmSync(path.join(f.stub, 'codex'));
|
||||
const r = row(f, ['--for', 'autoplan']);
|
||||
expect(r.status, r.out).toBe(0);
|
||||
expect(r.required).toEqual(['claude', 'codex', 'patch', 'runtime', 'pins', 'state-root', 'privacy', 'cores', 'revision', 'floor', 'wrapper']);
|
||||
expect(r.rows.patch).toEqual({ status: 'PASS', rest: 'gpt-6-astra (gstack-review/SKILL.md)' });
|
||||
expect(r.rows['codex-cli'].status).toBe('SKIP');
|
||||
expect(r.rows['codex-cli'].rest).toContain('optional');
|
||||
expect(r.trailer).toBe(`gstack: ok ${VERSION} for=autoplan`);
|
||||
// The same machine with a stale Codex render fails the patch row.
|
||||
installCodex(f, false);
|
||||
const noPatch = row(f, ['--for', 'autoplan']);
|
||||
expect(noPatch.status).toBe(1);
|
||||
expect(noPatch.rows.patch.status).toBe('FAIL');
|
||||
expect(noPatch.rows.patch.rest).toContain('fix: ');
|
||||
expect(noPatch.rows.patch.rest).toContain('(COMPONENT_MISSING; ');
|
||||
expect(noPatch.rows.patch.rest).toContain('--host codex --model');
|
||||
expect(noPatch.trailer).toBe('gstack: fail patch');
|
||||
});
|
||||
|
||||
test('--for autoplan: a hoisted Codex render carries the patch in its shared sections/preamble.md', () => {
|
||||
const f = makeFixture();
|
||||
const dest = installCodex(f, false);
|
||||
write(path.join(dest, 'gstack-review/sections/preamble.md'), '# gstack shared preamble 0123456789ab\n\n## Model-Specific Behavioral Patch (gpt-6-astra)\n');
|
||||
const r = row(f, ['--for', 'autoplan']);
|
||||
expect(r.rows.patch, r.out).toEqual({ status: 'PASS', rest: 'gpt-6-astra (gstack-review/sections/preamble.md)' });
|
||||
});
|
||||
|
||||
test('an empty installed-host set is never ok: claude is required and FAILs', () => {
|
||||
const f = makeFixture();
|
||||
write(path.join(f.state, 'installs.tsv'), '');
|
||||
const r = row(f, []);
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.required).toContain('claude');
|
||||
expect(r.rows.claude.status).toBe('FAIL');
|
||||
expect(r.rows.claude.rest).toContain(`fix: cd ${bashPath(f.root)} && ./setup --host claude --no-prefix`);
|
||||
expect(r.trailer).toBe('gstack: fail claude');
|
||||
expect(JSON.parse(doctor(f, ['--json']).out).for).toBe('installed-hosts:none(claude required)');
|
||||
});
|
||||
|
||||
test('wrong host: an install registered from another checkout does not count; --require names what is missing', () => {
|
||||
const f = makeFixture();
|
||||
const other = path.join(f.base, 'other');
|
||||
write(path.join(f.state, 'installs.tsv'), ['codex', 'global', '-', path.join(f.home, '.codex/skills'), other, other, VERSION, 'false', 'committed', 'x'].join('\t') + '\n');
|
||||
const r = row(f, ['--require', 'codex,patch']);
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.rows.codex.status).toBe('FAIL');
|
||||
expect(r.rows.patch.status).toBe('FAIL');
|
||||
expect(r.rows.claude.status).toBe('SKIP');
|
||||
expect(r.trailer).toBe('gstack: fail codex,patch');
|
||||
expect(JSON.parse(doctor(f, ['--json', '--require', 'codex,patch']).out).for).toBe('codex,patch');
|
||||
});
|
||||
|
||||
test('missing authentication: --for codex needs the CLI; absent, unauthenticated and present are told apart, --live probes once', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
const unauthed = row(f, ['--for', 'codex'], { STUB_AUTH_FAIL: '1' });
|
||||
expect(unauthed.status).toBe(1);
|
||||
expect(unauthed.rows['codex-cli'].status).toBe('FAIL');
|
||||
expect(unauthed.rows['codex-cli'].rest).toContain('not authenticated');
|
||||
expect(unauthed.rows['codex-cli'].rest).toContain('codex login --with-api-key');
|
||||
expect(unauthed.trailer).toBe('gstack: fail codex-cli');
|
||||
|
||||
const authed = row(f, ['--for', 'codex']);
|
||||
expect(authed.status, authed.out).toBe(0);
|
||||
expect(authed.rows['codex-cli'].rest).toContain('paid probe not run; add --live');
|
||||
expect(probeCalls(f)).not.toContain('probe-model');
|
||||
|
||||
const live = row(f, ['--for', 'codex', '--live']);
|
||||
expect(live.status, live.out).toBe(0);
|
||||
expect(live.rows['codex-cli'].rest).toContain('live probe ok');
|
||||
expect(probeCalls(f).match(/probe-model exec/g)?.length).toBe(1);
|
||||
|
||||
fs.rmSync(path.join(f.stub, 'codex'));
|
||||
const absent = row(f, ['--for', 'codex']);
|
||||
expect(absent.rows['codex-cli'].status).toBe('FAIL');
|
||||
expect(absent.rows['codex-cli'].rest).toContain('npm install -g @openai/codex');
|
||||
});
|
||||
|
||||
test('runtime mismatch: the supported minimum (1.4.2) and the floor (1.3.3) both FAIL in --check', () => {
|
||||
const f = makeFixture();
|
||||
const untested = row(f, [], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(untested.status).toBe(1);
|
||||
expect(untested.rows.runtime.status).toBe('FAIL');
|
||||
expect(untested.rows.runtime.rest).toContain('below the supported minimum 1.4.2');
|
||||
expect(untested.rows.runtime.rest).toContain('(RUNTIME_BELOW_MINIMUM; ');
|
||||
expect(untested.trailer).toBe('gstack: fail runtime');
|
||||
const old = row(f, [], { STUB_BUN_VERSION: '1.3.2' });
|
||||
expect(old.rows.runtime.rest).toContain('below the security floor 1.3.3');
|
||||
expect(old.trailer).toBe('gstack: fail runtime');
|
||||
});
|
||||
|
||||
test('bun removed from PATH: the doctor still reports, runtime FAILs, pins SKIPs with a reason, one trailer', () => {
|
||||
const f = makeFixture();
|
||||
fs.rmSync(path.join(f.stub, 'bun'));
|
||||
const r = row(f, []);
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.rows.runtime.status).toBe('FAIL');
|
||||
expect(r.rows.runtime.rest).toContain('bun not found on PATH');
|
||||
expect(r.rows.pins).toEqual({ status: 'SKIP', rest: expect.stringContaining('no bun to evaluate the project pins') });
|
||||
expect(r.rows.claude.status).toBe('PASS');
|
||||
expect(r.trailer).toBe('gstack: fail runtime');
|
||||
expect(r.trailers).toBe(1);
|
||||
});
|
||||
|
||||
test('project pins: --project reads the target repository, a range mismatch FAILs with its source, a match PASSes', () => {
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
write(path.join(project, 'package.json'), '{\n "engines": {\n "bun": ">=1.4.2"\n }\n}\n');
|
||||
const bad = row(f, ['--project', project], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(bad.rows.pins.status).toBe('FAIL');
|
||||
expect(bad.rows.pins.rest).toContain('bun 1.3.14 outside engines.bun >=1.4.2 (package.json:3)');
|
||||
expect(bad.rows.pins.rest).toContain('(PROJECT_PIN_MISMATCH; ');
|
||||
expect(bad.trailer).toBe('gstack: fail runtime,pins');
|
||||
const good = row(f, ['--project', project]);
|
||||
expect(good.rows.pins).toEqual({ status: 'PASS', rest: `${project}: bun >=1.4.2 (engines.bun, package.json:3)` });
|
||||
const none = row(f, ['--project', f.work]);
|
||||
expect(none.rows.pins.status).toBe('PASS');
|
||||
expect(none.rows.pins.rest).toContain('pins no runtime');
|
||||
const missing = row(f, ['--project', path.join(f.base, 'nope')]);
|
||||
expect(missing.rows.pins.status).toBe('SKIP');
|
||||
});
|
||||
|
||||
test('project pins on Capy: the PROJECT_PIN_MISMATCH fix is the exact bootstrapper command, which installs a verified pinned Bun', () => {
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
write(path.join(project, 'package.json'), '{\n "engines": {\n "bun": ">=1.4.2"\n }\n}\n');
|
||||
const wrapper = '/drive/skills/gstack/scripts/install.sh';
|
||||
const capy = row(f, ['--project', project], { STUB_BUN_VERSION: '1.3.14', GSTACK_CAPY_WRAPPER_PATH: wrapper });
|
||||
expect(capy.rows.pins.status).toBe('FAIL');
|
||||
expect(capy.rows.pins.rest).toContain(`fix: bash ${wrapper} (installs the project's pinned Bun when it is a verified version: 1.4.2 1.4.3 1.4.4; otherwise it names the conflict), or change the pin in ${project}`);
|
||||
expect(capy.rows.pins.rest).toContain('(PROJECT_PIN_MISMATCH; ');
|
||||
const forSkill = row(f, ['--project', project, '--for', 'review'], { STUB_BUN_VERSION: '1.3.14', GSTACK_CAPY_WRAPPER_PATH: wrapper });
|
||||
expect(forSkill.rows.pins.rest).toContain(`fix: bash ${wrapper} --for review (installs`);
|
||||
const plain = row(f, ['--project', project], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(plain.rows.pins.rest).toContain('fix: install the pinned version for this platform');
|
||||
expect(plain.rows.pins.rest).not.toContain(wrapper);
|
||||
});
|
||||
|
||||
test('project pins: a Node-only pin mismatch is a WARN (the trailer stays ok) that names the node it read and a fix that installs the pinned Node', () => {
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
write(path.join(project, '.github/workflows/native-locks.yml'), 'jobs:\n locks:\n steps:\n - uses: actions/setup-node@v4\n with:\n node-version: 24.18.0\n');
|
||||
script(path.join(f.stub, 'node'), ['echo v24.21.0']);
|
||||
const wrapper = '/drive/skills/gstack/scripts/install.sh';
|
||||
const capy = row(f, ['--project', project, '--for', 'health'], { GSTACK_CAPY_WRAPPER_PATH: wrapper });
|
||||
expect(capy.rows.pins.status).toBe('WARN');
|
||||
expect(capy.rows.pins.rest).toContain(`node 24.21.0 outside CI 24.18.0 (.github/workflows/native-locks.yml:6); node read from ${bashPath(f.stub)}/node (node pin only; bun pins pass)`);
|
||||
expect(capy.rows.pins.rest).toContain(`fix: bash ${wrapper} --for health (installs the project's pinned Node 24.18.0 into gstack's runtime store and launches it through the GSTACK_LAUNCH PATH), or change the pin in ${project}`);
|
||||
expect(capy.rows.pins.rest).toContain('(PROJECT_NODE_PIN_UNMET; ');
|
||||
expect(capy.trailer).toBe(`gstack: ok ${VERSION} for=health`);
|
||||
const plain = row(f, ['--project', project, '--for', 'health']);
|
||||
expect(plain.rows.pins.rest).toContain(`fix: nvm install 24.18.0 and put its bin directory first on PATH`);
|
||||
// A Bun pin that also fails keeps the FAIL and its code: only a Node-only gap is advisory.
|
||||
write(path.join(project, 'package.json'), '{\n "engines": {\n "bun": ">=1.4.2"\n }\n}\n');
|
||||
const both = row(f, ['--project', project, '--for', 'health'], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(both.rows.pins.status).toBe('FAIL');
|
||||
expect(both.rows.pins.rest).toContain('(PROJECT_PIN_MISMATCH; ');
|
||||
fs.rmSync(path.join(project, 'package.json'));
|
||||
script(path.join(f.stub, 'node'), ['echo v24.18.0']);
|
||||
expect(row(f, ['--project', project, '--for', 'health']).rows.pins.status).toBe('PASS');
|
||||
});
|
||||
|
||||
test('floor: min_gstack_version in the project\'s .gstack/ship-policy.json PASSes at or below the installed version, WARNs above it with the upgrade as the fix, and SKIPs when absent or null', () => {
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
fs.mkdirSync(project, { recursive: true });
|
||||
const none = row(f, ['--project', project]);
|
||||
expect(none.rows.floor).toEqual({ status: 'SKIP', rest: `(${project} declares none (.gstack/ship-policy.json absent; set min_gstack_version there to require a gstack version))` });
|
||||
write(path.join(project, '.gstack/ship-policy.json'), '{\n "bump": "patch",\n "min_gstack_version": null\n}\n');
|
||||
expect(row(f, ['--project', project]).rows.floor).toEqual({ status: 'SKIP', rest: `(${project}/.gstack/ship-policy.json sets no min_gstack_version (null or absent))` });
|
||||
// A present value that is not a dotted version is named as such, never read as "absent"; the shell never evaluates it.
|
||||
const marker = path.join(project, 'evaluated-marker');
|
||||
write(path.join(project, '.gstack/ship-policy.json'), `{\n "min_gstack_version": "1.2.3-rc1; $(touch ${marker})"\n}\n`);
|
||||
expect(row(f, ['--project', project]).rows.floor).toEqual({ status: 'SKIP', rest: `(${project}/.gstack/ship-policy.json sets min_gstack_version to something other than a plain dotted version)` });
|
||||
expect(fs.existsSync(marker)).toBe(false);
|
||||
write(path.join(project, '.gstack/ship-policy.json'), `{\n "min_gstack_version": "${VERSION}"\n}\n`);
|
||||
const met = row(f, ['--project', project]);
|
||||
expect(met.rows.floor).toEqual({ status: 'PASS', rest: `${VERSION} declared by ${project}/.gstack/ship-policy.json (installed ${VERSION})` });
|
||||
// Valid JSON may put the value on the line after its field (found by Codex in /ship's adversarial review).
|
||||
write(path.join(project, '.gstack/ship-policy.json'), `{\n "bump": "patch",\n "min_gstack_version":\n "${VERSION}"\n}\n`);
|
||||
expect(row(f, ['--project', project]).rows.floor.status).toBe('PASS');
|
||||
// The first occurrence is the top-level field: a later nested one never lowers the floor (found by Codex).
|
||||
write(path.join(project, '.gstack/ship-policy.json'), '{\n "min_gstack_version": "999.0.0.0",\n "$schema": {"min_gstack_version": "0.0.0"}\n}\n');
|
||||
expect(row(f, ['--project', project]).rows.floor.status).toBe('WARN');
|
||||
write(path.join(project, '.gstack/ship-policy.json'), '{\n "min_gstack_version": "999.0.0.0"\n}\n');
|
||||
const wrapper = '/drive/skills/gstack/scripts/install.sh';
|
||||
const unmet = row(f, ['--project', project, '--for', 'health'], { GSTACK_CAPY_WRAPPER_PATH: wrapper });
|
||||
expect(unmet.status, unmet.out).toBe(0);
|
||||
expect(unmet.rows.floor.status).toBe('WARN');
|
||||
expect(unmet.rows.floor.rest).toContain(`installed ${VERSION} is below the floor 999.0.0.0 that ${project}/.gstack/ship-policy.json declares (min_gstack_version); fix: bash ${wrapper} --for health (fast-forwards a clean checkout to origin and reinstalls), or `);
|
||||
expect(unmet.rows.floor.rest).toContain('(PROJECT_FLOOR_UNMET; ');
|
||||
expect(unmet.trailer).toBe(`gstack: ok ${VERSION} for=health`);
|
||||
const plain = row(f, ['--project', project]);
|
||||
expect(plain.rows.floor.rest).toContain('fix: ');
|
||||
expect(plain.rows.floor.rest).toContain('bin/gstack-upgrade (fast-forwards to the remote default branch');
|
||||
expect(plain.rows.floor.rest).not.toContain(wrapper);
|
||||
});
|
||||
|
||||
test('--revision: a matching VERSION passes, an unmet revision is never ok', () => {
|
||||
const f = makeFixture();
|
||||
const ok = row(f, ['--revision', VERSION]);
|
||||
expect(ok.status, ok.out).toBe(0);
|
||||
expect(ok.rows.revision.status).toBe('PASS');
|
||||
const unmet = row(f, ['--revision', 'v9.9.9.9']);
|
||||
expect(unmet.status).toBe(1);
|
||||
expect(unmet.rows.revision.status).toBe('FAIL');
|
||||
expect(unmet.rows.revision.rest).toContain(`installed ${VERSION}`);
|
||||
expect(unmet.rows.revision.rest).toContain('(requested v9.9.9.9)');
|
||||
expect(unmet.rows.revision.rest).toContain('(REVISION_UNMET; ');
|
||||
expect(unmet.trailer).toBe('gstack: fail revision');
|
||||
});
|
||||
|
||||
test('browser skills: the bundle and a Chromium launch plus render are required; planning skills never launch it', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
installPlaywrightStub(f, false);
|
||||
const broken = row(f, ['--for', 'qa']);
|
||||
expect(broken.status).toBe(1);
|
||||
expect(broken.rows['browse-bundle'].status).toBe('PASS');
|
||||
expect(broken.rows.browser.status).toBe('FAIL');
|
||||
expect(broken.rows.browser.rest).toContain("Executable doesn't exist");
|
||||
expect(broken.rows.browser.rest).toContain(`fix: ${bashPath(f.root)}/bin/gstack-browser-ensure (BROWSER_UNAVAILABLE; `);
|
||||
expect(broken.trailer).toBe('gstack: fail browser');
|
||||
installPlaywrightStub(f, true);
|
||||
const ok = row(f, ['--for', 'qa']);
|
||||
expect(ok.status, ok.out).toBe(0);
|
||||
expect(ok.rows.browser).toEqual({ status: 'PASS', rest: 'Chromium 141.0.1 launched and rendered (node)' });
|
||||
fs.rmSync(path.join(f.root, BROWSE_BIN));
|
||||
const noBundle = row(f, ['--for', 'browse']);
|
||||
expect(noBundle.rows['browse-bundle'].status).toBe('FAIL');
|
||||
expect(noBundle.rows['browse-bundle'].rest).toContain('fix: cd ');
|
||||
installPlaywrightStub(f, false);
|
||||
expect(row(f, ['--for', 'autoplan']).rows.browser.status).toBe('SKIP');
|
||||
});
|
||||
|
||||
test('cso: optional by default (SKIP, never silent), required by --for cso', () => {
|
||||
const f = makeFixture();
|
||||
expect(row(f, []).rows.cso).toEqual({ status: 'SKIP', rest: '(optional; toolchain absent or helper not built)' });
|
||||
const r = row(f, ['--for', 'cso']);
|
||||
expect(r.rows.cso.status).toBe('FAIL');
|
||||
expect(r.trailer).toBe('gstack: fail cso');
|
||||
for (const name of ['gstack-cso-launcher', 'gstack-cso-core']) write(path.join(f.root, 'bin', name + EXE), '#!/bin/sh\necho cso\n', 0o755);
|
||||
expect(row(f, ['--for', 'cso']).rows.cso.status).toBe('PASS');
|
||||
});
|
||||
|
||||
test('state root: GSTACK_EPHEMERAL=1 reports durable=no in --check (PASS) and warns in the dashboard', () => {
|
||||
const f = makeFixture();
|
||||
const r = row(f, [], { GSTACK_EPHEMERAL: '1' });
|
||||
expect(r.rows['state-root'].status).toBe('PASS');
|
||||
expect(r.rows['state-root'].rest).toContain(`${f.state} durable=no`);
|
||||
expect(r.rows['state-root'].rest).toContain('GSTACK_EPHEMERAL=1');
|
||||
expect(r.status, r.out).toBe(0);
|
||||
const dash = doctor(f, [], { GSTACK_EPHEMERAL: '1' });
|
||||
expect(dash.row('state root').state).toBe('warn');
|
||||
expect(dash.row('state root').detail).toContain('durable=no');
|
||||
expect(dash.row('state root').fix).toContain('GSTACK_STATE_ROOT');
|
||||
expect(doctor(f).row('state root').detail).toContain('durable=yes');
|
||||
});
|
||||
|
||||
test('--json: the same rows as objects keyed by the component ids, ok/failed/required and the trailer', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
const r = doctor(f, ['--json', '--for', 'autoplan'], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(r.status).toBe(1);
|
||||
const json = JSON.parse(r.out.trim().split('\n').at(-1)!);
|
||||
expect(json.schema_version).toBe(1);
|
||||
expect(json.revision).toBe(VERSION);
|
||||
expect(json.for).toBe('autoplan');
|
||||
expect(json.ok).toBe(false);
|
||||
expect(json.failed).toEqual(['runtime']);
|
||||
expect(json.required).toEqual(['claude', 'codex', 'patch', 'runtime', 'pins', 'state-root', 'privacy', 'cores', 'revision', 'floor', 'wrapper']);
|
||||
expect(json.rows.map((x: { id: string }) => x.id)).toEqual(['claude', 'codex', 'patch', 'codex-cli', 'browse-bundle', 'browser', 'cso', 'helpers', 'runtime', 'pins', 'state-root', 'privacy', 'cores', 'revision', 'floor', 'wrapper']);
|
||||
const runtime = json.rows.find((x: { id: string }) => x.id === 'runtime');
|
||||
expect(runtime.status).toBe('FAIL');
|
||||
expect(runtime.code).toBe('RUNTIME_BELOW_MINIMUM');
|
||||
expect(runtime.anchor).toBe('doctor-runtime-below-minimum');
|
||||
expect(runtime.fix).toContain('gstack-capy-install');
|
||||
expect(json.trailer).toBe('gstack: fail runtime');
|
||||
expect(r.out.trim().split('\n')).toHaveLength(1);
|
||||
const ok = JSON.parse(doctor(f, ['--json']).out.trim());
|
||||
expect(ok.ok).toBe(true);
|
||||
expect(ok.trailer).toBe(`gstack: ok ${VERSION} for=installed-hosts:claude,codex`);
|
||||
});
|
||||
|
||||
test('usage: --for with --require, an unknown skill or component, and a flag without a value exit 2', () => {
|
||||
const f = makeFixture();
|
||||
expect(doctor(f, ['--check', '--for', 'autoplan', '--require', 'claude']).status).toBe(2);
|
||||
expect(doctor(f, ['--for', 'no-such-skill']).status).toBe(2);
|
||||
expect(doctor(f, ['--require', 'claude,bogus']).status).toBe(2);
|
||||
expect(doctor(f, ['--check', '--project']).status).toBe(2);
|
||||
expect(doctor(f, ['--help']).out).toContain('--check');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,403 @@
|
||||
// Split from test/gstack-doctor.test.ts: launch/CSO rows, launch Bun, wrapper drift, rescue refs and Windows bash.
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { useDoctorCleanup, REPO, BROWSE_BIN, EXE, OTHER_BINS, write, script, bashPath, makeFixture, doctor, type Fixture } from './helpers/doctor-fixture';
|
||||
|
||||
useDoctorCleanup();
|
||||
|
||||
// #2595/#2124 and #3071: compiled binaries by launch state, and CSO from the
|
||||
// build-result record. A blocked binary is simulated by the application-control
|
||||
// message reporters captured (#2595), which works on every OS.
|
||||
describe('gstack-doctor launch and CSO rows', () => {
|
||||
const BLOCKED = `#!/bin/sh\necho "Program 'x.exe' failed to run: An Application Control policy has blocked this file" >&2\nexit 1\n`;
|
||||
const record = (f: Fixture, text: string) => write(path.join(f.root, 'bin/.gstack-cso-build-result'), text);
|
||||
const cso = (f: Fixture) => { for (const name of ['gstack-cso-launcher', 'gstack-cso-core']) write(path.join(f.root, 'bin', name + EXE), '#!/bin/sh\necho cso\n', 0o755); };
|
||||
|
||||
test('healthy binaries are ok; a blocked browse says blocked, not "not built"', () => {
|
||||
const f = makeFixture();
|
||||
let r = doctor(f);
|
||||
expect(r.row('binaries').state).toBe('ok');
|
||||
expect(r.row('binaries').detail).toContain('(4 of 4)');
|
||||
write(path.join(f.root, BROWSE_BIN), BLOCKED, 0o755);
|
||||
r = doctor(f);
|
||||
expect(r.row('browse bundle').state).toBe('warn');
|
||||
expect(r.row('browse bundle').detail).toContain('built, but blocked at launch (Program');
|
||||
expect(r.row('browse bundle').detail).not.toContain('not built');
|
||||
expect(r.row('browse bundle').fix).toContain(process.platform === 'win32' ? 'Smart App Control' : 'the OS refused to execute it');
|
||||
expect(r.status).toBe(0);
|
||||
});
|
||||
|
||||
test('blocked, broken and missing binaries are told apart', () => {
|
||||
const f = makeFixture();
|
||||
write(path.join(f.root, OTHER_BINS[1]), BLOCKED, 0o755);
|
||||
let r = doctor(f);
|
||||
expect(r.row('binaries').detail).toContain('blocked at launch: design');
|
||||
expect(r.row('binaries').detail).toContain('unavailable: /design-consultation');
|
||||
write(path.join(f.root, OTHER_BINS[1]), '#!/bin/sh\necho ok\n', 0o755);
|
||||
write(path.join(f.root, OTHER_BINS[2]), '#!/bin/sh\necho "usage" >&2\nexit 2\n', 0o755);
|
||||
r = doctor(f);
|
||||
expect(r.row('binaries').detail).toBe('launched but failed: pdf (exit 2: usage)');
|
||||
expect(r.row('binaries').fix).toBe(`cd ${bashPath(f.root)} && bun run build`);
|
||||
fs.rmSync(path.join(f.root, OTHER_BINS[2]));
|
||||
r = doctor(f);
|
||||
expect(r.row('binaries').detail).toBe('not built: pdf');
|
||||
});
|
||||
|
||||
test('the CSO row reads the build-result record', () => {
|
||||
const f = makeFixture();
|
||||
const none = doctor(f).row('cso');
|
||||
expect(none.state).toBe('not configured');
|
||||
expect(none.detail).toBe('native helper not built; /cso reports not assessed');
|
||||
expect(none.fix).toContain('./setup (it names any missing build prerequisite)');
|
||||
record(f, 'result=failed\nstage=build\nreason=exit 42\nrevision=1.2 (abc)\ninstalled=\nlauncher=no\ndiagnostic=/x/cso.log\n');
|
||||
let r = doctor(f);
|
||||
expect(r.row('cso').state).toBe('warn');
|
||||
expect(r.row('cso').detail).toBe('unavailable: the build step failed (exit 42); /cso reports not assessed');
|
||||
expect(r.row('cso').fix).toContain('bun run build:cso && ./setup (log: /x/cso.log;');
|
||||
cso(f);
|
||||
record(f, 'result=failed\nstage=publish\nreason=exit 1\nrevision=1.2 (abc)\ninstalled=1.1 (def)\nlauncher=yes\ndiagnostic=/x/cso.log\n');
|
||||
expect(doctor(f).row('cso').detail).toBe('publish step failed (exit 1) for 1.2 (abc); previous CSO kept: 1.1 (def)');
|
||||
record(f, 'result=ok\nstage=publish\nreason=committed\nrevision=1.2 (abc)\ninstalled=1.2 (abc)\nlauncher=yes\ndiagnostic=x\n');
|
||||
r = doctor(f);
|
||||
expect(r.row('cso')).toEqual({ state: 'ok', detail: 'native helper 1.2 (abc)', fix: '' });
|
||||
expect(r.status).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
// Field wave lane A: the trailer agrees with the Bun workflows run (A3), a
|
||||
// remote minimum fails the revision row (A2), and planning-only workflows do
|
||||
// not fail on a repo test-pin mismatch (A3 amendment).
|
||||
describe('gstack-doctor --check: launch Bun, supported minimum, planning-only pins', () => {
|
||||
const VERSION = fs.readFileSync(path.join(REPO, 'VERSION'), 'utf8').trim();
|
||||
const check = (f: Fixture, args: string[], extra: Record<string, string> = {}) => {
|
||||
const r = doctor(f, ['--check', ...args], extra);
|
||||
const lines = r.out.split('\n');
|
||||
const rows = Object.fromEntries(lines.filter(l => /^(PASS|FAIL|SKIP|WARN) /.test(l)).map(l => {
|
||||
const m = l.match(/^(PASS|FAIL|SKIP|WARN) ([a-z-]+)(?:\s(.*))?$/)!;
|
||||
return [m[2], { status: m[1], rest: m[3] ?? '' }];
|
||||
}));
|
||||
return { status: r.status, out: r.out, rows, trailer: lines.filter(l => l.startsWith('gstack: ')).at(-1) ?? '' };
|
||||
};
|
||||
/** A verified Bun in $HOME/.bun/bin (off PATH) that answers --version and runs TypeScript. */
|
||||
const verifiedBun = (f: Fixture, version = '1.4.2') =>
|
||||
script(path.join(f.home, '.bun/bin/bun'), [`[ "$1" = --version ] && { echo "${version}"; exit 0; }`, `exec "${process.execPath}" "$@"`]);
|
||||
|
||||
test('PATH Bun 1.3.14 with a verified 1.4.2 off PATH: runtime FAILs naming where it was found; with the launch PATH it PASSes', () => {
|
||||
const f = makeFixture();
|
||||
verifiedBun(f);
|
||||
const fresh = check(f, [], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(fresh.rows.runtime.status).toBe('FAIL');
|
||||
const home = bashPath(f.home);
|
||||
expect(fresh.rows.runtime.rest).toContain(`bun 1.4.2 found at ${home}/.bun/bin (not on PATH)`);
|
||||
expect(fresh.rows.runtime.rest).toContain(`fix: export PATH="${home}/.bun/bin:$PATH" or prefix commands with the GSTACK_LAUNCH line`);
|
||||
expect(fresh.rows.runtime.rest).toContain('(RUNTIME_BELOW_MINIMUM; ');
|
||||
const launched = check(f, [], { STUB_BUN_VERSION: '1.3.14', PATH: `${f.home}/.bun/bin${path.delimiter}${f.env.PATH}` });
|
||||
expect(launched.rows.runtime.status, launched.out).toBe('PASS');
|
||||
expect(launched.rows.runtime.rest).toContain(`at ${home}/.bun/bin/bun`);
|
||||
});
|
||||
|
||||
test('--min-revision: below FAILs with REVISION_BELOW_MINIMUM naming the upgrade command; at or above PASSes; unknown says so and never claims the minimum', () => {
|
||||
const f = makeFixture();
|
||||
const below = check(f, ['--min-revision', '99.0.0.0']);
|
||||
expect(below.status).toBe(1);
|
||||
expect(below.rows.revision.status).toBe('FAIL');
|
||||
expect(below.rows.revision.rest).toContain(`installed ${VERSION}`);
|
||||
expect(below.rows.revision.rest).toContain('below the supported minimum 99.0.0.0');
|
||||
expect(below.rows.revision.rest).toContain(`${bashPath(f.root)}/bin/gstack-upgrade`);
|
||||
expect(below.rows.revision.rest).toContain('(REVISION_BELOW_MINIMUM; ');
|
||||
expect(below.trailer).toBe('gstack: fail revision');
|
||||
const wrapped = check(f, ['--min-revision', '99.0.0.0'], { GSTACK_CAPY_WRAPPER_PATH: '/drive/skills/gstack/scripts/install.sh' });
|
||||
expect(wrapped.rows.revision.rest).toContain('fix: bash /drive/skills/gstack/scripts/install.sh (fast-forwards)');
|
||||
const at = check(f, ['--min-revision', VERSION]);
|
||||
expect(at.rows.revision.status, at.out).toBe('PASS');
|
||||
expect(at.rows.revision.rest).toContain(`>= supported minimum ${VERSION}`);
|
||||
const unknown = check(f, ['--min-revision', 'unknown']);
|
||||
expect(unknown.rows.revision.status).toBe('PASS');
|
||||
expect(unknown.rows.revision.rest).toContain('remote minimum unknown (fetch failed)');
|
||||
expect(unknown.rows.revision.rest).not.toContain('>= supported minimum');
|
||||
});
|
||||
|
||||
test('planning-only workflows SKIP a repo test-pin mismatch; test-running workflows and --require keep pins required', () => {
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
write(path.join(project, '.bun-version'), '1.4.2\n');
|
||||
const planning = check(f, ['--for', 'autoplan', '--project', project], { STUB_BUN_VERSION: '1.4.3' });
|
||||
expect(planning.rows.pins.status, planning.out).toBe('SKIP');
|
||||
expect(planning.rows.pins.rest).toMatch(/^\(planning-only; repo pins .*1\.4\.2.*, launch bun 1\.4\.3\)$/);
|
||||
for (const args of [['--for', 'review'], ['--for', 'ship'], ['--require', 'claude']]) {
|
||||
const tests = check(f, [...args, '--project', project], { STUB_BUN_VERSION: '1.4.3' });
|
||||
expect(tests.rows.pins.status, args.join(' ')).toBe('FAIL');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Plan A8/A-h: the Capy skill copy. Active-wrapper provenance decides; without
|
||||
// it the Drive copies do, failing only when every copy is stale. The printed
|
||||
// workaround (the checkout's own wrapper) certifies with the stale Drive copy
|
||||
// left unchanged. Plan A5: a drifted resolution is a runtime FAIL.
|
||||
describe('gstack-doctor --check: wrapper and runtime drift', () => {
|
||||
const posixPathTest = process.platform === 'win32' ? test.skip : test;
|
||||
const PRE_BOOTSTRAPPER = '#!/usr/bin/env bash\n# gstack Capy skill installer (pre-bootstrapper)\nset -u\nroot="${GSTACK_CAPY_ROOT:-$HOME/.local/share/gstack}"\nexec "$root/bin/gstack-capy-install" "$@"\n';
|
||||
const parse = (f: Fixture, args: string[], extra: Record<string, string> = {}) => {
|
||||
const r = doctor(f, ['--check', ...args], extra);
|
||||
const line = (id: string) => r.out.split('\n').find(l => new RegExp(`^(PASS|FAIL|SKIP|WARN) ${id}\\b`).test(l)) ?? '';
|
||||
return { status: r.status, out: r.out, line, trailer: r.out.split('\n').filter(l => l.startsWith('gstack: ')).at(-1) ?? '' };
|
||||
};
|
||||
const drive = (f: Fixture, scope: string, text: string) => { const file = path.join(f.home, '.capy/drive', scope, 'skills/gstack/scripts/install.sh'); write(file, text); return file; };
|
||||
const withSupport = (f: Fixture, min = 1) => write(path.join(f.root, 'capy/support.env'), `GSTACK_MIN_REVISION=1.0.0.0\nGSTACK_CAPY_MIN_WRAPPER=${min}\n`);
|
||||
const current = fs.readFileSync(path.join(REPO, 'capy/skill/gstack/scripts/install.sh'), 'utf8');
|
||||
const currentRev = current.match(/^GSTACK_CAPY_WRAPPER=(\d+)$/m)![1];
|
||||
|
||||
posixPathTest('direct doctor run: a pre-bootstrapper Drive copy (no revision line) fails wrapper with both fixes; a current copy is not flagged', () => {
|
||||
const f = makeFixture();
|
||||
withSupport(f);
|
||||
const stale = drive(f, 'user-garry-tan', PRE_BOOTSTRAPPER);
|
||||
const r = parse(f, []);
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.trailer).toBe('gstack: fail wrapper');
|
||||
const row = r.line('wrapper');
|
||||
expect(row).toContain(`FAIL wrapper — every Capy skill copy is stale (minimum wrapper 1): ${stale} (wrapper 0); fix: bash ${f.root}/capy/skill/gstack/scripts/install.sh --check (this session); owner: copy ${f.root}/capy/skill/gstack/ over the Drive skill folder, or have Capy re-sync it; this recurs every session until the Drive copy changes`);
|
||||
expect(row).toContain('(CAPY_WRAPPER_STALE; https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#capy-wrapper-stale)');
|
||||
write(stale, current);
|
||||
const fresh = parse(f, []);
|
||||
expect(fresh.line('wrapper')).toBe(`PASS wrapper Drive copy ${stale} (wrapper ${currentRev}) (minimum 1)`);
|
||||
expect(fresh.status, fresh.out).toBe(0);
|
||||
});
|
||||
|
||||
posixPathTest('direct doctor run: a bootstrapper Drive copy below the minimum still works, so it is an owner-action WARN with an ok trailer (only a pre-bootstrapper copy fails)', () => {
|
||||
const f = makeFixture();
|
||||
withSupport(f, Number(currentRev) + 1);
|
||||
const old = drive(f, 'user-garry-tan', current);
|
||||
const r = parse(f, []);
|
||||
expect(r.status, r.out).toBe(0);
|
||||
expect(r.trailer).toMatch(/^gstack: ok /);
|
||||
expect(r.line('wrapper')).toBe(`WARN wrapper — every Capy skill copy is below the minimum wrapper ${Number(currentRev) + 1} (it still works): ${old} (wrapper ${currentRev}); owner action: copy ${f.root}/capy/skill/gstack/ over the Drive skill folder, or have Capy re-sync it; this recurs every session until the Drive copy changes (CAPY_WRAPPER_STALE; https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#capy-wrapper-stale)`);
|
||||
const json = JSON.parse(doctor(f, ['--check', '--json']).out);
|
||||
expect(json.ok).toBe(true);
|
||||
expect(json.rows.find((x: { id: string }) => x.id === 'wrapper')).toMatchObject({ status: 'WARN', code: 'CAPY_WRAPPER_STALE' });
|
||||
// A pre-bootstrapper copy beside it keeps the FAIL: that copy cannot hand over at all.
|
||||
drive(f, 'org', PRE_BOOTSTRAPPER);
|
||||
expect(parse(f, []).trailer).toBe('gstack: fail wrapper');
|
||||
});
|
||||
|
||||
posixPathTest('two Drive copies, one current: PASS naming the stale one; GSTACK_CAPY_WRAPPER_PATH alone decides when set without a revision', () => {
|
||||
const f = makeFixture();
|
||||
withSupport(f);
|
||||
const stale = drive(f, 'org', PRE_BOOTSTRAPPER);
|
||||
const good = drive(f, 'user', current);
|
||||
const r = parse(f, []);
|
||||
expect(r.line('wrapper')).toBe(`PASS wrapper Drive copy ${good} (wrapper ${currentRev}) (minimum 1); stale copies: ${stale} (wrapper 0)`);
|
||||
expect(parse(f, [], { GSTACK_CAPY_WRAPPER_PATH: stale }).trailer).toBe('gstack: fail wrapper');
|
||||
});
|
||||
|
||||
posixPathTest('the printed workaround certifies: a current active wrapper passes with the stale Drive copy unchanged (WARN, owner action); a stale active wrapper is a WARN too', () => {
|
||||
const f = makeFixture();
|
||||
withSupport(f);
|
||||
const stale = drive(f, 'user-garry-tan', PRE_BOOTSTRAPPER);
|
||||
const checkoutCopy = path.join(f.root, 'capy/skill/gstack/scripts/install.sh');
|
||||
const r = parse(f, [], { GSTACK_CAPY_WRAPPER_REV: '1', GSTACK_CAPY_WRAPPER_PATH: checkoutCopy });
|
||||
expect(r.status, r.out).toBe(0);
|
||||
expect(r.trailer).toMatch(/^gstack: ok /);
|
||||
expect(r.line('wrapper')).toBe(`WARN wrapper — active wrapper 1 (${checkoutCopy}) is current; stale Drive copies (minimum 1): ${stale} (wrapper 0); owner action: copy ${f.root}/capy/skill/gstack/ over the Drive skill folder, or have Capy re-sync it; this recurs every session until the Drive copy changes (CAPY_WRAPPER_STALE; https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#capy-wrapper-stale)`);
|
||||
expect(fs.readFileSync(stale, 'utf8')).toBe(PRE_BOOTSTRAPPER);
|
||||
const json = JSON.parse(doctor(f, ['--check', '--json'], { GSTACK_CAPY_WRAPPER_REV: '1', GSTACK_CAPY_WRAPPER_PATH: checkoutCopy }).out);
|
||||
expect(json.ok).toBe(true);
|
||||
expect(json.rows.find((x: { id: string }) => x.id === 'wrapper')).toMatchObject({ status: 'WARN', code: 'CAPY_WRAPPER_STALE' });
|
||||
withSupport(f, 2);
|
||||
const old = parse(f, [], { GSTACK_CAPY_WRAPPER_REV: '1', GSTACK_CAPY_WRAPPER_PATH: stale });
|
||||
// Integration item 2: an active copy below the minimum still works, so it
|
||||
// is an owner-action WARN and the trailer stays ok.
|
||||
expect(old.status, old.out).toBe(0);
|
||||
expect(old.trailer).toMatch(/^gstack: ok /);
|
||||
expect(old.line('wrapper')).toBe(`WARN wrapper — the active Capy skill copy ${stale} is wrapper 1, minimum 2 (it still works); owner action: copy ${f.root}/capy/skill/gstack/ over the Drive skill folder, or have Capy re-sync it; this recurs every session until the Drive copy changes (CAPY_WRAPPER_STALE; https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#capy-wrapper-stale)`);
|
||||
});
|
||||
|
||||
test('a drifted Bun resolution is a runtime FAIL carrying the installer\'s detail, fix and BUN_RESOLUTION_DRIFT', () => {
|
||||
const f = makeFixture();
|
||||
const r = parse(f, [], { GSTACK_DOCTOR_RUNTIME_DRIFT: 'recorded bun 1.4.3 at /s/bun (home), now no eligible bun; changed: the recorded binary is gone', GSTACK_DOCTOR_RUNTIME_DRIFT_FIX: 'bash /d/install.sh --for review' });
|
||||
expect(r.trailer).toBe('gstack: fail runtime');
|
||||
expect(r.line('runtime')).toBe('FAIL runtime — bun resolution drifted: recorded bun 1.4.3 at /s/bun (home), now no eligible bun; changed: the recorded binary is gone; fix: bash /d/install.sh --for review (BUN_RESOLUTION_DRIFT; https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#bun-resolution-drift)');
|
||||
});
|
||||
|
||||
posixPathTest('the runtime row shows gstack\'s bun shim and where it resolves from here, or names a foreign ~/.local/bin/bun it left alone', () => {
|
||||
const f = makeFixture();
|
||||
const shim = path.join(f.home, '.local/bin/bun');
|
||||
write(shim, '#!/bin/sh\n# gstack-bun-shim: gstack-owned; delete this file to remove it\n[ "$GSTACK_BUN_SHIM_EXPLAIN" = 1 ] && echo "gstack bun shim: project=none record=none chose=/store/1.4.3/bun rule=default" >&2\necho 1.4.3\n', 0o755);
|
||||
expect(parse(f, []).line('runtime')).toContain(`; shim ${shim} -> /store/1.4.3/bun`);
|
||||
write(shim, '#!/bin/sh\necho mine\n', 0o755);
|
||||
expect(parse(f, []).line('runtime')).toContain(`; ${shim} is not gstack's shim (no marker), left untouched: launch with the GSTACK_LAUNCH line`);
|
||||
expect(parse(f, [], { GSTACK_BUN_INSTALL_VERSION: '1.4.2' }).line('runtime')).toContain('; install version 1.4.2 from GSTACK_BUN_INSTALL_VERSION');
|
||||
});
|
||||
|
||||
test('A-a: the Capy skill\'s dispatch examples (fail revision, fail runtime,pins, fail pins) match the real failure heads, unchanged', () => {
|
||||
const skill = fs.readFileSync(path.join(REPO, 'capy/skill/gstack/SKILL.md'), 'utf8');
|
||||
const step = skill.split('\n').find(l => l.includes('If the trailer names `revision`, `runtime` or `pins`'))!;
|
||||
const examples = [...step.matchAll(/`(gstack: fail [^`]+)`/g)].map(m => m[1]);
|
||||
expect(examples).toEqual(['gstack: fail revision …', 'gstack: fail runtime,pins', 'gstack: fail pins']);
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
write(path.join(project, '.bun-version'), '1.4.2\n');
|
||||
const real: Record<string, string> = {
|
||||
revision: parse(f, ['--require', 'claude', '--min-revision', '99.0.0.0']).trailer,
|
||||
'runtime,pins': parse(f, ['--require', 'claude', '--project', project], { STUB_BUN_VERSION: '1.3.14' }).trailer,
|
||||
pins: parse(f, ['--require', 'claude', '--project', project], { STUB_BUN_VERSION: '1.4.3' }).trailer,
|
||||
};
|
||||
for (const example of examples) {
|
||||
const ids = example.slice('gstack: fail '.length).replace(/ …$/, '');
|
||||
const head = real[ids];
|
||||
expect(head === `gstack: fail ${ids}` || head.startsWith(`gstack: fail ${ids} — `), `${example} vs ${head}`).toBe(true);
|
||||
expect(head.match(/^gstack: fail ([a-z,-]+)/)?.[1].split(',')).toEqual(ids.split(','));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Lane F item D: the plain report lists rescue refs with their commands, warns
|
||||
// about a CLAUDE.md gstack section that enumerates skills (#3169), and on
|
||||
// Windows names the bash gstack's TypeScript hands its scripts to. GSTACK_DOCTOR_PLATFORM
|
||||
// injects the platform and GSTACK_DOCTOR_BASH_PROBE the discovery inputs, so
|
||||
// every case runs on every OS.
|
||||
describe('gstack-doctor: rescue refs, CLAUDE.md skill lists, Windows bash', () => {
|
||||
const git = (f: Fixture, args: string[], extra: Record<string, string> = {}) => {
|
||||
const r = spawnSync('git', args, {
|
||||
cwd: f.root, encoding: 'utf8', timeout: 20_000,
|
||||
env: { ...process.env, HOME: f.home, GIT_CONFIG_NOSYSTEM: '1', GIT_AUTHOR_NAME: 'fixture', GIT_AUTHOR_EMAIL: 'fixture@example.com', GIT_COMMITTER_NAME: 'fixture', GIT_COMMITTER_EMAIL: 'fixture@example.com', ...extra },
|
||||
});
|
||||
if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
|
||||
return r.stdout.trim();
|
||||
};
|
||||
/** A git install with one rescue commit per entry: a user edit on top of HEAD, committed on the given date. */
|
||||
const withRescues = (f: Fixture, rescues: Array<{ date: string; unmerged?: boolean }>) => {
|
||||
git(f, ['init', '-q']);
|
||||
git(f, ['add', '-A']);
|
||||
git(f, ['commit', '-qm', 'release']);
|
||||
const index = path.join(f.base, 'rescue.idx');
|
||||
return rescues.map(({ date, unmerged }, i) => {
|
||||
const blob = spawnSync('git', ['hash-object', '-w', '--stdin'], { cwd: f.root, input: `edit ${i}\n`, encoding: 'utf8', timeout: 20_000 }).stdout.trim();
|
||||
git(f, ['read-tree', 'HEAD'], { GIT_INDEX_FILE: index });
|
||||
git(f, ['update-index', '--add', '--cacheinfo', `100644,${blob},local-edit-${i}.txt`], { GIT_INDEX_FILE: index });
|
||||
const tree = git(f, ['write-tree'], { GIT_INDEX_FILE: index });
|
||||
const message = `gstack rescue: local edits that conflicted with abc\n${unmerged ? '\nNeeds manual resolution: the install had unmerged files; their captured\ncontent may contain conflict markers.\n' : ''}`;
|
||||
const oid = spawnSync('git', ['commit-tree', tree, '-p', 'HEAD'], {
|
||||
cwd: f.root, input: message, encoding: 'utf8', timeout: 20_000,
|
||||
env: { ...process.env, HOME: f.home, GIT_CONFIG_NOSYSTEM: '1', GIT_AUTHOR_NAME: 'gstack rescue', GIT_AUTHOR_EMAIL: 'gstack@localhost', GIT_COMMITTER_NAME: 'gstack rescue', GIT_COMMITTER_EMAIL: 'gstack@localhost', GIT_AUTHOR_DATE: date, GIT_COMMITTER_DATE: date },
|
||||
}).stdout.trim();
|
||||
git(f, ['update-ref', `refs/gstack/rescue/${oid}`, oid]);
|
||||
return `refs/gstack/rescue/${oid}`;
|
||||
});
|
||||
};
|
||||
const rescueRefs = (f: Fixture) => git(f, ['for-each-ref', '--format=%(refname)', 'refs/gstack/rescue/']).split('\n').filter(Boolean);
|
||||
const commandFor = (out: string, label: 'inspect' | 'delete', ref: string) =>
|
||||
out.split('\n').map(l => l.trim()).find(l => l.startsWith(`${label}:`) && l.includes(`'${ref}'`))?.replace(/^[a-z]+:\s+/, '') ?? '';
|
||||
|
||||
test('rescue refs: two refs are listed newest first with their dates; the printed inspect command shows the edit and the printed delete command removes the ref', () => {
|
||||
const f = makeFixture();
|
||||
const [older, newer] = withRescues(f, [{ date: '2026-10-01T12:00:00Z' }, { date: '2026-10-14T08:30:00Z', unmerged: true }]);
|
||||
const r = doctor(f);
|
||||
const row = r.row('rescue refs');
|
||||
expect(row.state, r.out).toBe('warn');
|
||||
expect(row.detail).toContain(`2 in ${bashPath(f.root)}`);
|
||||
expect(row.fix).toContain('#auto-update-rescued-edits');
|
||||
const listing = r.out.split('\n').map(l => l.trim());
|
||||
expect(listing.findIndex(l => l.startsWith(newer))).toBeLessThan(listing.findIndex(l => l.startsWith(older)));
|
||||
expect(listing).toContain(`${older} (2026-10-01)`);
|
||||
expect(listing).toContain(`${newer} (2026-10-14, needs manual resolution)`);
|
||||
const q = `'${bashPath(f.root)}'`;
|
||||
expect(commandFor(r.out, 'inspect', older)).toBe(`git -C ${q} diff '${older}^' '${older}'`);
|
||||
expect(commandFor(r.out, 'delete', older)).toBe(`git -C ${q} update-ref -d '${older}'`);
|
||||
const shown = spawnSync('bash', ['-c', commandFor(r.out, 'inspect', older)], { cwd: f.work, encoding: 'utf8', timeout: 20_000 });
|
||||
expect(shown.status, shown.stderr).toBe(0);
|
||||
expect(shown.stdout).toContain('+edit 0');
|
||||
const deleted = spawnSync('bash', ['-c', commandFor(r.out, 'delete', older)], { cwd: f.work, encoding: 'utf8', timeout: 20_000 });
|
||||
expect(deleted.status, deleted.stderr).toBe(0);
|
||||
expect(rescueRefs(f)).toEqual([newer]);
|
||||
expect(doctor(f).row('rescue refs').detail).toContain(`1 in ${bashPath(f.root)}`);
|
||||
spawnSync('bash', ['-c', commandFor(r.out, 'delete', newer)], { cwd: f.work, encoding: 'utf8', timeout: 20_000 });
|
||||
const none = doctor(f);
|
||||
expect(none.row('rescue refs')).toEqual({ state: 'ok', detail: `none in ${bashPath(f.root)}`, fix: '' });
|
||||
expect(none.status, none.out).toBe(0);
|
||||
});
|
||||
|
||||
const LISTING = '## gstack\nUse /browse from gstack for all web browsing. Never use mcp__claude-in-chrome__* tools.\nAvailable skills: /office-hours, /plan-ceo-review, /plan-eng-review, /plan-design-review,\n/design-consultation, /design-shotgun, /design-html, /review, /ship, /qa, /browse, /retro, /investigate.\n';
|
||||
const SHORT = '## gstack\nUse /browse from gstack for all web browsing. Never use mcp__claude-in-chrome__* tools.\n';
|
||||
const replacement = (out: string) => out.split('\n').filter(l => l.startsWith(' '.repeat(34))).map(l => l.slice(34));
|
||||
|
||||
test('CLAUDE.md: a gstack section that enumerates skills warns with the short replacement block, for ~/.claude/CLAUDE.md and the project CLAUDE.md', () => {
|
||||
const f = makeFixture();
|
||||
const user = path.join(f.home, '.claude/CLAUDE.md');
|
||||
write(user, `# Me\n\n${LISTING}\n## Other\ntext\n`);
|
||||
const r = doctor(f);
|
||||
const row = r.row('CLAUDE.md');
|
||||
expect(row.state, r.out).toBe('warn');
|
||||
expect(row.detail).toContain(`${bashPath(f.home)}/.claude/CLAUDE.md lists 13 skills`);
|
||||
expect(row.fix).toContain('#claude-md-skill-list');
|
||||
expect(fs.readFileSync(path.join(REPO, 'docs/troubleshooting.md'), 'utf8')).toContain('<a id="claude-md-skill-list"></a>');
|
||||
expect(replacement(r.out)).toEqual(['## gstack', 'Use /browse from gstack for all web browsing. Never use mcp__claude-in-chrome__* tools.']);
|
||||
expect(r.status, r.out).toBe(0);
|
||||
write(user, SHORT);
|
||||
write(path.join(f.work, 'CLAUDE.md'), `# Project\n\n## gstack (recommended)\nskills: /office-hours /plan-ceo-review /plan-eng-review /review /ship /qa /browse /retro /investigate\n`);
|
||||
const project = doctor(f).row('CLAUDE.md');
|
||||
expect(project.state).toBe('warn');
|
||||
expect(project.detail).toContain(`${bashPath(f.work)}/CLAUDE.md lists 9 skills`);
|
||||
expect(project.detail).not.toContain('.claude/CLAUDE.md');
|
||||
});
|
||||
|
||||
test('CLAUDE.md: the short block, team-init\'s block, a separate Skill routing section and paths do not warn; no CLAUDE.md does not warn', () => {
|
||||
const f = makeFixture();
|
||||
const none = doctor(f).row('CLAUDE.md');
|
||||
expect(none.state).toBe('ok');
|
||||
expect(none.fix).toBe('');
|
||||
write(path.join(f.home, '.claude/CLAUDE.md'), SHORT);
|
||||
write(path.join(f.work, 'CLAUDE.md'), [
|
||||
'## gstack (recommended)',
|
||||
'Using gstack skills: After install, skills like /qa, /ship, /review, /investigate,',
|
||||
'and /browse are available. Use the install path ~/.claude/skills/gstack/bin/gstack-config /usr/local/bin/bun /opt/a/b /x/y /z/w.',
|
||||
'',
|
||||
'## Skill routing',
|
||||
'- Product ideas → invoke /office-hours',
|
||||
'- Strategy → invoke /plan-ceo-review',
|
||||
'- Architecture → invoke /plan-eng-review',
|
||||
'- Design → invoke /design-consultation or /plan-design-review',
|
||||
'- Review → invoke /autoplan, /investigate, /qa, /review, /ship',
|
||||
'',
|
||||
].join('\n'));
|
||||
const r = doctor(f);
|
||||
expect(r.row('CLAUDE.md').state, r.out).toBe('ok');
|
||||
expect(replacement(r.out)).toEqual([]);
|
||||
});
|
||||
|
||||
/** A JSON probe file: the discovery inputs resolveWindowsBash takes, in test/fixtures/windows-bash-resolution.json's shape. */
|
||||
const probe = (f: Fixture, inputs: Record<string, unknown>) => { const file = path.join(f.base, 'bash-probe.json'); write(file, JSON.stringify(inputs)); return file; };
|
||||
const GIT_BASH = 'C:/Program Files/Git/bin/bash.exe';
|
||||
|
||||
test('windows bash: on Windows the row names the resolved bash and what chose it', () => {
|
||||
const f = makeFixture();
|
||||
const found = doctor(f, [], { GSTACK_DOCTOR_PLATFORM: 'windows', GSTACK_DOCTOR_BASH_PROBE: probe(f, { exists: [GIT_BASH], gitExecPath: 'C:/Program Files/Git/mingw64/libexec/git-core' }) });
|
||||
expect(found.row('windows bash'), found.out).toEqual({ state: 'ok', detail: `${GIT_BASH} (chosen by git --exec-path)`, fix: '' });
|
||||
const override = doctor(f, [], { GSTACK_DOCTOR_PLATFORM: 'windows', GSTACK_GIT_BASH: 'D:\\tools\\bash.exe', GSTACK_DOCTOR_BASH_PROBE: probe(f, { exists: ['D:/tools/bash.exe', GIT_BASH] }) });
|
||||
expect(override.row('windows bash').detail).toBe('D:/tools/bash.exe (chosen by GSTACK_GIT_BASH)');
|
||||
});
|
||||
|
||||
test('windows bash: GSTACK_GIT_BASH and a different deprecated GSTACK_BASH warn naming both', () => {
|
||||
const f = makeFixture();
|
||||
const differ = doctor(f, [], { GSTACK_DOCTOR_PLATFORM: 'windows', GSTACK_GIT_BASH: 'D:/a/bash.exe', GSTACK_BASH: 'D:/b/bash.exe', GSTACK_DOCTOR_BASH_PROBE: probe(f, { exists: ['D:/a/bash.exe', 'D:/b/bash.exe'] }) });
|
||||
expect(differ.row('windows bash').state).toBe('warn');
|
||||
expect(differ.row('windows bash').detail).toContain('D:/a/bash.exe (chosen by GSTACK_GIT_BASH)');
|
||||
expect(differ.row('windows bash').detail).toContain('GSTACK_GIT_BASH (D:/a/bash.exe) and the deprecated GSTACK_BASH (D:/b/bash.exe) differ');
|
||||
});
|
||||
|
||||
test('windows bash: a refusal fails with BASH_UNAVAILABLE naming GSTACK_GIT_BASH; off Windows there is no row', () => {
|
||||
const f = makeFixture();
|
||||
const refused = doctor(f, [], { GSTACK_DOCTOR_PLATFORM: 'windows', GSTACK_DOCTOR_BASH_PROBE: probe(f, { exists: [], gitExecPath: null, which: { bash: 'C:/Windows/System32/bash.exe' } }) });
|
||||
const row = refused.row('windows bash');
|
||||
expect(row.state, refused.out).toBe('fail');
|
||||
expect(row.detail).toContain('(BASH_UNAVAILABLE)');
|
||||
expect(row.detail).toContain('PATH C:/Windows/System32/bash.exe: WSL launcher, not Git Bash');
|
||||
expect(row.detail).toContain(`install path ${GIT_BASH}: not found`);
|
||||
expect(row.fix).toContain('GSTACK_GIT_BASH');
|
||||
expect(row.fix).toContain('#bash-unavailable');
|
||||
expect(refused.status).toBe(1);
|
||||
expect(doctor(f, [], { GSTACK_DOCTOR_PLATFORM: 'posix' }).out).not.toContain('windows bash');
|
||||
});
|
||||
});
|
||||
+3
-879
@@ -8,128 +8,13 @@
|
||||
* bun/codex/claude on PATH and an explicit HOME. Scripts run through explicit
|
||||
* bash argv, so the file is in the curated Windows lane.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { useDoctorCleanup, REPO, BROWSE_BIN, write, bashPath, probeCalls, iso, syncOn, makeFixture, doctor, type Fixture } from './helpers/doctor-fixture';
|
||||
|
||||
// setup builds browse/dist/browse.exe on Windows (Git Bash), browse/dist/browse elsewhere.
|
||||
const BROWSE_BIN = process.platform === 'win32' ? 'browse/dist/browse.exe' : 'browse/dist/browse';
|
||||
const EXE = process.platform === 'win32' ? '.exe' : '';
|
||||
const OTHER_BINS = ['browse/dist/find-browse', 'design/dist/design', 'make-pdf/dist/pdf', 'bin/gstack-global-discover'].map(rel => rel + EXE);
|
||||
|
||||
const REPO = path.resolve(import.meta.dir, '..');
|
||||
const COPIED = [
|
||||
'setup', 'VERSION',
|
||||
'bin/gstack-doctor', 'bin/gstack-codex-status.sh', 'bin/gstack-state-root.sh', 'bin/gstack-install-registry.sh',
|
||||
'bin/gstack-render-claude.sh', 'bin/gstack-bun-version.sh', 'bin/gstack-hook-check', 'bin/gstack-config',
|
||||
'autoplan/SKILL.md', // its frontmatter registers the autoplan hook the hooks-row test breaks
|
||||
'bin/gstack-launch-probe.sh',
|
||||
'bin/gstack-doctor-check.sh', 'bin/gstack-doctor-components.sh', 'bin/gstack-runtime-pins.ts', 'lib/runtime-pins.ts',
|
||||
'bin/gstack-windows-bash.ts', 'lib/script-invocation.ts', 'lib/bun-isolation.ts', 'lib/result-codes.ts', 'lib/result-codes-release.ts', 'lib/result-codes-capy.ts', // the windows bash row
|
||||
];
|
||||
const bases: string[] = [];
|
||||
afterEach(() => { for (const b of bases.splice(0)) fs.rmSync(b, { recursive: true, force: true }); });
|
||||
|
||||
const write = (file: string, text: string, mode = 0o644) => {
|
||||
fs.mkdirSync(path.dirname(file), { recursive: true });
|
||||
fs.writeFileSync(file, text, { mode });
|
||||
};
|
||||
const script = (file: string, lines: string[]) => write(file, ['#!/usr/bin/env bash', ...lines].join('\n') + '\n', 0o755);
|
||||
|
||||
/** The fixture's PATH entries minus every directory holding a real bun, codex or claude. */
|
||||
function hostPath(base: string): string {
|
||||
const names = ['bun', 'codex', 'claude'];
|
||||
const exts = process.platform === 'win32' ? ['', '.exe', '.cmd', '.ps1'] : [''];
|
||||
return (process.env.PATH ?? process.env.Path ?? '').split(path.delimiter).filter(Boolean).map((dir, i) => {
|
||||
if (!names.some(n => exts.some(e => fs.existsSync(path.join(dir, n + e))))) return dir;
|
||||
const shim = path.join(base, `host-${i}`);
|
||||
fs.mkdirSync(shim, { recursive: true });
|
||||
for (const name of fs.readdirSync(dir)) {
|
||||
if (names.some(n => exts.some(e => name === n + e))) continue;
|
||||
try { fs.symlinkSync(path.join(dir, name), path.join(shim, name)); } catch { /* unreadable entry */ }
|
||||
}
|
||||
return shim;
|
||||
}).join(path.delimiter);
|
||||
}
|
||||
|
||||
interface Fixture { base: string; root: string; state: string; home: string; work: string; stub: string; probeLog: string; env: Record<string, string> }
|
||||
|
||||
function makeFixture(): Fixture {
|
||||
const base = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-doctor-')));
|
||||
bases.push(base);
|
||||
const root = path.join(base, 'gstack');
|
||||
const state = path.join(base, 'state');
|
||||
const home = path.join(base, 'home');
|
||||
const work = path.join(base, 'work');
|
||||
const stub = path.join(base, 'stub');
|
||||
const probeLog = path.join(base, 'probe-calls');
|
||||
for (const dir of [state, home, work, stub]) fs.mkdirSync(dir, { recursive: true });
|
||||
for (const rel of COPIED) {
|
||||
fs.mkdirSync(path.dirname(path.join(root, rel)), { recursive: true });
|
||||
fs.copyFileSync(path.join(REPO, rel), path.join(root, rel));
|
||||
fs.chmodSync(path.join(root, rel), fs.statSync(path.join(REPO, rel)).mode);
|
||||
}
|
||||
script(path.join(root, 'bin/gstack-codex-probe'), [
|
||||
'echo "$*" >> "$DOCTOR_PROBE_LOG"',
|
||||
'case "$1" in',
|
||||
' select-model) [ "${STUB_SELECT_FAIL:-}" = 1 ] && { echo "gstack-codex-probe: cannot find its scripts dir" >&2; exit 1; }',
|
||||
' echo "CODEX_SEL: gpt-stub-5"; echo "CODEX_SEL_KIND: $2"; echo "CODEX_MODEL: gpt-stub-5 ($2; source: codex config.toml)" >&2 ;;',
|
||||
' check-auth) [ "${STUB_AUTH_FAIL:-}" = 1 ] && { echo AUTH_FAILED; exit 1; }; echo AUTH_OK ;;',
|
||||
' show-sandbox) echo "CODEX_SANDBOX: read-only" ;;',
|
||||
' check-sandbox|check-version) ;;',
|
||||
' probe-model) echo "CODEX_PROBE_STATE: ${STUB_PROBE_STATE:-ok}"; exit "${STUB_PROBE_EXIT:-0}" ;;',
|
||||
' *) exit 64 ;;',
|
||||
'esac',
|
||||
]);
|
||||
const listed = spawnSync('bash', [path.join(root, 'bin/gstack-hook-check'), '--list', root], { encoding: 'utf8', timeout: 20_000 });
|
||||
const hooks = listed.stdout.split('\n').map(line => line.trim()).filter(Boolean);
|
||||
if (!hooks.includes('autoplan/bin/phase-publication-hook')) throw new Error(`gstack-hook-check --list missed the autoplan hook: ${listed.stdout}${listed.stderr}`);
|
||||
for (const hook of hooks) write(path.join(root, hook), '#!/bin/sh\nexit 0\n', 0o755);
|
||||
// The doctor launches each compiled binary's --version (#2595), so the
|
||||
// stand-ins answer it like the real binaries do.
|
||||
for (const rel of [BROWSE_BIN, ...OTHER_BINS]) write(path.join(root, rel), '#!/bin/sh\necho built\n', 0o755);
|
||||
for (const rel of ['browse/dist/server-node.mjs', 'browse/dist/.build-complete']) write(path.join(root, rel), 'built\n', 0o755);
|
||||
const version = fs.readFileSync(path.join(root, 'VERSION'), 'utf8').trim();
|
||||
write(path.join(state, 'installs.tsv'),
|
||||
['claude', 'global', '-', path.join(home, '.claude/skills'), root, root, version, 'false', 'committed', '2026-10-07T00:00:00Z'].join('\t') + '\n');
|
||||
// The stub answers --version; anything else (the pins row runs bin/gstack-runtime-pins.ts) goes to the real bun.
|
||||
script(path.join(stub, 'bun'), ['[ "$1" = --version ] && { echo "${STUB_BUN_VERSION:-1.4.2}"; exit 0; }', `exec "${process.execPath}" "$@"`]);
|
||||
script(path.join(stub, 'codex'), ['[ "$1" = --version ] && { echo "codex-cli 0.130.0"; exit 0; }', 'echo "unexpected codex call: $*" >> "$DOCTOR_PROBE_LOG"', 'exit 9']);
|
||||
script(path.join(stub, 'claude'), ['[ "$1" = --version ] && { echo "2.1.292 (Claude Code)"; exit 0; }', 'exit 9']);
|
||||
const env: Record<string, string> = {
|
||||
PATH: [stub, hostPath(base)].join(path.delimiter),
|
||||
HOME: home, GSTACK_STATE_ROOT: state, TMPDIR: base, DOCTOR_PROBE_LOG: probeLog,
|
||||
};
|
||||
if (process.env.SYSTEMROOT) env.SYSTEMROOT = process.env.SYSTEMROOT;
|
||||
return { base, root, state, home, work, stub, probeLog, env };
|
||||
}
|
||||
|
||||
function doctor(f: Fixture, args: string[] = [], extra: Record<string, string> = {}) {
|
||||
const r = spawnSync('bash', [path.join(f.root, 'bin/gstack-doctor'), ...args], { cwd: f.work, encoding: 'utf8', env: { ...f.env, ...extra }, timeout: 60_000 });
|
||||
const out = `${r.stdout}${r.stderr}`;
|
||||
return { status: r.status, out, row: (name: string) => rowOf(r.stdout, name) };
|
||||
}
|
||||
|
||||
/** The named row and its fix line: { state, detail, fix }. */
|
||||
function rowOf(stdout: string, name: string) {
|
||||
const lines = stdout.split('\n');
|
||||
const i = lines.findIndex(l => l.slice(16, 32).trim() === name);
|
||||
if (i < 0) throw new Error(`no row "${name}" in:\n${stdout}`);
|
||||
const fix = lines[i + 1]?.startsWith(' '.repeat(32) + 'fix: ') ? lines[i + 1].slice(37) : '';
|
||||
return { state: lines[i].slice(0, 16).trim(), detail: lines[i].slice(32), fix };
|
||||
}
|
||||
|
||||
/** How bash spells a directory (Git Bash on Windows prints /c/...). */
|
||||
const bashPath = (dir: string) => spawnSync('bash', ['-c', 'cd "$1" && pwd', '_', dir], { encoding: 'utf8', timeout: 10_000 }).stdout.trim();
|
||||
const probeCalls = (f: Fixture) => fs.existsSync(f.probeLog) ? fs.readFileSync(f.probeLog, 'utf8') : '';
|
||||
const iso = (secondsAgo: number) => new Date(Date.now() - secondsAgo * 1000).toISOString().replace(/\.\d+Z$/, 'Z');
|
||||
const syncOn = (f: Fixture, status: Record<string, unknown>) => {
|
||||
fs.mkdirSync(path.join(f.state, '.git'), { recursive: true });
|
||||
write(path.join(f.state, 'config.yaml'), 'artifacts_sync_mode: artifacts-only\n');
|
||||
write(path.join(f.state, '.brain-sync-status.json'), JSON.stringify(status).replace(/":/g, '": ').replace(/,"/g, ', "') + '\n');
|
||||
};
|
||||
useDoctorCleanup();
|
||||
|
||||
describe('gstack-doctor', () => {
|
||||
test('a healthy fixture: every core row ok, exit 0, and no paid probe', () => {
|
||||
@@ -392,764 +277,3 @@ describe('bug-report template and README (DX-2, DX-12)', () => {
|
||||
expect(section).toContain('`~/.claude/skills/gstack/bin/gstack-doctor`');
|
||||
});
|
||||
});
|
||||
|
||||
// #2595/#2124 and #3071: compiled binaries by launch state, and CSO from the
|
||||
// build-result record. A blocked binary is simulated by the application-control
|
||||
// message reporters captured (#2595), which works on every OS.
|
||||
describe('gstack-doctor launch and CSO rows', () => {
|
||||
const BLOCKED = `#!/bin/sh\necho "Program 'x.exe' failed to run: An Application Control policy has blocked this file" >&2\nexit 1\n`;
|
||||
const record = (f: Fixture, text: string) => write(path.join(f.root, 'bin/.gstack-cso-build-result'), text);
|
||||
const cso = (f: Fixture) => { for (const name of ['gstack-cso-launcher', 'gstack-cso-core']) write(path.join(f.root, 'bin', name + EXE), '#!/bin/sh\necho cso\n', 0o755); };
|
||||
|
||||
test('healthy binaries are ok; a blocked browse says blocked, not "not built"', () => {
|
||||
const f = makeFixture();
|
||||
let r = doctor(f);
|
||||
expect(r.row('binaries').state).toBe('ok');
|
||||
expect(r.row('binaries').detail).toContain('(4 of 4)');
|
||||
write(path.join(f.root, BROWSE_BIN), BLOCKED, 0o755);
|
||||
r = doctor(f);
|
||||
expect(r.row('browse bundle').state).toBe('warn');
|
||||
expect(r.row('browse bundle').detail).toContain('built, but blocked at launch (Program');
|
||||
expect(r.row('browse bundle').detail).not.toContain('not built');
|
||||
expect(r.row('browse bundle').fix).toContain(process.platform === 'win32' ? 'Smart App Control' : 'the OS refused to execute it');
|
||||
expect(r.status).toBe(0);
|
||||
});
|
||||
|
||||
test('blocked, broken and missing binaries are told apart', () => {
|
||||
const f = makeFixture();
|
||||
write(path.join(f.root, OTHER_BINS[1]), BLOCKED, 0o755);
|
||||
let r = doctor(f);
|
||||
expect(r.row('binaries').detail).toContain('blocked at launch: design');
|
||||
expect(r.row('binaries').detail).toContain('unavailable: /design-consultation');
|
||||
write(path.join(f.root, OTHER_BINS[1]), '#!/bin/sh\necho ok\n', 0o755);
|
||||
write(path.join(f.root, OTHER_BINS[2]), '#!/bin/sh\necho "usage" >&2\nexit 2\n', 0o755);
|
||||
r = doctor(f);
|
||||
expect(r.row('binaries').detail).toBe('launched but failed: pdf (exit 2: usage)');
|
||||
expect(r.row('binaries').fix).toBe(`cd ${bashPath(f.root)} && bun run build`);
|
||||
fs.rmSync(path.join(f.root, OTHER_BINS[2]));
|
||||
r = doctor(f);
|
||||
expect(r.row('binaries').detail).toBe('not built: pdf');
|
||||
});
|
||||
|
||||
test('the CSO row reads the build-result record', () => {
|
||||
const f = makeFixture();
|
||||
const none = doctor(f).row('cso');
|
||||
expect(none.state).toBe('not configured');
|
||||
expect(none.detail).toBe('native helper not built; /cso reports not assessed');
|
||||
expect(none.fix).toContain('./setup (it names any missing build prerequisite)');
|
||||
record(f, 'result=failed\nstage=build\nreason=exit 42\nrevision=1.2 (abc)\ninstalled=\nlauncher=no\ndiagnostic=/x/cso.log\n');
|
||||
let r = doctor(f);
|
||||
expect(r.row('cso').state).toBe('warn');
|
||||
expect(r.row('cso').detail).toBe('unavailable: the build step failed (exit 42); /cso reports not assessed');
|
||||
expect(r.row('cso').fix).toContain('bun run build:cso && ./setup (log: /x/cso.log;');
|
||||
cso(f);
|
||||
record(f, 'result=failed\nstage=publish\nreason=exit 1\nrevision=1.2 (abc)\ninstalled=1.1 (def)\nlauncher=yes\ndiagnostic=/x/cso.log\n');
|
||||
expect(doctor(f).row('cso').detail).toBe('publish step failed (exit 1) for 1.2 (abc); previous CSO kept: 1.1 (def)');
|
||||
record(f, 'result=ok\nstage=publish\nreason=committed\nrevision=1.2 (abc)\ninstalled=1.2 (abc)\nlauncher=yes\ndiagnostic=x\n');
|
||||
r = doctor(f);
|
||||
expect(r.row('cso')).toEqual({ state: 'ok', detail: 'native helper 1.2 (abc)', fix: '' });
|
||||
expect(r.status).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
// A1: `--check` is the one-line verdict a parent agent greps. Rows are
|
||||
// `PASS | FAIL | SKIP <id>` from lib/doctor-components.ts; the trailer is
|
||||
// `gstack: ok <revision> for=<what>` (exit 0) or `gstack: fail <ids>` (exit 1).
|
||||
// Pinned on tokens, ids, exit codes and the JSON shape, not prose.
|
||||
describe('gstack-doctor --check', () => {
|
||||
const VERSION = fs.readFileSync(path.join(REPO, 'VERSION'), 'utf8').trim();
|
||||
const row = (f: Fixture, args: string[], extra: Record<string, string> = {}) => {
|
||||
const r = doctor(f, ['--check', ...args], extra);
|
||||
const lines = r.out.split('\n');
|
||||
const rows = Object.fromEntries(lines.filter(l => /^(PASS|FAIL|SKIP|WARN) /.test(l)).map(l => {
|
||||
const m = l.match(/^(PASS|FAIL|SKIP|WARN) ([a-z-]+)(?:\s(.*))?$/)!;
|
||||
return [m[2], { status: m[1], rest: m[3] ?? '' }];
|
||||
}));
|
||||
const trailer = lines.filter(l => l.startsWith('gstack: ')).at(-1) ?? '';
|
||||
const required = lines.find(l => l.startsWith('required: '))?.slice(10).split(' ') ?? [];
|
||||
return { status: r.status, out: r.out, rows, trailer, required, trailers: lines.filter(l => l.startsWith('gstack: ')).length };
|
||||
};
|
||||
/** Register a Codex install from this checkout and render a review skill, with or without the Astra patch. */
|
||||
const installCodex = (f: Fixture, patch = true) => {
|
||||
const dest = path.join(f.home, '.codex/skills');
|
||||
fs.appendFileSync(path.join(f.state, 'installs.tsv'),
|
||||
['codex', 'global', '-', dest, path.join(dest, 'gstack'), f.root, VERSION, 'true', 'committed', '2026-10-07T00:00:00Z'].join('\t') + '\n');
|
||||
fs.mkdirSync(path.join(dest, 'gstack'), { recursive: true });
|
||||
write(path.join(dest, 'gstack-review/SKILL.md'), `---\nname: gstack-review\n---\n# Review\n${patch ? '\n## Model-Specific Behavioral Patch (gpt-6-astra)\n' : ''}`);
|
||||
return dest;
|
||||
};
|
||||
const installPlaywrightStub = (f: Fixture, launches: boolean) => write(path.join(f.root, 'node_modules/playwright/index.js'),
|
||||
launches
|
||||
? 'module.exports.chromium = { launch: async () => ({ version: () => "141.0.1", close: async () => {}, newPage: async () => ({ setContent: async () => {}, title: async () => "gstack smoke test" }) }) };'
|
||||
: 'module.exports.chromium = { launch: async () => { throw new Error("browserType.launch: Executable doesn\'t exist"); } };');
|
||||
|
||||
test('healthy Claude + Codex installs: every required row PASS, exactly one trailer, exit 0, no paid probe', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
const r = row(f, []);
|
||||
expect(r.status, r.out).toBe(0);
|
||||
expect(r.required).toEqual(['claude', 'codex', 'runtime', 'pins', 'state-root', 'privacy', 'cores', 'revision', 'floor', 'wrapper']);
|
||||
for (const id of r.required.filter(x => x !== 'pins' && x !== 'floor' && x !== 'wrapper')) expect(r.rows[id]?.status, `${id}\n${r.out}`).toBe('PASS');
|
||||
// The work dir is not a git repository, so there is no project to read pins or a floor from: SKIP with the reason, never silent.
|
||||
expect(r.rows.pins).toEqual({ status: 'SKIP', rest: expect.stringContaining('no project') });
|
||||
expect(r.rows.floor).toEqual({ status: 'SKIP', rest: expect.stringContaining('no project to read .gstack/ship-policy.json from') });
|
||||
// No ~/.capy/drive skill copy and no active wrapper: not a Capy machine.
|
||||
expect(r.rows.wrapper).toEqual({ status: 'SKIP', rest: expect.stringContaining('not a Capy machine') });
|
||||
expect(r.rows.patch.status).toBe('PASS');
|
||||
expect(r.rows['codex-cli'].status).toBe('PASS');
|
||||
expect(r.rows.browser).toEqual({ status: 'SKIP', rest: '(lazy; gstack-browser-ensure installs on first use)' });
|
||||
expect(r.rows.cso.status).toBe('SKIP');
|
||||
expect(r.trailer).toBe(`gstack: ok ${VERSION} for=installed-hosts:claude,codex`);
|
||||
expect(r.trailers).toBe(1);
|
||||
expect(r.rows.runtime.rest).toContain('floor 1.3.3, supported minimum 1.4.2');
|
||||
expect(r.rows.privacy.rest).toBe('telemetry=off artifacts_sync=off codex_reviews=enabled update_check=true');
|
||||
expect(r.rows['state-root'].rest).toContain('durable=yes');
|
||||
expect(probeCalls(f)).not.toContain('probe-model');
|
||||
});
|
||||
|
||||
// Value: protects=the --check state-root row names the variable that selected the root, after earlier rows read config;
|
||||
// fails_when=an in-process config read reselects the root from the doctor's own GSTACK_STATE_ROOT;
|
||||
// why_new=every other fixture sets GSTACK_STATE_ROOT itself, so a wrong "selected by" still reads GSTACK_STATE_ROOT; seam=none;
|
||||
// no_claim=CLAUDE_PLUGIN_DATA and default selection (GSTACK_HOME stands in for every selector other than GSTACK_STATE_ROOT)
|
||||
test('the state-root row names GSTACK_HOME when GSTACK_HOME selected the root, in text and JSON', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
const byHome = { GSTACK_STATE_ROOT: '', GSTACK_HOME: f.state };
|
||||
const r = row(f, [], byHome);
|
||||
expect(r.rows['state-root'].rest, r.out).toContain('(selected by GSTACK_HOME;');
|
||||
const json = JSON.parse(doctor(f, ['--json'], byHome).out);
|
||||
expect(json.rows.find((x: { id: string }) => x.id === 'state-root').detail).toContain('(selected by GSTACK_HOME;');
|
||||
});
|
||||
|
||||
test('--for autoplan: healthy Capy machine with Claude subagents as the outside voice and no Codex CLI passes', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
fs.rmSync(path.join(f.stub, 'codex'));
|
||||
const r = row(f, ['--for', 'autoplan']);
|
||||
expect(r.status, r.out).toBe(0);
|
||||
expect(r.required).toEqual(['claude', 'codex', 'patch', 'runtime', 'pins', 'state-root', 'privacy', 'cores', 'revision', 'floor', 'wrapper']);
|
||||
expect(r.rows.patch).toEqual({ status: 'PASS', rest: 'gpt-6-astra (gstack-review/SKILL.md)' });
|
||||
expect(r.rows['codex-cli'].status).toBe('SKIP');
|
||||
expect(r.rows['codex-cli'].rest).toContain('optional');
|
||||
expect(r.trailer).toBe(`gstack: ok ${VERSION} for=autoplan`);
|
||||
// The same machine with a stale Codex render fails the patch row.
|
||||
installCodex(f, false);
|
||||
const noPatch = row(f, ['--for', 'autoplan']);
|
||||
expect(noPatch.status).toBe(1);
|
||||
expect(noPatch.rows.patch.status).toBe('FAIL');
|
||||
expect(noPatch.rows.patch.rest).toContain('fix: ');
|
||||
expect(noPatch.rows.patch.rest).toContain('(COMPONENT_MISSING; ');
|
||||
expect(noPatch.rows.patch.rest).toContain('--host codex --model');
|
||||
expect(noPatch.trailer).toBe('gstack: fail patch');
|
||||
});
|
||||
|
||||
test('--for autoplan: a hoisted Codex render carries the patch in its shared sections/preamble.md', () => {
|
||||
const f = makeFixture();
|
||||
const dest = installCodex(f, false);
|
||||
write(path.join(dest, 'gstack-review/sections/preamble.md'), '# gstack shared preamble 0123456789ab\n\n## Model-Specific Behavioral Patch (gpt-6-astra)\n');
|
||||
const r = row(f, ['--for', 'autoplan']);
|
||||
expect(r.rows.patch, r.out).toEqual({ status: 'PASS', rest: 'gpt-6-astra (gstack-review/sections/preamble.md)' });
|
||||
});
|
||||
|
||||
test('an empty installed-host set is never ok: claude is required and FAILs', () => {
|
||||
const f = makeFixture();
|
||||
write(path.join(f.state, 'installs.tsv'), '');
|
||||
const r = row(f, []);
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.required).toContain('claude');
|
||||
expect(r.rows.claude.status).toBe('FAIL');
|
||||
expect(r.rows.claude.rest).toContain(`fix: cd ${bashPath(f.root)} && ./setup --host claude --no-prefix`);
|
||||
expect(r.trailer).toBe('gstack: fail claude');
|
||||
expect(JSON.parse(doctor(f, ['--json']).out).for).toBe('installed-hosts:none(claude required)');
|
||||
});
|
||||
|
||||
test('wrong host: an install registered from another checkout does not count; --require names what is missing', () => {
|
||||
const f = makeFixture();
|
||||
const other = path.join(f.base, 'other');
|
||||
write(path.join(f.state, 'installs.tsv'), ['codex', 'global', '-', path.join(f.home, '.codex/skills'), other, other, VERSION, 'false', 'committed', 'x'].join('\t') + '\n');
|
||||
const r = row(f, ['--require', 'codex,patch']);
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.rows.codex.status).toBe('FAIL');
|
||||
expect(r.rows.patch.status).toBe('FAIL');
|
||||
expect(r.rows.claude.status).toBe('SKIP');
|
||||
expect(r.trailer).toBe('gstack: fail codex,patch');
|
||||
expect(JSON.parse(doctor(f, ['--json', '--require', 'codex,patch']).out).for).toBe('codex,patch');
|
||||
});
|
||||
|
||||
test('missing authentication: --for codex needs the CLI; absent, unauthenticated and present are told apart, --live probes once', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
const unauthed = row(f, ['--for', 'codex'], { STUB_AUTH_FAIL: '1' });
|
||||
expect(unauthed.status).toBe(1);
|
||||
expect(unauthed.rows['codex-cli'].status).toBe('FAIL');
|
||||
expect(unauthed.rows['codex-cli'].rest).toContain('not authenticated');
|
||||
expect(unauthed.rows['codex-cli'].rest).toContain('codex login --with-api-key');
|
||||
expect(unauthed.trailer).toBe('gstack: fail codex-cli');
|
||||
|
||||
const authed = row(f, ['--for', 'codex']);
|
||||
expect(authed.status, authed.out).toBe(0);
|
||||
expect(authed.rows['codex-cli'].rest).toContain('paid probe not run; add --live');
|
||||
expect(probeCalls(f)).not.toContain('probe-model');
|
||||
|
||||
const live = row(f, ['--for', 'codex', '--live']);
|
||||
expect(live.status, live.out).toBe(0);
|
||||
expect(live.rows['codex-cli'].rest).toContain('live probe ok');
|
||||
expect(probeCalls(f).match(/probe-model exec/g)?.length).toBe(1);
|
||||
|
||||
fs.rmSync(path.join(f.stub, 'codex'));
|
||||
const absent = row(f, ['--for', 'codex']);
|
||||
expect(absent.rows['codex-cli'].status).toBe('FAIL');
|
||||
expect(absent.rows['codex-cli'].rest).toContain('npm install -g @openai/codex');
|
||||
});
|
||||
|
||||
test('runtime mismatch: the supported minimum (1.4.2) and the floor (1.3.3) both FAIL in --check', () => {
|
||||
const f = makeFixture();
|
||||
const untested = row(f, [], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(untested.status).toBe(1);
|
||||
expect(untested.rows.runtime.status).toBe('FAIL');
|
||||
expect(untested.rows.runtime.rest).toContain('below the supported minimum 1.4.2');
|
||||
expect(untested.rows.runtime.rest).toContain('(RUNTIME_BELOW_MINIMUM; ');
|
||||
expect(untested.trailer).toBe('gstack: fail runtime');
|
||||
const old = row(f, [], { STUB_BUN_VERSION: '1.3.2' });
|
||||
expect(old.rows.runtime.rest).toContain('below the security floor 1.3.3');
|
||||
expect(old.trailer).toBe('gstack: fail runtime');
|
||||
});
|
||||
|
||||
test('bun removed from PATH: the doctor still reports, runtime FAILs, pins SKIPs with a reason, one trailer', () => {
|
||||
const f = makeFixture();
|
||||
fs.rmSync(path.join(f.stub, 'bun'));
|
||||
const r = row(f, []);
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.rows.runtime.status).toBe('FAIL');
|
||||
expect(r.rows.runtime.rest).toContain('bun not found on PATH');
|
||||
expect(r.rows.pins).toEqual({ status: 'SKIP', rest: expect.stringContaining('no bun to evaluate the project pins') });
|
||||
expect(r.rows.claude.status).toBe('PASS');
|
||||
expect(r.trailer).toBe('gstack: fail runtime');
|
||||
expect(r.trailers).toBe(1);
|
||||
});
|
||||
|
||||
test('project pins: --project reads the target repository, a range mismatch FAILs with its source, a match PASSes', () => {
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
write(path.join(project, 'package.json'), '{\n "engines": {\n "bun": ">=1.4.2"\n }\n}\n');
|
||||
const bad = row(f, ['--project', project], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(bad.rows.pins.status).toBe('FAIL');
|
||||
expect(bad.rows.pins.rest).toContain('bun 1.3.14 outside engines.bun >=1.4.2 (package.json:3)');
|
||||
expect(bad.rows.pins.rest).toContain('(PROJECT_PIN_MISMATCH; ');
|
||||
expect(bad.trailer).toBe('gstack: fail runtime,pins');
|
||||
const good = row(f, ['--project', project]);
|
||||
expect(good.rows.pins).toEqual({ status: 'PASS', rest: `${project}: bun >=1.4.2 (engines.bun, package.json:3)` });
|
||||
const none = row(f, ['--project', f.work]);
|
||||
expect(none.rows.pins.status).toBe('PASS');
|
||||
expect(none.rows.pins.rest).toContain('pins no runtime');
|
||||
const missing = row(f, ['--project', path.join(f.base, 'nope')]);
|
||||
expect(missing.rows.pins.status).toBe('SKIP');
|
||||
});
|
||||
|
||||
test('project pins on Capy: the PROJECT_PIN_MISMATCH fix is the exact bootstrapper command, which installs a verified pinned Bun', () => {
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
write(path.join(project, 'package.json'), '{\n "engines": {\n "bun": ">=1.4.2"\n }\n}\n');
|
||||
const wrapper = '/drive/skills/gstack/scripts/install.sh';
|
||||
const capy = row(f, ['--project', project], { STUB_BUN_VERSION: '1.3.14', GSTACK_CAPY_WRAPPER_PATH: wrapper });
|
||||
expect(capy.rows.pins.status).toBe('FAIL');
|
||||
expect(capy.rows.pins.rest).toContain(`fix: bash ${wrapper} (installs the project's pinned Bun when it is a verified version: 1.4.2 1.4.3 1.4.4; otherwise it names the conflict), or change the pin in ${project}`);
|
||||
expect(capy.rows.pins.rest).toContain('(PROJECT_PIN_MISMATCH; ');
|
||||
const forSkill = row(f, ['--project', project, '--for', 'review'], { STUB_BUN_VERSION: '1.3.14', GSTACK_CAPY_WRAPPER_PATH: wrapper });
|
||||
expect(forSkill.rows.pins.rest).toContain(`fix: bash ${wrapper} --for review (installs`);
|
||||
const plain = row(f, ['--project', project], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(plain.rows.pins.rest).toContain('fix: install the pinned version for this platform');
|
||||
expect(plain.rows.pins.rest).not.toContain(wrapper);
|
||||
});
|
||||
|
||||
test('project pins: a Node-only pin mismatch is a WARN (the trailer stays ok) that names the node it read and a fix that installs the pinned Node', () => {
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
write(path.join(project, '.github/workflows/native-locks.yml'), 'jobs:\n locks:\n steps:\n - uses: actions/setup-node@v4\n with:\n node-version: 24.18.0\n');
|
||||
script(path.join(f.stub, 'node'), ['echo v24.21.0']);
|
||||
const wrapper = '/drive/skills/gstack/scripts/install.sh';
|
||||
const capy = row(f, ['--project', project, '--for', 'health'], { GSTACK_CAPY_WRAPPER_PATH: wrapper });
|
||||
expect(capy.rows.pins.status).toBe('WARN');
|
||||
expect(capy.rows.pins.rest).toContain(`node 24.21.0 outside CI 24.18.0 (.github/workflows/native-locks.yml:6); node read from ${bashPath(f.stub)}/node (node pin only; bun pins pass)`);
|
||||
expect(capy.rows.pins.rest).toContain(`fix: bash ${wrapper} --for health (installs the project's pinned Node 24.18.0 into gstack's runtime store and launches it through the GSTACK_LAUNCH PATH), or change the pin in ${project}`);
|
||||
expect(capy.rows.pins.rest).toContain('(PROJECT_NODE_PIN_UNMET; ');
|
||||
expect(capy.trailer).toBe(`gstack: ok ${VERSION} for=health`);
|
||||
const plain = row(f, ['--project', project, '--for', 'health']);
|
||||
expect(plain.rows.pins.rest).toContain(`fix: nvm install 24.18.0 and put its bin directory first on PATH`);
|
||||
// A Bun pin that also fails keeps the FAIL and its code: only a Node-only gap is advisory.
|
||||
write(path.join(project, 'package.json'), '{\n "engines": {\n "bun": ">=1.4.2"\n }\n}\n');
|
||||
const both = row(f, ['--project', project, '--for', 'health'], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(both.rows.pins.status).toBe('FAIL');
|
||||
expect(both.rows.pins.rest).toContain('(PROJECT_PIN_MISMATCH; ');
|
||||
fs.rmSync(path.join(project, 'package.json'));
|
||||
script(path.join(f.stub, 'node'), ['echo v24.18.0']);
|
||||
expect(row(f, ['--project', project, '--for', 'health']).rows.pins.status).toBe('PASS');
|
||||
});
|
||||
|
||||
test('floor: min_gstack_version in the project\'s .gstack/ship-policy.json PASSes at or below the installed version, WARNs above it with the upgrade as the fix, and SKIPs when absent or null', () => {
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
fs.mkdirSync(project, { recursive: true });
|
||||
const none = row(f, ['--project', project]);
|
||||
expect(none.rows.floor).toEqual({ status: 'SKIP', rest: `(${project} declares none (.gstack/ship-policy.json absent; set min_gstack_version there to require a gstack version))` });
|
||||
write(path.join(project, '.gstack/ship-policy.json'), '{\n "bump": "patch",\n "min_gstack_version": null\n}\n');
|
||||
expect(row(f, ['--project', project]).rows.floor).toEqual({ status: 'SKIP', rest: `(${project}/.gstack/ship-policy.json sets no min_gstack_version (null or absent))` });
|
||||
// A present value that is not a dotted version is named as such, never read as "absent"; the shell never evaluates it.
|
||||
const marker = path.join(project, 'evaluated-marker');
|
||||
write(path.join(project, '.gstack/ship-policy.json'), `{\n "min_gstack_version": "1.2.3-rc1; $(touch ${marker})"\n}\n`);
|
||||
expect(row(f, ['--project', project]).rows.floor).toEqual({ status: 'SKIP', rest: `(${project}/.gstack/ship-policy.json sets min_gstack_version to something other than a plain dotted version)` });
|
||||
expect(fs.existsSync(marker)).toBe(false);
|
||||
write(path.join(project, '.gstack/ship-policy.json'), `{\n "min_gstack_version": "${VERSION}"\n}\n`);
|
||||
const met = row(f, ['--project', project]);
|
||||
expect(met.rows.floor).toEqual({ status: 'PASS', rest: `${VERSION} declared by ${project}/.gstack/ship-policy.json (installed ${VERSION})` });
|
||||
// Valid JSON may put the value on the line after its field (found by Codex in /ship's adversarial review).
|
||||
write(path.join(project, '.gstack/ship-policy.json'), `{\n "bump": "patch",\n "min_gstack_version":\n "${VERSION}"\n}\n`);
|
||||
expect(row(f, ['--project', project]).rows.floor.status).toBe('PASS');
|
||||
// The first occurrence is the top-level field: a later nested one never lowers the floor (found by Codex).
|
||||
write(path.join(project, '.gstack/ship-policy.json'), '{\n "min_gstack_version": "999.0.0.0",\n "$schema": {"min_gstack_version": "0.0.0"}\n}\n');
|
||||
expect(row(f, ['--project', project]).rows.floor.status).toBe('WARN');
|
||||
write(path.join(project, '.gstack/ship-policy.json'), '{\n "min_gstack_version": "999.0.0.0"\n}\n');
|
||||
const wrapper = '/drive/skills/gstack/scripts/install.sh';
|
||||
const unmet = row(f, ['--project', project, '--for', 'health'], { GSTACK_CAPY_WRAPPER_PATH: wrapper });
|
||||
expect(unmet.status, unmet.out).toBe(0);
|
||||
expect(unmet.rows.floor.status).toBe('WARN');
|
||||
expect(unmet.rows.floor.rest).toContain(`installed ${VERSION} is below the floor 999.0.0.0 that ${project}/.gstack/ship-policy.json declares (min_gstack_version); fix: bash ${wrapper} --for health (fast-forwards a clean checkout to origin and reinstalls), or `);
|
||||
expect(unmet.rows.floor.rest).toContain('(PROJECT_FLOOR_UNMET; ');
|
||||
expect(unmet.trailer).toBe(`gstack: ok ${VERSION} for=health`);
|
||||
const plain = row(f, ['--project', project]);
|
||||
expect(plain.rows.floor.rest).toContain('fix: ');
|
||||
expect(plain.rows.floor.rest).toContain('bin/gstack-upgrade (fast-forwards to the remote default branch');
|
||||
expect(plain.rows.floor.rest).not.toContain(wrapper);
|
||||
});
|
||||
|
||||
test('--revision: a matching VERSION passes, an unmet revision is never ok', () => {
|
||||
const f = makeFixture();
|
||||
const ok = row(f, ['--revision', VERSION]);
|
||||
expect(ok.status, ok.out).toBe(0);
|
||||
expect(ok.rows.revision.status).toBe('PASS');
|
||||
const unmet = row(f, ['--revision', 'v9.9.9.9']);
|
||||
expect(unmet.status).toBe(1);
|
||||
expect(unmet.rows.revision.status).toBe('FAIL');
|
||||
expect(unmet.rows.revision.rest).toContain(`installed ${VERSION}`);
|
||||
expect(unmet.rows.revision.rest).toContain('(requested v9.9.9.9)');
|
||||
expect(unmet.rows.revision.rest).toContain('(REVISION_UNMET; ');
|
||||
expect(unmet.trailer).toBe('gstack: fail revision');
|
||||
});
|
||||
|
||||
test('browser skills: the bundle and a Chromium launch plus render are required; planning skills never launch it', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
installPlaywrightStub(f, false);
|
||||
const broken = row(f, ['--for', 'qa']);
|
||||
expect(broken.status).toBe(1);
|
||||
expect(broken.rows['browse-bundle'].status).toBe('PASS');
|
||||
expect(broken.rows.browser.status).toBe('FAIL');
|
||||
expect(broken.rows.browser.rest).toContain("Executable doesn't exist");
|
||||
expect(broken.rows.browser.rest).toContain(`fix: ${bashPath(f.root)}/bin/gstack-browser-ensure (BROWSER_UNAVAILABLE; `);
|
||||
expect(broken.trailer).toBe('gstack: fail browser');
|
||||
installPlaywrightStub(f, true);
|
||||
const ok = row(f, ['--for', 'qa']);
|
||||
expect(ok.status, ok.out).toBe(0);
|
||||
expect(ok.rows.browser).toEqual({ status: 'PASS', rest: 'Chromium 141.0.1 launched and rendered (node)' });
|
||||
fs.rmSync(path.join(f.root, BROWSE_BIN));
|
||||
const noBundle = row(f, ['--for', 'browse']);
|
||||
expect(noBundle.rows['browse-bundle'].status).toBe('FAIL');
|
||||
expect(noBundle.rows['browse-bundle'].rest).toContain('fix: cd ');
|
||||
installPlaywrightStub(f, false);
|
||||
expect(row(f, ['--for', 'autoplan']).rows.browser.status).toBe('SKIP');
|
||||
});
|
||||
|
||||
test('cso: optional by default (SKIP, never silent), required by --for cso', () => {
|
||||
const f = makeFixture();
|
||||
expect(row(f, []).rows.cso).toEqual({ status: 'SKIP', rest: '(optional; toolchain absent or helper not built)' });
|
||||
const r = row(f, ['--for', 'cso']);
|
||||
expect(r.rows.cso.status).toBe('FAIL');
|
||||
expect(r.trailer).toBe('gstack: fail cso');
|
||||
for (const name of ['gstack-cso-launcher', 'gstack-cso-core']) write(path.join(f.root, 'bin', name + EXE), '#!/bin/sh\necho cso\n', 0o755);
|
||||
expect(row(f, ['--for', 'cso']).rows.cso.status).toBe('PASS');
|
||||
});
|
||||
|
||||
test('state root: GSTACK_EPHEMERAL=1 reports durable=no in --check (PASS) and warns in the dashboard', () => {
|
||||
const f = makeFixture();
|
||||
const r = row(f, [], { GSTACK_EPHEMERAL: '1' });
|
||||
expect(r.rows['state-root'].status).toBe('PASS');
|
||||
expect(r.rows['state-root'].rest).toContain(`${f.state} durable=no`);
|
||||
expect(r.rows['state-root'].rest).toContain('GSTACK_EPHEMERAL=1');
|
||||
expect(r.status, r.out).toBe(0);
|
||||
const dash = doctor(f, [], { GSTACK_EPHEMERAL: '1' });
|
||||
expect(dash.row('state root').state).toBe('warn');
|
||||
expect(dash.row('state root').detail).toContain('durable=no');
|
||||
expect(dash.row('state root').fix).toContain('GSTACK_STATE_ROOT');
|
||||
expect(doctor(f).row('state root').detail).toContain('durable=yes');
|
||||
});
|
||||
|
||||
test('--json: the same rows as objects keyed by the component ids, ok/failed/required and the trailer', () => {
|
||||
const f = makeFixture();
|
||||
installCodex(f);
|
||||
const r = doctor(f, ['--json', '--for', 'autoplan'], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(r.status).toBe(1);
|
||||
const json = JSON.parse(r.out.trim().split('\n').at(-1)!);
|
||||
expect(json.schema_version).toBe(1);
|
||||
expect(json.revision).toBe(VERSION);
|
||||
expect(json.for).toBe('autoplan');
|
||||
expect(json.ok).toBe(false);
|
||||
expect(json.failed).toEqual(['runtime']);
|
||||
expect(json.required).toEqual(['claude', 'codex', 'patch', 'runtime', 'pins', 'state-root', 'privacy', 'cores', 'revision', 'floor', 'wrapper']);
|
||||
expect(json.rows.map((x: { id: string }) => x.id)).toEqual(['claude', 'codex', 'patch', 'codex-cli', 'browse-bundle', 'browser', 'cso', 'helpers', 'runtime', 'pins', 'state-root', 'privacy', 'cores', 'revision', 'floor', 'wrapper']);
|
||||
const runtime = json.rows.find((x: { id: string }) => x.id === 'runtime');
|
||||
expect(runtime.status).toBe('FAIL');
|
||||
expect(runtime.code).toBe('RUNTIME_BELOW_MINIMUM');
|
||||
expect(runtime.anchor).toBe('doctor-runtime-below-minimum');
|
||||
expect(runtime.fix).toContain('gstack-capy-install');
|
||||
expect(json.trailer).toBe('gstack: fail runtime');
|
||||
expect(r.out.trim().split('\n')).toHaveLength(1);
|
||||
const ok = JSON.parse(doctor(f, ['--json']).out.trim());
|
||||
expect(ok.ok).toBe(true);
|
||||
expect(ok.trailer).toBe(`gstack: ok ${VERSION} for=installed-hosts:claude,codex`);
|
||||
});
|
||||
|
||||
test('usage: --for with --require, an unknown skill or component, and a flag without a value exit 2', () => {
|
||||
const f = makeFixture();
|
||||
expect(doctor(f, ['--check', '--for', 'autoplan', '--require', 'claude']).status).toBe(2);
|
||||
expect(doctor(f, ['--for', 'no-such-skill']).status).toBe(2);
|
||||
expect(doctor(f, ['--require', 'claude,bogus']).status).toBe(2);
|
||||
expect(doctor(f, ['--check', '--project']).status).toBe(2);
|
||||
expect(doctor(f, ['--help']).out).toContain('--check');
|
||||
});
|
||||
});
|
||||
|
||||
// Field wave lane A: the trailer agrees with the Bun workflows run (A3), a
|
||||
// remote minimum fails the revision row (A2), and planning-only workflows do
|
||||
// not fail on a repo test-pin mismatch (A3 amendment).
|
||||
describe('gstack-doctor --check: launch Bun, supported minimum, planning-only pins', () => {
|
||||
const VERSION = fs.readFileSync(path.join(REPO, 'VERSION'), 'utf8').trim();
|
||||
const check = (f: Fixture, args: string[], extra: Record<string, string> = {}) => {
|
||||
const r = doctor(f, ['--check', ...args], extra);
|
||||
const lines = r.out.split('\n');
|
||||
const rows = Object.fromEntries(lines.filter(l => /^(PASS|FAIL|SKIP|WARN) /.test(l)).map(l => {
|
||||
const m = l.match(/^(PASS|FAIL|SKIP|WARN) ([a-z-]+)(?:\s(.*))?$/)!;
|
||||
return [m[2], { status: m[1], rest: m[3] ?? '' }];
|
||||
}));
|
||||
return { status: r.status, out: r.out, rows, trailer: lines.filter(l => l.startsWith('gstack: ')).at(-1) ?? '' };
|
||||
};
|
||||
/** A verified Bun in $HOME/.bun/bin (off PATH) that answers --version and runs TypeScript. */
|
||||
const verifiedBun = (f: Fixture, version = '1.4.2') =>
|
||||
script(path.join(f.home, '.bun/bin/bun'), [`[ "$1" = --version ] && { echo "${version}"; exit 0; }`, `exec "${process.execPath}" "$@"`]);
|
||||
|
||||
test('PATH Bun 1.3.14 with a verified 1.4.2 off PATH: runtime FAILs naming where it was found; with the launch PATH it PASSes', () => {
|
||||
const f = makeFixture();
|
||||
verifiedBun(f);
|
||||
const fresh = check(f, [], { STUB_BUN_VERSION: '1.3.14' });
|
||||
expect(fresh.rows.runtime.status).toBe('FAIL');
|
||||
const home = bashPath(f.home);
|
||||
expect(fresh.rows.runtime.rest).toContain(`bun 1.4.2 found at ${home}/.bun/bin (not on PATH)`);
|
||||
expect(fresh.rows.runtime.rest).toContain(`fix: export PATH="${home}/.bun/bin:$PATH" or prefix commands with the GSTACK_LAUNCH line`);
|
||||
expect(fresh.rows.runtime.rest).toContain('(RUNTIME_BELOW_MINIMUM; ');
|
||||
const launched = check(f, [], { STUB_BUN_VERSION: '1.3.14', PATH: `${f.home}/.bun/bin${path.delimiter}${f.env.PATH}` });
|
||||
expect(launched.rows.runtime.status, launched.out).toBe('PASS');
|
||||
expect(launched.rows.runtime.rest).toContain(`at ${home}/.bun/bin/bun`);
|
||||
});
|
||||
|
||||
test('--min-revision: below FAILs with REVISION_BELOW_MINIMUM naming the upgrade command; at or above PASSes; unknown says so and never claims the minimum', () => {
|
||||
const f = makeFixture();
|
||||
const below = check(f, ['--min-revision', '99.0.0.0']);
|
||||
expect(below.status).toBe(1);
|
||||
expect(below.rows.revision.status).toBe('FAIL');
|
||||
expect(below.rows.revision.rest).toContain(`installed ${VERSION}`);
|
||||
expect(below.rows.revision.rest).toContain('below the supported minimum 99.0.0.0');
|
||||
expect(below.rows.revision.rest).toContain(`${bashPath(f.root)}/bin/gstack-upgrade`);
|
||||
expect(below.rows.revision.rest).toContain('(REVISION_BELOW_MINIMUM; ');
|
||||
expect(below.trailer).toBe('gstack: fail revision');
|
||||
const wrapped = check(f, ['--min-revision', '99.0.0.0'], { GSTACK_CAPY_WRAPPER_PATH: '/drive/skills/gstack/scripts/install.sh' });
|
||||
expect(wrapped.rows.revision.rest).toContain('fix: bash /drive/skills/gstack/scripts/install.sh (fast-forwards)');
|
||||
const at = check(f, ['--min-revision', VERSION]);
|
||||
expect(at.rows.revision.status, at.out).toBe('PASS');
|
||||
expect(at.rows.revision.rest).toContain(`>= supported minimum ${VERSION}`);
|
||||
const unknown = check(f, ['--min-revision', 'unknown']);
|
||||
expect(unknown.rows.revision.status).toBe('PASS');
|
||||
expect(unknown.rows.revision.rest).toContain('remote minimum unknown (fetch failed)');
|
||||
expect(unknown.rows.revision.rest).not.toContain('>= supported minimum');
|
||||
});
|
||||
|
||||
test('planning-only workflows SKIP a repo test-pin mismatch; test-running workflows and --require keep pins required', () => {
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
write(path.join(project, '.bun-version'), '1.4.2\n');
|
||||
const planning = check(f, ['--for', 'autoplan', '--project', project], { STUB_BUN_VERSION: '1.4.3' });
|
||||
expect(planning.rows.pins.status, planning.out).toBe('SKIP');
|
||||
expect(planning.rows.pins.rest).toMatch(/^\(planning-only; repo pins .*1\.4\.2.*, launch bun 1\.4\.3\)$/);
|
||||
for (const args of [['--for', 'review'], ['--for', 'ship'], ['--require', 'claude']]) {
|
||||
const tests = check(f, [...args, '--project', project], { STUB_BUN_VERSION: '1.4.3' });
|
||||
expect(tests.rows.pins.status, args.join(' ')).toBe('FAIL');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Plan A8/A-h: the Capy skill copy. Active-wrapper provenance decides; without
|
||||
// it the Drive copies do, failing only when every copy is stale. The printed
|
||||
// workaround (the checkout's own wrapper) certifies with the stale Drive copy
|
||||
// left unchanged. Plan A5: a drifted resolution is a runtime FAIL.
|
||||
describe('gstack-doctor --check: wrapper and runtime drift', () => {
|
||||
const posixPathTest = process.platform === 'win32' ? test.skip : test;
|
||||
const PRE_BOOTSTRAPPER = '#!/usr/bin/env bash\n# gstack Capy skill installer (pre-bootstrapper)\nset -u\nroot="${GSTACK_CAPY_ROOT:-$HOME/.local/share/gstack}"\nexec "$root/bin/gstack-capy-install" "$@"\n';
|
||||
const parse = (f: Fixture, args: string[], extra: Record<string, string> = {}) => {
|
||||
const r = doctor(f, ['--check', ...args], extra);
|
||||
const line = (id: string) => r.out.split('\n').find(l => new RegExp(`^(PASS|FAIL|SKIP|WARN) ${id}\\b`).test(l)) ?? '';
|
||||
return { status: r.status, out: r.out, line, trailer: r.out.split('\n').filter(l => l.startsWith('gstack: ')).at(-1) ?? '' };
|
||||
};
|
||||
const drive = (f: Fixture, scope: string, text: string) => { const file = path.join(f.home, '.capy/drive', scope, 'skills/gstack/scripts/install.sh'); write(file, text); return file; };
|
||||
const withSupport = (f: Fixture, min = 1) => write(path.join(f.root, 'capy/support.env'), `GSTACK_MIN_REVISION=1.0.0.0\nGSTACK_CAPY_MIN_WRAPPER=${min}\n`);
|
||||
const current = fs.readFileSync(path.join(REPO, 'capy/skill/gstack/scripts/install.sh'), 'utf8');
|
||||
const currentRev = current.match(/^GSTACK_CAPY_WRAPPER=(\d+)$/m)![1];
|
||||
|
||||
posixPathTest('direct doctor run: a pre-bootstrapper Drive copy (no revision line) fails wrapper with both fixes; a current copy is not flagged', () => {
|
||||
const f = makeFixture();
|
||||
withSupport(f);
|
||||
const stale = drive(f, 'user-garry-tan', PRE_BOOTSTRAPPER);
|
||||
const r = parse(f, []);
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.trailer).toBe('gstack: fail wrapper');
|
||||
const row = r.line('wrapper');
|
||||
expect(row).toContain(`FAIL wrapper — every Capy skill copy is stale (minimum wrapper 1): ${stale} (wrapper 0); fix: bash ${f.root}/capy/skill/gstack/scripts/install.sh --check (this session); owner: copy ${f.root}/capy/skill/gstack/ over the Drive skill folder, or have Capy re-sync it; this recurs every session until the Drive copy changes`);
|
||||
expect(row).toContain('(CAPY_WRAPPER_STALE; https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#capy-wrapper-stale)');
|
||||
write(stale, current);
|
||||
const fresh = parse(f, []);
|
||||
expect(fresh.line('wrapper')).toBe(`PASS wrapper Drive copy ${stale} (wrapper ${currentRev}) (minimum 1)`);
|
||||
expect(fresh.status, fresh.out).toBe(0);
|
||||
});
|
||||
|
||||
posixPathTest('direct doctor run: a bootstrapper Drive copy below the minimum still works, so it is an owner-action WARN with an ok trailer (only a pre-bootstrapper copy fails)', () => {
|
||||
const f = makeFixture();
|
||||
withSupport(f, Number(currentRev) + 1);
|
||||
const old = drive(f, 'user-garry-tan', current);
|
||||
const r = parse(f, []);
|
||||
expect(r.status, r.out).toBe(0);
|
||||
expect(r.trailer).toMatch(/^gstack: ok /);
|
||||
expect(r.line('wrapper')).toBe(`WARN wrapper — every Capy skill copy is below the minimum wrapper ${Number(currentRev) + 1} (it still works): ${old} (wrapper ${currentRev}); owner action: copy ${f.root}/capy/skill/gstack/ over the Drive skill folder, or have Capy re-sync it; this recurs every session until the Drive copy changes (CAPY_WRAPPER_STALE; https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#capy-wrapper-stale)`);
|
||||
const json = JSON.parse(doctor(f, ['--check', '--json']).out);
|
||||
expect(json.ok).toBe(true);
|
||||
expect(json.rows.find((x: { id: string }) => x.id === 'wrapper')).toMatchObject({ status: 'WARN', code: 'CAPY_WRAPPER_STALE' });
|
||||
// A pre-bootstrapper copy beside it keeps the FAIL: that copy cannot hand over at all.
|
||||
drive(f, 'org', PRE_BOOTSTRAPPER);
|
||||
expect(parse(f, []).trailer).toBe('gstack: fail wrapper');
|
||||
});
|
||||
|
||||
posixPathTest('two Drive copies, one current: PASS naming the stale one; GSTACK_CAPY_WRAPPER_PATH alone decides when set without a revision', () => {
|
||||
const f = makeFixture();
|
||||
withSupport(f);
|
||||
const stale = drive(f, 'org', PRE_BOOTSTRAPPER);
|
||||
const good = drive(f, 'user', current);
|
||||
const r = parse(f, []);
|
||||
expect(r.line('wrapper')).toBe(`PASS wrapper Drive copy ${good} (wrapper ${currentRev}) (minimum 1); stale copies: ${stale} (wrapper 0)`);
|
||||
expect(parse(f, [], { GSTACK_CAPY_WRAPPER_PATH: stale }).trailer).toBe('gstack: fail wrapper');
|
||||
});
|
||||
|
||||
posixPathTest('the printed workaround certifies: a current active wrapper passes with the stale Drive copy unchanged (WARN, owner action); a stale active wrapper is a WARN too', () => {
|
||||
const f = makeFixture();
|
||||
withSupport(f);
|
||||
const stale = drive(f, 'user-garry-tan', PRE_BOOTSTRAPPER);
|
||||
const checkoutCopy = path.join(f.root, 'capy/skill/gstack/scripts/install.sh');
|
||||
const r = parse(f, [], { GSTACK_CAPY_WRAPPER_REV: '1', GSTACK_CAPY_WRAPPER_PATH: checkoutCopy });
|
||||
expect(r.status, r.out).toBe(0);
|
||||
expect(r.trailer).toMatch(/^gstack: ok /);
|
||||
expect(r.line('wrapper')).toBe(`WARN wrapper — active wrapper 1 (${checkoutCopy}) is current; stale Drive copies (minimum 1): ${stale} (wrapper 0); owner action: copy ${f.root}/capy/skill/gstack/ over the Drive skill folder, or have Capy re-sync it; this recurs every session until the Drive copy changes (CAPY_WRAPPER_STALE; https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#capy-wrapper-stale)`);
|
||||
expect(fs.readFileSync(stale, 'utf8')).toBe(PRE_BOOTSTRAPPER);
|
||||
const json = JSON.parse(doctor(f, ['--check', '--json'], { GSTACK_CAPY_WRAPPER_REV: '1', GSTACK_CAPY_WRAPPER_PATH: checkoutCopy }).out);
|
||||
expect(json.ok).toBe(true);
|
||||
expect(json.rows.find((x: { id: string }) => x.id === 'wrapper')).toMatchObject({ status: 'WARN', code: 'CAPY_WRAPPER_STALE' });
|
||||
withSupport(f, 2);
|
||||
const old = parse(f, [], { GSTACK_CAPY_WRAPPER_REV: '1', GSTACK_CAPY_WRAPPER_PATH: stale });
|
||||
// Integration item 2: an active copy below the minimum still works, so it
|
||||
// is an owner-action WARN and the trailer stays ok.
|
||||
expect(old.status, old.out).toBe(0);
|
||||
expect(old.trailer).toMatch(/^gstack: ok /);
|
||||
expect(old.line('wrapper')).toBe(`WARN wrapper — the active Capy skill copy ${stale} is wrapper 1, minimum 2 (it still works); owner action: copy ${f.root}/capy/skill/gstack/ over the Drive skill folder, or have Capy re-sync it; this recurs every session until the Drive copy changes (CAPY_WRAPPER_STALE; https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#capy-wrapper-stale)`);
|
||||
});
|
||||
|
||||
test('a drifted Bun resolution is a runtime FAIL carrying the installer\'s detail, fix and BUN_RESOLUTION_DRIFT', () => {
|
||||
const f = makeFixture();
|
||||
const r = parse(f, [], { GSTACK_DOCTOR_RUNTIME_DRIFT: 'recorded bun 1.4.3 at /s/bun (home), now no eligible bun; changed: the recorded binary is gone', GSTACK_DOCTOR_RUNTIME_DRIFT_FIX: 'bash /d/install.sh --for review' });
|
||||
expect(r.trailer).toBe('gstack: fail runtime');
|
||||
expect(r.line('runtime')).toBe('FAIL runtime — bun resolution drifted: recorded bun 1.4.3 at /s/bun (home), now no eligible bun; changed: the recorded binary is gone; fix: bash /d/install.sh --for review (BUN_RESOLUTION_DRIFT; https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#bun-resolution-drift)');
|
||||
});
|
||||
|
||||
posixPathTest('the runtime row shows gstack\'s bun shim and where it resolves from here, or names a foreign ~/.local/bin/bun it left alone', () => {
|
||||
const f = makeFixture();
|
||||
const shim = path.join(f.home, '.local/bin/bun');
|
||||
write(shim, '#!/bin/sh\n# gstack-bun-shim: gstack-owned; delete this file to remove it\n[ "$GSTACK_BUN_SHIM_EXPLAIN" = 1 ] && echo "gstack bun shim: project=none record=none chose=/store/1.4.3/bun rule=default" >&2\necho 1.4.3\n', 0o755);
|
||||
expect(parse(f, []).line('runtime')).toContain(`; shim ${shim} -> /store/1.4.3/bun`);
|
||||
write(shim, '#!/bin/sh\necho mine\n', 0o755);
|
||||
expect(parse(f, []).line('runtime')).toContain(`; ${shim} is not gstack's shim (no marker), left untouched: launch with the GSTACK_LAUNCH line`);
|
||||
expect(parse(f, [], { GSTACK_BUN_INSTALL_VERSION: '1.4.2' }).line('runtime')).toContain('; install version 1.4.2 from GSTACK_BUN_INSTALL_VERSION');
|
||||
});
|
||||
|
||||
test('A-a: the Capy skill\'s dispatch examples (fail revision, fail runtime,pins, fail pins) match the real failure heads, unchanged', () => {
|
||||
const skill = fs.readFileSync(path.join(REPO, 'capy/skill/gstack/SKILL.md'), 'utf8');
|
||||
const step = skill.split('\n').find(l => l.includes('If the trailer names `revision`, `runtime` or `pins`'))!;
|
||||
const examples = [...step.matchAll(/`(gstack: fail [^`]+)`/g)].map(m => m[1]);
|
||||
expect(examples).toEqual(['gstack: fail revision …', 'gstack: fail runtime,pins', 'gstack: fail pins']);
|
||||
const f = makeFixture();
|
||||
const project = path.join(f.base, 'project');
|
||||
write(path.join(project, '.bun-version'), '1.4.2\n');
|
||||
const real: Record<string, string> = {
|
||||
revision: parse(f, ['--require', 'claude', '--min-revision', '99.0.0.0']).trailer,
|
||||
'runtime,pins': parse(f, ['--require', 'claude', '--project', project], { STUB_BUN_VERSION: '1.3.14' }).trailer,
|
||||
pins: parse(f, ['--require', 'claude', '--project', project], { STUB_BUN_VERSION: '1.4.3' }).trailer,
|
||||
};
|
||||
for (const example of examples) {
|
||||
const ids = example.slice('gstack: fail '.length).replace(/ …$/, '');
|
||||
const head = real[ids];
|
||||
expect(head === `gstack: fail ${ids}` || head.startsWith(`gstack: fail ${ids} — `), `${example} vs ${head}`).toBe(true);
|
||||
expect(head.match(/^gstack: fail ([a-z,-]+)/)?.[1].split(',')).toEqual(ids.split(','));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Lane F item D: the plain report lists rescue refs with their commands, warns
|
||||
// about a CLAUDE.md gstack section that enumerates skills (#3169), and on
|
||||
// Windows names the bash gstack's TypeScript hands its scripts to. GSTACK_DOCTOR_PLATFORM
|
||||
// injects the platform and GSTACK_DOCTOR_BASH_PROBE the discovery inputs, so
|
||||
// every case runs on every OS.
|
||||
describe('gstack-doctor: rescue refs, CLAUDE.md skill lists, Windows bash', () => {
|
||||
const git = (f: Fixture, args: string[], extra: Record<string, string> = {}) => {
|
||||
const r = spawnSync('git', args, {
|
||||
cwd: f.root, encoding: 'utf8', timeout: 20_000,
|
||||
env: { ...process.env, HOME: f.home, GIT_CONFIG_NOSYSTEM: '1', GIT_AUTHOR_NAME: 'fixture', GIT_AUTHOR_EMAIL: 'fixture@example.com', GIT_COMMITTER_NAME: 'fixture', GIT_COMMITTER_EMAIL: 'fixture@example.com', ...extra },
|
||||
});
|
||||
if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
|
||||
return r.stdout.trim();
|
||||
};
|
||||
/** A git install with one rescue commit per entry: a user edit on top of HEAD, committed on the given date. */
|
||||
const withRescues = (f: Fixture, rescues: Array<{ date: string; unmerged?: boolean }>) => {
|
||||
git(f, ['init', '-q']);
|
||||
git(f, ['add', '-A']);
|
||||
git(f, ['commit', '-qm', 'release']);
|
||||
const index = path.join(f.base, 'rescue.idx');
|
||||
return rescues.map(({ date, unmerged }, i) => {
|
||||
const blob = spawnSync('git', ['hash-object', '-w', '--stdin'], { cwd: f.root, input: `edit ${i}\n`, encoding: 'utf8', timeout: 20_000 }).stdout.trim();
|
||||
git(f, ['read-tree', 'HEAD'], { GIT_INDEX_FILE: index });
|
||||
git(f, ['update-index', '--add', '--cacheinfo', `100644,${blob},local-edit-${i}.txt`], { GIT_INDEX_FILE: index });
|
||||
const tree = git(f, ['write-tree'], { GIT_INDEX_FILE: index });
|
||||
const message = `gstack rescue: local edits that conflicted with abc\n${unmerged ? '\nNeeds manual resolution: the install had unmerged files; their captured\ncontent may contain conflict markers.\n' : ''}`;
|
||||
const oid = spawnSync('git', ['commit-tree', tree, '-p', 'HEAD'], {
|
||||
cwd: f.root, input: message, encoding: 'utf8', timeout: 20_000,
|
||||
env: { ...process.env, HOME: f.home, GIT_CONFIG_NOSYSTEM: '1', GIT_AUTHOR_NAME: 'gstack rescue', GIT_AUTHOR_EMAIL: 'gstack@localhost', GIT_COMMITTER_NAME: 'gstack rescue', GIT_COMMITTER_EMAIL: 'gstack@localhost', GIT_AUTHOR_DATE: date, GIT_COMMITTER_DATE: date },
|
||||
}).stdout.trim();
|
||||
git(f, ['update-ref', `refs/gstack/rescue/${oid}`, oid]);
|
||||
return `refs/gstack/rescue/${oid}`;
|
||||
});
|
||||
};
|
||||
const rescueRefs = (f: Fixture) => git(f, ['for-each-ref', '--format=%(refname)', 'refs/gstack/rescue/']).split('\n').filter(Boolean);
|
||||
const commandFor = (out: string, label: 'inspect' | 'delete', ref: string) =>
|
||||
out.split('\n').map(l => l.trim()).find(l => l.startsWith(`${label}:`) && l.includes(`'${ref}'`))?.replace(/^[a-z]+:\s+/, '') ?? '';
|
||||
|
||||
test('rescue refs: two refs are listed newest first with their dates; the printed inspect command shows the edit and the printed delete command removes the ref', () => {
|
||||
const f = makeFixture();
|
||||
const [older, newer] = withRescues(f, [{ date: '2026-10-01T12:00:00Z' }, { date: '2026-10-14T08:30:00Z', unmerged: true }]);
|
||||
const r = doctor(f);
|
||||
const row = r.row('rescue refs');
|
||||
expect(row.state, r.out).toBe('warn');
|
||||
expect(row.detail).toContain(`2 in ${bashPath(f.root)}`);
|
||||
expect(row.fix).toContain('#auto-update-rescued-edits');
|
||||
const listing = r.out.split('\n').map(l => l.trim());
|
||||
expect(listing.findIndex(l => l.startsWith(newer))).toBeLessThan(listing.findIndex(l => l.startsWith(older)));
|
||||
expect(listing).toContain(`${older} (2026-10-01)`);
|
||||
expect(listing).toContain(`${newer} (2026-10-14, needs manual resolution)`);
|
||||
const q = `'${bashPath(f.root)}'`;
|
||||
expect(commandFor(r.out, 'inspect', older)).toBe(`git -C ${q} diff '${older}^' '${older}'`);
|
||||
expect(commandFor(r.out, 'delete', older)).toBe(`git -C ${q} update-ref -d '${older}'`);
|
||||
const shown = spawnSync('bash', ['-c', commandFor(r.out, 'inspect', older)], { cwd: f.work, encoding: 'utf8', timeout: 20_000 });
|
||||
expect(shown.status, shown.stderr).toBe(0);
|
||||
expect(shown.stdout).toContain('+edit 0');
|
||||
const deleted = spawnSync('bash', ['-c', commandFor(r.out, 'delete', older)], { cwd: f.work, encoding: 'utf8', timeout: 20_000 });
|
||||
expect(deleted.status, deleted.stderr).toBe(0);
|
||||
expect(rescueRefs(f)).toEqual([newer]);
|
||||
expect(doctor(f).row('rescue refs').detail).toContain(`1 in ${bashPath(f.root)}`);
|
||||
spawnSync('bash', ['-c', commandFor(r.out, 'delete', newer)], { cwd: f.work, encoding: 'utf8', timeout: 20_000 });
|
||||
const none = doctor(f);
|
||||
expect(none.row('rescue refs')).toEqual({ state: 'ok', detail: `none in ${bashPath(f.root)}`, fix: '' });
|
||||
expect(none.status, none.out).toBe(0);
|
||||
});
|
||||
|
||||
const LISTING = '## gstack\nUse /browse from gstack for all web browsing. Never use mcp__claude-in-chrome__* tools.\nAvailable skills: /office-hours, /plan-ceo-review, /plan-eng-review, /plan-design-review,\n/design-consultation, /design-shotgun, /design-html, /review, /ship, /qa, /browse, /retro, /investigate.\n';
|
||||
const SHORT = '## gstack\nUse /browse from gstack for all web browsing. Never use mcp__claude-in-chrome__* tools.\n';
|
||||
const replacement = (out: string) => out.split('\n').filter(l => l.startsWith(' '.repeat(34))).map(l => l.slice(34));
|
||||
|
||||
test('CLAUDE.md: a gstack section that enumerates skills warns with the short replacement block, for ~/.claude/CLAUDE.md and the project CLAUDE.md', () => {
|
||||
const f = makeFixture();
|
||||
const user = path.join(f.home, '.claude/CLAUDE.md');
|
||||
write(user, `# Me\n\n${LISTING}\n## Other\ntext\n`);
|
||||
const r = doctor(f);
|
||||
const row = r.row('CLAUDE.md');
|
||||
expect(row.state, r.out).toBe('warn');
|
||||
expect(row.detail).toContain(`${bashPath(f.home)}/.claude/CLAUDE.md lists 13 skills`);
|
||||
expect(row.fix).toContain('#claude-md-skill-list');
|
||||
expect(fs.readFileSync(path.join(REPO, 'docs/troubleshooting.md'), 'utf8')).toContain('<a id="claude-md-skill-list"></a>');
|
||||
expect(replacement(r.out)).toEqual(['## gstack', 'Use /browse from gstack for all web browsing. Never use mcp__claude-in-chrome__* tools.']);
|
||||
expect(r.status, r.out).toBe(0);
|
||||
write(user, SHORT);
|
||||
write(path.join(f.work, 'CLAUDE.md'), `# Project\n\n## gstack (recommended)\nskills: /office-hours /plan-ceo-review /plan-eng-review /review /ship /qa /browse /retro /investigate\n`);
|
||||
const project = doctor(f).row('CLAUDE.md');
|
||||
expect(project.state).toBe('warn');
|
||||
expect(project.detail).toContain(`${bashPath(f.work)}/CLAUDE.md lists 9 skills`);
|
||||
expect(project.detail).not.toContain('.claude/CLAUDE.md');
|
||||
});
|
||||
|
||||
test('CLAUDE.md: the short block, team-init\'s block, a separate Skill routing section and paths do not warn; no CLAUDE.md does not warn', () => {
|
||||
const f = makeFixture();
|
||||
const none = doctor(f).row('CLAUDE.md');
|
||||
expect(none.state).toBe('ok');
|
||||
expect(none.fix).toBe('');
|
||||
write(path.join(f.home, '.claude/CLAUDE.md'), SHORT);
|
||||
write(path.join(f.work, 'CLAUDE.md'), [
|
||||
'## gstack (recommended)',
|
||||
'Using gstack skills: After install, skills like /qa, /ship, /review, /investigate,',
|
||||
'and /browse are available. Use the install path ~/.claude/skills/gstack/bin/gstack-config /usr/local/bin/bun /opt/a/b /x/y /z/w.',
|
||||
'',
|
||||
'## Skill routing',
|
||||
'- Product ideas → invoke /office-hours',
|
||||
'- Strategy → invoke /plan-ceo-review',
|
||||
'- Architecture → invoke /plan-eng-review',
|
||||
'- Design → invoke /design-consultation or /plan-design-review',
|
||||
'- Review → invoke /autoplan, /investigate, /qa, /review, /ship',
|
||||
'',
|
||||
].join('\n'));
|
||||
const r = doctor(f);
|
||||
expect(r.row('CLAUDE.md').state, r.out).toBe('ok');
|
||||
expect(replacement(r.out)).toEqual([]);
|
||||
});
|
||||
|
||||
/** A JSON probe file: the discovery inputs resolveWindowsBash takes, in test/fixtures/windows-bash-resolution.json's shape. */
|
||||
const probe = (f: Fixture, inputs: Record<string, unknown>) => { const file = path.join(f.base, 'bash-probe.json'); write(file, JSON.stringify(inputs)); return file; };
|
||||
const GIT_BASH = 'C:/Program Files/Git/bin/bash.exe';
|
||||
|
||||
test('windows bash: on Windows the row names the resolved bash and what chose it', () => {
|
||||
const f = makeFixture();
|
||||
const found = doctor(f, [], { GSTACK_DOCTOR_PLATFORM: 'windows', GSTACK_DOCTOR_BASH_PROBE: probe(f, { exists: [GIT_BASH], gitExecPath: 'C:/Program Files/Git/mingw64/libexec/git-core' }) });
|
||||
expect(found.row('windows bash'), found.out).toEqual({ state: 'ok', detail: `${GIT_BASH} (chosen by git --exec-path)`, fix: '' });
|
||||
const override = doctor(f, [], { GSTACK_DOCTOR_PLATFORM: 'windows', GSTACK_GIT_BASH: 'D:\\tools\\bash.exe', GSTACK_DOCTOR_BASH_PROBE: probe(f, { exists: ['D:/tools/bash.exe', GIT_BASH] }) });
|
||||
expect(override.row('windows bash').detail).toBe('D:/tools/bash.exe (chosen by GSTACK_GIT_BASH)');
|
||||
});
|
||||
|
||||
test('windows bash: GSTACK_GIT_BASH and a different deprecated GSTACK_BASH warn naming both', () => {
|
||||
const f = makeFixture();
|
||||
const differ = doctor(f, [], { GSTACK_DOCTOR_PLATFORM: 'windows', GSTACK_GIT_BASH: 'D:/a/bash.exe', GSTACK_BASH: 'D:/b/bash.exe', GSTACK_DOCTOR_BASH_PROBE: probe(f, { exists: ['D:/a/bash.exe', 'D:/b/bash.exe'] }) });
|
||||
expect(differ.row('windows bash').state).toBe('warn');
|
||||
expect(differ.row('windows bash').detail).toContain('D:/a/bash.exe (chosen by GSTACK_GIT_BASH)');
|
||||
expect(differ.row('windows bash').detail).toContain('GSTACK_GIT_BASH (D:/a/bash.exe) and the deprecated GSTACK_BASH (D:/b/bash.exe) differ');
|
||||
});
|
||||
|
||||
test('windows bash: a refusal fails with BASH_UNAVAILABLE naming GSTACK_GIT_BASH; off Windows there is no row', () => {
|
||||
const f = makeFixture();
|
||||
const refused = doctor(f, [], { GSTACK_DOCTOR_PLATFORM: 'windows', GSTACK_DOCTOR_BASH_PROBE: probe(f, { exists: [], gitExecPath: null, which: { bash: 'C:/Windows/System32/bash.exe' } }) });
|
||||
const row = refused.row('windows bash');
|
||||
expect(row.state, refused.out).toBe('fail');
|
||||
expect(row.detail).toContain('(BASH_UNAVAILABLE)');
|
||||
expect(row.detail).toContain('PATH C:/Windows/System32/bash.exe: WSL launcher, not Git Bash');
|
||||
expect(row.detail).toContain(`install path ${GIT_BASH}: not found`);
|
||||
expect(row.fix).toContain('GSTACK_GIT_BASH');
|
||||
expect(row.fix).toContain('#bash-unavailable');
|
||||
expect(refused.status).toBe(1);
|
||||
expect(doctor(f, [], { GSTACK_DOCTOR_PLATFORM: 'posix' }).out).not.toContain('windows bash');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,386 @@
|
||||
/**
|
||||
* The generated bun-test child that test/docsync-fault-interface*.test.ts run: it mocks the docsync
|
||||
* fixture, observer, e2e gate and session runner, imports test/skill-e2e-ship-docsync.test.ts and replays
|
||||
* its registered callbacks (moved verbatim from test/docsync-fault-interface.test.ts, GSTA-151).
|
||||
*/
|
||||
import * as path from 'node:path';
|
||||
import { DOCS_CHECKPOINT_MARKER } from './docsync-fault-actor';
|
||||
|
||||
export function docsFaultCallbackScript(root: string): string {
|
||||
return `
|
||||
import { expect, mock, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import type { SkillTestResult } from ${JSON.stringify(path.join(root, 'test/helpers/session-runner'))};
|
||||
const root = ${JSON.stringify(root)};
|
||||
const fixtureModule = path.join(root, 'test/helpers/docsync-fixture.ts');
|
||||
const observerModule = path.join(root, 'test/helpers/docsync-observer.ts');
|
||||
const fixtures = { ...await import(fixtureModule) };
|
||||
const observers = { ...await import(observerModule) };
|
||||
const { CAPTURE_MS, CAPTURE_LONG_MS } = await import(path.join(root, 'test/helpers/eval-budgets.ts'));
|
||||
const { parseDocsCompletion } = await import(path.join(root, 'test/helpers/docsync-contract.ts'));
|
||||
const { docsActorSeeded, DOCS_SEEDED_AUDIT_ID } = await import(path.join(root, 'test/helpers/docsync-fault-actor.ts'));
|
||||
const callbacks = new Map();
|
||||
let fixture, control = '', launches = 0, recorded, legacyReaudit = false;
|
||||
let returnedResult: SkillTestResult | undefined;
|
||||
let consumers: string[] = [];
|
||||
function expectResult(result: SkillTestResult) {
|
||||
expect(result).toBe(returnedResult);
|
||||
expect(result).toEqual({
|
||||
toolCalls: expect.any(Array), browseErrors: [], exitReason: 'success', duration: 0,
|
||||
output: 'Bounded callback replay complete', transcript: [], model: 'free-callback-replay',
|
||||
firstResponseMs: 0, maxInterTurnMs: 0,
|
||||
costEstimate: { inputChars: 0, outputChars: 0, estimatedTokens: 0, estimatedCost: 0, turnsUsed: 1 },
|
||||
});
|
||||
expect(result.toolCalls.length).toBeGreaterThan(0);
|
||||
}
|
||||
mock.module(fixtureModule, () => ({ ...fixtures,
|
||||
fixtureDocs(...args) { fixture = fixtures.fixtureDocs(...args); return fixture; },
|
||||
}));
|
||||
mock.module(observerModule, () => ({ ...observers,
|
||||
docsBoundedStageInterface(...args) { return observers.docsBoundedStageInterface(...args) + '\\nBOUNDED_CALLBACK_USED'; },
|
||||
}));
|
||||
mock.module(path.join(root, 'test/helpers/e2e-gate.ts'), () => ({ describeE2ETier: () => (_name, body) => body() }));
|
||||
mock.module(path.join(root, 'test/helpers/e2e-helpers.ts'), () => ({
|
||||
runId: 'free-docsync-faults', describeIfSelected: (_name, _names, body) => body(),
|
||||
testConcurrentIfSelected: (name, body, budget) => callbacks.set(name, { body, budget }),
|
||||
createEvalCollector: () => ({}), finalizeEvalCollector() {},
|
||||
logCost(_name, result) {
|
||||
expectResult(result);
|
||||
consumers.push('logCost');
|
||||
},
|
||||
recordE2E(_collector, _name, _label, result, verdict) {
|
||||
expectResult(result);
|
||||
expect(verdict).toEqual({ passed: control === '' });
|
||||
consumers.push('recordE2E');
|
||||
recorded = verdict;
|
||||
},
|
||||
}));
|
||||
mock.module(path.join(root, 'test/helpers/session-runner.ts'), () => ({ async runSkillTest(options) {
|
||||
launches++;
|
||||
const legacy = options.testName === 'ship-docsync-failure';
|
||||
const scenario = legacy ? 'legacy-completion' : options.testName.slice('ship-docsync-'.length);
|
||||
expect(options.maxTurns).toBe(legacy ? 30 : 24);
|
||||
expect(options.timeout).toBeGreaterThan((legacy ? CAPTURE_LONG_MS : CAPTURE_MS) - 20_000);
|
||||
expect(options.timeout).toBeLessThanOrEqual((legacy ? CAPTURE_LONG_MS : CAPTURE_MS) - 15_000);
|
||||
expect(options.tools).toEqual(['Bash', 'Read', 'Write', 'Edit', 'Glob', 'Grep']);
|
||||
expect(options.allowedTools).toEqual(options.tools);
|
||||
expect(options.prompt).toContain('BOUNDED_CALLBACK_USED');
|
||||
expect(options.prompt).toContain(fixture.invocation);
|
||||
expect(options.prompt).toContain('only you apply the loaded workflow');
|
||||
expect(options.prompt).toContain('do not probe invented ids');
|
||||
expect(options.prompt).toContain('Save each actual completion/rejected output once');
|
||||
expect(options.prompt).toContain('Private artifact filenames must end in .json, .md or .markdown');
|
||||
expect(options.prompt).toContain('.txt and .log filenames are not supported');
|
||||
expect(options.prompt).toContain('in a .md file without changing its bytes or reconstructing JSON');
|
||||
expect(options.prompt).toContain('the parent must not manufacture it');
|
||||
const repairable = ['recovery', 'late-result'].includes(scenario);
|
||||
const actor = path.join(root, 'test/helpers/docsync-fault-actor.ts');
|
||||
const stateFile = path.join(fixture.home, 'actor-state.json');
|
||||
expect(options.prompt.includes('bun ' + actor + ' repair ' + stateFile)).toBe(repairable);
|
||||
expect(options.prompt.includes('returns no result within the Collect deadline')).toBe(repairable);
|
||||
expect(options.prompt.includes('This launcher has no repair operation')).toBe(!repairable);
|
||||
expect(options.prompt.includes('bun ' + actor + ' inspect ' + stateFile)).toBe(true);
|
||||
expect(options.prompt).toContain('batched read-only observation');
|
||||
expect(options.prompt).toContain('Parent output handling');
|
||||
expect(options.prompt).toContain('as its own standalone Bash call with no redirect, pipe, wrapper, substitution or other composition');
|
||||
expect(options.prompt).toContain('Native Read, Glob and Grep stay available for file reads and are not Bash commands');
|
||||
expect(options.prompt).toContain('Never redirect a command into a file and never re-run a command merely to save its output');
|
||||
expect(options.prompt).toContain('Keep inspect observations in their original tool results in context and compare those returned values directly');
|
||||
expect(options.prompt).toContain('Do not transcribe or reserialize inspect JSON into duplicate snapshot files; prepare already saves the required candidate and prompt');
|
||||
expect(options.prompt).toContain('preserve each actual child completion/rejected output once in Markdown');
|
||||
expect(options.prompt).toContain('Persist each required checkpoint as one short appended journal entry');
|
||||
expect(options.prompt).toContain('use native Edit with old_string exactly ' + ${JSON.stringify(JSON.stringify(DOCS_CHECKPOINT_MARKER))});
|
||||
expect(options.prompt).toContain('new_string containing only the new entry followed by that same marker, and replace_all=false');
|
||||
expect(options.prompt).toContain('if missing or duplicated, stop rather than guessing an edit');
|
||||
expect(options.prompt).toContain('Preserve unrelated sections and every earlier entry byte-for-byte');
|
||||
expect(options.prompt).toContain("retaining each earlier attempt's id, count, evidence paths and outcome");
|
||||
expect(options.prompt).toContain('The latest stated value is current; do not recopy previous entries');
|
||||
expect(options.prompt).toContain('Reference saved candidate/prompt/completion artifacts instead of repeating their contents or prior narration');
|
||||
expect(options.prompt).toContain('Before dispatch, save the incremented attempt count, fresh audit id and candidate/prompt paths together');
|
||||
expect(options.prompt).toContain('Save the returned child handle before polling');
|
||||
expect(options.prompt).toContain('consolidation must never postpone the pre-launch count or child-settlement checks');
|
||||
expect(options.prompt).toContain('If recovery is authorized, save the intermediate result in one checkpoint before continuing it');
|
||||
expect(options.prompt).toContain('After the loaded Continue or recover / Blocked recovery steps reach a final outcome');
|
||||
expect(options.prompt).toContain('Append the finishing checkpoint and Write the complete report in the same response using separate native file calls');
|
||||
expect(options.prompt).toContain('Never omit the final report or final response, even when publication is blocked');
|
||||
expect(options.prompt).toContain('when it requires stopping, write the required invocation state and report, then stop rather than continuing later preparation to fill optional artifacts');
|
||||
expect(options.prompt).toContain('do not introduce any undeclared comparison or processing program to compare or transform observations');
|
||||
expect(options.prompt).toContain('Use only the transport commands above and the commands permitted by the Fixture observation interface below');
|
||||
expect(options.prompt).toContain('inspect takes no arguments beyond the state path shown above');
|
||||
expect(options.prompt).not.toContain('inspect call below');
|
||||
expect(options.prompt).not.toContain('inspect receipt');
|
||||
const calls = [];
|
||||
const config = JSON.parse(fs.readFileSync(path.join(fixture.env.CLAUDE_CONFIG_DIR, 'settings.json'), 'utf8'));
|
||||
const hook = config.hooks.PreToolUse.flatMap(entry => entry.hooks).find(entry => entry.command.includes('docsync-fault-actor.ts'));
|
||||
expect(hook).toBeDefined();
|
||||
const record = (tool, input, output) => calls.push({ tool, input, output });
|
||||
const pretool = (tool, input) => {
|
||||
const result = Bun.spawnSync(['bash', '-c', hook.command], { cwd: fixture.repo,
|
||||
stdin: Buffer.from(JSON.stringify({ hook_event_name: 'PreToolUse', cwd: fixture.repo, tool_name: tool, tool_input: input })),
|
||||
stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
|
||||
expect(result.exitCode, result.stderr.toString()).toBe(0);
|
||||
};
|
||||
const read = file_path => {
|
||||
pretool('Read', { file_path });
|
||||
const output = fs.readFileSync(file_path, 'utf8');
|
||||
record('Read', { file_path }, output);
|
||||
return output;
|
||||
};
|
||||
const write = (file_path, content) => {
|
||||
pretool('Write', { file_path, content });
|
||||
fs.writeFileSync(file_path, content);
|
||||
record('Write', { file_path, content }, 'File written');
|
||||
};
|
||||
const invoke = (action, args = {}) => {
|
||||
const argv = [actor, action, stateFile, ...Object.entries(args).map(([key, value]) => key + '=' + value)];
|
||||
const command = 'bun ' + argv.join(' ');
|
||||
pretool('Bash', { command });
|
||||
const result = Bun.spawnSync([process.execPath, ...argv], { cwd: fixture.repo, stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
|
||||
const text = result.stdout.toString().trimEnd();
|
||||
const output = (result.exitCode ? 'Exit code ' + result.exitCode + '\\n' : '') + text;
|
||||
record('Bash', { command }, output);
|
||||
return { text, output, exit: result.exitCode };
|
||||
};
|
||||
read(path.join(fixture.home, 'phase.md'));
|
||||
read(path.join(fixture.skills, 'ship/sections/documentation.md'));
|
||||
const initialRecord = read(fixture.invocation);
|
||||
expect(initialRecord).toContain('Attempts used: 0');
|
||||
expect(initialRecord).toContain('synthetic prior-stage state');
|
||||
const marker = ${JSON.stringify(DOCS_CHECKPOINT_MARKER)};
|
||||
expect(initialRecord.split(marker)).toHaveLength(2);
|
||||
const recordPrefix = initialRecord.split(marker)[0];
|
||||
let checkpointCount = 0;
|
||||
const seeded = docsActorSeeded(scenario);
|
||||
let attemptsUsed = seeded ? 1 : 0;
|
||||
let seedOutput = '';
|
||||
if (seeded) {
|
||||
expect(initialRecord).toContain('Attempts used: 1');
|
||||
read(path.join(fixture.home, 'candidate-' + DOCS_SEEDED_AUDIT_ID + '.json'));
|
||||
const saved = path.join(fixture.home, 'completion-' + DOCS_SEEDED_AUDIT_ID + '.md');
|
||||
seedOutput = control === 'skip-seeded-output' ? fs.readFileSync(saved, 'utf8') : read(saved);
|
||||
}
|
||||
const checkpoint = (details, finished = false) => {
|
||||
const before = fs.readFileSync(fixture.invocation, 'utf8');
|
||||
expect(before.split(marker)).toHaveLength(2);
|
||||
const entry = '### Checkpoint ' + (++checkpointCount) + '\\nAttempts used: ' + attemptsUsed + '.\\n'
|
||||
+ details + '\\nNext: ' + (finished ? 'Documentation gate finished; see ship-report.md. STOP before Step 15.' : 'Continue the actual documentation gate; STOP before Step 15.') + '\\n';
|
||||
const input = { file_path: fixture.invocation, old_string: marker, new_string: entry + marker, replace_all: false };
|
||||
pretool('Edit', input);
|
||||
const after = before.replace(input.old_string, input.new_string);
|
||||
fs.writeFileSync(fixture.invocation, after);
|
||||
record('Edit', input, 'File edited');
|
||||
expect(after.startsWith(recordPrefix)).toBe(true);
|
||||
expect(after.replace(input.new_string, marker)).toBe(before);
|
||||
expect(after.split(marker)).toHaveLength(2);
|
||||
expect(input.new_string).not.toContain(recordPrefix);
|
||||
};
|
||||
const inspectResult = invoke('inspect');
|
||||
const observed = JSON.parse(inspectResult.text);
|
||||
expect(observed.operation).toBe('inspect');
|
||||
expect(observed.files[fixtures.DOC_PATH].exists).toBe(true);
|
||||
expect(observed.pre_existing_dirty).toContain(String.fromCharCode(0));
|
||||
expect(inspectResult.text).not.toContain(String.fromCharCode(0));
|
||||
expect(calls.at(-1).output).toBe(inspectResult.text);
|
||||
if (control === 'tampered-inspect') calls[calls.length - 1].output = inspectResult.text.replace('"operation":"inspect"', '"operation":"tampered"');
|
||||
const prepare = id => {
|
||||
const result = invoke('prepare', { audit_id: id });
|
||||
expect(result.exit).toBe(0);
|
||||
const prepared = JSON.parse(result.text);
|
||||
read(prepared.candidate);
|
||||
read(prepared.prompt);
|
||||
return prepared;
|
||||
};
|
||||
const dispatch = prepared => {
|
||||
attemptsUsed++;
|
||||
checkpoint('Audit: ' + prepared.audit_id + '; candidate: ' + prepared.candidate + '; prompt: ' + prepared.prompt);
|
||||
const result = invoke('dispatch', { audit_id: prepared.audit_id, candidate: prepared.candidate, prompt: prepared.prompt, run_in_background: 'false' });
|
||||
const saved = calls.at(-2);
|
||||
expect(saved.tool).toBe('Edit');
|
||||
expect(saved.input.file_path).toBe(fixture.invocation);
|
||||
expect(saved.input.old_string).toBe(marker);
|
||||
expect(saved.input.new_string).toContain('Attempts used: ' + attemptsUsed);
|
||||
expect(saved.input.new_string).toContain(prepared.audit_id);
|
||||
expect(saved.input.new_string).toContain(prepared.candidate);
|
||||
expect(saved.input.new_string).toContain(prepared.prompt);
|
||||
return result;
|
||||
};
|
||||
let output = '', accepted = null, first;
|
||||
if (scenario !== 'missing-asset') {
|
||||
first = seeded ? { audit_id: DOCS_SEEDED_AUDIT_ID, candidate: path.join(fixture.home, 'candidate-' + DOCS_SEEDED_AUDIT_ID + '.json'),
|
||||
prompt: path.join(fixture.home, 'prompt-' + DOCS_SEEDED_AUDIT_ID + '.md') } : prepare('ship-docs-20260926-a1');
|
||||
const initial = seeded ? { text: seedOutput, output: seedOutput } : dispatch(first);
|
||||
output = initial.text;
|
||||
if (scenario === 'missing-marker') {
|
||||
expect(initial.output).toBe('SESSION_KIND: interactive\\n{"schema_version":1,"audit_id":"' + first.audit_id + '","status":"blocked","files_updated":[],"files_reviewed":[],"documentation_section":"blocked — fixture child audit ' + first.audit_id + '; Missing spawned marker.","blockers":["Missing spawned marker"],"decisions":[]}');
|
||||
}
|
||||
if (scenario === 'launch-failure') {
|
||||
expect(initial.text).toBe('Child launch failed: injected unavailable worker. No child was started.');
|
||||
expect(seeded ? initialRecord.includes('dispatch exit code 23') : initial.output.startsWith('Exit code 23\\n')).toBe(true);
|
||||
const attempts = JSON.parse(fs.readFileSync(stateFile, 'utf8')).tasks;
|
||||
expect(attempts).toHaveLength(1);
|
||||
expect(attempts[0].id).toBeNull();
|
||||
expect(attempts[0].candidate).toBe(fs.readFileSync(first.candidate, 'utf8'));
|
||||
}
|
||||
if (['timeout-unsettled', 'late-result'].includes(scenario)) {
|
||||
expect(initial.output).toBe('{"task_id":"fixture-child-1","status":"running","elapsed_ms":0,"virtual_clock":true}');
|
||||
const task_id = JSON.parse(output).task_id;
|
||||
if (seeded) expect(initialRecord).toContain('Returned child handle: ' + task_id + '.');
|
||||
else checkpoint('Running child handle: ' + task_id);
|
||||
expect(invoke('status', { task_id }).output).toBe('{"task_id":"fixture-child-1","status":"running","settled":false,"elapsed_ms":600001,"virtual_clock":true}');
|
||||
const stop = invoke('stop', { task_id });
|
||||
expect(JSON.parse(stop.text).settled).toBe(scenario === 'late-result');
|
||||
if (control !== 'skip-post-stop-status') {
|
||||
const status = invoke('status', { task_id });
|
||||
if (scenario === 'timeout-unsettled') expect(status.output).toBe('{"task_id":"fixture-child-1","status":"running","settled":false,"elapsed_ms":900002,"virtual_clock":true}');
|
||||
}
|
||||
}
|
||||
if (repairable) expect(invoke('repair').exit).toBe(0);
|
||||
if (repairable || scenario.startsWith('stale-') || legacy && legacyReaudit) {
|
||||
read(path.join(fixture.repo, 'app.ts'));
|
||||
const second = prepare('ship-docs-20260926-a2');
|
||||
if (control === 'stale-candidate' || control === 'legacy-stale') {
|
||||
const old = JSON.parse(fs.readFileSync(first.candidate, 'utf8'));
|
||||
old.audit_id = second.audit_id;
|
||||
write(second.candidate, JSON.stringify(old));
|
||||
}
|
||||
output = dispatch(second).text;
|
||||
if (scenario === 'late-result') expect(() => parseDocsCompletion(output, second.audit_id)).toThrow('completion identity');
|
||||
else if (legacy) expect(() => parseDocsCompletion(output, second.audit_id)).toThrow('completion fields');
|
||||
else accepted = parseDocsCompletion(output, second.audit_id);
|
||||
if (control === 'legacy-third') {
|
||||
const third = prepare('ship-docs-20260926-a3');
|
||||
output = dispatch(third).text;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
expect(fs.existsSync(path.join(fixture.skills, 'document-release/sections/audit-scope.md'))).toBe(false);
|
||||
}
|
||||
if (control === 'invalid-repair') expect(invoke('repair').output).toBe('Exit code 24\\nError: repair not available');
|
||||
if (control === 'invented-handle') expect(invoke('status', { task_id: 'ship-docs-20260926-a1' }).output).toBe('Exit code 24\\nError: unknown fixture child');
|
||||
if (control === 'restore-partial') write(path.join(fixture.repo, fixtures.DOC_PATH), Buffer.from(fixture.before.contents[fixtures.DOC_PATH], 'base64').toString());
|
||||
if (control === 'user-content') write(path.join(fixture.repo, 'personal-note.txt'), 'clobbered');
|
||||
if (control === 'private-state') read(stateFile);
|
||||
if (control === 'git-mutation') record('Bash', { command: 'git add ' + fixtures.DOC_PATH }, '');
|
||||
const runShell = (command) => {
|
||||
pretool('Bash', { command });
|
||||
const r = Bun.spawnSync(['bash', '-c', command], { cwd: fixture.repo, stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
|
||||
record('Bash', { command }, (r.exitCode ? 'Exit code ' + r.exitCode + '\\n' : '') + r.stdout.toString().trimEnd());
|
||||
return r.exitCode;
|
||||
};
|
||||
if (control === 'redirect-transport') {
|
||||
const snapshot = path.join(fixture.home, 'snapshot.json');
|
||||
expect(runShell('bun ' + actor + ' inspect ' + stateFile + ' > ' + snapshot)).toBe(0);
|
||||
expect(calls.at(-1).output).toBe('');
|
||||
expect(JSON.parse(fs.readFileSync(snapshot, 'utf8')).head).toBe(observed.head);
|
||||
}
|
||||
if (control === 'compare-program') expect(runShell('diff ' + path.join(fixture.repo, fixtures.DOC_PATH) + ' ' + path.join(fixture.repo, fixtures.DOC_PATH))).toBe(0);
|
||||
if (control === 'mutate-index') {
|
||||
const staged = Bun.spawnSync(['git', 'add', fixtures.DOC_PATH], { cwd: fixture.repo, stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
|
||||
expect(staged.exitCode).toBe(0);
|
||||
}
|
||||
if (['legacy-unchanged', 'legacy-unsettled', 'legacy-fake-repair'].includes(control)) {
|
||||
const state = JSON.parse(fs.readFileSync(stateFile, 'utf8'));
|
||||
if (control === 'legacy-unchanged') {
|
||||
state.tasks[1].observed_candidate.hashes = { ...state.tasks[0].observed_candidate.hashes };
|
||||
state.tasks[1].candidate = JSON.stringify(state.tasks[1].observed_candidate);
|
||||
}
|
||||
if (control === 'legacy-unsettled') state.tasks[0].settled = false;
|
||||
if (control === 'legacy-fake-repair') { state.repaired = true; state.events.push({ action: 'repair' }); }
|
||||
fs.writeFileSync(stateFile, JSON.stringify(state));
|
||||
}
|
||||
const outside = path.join(path.dirname(import.meta.path), 'outside.md');
|
||||
if (control === 'outside-artifact') record('Write', { file_path: outside, content: output }, 'attempted write');
|
||||
if (control === 'protected-artifact') record('Write', { file_path: path.join(fixture.skills, 'private.md'), content: output }, 'attempted write');
|
||||
if (control === 'script-artifact') record('Write', { file_path: actor, content: output }, 'attempted write');
|
||||
if (control === 'symlink-artifact') {
|
||||
fs.writeFileSync(outside, 'outside fixture control');
|
||||
const link = path.join(fixture.home, 'linked.md');
|
||||
fs.symlinkSync(outside, link);
|
||||
record('Write', { file_path: link, content: output }, 'attempted write');
|
||||
}
|
||||
write(path.join(fixture.home, control === 'raw-text-artifact' ? 'completion.txt' : 'completion.md'), output);
|
||||
expect(fs.readFileSync(path.join(fixture.home, control === 'raw-text-artifact' ? 'completion.txt' : 'completion.md'), 'utf8')).toBe(output);
|
||||
if (control === '') expect(fs.readdirSync(fixture.home).filter(name => /inspect|snapshot/.test(name))).toEqual([]);
|
||||
const report = path.join(fixture.home, 'ship-report.md');
|
||||
const finalReport = control === 'false-current' ? 'Documentation: current' : accepted
|
||||
? 'Documentation: ' + accepted.status + '\\n' + accepted.documentation_section
|
||||
: 'Documentation: blocked\\n' + (legacy ? 'Invalid legacy completion; partial edit retained: ' + fixtures.DOC_PATH : 'Actual child result did not clear the gate') + '\\nEvidence: completion.md';
|
||||
checkpoint(finalReport, true);
|
||||
if (control !== 'missing-report') write(report, finalReport);
|
||||
expect(fs.readFileSync(fixture.invocation, 'utf8')).toContain(finalReport);
|
||||
expect(fs.readFileSync(fixture.invocation, 'utf8')).toContain('Attempts used: ' + attemptsUsed);
|
||||
if (attemptsUsed > 1) expect(fs.readFileSync(fixture.invocation, 'utf8')).toContain(first.audit_id);
|
||||
if (control === '') {
|
||||
expect(calls.slice(-2).map(call => [call.tool, call.input.file_path])).toEqual([
|
||||
['Edit', fixture.invocation], ['Write', report],
|
||||
]);
|
||||
expect(fs.readFileSync(report, 'utf8')).toBe(finalReport);
|
||||
}
|
||||
if (accepted) expect(invoke('publish', { audit_id: accepted.audit_id, report }).exit).toBe(0);
|
||||
if (control === 'invalid-publication') expect(invoke('publish', { audit_id: 'ship-docs-20260926-a1', report }).exit).toBe(24);
|
||||
returnedResult = { exitReason: 'success', output: 'Bounded callback replay complete', toolCalls: calls, transcript: [],
|
||||
browseErrors: [], duration: 0, model: 'free-callback-replay', firstResponseMs: 0, maxInterTurnMs: 0,
|
||||
costEstimate: { inputChars: 0, outputChars: 0, estimatedTokens: 0, estimatedCost: 0, turnsUsed: 1 } } satisfies SkillTestResult;
|
||||
return returnedResult;
|
||||
} }));
|
||||
await import(path.join(root, 'test/skill-e2e-ship-docsync.test.ts'));
|
||||
expect(callbacks.size).toBe(12);
|
||||
const names = ['ship-docsync-failure', 'ship-docsync-missing-marker', 'ship-docsync-missing-asset',
|
||||
'ship-docsync-launch-failure', 'ship-docsync-timeout-unsettled', 'ship-docsync-late-result',
|
||||
'ship-docsync-stale-before', 'ship-docsync-stale-after', 'ship-docsync-recovery'];
|
||||
for (const name of names) test(name + ' consumes actual adapter results', async () => {
|
||||
control = '';
|
||||
legacyReaudit = false;
|
||||
recorded = undefined;
|
||||
returnedResult = undefined;
|
||||
consumers = [];
|
||||
const before = launches;
|
||||
expect(callbacks.get(name).budget).toBe(name === 'ship-docsync-failure' ? CAPTURE_LONG_MS : CAPTURE_MS);
|
||||
await callbacks.get(name).body();
|
||||
expect(launches).toBe(before + 1);
|
||||
expect(recorded).toEqual({ passed: true });
|
||||
expect(consumers).toEqual(['logCost', 'recordE2E']);
|
||||
expect(fs.existsSync(fixture.home)).toBe(false);
|
||||
});
|
||||
test('ship-docsync-failure accepts its remaining changed-input audit and preserves raw output in Markdown', async () => {
|
||||
control = '';
|
||||
legacyReaudit = true;
|
||||
recorded = undefined;
|
||||
returnedResult = undefined;
|
||||
consumers = [];
|
||||
await callbacks.get('ship-docsync-failure').body();
|
||||
expect(recorded).toEqual({ passed: true });
|
||||
expect(consumers).toEqual(['logCost', 'recordE2E']);
|
||||
expect(fs.existsSync(fixture.home)).toBe(false);
|
||||
});
|
||||
for (const [name, mutation] of [
|
||||
['ship-docsync-failure', 'false-current'], ['ship-docsync-failure', 'invalid-publication'],
|
||||
['ship-docsync-failure', 'restore-partial'], ['ship-docsync-failure', 'user-content'],
|
||||
['ship-docsync-failure', 'private-state'], ['ship-docsync-failure', 'git-mutation'],
|
||||
['ship-docsync-failure', 'mutate-index'], ['ship-docsync-missing-marker', 'invalid-repair'],
|
||||
['ship-docsync-missing-marker', 'redirect-transport'], ['ship-docsync-missing-marker', 'compare-program'],
|
||||
['ship-docsync-launch-failure', 'invented-handle'], ['ship-docsync-timeout-unsettled', 'skip-post-stop-status'],
|
||||
['ship-docsync-late-result', 'missing-report'],
|
||||
['ship-docsync-stale-before', 'stale-candidate'],
|
||||
['ship-docsync-recovery', 'skip-seeded-output'],
|
||||
['ship-docsync-failure', 'legacy-unchanged'], ['ship-docsync-failure', 'legacy-unsettled'],
|
||||
['ship-docsync-failure', 'legacy-stale'], ['ship-docsync-failure', 'legacy-third'],
|
||||
['ship-docsync-failure', 'legacy-fake-repair'],
|
||||
['ship-docsync-missing-marker', 'tampered-inspect'],
|
||||
['ship-docsync-missing-marker', 'raw-text-artifact'], ['ship-docsync-missing-marker', 'outside-artifact'],
|
||||
['ship-docsync-missing-marker', 'protected-artifact'], ['ship-docsync-missing-marker', 'symlink-artifact'],
|
||||
['ship-docsync-missing-marker', 'script-artifact'],
|
||||
]) test(name + ' rejects ' + mutation, async () => {
|
||||
control = mutation;
|
||||
legacyReaudit = name === 'ship-docsync-failure';
|
||||
recorded = undefined;
|
||||
returnedResult = undefined;
|
||||
consumers = [];
|
||||
await expect(callbacks.get(name).body()).rejects.toThrow();
|
||||
expect(recorded).toEqual({ passed: false });
|
||||
expect(consumers).toEqual(['logCost', 'recordE2E']);
|
||||
expect(fs.existsSync(fixture.home)).toBe(false);
|
||||
});
|
||||
`;
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* Shared fixture for the gstack-doctor tests (test/gstack-doctor.test.ts,
|
||||
* test/gstack-doctor-check.test.ts, test/gstack-doctor-launch.test.ts): a
|
||||
* fixture install root, state root, stub bun/codex/claude on PATH, and the
|
||||
* doctor() and rowOf() readers. Each test file calls useDoctorCleanup().
|
||||
*/
|
||||
import { afterEach } from 'bun:test';
|
||||
import { spawnSync } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
// setup builds browse/dist/browse.exe on Windows (Git Bash), browse/dist/browse elsewhere.
|
||||
export const BROWSE_BIN = process.platform === 'win32' ? 'browse/dist/browse.exe' : 'browse/dist/browse';
|
||||
export const EXE = process.platform === 'win32' ? '.exe' : '';
|
||||
export const OTHER_BINS = ['browse/dist/find-browse', 'design/dist/design', 'make-pdf/dist/pdf', 'bin/gstack-global-discover'].map(rel => rel + EXE);
|
||||
|
||||
export const REPO = path.resolve(import.meta.dir, '../..');
|
||||
const COPIED = [
|
||||
'setup', 'VERSION',
|
||||
'bin/gstack-doctor', 'bin/gstack-codex-status.sh', 'bin/gstack-state-root.sh', 'bin/gstack-install-registry.sh',
|
||||
'bin/gstack-render-claude.sh', 'bin/gstack-bun-version.sh', 'bin/gstack-hook-check', 'bin/gstack-config',
|
||||
'autoplan/SKILL.md', // its frontmatter registers the autoplan hook the hooks-row test breaks
|
||||
'bin/gstack-launch-probe.sh',
|
||||
'bin/gstack-doctor-check.sh', 'bin/gstack-doctor-components.sh', 'bin/gstack-runtime-pins.ts', 'lib/runtime-pins.ts',
|
||||
'bin/gstack-windows-bash.ts', 'lib/script-invocation.ts', 'lib/bun-isolation.ts', 'lib/result-codes.ts', 'lib/result-codes-release.ts', 'lib/result-codes-capy.ts', // the windows bash row
|
||||
];
|
||||
const bases: string[] = [];
|
||||
/** Registers the per-test fixture cleanup; each test file calls it at top level (a hook in this module would bind to the first importing file only). */
|
||||
export function useDoctorCleanup() {
|
||||
afterEach(() => { for (const b of bases.splice(0)) fs.rmSync(b, { recursive: true, force: true }); });
|
||||
}
|
||||
|
||||
export const write = (file: string, text: string, mode = 0o644) => {
|
||||
fs.mkdirSync(path.dirname(file), { recursive: true });
|
||||
fs.writeFileSync(file, text, { mode });
|
||||
};
|
||||
export const script = (file: string, lines: string[]) => write(file, ['#!/usr/bin/env bash', ...lines].join('\n') + '\n', 0o755);
|
||||
|
||||
/** The fixture's PATH entries minus every directory holding a real bun, codex or claude. */
|
||||
function hostPath(base: string): string {
|
||||
const names = ['bun', 'codex', 'claude'];
|
||||
const exts = process.platform === 'win32' ? ['', '.exe', '.cmd', '.ps1'] : [''];
|
||||
return (process.env.PATH ?? process.env.Path ?? '').split(path.delimiter).filter(Boolean).map((dir, i) => {
|
||||
if (!names.some(n => exts.some(e => fs.existsSync(path.join(dir, n + e))))) return dir;
|
||||
const shim = path.join(base, `host-${i}`);
|
||||
fs.mkdirSync(shim, { recursive: true });
|
||||
for (const name of fs.readdirSync(dir)) {
|
||||
if (names.some(n => exts.some(e => name === n + e))) continue;
|
||||
try { fs.symlinkSync(path.join(dir, name), path.join(shim, name)); } catch { /* unreadable entry */ }
|
||||
}
|
||||
return shim;
|
||||
}).join(path.delimiter);
|
||||
}
|
||||
|
||||
export interface Fixture { base: string; root: string; state: string; home: string; work: string; stub: string; probeLog: string; env: Record<string, string> }
|
||||
|
||||
export function makeFixture(): Fixture {
|
||||
const base = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-doctor-')));
|
||||
bases.push(base);
|
||||
const root = path.join(base, 'gstack');
|
||||
const state = path.join(base, 'state');
|
||||
const home = path.join(base, 'home');
|
||||
const work = path.join(base, 'work');
|
||||
const stub = path.join(base, 'stub');
|
||||
const probeLog = path.join(base, 'probe-calls');
|
||||
for (const dir of [state, home, work, stub]) fs.mkdirSync(dir, { recursive: true });
|
||||
for (const rel of COPIED) {
|
||||
fs.mkdirSync(path.dirname(path.join(root, rel)), { recursive: true });
|
||||
fs.copyFileSync(path.join(REPO, rel), path.join(root, rel));
|
||||
fs.chmodSync(path.join(root, rel), fs.statSync(path.join(REPO, rel)).mode);
|
||||
}
|
||||
script(path.join(root, 'bin/gstack-codex-probe'), [
|
||||
'echo "$*" >> "$DOCTOR_PROBE_LOG"',
|
||||
'case "$1" in',
|
||||
' select-model) [ "${STUB_SELECT_FAIL:-}" = 1 ] && { echo "gstack-codex-probe: cannot find its scripts dir" >&2; exit 1; }',
|
||||
' echo "CODEX_SEL: gpt-stub-5"; echo "CODEX_SEL_KIND: $2"; echo "CODEX_MODEL: gpt-stub-5 ($2; source: codex config.toml)" >&2 ;;',
|
||||
' check-auth) [ "${STUB_AUTH_FAIL:-}" = 1 ] && { echo AUTH_FAILED; exit 1; }; echo AUTH_OK ;;',
|
||||
' show-sandbox) echo "CODEX_SANDBOX: read-only" ;;',
|
||||
' check-sandbox|check-version) ;;',
|
||||
' probe-model) echo "CODEX_PROBE_STATE: ${STUB_PROBE_STATE:-ok}"; exit "${STUB_PROBE_EXIT:-0}" ;;',
|
||||
' *) exit 64 ;;',
|
||||
'esac',
|
||||
]);
|
||||
const listed = spawnSync('bash', [path.join(root, 'bin/gstack-hook-check'), '--list', root], { encoding: 'utf8', timeout: 20_000 });
|
||||
const hooks = listed.stdout.split('\n').map(line => line.trim()).filter(Boolean);
|
||||
if (!hooks.includes('autoplan/bin/phase-publication-hook')) throw new Error(`gstack-hook-check --list missed the autoplan hook: ${listed.stdout}${listed.stderr}`);
|
||||
for (const hook of hooks) write(path.join(root, hook), '#!/bin/sh\nexit 0\n', 0o755);
|
||||
// The doctor launches each compiled binary's --version (#2595), so the
|
||||
// stand-ins answer it like the real binaries do.
|
||||
for (const rel of [BROWSE_BIN, ...OTHER_BINS]) write(path.join(root, rel), '#!/bin/sh\necho built\n', 0o755);
|
||||
for (const rel of ['browse/dist/server-node.mjs', 'browse/dist/.build-complete']) write(path.join(root, rel), 'built\n', 0o755);
|
||||
const version = fs.readFileSync(path.join(root, 'VERSION'), 'utf8').trim();
|
||||
write(path.join(state, 'installs.tsv'),
|
||||
['claude', 'global', '-', path.join(home, '.claude/skills'), root, root, version, 'false', 'committed', '2026-10-07T00:00:00Z'].join('\t') + '\n');
|
||||
// The stub answers --version; anything else (the pins row runs bin/gstack-runtime-pins.ts) goes to the real bun.
|
||||
script(path.join(stub, 'bun'), ['[ "$1" = --version ] && { echo "${STUB_BUN_VERSION:-1.4.2}"; exit 0; }', `exec "${process.execPath}" "$@"`]);
|
||||
script(path.join(stub, 'codex'), ['[ "$1" = --version ] && { echo "codex-cli 0.130.0"; exit 0; }', 'echo "unexpected codex call: $*" >> "$DOCTOR_PROBE_LOG"', 'exit 9']);
|
||||
script(path.join(stub, 'claude'), ['[ "$1" = --version ] && { echo "2.1.292 (Claude Code)"; exit 0; }', 'exit 9']);
|
||||
const env: Record<string, string> = {
|
||||
PATH: [stub, hostPath(base)].join(path.delimiter),
|
||||
HOME: home, GSTACK_STATE_ROOT: state, TMPDIR: base, DOCTOR_PROBE_LOG: probeLog,
|
||||
};
|
||||
if (process.env.SYSTEMROOT) env.SYSTEMROOT = process.env.SYSTEMROOT;
|
||||
return { base, root, state, home, work, stub, probeLog, env };
|
||||
}
|
||||
|
||||
export function doctor(f: Fixture, args: string[] = [], extra: Record<string, string> = {}) {
|
||||
const r = spawnSync('bash', [path.join(f.root, 'bin/gstack-doctor'), ...args], { cwd: f.work, encoding: 'utf8', env: { ...f.env, ...extra }, timeout: 60_000 });
|
||||
const out = `${r.stdout}${r.stderr}`;
|
||||
return { status: r.status, out, row: (name: string) => rowOf(r.stdout, name) };
|
||||
}
|
||||
|
||||
/** The named row and its fix line: { state, detail, fix }. */
|
||||
export function rowOf(stdout: string, name: string) {
|
||||
const lines = stdout.split('\n');
|
||||
const i = lines.findIndex(l => l.slice(16, 32).trim() === name);
|
||||
if (i < 0) throw new Error(`no row "${name}" in:\n${stdout}`);
|
||||
const fix = lines[i + 1]?.startsWith(' '.repeat(32) + 'fix: ') ? lines[i + 1].slice(37) : '';
|
||||
return { state: lines[i].slice(0, 16).trim(), detail: lines[i].slice(32), fix };
|
||||
}
|
||||
|
||||
/** How bash spells a directory (Git Bash on Windows prints /c/...). */
|
||||
export const bashPath = (dir: string) => spawnSync('bash', ['-c', 'cd "$1" && pwd', '_', dir], { encoding: 'utf8', timeout: 10_000 }).stdout.trim();
|
||||
export const probeCalls = (f: Fixture) => fs.existsSync(f.probeLog) ? fs.readFileSync(f.probeLog, 'utf8') : '';
|
||||
export const iso = (secondsAgo: number) => new Date(Date.now() - secondsAgo * 1000).toISOString().replace(/\.\d+Z$/, 'Z');
|
||||
export const syncOn = (f: Fixture, status: Record<string, unknown>) => {
|
||||
fs.mkdirSync(path.join(f.state, '.git'), { recursive: true });
|
||||
write(path.join(f.state, 'config.yaml'), 'artifacts_sync_mode: artifacts-only\n');
|
||||
write(path.join(f.state, '.brain-sync-status.json'), JSON.stringify(status).replace(/":/g, '": ').replace(/,"/g, ', "') + '\n');
|
||||
};
|
||||
@@ -199,9 +199,9 @@ export const FREE_FIXTURES: Readonly<Record<string, readonly string[]>> = {
|
||||
'test/fixtures/shard-cli-parity/**': ['test/shard-cli-parity.test.ts'],
|
||||
'test/fixtures/shard-equivalence/**': ['test/shard-engine-equivalence.test.ts'],
|
||||
'test/fixtures/shared-libs-claude-version-probe.json': ['test/shared-libs-fixture.test.ts'],
|
||||
'test/fixtures/shared-libs-index-flags-loop-read-39173752116.json': ['test/shared-libs-checker-interface-evidence.test.ts'],
|
||||
'test/fixtures/shared-libs-index-flags-loop-read-39173752116.json': ['test/shared-libs-checker-interface-evidence-replays.test.ts'],
|
||||
'test/fixtures/shared-libs-no-change-ci-public.json': ['test/shared-libs-fixture.test.ts'],
|
||||
'test/fixtures/shared-libs-path-ignored-errored-read-40617200857.json': ['test/shared-libs-checker-interface-evidence.test.ts'],
|
||||
'test/fixtures/shared-libs-path-ignored-errored-read-40617200857.json': ['test/shared-libs-checker-interface-evidence-replays.test.ts'],
|
||||
'test/fixtures/shared-libs-plan-callers-fixes-behavior-local.json': ['test/shared-libs-plan-actor.test.ts'],
|
||||
'test/fixtures/shared-libs-plan-callers-future-risk-37195203538.json': ['test/shared-libs-plan-actor.test.ts'],
|
||||
'test/fixtures/shared-libs-plan-callers-no-hardening-36633323521.json': ['test/shared-libs-plan-actor.test.ts'],
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Shared fixture for the #1694 host-render prune tests (test/host-renders-prune*.test.ts):
|
||||
* a real `--host all` legacy render, the backup listing and a setup run that must pass.
|
||||
*/
|
||||
import { expect } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { runGeneration } from '../../scripts/gen-skill-docs';
|
||||
import { runSetup, type Fixture } from './install-fixture';
|
||||
|
||||
export const ROOT = path.resolve(import.meta.dir, '../..');
|
||||
export const OTHER_DIRS = ['.agents', '.factory', '.kiro', '.opencode', '.cursor', '.copilot', '.agy', '.slate', '.openclaw', '.hermes', '.gbrain'];
|
||||
|
||||
export const skillFiles = (dir: string): string[] => !fs.existsSync(dir) ? []
|
||||
: (fs.readdirSync(dir, { recursive: true }) as string[]).filter(rel => path.basename(rel) === 'SKILL.md' && fs.statSync(path.join(dir, rel)).isFile());
|
||||
|
||||
export async function legacyRender(src: string): Promise<void> {
|
||||
const result = await runGeneration({ host: 'all', outputRoot: src });
|
||||
if (result.exitCode !== 0) throw new Error('legacy render failed');
|
||||
}
|
||||
|
||||
export function backups(f: Fixture): string[] {
|
||||
const dir = path.join(f.home, '.gstack/backups/host-renders');
|
||||
return fs.existsSync(dir) ? fs.readdirSync(dir).map(d => path.join(dir, d)) : [];
|
||||
}
|
||||
|
||||
export function setupOk(f: Fixture, src: string, args: string[] = []) {
|
||||
const r = runSetup(f, path.join(src, 'setup'), args);
|
||||
expect(r.status, r.stdout + r.stderr).toBe(0);
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { existsSync, lstatSync, rmSync, symlinkSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { expect } from 'bun:test';
|
||||
import { fixtureWriteFileSync, fixtureMkdirSync, tree, fixture, install } from './install-fixture';
|
||||
|
||||
/** F13: a Claude-only setup run twice leaves a cyclic foreign ownership link at `target` and the rest of the global tree untouched. */
|
||||
export function claudeOnlySetupPreservesCyclicLink(target: string): void {
|
||||
const f = fixture('ordinary');
|
||||
rmSync(join(f.global, 'gstack-retired'));
|
||||
for (const rel of ['bin', 'lib']) {
|
||||
const asset = join(f.global, 'gstack', rel);
|
||||
rmSync(asset);
|
||||
symlinkSync(join(f.source, rel), asset, 'dir');
|
||||
}
|
||||
const old = join(f.global, 'gstack-claude');
|
||||
rmSync(old, { recursive: true });
|
||||
const oldRender = join(f.source, '.agents/skills/gstack-claude');
|
||||
fixtureMkdirSync(oldRender, { recursive: true });
|
||||
fixtureWriteFileSync(join(oldRender, 'SKILL.md'), '<!-- AUTO-GENERATED from SKILL.md.tmpl -->\n<!-- Regenerate: bun run gen:skill-docs -->\nPrior legacy render.\n');
|
||||
symlinkSync(oldRender, old, 'dir');
|
||||
const link = target === 'legacy' ? old
|
||||
: target === 'replacement' ? join(f.global, 'gstack-claude-code')
|
||||
: target === 'legacy-skill' ? join(old, 'SKILL.md')
|
||||
: target === 'runtime' ? join(f.global, 'gstack')
|
||||
: join(f.global, 'gstack', target === 'runtime-bin' ? 'bin' : 'lib');
|
||||
if (target === 'legacy-skill') {
|
||||
rmSync(old);
|
||||
fixtureMkdirSync(old);
|
||||
}
|
||||
if (existsSync(link) || lstatSync(link, { throwIfNoEntry: false })) rmSync(link, { recursive: true });
|
||||
symlinkSync(link, link);
|
||||
const before = tree(f.global);
|
||||
for (let run = 0; run < 2; run++) {
|
||||
install(f, '--host claude');
|
||||
expect(tree(f.global)).toEqual(before);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
/**
|
||||
* Captures and replay adapters shared by test/shared-libs-checker-interface-evidence*.test.ts
|
||||
* (moved from test/shared-libs-checker-interface-evidence.test.ts, GSTA-151). Each test file
|
||||
* runs its own beforeAll over the captures it replays and its own afterAll cleanup.
|
||||
*/
|
||||
import { expect } from 'bun:test';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { hasTrustedSharedLibsCheck } from './shared-libs-review-start-evidence';
|
||||
import {
|
||||
createSharedInteractiveToolHandler, createSharedLibsFixture, fixtureGit, fixtureWorkingTree, fixtureWrite,
|
||||
installNormalizingFilter, reviewLifecycleInstructions, reviewRevalidationPrompt, reviewRecords,
|
||||
seedReviewSources, seedSkippedAdvisory, SHARED_LIBS_ROOT, shellQuote, toolCommandTrace,
|
||||
type SharedLibsFixture,
|
||||
} from './shared-libs-eval-fixture';
|
||||
import {
|
||||
seedPathReviewPrerequisites, checkPathReviewPrerequisites,
|
||||
hasPathReviewPrerequisiteReceipt, type PathEligibilityFixture,
|
||||
} from './shared-libs-path-fixture';
|
||||
import { CAPTURE_LONG_MS } from './eval-budgets';
|
||||
import capturedChecker from '../fixtures/shared-libs-index-flags-r59-checker-public.json';
|
||||
|
||||
export const helper = path.join(SHARED_LIBS_ROOT, 'bin/gstack-review-log');
|
||||
export const fixtures: SharedLibsFixture[] = [];
|
||||
export const captures = new Map<string, any>();
|
||||
export const pathSource = fs.readFileSync(path.join(import.meta.dir, '..', 'skill-e2e-shared-libs-paths.test.ts'), 'utf8');
|
||||
export const pathKinds = ['symlinks', 'submodule', 'ignored', 'legacy', 'assume-unchanged', 'skip-worktree', 'removed-filter'] as const;
|
||||
|
||||
export async function capture(change: string, prepared?: PathEligibilityFixture, declared = false) {
|
||||
const f = prepared?.fixture ?? createSharedLibsFixture(`checker-${change}`);
|
||||
fixtures.push(f);
|
||||
let current = prepared?.current;
|
||||
if (!current) {
|
||||
seedReviewSources(f);
|
||||
fixtureWrite(f, 'src/retry-worker.ts', fs.readFileSync(path.join(f.repo, 'src/retry-worker.ts'), 'utf8')
|
||||
.replace('const unusedRetryDiagnostic = "unused";\n', ''));
|
||||
if (change === 'filtered') installNormalizingFilter(f);
|
||||
const { action: _action, ...finding } = await seedSkippedAdvisory(f);
|
||||
current = finding;
|
||||
if (change === 'branch') fixtureGit(f, 'checkout', '-b', 'feature-a');
|
||||
if (change === 'secondary') fixtureWrite(f, 'src/retry-route.ts',
|
||||
fs.readFileSync(path.join(f.repo, 'src/retry-route.ts'), 'utf8') + '// Changed caller\n');
|
||||
if (change === 'filtered') fixtureWrite(f, 'src/retry-route.ts',
|
||||
fs.readFileSync(path.join(f.repo, 'src/retry-route.ts'), 'utf8') + '// RAW-ONLY changed caller\n');
|
||||
}
|
||||
const events: any[] = [];
|
||||
const invoke = (command: string) => {
|
||||
const id = `call-${events.length}`;
|
||||
events.push({ type: 'assistant', message: { content: [{ type: 'tool_use', id, name: 'Bash', input: { command } }] } });
|
||||
const output = execFileSync('bash', ['-c', command], { cwd: f.repo, env: { ...process.env, ...f.env },
|
||||
encoding: 'utf8', timeout: 30_000 });
|
||||
events.push({ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: id, content: output }] } });
|
||||
return output.trim();
|
||||
};
|
||||
const instructionFile = reviewLifecycleInstructions(f);
|
||||
const instructions = fs.readFileSync(instructionFile, 'utf8');
|
||||
const resumed = prepared?.resumed ?? seedPathReviewPrerequisites(f);
|
||||
const prerequisites = checkPathReviewPrerequisites(f, resumed.input);
|
||||
const protocol = declared ? [...reviewRevalidationPrompt(f, instructionFile, path.join(f.root, 'current-advisory.jsonl'), resumed)
|
||||
.matchAll(/```bash\n([\s\S]*?)\n```/g)].map(match => match[1]) : [];
|
||||
if (declared) expect(protocol).toHaveLength(3);
|
||||
const startCommand = instructions.match(/```bash\n(DIFF_BASE=\$[\s\S]*?)\n```/)?.[1];
|
||||
expect(startCommand).toBeDefined();
|
||||
const token = invoke(declared ? protocol[0] : startCommand!).split('\n')[0];
|
||||
if (declared) invoke('git diff origin/main');
|
||||
for (const file of current.evidence_paths) invoke(`cat ${shellQuote(file)}`);
|
||||
const checkAt = events.length;
|
||||
const receipt = JSON.parse(invoke(declared ? protocol[1].replace('REVIEW_START', token).replace('CURRENT_FINDING_JSON', JSON.stringify(current))
|
||||
: `${shellQuote(helper)} --check-shared-libs ${token} <<'FINDING'\n${JSON.stringify(current)}\nFINDING`));
|
||||
const questions: any[] = [];
|
||||
if (declared && !receipt.reusable) {
|
||||
const input = { questions: [{ question: 'Revalidate this supplied authored-source advisory?',
|
||||
options: [{ label: 'Fix', description: 'Apply the extraction.' },
|
||||
{ label: 'Skip', description: 'Keep the source and index unchanged; record this advisory decision.' }] }] };
|
||||
const callback = createSharedInteractiveToolHandler('skip', {
|
||||
nonQuestion: () => { throw new Error('No non-question tool is allowed by this free actor'); },
|
||||
onQuestion: value => { questions.push(value); }, onAnswer: () => {},
|
||||
});
|
||||
const id = `decision-${events.length}`;
|
||||
events.push({ type: 'assistant', message: { content: [{ type: 'tool_use', id, name: 'AskUserQuestion', input }] } });
|
||||
const answer = await callback('AskUserQuestion', input);
|
||||
expect(answer.updatedInput.answers).toEqual({ [input.questions[0].question]: 'Skip' });
|
||||
events.push({ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: id,
|
||||
content: JSON.stringify(answer.updatedInput.answers) }] } });
|
||||
}
|
||||
{
|
||||
const settled = JSON.parse(invoke(resumed.checkCommand));
|
||||
expect(settled).toEqual(checkPathReviewPrerequisites(f, resumed.input));
|
||||
expect(settled).toMatchObject({ synthetic: true, native_coverage: false, settled: true, current: true });
|
||||
}
|
||||
const finishAt = events.length;
|
||||
const record = JSON.stringify({ skill: 'review', status: 'clean', issues_found: 0,
|
||||
completed: true, converged: true, findings: change === 'unchanged' ? [] : [{ ...current, action: 'skipped' }] });
|
||||
invoke(declared ? protocol[2].replace("'FINAL_REVIEW_JSON'", shellQuote(record)).replace('REVIEW_START', token)
|
||||
: `${shellQuote(helper)} ${shellQuote(record)} --finish ${token} && ${shellQuote(path.join(SHARED_LIBS_ROOT, 'bin/gstack-review-read'))}`);
|
||||
const expected = { helper, repo: f.repo, state: f.state, slug: 'fixture-shared-libs',
|
||||
directory: path.join(f.state, 'projects/fixture-shared-libs/.review-starts'),
|
||||
branch: fixtureGit(f, 'symbolic-ref', '--quiet', '--short', 'HEAD'), wtree: fixtureWorkingTree(f),
|
||||
startedAt: receipt.review_start.started_at, finding: current, reusable: change === 'unchanged',
|
||||
coveredPaths: receipt.snapshot.covered_paths,
|
||||
...(prepared ? { sources: Object.fromEntries(current!.evidence_paths.map((file: string) => [file, fs.readFileSync(path.join(f.repo, file), 'utf8')])) } : {}) };
|
||||
return { f, current, token, receipt, events, checkAt, finishAt, expected, prepared, resumed, prerequisites, ...(declared ? { questions } : {}) };
|
||||
}
|
||||
|
||||
export function replay(change = 'unchanged') { return structuredClone(captures.get(change)); }
|
||||
export function call(run: any, at = run.checkAt) { return run.events[at].message.content[0]; }
|
||||
export function result(run: any, at = run.checkAt) { return run.events[at + 1].message.content[0]; }
|
||||
export function alterReceipt(run: any, change: (receipt: any) => void) {
|
||||
const receipt = JSON.parse(result(run).content);
|
||||
change(receipt);
|
||||
result(run).content = JSON.stringify(receipt);
|
||||
}
|
||||
|
||||
export function pathCallback(run: any, overrides: Record<string, any> = {}) {
|
||||
const start = pathSource.indexOf('async function exerciseEligibility(');
|
||||
const end = pathSource.indexOf('\ndescribeE2E(', start);
|
||||
const readStart = pathSource.indexOf('function sourceReadTrace(');
|
||||
expect(start).toBeGreaterThan(readStart);
|
||||
expect(end).toBeGreaterThan(start);
|
||||
const rows: any[] = [];
|
||||
const native = { events: run.events, exitReason: 'success', output: '', toolCalls: run.events
|
||||
.filter((event: any) => event.type === 'assistant')
|
||||
.flatMap((event: any) => event.message.content.filter((block: any) => block.type === 'tool_use')
|
||||
.map((block: any) => ({ tool: block.name, input: block.input }))) };
|
||||
const exercise = new Function('deps', new Bun.Transpiler({ loader: 'ts' }).transformSync(`const {
|
||||
captures, preparePathEligibilityFixture, fs, path, reviewLifecycleInstructions, reviewRevalidationPrompt,
|
||||
runSharedInteractive, readRequests, toolCommandTrace, fixtureGit, fixtureWorkingTree, reviewRecords, expect,
|
||||
CAPTURE_LONG_MS, hasTrustedSharedLibsCheck, SHARED_LIBS_ROOT,
|
||||
checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt } = deps;
|
||||
${pathSource.slice(readStart, end)} return exerciseEligibility;`))({
|
||||
captures: { runAttempt: async (_name: string, _kinds: string[], _timeout: number, work: any) =>
|
||||
work({ add: (scenario: string, row: any) => rows.push({ scenario, row }) }) },
|
||||
preparePathEligibilityFixture: () => run.prepared,
|
||||
fs: { ...fs, rmSync: (directory: string) => { expect(directory).toBe(run.f.root); } }, path,
|
||||
reviewLifecycleInstructions, reviewRevalidationPrompt,
|
||||
runSharedInteractive: async (fixture: any, _name: string, prompt: string, choice: string) => {
|
||||
expect(choice).toBe('skip');
|
||||
expect(fixture).toBe(run.prepared.fixture);
|
||||
expect(prompt).toContain(reviewRevalidationPrompt(fixture, path.join(fixture.root, 'review-lifecycle.md'),
|
||||
path.join(fixture.root, 'current-advisory.jsonl'), run.prepared.resumed));
|
||||
return { result: native, questions: run.questions ?? [{}] };
|
||||
},
|
||||
readRequests: () => [], toolCommandTrace, fixtureGit, fixtureWorkingTree, reviewRecords, expect,
|
||||
CAPTURE_LONG_MS, hasTrustedSharedLibsCheck, SHARED_LIBS_ROOT,
|
||||
checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt, ...overrides,
|
||||
});
|
||||
return { rows, invoke: () => exercise('shared-libs-review-path-eligibility', [run.kind]) };
|
||||
}
|
||||
|
||||
export function capturedPathRun(index: number) {
|
||||
const captured = structuredClone(capturedChecker.attempts[index]);
|
||||
const events: any[] = captured.events;
|
||||
const blocks = events.flatMap(event => event.message.content);
|
||||
const calls = blocks.filter(block => block.type === 'tool_use');
|
||||
const returned = (id: string) => {
|
||||
const result = blocks.find(block => block.type === 'tool_result' && block.tool_use_id === id);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.is_error).not.toBe(true);
|
||||
expect(typeof result.content).toBe('string');
|
||||
return result.content as string;
|
||||
};
|
||||
const files = new Map<string, string>(calls.filter(call => call.name === 'Read')
|
||||
.map(call => [call.input.file_path, returned(call.id).replace(/^\d+\t/gm, '')]));
|
||||
const repo = captured.repo, root = path.posix.dirname(repo), state = path.posix.join(root, 'state');
|
||||
const input = path.posix.join(root, 'resumed-review-prerequisites.json');
|
||||
const supplied = path.posix.join(root, 'current-advisory.jsonl');
|
||||
const current = JSON.parse(files.get(supplied)!);
|
||||
const prerequisiteCall = calls.find(call => call.input.command?.includes('--check-review-prerequisites'));
|
||||
const prerequisites = JSON.parse(returned(prerequisiteCall.id));
|
||||
expect(prerequisites).toMatchObject({ settled: true, current: true, context: { binding: { root, repo, state } } });
|
||||
expect(prerequisites.context).toEqual(JSON.parse(files.get(input)!));
|
||||
const finish = calls.find(call => call.input.command?.includes('--finish'));
|
||||
const records = returned(finish.id).split('\n').filter(line => line.startsWith('{')).map(line => JSON.parse(line));
|
||||
const f = { root, repo, state } as SharedLibsFixture;
|
||||
const run = { f, kind: 'assume-unchanged', events, questions: calls.filter(call => call.name === 'AskUserQuestion').map(call => call.input),
|
||||
prepared: { fixture: f, current, sourcePaths: ['src/retry-route.ts'], beforeTree: prerequisites.context.binding.wtree,
|
||||
resumed: { input, checkCommand: prerequisiteCall.input.command } } };
|
||||
expect(captured.exit_reason).toBe('success');
|
||||
expect(run.questions).toHaveLength(1);
|
||||
for (const call of calls.filter(call => call.name === 'AskUserQuestion')) {
|
||||
for (const question of call.input.questions) {
|
||||
expect(returned(call.id)).toContain(`"${question.question}"="Skip"`);
|
||||
expect(question.options.some((option: any) => option.label === 'Skip')).toBe(true);
|
||||
}
|
||||
}
|
||||
const overrides = {
|
||||
path: path.posix, SHARED_LIBS_ROOT: '/workspace/gstack',
|
||||
fs: {
|
||||
readFileSync: (file: string) => { expect(files.has(file)).toBe(true); return files.get(file); },
|
||||
realpathSync: (file: string) => file,
|
||||
writeFileSync: (file: string, contents: string) => {
|
||||
expect(file).toBe(supplied);
|
||||
expect(JSON.parse(contents)).toEqual(current);
|
||||
},
|
||||
rmSync: (directory: string) => { expect(directory).toBe(root); },
|
||||
},
|
||||
reviewLifecycleInstructions: () => path.posix.join(root, 'review-lifecycle.md'),
|
||||
checkPathReviewPrerequisites: (fixture: SharedLibsFixture, file: string) => {
|
||||
expect(fixture).toBe(f); expect(file).toBe(input); return prerequisites;
|
||||
},
|
||||
fixtureGit: (fixture: SharedLibsFixture, ...args: string[]) => {
|
||||
expect(fixture).toBe(f); expect(args).toEqual(['symbolic-ref', '--quiet', '--short', 'HEAD']);
|
||||
return prerequisites.context.binding.branch;
|
||||
},
|
||||
fixtureWorkingTree: (fixture: SharedLibsFixture) => {
|
||||
expect(fixture).toBe(f); return prerequisites.context.binding.wtree;
|
||||
},
|
||||
reviewRecords: (fixture: SharedLibsFixture) => { expect(fixture).toBe(f); return structuredClone(records); },
|
||||
};
|
||||
return { run, overrides };
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/** Train setups shared by the test/ship-queue-train*.test.ts files (moved from test/ship-queue-train.test.ts, GSTA-151). */
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { GREEN_GATE, nonceOf, openPr, queue, readyReceipt, type Rule, type TrainFixture } from './ship-queue-train-fixture';
|
||||
|
||||
export function twoPrTrain(fx: TrainFixture, gate: Rule = GREEN_GATE) {
|
||||
const h1 = openPr(fx, '1');
|
||||
const h2 = openPr(fx, '2');
|
||||
readyReceipt(fx, '1', h1);
|
||||
readyReceipt(fx, '2', h2);
|
||||
fx.write(d => { d.rules['evals.yml'] = gate; });
|
||||
const r = queue(fx, ['train', 'build', '--prs', `1@${h1},2@${h2}`]);
|
||||
return { h1, h2, r, nonce: nonceOf(r.out) };
|
||||
}
|
||||
|
||||
/** A main commit with a prefix's tree plus a VERSION stamp, the way stamp-at-merge publishes it. */
|
||||
export function publishMain(fx: TrainFixture, prefixCommit: string, version: string, extra?: { file: string; text: string }): string {
|
||||
const { repo } = fx;
|
||||
repo.git('checkout', '-q', '-B', 'mainsim', 'origin/main');
|
||||
repo.git('rm', '-rq', '.');
|
||||
repo.git('checkout', prefixCommit, '--', '.');
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), version + '\n');
|
||||
if (extra) fs.writeFileSync(path.join(repo.work, extra.file), extra.text);
|
||||
repo.git('add', '-A');
|
||||
repo.git('commit', '-q', '-m', `merge to ${version}`);
|
||||
repo.git('push', '-q', 'origin', 'HEAD:refs/heads/main');
|
||||
repo.git('fetch', '-q', 'origin');
|
||||
return repo.git('rev-parse', 'HEAD');
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* #1694 host-render prune: a host linked into the render is kept, and the gstack-upgrade migration prunes existing installs.
|
||||
* Split from test/host-renders-prune.test.ts so the free-suite packer can balance it (60 s seed ceiling).
|
||||
*/
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, put, type Fixture } from './helpers/install-fixture';
|
||||
import { ROOT, backups, legacyRender, setupOk, skillFiles } from './helpers/host-renders-prune-fixture';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('setup prunes unrecorded host renders without losing a file (#1694)', () => {
|
||||
test('a host whose skills link into the render is kept even with no registry row', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
await legacyRender(src);
|
||||
fs.mkdirSync(path.join(f.home, '.factory/skills'), { recursive: true });
|
||||
fs.symlinkSync(path.join(src, '.factory/skills/gstack-qa'), path.join(f.home, '.factory/skills/gstack-qa'));
|
||||
setupOk(f, src);
|
||||
expect(fs.readFileSync(path.join(src, '.gstack-installed-hosts'), 'utf8')).toEndWith('\nclaude\nfactory\n');
|
||||
expect(skillFiles(path.join(src, '.factory')).length).toBeGreaterThan(40);
|
||||
expect(fs.existsSync(path.join(f.home, '.factory/skills/gstack-qa/SKILL.md'))).toBe(true);
|
||||
}, 240_000);
|
||||
});
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('gstack-upgrade migration prunes existing installs (#1694)', () => {
|
||||
const migrations = fs.readdirSync(path.join(ROOT, 'gstack-upgrade/migrations'))
|
||||
.filter(n => fs.readFileSync(path.join(ROOT, 'gstack-upgrade/migrations', n), 'utf8').includes('gstack-host-renders.sh'));
|
||||
|
||||
test('exactly one migration owns the prune, and setup runs it (not newer than VERSION)', () => {
|
||||
expect(migrations).toEqual([expect.stringMatching(/^v\d+\.\d+\.\d+\.\d+\.sh$/)]);
|
||||
const parts = (v: string) => v.split('.').map(Number);
|
||||
const mine = parts(migrations[0]!.slice(1, -3));
|
||||
const version = parts(fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf8').trim());
|
||||
const cmp = mine.map((n, i) => n - version[i]!).find(d => d !== 0) ?? 0;
|
||||
expect(cmp).toBeLessThanOrEqual(0);
|
||||
});
|
||||
|
||||
function migrate(f: Fixture, install: string) {
|
||||
return spawnSync('bash', [path.join(install, 'gstack-upgrade/migrations', migrations[0]!)], {
|
||||
cwd: f.home, encoding: 'utf8', timeout: 60_000, env: { ...f.env, GSTACK_INSTALL_DIR: install },
|
||||
});
|
||||
}
|
||||
|
||||
test('a pre-record Claude install: renders of other hosts are backed up and removed, a look-alike survives, rerun is a no-op', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
await legacyRender(src);
|
||||
put(path.join(src, '.opencode/skills/mine/SKILL.md'), 'no banner\n');
|
||||
const r = migrate(f, src);
|
||||
expect(r.status, r.stdout + r.stderr).toBe(0);
|
||||
expect(fs.readFileSync(path.join(src, '.gstack-installed-hosts'), 'utf8')).toEndWith('\nclaude\n');
|
||||
expect(skillFiles(src).filter(rel => rel.startsWith('.'))).toEqual(['.opencode/skills/mine/SKILL.md']);
|
||||
expect(r.stdout).toContain('kept .opencode/skills/mine/SKILL.md: not proven generated');
|
||||
expect(backups(f)).toHaveLength(1);
|
||||
const again = migrate(f, src);
|
||||
expect(again.status).toBe(0);
|
||||
expect(again.stdout).not.toContain('pruned ');
|
||||
expect(backups(f)).toHaveLength(1);
|
||||
}, 240_000);
|
||||
|
||||
test('a checkout no install points at is left alone', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, 'elsewhere/gstack'));
|
||||
await legacyRender(src);
|
||||
const before = skillFiles(src).length;
|
||||
const r = migrate(f, src);
|
||||
expect(r.status).toBe(0);
|
||||
expect(r.stdout).toContain(`host renders: no install from ${src} was found, so its renders were left alone`);
|
||||
expect(skillFiles(src).length).toBe(before);
|
||||
expect(fs.existsSync(path.join(src, '.gstack-installed-hosts'))).toBe(false);
|
||||
}, 240_000);
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* #1694 host-render prune: two installs sharing one state root each keep only their own hosts.
|
||||
* Split from test/host-renders-prune.test.ts so the free-suite packer can balance it (60 s seed ceiling).
|
||||
*/
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource } from './helpers/install-fixture';
|
||||
import { OTHER_DIRS, backups, legacyRender, setupOk, skillFiles } from './helpers/host-renders-prune-fixture';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('setup prunes unrecorded host renders without losing a file (#1694)', () => {
|
||||
test('two installs sharing one state root each end with only their own hosts', async () => {
|
||||
const f = makeFixture();
|
||||
const a = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
const b = makeSource(f, path.join(f.home, 'src-b/gstack'));
|
||||
await legacyRender(a);
|
||||
await legacyRender(b);
|
||||
setupOk(f, a);
|
||||
setupOk(f, b, ['--host', 'codex']);
|
||||
for (const dir of OTHER_DIRS) expect(fs.existsSync(path.join(a, dir)), `a ${dir}`).toBe(false);
|
||||
expect(skillFiles(path.join(b, '.agents')).length).toBeGreaterThan(40);
|
||||
for (const dir of OTHER_DIRS.filter(d => d !== '.agents')) expect(fs.existsSync(path.join(b, dir)), `b ${dir}`).toBe(false);
|
||||
expect(backups(f)).toHaveLength(2);
|
||||
}, 240_000);
|
||||
});
|
||||
@@ -8,39 +8,19 @@
|
||||
* identity) is moved to $GSTACK_STATE_ROOT/backups/host-renders/; anything
|
||||
* else stays; only emptied directories are removed. The legacy layout here is
|
||||
* a real `--host all` render.
|
||||
*
|
||||
* Split by test so the free-suite packer can balance the suite (60 s seed ceiling):
|
||||
* test/host-renders-prune-shared-root.test.ts and test/host-renders-prune-migration.test.ts hold the rest.
|
||||
*/
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { runGeneration } from '../scripts/gen-skill-docs';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, put, runSetup, type Fixture } from './helpers/install-fixture';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const OTHER_DIRS = ['.agents', '.factory', '.kiro', '.opencode', '.cursor', '.copilot', '.agy', '.slate', '.openclaw', '.hermes', '.gbrain'];
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, put } from './helpers/install-fixture';
|
||||
import { backups, legacyRender, setupOk, skillFiles } from './helpers/host-renders-prune-fixture';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
const skillFiles = (dir: string): string[] => !fs.existsSync(dir) ? []
|
||||
: (fs.readdirSync(dir, { recursive: true }) as string[]).filter(rel => path.basename(rel) === 'SKILL.md' && fs.statSync(path.join(dir, rel)).isFile());
|
||||
|
||||
async function legacyRender(src: string): Promise<void> {
|
||||
const result = await runGeneration({ host: 'all', outputRoot: src });
|
||||
if (result.exitCode !== 0) throw new Error('legacy render failed');
|
||||
}
|
||||
|
||||
function backups(f: Fixture): string[] {
|
||||
const dir = path.join(f.home, '.gstack/backups/host-renders');
|
||||
return fs.existsSync(dir) ? fs.readdirSync(dir).map(d => path.join(dir, d)) : [];
|
||||
}
|
||||
|
||||
function setupOk(f: Fixture, src: string, args: string[] = []) {
|
||||
const r = runSetup(f, path.join(src, 'setup'), args);
|
||||
expect(r.status, r.stdout + r.stderr).toBe(0);
|
||||
return r;
|
||||
}
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('setup prunes unrecorded host renders without losing a file (#1694)', () => {
|
||||
test('a legacy all-host render inside a Claude install: generated files backed up, user files kept, links handled', async () => {
|
||||
const f = makeFixture();
|
||||
@@ -90,79 +70,4 @@ describe.skipIf(process.platform === 'win32')('setup prunes unrecorded host rend
|
||||
expect(again.stdout).not.toContain('host-render backup');
|
||||
expect(backups(f)).toHaveLength(1);
|
||||
}, 240_000);
|
||||
|
||||
test('two installs sharing one state root each end with only their own hosts', async () => {
|
||||
const f = makeFixture();
|
||||
const a = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
const b = makeSource(f, path.join(f.home, 'src-b/gstack'));
|
||||
await legacyRender(a);
|
||||
await legacyRender(b);
|
||||
setupOk(f, a);
|
||||
setupOk(f, b, ['--host', 'codex']);
|
||||
for (const dir of OTHER_DIRS) expect(fs.existsSync(path.join(a, dir)), `a ${dir}`).toBe(false);
|
||||
expect(skillFiles(path.join(b, '.agents')).length).toBeGreaterThan(40);
|
||||
for (const dir of OTHER_DIRS.filter(d => d !== '.agents')) expect(fs.existsSync(path.join(b, dir)), `b ${dir}`).toBe(false);
|
||||
expect(backups(f)).toHaveLength(2);
|
||||
}, 240_000);
|
||||
|
||||
test('a host whose skills link into the render is kept even with no registry row', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
await legacyRender(src);
|
||||
fs.mkdirSync(path.join(f.home, '.factory/skills'), { recursive: true });
|
||||
fs.symlinkSync(path.join(src, '.factory/skills/gstack-qa'), path.join(f.home, '.factory/skills/gstack-qa'));
|
||||
setupOk(f, src);
|
||||
expect(fs.readFileSync(path.join(src, '.gstack-installed-hosts'), 'utf8')).toEndWith('\nclaude\nfactory\n');
|
||||
expect(skillFiles(path.join(src, '.factory')).length).toBeGreaterThan(40);
|
||||
expect(fs.existsSync(path.join(f.home, '.factory/skills/gstack-qa/SKILL.md'))).toBe(true);
|
||||
}, 240_000);
|
||||
});
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('gstack-upgrade migration prunes existing installs (#1694)', () => {
|
||||
const migrations = fs.readdirSync(path.join(ROOT, 'gstack-upgrade/migrations'))
|
||||
.filter(n => fs.readFileSync(path.join(ROOT, 'gstack-upgrade/migrations', n), 'utf8').includes('gstack-host-renders.sh'));
|
||||
|
||||
test('exactly one migration owns the prune, and setup runs it (not newer than VERSION)', () => {
|
||||
expect(migrations).toEqual([expect.stringMatching(/^v\d+\.\d+\.\d+\.\d+\.sh$/)]);
|
||||
const parts = (v: string) => v.split('.').map(Number);
|
||||
const mine = parts(migrations[0]!.slice(1, -3));
|
||||
const version = parts(fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf8').trim());
|
||||
const cmp = mine.map((n, i) => n - version[i]!).find(d => d !== 0) ?? 0;
|
||||
expect(cmp).toBeLessThanOrEqual(0);
|
||||
});
|
||||
|
||||
function migrate(f: Fixture, install: string) {
|
||||
return spawnSync('bash', [path.join(install, 'gstack-upgrade/migrations', migrations[0]!)], {
|
||||
cwd: f.home, encoding: 'utf8', timeout: 60_000, env: { ...f.env, GSTACK_INSTALL_DIR: install },
|
||||
});
|
||||
}
|
||||
|
||||
test('a pre-record Claude install: renders of other hosts are backed up and removed, a look-alike survives, rerun is a no-op', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
await legacyRender(src);
|
||||
put(path.join(src, '.opencode/skills/mine/SKILL.md'), 'no banner\n');
|
||||
const r = migrate(f, src);
|
||||
expect(r.status, r.stdout + r.stderr).toBe(0);
|
||||
expect(fs.readFileSync(path.join(src, '.gstack-installed-hosts'), 'utf8')).toEndWith('\nclaude\n');
|
||||
expect(skillFiles(src).filter(rel => rel.startsWith('.'))).toEqual(['.opencode/skills/mine/SKILL.md']);
|
||||
expect(r.stdout).toContain('kept .opencode/skills/mine/SKILL.md: not proven generated');
|
||||
expect(backups(f)).toHaveLength(1);
|
||||
const again = migrate(f, src);
|
||||
expect(again.status).toBe(0);
|
||||
expect(again.stdout).not.toContain('pruned ');
|
||||
expect(backups(f)).toHaveLength(1);
|
||||
}, 240_000);
|
||||
|
||||
test('a checkout no install points at is left alone', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, 'elsewhere/gstack'));
|
||||
await legacyRender(src);
|
||||
const before = skillFiles(src).length;
|
||||
const r = migrate(f, src);
|
||||
expect(r.status).toBe(0);
|
||||
expect(r.stdout).toContain(`host renders: no install from ${src} was found, so its renders were left alone`);
|
||||
expect(skillFiles(src).length).toBe(before);
|
||||
expect(fs.existsSync(path.join(src, '.gstack-installed-hosts'))).toBe(false);
|
||||
}, 240_000);
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Split from test/setup-codex-scope-namespaces.test.ts so the free-suite packer can balance it (60 s seed ceiling): supported generation-namespace and generated-skill leaf aliases.
|
||||
*/
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { existsSync, readFileSync, symlinkSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { cleanupFixtures, cleanupSeed, fixtureWriteFileSync, fixtureMkdirSync, fixtureUtimesSync, tree, fixture, install } from './helpers/install-fixture';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('setup Codex destination follows recognized source scope', () => {
|
||||
for (const level of ['agents', 'skills']) for (const preexisting of [false, true]) for (const windows of [false, true]) test(`internal generation namespace alias remains supported: ${level}, preexisting=${preexisting}, Windows=${windows}`, () => {
|
||||
const f = fixture('.claude');
|
||||
const internal = join(f.source, 'generated-codex');
|
||||
fixtureMkdirSync(internal);
|
||||
if (level === 'agents') symlinkSync(internal, join(f.source, '.agents'), 'dir');
|
||||
else {
|
||||
fixtureMkdirSync(join(f.source, '.agents'));
|
||||
symlinkSync(internal, join(f.source, '.agents/skills'), 'dir');
|
||||
}
|
||||
const generated = join(f.source, '.agents/skills');
|
||||
if (preexisting) {
|
||||
fixtureMkdirSync(join(generated, 'gstack-review'), { recursive: true });
|
||||
fixtureWriteFileSync(join(generated, 'gstack-review/SKILL.md'), 'Prior internal render.\n');
|
||||
}
|
||||
if (windows) {
|
||||
fixtureWriteFileSync(join(f.dir, 'commands/uname'), '#!/bin/sh\nprintf "MINGW64_NT-10.0\\n"\n', { mode: 0o755 });
|
||||
for (const rel of ['browse/dist/browse.exe', 'design/dist/design.exe', 'make-pdf/dist/pdf.exe']) {
|
||||
fixtureWriteFileSync(join(f.source, rel), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
||||
fixtureUtimesSync(join(f.source, rel), new Date('2040-01-01'), new Date('2040-01-01'));
|
||||
}
|
||||
}
|
||||
fixtureWriteFileSync(join(f.source, 'uncommitted-work'), 'Preserve source edits.\n');
|
||||
const excluded = tree(f.global), sibling = tree(f.other);
|
||||
const sourceBefore = Object.fromEntries(['SKILL.md', 'bin', 'lib', 'uncommitted-work'].map(rel => [rel, tree(join(f.source, rel))]));
|
||||
for (let run = 0; run < 2; run++) {
|
||||
install(f);
|
||||
expect(tree(f.global)).toEqual(excluded);
|
||||
expect(tree(f.other)).toEqual(sibling);
|
||||
for (const [rel, before] of Object.entries(sourceBefore)) expect(tree(join(f.source, rel))).toEqual(before);
|
||||
expect(readFileSync(join(f.project, '.agents/skills/gstack-review/SKILL.md'))).toEqual(readFileSync(join(generated, 'gstack-review/SKILL.md')));
|
||||
expect(existsSync(join(f.source, 'bin/bin'))).toBe(false);
|
||||
}
|
||||
}, 90_000);
|
||||
|
||||
for (const windows of [false, true]) test(`individual generated skill leaf alias remains supported, Windows=${windows}`, () => {
|
||||
const f = fixture('.claude');
|
||||
const rendered = join(f.source, '.agents/skills/gstack-review');
|
||||
const local = join(f.project, '.agents/skills');
|
||||
fixtureMkdirSync(rendered, { recursive: true });
|
||||
fixtureMkdirSync(local, { recursive: true });
|
||||
fixtureWriteFileSync(join(rendered, 'user-notes'), 'Keep notes beside the source render.\n');
|
||||
symlinkSync(rendered, join(local, 'gstack-review'), 'dir');
|
||||
if (windows) {
|
||||
fixtureWriteFileSync(join(f.dir, 'commands/uname'), '#!/bin/sh\nprintf "MINGW64_NT-10.0\\n"\n', { mode: 0o755 });
|
||||
for (const rel of ['browse/dist/browse.exe', 'design/dist/design.exe', 'make-pdf/dist/pdf.exe']) {
|
||||
fixtureWriteFileSync(join(f.source, rel), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
||||
fixtureUtimesSync(join(f.source, rel), new Date('2040-01-01'), new Date('2040-01-01'));
|
||||
}
|
||||
}
|
||||
const excluded = tree(f.global);
|
||||
for (let run = 0; run < 2; run++) {
|
||||
install(f);
|
||||
expect(tree(f.global)).toEqual(excluded);
|
||||
expect(readFileSync(join(rendered, 'user-notes'), 'utf8')).toBe('Keep notes beside the source render.\n');
|
||||
expect(readFileSync(join(local, 'gstack-review/SKILL.md'))).toEqual(readFileSync(join(rendered, 'SKILL.md')));
|
||||
}
|
||||
}, 90_000);
|
||||
});
|
||||
@@ -2,7 +2,7 @@ import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { cpSync, existsSync, readFileSync, realpathSync, rmSync, symlinkSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { cleanupFixtures, cleanupSeed, fixtureWriteFileSync, fixtureCopyFileSync, fixtureMkdirSync, fixtureUtimesSync, tree, fixture, install } from './helpers/install-fixture';
|
||||
import { cleanupFixtures, cleanupSeed, fixtureWriteFileSync, fixtureCopyFileSync, fixtureMkdirSync, tree, fixture, install } from './helpers/install-fixture';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
@@ -195,64 +195,6 @@ describe.skipIf(process.platform === 'win32')('setup Codex destination follows r
|
||||
}
|
||||
}, 90_000);
|
||||
|
||||
for (const level of ['agents', 'skills']) for (const preexisting of [false, true]) for (const windows of [false, true]) test(`internal generation namespace alias remains supported: ${level}, preexisting=${preexisting}, Windows=${windows}`, () => {
|
||||
const f = fixture('.claude');
|
||||
const internal = join(f.source, 'generated-codex');
|
||||
fixtureMkdirSync(internal);
|
||||
if (level === 'agents') symlinkSync(internal, join(f.source, '.agents'), 'dir');
|
||||
else {
|
||||
fixtureMkdirSync(join(f.source, '.agents'));
|
||||
symlinkSync(internal, join(f.source, '.agents/skills'), 'dir');
|
||||
}
|
||||
const generated = join(f.source, '.agents/skills');
|
||||
if (preexisting) {
|
||||
fixtureMkdirSync(join(generated, 'gstack-review'), { recursive: true });
|
||||
fixtureWriteFileSync(join(generated, 'gstack-review/SKILL.md'), 'Prior internal render.\n');
|
||||
}
|
||||
if (windows) {
|
||||
fixtureWriteFileSync(join(f.dir, 'commands/uname'), '#!/bin/sh\nprintf "MINGW64_NT-10.0\\n"\n', { mode: 0o755 });
|
||||
for (const rel of ['browse/dist/browse.exe', 'design/dist/design.exe', 'make-pdf/dist/pdf.exe']) {
|
||||
fixtureWriteFileSync(join(f.source, rel), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
||||
fixtureUtimesSync(join(f.source, rel), new Date('2040-01-01'), new Date('2040-01-01'));
|
||||
}
|
||||
}
|
||||
fixtureWriteFileSync(join(f.source, 'uncommitted-work'), 'Preserve source edits.\n');
|
||||
const excluded = tree(f.global), sibling = tree(f.other);
|
||||
const sourceBefore = Object.fromEntries(['SKILL.md', 'bin', 'lib', 'uncommitted-work'].map(rel => [rel, tree(join(f.source, rel))]));
|
||||
for (let run = 0; run < 2; run++) {
|
||||
install(f);
|
||||
expect(tree(f.global)).toEqual(excluded);
|
||||
expect(tree(f.other)).toEqual(sibling);
|
||||
for (const [rel, before] of Object.entries(sourceBefore)) expect(tree(join(f.source, rel))).toEqual(before);
|
||||
expect(readFileSync(join(f.project, '.agents/skills/gstack-review/SKILL.md'))).toEqual(readFileSync(join(generated, 'gstack-review/SKILL.md')));
|
||||
expect(existsSync(join(f.source, 'bin/bin'))).toBe(false);
|
||||
}
|
||||
}, 90_000);
|
||||
|
||||
for (const windows of [false, true]) test(`individual generated skill leaf alias remains supported, Windows=${windows}`, () => {
|
||||
const f = fixture('.claude');
|
||||
const rendered = join(f.source, '.agents/skills/gstack-review');
|
||||
const local = join(f.project, '.agents/skills');
|
||||
fixtureMkdirSync(rendered, { recursive: true });
|
||||
fixtureMkdirSync(local, { recursive: true });
|
||||
fixtureWriteFileSync(join(rendered, 'user-notes'), 'Keep notes beside the source render.\n');
|
||||
symlinkSync(rendered, join(local, 'gstack-review'), 'dir');
|
||||
if (windows) {
|
||||
fixtureWriteFileSync(join(f.dir, 'commands/uname'), '#!/bin/sh\nprintf "MINGW64_NT-10.0\\n"\n', { mode: 0o755 });
|
||||
for (const rel of ['browse/dist/browse.exe', 'design/dist/design.exe', 'make-pdf/dist/pdf.exe']) {
|
||||
fixtureWriteFileSync(join(f.source, rel), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
||||
fixtureUtimesSync(join(f.source, rel), new Date('2040-01-01'), new Date('2040-01-01'));
|
||||
}
|
||||
}
|
||||
const excluded = tree(f.global);
|
||||
for (let run = 0; run < 2; run++) {
|
||||
install(f);
|
||||
expect(tree(f.global)).toEqual(excluded);
|
||||
expect(readFileSync(join(rendered, 'user-notes'), 'utf8')).toBe('Keep notes beside the source render.\n');
|
||||
expect(readFileSync(join(local, 'gstack-review/SKILL.md'))).toEqual(readFileSync(join(rendered, 'SKILL.md')));
|
||||
}
|
||||
}, 90_000);
|
||||
|
||||
for (const target of ['dangling-skills', 'dangling-agents', 'cyclic-skills', 'file-skills']) test(`unresolvable namespace is refused without mutation: ${target}`, () => {
|
||||
const f = fixture('.claude');
|
||||
const agents = join(f.project, '.agents');
|
||||
|
||||
@@ -1,45 +1,16 @@
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { existsSync, lstatSync, rmSync, symlinkSync } from 'node:fs';
|
||||
import { symlinkSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { cleanupFixtures, cleanupSeed, fixtureWriteFileSync, fixtureCopyFileSync, fixtureMkdirSync, fixtureUtimesSync, tree, fixture, install } from './helpers/install-fixture';
|
||||
import { cleanupFixtures, cleanupSeed, fixtureWriteFileSync, fixtureCopyFileSync, fixtureMkdirSync, fixtureUtimesSync, tree, fixture } from './helpers/install-fixture';
|
||||
import { claudeOnlySetupPreservesCyclicLink } from './helpers/setup-codex-scope-cyclic';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('F13 independent review boundaries', () => {
|
||||
for (const target of ['legacy', 'replacement', 'legacy-skill', 'runtime', 'runtime-bin', 'runtime-lib']) {
|
||||
test(`Claude-only setup preserves cyclic foreign ownership link: ${target}`, () => {
|
||||
const f = fixture('ordinary');
|
||||
rmSync(join(f.global, 'gstack-retired'));
|
||||
for (const rel of ['bin', 'lib']) {
|
||||
const asset = join(f.global, 'gstack', rel);
|
||||
rmSync(asset);
|
||||
symlinkSync(join(f.source, rel), asset, 'dir');
|
||||
}
|
||||
const old = join(f.global, 'gstack-claude');
|
||||
rmSync(old, { recursive: true });
|
||||
const oldRender = join(f.source, '.agents/skills/gstack-claude');
|
||||
fixtureMkdirSync(oldRender, { recursive: true });
|
||||
fixtureWriteFileSync(join(oldRender, 'SKILL.md'), '<!-- AUTO-GENERATED from SKILL.md.tmpl -->\n<!-- Regenerate: bun run gen:skill-docs -->\nPrior legacy render.\n');
|
||||
symlinkSync(oldRender, old, 'dir');
|
||||
const link = target === 'legacy' ? old
|
||||
: target === 'replacement' ? join(f.global, 'gstack-claude-code')
|
||||
: target === 'legacy-skill' ? join(old, 'SKILL.md')
|
||||
: target === 'runtime' ? join(f.global, 'gstack')
|
||||
: join(f.global, 'gstack', target === 'runtime-bin' ? 'bin' : 'lib');
|
||||
if (target === 'legacy-skill') {
|
||||
rmSync(old);
|
||||
fixtureMkdirSync(old);
|
||||
}
|
||||
if (existsSync(link) || lstatSync(link, { throwIfNoEntry: false })) rmSync(link, { recursive: true });
|
||||
symlinkSync(link, link);
|
||||
const before = tree(f.global);
|
||||
for (let run = 0; run < 2; run++) {
|
||||
install(f, '--host claude');
|
||||
expect(tree(f.global)).toEqual(before);
|
||||
}
|
||||
}, 90_000);
|
||||
for (const target of ['legacy', 'replacement', 'legacy-skill']) {
|
||||
test(`Claude-only setup preserves cyclic foreign ownership link: ${target}`, () => claudeOnlySetupPreservesCyclicLink(target), 90_000);
|
||||
}
|
||||
|
||||
for (const alias of [false, true]) for (const windows of [false, true]) {
|
||||
@@ -86,5 +57,4 @@ describe.skipIf(process.platform === 'win32')('F13 independent review boundaries
|
||||
}
|
||||
}, 90_000);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* F13 independent review boundaries: Claude-only setup preserves cyclic foreign ownership links inside the runtime.
|
||||
* Split from test/setup-codex-scope-review-boundaries.test.ts so the free-suite packer can balance it (60 s seed ceiling).
|
||||
*/
|
||||
import { afterAll, afterEach, describe, test } from 'bun:test';
|
||||
import { cleanupFixtures, cleanupSeed } from './helpers/install-fixture';
|
||||
import { claudeOnlySetupPreservesCyclicLink } from './helpers/setup-codex-scope-cyclic';
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('F13 independent review boundaries', () => {
|
||||
for (const target of ['runtime', 'runtime-bin', 'runtime-lib']) {
|
||||
test(`Claude-only setup preserves cyclic foreign ownership link: ${target}`, () => claudeOnlySetupPreservesCyclicLink(target), 90_000);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,178 @@
|
||||
// Split from test/shared-libs-checker-interface-evidence.test.ts (GSTA-151): the cases that replay the declared-protocol captures.
|
||||
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { sharedLibsFingerprint } from '../lib/review-evidence';
|
||||
import { hasTrustedSharedLibsCheck, hasTrustedReviewStartRead } from './helpers/shared-libs-review-start-evidence';
|
||||
import {
|
||||
fixtureGit, fixtureWorkingTree, reviewRecords, SHARED_LIBS_ROOT, toolCommandTrace, type SharedLibsFixture,
|
||||
} from './helpers/shared-libs-eval-fixture';
|
||||
import {
|
||||
preparePathEligibilityFixture, checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt,
|
||||
} from './helpers/shared-libs-path-fixture';
|
||||
import { fixtures, captures, pathKinds, capture, replay, call, result, pathCallback } from './helpers/shared-libs-checker-evidence';
|
||||
|
||||
const source = fs.readFileSync(path.join(import.meta.dir, 'skill-e2e-shared-libs.test.ts'), 'utf8');
|
||||
|
||||
beforeAll(async () => {
|
||||
for (const change of ['unchanged', 'secondary', 'branch', 'filtered']) captures.set(`declared-${change}`, await capture(change, undefined, true));
|
||||
for (const kind of pathKinds) captures.set(`declared-path-${kind}`, await capture(`path-${kind}`, preparePathEligibilityFixture(kind), true));
|
||||
}, 120_000);
|
||||
afterAll(() => { for (const fixture of fixtures) fs.rmSync(fixture.root, { recursive: true, force: true }); });
|
||||
|
||||
describe('native executable shared-code checker evidence', () => {
|
||||
test('the actual path callback consumes the current synthetic prerequisite result without claiming native coverage', async () => {
|
||||
const run = replay('declared-path-assume-unchanged');
|
||||
run.kind = 'assume-unchanged';
|
||||
let verified = 0;
|
||||
const adapter = pathCallback(run, { hasPathReviewPrerequisiteReceipt: (events: any[], command: string, expected: any) => {
|
||||
verified++;
|
||||
expect(command).toBe(run.prepared.resumed.checkCommand);
|
||||
expect(expected).toMatchObject({ synthetic: true, native_coverage: false, settled: true, current: true });
|
||||
expect(expected.context.binding.repo).toBe(run.f.repo);
|
||||
expect(expected.context.binding.state).toBe(run.f.state);
|
||||
expect(expected.context.binding.index).toMatch(/^h /m);
|
||||
return hasPathReviewPrerequisiteReceipt(events, command, expected);
|
||||
} });
|
||||
await adapter.invoke();
|
||||
expect(verified).toBe(1);
|
||||
expect(adapter.rows[0].row.passed).toBe(true);
|
||||
expect(adapter.rows[0].row.transcript[0]).toMatchObject({
|
||||
prerequisite_source: 'synthetic-fixture-input', prerequisite_native_coverage: false,
|
||||
});
|
||||
const refused = pathCallback(run, { hasPathReviewPrerequisiteReceipt: () => false });
|
||||
await expect(refused.invoke()).rejects.toThrow('consume current synthetic prerequisites');
|
||||
expect(refused.rows[0].row.passed).toBe(false);
|
||||
});
|
||||
|
||||
test.each(['missing', 'failed', 'unpaired', 'assistant-only', 'caption', 'false', 'foreign state', 'after finish'])(
|
||||
'the registered path callback rejects %s prerequisite receipts even with a completed record', async invalid => {
|
||||
const run = replay('declared-path-ignored');
|
||||
run.kind = 'ignored';
|
||||
const at = run.events.findIndex((event: any) => event.type === 'assistant'
|
||||
&& event.message.content[0].input?.command === run.prepared.resumed.checkCommand);
|
||||
expect(at).toBeGreaterThan(run.checkAt);
|
||||
if (invalid === 'missing') run.events.splice(at, 2);
|
||||
if (invalid === 'failed') result(run, at).is_error = true;
|
||||
if (invalid === 'unpaired') result(run, at).tool_use_id = 'another-call';
|
||||
if (invalid === 'assistant-only') run.events[at + 1].type = 'assistant';
|
||||
if (invalid === 'caption') call(run, at).input = { command: 'true', description: run.prepared.resumed.checkCommand };
|
||||
if (invalid === 'false' || invalid === 'foreign state') {
|
||||
const receipt = JSON.parse(result(run, at).content);
|
||||
if (invalid === 'false') receipt.settled = false;
|
||||
else receipt.context.binding.state = '/another-fixture/state';
|
||||
result(run, at).content = JSON.stringify(receipt);
|
||||
}
|
||||
if (invalid === 'after finish') run.events.push(...run.events.splice(at, 2));
|
||||
const adapter = pathCallback(run);
|
||||
await expect(adapter.invoke()).rejects.toThrow('consume current synthetic prerequisites');
|
||||
expect(adapter.rows[0].row.passed).toBe(false);
|
||||
});
|
||||
|
||||
test.each(['raw source', 'supplied context'])('the registered callback rejects late changes to %s', async changed => {
|
||||
const run = replay('declared-path-assume-unchanged');
|
||||
run.kind = 'assume-unchanged';
|
||||
const file = changed === 'raw source' ? path.join(run.f.repo, 'src/retry-route.ts') : run.prepared.resumed.input;
|
||||
const before = fs.readFileSync(file, 'utf8');
|
||||
const adapter = pathCallback(run, { runSharedInteractive: async () => {
|
||||
fs.writeFileSync(file, before + '\n');
|
||||
return { questions: run.questions, result: { exitReason: 'success', output: '', events: run.events,
|
||||
toolCalls: run.events.filter((event: any) => event.type === 'assistant')
|
||||
.map((event: any) => ({ tool: event.message.content[0].name, input: event.message.content[0].input })) } };
|
||||
} });
|
||||
try {
|
||||
await expect(adapter.invoke()).rejects.toThrow('prerequisite state must remain unchanged');
|
||||
expect(adapter.rows[0].row.passed).toBe(false);
|
||||
} finally { fs.writeFileSync(file, before); }
|
||||
});
|
||||
|
||||
test.each(['unchanged', 'secondary', 'branch', 'filtered'])('declared receipt commands satisfy the real %s revalidation callback', change => {
|
||||
const run = replay(`declared-${change}`);
|
||||
expect(result(run, 0).content.trim()).toBe(run.token);
|
||||
expect(JSON.parse(result(run).content)).toEqual(run.receipt);
|
||||
expect(call(run, run.finishAt).input.command).toContain(`--finish ${run.token} && '${SHARED_LIBS_ROOT}/bin/gstack-review-read'`);
|
||||
expect(run.questions).toHaveLength(change === 'unchanged' ? 0 : 1);
|
||||
const scenario = source.slice(source.indexOf("test('shared-libs-review-revalidation'"));
|
||||
const marker = '}, result => {';
|
||||
const start = scenario.indexOf(marker) + marker.length;
|
||||
const body = scenario.slice(start, scenario.indexOf('\n });', start));
|
||||
const verify = new Function('deps', 'result', new Bun.Transpiler({ loader: 'ts' }).transformSync(`const {
|
||||
change, questions, expect, toolCommandTrace, reviewRecords, createHash, path, f, current,
|
||||
fixtureGit, fixtureWorkingTree, hasTrustedReviewStartRead, hasTrustedSharedLibsCheck, SHARED_LIBS_ROOT,
|
||||
resumed, prerequisites, checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt
|
||||
} = deps; ${body}`));
|
||||
const native = { events: run.events, toolCalls: run.events.filter((event: any) => event.type === 'assistant')
|
||||
.map((event: any) => ({ tool: event.message.content[0].name, input: event.message.content[0].input })) };
|
||||
let checks = 0;
|
||||
verify({ change, questions: run.questions, expect, toolCommandTrace, reviewRecords, createHash, path,
|
||||
f: run.f, current: run.current, fixtureGit, fixtureWorkingTree, hasTrustedReviewStartRead, SHARED_LIBS_ROOT,
|
||||
resumed: run.resumed, prerequisites: run.prerequisites, checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt,
|
||||
hasTrustedSharedLibsCheck: (events: unknown[], expected: any) => {
|
||||
checks++;
|
||||
expect(events).toBe(run.events);
|
||||
expect(expected).toEqual(run.expected);
|
||||
return hasTrustedSharedLibsCheck(events, expected);
|
||||
} }, native);
|
||||
expect(checks).toBe(1);
|
||||
});
|
||||
|
||||
test.each(pathKinds)('declared receipt commands satisfy the real %s path callback after an actual actor decision', async kind => {
|
||||
const run = replay(`declared-path-${kind}`);
|
||||
run.kind = kind;
|
||||
expect(result(run, 0).content.trim()).toBe(run.token);
|
||||
expect(JSON.parse(result(run).content)).toEqual(run.receipt);
|
||||
expect(run.receipt.reusable).toBe(false);
|
||||
expect(run.questions).toHaveLength(1);
|
||||
let checks = 0;
|
||||
const adapter = pathCallback(run, { hasTrustedSharedLibsCheck: (events: unknown[], expected: any) => {
|
||||
checks++;
|
||||
expect(expected).toEqual(run.expected);
|
||||
return hasTrustedSharedLibsCheck(events, expected);
|
||||
} });
|
||||
await adapter.invoke();
|
||||
expect(checks).toBe(1);
|
||||
expect(adapter.rows).toMatchObject([{ scenario: kind, row: { passed: true } }]);
|
||||
});
|
||||
|
||||
test.each(['revised-only identity', 'unsupported finding', 'unfinished review', 'missing explicit decision'])(
|
||||
'canonical transport cannot waive %s in the real ignored-path callback', async failure => {
|
||||
const run = replay('declared-path-ignored');
|
||||
run.kind = 'ignored';
|
||||
if (failure === 'missing explicit decision') run.questions = [];
|
||||
const adapter = pathCallback(run, { reviewRecords: (fixture: SharedLibsFixture) => {
|
||||
const records = reviewRecords(fixture);
|
||||
const final = records.at(-1);
|
||||
if (failure === 'revised-only identity') {
|
||||
const revised = { ...final.findings[0], evidence_paths: [
|
||||
'src/retry-worker.ts', 'src/scheduler.ts', 'src/retry-route.ts', 'lib/retry-after.ts',
|
||||
] };
|
||||
revised.fingerprint = sharedLibsFingerprint(revised);
|
||||
revised.snapshot_covered_paths = [...revised.evidence_paths];
|
||||
expect(revised.fingerprint).not.toBe(run.current.fingerprint);
|
||||
final.findings = [revised];
|
||||
}
|
||||
if (failure === 'unsupported finding') final.findings = [];
|
||||
if (failure === 'unfinished review') final.completed = false;
|
||||
return records;
|
||||
} });
|
||||
await expect(adapter.invoke()).rejects.toThrow();
|
||||
expect(adapter.rows).toMatchObject([{ scenario: 'ignored', row: { passed: false } }]);
|
||||
});
|
||||
|
||||
test.each(['start batching', 'mixed checker stdout', 'finish metadata prelude', 'loop-only caller reads'])(
|
||||
'the unchanged detector still rejects %s after protocol declaration', shape => {
|
||||
const run = replay('declared-unchanged');
|
||||
if (shape === 'start batching') call(run, 0).input.command = `echo start; ${call(run, 0).input.command}; git diff origin/main`;
|
||||
if (shape === 'mixed checker stdout') result(run).content = `checker receipt:\n${result(run).content}\nexit=0`;
|
||||
if (shape === 'finish metadata prelude') call(run, run.finishAt).input.command = `TS=$(date -u); ${call(run, run.finishAt).input.command}`;
|
||||
if (shape === 'loop-only caller reads') {
|
||||
for (const event of run.events) for (const block of event.message.content) {
|
||||
if (block.type === 'tool_use' && block.name === 'Bash' && block.input.command.startsWith('cat ')) {
|
||||
block.input.command = `for f in ${block.input.command.slice(4)}; do cat "$f"; done`;
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(hasTrustedSharedLibsCheck(run.events, run.expected)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,156 @@
|
||||
// Split from test/shared-libs-checker-interface-evidence.test.ts (GSTA-151): the cases that need no beforeAll capture (R59 public attempts, synthetic prerequisites, captured gate reads).
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { hasTrustedSharedLibsCheck } from './helpers/shared-libs-review-start-evidence';
|
||||
import { fixtureGit, fixtureWorkingTree } from './helpers/shared-libs-eval-fixture';
|
||||
import { preparePathEligibilityFixture, checkPathReviewPrerequisites } from './helpers/shared-libs-path-fixture';
|
||||
import { pathCallback, capturedPathRun } from './helpers/shared-libs-checker-evidence';
|
||||
import loopRead from './fixtures/shared-libs-index-flags-loop-read-39173752116.json';
|
||||
import erroredRead from './fixtures/shared-libs-path-ignored-errored-read-40617200857.json';
|
||||
|
||||
describe('native executable shared-code checker evidence', () => {
|
||||
test.each([0, 1])('the complete R59 public attempt %i satisfies the actual callback without a manual fingerprint call', async index => {
|
||||
const { run, overrides } = capturedPathRun(index);
|
||||
const commands = run.events.flatMap(event => event.message.content)
|
||||
.filter(block => block.type === 'tool_use' && block.name === 'Bash').map(block => block.input.command).join('\n');
|
||||
expect(commands).not.toContain('sharedLibsFingerprint');
|
||||
let checks = 0;
|
||||
const adapter = pathCallback(run, { ...overrides, hasTrustedSharedLibsCheck: (events: unknown[], expected: any) => {
|
||||
checks++;
|
||||
expect(events).toBe(run.events);
|
||||
expect(expected.finding).toEqual(run.prepared.current);
|
||||
expect(expected.reusable).toBe(false);
|
||||
expect(expected.coveredPaths).toEqual(['src/retry-worker.ts', 'lib/retry-after.ts']);
|
||||
return hasTrustedSharedLibsCheck(events, expected);
|
||||
} });
|
||||
await adapter.invoke();
|
||||
expect(checks).toBe(1);
|
||||
expect(adapter.rows).toMatchObject([{ scenario: 'assume-unchanged', row: { passed: true } }]);
|
||||
const refused = pathCallback(run, { ...overrides, hasTrustedSharedLibsCheck: () => false });
|
||||
await expect(refused.invoke()).rejects.toThrow();
|
||||
expect(refused.rows[0].row.passed).toBe(false);
|
||||
});
|
||||
|
||||
test.each([0, 1].flatMap(index => ['missing', 'failed', 'unpaired', 'fingerprint', 'binding', 'extra coverage'].map(invalid => [index, invalid] as const)))(
|
||||
'the R59 public attempt %i callback rejects a %s checker receipt', async (index, invalid) => {
|
||||
const { run, overrides } = capturedPathRun(index);
|
||||
const blocks = run.events.flatMap(event => event.message.content);
|
||||
const check = blocks.find(block => block.type === 'tool_use' && block.input.command?.includes('--check-shared-libs'));
|
||||
const receipt = blocks.find(block => block.type === 'tool_result' && block.tool_use_id === check.id);
|
||||
if (invalid === 'missing') receipt.content = '';
|
||||
else if (invalid === 'failed') receipt.is_error = true;
|
||||
else if (invalid === 'unpaired') receipt.tool_use_id = 'unpaired-checker';
|
||||
else {
|
||||
const value = JSON.parse(receipt.content);
|
||||
if (invalid === 'fingerprint') value.fingerprint = `shared-libs:${'a'.repeat(64)}`;
|
||||
if (invalid === 'binding') value.review_start.started_at = 'foreign';
|
||||
if (invalid === 'extra coverage') value.snapshot.covered_paths.push('src/retry-route.ts');
|
||||
receipt.content = JSON.stringify(value);
|
||||
}
|
||||
let checks = 0;
|
||||
const adapter = pathCallback(run, { ...overrides, hasTrustedSharedLibsCheck: (events: unknown[], expected: any) => {
|
||||
checks++;
|
||||
return hasTrustedSharedLibsCheck(events, expected);
|
||||
} });
|
||||
await expect(adapter.invoke()).rejects.toThrow();
|
||||
expect(checks).toBe(1);
|
||||
expect(adapter.rows[0].row.passed).toBe(false);
|
||||
});
|
||||
|
||||
test.each(['missing file', 'missing QA', 'empty probes', 'failed probe', 'missing native', 'failed native',
|
||||
'blocked native', 'foreign state', 'branch', 'base', 'index flag', 'raw hidden source', 'configuration', 'structured required'])(
|
||||
'synthetic prerequisites cannot settle with %s', async invalid => {
|
||||
const prepared = preparePathEligibilityFixture('assume-unchanged'), f = prepared.fixture;
|
||||
try {
|
||||
const original = checkPathReviewPrerequisites(f, prepared.resumed.input);
|
||||
expect(original.settled).toBe(true);
|
||||
const context = structuredClone(original.context);
|
||||
if (invalid === 'missing QA') delete context.qa;
|
||||
if (invalid === 'empty probes') context.qa.required_probes = [];
|
||||
if (invalid === 'failed probe') context.qa.required_probes[0].status = 'failed';
|
||||
if (invalid === 'missing native') delete context.native_adversarial;
|
||||
if (invalid === 'failed native' || invalid === 'blocked native') context.native_adversarial.status = invalid.split(' ')[0];
|
||||
if (invalid === 'foreign state') context.binding.state = '/another-fixture/state';
|
||||
if (invalid === 'structured required') context.structured_review.required = true;
|
||||
fs.writeFileSync(prepared.resumed.input, JSON.stringify(context));
|
||||
if (invalid === 'missing file') fs.unlinkSync(prepared.resumed.input);
|
||||
if (invalid === 'branch') fixtureGit(f, 'checkout', '-b', 'another-branch');
|
||||
if (invalid === 'base') fixtureGit(f, 'update-ref', 'refs/remotes/origin/main', 'HEAD~1');
|
||||
if (invalid === 'index flag') fixtureGit(f, 'update-index', '--no-assume-unchanged', 'src/retry-route.ts');
|
||||
if (invalid === 'raw hidden source') {
|
||||
fs.appendFileSync(path.join(f.repo, 'src/retry-route.ts'), '\n// Changed after the synthetic QA result\n');
|
||||
expect(fixtureWorkingTree(f)).toBe(original.context.binding.wtree);
|
||||
}
|
||||
if (invalid === 'configuration') fixtureGit(f, 'config', 'core.ignorecase', 'true');
|
||||
const checked = checkPathReviewPrerequisites(f, prepared.resumed.input);
|
||||
expect(checked.settled).toBe(false);
|
||||
expect(JSON.parse(execFileSync('bash', ['-c', prepared.resumed.checkCommand], {
|
||||
cwd: f.repo, env: { ...process.env, ...f.env }, encoding: 'utf8', timeout: 30_000,
|
||||
}))).toEqual(checked);
|
||||
const run = { f, prepared, kind: 'assume-unchanged', events: [] };
|
||||
const adapter = pathCallback(run);
|
||||
await expect(adapter.invoke()).rejects.toThrow('fixture prerequisites must be settled before capture');
|
||||
} finally { fs.rmSync(f.root, { recursive: true, force: true }); }
|
||||
});
|
||||
});
|
||||
|
||||
// Gate 39173752116 slice 12: the skip-worktree review read every evidence file in one
|
||||
// literal for-loop that printed each path before its contents.
|
||||
describe('literal loop reads from the captured skip-worktree review', () => {
|
||||
const loop = (events: any[]) => events.flatMap(event => event.message.content)
|
||||
.find((block: any) => block.type === 'tool_use' && block.input?.command?.startsWith('for f in '));
|
||||
const output = (events: any[], id: string) => events.flatMap(event => event.message.content)
|
||||
.find((block: any) => block.type === 'tool_result' && block.tool_use_id === id);
|
||||
|
||||
test('a literal loop whose output names each evidence file counts as reading it', () => {
|
||||
expect(hasTrustedSharedLibsCheck(structuredClone(loopRead.events), loopRead.expected)).toBe(true);
|
||||
});
|
||||
|
||||
test.each(['variable list', 'file missing from output', 'path outside the repo'])('%s is still rejected', shape => {
|
||||
const events = structuredClone(loopRead.events), call = loop(events), files = 'src/retry-worker.ts src/retry-route.ts lib/retry-after.ts';
|
||||
expect(call.input.command).toContain(`for f in ${files} `);
|
||||
if (shape === 'variable list') call.input.command = `FILES="${files}"; ${call.input.command.replace(files, '$FILES')}`;
|
||||
if (shape === 'file missing from output') {
|
||||
const result = output(events, call.id);
|
||||
result.content = JSON.parse(JSON.stringify(result.content).replaceAll('src/retry-route.ts', 'src/omitted.ts'));
|
||||
}
|
||||
if (shape === 'path outside the repo') call.input.command = call.input.command.replace(' src/retry-route.ts ', ' ../outside/src/retry-route.ts ');
|
||||
expect(hasTrustedSharedLibsCheck(events, loopRead.expected)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// Gate 40617200857 slice 8: the ignored-path review returned all of src/retry-worker.ts through
|
||||
// cat -n, then a later `echo ===` in the same call failed, so the result carried is_error.
|
||||
describe('errored Bash reads from the captured ignored-path review', () => {
|
||||
const blocks = (events: any[]) => events.flatMap(event => event.message.content);
|
||||
const read = (events: any[]) => blocks(events).find((block: any) => block.type === 'tool_use'
|
||||
&& block.input?.command?.startsWith('cat -n src/retry-worker.ts; echo ===;'));
|
||||
const output = (events: any[], id: string) => blocks(events).find((block: any) => block.type === 'tool_result' && block.tool_use_id === id);
|
||||
|
||||
test('a whole evidence source returned before a later failure counts as reading it', () => {
|
||||
const events = structuredClone(erroredRead.events);
|
||||
expect(output(events, read(events).id).is_error).toBe(true);
|
||||
expect(hasTrustedSharedLibsCheck(events, erroredRead.expected)).toBe(true);
|
||||
});
|
||||
|
||||
test.each(['no expected sources', 'empty expected source', 'last source line missing', 'missing file', 'errored single read', 'errored native Read', 'errored checker'])('%s is still rejected', shape => {
|
||||
const events = structuredClone(erroredRead.events), call = read(events), result = output(events, call.id);
|
||||
const expected: any = structuredClone(erroredRead.expected);
|
||||
if (shape === 'no expected sources') delete expected.sources;
|
||||
if (shape === 'empty expected source') expected.sources['src/retry-worker.ts'] = '';
|
||||
if (shape === 'last source line missing') result.content = result.content.replace(/\n +15\t\}\n/, '\n');
|
||||
if (shape === 'missing file') result.content = 'Exit code 1\ncat: src/retry-worker.ts: No such file or directory';
|
||||
if (shape === 'errored single read') call.input.command = 'cat -n src/retry-worker.ts';
|
||||
if (shape === 'errored native Read') {
|
||||
call.name = 'Read';
|
||||
call.input = { file_path: 'src/retry-worker.ts' };
|
||||
}
|
||||
if (shape === 'errored checker') {
|
||||
const checker = blocks(events).find((block: any) => block.type === 'tool_use' && block.input?.command?.includes('--check-shared-libs'));
|
||||
output(events, checker.id).is_error = true;
|
||||
}
|
||||
expect(hasTrustedSharedLibsCheck(events, expected)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,373 +1,26 @@
|
||||
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { sharedLibsFingerprint } from '../lib/review-evidence';
|
||||
import { hasTrustedSharedLibsCheck, hasTrustedReviewStartRead } from './helpers/shared-libs-review-start-evidence';
|
||||
import {
|
||||
createSharedInteractiveToolHandler, createSharedLibsFixture, fixtureGit, fixtureWorkingTree, fixtureWrite, installNormalizingFilter,
|
||||
reviewLifecycleInstructions, reviewRevalidationPrompt, reviewRecords, seedReviewSources, seedSkippedAdvisory,
|
||||
SHARED_LIBS_ROOT, shellQuote, toolCommandTrace,
|
||||
fixtureGit, fixtureWorkingTree, reviewRecords, SHARED_LIBS_ROOT, shellQuote, toolCommandTrace,
|
||||
type SharedLibsFixture,
|
||||
} from './helpers/shared-libs-eval-fixture';
|
||||
import {
|
||||
preparePathEligibilityFixture, seedPathReviewPrerequisites, checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt, type PathEligibilityFixture,
|
||||
preparePathEligibilityFixture, checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt,
|
||||
} from './helpers/shared-libs-path-fixture';
|
||||
import { CAPTURE_LONG_MS } from './helpers/eval-budgets';
|
||||
import capturedChecker from './fixtures/shared-libs-index-flags-r59-checker-public.json';
|
||||
import loopRead from './fixtures/shared-libs-index-flags-loop-read-39173752116.json';
|
||||
import erroredRead from './fixtures/shared-libs-path-ignored-errored-read-40617200857.json';
|
||||
import { helper, fixtures, captures, pathKinds, capture, replay, call, result, alterReceipt, pathCallback } from './helpers/shared-libs-checker-evidence';
|
||||
|
||||
const helper = path.join(SHARED_LIBS_ROOT, 'bin/gstack-review-log');
|
||||
const fixtures: SharedLibsFixture[] = [];
|
||||
const captures = new Map<string, any>();
|
||||
const source = fs.readFileSync(path.join(import.meta.dir, 'skill-e2e-shared-libs.test.ts'), 'utf8');
|
||||
const pathSource = fs.readFileSync(path.join(import.meta.dir, 'skill-e2e-shared-libs-paths.test.ts'), 'utf8');
|
||||
const pathKinds = ['symlinks', 'submodule', 'ignored', 'legacy', 'assume-unchanged', 'skip-worktree', 'removed-filter'] as const;
|
||||
|
||||
async function capture(change: string, prepared?: PathEligibilityFixture, declared = false) {
|
||||
const f = prepared?.fixture ?? createSharedLibsFixture(`checker-${change}`);
|
||||
fixtures.push(f);
|
||||
let current = prepared?.current;
|
||||
if (!current) {
|
||||
seedReviewSources(f);
|
||||
fixtureWrite(f, 'src/retry-worker.ts', fs.readFileSync(path.join(f.repo, 'src/retry-worker.ts'), 'utf8')
|
||||
.replace('const unusedRetryDiagnostic = "unused";\n', ''));
|
||||
if (change === 'filtered') installNormalizingFilter(f);
|
||||
const { action: _action, ...finding } = await seedSkippedAdvisory(f);
|
||||
current = finding;
|
||||
if (change === 'branch') fixtureGit(f, 'checkout', '-b', 'feature-a');
|
||||
if (change === 'secondary') fixtureWrite(f, 'src/retry-route.ts',
|
||||
fs.readFileSync(path.join(f.repo, 'src/retry-route.ts'), 'utf8') + '// Changed caller\n');
|
||||
if (change === 'filtered') fixtureWrite(f, 'src/retry-route.ts',
|
||||
fs.readFileSync(path.join(f.repo, 'src/retry-route.ts'), 'utf8') + '// RAW-ONLY changed caller\n');
|
||||
}
|
||||
const events: any[] = [];
|
||||
const invoke = (command: string) => {
|
||||
const id = `call-${events.length}`;
|
||||
events.push({ type: 'assistant', message: { content: [{ type: 'tool_use', id, name: 'Bash', input: { command } }] } });
|
||||
const output = execFileSync('bash', ['-c', command], { cwd: f.repo, env: { ...process.env, ...f.env },
|
||||
encoding: 'utf8', timeout: 30_000 });
|
||||
events.push({ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: id, content: output }] } });
|
||||
return output.trim();
|
||||
};
|
||||
const instructionFile = reviewLifecycleInstructions(f);
|
||||
const instructions = fs.readFileSync(instructionFile, 'utf8');
|
||||
const resumed = prepared?.resumed ?? seedPathReviewPrerequisites(f);
|
||||
const prerequisites = checkPathReviewPrerequisites(f, resumed.input);
|
||||
const protocol = declared ? [...reviewRevalidationPrompt(f, instructionFile, path.join(f.root, 'current-advisory.jsonl'), resumed)
|
||||
.matchAll(/```bash\n([\s\S]*?)\n```/g)].map(match => match[1]) : [];
|
||||
if (declared) expect(protocol).toHaveLength(3);
|
||||
const startCommand = instructions.match(/```bash\n(DIFF_BASE=\$[\s\S]*?)\n```/)?.[1];
|
||||
expect(startCommand).toBeDefined();
|
||||
const token = invoke(declared ? protocol[0] : startCommand!).split('\n')[0];
|
||||
if (declared) invoke('git diff origin/main');
|
||||
for (const file of current.evidence_paths) invoke(`cat ${shellQuote(file)}`);
|
||||
const checkAt = events.length;
|
||||
const receipt = JSON.parse(invoke(declared ? protocol[1].replace('REVIEW_START', token).replace('CURRENT_FINDING_JSON', JSON.stringify(current))
|
||||
: `${shellQuote(helper)} --check-shared-libs ${token} <<'FINDING'\n${JSON.stringify(current)}\nFINDING`));
|
||||
const questions: any[] = [];
|
||||
if (declared && !receipt.reusable) {
|
||||
const input = { questions: [{ question: 'Revalidate this supplied authored-source advisory?',
|
||||
options: [{ label: 'Fix', description: 'Apply the extraction.' },
|
||||
{ label: 'Skip', description: 'Keep the source and index unchanged; record this advisory decision.' }] }] };
|
||||
const callback = createSharedInteractiveToolHandler('skip', {
|
||||
nonQuestion: () => { throw new Error('No non-question tool is allowed by this free actor'); },
|
||||
onQuestion: value => { questions.push(value); }, onAnswer: () => {},
|
||||
});
|
||||
const id = `decision-${events.length}`;
|
||||
events.push({ type: 'assistant', message: { content: [{ type: 'tool_use', id, name: 'AskUserQuestion', input }] } });
|
||||
const answer = await callback('AskUserQuestion', input);
|
||||
expect(answer.updatedInput.answers).toEqual({ [input.questions[0].question]: 'Skip' });
|
||||
events.push({ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: id,
|
||||
content: JSON.stringify(answer.updatedInput.answers) }] } });
|
||||
}
|
||||
{
|
||||
const settled = JSON.parse(invoke(resumed.checkCommand));
|
||||
expect(settled).toEqual(checkPathReviewPrerequisites(f, resumed.input));
|
||||
expect(settled).toMatchObject({ synthetic: true, native_coverage: false, settled: true, current: true });
|
||||
}
|
||||
const finishAt = events.length;
|
||||
const record = JSON.stringify({ skill: 'review', status: 'clean', issues_found: 0,
|
||||
completed: true, converged: true, findings: change === 'unchanged' ? [] : [{ ...current, action: 'skipped' }] });
|
||||
invoke(declared ? protocol[2].replace("'FINAL_REVIEW_JSON'", shellQuote(record)).replace('REVIEW_START', token)
|
||||
: `${shellQuote(helper)} ${shellQuote(record)} --finish ${token} && ${shellQuote(path.join(SHARED_LIBS_ROOT, 'bin/gstack-review-read'))}`);
|
||||
const expected = { helper, repo: f.repo, state: f.state, slug: 'fixture-shared-libs',
|
||||
directory: path.join(f.state, 'projects/fixture-shared-libs/.review-starts'),
|
||||
branch: fixtureGit(f, 'symbolic-ref', '--quiet', '--short', 'HEAD'), wtree: fixtureWorkingTree(f),
|
||||
startedAt: receipt.review_start.started_at, finding: current, reusable: change === 'unchanged',
|
||||
coveredPaths: receipt.snapshot.covered_paths,
|
||||
...(prepared ? { sources: Object.fromEntries(current!.evidence_paths.map((file: string) => [file, fs.readFileSync(path.join(f.repo, file), 'utf8')])) } : {}) };
|
||||
return { f, current, token, receipt, events, checkAt, finishAt, expected, prepared, resumed, prerequisites, ...(declared ? { questions } : {}) };
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
for (const change of ['unchanged', 'secondary', 'branch', 'filtered']) captures.set(change, await capture(change));
|
||||
for (const kind of pathKinds) captures.set(`path-${kind}`, await capture(`path-${kind}`, preparePathEligibilityFixture(kind)));
|
||||
for (const change of ['unchanged', 'secondary', 'branch', 'filtered']) captures.set(`declared-${change}`, await capture(change, undefined, true));
|
||||
for (const kind of pathKinds) captures.set(`declared-path-${kind}`, await capture(`path-${kind}`, preparePathEligibilityFixture(kind), true));
|
||||
}, 120_000);
|
||||
afterAll(() => { for (const fixture of fixtures) fs.rmSync(fixture.root, { recursive: true, force: true }); });
|
||||
|
||||
function replay(change = 'unchanged') { return structuredClone(captures.get(change)); }
|
||||
function call(run: any, at = run.checkAt) { return run.events[at].message.content[0]; }
|
||||
function result(run: any, at = run.checkAt) { return run.events[at + 1].message.content[0]; }
|
||||
function alterReceipt(run: any, change: (receipt: any) => void) {
|
||||
const receipt = JSON.parse(result(run).content);
|
||||
change(receipt);
|
||||
result(run).content = JSON.stringify(receipt);
|
||||
}
|
||||
|
||||
function pathCallback(run: any, overrides: Record<string, any> = {}) {
|
||||
const start = pathSource.indexOf('async function exerciseEligibility(');
|
||||
const end = pathSource.indexOf('\ndescribeE2E(', start);
|
||||
const readStart = pathSource.indexOf('function sourceReadTrace(');
|
||||
expect(start).toBeGreaterThan(readStart);
|
||||
expect(end).toBeGreaterThan(start);
|
||||
const rows: any[] = [];
|
||||
const native = { events: run.events, exitReason: 'success', output: '', toolCalls: run.events
|
||||
.filter((event: any) => event.type === 'assistant')
|
||||
.flatMap((event: any) => event.message.content.filter((block: any) => block.type === 'tool_use')
|
||||
.map((block: any) => ({ tool: block.name, input: block.input }))) };
|
||||
const exercise = new Function('deps', new Bun.Transpiler({ loader: 'ts' }).transformSync(`const {
|
||||
captures, preparePathEligibilityFixture, fs, path, reviewLifecycleInstructions, reviewRevalidationPrompt,
|
||||
runSharedInteractive, readRequests, toolCommandTrace, fixtureGit, fixtureWorkingTree, reviewRecords, expect,
|
||||
CAPTURE_LONG_MS, hasTrustedSharedLibsCheck, SHARED_LIBS_ROOT,
|
||||
checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt } = deps;
|
||||
${pathSource.slice(readStart, end)} return exerciseEligibility;`))({
|
||||
captures: { runAttempt: async (_name: string, _kinds: string[], _timeout: number, work: any) =>
|
||||
work({ add: (scenario: string, row: any) => rows.push({ scenario, row }) }) },
|
||||
preparePathEligibilityFixture: () => run.prepared,
|
||||
fs: { ...fs, rmSync: (directory: string) => { expect(directory).toBe(run.f.root); } }, path,
|
||||
reviewLifecycleInstructions, reviewRevalidationPrompt,
|
||||
runSharedInteractive: async (fixture: any, _name: string, prompt: string, choice: string) => {
|
||||
expect(choice).toBe('skip');
|
||||
expect(fixture).toBe(run.prepared.fixture);
|
||||
expect(prompt).toContain(reviewRevalidationPrompt(fixture, path.join(fixture.root, 'review-lifecycle.md'),
|
||||
path.join(fixture.root, 'current-advisory.jsonl'), run.prepared.resumed));
|
||||
return { result: native, questions: run.questions ?? [{}] };
|
||||
},
|
||||
readRequests: () => [], toolCommandTrace, fixtureGit, fixtureWorkingTree, reviewRecords, expect,
|
||||
CAPTURE_LONG_MS, hasTrustedSharedLibsCheck, SHARED_LIBS_ROOT,
|
||||
checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt, ...overrides,
|
||||
});
|
||||
return { rows, invoke: () => exercise('shared-libs-review-path-eligibility', [run.kind]) };
|
||||
}
|
||||
|
||||
function capturedPathRun(index: number) {
|
||||
const captured = structuredClone(capturedChecker.attempts[index]);
|
||||
const events: any[] = captured.events;
|
||||
const blocks = events.flatMap(event => event.message.content);
|
||||
const calls = blocks.filter(block => block.type === 'tool_use');
|
||||
const returned = (id: string) => {
|
||||
const result = blocks.find(block => block.type === 'tool_result' && block.tool_use_id === id);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.is_error).not.toBe(true);
|
||||
expect(typeof result.content).toBe('string');
|
||||
return result.content as string;
|
||||
};
|
||||
const files = new Map<string, string>(calls.filter(call => call.name === 'Read')
|
||||
.map(call => [call.input.file_path, returned(call.id).replace(/^\d+\t/gm, '')]));
|
||||
const repo = captured.repo, root = path.posix.dirname(repo), state = path.posix.join(root, 'state');
|
||||
const input = path.posix.join(root, 'resumed-review-prerequisites.json');
|
||||
const supplied = path.posix.join(root, 'current-advisory.jsonl');
|
||||
const current = JSON.parse(files.get(supplied)!);
|
||||
const prerequisiteCall = calls.find(call => call.input.command?.includes('--check-review-prerequisites'));
|
||||
const prerequisites = JSON.parse(returned(prerequisiteCall.id));
|
||||
expect(prerequisites).toMatchObject({ settled: true, current: true, context: { binding: { root, repo, state } } });
|
||||
expect(prerequisites.context).toEqual(JSON.parse(files.get(input)!));
|
||||
const finish = calls.find(call => call.input.command?.includes('--finish'));
|
||||
const records = returned(finish.id).split('\n').filter(line => line.startsWith('{')).map(line => JSON.parse(line));
|
||||
const f = { root, repo, state } as SharedLibsFixture;
|
||||
const run = { f, kind: 'assume-unchanged', events, questions: calls.filter(call => call.name === 'AskUserQuestion').map(call => call.input),
|
||||
prepared: { fixture: f, current, sourcePaths: ['src/retry-route.ts'], beforeTree: prerequisites.context.binding.wtree,
|
||||
resumed: { input, checkCommand: prerequisiteCall.input.command } } };
|
||||
expect(captured.exit_reason).toBe('success');
|
||||
expect(run.questions).toHaveLength(1);
|
||||
for (const call of calls.filter(call => call.name === 'AskUserQuestion')) {
|
||||
for (const question of call.input.questions) {
|
||||
expect(returned(call.id)).toContain(`"${question.question}"="Skip"`);
|
||||
expect(question.options.some((option: any) => option.label === 'Skip')).toBe(true);
|
||||
}
|
||||
}
|
||||
const overrides = {
|
||||
path: path.posix, SHARED_LIBS_ROOT: '/workspace/gstack',
|
||||
fs: {
|
||||
readFileSync: (file: string) => { expect(files.has(file)).toBe(true); return files.get(file); },
|
||||
realpathSync: (file: string) => file,
|
||||
writeFileSync: (file: string, contents: string) => {
|
||||
expect(file).toBe(supplied);
|
||||
expect(JSON.parse(contents)).toEqual(current);
|
||||
},
|
||||
rmSync: (directory: string) => { expect(directory).toBe(root); },
|
||||
},
|
||||
reviewLifecycleInstructions: () => path.posix.join(root, 'review-lifecycle.md'),
|
||||
checkPathReviewPrerequisites: (fixture: SharedLibsFixture, file: string) => {
|
||||
expect(fixture).toBe(f); expect(file).toBe(input); return prerequisites;
|
||||
},
|
||||
fixtureGit: (fixture: SharedLibsFixture, ...args: string[]) => {
|
||||
expect(fixture).toBe(f); expect(args).toEqual(['symbolic-ref', '--quiet', '--short', 'HEAD']);
|
||||
return prerequisites.context.binding.branch;
|
||||
},
|
||||
fixtureWorkingTree: (fixture: SharedLibsFixture) => {
|
||||
expect(fixture).toBe(f); return prerequisites.context.binding.wtree;
|
||||
},
|
||||
reviewRecords: (fixture: SharedLibsFixture) => { expect(fixture).toBe(f); return structuredClone(records); },
|
||||
};
|
||||
return { run, overrides };
|
||||
}
|
||||
|
||||
describe('native executable shared-code checker evidence', () => {
|
||||
test.each([0, 1])('the complete R59 public attempt %i satisfies the actual callback without a manual fingerprint call', async index => {
|
||||
const { run, overrides } = capturedPathRun(index);
|
||||
const commands = run.events.flatMap(event => event.message.content)
|
||||
.filter(block => block.type === 'tool_use' && block.name === 'Bash').map(block => block.input.command).join('\n');
|
||||
expect(commands).not.toContain('sharedLibsFingerprint');
|
||||
let checks = 0;
|
||||
const adapter = pathCallback(run, { ...overrides, hasTrustedSharedLibsCheck: (events: unknown[], expected: any) => {
|
||||
checks++;
|
||||
expect(events).toBe(run.events);
|
||||
expect(expected.finding).toEqual(run.prepared.current);
|
||||
expect(expected.reusable).toBe(false);
|
||||
expect(expected.coveredPaths).toEqual(['src/retry-worker.ts', 'lib/retry-after.ts']);
|
||||
return hasTrustedSharedLibsCheck(events, expected);
|
||||
} });
|
||||
await adapter.invoke();
|
||||
expect(checks).toBe(1);
|
||||
expect(adapter.rows).toMatchObject([{ scenario: 'assume-unchanged', row: { passed: true } }]);
|
||||
const refused = pathCallback(run, { ...overrides, hasTrustedSharedLibsCheck: () => false });
|
||||
await expect(refused.invoke()).rejects.toThrow();
|
||||
expect(refused.rows[0].row.passed).toBe(false);
|
||||
});
|
||||
|
||||
test.each([0, 1].flatMap(index => ['missing', 'failed', 'unpaired', 'fingerprint', 'binding', 'extra coverage'].map(invalid => [index, invalid] as const)))(
|
||||
'the R59 public attempt %i callback rejects a %s checker receipt', async (index, invalid) => {
|
||||
const { run, overrides } = capturedPathRun(index);
|
||||
const blocks = run.events.flatMap(event => event.message.content);
|
||||
const check = blocks.find(block => block.type === 'tool_use' && block.input.command?.includes('--check-shared-libs'));
|
||||
const receipt = blocks.find(block => block.type === 'tool_result' && block.tool_use_id === check.id);
|
||||
if (invalid === 'missing') receipt.content = '';
|
||||
else if (invalid === 'failed') receipt.is_error = true;
|
||||
else if (invalid === 'unpaired') receipt.tool_use_id = 'unpaired-checker';
|
||||
else {
|
||||
const value = JSON.parse(receipt.content);
|
||||
if (invalid === 'fingerprint') value.fingerprint = `shared-libs:${'a'.repeat(64)}`;
|
||||
if (invalid === 'binding') value.review_start.started_at = 'foreign';
|
||||
if (invalid === 'extra coverage') value.snapshot.covered_paths.push('src/retry-route.ts');
|
||||
receipt.content = JSON.stringify(value);
|
||||
}
|
||||
let checks = 0;
|
||||
const adapter = pathCallback(run, { ...overrides, hasTrustedSharedLibsCheck: (events: unknown[], expected: any) => {
|
||||
checks++;
|
||||
return hasTrustedSharedLibsCheck(events, expected);
|
||||
} });
|
||||
await expect(adapter.invoke()).rejects.toThrow();
|
||||
expect(checks).toBe(1);
|
||||
expect(adapter.rows[0].row.passed).toBe(false);
|
||||
});
|
||||
|
||||
test('the actual path callback consumes the current synthetic prerequisite result without claiming native coverage', async () => {
|
||||
const run = replay('declared-path-assume-unchanged');
|
||||
run.kind = 'assume-unchanged';
|
||||
let verified = 0;
|
||||
const adapter = pathCallback(run, { hasPathReviewPrerequisiteReceipt: (events: any[], command: string, expected: any) => {
|
||||
verified++;
|
||||
expect(command).toBe(run.prepared.resumed.checkCommand);
|
||||
expect(expected).toMatchObject({ synthetic: true, native_coverage: false, settled: true, current: true });
|
||||
expect(expected.context.binding.repo).toBe(run.f.repo);
|
||||
expect(expected.context.binding.state).toBe(run.f.state);
|
||||
expect(expected.context.binding.index).toMatch(/^h /m);
|
||||
return hasPathReviewPrerequisiteReceipt(events, command, expected);
|
||||
} });
|
||||
await adapter.invoke();
|
||||
expect(verified).toBe(1);
|
||||
expect(adapter.rows[0].row.passed).toBe(true);
|
||||
expect(adapter.rows[0].row.transcript[0]).toMatchObject({
|
||||
prerequisite_source: 'synthetic-fixture-input', prerequisite_native_coverage: false,
|
||||
});
|
||||
const refused = pathCallback(run, { hasPathReviewPrerequisiteReceipt: () => false });
|
||||
await expect(refused.invoke()).rejects.toThrow('consume current synthetic prerequisites');
|
||||
expect(refused.rows[0].row.passed).toBe(false);
|
||||
});
|
||||
|
||||
test.each(['missing', 'failed', 'unpaired', 'assistant-only', 'caption', 'false', 'foreign state', 'after finish'])(
|
||||
'the registered path callback rejects %s prerequisite receipts even with a completed record', async invalid => {
|
||||
const run = replay('declared-path-ignored');
|
||||
run.kind = 'ignored';
|
||||
const at = run.events.findIndex((event: any) => event.type === 'assistant'
|
||||
&& event.message.content[0].input?.command === run.prepared.resumed.checkCommand);
|
||||
expect(at).toBeGreaterThan(run.checkAt);
|
||||
if (invalid === 'missing') run.events.splice(at, 2);
|
||||
if (invalid === 'failed') result(run, at).is_error = true;
|
||||
if (invalid === 'unpaired') result(run, at).tool_use_id = 'another-call';
|
||||
if (invalid === 'assistant-only') run.events[at + 1].type = 'assistant';
|
||||
if (invalid === 'caption') call(run, at).input = { command: 'true', description: run.prepared.resumed.checkCommand };
|
||||
if (invalid === 'false' || invalid === 'foreign state') {
|
||||
const receipt = JSON.parse(result(run, at).content);
|
||||
if (invalid === 'false') receipt.settled = false;
|
||||
else receipt.context.binding.state = '/another-fixture/state';
|
||||
result(run, at).content = JSON.stringify(receipt);
|
||||
}
|
||||
if (invalid === 'after finish') run.events.push(...run.events.splice(at, 2));
|
||||
const adapter = pathCallback(run);
|
||||
await expect(adapter.invoke()).rejects.toThrow('consume current synthetic prerequisites');
|
||||
expect(adapter.rows[0].row.passed).toBe(false);
|
||||
});
|
||||
|
||||
test.each(['missing file', 'missing QA', 'empty probes', 'failed probe', 'missing native', 'failed native',
|
||||
'blocked native', 'foreign state', 'branch', 'base', 'index flag', 'raw hidden source', 'configuration', 'structured required'])(
|
||||
'synthetic prerequisites cannot settle with %s', async invalid => {
|
||||
const prepared = preparePathEligibilityFixture('assume-unchanged'), f = prepared.fixture;
|
||||
try {
|
||||
const original = checkPathReviewPrerequisites(f, prepared.resumed.input);
|
||||
expect(original.settled).toBe(true);
|
||||
const context = structuredClone(original.context);
|
||||
if (invalid === 'missing QA') delete context.qa;
|
||||
if (invalid === 'empty probes') context.qa.required_probes = [];
|
||||
if (invalid === 'failed probe') context.qa.required_probes[0].status = 'failed';
|
||||
if (invalid === 'missing native') delete context.native_adversarial;
|
||||
if (invalid === 'failed native' || invalid === 'blocked native') context.native_adversarial.status = invalid.split(' ')[0];
|
||||
if (invalid === 'foreign state') context.binding.state = '/another-fixture/state';
|
||||
if (invalid === 'structured required') context.structured_review.required = true;
|
||||
fs.writeFileSync(prepared.resumed.input, JSON.stringify(context));
|
||||
if (invalid === 'missing file') fs.unlinkSync(prepared.resumed.input);
|
||||
if (invalid === 'branch') fixtureGit(f, 'checkout', '-b', 'another-branch');
|
||||
if (invalid === 'base') fixtureGit(f, 'update-ref', 'refs/remotes/origin/main', 'HEAD~1');
|
||||
if (invalid === 'index flag') fixtureGit(f, 'update-index', '--no-assume-unchanged', 'src/retry-route.ts');
|
||||
if (invalid === 'raw hidden source') {
|
||||
fs.appendFileSync(path.join(f.repo, 'src/retry-route.ts'), '\n// Changed after the synthetic QA result\n');
|
||||
expect(fixtureWorkingTree(f)).toBe(original.context.binding.wtree);
|
||||
}
|
||||
if (invalid === 'configuration') fixtureGit(f, 'config', 'core.ignorecase', 'true');
|
||||
const checked = checkPathReviewPrerequisites(f, prepared.resumed.input);
|
||||
expect(checked.settled).toBe(false);
|
||||
expect(JSON.parse(execFileSync('bash', ['-c', prepared.resumed.checkCommand], {
|
||||
cwd: f.repo, env: { ...process.env, ...f.env }, encoding: 'utf8', timeout: 30_000,
|
||||
}))).toEqual(checked);
|
||||
const run = { f, prepared, kind: 'assume-unchanged', events: [] };
|
||||
const adapter = pathCallback(run);
|
||||
await expect(adapter.invoke()).rejects.toThrow('fixture prerequisites must be settled before capture');
|
||||
} finally { fs.rmSync(f.root, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
test.each(['raw source', 'supplied context'])('the registered callback rejects late changes to %s', async changed => {
|
||||
const run = replay('declared-path-assume-unchanged');
|
||||
run.kind = 'assume-unchanged';
|
||||
const file = changed === 'raw source' ? path.join(run.f.repo, 'src/retry-route.ts') : run.prepared.resumed.input;
|
||||
const before = fs.readFileSync(file, 'utf8');
|
||||
const adapter = pathCallback(run, { runSharedInteractive: async () => {
|
||||
fs.writeFileSync(file, before + '\n');
|
||||
return { questions: run.questions, result: { exitReason: 'success', output: '', events: run.events,
|
||||
toolCalls: run.events.filter((event: any) => event.type === 'assistant')
|
||||
.map((event: any) => ({ tool: event.message.content[0].name, input: event.message.content[0].input })) } };
|
||||
} });
|
||||
try {
|
||||
await expect(adapter.invoke()).rejects.toThrow('prerequisite state must remain unchanged');
|
||||
expect(adapter.rows[0].row.passed).toBe(false);
|
||||
} finally { fs.writeFileSync(file, before); }
|
||||
});
|
||||
|
||||
test.each(['unchanged', 'secondary', 'branch', 'filtered'])('real %s checker receipt supplies the mechanical proof without manual trace words', change => {
|
||||
const run = replay(change);
|
||||
expect(run.receipt.reusable).toBe(change === 'unchanged');
|
||||
@@ -574,152 +227,4 @@ describe('native executable shared-code checker evidence', () => {
|
||||
await expect(adapter.invoke()).rejects.toThrow();
|
||||
expect(adapter.rows).toMatchObject([{ scenario: 'symlinks', row: { passed: false } }]);
|
||||
});
|
||||
|
||||
test.each(['unchanged', 'secondary', 'branch', 'filtered'])('declared receipt commands satisfy the real %s revalidation callback', change => {
|
||||
const run = replay(`declared-${change}`);
|
||||
expect(result(run, 0).content.trim()).toBe(run.token);
|
||||
expect(JSON.parse(result(run).content)).toEqual(run.receipt);
|
||||
expect(call(run, run.finishAt).input.command).toContain(`--finish ${run.token} && '${SHARED_LIBS_ROOT}/bin/gstack-review-read'`);
|
||||
expect(run.questions).toHaveLength(change === 'unchanged' ? 0 : 1);
|
||||
const scenario = source.slice(source.indexOf("test('shared-libs-review-revalidation'"));
|
||||
const marker = '}, result => {';
|
||||
const start = scenario.indexOf(marker) + marker.length;
|
||||
const body = scenario.slice(start, scenario.indexOf('\n });', start));
|
||||
const verify = new Function('deps', 'result', new Bun.Transpiler({ loader: 'ts' }).transformSync(`const {
|
||||
change, questions, expect, toolCommandTrace, reviewRecords, createHash, path, f, current,
|
||||
fixtureGit, fixtureWorkingTree, hasTrustedReviewStartRead, hasTrustedSharedLibsCheck, SHARED_LIBS_ROOT,
|
||||
resumed, prerequisites, checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt
|
||||
} = deps; ${body}`));
|
||||
const native = { events: run.events, toolCalls: run.events.filter((event: any) => event.type === 'assistant')
|
||||
.map((event: any) => ({ tool: event.message.content[0].name, input: event.message.content[0].input })) };
|
||||
let checks = 0;
|
||||
verify({ change, questions: run.questions, expect, toolCommandTrace, reviewRecords, createHash, path,
|
||||
f: run.f, current: run.current, fixtureGit, fixtureWorkingTree, hasTrustedReviewStartRead, SHARED_LIBS_ROOT,
|
||||
resumed: run.resumed, prerequisites: run.prerequisites, checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt,
|
||||
hasTrustedSharedLibsCheck: (events: unknown[], expected: any) => {
|
||||
checks++;
|
||||
expect(events).toBe(run.events);
|
||||
expect(expected).toEqual(run.expected);
|
||||
return hasTrustedSharedLibsCheck(events, expected);
|
||||
} }, native);
|
||||
expect(checks).toBe(1);
|
||||
});
|
||||
|
||||
test.each(pathKinds)('declared receipt commands satisfy the real %s path callback after an actual actor decision', async kind => {
|
||||
const run = replay(`declared-path-${kind}`);
|
||||
run.kind = kind;
|
||||
expect(result(run, 0).content.trim()).toBe(run.token);
|
||||
expect(JSON.parse(result(run).content)).toEqual(run.receipt);
|
||||
expect(run.receipt.reusable).toBe(false);
|
||||
expect(run.questions).toHaveLength(1);
|
||||
let checks = 0;
|
||||
const adapter = pathCallback(run, { hasTrustedSharedLibsCheck: (events: unknown[], expected: any) => {
|
||||
checks++;
|
||||
expect(expected).toEqual(run.expected);
|
||||
return hasTrustedSharedLibsCheck(events, expected);
|
||||
} });
|
||||
await adapter.invoke();
|
||||
expect(checks).toBe(1);
|
||||
expect(adapter.rows).toMatchObject([{ scenario: kind, row: { passed: true } }]);
|
||||
});
|
||||
|
||||
test.each(['revised-only identity', 'unsupported finding', 'unfinished review', 'missing explicit decision'])(
|
||||
'canonical transport cannot waive %s in the real ignored-path callback', async failure => {
|
||||
const run = replay('declared-path-ignored');
|
||||
run.kind = 'ignored';
|
||||
if (failure === 'missing explicit decision') run.questions = [];
|
||||
const adapter = pathCallback(run, { reviewRecords: (fixture: SharedLibsFixture) => {
|
||||
const records = reviewRecords(fixture);
|
||||
const final = records.at(-1);
|
||||
if (failure === 'revised-only identity') {
|
||||
const revised = { ...final.findings[0], evidence_paths: [
|
||||
'src/retry-worker.ts', 'src/scheduler.ts', 'src/retry-route.ts', 'lib/retry-after.ts',
|
||||
] };
|
||||
revised.fingerprint = sharedLibsFingerprint(revised);
|
||||
revised.snapshot_covered_paths = [...revised.evidence_paths];
|
||||
expect(revised.fingerprint).not.toBe(run.current.fingerprint);
|
||||
final.findings = [revised];
|
||||
}
|
||||
if (failure === 'unsupported finding') final.findings = [];
|
||||
if (failure === 'unfinished review') final.completed = false;
|
||||
return records;
|
||||
} });
|
||||
await expect(adapter.invoke()).rejects.toThrow();
|
||||
expect(adapter.rows).toMatchObject([{ scenario: 'ignored', row: { passed: false } }]);
|
||||
});
|
||||
|
||||
test.each(['start batching', 'mixed checker stdout', 'finish metadata prelude', 'loop-only caller reads'])(
|
||||
'the unchanged detector still rejects %s after protocol declaration', shape => {
|
||||
const run = replay('declared-unchanged');
|
||||
if (shape === 'start batching') call(run, 0).input.command = `echo start; ${call(run, 0).input.command}; git diff origin/main`;
|
||||
if (shape === 'mixed checker stdout') result(run).content = `checker receipt:\n${result(run).content}\nexit=0`;
|
||||
if (shape === 'finish metadata prelude') call(run, run.finishAt).input.command = `TS=$(date -u); ${call(run, run.finishAt).input.command}`;
|
||||
if (shape === 'loop-only caller reads') {
|
||||
for (const event of run.events) for (const block of event.message.content) {
|
||||
if (block.type === 'tool_use' && block.name === 'Bash' && block.input.command.startsWith('cat ')) {
|
||||
block.input.command = `for f in ${block.input.command.slice(4)}; do cat "$f"; done`;
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(hasTrustedSharedLibsCheck(run.events, run.expected)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// Gate 39173752116 slice 12: the skip-worktree review read every evidence file in one
|
||||
// literal for-loop that printed each path before its contents.
|
||||
describe('literal loop reads from the captured skip-worktree review', () => {
|
||||
const loop = (events: any[]) => events.flatMap(event => event.message.content)
|
||||
.find((block: any) => block.type === 'tool_use' && block.input?.command?.startsWith('for f in '));
|
||||
const output = (events: any[], id: string) => events.flatMap(event => event.message.content)
|
||||
.find((block: any) => block.type === 'tool_result' && block.tool_use_id === id);
|
||||
|
||||
test('a literal loop whose output names each evidence file counts as reading it', () => {
|
||||
expect(hasTrustedSharedLibsCheck(structuredClone(loopRead.events), loopRead.expected)).toBe(true);
|
||||
});
|
||||
|
||||
test.each(['variable list', 'file missing from output', 'path outside the repo'])('%s is still rejected', shape => {
|
||||
const events = structuredClone(loopRead.events), call = loop(events), files = 'src/retry-worker.ts src/retry-route.ts lib/retry-after.ts';
|
||||
expect(call.input.command).toContain(`for f in ${files} `);
|
||||
if (shape === 'variable list') call.input.command = `FILES="${files}"; ${call.input.command.replace(files, '$FILES')}`;
|
||||
if (shape === 'file missing from output') {
|
||||
const result = output(events, call.id);
|
||||
result.content = JSON.parse(JSON.stringify(result.content).replaceAll('src/retry-route.ts', 'src/omitted.ts'));
|
||||
}
|
||||
if (shape === 'path outside the repo') call.input.command = call.input.command.replace(' src/retry-route.ts ', ' ../outside/src/retry-route.ts ');
|
||||
expect(hasTrustedSharedLibsCheck(events, loopRead.expected)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// Gate 40617200857 slice 8: the ignored-path review returned all of src/retry-worker.ts through
|
||||
// cat -n, then a later `echo ===` in the same call failed, so the result carried is_error.
|
||||
describe('errored Bash reads from the captured ignored-path review', () => {
|
||||
const blocks = (events: any[]) => events.flatMap(event => event.message.content);
|
||||
const read = (events: any[]) => blocks(events).find((block: any) => block.type === 'tool_use'
|
||||
&& block.input?.command?.startsWith('cat -n src/retry-worker.ts; echo ===;'));
|
||||
const output = (events: any[], id: string) => blocks(events).find((block: any) => block.type === 'tool_result' && block.tool_use_id === id);
|
||||
|
||||
test('a whole evidence source returned before a later failure counts as reading it', () => {
|
||||
const events = structuredClone(erroredRead.events);
|
||||
expect(output(events, read(events).id).is_error).toBe(true);
|
||||
expect(hasTrustedSharedLibsCheck(events, erroredRead.expected)).toBe(true);
|
||||
});
|
||||
|
||||
test.each(['no expected sources', 'empty expected source', 'last source line missing', 'missing file', 'errored single read', 'errored native Read', 'errored checker'])('%s is still rejected', shape => {
|
||||
const events = structuredClone(erroredRead.events), call = read(events), result = output(events, call.id);
|
||||
const expected: any = structuredClone(erroredRead.expected);
|
||||
if (shape === 'no expected sources') delete expected.sources;
|
||||
if (shape === 'empty expected source') expected.sources['src/retry-worker.ts'] = '';
|
||||
if (shape === 'last source line missing') result.content = result.content.replace(/\n +15\t\}\n/, '\n');
|
||||
if (shape === 'missing file') result.content = 'Exit code 1\ncat: src/retry-worker.ts: No such file or directory';
|
||||
if (shape === 'errored single read') call.input.command = 'cat -n src/retry-worker.ts';
|
||||
if (shape === 'errored native Read') {
|
||||
call.name = 'Read';
|
||||
call.input = { file_path: 'src/retry-worker.ts' };
|
||||
}
|
||||
if (shape === 'errored checker') {
|
||||
const checker = blocks(events).find((block: any) => block.type === 'tool_use' && block.input?.command?.includes('--check-shared-libs'));
|
||||
output(events, checker.id).is_error = true;
|
||||
}
|
||||
expect(hasTrustedSharedLibsCheck(events, expected)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,201 @@
|
||||
// Split from test/ship-queue-train.test.ts (GSTA-151): dispatch recovery, train status, and the verdict, bisect and rebuild cases.
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { cleanup } from './helpers/restamp-fixture';
|
||||
import { coordinatorClone } from './helpers/ship-queue-fixture';
|
||||
import { twoPrTrain } from './helpers/ship-queue-train-cases';
|
||||
import {
|
||||
COMPLETE, FAIL, GREEN_GATE, PASS, RED_GATE, TRAIN_POLICY, dispatches, line, queue, trainFixture, trainJson,
|
||||
type Rule, type TrainFixture,
|
||||
} from './helpers/ship-queue-train-fixture';
|
||||
|
||||
const fixtures: TrainFixture[] = [];
|
||||
const make = (policy: Record<string, unknown> = TRAIN_POLICY) => { const f = trainFixture(policy); fixtures.push(f); return f; };
|
||||
afterEach(() => { while (fixtures.length) cleanup(fixtures.pop()!.repo); });
|
||||
|
||||
const next = (out: string) => line(out, 'NEXT:');
|
||||
const remoteRefs = (fx: TrainFixture) => fx.repo.git('ls-remote', 'origin');
|
||||
|
||||
describe('dispatch recovery and status', () => {
|
||||
test('a partial dispatch (gh failed after GitHub accepted it) is unknown, never re-dispatched, and train status finds the run by nonce', () => {
|
||||
const fx = make();
|
||||
const { r, nonce } = twoPrTrain(fx, { ...GREEN_GATE, failButCreate: true });
|
||||
expect(r.status).toBe(EXIT.refused);
|
||||
expect(r.err).toContain('(QUEUE_TRAIN_DISPATCH_UNKNOWN)');
|
||||
expect(next(r.out)).toBe(`NEXT: gstack-ship-queue train status --train ${nonce}`);
|
||||
expect(trainJson(fx, nonce).state).toBe('dispatch-unknown');
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).err).toContain('(QUEUE_TRAIN_DISPATCH_UNKNOWN)');
|
||||
expect(queue(fx, ['train', 'build', '--train', nonce]).err).toContain('(QUEUE_TRAIN_DISPATCH_UNKNOWN)');
|
||||
const status = queue(fx, ['train', 'status', '--train', nonce]);
|
||||
expect(status.status).toBe(EXIT.ok);
|
||||
expect(status.out).toMatch(new RegExp(`^ATTEMPT: a1 gate state=dispatched nonce=${nonce.replace(/\./g, '\\.')} run=101 `, 'm'));
|
||||
expect(trainJson(fx, nonce).state).toBe('gate-pending');
|
||||
expect(next(status.out)).toBe(`NEXT: gstack-ship-queue train verdict --train ${nonce}`);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
expect(dispatches(fx, 'evals.yml').length).toBe(1);
|
||||
}, 180_000);
|
||||
|
||||
test('a dispatch that never started is marked absent by status; only then does build dispatch it again, under the same nonce', () => {
|
||||
const fx = make();
|
||||
const { r, nonce } = twoPrTrain(fx, { silent: true });
|
||||
expect(r.err).toContain('(QUEUE_TRAIN_DISPATCH_UNKNOWN)');
|
||||
const status = queue(fx, ['train', 'status', '--train', nonce]);
|
||||
expect(status.out).toContain('ATTEMPT: a1 gate state=absent');
|
||||
expect(next(status.out)).toBe(`NEXT: gstack-ship-queue train build --train ${nonce}`);
|
||||
fx.write(d => { d.rules['evals.yml'] = GREEN_GATE; });
|
||||
const again = queue(fx, ['train', 'build', '--train', nonce]);
|
||||
expect(again.status).toBe(EXIT.ok);
|
||||
expect(dispatches(fx, 'evals.yml').map(d => (d.inputs as any).nonce)).toEqual([nonce, nonce]);
|
||||
expect(trainJson(fx, nonce).attempts).toEqual(['a1', 'a2']);
|
||||
}, 180_000);
|
||||
|
||||
test('train status on a clean state root rebuilds the records from refs/notes/gstack-trains and spends nothing', () => {
|
||||
const fx = make();
|
||||
const { nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const before = dispatches(fx).length;
|
||||
const clone = coordinatorClone(fx.repo);
|
||||
const fresh = path.join(fx.repo.root, 'fresh-state');
|
||||
const s = queue(fx, ['train', 'status', '--train', nonce], { GSTACK_STATE_ROOT: fresh }, clone);
|
||||
expect(s.status).toBe(EXIT.ok);
|
||||
expect(s.out).toMatch(/^NOTES: read 2 record\(s\), restored 2 /m);
|
||||
expect(s.out).toContain(`TRAIN: ${nonce} state=green`);
|
||||
expect(s.out).toContain('CHECK: gstack/full-gate on');
|
||||
expect(trainJson(fx, nonce, fresh)).toEqual(trainJson(fx, nonce));
|
||||
expect(dispatches(fx).length).toBe(before);
|
||||
const all = queue(fx, ['train', 'status'], { GSTACK_STATE_ROOT: fresh }, clone);
|
||||
expect(all.out).toContain(`NEXT(${nonce}): gstack-ship-queue verify --pr 1 --train ${nonce}`);
|
||||
}, 180_000);
|
||||
});
|
||||
|
||||
describe('verdict, bisect, rebuild', () => {
|
||||
function redTrain(fx: TrainFixture, pattern: string) {
|
||||
const t = twoPrTrain(fx, RED_GATE);
|
||||
const v = queue(fx, ['train', 'verdict', '--train', t.nonce]);
|
||||
const prefixes = trainJson(fx, t.nonce).prefixes.map((p: any) => p.commit);
|
||||
fx.write(d => { d.rules['evals.yml'] = { bisect: { prefixes, patterns: { c1: pattern } } }; });
|
||||
return { ...t, v, prefixes };
|
||||
}
|
||||
|
||||
test('a red train names its cases and a capped bisect; the bisect runs only the red cases on every prefix and attributes a monotone pattern; prune deletes the dropped train\'s branch', () => {
|
||||
const fx = make();
|
||||
const { h1, nonce, v, prefixes } = redTrain(fx, 'GGR');
|
||||
expect(v.status).toBe(EXIT.fail);
|
||||
expect(v.err).toContain(`train ${nonce} is red on c1`);
|
||||
expect(v.out).toContain('ATTEMPT: a1 gate run 101 RED red=c1 cost=$1.70');
|
||||
expect(next(v.out)).toBe(`NEXT: gstack-ship-queue train bisect --train ${nonce} --spend-cap 2.70`);
|
||||
const dry = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '2.70', '--dry-run']);
|
||||
expect(dry.out).toContain('BISECT: cases c1 prefixes T0,T1,T2 need results; $0.90 reserved per prefix; spent $0.00, cap $2.70');
|
||||
expect(dry.out).toContain('DRY-RUN: nothing dispatched');
|
||||
expect(dispatches(fx, 'evals.yml').length).toBe(1);
|
||||
const go = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '2.70']);
|
||||
expect(go.status).toBe(EXIT.ok);
|
||||
const sent = dispatches(fx, 'evals.yml').at(-1)!.inputs as any;
|
||||
expect(sent.cases).toBe('c1');
|
||||
expect(sent.prefix_shas).toBe(prefixes.join(','));
|
||||
expect(sent.expected_sha).toBe(prefixes[2]);
|
||||
expect(sent.nonce).toMatch(/^gate\.bisect-/);
|
||||
const done = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '2.70']);
|
||||
expect(done.status).toBe(EXIT.ok);
|
||||
expect(done.out).toContain('PATTERN: c1 T0=G T1=G T2=R');
|
||||
expect(done.out).toContain('BISECT: ATTRIBUTED #2');
|
||||
expect(next(done.out)).toBe(`NEXT: gstack-ship-queue train build --prs 1@${h1}`);
|
||||
expect(trainJson(fx, nonce).state).toBe('attributed');
|
||||
expect(queue(fx, ['train', 'prune', '--dry-run']).out).toContain(`WOULD-DELETE: train/${nonce} (attributed)`);
|
||||
expect(queue(fx, ['train', 'prune']).out).toContain(`DELETED: train/${nonce} (attributed)`);
|
||||
expect(remoteRefs(fx)).not.toContain(`refs/heads/train/${nonce}`);
|
||||
expect(queue(fx, ['train', 'prune']).out).toContain(`GONE: train/${nonce}`);
|
||||
}, 180_000);
|
||||
|
||||
test('red on every prefix, T0 included, is RED_ON_MAIN; a non-monotone pattern is unattributed and earns no rebuild', () => {
|
||||
const main = make();
|
||||
const m = redTrain(main, 'RRR');
|
||||
queue(main, ['train', 'bisect', '--train', m.nonce, '--spend-cap', '5']);
|
||||
const onMain = queue(main, ['train', 'bisect', '--train', m.nonce, '--spend-cap', '5']);
|
||||
expect(onMain.status).toBe(EXIT.fail);
|
||||
expect(onMain.err).toContain('(QUEUE_TRAIN_RED_ON_MAIN)');
|
||||
expect(next(onMain.out)).toMatch(/^NEXT: fix forward on main first, then gstack-ship-queue train build --prs /);
|
||||
const fx = make();
|
||||
const n = redTrain(fx, 'GRG');
|
||||
queue(fx, ['train', 'bisect', '--train', n.nonce, '--spend-cap', '5']);
|
||||
const mixed = queue(fx, ['train', 'bisect', '--train', n.nonce, '--spend-cap', '5']);
|
||||
expect(mixed.status).toBe(EXIT.fail);
|
||||
expect(mixed.err).toContain('(QUEUE_TRAIN_UNATTRIBUTED)');
|
||||
expect(mixed.out).toContain('BISECT: UNATTRIBUTED (not monotone)');
|
||||
expect(next(mixed.out)).toMatch(/^NEXT: route the red cases to a repair lane \(GStack Minder\); once the repair merges: /);
|
||||
const refused = queue(fx, ['train', 'rebuild', '--train', n.nonce]);
|
||||
expect(refused.status).toBe(EXIT.refused);
|
||||
expect(refused.err).toMatch(/rebuild refused: the bisect was not all green \(c1=GRG\).*\(QUEUE_TRAIN_REBUILD_REFUSED\)/);
|
||||
}, 240_000);
|
||||
|
||||
test('rebuild-once: refused without a bisect; an all-green bisect earns exactly one unchanged rebuild, both runs reported; a second red stays red', () => {
|
||||
const fx = make();
|
||||
const { nonce } = redTrain(fx, 'GGG');
|
||||
expect(queue(fx, ['train', 'rebuild', '--train', nonce]).err).toMatch(/rebuild refused: no bisect record.*\(QUEUE_TRAIN_REBUILD_REFUSED\)/);
|
||||
queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']);
|
||||
const green = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']);
|
||||
expect(green.out).toContain('BISECT: UNATTRIBUTED (all green)');
|
||||
expect(next(green.out)).toBe(`NEXT: gstack-ship-queue train rebuild --train ${nonce}`);
|
||||
fx.write(d => { d.rules['evals.yml'] = RED_GATE; });
|
||||
const rebuild = queue(fx, ['train', 'rebuild', '--train', nonce]);
|
||||
expect(rebuild.status).toBe(EXIT.ok);
|
||||
expect(dispatches(fx, 'evals.yml').at(-1)!.inputs).toMatchObject({ evals_all: 'true', nonce: `${nonce}.2` });
|
||||
const second = queue(fx, ['train', 'verdict', '--train', nonce]);
|
||||
expect(second.status).toBe(EXIT.fail);
|
||||
expect(second.out).toContain('ATTEMPT: a1 gate run 101 RED red=c1');
|
||||
expect(second.out).toMatch(/^ATTEMPT: a2 rebuild run \d+ RED red=c1/m);
|
||||
expect(next(second.out)).toMatch(/^NEXT: second red stays red: route c1 to a repair lane/);
|
||||
expect(queue(fx, ['train', 'rebuild', '--train', nonce]).err).toMatch(/rebuild refused: already rebuilt once/);
|
||||
expect(queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']).err).toContain('second red is not bisected again');
|
||||
}, 240_000);
|
||||
|
||||
test('a capped bisect launches only what fits, keeps completed prefixes, and resumes without repeating one', () => {
|
||||
const fx = make();
|
||||
const { nonce, prefixes } = redTrain(fx, 'GGR');
|
||||
const none = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '0.5']);
|
||||
expect(none.status).toBe(EXIT.refused);
|
||||
expect(none.err).toContain('(QUEUE_TRAIN_BISECT_CAPPED)');
|
||||
expect(next(none.out)).toBe(`NEXT: gstack-ship-queue train bisect --train ${nonce} --spend-cap 2.70`);
|
||||
expect(dispatches(fx, 'evals.yml').length).toBe(1);
|
||||
const part = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '1.9']);
|
||||
expect(part.status).toBe(EXIT.refused);
|
||||
expect(part.err).toContain('(QUEUE_TRAIN_BISECT_CAPPED)');
|
||||
expect(part.out).toContain('BISECT: launch T0,T1; 1 prefix(es) wait for a higher cap');
|
||||
expect((dispatches(fx, 'evals.yml').at(-1)!.inputs as any).prefix_shas).toBe(prefixes.slice(0, 2).join(','));
|
||||
const resume = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']);
|
||||
expect(resume.status).toBe(EXIT.ok);
|
||||
expect((dispatches(fx, 'evals.yml').at(-1)!.inputs as any).prefix_shas).toBe(prefixes[2]);
|
||||
const done = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']);
|
||||
expect(done.out).toContain('BISECT: ATTRIBUTED #2');
|
||||
expect(done.out).toContain('BISECT: spent $1.50 of cap $5.00');
|
||||
expect(dispatches(fx, 'evals.yml').length).toBe(3);
|
||||
}, 240_000);
|
||||
|
||||
test('a bisect refuses prefixes that are not ancestors of train/<nonce>', () => {
|
||||
const fx = make();
|
||||
const { nonce } = redTrain(fx, 'GGR');
|
||||
fx.repo.git('push', '-q', '-f', 'origin', `origin/main:refs/heads/train/${nonce}`);
|
||||
const r = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']);
|
||||
expect(r.status).toBe(EXIT.refused);
|
||||
expect(r.err).toMatch(/train\/\S+ is at [0-9a-f]{12}, not the recorded train head .*\(QUEUE_TRAIN_PREFIX_INVALID\)/);
|
||||
expect(dispatches(fx, 'evals.yml').length).toBe(1);
|
||||
}, 180_000);
|
||||
|
||||
test('an INFRA/INCOMPLETE-only census is never green and earns one re-dispatch, reported beside the first run', () => {
|
||||
const fx = make();
|
||||
const infra: Rule = { conclusion: 'failure', record: { panels: [PASS('c1'), FAIL('c2', 'INFRA'), PASS('j1', 'judge')], census: { ...COMPLETE, killed_before_upload: 1 }, verdict: 'RED' } };
|
||||
const { nonce } = twoPrTrain(fx, infra);
|
||||
const v = queue(fx, ['train', 'verdict', '--train', nonce]);
|
||||
expect(v.status).toBe(EXIT.fail);
|
||||
expect(v.err).toMatch(/gate is incomplete: 1 slice killed before upload; c2 FAIL \(INFRA\).*\(QUEUE_TRAIN_INCOMPLETE\)/);
|
||||
expect(next(v.out)).toBe(`NEXT: gstack-ship-queue train rebuild --train ${nonce} --infra (the single re-dispatch EVAL_POLICY.infraRedispatch allows; report both runs)`);
|
||||
expect(queue(fx, ['train', 'rebuild', '--train', nonce]).err).toContain('rebuild refused: no bisect record');
|
||||
const again = queue(fx, ['train', 'rebuild', '--train', nonce, '--infra']);
|
||||
expect(again.status).toBe(EXIT.ok);
|
||||
const second = queue(fx, ['train', 'verdict', '--train', nonce]);
|
||||
expect(second.out).toMatch(/^ATTEMPT: a2 infra-redispatch run \d+ INCOMPLETE/m);
|
||||
expect(next(second.out)).toMatch(/^NEXT: diagnose run /);
|
||||
expect(queue(fx, ['train', 'rebuild', '--train', nonce, '--infra']).err).toMatch(/already re-dispatched once.*\(QUEUE_TRAIN_REBUILD_REFUSED\)/);
|
||||
}, 180_000);
|
||||
});
|
||||
@@ -0,0 +1,195 @@
|
||||
// Split from test/ship-queue-train.test.ts (GSTA-151): verify freezes, GitHub merge-state reads and stale-train refusals.
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { cleanup } from './helpers/restamp-fixture';
|
||||
import { coordinatorClone } from './helpers/ship-queue-fixture';
|
||||
import { publishMain, twoPrTrain } from './helpers/ship-queue-train-cases';
|
||||
import {
|
||||
TRAIN_POLICY, dispatches, line, nonceOf, openPr, queue, readyReceipt, repoKey, trainFixture, trainJson,
|
||||
type TrainFixture,
|
||||
} from './helpers/ship-queue-train-fixture';
|
||||
|
||||
const fixtures: TrainFixture[] = [];
|
||||
const make = (policy: Record<string, unknown> = TRAIN_POLICY) => { const f = trainFixture(policy); fixtures.push(f); return f; };
|
||||
afterEach(() => { while (fixtures.length) cleanup(fixtures.pop()!.repo); });
|
||||
|
||||
const next = (out: string) => line(out, 'NEXT:');
|
||||
|
||||
describe('verify, freeze, repair and clear', () => {
|
||||
// fails_when=a freeze lists a PR GitHub reports MERGED as unmerged (train 24's freeze named #3453), or a post-merge CHANGELOG with a line the pin never wrote confirms; why_new=the freeze test above merges nothing of the slot it freezes on; seam=the fixture's gh pr view state; no_claim=the backstop's outcome
|
||||
test('a post-merge CHANGELOG beyond the rule still freezes, and the freeze lists the slot GitHub reports MERGED as merged, not unmerged', () => {
|
||||
const fx = make();
|
||||
const { h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const released = (prefix: string, version: string) => fx.repo.git('show', `${prefix}:CHANGELOG.md`).replace('## [Unreleased]', `## [${version}] - 2026-10-18`) + '\n';
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: released(t.prefixes[1].commit, '1.2.4.0') });
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
expect(line(v('2').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h2}`);
|
||||
// Main's CHANGELOG plus #2's stamped entry, with one line the pin never wrote.
|
||||
const smuggled = fx.repo.git('show', `${main1}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.5.0] - 2026-10-18\n\n- #2 change\n- added after the gate\n') + '\n';
|
||||
const broken = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'CHANGELOG.md', text: smuggled });
|
||||
fx.write(d => { (d.prs['2'] as any).state = 'MERGED'; });
|
||||
const frozen = v('2');
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(frozen.err).toContain(`main ${broken.slice(0, 12)} is neither T1 nor T2 modulo stamps (vs T2: differs: CHANGELOG.md, which is not main ${main1.slice(0, 12)}'s plus #2's own entry: the PR's entry holds a line its pin never added: "- added after the gate")`);
|
||||
expect(line(frozen.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1,#2; main /);
|
||||
expect(line(frozen.out, 'freeze:')).toMatch(/; #2 merged on GitHub without a verified tree; unmerged \(none\); repair none admitted$/);
|
||||
const freezeFile = path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`);
|
||||
expect(JSON.parse(fs.readFileSync(freezeFile, 'utf8'))).toMatchObject({ merged: ['1', '2'], unmerged: [] });
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=a first slot GitHub reports MERGED whose squash fails the post-merge check freezes the queue, and a GitHub state that cannot be read refuses instead of reading as not merged; fails_when=stopped() reads an empty merged list, or an unreadable gh answer, as "nothing merged" while main already holds the unverified squash (review of GSTA-129, passes 1 and 2); why_new=the test above freezes on slot 2 with slot 1 verified; seam=the fixture's gh pr view state; no_claim=the backstop's outcome
|
||||
test("slot 1 merged on GitHub but not confirmed: an unreadable GitHub state refuses, and a MERGED one freezes with #1 merged and #2 unmerged instead of saying nothing merged", () => {
|
||||
const fx = make();
|
||||
const { h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const smuggled = fx.repo.git('show', `${t.prefixes[0].commit}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.4.0] - 2026-10-18\n\n- #1 change\n- added after the gate\n') + '\n';
|
||||
const broken = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: smuggled });
|
||||
// While GitHub's answer for #1 cannot be read, the verify neither freezes nor says "nothing merged": it refuses and asks to be rerun.
|
||||
const row = fx.read().prs['1'] as any;
|
||||
fx.write(d => { delete d.prs['1']; });
|
||||
const unreadable = v('1');
|
||||
expect(unreadable.status).toBe(EXIT.refused);
|
||||
expect(unreadable.err).toContain(`main ${broken.slice(0, 12)} is neither T0 nor T1 modulo stamps`);
|
||||
expect(unreadable.err).toMatch(/; whether #1 merged on GitHub could not be read, so whether the queue must freeze is unknown; .*\(QUEUE_PROOF_MISSING\)/);
|
||||
expect(unreadable.out).toContain(`NEXT: gstack-ship-queue verify --pr 1 --train ${nonce} (once gh pr view answers)`);
|
||||
expect(fs.existsSync(path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`))).toBe(false);
|
||||
fx.write(d => { d.prs['1'] = { ...row, state: 'MERGED' }; });
|
||||
const frozen = v('1');
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(frozen.err).toContain(`main ${broken.slice(0, 12)} is neither T0 nor T1 modulo stamps`);
|
||||
expect(frozen.err).toContain('"- added after the gate"); the queue is frozen;');
|
||||
expect(line(frozen.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1; main /);
|
||||
expect(line(frozen.out, 'freeze:')).toMatch(/; #1 merged on GitHub without a verified tree; unmerged #2; repair none admitted$/);
|
||||
expect(JSON.parse(fs.readFileSync(path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`), 'utf8'))).toMatchObject({ merged: ['1'], unmerged: [{ pr: '2', head: h2 }] });
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=the freeze record is built from the same GitHub read that decided to freeze, so a slot that read MERGED stays merged even when GitHub stops answering a moment later; fails_when=freezeQueue reads GitHub again and files anything but an exact MERGED under unmerged (the misfile that listed train 24's merged #3453 as unmerged, GSTA-129 defect 1); why_new=the test above holds GitHub's answer fixed across the verify; seam=the fixture's gh pr view vanishing after one answer; no_claim=the backstop's outcome
|
||||
test("a slot that read MERGED when the verify decided to freeze is recorded as merged even when GitHub stops answering before the record is written", () => {
|
||||
const fx = make();
|
||||
const { h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const smuggled = fx.repo.git('show', `${t.prefixes[0].commit}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.4.0] - 2026-10-18\n\n- #1 change\n- added after the gate\n') + '\n';
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: smuggled });
|
||||
fx.write(d => { (d.prs['1'] as any).state = 'MERGED'; d.vanish = { '1': 1 }; });
|
||||
const frozen = queue(fx, ['verify', '--pr', '1', '--train', nonce], {}, coord);
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(frozen.err).toContain('"- added after the gate"); the queue is frozen;');
|
||||
expect(fx.read().vanish).toEqual({ '1': 0 });
|
||||
expect(line(frozen.out, 'freeze:')).toMatch(/; #1 merged on GitHub without a verified tree; unmerged #2; repair none admitted$/);
|
||||
expect(JSON.parse(fs.readFileSync(path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`), 'utf8'))).toMatchObject({ merged: ['1'], unmerged: [{ pr: '2', head: h2 }] });
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=a slot unreadable on GitHub beside a merged one is left out of unmerged and named in the reason, so the rebuild after the repair never seats a PR that may already be in; fails_when=freezeQueue files an unreadable slot under unmerged, or drops it without naming it; why_new=the test above keeps slot 2 readable; seam=the fixture's gh pr view vanishing for slot 2; no_claim=the backstop's outcome
|
||||
test("a slot unreadable on GitHub beside a merged one is left out of unmerged, recorded as unreadable and named by the NEXT after the repair", () => {
|
||||
const fx = make();
|
||||
const { h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const smuggled = fx.repo.git('show', `${t.prefixes[0].commit}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.4.0] - 2026-10-18\n\n- #1 change\n- added after the gate\n') + '\n';
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: smuggled });
|
||||
fx.write(d => { (d.prs['1'] as any).state = 'MERGED'; d.vanish = { '2': 0 }; });
|
||||
const frozen = queue(fx, ['verify', '--pr', '1', '--train', nonce], {}, coord);
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(line(frozen.out, 'freeze:')).toMatch(/; #1 merged on GitHub without a verified tree; #2 unreadable on GitHub, left out of unmerged; seat it in a train by hand once gh pr view answers; unmerged \(none\); repair none admitted$/);
|
||||
expect(JSON.parse(fs.readFileSync(path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`), 'utf8'))).toMatchObject({ merged: ['1'], unmerged: [], unreadable: [{ pr: '2', head: h2 }] });
|
||||
expect(line(frozen.out, 'unreadable:')).toBe(`unreadable: #2@${h2.slice(0, 12)} (GitHub did not answer at the freeze; neither merged nor unmerged)`);
|
||||
// The repair clears the freeze, and the NEXT names the unreadable slot instead of omitting it (#3519 b).
|
||||
const h3 = openPr(fx, '3');
|
||||
readyReceipt(fx, '3', h3);
|
||||
const rn = nonceOf(queue(fx, ['train', 'build', '--repair', '--prs', `3@${h3}`]).out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', rn]).status).toBe(EXIT.ok);
|
||||
publishMain(fx, trainJson(fx, rn).prefixes[1].commit, '1.2.6.0');
|
||||
const cleared = queue(fx, ['verify', '--pr', '3', '--train', rn], {}, coord);
|
||||
expect(cleared.out).toMatch(/^FREEZE: cleared /m);
|
||||
expect(next(cleared.out)).toBe(`NEXT: gh pr view 2 --json state,headRefOid (unreadable at the freeze: #2@${h2.slice(0, 12)}); seat each that is OPEN in a train`);
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=verify on a train whose every slot already merged, against a main another train verified, refuses as stale instead of freezing the queue and dispatching a backstop (#3519 c: train 24's record froze the queue at 9ccb5233, T1 of verified train 28, run 40586582766); fails_when=stopped() freezes when every slot merged and main's sha is another train's verified prefix, or refuses without that proof; why_new=every freeze test above has an unmerged or unverified main; seam=a second train record written into the state root; no_claim=what prune --stale then does (covered by the prune tests)
|
||||
test("verify on a train whose every slot merged, against a main another train verified, refuses as stale and freezes nothing", () => {
|
||||
const fx = make();
|
||||
const { nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
const later = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'stray.txt', text: 'a later train\n' });
|
||||
fx.write(d => { (d.prs['2'] as any).state = 'MERGED'; });
|
||||
const freezeFile = path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`);
|
||||
const tree = fx.repo.git('rev-parse', `${later}^{tree}`);
|
||||
const otherNonce = `${nonce}-later`;
|
||||
const other = { ...t, nonce: otherNonce, state: 'merging', prefixes: [t.prefixes[0], { index: 1, commit: later, tree, pr: '9' }], merged: [{ pr: '9', sha: later, tree, at: '2026-10-18T13:00:00.000Z' }] };
|
||||
fs.mkdirSync(path.join(fx.state, 'ship-queue', 'trains', otherNonce), { recursive: true });
|
||||
fs.writeFileSync(path.join(fx.state, 'ship-queue', 'trains', otherNonce, 'train.json'), JSON.stringify(other));
|
||||
const stale = v('2');
|
||||
expect(stale.status).toBe(EXIT.refused);
|
||||
expect(stale.err).toContain(`every slot of train ${nonce} merged on GitHub and main ${later.slice(0, 12)} is T1 of train ${otherNonce} (#9, verified at 2026-10-18T13:00:00.000Z), so this record is stale and the queue is not frozen`);
|
||||
expect(stale.err).toContain('(QUEUE_TRAIN_STALE)');
|
||||
expect(next(stale.out)).toBe(`NEXT: gstack-ship-queue train prune --stale --train ${nonce}`);
|
||||
expect(fs.existsSync(freezeFile)).toBe(false);
|
||||
expect(dispatches(fx, 'evals.yml').filter(d => d.ref === 'main').length).toBe(0);
|
||||
// Without another train's verified record for this main, the same mismatch still freezes.
|
||||
fs.rmSync(path.join(fx.state, 'ship-queue', 'trains', otherNonce), { recursive: true });
|
||||
const frozen = v('2');
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(line(frozen.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1,#2; main /);
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=a train with a slot still OPEN on GitHub freezes on a mismatch even when main's sha is another train's verified prefix; fails_when=the every-slot-merged guard before verifiedElsewhere is dropped or weakened, so a live train refuses as stale and skips the freeze; why_new=the test above only covers an all-merged train; seam=none; no_claim=prune behavior
|
||||
test("a train with a slot still open freezes on the mismatch even when another train verified main's sha", () => {
|
||||
const fx = make();
|
||||
const { nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
const later = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'stray.txt', text: 'a later train\n' });
|
||||
const tree = fx.repo.git('rev-parse', `${later}^{tree}`);
|
||||
const otherNonce = `${nonce}-later`;
|
||||
const other = { ...t, nonce: otherNonce, state: 'merging', prefixes: [t.prefixes[0], { index: 1, commit: later, tree, pr: '9' }], merged: [{ pr: '9', sha: later, tree, at: '2026-10-18T13:00:00.000Z' }] };
|
||||
fs.mkdirSync(path.join(fx.state, 'ship-queue', 'trains', otherNonce), { recursive: true });
|
||||
fs.writeFileSync(path.join(fx.state, 'ship-queue', 'trains', otherNonce, 'train.json'), JSON.stringify(other));
|
||||
const partial = v('2');
|
||||
expect(partial.status).toBe(EXIT.fail);
|
||||
expect(partial.err).not.toContain('(QUEUE_TRAIN_STALE)');
|
||||
expect(line(partial.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1; main /);
|
||||
expect(fs.existsSync(path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`))).toBe(true);
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=a post-merge CHANGELOG difference is excused only when main's parent is T<i-1> modulo stamps, so a foreign commit between the verified head and the squash freezes; fails_when=published() skips or inverts the parent check; why_new=the two tests above reach the CHANGELOG rule only with a parent that is T1 modulo stamps; seam=none; no_claim=a parent differing from T1 in the CHANGELOG alone
|
||||
test("a post-merge CHANGELOG difference is not excused when main's parent is not the verified prefix modulo stamps: the queue freezes naming the parent", () => {
|
||||
const fx = make();
|
||||
const { nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const released = fx.repo.git('show', `${t.prefixes[1].commit}:CHANGELOG.md`).replace('## [Unreleased]', '## [1.2.4.0] - 2026-10-18') + '\n';
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: released });
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
const foreign = publishMain(fx, t.prefixes[1].commit, '1.2.4.1', { file: 'stray.txt', text: 'landed between the two slots\n' });
|
||||
const text = fx.repo.git('show', `${main1}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.5.0] - 2026-10-18\n\n- #2 change\n- added after the gate\n') + '\n';
|
||||
const main2 = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'CHANGELOG.md', text });
|
||||
expect(fx.repo.git('rev-parse', `${main2}^`)).toBe(foreign);
|
||||
const frozen = v('2');
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(frozen.err).toContain(`main ${main2.slice(0, 12)} is neither T1 nor T2 modulo stamps`);
|
||||
expect(frozen.err).toContain(`main's parent ${foreign.slice(0, 12)} is not T1 modulo stamps`);
|
||||
expect(line(frozen.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1; main /);
|
||||
}, 300_000);
|
||||
});
|
||||
@@ -0,0 +1,258 @@
|
||||
// Split from test/ship-queue-train.test.ts (GSTA-151): verify --train acceptance, prefix equality and the CHANGELOG rule before and after merge.
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { mergeChangelogs, parseChangelog } from '../lib/changelog-check';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { cleanup } from './helpers/restamp-fixture';
|
||||
import { coordinatorClone } from './helpers/ship-queue-fixture';
|
||||
import { publishMain, twoPrTrain } from './helpers/ship-queue-train-cases';
|
||||
import {
|
||||
GREEN_GATE, TRAIN_POLICY, dispatches, line, nonceOf, openPr, queue, readyReceipt, repoKey, setPrBody, shippedBody, trainFixture, trainJson,
|
||||
type TrainFixture,
|
||||
} from './helpers/ship-queue-train-fixture';
|
||||
|
||||
const fixtures: TrainFixture[] = [];
|
||||
const make = (policy: Record<string, unknown> = TRAIN_POLICY) => { const f = trainFixture(policy); fixtures.push(f); return f; };
|
||||
afterEach(() => { while (fixtures.length) cleanup(fixtures.pop()!.repo); });
|
||||
|
||||
const next = (out: string) => line(out, 'NEXT:');
|
||||
|
||||
describe('verify, freeze, repair and clear', () => {
|
||||
test('verify accepts each merge only at prefix equality modulo stamps; an interrupted publication freezes the queue until one repair train lands', () => {
|
||||
const fx = make();
|
||||
const { h1, h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string, train = nonce) => queue(fx, ['verify', '--pr', pr, '--train', train], {}, coord);
|
||||
|
||||
const pre1 = v('1');
|
||||
expect(pre1.status).toBe(EXIT.ok);
|
||||
expect(pre1.out).toContain(`VERIFY_TRAIN: #1 may merge as slot 1 of train ${nonce}`);
|
||||
expect(line(pre1.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h1}`);
|
||||
const early = v('2');
|
||||
expect(early.status).toBe(EXIT.fail);
|
||||
expect(early.err).toMatch(/is neither T1 nor T2 modulo stamps.*nothing of train \S+ merged, so the queue is not frozen.*\(QUEUE_TRAIN_TREE_MISMATCH\)/);
|
||||
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
const post1 = v('1');
|
||||
expect(post1.status).toBe(EXIT.ok);
|
||||
expect(post1.out).toMatch(/^main: [0-9a-f]{40} = T1 \(same modulo stamps \(1 stamp file\(s\)\)\)$/m);
|
||||
expect(post1.out).toContain(`VERIFY_TRAIN: #1 merged; main's tree is T1 of train ${nonce} (1/2 merged)`);
|
||||
expect(next(post1.out)).toBe(`NEXT: gstack-ship-queue verify --pr 2 --train ${nonce}`);
|
||||
expect(line(v('2').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h2}`);
|
||||
|
||||
const broken = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'stray.txt', text: 'not in the train\n' });
|
||||
const mismatch = v('2');
|
||||
expect(mismatch.status).toBe(EXIT.fail);
|
||||
expect(mismatch.err).toContain('(QUEUE_TRAIN_TREE_MISMATCH)');
|
||||
expect(line(mismatch.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(new RegExp(`^QUEUE_TRAIN_FROZEN: train \\S+ merged #1; main ${broken.slice(0, 12)} tree [0-9a-f]{12}; backstop dispatched run \\d+ \\(nonce gate\\.backstop-`));
|
||||
const backstop = dispatches(fx, 'evals.yml').at(-1)!;
|
||||
expect([backstop.ref, (backstop.inputs as any).expected_sha, (backstop.inputs as any).evals_all]).toEqual(['main', broken, 'true']);
|
||||
const freezeFile = path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`);
|
||||
expect(JSON.parse(fs.readFileSync(freezeFile, 'utf8'))).toMatchObject({ kind: 'freeze', merged: ['1'], unmerged: [{ pr: '2', head: h2 }], cleared_at: null });
|
||||
|
||||
const h3 = openPr(fx, '3');
|
||||
readyReceipt(fx, '3', h3);
|
||||
const ordinary = queue(fx, ['train', 'build', '--prs', `3@${h3}`, '--urgent']);
|
||||
expect(ordinary.status).toBe(EXIT.refused);
|
||||
expect(ordinary.err).toContain('(QUEUE_TRAIN_FROZEN)');
|
||||
expect(next(ordinary.out)).toBe('NEXT: gstack-ship-queue train build --repair --prs <repair-pr>@<sha>');
|
||||
const fresh = path.join(fx.repo.root, 'fresh-state');
|
||||
expect(queue(fx, ['train', 'status'], { GSTACK_STATE_ROOT: fresh }, coord).out).toMatch(/^QUEUE_TRAIN_FROZEN: train /m);
|
||||
|
||||
const repair = queue(fx, ['train', 'build', '--repair', '--prs', `3@${h3}`]);
|
||||
expect(repair.status).toBe(EXIT.ok);
|
||||
const rn = nonceOf(repair.out);
|
||||
expect(trainJson(fx, rn)).toMatchObject({ repair: true, base: { sha: broken } });
|
||||
expect(queue(fx, ['train', 'verdict', '--train', rn]).status).toBe(EXIT.ok);
|
||||
expect(v('2').err).toContain('(QUEUE_TRAIN_FROZEN)');
|
||||
expect(dispatches(fx, 'evals.yml').filter(d => d.ref === 'main').length).toBe(1);
|
||||
expect(line(v('3', rn).out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h3}`);
|
||||
publishMain(fx, trainJson(fx, rn).prefixes[1].commit, '1.2.6.0');
|
||||
const cleared = v('3', rn);
|
||||
expect(cleared.status).toBe(EXIT.ok);
|
||||
expect(cleared.out).toMatch(/^FREEZE: cleared \(repair #3 via train \S+; main [0-9a-f]{12} carries a green record\)$/m);
|
||||
expect(next(cleared.out)).toBe(`NEXT: gstack-ship-queue train build --prs 2@${h2}`);
|
||||
expect(JSON.parse(fs.readFileSync(freezeFile, 'utf8')).cleared_at).toBe('2026-10-18T12:00:00.000Z');
|
||||
expect(queue(fx, ['train', 'status']).out).not.toContain('QUEUE_TRAIN_FROZEN');
|
||||
}, 300_000);
|
||||
test("rule 22: verify --train binds the receipt to the pinned head when the current head is its stamp commit; a receipt for another head refuses the slot and merges nothing", () => {
|
||||
const fx = make();
|
||||
const { h1, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = () => queue(fx, ['verify', '--pr', '1', '--train', nonce], {}, coord);
|
||||
const { repo } = fx;
|
||||
repo.git('checkout', '-q', '-B', 'lane1', h1);
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.4.0\n');
|
||||
repo.git('commit', '-qam', 'v1.2.4.0 stamp');
|
||||
const stamped = repo.git('rev-parse', 'HEAD');
|
||||
repo.git('push', '-q', '-f', 'origin', `${stamped}:refs/pull/1/head`);
|
||||
const ok = v();
|
||||
expect(ok.status).toBe(EXIT.ok);
|
||||
expect(ok.out).toContain(`head: ${stamped} (same modulo stamps (1 stamp file(s)))`);
|
||||
expect(ok.out).toContain(`SHIP_RECEIPT: pr=1 head=${h1.slice(0, 12)} version=- base=main (binds the pinned head)`);
|
||||
expect(line(ok.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${stamped}`);
|
||||
setPrBody(fx, '1', shippedBody('1', 'b'.repeat(40)));
|
||||
const stale = v();
|
||||
expect(stale.status).toBe(EXIT.refused);
|
||||
expect(stale.err).toMatch(new RegExp(`PR #1's ship receipt is for bbbbbbbbbbbb, not the head ${h1.slice(0, 12)} or ${stamped.slice(0, 12)} being merged.*\\(QUEUE_RECEIPT_STALE\\)`));
|
||||
expect(stale.out).not.toContain('MERGE_CONDITION:');
|
||||
expect(next(stale.out)).toBe("NEXT: #1's lane runs /ship and READYs again; then gstack-ship-queue train build --prs <pins>");
|
||||
expect(trainJson(fx, nonce).merged).toEqual([]);
|
||||
setPrBody(fx, '1', '');
|
||||
expect(v().err).toContain('(QUEUE_RECEIPT_MISSING)');
|
||||
setPrBody(fx, '1', '```gstack-ship-receipt\n{"schema_version":1}\n```\n');
|
||||
const invalid = v();
|
||||
expect(invalid.err).toMatch(/PR #1's ship receipt is invalid \(.*\).*\(QUEUE_RECEIPT_MISSING\)/);
|
||||
expect(invalid.out).not.toContain('MERGE_CONDITION:');
|
||||
setPrBody(fx, '1', shippedBody('2', h1));
|
||||
const otherPr = v();
|
||||
expect(otherPr.err).toMatch(/PR #1's ship receipt names pr=2, not this PR.*\(QUEUE_RECEIPT_STALE\)/);
|
||||
expect(otherPr.out).not.toContain('MERGE_CONDITION:');
|
||||
expect(trainJson(fx, nonce).merged).toEqual([]);
|
||||
setPrBody(fx, '1', shippedBody('1', stamped));
|
||||
expect(v().out).toContain(`SHIP_RECEIPT: pr=1 head=${stamped.slice(0, 12)} version=- base=main (binds the current head)`);
|
||||
const saved = fx.read().prs['1'];
|
||||
fx.write(d => { delete d.prs['1']; });
|
||||
const unreadable = v();
|
||||
expect(unreadable.status).toBe(EXIT.refused);
|
||||
expect(unreadable.err).toContain('(QUEUE_PROOF_MISSING)');
|
||||
expect(unreadable.out).not.toContain('MERGE_CONDITION:');
|
||||
fx.write(d => { d.prs['1'] = saved; });
|
||||
expect(trainJson(fx, nonce).merged).toEqual([]);
|
||||
}, 300_000);
|
||||
|
||||
test('from slot 2 on, a head that merges main into the pin verifies when its tree is the slot\'s prefix modulo stamps', () => {
|
||||
const fx = make();
|
||||
const { h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
|
||||
const { repo } = fx;
|
||||
const laneHead = (extra?: { file: string; text: string }) => {
|
||||
repo.git('reset', '-q', '--hard');
|
||||
repo.git('checkout', '-q', '-B', 'lane2', h2);
|
||||
repo.git('rm', '-rq', '.');
|
||||
repo.git('checkout', t.prefixes[2].commit, '--', '.');
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.5.0\n');
|
||||
if (extra) fs.writeFileSync(path.join(repo.work, extra.file), extra.text);
|
||||
repo.git('add', '-A');
|
||||
const tree = repo.git('write-tree');
|
||||
const head = repo.git('commit-tree', tree, '-p', h2, '-p', main1, '-m', 'merge main into #2, stamp 1.2.5.0');
|
||||
repo.git('push', '-q', '-f', 'origin', `${head}:refs/pull/2/head`);
|
||||
return head;
|
||||
};
|
||||
|
||||
const merged = laneHead();
|
||||
const ok = v('2');
|
||||
expect(ok.status).toBe(EXIT.ok);
|
||||
expect(ok.out).toMatch(new RegExp(`^head: ${merged} \\(T2 with main merged in, same modulo stamps`, 'm'));
|
||||
expect(line(ok.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${merged}`);
|
||||
|
||||
const stray = laneHead({ file: 'stray.txt', text: 'not in the train\n' });
|
||||
const moved = v('2');
|
||||
expect(moved.status).toBe(EXIT.fail);
|
||||
expect(moved.err).toMatch(new RegExp(`#2 moved past its pinned head ${h2.slice(0, 12)} and is not T2 modulo stamps \\(${stray.slice(0, 12)}: .*\\(QUEUE_TRAIN_MOVED\\)`));
|
||||
}, 300_000);
|
||||
|
||||
test("GSTA-67 (#3345 at 593e61c): a merged-in head whose CHANGELOG was resolved by hand verifies even where T<i>'s mechanical CHANGELOG differs; an invented line or a head without main is still refused", () => {
|
||||
const fx = make();
|
||||
const h1 = openPr(fx, '1', { changelog: false });
|
||||
const h2 = openPr(fx, '2', { changelog: cl => cl.replace('# Changelog\n', '# Changelog\n\n## [Unreleased]\n\n- #2 change\n').replace('## [1.2.2.0] - 2026-09-01\n\n', '') });
|
||||
readyReceipt(fx, '1', h1);
|
||||
readyReceipt(fx, '2', h2);
|
||||
fx.write(d => { d.rules['evals.yml'] = GREEN_GATE; });
|
||||
const nonce = nonceOf(queue(fx, ['train', 'build', '--prs', `1@${h1},2@${h2}`]).out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
expect(fx.repo.git('show', `${t.prefixes[2].commit}:CHANGELOG.md`)).not.toContain('## [1.2.2.0]');
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = () => queue(fx, ['verify', '--pr', '2', '--train', nonce], {}, coord);
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
const { repo } = fx;
|
||||
const laneHead = (entry: string, parents: string[]) => {
|
||||
repo.git('reset', '-q', '--hard');
|
||||
repo.git('checkout', '-q', '-B', 'lane2', h2);
|
||||
repo.git('rm', '-rq', '.');
|
||||
repo.git('checkout', t.prefixes[2].commit, '--', '.');
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.5.0\n');
|
||||
fs.writeFileSync(path.join(repo.work, 'CHANGELOG.md'), repo.git('show', `${main1}:CHANGELOG.md`).replace('# Changelog\n', `# Changelog\n\n## [1.2.5.0] - 2026-10-18\n\n${entry}\n`) + '\n');
|
||||
repo.git('add', '-A');
|
||||
const head = repo.git('commit-tree', repo.git('write-tree'), ...parents.flatMap(p => ['-p', p]), '-m', 'merge main into #2 (CHANGELOG by hand), stamp 1.2.5.0');
|
||||
repo.git('push', '-q', '-f', 'origin', `${head}:refs/pull/2/head`);
|
||||
return head;
|
||||
};
|
||||
|
||||
const byHand = laneHead('- #2 change', [h2, main1]);
|
||||
const ok = v();
|
||||
expect(ok.status).toBe(EXIT.ok);
|
||||
expect(ok.out).toContain(`head: ${byHand} (T2 with main merged in, same modulo stamps (1 stamp file(s)) except CHANGELOG.md, resolved as main's CHANGELOG.md plus #2's own entry)`);
|
||||
expect(line(ok.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${byHand}`);
|
||||
|
||||
const invented = laneHead('- #2 change\n- added after the gate', [h2, main1]);
|
||||
const refused = v();
|
||||
expect(refused.status).toBe(EXIT.fail);
|
||||
expect(refused.err).toContain(`#2 moved past its pinned head ${h2.slice(0, 12)} and is not T2 modulo stamps (${invented.slice(0, 12)}: differs from T2 in CHANGELOG.md, which is not main's plus #2's own entry: the PR's entry holds a line its pin never added: "- added after the gate"; against the pin it differs: `);
|
||||
expect(refused.err).toContain('(QUEUE_TRAIN_MOVED)');
|
||||
|
||||
const orphan = laneHead('- #2 change', [h2]);
|
||||
const noMain = v();
|
||||
expect(noMain.status).toBe(EXIT.fail);
|
||||
expect(noMain.err).toContain(`(${orphan.slice(0, 12)}: does not contain main ${main1.slice(0, 12)}; against the pin it differs: `);
|
||||
}, 300_000);
|
||||
// fails_when=the post-merge verify of a merged-in head the pre-merge verify accepted freezes the queue because T<i>'s single [Unreleased] became two released sections, or the pre-merge verify refuses the correction bullet mergeChangelogs itself wrote; why_new=the GSTA-67 test above never publishes the accepted head and never stacks a child on a released parent; seam=none (real git, the fixture's gh); no_claim=what the squash commit's message says
|
||||
test("train 24 (GSTA-96): a stacked child's head the pre-merge verify accepted confirms after its squash merge under the same CHANGELOG rule, corrections to the released parent included", () => {
|
||||
const fx = make();
|
||||
const { repo } = fx;
|
||||
const h1 = openPr(fx, '1', { changelog: cl => cl.replace('# Changelog\n', '# Changelog\n\n## [Unreleased]\n\n**Parent entry of #1.**\n\n### Changed\n- #1 change, the first wording\n- #1 second bullet, unchanged\n') });
|
||||
const h2 = openPr(fx, '2', { from: 'pr-1', changelog: cl => cl.replace('## [Unreleased]\n\n**Parent entry of #1.**', '## [Unreleased]\n\n**Child entry of #2.**\n\n### Changed\n- #2 change\n\n**Parent entry of #1.**').replace('- #1 change, the first wording', '- #1 change, the better wording') });
|
||||
readyReceipt(fx, '1', h1);
|
||||
readyReceipt(fx, '2', h2);
|
||||
fx.write(d => { d.rules['evals.yml'] = GREEN_GATE; });
|
||||
const nonce = nonceOf(queue(fx, ['train', 'build', '--prs', `1@${h1},2@${h2}`]).out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
expect(parseChangelog(repo.git('show', `${t.prefixes[2].commit}:CHANGELOG.md`)).sections.map(s => s.version ?? 'Unreleased')).toEqual(['Unreleased', '1.2.3.0', '1.2.2.0']);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
|
||||
// Slot 1: #1 squash-merges and is released as 1.2.4.0 (its [Unreleased] re-headed).
|
||||
expect(line(v('1').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h1}`);
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: repo.git('show', `${t.prefixes[1].commit}:CHANGELOG.md`).replace('## [Unreleased]', '## [1.2.4.0] - 2026-10-18') + '\n' });
|
||||
expect(v('1').out).toContain(`VERIFY_TRAIN: #1 merged; main's tree is T1 of train ${nonce} (1/2 merged)`);
|
||||
|
||||
// Slot 2: the lane merges main into its pin; mergeChangelogs carries the child past its released parent.
|
||||
const merged = mergeChangelogs(repo.git('show', `${h2}:CHANGELOG.md`) + '\n', repo.git('show', `${main1}:CHANGELOG.md`) + '\n', repo.git('show', `${h1}:CHANGELOG.md`) + '\n')!;
|
||||
expect(merged).toContain('- Correction to the 1.2.4.0 entry below: "first" should read "better".');
|
||||
repo.git('reset', '-q', '--hard');
|
||||
repo.git('checkout', '-q', '-B', 'lane2', h2);
|
||||
repo.git('rm', '-rq', '.');
|
||||
repo.git('checkout', t.prefixes[2].commit, '--', '.');
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.5.0\n');
|
||||
fs.writeFileSync(path.join(repo.work, 'CHANGELOG.md'), merged.replace('## [Unreleased]', '## [1.2.5.0] - 2026-10-18'));
|
||||
repo.git('add', '-A');
|
||||
const laneHead = repo.git('commit-tree', repo.git('write-tree'), '-p', h2, '-p', main1, '-m', 'merge main into #2, stamp 1.2.5.0');
|
||||
repo.git('push', '-q', '-f', 'origin', `${laneHead}:refs/pull/2/head`);
|
||||
repo.git('reset', '-q', '--hard');
|
||||
const pre = v('2');
|
||||
expect([pre.status, pre.err]).toEqual([EXIT.ok, '']);
|
||||
expect(pre.out).toContain(`head: ${laneHead} (T2 with main merged in, same modulo stamps (1 stamp file(s)) except CHANGELOG.md, resolved as main's CHANGELOG.md plus #2's own entry)`);
|
||||
expect(line(pre.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${laneHead}`);
|
||||
|
||||
// The squash merge publishes exactly that tree; the post-merge verify confirms it instead of freezing the queue.
|
||||
const main2 = publishMain(fx, laneHead, '1.2.5.0');
|
||||
expect(repo.git('rev-parse', `${main2}^{tree}`)).toBe(repo.git('rev-parse', `${laneHead}^{tree}`));
|
||||
const post = v('2');
|
||||
expect([post.status, post.err]).toEqual([EXIT.ok, '']);
|
||||
expect(line(post.out, 'main:')).toBe(`main: ${main2} = T2 (same modulo stamps (1 stamp file(s)) except CHANGELOG.md, main ${main1.slice(0, 12)}'s CHANGELOG.md plus #2's own entry)`);
|
||||
expect(post.out).toContain(`VERIFY_TRAIN: #2 merged; main's tree is T2 of train ${nonce} (2/2 merged)`);
|
||||
expect(queue(fx, ['train', 'status']).out).not.toContain('QUEUE_TRAIN_FROZEN');
|
||||
}, 300_000);
|
||||
});
|
||||
@@ -15,14 +15,15 @@ import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { mergeChangelogs, parseChangelog } from '../lib/changelog-check';
|
||||
import { parseChangelog } from '../lib/changelog-check';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { baseOverlap } from '../lib/ship-queue-train';
|
||||
import { TRAIN_HELP } from '../lib/ship-queue-train-cli';
|
||||
import { BASE_POLICY, cleanup, runBin } from './helpers/restamp-fixture';
|
||||
import { coordinatorClone } from './helpers/ship-queue-fixture';
|
||||
import { publishMain, twoPrTrain } from './helpers/ship-queue-train-cases';
|
||||
import {
|
||||
COMPLETE, FAIL, GREEN_GATE, PASS, RED_GATE, TRAIN_BLOCK, TRAIN_POLICY, dispatches, githubOrigin, line, mergeRefCommit, nonceOf, openPr, queue, readyReceipt, repoKey, setPrBody, shippedBody, trainFixture, trainJson, urlKey,
|
||||
GREEN_GATE, TRAIN_BLOCK, TRAIN_POLICY, dispatches, githubOrigin, line, mergeRefCommit, nonceOf, openPr, queue, readyReceipt, repoKey, setPrBody, shippedBody, trainFixture, trainJson, urlKey,
|
||||
type Rule, type TrainFixture,
|
||||
} from './helpers/ship-queue-train-fixture';
|
||||
|
||||
@@ -34,31 +35,6 @@ const result = (out: string) => line(out, 'GSTACK_RESULT:');
|
||||
const next = (out: string) => line(out, 'NEXT:');
|
||||
const remoteRefs = (fx: TrainFixture) => fx.repo.git('ls-remote', 'origin');
|
||||
|
||||
function twoPrTrain(fx: TrainFixture, gate: Rule = GREEN_GATE) {
|
||||
const h1 = openPr(fx, '1');
|
||||
const h2 = openPr(fx, '2');
|
||||
readyReceipt(fx, '1', h1);
|
||||
readyReceipt(fx, '2', h2);
|
||||
fx.write(d => { d.rules['evals.yml'] = gate; });
|
||||
const r = queue(fx, ['train', 'build', '--prs', `1@${h1},2@${h2}`]);
|
||||
return { h1, h2, r, nonce: nonceOf(r.out) };
|
||||
}
|
||||
|
||||
/** A main commit with a prefix's tree plus a VERSION stamp, the way stamp-at-merge publishes it. */
|
||||
function publishMain(fx: TrainFixture, prefixCommit: string, version: string, extra?: { file: string; text: string }): string {
|
||||
const { repo } = fx;
|
||||
repo.git('checkout', '-q', '-B', 'mainsim', 'origin/main');
|
||||
repo.git('rm', '-rq', '.');
|
||||
repo.git('checkout', prefixCommit, '--', '.');
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), version + '\n');
|
||||
if (extra) fs.writeFileSync(path.join(repo.work, extra.file), extra.text);
|
||||
repo.git('add', '-A');
|
||||
repo.git('commit', '-q', '-m', `merge to ${version}`);
|
||||
repo.git('push', '-q', 'origin', 'HEAD:refs/heads/main');
|
||||
repo.git('fetch', '-q', 'origin');
|
||||
return repo.git('rev-parse', 'HEAD');
|
||||
}
|
||||
|
||||
// fails_when=coordinatorClone copies origin.git/objects file by file again, so an entry that appears or vanishes there mid-copy (the detached maintenance.lock every push into the fixture origin leaves) fails the clone, as in two Free Tests reds on 2026-10-28 (GSTA-139 ledger); why_new=no other test clones while origin's objects directory changes; seam=a dangling symlink planted under objects/, which a local copy refuses on every run; no_claim=which process removed the loose object those runs named
|
||||
test('the coordinator clone reads origin through git, never by copying its objects directory (GSTA-139)', () => {
|
||||
const fx = make();
|
||||
@@ -584,600 +560,3 @@ describe('train build', () => {
|
||||
expect(all.out).toMatch(/^SLOT: 1 #3 head=[0-9a-f]{40} screened \(narrow\) ready_at=2026-10-18T09:00:00\.000Z$/m);
|
||||
}, 180_000);
|
||||
});
|
||||
|
||||
describe('dispatch recovery and status', () => {
|
||||
test('a partial dispatch (gh failed after GitHub accepted it) is unknown, never re-dispatched, and train status finds the run by nonce', () => {
|
||||
const fx = make();
|
||||
const { r, nonce } = twoPrTrain(fx, { ...GREEN_GATE, failButCreate: true });
|
||||
expect(r.status).toBe(EXIT.refused);
|
||||
expect(r.err).toContain('(QUEUE_TRAIN_DISPATCH_UNKNOWN)');
|
||||
expect(next(r.out)).toBe(`NEXT: gstack-ship-queue train status --train ${nonce}`);
|
||||
expect(trainJson(fx, nonce).state).toBe('dispatch-unknown');
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).err).toContain('(QUEUE_TRAIN_DISPATCH_UNKNOWN)');
|
||||
expect(queue(fx, ['train', 'build', '--train', nonce]).err).toContain('(QUEUE_TRAIN_DISPATCH_UNKNOWN)');
|
||||
const status = queue(fx, ['train', 'status', '--train', nonce]);
|
||||
expect(status.status).toBe(EXIT.ok);
|
||||
expect(status.out).toMatch(new RegExp(`^ATTEMPT: a1 gate state=dispatched nonce=${nonce.replace(/\./g, '\\.')} run=101 `, 'm'));
|
||||
expect(trainJson(fx, nonce).state).toBe('gate-pending');
|
||||
expect(next(status.out)).toBe(`NEXT: gstack-ship-queue train verdict --train ${nonce}`);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
expect(dispatches(fx, 'evals.yml').length).toBe(1);
|
||||
}, 180_000);
|
||||
|
||||
test('a dispatch that never started is marked absent by status; only then does build dispatch it again, under the same nonce', () => {
|
||||
const fx = make();
|
||||
const { r, nonce } = twoPrTrain(fx, { silent: true });
|
||||
expect(r.err).toContain('(QUEUE_TRAIN_DISPATCH_UNKNOWN)');
|
||||
const status = queue(fx, ['train', 'status', '--train', nonce]);
|
||||
expect(status.out).toContain('ATTEMPT: a1 gate state=absent');
|
||||
expect(next(status.out)).toBe(`NEXT: gstack-ship-queue train build --train ${nonce}`);
|
||||
fx.write(d => { d.rules['evals.yml'] = GREEN_GATE; });
|
||||
const again = queue(fx, ['train', 'build', '--train', nonce]);
|
||||
expect(again.status).toBe(EXIT.ok);
|
||||
expect(dispatches(fx, 'evals.yml').map(d => (d.inputs as any).nonce)).toEqual([nonce, nonce]);
|
||||
expect(trainJson(fx, nonce).attempts).toEqual(['a1', 'a2']);
|
||||
}, 180_000);
|
||||
|
||||
test('train status on a clean state root rebuilds the records from refs/notes/gstack-trains and spends nothing', () => {
|
||||
const fx = make();
|
||||
const { nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const before = dispatches(fx).length;
|
||||
const clone = coordinatorClone(fx.repo);
|
||||
const fresh = path.join(fx.repo.root, 'fresh-state');
|
||||
const s = queue(fx, ['train', 'status', '--train', nonce], { GSTACK_STATE_ROOT: fresh }, clone);
|
||||
expect(s.status).toBe(EXIT.ok);
|
||||
expect(s.out).toMatch(/^NOTES: read 2 record\(s\), restored 2 /m);
|
||||
expect(s.out).toContain(`TRAIN: ${nonce} state=green`);
|
||||
expect(s.out).toContain('CHECK: gstack/full-gate on');
|
||||
expect(trainJson(fx, nonce, fresh)).toEqual(trainJson(fx, nonce));
|
||||
expect(dispatches(fx).length).toBe(before);
|
||||
const all = queue(fx, ['train', 'status'], { GSTACK_STATE_ROOT: fresh }, clone);
|
||||
expect(all.out).toContain(`NEXT(${nonce}): gstack-ship-queue verify --pr 1 --train ${nonce}`);
|
||||
}, 180_000);
|
||||
});
|
||||
|
||||
describe('verdict, bisect, rebuild', () => {
|
||||
function redTrain(fx: TrainFixture, pattern: string) {
|
||||
const t = twoPrTrain(fx, RED_GATE);
|
||||
const v = queue(fx, ['train', 'verdict', '--train', t.nonce]);
|
||||
const prefixes = trainJson(fx, t.nonce).prefixes.map((p: any) => p.commit);
|
||||
fx.write(d => { d.rules['evals.yml'] = { bisect: { prefixes, patterns: { c1: pattern } } }; });
|
||||
return { ...t, v, prefixes };
|
||||
}
|
||||
|
||||
test('a red train names its cases and a capped bisect; the bisect runs only the red cases on every prefix and attributes a monotone pattern; prune deletes the dropped train\'s branch', () => {
|
||||
const fx = make();
|
||||
const { h1, nonce, v, prefixes } = redTrain(fx, 'GGR');
|
||||
expect(v.status).toBe(EXIT.fail);
|
||||
expect(v.err).toContain(`train ${nonce} is red on c1`);
|
||||
expect(v.out).toContain('ATTEMPT: a1 gate run 101 RED red=c1 cost=$1.70');
|
||||
expect(next(v.out)).toBe(`NEXT: gstack-ship-queue train bisect --train ${nonce} --spend-cap 2.70`);
|
||||
const dry = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '2.70', '--dry-run']);
|
||||
expect(dry.out).toContain('BISECT: cases c1 prefixes T0,T1,T2 need results; $0.90 reserved per prefix; spent $0.00, cap $2.70');
|
||||
expect(dry.out).toContain('DRY-RUN: nothing dispatched');
|
||||
expect(dispatches(fx, 'evals.yml').length).toBe(1);
|
||||
const go = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '2.70']);
|
||||
expect(go.status).toBe(EXIT.ok);
|
||||
const sent = dispatches(fx, 'evals.yml').at(-1)!.inputs as any;
|
||||
expect(sent.cases).toBe('c1');
|
||||
expect(sent.prefix_shas).toBe(prefixes.join(','));
|
||||
expect(sent.expected_sha).toBe(prefixes[2]);
|
||||
expect(sent.nonce).toMatch(/^gate\.bisect-/);
|
||||
const done = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '2.70']);
|
||||
expect(done.status).toBe(EXIT.ok);
|
||||
expect(done.out).toContain('PATTERN: c1 T0=G T1=G T2=R');
|
||||
expect(done.out).toContain('BISECT: ATTRIBUTED #2');
|
||||
expect(next(done.out)).toBe(`NEXT: gstack-ship-queue train build --prs 1@${h1}`);
|
||||
expect(trainJson(fx, nonce).state).toBe('attributed');
|
||||
expect(queue(fx, ['train', 'prune', '--dry-run']).out).toContain(`WOULD-DELETE: train/${nonce} (attributed)`);
|
||||
expect(queue(fx, ['train', 'prune']).out).toContain(`DELETED: train/${nonce} (attributed)`);
|
||||
expect(remoteRefs(fx)).not.toContain(`refs/heads/train/${nonce}`);
|
||||
expect(queue(fx, ['train', 'prune']).out).toContain(`GONE: train/${nonce}`);
|
||||
}, 180_000);
|
||||
|
||||
test('red on every prefix, T0 included, is RED_ON_MAIN; a non-monotone pattern is unattributed and earns no rebuild', () => {
|
||||
const main = make();
|
||||
const m = redTrain(main, 'RRR');
|
||||
queue(main, ['train', 'bisect', '--train', m.nonce, '--spend-cap', '5']);
|
||||
const onMain = queue(main, ['train', 'bisect', '--train', m.nonce, '--spend-cap', '5']);
|
||||
expect(onMain.status).toBe(EXIT.fail);
|
||||
expect(onMain.err).toContain('(QUEUE_TRAIN_RED_ON_MAIN)');
|
||||
expect(next(onMain.out)).toMatch(/^NEXT: fix forward on main first, then gstack-ship-queue train build --prs /);
|
||||
const fx = make();
|
||||
const n = redTrain(fx, 'GRG');
|
||||
queue(fx, ['train', 'bisect', '--train', n.nonce, '--spend-cap', '5']);
|
||||
const mixed = queue(fx, ['train', 'bisect', '--train', n.nonce, '--spend-cap', '5']);
|
||||
expect(mixed.status).toBe(EXIT.fail);
|
||||
expect(mixed.err).toContain('(QUEUE_TRAIN_UNATTRIBUTED)');
|
||||
expect(mixed.out).toContain('BISECT: UNATTRIBUTED (not monotone)');
|
||||
expect(next(mixed.out)).toMatch(/^NEXT: route the red cases to a repair lane \(GStack Minder\); once the repair merges: /);
|
||||
const refused = queue(fx, ['train', 'rebuild', '--train', n.nonce]);
|
||||
expect(refused.status).toBe(EXIT.refused);
|
||||
expect(refused.err).toMatch(/rebuild refused: the bisect was not all green \(c1=GRG\).*\(QUEUE_TRAIN_REBUILD_REFUSED\)/);
|
||||
}, 240_000);
|
||||
|
||||
test('rebuild-once: refused without a bisect; an all-green bisect earns exactly one unchanged rebuild, both runs reported; a second red stays red', () => {
|
||||
const fx = make();
|
||||
const { nonce } = redTrain(fx, 'GGG');
|
||||
expect(queue(fx, ['train', 'rebuild', '--train', nonce]).err).toMatch(/rebuild refused: no bisect record.*\(QUEUE_TRAIN_REBUILD_REFUSED\)/);
|
||||
queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']);
|
||||
const green = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']);
|
||||
expect(green.out).toContain('BISECT: UNATTRIBUTED (all green)');
|
||||
expect(next(green.out)).toBe(`NEXT: gstack-ship-queue train rebuild --train ${nonce}`);
|
||||
fx.write(d => { d.rules['evals.yml'] = RED_GATE; });
|
||||
const rebuild = queue(fx, ['train', 'rebuild', '--train', nonce]);
|
||||
expect(rebuild.status).toBe(EXIT.ok);
|
||||
expect(dispatches(fx, 'evals.yml').at(-1)!.inputs).toMatchObject({ evals_all: 'true', nonce: `${nonce}.2` });
|
||||
const second = queue(fx, ['train', 'verdict', '--train', nonce]);
|
||||
expect(second.status).toBe(EXIT.fail);
|
||||
expect(second.out).toContain('ATTEMPT: a1 gate run 101 RED red=c1');
|
||||
expect(second.out).toMatch(/^ATTEMPT: a2 rebuild run \d+ RED red=c1/m);
|
||||
expect(next(second.out)).toMatch(/^NEXT: second red stays red: route c1 to a repair lane/);
|
||||
expect(queue(fx, ['train', 'rebuild', '--train', nonce]).err).toMatch(/rebuild refused: already rebuilt once/);
|
||||
expect(queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']).err).toContain('second red is not bisected again');
|
||||
}, 240_000);
|
||||
|
||||
test('a capped bisect launches only what fits, keeps completed prefixes, and resumes without repeating one', () => {
|
||||
const fx = make();
|
||||
const { nonce, prefixes } = redTrain(fx, 'GGR');
|
||||
const none = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '0.5']);
|
||||
expect(none.status).toBe(EXIT.refused);
|
||||
expect(none.err).toContain('(QUEUE_TRAIN_BISECT_CAPPED)');
|
||||
expect(next(none.out)).toBe(`NEXT: gstack-ship-queue train bisect --train ${nonce} --spend-cap 2.70`);
|
||||
expect(dispatches(fx, 'evals.yml').length).toBe(1);
|
||||
const part = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '1.9']);
|
||||
expect(part.status).toBe(EXIT.refused);
|
||||
expect(part.err).toContain('(QUEUE_TRAIN_BISECT_CAPPED)');
|
||||
expect(part.out).toContain('BISECT: launch T0,T1; 1 prefix(es) wait for a higher cap');
|
||||
expect((dispatches(fx, 'evals.yml').at(-1)!.inputs as any).prefix_shas).toBe(prefixes.slice(0, 2).join(','));
|
||||
const resume = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']);
|
||||
expect(resume.status).toBe(EXIT.ok);
|
||||
expect((dispatches(fx, 'evals.yml').at(-1)!.inputs as any).prefix_shas).toBe(prefixes[2]);
|
||||
const done = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']);
|
||||
expect(done.out).toContain('BISECT: ATTRIBUTED #2');
|
||||
expect(done.out).toContain('BISECT: spent $1.50 of cap $5.00');
|
||||
expect(dispatches(fx, 'evals.yml').length).toBe(3);
|
||||
}, 240_000);
|
||||
|
||||
test('a bisect refuses prefixes that are not ancestors of train/<nonce>', () => {
|
||||
const fx = make();
|
||||
const { nonce } = redTrain(fx, 'GGR');
|
||||
fx.repo.git('push', '-q', '-f', 'origin', `origin/main:refs/heads/train/${nonce}`);
|
||||
const r = queue(fx, ['train', 'bisect', '--train', nonce, '--spend-cap', '5']);
|
||||
expect(r.status).toBe(EXIT.refused);
|
||||
expect(r.err).toMatch(/train\/\S+ is at [0-9a-f]{12}, not the recorded train head .*\(QUEUE_TRAIN_PREFIX_INVALID\)/);
|
||||
expect(dispatches(fx, 'evals.yml').length).toBe(1);
|
||||
}, 180_000);
|
||||
|
||||
test('an INFRA/INCOMPLETE-only census is never green and earns one re-dispatch, reported beside the first run', () => {
|
||||
const fx = make();
|
||||
const infra: Rule = { conclusion: 'failure', record: { panels: [PASS('c1'), FAIL('c2', 'INFRA'), PASS('j1', 'judge')], census: { ...COMPLETE, killed_before_upload: 1 }, verdict: 'RED' } };
|
||||
const { nonce } = twoPrTrain(fx, infra);
|
||||
const v = queue(fx, ['train', 'verdict', '--train', nonce]);
|
||||
expect(v.status).toBe(EXIT.fail);
|
||||
expect(v.err).toMatch(/gate is incomplete: 1 slice killed before upload; c2 FAIL \(INFRA\).*\(QUEUE_TRAIN_INCOMPLETE\)/);
|
||||
expect(next(v.out)).toBe(`NEXT: gstack-ship-queue train rebuild --train ${nonce} --infra (the single re-dispatch EVAL_POLICY.infraRedispatch allows; report both runs)`);
|
||||
expect(queue(fx, ['train', 'rebuild', '--train', nonce]).err).toContain('rebuild refused: no bisect record');
|
||||
const again = queue(fx, ['train', 'rebuild', '--train', nonce, '--infra']);
|
||||
expect(again.status).toBe(EXIT.ok);
|
||||
const second = queue(fx, ['train', 'verdict', '--train', nonce]);
|
||||
expect(second.out).toMatch(/^ATTEMPT: a2 infra-redispatch run \d+ INCOMPLETE/m);
|
||||
expect(next(second.out)).toMatch(/^NEXT: diagnose run /);
|
||||
expect(queue(fx, ['train', 'rebuild', '--train', nonce, '--infra']).err).toMatch(/already re-dispatched once.*\(QUEUE_TRAIN_REBUILD_REFUSED\)/);
|
||||
}, 180_000);
|
||||
});
|
||||
|
||||
describe('verify, freeze, repair and clear', () => {
|
||||
test('verify accepts each merge only at prefix equality modulo stamps; an interrupted publication freezes the queue until one repair train lands', () => {
|
||||
const fx = make();
|
||||
const { h1, h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string, train = nonce) => queue(fx, ['verify', '--pr', pr, '--train', train], {}, coord);
|
||||
|
||||
const pre1 = v('1');
|
||||
expect(pre1.status).toBe(EXIT.ok);
|
||||
expect(pre1.out).toContain(`VERIFY_TRAIN: #1 may merge as slot 1 of train ${nonce}`);
|
||||
expect(line(pre1.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h1}`);
|
||||
const early = v('2');
|
||||
expect(early.status).toBe(EXIT.fail);
|
||||
expect(early.err).toMatch(/is neither T1 nor T2 modulo stamps.*nothing of train \S+ merged, so the queue is not frozen.*\(QUEUE_TRAIN_TREE_MISMATCH\)/);
|
||||
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
const post1 = v('1');
|
||||
expect(post1.status).toBe(EXIT.ok);
|
||||
expect(post1.out).toMatch(/^main: [0-9a-f]{40} = T1 \(same modulo stamps \(1 stamp file\(s\)\)\)$/m);
|
||||
expect(post1.out).toContain(`VERIFY_TRAIN: #1 merged; main's tree is T1 of train ${nonce} (1/2 merged)`);
|
||||
expect(next(post1.out)).toBe(`NEXT: gstack-ship-queue verify --pr 2 --train ${nonce}`);
|
||||
expect(line(v('2').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h2}`);
|
||||
|
||||
const broken = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'stray.txt', text: 'not in the train\n' });
|
||||
const mismatch = v('2');
|
||||
expect(mismatch.status).toBe(EXIT.fail);
|
||||
expect(mismatch.err).toContain('(QUEUE_TRAIN_TREE_MISMATCH)');
|
||||
expect(line(mismatch.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(new RegExp(`^QUEUE_TRAIN_FROZEN: train \\S+ merged #1; main ${broken.slice(0, 12)} tree [0-9a-f]{12}; backstop dispatched run \\d+ \\(nonce gate\\.backstop-`));
|
||||
const backstop = dispatches(fx, 'evals.yml').at(-1)!;
|
||||
expect([backstop.ref, (backstop.inputs as any).expected_sha, (backstop.inputs as any).evals_all]).toEqual(['main', broken, 'true']);
|
||||
const freezeFile = path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`);
|
||||
expect(JSON.parse(fs.readFileSync(freezeFile, 'utf8'))).toMatchObject({ kind: 'freeze', merged: ['1'], unmerged: [{ pr: '2', head: h2 }], cleared_at: null });
|
||||
|
||||
const h3 = openPr(fx, '3');
|
||||
readyReceipt(fx, '3', h3);
|
||||
const ordinary = queue(fx, ['train', 'build', '--prs', `3@${h3}`, '--urgent']);
|
||||
expect(ordinary.status).toBe(EXIT.refused);
|
||||
expect(ordinary.err).toContain('(QUEUE_TRAIN_FROZEN)');
|
||||
expect(next(ordinary.out)).toBe('NEXT: gstack-ship-queue train build --repair --prs <repair-pr>@<sha>');
|
||||
const fresh = path.join(fx.repo.root, 'fresh-state');
|
||||
expect(queue(fx, ['train', 'status'], { GSTACK_STATE_ROOT: fresh }, coord).out).toMatch(/^QUEUE_TRAIN_FROZEN: train /m);
|
||||
|
||||
const repair = queue(fx, ['train', 'build', '--repair', '--prs', `3@${h3}`]);
|
||||
expect(repair.status).toBe(EXIT.ok);
|
||||
const rn = nonceOf(repair.out);
|
||||
expect(trainJson(fx, rn)).toMatchObject({ repair: true, base: { sha: broken } });
|
||||
expect(queue(fx, ['train', 'verdict', '--train', rn]).status).toBe(EXIT.ok);
|
||||
expect(v('2').err).toContain('(QUEUE_TRAIN_FROZEN)');
|
||||
expect(dispatches(fx, 'evals.yml').filter(d => d.ref === 'main').length).toBe(1);
|
||||
expect(line(v('3', rn).out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h3}`);
|
||||
publishMain(fx, trainJson(fx, rn).prefixes[1].commit, '1.2.6.0');
|
||||
const cleared = v('3', rn);
|
||||
expect(cleared.status).toBe(EXIT.ok);
|
||||
expect(cleared.out).toMatch(/^FREEZE: cleared \(repair #3 via train \S+; main [0-9a-f]{12} carries a green record\)$/m);
|
||||
expect(next(cleared.out)).toBe(`NEXT: gstack-ship-queue train build --prs 2@${h2}`);
|
||||
expect(JSON.parse(fs.readFileSync(freezeFile, 'utf8')).cleared_at).toBe('2026-10-18T12:00:00.000Z');
|
||||
expect(queue(fx, ['train', 'status']).out).not.toContain('QUEUE_TRAIN_FROZEN');
|
||||
}, 300_000);
|
||||
test("rule 22: verify --train binds the receipt to the pinned head when the current head is its stamp commit; a receipt for another head refuses the slot and merges nothing", () => {
|
||||
const fx = make();
|
||||
const { h1, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = () => queue(fx, ['verify', '--pr', '1', '--train', nonce], {}, coord);
|
||||
const { repo } = fx;
|
||||
repo.git('checkout', '-q', '-B', 'lane1', h1);
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.4.0\n');
|
||||
repo.git('commit', '-qam', 'v1.2.4.0 stamp');
|
||||
const stamped = repo.git('rev-parse', 'HEAD');
|
||||
repo.git('push', '-q', '-f', 'origin', `${stamped}:refs/pull/1/head`);
|
||||
const ok = v();
|
||||
expect(ok.status).toBe(EXIT.ok);
|
||||
expect(ok.out).toContain(`head: ${stamped} (same modulo stamps (1 stamp file(s)))`);
|
||||
expect(ok.out).toContain(`SHIP_RECEIPT: pr=1 head=${h1.slice(0, 12)} version=- base=main (binds the pinned head)`);
|
||||
expect(line(ok.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${stamped}`);
|
||||
setPrBody(fx, '1', shippedBody('1', 'b'.repeat(40)));
|
||||
const stale = v();
|
||||
expect(stale.status).toBe(EXIT.refused);
|
||||
expect(stale.err).toMatch(new RegExp(`PR #1's ship receipt is for bbbbbbbbbbbb, not the head ${h1.slice(0, 12)} or ${stamped.slice(0, 12)} being merged.*\\(QUEUE_RECEIPT_STALE\\)`));
|
||||
expect(stale.out).not.toContain('MERGE_CONDITION:');
|
||||
expect(next(stale.out)).toBe("NEXT: #1's lane runs /ship and READYs again; then gstack-ship-queue train build --prs <pins>");
|
||||
expect(trainJson(fx, nonce).merged).toEqual([]);
|
||||
setPrBody(fx, '1', '');
|
||||
expect(v().err).toContain('(QUEUE_RECEIPT_MISSING)');
|
||||
setPrBody(fx, '1', '```gstack-ship-receipt\n{"schema_version":1}\n```\n');
|
||||
const invalid = v();
|
||||
expect(invalid.err).toMatch(/PR #1's ship receipt is invalid \(.*\).*\(QUEUE_RECEIPT_MISSING\)/);
|
||||
expect(invalid.out).not.toContain('MERGE_CONDITION:');
|
||||
setPrBody(fx, '1', shippedBody('2', h1));
|
||||
const otherPr = v();
|
||||
expect(otherPr.err).toMatch(/PR #1's ship receipt names pr=2, not this PR.*\(QUEUE_RECEIPT_STALE\)/);
|
||||
expect(otherPr.out).not.toContain('MERGE_CONDITION:');
|
||||
expect(trainJson(fx, nonce).merged).toEqual([]);
|
||||
setPrBody(fx, '1', shippedBody('1', stamped));
|
||||
expect(v().out).toContain(`SHIP_RECEIPT: pr=1 head=${stamped.slice(0, 12)} version=- base=main (binds the current head)`);
|
||||
const saved = fx.read().prs['1'];
|
||||
fx.write(d => { delete d.prs['1']; });
|
||||
const unreadable = v();
|
||||
expect(unreadable.status).toBe(EXIT.refused);
|
||||
expect(unreadable.err).toContain('(QUEUE_PROOF_MISSING)');
|
||||
expect(unreadable.out).not.toContain('MERGE_CONDITION:');
|
||||
fx.write(d => { d.prs['1'] = saved; });
|
||||
expect(trainJson(fx, nonce).merged).toEqual([]);
|
||||
}, 300_000);
|
||||
|
||||
test('from slot 2 on, a head that merges main into the pin verifies when its tree is the slot\'s prefix modulo stamps', () => {
|
||||
const fx = make();
|
||||
const { h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
|
||||
const { repo } = fx;
|
||||
const laneHead = (extra?: { file: string; text: string }) => {
|
||||
repo.git('reset', '-q', '--hard');
|
||||
repo.git('checkout', '-q', '-B', 'lane2', h2);
|
||||
repo.git('rm', '-rq', '.');
|
||||
repo.git('checkout', t.prefixes[2].commit, '--', '.');
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.5.0\n');
|
||||
if (extra) fs.writeFileSync(path.join(repo.work, extra.file), extra.text);
|
||||
repo.git('add', '-A');
|
||||
const tree = repo.git('write-tree');
|
||||
const head = repo.git('commit-tree', tree, '-p', h2, '-p', main1, '-m', 'merge main into #2, stamp 1.2.5.0');
|
||||
repo.git('push', '-q', '-f', 'origin', `${head}:refs/pull/2/head`);
|
||||
return head;
|
||||
};
|
||||
|
||||
const merged = laneHead();
|
||||
const ok = v('2');
|
||||
expect(ok.status).toBe(EXIT.ok);
|
||||
expect(ok.out).toMatch(new RegExp(`^head: ${merged} \\(T2 with main merged in, same modulo stamps`, 'm'));
|
||||
expect(line(ok.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${merged}`);
|
||||
|
||||
const stray = laneHead({ file: 'stray.txt', text: 'not in the train\n' });
|
||||
const moved = v('2');
|
||||
expect(moved.status).toBe(EXIT.fail);
|
||||
expect(moved.err).toMatch(new RegExp(`#2 moved past its pinned head ${h2.slice(0, 12)} and is not T2 modulo stamps \\(${stray.slice(0, 12)}: .*\\(QUEUE_TRAIN_MOVED\\)`));
|
||||
}, 300_000);
|
||||
|
||||
test("GSTA-67 (#3345 at 593e61c): a merged-in head whose CHANGELOG was resolved by hand verifies even where T<i>'s mechanical CHANGELOG differs; an invented line or a head without main is still refused", () => {
|
||||
const fx = make();
|
||||
const h1 = openPr(fx, '1', { changelog: false });
|
||||
const h2 = openPr(fx, '2', { changelog: cl => cl.replace('# Changelog\n', '# Changelog\n\n## [Unreleased]\n\n- #2 change\n').replace('## [1.2.2.0] - 2026-09-01\n\n', '') });
|
||||
readyReceipt(fx, '1', h1);
|
||||
readyReceipt(fx, '2', h2);
|
||||
fx.write(d => { d.rules['evals.yml'] = GREEN_GATE; });
|
||||
const nonce = nonceOf(queue(fx, ['train', 'build', '--prs', `1@${h1},2@${h2}`]).out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
expect(fx.repo.git('show', `${t.prefixes[2].commit}:CHANGELOG.md`)).not.toContain('## [1.2.2.0]');
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = () => queue(fx, ['verify', '--pr', '2', '--train', nonce], {}, coord);
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
const { repo } = fx;
|
||||
const laneHead = (entry: string, parents: string[]) => {
|
||||
repo.git('reset', '-q', '--hard');
|
||||
repo.git('checkout', '-q', '-B', 'lane2', h2);
|
||||
repo.git('rm', '-rq', '.');
|
||||
repo.git('checkout', t.prefixes[2].commit, '--', '.');
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.5.0\n');
|
||||
fs.writeFileSync(path.join(repo.work, 'CHANGELOG.md'), repo.git('show', `${main1}:CHANGELOG.md`).replace('# Changelog\n', `# Changelog\n\n## [1.2.5.0] - 2026-10-18\n\n${entry}\n`) + '\n');
|
||||
repo.git('add', '-A');
|
||||
const head = repo.git('commit-tree', repo.git('write-tree'), ...parents.flatMap(p => ['-p', p]), '-m', 'merge main into #2 (CHANGELOG by hand), stamp 1.2.5.0');
|
||||
repo.git('push', '-q', '-f', 'origin', `${head}:refs/pull/2/head`);
|
||||
return head;
|
||||
};
|
||||
|
||||
const byHand = laneHead('- #2 change', [h2, main1]);
|
||||
const ok = v();
|
||||
expect(ok.status).toBe(EXIT.ok);
|
||||
expect(ok.out).toContain(`head: ${byHand} (T2 with main merged in, same modulo stamps (1 stamp file(s)) except CHANGELOG.md, resolved as main's CHANGELOG.md plus #2's own entry)`);
|
||||
expect(line(ok.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${byHand}`);
|
||||
|
||||
const invented = laneHead('- #2 change\n- added after the gate', [h2, main1]);
|
||||
const refused = v();
|
||||
expect(refused.status).toBe(EXIT.fail);
|
||||
expect(refused.err).toContain(`#2 moved past its pinned head ${h2.slice(0, 12)} and is not T2 modulo stamps (${invented.slice(0, 12)}: differs from T2 in CHANGELOG.md, which is not main's plus #2's own entry: the PR's entry holds a line its pin never added: "- added after the gate"; against the pin it differs: `);
|
||||
expect(refused.err).toContain('(QUEUE_TRAIN_MOVED)');
|
||||
|
||||
const orphan = laneHead('- #2 change', [h2]);
|
||||
const noMain = v();
|
||||
expect(noMain.status).toBe(EXIT.fail);
|
||||
expect(noMain.err).toContain(`(${orphan.slice(0, 12)}: does not contain main ${main1.slice(0, 12)}; against the pin it differs: `);
|
||||
}, 300_000);
|
||||
// fails_when=the post-merge verify of a merged-in head the pre-merge verify accepted freezes the queue because T<i>'s single [Unreleased] became two released sections, or the pre-merge verify refuses the correction bullet mergeChangelogs itself wrote; why_new=the GSTA-67 test above never publishes the accepted head and never stacks a child on a released parent; seam=none (real git, the fixture's gh); no_claim=what the squash commit's message says
|
||||
test("train 24 (GSTA-96): a stacked child's head the pre-merge verify accepted confirms after its squash merge under the same CHANGELOG rule, corrections to the released parent included", () => {
|
||||
const fx = make();
|
||||
const { repo } = fx;
|
||||
const h1 = openPr(fx, '1', { changelog: cl => cl.replace('# Changelog\n', '# Changelog\n\n## [Unreleased]\n\n**Parent entry of #1.**\n\n### Changed\n- #1 change, the first wording\n- #1 second bullet, unchanged\n') });
|
||||
const h2 = openPr(fx, '2', { from: 'pr-1', changelog: cl => cl.replace('## [Unreleased]\n\n**Parent entry of #1.**', '## [Unreleased]\n\n**Child entry of #2.**\n\n### Changed\n- #2 change\n\n**Parent entry of #1.**').replace('- #1 change, the first wording', '- #1 change, the better wording') });
|
||||
readyReceipt(fx, '1', h1);
|
||||
readyReceipt(fx, '2', h2);
|
||||
fx.write(d => { d.rules['evals.yml'] = GREEN_GATE; });
|
||||
const nonce = nonceOf(queue(fx, ['train', 'build', '--prs', `1@${h1},2@${h2}`]).out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
expect(parseChangelog(repo.git('show', `${t.prefixes[2].commit}:CHANGELOG.md`)).sections.map(s => s.version ?? 'Unreleased')).toEqual(['Unreleased', '1.2.3.0', '1.2.2.0']);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
|
||||
// Slot 1: #1 squash-merges and is released as 1.2.4.0 (its [Unreleased] re-headed).
|
||||
expect(line(v('1').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h1}`);
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: repo.git('show', `${t.prefixes[1].commit}:CHANGELOG.md`).replace('## [Unreleased]', '## [1.2.4.0] - 2026-10-18') + '\n' });
|
||||
expect(v('1').out).toContain(`VERIFY_TRAIN: #1 merged; main's tree is T1 of train ${nonce} (1/2 merged)`);
|
||||
|
||||
// Slot 2: the lane merges main into its pin; mergeChangelogs carries the child past its released parent.
|
||||
const merged = mergeChangelogs(repo.git('show', `${h2}:CHANGELOG.md`) + '\n', repo.git('show', `${main1}:CHANGELOG.md`) + '\n', repo.git('show', `${h1}:CHANGELOG.md`) + '\n')!;
|
||||
expect(merged).toContain('- Correction to the 1.2.4.0 entry below: "first" should read "better".');
|
||||
repo.git('reset', '-q', '--hard');
|
||||
repo.git('checkout', '-q', '-B', 'lane2', h2);
|
||||
repo.git('rm', '-rq', '.');
|
||||
repo.git('checkout', t.prefixes[2].commit, '--', '.');
|
||||
fs.writeFileSync(path.join(repo.work, 'VERSION'), '1.2.5.0\n');
|
||||
fs.writeFileSync(path.join(repo.work, 'CHANGELOG.md'), merged.replace('## [Unreleased]', '## [1.2.5.0] - 2026-10-18'));
|
||||
repo.git('add', '-A');
|
||||
const laneHead = repo.git('commit-tree', repo.git('write-tree'), '-p', h2, '-p', main1, '-m', 'merge main into #2, stamp 1.2.5.0');
|
||||
repo.git('push', '-q', '-f', 'origin', `${laneHead}:refs/pull/2/head`);
|
||||
repo.git('reset', '-q', '--hard');
|
||||
const pre = v('2');
|
||||
expect([pre.status, pre.err]).toEqual([EXIT.ok, '']);
|
||||
expect(pre.out).toContain(`head: ${laneHead} (T2 with main merged in, same modulo stamps (1 stamp file(s)) except CHANGELOG.md, resolved as main's CHANGELOG.md plus #2's own entry)`);
|
||||
expect(line(pre.out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${laneHead}`);
|
||||
|
||||
// The squash merge publishes exactly that tree; the post-merge verify confirms it instead of freezing the queue.
|
||||
const main2 = publishMain(fx, laneHead, '1.2.5.0');
|
||||
expect(repo.git('rev-parse', `${main2}^{tree}`)).toBe(repo.git('rev-parse', `${laneHead}^{tree}`));
|
||||
const post = v('2');
|
||||
expect([post.status, post.err]).toEqual([EXIT.ok, '']);
|
||||
expect(line(post.out, 'main:')).toBe(`main: ${main2} = T2 (same modulo stamps (1 stamp file(s)) except CHANGELOG.md, main ${main1.slice(0, 12)}'s CHANGELOG.md plus #2's own entry)`);
|
||||
expect(post.out).toContain(`VERIFY_TRAIN: #2 merged; main's tree is T2 of train ${nonce} (2/2 merged)`);
|
||||
expect(queue(fx, ['train', 'status']).out).not.toContain('QUEUE_TRAIN_FROZEN');
|
||||
}, 300_000);
|
||||
|
||||
// fails_when=a freeze lists a PR GitHub reports MERGED as unmerged (train 24's freeze named #3453), or a post-merge CHANGELOG with a line the pin never wrote confirms; why_new=the freeze test above merges nothing of the slot it freezes on; seam=the fixture's gh pr view state; no_claim=the backstop's outcome
|
||||
test('a post-merge CHANGELOG beyond the rule still freezes, and the freeze lists the slot GitHub reports MERGED as merged, not unmerged', () => {
|
||||
const fx = make();
|
||||
const { h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const released = (prefix: string, version: string) => fx.repo.git('show', `${prefix}:CHANGELOG.md`).replace('## [Unreleased]', `## [${version}] - 2026-10-18`) + '\n';
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: released(t.prefixes[1].commit, '1.2.4.0') });
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
expect(line(v('2').out, 'MERGE_CONDITION:')).toBe(`MERGE_CONDITION: sha=${h2}`);
|
||||
// Main's CHANGELOG plus #2's stamped entry, with one line the pin never wrote.
|
||||
const smuggled = fx.repo.git('show', `${main1}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.5.0] - 2026-10-18\n\n- #2 change\n- added after the gate\n') + '\n';
|
||||
const broken = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'CHANGELOG.md', text: smuggled });
|
||||
fx.write(d => { (d.prs['2'] as any).state = 'MERGED'; });
|
||||
const frozen = v('2');
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(frozen.err).toContain(`main ${broken.slice(0, 12)} is neither T1 nor T2 modulo stamps (vs T2: differs: CHANGELOG.md, which is not main ${main1.slice(0, 12)}'s plus #2's own entry: the PR's entry holds a line its pin never added: "- added after the gate")`);
|
||||
expect(line(frozen.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1,#2; main /);
|
||||
expect(line(frozen.out, 'freeze:')).toMatch(/; #2 merged on GitHub without a verified tree; unmerged \(none\); repair none admitted$/);
|
||||
const freezeFile = path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`);
|
||||
expect(JSON.parse(fs.readFileSync(freezeFile, 'utf8'))).toMatchObject({ merged: ['1', '2'], unmerged: [] });
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=a first slot GitHub reports MERGED whose squash fails the post-merge check freezes the queue, and a GitHub state that cannot be read refuses instead of reading as not merged; fails_when=stopped() reads an empty merged list, or an unreadable gh answer, as "nothing merged" while main already holds the unverified squash (review of GSTA-129, passes 1 and 2); why_new=the test above freezes on slot 2 with slot 1 verified; seam=the fixture's gh pr view state; no_claim=the backstop's outcome
|
||||
test("slot 1 merged on GitHub but not confirmed: an unreadable GitHub state refuses, and a MERGED one freezes with #1 merged and #2 unmerged instead of saying nothing merged", () => {
|
||||
const fx = make();
|
||||
const { h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const smuggled = fx.repo.git('show', `${t.prefixes[0].commit}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.4.0] - 2026-10-18\n\n- #1 change\n- added after the gate\n') + '\n';
|
||||
const broken = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: smuggled });
|
||||
// While GitHub's answer for #1 cannot be read, the verify neither freezes nor says "nothing merged": it refuses and asks to be rerun.
|
||||
const row = fx.read().prs['1'] as any;
|
||||
fx.write(d => { delete d.prs['1']; });
|
||||
const unreadable = v('1');
|
||||
expect(unreadable.status).toBe(EXIT.refused);
|
||||
expect(unreadable.err).toContain(`main ${broken.slice(0, 12)} is neither T0 nor T1 modulo stamps`);
|
||||
expect(unreadable.err).toMatch(/; whether #1 merged on GitHub could not be read, so whether the queue must freeze is unknown; .*\(QUEUE_PROOF_MISSING\)/);
|
||||
expect(unreadable.out).toContain(`NEXT: gstack-ship-queue verify --pr 1 --train ${nonce} (once gh pr view answers)`);
|
||||
expect(fs.existsSync(path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`))).toBe(false);
|
||||
fx.write(d => { d.prs['1'] = { ...row, state: 'MERGED' }; });
|
||||
const frozen = v('1');
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(frozen.err).toContain(`main ${broken.slice(0, 12)} is neither T0 nor T1 modulo stamps`);
|
||||
expect(frozen.err).toContain('"- added after the gate"); the queue is frozen;');
|
||||
expect(line(frozen.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1; main /);
|
||||
expect(line(frozen.out, 'freeze:')).toMatch(/; #1 merged on GitHub without a verified tree; unmerged #2; repair none admitted$/);
|
||||
expect(JSON.parse(fs.readFileSync(path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`), 'utf8'))).toMatchObject({ merged: ['1'], unmerged: [{ pr: '2', head: h2 }] });
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=the freeze record is built from the same GitHub read that decided to freeze, so a slot that read MERGED stays merged even when GitHub stops answering a moment later; fails_when=freezeQueue reads GitHub again and files anything but an exact MERGED under unmerged (the misfile that listed train 24's merged #3453 as unmerged, GSTA-129 defect 1); why_new=the test above holds GitHub's answer fixed across the verify; seam=the fixture's gh pr view vanishing after one answer; no_claim=the backstop's outcome
|
||||
test("a slot that read MERGED when the verify decided to freeze is recorded as merged even when GitHub stops answering before the record is written", () => {
|
||||
const fx = make();
|
||||
const { h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const smuggled = fx.repo.git('show', `${t.prefixes[0].commit}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.4.0] - 2026-10-18\n\n- #1 change\n- added after the gate\n') + '\n';
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: smuggled });
|
||||
fx.write(d => { (d.prs['1'] as any).state = 'MERGED'; d.vanish = { '1': 1 }; });
|
||||
const frozen = queue(fx, ['verify', '--pr', '1', '--train', nonce], {}, coord);
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(frozen.err).toContain('"- added after the gate"); the queue is frozen;');
|
||||
expect(fx.read().vanish).toEqual({ '1': 0 });
|
||||
expect(line(frozen.out, 'freeze:')).toMatch(/; #1 merged on GitHub without a verified tree; unmerged #2; repair none admitted$/);
|
||||
expect(JSON.parse(fs.readFileSync(path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`), 'utf8'))).toMatchObject({ merged: ['1'], unmerged: [{ pr: '2', head: h2 }] });
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=a slot unreadable on GitHub beside a merged one is left out of unmerged and named in the reason, so the rebuild after the repair never seats a PR that may already be in; fails_when=freezeQueue files an unreadable slot under unmerged, or drops it without naming it; why_new=the test above keeps slot 2 readable; seam=the fixture's gh pr view vanishing for slot 2; no_claim=the backstop's outcome
|
||||
test("a slot unreadable on GitHub beside a merged one is left out of unmerged, recorded as unreadable and named by the NEXT after the repair", () => {
|
||||
const fx = make();
|
||||
const { h2, nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const smuggled = fx.repo.git('show', `${t.prefixes[0].commit}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.4.0] - 2026-10-18\n\n- #1 change\n- added after the gate\n') + '\n';
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: smuggled });
|
||||
fx.write(d => { (d.prs['1'] as any).state = 'MERGED'; d.vanish = { '2': 0 }; });
|
||||
const frozen = queue(fx, ['verify', '--pr', '1', '--train', nonce], {}, coord);
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(line(frozen.out, 'freeze:')).toMatch(/; #1 merged on GitHub without a verified tree; #2 unreadable on GitHub, left out of unmerged; seat it in a train by hand once gh pr view answers; unmerged \(none\); repair none admitted$/);
|
||||
expect(JSON.parse(fs.readFileSync(path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`), 'utf8'))).toMatchObject({ merged: ['1'], unmerged: [], unreadable: [{ pr: '2', head: h2 }] });
|
||||
expect(line(frozen.out, 'unreadable:')).toBe(`unreadable: #2@${h2.slice(0, 12)} (GitHub did not answer at the freeze; neither merged nor unmerged)`);
|
||||
// The repair clears the freeze, and the NEXT names the unreadable slot instead of omitting it (#3519 b).
|
||||
const h3 = openPr(fx, '3');
|
||||
readyReceipt(fx, '3', h3);
|
||||
const rn = nonceOf(queue(fx, ['train', 'build', '--repair', '--prs', `3@${h3}`]).out);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', rn]).status).toBe(EXIT.ok);
|
||||
publishMain(fx, trainJson(fx, rn).prefixes[1].commit, '1.2.6.0');
|
||||
const cleared = queue(fx, ['verify', '--pr', '3', '--train', rn], {}, coord);
|
||||
expect(cleared.out).toMatch(/^FREEZE: cleared /m);
|
||||
expect(next(cleared.out)).toBe(`NEXT: gh pr view 2 --json state,headRefOid (unreadable at the freeze: #2@${h2.slice(0, 12)}); seat each that is OPEN in a train`);
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=verify on a train whose every slot already merged, against a main another train verified, refuses as stale instead of freezing the queue and dispatching a backstop (#3519 c: train 24's record froze the queue at 9ccb5233, T1 of verified train 28, run 40586582766); fails_when=stopped() freezes when every slot merged and main's sha is another train's verified prefix, or refuses without that proof; why_new=every freeze test above has an unmerged or unverified main; seam=a second train record written into the state root; no_claim=what prune --stale then does (covered by the prune tests)
|
||||
test("verify on a train whose every slot merged, against a main another train verified, refuses as stale and freezes nothing", () => {
|
||||
const fx = make();
|
||||
const { nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
const later = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'stray.txt', text: 'a later train\n' });
|
||||
fx.write(d => { (d.prs['2'] as any).state = 'MERGED'; });
|
||||
const freezeFile = path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`);
|
||||
const tree = fx.repo.git('rev-parse', `${later}^{tree}`);
|
||||
const otherNonce = `${nonce}-later`;
|
||||
const other = { ...t, nonce: otherNonce, state: 'merging', prefixes: [t.prefixes[0], { index: 1, commit: later, tree, pr: '9' }], merged: [{ pr: '9', sha: later, tree, at: '2026-10-18T13:00:00.000Z' }] };
|
||||
fs.mkdirSync(path.join(fx.state, 'ship-queue', 'trains', otherNonce), { recursive: true });
|
||||
fs.writeFileSync(path.join(fx.state, 'ship-queue', 'trains', otherNonce, 'train.json'), JSON.stringify(other));
|
||||
const stale = v('2');
|
||||
expect(stale.status).toBe(EXIT.refused);
|
||||
expect(stale.err).toContain(`every slot of train ${nonce} merged on GitHub and main ${later.slice(0, 12)} is T1 of train ${otherNonce} (#9, verified at 2026-10-18T13:00:00.000Z), so this record is stale and the queue is not frozen`);
|
||||
expect(stale.err).toContain('(QUEUE_TRAIN_STALE)');
|
||||
expect(next(stale.out)).toBe(`NEXT: gstack-ship-queue train prune --stale --train ${nonce}`);
|
||||
expect(fs.existsSync(freezeFile)).toBe(false);
|
||||
expect(dispatches(fx, 'evals.yml').filter(d => d.ref === 'main').length).toBe(0);
|
||||
// Without another train's verified record for this main, the same mismatch still freezes.
|
||||
fs.rmSync(path.join(fx.state, 'ship-queue', 'trains', otherNonce), { recursive: true });
|
||||
const frozen = v('2');
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(line(frozen.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1,#2; main /);
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=a train with a slot still OPEN on GitHub freezes on a mismatch even when main's sha is another train's verified prefix; fails_when=the every-slot-merged guard before verifiedElsewhere is dropped or weakened, so a live train refuses as stale and skips the freeze; why_new=the test above only covers an all-merged train; seam=none; no_claim=prune behavior
|
||||
test("a train with a slot still open freezes on the mismatch even when another train verified main's sha", () => {
|
||||
const fx = make();
|
||||
const { nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
publishMain(fx, t.prefixes[1].commit, '1.2.4.0');
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
const later = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'stray.txt', text: 'a later train\n' });
|
||||
const tree = fx.repo.git('rev-parse', `${later}^{tree}`);
|
||||
const otherNonce = `${nonce}-later`;
|
||||
const other = { ...t, nonce: otherNonce, state: 'merging', prefixes: [t.prefixes[0], { index: 1, commit: later, tree, pr: '9' }], merged: [{ pr: '9', sha: later, tree, at: '2026-10-18T13:00:00.000Z' }] };
|
||||
fs.mkdirSync(path.join(fx.state, 'ship-queue', 'trains', otherNonce), { recursive: true });
|
||||
fs.writeFileSync(path.join(fx.state, 'ship-queue', 'trains', otherNonce, 'train.json'), JSON.stringify(other));
|
||||
const partial = v('2');
|
||||
expect(partial.status).toBe(EXIT.fail);
|
||||
expect(partial.err).not.toContain('(QUEUE_TRAIN_STALE)');
|
||||
expect(line(partial.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1; main /);
|
||||
expect(fs.existsSync(path.join(fx.state, 'ship-queue', 'freeze', `${repoKey(fx)}.json`))).toBe(true);
|
||||
}, 300_000);
|
||||
|
||||
// Value: protects=a post-merge CHANGELOG difference is excused only when main's parent is T<i-1> modulo stamps, so a foreign commit between the verified head and the squash freezes; fails_when=published() skips or inverts the parent check; why_new=the two tests above reach the CHANGELOG rule only with a parent that is T1 modulo stamps; seam=none; no_claim=a parent differing from T1 in the CHANGELOG alone
|
||||
test("a post-merge CHANGELOG difference is not excused when main's parent is not the verified prefix modulo stamps: the queue freezes naming the parent", () => {
|
||||
const fx = make();
|
||||
const { nonce } = twoPrTrain(fx);
|
||||
expect(queue(fx, ['train', 'verdict', '--train', nonce]).status).toBe(EXIT.ok);
|
||||
const t = trainJson(fx, nonce);
|
||||
const coord = coordinatorClone(fx.repo);
|
||||
const v = (pr: string) => queue(fx, ['verify', '--pr', pr, '--train', nonce], {}, coord);
|
||||
const released = fx.repo.git('show', `${t.prefixes[1].commit}:CHANGELOG.md`).replace('## [Unreleased]', '## [1.2.4.0] - 2026-10-18') + '\n';
|
||||
const main1 = publishMain(fx, t.prefixes[1].commit, '1.2.4.0', { file: 'CHANGELOG.md', text: released });
|
||||
expect(v('1').status).toBe(EXIT.ok);
|
||||
const foreign = publishMain(fx, t.prefixes[1].commit, '1.2.4.1', { file: 'stray.txt', text: 'landed between the two slots\n' });
|
||||
const text = fx.repo.git('show', `${main1}:CHANGELOG.md`).replace('# Changelog\n', '# Changelog\n\n## [1.2.5.0] - 2026-10-18\n\n- #2 change\n- added after the gate\n') + '\n';
|
||||
const main2 = publishMain(fx, t.prefixes[2].commit, '1.2.5.0', { file: 'CHANGELOG.md', text });
|
||||
expect(fx.repo.git('rev-parse', `${main2}^`)).toBe(foreign);
|
||||
const frozen = v('2');
|
||||
expect(frozen.status).toBe(EXIT.fail);
|
||||
expect(frozen.err).toContain(`main ${main2.slice(0, 12)} is neither T1 nor T2 modulo stamps`);
|
||||
expect(frozen.err).toContain(`main's parent ${foreign.slice(0, 12)} is not T1 modulo stamps`);
|
||||
expect(line(frozen.out, 'QUEUE_TRAIN_FROZEN:')).toMatch(/^QUEUE_TRAIN_FROZEN: train \S+ merged #1; main /);
|
||||
}, 300_000);
|
||||
});
|
||||
@@ -56,6 +56,7 @@ const BASELINE = [
|
||||
'test/ceo-split-question-policy.test.ts',
|
||||
'test/ceo-stale-fill-decision.test.ts', // replays census reports against the paid CEO section-loading case's structured checker
|
||||
'test/changed-files-union.test.ts',
|
||||
'test/claude-overlay-setup-installs.test.ts', // GSTA-151: its bin/gstack-skill-start assertion moved to test/claude-overlay-setup-project.test.ts in the shard-time split; the remaining cases still run the real ./setup through test/helpers/install-fixture.ts
|
||||
'test/claude-provider-keychain.test.ts',
|
||||
'test/codex-carve-fixture.test.ts',
|
||||
'test/codex-eval-recording.test.ts',
|
||||
@@ -83,6 +84,8 @@ const BASELINE = [
|
||||
'test/docsync-atomic-writes.test.ts', // landed in v1.91.7.0 before this ratchet: harness owner for its functional-QA/docsync paid evals
|
||||
'test/docsync-child-marker.test.ts', // replays a PR-lane capture against the paid ship-docsync case's child-marker check
|
||||
'test/docsync-command-grammar.test.ts', // landed in v1.91.7.0 before this ratchet: harness owner for its functional-QA/docsync paid evals
|
||||
'test/docsync-fault-interface-faults.test.ts', // GSTA-151: split from test/docsync-fault-interface.test.ts for shard time; replays the fault-control callbacks through the generated child
|
||||
'test/docsync-fault-interface-legacy.test.ts', // GSTA-151: split from test/docsync-fault-interface.test.ts for shard time; replays the legacy-control callbacks through the generated child
|
||||
'test/docsync-nested-writes.test.ts', // landed in v1.91.7.0 before this ratchet: harness owner for its functional-QA/docsync paid evals
|
||||
'test/dx-selected-navigation-ap.test.ts',
|
||||
'test/eng-batching-current-ledger.test.ts',
|
||||
@@ -124,6 +127,7 @@ const BASELINE = [
|
||||
'test/helpers/session-runner.test.ts',
|
||||
'test/helpers/sync-command-capture.test.ts',
|
||||
'test/hooks-windows-paths.test.ts',
|
||||
'test/host-renders-prune-shared-root.test.ts', // GSTA-151: split from test/host-renders-prune.test.ts for shard time; runs the real ./setup prune through test/helpers/install-fixture.ts
|
||||
'test/ios-debug-bridge-release-guard.test.ts',
|
||||
'test/ios-qa-stateserver-hardening.test.ts',
|
||||
'test/ios-qa-swift-build.test.ts',
|
||||
@@ -208,10 +212,13 @@ const BASELINE = [
|
||||
'test/session-runner-timeout.test.ts',
|
||||
'test/setup-browser-hint.test.ts',
|
||||
'test/setup-bun-cmd-and-pipe-bugs.test.ts',
|
||||
'test/setup-codex-scope-runtime-links.test.ts', // GSTA-151: split from test/setup-codex-scope-review-boundaries.test.ts for shard time; runs the real ./setup through test/helpers/install-fixture.ts
|
||||
'test/setup-conductor-worktree.test.ts',
|
||||
'test/setup-playwright-platform.test.ts',
|
||||
'test/setup-sections-linking.test.ts',
|
||||
'test/shared-libs-cancellation.test.ts', // landed in v1.91.7.0 before this ratchet: harness owner for its functional-QA/docsync paid evals
|
||||
'test/shared-libs-checker-interface-evidence-declared.test.ts', // GSTA-151: split from test/shared-libs-checker-interface-evidence.test.ts for shard time; same cases, slices the same paid source
|
||||
'test/shared-libs-checker-interface-evidence-replays.test.ts', // GSTA-151: split from test/shared-libs-checker-interface-evidence.test.ts for shard time; same cases
|
||||
'test/shared-libs-checker-interface-evidence.test.ts', // slices test/skill-e2e-shared-libs.test.ts source (recorded 2026-10 when the ratchet learned paid-source slicing)
|
||||
'test/shared-libs-fixture.test.ts', // slices test/skill-e2e-shared-libs-periodic.test.ts source (recorded 2026-10 when the ratchet learned paid-source slicing)
|
||||
'test/shared-libs-plan-actor.test.ts',
|
||||
|
||||
@@ -20,7 +20,7 @@ const native = load('native-qualification.yml');
|
||||
* intentionally excluded Windows-safe tests, lower this floor to the printed
|
||||
* count in the same PR and say why; when the count grows, raise it.
|
||||
*/
|
||||
const WINDOWS_CURATED_FLOOR = 638;
|
||||
const WINDOWS_CURATED_FLOOR = 795;
|
||||
|
||||
test('the Windows lane plans, runs one strict shard per job and verifies every result', () => {
|
||||
expect(Object.keys(windows.on).sort()).toEqual(['pull_request', 'push', 'workflow_call', 'workflow_dispatch']);
|
||||
|
||||
Reference in new issue
Block a user