package pipeline import ( "context" "path/filepath" "sort" "testing" "time" "git.a-wan.net/alan/pipelines/internal/protocol" ) // Artifact search returns only deliverables unless debugging files are asked // for, and the step read path classifies stored records that carry no group. func TestSearchArtifactsExcludeDebugFilesByDefault(t *testing.T) { ctx := context.Background() store, err := Open(filepath.Join(t.TempDir(), "search-debug.db")) if err != nil { t.Fatal(err) } t.Cleanup(func() { store.Close() }) if _, err := store.Submit(ctx, "Quartz", Template([]string{"quartz"}, true)); err != nil { t.Fatal(err) } items, err := store.List(ctx) if err != nil { t.Fatal(err) } definition, err := store.Get(ctx, items[0].ID, 1) if err != nil { t.Fatal(err) } run, _, err := store.CreateRun(ctx, definition, "quartz-key", "/work/q", false, nil, map[string]any{"prompt": "task"}) if err != nil { t.Fatal(err) } if err := store.BeginStep(ctx, run, 1, "quartz", map[string]any{"prompt": "task"}); err != nil { t.Fatal(err) } // Stored without a group, as a server before the field recorded them. files := []protocol.StageArtifact{ {Name: "input.md", ContentType: "text/markdown", URL: "/a/input.md"}, {Name: "history.md", ContentType: "text/markdown", URL: "/a/history.md"}, {Name: "private/qz-shot.png", ContentType: "image/png", URL: "/a/private/qz-shot.png"}, {Name: "public/qz-report.md", ContentType: "text/markdown", URL: "/a/public/qz-report.md"}, } if err := store.FinishStep(ctx, run, protocol.RunStep{Sequence: 1, Status: "completed", Outcome: "success", Target: protocol.SuccessEnd, Artifacts: files}); err != nil { t.Fatal(err) } names := func(req protocol.SearchRequest) []string { t.Helper() req.Kind = protocol.SearchKindArtifact response, err := store.Search(ctx, req, time.Now()) if err != nil { t.Fatal(err) } var got []string for _, hit := range response.Results { got = append(got, hit.Artifact.Name+"="+hit.Artifact.Group) } sort.Strings(got) return got } if got := names(protocol.SearchRequest{Query: "md"}); len(got) != 1 || got[0] != "public/qz-report.md=deliverable" { t.Fatalf("default search = %v, want only the public deliverable", got) } if got := names(protocol.SearchRequest{Query: "history"}); len(got) != 0 { t.Fatalf("history.md surfaced by default: %v", got) } if got := names(protocol.SearchRequest{Query: "qz", IncludeDebug: true}); len(got) != 2 || got[0] != "private/qz-shot.png=debug" { t.Fatalf("include_debug search = %v", got) } detail, err := store.GetRun(ctx, run) if err != nil { t.Fatal(err) } groups := map[string]string{} for _, file := range detail.Steps[0].Artifacts { groups[file.Name] = file.Group } if groups["history.md"] != protocol.ArtifactGroupDebug || groups["private/qz-shot.png"] != protocol.ArtifactGroupDebug || groups["public/qz-report.md"] != protocol.ArtifactGroupDeliverable { t.Fatalf("read path groups = %v", groups) } }