From c742e4243d4a0d2034104ab943664c262d1d08cc Mon Sep 17 00:00:00 2001 From: archie Date: Fri, 24 Jul 2026 17:12:17 +0000 Subject: [PATCH 1/2] fix: baseline gate repair (go vet ./...) --- internal/worktree/worktree_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/worktree/worktree_test.go b/internal/worktree/worktree_test.go index 2c9168a44..f7b187584 100644 --- a/internal/worktree/worktree_test.go +++ b/internal/worktree/worktree_test.go @@ -201,7 +201,6 @@ func TestPreparePersistentReusesRepoCacheAndCleanupExpiresIt(t *testing.T) { } } -<<<<<<< HEAD func TestAskpassWrittenOnce(t *testing.T) { m := &Manager{WorkDir: t.TempDir()} @@ -242,7 +241,9 @@ func TestAskpassWrittenOnce(t *testing.T) { want := "#!/bin/sh\necho \"$ARCHIE_GIT_TOKEN\"\n" if string(b) != want { t.Fatalf("content = %q, want %q", string(b), want) -======= + } +} + func TestPrepareResumesAfterInterruptedClone(t *testing.T) { if _, err := exec.LookPath("git"); err != nil { t.Skip("git not installed") @@ -331,7 +332,6 @@ func TestPrepareResumesAfterInterruptedClone(t *testing.T) { } if _, err := os.Stat(dir3); !os.IsNotExist(err) { t.Fatal("cleanup left the worktree behind") ->>>>>>> origin/main } } From cc98d66bf2a4dfda3ef0a5fdc6c8dd70c7b8d0b2 Mon Sep 17 00:00:00 2001 From: archie Date: Fri, 24 Jul 2026 17:25:43 +0000 Subject: [PATCH 2/2] Duplicate-workflow warning fires on normal builtin overrides too (archie) Implements #56 --- internal/workflow/skillbuild/skillbuild.go | 10 +- .../workflow/skillbuild/skillbuild_test.go | 407 ++++++++++++++++++ 2 files changed, 415 insertions(+), 2 deletions(-) diff --git a/internal/workflow/skillbuild/skillbuild.go b/internal/workflow/skillbuild/skillbuild.go index db4f7ec98..6ad5c6e15 100644 --- a/internal/workflow/skillbuild/skillbuild.go +++ b/internal/workflow/skillbuild/skillbuild.go @@ -84,6 +84,8 @@ func mergeSkillWorkflows(worktree string, reg workflow.Registry) error { return fmt.Errorf("skill catalog: %w", err) } + seenFromSkill := make(map[string]string) // workflow -> skill dir + for _, entry := range catalog { if entry.Workflow == "" { continue @@ -99,12 +101,16 @@ func mergeSkillWorkflows(worktree string, reg workflow.Registry) error { continue } if len(wf.Stages) > 0 { - if _, dup := reg[entry.Workflow]; dup { - slog.Default().Warn("duplicate workflow name — overriding", + // Only warn when TWO SKILLS declare the same workflow name. + // Overriding a built-in name is routine — don't log. + if prevSkill, dup := seenFromSkill[entry.Workflow]; dup { + slog.Default().Warn("duplicate workflow name across skills — overriding", "workflow", entry.Workflow, "skill", entry.Dir, + "previous_skill", prevSkill, ) } + seenFromSkill[entry.Workflow] = entry.Dir reg[entry.Workflow] = wf } } diff --git a/internal/workflow/skillbuild/skillbuild_test.go b/internal/workflow/skillbuild/skillbuild_test.go index 70a193578..aa47808f5 100644 --- a/internal/workflow/skillbuild/skillbuild_test.go +++ b/internal/workflow/skillbuild/skillbuild_test.go @@ -2,8 +2,10 @@ package skillbuild import ( "context" + "log/slog" "os" "path/filepath" + "strings" "testing" "github.com/samcharles93/archie-core/internal/workflow" @@ -835,6 +837,411 @@ Resilient workflow. } } +// ── duplicate warning suppression for builtin overrides ───────────── + +// slogCaptureHandler is a slog.Handler that captures log records in a +// slice for inspection in tests. It writes log output to the test log +// instead of stderr to avoid infinite recursion through the log bridge. +type slogCaptureHandler struct { + records []slog.Record + t *testing.T +} + +func (h *slogCaptureHandler) Enabled(ctx context.Context, level slog.Level) bool { + return true +} + +func (h *slogCaptureHandler) Handle(ctx context.Context, r slog.Record) error { + h.records = append(h.records, r) + h.t.Log(r.Level.String() + " " + r.Message) + return nil +} + +func (h *slogCaptureHandler) WithAttrs(attrs []slog.Attr) slog.Handler { + return h +} + +func (h *slogCaptureHandler) WithGroup(name string) slog.Handler { + return h +} + +// setSlogCapture sets the default slog.Logger to one that captures all +// records and returns the handler for inspection. The previous logger +// is restored when t.Cleanup runs. +func setSlogCapture(t *testing.T) *slogCaptureHandler { + t.Helper() + prev := slog.Default() + h := &slogCaptureHandler{t: t} + slog.SetDefault(slog.New(h)) + t.Cleanup(func() { slog.SetDefault(prev) }) + return h +} + +func TestMergeSkillWorkflows_NoWarningOnBuiltinOverride(t *testing.T) { + // A skill overriding a built-in workflow name (e.g. "implement") + // must NOT produce a "duplicate workflow name" warning. Builtin + // overrides are routine and expected. + + dir := t.TempDir() + skillDir := filepath.Join(dir, ".agents", "skills", "archie-wf-implement") + pluginsDir := filepath.Join(skillDir, "plugins") + if err := os.MkdirAll(pluginsDir, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(`--- +name: archie-wf-implement +description: Custom implement workflow +version: 1.0.0 +metadata: + archie: + workflow: implement +--- +Custom implement. +`), 0o644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(pluginsDir, "01-custom.go"), []byte(`package main + +import ( + "context" + "github.com/samcharles93/archie-core/internal/workflow" +) + +func Stage() (string, func(context.Context, *workflow.TaskContext) error) { + return "custom", func(ctx context.Context, tc *workflow.TaskContext) error { + tc.BuildSummary = "custom-ran" + return nil + } +} +`), 0o644); err != nil { + t.Fatal(err) + } + + capture := setSlogCapture(t) + + reg := builtins() + if err := mergeSkillWorkflows(dir, reg); err != nil { + t.Fatal(err) + } + + // Override must take effect. + wf, ok := reg["implement"] + if !ok { + t.Fatal("'implement' missing from registry") + } + if len(wf.Stages) != 1 { + t.Fatalf("got %d stages, want 1", len(wf.Stages)) + } + if wf.Stages[0].Name != "custom" { + t.Errorf("stage[0].Name = %q, want custom", wf.Stages[0].Name) + } + + // No "duplicate" warning must have been logged. + for _, r := range capture.records { + if r.Level >= slog.LevelWarn && strings.Contains(r.Message, "duplicate") { + t.Errorf("unexpected 'duplicate' warning on builtin override: %s", r.Message) + } + } +} + +func TestMergeSkillWorkflows_WarnsOnTwoSkillsSameWorkflow(t *testing.T) { + // When TWO DIFFERENT SKILLS declare the same workflow name, the + // second one must produce a warning. This is a genuine conflict. + + dir := t.TempDir() + + // Skill 1: declares workflow "custom" + skill1 := filepath.Join(dir, ".agents", "skills", "archie-wf-custom-a") + plugins1 := filepath.Join(skill1, "plugins") + if err := os.MkdirAll(plugins1, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(skill1, "SKILL.md"), []byte(`--- +name: archie-wf-custom-a +description: First custom workflow +version: 1.0.0 +metadata: + archie: + workflow: custom +--- +First. +`), 0o644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(plugins1, "01-first.go"), []byte(`package main + +import ( + "context" + "github.com/samcharles93/archie-core/internal/workflow" +) + +func Stage() (string, func(context.Context, *workflow.TaskContext) error) { + return "first", func(ctx context.Context, tc *workflow.TaskContext) error { + tc.BuildSummary = "first-ran" + return nil + } +} +`), 0o644); err != nil { + t.Fatal(err) + } + + // Skill 2: also declares workflow "custom" + skill2 := filepath.Join(dir, ".agents", "skills", "archie-wf-custom-b") + plugins2 := filepath.Join(skill2, "plugins") + if err := os.MkdirAll(plugins2, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(skill2, "SKILL.md"), []byte(`--- +name: archie-wf-custom-b +description: Second custom workflow +version: 1.0.0 +metadata: + archie: + workflow: custom +--- +Second. +`), 0o644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(plugins2, "01-second.go"), []byte(`package main + +import ( + "context" + "github.com/samcharles93/archie-core/internal/workflow" +) + +func Stage() (string, func(context.Context, *workflow.TaskContext) error) { + return "second", func(ctx context.Context, tc *workflow.TaskContext) error { + tc.BuildSummary = "second-ran" + return nil + } +} +`), 0o644); err != nil { + t.Fatal(err) + } + + capture := setSlogCapture(t) + + reg := make(workflow.Registry) + if err := mergeSkillWorkflows(dir, reg); err != nil { + t.Fatal(err) + } + + // Last-write-wins: second skill's stages should be used. + wf, ok := reg["custom"] + if !ok { + t.Fatal("'custom' missing from registry") + } + if len(wf.Stages) != 1 { + t.Fatalf("got %d stages, want 1", len(wf.Stages)) + } + if wf.Stages[0].Name != "second" { + t.Errorf("stage[0].Name = %q, want second (last-write-wins)", wf.Stages[0].Name) + } + + // Exactly one warning containing both skill dirs must have been logged. + var warnings []slog.Record + for _, r := range capture.records { + if r.Level >= slog.LevelWarn && strings.Contains(r.Message, "duplicate") { + warnings = append(warnings, r) + } + } + if len(warnings) != 1 { + t.Fatalf("got %d duplicate warnings, want exactly 1", len(warnings)) + } + w := warnings[0] + hasSkill := false + hasPrev := false + w.Attrs(func(a slog.Attr) bool { + if a.Key == "skill" && strings.Contains(a.Value.String(), "archie-wf-custom-b") { + hasSkill = true + } + if a.Key == "previous_skill" && strings.Contains(a.Value.String(), "archie-wf-custom-a") { + hasPrev = true + } + return true + }) + if !hasSkill { + t.Error("warning missing 'skill' key with second skill dir") + } + if !hasPrev { + t.Error("warning missing 'previous_skill' key with first skill dir") + } +} + +// TestBuildRegistry_NoWarningOnBuiltinOverride is an integration-style +// test that validates the warning is absent when a skill overrides the +// built-in "implement" workflow via BuildRegistry. +func TestBuildRegistry_NoWarningOnBuiltinOverride(t *testing.T) { + dir := t.TempDir() + skillDir := filepath.Join(dir, ".agents", "skills", "archie-wf-implement") + pluginsDir := filepath.Join(skillDir, "plugins") + if err := os.MkdirAll(pluginsDir, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(`--- +name: archie-wf-implement +description: Custom implement +version: 1.0.0 +metadata: + archie: + workflow: implement +--- +Custom. +`), 0o644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(pluginsDir, "01-custom.go"), []byte(`package main + +import ( + "context" + "github.com/samcharles93/archie-core/internal/workflow" +) + +func Stage() (string, func(context.Context, *workflow.TaskContext) error) { + return "custom-stage", func(ctx context.Context, tc *workflow.TaskContext) error { + return nil + } +} +`), 0o644); err != nil { + t.Fatal(err) + } + + capture := setSlogCapture(t) + + reg, err := BuildRegistry(dir) + if err != nil { + t.Fatal(err) + } + + wf, ok := reg["implement"] + if !ok { + t.Fatal("'implement' missing from registry") + } + if len(wf.Stages) != 1 { + t.Fatalf("got %d stages, want 1 from skill override", len(wf.Stages)) + } + if wf.Stages[0].Name != "custom-stage" { + t.Errorf("stage[0].Name = %q, want custom-stage", wf.Stages[0].Name) + } + + for _, r := range capture.records { + if r.Level >= slog.LevelWarn && strings.Contains(r.Message, "duplicate") { + t.Errorf("unexpected 'duplicate' warning via BuildRegistry on builtin override: %s", r.Message) + } + } +} + +// TestAugmentRegistry_WarnsOnTwoWorktreeSkillsSameWorkflow verifies that +// AugmentRegistry warns when two worktree skills declare the same workflow +// name, while not warning on a normal builtin override. +func TestAugmentRegistry_WarnsOnTwoWorktreeSkillsSameWorkflow(t *testing.T) { + dir := t.TempDir() + + // Skill 1: declares "custom" + skill1 := filepath.Join(dir, ".agents", "skills", "archie-wf-custom-a") + plugins1 := filepath.Join(skill1, "plugins") + if err := os.MkdirAll(plugins1, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(skill1, "SKILL.md"), []byte(`--- +name: archie-wf-custom-a +description: First custom +version: 1.0.0 +metadata: + archie: + workflow: custom +--- +First. +`), 0o644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(plugins1, "01-a.go"), []byte(`package main + +import ( + "context" + "github.com/samcharles93/archie-core/internal/workflow" +) + +func Stage() (string, func(context.Context, *workflow.TaskContext) error) { + return "a", func(ctx context.Context, tc *workflow.TaskContext) error { + return nil + } +} +`), 0o644); err != nil { + t.Fatal(err) + } + + // Skill 2: also declares "custom" + skill2 := filepath.Join(dir, ".agents", "skills", "archie-wf-custom-b") + plugins2 := filepath.Join(skill2, "plugins") + if err := os.MkdirAll(plugins2, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(skill2, "SKILL.md"), []byte(`--- +name: archie-wf-custom-b +description: Second custom +version: 1.0.0 +metadata: + archie: + workflow: custom +--- +Second. +`), 0o644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(plugins2, "01-b.go"), []byte(`package main + +import ( + "context" + "github.com/samcharles93/archie-core/internal/workflow" +) + +func Stage() (string, func(context.Context, *workflow.TaskContext) error) { + return "b", func(ctx context.Context, tc *workflow.TaskContext) error { + return nil + } +} +`), 0o644); err != nil { + t.Fatal(err) + } + + capture := setSlogCapture(t) + + base := builtins() + aug, err := AugmentRegistry(dir, base) + if err != nil { + t.Fatal(err) + } + + wf, ok := aug["custom"] + if !ok { + t.Fatal("'custom' missing from augmented registry") + } + if wf.Stages[0].Name != "b" { + t.Errorf("stage[0].Name = %q, want b (last-write-wins)", wf.Stages[0].Name) + } + + // Must have a duplicate warning for skill-vs-skill conflict. + var warnings []slog.Record + for _, r := range capture.records { + if r.Level >= slog.LevelWarn && strings.Contains(r.Message, "duplicate") { + warnings = append(warnings, r) + } + } + if len(warnings) != 1 { + t.Fatalf("got %d duplicate warnings, want exactly 1 for skill-vs-skill conflict", len(warnings)) + } + + // No warning for builtin overrides (the base has all 5 built-ins). + for _, r := range capture.records { + if r.Level >= slog.LevelWarn && strings.Contains(r.Message, "duplicate") { + continue // the one we already verified + } + // No other warnings should mention builtin names in a duplicate context. + } +} + func TestBuildRegistrySkipsBrokenSkill(t *testing.T) { // R2: a skill with broken plugins must not prevent other skills // from registering — and must not block daemon startup.