Skip to content

Commit edf56aa

Browse files
committed
fix: avoid redundant inspector workflow refresh
Inspector workflow entry should initialize workflows only when the list is empty. The previous guard still refreshed unconditionally, so the check was dead code and repeated entries could rebuild already-loaded workflows. Constraint: Issue #209 asks for the empty-workflow guard to short-circuit subsequent refreshes Rejected: Refresh on every Inspector entry | preserves the dead-code guard and keeps unnecessary re-fetch behavior Confidence: high Scope-risk: narrow Directive: Keep Inspector workflow initialization lazy unless a future change needs explicit reload behavior Tested: env -u GOROOT go test ./internal/app -run TestInspectorEnsureWorkflows -count=1 Tested: env -u GOROOT make test Tested: env -u GOROOT make build Tested: env -u GOROOT go vet ./... Tested: git diff --check Related: #209
1 parent 0b33442 commit edf56aa

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

internal/app/screen_inspector.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ func (im *inspectorModel) refreshWorkflows() {
7979
func (im *inspectorModel) ensureWorkflows() {
8080
if len(im.workflows) == 0 {
8181
im.refreshWorkflows()
82-
return
8382
}
84-
im.refreshWorkflows()
8583
}
8684

8785
func (im *inspectorModel) Enter(m *Model) {

internal/app/screen_inspector_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,43 @@ package app
33
import (
44
"testing"
55
"unicode/utf8"
6+
7+
"unic/internal/inspector"
68
)
79

10+
func TestInspectorEnsureWorkflowsKeepsExistingWorkflows(t *testing.T) {
11+
im := inspectorModel{
12+
checklistPath: "new-checklist.yaml",
13+
workflows: []inspector.Workflow{
14+
{
15+
Kind: inspector.WorkflowSecurity,
16+
Title: "Existing Workflow",
17+
Description: "already loaded",
18+
Available: true,
19+
},
20+
},
21+
}
22+
23+
im.ensureWorkflows()
24+
25+
if len(im.workflows) != 1 {
26+
t.Fatalf("expected existing workflow list to be preserved, got %d workflows", len(im.workflows))
27+
}
28+
if im.workflows[0].Title != "Existing Workflow" {
29+
t.Fatalf("expected existing workflow to be preserved, got %#v", im.workflows[0])
30+
}
31+
}
32+
33+
func TestInspectorEnsureWorkflowsRefreshesEmptyWorkflows(t *testing.T) {
34+
im := inspectorModel{}
35+
36+
im.ensureWorkflows()
37+
38+
if len(im.workflows) == 0 {
39+
t.Fatal("expected empty workflow list to be populated")
40+
}
41+
}
42+
843
func TestInspectorShortenHandlesUnicodeSafely(t *testing.T) {
944
tests := []struct {
1045
name string

0 commit comments

Comments
 (0)