|
| 1 | +# Sprint 43: CLI Error Consistency + Import Validation |
| 2 | + |
| 3 | +**Goal:** Close remaining CLI correctness gaps so `run`, `check`, and `build` have consistent import handling and JSON error behavior. |
| 4 | +**Estimated Effort:** 0.5-1 day |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Context |
| 9 | + |
| 10 | +Post-Sprint-42 verification still shows two launch-relevant issues: |
| 11 | + |
| 12 | +1. `check --error-format json` reports success for missing imports. |
| 13 | +2. `build --error-format json` can fail silently (non-zero exit, empty JSON output) on early errors. |
| 14 | + |
| 15 | +There is also process confusion around workspace/commit state, so this sprint includes explicit hygiene checks in CI/local verification. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Agent Instructions |
| 20 | + |
| 21 | +1. Treat this as a correctness sprint, not a refactor sprint. |
| 22 | +2. Keep behavior aligned across `run`, `check`, and `build` for module loading and JSON error output. |
| 23 | +3. Add regression tests first-class (must fail before fix, pass after fix). |
| 24 | +4. Do not weaken or skip tests to get green. |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## Task 43.1: Make `check` Validate Imports |
| 29 | + |
| 30 | +**Priority:** P0 |
| 31 | + |
| 32 | +**Files (likely):** |
| 33 | +- `src/main.rs` |
| 34 | +- `src/module/loader.rs` (only if needed) |
| 35 | +- `tests/cli_tests.rs` |
| 36 | +- fixtures under `tests/fixtures/` |
| 37 | + |
| 38 | +### Requirements |
| 39 | + |
| 40 | +1. In `check(...)`, load imports the same way `run(...)` and `build(...)` do. |
| 41 | +2. Missing imports must produce an error (not success) in both human and JSON modes. |
| 42 | +3. Preserve existing `--partial` behavior, but include module errors in the structured response. |
| 43 | + |
| 44 | +### Acceptance Criteria |
| 45 | + |
| 46 | +1. `forma check --error-format json <file-with-missing-import>` returns non-zero and JSON with `success: false` and at least one `MODULE` error. |
| 47 | +2. `forma check <file-with-missing-import>` prints human-readable module error and exits non-zero. |
| 48 | +3. Existing successful-check flows still pass. |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## Task 43.2: Ensure `build` Always Emits JSON Errors on Failure |
| 53 | + |
| 54 | +**Priority:** P0 |
| 55 | + |
| 56 | +**Files (likely):** |
| 57 | +- `src/main.rs` |
| 58 | +- `tests/cli_tests.rs` |
| 59 | + |
| 60 | +### Requirements |
| 61 | + |
| 62 | +1. For all early `build(...)` failure paths (lex/parse/module/type/codegen/link), if `--error-format json` is set, emit a JSON error payload before returning. |
| 63 | +2. Eliminate silent JSON failures (non-zero with empty stdout/stderr JSON body). |
| 64 | +3. Keep current human-format output unchanged. |
| 65 | + |
| 66 | +### Acceptance Criteria |
| 67 | + |
| 68 | +1. `forma build --error-format json <file-with-missing-import>` returns non-zero and prints structured JSON error output. |
| 69 | +2. At least one regression test asserts that build failure in JSON mode is never silent. |
| 70 | +3. No regression in successful build JSON output. |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Task 43.3: CLI Parity Regression Tests |
| 75 | + |
| 76 | +**Priority:** P1 |
| 77 | + |
| 78 | +**Files (likely):** |
| 79 | +- `tests/cli_tests.rs` |
| 80 | +- `tests/fixtures/missing_import.forma` |
| 81 | + |
| 82 | +### Requirements |
| 83 | + |
| 84 | +1. Add tests covering missing-import behavior for: |
| 85 | +- `run --error-format json` |
| 86 | +- `check --error-format json` |
| 87 | +- `build --error-format json` |
| 88 | +2. Assert parity of key fields (`success`, `code`, non-empty `errors`, exit status). |
| 89 | + |
| 90 | +### Acceptance Criteria |
| 91 | + |
| 92 | +1. All three commands fail consistently on missing import with structured JSON errors. |
| 93 | +2. New tests are deterministic and pass in CI. |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## Task 43.4: Workspace Hygiene Guardrail |
| 98 | + |
| 99 | +**Priority:** P1 |
| 100 | + |
| 101 | +**Files (likely):** |
| 102 | +- `.github/workflows/ci.yml` (optional) |
| 103 | +- docs/PR checklist (optional) |
| 104 | + |
| 105 | +### Requirements |
| 106 | + |
| 107 | +1. Add a lightweight verification step/checklist item in sprint output requiring: |
| 108 | +- `git status --short` capture before final summary |
| 109 | +- explicit list of intentionally untracked files (if any) |
| 110 | +2. Ensure sprint completion summaries clearly distinguish: |
| 111 | +- committed changes |
| 112 | +- uncommitted workspace edits |
| 113 | + |
| 114 | +### Acceptance Criteria |
| 115 | + |
| 116 | +1. Final verification output includes commit hash and clean/dirty status. |
| 117 | +2. No ambiguity about whether fixes are committed. |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## Verification Checklist |
| 122 | + |
| 123 | +Run and include results in PR summary: |
| 124 | + |
| 125 | +1. `cargo test --all` |
| 126 | +2. `cargo clippy --all-targets -- -D warnings` |
| 127 | +3. `cargo clippy --all-features --all-targets -- -D warnings` |
| 128 | +4. `cargo fmt --all -- --check` |
| 129 | +5. `cargo build --release` |
| 130 | +6. Targeted CLI repros: |
| 131 | +- `forma check --error-format json tests/fixtures/missing_import.forma` |
| 132 | +- `forma build --error-format json tests/fixtures/missing_import.forma` |
| 133 | +- `forma run --error-format json tests/fixtures/missing_import.forma` |
| 134 | +7. `git status --short` and `git log --oneline -n 1` |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +## Out of Scope |
| 139 | + |
| 140 | +1. New module system features. |
| 141 | +2. Capability model changes. |
| 142 | +3. Broad CLI redesign. |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +## Definition of Done |
| 147 | + |
| 148 | +1. `check` no longer reports false success on missing imports. |
| 149 | +2. `build --error-format json` never fails silently. |
| 150 | +3. CLI parity tests cover and lock this behavior. |
| 151 | +4. Sprint summary includes explicit commit/worktree state. |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## Coding Agent Prompt |
| 156 | + |
| 157 | +```text |
| 158 | +Implement Sprint 43: CLI Error Consistency + Import Validation. |
| 159 | +
|
| 160 | +Fix these exact defects: |
| 161 | +1) `forma check --error-format json` currently returns success on missing imports. |
| 162 | +2) `forma build --error-format json` can fail silently (non-zero exit with no JSON error output) on early failures. |
| 163 | +
|
| 164 | +Requirements: |
| 165 | +- Make `check` load/validate imports consistently with `run` and `build`. |
| 166 | +- Ensure `build` emits JSON-formatted errors for all failure paths when `--error-format json` is set. |
| 167 | +- Add regression tests in tests/cli_tests.rs using a missing-import fixture. |
| 168 | +- Keep human-readable output behavior intact. |
| 169 | +
|
| 170 | +Validation to run: |
| 171 | +- cargo test --all |
| 172 | +- cargo clippy --all-targets -- -D warnings |
| 173 | +- cargo clippy --all-features --all-targets -- -D warnings |
| 174 | +- cargo fmt --all -- --check |
| 175 | +- cargo build --release |
| 176 | +- forma check/build/run --error-format json on missing-import fixture |
| 177 | +- git status --short |
| 178 | +- git log --oneline -n 1 |
| 179 | +
|
| 180 | +Deliverables: |
| 181 | +- code changes |
| 182 | +- regression tests |
| 183 | +- concise summary with file list, command results, and commit hash |
| 184 | +``` |
0 commit comments