Skip to content

test: add command-level tests for create, sync and config - #31

Merged
epodivilov merged 3 commits into
mainfrom
test/command-level-tests
Jul 22, 2026
Merged

test: add command-level tests for create, sync and config#31
epodivilov merged 3 commits into
mainfrom
test/command-level-tests

Conversation

@epodivilov

Copy link
Copy Markdown
Owner

Adds command-level tests for the three CLI commands that had none. Tests only — no production code changed. They follow the existing update.test.ts / remove.test.ts pattern: drive the command through fake ports and assert on what it renders via UiPort plus the resulting fake git/fs/shell state.

Covered

create (19 tests)

  • Happy path: worktree creation with the resolved base, config and local-config symlinks, file copy, declared symlinks, post-create hook command/cwd/env.
  • Branch resolution: explicit --base, base prompt when the flag is absent, existing local branch (no base resolution), remote-only branch (checked out from the remote).
  • --dry-run: every preview line, and no git/fs/shell side effects.
  • Failures: branch already has a worktree, target directory exists but is not a worktree, git refuses to create the worktree, missing branch name in non-interactive mode.
  • Non-fatal degradations: config symlink failure, copy failure, symlink failure, failing hook, missing config — each warns and the command still completes.
  • Rollback: an interrupt while the worktree is being populated triggers the registered CleanupHandle, which force-removes the worktree and cancels with exit 130. The rollback's own failure is swallowed and never reaches the user. A successful run deregisters the handler.

sync (16 tests)

  • Happy path across multiple worktrees, up-to-date reporting, broken symlink recreation, branch filter, empty worktree list.
  • --dry-run: "would" verbs, no writes, hooks skipped.
  • Existing destinations: skip with the --force hint, overwrite with --force, real file where a symlink belongs.
  • post-sync hooks: command/cwd/env per worktree, failing hook downgraded to a warning.
  • Failures: unknown branch, outside a git repository, missing config, legacy config warning.

config show (8 tests)

  • Human output: sources header, per-field provenance for repo/local/global/default, repo winning over global.
  • --json: payload shape on stdout, undefined serialized as null, interactive UI bypassed.
  • Errors: missing config and invalid JSONC on the human path, JSON error on stderr with a failure exit.

Not covered

  • Cancel paths (Ctrl-C at the branch/base prompts) in resolve-params.
  • Glob-based copy/symlink patterns and tracked-target skipping — these live in resolve-worktree-plan and are exercised at the use-case level.
  • The parent config command without a subcommand (citty help routing).
  • In config show --json, the catch around the JSON branch is only reachable because the test stubs process.exit instead of terminating, so only the first stderr line is asserted.

@epodivilov
epodivilov marked this pull request as ready for review July 21, 2026 22:04
@epodivilov
epodivilov force-pushed the test/command-level-tests branch from d4149e4 to 7b988dd Compare July 21, 2026 22:08
@epodivilov
epodivilov merged commit 610556b into main Jul 22, 2026
1 check passed
@epodivilov
epodivilov deleted the test/command-level-tests branch July 22, 2026 07:17
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.

1 participant