mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 08:31:44 +01:00
v1.91.300.0 stamp #3543 (train 40 slot 2)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
commit
6f6944012c
52 files changed
+1054
-4939
No files matched your search
@@ -4,7 +4,7 @@
|
||||
* every choice rec takes shown in words, gate ids only on the agent line, the
|
||||
* rec_hash binding, and the incomplete and answered states.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
@@ -13,6 +13,8 @@ import { capyRelayLine, renderCaptainBrief } from '../lib/captain-brief';
|
||||
import { parseReply, recHash, type GateList } from '../lib/gate-list';
|
||||
import { findSection, headings } from '../lib/markdown-sections';
|
||||
import { loadBriefInputs } from '../lib/owner-brief';
|
||||
import { capyRunner, phaseVia, readRunJson, writePlan } from './helpers/autoplan-capy';
|
||||
import { SMALL_PLAN } from './helpers/autoplan-run-fixture';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const dirs: string[] = [];
|
||||
@@ -151,3 +153,89 @@ describe('gstack-owner-brief render --captain', () => {
|
||||
expect(capyRelayLine('/r', {})).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('carried decisions at a cap gate (#3546)', () => {
|
||||
const r = capyRunner();
|
||||
afterAll(() => r.cleanup());
|
||||
const SECTIONS = '\n## Before → after\n\nBefore: retries hammer. After: they back off.\n\n## Why it matters\n\nOutages.\n\n## What caused this work\n\nIncident 7.\n\n## Big decisions\n\n1. Exponential backoff.\n';
|
||||
const PLAN = SMALL_PLAN + SECTIONS;
|
||||
const WORDS: Record<string, string> = { 'keep your direction': 'keep the plan as written', 'accept the change': "make the reviewer's change" };
|
||||
|
||||
function cappedRun(): string {
|
||||
const dir = path.join(r.host.base, 'carried');
|
||||
const plan = writePlan(dir, PLAN);
|
||||
const out = path.join(dir, 'run');
|
||||
expect(r.ap(['next', '--out', out, '--plan', plan, '--no-ui', '--max-rounds', '1']).status).toBe(0);
|
||||
const challenge = (title: string) => ({ severity: 'Medium', title, fix: `change: ${title}`, user_challenge: true, changes: 'scope' });
|
||||
phaseVia(r, out, 'ceo', { native: [challenge('Use a queue table'), challenge('Add metrics')], outside: [challenge('Drop jitter')] });
|
||||
phaseVia(r, out, 'eng', { native: [], outside: [] });
|
||||
const ds = JSON.parse(fs.readFileSync(path.join(out, 'gate.json'), 'utf8')).items.filter((i: any) => i.id.startsWith('d'));
|
||||
expect(ds.map((i: any) => i.recommended)).toEqual(['a', 'a', 'a']);
|
||||
expect(r.ap(['answer', '--by', 'human', '--out', out, '--gate-rev', '1', '--reply', `${ds.map((i: any) => `${i.id}b`).join(' ')} p1b`]).status).toBe(0);
|
||||
const v2 = path.join(dir, 'plan-v2.md');
|
||||
fs.writeFileSync(v2, PLAN.replace('cap 30 s', 'cap 60 s, dead-letter after 8 attempts'));
|
||||
const rev = r.ap(['revise', '--out', out, '--plan', v2, '--incorporates', readRunJson(out).amendments.map((a: any) => a.decision).join(',')]);
|
||||
expect(rev.stdout).toMatch(/^REVISED: plan=[0-9a-f]{12} reopened=none capped=ceo,eng$/m);
|
||||
return out;
|
||||
}
|
||||
const cli = (bin: string, args: string[]) => spawnSync('bun', [path.join(ROOT, 'bin', bin), ...args], { encoding: 'utf8', timeout: 60_000 }).stdout ?? '';
|
||||
function renders(out: string) {
|
||||
const gate = JSON.parse(fs.readFileSync(path.join(out, 'gate.json'), 'utf8')) as GateList;
|
||||
const gateText = cli('gstack-gate', ['render', path.join(out, 'gate.json'), '--all']);
|
||||
const briefText = cli('gstack-owner-brief', ['render', '--captain', '--out', out]);
|
||||
const gateRec = JSON.parse(/\`rec\` resolves to: (\{.*\})$/m.exec(gateText)![1]!).choices as Record<string, string>;
|
||||
const briefRec = Object.fromEntries(/rec resolves to ([a-z0-9 ]+);/.exec(briefText)![1]!.split(' ').map(t => [t.slice(0, -1), t.slice(-1)]));
|
||||
return { gate, gateText, briefText, gateRec, briefRec };
|
||||
}
|
||||
let out = '';
|
||||
beforeAll(() => { out = cappedRun(); });
|
||||
|
||||
test('the Captain brief resolves rec to the carried choices, as gstack-gate render does, with the same choice labels', () => {
|
||||
const { gate, gateText, briefText, gateRec, briefRec } = renders(out);
|
||||
expect(gate.gate_rev).toBe(2);
|
||||
expect(gate.items.some(i => i.cap?.kind === 'delta')).toBe(true);
|
||||
const carried = gate.items.filter(i => i.carried);
|
||||
expect(carried.map(i => [i.recommended, i.carried!.chosen])).toEqual([['a', 'b'], ['a', 'b'], ['a', 'b']]);
|
||||
expect(briefRec).toEqual(gateRec);
|
||||
expect(Object.fromEntries(carried.map(i => [i.id, gateRec[i.id]]))).toEqual({ d1: 'b', d2: 'b', d3: 'b' });
|
||||
gate.items.filter(i => i.id !== 'p1').forEach((item, n) => {
|
||||
const text = item.options.find(o => o.key === gateRec[item.id])!.text;
|
||||
expect(gateText).toContain(` ${item.id}${gateRec[item.id]}) ${text}`);
|
||||
expect(briefText).toContain(` ${n + 1}. ${item.title.replace(/\s*\[[^\]]*\]\s*$/, '')}: ${WORDS[text] ?? text}`);
|
||||
});
|
||||
expect(briefText).toContain("Use a queue table: make the reviewer's change (your answer at gate_rev 1, carried forward).");
|
||||
expect(briefText).toContain('rec keeps the 3 you already answered and takes the recommended answer for the rest.');
|
||||
expect(briefText).toContain('Reply **rec** to keep the answers you already gave and take every other recommendation (recommended)');
|
||||
});
|
||||
|
||||
test('an answer already given at this gate is what rec keeps, as gstack-autoplan answer --reply rec records it', () => {
|
||||
const copy = path.join(r.host.base, 'prior');
|
||||
fs.cpSync(out, copy, { recursive: true });
|
||||
const partial = r.ap(['answer', '--by', 'human', '--out', copy, '--gate-rev', '2', '--reply', 'd2a']);
|
||||
expect(partial.stdout).toMatch(/^GATE_PENDING: /m);
|
||||
const { briefText, briefRec } = renders(copy);
|
||||
expect(briefRec).toMatchObject({ d1: 'b', d2: 'a', d3: 'b' });
|
||||
expect(briefText).toContain('Add metrics: keep the plan as written (a reviewer suggested changing it) (your answer at this gate).');
|
||||
const answered = r.ap(['answer', '--by', 'human', '--out', copy, '--gate-rev', '2', '--reply', 'rec']);
|
||||
expect(answered.stdout).toMatch(/^APPROVED: gate_rev=2/m);
|
||||
const recorded = fs.readFileSync(path.join(copy, 'decisions.jsonl'), 'utf8').split('\n').filter(Boolean).map(l => JSON.parse(l)).filter(d => d.gate_rev === 2);
|
||||
expect(Object.fromEntries(recorded.map(d => [d.label.toLowerCase(), d.chosen]))).toEqual(briefRec);
|
||||
});
|
||||
|
||||
test('negative control: without carried decisions (gate items and their decision rows) both resolve rec to the recommendations', () => {
|
||||
const copy = path.join(r.host.base, 'uncarried');
|
||||
fs.cpSync(out, copy, { recursive: true });
|
||||
const gate = JSON.parse(fs.readFileSync(path.join(copy, 'gate.json'), 'utf8')) as GateList;
|
||||
expect(Object.fromEntries(gate.items.map(i => [i.id, i.recommended]))).not.toEqual(renders(out).gateRec);
|
||||
for (const item of gate.items) delete item.carried;
|
||||
fs.writeFileSync(path.join(copy, 'gate.json'), JSON.stringify(gate));
|
||||
const rows = fs.readFileSync(path.join(copy, 'decisions.jsonl'), 'utf8').split('\n').filter(Boolean).map(l => JSON.parse(l));
|
||||
fs.writeFileSync(path.join(copy, 'decisions.jsonl'), rows.map(d => JSON.stringify(d.carried_from ? { ...d, status: 'pending', chosen: undefined, answered_at: undefined, reply: undefined, carried_from: undefined } : d)).join('\n') + '\n');
|
||||
const { briefText, gateRec, briefRec } = renders(copy);
|
||||
expect(briefRec).toEqual(gateRec);
|
||||
expect(gateRec).toEqual(Object.fromEntries(gate.items.map(i => [i.id, i.recommended])));
|
||||
expect(briefText).toContain('Use a queue table: keep the plan as written (a reviewer suggested changing it).');
|
||||
expect(briefText).not.toContain('carried forward');
|
||||
expect(briefText).toContain('rec takes the recommended answer for each.');
|
||||
});
|
||||
});
|
||||
@@ -234,16 +234,65 @@ test('the installed docs-candidate helper is admitted only with a private .json
|
||||
expect(docsNativeInterface(fixture)).toContain('compare <that .json> and --help commands');
|
||||
});
|
||||
|
||||
// Train gate 39904966815 (ship-docsync-completion, attempt 1) and GSTA-63's focused run joined the candidate's
|
||||
// --help onto a line of reads. The join stays refused; the own-call rule now sits in the sentence naming --help.
|
||||
test('a candidate --help joined to reads stays refused, and the interface says so where it names the command', () => {
|
||||
// Train gate 39904966815 and GSTA-63's focused run joined the candidate's --help onto a line of reads; v1.91.185.0 moved the
|
||||
// own-call rule into the sentence naming --help and the slip came back four times (JOINED_READ_LINES below). The --help only
|
||||
// prints usage, so it now joins a line of reads like a Git read; every other own-call command stays alone.
|
||||
test('a candidate --help joined to reads is a read, and the interface names it as the one exception to the own-call rule', () => {
|
||||
const skills = fixture.skills.split(path.sep).join('/');
|
||||
const joined = `git diff; git diff --cached; cat options.ts; ls -la handbook handbook/reference handbook/reference/commands; ${skills}/bin/gstack-docs-candidate --help`;
|
||||
expect(docsCommandAllowed(joined, fixture)).toBe(false);
|
||||
expect(docsCommandAllowed(`${skills}/bin/gstack-docs-candidate --help`, fixture)).toBe(true);
|
||||
const candidate = `${skills}/bin/gstack-docs-candidate`;
|
||||
const joined = `git diff; git diff --cached; cat options.ts; ls -la handbook handbook/reference handbook/reference/commands; ${candidate} --help`;
|
||||
expect(docsCommandAllowed(joined, fixture)).toBe(true);
|
||||
for (const command of [`${candidate} --help`, `${candidate} --help 2>&1`, `git status; ${candidate} snapshot --help`, `${candidate} compare --help 2>/dev/null; git log --oneline -3`,
|
||||
`${candidate} --help | head -20`]) expect(docsCommandAllowed(command, fixture), command).toBe(true);
|
||||
const record = path.join(fixture.home, 'c.json');
|
||||
for (const command of [
|
||||
`git status; ${candidate} snapshot --out ${record} --audit-id a --mode edit --base main`, `git status; ${candidate} compare ${record}`,
|
||||
`${candidate} --help; git add app.ts`, `${candidate} --help > ${path.join(fixture.home, 'usage.md')}`, `${candidate} --help | sh`,
|
||||
`echo x | ${candidate} --help`, `git status | ${candidate} --help`, `cd ${fixture.repo} && ${candidate} --help`, `git status; ${candidate} --help snapshot`,
|
||||
`git status; ${candidate} --version`, `git status; ${candidate} -h`, `git status; ${candidate} --help --exec rm`,
|
||||
`git status; ~/.claude/skills/gstack/bin/gstack-docs-candidate --help`, `git status; ${path.join(path.dirname(fixture.home), 'bin/gstack-docs-candidate')} --help`,
|
||||
`git status; ${skills}/bin/gstack-skill-start --help`, `git status; ${skills}/bin/gstack-skill-end --help`,
|
||||
]) expect(docsCommandAllowed(command, fixture), command).toBe(false);
|
||||
const sentence = docsNativeInterface(fixture).split(/(?<=\.)\s+(?=[A-Z])/).find(part => part.includes('gstack-docs-candidate snapshot'));
|
||||
expect(sentence).toContain('as its own Bash call, with nothing joined before or after it');
|
||||
expect(sentence).toContain('a --help is no exception');
|
||||
expect(sentence).not.toContain('a --help is no exception');
|
||||
expect(docsNativeInterface(fixture)).toContain(`So may the installed ${candidate} --help, alone or after snapshot or compare, because it only prints usage (the one exception)`);
|
||||
});
|
||||
|
||||
// Five red ship-docsync parents, each red only on 'command outside declared docs observation interface', and each with exactly
|
||||
// one refused line (every other Bash call of the five captures replays clean): four joined the candidate's --help onto a line of
|
||||
// reads, and gate 40643690306 put `git tag` in one. {home} is the fixture home; the sha is the capture file's sha256 prefix.
|
||||
const JOINED_READ_LINES: Array<[source: string, scenario: 'current' | 'store', line: string]> = [
|
||||
['screen 40558235014 slice 5 @ 70cedc3d, capture c73fb9d0b1b0', 'current',
|
||||
'git diff main HEAD; cat personal-note.txt; ls -la; find handbook; {home}/.claude/skills/gstack/bin/gstack-docs-candidate --help'],
|
||||
['gate 40600731931 slice 4 @ 5fef38a5, capture 606503d8b78a', 'store',
|
||||
'cat handbook/reference/commands/widget.md.tmpl; echo ---; cat CHANGELOG.md TODOS.md VERSION package.json AGENTS.md; echo ---; cat personal-note.txt; echo ---; find handbook; {home}/.claude/skills/gstack/bin/gstack-docs-candidate --help'],
|
||||
['screen 40627127462 slice 5 @ 76a155d4, capture 67fa4dea377a', 'current',
|
||||
'git diff main...HEAD; cat handbook/reference/commands/widget.md.tmpl; ls -la handbook handbook/reference handbook/reference/commands; cat personal-note.txt | head -3; {home}/.claude/skills/gstack/bin/gstack-docs-candidate --help'],
|
||||
['screen 40627127462 rerun 1 @ 76a155d4, capture 53d06fea1a89', 'current',
|
||||
'git diff main HEAD; git rev-parse origin/main; {home}/.claude/skills/gstack/bin/gstack-docs-candidate --help 2>&1'],
|
||||
['gate 40643690306 slice 4 @ c188a78c, capture 6ac1902bd83f', 'store',
|
||||
'git rev-parse HEAD origin/main; git merge-base main HEAD; git tag; cat {home}/fixture-interface.md | head -5; ls {home}'],
|
||||
];
|
||||
|
||||
test.each(JOINED_READ_LINES)('captured joined read line from %s is a declared read', (_source, scenario, line) => {
|
||||
const owned = fixtureDocs(scenario);
|
||||
try {
|
||||
const command = line.replaceAll('{home}', owned.home);
|
||||
const publish = path.join(owned.home, 'fixture-publish.ts');
|
||||
expect(docsCommandAllowed(command, owned, [publish])).toBe(true);
|
||||
expect(docsToolFailures(nativeResult(command, 'usage: gstack-docs-candidate snapshot ...'), owned, [publish], true)).toEqual([]);
|
||||
expect(docsCommandAllowed(`${command}; git add app.ts`, owned, [publish])).toBe(false);
|
||||
} finally { owned.clean(); }
|
||||
});
|
||||
|
||||
test('operand-free tag listings are reads, and every tag write stays refused', () => {
|
||||
for (const listing of ['git tag', 'git tag -l', 'git tag --list', 'git status; git tag; git log --oneline -3'])
|
||||
expect(docsCommandAllowed(listing, fixture), listing).toBe(true);
|
||||
for (const write of ['git tag v1', 'git tag -a v1 -m release', 'git tag -d v1', 'git tag -f v1 HEAD~1', 'git tag -s v1', 'git tag -v v1', 'git tag -l "v*"',
|
||||
'git tag --contains HEAD', 'git tag -n', 'git tag --sort=-v:refname', 'git tag -l v1', 'git tag; git tag v2', 'git tag | sh'])
|
||||
expect(docsCommandAllowed(write, fixture), write).toBe(false);
|
||||
expect(docsNativeInterface(fixture)).toContain('tag listings with no operand and only -l/--list');
|
||||
});
|
||||
|
||||
test('the installed lifecycle helpers are admitted for their own --help, which starts nothing', () => {
|
||||
|
||||
@@ -15,13 +15,13 @@ export const docsCapsCommand = (skills: string) => `${skills}/bin/gstack-ship-re
|
||||
export function docsNativeInterface(fixture: Pick<ReturnType<typeof fixtureDocs>, 'home' | 'repo' | 'skills'> & Partial<Pick<ReturnType<typeof fixtureDocs>, 'env'>>, scripts: string[] = [], transport = false, insert = false, file?: string): string {
|
||||
const skills = fixture.skills.split(path.sep).join('/');
|
||||
const state = fixture.env?.GSTACK_HOME ?? path.join(fixture.home, 'state');
|
||||
return `Fixture observation interface (applies to parent and every child; ${file ? `saved at ${file}: each child prompt tells the child to Read that file first instead of copying this text` : 'include this interface in child prompts'}): Bash may execute only separate literal pwd, ls, cat, stat, sha256sum and Git read commands (status, diff, show, log, ls-files, ls-tree, check-ignore, rev-parse, merge-base, hash-object without -w, branch listings with no operand and only --show-current, -a/--all, -r/--remotes, -v/--verbose, -l/--list, --no-color or --no-abbrev (no --merged, --sort, --format or --contains), describe with only --tags, --always, --abbrev=<n> or --exact-match and at most one revision). Bash may also run each of the following as its own Bash call, with nothing joined before or after it by ;, &&, || or a pipe (a --help is no exception, so never add one to a line of reads): the exact generated Preamble block with its spawned prefix, literal installed gstack-skill-start/gstack-skill-end commands for document-release (start requires GSTACK_SESSION_KIND=spawned) or their own --help, or the literal installed ${skills}/bin/gstack-docs-candidate snapshot (its --out a private .json under ${fixture.home}), compare <that .json> and --help commands, and /ship Step 14.5's three own-tree housekeeping commands exactly as written, each on its own line: the shared .gstack/tmp exclude line (the one &&-joined housekeeping line this interface admits)
|
||||
return `Fixture observation interface (applies to parent and every child; ${file ? `saved at ${file}: each child prompt tells the child to Read that file first instead of copying this text` : 'include this interface in child prompts'}): Bash may execute only separate literal pwd, ls, cat, stat, sha256sum and Git read commands (status, diff, show, log, ls-files, ls-tree, check-ignore, rev-parse, merge-base, hash-object without -w, branch listings with no operand and only --show-current, -a/--all, -r/--remotes, -v/--verbose, -l/--list, --no-color or --no-abbrev (no --merged, --sort, --format or --contains), tag listings with no operand and only -l/--list, describe with only --tags, --always, --abbrev=<n> or --exact-match and at most one revision). Bash may also run each of the following as its own Bash call, with nothing joined before or after it by ;, &&, || or a pipe (one exception follows the read grammar below): the exact generated Preamble block with its spawned prefix, literal installed gstack-skill-start/gstack-skill-end commands for document-release (start requires GSTACK_SESSION_KIND=spawned) or their own --help, or the literal installed ${skills}/bin/gstack-docs-candidate snapshot (its --out a private .json under ${fixture.home}), compare <that .json> and --help commands, and /ship Step 14.5's three own-tree housekeeping commands exactly as written, each on its own line: the shared .gstack/tmp exclude line (the one &&-joined housekeeping line this interface admits)
|
||||
${DOCS_TMP_EXCLUDE}
|
||||
then
|
||||
${DOCS_AUDIT_RESET}
|
||||
and the cap gate, which reads origin/main's policy and whose DOCS_CAP lines and exit status decide it
|
||||
${docsCapsCommand(skills)}
|
||||
(no --json, no other base, no other gstack-ship-receipt subcommand). ${readOnlyInterfaceText(fixture.home)} The Git reads above may join such a line too, but not in a line with cd. A for loop over literal words (a lowercase loop variable; words without quotes, globs or $) whose body uses only such reads counts as those reads, one pass per word, wherever it sits in the line. Every read stays off actor-state.json and off ${docsConfigDir(fixture.home)} except its settings.json: that directory holds Claude's credentials and every agent's session transcript, so judge a child only by the output it returns (its echoed SESSION_KIND line included) and by the repository. The additional scripts below also run each as its own Bash call; no own-call command ever joins such a line. Otherwise no shell composition, custom interpreters, arbitrary scripts, inline eval or memory-mapped writes. The only additional scripts are ${scripts.length ? scripts.join(', ') : 'none'}.${insert ? ` To insert one saved private Markdown artifact into another (a saved section file into a report), Bash may also run the single literal command cat SOURCE.md >> TARGET.md with absolute paths under ${fixture.home}.` : ''} Read/Glob/Grep remain available; Read skill and section files with Read (offset/limit for ranges), because Bash output over 30KB becomes a truncated preview. A private JSON/Markdown artifact (the snapshot --out file, saved child output, a section or report file) lives directly under ${fixture.home} or in a new directory you create there, never inside the repository, ${skills}, ${docsConfigDir(fixture.home)}, ${state} (gstack's own state directory, not a place for your files) or ${fixture.home}/remote.git. Use Write/Edit for permitted docs, those private artifacts and Step 14.5's receipt record ${fixture.repo}/${DOCS_AUDIT_RECORD} (the only permitted write under the repository besides the document, excluded from git by the line above); do not rewrite installed skills, config, actor state or scripts. No effects outside the owned fixture. The owner preserves evidence and cleans up. Missing observer coverage blocks acceptance; the Linux kernel monitor covers syscall writes in the product tree, not hostile processes or arbitrary external destinations.
|
||||
(no --json, no other base, no other gstack-ship-receipt subcommand). ${readOnlyInterfaceText(fixture.home)} The Git reads above may join such a line too, but not in a line with cd. So may the installed ${skills}/bin/gstack-docs-candidate --help, alone or after snapshot or compare, because it only prints usage (the one exception); neither a joined Git read nor that --help may be fed by a pipe. A for loop over literal words (a lowercase loop variable; words without quotes, globs or $) whose body uses only such reads counts as those reads, one pass per word, wherever it sits in the line. Every read stays off actor-state.json and off ${docsConfigDir(fixture.home)} except its settings.json: that directory holds Claude's credentials and every agent's session transcript, so judge a child only by the output it returns (its echoed SESSION_KIND line included) and by the repository. The additional scripts below also run each as its own Bash call; no other own-call command ever joins such a line. Otherwise no shell composition, custom interpreters, arbitrary scripts, inline eval or memory-mapped writes. The only additional scripts are ${scripts.length ? scripts.join(', ') : 'none'}.${insert ? ` To insert one saved private Markdown artifact into another (a saved section file into a report), Bash may also run the single literal command cat SOURCE.md >> TARGET.md with absolute paths under ${fixture.home}.` : ''} Read/Glob/Grep remain available; Read skill and section files with Read (offset/limit for ranges), because Bash output over 30KB becomes a truncated preview. A private JSON/Markdown artifact (the snapshot --out file, saved child output, a section or report file) lives directly under ${fixture.home} or in a new directory you create there, never inside the repository, ${skills}, ${docsConfigDir(fixture.home)}, ${state} (gstack's own state directory, not a place for your files) or ${fixture.home}/remote.git. Use Write/Edit for permitted docs, those private artifacts and Step 14.5's receipt record ${fixture.repo}/${DOCS_AUDIT_RECORD} (the only permitted write under the repository besides the document, excluded from git by the line above); do not rewrite installed skills, config, actor state or scripts. No effects outside the owned fixture. The owner preserves evidence and cleans up. Missing observer coverage blocks acceptance; the Linux kernel monitor covers syscall writes in the product tree, not hostile processes or arbitrary external destinations.
|
||||
|
||||
The working directory for parent and child Bash calls is already ${fixture.repo}. Run Git reads directly, for example: git status, git diff --cached, git merge-base main HEAD, git rev-parse HEAD. Do not use Git global options such as -C, -c, --git-dir or --work-tree, and do not prepend cd or another shell wrapper. The literal git subcommand must immediately follow git; an absolute owned repository path does not make git -C an allowed command.
|
||||
|
||||
|
||||
@@ -322,9 +322,12 @@ function docsUnrollLoops(text: string): string | null {
|
||||
|
||||
/**
|
||||
* A read-only line the shared grammar cannot see whole: loops are checked as
|
||||
* their unrolled passes, and each declared Git read joined to grammar reads
|
||||
* (never after a cd, never fed by a pipe) is checked literally and then stands
|
||||
* in the line as a neutral read for the grammar.
|
||||
* their unrolled passes, and each declared Git read or installed candidate
|
||||
* --help joined to grammar reads (never after a cd, never fed by a pipe) is
|
||||
* checked literally and then stands in the line as a neutral read for the grammar.
|
||||
* The candidate's --help prints its usage and returns before it touches Git or a
|
||||
* file (bin/gstack-docs-candidate main), so joining it reads nothing more (gates
|
||||
* 40600731931 and 40627127462, screen 40558235014: the parent ended a line of reads with it).
|
||||
*/
|
||||
function docsComposedReadAllowed(text: string, fixture: ReturnType<typeof fixtureDocs>): boolean {
|
||||
const line = docsUnrollLoops(text);
|
||||
@@ -332,13 +335,16 @@ function docsComposedReadAllowed(text: string, fixture: ReturnType<typeof fixtur
|
||||
if (line !== text && readOnlyCommandAllowed(line, docsReadOnlyScope(fixture))) return true;
|
||||
const segments = docsTopLevelSegments(line);
|
||||
if (!segments) return false;
|
||||
const candidate = path.join(fixture.skills, 'bin/gstack-docs-candidate').split(path.sep).join('/');
|
||||
const commands = segments.map(segment => line.slice(segment.start, segment.end).trim());
|
||||
const git = commands.flatMap((command, index) => /^git(?:\s|$)/.test(command) ? [index] : []);
|
||||
if (!git.length || commands.some(command => /^cd(?:\s|$)/.test(command))) return false;
|
||||
const declared = commands.flatMap((command, index) => /^git(?:\s|$)/.test(command) || command.startsWith(`${candidate} `) ? [index] : []);
|
||||
if (!declared.length || commands.some(command => /^cd(?:\s|$)/.test(command))) return false;
|
||||
let neutral = line;
|
||||
for (const index of git.reverse()) {
|
||||
for (const index of declared.reverse()) {
|
||||
const read = unwrapHarmlessRead(commands[index]!, fixture);
|
||||
if (segments[index - 1]?.op === '|' || read === null || !/^git\s/.test(read) || !literalDocsCommandAllowed(read, fixture, [])) return false;
|
||||
const help = read !== null && /^(?:(?:snapshot|compare) )?--help$/.test(read.slice(candidate.length + 1));
|
||||
if (segments[index - 1]?.op === '|' || read === null || !(/^git\s/.test(read) || (read.startsWith(`${candidate} `) && help))
|
||||
|| !literalDocsCommandAllowed(read, fixture, [])) return false;
|
||||
neutral = `${neutral.slice(0, segments[index]!.start)} pwd ${neutral.slice(segments[index]!.end)}`;
|
||||
}
|
||||
return readOnlyCommandAllowed(neutral, docsReadOnlyScope(fixture));
|
||||
@@ -384,6 +390,9 @@ function literalDocsCommandAllowed(text: string, fixture: ReturnType<typeof fixt
|
||||
// A branch listing reads refs (gates 40458489644 and 40477638211: the parent oriented with `git branch -a`);
|
||||
// an operand or any other option creates, moves, deletes or retargets a branch.
|
||||
if (rest[0] === 'branch') return rest.slice(1).every(arg => DOCS_BRANCH_LIST_FLAGS.test(arg));
|
||||
// A tag listing reads refs the same way (gate 40643690306: the parent ended a line of reads with `git tag`);
|
||||
// an operand or any other option creates, deletes, signs or verifies a tag.
|
||||
if (rest[0] === 'tag') return rest.slice(1).every(arg => arg === '-l' || arg === '--list');
|
||||
if (rest[0] === 'describe') {
|
||||
const operands = rest.slice(1).filter(arg => !DOCS_DESCRIBE_FLAGS.test(arg));
|
||||
return operands.length <= 1 && operands.every(arg => !arg.startsWith('-'));
|
||||
|
||||
@@ -10,7 +10,7 @@ import { COOKIE_MANUAL_REVIEW_FILE } from './cookie-workflow-manual-review';
|
||||
// exact historical prompt bytes, including the section's line range.
|
||||
const LATER_BROWSER_BLOCK = /\*\*Windows: Opera and Opera GX\.\*\*[\s\S]*?appear in CLI output\.\n\n/;
|
||||
const LATER_BROWSER_EDITS: Array<[string, string]> = [
|
||||
['The picker recognizes Chrome, Chromium, Brave, Edge, Windows-only Opera and Opera GX, and macOS-only Comet, Arc, and Dia.', 'The picker recognizes Chrome, Chromium, Brave, Edge, and macOS-only Comet, Arc, and Dia.'],
|
||||
['The picker recognizes Chrome, Chromium, Brave, Edge, Windows-only Opera and Opera GX, and macOS-only Comet and Arc.', 'The picker recognizes Chrome, Chromium, Brave, Edge, and macOS-only Comet, Arc, and Dia.'],
|
||||
[' Opera and Opera GX are Windows-only and read from `%APPDATA%\\Opera Software\\Opera Stable` or `Opera GX Stable`, in `Default` or `Profile N` directories; legacy root-level layouts, Opera side profiles and portable or relocated installs are not detected. Opera has no native extraction, so its App-Bound cookies (if any) need manual sign-in.', ''],
|
||||
];
|
||||
|
||||
@@ -35,6 +35,8 @@ const LATER_WAVE_EDITS: Array<[string, string]> = [
|
||||
"The skill-start output above already ran artifacts sync. Act on its lines:\nGBrain hint text (if present) tells you when to prefer `gbrain` over Grep;\n`ARTIFACTS_SYNC:` reports sync health (`off`, `mode=... | queue=N`,\n`remote-mode`, or a restore hint naming `gstack-brain-restore`).\n\nThe one-time privacy stop-gate (artifacts-sync consent) arrives as a\n`GSTACK_INSTRUCTION` block from skill-start when consent is actually pending\n\u2014 fire it via AskUserQuestion exactly as the block instructs."],
|
||||
// Oct 8 wave: the tier-1 voice directive gained the reply-language rule (two lines longer).
|
||||
["Reply in the language of the user's latest message unless asked otherwise. Code, commands, paths, identifiers and quoted output stay verbatim.\n\n", ''],
|
||||
// Dia removal (GSTA-143) dropped its platform sentence; same line count.
|
||||
["\nKeychain approval is the user's choice.", "\nDia is macOS-only. Keychain approval is the user's choice."],
|
||||
// #3129 dropped the Claude body's "When to invoke" section above the preamble (seven lines shorter).
|
||||
['<!-- Regenerate: bun run gen:skill-docs -->\n\n## Preamble (run first)\n', '<!-- Regenerate: bun run gen:skill-docs -->\n\n\n## When to invoke this skill\n\nOpens an interactive picker UI where you select which cookie domains to import.\nUse before QA testing authenticated pages. Use when asked to "import cookies",\n"login to the site", or "authenticate the browser".\n\n## Preamble (run first)\n'],
|
||||
];
|
||||
|
||||
@@ -0,0 +1,356 @@
|
||||
/**
|
||||
* A test a branch removes (deleted, or the old name of a rename) owes no lane
|
||||
* when nothing remaining imports it (issue #3529, gbrain#7829); any other
|
||||
* removal, a renamed source's old name included, owes what an edit owes, as on
|
||||
* main. Each waived test prints a visible `removed (no lane owed): <path> — <why>`
|
||||
* line: it runs the tests of files that still name it, and a deleted test runs
|
||||
* its owning suite (the remaining tests of the files it exercised) or says which
|
||||
* subjects lost their last test; a modified file whose only test was deleted
|
||||
* still fails, and an unreadable deleted test fails closed.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { BASE_PREGATE, cleanup, commit, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/pregate-fixture';
|
||||
|
||||
const repos: FixtureRepo[] = [];
|
||||
const fixture = (opts?: Parameters<typeof makeFixtureRepo>[0]) => { const r = makeFixtureRepo(opts); repos.push(r); return r; };
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
|
||||
const UTIL_V2 = "const test = require('node:test');\nconst assert = require('node:assert');\nconst { add } = require('../lib/util.js');\ntest('adds again', () => assert.strictEqual(add(2, 2), 4));\n";
|
||||
|
||||
function lanes(repo: FixtureRepo) {
|
||||
const r = runBin(repo, 'gstack-pregate', ['--base', 'main', '--allow-repo-commands', '--stage', 'tests']);
|
||||
const out = JSON.parse(fs.readFileSync(path.join(repo.work, '.gstack/tmp/pregate.json'), 'utf8'));
|
||||
const check = out.checks.find((c: { id: string }) => c.id === 'lanes');
|
||||
const lines: string[] = check.lines ?? [];
|
||||
return { status: r.status, check, lines, removed: lines.filter(l => l.startsWith('removed (no lane owed): ')), ran: lines.find(l => l.startsWith('ran: ')) ?? '' };
|
||||
}
|
||||
|
||||
function move(repo: FixtureRepo, from: string, to: string, edit?: [string, (text: string) => string]) {
|
||||
repo.git('mv', from, to);
|
||||
if (edit) { const file = path.join(repo.work, edit[0]); fs.writeFileSync(file, edit[1](fs.readFileSync(file, 'utf8'))); }
|
||||
repo.git('add', '-A');
|
||||
repo.git('commit', '-q', '-m', 'move');
|
||||
}
|
||||
|
||||
describe('removed paths in lanes (#3529)', () => {
|
||||
test('a deleted test runs its owning suite: the remaining tests of the files it exercised', () => {
|
||||
const repo = fixture({ baseFiles: { 'test/util-v2.test.js': UTIL_V2 } });
|
||||
commit(repo, { 'test/util.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).not.toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.status).toBe('pass');
|
||||
expect(r.removed).toEqual(['removed (no lane owed): test/util.test.js — owning suite runs: test/util-v2.test.js']);
|
||||
expect(r.ran).toContain('test/util-v2.test.js');
|
||||
expect(r.ran).not.toContain("'test/util.test.js'");
|
||||
expect(r.check.detail).toContain('1 removed path(s)');
|
||||
});
|
||||
|
||||
test('deleting the only test of a file says coverage removed, in the line and in the detail', () => {
|
||||
const repo = fixture();
|
||||
commit(repo, { 'test/util.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.status).toBe('pass');
|
||||
expect(r.removed).toEqual(['removed (no lane owed): test/util.test.js — coverage removed: lib/util.js has no remaining test']);
|
||||
expect(r.check.detail).toContain('1 removed path(s); 1 subject(s) lost their last test');
|
||||
});
|
||||
|
||||
test('deleting a file and its test together waives the test; the deleted file still owes a lane', () => {
|
||||
const repo = fixture();
|
||||
commit(repo, { 'test/util.test.js': null, 'lib/util.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.detail).toContain('1 touched file(s) with no test lane: lib/util.js');
|
||||
expect(r.removed).toEqual(['removed (no lane owed): test/util.test.js — it exercised no file still in the tree']);
|
||||
expect(r.check.detail).not.toContain('lost their last test');
|
||||
});
|
||||
|
||||
test('a renamed test runs under its new name; its old name is noted', () => {
|
||||
const repo = fixture();
|
||||
move(repo, 'test/util.test.js', 'test/util2.test.js');
|
||||
const r = lanes(repo);
|
||||
expect(r.check.status).toBe('pass');
|
||||
expect(r.removed).toEqual(['removed (no lane owed): test/util.test.js — old name of test/util2.test.js']);
|
||||
expect(r.ran).toContain('test/util2.test.js');
|
||||
});
|
||||
|
||||
test('an unstaged deletion behaves like a committed one: the missing test is never selected', () => {
|
||||
const repo = fixture({ baseFiles: { 'test/util-v2.test.js': UTIL_V2 } });
|
||||
fs.rmSync(path.join(repo.work, 'test/util.test.js'));
|
||||
const r = lanes(repo);
|
||||
expect(r.check.status).toBe('pass');
|
||||
expect(r.removed).toEqual(['removed (no lane owed): test/util.test.js — owning suite runs: test/util-v2.test.js']);
|
||||
expect(r.ran).not.toContain("'test/util.test.js'");
|
||||
});
|
||||
|
||||
test('a deleted executable test is read at its merge-base mode', () => {
|
||||
const repo = fixture({ baseFiles: { 'test/util-v2.test.js': UTIL_V2 } });
|
||||
fs.chmodSync(path.join(repo.work, 'test/util.test.js'), 0o755);
|
||||
repo.git('add', '-A'); repo.git('commit', '-q', '-m', 'exec'); repo.git('push', '-q', 'origin', 'HEAD:main');
|
||||
commit(repo, { 'test/util.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.status).toBe('pass');
|
||||
expect(r.removed).toEqual(['removed (no lane owed): test/util.test.js — owning suite runs: test/util-v2.test.js']);
|
||||
});
|
||||
|
||||
test('a shared test helper the deleted test imported selects no suite and never reads as lost coverage', () => {
|
||||
const helper = "exports.check = (a, b) => a === b;\n";
|
||||
const usesHelper = "const test = require('node:test');\nconst { check } = require('./helpers/h.js');\ntest('helper', () => check(1, 1));\n";
|
||||
const util = "const test = require('node:test');\nconst assert = require('node:assert');\nconst { check } = require('./helpers/h.js');\nconst { add } = require('../lib/util.js');\ntest('adds', () => assert.ok(check(add(1, 2), 3)));\n";
|
||||
const repo = fixture({ baseFiles: { 'test/helpers/h.js': helper, 'test/helper-user.test.js': usesHelper, 'test/util.test.js': util, 'test/util-v2.test.js': UTIL_V2 } });
|
||||
commit(repo, { 'test/util.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.removed).toEqual(['removed (no lane owed): test/util.test.js — owning suite runs: test/util-v2.test.js']);
|
||||
expect(r.ran).not.toContain('helper-user');
|
||||
});
|
||||
|
||||
test('a deleted test named after a bin/ entrypoint reports that bin when it loses its last test', () => {
|
||||
const repo = fixture({ baseFiles: { 'bin/gstack-foo': '#!/bin/sh\necho foo\n', 'test/gstack-foo.test.js': "const test = require('node:test');\ntest('foo', () => {});\n" } });
|
||||
commit(repo, { 'test/gstack-foo.test.js': null });
|
||||
expect(lanes(repo).removed).toEqual(['removed (no lane owed): test/gstack-foo.test.js — coverage removed: bin/gstack-foo has no remaining test']);
|
||||
});
|
||||
|
||||
test('a file declared no lane needed never reads as lost coverage', () => {
|
||||
const repo = fixture({ pregate: { ...BASE_PREGATE, dependencies: { ...BASE_PREGATE.dependencies, 'lib/util.js': [] } } });
|
||||
commit(repo, { 'test/util.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.status).toBe('pass');
|
||||
expect(r.removed).toEqual(['removed (no lane owed): test/util.test.js — its files keep indirect or declared coverage']);
|
||||
expect(r.check.detail).not.toContain('lost their last test');
|
||||
});
|
||||
|
||||
test('the owning suite is the tests that exercise the same files directly, not every test that reaches them', () => {
|
||||
const wrap = "exports.addTwice = (a) => require('./util.js').add(a, a);\n";
|
||||
const wrapTest = "const test = require('node:test');\nconst assert = require('node:assert');\nconst { addTwice } = require('../lib/wrap.js');\ntest('twice', () => assert.strictEqual(addTwice(2), 4));\n";
|
||||
const repo = fixture({ baseFiles: { 'lib/wrap.js': wrap, 'test/wrap.test.js': wrapTest, 'test/util-v2.test.js': UTIL_V2 } });
|
||||
commit(repo, { 'test/util.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.removed).toEqual(['removed (no lane owed): test/util.test.js — owning suite runs: test/util-v2.test.js']);
|
||||
expect(r.ran).not.toContain('test/wrap.test.js');
|
||||
});
|
||||
|
||||
test('a test renamed to a non-test path is accounted for like a deleted test', () => {
|
||||
const repo = fixture();
|
||||
move(repo, 'test/util.test.js', 'docs/util-notes.md');
|
||||
expect(lanes(repo).removed).toEqual(['removed (no lane owed): test/util.test.js — coverage removed: lib/util.js has no remaining test']);
|
||||
});
|
||||
|
||||
describe('negative controls', () => {
|
||||
test('deleting every file of a fixture directory a remaining test reads selects that test', () => {
|
||||
const reader = "const test = require('node:test');\nconst fs = require('node:fs');\ntest('reads the fixture dir', () => { fs.readdirSync('test/fixtures/data'); });\n";
|
||||
const repo = fixture({ baseFiles: { 'test/fixtures/data/a.json': '{}\n', 'test/fixtures/data/b.json': '{}\n', 'test/fixture-dir.test.js': reader } });
|
||||
commit(repo, { 'test/fixtures/data/a.json': null, 'test/fixtures/data/b.json': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.removed).toEqual([]);
|
||||
expect(r.ran).toContain('test/fixture-dir.test.js');
|
||||
});
|
||||
|
||||
test.each(['package.json', '.github/workflows/windows.yml', 'test/golden/digest.txt'])('deleting %s owes what editing it owes: PREGATE_NO_LANE', file => {
|
||||
const repo = fixture();
|
||||
commit(repo, { [file]: null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.detail).toContain(file);
|
||||
expect(r.removed).toEqual([]);
|
||||
});
|
||||
|
||||
test('a deleted source file a remaining config still names fails closed', () => {
|
||||
const repo = fixture({ baseFiles: { 'scripts/setup.js': "console.log('setup');\n", 'bunfig.toml': '[test]\npreload = ["./scripts/setup.js"]\n' } });
|
||||
commit(repo, { 'scripts/setup.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.detail).toContain('scripts/setup.js');
|
||||
});
|
||||
|
||||
test('a deleted test that remaining code still imports fails closed', () => {
|
||||
const repo = fixture({ baseFiles: { 'lib/uses-test.js': "exports.cases = require('../test/util.test.js');\n" } });
|
||||
commit(repo, { 'test/util.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.removed).toEqual([]);
|
||||
const why = runBin(repo, 'gstack-pregate', ['--base', 'main', '--allow-repo-commands', '--stage', 'tests', '--explain']);
|
||||
expect(`${why.out}${why.err}`).toContain('test/util.test.js: removed, but still imported by lib/uses-test.js');
|
||||
});
|
||||
|
||||
const GO_MOD = 'module example.com/demo\n\ngo 1.22\n';
|
||||
const NOT_A_TEST = 'removed, but only a removed test is waived; any other removal owes what an edit owes';
|
||||
test.each([
|
||||
['a file nothing references', { 'lib/orphan.js': 'exports.o = 1;\n' }, 'lib/orphan.js'],
|
||||
['a file untested code imports without an extension', { 'src/d.ts': 'export const d = 1;\n', 'src/u.ts': "import { d } from './d';\nexport const u = d + 1;\n" }, 'src/d.ts'],
|
||||
['a module untested code imports by its dotted name', { 'pkg/__init__.py': '', 'pkg/m.py': 'X = 1\n', 'app.py': 'from pkg import m\nprint(m.X)\n' }, 'pkg/m.py'],
|
||||
['a module run by its dotted name', { 'tools/__init__.py': '', 'tools/cli.py': 'print(1)\n', 'Makefile': 'run:\n\tpython3 -m tools.cli\n' }, 'tools/cli.py'],
|
||||
['a Go file its package still uses', { 'go.mod': GO_MOD, 'pkg/value.go': 'package pkg\n\nfunc value() int { return 1 }\n', 'pkg/main.go': 'package pkg\n\nfunc Main() int { return value() }\n' }, 'pkg/value.go'],
|
||||
['a Ruby file loaded by require_relative', { 'lib/value.rb': 'VALUE = 1\n', 'lib/main.rb': "require_relative 'value'\n" }, 'lib/value.rb'],
|
||||
['a shell helper a bin sources', { 'bin/helper.sh': 'greet() { echo hi; }\n', 'bin/tool': '#!/bin/sh\nDIR=$(dirname "$0")\n. "$DIR/helper.sh"\ngreet\n' }, 'bin/helper.sh'],
|
||||
['a config its runner loads by name', { 'vitest.config.ts': 'export default {};\n' }, 'vitest.config.ts'],
|
||||
['a Python startup file', { 'sitecustomize.py': 'import builtins\nbuiltins.FEATURE = True\n' }, 'sitecustomize.py'],
|
||||
['a setup file a nested config names relative to itself', { 'packages/app/setup.ts': 'export {};\n', 'packages/app/bunfig.toml': '[test]\npreload = ["./setup.ts"]\n' }, 'packages/app/setup.ts'],
|
||||
])('deleting %s still owes a lane, as on main', (_what, files, deleted) => {
|
||||
const repo = fixture({ baseFiles: files });
|
||||
commit(repo, { [deleted]: null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.removed).toEqual([]);
|
||||
const explain = runBin(repo, 'gstack-pregate', ['--base', 'main', '--allow-repo-commands', '--stage', 'tests', '--explain']);
|
||||
expect(explain.out + explain.err).toContain(`${deleted}: ${NOT_A_TEST}`);
|
||||
});
|
||||
|
||||
test('deleting a Go test whose package may share its helpers fails closed', () => {
|
||||
const repo = fixture({ baseFiles: { 'go.mod': GO_MOD, 'pkg/a.go': 'package pkg\n', 'pkg/a_test.go': 'package pkg\n\nfunc helper() {}\n', 'pkg/b_test.go': 'package pkg\n' } });
|
||||
commit(repo, { 'pkg/a_test.go': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.removed).toEqual([]);
|
||||
const explain = runBin(repo, 'gstack-pregate', ['--base', 'main', '--allow-repo-commands', '--stage', 'tests', '--explain']);
|
||||
expect(explain.out + explain.err).toContain('pkg/a_test.go: removed, but a Go or Ruby test may define helpers');
|
||||
});
|
||||
|
||||
test('a renamed source\'s old name still owes a lane, as on main', () => {
|
||||
const repo = fixture();
|
||||
move(repo, 'lib/util.js', 'lib/util2.js', ['test/util.test.js', t => t.replace('../lib/util.js', '../lib/util2.js')]);
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.detail).toContain('lib/util.js');
|
||||
expect(r.removed).toEqual([]);
|
||||
});
|
||||
|
||||
const CURATION = "exports.SKIP = ['test/util.test.js'];\n";
|
||||
const CURATION_TEST = "const test = require('node:test');\nconst assert = require('node:assert');\nconst fs = require('node:fs');\nconst path = require('node:path');\nconst { SKIP } = require('../scripts/curation.js');\ntest('every entry names a real test', () => assert.deepStrictEqual(SKIP.filter(f => !fs.existsSync(path.join(__dirname, '..', f))), []));\n";
|
||||
test.each([
|
||||
['deleted test', (repo: FixtureRepo) => commit(repo, { 'test/util.test.js': null })],
|
||||
['test renamed to another test', (repo: FixtureRepo) => move(repo, 'test/util.test.js', 'test/util2.test.js')],
|
||||
])('a %s that a tested curation list still names runs that list\'s test, which fails loudly', (_how, change) => {
|
||||
const repo = fixture({ baseFiles: { 'scripts/curation.js': CURATION, 'test/curation.test.js': CURATION_TEST } });
|
||||
change(repo);
|
||||
const r = lanes(repo);
|
||||
expect(r.ran).toContain('test/curation.test.js');
|
||||
expect(r.check.status).toBe('fail');
|
||||
expect(r.removed[0]).toContain('files naming it run: test/curation.test.js');
|
||||
});
|
||||
|
||||
test.each([
|
||||
['an extensionless path in package.json', 'test/util.test.js', { 'package.json': '{ "name": "fixture", "scripts": { "smoke": "node --test test/util.test" } }\n' }],
|
||||
['a dotted module name in a Makefile', 'tests/test_alpha.py', { 'tests/__init__.py': '', 'tests/test_alpha.py': 'import unittest\nclass T(unittest.TestCase):\n def test_a(self):\n pass\n', 'Makefile': 'smoke:\n\tpython3 -m unittest tests.test_alpha\n' }],
|
||||
['a dotted module name untested code imports at run time', 'app/test_handlers.py', { 'app/__init__.py': '', 'app/test_handlers.py': 'X = 1\n', 'app/registry.py': 'import importlib\nH = importlib.import_module("app.test_handlers")\n' }],
|
||||
['a JSON-escaped tab before the name', 'alpha.test.js', { 'alpha.test.js': "const test = require('node:test');\ntest('a', () => {});\n", 'package.json': '{ "name": "fixture", "scripts": { "smoke": "node --test\\talpha.test.js" } }\n' }],
|
||||
['a URL-encoded path', 'test/alpha.test.js', { 'test/alpha.test.js': "const test = require('node:test');\ntest('a', () => {});\n", 'ci/links.txt': 'https://example.test/run?file=test%2Falpha.test.js\n' }],
|
||||
])('a removed test named only by %s that no test covers fails closed', (_how, removed, files) => {
|
||||
const repo = fixture({ baseFiles: files });
|
||||
commit(repo, { [removed]: null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.removed).toEqual([]);
|
||||
const explain = runBin(repo, 'gstack-pregate', ['--base', 'main', '--allow-repo-commands', '--stage', 'tests', '--explain']);
|
||||
expect(explain.out + explain.err).toContain(`${removed}: removed, but still named by`);
|
||||
});
|
||||
|
||||
test('a removed test a file no test covers still names fails closed', () => {
|
||||
const repo = fixture({ baseFiles: { 'scripts/skip-list.txt': 'test/util.test.js\n' } });
|
||||
commit(repo, { 'test/util.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.removed).toEqual([]);
|
||||
const explain = runBin(repo, 'gstack-pregate', ['--base', 'main', '--allow-repo-commands', '--stage', 'tests', '--explain']);
|
||||
expect(explain.out + explain.err).toContain('test/util.test.js: removed, but still named by scripts/skip-list.txt, which no test covers');
|
||||
});
|
||||
|
||||
test('a rename into a waived path does not waive the old name: package.json renamed to Markdown fails closed', () => {
|
||||
const repo = fixture();
|
||||
move(repo, 'package.json', 'docs/package.md');
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.detail).toContain('package.json');
|
||||
expect(r.removed).toEqual([]);
|
||||
});
|
||||
|
||||
test('a renamed source remaining untested code still imports by its old name fails closed', () => {
|
||||
const repo = fixture({ baseFiles: { 'lib/a.js': 'exports.a = 1;\n', 'lib/u.js': "exports.u = require('./a.js').a;\n", 'notes/plan.md': '# plan\n' } });
|
||||
move(repo, 'lib/a.js', 'notes/a.md');
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.detail).toContain('lib/a.js');
|
||||
expect(r.removed).toEqual([]);
|
||||
});
|
||||
|
||||
test('a deleted file a remaining bin reads through its directory fails closed', () => {
|
||||
const repo = fixture({ baseFiles: { 'lib/plugins/a.js': 'exports.a = 1;\n', 'lib/plugins/b.js': 'exports.b = 2;\n', 'bin/load.js': "const fs = require('node:fs');\nfor (const f of fs.readdirSync('lib/plugins')) require('../lib/plugins/' + f);\n" } });
|
||||
commit(repo, { 'lib/plugins/a.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.removed).toEqual([]);
|
||||
const explain = runBin(repo, 'gstack-pregate', ['--base', 'main', '--allow-repo-commands', '--stage', 'tests', '--explain']);
|
||||
expect(explain.out + explain.err).toContain(`lib/plugins/a.js: ${NOT_A_TEST}`);
|
||||
});
|
||||
|
||||
test('a deleted file a tested loader reaches by a computed path fails closed', () => {
|
||||
const loader = "const path = require('node:path');\nexports.value = () => require(path.join(__dirname, 'lib', 'value.js')).value;\n";
|
||||
const loaderTest = "const test = require('node:test');\nconst { value } = require('../loader.js');\ntest('loads', () => value());\n";
|
||||
const repo = fixture({ baseFiles: { 'lib/value.js': 'exports.value = 1;\n', 'loader.js': loader, 'test/loader.test.js': loaderTest } });
|
||||
commit(repo, { 'lib/value.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.removed).toEqual([]);
|
||||
const explain = runBin(repo, 'gstack-pregate', ['--base', 'main', '--allow-repo-commands', '--stage', 'tests', '--explain']);
|
||||
expect(explain.out + explain.err).toContain(`lib/value.js: ${NOT_A_TEST}`);
|
||||
});
|
||||
|
||||
test('a Go test renamed into another directory is refused: its old package may still call its helpers', () => {
|
||||
const repo = fixture({ baseFiles: { 'go.mod': 'module example.com/demo\n\ngo 1.22\n', 'pkg/a.go': 'package pkg\n', 'pkg/a_test.go': 'package pkg\n\nfunc helper() {}\n', 'pkg/b_test.go': 'package pkg\n\nfunc TestB(t *testing.T) { helper() }\n', 'isolated/keep.go': 'package isolated\n' } });
|
||||
move(repo, 'pkg/a_test.go', 'isolated/a_test.go');
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.detail).toContain('pkg/a_test.go');
|
||||
expect(r.removed).toEqual([]);
|
||||
});
|
||||
|
||||
test('a modified file whose only test was deleted still fails PREGATE_NO_LANE', () => {
|
||||
const repo = fixture();
|
||||
commit(repo, { 'test/util.test.js': null, 'lib/util.js': "exports.add = (a, b) => b + a;\n" });
|
||||
const r = lanes(repo);
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.detail).toContain('lib/util.js');
|
||||
expect(r.check.detail).not.toContain('test/util.test.js');
|
||||
expect(r.check.detail).toContain('1 removed path(s); 1 subject(s) lost their last test');
|
||||
expect(r.removed).toEqual(['removed (no lane owed): test/util.test.js — coverage removed: lib/util.js has no remaining test']);
|
||||
});
|
||||
|
||||
test('a deleted file a remaining test still imports selects that test, which fails loudly', () => {
|
||||
const repo = fixture();
|
||||
commit(repo, { 'lib/util.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.removed).toEqual([]);
|
||||
expect(r.ran).toContain('test/util.test.js');
|
||||
expect(r.check.code).toBe('PREGATE_LANE_FAILED');
|
||||
});
|
||||
|
||||
test('an explicit dependencies mapping for a deleted path still selects its mapped test', () => {
|
||||
const repo = fixture({ pregate: { ...BASE_PREGATE, dependencies: { ...BASE_PREGATE.dependencies, 'test/util.test.js': ['test/retry.test.js'] } } });
|
||||
commit(repo, { 'test/util.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.status).toBe('pass');
|
||||
expect(r.removed).toEqual([]);
|
||||
expect(r.ran).toContain('test/retry.test.js');
|
||||
});
|
||||
|
||||
test('a deleted markdown file keeps its docs/no-tests label', () => {
|
||||
const repo = fixture({ baseFiles: { 'notes/plan.md': '# plan\n' } });
|
||||
commit(repo, { 'notes/plan.md': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.status).toBe('pass');
|
||||
expect(r.removed).toEqual([]);
|
||||
expect(r.lines).toContain('docs/no-tests (empty lane): notes/plan.md');
|
||||
});
|
||||
|
||||
test('a deleted test whose merge-base text cannot be read (over 1 MiB) fails closed', () => {
|
||||
const big = "const test = require('node:test');\nrequire('../lib/util.js');\n// " + 'x'.repeat(1024 * 1024) + '\n';
|
||||
const repo = fixture({ baseFiles: { 'test/big.test.js': big } });
|
||||
commit(repo, { 'test/big.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.detail).toContain('test/big.test.js');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -4,7 +4,7 @@
|
||||
* that moved out of it.
|
||||
*/
|
||||
import { expect, test } from 'bun:test';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { collectFreeTestFiles, createFreeCiPlan, curateWindowsSafe, parseCliOptions, validateFreeCiPlan } from '../scripts/test-free-shards';
|
||||
import { windowsCurationLine } from '../scripts/lib/free-ci-health';
|
||||
@@ -113,11 +113,10 @@ test('native qualification is dispatch-only with one exclusive mode per run', ()
|
||||
expect(Object.keys(native.on)).toEqual(['workflow_dispatch']);
|
||||
const mode = native.on.workflow_dispatch.inputs.mode;
|
||||
expect(mode).toMatchObject({ type: 'choice', required: true });
|
||||
expect(mode.options).toEqual(['cookie-native', 'windows-native-diagnostics', 'dia-native', 'dia-launch-comparison', 'dia-gui-readiness']);
|
||||
expect(mode.options).toEqual(['cookie-native', 'windows-native-diagnostics']);
|
||||
expect(native.permissions).toEqual({ contents: 'read' });
|
||||
expect(native.jobs['cookie-native-qualification'].if).toBe("inputs.mode == 'cookie-native'");
|
||||
expect(native.jobs['windows-native-diagnostics'].if).toBe("inputs.mode == 'windows-native-diagnostics'");
|
||||
expect(native.jobs['dia-native-qualification'].if).toBe("startsWith(inputs.mode, 'dia-')");
|
||||
for (const job of ['cookie-native-qualification', 'windows-native-diagnostics']) {
|
||||
const setup = native.jobs[job].steps.find((step: any) => step.uses?.startsWith('actions/setup-node@'));
|
||||
expect(setup.with['node-version']).toBe('24.18.0');
|
||||
@@ -125,6 +124,12 @@ test('native qualification is dispatch-only with one exclusive mode per run', ()
|
||||
}
|
||||
});
|
||||
|
||||
test('the removed Dia qualification harness has no mode and no scripts', () => {
|
||||
expect(Object.keys(native.jobs)).toEqual(['cookie-native-qualification', 'windows-native-diagnostics']);
|
||||
for (const file of [path.join(import.meta.dir, '..', '.github/scripts', 'dia-gui-readiness.c'), path.join(import.meta.dir, '..', '.github/scripts', 'dia-launch-driver.mjs'),
|
||||
path.join(import.meta.dir, '..', '.github/scripts', 'qualify-dia-macos.ts'), path.join(import.meta.dir, '..', '.github/scripts', 'run-dia-native-qualification.ts')]) expect(existsSync(file)).toBe(false);
|
||||
});
|
||||
|
||||
test('focused Windows diagnostics include the repaired lock and close cases without default-profile qualification', () => {
|
||||
const run = native.jobs['windows-native-diagnostics'].steps.find((step: any) => step.name === 'Run focused native launch and credential diagnostics').run;
|
||||
const pattern = run.match(/--test-name-pattern '([^']+)'/)?.[1];
|
||||
@@ -134,35 +139,3 @@ test('focused Windows diagnostics include the repaired lock and close cases with
|
||||
'native Windows process qualification > real Edge synthetic profile: normal-close', 'native Windows process qualification > real Edge synthetic profile: stalled-close']) expect(selected.test(name)).toBe(true);
|
||||
expect(selected.test('native Windows process qualification > an exclusively created default Edge profile persists v20')).toBe(false);
|
||||
});
|
||||
|
||||
test('Dia comparison uses separate pinned runtime jobs and retains diagnostic failures', () => {
|
||||
const job = native.jobs['dia-native-qualification'];
|
||||
expect(job['runs-on']).toBe('macos-15');
|
||||
expect(job.strategy['fail-fast']).toBe(false);
|
||||
expect(job.strategy.matrix.runtime).toBe(`\${{ fromJSON(inputs.mode == 'dia-launch-comparison' && '["bun","node"]' || '["bun"]') }}`);
|
||||
const node = job.steps.find((step: any) => step.uses?.startsWith('actions/setup-node@'));
|
||||
expect(node.if).toBe("inputs.mode == 'dia-launch-comparison'");
|
||||
expect(node.with).toEqual({ 'node-version': '24.18.0', architecture: 'arm64' });
|
||||
const comparison = job.steps.find((step: any) => step.name === 'Compare protected native Dia launch without qualification credit');
|
||||
expect(comparison.if).toBe("inputs.mode == 'dia-launch-comparison'");
|
||||
expect(comparison.run).toContain('--launch-comparison "$COMPARISON_RUNTIME"');
|
||||
expect(comparison['continue-on-error']).toBeUndefined();
|
||||
const upload = job.steps.find((step: any) => step.uses?.startsWith('actions/upload-artifact@'));
|
||||
expect(upload.if).toBe('always()');
|
||||
expect(upload.with.name).toContain("format('dia-launch-comparison-{0}', matrix.runtime)");
|
||||
});
|
||||
|
||||
test('Dia GUI readiness runs alone, without dependency or browser installation', () => {
|
||||
const job = native.jobs['dia-native-qualification'];
|
||||
const probe = job.steps.find((step: any) => step.name === 'Inspect GUI readiness without browser or Keychain access');
|
||||
expect(probe.if).toBe("inputs.mode == 'dia-gui-readiness'");
|
||||
expect(probe.run).toEndWith('.github/scripts/run-dia-native-qualification.ts --gui-readiness-only');
|
||||
expect(probe.env).toEqual({ GSTACK_DIA_NATIVE_QUALIFY: '1' });
|
||||
for (const name of ['Install pinned dependencies', 'Install the synthetic destination browser']) {
|
||||
expect(job.steps.find((step: any) => step.name === name).if).toBe("inputs.mode != 'dia-gui-readiness'");
|
||||
}
|
||||
expect(job.steps.find((step: any) => step.name === 'Qualify native Dia discovery, decryption, and import').if).toBe("inputs.mode == 'dia-native'");
|
||||
const upload = job.steps.find((step: any) => step.uses?.startsWith('actions/upload-artifact@'));
|
||||
expect(upload.with.name).toContain("inputs.mode == 'dia-gui-readiness' && 'dia-gui-readiness'");
|
||||
expect(upload.with.path).toBe('${{ runner.temp }}/dia-native-qualification.json');
|
||||
});
|
||||
Reference in new issue
Block a user