* chore: add task spec for issue 258 * chore: add implementation plan for issue 258 * fix(spec): address CodeRabbit review comments on plan and spec - Plan: clarify git diff strategy (local HEAD vs CI origin/dev...HEAD) - Plan: add Phase 2 rename/delete/add handling via git diff --name-status - Plan: add N:M test file discovery (not just 1:1 mapping) - Plan: align Phase 3 with existing runTest() infrastructure - Plan: replace raw `go test ./...` fallback with runTest() call - Plan: correct file paths to internal/cmd/test/ (not cmd/core/cmd/) - Spec: explicitly scope as Go-only with note on future language support - Spec: wrap bare URL in angle brackets - Spec: add --base flag for CI/PR context - Spec: update acceptance criteria to match revised plan - Spec: add technical context pointing to existing infrastructure Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * ci: retrigger checks after disabling default CodeQL setup Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2.9 KiB
2.9 KiB
Implementation Plan: Issue 258
Phase 1: Command Structure
- Extend existing
internal/cmd/test/cmd_main.gowith smart detection flags - Add flags:
--all,--filter(alias for--run) - Existing flags (
--coverage,--verbose,--short,--race,--json,--pkg,--run) are already registered
Phase 2: Change Detection
- Determine diff strategy based on context:
- Local development (default):
git diff --name-only HEADfor uncommitted changes, plusgit diff --name-only --cachedfor staged changes - CI/PR context:
git diff --name-only origin/dev...HEADto compare against base branch - Auto-detect CI via
CIorGITHUB_ACTIONSenv vars; allow override via--baseflag
- Local development (default):
- Filter for
.gofiles (exclude_test.go) - Use
git diff --name-statusto detect renames (R), adds (A), and deletes (D):- Renames: Map tests to the new file path
- Deletes: Skip deleted source files (do not run orphaned tests)
- New files without tests: Log a warning
- Map each changed file to test file(s) using N:M discovery:
- Search for
*_test.gofiles in the same package directory (not just<file>_test.go) - Handle shared test files that cover multiple source files
internal/foo/bar.go→internal/foo/bar_test.go,internal/foo/bar_integration_test.go, etc.- Skip if no matching test files exist (warn user)
- Search for
Phase 3: Test Execution
- Reuse existing
runTest()frominternal/cmd/test/cmd_runner.go- This preserves environment setup (
MACOSX_DEPLOYMENT_TARGET), output filtering (linker warnings), coverage parsing, JSON support, and consistent styling
- This preserves environment setup (
- Map smart detection flags to existing
runTest()parameters:--coverage→coverageparam (already exists)--filter→runparam (mapped to-run)- Detected test packages →
pkgparam (comma-joined or iterated)
- Do not invoke
go testdirectly — all execution goes throughrunTest()
Phase 4: Edge Cases
- No changed files → inform user, suggest
--all - No matching test files → inform user with list of changed files that lack tests
--allflag → skip detection, callrunTest()withpkg="./..."(uses existing infrastructure, not rawgo test)- Mixed renames and edits → deduplicate test file list
- Non-Go files changed → skip silently (only
.gofiles trigger detection)
Files to Modify
internal/cmd/test/cmd_main.go(add--all,--filter,--baseflags)internal/cmd/test/cmd_runner.go(add change detection logic before calling existingrunTest())internal/cmd/test/cmd_detect.go(new — git diff parsing and file-to-test mapping)
Testing
- Add
internal/cmd/test/cmd_detect_test.gowith unit tests for:- File-to-test mapping (1:1, 1:N, renames, deletes)
- Git diff parsing (
--name-only,--name-status) - CI vs local context detection
- Manual testing with actual git changes