|
| 1 | +# /implement — Plan and Implement from notes/plan.md |
| 2 | + |
| 3 | +Orchestrates the full implementation workflow: plan → implement → test → verify → commit → document. |
| 4 | + |
| 5 | +## Reference Codebases |
| 6 | + |
| 7 | +- **tmuxinator**: `~/study/ruby/tmuxinator/` |
| 8 | +- **teamocil**: `~/study/ruby/teamocil/` |
| 9 | +- **tmux**: `~/study/c/tmux/` |
| 10 | +- **libtmux**: `~/work/python/libtmux/` |
| 11 | +- **tmuxp**: `~/work/python/tmuxp/` |
| 12 | + |
| 13 | +## Workflow |
| 14 | + |
| 15 | +### Phase 1: Planning Mode |
| 16 | + |
| 17 | +1. **Read the plan**: Load `notes/plan.md` to understand what needs to be implemented |
| 18 | +2. **Select a task**: Pick the highest priority incomplete item from the plan |
| 19 | +3. **Research**: |
| 20 | + - Read relevant tmuxinator/teamocil Ruby source for behavior reference |
| 21 | + - Read libtmux Python source for available APIs |
| 22 | + - Read tmuxp source for integration points |
| 23 | + - **Study existing tests** for similar functionality (see Testing Pattern below) |
| 24 | +4. **Create implementation plan**: Design the specific changes needed |
| 25 | +5. **Exit planning mode** with the finalized approach |
| 26 | + |
| 27 | +### Phase 2: Implementation |
| 28 | + |
| 29 | +1. **Make changes**: Edit the necessary files |
| 30 | +2. **Follow conventions**: Match existing code style, use type hints, add docstrings |
| 31 | + |
| 32 | +### Phase 3: Write Tests |
| 33 | + |
| 34 | +**CRITICAL**: Before running verification, write tests for new functionality. |
| 35 | + |
| 36 | +1. **Find similar tests**: Search `tests/` for existing tests of similar features |
| 37 | +2. **Follow the project test pattern** (see Testing Pattern below) |
| 38 | +3. **Add test cases**: Cover normal cases, edge cases, and error conditions |
| 39 | + |
| 40 | +### Phase 4: Verification |
| 41 | + |
| 42 | +Run the full QA suite: |
| 43 | + |
| 44 | +```bash |
| 45 | +uv run ruff check . --fix --show-fixes |
| 46 | +uv run ruff format . |
| 47 | +uv run mypy |
| 48 | +uv run py.test --reruns 0 -vvv |
| 49 | +``` |
| 50 | + |
| 51 | +All checks must pass before proceeding. |
| 52 | + |
| 53 | +### Phase 5: Commit Implementation |
| 54 | + |
| 55 | +**Source and tests must be in separate commits.** |
| 56 | + |
| 57 | +1. **Commit source code first**: Implementation changes only (e.g., `fix(cli): Read socket_name/path and config from workspace config`) |
| 58 | +2. **Commit tests second**: Test files only (e.g., `tests(cli): Add config key precedence tests for load_workspace`) |
| 59 | + |
| 60 | +Follow the project's commit conventions (e.g., `feat:`, `fix:`, `refactor:` for source; `tests:` or `tests(<scope>):` for tests). |
| 61 | + |
| 62 | +### Phase 6: Update Documentation |
| 63 | + |
| 64 | +1. **Update `notes/completed.md`**: Add entry for what was implemented |
| 65 | + - Date |
| 66 | + - What was done |
| 67 | + - Files changed |
| 68 | + - Any notes or follow-ups |
| 69 | + |
| 70 | +2. **Update `notes/plan.md`**: Mark the item as complete or remove it |
| 71 | + |
| 72 | +3. **Commit notes separately**: Use message like `notes: Mark <feature> as complete` |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +## Testing Pattern |
| 77 | + |
| 78 | +This project uses a consistent test pattern. **Always follow this pattern for new tests.** |
| 79 | + |
| 80 | +### 1. NamedTuple Fixture Class |
| 81 | + |
| 82 | +```python |
| 83 | +import typing as t |
| 84 | + |
| 85 | +class MyFeatureTestFixture(t.NamedTuple): |
| 86 | + """Test fixture for my feature tests.""" |
| 87 | + |
| 88 | + # pytest (internal): Test fixture name |
| 89 | + test_id: str |
| 90 | + |
| 91 | + # test params |
| 92 | + input_value: str |
| 93 | + expected_output: str |
| 94 | + expected_error: str | None = None |
| 95 | +``` |
| 96 | + |
| 97 | +### 2. Fixture List |
| 98 | + |
| 99 | +```python |
| 100 | +TEST_MY_FEATURE_FIXTURES: list[MyFeatureTestFixture] = [ |
| 101 | + MyFeatureTestFixture( |
| 102 | + test_id="normal-case", |
| 103 | + input_value="foo", |
| 104 | + expected_output="bar", |
| 105 | + ), |
| 106 | + MyFeatureTestFixture( |
| 107 | + test_id="edge-case-empty", |
| 108 | + input_value="", |
| 109 | + expected_output="", |
| 110 | + ), |
| 111 | + MyFeatureTestFixture( |
| 112 | + test_id="error-case", |
| 113 | + input_value="bad", |
| 114 | + expected_output="", |
| 115 | + expected_error="Invalid input", |
| 116 | + ), |
| 117 | +] |
| 118 | +``` |
| 119 | + |
| 120 | +### 3. Parametrized Test Function |
| 121 | + |
| 122 | +```python |
| 123 | +@pytest.mark.parametrize( |
| 124 | + "test", |
| 125 | + TEST_MY_FEATURE_FIXTURES, |
| 126 | + ids=[test.test_id for test in TEST_MY_FEATURE_FIXTURES], |
| 127 | +) |
| 128 | +def test_my_feature(test: MyFeatureTestFixture) -> None: |
| 129 | + """Test my feature with various inputs.""" |
| 130 | + result = my_function(test.input_value) |
| 131 | + assert result == test.expected_output |
| 132 | + |
| 133 | + if test.expected_error: |
| 134 | + # check error handling |
| 135 | + pass |
| 136 | +``` |
| 137 | + |
| 138 | +### Key Rules |
| 139 | + |
| 140 | +- **Function tests only** — No `class TestFoo:` groupings (per CLAUDE.md) |
| 141 | +- **Use fixtures from `tests/fixtures/`** — Prefer real tmux fixtures over mocks |
| 142 | +- **Use `tmp_path`** — Not Python's `tempfile` |
| 143 | +- **Use `monkeypatch`** — Not `unittest.mock` |
| 144 | + |
| 145 | +--- |
| 146 | + |
| 147 | +## Output |
| 148 | + |
| 149 | +After completion, report: |
| 150 | +- What was implemented |
| 151 | +- Files changed (including test files) |
| 152 | +- Test results summary |
| 153 | +- What remains in the plan |
| 154 | + |
| 155 | +## Notes |
| 156 | + |
| 157 | +- If tests fail, fix the issues before committing |
| 158 | +- If libtmux changes are needed, note them but don't modify libtmux in this workflow |
| 159 | +- One logical change per run — don't implement multiple unrelated items |
| 160 | +- **Always write tests** — No implementation is complete without tests |
0 commit comments