From edf56aa4f3bb1f8a8bbd64cd78debc48a6969b03 Mon Sep 17 00:00:00 2001 From: "kuma.jung" Date: Sun, 7 Jun 2026 16:54:59 +0900 Subject: [PATCH 1/2] 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: https://github.com/DevopsArtFactory/unic/issues/209 --- internal/app/screen_inspector.go | 2 -- internal/app/screen_inspector_test.go | 35 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/internal/app/screen_inspector.go b/internal/app/screen_inspector.go index 9fa8c16..7d84bd9 100644 --- a/internal/app/screen_inspector.go +++ b/internal/app/screen_inspector.go @@ -79,9 +79,7 @@ func (im *inspectorModel) refreshWorkflows() { func (im *inspectorModel) ensureWorkflows() { if len(im.workflows) == 0 { im.refreshWorkflows() - return } - im.refreshWorkflows() } func (im *inspectorModel) Enter(m *Model) { diff --git a/internal/app/screen_inspector_test.go b/internal/app/screen_inspector_test.go index a0d83de..f36e5c7 100644 --- a/internal/app/screen_inspector_test.go +++ b/internal/app/screen_inspector_test.go @@ -3,8 +3,43 @@ package app import ( "testing" "unicode/utf8" + + "unic/internal/inspector" ) +func TestInspectorEnsureWorkflowsKeepsExistingWorkflows(t *testing.T) { + im := inspectorModel{ + checklistPath: "new-checklist.yaml", + workflows: []inspector.Workflow{ + { + Kind: inspector.WorkflowSecurity, + Title: "Existing Workflow", + Description: "already loaded", + Available: true, + }, + }, + } + + im.ensureWorkflows() + + if len(im.workflows) != 1 { + t.Fatalf("expected existing workflow list to be preserved, got %d workflows", len(im.workflows)) + } + if im.workflows[0].Title != "Existing Workflow" { + t.Fatalf("expected existing workflow to be preserved, got %#v", im.workflows[0]) + } +} + +func TestInspectorEnsureWorkflowsRefreshesEmptyWorkflows(t *testing.T) { + im := inspectorModel{} + + im.ensureWorkflows() + + if len(im.workflows) == 0 { + t.Fatal("expected empty workflow list to be populated") + } +} + func TestInspectorShortenHandlesUnicodeSafely(t *testing.T) { tests := []struct { name string From 242d652b8682352109856ab42bbd2ac5260a6ec8 Mon Sep 17 00:00:00 2001 From: "kuma.jung" Date: Sun, 7 Jun 2026 17:00:05 +0900 Subject: [PATCH 2/2] test: tighten inspector workflow refresh assertions CodeRabbit pointed out that the regression test carried an unused checklistPath and only asserted that empty workflow initialization produced some data. The test now keeps the setup focused and checks the exact default workflow count. Constraint: Address actionable CodeRabbit feedback on PR #225 Confidence: high Scope-risk: narrow 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 --- internal/app/screen_inspector_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/app/screen_inspector_test.go b/internal/app/screen_inspector_test.go index f36e5c7..2f1b9ce 100644 --- a/internal/app/screen_inspector_test.go +++ b/internal/app/screen_inspector_test.go @@ -9,7 +9,6 @@ import ( func TestInspectorEnsureWorkflowsKeepsExistingWorkflows(t *testing.T) { im := inspectorModel{ - checklistPath: "new-checklist.yaml", workflows: []inspector.Workflow{ { Kind: inspector.WorkflowSecurity, @@ -35,8 +34,8 @@ func TestInspectorEnsureWorkflowsRefreshesEmptyWorkflows(t *testing.T) { im.ensureWorkflows() - if len(im.workflows) == 0 { - t.Fatal("expected empty workflow list to be populated") + if len(im.workflows) != 2 { + t.Fatalf("expected empty workflow list to be populated with 2 workflows, got %d", len(im.workflows)) } }