mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-02 23:14:33 +01:00
* docs(designs): gstack field wave plan (2026-10-12) and the shared simulated Capy host fixture
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(pregate): price_command config key for the non-executing call plan a paid gate is priced from
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(pregate): repo guards a lane must pass, verified launch Bun and per-file serial runs in lanes, unknown flags exit 2
The guards check runs each .gstack/pregate.json guard whose globs match a
touched file in its own process with its own timeout (PREGATE_GUARD_FAILED,
never downgradable, incomplete without --allow-repo-commands). The lanes
runner and guards get the first Bun in $BUN_INSTALL/bin or ~/.bun/bin that
satisfies gstack's and the project's engines.bun; serial_patterns files run
one process each. price_file replaces the unreleased price_command key: a
paid gate is priced from a call-plan data file, never by running a command.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(pricing): Sonnet 5.5, Gemini 3.x and gbrain embedding rows from fetched pages; Opus 4.7 at its current list price
Each new row carries its source URL and fetch date (2026-10-12). Embedding
models bill input only, so they live in EMBEDDING_PRICING beside PRICING
(eval arms never resolve to them); pricingRow also accepts gbrain's
provider:model ids (voyage:voyage-4). claude-opus-4-7 moves from 15/75 to the
5/25 the Anthropic pricing page lists; benchmark-runner's expected costs follow.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(eval-plan): price-gate prices a paid gate from a call-plan data file, never executing it
gstack-eval-plan price-gate --gate "<exact command>" reads a GSTACK_EVAL_CALLS
v1 file (--plan-file, else the base policy's price_file at HEAD), checks its
binding (gate command string equality, head with only the plan file changed
since, every input's sha256 at HEAD), prices each call purpose (aggregate
totals) and each one-call reservation, and writes a receipt binding the price
to the gate, head, inputs and plan bytes. Unpriced models print unknown, never
zero (EVAL_PRICE_MISSING); a missing plan or no call lines is
EVAL_GATE_UNPRICED unless --allow-unpriced records an owner override; over
--cap-usd / --smoke-cap-usd is EVAL_GATE_OVER_CAP; malformed or partial files
refuse EVAL_DRY_RUN_FAILED and stale ones EVAL_PLAN_STALE. dry-run --cap adds
the same reservation-fits-cap check. Wire format, receipt and the reference
emitter (formatEvalCalls): docs/eval-calls.md.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(eval-plan): the approval step prices every paid gate with price-gate
Step 4 runs gstack-eval-plan price-gate for each paid gate the plan names and
puts its GATE_PRICE line in the ask; the dry-run checklist documents
reservation-fits-cap under --cap.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(sealed): sealed-output guard over every published commit, in the pre-push hook and gstack-pregate sealed
A repo with a sealed key in .gstack/pregate.json (base branch union the
pushed commit, so a push can tighten but never relax) refuses publishing
sealed paths, transcripts, quoted answers, seeds or local home paths to a
public or unknown destination (SEALED_OUTPUT_REFUSED); private warns.
Path rules see every added, renamed or copied path in each published
commit (git rev-list <local> --not --remotes=<remote>), text rules each
commit's added lines; waivers only from the base branch allow file; a
malformed policy fails closed; visibility caches public 24 h, private 1 h.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(eval-plan): only an undeclared plan is unpriced; a missing price_file is stale, a bad base policy refuses
price-gate's EVAL_GATE_UNPRICED (and --allow-unpriced) now covers only no
plan declared at all or a plan with zero call lines. A declared price_file
missing from the HEAD commit is EVAL_PLAN_STALE (exit 1, not overridable); an
unresolvable origin/<base> is POLICY_SOURCE_UNAVAILABLE and an invalid
.gstack/pregate.json is PREGATE_CONFIG_INVALID (both exit 3).
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(restamp): the repo's stamp rule (stamp_files, literal stamp_patterns) and restamp_command in the staging worktree
stamp_files is an allowlist applied before every stamp rule; stamp_patterns
are bounded literal {version} templates shared by the restamp writer and the
tree receipt. restamp_command runs first in the staging worktree with the
target version (argument and GSTACK_RESTAMP_VERSION), needs a clean caller
tree, skips gstack's version writer and keeps output confinement; a failure
or a wrong version writes nothing. migrations { dir, id } is the policy key
gstack-pregate regate reads.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(pregate): gstack-pregate regate --against <gated-head> with per-lane reuse and migration collisions
Reuse comes only from a tree receipt evaluated now, with a bundle produced
on the gated tree, the current execution identity and an unmoved, known
predecessor head. Each lane prints reusable/rerun/not-reusable; REGATE:
not-needed needs stamp-only, every bundle and --require lane reusable (a
stamp-sensitive lane reruns) and a finished migration lookup. Migration
numbers the branch adds are checked against the base tree and every other
open PR (gh pr list --limit 1000; 100-file lists refetched with gh api
--paginate); any lookup that cannot finish is unknown and blocks
not-needed (MIGRATION_COLLISION). Bare --against routes to the verb.
docs/pregate.md gains the regate section and the gbrain worked configs.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(contract): lanes run gstack-pregate (and the sealed guard where configured) before done; handoff carries the gstack trailer and PREGATE: line
The coordinator contract gains a 'Before done' paragraph and the handoff
order GSTACK_RESULT, gstack: ok|fail <rev>, PREGATE:, gate summary; the
spec section is regenerated and docs/unattended.md states the same rule.
A new test pins the terms and their order; the byte-identity pins stay.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* v1.91.98.0: pregate guards, priced paid gates, regate and the sealed-output guard
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* test: drop the helper-only Capy host fixture test (test-of-test ratchet); lane tests exercise the helper
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: price-gate --gate-file keeps free text out of the /eval-plan fence; shortest dependency traces; bounded test spawns
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* ci(windows): curate out the new pregate/restamp tests that spawn bin/ shebang scripts through runBin
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
---------
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
224 lines
13 KiB
TypeScript
224 lines
13 KiB
TypeScript
/**
|
|
* Field wave CD4: the sealed-output guard. A repo that declares `sealed` in
|
|
* `.gstack/pregate.json` cannot push sealed or eval output to a public
|
|
* destination by accident: the managed pre-push hook and
|
|
* `gstack-pregate sealed` enumerate every commit the push publishes (local
|
|
* sha minus everything the destination remote already has), apply path
|
|
* rules to every added, renamed or copied path (binary and empty files,
|
|
* add-then-delete) and text rules to each commit's added lines. The policy
|
|
* is the union of the base branch's and the pushed one; waivers come only
|
|
* from the base branch's allow file; an unknown visibility counts as public.
|
|
* Field incident: a per-cell transcript, a quoted sealed answer, a seed and a
|
|
* /home/user path were pushed to a public eval repo with exit 0 and no output.
|
|
*/
|
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
import { spawnSync } from 'node:child_process';
|
|
import * as fs from 'node:fs';
|
|
import * as os from 'node:os';
|
|
import * as path from 'node:path';
|
|
import { resolveVisibility } from '../lib/sealed-guard';
|
|
|
|
const ROOT = path.resolve(import.meta.dir, '..');
|
|
const PREPUSH = path.join(ROOT, 'bin', 'gstack-redact-prepush');
|
|
const PREGATE = path.join(ROOT, 'bin', 'gstack-pregate');
|
|
const ZERO = '0'.repeat(40);
|
|
const SEALED = {
|
|
paths: ['heldout/**'],
|
|
transcripts: ['runs/**/transcript*.jsonl'],
|
|
answer_markers: ['SEALED ANSWER:'],
|
|
seed_patterns: ['shuffle_seed=\\d+'],
|
|
local_paths: true,
|
|
};
|
|
|
|
interface Scratch { root: string; work: string; origin: string; state: string; env: Record<string, string> }
|
|
const scratches: Scratch[] = [];
|
|
afterEach(() => { while (scratches.length) fs.rmSync(scratches.pop()!.root, { recursive: true, force: true }); });
|
|
|
|
function sh(cwd: string, env: Record<string, string>, args: string[]): string {
|
|
const r = spawnSync('git', args, { cwd, encoding: 'utf8', timeout: 30_000, env: { ...process.env, ...env } });
|
|
if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
|
|
return (r.stdout ?? '').trim();
|
|
}
|
|
|
|
/** A bare origin with main carrying the given base files, and a clone on branch `results`. */
|
|
function scratch(baseFiles: Record<string, string | Buffer>): Scratch {
|
|
const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'sealed-guard-')));
|
|
const work = path.join(root, 'work'); const origin = path.join(root, 'origin.git'); const state = path.join(root, 'state');
|
|
fs.mkdirSync(work); fs.mkdirSync(state);
|
|
const env = { HOME: root, GSTACK_HOME: state, GSTACK_STATE_ROOT: state, GIT_CONFIG_GLOBAL: path.join(root, 'gitconfig'), GIT_CONFIG_NOSYSTEM: '1' };
|
|
fs.writeFileSync(env.GIT_CONFIG_GLOBAL, '[user]\n\tname = t\n\temail = t@example.com\n[commit]\n\tgpgsign = false\n[init]\n\tdefaultBranch = main\n');
|
|
spawnSync('git', ['init', '-q', '--bare', origin], { env: { ...process.env, ...env }, timeout: 30_000 });
|
|
sh(work, env, ['init', '-q', '-b', 'main']);
|
|
write(work, { 'README.md': '# evals\n', ...baseFiles });
|
|
sh(work, env, ['add', '-A']); sh(work, env, ['commit', '-q', '-m', 'base']);
|
|
sh(work, env, ['remote', 'add', 'origin', origin]);
|
|
sh(work, env, ['push', '-q', 'origin', 'main']);
|
|
sh(work, env, ['remote', 'set-head', 'origin', 'main']);
|
|
sh(work, env, ['checkout', '-q', '-b', 'results']);
|
|
const s = { root, work, origin, state, env };
|
|
scratches.push(s);
|
|
return s;
|
|
}
|
|
function write(work: string, files: Record<string, string | Buffer | null>): void {
|
|
for (const [rel, body] of Object.entries(files)) {
|
|
const abs = path.join(work, rel);
|
|
if (body === null) { fs.rmSync(abs, { force: true }); continue; }
|
|
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
fs.writeFileSync(abs, body);
|
|
}
|
|
}
|
|
function commit(s: Scratch, files: Record<string, string | Buffer | null>, msg = 'results'): string {
|
|
write(s.work, files);
|
|
sh(s.work, s.env, ['add', '-A']); sh(s.work, s.env, ['commit', '-q', '-m', msg]);
|
|
return sh(s.work, s.env, ['rev-parse', 'HEAD']);
|
|
}
|
|
const policy = (sealed: unknown) => JSON.stringify({ sealed }, null, 2) + '\n';
|
|
|
|
/** Drive the hook exactly as git does for `git push origin results` (a new remote branch). */
|
|
function hook(s: Scratch, extraEnv: Record<string, string> = {}) {
|
|
const head = sh(s.work, s.env, ['rev-parse', 'HEAD']);
|
|
const r = spawnSync('bun', [PREPUSH, 'origin', s.origin], { cwd: s.work, input: `refs/heads/results ${head} refs/heads/results ${ZERO}\n`, encoding: 'utf8', timeout: 60_000, env: { ...process.env, ...s.env, ...extraEnv } });
|
|
return { code: r.status, err: r.stderr ?? '' };
|
|
}
|
|
|
|
describe('pre-push hook: public destination refuses each kind of sealed output', () => {
|
|
test('a transcript, a sealed answer, a seed and a local home path each refuse, naming file, line and rule, never the matched text', () => {
|
|
const cases: Array<[Record<string, string | Buffer>, string, RegExp]> = [
|
|
[{ 'runs/cat40/cell-07/transcript.jsonl': '{"q":"x"}\n' }, 'sealed.transcript', /sealed\.transcript\s+runs\/cat40\/cell-07\/transcript\.jsonl/],
|
|
[{ 'runs/cat40/summary.md': 'intro\nSEALED ANSWER: fund-a led the round\n' }, 'sealed.answer', /sealed\.answer\s+runs\/cat40\/summary\.md:2/],
|
|
[{ 'runs/cat40/summary.md': 'run with shuffle_seed=42\n' }, 'sealed.seed', /sealed\.seed\s+runs\/cat40\/summary\.md:1/],
|
|
[{ 'runs/cat40/summary.md': 'raw at /home/user/.capy/work/evals/raw.jsonl\n' }, 'sealed.local_path', /sealed\.local_path\s+runs\/cat40\/summary\.md:1/],
|
|
];
|
|
for (const [files, rule, where] of cases) {
|
|
const s = scratch({ '.gstack/pregate.json': policy(SEALED) });
|
|
commit(s, files);
|
|
const r = hook(s);
|
|
expect(r.code).toBe(1);
|
|
expect(r.err).toMatch(where);
|
|
expect(r.err).toContain(rule);
|
|
expect(r.err).toContain('(SEALED_OUTPUT_REFUSED)');
|
|
expect(r.err).toContain('sealed.visibility');
|
|
expect(r.err).not.toContain('fund-a led');
|
|
}
|
|
});
|
|
|
|
test('path rules ignore content: a binary file, an empty transcript, an add-then-delete and a rename into a sealed path all refuse', () => {
|
|
const binary = scratch({ '.gstack/pregate.json': policy(SEALED) });
|
|
commit(binary, { 'heldout/questions.bin': Buffer.from([0, 1, 2, 0, 255, 0]) });
|
|
expect(hook(binary).err).toMatch(/sealed\.path\s+heldout\/questions\.bin/);
|
|
const empty = scratch({ '.gstack/pregate.json': policy(SEALED) });
|
|
commit(empty, { 'runs/c1/transcript.jsonl': '' });
|
|
expect(hook(empty).code).toBe(1);
|
|
const gone = scratch({ '.gstack/pregate.json': policy(SEALED) });
|
|
const added = commit(gone, { 'runs/c1/transcript.jsonl': '{"q":1}\n' });
|
|
commit(gone, { 'runs/c1/transcript.jsonl': null }, 'remove it again');
|
|
const g = hook(gone);
|
|
expect(g.code).toBe(1);
|
|
expect(g.err).toContain(`sealed.transcript runs/c1/transcript.jsonl commit ${added.slice(0, 12)}`);
|
|
const moved = scratch({ '.gstack/pregate.json': policy(SEALED) });
|
|
commit(moved, { 'scratch/t.jsonl': '{"q":1}\n{"q":2}\n{"q":3}\n' });
|
|
fs.mkdirSync(path.join(moved.work, 'heldout'));
|
|
sh(moved.work, moved.env, ['mv', 'scratch/t.jsonl', 'heldout/t.jsonl']);
|
|
sh(moved.work, moved.env, ['commit', '-q', '-m', 'move']);
|
|
expect(hook(moved).err).toMatch(/sealed\.path\s+heldout\/t\.jsonl/);
|
|
});
|
|
|
|
test('commits the destination already has are not this push: a branch from main that only adds a doc passes', () => {
|
|
const s = scratch({ 'runs/old/transcript.jsonl': '{"q":"published before the policy"}\n', '.gstack/pregate.json': policy(SEALED) });
|
|
commit(s, { 'docs/notes.md': 'notes\n' });
|
|
const r = hook(s);
|
|
expect(r.code).toBe(0);
|
|
expect(r.err).not.toContain('sealed.');
|
|
});
|
|
});
|
|
|
|
describe('policy union, waivers, private destinations and fail-closed parsing', () => {
|
|
test('a push can tighten the policy but never relax it: dropping the base sealed config does not let a transcript through', () => {
|
|
const s = scratch({ '.gstack/pregate.json': policy(SEALED) });
|
|
commit(s, { '.gstack/pregate.json': '{}\n', 'runs/c1/transcript.jsonl': '{}\n' });
|
|
expect(hook(s).code).toBe(1);
|
|
const tighten = scratch({ '.gstack/pregate.json': policy(SEALED) });
|
|
commit(tighten, { '.gstack/pregate.json': policy({ ...SEALED, paths: ['heldout/**', 'cells/**'] }), 'cells/c1.json': '{}\n' });
|
|
expect(hook(tighten).err).toMatch(/sealed\.path\s+cells\/c1\.json/);
|
|
});
|
|
|
|
test('a waiver counts only from the base branch allow file and is listed; the same line committed in the push is ignored', () => {
|
|
const s = scratch({ '.gstack/pregate.json': policy(SEALED) });
|
|
const sha = commit(s, { 'runs/c1/transcript.jsonl': '{}\n' });
|
|
const allow = `# rule\tpath\tsha\treason\nsealed.transcript\truns/c1/transcript.jsonl\t${sha.slice(0, 12)}\tsynthetic fixture, no sealed content\n`;
|
|
commit(s, { '.gstack/sealed-allow.tsv': allow });
|
|
expect(hook(s).code).toBe(1);
|
|
sh(s.work, s.env, ['checkout', '-q', 'main']);
|
|
write(s.work, { '.gstack/sealed-allow.tsv': allow });
|
|
sh(s.work, s.env, ['add', '-A']); sh(s.work, s.env, ['commit', '-q', '-m', 'allow']); sh(s.work, s.env, ['push', '-q', 'origin', 'main']);
|
|
sh(s.work, s.env, ['checkout', '-q', 'results']);
|
|
const r = hook(s);
|
|
expect(r.code).toBe(0);
|
|
expect(r.err).toContain('waived sealed.transcript runs/c1/transcript.jsonl');
|
|
});
|
|
|
|
test('a private destination (base override) warns and passes; a repo without the key sees no change; a malformed sealed policy refuses', () => {
|
|
const priv = scratch({ '.gstack/pregate.json': policy({ ...SEALED, visibility: 'private' }) });
|
|
commit(priv, { 'runs/c1/transcript.jsonl': '{}\n' });
|
|
const p = hook(priv);
|
|
expect(p.code).toBe(0);
|
|
expect(p.err).toMatch(/warning.*sealed\.transcript\s+runs\/c1\/transcript\.jsonl/s);
|
|
const none = scratch({});
|
|
commit(none, { 'runs/c1/transcript.jsonl': '{}\n' });
|
|
const n = hook(none);
|
|
expect(n.code).toBe(0);
|
|
expect(n.err).not.toContain('sealed');
|
|
const bad = scratch({ '.gstack/pregate.json': policy(SEALED) });
|
|
commit(bad, { '.gstack/pregate.json': policy({ paths: 'heldout/**' }), 'docs/x.md': 'x\n' });
|
|
const b = hook(bad);
|
|
expect(b.code).toBe(1);
|
|
expect(b.err).toContain('(SEALED_OUTPUT_REFUSED)');
|
|
expect(b.err).toContain('sealed policy');
|
|
});
|
|
});
|
|
|
|
describe('gstack-pregate sealed (the standalone preflight before any push or PR creation)', () => {
|
|
test('--range refuses the same findings with exit 1; the default range is what origin does not have yet', () => {
|
|
const s = scratch({ '.gstack/pregate.json': policy(SEALED) });
|
|
commit(s, { 'runs/c1/transcript.jsonl': '{}\n' });
|
|
const run = (args: string[]) => spawnSync(PREGATE, ['sealed', ...args], { cwd: s.work, encoding: 'utf8', timeout: 60_000, env: { ...process.env, ...s.env } });
|
|
const ranged = run(['--range', 'origin/main..HEAD', '--base', 'main']);
|
|
expect(ranged.status).toBe(1);
|
|
expect(ranged.stderr).toMatch(/sealed\.transcript\s+runs\/c1\/transcript\.jsonl/);
|
|
expect(ranged.stdout).toMatch(/^SEALED: refused findings=1 commits=1 visibility=unknown \(counted public\)/m);
|
|
const dflt = run(['--base', 'main']);
|
|
expect(dflt.status).toBe(1);
|
|
sh(s.work, s.env, ['push', '-q', 'origin', 'results']);
|
|
const after = run(['--base', 'main']);
|
|
expect(after.status).toBe(0);
|
|
expect(after.stdout).toMatch(/^SEALED: clear findings=0 commits=0/m);
|
|
});
|
|
});
|
|
|
|
describe('visibility (cache under the state root; unknown counts as public)', () => {
|
|
test('a public answer is cached; a cached private answer older than an hour is re-queried before it can downgrade; a failed lookup is unknown', () => {
|
|
const state = fs.mkdtempSync(path.join(os.tmpdir(), 'sealed-vis-'));
|
|
try {
|
|
let calls = 0;
|
|
let answer: string | null = 'PUBLIC';
|
|
const gh = () => { calls += 1; return answer === null ? { ok: false, out: '' } : { ok: true, out: JSON.stringify({ visibility: answer }) }; };
|
|
const env = { GSTACK_STATE_ROOT: state };
|
|
const t0 = Date.parse('2026-10-12T00:00:00Z');
|
|
expect(resolveVisibility('https://github.com/acme-example/evals.git', { env, gh, now: t0 }).visibility).toBe('public');
|
|
expect(resolveVisibility('https://github.com/acme-example/evals.git', { env, gh, now: t0 + 60_000 }).visibility).toBe('public');
|
|
expect(calls).toBe(1);
|
|
answer = 'PRIVATE';
|
|
expect(resolveVisibility('git@github.com:acme-example/private-evals.git', { env, gh, now: t0 }).visibility).toBe('private');
|
|
expect(resolveVisibility('git@github.com:acme-example/private-evals.git', { env, gh, now: t0 + 30 * 60_000 }).visibility).toBe('private');
|
|
expect(calls).toBe(2);
|
|
answer = null;
|
|
const stale = resolveVisibility('git@github.com:acme-example/private-evals.git', { env, gh, now: t0 + 2 * 3600_000 });
|
|
expect(calls).toBe(3);
|
|
expect(stale.visibility).toBe('unknown');
|
|
expect(resolveVisibility('/srv/git/evals.git', { env, gh, now: t0 }).visibility).toBe('unknown');
|
|
expect(calls).toBe(3);
|
|
expect(fs.existsSync(path.join(state, 'sealed-visibility.json'))).toBe(true);
|
|
} finally { fs.rmSync(state, { recursive: true, force: true }); }
|
|
});
|
|
});
|