refactor(scorecard): extract infra maps and add workflow/insight tests
- Extract duplicated infra file maps into package-level vars: infraCoreFiles (4 entries, used by workflows/insight) and infraAllFiles (10 entries, used by breadth/sampleCommandFiles) - Add TestScoreWorkflows: prefix matching, infra skip, store-usage structural detection, multi-API-call detection (4 subtests) - Add TestScoreInsight: prefix matching, infra skip, store+aggregation structural detection, store-without-aggregation negative case (4 subtests) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Files touched
M internal/pipeline/scorecard.goM internal/pipeline/scorecard_tier2_test.go
Diff
commit 64e5ea5800bd0528c916cdae33239ba422e7c096
Author: Trevin Chow <trevin@trevinchow.com>
Date: Fri Mar 27 21:49:24 2026 -0700
refactor(scorecard): extract infra maps and add workflow/insight tests
- Extract duplicated infra file maps into package-level vars:
infraCoreFiles (4 entries, used by workflows/insight) and
infraAllFiles (10 entries, used by breadth/sampleCommandFiles)
- Add TestScoreWorkflows: prefix matching, infra skip, store-usage
structural detection, multi-API-call detection (4 subtests)
- Add TestScoreInsight: prefix matching, infra skip, store+aggregation
structural detection, store-without-aggregation negative case (4 subtests)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---
internal/pipeline/scorecard.go | 41 +++++-----
internal/pipeline/scorecard_tier2_test.go | 120 ++++++++++++++++++++++++++++++
2 files changed, 139 insertions(+), 22 deletions(-)
diff --git a/internal/pipeline/scorecard.go b/internal/pipeline/scorecard.go
index a58c39e7..d0e0e5f7 100644
--- a/internal/pipeline/scorecard.go
+++ b/internal/pipeline/scorecard.go
@@ -11,6 +11,21 @@ import (
"strings"
)
+// infraCoreFiles are CLI infrastructure files excluded from workflow/insight scoring.
+// These contain shared helpers and framework code, not individual commands.
+var infraCoreFiles = map[string]bool{
+ "helpers.go": true, "root.go": true, "doctor.go": true, "auth.go": true,
+}
+
+// infraAllFiles extends infraCoreFiles with vision/data-layer commands that are
+// scored by their own dedicated dimensions (vision, sync_correctness, etc.)
+// and should not be double-counted by breadth or sampled as generic commands.
+var infraAllFiles = map[string]bool{
+ "helpers.go": true, "root.go": true, "doctor.go": true, "auth.go": true,
+ "export.go": true, "import.go": true, "search.go": true, "sync.go": true,
+ "tail.go": true, "analytics.go": true,
+}
+
// Scorecard holds the auto-scored evaluation of a generated CLI against the Steinberger bar.
type Scorecard struct {
APIName string `json:"api_name"`
@@ -496,18 +511,13 @@ func scoreBreadth(dir string) int {
if err != nil {
return 0
}
- infra := map[string]bool{
- "helpers.go": true, "root.go": true, "doctor.go": true, "auth.go": true,
- "export.go": true, "import.go": true, "search.go": true, "sync.go": true,
- "tail.go": true, "analytics.go": true,
- }
commandFiles := 0
lazyDescs := 0
for _, e := range entries {
if e.IsDir() || !strings.HasSuffix(e.Name(), ".go") {
continue
}
- if infra[e.Name()] {
+ if infraAllFiles[e.Name()] {
continue
}
commandFiles++
@@ -669,16 +679,12 @@ func scoreWorkflows(dir string) int {
"reconcile", "revenue", "archive", "search", "sync", "busy", "export",
"noshow", "reassign", "clone"}
- infra := map[string]bool{
- "helpers.go": true, "root.go": true, "doctor.go": true, "auth.go": true,
- }
-
compoundCommands := 0
for _, e := range entries {
if e.IsDir() || !strings.HasSuffix(e.Name(), ".go") {
continue
}
- if infra[e.Name()] {
+ if infraCoreFiles[e.Name()] {
continue
}
@@ -754,16 +760,12 @@ func scoreInsight(dir string) int {
"stats", "conflicts", "stale", "analytics", "busiest", "velocity",
"utilization", "coverage", "gaps", "noshow"}
- infra := map[string]bool{
- "helpers.go": true, "root.go": true, "doctor.go": true, "auth.go": true,
- }
-
found := 0
for _, e := range entries {
if e.IsDir() || !strings.HasSuffix(e.Name(), ".go") {
continue
}
- if infra[e.Name()] {
+ if infraCoreFiles[e.Name()] {
continue
}
name := strings.ToLower(e.Name())
@@ -1149,17 +1151,12 @@ func sampleCommandFiles(dir string, n int) []string {
if err != nil {
return nil
}
- infra := map[string]bool{
- "helpers.go": true, "root.go": true, "doctor.go": true, "auth.go": true,
- "export.go": true, "import.go": true, "search.go": true, "sync.go": true,
- "tail.go": true, "analytics.go": true,
- }
var files []string
for _, e := range entries {
if e.IsDir() || !strings.HasSuffix(e.Name(), ".go") {
continue
}
- if infra[e.Name()] {
+ if infraAllFiles[e.Name()] {
continue
}
content := readFileContent(filepath.Join(cliDir, e.Name()))
diff --git a/internal/pipeline/scorecard_tier2_test.go b/internal/pipeline/scorecard_tier2_test.go
index f38b5087..aaa5208c 100644
--- a/internal/pipeline/scorecard_tier2_test.go
+++ b/internal/pipeline/scorecard_tier2_test.go
@@ -468,6 +468,126 @@ CREATE TABLE bookings (
})
}
+func TestScoreWorkflows(t *testing.T) {
+ t.Run("counts files matching expanded prefixes", func(t *testing.T) {
+ dir := t.TempDir()
+
+ // 3 workflow files by prefix
+ writeScorecardFixture(t, dir, "internal/cli/stale_tasks.go", `package cli`)
+ writeScorecardFixture(t, dir, "internal/cli/agenda.go", `package cli`)
+ writeScorecardFixture(t, dir, "internal/cli/conflicts.go", `package cli`)
+
+ assert.GreaterOrEqual(t, scoreWorkflows(dir), 6) // 3 compound commands → 6
+ })
+
+ t.Run("skips infra files", func(t *testing.T) {
+ dir := t.TempDir()
+
+ // helpers.go should not count as a workflow
+ writeScorecardFixture(t, dir, "internal/cli/helpers.go", `package cli`)
+ writeScorecardFixture(t, dir, "internal/cli/root.go", `package cli`)
+
+ assert.Equal(t, 0, scoreWorkflows(dir))
+ })
+
+ t.Run("detects store-using commands structurally", func(t *testing.T) {
+ dir := t.TempDir()
+
+ // File doesn't match any prefix but imports store
+ writeScorecardFixture(t, dir, "internal/cli/bookings_report.go", `
+package cli
+
+import "example.com/project/internal/store"
+
+func runReport(db *store.DB) {}
+`)
+ writeScorecardFixture(t, dir, "internal/cli/availability.go", `
+package cli
+
+func runAvailability() {
+ db := store.Open()
+ _ = db
+}
+`)
+
+ assert.GreaterOrEqual(t, scoreWorkflows(dir), 4) // 2 compound → 4
+ })
+
+ t.Run("counts multi-API-call files", func(t *testing.T) {
+ dir := t.TempDir()
+
+ // File makes 2+ different API calls
+ writeScorecardFixture(t, dir, "internal/cli/transfer.go", `
+package cli
+
+func runTransfer() {
+ resp1 := c.Get("/source")
+ _ = c.Post("/destination", resp1)
+}
+`)
+
+ assert.GreaterOrEqual(t, scoreWorkflows(dir), 2) // 1 compound → 2
+ })
+}
+
+func TestScoreInsight(t *testing.T) {
+ t.Run("counts files matching expanded prefixes", func(t *testing.T) {
+ dir := t.TempDir()
+
+ writeScorecardFixture(t, dir, "internal/cli/stats.go", `package cli`)
+ writeScorecardFixture(t, dir, "internal/cli/health.go", `package cli`)
+ writeScorecardFixture(t, dir, "internal/cli/trends.go", `package cli`)
+
+ assert.GreaterOrEqual(t, scoreInsight(dir), 6) // 3 found → 6
+ })
+
+ t.Run("skips infra files", func(t *testing.T) {
+ dir := t.TempDir()
+
+ writeScorecardFixture(t, dir, "internal/cli/helpers.go", `package cli`)
+ writeScorecardFixture(t, dir, "internal/cli/root.go", `package cli`)
+ writeScorecardFixture(t, dir, "internal/cli/doctor.go", `package cli`)
+
+ assert.Equal(t, 0, scoreInsight(dir))
+ })
+
+ t.Run("detects store plus aggregation structurally", func(t *testing.T) {
+ dir := t.TempDir()
+
+ // File uses store AND aggregation — should count as insight
+ writeScorecardFixture(t, dir, "internal/cli/usage_report.go", `
+package cli
+
+import "example.com/project/internal/store"
+
+func runUsageReport(db *store.DB) {
+ rows := db.Query("SELECT COUNT(*) FROM bookings GROUP BY status")
+ _ = rows
+}
+`)
+
+ assert.GreaterOrEqual(t, scoreInsight(dir), 2) // 1 found → 2
+ })
+
+ t.Run("store without aggregation does not count", func(t *testing.T) {
+ dir := t.TempDir()
+
+ // File uses store but NO aggregation — should not count
+ writeScorecardFixture(t, dir, "internal/cli/lookup.go", `
+package cli
+
+import "example.com/project/internal/store"
+
+func runLookup(db *store.DB) {
+ row := db.Query("SELECT * FROM bookings WHERE id = ?")
+ _ = row
+}
+`)
+
+ assert.Equal(t, 0, scoreInsight(dir))
+ })
+}
+
func writeScorecardFixture(t *testing.T, root, relPath, content string) {
t.Helper()