-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(test): Add smart test detection (issue #258) #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Implementation Plan: Issue 258 | ||
|
|
||
| ## Phase 1: Command Structure | ||
| 1. Create `cmd/core/cmd/test.go` | ||
| 2. Register `test` command with Cobra | ||
| 3. Add flags: `--all`, `--filter`, `--coverage` | ||
|
|
||
| ## Phase 2: Change Detection | ||
| 1. Run `git diff --name-only HEAD` to get changed files | ||
| 2. Filter for `.go` files (exclude `_test.go`) | ||
| 3. Map each file to its test file: | ||
| - `internal/foo/bar.go` → `internal/foo/bar_test.go` | ||
| - Skip if test file does not exist | ||
|
Comment on lines
+8
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add edge cases for file operations beyond simple edits. Phase 2 handles basic file-to-test mapping but doesn't address several important scenarios:
Consider adding a sub-section to Phase 2 or Phase 4 that explicitly handles these cases: ## Phase 2.5: Advanced Mapping
- Detect renames via `git diff --name-status` (R flag)
- For deleted files, consider if tests should still run
- For new files, optionally warn about missing tests
- Support N:M mapping (multiple tests per file, multiple files per test)🤖 Prompt for AI Agents |
||
|
|
||
| ## Phase 3: Test Execution | ||
| 1. Build `go test` command with detected test files | ||
| 2. Pass through `--coverage` flag as `-cover` | ||
| 3. Pass through `--filter` as `-run` pattern | ||
| 4. Stream output to terminal | ||
|
Comment on lines
+16
to
+19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find the go test command implementation in core
rg -n "goTest|go.*test.*Command" cmd/core/ -A 10 -B 3 -t goRepository: host-uk/core Length of output: 105 🏁 Script executed: #!/bin/bash
# Search more broadly for test command implementation
fd -type f -name "*.go" cmd/core/ | head -20 | xargs rg -l "test" | head -10Repository: host-uk/core Length of output: 520 🏁 Script executed: #!/bin/bash
# Check the cmd/core directory structure
find cmd/core -type f -name "*.go" | head -20Repository: host-uk/core Length of output: 99 🏁 Script executed: #!/bin/bash
# Get repository structure
ls -laRepository: host-uk/core Length of output: 1796 🏁 Script executed: #!/bin/bash
# Find the plan.md file
find . -name "plan.md" -type fRepository: host-uk/core Length of output: 86 🏁 Script executed: #!/bin/bash
# Look for core command implementation
rg -l "core.*go.*test|goTest" --max-count 20Repository: host-uk/core Length of output: 408 🏁 Script executed: #!/bin/bash
# Read the plan.md file to understand Phase 3 context
cat -n .core/task/issue/258/plan.mdRepository: host-uk/core Length of output: 1308 🏁 Script executed: #!/bin/bash
# Examine the existing core go test command implementation
cat -n internal/cmd/go/cmd_qa.goRepository: host-uk/core Length of output: 18776 🏁 Script executed: #!/bin/bash
# Check for other go command files
ls -la internal/cmd/go/Repository: host-uk/core Length of output: 554 🏁 Script executed: #!/bin/bash
# Examine the existing core go test command
cat -n internal/cmd/go/cmd_gotest.goRepository: host-uk/core Length of output: 11482 Align Phase 3 implementation with existing Phase 3 proposes building a direct
Running
🤖 Prompt for AI Agents |
||
|
|
||
| ## Phase 4: Edge Cases | ||
| - No changed files → inform user, optionally run all | ||
| - No matching test files → inform user | ||
| - `--all` flag → skip detection, run `go test ./...` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Check project test organization and existing test commands
# Check module structure
echo "=== Module structure ==="
fd -e mod go.mod
echo -e "\n=== Test build tags ==="
rg -n "//go:build|// \+build" --glob "*_test.go" | head -20
echo -e "\n=== Test helper scripts/configs ==="
find . -type f \( -name "*test*" -o -name "*Test*" \) -not -path "*/vendor/*" -not -path "*/.git/*" | grep -E "\.(sh|yaml|json|txt|md)$" | head -30
echo -e "\n=== Checking for 'core go test' command definition ==="
rg "core go test|go test" --glob "*.md" --glob "*.sh" --glob "*.go" -B 2 -A 2 | head -50Repository: host-uk/core Length of output: 2606 Use GEMINI.md explicitly states: "Agents should always prefer 🤖 Prompt for AI Agents |
||
|
|
||
| ## Files to Create/Modify | ||
| - `cmd/core/cmd/test.go` (new) | ||
| - `cmd/core/cmd/root.go` (register command) | ||
|
|
||
| ## Testing | ||
| - Add `cmd/core/cmd/test_test.go` with unit tests | ||
| - Manual testing with actual git changes | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Issue 258: Smart Test Detection | ||
|
|
||
| ## Original Issue | ||
| https://github.com/host-uk/core/issues/258 | ||
|
|
||
| ## Summary | ||
| Make `core test` smart - detect changed files and run only relevant tests. | ||
|
|
||
| ## Commands | ||
| ```bash | ||
| core test # Run tests for changed files only | ||
| core test --all # Run all tests | ||
| core test --filter UserTest # Run specific test | ||
| core test --coverage # With coverage report | ||
| ``` | ||
|
|
||
| ## Acceptance Criteria | ||
| - [ ] Detect changed `.go` files via `git diff --name-only` | ||
| - [ ] Map source files to test files (`foo.go` → `foo_test.go`) | ||
| - [ ] Run only relevant tests via `go test` | ||
| - [ ] Support `--all` flag to run all tests | ||
| - [ ] Support `--filter` flag for pattern matching | ||
| - [ ] Support `--coverage` flag for coverage reports | ||
|
Comment on lines
+17
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify language scope - spec appears Go-only but PR objectives suggest multi-language support. The acceptance criteria focus exclusively on Go files ( Consider:
🤖 Prompt for AI Agents |
||
|
|
||
| ## Technical Context | ||
| - Go CLI using Cobra | ||
| - Commands in `cmd/core/cmd/` | ||
| - Follow existing patterns in `dev_*.go` files | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: host-uk/core
Length of output: 86
🏁 Script executed:
Repository: host-uk/core
Length of output: 1308
🏁 Script executed:
Repository: host-uk/core
Length of output: 1268
🏁 Script executed:
Repository: host-uk/core
Length of output: 716
🏁 Script executed:
Repository: host-uk/core
Length of output: 1891
🏁 Script executed:
Repository: host-uk/core
Length of output: 38
🏁 Script executed:
Repository: host-uk/core
Length of output: 355
🏁 Script executed:
Repository: host-uk/core
Length of output: 2338
🏁 Script executed:
Repository: host-uk/core
Length of output: 38
🏁 Script executed:
Repository: host-uk/core
Length of output: 108
🏁 Script executed:
Repository: host-uk/core
Length of output: 384
🏁 Script executed:
cat -n ./.github/workflows/ci.yml | head -60Repository: host-uk/core
Length of output: 1375
🏁 Script executed:
Repository: host-uk/core
Length of output: 83
🏁 Script executed:
Repository: host-uk/core
Length of output: 38
🏁 Script executed:
Repository: host-uk/core
Length of output: 38
🏁 Script executed:
Repository: host-uk/core
Length of output: 4359
Clarify the context and git diff strategy for change detection.
The command
git diff --name-only HEADcompares the working directory against HEAD, which works for local uncommitted changes but may not be appropriate for CI/PR contexts where you typically want to compare against the base branch.Consider these scenarios:
git diff --name-only HEADshows uncommitted changes ✓git diff --name-only origin/main...HEADor similar to compare the PR branch against the base branchgit diff --name-only HEADreturns nothing without additional flagsBefore implementing Phase 2, clarify:
🤖 Prompt for AI Agents