-
Notifications
You must be signed in to change notification settings - Fork 6
fix(cli): report stash plan's real outcome — no 'Plan drafted' without the file (rc.3 M2) #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+303
−11
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d48421a
fix(cli): report stash plan's real outcome — no 'Plan drafted' withou…
coderdan c483b3b
fix(cli): route stash plan's fs stat errors through a controlled exit
coderdan 5fafc09
fix(cli): reject a non-file plan.md; cover revise-and-drafted (review…
coderdan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'stash': patch | ||
| --- | ||
|
|
||
| `stash plan` now reports the outcome that actually occurred instead of unconditionally printing `Plan drafted at .cipherstash/plan.md` and exiting 0 (#738). The plan file is written by the handed-off agent, so the command verifies it on disk after the handoff: "Plan drafted" appears only when the file exists; if a launched agent (Claude Code, Codex, or the wizard) exits without writing it, `plan` errors and exits non-zero so automation never proceeds against a plan that was never created; deferred handoffs (`--target agents-md`, or a CLI target that isn't installed) end with an honest "No plan drafted yet" hint; and a pre-existing plan the run didn't modify is reported as left unchanged rather than drafted. An unexpected filesystem error while reading the plan path (a locked or malformed `.cipherstash/`) now exits non-zero with a clear message rather than an opaque crash. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,6 +85,6 @@ export const handoffClaudeStep: HandoffStep = { | |
| ) | ||
| } | ||
|
|
||
| return state | ||
| return { ...state, agentLaunched: true } | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,6 +130,6 @@ export const handoffCodexStep: HandoffStep = { | |
| ) | ||
| } | ||
|
|
||
| return state | ||
| return { ...state, agentLaunched: true } | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,6 @@ export const handoffWizardStep: HandoffStep = { | |
| ) | ||
| } | ||
|
|
||
| return state | ||
| return { ...state, agentLaunched: true } | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| import { | ||
| chmodSync, | ||
| mkdirSync, | ||
| mkdtempSync, | ||
| rmSync, | ||
| symlinkSync, | ||
| writeFileSync, | ||
| } from 'node:fs' | ||
| import { tmpdir } from 'node:os' | ||
| import { delimiter, join } from 'node:path' | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest' | ||
| import { messages } from '../../src/messages.js' | ||
| import { runPiped } from '../helpers/spawn-piped.js' | ||
|
|
||
| /** | ||
| * #738: `stash plan` printed `Plan drafted at .cipherstash/plan.md` and exited | ||
| * 0 unconditionally. The plan file is written by the handed-off agent, not by | ||
| * the CLI, so a failed or deferred handoff produced a false success — and sent | ||
| * `stash impl` (and any automation reading the outro) after a file that never | ||
| * existed. The command now verifies the file on disk after the handoff and | ||
| * reports the outcome that actually occurred. | ||
| * | ||
| * A fake `claude` binary prepended to PATH drives the "agent launched" paths | ||
| * without the real agent — no DB, no network. (The e2e suite runs on POSIX | ||
| * only, so a /bin/sh script is fine.) | ||
| */ | ||
| describe('stash plan — outcome reflects the plan file on disk', () => { | ||
| let dir: string | ||
|
|
||
| beforeEach(() => { | ||
| dir = mkdtempSync(join(tmpdir(), 'plan-outcome-e2e-')) | ||
| mkdirSync(join(dir, '.cipherstash'), { recursive: true }) | ||
| writeFileSync( | ||
| join(dir, '.cipherstash', 'context.json'), | ||
| JSON.stringify({ | ||
| integration: 'postgresql', | ||
| packageManager: 'npm', | ||
| schemas: [], | ||
| }), | ||
| ) | ||
| }) | ||
| afterEach(() => { | ||
| rmSync(dir, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| /** | ||
| * Write an executable fake `claude` into a bin dir under the fixture and | ||
| * return a PATH that resolves it first. `spawnAgent` inherits the CLI's | ||
| * cwd, so the script's relative paths land inside the fixture project. | ||
| */ | ||
| function fakeClaudePath(script: string): string { | ||
| const bin = join(dir, 'fake-bin') | ||
| mkdirSync(bin, { recursive: true }) | ||
| const file = join(bin, 'claude') | ||
| writeFileSync(file, `#!/bin/sh\n${script}\n`) | ||
| chmodSync(file, 0o755) | ||
| return `${bin}${delimiter}${process.env.PATH ?? ''}` | ||
| } | ||
|
|
||
| it('exits 1 when the launched agent writes no plan (no false success)', async () => { | ||
| const r = await runPiped(['plan', '--target', 'claude-code'], { | ||
| cwd: dir, | ||
| env: { PATH: fakeClaudePath('exit 0') }, | ||
| timeoutMs: 20000, | ||
| }) | ||
| expect(r.timedOut).toBe(false) | ||
| expect(r.exitCode).toBe(1) | ||
| const out = r.stdout + r.stderr | ||
| expect(out).toContain(messages.plan.notWritten) | ||
| expect(out).not.toContain(messages.plan.drafted) | ||
| }) | ||
|
|
||
| it('reports "Plan drafted" and exits 0 when the agent wrote the plan', async () => { | ||
| const r = await runPiped(['plan', '--target', 'claude-code'], { | ||
| cwd: dir, | ||
| env: { | ||
| PATH: fakeClaudePath('echo "# Plan" > .cipherstash/plan.md'), | ||
| }, | ||
| timeoutMs: 20000, | ||
| }) | ||
| expect(r.timedOut).toBe(false) | ||
| expect(r.exitCode).toBe(0) | ||
| const out = r.stdout + r.stderr | ||
| expect(out).toContain(`${messages.plan.drafted} \`.cipherstash/plan.md\``) | ||
| }) | ||
|
|
||
| it('reports a pre-existing plan as unchanged, not drafted', async () => { | ||
| writeFileSync(join(dir, '.cipherstash', 'plan.md'), '# old plan\n') | ||
| const r = await runPiped(['plan', '--target', 'claude-code'], { | ||
| cwd: dir, | ||
| env: { PATH: fakeClaudePath('exit 0') }, | ||
| timeoutMs: 20000, | ||
| }) | ||
| expect(r.timedOut).toBe(false) | ||
| // A usable plan exists on disk, so this is not a failure — but the run | ||
| // must not claim it drafted anything. | ||
| expect(r.exitCode).toBe(0) | ||
| const out = r.stdout + r.stderr | ||
| expect(out).toContain(messages.plan.unchanged) | ||
| expect(out).not.toContain(messages.plan.drafted) | ||
| }) | ||
|
|
||
| it('reports "drafted" when the agent revises a pre-existing plan', async () => { | ||
| writeFileSync(join(dir, '.cipherstash', 'plan.md'), '# old plan\n') | ||
| const r = await runPiped(['plan', '--target', 'claude-code'], { | ||
| cwd: dir, | ||
| // The agent appends — a real revision that changes size (and mtime), so | ||
| // the change-detection limb reports "drafted", not "unchanged". | ||
| env: { PATH: fakeClaudePath('echo "# revised" >> .cipherstash/plan.md') }, | ||
| timeoutMs: 20000, | ||
| }) | ||
| expect(r.timedOut).toBe(false) | ||
| expect(r.exitCode).toBe(0) | ||
| const out = r.stdout + r.stderr | ||
| expect(out).toContain(`${messages.plan.drafted} \`.cipherstash/plan.md\``) | ||
| expect(out).not.toContain(messages.plan.unchanged) | ||
| }) | ||
|
|
||
| it('treats a plan.md directory as no plan, not a false "unchanged"', async () => { | ||
| // `statSync` succeeds for a directory, but no agent can write a plan there. | ||
| // Without the isFile() gate this would warn "already exists" and then, with | ||
| // an agent that writes nothing, report a false "unchanged" exit 0. | ||
| mkdirSync(join(dir, '.cipherstash', 'plan.md')) | ||
| const r = await runPiped(['plan', '--target', 'claude-code'], { | ||
| cwd: dir, | ||
| env: { PATH: fakeClaudePath('exit 0') }, | ||
| timeoutMs: 20000, | ||
| }) | ||
| expect(r.timedOut).toBe(false) | ||
| expect(r.exitCode).toBe(1) | ||
| const out = r.stdout + r.stderr | ||
| expect(out).toContain(messages.plan.notWritten) | ||
| expect(out).not.toContain(messages.plan.unchanged) | ||
| expect(out).not.toContain(messages.plan.drafted) | ||
| }) | ||
|
|
||
| it('agents-md handoff says "No plan drafted yet" instead of claiming success', async () => { | ||
| const r = await runPiped(['plan', '--target', 'agents-md'], { | ||
| cwd: dir, | ||
| timeoutMs: 20000, | ||
| }) | ||
| expect(r.timedOut).toBe(false) | ||
| // The deferred handoff delivered its files-and-instructions contract, so | ||
| // exit 0 — but the plan is written later, by the user's editor agent. | ||
| expect(r.exitCode).toBe(0) | ||
| const out = r.stdout + r.stderr | ||
| expect(out).toContain(messages.plan.noPlanYet) | ||
| expect(out).not.toContain(messages.plan.drafted) | ||
| }) | ||
|
|
||
| it('claude-code target without claude on PATH defers honestly', async () => { | ||
| const r = await runPiped(['plan', '--target', 'claude-code'], { | ||
| cwd: dir, | ||
| // A PATH with no `claude` anywhere: the handoff writes files and | ||
| // prints install instructions instead of spawning. | ||
| env: { PATH: '/usr/bin:/bin' }, | ||
| timeoutMs: 20000, | ||
| }) | ||
| expect(r.timedOut).toBe(false) | ||
| expect(r.exitCode).toBe(0) | ||
| const out = r.stdout + r.stderr | ||
| expect(out).toContain(messages.plan.noPlanYet) | ||
| expect(out).not.toContain(messages.plan.drafted) | ||
| }) | ||
|
|
||
| it('exits 1 with a clear message when the plan path cannot be statted', async () => { | ||
| // A self-referential symlink at plan.md makes `statSync` throw ELOOP, not | ||
| // ENOENT — a non-ENOENT fs error that must surface as a controlled exit | ||
| // (clear message + non-zero), never an opaque "Fatal error" crash. | ||
| symlinkSync('plan.md', join(dir, '.cipherstash', 'plan.md')) | ||
| const r = await runPiped(['plan', '--target', 'agents-md'], { | ||
| cwd: dir, | ||
| timeoutMs: 20000, | ||
| }) | ||
| expect(r.timedOut).toBe(false) | ||
| expect(r.exitCode).toBe(1) | ||
| const out = r.stdout + r.stderr | ||
| expect(out).toContain('Could not read') | ||
| expect(out).not.toContain(messages.plan.drafted) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.