mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-28 07:32:14 +02:00
* fix(memory-ingest): --scan-secrets scans the rendered page and fails closed --scan-secrets ran gitleaks on the raw transcript .jsonl, then imported a page rendered from it. gitleaks' assignment rules don't match across a JSON-escaped quote (KEY=\"v\" on disk), so a secret the rendered page shows as KEY="v" was imported unflagged. And the gate skipped a file only on scanner "gitleaks" with findings, so a scan that errored (non-zero exit, 16MB maxBuffer overflow on a file with many findings, unparseable report) or could not run (gitleaks missing, slow-probe cooldown) imported the file unscanned. Scan the rendered page body, the exact bytes writeStaged() writes, via a new secretScanText() helper, and skip the file whenever the scan did not complete. Skipped files stay out of the state file, so the next run retries them. Reword the helper warnings and setup-gbrain/memory.md, which described the fail-open as intended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(test): reconcile Bun failure markers and footer counts * fix(sync-gbrain): verify source-scoped reads without mutation * fix(test): recognize grounded TTHW target choices structurally * fix(aside): make the readiness probe work under zsh and report why it failed The probe built its deadline into `_T` and expanded it unquoted, so `$_T aside repl …` only worked in a shell that word-splits. zsh does not: it looked for a command literally named "gtimeout 30", the probe answered ASIDE_NOT_RUNNING with Aside installed and ready, and every browsing skill fell back to the bundled Chromium in silence. zsh is the macOS default and Aside is macOS-only, so on a stock Mac the probe could never report READY. The deadline becomes a function, `_gs_d`. It receives the command as "$@", already split, so sh, bash and zsh all behave the same, and the gtimeout → timeout → perl alarm chain is unchanged. A 4th arm runs the call unbounded when none of the three is present, which is what the empty `_T` did before. Not `eval`: it re-parses the string, so the parens and `;` of the perl arm become syntax and that arm dies in bash *and* zsh — on a stock Mac, the arm that actually runs. On failure the probe now prints the CLI's reason after ASIDE_NOT_RUNNING:, the shape gstack-render already uses: the first line that starts with a capital letter, i.e. the CLI's own sentence or Node's `Error:` line below its loader frame. "Not running" covers states with different fixes — no window open for the profile, a NODE_OPTIONS preload that kills the CLI — and a bare verdict sent all of them to "open the Aside app". The BROWSER SETUP prose quotes that reason before asking the user to open the app. The text pin asserted the broken invocation verbatim, so it now pins the function and asserts neither `$_T aside repl` nor an eval form comes back. A second test executes the rendered probe in sh, bash and zsh on each of the four deadline arms with stubbed binaries on a narrowed PATH, plus two failing CLIs: one that prints its own sentence, one that crashes like Node with the useful line below the frame. The deadline function costs zero bytes against the lines it replaces; the reason costs 53 per copy of the probe (44 where the reworded BROWSER SETUP line gives 9 back). That moves four guards by the measured amount: plan-devex-review's skeleton cap to 68,550 (measured 68,544), plan-ceo-review's skeleton cap to 80,150 (measured 80,111) and union ratio to 1.081 (measured 1.0803), and plan-eng-review's union ratio to 1.151 (measured 1.1504). Fixes #2842, #2941. * Clarify engineering review startup and decision flow * Fix Windows readiness fixture PATH and command shim * fix(test): recognize grounded TTHW target choices structurally * Clarify engineering review startup and decision flow * fix(test): restrict QA-only fixture tools to its no-Edit contract * v1.90.0.0 fix(sync-gbrain): guard readiness verdicts and refresh metadata * fix(browse): validate canonical upload targets * fix(gbrain): classify structured PGLite busy response * fix(browse): preserve native extension runtime APIs * Fix displayless browser handoff ownership * Accept unique installed autoplan methodology aliases * fix(skills): preserve positional literals during installation * fix(browse): checksum installer contents through stdin * fix(test): normalize Windows checksum fixture paths * test: emulate unavailable shasum in Windows checksum fixture * fix(investigate): preserve owned freeze lifecycle * fix(review): preserve N+1 retry and Red Team completion * fix: bound Aside readiness and preserve safe fallback * test: exercise setup and Chromium on native ARM * fix: preserve install ownership and ARM browser selection * Fix gbrain ingest scan boundaries and seed observation * Refresh managed ship hooks and supervise expanded paid census * Reject resumed gbrain pages excluded by current policy * Recover zombie agent locks safely and enable CI Python venv * Repair paid actor declarations and Aside pitch assertions * Bump consolidated wave to next free minor release * Clarify CEO review admin choices and option tradeoffs * Preserve CEO mode handoff anchors in clarified workflow * Make Windows portability fixtures use shell-native paths * Restore ARM Bun alias and clarify ship review gates * Refresh ship workflow golden snapshots * Fix Windows DX documentation controls without piped stdin * Decode Codex child pipes without Bun's encoded-stream stall * Bound DX pre-review audit before product questions * Clarify trusted review-start read in paid revalidation * Bump consolidated wave to next free minor release * Clarify CEO review admin choices and option tradeoffs * Preserve CEO mode handoff anchors in clarified workflow * Make Windows portability fixtures use shell-native paths * Restore ARM Bun alias and clarify ship review gates * Refresh ship workflow golden snapshots * Fix Windows DX documentation controls without piped stdin * Decode Codex child pipes without Bun's encoded-stream stall * Bound DX pre-review audit before product questions * Clarify trusted review-start read in paid revalidation * Reconcile new main planning flow and paid judge census * fix: reconcile rebased planning and source-bound validation * test: pin cookie workflow judge to scored Sonnet model * fix: keep terminal agent boot out of module imports * fix: preserve pending-question uncertainty in engineering review * fix: stabilize Windows reliability-wave fixtures * fix: clarify design consultation research workflow * fix: preserve independent design consultation inputs * fix: resolve design taste scope and browser research guidance * fix: make consultation opt-in preflight unambiguous * test: await native Edge owner readiness or terminal result --------- Co-authored-by: Bruce Krysiak <brucek@alum.mit.edu> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Antonio Vitalic <antoninte99@gmail.com>
263 lines
15 KiB
TypeScript
263 lines
15 KiB
TypeScript
import { expect, test } from 'bun:test';
|
|
import * as fs from 'node:fs';
|
|
import * as os from 'node:os';
|
|
import * as path from 'node:path';
|
|
|
|
const ROOT = path.resolve(import.meta.dir, '..');
|
|
|
|
// Import the real five paid bodies in a separate process, before invoking any
|
|
// callback. Only provider/selection boundaries are stubbed; recordE2E is loaded
|
|
// from its actual source so default pass criteria and metadata stay covered.
|
|
async function exerciseCases() {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tpa-recording-'));
|
|
const script = path.join(dir, 'recording-fixture.test.ts');
|
|
const facts = path.join(dir, 'facts.json');
|
|
fs.writeFileSync(script, `
|
|
import { expect, mock, test } from 'bun:test';
|
|
import * as fs from 'node:fs';
|
|
import * as path from 'node:path';
|
|
const root = ${JSON.stringify(ROOT)};
|
|
const factsPath = ${JSON.stringify(facts)};
|
|
const { CLAUDE_FRONTIER_EVAL_MODEL } = await import(path.join(root, 'lib/eval-model.ts'));
|
|
const readFile = fs.readFileSync.bind(fs);
|
|
const recoveryResponses = JSON.parse(readFile(path.join(root, 'test/fixtures/third-party-actions-recovery-public.json'), 'utf8')).responses;
|
|
const writeFile = fs.writeFileSync.bind(fs);
|
|
const remove = fs.rmSync.bind(fs);
|
|
const source = readFile(path.join(root, 'test/helpers/e2e-helpers.ts'), 'utf8');
|
|
const start = source.indexOf('export function recordE2E(');
|
|
const end = source.indexOf('/**', start);
|
|
if (start < 0 || end < 0) throw new Error('recordE2E source boundary missing');
|
|
const recordSource = new Bun.Transpiler({ loader: 'ts' }).transformSync(source.slice(start, end).replace('export function', 'function'));
|
|
const recordE2E = new Function(recordSource + '\\nreturn recordE2E;')();
|
|
const cases = new Map();
|
|
const records = [];
|
|
const facts = [];
|
|
let mode = 'pass';
|
|
let text = '';
|
|
let result;
|
|
let runnerCalls = 0;
|
|
let recordCalls = 0;
|
|
let recordThrows = false;
|
|
let selected = true;
|
|
const runnerError = new Error('fixture runner failed');
|
|
const fixtureError = new Error('fixture contract read failed');
|
|
const cleanupError = new Error('fixture cleanup failed');
|
|
const recordingError = new Error('fixture recorder failed');
|
|
let forwardCollector;
|
|
const collector = { addTest(entry) {
|
|
recordCalls++;
|
|
records.push(entry);
|
|
forwardCollector?.addTest(entry);
|
|
if (recordThrows) throw recordingError;
|
|
} };
|
|
mock.module('fs', () => ({ ...fs, readFileSync(file, ...args) {
|
|
if ((mode === 'fixture' && String(file) === path.join(root, 'ship/SKILL.md')) ||
|
|
(mode === 'apple-doc' && String(file) === path.join(root, 'ship/sections/apple-release.md'))) throw fixtureError;
|
|
return readFile(file, ...args);
|
|
}, rmSync(file, ...args) {
|
|
const value = remove(file, ...args);
|
|
if (mode === 'cleanup' && path.basename(String(file)).startsWith('tpa-e2e-')) throw cleanupError;
|
|
return value;
|
|
} }));
|
|
mock.module(path.join(root, 'test/helpers/session-runner.ts'), () => ({
|
|
runSkillTest: async (opts) => {
|
|
runnerCalls++;
|
|
if (opts.maxTurns !== 8 || opts.timeout !== 240000 || opts.model !== undefined ||
|
|
JSON.stringify(opts.allowedTools) !== JSON.stringify(['Read', 'Bash'])) throw new Error('paid runner policy changed');
|
|
if (mode === 'runner') throw runnerError;
|
|
if (mode === 'undefined') throw undefined;
|
|
result = {
|
|
toolCalls: [{ tool: 'Bash', input: { command: 'fixture readiness probe' }, output: 'fixture' }],
|
|
browseErrors: mode === 'browse-error' ? ['existing browse failure'] : [],
|
|
exitReason: mode === 'exit' ? 'timeout' : 'success', duration: 123,
|
|
output: 'x'.repeat(2100),
|
|
transcript: [{ type: 'assistant', message: { content: [{ type: 'text', text }] } }],
|
|
costEstimate: { inputChars: 70, outputChars: 2100, estimatedTokens: 19, estimatedCost: 0.37, turnsUsed: 3 },
|
|
model: 'claude-sonnet-4-6', firstResponseMs: 7, maxInterTurnMs: 11,
|
|
};
|
|
return result;
|
|
},
|
|
}));
|
|
mock.module(path.join(root, 'test/helpers/e2e-helpers.ts'), () => ({
|
|
ROOT: root, runId: 'free-tpa-fixture', createEvalCollector: () => collector,
|
|
describeIfSelected: (_name, _ids, body) => { if (selected) body(); },
|
|
testIfSelected: (name, body, timeout) => {
|
|
if (timeout !== 360000) throw new Error('paid Bun budget changed');
|
|
cases.set(name, body);
|
|
},
|
|
logCost: () => {}, recordE2E, finalizeEvalCollector: async () => {},
|
|
}));
|
|
await import(path.join(root, 'test/skill-e2e-third-party-actions.test.ts'));
|
|
const positives = {
|
|
'tpa-present': 'A) Aside for dashboard.acme.test. D) defer.',
|
|
'tpa-absent-linux': "A) gstack's own visible browser B) manual instructions C) defer.",
|
|
'tpa-broken': 'Please open the Aside app.',
|
|
'tpa-absent-darwin': '> Download Aside (macOS 15+) at aside.com; open, sign in, re-run.',
|
|
'tpa-apple-ban': 'Generate the app-specific password on any device with fastlane-credentials.',
|
|
};
|
|
const negatives = {
|
|
'tpa-present': ['A) dashboard.acme.test D) defer', 'Aside dashboard.acme.test defer', 'A) Aside dashboard.acme.test', 'A) Aside D) defer', 'A) Aside dashboard.acme.test D) defer; download it at aside.com', 'A) Aside dashboard.acme.test D) defer; Download Aside (macOS 15+) at aside.com'],
|
|
'tpa-absent-linux': ["A) gstack's own visible browser B) manual; download it at aside.com", "A) gstack's own visible browser B) manual; Download Aside (macOS 15+) at aside.com", "A) Drive it in your Aside browser B) manual in gstack's own visible browser", "gstack's own visible browser; manual", "A) gstack's own visible browser", 'A) manual instructions'],
|
|
'tpa-broken': ["A) Open the Aside app, then I will recheck and drive it in your Aside browser", 'No current question.'],
|
|
'tpa-absent-darwin': ['Aside for macOS 15+', 'Download it at aside.com', 'Download Aside at aside.com', 'Do not Download Aside (macOS 15+) at aside.com', 'A) Drive it in your Aside browser; Download Aside (macOS 15+) at aside.com'],
|
|
'tpa-apple-ban': ['A) drive it; generate an app-specific password', 'Generate an app-specific password; drive account.apple.com', 'Generate credentials on any device', 'app-specific password'],
|
|
};
|
|
async function invoke(name, kind, output, throwRecording = false) {
|
|
mode = kind; text = output; result = undefined; runnerCalls = 0; recordCalls = 0; recordThrows = throwRecording;
|
|
records.length = 0;
|
|
let failed = false; let error;
|
|
try { await cases.get(name)(); } catch (caught) { failed = true; error = caught; }
|
|
const created = fs.readdirSync(${JSON.stringify(dir)}).filter(name => name.startsWith('tpa-e2e-'));
|
|
return { failed, error, entry: records[0], records: [...records], runnerCalls, recordCalls, created, result };
|
|
}
|
|
test('actual paid assertion boundaries and all failure stages retain one accurate record', async () => {
|
|
expect([...cases.keys()]).toEqual(Object.keys(positives));
|
|
const liveFailure = await invoke('tpa-broken', 'assertion', negatives['tpa-broken'][0]);
|
|
expect(liveFailure.failed).toBe(true);
|
|
expect(liveFailure.records).toHaveLength(1);
|
|
expect(liveFailure.entry.passed).toBe(false);
|
|
for (const [name, positive] of Object.entries(positives)) {
|
|
for (const [kind, output] of [['pass', positive], ['exit', positive], ['runner', positive], ['fixture', positive], ...negatives[name].map(value => ['assertion', value])]) {
|
|
const observed = await invoke(name, kind, output);
|
|
facts.push({ name, kind, failed: observed.failed, records: observed.records.length, passed: observed.entry?.passed });
|
|
expect(observed.failed, name + ':' + kind).toBe(kind !== 'pass');
|
|
expect(observed.records, name + ':' + kind).toHaveLength(1);
|
|
expect(observed.recordCalls).toBe(1);
|
|
expect(observed.entry).toMatchObject({ name, suite: 'e2e-third-party-actions', tier: 'e2e', passed: kind === 'pass' });
|
|
expect(observed.created).toEqual([]);
|
|
if (kind === 'runner' || kind === 'fixture') {
|
|
expect(observed.error).toBe(kind === 'runner' ? runnerError : fixtureError);
|
|
expect(observed.entry).toMatchObject({ exit_reason: 'harness_error', cost_usd: 0, model: CLAUDE_FRONTIER_EVAL_MODEL });
|
|
expect(observed.entry.error).toContain('cost and usage unavailable');
|
|
expect(observed.entry.transcript).toBeUndefined();
|
|
expect(observed.runnerCalls).toBe(kind === 'runner' ? 1 : 0);
|
|
} else {
|
|
expect(observed.entry).toMatchObject({ duration_ms: 123, cost_usd: 0.37, turns_used: 3, tokens_used: 19, model: 'claude-sonnet-4-6', first_response_ms: 7, max_inter_turn_ms: 11 });
|
|
expect(observed.entry.output).toHaveLength(2000);
|
|
expect(observed.entry.transcript).toEqual(observed.result.transcript);
|
|
expect(observed.entry.exit_reason).toBe(observed.result.exitReason);
|
|
expect(observed.entry.last_tool_call).toContain('fixture readiness probe');
|
|
if (kind !== 'pass') expect(observed.entry.error).toBeTruthy();
|
|
}
|
|
}
|
|
const browse = await invoke(name, 'browse-error', positive);
|
|
expect(browse.failed).toBe(false);
|
|
expect(browse.entry).toMatchObject({ passed: false, browse_errors: ['existing browse failure'] });
|
|
expect(browse.recordCalls).toBe(1);
|
|
}
|
|
// An unavailable-option explanation remains a passing attempt; only a real
|
|
// consent offer is forbidden by the updated contract assertion.
|
|
const narration = await invoke('tpa-absent-darwin', 'pass',
|
|
'> Download Aside (macOS 15+) at aside.com; open, sign in, re-run. Driving in your Aside browser is unavailable.');
|
|
expect(narration.failed).toBe(false);
|
|
expect(narration.entry.passed).toBe(true);
|
|
expect(narration.recordCalls).toBe(1);
|
|
for (const response of recoveryResponses) {
|
|
for (const [output, passed] of [
|
|
[response.text, true],
|
|
[response.text.replace('option included.', 'option included; then I drive in your Aside browser.'), false],
|
|
]) {
|
|
const observed = await invoke('tpa-broken', 'pass', output);
|
|
expect(observed.failed).toBe(!passed);
|
|
expect(observed.entry.passed).toBe(passed);
|
|
expect(observed.recordCalls).toBe(1);
|
|
expect(observed.entry.transcript).toEqual(observed.result.transcript);
|
|
}
|
|
}
|
|
// A runner/setup exception has no returned model. Mirror the same capture
|
|
// resolution that the real session runner would have used, including overrides.
|
|
for (const [overrides, expected] of [
|
|
[{}, CLAUDE_FRONTIER_EVAL_MODEL],
|
|
[{ GSTACK_EVAL_MODEL: 'global-model' }, 'global-model'],
|
|
[{ GSTACK_EVAL_MODEL: 'global-model', GSTACK_EVAL_MODEL_CAPTURE: 'capture-model' }, 'capture-model'],
|
|
[{ GSTACK_EVAL_MODEL: 'global-model', GSTACK_EVAL_MODEL_CAPTURE: 'capture-model', EVALS_MODEL: 'evals-model' }, 'evals-model'],
|
|
]) {
|
|
for (const key of ['EVALS_MODEL', 'GSTACK_EVAL_MODEL', 'GSTACK_EVAL_MODEL_CAPTURE']) delete process.env[key];
|
|
Object.assign(process.env, overrides);
|
|
const observed = await invoke('tpa-broken', 'runner', positives['tpa-broken']);
|
|
expect(observed.failed).toBe(true);
|
|
expect(observed.recordCalls).toBe(1);
|
|
expect(observed.entry).toMatchObject({ passed: false, exit_reason: 'harness_error', model: expected });
|
|
}
|
|
for (const key of ['EVALS_MODEL', 'GSTACK_EVAL_MODEL', 'GSTACK_EVAL_MODEL_CAPTURE']) delete process.env[key];
|
|
const doc = await invoke('tpa-apple-ban', 'apple-doc', positives['tpa-apple-ban']);
|
|
expect(doc.error).toBe(fixtureError);
|
|
expect(doc.entry).toMatchObject({ passed: false, exit_reason: 'harness_error' });
|
|
expect(doc.recordCalls).toBe(1);
|
|
expect(doc.runnerCalls).toBe(0);
|
|
const cleanup = await invoke('tpa-broken', 'cleanup', positives['tpa-broken']);
|
|
expect(cleanup.error).toBe(cleanupError);
|
|
expect(cleanup.recordCalls).toBe(1);
|
|
expect(cleanup.records).toHaveLength(1);
|
|
expect(cleanup.entry).toMatchObject({ passed: false, cost_usd: 0.37, duration_ms: 123 });
|
|
expect(cleanup.entry.transcript).toEqual(cleanup.result.transcript);
|
|
expect(cleanup.created).toEqual([]);
|
|
const undef = await invoke('tpa-broken', 'undefined', positives['tpa-broken']);
|
|
expect(undef.failed).toBe(true);
|
|
expect(undef.error).toBeUndefined();
|
|
expect(undef.entry.passed).toBe(false);
|
|
expect(undef.recordCalls).toBe(1);
|
|
for (const kind of ['pass', 'runner', 'assertion']) {
|
|
const observed = await invoke('tpa-broken', kind, kind === 'assertion' ? negatives['tpa-broken'][0] : positives['tpa-broken'], true);
|
|
expect(observed.failed).toBe(true);
|
|
expect(observed.recordCalls).toBe(1);
|
|
expect(observed.records).toHaveLength(1);
|
|
if (kind === 'pass') expect(observed.error).toBe(recordingError);
|
|
else {
|
|
expect(observed.error).toBeInstanceOf(AggregateError);
|
|
expect(observed.error.errors).toHaveLength(2);
|
|
expect(observed.error.errors[1]).toBe(recordingError);
|
|
if (kind === 'runner') expect(observed.error.errors[0]).toBe(runnerError);
|
|
else expect(observed.error.errors[0].message).toContain('in your Aside browser');
|
|
}
|
|
}
|
|
const { EvalCollector } = await import(path.join(root, 'test/helpers/eval-store.ts'));
|
|
forwardCollector = new EvalCollector('e2e', path.join(${JSON.stringify(dir)}, 'actual-collector'));
|
|
await invoke('tpa-broken', 'assertion', negatives['tpa-broken'][0]);
|
|
await invoke('tpa-broken', 'pass', positives['tpa-broken']);
|
|
const saved = JSON.parse(readFile(await forwardCollector.finalize(), 'utf8'));
|
|
expect(saved.tests.map(entry => [entry.name, entry.attempt, entry.passed, entry.cost_usd])).toEqual([
|
|
['tpa-broken', 1, false, 0.37], ['tpa-broken', 2, true, 0.37],
|
|
]);
|
|
expect(saved.flaky_retries).toEqual([{ name: 'tpa-broken', attempts: 2 }]);
|
|
forwardCollector = undefined;
|
|
selected = false; cases.clear(); runnerCalls = 0; recordCalls = 0;
|
|
await import(path.join(root, 'test/skill-e2e-third-party-actions.test.ts') + '?unselected');
|
|
expect(cases.size).toBe(0);
|
|
expect(runnerCalls).toBe(0);
|
|
expect(recordCalls).toBe(0);
|
|
writeFile(factsPath, JSON.stringify(facts));
|
|
});
|
|
`);
|
|
try {
|
|
const childEnv = { ...process.env, EVALS: '', EVALS_ALL: '', EVALS_PREFLIGHT_OK: '1',
|
|
GSTACK_CLAUDE_CLI_VERSION: 'free TPA fixture',
|
|
HOME: dir, TMPDIR: dir, TMP: dir, TEMP: dir, GSTACK_EVAL_DIR: path.join(dir, 'evals') };
|
|
for (const key of ['EVALS_MODEL', 'GSTACK_EVAL_MODEL', 'GSTACK_EVAL_MODEL_CAPTURE']) delete childEnv[key];
|
|
const proc = Bun.spawn([process.execPath, 'test', script], {
|
|
cwd: ROOT,
|
|
env: childEnv,
|
|
stdout: 'pipe', stderr: 'pipe',
|
|
});
|
|
const stop = () => { if (proc.exitCode === null) { try { proc.kill('SIGKILL'); } catch {} } };
|
|
const timeout = setTimeout(stop, 10_000);
|
|
try {
|
|
const [stdout, stderr, code] = await Promise.all([
|
|
new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited,
|
|
]);
|
|
return { code, output: stdout + stderr, facts: fs.existsSync(facts) ? JSON.parse(fs.readFileSync(facts, 'utf8')) : [] };
|
|
} finally {
|
|
clearTimeout(timeout);
|
|
stop();
|
|
await proc.exited;
|
|
}
|
|
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
}
|
|
|
|
test('TPA records the real paid case outcome once after all existing assertions', async () => {
|
|
const observed = await exerciseCases();
|
|
expect(observed.code, observed.output).toBe(0);
|
|
expect(observed.facts).toHaveLength(43);
|
|
expect(observed.facts.filter((entry: any) => entry.passed)).toHaveLength(5);
|
|
}, 20_000);
|