mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-24 09:01:28 +01:00
Review and ship tools: read Codex numbered severities, check Remote Control sessions, see every worktree (#4681)
Five fixes from outside reports. The too-large-diff fix line now suggests only folders the policy can exclude, Codex findings written as `### 1. High` keep their severity, /autoplan's report check runs in Remote Control sessions, /ship's version picker sees all worktrees, and PR before/after images use the real base. Why: each reproduced on main with a failing test and gave a wrong answer. Nothing to do after merge. Co-authored-by: larsonthune <195244869+larsonthune@users.noreply.github.com> Co-authored-by: vilano93 <244097767+vilano93@users.noreply.github.com> Co-authored-by: szsunyuan <3579304+szsunyuan@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p1/red-team#1 reader=red-team
This commit is contained in:
13 files changed
+250
-39
No files matched your search
@@ -66,7 +66,7 @@ describe('Autoplan hook journal-root verdicts', () => {
|
||||
const entry = path.join(ROOT, 'autoplan/sections/design-phase.md');
|
||||
const real = JSON.parse(fs.readFileSync(path.join(ROOT, 'test/fixtures/claude-native-journal-roots-2.1.284.json'), 'utf8'));
|
||||
/** One owned native journal; the current phase-entry Read is its last record unless `current` is false. */
|
||||
function session(shape: 'unknown' | 'competing_root' | 'foreign_cwd' | 'sidechain' | 'agent' | 'cycle' | 'startup',
|
||||
function session(shape: 'unknown' | 'competing_root' | 'foreign_cwd' | 'sidechain' | 'agent' | 'cycle' | 'startup' | 'bridge' | 'bridge_competing',
|
||||
{ current = true, partial = false } = {}) {
|
||||
const base = fs.realpathSync(fs.mkdtempSync(path.join(tmpdir(), 'autoplan-hook-roots-'))); dirs.push(base);
|
||||
const cwd = path.join(base, 'project'), project = path.join(base, 'config', 'projects', 'project');
|
||||
@@ -84,10 +84,13 @@ describe('Autoplan hook journal-root verdicts', () => {
|
||||
rows = real.journals.startup.lines.map((line: string) => JSON.parse(line.replaceAll('__CWD__', JSON.stringify(cwd).slice(1, -1))));
|
||||
for (const row of rows as any[]) if (row.sessionId) row.sessionId = sessionId;
|
||||
} else {
|
||||
const head = shape === 'unknown' ? node(null, { type: 'system', subtype: 'local_command' }) : hook(null);
|
||||
const head = shape === 'unknown' ? node(null, { type: 'system', subtype: 'local_command' })
|
||||
: shape.startsWith('bridge') ? node(null, { type: 'system', subtype: 'bridge_status', isMeta: false,
|
||||
content: '/remote-control is active', url: 'https://claude.ai/code/session_x' })
|
||||
: hook(null);
|
||||
const turn = prompt(head.uuid);
|
||||
rows = [head, turn];
|
||||
if (shape === 'competing_root') rows.push(prompt(null));
|
||||
rows = shape.startsWith('bridge') ? [{ type: 'bridge-session', sessionId }, head, turn, hook(turn.uuid)] : [head, turn];
|
||||
if (shape === 'competing_root' || shape === 'bridge_competing') rows.push(prompt(null));
|
||||
if (shape === 'foreign_cwd') Object.assign(head, { cwd: path.join(base, 'config') });
|
||||
if (shape === 'sidechain') Object.assign(head, { isSidechain: true });
|
||||
if (shape === 'agent') Object.assign(head, { agentId: 'agent-1' });
|
||||
@@ -171,6 +174,22 @@ describe('Autoplan hook journal-root verdicts', () => {
|
||||
expect(output.hookSpecificOutput.permissionDecisionReason).toContain('Autoplan invocation evidence is unavailable');
|
||||
});
|
||||
|
||||
// Value: protects=a session with Remote Control active from the start (a system bridge_status record as the journal
|
||||
// root, #4298) is owned and verified like a plain session, while a competing root next to it still denies;
|
||||
// fails_when=the bridge head reads as unrecognized_shape and publication enforcement is skipped, or the new
|
||||
// preamble record hides a second root; why_new=only SessionStart attachments were accepted above the first turn; seam=none
|
||||
test('a Remote Control bridge_status root is owned and reaches publication evaluation', async () => {
|
||||
const output = await session('bridge').hookRun();
|
||||
expect(output.systemMessage ?? '').not.toContain('NOT verified');
|
||||
expect(output.hookSpecificOutput.permissionDecision).toBe('deny');
|
||||
expect(output.hookSpecificOutput.permissionDecisionReason).toContain('Autoplan invocation evidence is unavailable');
|
||||
});
|
||||
test('a bridge_status root next to a second null-parent prompt is still a competing root', async () => {
|
||||
const output = await session('bridge_competing').hookRun();
|
||||
expect(output.hookSpecificOutput.permissionDecision).toBe('deny');
|
||||
expect(output.hookSpecificOutput.permissionDecisionReason).toContain('code competing_root');
|
||||
});
|
||||
|
||||
test('the shipped shim degrades and denies with real native spellings', () => {
|
||||
// On Windows the hook env and transcript arrive spelled C:/...; the fold must accept them.
|
||||
const forward = (value: string) => process.platform === 'win32' ? value.replaceAll('\\', '/') : value;
|
||||
|
||||
@@ -1378,3 +1378,44 @@ describe("concurrent VERSION fetches (W2-A3)", () => {
|
||||
}
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
describe("sibling scan finds git worktrees outside the workspace_root layout (#4196)", () => {
|
||||
const NEXTVER = join(import.meta.dir, "..", "bin", "gstack-next-version");
|
||||
|
||||
// Value: protects=a linked worktree anywhere on disk (Claude Code's .claude/worktrees, plain git worktree add) counts
|
||||
// as a sibling when /ship picks a version, and workspace_root null still turns the scan off; fails_when=only
|
||||
// <workspace_root>/<repo>/<workspace>/ is read, so two worktrees can take the same version; why_new=every sibling
|
||||
// case used the Conductor layout or disabled the scan; seam=none
|
||||
test("a linked worktree outside workspace_root is a sibling; null disables the scan", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "nextver-wt-"));
|
||||
const work = join(root, "work");
|
||||
mkdirSync(work);
|
||||
const git = (cwd: string, ...args: string[]) =>
|
||||
execFileSync("git", ["-c", "user.email=t@t", "-c", "user.name=t", ...args], { cwd, stdio: ["ignore", "pipe", "pipe"], timeout: 30_000 });
|
||||
git(work, "init", "-q", "-b", "main");
|
||||
writeFileSync(join(work, "VERSION"), "1.0.0.0\n");
|
||||
git(work, "add", "-A");
|
||||
git(work, "commit", "-qm", "base");
|
||||
const wt = join(root, "elsewhere", "wt1");
|
||||
git(work, "worktree", "add", "-q", "-b", "feat", wt);
|
||||
writeFileSync(join(wt, "VERSION"), "1.0.1.0\n");
|
||||
git(wt, "commit", "-qam", "bump");
|
||||
const stubDir = mkdtempSync(join(tmpdir(), "nextver-stubgh-"));
|
||||
writeFileSync(join(stubDir, "gh"), "#!/bin/sh\nexit 1\n", { mode: 0o755 });
|
||||
const run = (workspaceRoot: string) => {
|
||||
const proc = Bun.spawnSync(
|
||||
["bun", "run", NEXTVER, "--base", "main", "--bump", "patch", "--current-version", "1.0.0.0", "--workspace-root", workspaceRoot],
|
||||
{ cwd: work, env: { ...process.env, PATH: `${stubDir}:${process.env.PATH}` }, timeout: 30_000 },
|
||||
);
|
||||
return JSON.parse(new TextDecoder().decode(proc.stdout));
|
||||
};
|
||||
try {
|
||||
const found = run(join(root, "no-such-root"));
|
||||
expect(found.siblings.map((s: any) => [s.branch, s.version])).toEqual([["feat", "1.0.1.0"]]);
|
||||
expect(run("null").siblings).toEqual([]);
|
||||
} finally {
|
||||
rmSync(stubDir, { recursive: true, force: true });
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -114,3 +114,35 @@ describe('design proposals use the proposal gate', () => {
|
||||
expect(outsideVoiceCommand({ ...ctx, skillName: 'plan-ceo-review' }, { timeoutMs: 300000 })).toMatch(/ review "\$_OUTSIDE_TMP\/text"/);
|
||||
});
|
||||
});
|
||||
|
||||
// Value: protects=a numbered heading (`### 1. High — title`, as Codex writes findings) carries its severity word;
|
||||
// fails_when=the label start allows only one prefix, so no severity is read and a completed review comes back
|
||||
// untagged_review; why_new=every label case had a heading or a number, never both; seam=none
|
||||
describe('a numbered heading carries its severity word', () => {
|
||||
for (const [heading, highest] of [
|
||||
['### 1. High — Make it look good silently removes editing', 'P1'],
|
||||
['## 2. Critical — The security model protects the session, not the document', 'P0'],
|
||||
['### 3. Medium — Batch import is a toast, not a workflow', 'P2'],
|
||||
['### 4. [P1] Tagged numbered heading', 'P1'],
|
||||
] as const) {
|
||||
test(heading, () => {
|
||||
const text = `${heading}\nBody text.\nRecommendation: fix it because the change loses data.\n\nVERDICT: FINDINGS\n`;
|
||||
const result = classifyOutsideReview({ text, exitCode: 0, stderr: '', events: '' } as never);
|
||||
expect(result.findings?.highest).toBe(highest);
|
||||
expect(result.reason).not.toBe('untagged_review');
|
||||
});
|
||||
}
|
||||
test('prose "high-level" under a numbered heading is still not a label', () => {
|
||||
const text = `### 1. A high-level concern about naming\nBody.\nRecommendation: rename it because readers guess wrong.\n\nVERDICT: FINDINGS\n`;
|
||||
const result = classifyOutsideReview({ text, exitCode: 0, stderr: '', events: '' } as never);
|
||||
expect(result.findings?.highest ?? null).toBeNull();
|
||||
});
|
||||
// Value: protects=a clean second-model review laid out under numbered section headings stays clean; fails_when=numbered
|
||||
// headings count as unlabeled findings and a VERDICT: CLEAN reply reads as untagged_review; why_new=only FINDINGS replies
|
||||
// with numbered headings were tested; seam=none
|
||||
test('a CLEAN review with numbered section headings stays clean', () => {
|
||||
const text = '## 1. Scope\nI read the diff.\n## 2. Result\nNothing found.\nRecommendation: ship because no issue was found.\n\nVERDICT: CLEAN\n';
|
||||
const result = classifyOutsideReview({ text, exitCode: 0, stderr: '', events: '', gate: 'review' } as never);
|
||||
expect(result.verdict).toBe('clean');
|
||||
});
|
||||
});
|
||||
+45
-1
@@ -9,7 +9,7 @@ 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 { buildPage, cleanText, diffLines, hunks, pathSides, resolveCommit } from '../lib/pr-shots';
|
||||
import { buildPage, cleanText, defaultBase, diffLines, hunks, pathSides, resolveCommit } from '../lib/pr-shots';
|
||||
import { wtreeFingerprint } from '../lib/script-invocation';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
@@ -27,6 +27,50 @@ function repo(files: Record<string, string>): { dir: string; base: string } {
|
||||
return { dir, base: git('rev-parse', 'HEAD').stdout.trim() };
|
||||
}
|
||||
|
||||
describe('default base (#3733)', () => {
|
||||
const featureRepo = (baseBranch: string) => {
|
||||
const r = repo({ 'doc.md': 'before\n' });
|
||||
const git = (...a: string[]) => {
|
||||
const out = spawnSync('git', a, { cwd: r.dir, encoding: 'utf8', env: GIT_ENV, timeout: 30_000 });
|
||||
if (out.status !== 0) throw new Error(`fixture git ${a.join(' ')} failed: ${out.stderr}`);
|
||||
return out.stdout.trim();
|
||||
};
|
||||
if (baseBranch !== 'main') git('branch', '-m', baseBranch);
|
||||
const origin = tmp('shots-origin-');
|
||||
git('init', '-q', '--bare', '--initial-branch', baseBranch, origin);
|
||||
git('remote', 'add', 'origin', origin);
|
||||
git('push', '-q', '-u', 'origin', baseBranch);
|
||||
git('remote', 'set-head', 'origin', baseBranch);
|
||||
git('checkout', '-q', '-b', 'feature');
|
||||
fs.writeFileSync(path.join(r.dir, 'doc.md'), 'after\n');
|
||||
git('add', 'doc.md'); git('commit', '-q', '-m', 'feature text');
|
||||
git('push', '-q', '-u', 'origin', 'feature');
|
||||
return { ...r, git };
|
||||
};
|
||||
|
||||
// Value: protects=a clone whose origin/HEAD names the pushed feature branch still compares against the real base, so
|
||||
// committed PR changes show; fails_when=the feature head is its own before-image and generation refuses with
|
||||
// PR_SHOTS_IDENTICAL; why_new=path-mode tests always passed --base; seam=none
|
||||
test.each(['main', 'develop'])('origin/HEAD naming the feature branch still compares against %s', baseBranch => {
|
||||
const r = featureRepo(baseBranch);
|
||||
expect(defaultBase(r.dir)).toBe(r.base);
|
||||
r.git('remote', 'set-head', 'origin', 'feature');
|
||||
const chosen = defaultBase(r.dir);
|
||||
expect(chosen).toBe(r.base);
|
||||
const sides = pathSides(r.dir, 'doc.md', chosen as string);
|
||||
if ('code' in sides) throw new Error(sides.message);
|
||||
expect([sides.before.text, sides.after.text]).toEqual(['before\n', 'after\n']);
|
||||
});
|
||||
|
||||
// Value: protects=a stale origin/HEAD (its branch is gone) falls back to main instead of refusing; fails_when=the
|
||||
// dangling target is taken as the base with no fallback; why_new=the case above always resolves; seam=none
|
||||
test('a dangling origin/HEAD falls back to main', () => {
|
||||
const r = featureRepo('main');
|
||||
r.git('symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/retired');
|
||||
expect(defaultBase(r.dir)).toBe(r.base);
|
||||
});
|
||||
});
|
||||
|
||||
describe('diff and hunks', () => {
|
||||
test('a change at line 240 of 300 stays visible; gaps say how much they hide', () => {
|
||||
const a = Array.from({ length: 300 }, (_, i) => `line ${i + 1}`);
|
||||
|
||||
@@ -267,6 +267,26 @@ describe('the review ceiling lines', () => {
|
||||
expect(over).toEndWith('nothing was written (REVIEW_DIFF_TOO_LARGE)');
|
||||
});
|
||||
|
||||
// Value: protects=the printed policy names only folders whose files the policy can exclude (content, never code or
|
||||
// tests), says split the PR when excludable bytes cannot reach the ceiling, and never asks again for a policy that is
|
||||
// already landed; fails_when=a code-only folder is suggested, or the active line repeats the landed patterns (#4369);
|
||||
// why_new=every ceiling case had a content-only top folder; seam=tooLargeLine; no_claim=the policy's consumer checks
|
||||
test('the fix suggests only excludable folders, and says split when the policy cannot get under the ceiling', () => {
|
||||
const json = (line: string) => JSON.parse(line.match(/land (\{.*?\}) in /)![1]!);
|
||||
const codeHeavy = { bytes: 2_378_104, byDir: [['src', 2_029_068], ['docs', 349_036]] as Array<[string, number]>,
|
||||
byFile: [['src/mod0.ts', 676_380], ['src/mod1.ts', 676_357], ['src/mod2.ts', 676_331], ['docs/guide.md', 349_036]] as Array<[string, number]> };
|
||||
const none = tooLargeLine('ctx', 'batched', codeHeavy, { state: 'none', base: 'main', source: 'origin/main@abc' }).line;
|
||||
expect(none).not.toContain('review_exclude_paths');
|
||||
expect(none).toContain('fix: split the PR (largest files: src/mod0.ts');
|
||||
const landed = tooLargeLine('ctx', 'batched', codeHeavy, { state: 'active', base: 'main', source: 'origin/main@abc', record: { patterns: ['src/**'], excluded: 0 } }).line;
|
||||
expect(landed).toContain('still over after excluding 0 files; split the PR');
|
||||
const mixed = { bytes: 3_000_000, byDir: [['src', 1_600_000], ['results', 1_400_000]] as Array<[string, number]>,
|
||||
byFile: [['src/a.ts', 1_600_000], ['results/run.jsonl', 1_400_000]] as Array<[string, number]> };
|
||||
expect(json(tooLargeLine('ctx', 'batched', mixed, { state: 'none', base: 'main', source: 'origin/main@abc' }).line).review_exclude_paths).toEqual(['results/**']);
|
||||
const again = tooLargeLine('ctx', 'batched', mixed, { state: 'active', base: 'main', source: 'origin/main@abc', record: { patterns: ['results/**'], excluded: 0 } }).line;
|
||||
expect(again).toContain('still over after excluding 0 files; split the PR');
|
||||
});
|
||||
|
||||
// Value: protects=a REVIEW_DIFF_UNREADABLE stop says timeout or git exit, the timeout, and keeps full stderr in a file with
|
||||
// remote URLs redacted; fails_when=a credential-bearing remote URL reaches the line or the log, or the fix ignores the
|
||||
// reason; why_new=task 5; seam=readSelection and unreadableLine; no_claim=a real 120-second timeout
|
||||
|
||||
Reference in new issue
Block a user