Rework omni search onto a typed search contract and add a TUI artifacts view
Protocol: replace the loose Query/Kind/Matches/Limit search fields with a Search request object and a SearchResults response, and have the server answer search from Store.Search over the shared run projections (runFrom/runStamps).
CLI: add the read-only 'pipelines search QUERY [--type KIND] [--limit N] [--json]' command with usage/help, and document the typed targets, ranking and bounds in docs/cli.md.
TUI: the '/' popup keeps type-to-search, up/down, Enter and Esc, renders one ranked list with kind badges and a bracketed (non-colour) match snippet, and Enter opens the matched pipeline, run, step, artifact or field; footer text updated to match.
TUI: add a dedicated run artifacts view ('A') with open/copy of recorded files, and move artifacts out of the run-detail File changes section (artifactCaptureNotes).
Tests: add Store.OpenReadOnly for read-only inspection of a live database plus pipeline/server/TUI search tests and artifacts tests, including env-gated live checks.
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/cli"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// TestCLISearchEndToEndEveryKind seeds a store whose pipeline, source, run,
|
||||
// stage, field text and artifact all contain one token, then runs the CLI
|
||||
// search command over a real Handler and asserts the server returned one match
|
||||
// of every kind and rejects an unknown --type rather than ignoring it.
|
||||
func TestCLISearchEndToEndEveryKind(t *testing.T) {
|
||||
t.Setenv("PIPELINES_HARNESS_CONFIG", filepath.Join(t.TempDir(), "harnesses.json"))
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "search-e2e.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if _, err := store.Submit(ctx, "Zephyr Build", pipeline.Template([]string{"zephyr"}, 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, "zephyr-key", "/work/zephyr", false, nil, map[string]any{"prompt": "zephyr task"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.BeginStep(ctx, run, 1, "zephyr", map[string]any{"prompt": "zephyr task"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.FinishStep(ctx, run, protocol.RunStep{
|
||||
Sequence: 1, Status: "completed", Outcome: "success", Target: protocol.SuccessEnd,
|
||||
Output: map[string]any{"summary": "zephyr completed"},
|
||||
Artifacts: []protocol.StageArtifact{{Name: "zephyr.txt", SizeBytes: 12, ContentType: "text/plain", URL: "/artifacts/" + strconv.FormatInt(run, 10) + "/1/zephyr.txt"}},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
handler := Handler(ctx, store)
|
||||
defer func() { cancel(); WaitRuns(handler) }()
|
||||
http := httptest.NewServer(handler)
|
||||
defer http.Close()
|
||||
url := "ws" + strings.TrimPrefix(http.URL, "http") + "/connect"
|
||||
|
||||
runCLI := func(args ...string) (string, error) {
|
||||
var out bytes.Buffer
|
||||
app := cli.App{Out: &out, Err: &out, In: strings.NewReader("")}
|
||||
err := app.Run(ctx, append([]string{"--url", url}, args...))
|
||||
return out.String(), err
|
||||
}
|
||||
output, err := runCLI("search", "zephyr", "--json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var response protocol.SearchResponse
|
||||
if err := json.Unmarshal([]byte(output), &response); err != nil {
|
||||
t.Fatal(err, output)
|
||||
}
|
||||
kinds := map[string]bool{}
|
||||
for _, hit := range response.Results {
|
||||
kinds[hit.Kind] = true
|
||||
if hit.Target == "" || hit.MatchedField == "" || hit.Score == 0 {
|
||||
t.Fatalf("hit lacks ranking/navigation context: %+v", hit)
|
||||
}
|
||||
}
|
||||
for _, kind := range protocol.SearchKinds {
|
||||
if !kinds[kind] {
|
||||
t.Fatalf("kind %q missing from end-to-end search: %s", kind, output)
|
||||
}
|
||||
}
|
||||
|
||||
if output, err := runCLI("search", "zephyr", "--type", "run", "--json"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
var filtered protocol.SearchResponse
|
||||
if err := json.Unmarshal([]byte(output), &filtered); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, hit := range filtered.Results {
|
||||
if hit.Kind != protocol.SearchKindRun {
|
||||
t.Fatalf("kind filter leaked %q", hit.Kind)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := runCLI("search", "zephyr", "--type", "bogus"); err == nil || !strings.Contains(err.Error(), "unknown search kind") {
|
||||
t.Fatalf("invalid kind must error, got %v", err)
|
||||
}
|
||||
}
|
||||
@@ -217,14 +217,21 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin
|
||||
} else {
|
||||
response.Pipelines = items
|
||||
}
|
||||
} else if request.Type == protocol.Search && len(stores) > 0 && runs != nil {
|
||||
response.Type = protocol.SearchResults
|
||||
matches, err := runs.search(request)
|
||||
if err != nil {
|
||||
} else if request.Type == protocol.Search {
|
||||
if len(stores) == 0 {
|
||||
response.Type = protocol.Error
|
||||
response.Error = err.Error()
|
||||
response.Error = "search unavailable: no store"
|
||||
} else if request.Search == nil {
|
||||
response.Type = protocol.Error
|
||||
response.Error = "search requires a query"
|
||||
} else {
|
||||
response.Matches = matches
|
||||
response.Type = protocol.SearchResults
|
||||
var err error
|
||||
response.SearchResults, err = stores[0].Search(ctx, *request.Search, time.Now())
|
||||
if err != nil {
|
||||
response.Type = protocol.Error
|
||||
response.Error = err.Error()
|
||||
}
|
||||
}
|
||||
} else if runs != nil && (request.Type == protocol.RunPipeline || request.Type == protocol.RetryRun || request.Type == protocol.ListRuns || request.Type == protocol.GetRun || request.Type == protocol.CancelRun || request.Type == protocol.DecideRun || request.Type == protocol.SetRunTitle || request.Type == protocol.GetRunEvidence) {
|
||||
var err error
|
||||
|
||||
Reference in New Issue
Block a user