Skip to content

Commit 44096e6

Browse files
committed
test(sarif): cover dry-run SARIF write-error path in fix
Add TestReportFixResultTo_DryRunSARIFWriteErrorReturns2 to exercise the early-return branch (lines 369-370 in fix.go) when formatDiagnosticsTo fails mid-encoding because the 64 KiB stderr buffer overflows. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hz6AviY41wKUmGY2sTj5KJ
1 parent 46572ea commit 44096e6

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

cmd/mdsmith/main_unit_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,16 @@ func TestReportFixResultTo_DryRunJSONWriteErrorFlushes(t *testing.T) {
21822182
assert.Equal(t, 2, code)
21832183
}
21842184

2185+
func TestReportFixResultTo_DryRunSARIFWriteErrorReturns2(t *testing.T) {
2186+
// Drive lines 369-370 in fix.go: enough diagnostics to overflow the
2187+
// 64 KiB buffer during SARIF JSON encoding so formatDiagnosticsTo
2188+
// returns non-zero and the early-return branch is taken.
2189+
opts := fixCLIOpts{dryRun: true, format: "sarif"}
2190+
result := &fixpkg.Result{FilesChecked: 1, Diagnostics: manyDiagnostics(2000)}
2191+
code := reportFixResultTo(opts, result, &vlog.Logger{}, &alwaysErrorWriter{})
2192+
assert.Equal(t, 2, code)
2193+
}
2194+
21852195
func TestReportCheckResultTo_LargeDiagWriteErrorReturns2(t *testing.T) {
21862196
// Enough diagnostics to overflow the 64 KiB stderr buffer, so the
21872197
// formatter itself observes the write failure mid-stream and the

0 commit comments

Comments
 (0)