package testci import ( "bufio" "os" "strings" "testing" ) // Budget records stay one short line each. Merges used to join both // sides' reasons, and a record grew past the budget tool's 64 KB line // limit (2026-11-12). A reason is the measured value and a short why, // never a history: that lives in the commits. const ( maxBudgetRecord = 500 maxBudgetReason = 200 ) func TestBudgetRecordsAreShort(t *testing.T) { f, err := os.Open("../../.rastrillo/budgets.txt") if err != nil { t.Fatal(err) } defer f.Close() sc := bufio.NewScanner(f) sc.Buffer(make([]byte, 0, 64<<10), 1<<20) for n := 1; sc.Scan(); n++ { line := sc.Text() if line == "" || strings.HasPrefix(line, "#") { continue } if len(line) > maxBudgetRecord { t.Errorf(".rastrillo/budgets.txt:%d: record is %d bytes, over %d: keep the reason to the measured value and a short why", n, len(line), maxBudgetRecord) continue } if r := budgetReason(line); len(r) > maxBudgetReason { t.Errorf(".rastrillo/budgets.txt:%d: reason is %d bytes, over %d", n, len(r), maxBudgetReason) } } if err := sc.Err(); err != nil { t.Fatal(err) } } // budgetReason is a record's reason: what follows its fixed fields // (size: dir, source, test; time: dir, duration; perf: method, path, // duration; boot: duration). func budgetReason(line string) string { f := strings.Fields(line) fixed := map[string]int{"size": 4, "time": 3, "perf": 4, "boot": 2}[f[0]] if fixed == 0 || len(f) <= fixed { return "" } return strings.Join(f[fixed:], " ") }