Skip to content

refactor: separate command options from seams, and derive CLI result types - #286

Merged
pantoninho merged 6 commits into
mainfrom
refactor/260-options-vs-seams
Nov 13, 2026
Merged

pantoninho merged 6 commits into
mainfrom
refactor/260-options-vs-seams

Conversation

@pantoninho

Copy link
Copy Markdown
Owner

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.

  • CommandDeps is renamed CommandEnv. It holds the seams only. cwd, attach, namespaces and waitTimeoutMs moved to per-command option types:
    • CommandOptions { cwd? }
    • UpOptions (attach, waitTimeoutMs, namespaces)
    • UpDryRunOptions
    • DownOptions / AttachOptions (shared)
    • RestartOptions (services, namespaces, waitTimeoutMs)
    • LogsOptions
    • PruneSharedPortsOptions
  • Call shapes:
    • runRestart(env, { services, namespaces, waitTimeoutMs })
    • runLs(env, { cwd }) and runPrune(env, { cwd }): LsDeps and PruneDeps lose cwd.
    • runInit(env, options): InitDeps becomes InitOptions.
  • Option values are now passed explicitly into the helpers that need them: health-wait timeouts, the restart of dead services, the attach decision and namespace reconciliation. No helper reads an option from the env any more.
  • The CLI's ExecuteDeps is derived from the command signatures (Invocation<typeof runX>, which equals Parameters<typeof runX>[1] but keeps optionality). Its result types are Awaited<ReturnType<…>>. The CLI's own copies of the option and result types are gone.
  • The CLI test stubs are vi.fn<Stub<"cmd">>(), so they are type-checked against the real command results.

CommandEnv field counts

type before after
CommandDeps → CommandEnv 37 (4 options + 33 seams) 33 (seams only)
LsDeps 7 6 (cwd moved to options)
PruneDeps 9 8 (cwd moved to options)
InitDeps 1 removed: InitOptions = CommandOptions

Handler fallbacks removed from cli.ts (commit 3d2f9b3)

Each fallback below guarded a field that the real result type now guarantees:

fallback why it can go
(await deps.down(...)) ?? {} runDown returns Promise<DownResult> and never resolves undefined.
result.stopped ?? true stopped: boolean is required in both DownResult variants.
result.worktreeId ?? "" The handler now branches on result.shared. The shared: false variant has worktreeId: string; the shared variant does not print it.
sharedStarted ?? false (up) UpResult.sharedStarted: boolean is required, so formatUp(result) is called directly.
dry-run droppedEdges, droppedNamespaceEdges, bracedEnvVars, selectedSharedServices, wouldRestartShared ?? [] All of these are required ReadonlyArrays on DryRunResult.
dry-run selection only when namespaces was set; selectedServices ?? [] DryRunResult.namespaces and selectedServices are required: a real preview always carries its selection, so the selection block is always built.
dry-run instance ?? "fresh", wouldReload ?? false, wouldRestart ?? [] All are required on DryRunResult.
prune warnings ?? [], unreclaimed ?? [] Both are required on PruneResult.

None of these fallbacks could fire for a real command: they only covered partial test stubs. built-cli.e2e and 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. The dropped_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.

  • Scope: call sites and their deps/options construction only. There are zero assertion changes and zero changes to scenario setup semantics.
  • Casts: every as never on 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.
  • Untouched: built-cli.e2e.test.ts and real-pc.smoke.test.ts.

Where each option field went

e2e call / construction field before (env) now
stubDriverDeps(worktree), used by every up/down/attach scenario cwd: worktree env at.cwd (down, attach) and up.cwd (up)
stubDriverDeps(worktree) attach: false env up.attach → runUp(deps.env, deps.up)
#87 default-health-wait scenario cwd, attach: false, waitTimeoutMs: 8000 env literal up: { cwd, attach: false, waitTimeoutMs: 8000 }, at: { cwd }
#240 shared-health scenario waitForSharedHealth (a seam) spread into stub deps stubDriverDeps(worktree, { waitForSharedHealth }), still in the env
bootRestartStack up cwd, attach: false upDeps env upOptions = { ...upDeps.up }
bootRestartStack up -n namespaces conditional spread into the env conditional spread into upOptions: UpOptions
bootRestartStack restart (10 calls) cwd, waitTimeoutMs: 10_000 restartDeps restartOptions, spread into runRestart(stack.restartDeps, { ...stack.restartOptions, services, namespaces? })
bootRestartStack restart attach: false restartDeps dropped: restart never read attach (only runUp did, via shouldAttachAfterUp)
runRestart(deps, [], ["jobs"]) namespaces third positional argument { services: [], namespaces: ["jobs"] }
runLs({ cwd, driver }) (7 calls) cwd env runLs({ driver }, { cwd })
runPrune({ cwd: billingWt, driver }) (4 calls) cwd env runPrune({ driver }, { cwd: billingWt })

Runtime check: e2e.test.ts looped 5× on each side

run branch (tests) main 24b706a (tests)
1 23.96s 24.17s
2 23.92s 24.19s
3 23.89s 24.24s
4 23.95s 24.18s
5 24.01s 24.29s

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)

  • commands, restart, init and shared-instance tests: the options moved to the options argument. Assertion counts are unchanged (commands.test.ts 1069, restart.test.ts 104).
  • Two silent leaks fixed:
    • The multi-worktree wt() helper conditionally spread namespaces into the env. It no longer accepts namespaces, so the compiler flagged every caller, and each caller now passes them as options.
    • Two untyped deps literals carried waitTimeoutMs: 5_000. They now pass it as an option.
  • cwd dropped from three fixtures: the attach, logs and prune fixtures no longer set cwd. Their git is stubbed, and cwd only feeds defaultGit(cwd), so it never reached anything.

Commits

  • Tests and prod code are in separate commits.
  • At 67eca91 (prod split) the unit/e2e test files do not type-check yet. 230c4c3 and 59de24e fix that.
  • At d88d1ec the typed CLI stubs pass at runtime but type-check only from 3d2f9b3 on. This is noted in that commit message.

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, then src/built-cli.e2e.test.ts: 53/53 passed.
  • Real-PC smoke (DEVTREES_REAL_PC_E2E=1 vp test run src/real-pc.smoke.test.ts, after vp 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

pantoninho and others added 5 commits November 13, 2026 15:54
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
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

fallow code-quality report


Audit scope: 10 changed files vs origin/main (79405b1..HEAD)
note: skipped 47 files matching default duplicates ignores (use --explain-skipped for the list)
✓ No issues in 10 changed files (0.12s)

Thresholds are tunable — see .fallowrc.jsonc and the README.

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
@pantoninho
pantoninho merged commit e00ef4f into main Nov 13, 2026
4 checks passed
@pantoninho
pantoninho deleted the refactor/260-options-vs-seams branch November 13, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: separate command options from seams, and derive CLI result types

1 participant