Skip to content

Commit 5eb05d5

Browse files
cpcloudclaude
andcommitted
chore: fix all gosec G118/G602/G703 findings from updated linter
- G118: add t.Cleanup(cancel) to all test context.WithCancel calls so the cancel function is always invoked at test end - G602: nolint on table.go slice access where specs and natural have equal length by construction - G703: nolint on WriteFile calls where path is tmpDir + constant filename (no tainted components) - Keep nolint on extraction.go production code where cancel is stored in struct field and called on extraction close Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0cf3181 commit 5eb05d5

6 files changed

Lines changed: 19 additions & 5 deletions

File tree

internal/app/chat_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ func TestNoSpinnerAfterCancellation(t *testing.T) {
244244
m.openChat()
245245

246246
_, cancel := context.WithCancel(context.Background())
247+
t.Cleanup(cancel)
247248
m.chat.Streaming = true
248249
m.chat.StreamingSQL = true
249250
m.chat.CancelFn = cancel
@@ -278,6 +279,7 @@ func TestLateSQLChunkAfterCancellationIsDropped(t *testing.T) {
278279
m.openChat()
279280

280281
_, cancel := context.WithCancel(context.Background())
282+
t.Cleanup(cancel)
281283
m.chat.Streaming = true
282284
m.chat.StreamingSQL = true
283285
m.chat.CancelFn = cancel
@@ -314,6 +316,7 @@ func TestLateChatChunkAfterCancellationIsDropped(t *testing.T) {
314316
m.openChat()
315317

316318
_, cancel := context.WithCancel(context.Background())
319+
t.Cleanup(cancel)
317320
m.chat.Streaming = true
318321
m.chat.CancelFn = cancel
319322
m.chat.Messages = []chatMessage{

internal/app/extraction_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func newExtractionModel(t *testing.T, steps map[extractionStep]stepStatus) *Mode
2626

2727
m := newTestModel(t)
2828
ctx, cancel := context.WithCancel(context.Background())
29+
t.Cleanup(cancel)
2930
ex := &extractionLogState{
3031
ID: nextExtractionID.Add(1),
3132
ctx: ctx,
@@ -913,6 +914,7 @@ func TestForeground_SwapsCurrentToBackground(t *testing.T) {
913914

914915
// Create a new foreground extraction.
915916
ctx, cancel := context.WithCancel(context.Background())
917+
t.Cleanup(cancel)
916918
m.ex.extraction = &extractionLogState{
917919
ID: nextExtractionID.Add(1),
918920
Filename: "second.pdf",
@@ -1051,6 +1053,7 @@ func TestMultipleBgExtractions(t *testing.T) {
10511053

10521054
// Create and background second.
10531055
ctx, cancel := context.WithCancel(context.Background())
1056+
t.Cleanup(cancel)
10541057
m.ex.extraction = &extractionLogState{
10551058
ID: nextExtractionID.Add(1),
10561059
Filename: "b.pdf",
@@ -1088,6 +1091,7 @@ func TestStartExtraction_AutoBackgroundsExisting(t *testing.T) {
10881091
// This tests the backgrounding logic directly.
10891092
m.backgroundExtraction()
10901093
ctx, cancel := context.WithCancel(context.Background())
1094+
t.Cleanup(cancel)
10911095
m.ex.extraction = &extractionLogState{
10921096
ID: nextExtractionID.Add(1),
10931097
Filename: "new.pdf",
@@ -1134,6 +1138,7 @@ func TestCtrlQ_CancelsAllBgExtractions(t *testing.T) {
11341138

11351139
// Create another foreground extraction.
11361140
ctx, cancel := context.WithCancel(context.Background())
1141+
t.Cleanup(cancel)
11371142
m.ex.extraction = &extractionLogState{
11381143
ID: nextExtractionID.Add(1),
11391144
Filename: "fg2.pdf",
@@ -1817,6 +1822,7 @@ func TestDispatch_VendorCrossReference(t *testing.T) {
18171822
require.NoError(t, sdb.Stage(ops))
18181823

18191824
ctx, cancel := context.WithCancel(context.Background())
1825+
t.Cleanup(cancel)
18201826
defer cancel()
18211827
ex := &extractionLogState{
18221828
ID: nextExtractionID.Add(1),
@@ -1885,6 +1891,7 @@ func TestDispatch_InvalidProjectIDShowsError(t *testing.T) {
18851891
require.NoError(t, sdb.Stage(ops))
18861892

18871893
ctx, cancel := context.WithCancel(context.Background())
1894+
t.Cleanup(cancel)
18881895
defer cancel()
18891896
ex := &extractionLogState{
18901897
ID: nextExtractionID.Add(1),
@@ -1950,6 +1957,7 @@ func TestDispatch_OffsetCrossReference(t *testing.T) {
19501957
require.NoError(t, sdb.Stage(ops))
19511958

19521959
ctx, cancel := context.WithCancel(context.Background())
1960+
t.Cleanup(cancel)
19531961
defer cancel()
19541962
ex := &extractionLogState{
19551963
ID: nextExtractionID.Add(1),
@@ -2032,6 +2040,7 @@ func TestDispatch_DuplicateVendorDedup(t *testing.T) {
20322040
require.NoError(t, sdb.Stage(ops))
20332041

20342042
ctx, cancel := context.WithCancel(context.Background())
2043+
t.Cleanup(cancel)
20352044
defer cancel()
20362045
ex := &extractionLogState{
20372046
ID: nextExtractionID.Add(1),
@@ -2102,6 +2111,7 @@ func TestDispatch_DuplicateApplianceDedup(t *testing.T) {
21022111
require.NoError(t, sdb.Stage(ops))
21032112

21042113
ctx, cancel := context.WithCancel(context.Background())
2114+
t.Cleanup(cancel)
21052115
defer cancel()
21062116
ex := &extractionLogState{
21072117
ID: nextExtractionID.Add(1),
@@ -2163,6 +2173,7 @@ func TestDispatch_TransactionRollbackOnFailure(t *testing.T) {
21632173
require.NoError(t, sdb.Stage(ops))
21642174

21652175
ctx, cancel := context.WithCancel(context.Background())
2176+
t.Cleanup(cancel)
21662177
defer cancel()
21672178
ex := &extractionLogState{
21682179
ID: nextExtractionID.Add(1),

internal/app/table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,8 @@ func columnWidths(
879879
// Content exceeds terminal width — apply Max constraints.
880880
widths := make([]int, columnCount)
881881
for i, w := range natural {
882-
if specs[i].Max > 0 &&
883-
w > specs[i].Max { //nolint:gosec // specs and natural have equal length (columnCount)
882+
if specs[i].Max > 0 && //nolint:gosec // specs and natural have equal length (columnCount)
883+
w > specs[i].Max { //nolint:gosec // same bounds
884884
w = specs[i].Max //nolint:gosec // same bounds
885885
}
886886
widths[i] = w

internal/extract/ocr_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func BenchmarkOcrPage(b *testing.B) {
4444

4545
tmpDir := b.TempDir()
4646
pdfPath := filepath.Join(tmpDir, "input.pdf")
47-
if err := os.WriteFile(pdfPath, data, 0o600); err != nil {
47+
if err := os.WriteFile(pdfPath, data, 0o600); err != nil { //nolint:gosec // path is tmpDir + constant filename
4848
b.Fatal(err)
4949
}
5050

internal/extract/ocr_progress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func ocrPDFWithProgress(
118118
defer os.RemoveAll(tmpDir) //nolint:errcheck // best-effort cleanup
119119

120120
pdfPath := filepath.Join(tmpDir, "input.pdf")
121-
if err := os.WriteFile(pdfPath, data, 0o600); err != nil {
121+
if err := os.WriteFile(pdfPath, data, 0o600); err != nil { //nolint:gosec // path is tmpDir + constant filename
122122
ch <- ExtractProgress{Err: fmt.Errorf("write temp pdf: %w", err), Done: true}
123123
return
124124
}

internal/extract/text.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func extractPDF(ctx context.Context, data []byte) (string, error) {
5959
defer os.RemoveAll(tmpDir) //nolint:errcheck // best-effort cleanup
6060

6161
pdfPath := filepath.Join(tmpDir, "input.pdf")
62-
if err := os.WriteFile(pdfPath, data, 0o600); err != nil {
62+
if err := os.WriteFile(pdfPath, data, 0o600); err != nil { //nolint:gosec // path is tmpDir + constant filename
6363
return "", fmt.Errorf("write temp pdf: %w", err)
6464
}
6565

0 commit comments

Comments
 (0)