spawn/packages/cli/src/__tests__
A 405dbc6ba6
refactor: use getSpawnCloudConfigPath(), remove dead _cloudName param (#3010) (#3012)
Replace hand-constructed openrouter.json path with getSpawnCloudConfigPath("openrouter")
for single-source-of-truth path resolution. Remove unused _cloudName parameter since
the function delegates ALL cloud credentials unconditionally.

Agent: ux-engineer

Co-authored-by: B <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-26 19:26:09 +07:00
..
agent-setup-cov.test.ts test: remove duplicate junie envVars test from agent-setup-cov (#2969) 2026-03-25 08:40:33 +07:00
agent-tarball.test.ts fix: remove local tarball download path (#2970) 2026-03-24 21:42:31 -07:00
auto-update.test.ts test: add missing assertions to no-op smoke tests (#2879) 2026-03-23 04:12:18 +07:00
aws-cov.test.ts test: add missing assertions to no-op smoke tests (#2879) 2026-03-23 04:12:18 +07:00
aws.test.ts fix(security): add AWS secret key validation and harden path traversal (#2690) 2026-03-16 01:29:01 -07:00
billing-guidance.test.ts feat: enforce CI coverage thresholds + colocate billing guidance (#2811) 2026-03-19 22:52:45 -07:00
check-entity-messages.test.ts feat: show cloud prices as lead indicator (#2347) 2026-03-08 23:41:39 -07:00
check-entity.test.ts test: consolidate repetitive check-entity tests into data-driven loops (#2389) 2026-03-09 16:53:08 -04:00
clear-history.test.ts fix: remove 100-entry history cap — keep all records (#2819) 2026-03-20 06:32:08 -07:00
cloud-credentials.test.ts refactor: Remove dead code and stale references (#2278) 2026-03-07 03:56:13 -05:00
cloud-init.test.ts refactor(test): extract shouldSkipCloudInit helper and add unit tests (#2958) 2026-03-24 22:32:53 +07:00
cmd-connect-cov.test.ts test: add comprehensive code coverage tests (#2802) 2026-03-19 22:24:54 -07:00
cmd-delete-cov.test.ts test: remove duplicate and theatrical tests (#2981) 2026-03-25 20:37:47 +07:00
cmd-feedback.test.ts feat: add downloadFile to CloudRunner + local OpenClaw config merge (#2636) 2026-03-14 15:47:32 -07:00
cmd-fix-cov.test.ts test: remove duplicate cmdFix tests from cmd-fix-cov.test.ts (#2910) 2026-03-23 21:35:44 +07:00
cmd-fix.test.ts fix(fix): add missing LANG export to buildFixScript (#2954) 2026-03-24 20:38:05 +07:00
cmd-interactive-cov.test.ts test: add comprehensive code coverage tests (#2802) 2026-03-19 22:24:54 -07:00
cmd-interactive.test.ts feat: add downloadFile to CloudRunner + local OpenClaw config merge (#2636) 2026-03-14 15:47:32 -07:00
cmd-link-cov.test.ts test: remove duplicate and theatrical tests (#2873) 2026-03-22 20:22:47 +07:00
cmd-link.test.ts feat(cli): add spawn link command to reconnect existing deployments (#2675) 2026-03-15 23:11:13 -07:00
cmd-list-cov.test.ts test: remove duplicate and theatrical tests (#2831) 2026-03-20 13:47:17 -07:00
cmd-listing-output.test.ts test: remove duplicate terminal-width boilerplate in cmd-listing-output tests (#2721) 2026-03-17 14:22:05 -07:00
cmd-pick-cov.test.ts test: remove duplicate and theatrical tests (#2901) 2026-03-23 16:28:30 +07:00
cmd-run-cov.test.ts test: remove duplicate and theatrical tests (#2858) 2026-03-21 19:49:27 +07:00
cmd-status-cov.test.ts test: add comprehensive code coverage tests (#2802) 2026-03-19 22:24:54 -07:00
cmd-uninstall-cov.test.ts fix: prevent uninstall from truncating RC files with missing end marker (#2927) 2026-03-24 06:54:10 +07:00
cmd-update-cov.test.ts test: add comprehensive code coverage tests (#2802) 2026-03-19 22:24:54 -07:00
cmdlast.test.ts refactor: remove dead parameters from internal functions (#2581) 2026-03-13 09:55:03 -07:00
cmdlist-integration.test.ts fix: use process.env.HOME instead of os.homedir() for test sandboxing (#2417) 2026-03-10 00:20:19 -07:00
cmdrun-duplicate-detection.test.ts feat: add downloadFile to CloudRunner + local OpenClaw config merge (#2636) 2026-03-14 15:47:32 -07:00
cmdrun-happy-path.test.ts fix: resolve ANSI spinner corruption and garbled output (#3001) (#3003) 2026-03-26 15:28:32 +07:00
commands-cloud-info.test.ts test: remove duplicate and theatrical tests (#2645) 2026-03-15 01:15:00 -04:00
commands-display.test.ts feat: show cloud prices as lead indicator (#2347) 2026-03-08 23:41:39 -07:00
commands-error-paths.test.ts test: remove duplicate and theatrical tests (#2645) 2026-03-15 01:15:00 -04:00
commands-exported-utils.test.ts test: remove theatrical getTerminalWidth tests that can never fail (#2510) 2026-03-11 21:42:23 -04:00
commands-name-suggestions.test.ts test: consolidate duplicate function calls in test assertions (#2373) 2026-03-09 04:49:53 -04:00
commands-resolve-run.test.ts feat: add downloadFile to CloudRunner + local OpenClaw config merge (#2636) 2026-03-14 15:47:32 -07:00
commands-swap-resolve.test.ts feat: add downloadFile to CloudRunner + local OpenClaw config merge (#2636) 2026-03-14 15:47:32 -07:00
config-priority.test.ts feat: add --config and --steps CLI flags for programmatic setup (#2545) 2026-03-13 00:32:58 +00:00
credential-hints.test.ts test: remove duplicate and theatrical tests (#2763) 2026-03-18 06:37:40 -07:00
custom-flag.test.ts test: fix theatrical promptBundle test with real assertion (#2703) 2026-03-16 22:08:10 -07:00
delete-spinner.test.ts refactor: eliminate process-global mock.module() pollution in tests (#2490) 2026-03-10 23:57:57 -07:00
digitalocean-token.test.ts fix(digitalocean): add OAuth recovery in doApi for mid-session 401 errors (#2723) 2026-03-17 16:13:42 -07:00
do-cov.test.ts test: remove duplicate and theatrical tests (#2912) 2026-03-24 00:22:49 +07:00
do-min-size.test.ts test: remove theatrical source-grep tests, replace with real unit tests (#2948) 2026-03-24 02:08:45 -07:00
do-payment-warning.test.ts test: add comprehensive code coverage tests (#2802) 2026-03-19 22:24:54 -07:00
do-snapshot.test.ts fix(digitalocean): add OAuth recovery in doApi for mid-session 401 errors (#2723) 2026-03-17 16:13:42 -07:00
download-and-failure.test.ts feat: add downloadFile to CloudRunner + local OpenClaw config merge (#2636) 2026-03-14 15:47:32 -07:00
fs-sandbox.test.ts test: remove theatrical always-pass test from fs-sandbox (#2504) 2026-03-11 16:47:52 -04:00
fuzzy-key-matching.test.ts test: remove duplicate and theatrical tests (#2580) 2026-03-13 09:31:41 -04:00
gateway-resilience.test.ts test: remove duplicate and theatrical tests (#2650) 2026-03-15 08:49:51 -04:00
gcp-cov.test.ts test: remove duplicate and theatrical tests (#2912) 2026-03-24 00:22:49 +07:00
gcp-shellquote.test.ts test: remove duplicate and theatrical tests (#2652) 2026-03-15 13:11:58 -04:00
hetzner-cov.test.ts test: remove duplicate and theatrical tests (#2912) 2026-03-24 00:22:49 +07:00
hetzner-pagination.test.ts fix(hetzner): paginate SSH key and server list API calls to prevent truncation at 25 items (#2741) 2026-03-17 22:11:45 -07:00
history-corruption.test.ts fix: use process.env.HOME instead of os.homedir() for test sandboxing (#2417) 2026-03-10 00:20:19 -07:00
history-cov.test.ts test: remove duplicate and theatrical tests (#2846) 2026-03-20 17:57:40 -07:00
history-spawn-id.test.ts test: remove duplicate saveLaunchCmd fallback test from history-spawn-id (#2975) 2026-03-25 12:11:00 +07:00
history-trimming.test.ts test: remove duplicate saveSpawnRecord describe block (#2896) 2026-03-23 12:14:49 +07:00
history.test.ts fix: prevent permanent history lock when PID file write fails (#2928) 2026-03-24 06:47:10 +07:00
icon-integrity.test.ts test: remove duplicate and theatrical tests (#2868) 2026-03-22 12:06:55 +07:00
junie-agent.test.ts test: remove duplicate and theatrical tests (#2650) 2026-03-15 08:49:51 -04:00
kill-with-timeout.test.ts fix(ssh): always escalate to SIGKILL in killWithTimeout (#2752) 2026-03-18 05:54:38 +00:00
manifest-cache-lifecycle.test.ts test: remove 34 theatrical tests from manifest-cache-lifecycle.test.ts (#2317) 2026-03-08 01:18:54 -05:00
manifest-integrity.test.ts test: remove theatrical tests from manifest-integrity (#2552) 2026-03-12 21:41:03 -04:00
manifest-type-contracts.test.ts test: remove duplicate and theatrical tests (#2868) 2026-03-22 12:06:55 +07:00
manifest.test.ts fix: validate manifest fields are plain objects, not just truthy (#2921) 2026-03-24 06:48:54 +07:00
oauth-code-validation.test.ts fix: add unique spawn IDs to prevent history record corruption (#2235) 2026-03-05 23:27:03 -08:00
oauth-cov.test.ts style: remove unnecessary as never casts from oauth-cov.test.ts (#3002) 2026-03-26 14:33:58 +07:00
oauth-pkce.test.ts feat(oauth): add PKCE S256 code challenge to OpenRouter OAuth flow (#2654) 2026-03-15 10:14:48 -07:00
orchestrate-cov.test.ts test: remove duplicate and theatrical tests (#2981) 2026-03-25 20:37:47 +07:00
orchestrate.test.ts fix: skip interactive session in headless mode (#2895) 2026-03-22 21:38:53 -07:00
parse.test.ts refactor: Remove dead code and stale references (#2238) 2026-03-06 03:49:47 -05:00
paths.test.ts test: remove theatrical NODE_INSTALL_CMD test and fix banned homedir import (#2692) 2026-03-16 05:51:32 -07:00
picker-cov.test.ts test: remove duplicate and theatrical tests (#2826) 2026-03-20 06:11:57 -07:00
preflight-credentials.test.ts test: remove theatrical tests — replace no-op assertions with real signal (#2863) 2026-03-22 08:38:39 +07:00
preload.ts refactor: add no-try-catch + no-try-finally grit rules, eliminate all violations (#2481) 2026-03-10 21:27:25 -07:00
prompt-file-security.test.ts fix(security): resolve symlinks in prompt file validation to prevent bypass (#2744) 2026-03-17 22:21:11 -07:00
README.md test: remove theatrical source-grep test for docker-mode waitForReady (#2953) 2026-03-24 20:40:03 +07:00
recursive-spawn.test.ts refactor: use getSpawnCloudConfigPath(), remove dead _cloudName param (#3010) (#3012) 2026-03-26 19:26:09 +07:00
result-helpers.test.ts test: remove conditional-expect anti-pattern in result-helpers.test.ts (#2514) 2026-03-12 01:04:57 -04:00
run-path-credential-display.test.ts test: remove duplicate and theatrical tests (#2820) 2026-03-20 05:00:22 -07:00
script-failure-guidance.test.ts fix: pin GitHub Actions to commit SHAs, version-lock CI tools (#2983) 2026-03-26 00:27:58 +07:00
security-connection-validation.test.ts test: consolidate repetitive validateLaunchCmd and validatePreLaunchCmd valid-input tests (#2771) 2026-03-18 14:16:38 -07:00
security.test.ts test: remove duplicate and theatrical tests (#2652) 2026-03-15 13:11:58 -04:00
shared-helpers.test.ts feat: add downloadFile to CloudRunner + local OpenClaw config merge (#2636) 2026-03-14 15:47:32 -07:00
shell.test.ts test: consolidate redundant platform tests in shell.test.ts (#2767) 2026-03-18 10:28:09 -07:00
spawn-config.test.ts feat: add --config and --steps CLI flags for programmatic setup (#2545) 2026-03-13 00:32:58 +00:00
spawn-skill.test.ts fix: embed skill content instead of reading from disk (#2992) 2026-03-26 06:16:52 +07:00
sprite-cov.test.ts fix(security): add cmd validation to Sprite runSprite() and runSpriteSilent() (#2904) 2026-03-23 17:30:25 +07:00
sprite-keep-alive.test.ts fix(security): validate cmd parameter in sprite interactiveSession (#2888) 2026-03-22 18:53:28 -07:00
ssh-cov.test.ts fix: use POSIX normalize for remote Linux paths in validateRemotePath (#2929) 2026-03-23 19:34:49 -07:00
ssh-keys-cov.test.ts fix: handle missing ssh-keygen in getSshFingerprint (#2926) 2026-03-24 06:50:45 +07:00
ssh-keys.test.ts test: remove duplicate and theatrical tests (#2861) 2026-03-22 03:43:47 +07:00
steps-flag.test.ts test: remove duplicate and theatrical tests (#2700) 2026-03-16 20:12:47 -07:00
test-helpers.ts fix(types): remove as type assertions from test mocks (#2913) 2026-03-24 00:24:49 +07:00
ui-cov.test.ts test: remove duplicate validator tests from ui-cov.test.ts (#3004) 2026-03-26 16:27:58 +07:00
ui-utils.test.ts test: add coverage for retryOrQuit and skipCloudInit auto-detection (#2810) 2026-03-19 23:45:04 -07:00
unknown-flags.test.ts fix(ux): add spawn link to help output and --fast to KNOWN_FLAGS (#2828) 2026-03-20 08:49:26 -07:00
update-check-cov.test.ts test: remove duplicate checkForUpdates tests from update-check-cov.test.ts (#2997) 2026-03-25 18:57:18 -07:00
update-check.test.ts fix(update-check): redirect install script stdout to stderr in --output json mode (#2919) 2026-03-24 03:18:50 +07:00
with-retry-result.test.ts test: remove duplicate Result constructors describe block (#2704) 2026-03-17 02:23:24 -07:00

CLI Tests

This directory contains unit tests for the Spawn CLI TypeScript implementation.

Test Runner

Tests use Bun's built-in test runner (bun:test). Do NOT use vitest.

# Run all tests
bun test

# Run a specific file
bun test src/__tests__/manifest.test.ts

Test Files

Core manifest

  • manifest.test.tsagentKeys, cloudKeys, matrixStatus, countImplemented, loadManifest (cache/network), stripDangerousKeys
  • manifest-integrity.test.ts — Structural validation: script files exist for implemented entries, no orphans
  • manifest-type-contracts.test.ts — Field type precision for every agent/cloud in the real manifest
  • manifest-cache-lifecycle.test.ts — Cache TTL, expiry, forced refresh

Commands: happy paths

  • cmdrun-happy-path.test.ts — Successful download, history recording, env var passing
  • cmd-interactive.test.ts — Interactive agent/cloud selection flow
  • cmd-listing-output.test.tscmdMatrix, cmdAgents, cmdClouds output formatting
  • cmdlast.test.tscmdLast: history display and resumption
  • cmdlist-integration.test.tscmdList with real history records
  • commands-display.test.tscmdAgentInfo (happy path), cmdHelp
  • commands-cloud-info.test.tscmdCloudInfo display
  • cmd-update-cov.test.tscmdUpdate, script download and execution
  • cmd-feedback.test.tsspawn feedback command: empty message rejection, URL construction
  • cmd-fix.test.tsspawn fix command: SSH connection repair via DI-injected runScript
  • cmd-link.test.tsspawn link command: TCP reachability check, SSH agent detection via DI

Commands: coverage tests

  • cmd-connect-cov.test.tscmdConnect, cmdEnterAgent, cmdOpenDashboard coverage
  • cmd-delete-cov.test.tscmdDelete coverage
  • cmd-fix-cov.test.tscmdFix, fixSpawn coverage
  • cmd-interactive-cov.test.tscmdInteractive, cmdAgentInteractive coverage
  • cmd-link-cov.test.tscmdLink coverage
  • cmd-list-cov.test.tscmdList coverage
  • cmd-pick-cov.test.tscmdPick coverage
  • cmd-run-cov.test.tscmdRun, cmdRunHeadless coverage
  • cmd-status-cov.test.tscmdStatus coverage
  • cmd-uninstall-cov.test.tscmdUninstall coverage

Commands: error paths

  • commands-error-paths.test.ts — Validation failures, unknown agents/clouds, prompt rejection
  • commands-name-suggestions.test.ts — Display name typo suggestions in errors
  • commands-swap-resolve.test.tsdetectAndFixSwappedArgs, resolveAndLog
  • commands-resolve-run.test.ts — Display name resolution in cmdRun
  • cmdrun-duplicate-detection.test.ts--name collision detection

Commands: utilities

  • commands-exported-utils.test.tsparseAuthEnvVars, getImplementedAgents, getMissingClouds, getErrorMessage, etc.
  • script-failure-guidance.test.tsgetScriptFailureGuidance, getSignalGuidance, buildRetryCommand
  • download-and-failure.test.ts — Download fallback pipeline, failure reporting
  • run-path-credential-display.test.tsprioritizeCloudsByCredentials, run-path validation
  • delete-spinner.test.tsconfirmAndDelete: spinner messages from stderr, final result display
  • steps-flag.test.ts--steps and --config flags: findUnknownFlag, getAgentOptionalSteps, validateStepNames

Security

  • security.test.tsvalidateIdentifier, validateScriptContent, validatePrompt (core, boundary, encoding edge cases)
  • security-connection-validation.test.tsvalidateConnectionIP, validateUsername, validateServerIdentifier, validateLaunchCmd
  • prompt-file-security.test.tsvalidatePromptFilePath, validatePromptFileStats

Infrastructure: coverage tests

  • agent-setup-cov.test.tssetupAgent, wrapSshCall, agent setup orchestration coverage
  • aws-cov.test.ts — AWS module coverage
  • do-cov.test.ts — DigitalOcean module coverage
  • gcp-cov.test.ts — GCP module coverage
  • hetzner-cov.test.ts — Hetzner module coverage
  • history-cov.test.ts — History module coverage
  • oauth-cov.test.ts — OAuth module coverage
  • orchestrate-cov.test.tsrunOrchestration coverage
  • sprite-cov.test.ts — Sprite module coverage
  • ssh-cov.test.ts — SSH helpers coverage
  • ssh-keys-cov.test.ts — SSH key management coverage
  • ui-cov.test.ts — UI helpers coverage
  • update-check-cov.test.ts — Update check coverage

Infrastructure

  • history.test.ts — History read/write
  • history-trimming.test.ts — History trimming at size limits
  • history-corruption.test.ts — History corruption recovery: malformed JSON, concurrent writes
  • clear-history.test.tsclearHistory, cmdListClear
  • paths.test.tsgetSpawnDir, getCacheDir, getHistoryPath, getSshDir, path resolution
  • ssh-keys.test.ts — SSH key discovery, generation, fingerprinting
  • update-check.test.ts — Auto-update check logic
  • auto-update.test.tssetupAutoUpdate: systemd service unit generation and orchestration integration
  • kill-with-timeout.test.tskillWithTimeout: SIGKILL after grace period, already-exited process handling
  • with-retry-result.test.tswithRetry, wrapSshCall, Result constructors
  • orchestrate.test.tsrunOrchestration
  • shell.test.tsgetLocalShell, isWindows, getInstallCmd, getWhichCommand, getInstallScriptUrl: platform-aware shell detection
  • fs-sandbox.test.ts — Guardrail: verifies test preload sandbox isolates filesystem writes

Parsing and type utilities

  • parse.test.tsparseJsonWith
  • picker-cov.test.tsparsePickerInput: tab-separated picker input parsing, pickFallback, pickToTTY, pickToTTYWithActions
  • fuzzy-key-matching.test.tsfindClosestKeyByNameOrKey, levenshtein, findClosestMatch, resolveAgentKey, resolveCloudKey
  • unknown-flags.test.ts — Unknown flag detection, KNOWN_FLAGS, expandEqualsFlags
  • custom-flag.test.ts--custom flag for AWS, GCP, Hetzner, DigitalOcean
  • credential-hints.test.tscredentialHints
  • cloud-credentials.test.tshasCloudCredentials
  • preflight-credentials.test.tspreflightCredentialCheck
  • result-helpers.test.tsasyncTryCatch, asyncTryCatchIf, tryCatch, tryCatchIf, mapResult, unwrapOr
  • config-priority.test.tsloadSpawnConfig default values, field merging, and override priority
  • spawn-config.test.tsloadSpawnConfig file parsing, validation, size limits, and null-byte rejection

Cloud-specific

  • aws.test.ts — AWS credential cache, SigV4 signing helpers
  • billing-guidance.test.tsisBillingError, handleBillingError, showNonBillingError
  • cloud-init.test.tsgetPackagesForTier, needsNode, needsBun, NODE_INSTALL_CMD
  • check-entity.test.ts / check-entity-messages.test.ts — Entity validation
  • agent-tarball.test.tstryTarballInstall: GitHub Release tarball install, fallback, URL validation
  • gateway-resilience.test.tsstartGateway systemd unit with auto-restart and cron heartbeat
  • digitalocean-token.test.ts — DigitalOcean token storage, retrieval, and API client helpers
  • do-min-size.test.ts — DigitalOcean minimum droplet size enforcement: slugRamGb RAM comparison, AGENT_MIN_SIZE map
  • do-payment-warning.test.tsensureDoToken proactive payment method reminder for first-time DigitalOcean users
  • do-snapshot.test.tsfindSpawnSnapshot: DigitalOcean snapshot lookup, filtering, error handling
  • hetzner-pagination.test.ts — Hetzner API pagination: multi-page server listing and cursor handling
  • sprite-keep-alive.test.tsinstallSpriteKeepAlive download/install, graceful failure, session script wrapping
  • ui-utils.test.tsvalidateServerName, validateRegionName, toKebabCase, sanitizeTermValue, jsonEscape
  • gcp-shellquote.test.tsshellQuote GCP-specific quoting edge cases

Agent-specific

  • junie-agent.test.ts — Junie CLI agent configuration validation

Shared helpers

  • shared-helpers.test.tsgenerateEnvConfig, hasStatus, toObjectArray, toRecord

OAuth and auth

  • oauth-code-validation.test.tsOAUTH_CODE_REGEX format validation
  • oauth-pkce.test.tsgenerateCodeVerifier, generateCodeChallenge PKCE S256 flow

History (extended)

  • history-spawn-id.test.ts — Unique spawn IDs, saveVmConnection/saveLaunchCmd by spawnId, concurrent spawn isolation

Manifest (extended)

  • icon-integrity.test.ts — Icon file existence and format validation

Support files (not test files)

  • test-helpers.ts — Shared fixtures: createMockManifest, mockClackPrompts, setupTestEnvironment, etc.
  • preload.ts — Global test setup (temp dir isolation, env sandboxing)