# Command Testing Patterns

**How to test meta plugin commands during development**

---

## Headless Execution Pattern

When testing commands, use direct headless Claude Code execution:

```bash
# Basic pattern
claude --dangerously-skip-permissions --model haiku "capture: test idea"
claude --dangerously-skip-permissions --model sonnet "apply razors to: build X"

# Save output to log
claude --dangerously-skip-permissions --model haiku \
  "show me my inbox" \
  2>&1 | tee /tmp/test-output.log
```

**Why headless over Task tool:**
- Faster for command testing
- Can use slash command syntax (Task tool can't)
- Direct output control (pipes, tee)
- Good for one-off verification

---

## Test Workflow

```bash
# 1. Set up log directory
LOG_DIR=~/workspace/logs/$(date +%Y-%m-%d)-command-test
mkdir -p "$LOG_DIR"

# 2. Test command with logging
claude --dangerously-skip-permissions --model haiku \
  "capture: test item $(date +%s)" \
  2>&1 | tee "$LOG_DIR/capture-test.log"

# 3. Verify persistence
cat ~/workspace/ops/inbox.md | tail -10

# 4. Check for errors
grep -i "error\|fail" "$LOG_DIR/capture-test.log"
```

---

## Commands and Their Persistence

| Command | Persists To | Notes |
|---------|-------------|-------|
| `/capture` | `~/workspace/ops/inbox.md` | ✅ Auto-persists |
| `/inbox` | (none) | Read-only display |
| `/work` | (none) | Read-only display |
| `/razor` | **Missing** | Should persist to killed.md/exo-coord |
| `/ship` | (none) | Read-only display |

**Known gap:** Razor doesn't persist verdicts yet. Outputs go to logs only.

---

## Output Capture Patterns

```bash
# Save full output
claude ... "command" > /tmp/output.log

# Save stdout + stderr
claude ... "command" 2>&1 > /tmp/full-output.log

# Save and watch
claude ... "command" 2>&1 | tee /tmp/output.log

# Background with logging
claude ... "command" > /tmp/output.log 2>&1 &
```

---

## Shell Interpolation Testing

Commands use shell interpolation for dynamic context:

```markdown
# In command frontmatter
- Inbox count: !`grep -c "^## " ~/workspace/ops/inbox.md`
```

**To test:**
1. Trigger command that uses interpolation
2. Check output contains actual values (not the shell command)
3. Verify values are current (not cached)

**Example:**
```bash
claude ... "show me my inbox"
# Should show: "INBOX: [8] items"
# NOT: "INBOX: !`grep -c...` items"
```

---

## QA Checklist

Before committing command changes:

- [ ] Test command headless (basic execution)
- [ ] Verify shell interpolation (if used)
- [ ] Check persistence (if command writes files)
- [ ] Test error cases (missing files, empty state)
- [ ] Verify allowed-tools (command can execute)
- [ ] Update CHANGELOG.md
- [ ] Bump plugin version

---

## Full QA Report

For comprehensive testing approach, see:
- `reports/2025-12-20-workflow-qa-comprehensive.md`
- `HEADLESS-CLAUDE-PATTERNS.md`

---

*Last updated: 2025-12-20*
