diff --git a/internal/domain/workflow/diff_rules.go b/internal/domain/workflow/diff_rules.go index 250436bd0..ff41004cf 100644 --- a/internal/domain/workflow/diff_rules.go +++ b/internal/domain/workflow/diff_rules.go @@ -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. diff --git a/internal/domain/workflow/workflow.go b/internal/domain/workflow/workflow.go index ce564ea38..571cea91f 100644 --- a/internal/domain/workflow/workflow.go +++ b/internal/domain/workflow/workflow.go @@ -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.