console: perf-budgets.txt, # starts a comment anywhere on a line
A trailing comment no longer becomes reason text, and a comment after an empty reason is refused as a missing reason.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+15
−7
internal/console/perfbudgets_test.go+9 −5internal/console/testdata/perf-budgets.txt+6 −2
CI failed — run details
diff --git a/internal/console/perfbudgets_test.go b/internal/console/perfbudgets_test.go| index 11bf47f0e..abf882d37 100644 |
| --- a/internal/console/perfbudgets_test.go |
| +++ b/internal/console/perfbudgets_test.go |
| @@ -21,7 +21,8 @@ type perfRecord struct { |
| } |
| // parsePerfBudgets reads the budgets file: one record per line, blank lines |
| -// and lines whose first non-blank character is # ignored. A record is |
| +// ignored, and # starts a comment that runs to the end of the line (so a |
| +// reason cannot contain #). A record is |
| // |
| // <screen> over|skip|deferred: <reason> |
| // <screen> calls <n>: <reason> |
| @@ -39,8 +40,9 @@ func parsePerfBudgets(r io.Reader) (map[string]perfRecord, error) { |
| n := 0 |
| for sc.Scan() { |
| n++ |
| - line := strings.TrimSpace(sc.Text()) |
| - if line == "" || strings.HasPrefix(line, "#") { |
| + line, _, _ := strings.Cut(sc.Text(), "#") |
| + line = strings.TrimSpace(line) |
| + if line == "" { |
| continue |
| } |
| screen, rest, ok := perfSplitScreen(line) |
| @@ -164,7 +166,7 @@ func perfScreenPath(screen string) (path string, hasParams bool) { |
| func TestParsePerfBudgets(t *testing.T) { |
| src := `# a comment, then a blank line |
| -GET /a/{sqid}/apps/{app} calls 2: reads the edges file |
| +GET /a/{sqid}/apps/{app} calls 2: reads the edges file # trailing comment |
| GET /slow over: known slow today |
| GET /part deferred: a deferred-part endpoint |
| POST /door skip: answers GET with the gate's 404 |
| @@ -203,13 +205,15 @@ get /f over: x |
| GET /g |
| /h |
| GET /i calls: x |
| +GET /j over: # explanation only |
| +GET /k over:# |
| ` |
| _, err := parsePerfBudgets(strings.NewReader(src)) |
| if err == nil { |
| t.Fatal("want an error") |
| } |
| msg := err.Error() |
| - for _, line := range []string{"line 2", "line 3", "line 4", "line 5", "line 7", "line 8", "line 9", "line 10", "line 11"} { |
| + for _, line := range []string{"line 2", "line 3", "line 4", "line 5", "line 7", "line 8", "line 9", "line 10", "line 11", "line 12", "line 13"} { |
| if !strings.Contains(msg, line+":") { |
| t.Errorf("error does not name %s:\n%s", line, msg) |
| } |
diff --git a/internal/console/testdata/perf-budgets.txt b/internal/console/testdata/perf-budgets.txt| index 8660a1112..f1050e78c 100644 |
| --- a/internal/console/testdata/perf-budgets.txt |
| +++ b/internal/console/testdata/perf-budgets.txt |
| @@ -1,5 +1,5 @@ |
| -# Console perf budgets. One record per line; a line whose first character is # |
| -# is a comment. Read by the perf walk (perfbudgets_test.go). |
| +# Console perf budgets. One record per line; blank lines and comments are |
| +# ignored. Read by the perf walk (perfbudgets_test.go). |
| # |
| # <screen> over: <reason> known slow today; measured and printed, never |
| # failed; plan 2 deletes the record |
| @@ -14,3 +14,7 @@ |
| # upper-case method, a space, the path) or "/fleet/architecture" (a method-less |
| # registration). Every record needs a reason after the colon. A screen may |
| # appear once. |
| +# |
| +# A # starts a comment that runs to the end of the line, so a reason cannot |
| +# contain one: name a discussion as "discussion 404", not "#404". A comment |
| +# after an empty reason does not make a reason. |