spawn/packages/cli/src/__tests__
A 5004a4db52
test: replace loose cloud-type count assertion with enumerated known-set check (#2709)
The "should have a reasonable number of distinct cloud types" test used
toBeGreaterThanOrEqual(2) and toBeLessThanOrEqual(10) — bounds so wide
they would never catch a real type-naming mistake. Replace it with an
explicit allowlist check so adding an unknown type fails immediately.

Current valid types (api, cli, local) are all in the set; vm, container,
sandbox, and cloud are pre-approved to avoid blocking planned additions.

Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 09:55:15 -07:00
..
agent-tarball.test.ts test: remove duplicate and theatrical tests (#2677) 2026-03-15 22:20:53 -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 fix(digitalocean): catch billing 403 thrown by doApi on droplet creation (#2628) 2026-03-14 18:09:48 -04: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 refactor: centralize path resolution into shared/paths.ts (#2422) 2026-03-10 00:48:03 -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 test: remove theatrical NODE_INSTALL_CMD test and fix banned homedir import (#2692) 2026-03-16 05:51:32 -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.test.ts fix: prepend IS_SANDBOX and PATH exports in buildFixScript (#2604) 2026-03-13 20:35:49 -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.test.ts feat(cli): add spawn link command to reconnect existing deployments (#2675) 2026-03-15 23:11:13 -07:00
cmd-listing-output.test.ts feat: show cloud prices as lead indicator (#2347) 2026-03-08 23:41:39 -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 test: remove duplicate and theatrical tests (#2677) 2026-03-15 22:20:53 -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
commands-update-download.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 (#2643) 2026-03-14 21:40:25 -04: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
do-payment-warning.test.ts fix(digitalocean): warn first-time users about required payment method (#2403) 2026-03-09 16:54:11 -07:00
do-snapshot.test.ts refactor: eliminate process-global mock.module() pollution in tests (#2490) 2026-03-10 23:57:57 -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-shellquote.test.ts test: remove duplicate and theatrical tests (#2652) 2026-03-15 13:11:58 -04: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-spawn-id.test.ts refactor: centralize path resolution into shared/paths.ts (#2422) 2026-03-10 00:48:03 -07:00
history-trimming.test.ts fix: use process.env.HOME instead of os.homedir() for test sandboxing (#2417) 2026-03-10 00:20:19 -07:00
history.test.ts test: remove duplicate getSpawnDir/getHistoryPath tests from history.test.ts (#2426) 2026-03-10 02:35:13 -07:00
icon-integrity.test.ts test: remove duplicate and theatrical tests (#2539) 2026-03-12 16:48:33 -04:00
junie-agent.test.ts test: remove duplicate and theatrical tests (#2650) 2026-03-15 08:49:51 -04: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: replace loose cloud-type count assertion with enumerated known-set check (#2709) 2026-03-17 09:55:15 -07:00
manifest.test.ts test: consolidate duplicate security validation tests (#2382) 2026-03-09 10:37:01 -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-pkce.test.ts feat(oauth): add PKCE S256 code challenge to OpenRouter OAuth flow (#2654) 2026-03-15 10:14:48 -07:00
orchestrate.test.ts feat: add downloadFile to CloudRunner + local OpenClaw config merge (#2636) 2026-03-14 15:47:32 -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.test.ts test: add unit tests for parsePickerInput in picker.ts (#2421) 2026-03-10 01:31:59 -07:00
preflight-credentials.test.ts fix: check saved OpenRouter key and return empty list when cloud config exists (#2640) 2026-03-14 20:37:18 -04: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 test: Remove duplicate and theatrical tests (#2534) 2026-03-12 12:52:45 -04:00
README.md docs: add cmd-link.test.ts to test README index (#2705) 2026-03-17 05:51:51 -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 feat: show cloud prices as lead indicator (#2347) 2026-03-08 23:41:39 -07:00
script-failure-guidance.test.ts test: remove duplicate and theatrical tests (#2694) 2026-03-16 14:17:27 -07:00
security-connection-validation.test.ts fix(security): validate tunnel URL and port from history before openBrowser() (#2697) 2026-03-16 15:22:29 -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
spawn-config.test.ts feat: add --config and --steps CLI flags for programmatic setup (#2545) 2026-03-13 00:32:58 +00:00
sprite-keep-alive.test.ts fix(sprite): replace personal VM URL with official CDN for keep-alive script (#2701) 2026-03-16 20:04:49 -07:00
ssh-keys.test.ts test: remove duplicate and theatrical tests (#2616) 2026-03-14 12:46:55 -04:00
steps-flag.test.ts test: remove duplicate and theatrical tests (#2700) 2026-03-16 20:12:47 -07:00
test-helpers.ts fix: remove spinner from delete to prevent output overlap (#2487) 2026-03-10 23:35:12 -07:00
ui-utils.test.ts security: add shell quoting around TERM in cloud module commands (#2579) 2026-03-13 08:17:46 -04:00
unknown-flags.test.ts test: remove duplicate and theatrical tests (#2700) 2026-03-16 20:12:47 -07:00
update-check.test.ts refactor: add no-try-catch + no-try-finally grit rules, eliminate all violations (#2481) 2026-03-10 21:27:25 -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
  • commands-update-download.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: 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

  • 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
  • with-retry-result.test.tswithRetry, wrapSshCall, Result constructors
  • orchestrate.test.tsrunOrchestration
  • fs-sandbox.test.ts — Guardrail: verifies test preload sandbox isolates filesystem writes

Parsing and type utilities

  • parse.test.tsparseJsonWith
  • picker.test.tsparsePickerInput: tab-separated picker input parsing
  • 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
  • do-payment-warning.test.tsensureDoToken proactive payment method reminder for first-time DigitalOcean users
  • do-snapshot.test.tsfindSpawnSnapshot: DigitalOcean snapshot lookup, filtering, error 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)