fix(workflow): clip park details within the store cap and share the diff-rule blocking level

This commit is contained in:
sam committed 2026-10-17 10:11:07 +11:00
1 parent e452451926
commit 7986ccb3f7
2 files changed
+17 -6

No files matched your search

+8 -5
View File
@@ -38,9 +38,8 @@ const (
DiffRuleLevelWarn = "warn"
)
// diffRuleDetailBytes bounds how much of a park Detail the rendered findings
// occupy, matching the store's own park-reason cap headroom (see
// parkDetailBytes in prreview_own_pr.go).
// diffRuleDetailBytes bounds the rendered findings to the store's park-reason
// cap.
const diffRuleDetailBytes = 4000
// DiffRule is one declarative rule applied to the added lines of the committed
@@ -121,7 +120,7 @@ func runDiffRules(ctx context.Context, tc *TaskContext, rules []compiledDiffRule
var blocking []diffFinding
for _, finding := range matchDiffRules(rules, added) {
logRuleFinding(tc, finding)
if finding.Level == DiffRuleLevelError {
if finding.Blocking() {
blocking = append(blocking, finding)
}
}
@@ -170,7 +169,7 @@ func logRuleFinding(tc *TaskContext, finding diffFinding) {
"line", finding.Line,
"message", finding.Message,
}
if finding.Level == DiffRuleLevelError {
if finding.Blocking() {
tc.Log.Warn("diff rule finding", attributes...)
return
}
@@ -301,6 +300,10 @@ type diffFinding struct {
Line int
}
// Blocking reports whether the finding parks the task rather than only
// logging.
func (f diffFinding) Blocking() bool { return f.Level == DiffRuleLevelError }
// matchDiffRules applies every rule to every added line. Rules are not
// short-circuited by the first match: two rules can both object to one line,
// and an operator who wrote both wants to read both.
+9 -1
View File
@@ -512,11 +512,19 @@ func park(ctx context.Context, tc *TaskContext, reason string) {
tc.Log.Error("task parked", "stage", tc.Stage, "reason", reason)
}
const clipMarker = "\n…(truncated)"
// clip bounds s to n bytes, marker included, cut on a rune boundary, so a
// clipped value still fits a store column capped at n.
func clip(s string, n int) string {
if len(s) <= n {
return s
}
return s[:n] + "\n…(truncated)"
cut := max(n-len(clipMarker), 0)
for cut > 0 && !utf8.RuneStart(s[cut]) {
cut--
}
return s[:cut] + clipMarker
}
// clipTail keeps the last n bytes of s, cut on a rune boundary.