Why: Project retrieval hits, tool results, and saved visible analysis must be individually traceable and fully analyzed before later project actions consume them. Evidence: RED tests first showed missing run-source capture, tool-result capture, and run-wide preflight; go test -p 1 ./... and go build ./... passed; isolated PostgreSQL source, migration, audit, and context tests passed. Impact: Persist actual run-bound sources with current-status checks and exact manifests behind the disabled X3 assembly gate; no live product path, migration, deployment, or release is enabled. Refs: TT-N03, TT-R01; approved X3 stage-five plan r1
53 lines
2.0 KiB
Go
53 lines
2.0 KiB
Go
package store
|
|
|
|
import (
|
|
"testing"
|
|
|
|
core "agent-system-core"
|
|
)
|
|
|
|
func TestRunWorkSourceUsesStoredRunAndRetainsEachActualHit(t *testing.T) {
|
|
st := openTestStore(t)
|
|
if err := st.EnsureUser("alice", "Alice"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, err := st.CreateProject("alice", "P")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
conv, err := st.CreateConversation("alice", string(p.ID), "Work", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
run := core.Run{ConversationID: conv.ID, ProjectID: p.ID, Owner: "alice", Kind: core.RunConversation, Status: core.RunRunning, Phase: core.PhaseThinking}
|
|
if err := st.CreateRun(&run); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
input := RunWorkObservationInput{RunID: string(run.ID), SourceKind: "retrieval-hit", SourceID: "knowledge-1", SourceVersion: "v1", Text: "实际命中的资料", Delivery: "complete", Metadata: map[string]string{"query": "效率", "ref": "https://example.test/a"}}
|
|
first, err := st.AppendRunWorkObservation(input)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
second, err := st.AppendRunWorkObservation(input)
|
|
if err != nil || first == second {
|
|
t.Fatalf("repeated actual hit lost occurrence identity: first=%q second=%q err=%v", first, second, err)
|
|
}
|
|
rows, err := st.PendingProjectWorkObservations(10)
|
|
if err != nil || len(rows) != 2 {
|
|
t.Fatalf("run observations missing: %+v %v", rows, err)
|
|
}
|
|
for _, row := range rows {
|
|
if row.Owner != "alice" || row.ProjectID != string(p.ID) || row.ConversationID != string(conv.ID) || row.RunID != string(run.ID) || row.SourceID != "knowledge-1" || row.Text != input.Text || row.Metadata["query"] != "效率" {
|
|
t.Fatalf("source was not derived from trusted run or actual hit: %+v", row)
|
|
}
|
|
}
|
|
runRows, err := st.ProjectRunObservations(string(run.ID))
|
|
if err != nil || len(runRows) != 2 {
|
|
t.Fatalf("run manifest omitted actual retrieval occurrences: %+v %v", runRows, err)
|
|
}
|
|
input.RunID = "run-forged"
|
|
if _, err := st.AppendRunWorkObservation(input); err == nil {
|
|
t.Fatal("unbound run locator became a project source")
|
|
}
|
|
}
|