Skip to content

test: add unit tests for alias, alias resolution, and msg commands#28

Open
mldangelo wants to merge 1 commit intomainfrom
test/add-msg-ticket-alias-tests
Open

test: add unit tests for alias, alias resolution, and msg commands#28
mldangelo wants to merge 1 commit intomainfrom
test/add-msg-ticket-alias-tests

Conversation

@mldangelo
Copy link
Member

Summary

  • Add 29 new unit tests covering three features that had zero test coverage
  • All tests run locally without tmux or Docker (part of make test)

Alias command tests (17 tests)

  • Empty state listing, argument validation for set/rm
  • Name validation: rejects spaces and special chars, accepts hyphens and underscores
  • Full CRUD lifecycle: set, list, overwrite, remove
  • Persistence verified directly via yq against ~/.crabcode/config.yaml
  • Unknown subcommand error handling

Alias resolution tests (2 tests)

  • Verifies crab <alias> resolves to the target command at runtime
  • Single-word and multi-word alias resolution

Msg command tests (10 tests)

  • Help output and no-args behavior
  • Status display without active relay
  • Text-to-speech toggle (on/off) and state reflection
  • Unknown subcommand handling
  • Graceful degradation for read/history without relay

Test plan

  • make test — all 29 new tests pass
  • Pre-existing failures (14) confirmed unchanged via git stash comparison
  • Tests clean up after themselves (backup/restore global config, remove test aliases)
Results: 40 passed, 14 failed (54 total)
# Before this PR: 11 passed, 14 failed (25 total)
# Net: +29 passing tests, 0 new failures

🤖 Generated with Claude Code

Add 29 new unit tests covering three previously untested features:

Alias command tests (17):
- List empty state, set/rm argument validation
- Name validation (spaces, special chars rejected; hyphens, underscores ok)
- Set, list, overwrite, remove operations
- Persistence in global config verified via yq
- Unknown subcommand handling

Alias resolution tests (2):
- Single-word alias resolves to target command
- Multi-word alias resolves correctly

Msg command tests (10):
- Help output, status display, say toggle (on/off/state)
- Unknown subcommand handling
- Graceful behavior for read/history without active relay

All 29 new tests pass. Pre-existing test failures unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mldangelo added a commit that referenced this pull request Feb 14, 2026
Root causes fixed:
- Config parsing tests: single-quoted $TEST_CONFIG prevented variable
  expansion inside run_test's eval, so yq opened literal "$TEST_CONFIG"
- Config without config: test assumed no ~/.crabcode/ exists but user
  config was present; broadened pattern to match "No projects" output
- Ticket/subcommand tests: commands hit load_config + validate_config
  before reaching validation logic, failing with "Missing required
  config" since no project was configured
- Unknown subcommand: same config dependency; changed to use "ws 1
  foobar" which routes through the ws handler properly

Fixes applied:
- Add test isolation: backup/restore ~/.crabcode via trap EXIT so
  tests never pollute or depend on user's real config
- Fix yq quoting: use escaped \$(yq ...) so expansion happens at
  eval time, not parse time
- Create minimal project config (temp git repo + project yaml) for
  tests that require config validation
- Guard ticket tests behind yq check since they need project config
- Clean up temp repos on exit

Also includes the 29 new tests from PR #28 (alias, alias resolution,
msg) with the same isolation improvements.

Results: 54 passed, 0 failed (was: 11 passed, 14 failed)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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

Comments