Files
gstack/test/helpers/plan-count-fixture.ts
T
ac20ef1e13 v1.91.16.0 fix: safe installs and upgrades, skills start everywhere, truthful completion (parallel wave) (#3014)
* fix(make-pdf,design): real TOC page numbers and anchors; design models move to gpt-5.5 + gpt-image-2 (#2903, #2807)

* ci: pin every action to a SHA, Scorecard, checksummed Bun, scoped Codex CLI in the CI image, macOS named-regressions job (#1948, #1706, #1997)

* fix(cso,browse): Windows/macOS lease identity, retention skips bad runs, truthful 'not assessed' reports, env.kv false positive, Windows browse spawn fixes (#2894, #2912, #2048, #2637, #2805)

* fix(outside-voice): one Codex model precedence for probe and dispatch, bounded timeouts with KILL escalation, probe cache identity, guarded mktemp, skills hidden in nested Codex (#2776, #2914, #2787, #2881, #2847)

* feat(setup): install registry, ./setup --status, staged activation, per-scope migrations, host tiers and conformance kit, OpenCode/Hermes fixes, Copilot CLI (experimental), disabled_skills, slimmer CLAUDE.md (#1925, #2879, #2347, #2338, #2626, #2629, #2825, #2015, #393, #1206, #2096)

Co-authored-by: Andrey Esipov <61357035+andrey-esipov@users.noreply.github.com>
Co-authored-by: Matthew Williams <5863886+ridermw@users.noreply.github.com>
Co-authored-by: Rocky Wu <92764750+lolisaigao1234@users.noreply.github.com>

* fix(preamble): skills start in worktree-isolated Claude Code sessions — one literal skill-start line, context-recovery helper, no eval in skill blocks, $N token tripwire, honest plan-mode precedence (#2763, #2896, #2851)

* fix(setup): per-install renders for renamed, vendored and custom-config installs, space-safe alias roots, per-host /cso launcher path (#1882, #2906)

* test: free tests never write the real HOME (home-write tripwire), no orphaned browse daemons, symlinked-TMPDIR (macOS) fixes, gbrain-on-PATH isolation (#2895, #2816, #2829, #2841, #2982, #2911, #2909, #2908, #2910)

* chore: integrate wave follow-ups — regenerate all hosts, README model docs, TODOS, touchfiles, duration seeds, Bun 1.3 telemetry test fix, replay fixtures pinned to their recorded bytes

* v1.91.14.0: release metadata

* test(browse): group-kill cleanup falls back to the leader when macOS returns EPERM for a live group

* ci: Codex login steps run under bash (the CI container's default sh rejects pipefail)

* fix: full-suite repairs — private state roots for 7 real-HOME writers, truthful home-guard attribution with --attribute-home, gstack-paths shim in ship-hook fixtures, Copilot in team-init probes, test-of-test detector, cookie review fixture pinned to the approved excerpt

* fix(windows): LF for Dockerfiles, normalized home-guard exclusions, path.relative fixture containment, ship push test spawn timeouts

* test(design-detect): widen the whole-scan budget test's timing margins so a loaded macOS runner can't time out the single-batch call

* fix(evals): qa protocol names defined for the judge, async PTY judge so overlapping sessions keep their cleanup deadline, bws setup cases use the standard JUDGE_MS tier

* test(pty): the non-blocking judge case is POSIX-only (its fake judge is a shebang script, like the PTY harness it covers)

* test(evals): ship-coverage-audit names absolute skill paths, uses Read, and skips the Step 7 artifact nothing consumes (removes the mechanism behind 3 of 4 historical timeouts)

* test: deflake terminal-agent concurrent startup (write the placeholder record before spawning, like the product) and qa-evidence resumed pipe (barrier on a full high-water mark instead of a sleep)

* fix(design): daemon log stream handles open errors instead of crashing the daemon; shutdown test awaits the stubbed exit

* test(evals): skillify checks the product's resolved state root (no GSTACK_HOME bypass), negative cases check every root; tpa shims live outside the agent's cwd and answer consistently

* test(evals): coverage-audit detector splits parallel columns at │ rails and [+] groups; coverage prompts name absolute skill paths; TODOs from the gate eval census

* fix(plan-eng-review): scope gate always sends the menu (no headless 'Scope pending' exit); PTY harness ends idle turn-ends and API-error panels promptly with a precise diagnostic

* test(evals): one position-bound coverage-read rule credits read-only && chains (labels, context ranges, git displays in either order) and still rejects forged output

* fix(ship): documentation section has one saved source inserted by cat (never retyped); spawned-marker evidence is the child output; refreshed codex/factory ship goldens

* test(docsync): the byte-exact insert positive is POSIX-only (the bash-command observer refuses backslash paths by design)

* test(evals): plan-design-with-ui focus-title rule accepts the comma-less 'dimensions or focus' wording (replayed on the captured CI run, negative controls kept)

* fix(qa-callers): exploratory preflight says the scope/method Reads come after exploratory.md; design-review scan check credits an executed scan proven by one engine run over the changed files

---------

Co-authored-by: Andrey Esipov <61357035+andrey-esipov@users.noreply.github.com>
Co-authored-by: Matthew Williams <5863886+ridermw@users.noreply.github.com>
Co-authored-by: Rocky Wu <92764750+lolisaigao1234@users.noreply.github.com>
2026-10-03 07:54:09 -07:00

164 lines
7.2 KiB
TypeScript

import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { spawnSync } from 'node:child_process';
import { getHermeticDirs } from './hermetic-env';
export interface NativeReviewState {
env: Record<string, string>;
cleanup(): void;
}
const ownedNativeReviewStates = new WeakMap<NativeReviewState, {
root: string; realRoot: string; dev: number; ino: number;
}>();
/** Only an explicit live constructor-owned state can grant Autoplan artifacts. */
export function ownedNativeReviewStateRoot(state: NativeReviewState, env: Record<string, string | undefined>): string {
const owned = ownedNativeReviewStates.get(state);
if (!owned || env.GSTACK_HOME !== owned.root || env.GSTACK_STATE_ROOT !== owned.root)
throw new Error('Autoplan artifacts require the matching owned native review state');
const stat = fs.lstatSync(owned.root);
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.dev !== owned.dev || stat.ino !== owned.ino ||
fs.realpathSync(owned.root) !== owned.realRoot)
throw new Error('Autoplan native review state was replaced');
return owned.root;
}
/** Disposable config for evals that explicitly cover native review only. */
export function createNativeReviewState(opts: { preconfiguredReviewActor?: boolean } = {}): NativeReviewState {
const sharedState = getHermeticDirs().gstackHome;
const stateRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-native-review-state-'));
let state: NativeReviewState | undefined;
const cleanup = () => {
if (state) ownedNativeReviewStates.delete(state);
fs.rmSync(stateRoot, { recursive: true, force: true });
};
try {
for (const entry of fs.readdirSync(sharedState, { withFileTypes: true })) {
// Keep onboarding seeds; never copy sibling review logs/artifacts.
if (entry.isFile() && (entry.name === '.activated' ||
/^\..*(?:-seen|-prompted|-shown)$/.test(entry.name) ||
entry.name.startsWith('.feature-prompted-'))) {
fs.copyFileSync(path.join(sharedState, entry.name), path.join(stateRoot, entry.name));
}
}
let config = fs.readFileSync(path.join(sharedState, 'config.yaml'), 'utf8')
.replace(/^codex_reviews:.*(?:\r?\n|$)/gm, '');
if (opts.preconfiguredReviewActor) {
// This fixture has already declined setup changes and cross-project recall.
// Keep native review questions interactive; never alter shared/operator state.
config = config.replace(/^(?:routing_declined|cross_project_learnings):.*(?:\r?\n|$)/gm, '')
+ '\nrouting_declined: true\ncross_project_learnings: false\n';
}
fs.writeFileSync(path.join(stateRoot, 'config.yaml'), config + '\ncodex_reviews: disabled\n');
// Readers and onboarding writers must agree on the owned state.
state = { env: { GSTACK_HOME: stateRoot, GSTACK_STATE_ROOT: stateRoot }, cleanup };
const stat = fs.lstatSync(stateRoot);
ownedNativeReviewStates.set(state, { root: stateRoot, realRoot: fs.realpathSync(stateRoot), dev: stat.dev, ino: stat.ino });
return state;
} catch (error) {
cleanup();
throw error;
}
}
/**
* Count evals review a seeded plan, never the checkout that supplies skills.
* Put the complete request in Claude's initial project context before the
* bare slash command starts: a later message can remain queued behind the
* skill's first AskUserQuestion and leave it reviewing the live branch.
*/
export function createPlanCountFixture(prompt: string, opts: {
nativeReviewOnly?: boolean;
preconfiguredReviewActor?: boolean;
files?: Record<string, string>;
/** Explicit caller-authorized working plan, relocated into this fixture. */
requestedPlanPath?: string;
} = {}): {
cwd: string;
env: Record<string, string>;
seed: string;
workingPlanPath?: string;
cleanup(): void;
} {
if (opts.preconfiguredReviewActor && !opts.nativeReviewOnly)
throw new Error('Preconfigured review actor requires owned native review state');
const cwd = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-plan-count-')));
let nativeState: ReturnType<typeof createNativeReviewState> | undefined;
const env: Record<string, string> = {};
const cleanup = () => {
try {
fs.rmSync(cwd, { recursive: true, force: true });
} finally {
nativeState?.cleanup();
}
};
try {
let workingPlanPath: string | undefined;
if (opts.requestedPlanPath !== undefined) {
const requested = opts.requestedPlanPath;
const name = path.basename(requested);
if (!path.isAbsolute(requested) || !/^[\w-]+\.md$/.test(name) ||
/^(?:plan|claude)\.md$/i.test(name) || prompt.split(requested).length !== 2 ||
Object.hasOwn(opts.files ?? {}, name))
throw new Error('Working plan requires one explicit path and a distinct ordinary Markdown filename');
workingPlanPath = path.join(cwd, name);
prompt = prompt.replace(requested, workingPlanPath);
}
const files = Object.entries(opts.files ?? {});
for (const [name] of files) {
const parts = name.split(/[\\/]/);
// The fixture owns its seed plan, instructions and Git metadata. Extra
// context must be an ordinary relative file, never an overwrite/escape.
if (path.isAbsolute(name) || path.win32.isAbsolute(name) || parts.some(part =>
part === '' || part === '.' || part === '..' || part.toLowerCase() === '.git') ||
/^(?:plan|claude)\.md$/i.test(name)) {
throw new Error(`Invalid plan-count fixture file: ${name}`);
}
}
if (opts.nativeReviewOnly) {
// Seeded-N bands cover native finding cadence; mode fixtures keep defaults.
nativeState = createNativeReviewState({ preconfiguredReviewActor: opts.preconfiguredReviewActor });
Object.assign(env, nativeState.env);
}
fs.writeFileSync(path.join(cwd, 'PLAN.md'), prompt);
fs.writeFileSync(path.join(cwd, 'CLAUDE.md'), [
'# Plan review fixture',
'',
'This repository contains the plan under review. Use PLAN.md as the',
'current plan for the requested plan-review skill. The skill installation',
'supplies the workflow; its source checkout is not the review target.',
'',
'The complete user request is available from the start of this session:',
'',
prompt,
'',
].join('\n'));
for (const [name, content] of files) {
const target = path.join(cwd, name);
fs.mkdirSync(path.dirname(target), { recursive: true });
fs.writeFileSync(target, content);
}
const git = (args: string[]) => {
const result = spawnSync('git', args, {
cwd,
encoding: 'utf8',
timeout: 10_000,
});
if (result.error || result.status !== 0) {
throw new Error(`Could not initialize plan-count fixture: ${result.error?.message ?? result.stderr}`);
}
};
git(['init', '-b', 'main']);
git(['add', '--', 'PLAN.md', 'CLAUDE.md', ...files.map(([name]) => name)]);
git(['-c', 'user.name=Plan Count Fixture', '-c', 'user.email=plan-count@example.test',
'-c', 'commit.gpgsign=false', 'commit', '--no-verify', '-m', 'Seed review plan']);
git(['update-ref', 'refs/remotes/origin/main', 'HEAD']);
return { cwd, env, seed: prompt, workingPlanPath, cleanup };
} catch (error) {
cleanup();
throw error;
}
}