-
Notifications
You must be signed in to change notification settings - Fork 5
feat(cli): honest non-interactive init — fail on skew, no false success (rc.2 M4) #687
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,29 @@ | ||
| --- | ||
| 'stash': minor | ||
| --- | ||
|
|
||
| `stash init` is honest non-interactively — it no longer reports success for a | ||
| setup that didn't fully complete. | ||
|
|
||
| - **Fails on version skew.** A non-interactive run can't reconcile an | ||
| already-installed `@cipherstash/*` package that's *older* than this CLI | ||
| expects (it won't mutate an install without consent), so instead of warning | ||
| and proceeding — scaffolding against mismatched packages and then claiming | ||
| success — it now refuses with a non-zero exit and the exact align command. | ||
| Interactive runs still offer to align. A *newer* install stays a warn (the | ||
| install is likely fine; update the CLI instead). | ||
| - **No false "Setup complete".** If the EQL extension isn't installed at the | ||
| end — and the integration isn't one that installs it out-of-band — the | ||
| summary reads "Setup incomplete" and init exits non-zero, pointing at | ||
| `stash eql install`. Integrations that install EQL via a migration are | ||
| reported honestly rather than as failures: Prisma Next (installs it via | ||
| `migration apply`) and the Drizzle flow, which *generates* an EQL migration | ||
| and now says "EQL migration generated — apply it with `drizzle-kit migrate`" | ||
| instead of claiming the extension is already installed. | ||
| - **Honest checkmarks.** The summary no longer claims "Database connection | ||
| verified" (init resolves a URL but doesn't open a connection) — it now says | ||
| "Database URL resolved" — and only shows "Encryption client scaffolded" when | ||
| a client was actually written (skipped for Prisma Next). | ||
| - **No false "skills loaded".** The agent handoff prompt only points at the | ||
| skills directory when skills were actually copied (a stripped build installs | ||
| none), instead of telling the agent to read files that aren't there. |
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
40 changes: 40 additions & 0 deletions
40
packages/cli/src/commands/impl/steps/__tests__/handoff-claude.test.ts
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,40 @@ | ||
| import { beforeEach, expect, it, vi } from 'vitest' | ||
| import type { InitState } from '../../../init/types.js' | ||
|
|
||
| // The launch prompt's skills clause is the unit under test. Mock the skill | ||
| // installer so we control whether any skills were "copied", and stub the | ||
| // artifact writer / agent spawner so no files are written and no process is | ||
| // spawned. `impl.test.ts` mocks `howToProceedStep.run` out entirely, so | ||
| // nothing there drives this prompt — this file is its dedicated coverage. | ||
| const installSkills = vi.hoisted(() => vi.fn()) | ||
| vi.mock('../../../init/lib/install-skills.js', () => ({ installSkills })) | ||
| vi.mock('../../../init/lib/handoff-helpers.js', () => ({ | ||
| writeArtifacts: vi.fn(), | ||
| spawnAgent: vi.fn(async () => 0), | ||
| })) | ||
| vi.mock('@clack/prompts', () => ({ | ||
| note: vi.fn(), | ||
| log: { success: vi.fn(), info: vi.fn(), warn: vi.fn() }, | ||
| })) | ||
|
|
||
| import * as p from '@clack/prompts' | ||
| import { handoffClaudeStep } from '../handoff-claude.js' | ||
|
|
||
| // `agents` undefined → Claude "not installed" path, which routes the launch | ||
| // prompt into a `p.note` (rather than spawning). That note's body is what we | ||
| // assert on. | ||
| const state = { integration: 'postgresql' } as unknown as InitState | ||
|
|
||
| beforeEach(() => vi.clearAllMocks()) | ||
|
|
||
| it('launch prompt omits the skills dir when no skills were copied', async () => { | ||
| installSkills.mockReturnValue([]) | ||
| await handoffClaudeStep.run(state) | ||
| expect(vi.mocked(p.note).mock.calls[0][0]).not.toContain('.claude/skills/') | ||
| }) | ||
|
|
||
| it('launch prompt names the skills dir when skills were copied', async () => { | ||
| installSkills.mockReturnValue(['stash-encryption']) | ||
| await handoffClaudeStep.run(state) | ||
| expect(vi.mocked(p.note).mock.calls[0][0]).toContain('.claude/skills/') | ||
| }) |
54 changes: 54 additions & 0 deletions
54
packages/cli/src/commands/impl/steps/__tests__/handoff-codex.test.ts
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,54 @@ | ||
| import { beforeEach, expect, it, vi } from 'vitest' | ||
| import type { InitState } from '../../../init/types.js' | ||
|
|
||
| // Same seam as the handoff-claude test: the launch prompt's skills clause is | ||
| // the unit under test. Mock the skill installer to control whether skills were | ||
| // "copied". The Codex handoff also writes AGENTS.md to disk before printing | ||
| // the prompt, so stub `node:fs` and the AGENTS.md builders to keep the test | ||
| // hermetic (no file lands in the repo) — the assertion is purely on the | ||
| // launch-prompt text. | ||
| const installSkills = vi.hoisted(() => vi.fn()) | ||
| vi.mock('../../../init/lib/install-skills.js', () => ({ installSkills })) | ||
| vi.mock('../../../init/lib/handoff-helpers.js', () => ({ | ||
| writeArtifacts: vi.fn(), | ||
| spawnAgent: vi.fn(async () => 0), | ||
| })) | ||
| vi.mock('../../../init/lib/build-agents-md.js', () => ({ | ||
| buildAgentsMdBody: vi.fn(() => '# managed doctrine'), | ||
| })) | ||
| vi.mock('../../../init/lib/sentinel-upsert.js', () => ({ | ||
| upsertManagedBlock: vi.fn(() => '# AGENTS.md'), | ||
| })) | ||
| vi.mock('node:fs', () => ({ | ||
| existsSync: vi.fn(() => false), | ||
| readFileSync: vi.fn(() => ''), | ||
| writeFileSync: vi.fn(), | ||
| })) | ||
| vi.mock('@clack/prompts', () => ({ | ||
| note: vi.fn(), | ||
| log: { success: vi.fn(), info: vi.fn(), warn: vi.fn() }, | ||
| })) | ||
|
|
||
| import * as p from '@clack/prompts' | ||
| import { handoffCodexStep } from '../handoff-codex.js' | ||
|
|
||
| // `agents` undefined → Codex "not installed" path, which routes the launch | ||
| // prompt into a `p.note`. | ||
| const state = { integration: 'postgresql' } as unknown as InitState | ||
|
|
||
| beforeEach(() => vi.clearAllMocks()) | ||
|
|
||
| it('launch prompt drops .codex/skills/ but keeps AGENTS.md when no skills copied', async () => { | ||
| installSkills.mockReturnValue([]) | ||
| await handoffCodexStep.run(state) | ||
| const body = vi.mocked(p.note).mock.calls[0][0] | ||
| expect(body).not.toContain('.codex/skills/') | ||
| // The durable rules live in AGENTS.md regardless, so the prompt still names it. | ||
| expect(body).toContain('AGENTS.md') | ||
| }) | ||
|
|
||
| it('launch prompt names .codex/skills/ when skills were copied', async () => { | ||
| installSkills.mockReturnValue(['stash-encryption']) | ||
| await handoffCodexStep.run(state) | ||
| expect(vi.mocked(p.note).mock.calls[0][0]).toContain('.codex/skills/') | ||
| }) |
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
Oops, something went wrong.
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.