Repository navigation
refactor: separate command options from seams, and derive CLI result types - #286
Merged
Merged
Conversation
Every ExecuteDeps stub is now vi.fn<Stub<"cmd">>() and resolves a complete command result (upResult/dryRunResult/lsInstance/pruneResult builders, whose empty defaults render exactly as the formatters render absent fields). The stubs no longer lean on the CLI's tolerance for partial results: down returns its DownResult variant, a dry-run preview carries its selection, restart its skippedShared. One assertion follows the real shape: a dry run with no dropped edge still prints its selection notes on stderr, so the test pins those exact lines instead of an empty stderr. The stubs type-check once the next commit derives ExecuteDeps' result types from the commands; at this commit they pass at runtime only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XB2nwzXmHUTorMcFTpChXd
ExecuteDeps declared each command's result shape by hand, so the CLI copy could drift from what commands.ts returns without a type error. Each entry now resolves to ReturnType<typeof runX>, imported as a type only (the entrypoint still lazy-loads commands.js). The handler fallbacks that only existed for partial test stubs (an undefined down result, a dry run without its selection, a prune without warnings) are gone: the derived types say those fields are always there. Emitted output is unchanged for every real command result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XB2nwzXmHUTorMcFTpChXd
CommandDeps mixed per-invocation options (cwd, attach, namespaces, waitTimeoutMs) with the injected seams. Every command now has the same shape, runX(env, options): - CommandEnv (was CommandDeps) holds only seams and test budgets. - Each command's options carry its flags plus cwd: UpOptions, UpDryRunOptions, DownOptions, AttachOptions, RestartOptions (services, namespaces, waitTimeoutMs; was positional), LogsOptions, PruneSharedPortsOptions, and CommandOptions for ls, prune, env and the bare-restart remedy. SharedNamespaceDownOptions gains cwd. - LsDeps and PruneDeps lose cwd; InitDeps becomes InitOptions, with an empty InitEnv so init takes (env, options) too. - Internal helpers get the option they read passed explicitly (the up selection, the wait budget, attach) instead of reading it off the env. The CLI's ExecuteDeps entries are now Invocation<typeof runX>: the command signature minus its env, so the options and results are both derived. The unit tests still call the old signatures; the next commits update their call sites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XB2nwzXmHUTorMcFTpChXd
Every call site in commands, restart, init and shared-instance tests now passes cwd, attach, namespaces and waitTimeoutMs in the options argument, not in the env. Helpers that took option fields in an env extra now take an options parameter (dryFailure, realChecks, upError, failure, lockFreeDuringWait); liveInstance's callers pass them at the call. The multi-worktree `wt()` helper no longer spreads `namespaces` into the env: every caller passes them to runUp/runUpDryRun, and againstDead returns them as `options`. Two untyped deps literals carried `waitTimeoutMs: 5_000`, which no longer reaches the command from the env; they now pass it as an option. The attach/logs/prune fixtures drop `cwd`: their git is stubbed, so cwd only fed the default git and never reached anything. No assertion changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XB2nwzXmHUTorMcFTpChXd
The authorised frozen-suite edit for #260: call sites and their deps/options construction only. No assertion or scenario setup changed. Every `as never` cast on a command call is gone, so the compiler checks each call: a cwd, namespaces or waitTimeoutMs left in the env is now a type error, not a silent fallback to process.cwd(), every booted namespace or the 120s timeout. - stubDriverDeps returns { env, at, up }: env is the stub driver and the no-op waits (plus an `extra` env), at is { cwd }, up is { cwd, attach: false }. - #87's hand-built deps keep the same shape, with waitTimeoutMs: 8000 in `up`. - bootRestartStack's restartDeps is the env ({ driver }); restartOptions carries cwd and waitTimeoutMs: 10_000. The `attach: false` it carried was never read by restart and is dropped. -n namespaces go to up's options. - runLs / runPrune take the driver as the env and cwd as the option. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XB2nwzXmHUTorMcFTpChXd
Contributor
fallow code-quality reportThresholds are tunable — see |
pcInstance spread `namespaces` into the env (`{ ...onPc.deps, namespaces }`),
which hid it from the compiler: up silently dropped it, so "never checks
the ports of a service the instance did not boot" no longer exercised
`-n default`. It now passes them as up's options and keeps them out of the
returned env. Its docstring said "(default: all)"; omitting them selects
only `default`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XB2nwzXmHUTorMcFTpChXd
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #260. This is the last ticket of the architecture epic.
What changed
Every command now takes its seams and its options as two separate arguments, in one style:
runX(env: CommandEnv = {}, options: XOptions = {}). The seams come first and the options second.CommandDepsis renamedCommandEnv. It holds the seams only.cwd,attach,namespacesandwaitTimeoutMsmoved to per-command option types:CommandOptions { cwd? }UpOptions(attach,waitTimeoutMs,namespaces)UpDryRunOptionsDownOptions/AttachOptions(shared)RestartOptions(services,namespaces,waitTimeoutMs)LogsOptionsPruneSharedPortsOptionsrunRestart(env, { services, namespaces, waitTimeoutMs })runLs(env, { cwd })andrunPrune(env, { cwd }):LsDepsandPruneDepslosecwd.runInit(env, options):InitDepsbecomesInitOptions.ExecuteDepsis derived from the command signatures (Invocation<typeof runX>, which equalsParameters<typeof runX>[1]but keeps optionality). Its result types areAwaited<ReturnType<…>>. The CLI's own copies of the option and result types are gone.vi.fn<Stub<"cmd">>(), so they are type-checked against the real command results.CommandEnvfield countsCommandDeps→CommandEnvLsDepscwdmoved to options)PruneDepscwdmoved to options)InitDepsInitOptions = CommandOptionsHandler fallbacks removed from
cli.ts(commit 3d2f9b3)Each fallback below guarded a field that the real result type now guarantees:
(await deps.down(...)) ?? {}runDownreturnsPromise<DownResult>and never resolvesundefined.result.stopped ?? truestopped: booleanis required in bothDownResultvariants.result.worktreeId ?? ""result.shared. Theshared: falsevariant hasworktreeId: string; the shared variant does not print it.sharedStarted ?? false(up)UpResult.sharedStarted: booleanis required, soformatUp(result)is called directly.droppedEdges,droppedNamespaceEdges,bracedEnvVars,selectedSharedServices,wouldRestartShared?? []ReadonlyArrays onDryRunResult.namespaceswas set;selectedServices ?? []DryRunResult.namespacesandselectedServicesare required: a real preview always carries its selection, so the selection block is always built.instance ?? "fresh",wouldReload ?? false,wouldRestart ?? []DryRunResult.warnings ?? [],unreclaimed ?? []PruneResult.None of these fallbacks could fire for a real command: they only covered partial test stubs.
built-cli.e2eand the agent-surface fixtures confirm that the output is unchanged.Changed test (no tests deleted)
cli.test.ts, up --dry-run: "says nothing on stderr…" is now "warns about no edge on stderr…". The stub now returns a real-shaped preview, which carries its selection. The CLI prints the selection notes for such a preview, as it always did for real runs, so the test pins those two exact lines instead of an empty stderr. Thedropped_edges: []JSON assertion is unchanged.Authorised frozen-suite edit:
src/e2e.test.ts(commit 59de24e)This edit was authorised by the coordinator. The precedent is #256's wiring-only edit.
as neveron a command call is removed (92 casts), so the compiler now checks each call. An option field left in the env is a type error.built-cli.e2e.test.tsandreal-pc.smoke.test.ts.Where each option field went
stubDriverDeps(worktree), used by every up/down/attach scenariocwd: worktreeat.cwd(down, attach) andup.cwd(up)stubDriverDeps(worktree)attach: falseup.attach→runUp(deps.env, deps.up)cwd,attach: false,waitTimeoutMs: 8000up: { cwd, attach: false, waitTimeoutMs: 8000 },at: { cwd }waitForSharedHealth(a seam)stubDriverDeps(worktree, { waitForSharedHealth }), still in the envbootRestartStackupcwd,attach: falseupDepsenvupOptions = { ...upDeps.up }bootRestartStackup-nnamespacesupOptions: UpOptionsbootRestartStackrestart (10 calls)cwd,waitTimeoutMs: 10_000restartDepsrestartOptions, spread intorunRestart(stack.restartDeps, { ...stack.restartOptions, services, namespaces? })bootRestartStackrestartattach: falserestartDepsattach(onlyrunUpdid, viashouldAttachAfterUp)runRestart(deps, [], ["jobs"])namespaces{ services: [], namespaces: ["jobs"] }runLs({ cwd, driver })(7 calls)cwdrunLs({ driver }, { cwd })runPrune({ cwd: billingWt, driver })(4 calls)cwdrunPrune({ driver }, { cwd: billingWt })Runtime check:
e2e.test.tslooped 5× on each sidetests)tests)All 30/30 tests pass on both sides. The runtimes match: if a timeout had fallen back to 120s, the runs would be far longer.
Unit-suite call sites (commit 230c4c3)
wt()helper conditionally spreadnamespacesinto the env. It no longer acceptsnamespaces, so the compiler flagged every caller, and each caller now passes them as options.waitTimeoutMs: 5_000. They now pass it as an option.cwddropped from three fixtures: the attach, logs and prune fixtures no longer setcwd. Theirgitis stubbed, andcwdonly feedsdefaultGit(cwd), so it never reached anything.Commits
Verification
vp check: clean (formatting, lint, types).vp test: 46 files passed, 1 skipped; 1772 tests passed, 80 skipped. No flakes this run.vp pack, thensrc/built-cli.e2e.test.ts: 53/53 passed.DEVTREES_REAL_PC_E2E=1 vp test run src/real-pc.smoke.test.ts, aftervp pack): 77 passed, 2 failed. The 2 failures are scenarios 108 and 109, the known Real-PC smoke scenarios 108/109 fail on process-compose v1.124.0 (CI pins v1.122.0) #273 failures.test/fixtures/agent-surface/is unchanged against main (git diff origin/main -- test/fixtures/is empty).Bugs found (not fixed)
None.
🤖 Generated with Claude Code
https://claude.ai/code/session_01XB2nwzXmHUTorMcFTpChXd