mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-29 19:34:29 +01:00
/codex cleanup stops asking for /careful approval, and plan-mode Codex reviews start again (#4851)
`/codex challenge` and `/codex consult` no longer stop for a /careful delete warning on every run, and the Codex second-model review in `/plan-eng-review` and `/plan-ceo-review` works in Claude Code plan mode again. Why: both broke a core review path on every use; the reports came from @dmfrede and @mcp10. Nothing to do after merge. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=security
This commit is contained in:
1 parent
77da8a0160
commit
be64b10297
12 files changed
+147
-30
No files matched your search
@@ -0,0 +1,6 @@
|
||||
---
|
||||
important: regression
|
||||
---
|
||||
**`/codex challenge` and `/codex consult` no longer stop for a /careful delete warning at the end of every run.** Their cleanup deleted the prompt file through a variable the safety check could not resolve, so it asked every time; the cleanup now uses a guarded variable the check accepts. Thanks @dmfrede (#4841).
|
||||
|
||||
- **The Codex second-model review in `/plan-eng-review` and `/plan-ceo-review` works in Claude Code plan mode again.** The prompt file was created under `$TMPDIR`, where plan mode refuses Write, so Codex never started. It is now created in the project's `.gstack/tmp/` (never through a symlinked `.gstack` folder) and deleted with a plain `rm` of that one path. Thanks @mcp10 (#4842).
|
||||
@@ -113,7 +113,7 @@ if grep -qiE "auth|login|unauthorized" "$TMPERR" 2>/dev/null; then
|
||||
"$_CODEX_PROBE" log-event codex_auth_failed
|
||||
fi
|
||||
bun --no-env-file --config=/dev/null ~/.claude/skills/gstack/lib/outside-review-result.ts --label 'Codex challenge' --exit "$_CODEX_EXIT" --stderr "$TMPERR" --events "$TMPRESP.events" execution "$TMPRESP"
|
||||
rm -f "$TMPRESP" "$TMPRESP.events" "$PROMPT_FILE"
|
||||
rm -f "$TMPRESP" "$TMPRESP.events" "${PROMPT_FILE:?}"
|
||||
```
|
||||
|
||||
`VERDICT: unavailable` means the challenge did not run (its line names why, such as a
|
||||
|
||||
@@ -99,7 +99,7 @@ if grep -qiE "auth|login|unauthorized" "$TMPERR" 2>/dev/null; then
|
||||
"$_CODEX_PROBE" log-event codex_auth_failed
|
||||
fi
|
||||
bun --no-env-file --config=/dev/null ~/.claude/skills/gstack/lib/outside-review-result.ts --label 'Codex challenge' --exit "$_CODEX_EXIT" --stderr "$TMPERR" --events "$TMPRESP.events" execution "$TMPRESP"
|
||||
rm -f "$TMPRESP" "$TMPRESP.events" "$PROMPT_FILE"
|
||||
rm -f "$TMPRESP" "$TMPRESP.events" "${PROMPT_FILE:?}"
|
||||
```
|
||||
|
||||
`VERDICT: unavailable` means the challenge did not run (its line names why, such as a
|
||||
|
||||
@@ -173,7 +173,7 @@ elif [ "$_CODEX_EXIT" != "0" ]; then
|
||||
"$_CODEX_PROBE" log-event codex_nonzero_exit "$_LABEL:$_CODEX_EXIT"
|
||||
fi
|
||||
bun --no-env-file --config=/dev/null ~/.claude/skills/gstack/lib/outside-review-result.ts --label 'Codex consult' --exit "$_CODEX_EXIT" --stderr "$TMPERR" --events "$TMPRESP.events" execution "$TMPRESP"
|
||||
rm -f "$PROMPT_FILE"
|
||||
rm -f "${PROMPT_FILE:?}"
|
||||
```
|
||||
|
||||
`VERDICT: unavailable` means Codex did not answer from a working
|
||||
|
||||
@@ -159,7 +159,7 @@ elif [ "$_CODEX_EXIT" != "0" ]; then
|
||||
"$_CODEX_PROBE" log-event codex_nonzero_exit "$_LABEL:$_CODEX_EXIT"
|
||||
fi
|
||||
bun --no-env-file --config=/dev/null ~/.claude/skills/gstack/lib/outside-review-result.ts --label 'Codex consult' --exit "$_CODEX_EXIT" --stderr "$TMPERR" --events "$TMPRESP.events" execution "$TMPRESP"
|
||||
rm -f "$PROMPT_FILE"
|
||||
rm -f "${PROMPT_FILE:?}"
|
||||
```
|
||||
|
||||
`VERDICT: unavailable` means Codex did not answer from a working
|
||||
|
||||
@@ -451,12 +451,12 @@ THE PLAN:
|
||||
|
||||
**If `CODEX_MODE: ready` — run Codex:**
|
||||
|
||||
Run this block for `ready`, in the one foreground Bash call described below.
|
||||
Run this block for `ready`, in the one foreground Bash call.
|
||||
Its opening harness guard rechecks the fresh shell: exit 78 uses the same Native
|
||||
fallback below, never a replacement provider. Finish termination before fallback and consume only
|
||||
completed output. Use private temporary paths, with no background jobs.
|
||||
completed output. No background jobs.
|
||||
|
||||
Create a private prompt file: run `umask 077; mktemp "${TMPDIR:-/tmp}/gstack-plan-prompt.XXXXXXXX"` in Bash and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in that file. Substitute its shell-quoted path for `<prepared-prompt-file>`; never interpolate user text into shell source. Request severity (Critical, High, Medium or Low) per finding and the prompt's Recommendation and VERDICT lines.
|
||||
Create a private prompt file: run `[ ! -L .gstack -a ! -L .gstack/tmp ] && mkdir -p -m700 .gstack/tmp && mktemp "$PWD/.gstack/tmp/gstack-plan-prompt.XXXXXX"` and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in it. Substitute its shell-quoted path for `<prepared-prompt-file>`; never interpolate user text into shell source. Request severity (Critical, High, Medium or Low) per finding and the prompt's Recommendation and VERDICT lines.
|
||||
|
||||
```bash
|
||||
# GSTACK_ACTIVE_HOST names the harness, never the model.
|
||||
@@ -495,7 +495,7 @@ esac
|
||||
echo 'OUTSIDE_STATUS: completed provider=codex host=claude'
|
||||
```
|
||||
|
||||
Use Bash `timeout: 360000`; show the full response in a `tool-output` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing Recommendation: <action> because <reason> markers, timeout or CLI failure means `outside_status: unavailable`. P0/P1 findings block like native ones; `OUTSIDE_STATUS: unverified` is missing coverage. Use the caller's fallback; missing coverage is never clean/PASS. After either outcome, delete only your private prompt; scratch cleanup is automatic.
|
||||
Use Bash `timeout: 360000`; show the full response in a `tool-output` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing Recommendation: <action> because <reason> markers, timeout or CLI failure means `outside_status: unavailable`. P0/P1 findings block like native ones; `OUTSIDE_STATUS: unverified` is missing coverage. Use the caller's fallback; missing coverage is never clean/PASS. After either outcome, run `rm -- '<prepared-prompt-file>'`; scratch cleanup is automatic.
|
||||
|
||||
Present the full output verbatim:
|
||||
|
||||
|
||||
@@ -966,12 +966,12 @@ THE PLAN:
|
||||
|
||||
**If `CODEX_MODE: ready` — run Codex:**
|
||||
|
||||
Run this block for `ready`, in the one foreground Bash call described below.
|
||||
Run this block for `ready`, in the one foreground Bash call.
|
||||
Its opening harness guard rechecks the fresh shell: exit 78 uses the same Native
|
||||
fallback below, never a replacement provider. Finish termination before fallback and consume only
|
||||
completed output. Use private temporary paths, with no background jobs.
|
||||
completed output. No background jobs.
|
||||
|
||||
Create a private prompt file: run `umask 077; mktemp "${TMPDIR:-/tmp}/gstack-plan-prompt.XXXXXXXX"` in Bash and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in that file. Substitute its shell-quoted path for `<prepared-prompt-file>`; never interpolate user text into shell source. Request severity (Critical, High, Medium or Low) per finding and the prompt's Recommendation and VERDICT lines.
|
||||
Create a private prompt file: run `[ ! -L .gstack -a ! -L .gstack/tmp ] && mkdir -p -m700 .gstack/tmp && mktemp "$PWD/.gstack/tmp/gstack-plan-prompt.XXXXXX"` and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in it. Substitute its shell-quoted path for `<prepared-prompt-file>`; never interpolate user text into shell source. Request severity (Critical, High, Medium or Low) per finding and the prompt's Recommendation and VERDICT lines.
|
||||
|
||||
```bash
|
||||
# GSTACK_ACTIVE_HOST names the harness, never the model.
|
||||
@@ -1010,7 +1010,7 @@ esac
|
||||
echo 'OUTSIDE_STATUS: completed provider=codex host=claude'
|
||||
```
|
||||
|
||||
Use Bash `timeout: 360000`; show the full response in a `tool-output` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing Recommendation: <action> because <reason> markers, timeout or CLI failure means `outside_status: unavailable`. P0/P1 findings block like native ones; `OUTSIDE_STATUS: unverified` is missing coverage. Use the caller's fallback; missing coverage is never clean/PASS. After either outcome, delete only your private prompt; scratch cleanup is automatic.
|
||||
Use Bash `timeout: 360000`; show the full response in a `tool-output` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing Recommendation: <action> because <reason> markers, timeout or CLI failure means `outside_status: unavailable`. P0/P1 findings block like native ones; `OUTSIDE_STATUS: unverified` is missing coverage. Use the caller's fallback; missing coverage is never clean/PASS. After either outcome, run `rm -- '<prepared-prompt-file>'`; scratch cleanup is automatic.
|
||||
|
||||
Present the full output verbatim:
|
||||
|
||||
|
||||
@@ -416,10 +416,10 @@ function codexPlanReviewRun(ctx: TemplateContext, ceo: boolean, needsApprovalRea
|
||||
// (gates 40477638211 and 40454750574: every judge sample read "(or unverified)" as a branch nothing can enter).
|
||||
return `**If \`CODEX_MODE: ready\` — run ${outsideVoiceFor(ctx).label}:**
|
||||
|
||||
${['plan-ceo-review', 'plan-eng-review'].includes(ctx.skillName) ? `Run this block for \`ready\`, in the one foreground Bash call described below.
|
||||
${['plan-ceo-review', 'plan-eng-review'].includes(ctx.skillName) ? `Run this block for \`ready\`, in the one foreground Bash call.
|
||||
Its opening harness guard rechecks the fresh shell: exit 78 uses the same Native
|
||||
fallback below, never a replacement provider. Finish termination before fallback and consume only
|
||||
completed output. Use private temporary paths, with no background jobs.` : `Run the selected backend in the one foreground Bash invocation described below.
|
||||
completed output. No background jobs.` : `Run the selected backend in the one foreground Bash invocation described below.
|
||||
Finish a failed attempt's termination before fallback; consume only its completed
|
||||
output. No background jobs or shared temporary paths.`}
|
||||
|
||||
|
||||
@@ -177,8 +177,9 @@ export function outsideVoiceInvocation(ctx: TemplateContext, requested: OutsideC
|
||||
: planRecommendation
|
||||
? "Request severity (Critical, High, Medium or Low) per finding and the prompt's Recommendation and VERDICT lines."
|
||||
: `Request severity (Critical, High, Medium or Low) per finding, a Recommendation: <action> because <reason> line, and ${VERDICT_LAST_LINE}.`;
|
||||
const preparation = `${['plan-ceo-review', 'plan-eng-review'].includes(ctx.skillName)
|
||||
? 'Create a private prompt file: run `umask 077; mktemp "${TMPDIR:-/tmp}/gstack-plan-prompt.XXXXXXXX"` in Bash and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in that file'
|
||||
const planPrompt = ['plan-ceo-review', 'plan-eng-review'].includes(ctx.skillName);
|
||||
const preparation = `${planPrompt
|
||||
? 'Create a private prompt file: run `[ ! -L .gstack -a ! -L .gstack/tmp ] && mkdir -p -m700 .gstack/tmp && mktemp "$PWD/.gstack/tmp/gstack-plan-prompt.XXXXXX"` and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in it'
|
||||
: 'Write the **complete prompt and context**, including actual plan/spec/source, to a private file'}${outsideVoiceFor(ctx).id === 'claude-code' ? ' (Claude Code has no tools, git or path access)' : ''}. Substitute its shell-quoted path for \`<prepared-prompt-file>\`; never interpolate user text into shell source. ${completion}`;
|
||||
return `${preparation}
|
||||
|
||||
@@ -186,7 +187,7 @@ export function outsideVoiceInvocation(ctx: TemplateContext, requested: OutsideC
|
||||
${outsideVoiceCommand(ctx, opts)}
|
||||
\`\`\`
|
||||
|
||||
Use Bash \`timeout: ${gateMs}\`; show the full response in a \`tool-output\` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing ${planRecommendation ? 'Recommendation: <action> because <reason>' : opts.purpose === 'design-direction' ? 'Recommendation' : 'score/severity/completion'} markers, timeout or CLI failure means \`outside_status: unavailable\`. P0/P1 findings block like native ones; \`OUTSIDE_STATUS: unverified\` is missing coverage. ${opts.purpose === 'design-direction' ? 'Continue completed proposals; native completion does not count as outside coverage.' : opts.nativeAlreadyRequired === 'dispatched' ? 'A dispatched native pass runs once either way; outside output cannot complete it.' : opts.nativeAlreadyRequired ? 'Retain the required native pass without duplicating it; it cannot complete outside coverage.' : "Use the caller's fallback; missing coverage is never clean/PASS."} After either outcome, delete only your private prompt; scratch cleanup is automatic.`;
|
||||
Use Bash \`timeout: ${gateMs}\`; show the full response in a \`tool-output\` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing ${planRecommendation ? 'Recommendation: <action> because <reason>' : opts.purpose === 'design-direction' ? 'Recommendation' : 'score/severity/completion'} markers, timeout or CLI failure means \`outside_status: unavailable\`. P0/P1 findings block like native ones; \`OUTSIDE_STATUS: unverified\` is missing coverage. ${opts.purpose === 'design-direction' ? 'Continue completed proposals; native completion does not count as outside coverage.' : opts.nativeAlreadyRequired === 'dispatched' ? 'A dispatched native pass runs once either way; outside output cannot complete it.' : opts.nativeAlreadyRequired ? 'Retain the required native pass without duplicating it; it cannot complete outside coverage.' : "Use the caller's fallback; missing coverage is never clean/PASS."} After either outcome, ${planPrompt ? "run `rm -- '<prepared-prompt-file>'`" : 'delete only your private prompt'}; scratch cleanup is automatic.`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,10 @@ import * as path from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
// The plan skills' own prompt-file command (#4842): it creates the prompt in the project's .gstack/tmp/.
|
||||
const PROMPT_CREATE = [...fs.readFileSync(path.join(ROOT, 'plan-ceo-review/sections/review-sections.md'), 'utf8')
|
||||
.matchAll(/`([^`\n]+)`/g)].map(m => m[1]).filter(s => s.includes('gstack-plan-prompt'));
|
||||
if (PROMPT_CREATE.length !== 1) throw Error('expected one plan prompt-file command, found ' + PROMPT_CREATE.length);
|
||||
const ORIGINAL_PLAN = `# Test Plan: add /greet skill
|
||||
|
||||
## Context
|
||||
@@ -175,13 +179,13 @@ mock.module(${JSON.stringify(path.join(ROOT, 'test/helpers/session-runner.ts'))}
|
||||
if (scenario === 'temp' || scenario === 'temp-retry') {
|
||||
const {hermeticChildEnv, getHermeticDirs} = await import(${JSON.stringify(path.join(ROOT, 'test/helpers/hermetic-env.ts'))});
|
||||
// Same final environment merge as session-runner. The original cf74
|
||||
// command created its file in inherited shard TMPDIR, beside both roots.
|
||||
// command created its file in inherited shard TMPDIR, beside both roots;
|
||||
// the generated command now creates it inside the project (#4842).
|
||||
const env = hermeticChildEnv({GSTACK_HEADLESS: '1', ...opts.env});
|
||||
const defaults = getHermeticDirs();
|
||||
const cleanupFiles = [];
|
||||
try {
|
||||
const command = 'umask 077; mktemp "$' + '{TMPDIR:-/tmp}/gstack-plan-prompt.XXXXXXXX"';
|
||||
const made = spawnSync('bash', ['-c', command], {cwd, env, encoding: 'utf8', timeout: 5000});
|
||||
const made = spawnSync('bash', ['-c', ${JSON.stringify(PROMPT_CREATE[0])}], {cwd, env, encoding: 'utf8', timeout: 5000});
|
||||
if (made.error || made.status !== 0) throw Error('Actual prompt mktemp failed: ' + made.stderr);
|
||||
const prompt = made.stdout.trim();
|
||||
const freeRoot = fs.realpathSync(${JSON.stringify(directory)});
|
||||
@@ -277,7 +281,7 @@ await import(${JSON.stringify(path.join(ROOT, 'test/skill-e2e-autoplan-dual-voic
|
||||
const temp = attempt.temp;
|
||||
const expected = path.join(attempt.env.HOME, 'tmp');
|
||||
expect(temp.env).toEqual({TMPDIR: expected, TEMP: expected, TMP: expected});
|
||||
expect(path.dirname(temp.prompt)).toBe(expected);
|
||||
expect(path.dirname(temp.prompt)).toBe(path.join(attempt.cwd, '.gstack', 'tmp'));
|
||||
expect(temp.directoryMode).toBe(0o700);
|
||||
expect(temp.promptMode).toBe(0o600);
|
||||
expect(temp.owned.claudeVoiceFired).toBe(true);
|
||||
|
||||
+9
-9
@@ -5,53 +5,53 @@
|
||||
"agy/gstack-autoplan": 109163,
|
||||
"agy/gstack-plan-design-review": 109100,
|
||||
"agy/gstack-plan-devex-review": 115130,
|
||||
"agy/gstack-plan-eng-review": 143744,
|
||||
"agy/gstack-plan-eng-review": 143742,
|
||||
"agy/gstack-review": 104939,
|
||||
"codex/gstack-autoplan": 107431,
|
||||
"codex/gstack-plan-design-review": 110375,
|
||||
"codex/gstack-plan-devex-review": 114416,
|
||||
"codex/gstack-plan-eng-review": 142687,
|
||||
"codex/gstack-plan-eng-review": 142685,
|
||||
"codex/gstack-review": 104273,
|
||||
"copilot/gstack-autoplan": 108606,
|
||||
"copilot/gstack-plan-design-review": 109366,
|
||||
"copilot/gstack-plan-devex-review": 114592,
|
||||
"copilot/gstack-plan-eng-review": 143909,
|
||||
"copilot/gstack-plan-eng-review": 143907,
|
||||
"copilot/gstack-review": 104520,
|
||||
"cursor/gstack-autoplan": 107838,
|
||||
"cursor/gstack-plan-design-review": 107908,
|
||||
"cursor/gstack-plan-devex-review": 113862,
|
||||
"cursor/gstack-plan-eng-review": 142499,
|
||||
"cursor/gstack-plan-eng-review": 142497,
|
||||
"cursor/gstack-review": 122992,
|
||||
"factory/gstack-autoplan": 110116,
|
||||
"factory/gstack-plan-design-review": 111006,
|
||||
"factory/gstack-plan-devex-review": 117225,
|
||||
"factory/gstack-plan-eng-review": 145607,
|
||||
"factory/gstack-plan-eng-review": 145605,
|
||||
"factory/gstack-review": 126765,
|
||||
"gbrain/gstack-autoplan": 108245,
|
||||
"gbrain/gstack-plan-eng-review": 125054,
|
||||
"gemini/gstack-autoplan": 108396,
|
||||
"gemini/gstack-plan-design-review": 109194,
|
||||
"gemini/gstack-plan-devex-review": 114420,
|
||||
"gemini/gstack-plan-eng-review": 143742,
|
||||
"gemini/gstack-plan-eng-review": 143740,
|
||||
"gemini/gstack-review": 104342,
|
||||
"hermes/gstack-autoplan": 108250,
|
||||
"hermes/gstack-plan-eng-review": 125007,
|
||||
"kiro/gstack-autoplan": 107612,
|
||||
"kiro/gstack-plan-design-review": 107754,
|
||||
"kiro/gstack-plan-devex-review": 113714,
|
||||
"kiro/gstack-plan-eng-review": 142361,
|
||||
"kiro/gstack-plan-eng-review": 142359,
|
||||
"kiro/gstack-review": 122816,
|
||||
"openclaw/gstack-autoplan": 108068,
|
||||
"openclaw/gstack-plan-eng-review": 123553,
|
||||
"opencode/gstack-autoplan": 108587,
|
||||
"opencode/gstack-plan-design-review": 109222,
|
||||
"opencode/gstack-plan-devex-review": 114470,
|
||||
"opencode/gstack-plan-eng-review": 143768,
|
||||
"opencode/gstack-plan-eng-review": 143766,
|
||||
"opencode/gstack-review": 123614,
|
||||
"slate/gstack-autoplan": 107725,
|
||||
"slate/gstack-plan-design-review": 107831,
|
||||
"slate/gstack-plan-devex-review": 113788,
|
||||
"slate/gstack-plan-eng-review": 142430,
|
||||
"slate/gstack-plan-eng-review": 142428,
|
||||
"slate/gstack-review": 122904
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Private prompt files for second-model reviews stay inside the project and clean up without a careful ask.
|
||||
*
|
||||
* #4841: /codex challenge and consult deleted their prompt with rm -f "$PROMPT_FILE". The assignment above it
|
||||
* holds a $, so careful/bin/check-careful.sh cannot resolve it and asks about a delete "through a variable that
|
||||
* may be empty" on every run. The cleanup now reads "${PROMPT_FILE:?}", which careful treats as guarded.
|
||||
*
|
||||
* #4842: /plan-ceo-review and /plan-eng-review created the prompt with mktemp under $TMPDIR, outside the project.
|
||||
* Claude Code's plan mode refuses a Write there, so Codex never started. The prompt now goes in the session folder's
|
||||
* .gstack/tmp/ (refusing a symlinked .gstack or .gstack/tmp), and its cleanup removes that one path without an ask.
|
||||
*/
|
||||
import { afterAll, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { usePrivateStateRoot } from './helpers/private-state-root';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const CHECK = path.join(ROOT, 'careful', 'bin', 'check-careful.sh');
|
||||
const scratch = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-prompt-file-')));
|
||||
usePrivateStateRoot();
|
||||
afterAll(() => fs.rmSync(scratch, { recursive: true, force: true }));
|
||||
|
||||
function bashFences(file: string): string[] {
|
||||
const text = fs.readFileSync(path.join(ROOT, file), 'utf8');
|
||||
return [...text.matchAll(/^```bash\n([\s\S]*?)\n```$/gm)].map(m => m[1]);
|
||||
}
|
||||
|
||||
function careful(command: string, cwd: string): string {
|
||||
const r = spawnSync('bash', [CHECK], {
|
||||
cwd, encoding: 'utf8', timeout: 30_000,
|
||||
input: JSON.stringify({ tool_name: 'Bash', tool_input: { command } }),
|
||||
env: { ...process.env, GSTACK_HOOK_CWD: cwd },
|
||||
});
|
||||
expect(r.status, r.stderr).toBe(0);
|
||||
return r.stdout.trim();
|
||||
}
|
||||
|
||||
function git(cwd: string, ...args: string[]): string {
|
||||
const r = spawnSync('git', args, { cwd, encoding: 'utf8', timeout: 30_000 });
|
||||
expect(r.status, r.stderr).toBe(0);
|
||||
return r.stdout;
|
||||
}
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('/codex prompt cleanup passes careful (#4841)', () => {
|
||||
for (const file of ['codex/sections/challenge-mode.md', 'codex/sections/consult-mode.md']) {
|
||||
test(file, () => {
|
||||
const block = bashFences(file).find(b => /^PROMPT_FILE=/m.test(b) && /^rm -f .*PROMPT_FILE/m.test(b));
|
||||
expect(block).toBeDefined();
|
||||
const lines = block!.split('\n');
|
||||
const cleanup = lines.find(l => /^rm -f .*PROMPT_FILE/.test(l))!;
|
||||
const names = new Set([...cleanup.matchAll(/\$\{?([A-Z_]+)/g)].map(m => m[1]));
|
||||
const assignments = lines.filter(l => names.has(l.split('=')[0]));
|
||||
expect(assignments.some(l => l.startsWith('PROMPT_FILE='))).toBe(true);
|
||||
expect(careful([...assignments, cleanup].join('\n'), scratch)).toBe('{}');
|
||||
expect(cleanup).toContain('"${PROMPT_FILE:?}"');
|
||||
expect(careful(block!, scratch)).toBe('{}');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('plan-review prompt file lives in the project (#4842)', () => {
|
||||
for (const skill of ['plan-ceo-review', 'plan-eng-review']) {
|
||||
test(skill, () => {
|
||||
const text = fs.readFileSync(path.join(ROOT, skill, 'sections', 'review-sections.md'), 'utf8');
|
||||
const spans = [...text.matchAll(/`([^`\n]+)`/g)].map(m => m[1]);
|
||||
const create = spans.filter(s => s.includes('gstack-plan-prompt'));
|
||||
expect(create).toHaveLength(1);
|
||||
expect(create[0]).not.toContain('TMPDIR');
|
||||
const cleanup = spans.filter(s => s.startsWith('rm ') && s.includes('<prepared-prompt-file>'));
|
||||
expect(cleanup).toEqual(["rm -- '<prepared-prompt-file>'"]);
|
||||
|
||||
const project = path.join(scratch, skill);
|
||||
fs.mkdirSync(project);
|
||||
git(project, 'init', '-q');
|
||||
const made = spawnSync('bash', ['-c', create[0]], { cwd: project, encoding: 'utf8', timeout: 30_000 });
|
||||
expect(made.status, made.stderr).toBe(0);
|
||||
const prompt = made.stdout.trim();
|
||||
expect(path.dirname(prompt)).toBe(path.join(project, '.gstack', 'tmp'));
|
||||
expect(path.basename(prompt).startsWith('gstack-plan-prompt.')).toBe(true);
|
||||
expect(fs.statSync(prompt).mode & 0o777).toBe(0o600);
|
||||
expect(fs.statSync(path.dirname(prompt)).mode & 0o777).toBe(0o700);
|
||||
fs.writeFileSync(prompt, 'review this plan');
|
||||
|
||||
const remove = cleanup[0].replace('<prepared-prompt-file>', prompt);
|
||||
expect(careful(remove, project)).toBe('{}');
|
||||
const removed = spawnSync('bash', ['-c', remove], { cwd: project, encoding: 'utf8', timeout: 30_000 });
|
||||
expect(removed.status, removed.stderr).toBe(0);
|
||||
expect(fs.existsSync(prompt)).toBe(false);
|
||||
|
||||
// A cloned repo can commit .gstack or .gstack/tmp as a symlink; the prompt must never land where it points.
|
||||
for (const link of ['.gstack', '.gstack/tmp']) {
|
||||
const linked = path.join(scratch, skill + '-link-' + link.replace(/\W/g, ''));
|
||||
const outside = path.join(linked, 'outside');
|
||||
fs.mkdirSync(outside, { recursive: true });
|
||||
fs.mkdirSync(path.join(linked, 'repo', path.dirname(link)), { recursive: true });
|
||||
fs.symlinkSync(outside, path.join(linked, 'repo', link));
|
||||
const refused = spawnSync('bash', ['-c', create[0]], { cwd: path.join(linked, 'repo'), encoding: 'utf8', timeout: 30_000 });
|
||||
expect(refused.status, link).not.toBe(0);
|
||||
expect(refused.stdout.trim(), link).toBe('');
|
||||
expect(fs.readdirSync(outside), link).toEqual([]);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user