Skip to content

Commit 816df40

Browse files
committed
refactor: Improve alias detection, typecheck handling, and test coverage roadmap
- Use regex for more robust `cr=cmdr` alias detection in `cmd/cmdr/main.go` to avoid false positives. - Keep raw command string in `CommandRunner` constructor and normalize in `Run()` within `internal/cmdrunner.go`. - Conditionally add the `typecheck` synthesized command based on `hasTypecheckCapability()` in `internal/interactive.go`. - Use `os.DevNull` for typecheck commands, improving portability and correctness in `internal/sources_other.go`. - Add a roadmap item to enable skipped typecheck tests in `ROADMAP.md`.
1 parent 70352d7 commit 816df40

5 files changed

Lines changed: 16 additions & 7 deletions

File tree

ROADMAP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ For more experimental and creative ideas, see [docs/ideas.txt](docs/ideas.txt).
151151
### Test Coverage
152152
-**Increase test coverage** - Add more unit tests, especially for command discovery and source detection
153153
-**Integration test framework** - Create optional integration tests that run when tools are available (controlled by environment variable or build tag)
154+
-**Enable skipped typecheck tests** - Replace skipped tests with runnable versions using mocks or temporary wrappers to regain coverage over typecheck orchestration code paths
154155

155156
### Lazy Loading
156157
- Load runners on-demand

cmd/cmdr/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
"regexp"
78
"strings"
89

910
"github.com/osteele/cmd-runner/internal"
@@ -273,7 +274,10 @@ func installAlias(dryRun bool) error {
273274
return fmt.Errorf("failed to read %s: %w", targetFile, err)
274275
}
275276

276-
if strings.Contains(string(content), aliasLine) {
277+
// Match "alias cr=cmdr" as a complete statement (not substring)
278+
// This avoids false positives like "alias cr=cmdr-dev" or commented lines
279+
aliasPattern := regexp.MustCompile(`(?m)^\s*alias\s+cr=cmdr\s*$`)
280+
if aliasPattern.Match(content) {
277281
if dryRun {
278282
fmt.Printf("[DRY RUN] Alias 'cr' is already installed in %s\n", targetFile)
279283
} else {

internal/cmdrunner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type CommandRunner struct {
2020

2121
func New(command string, args []string) *CommandRunner {
2222
return &CommandRunner{
23-
Command: NormalizeCommand(command),
23+
Command: command, // Keep raw command; normalization happens in Run()
2424
Args: args,
2525
}
2626
}

internal/interactive.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ func (s *InteractiveSession) gatherCommands() {
8484

8585
// Add synthesized commands
8686
synth := map[string]CommandInfo{
87-
"check": {Description: "Runs lint, typecheck, and test", Execution: "synthesized"},
88-
"fix": {Description: "Runs format and lint fix", Execution: "synthesized"},
89-
"typecheck": {Description: "Runs type checking", Execution: "synthesized"},
87+
"check": {Description: "Runs lint, typecheck, and test", Execution: "synthesized"},
88+
"fix": {Description: "Runs format and lint fix", Execution: "synthesized"},
89+
}
90+
91+
// Only add typecheck if project has capability
92+
if s.runner.hasTypecheckCapability() {
93+
synth["typecheck"] = CommandInfo{Description: "Runs type checking", Execution: "synthesized"}
9094
}
9195

9296
for cmd, info := range synth {

internal/sources_other.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ func (g *GoSource) FindCommand(command string, args []string) *exec.Cmd {
136136
"setup": {"mod", "download"},
137137
"install": {"install", "."},
138138
"lint": {"vet", "./..."},
139-
"typecheck": {"build", "-o", "/dev/null", "./..."},
140-
"tc": {"build", "-o", "/dev/null", "./..."},
139+
"typecheck": {"build", "-o", os.DevNull, "./..."},
140+
"tc": {"build", "-o", os.DevNull, "./..."},
141141
}
142142

143143
for _, variant := range GetCommandVariants(command) {

0 commit comments

Comments
 (0)