Repository navigation
feat(cli): let every command be driven through run() hermetically - #191
Conversation
The CLI bucket could only cover `validate`, because `run()` threaded no dependencies to the other commands. They could not be exercised from the outside without reading the developer's real disk, home directory and environment. The audit's framing — "five commands have no seam" — was imprecise. Each already had one; they were simply different, and `run()` passed none of them along: validate, init fs migrate fs (required; reached through init) prompt configLoader, cwd runtime cwd, storeFactory, dbExists eval env, runner, validator overrides compose none — Bun.file, process.cwd(), homedir() directly `run()` now passes its injected `fs` to `compose`, `prompt` and `runtime` alongside `validate` and `init`, derives `cwd` from it for commands that locate work by path, and threads an injected `env` to `eval`. Threading `cwd` alone was not enough. `loadConfig()` falls back to its own Bun-backed reader, so a command handed an injected `cwd` still read the real disk — `weave prompt list` against a virtual config listed the builtins and never saw it. `toConfigFileReader()` bridges a `FileSystem` into config discovery, which is what actually closes the gap. `compose` had no seam at all and gains one: config discovery, the bootstrap copy and every file the adapter writes now go through `fs`. Its bootstrap write was also unchecked (`await Bun.write(...)` with no error path); it now reports failures, which needs a FileWriteError variant on CliError. Eight CLI scenarios cover the result, asserting what the commands print and write rather than merely that they returned a number. Refs #183 (task group 13) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve
|
Warning Review limit reachedNext included review available in 42 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: ⛔ Files ignored due to path filters (4)
📒 Files selected for processing (8)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Several new injected-filesystem paths currently swallow or ignore filesystem errors (notably compose adapter hooks and runtime/db existence checks), which can mask real failures and break hermetic correctness guarantees.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 3
Open (3)
What changed in this PR
This PR (part of #183 / task group 13) makes the CLI “bucket” viable by ensuring every CLI command can be driven through run() with injected dependencies (virtual filesystem / environment), so scenarios can execute hermetically without touching the developer’s real disk, $HOME, or ambient env.
Changes:
- Thread
fs(andcwd/envwhere needed) frompackages/cli/src/cli.ts::run()intoprompt,runtime,eval, andcompose. - Add a
FileSystem→@weaveio/weave-configbridge (toConfigFileReader) so config discovery uses injected I/O rather than Bun’s real filesystem defaults. - Add new black-box CLI scenarios covering
prompt,runtime,compose, andevalseams; update testing strategy docs accordingly.
| File | Description |
|---|---|
| tests/cli/command-seams.scenario.test.ts | New hermetic scenarios asserting commands are drivable via run() against a virtual FS/env. |
| packages/cli/src/fs/file-system.ts | Adds toConfigFileReader() bridge to feed injected FileSystem into config discovery. |
| packages/cli/src/errors.ts | Adds FileWriteError variant and formatting for compose/bootstrap write failures. |
| packages/cli/src/commands/runtime.ts | Allows runtime DB lookup to use injected fs/cwd instead of always consulting real disk. |
| packages/cli/src/commands/prompt.ts | Ensures prompt config discovery uses injected fs via toConfigFileReader (not just injected cwd). |
| packages/cli/src/commands/compose.ts | Adds fs seam for config discovery/bootstrap/adapter writes; adds explicit write failure reporting. |
| packages/cli/src/cli.ts | Threads injected fs/cwd/env through run() into command handlers. |
| docs/testing-strategy.md | Updates audit wording and records the new CLI seam approach. |
| .codesight/libs.md | Auto-updated metadata reflecting new symbols/types. |
| .codesight/graph.md | Auto-updated import graph metadata. |
| .codesight/coverage.md | Auto-updated test file count metadata. |
| .codesight/CODESIGHT.md | Auto-updated aggregate metadata snapshot. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Check whether destination already exists | ||
| const existsCheck = await Bun.file( | ||
| join(destDir, BOOTSTRAP_FILES[0]), | ||
| ).exists(); | ||
| const existsResult = await fs.exists(join(destDir, BOOTSTRAP_FILES[0])); | ||
| const existsCheck = existsResult.isOk() && existsResult.value; | ||
| if (existsCheck) { |
| const fs = ctx.fs; | ||
| const checkExists = | ||
| ctx.dbExists ?? | ||
| (fs | ||
| ? async (path: string) => { | ||
| const result = await fs.exists(path); | ||
| return result.isOk() && result.value; | ||
| } | ||
| : defaultDbExists); | ||
| const exists = await checkExists(dbPath); |
| exists: async (path) => { | ||
| const result = await fs.exists(path); | ||
| return result.isOk() && result.value; | ||
| }, |

Part of #183 — task group 13. Prerequisite for populating the CLI bucket.
The problem
The CLI bucket could only cover
validate, becauserun()threaded no dependencies to anything else. No other command could be exercised from the outside without reading the developer's real disk, home directory and environment.Correcting the framing
The audit said "five commands have no seam". That was imprecise — each already had one, they were just different seams, and
run()passed none of them along:validate,initfsmigratefs(required; reached throughinit, so already covered)promptconfigLoader,cwdruntimecwd,storeFactory,dbExistsevalenv,runner, validator overridescomposeBun.file,process.cwd(),homedir()directlySo the work was mostly plumbing what already existed, plus giving
composea seam.Threading
cwdwas not enoughThis is the part worth reviewing. Passing an injected
cwdtopromptlooked sufficient and was not:loadConfig()falls back to its own Bun-backed reader, so the command still read the real disk.weave prompt listagainst a virtual config listed the builtins and never saw it.I caught this because a scenario I had written was passing while asserting only
typeof exitCode === "number"— weak enough to pass trivially. A probe confirmedSEES_VIRTUAL_AGENT=false.toConfigFileReader()bridges aFileSysteminto config discovery, which is what actually closes the gap, and the scenarios now assert what the commands print and write.composeIt had no seam at all. Config discovery, the bootstrap copy and every file the adapter writes now go through
fs— the adapter's existing injectable I/O hooks made the last part straightforward.Its bootstrap write was also unchecked —
await Bun.write(dest, text)with no error path, so a failed write was silent. It now reports failures, which needs aFileWriteErrorvariant onCliError.Review notes
tests/now coversprompt list,prompt inspect(found and not-found),runtime status,compose(success and unsupported adapter), andevalenvironment filtering.Verification
bun test ./tests: 26 pass, 0 failbun run test: 6,107 across 194 files, 0 failbun run typecheck,bun run lint,bun run verify:test-coverage,bun run docs:check-links: pass🤖 Generated with Claude Code
https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve