Skip to content

Commit 4208dd6

Browse files
spboyerCopilot
andcommitted
fix: fail diff when skills exceed absolute token limits, improve wording
- Passed flag now checks both ThresholdExceeded and OverLimit — a skill over its absolute budget causes failure regardless of percent-change threshold - Clarify Long description with fallback behavior - Add inline comment above base ref fallback - Generalize error message from 'threshold exceeded' to 'budget exceeded' Addresses wbreza [High] and chlowell review feedback on PR #93. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 55cc014 commit 4208dd6

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

cmd/waza/tokens/diff.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func newDiffCmd() *cobra.Command {
2828
Short: "Compare SKILL.md token budgets against a base ref",
2929
Long: `Compare token budgets for SKILL.md files between a base git ref and current changes.
3030
31-
By default, compares origin/main to the working tree and reports per-skill deltas.
32-
Skill roots include configured paths.skills from .waza.yaml plus skills/ and
33-
.github/skills/.`,
31+
By default the base ref is origin/main, falling back to main when origin/main
32+
is not available. Skill roots include configured paths.skills from .waza.yaml
33+
plus skills/ and .github/skills/.`,
3434
Args: cobra.MaximumNArgs(1),
3535
RunE: runDiff,
3636
SilenceErrors: true,
@@ -92,6 +92,7 @@ func runDiff(cmd *cobra.Command, args []string) error {
9292
return errors.New("not a git repository; diff command requires git")
9393
}
9494

95+
// Prefers origin/main, falls back to main.
9596
baseRef := defaultDiffBaseRef
9697
if len(args) == 1 {
9798
baseRef = args[0]
@@ -110,7 +111,7 @@ func runDiff(cmd *cobra.Command, args []string) error {
110111
}
111112
passed := true
112113
for _, d := range diffs {
113-
if d.ThresholdExceeded {
114+
if d.ThresholdExceeded || d.OverLimit {
114115
passed = false
115116
break
116117
}
@@ -142,7 +143,7 @@ func runDiff(cmd *cobra.Command, args []string) error {
142143

143144
if !passed {
144145
cmd.SilenceUsage = true
145-
return fmt.Errorf("token diff threshold exceeded for one or more skills (threshold %.1f%%)", threshold)
146+
return fmt.Errorf("token budget exceeded for one or more skills")
146147
}
147148
return nil
148149
}

cmd/waza/tokens/diff_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestDiff_ThresholdAndSkillRoots(t *testing.T) {
3838

3939
err := cmd.Execute()
4040
require.Error(t, err)
41-
require.Contains(t, err.Error(), "threshold exceeded")
41+
require.Contains(t, err.Error(), "budget exceeded")
4242
require.Contains(t, out.String(), "skills/alpha")
4343
require.Contains(t, out.String(), ".github/skills/beta")
4444
require.Contains(t, out.String(), "⚠️")
@@ -68,13 +68,14 @@ tokens:
6868
cmd.SetErr(new(bytes.Buffer))
6969
cmd.SetArgs([]string{"main", "--format", "json", "--threshold", "500"})
7070

71-
require.NoError(t, cmd.Execute())
71+
err := cmd.Execute()
72+
require.Error(t, err, "should fail because skill is over its absolute token limit")
7273

7374
var report diffReport
7475
require.NoError(t, json.Unmarshal(out.Bytes(), &report))
7576
require.Equal(t, "main", report.BaseRef)
7677
require.Equal(t, "WORKING", report.HeadRef)
77-
require.True(t, report.Passed)
78+
require.False(t, report.Passed, "Passed should be false when a skill is over its absolute limit")
7879
require.Len(t, report.Skills, 1)
7980
require.Equal(t, "custom-skills/delta", report.Skills[0].Path)
8081
require.Equal(t, 5, report.Skills[0].Limit)

0 commit comments

Comments
 (0)