Why: Project work currently reaches model calls without current authorized project facts or a persisted input receipt. Evidence: SELF go test ./... -count=1, targeted go test -race for W6 paths, go vet ./..., and CGO_ENABLED=0 go build ./cmd/agent-system passed on this change set. Impact: Add optional X1 interfaces, trusted persisted work-task binding, request-scoped context injection, evidence reauthorization, and attempted/responded/unknown manifests. Existing non-project behavior stays available. Refs: TT-C01 TT-C02 TT-C03 TT-C04; stage5 W6; Dev stage6 X1 public extension request r1
44 lines
1.8 KiB
Go
44 lines
1.8 KiB
Go
package projectcontext
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"agent-system-backend/pkg/extension"
|
|
)
|
|
|
|
func TestAssembleOffersOnlyBudgetedEvidenceReferences(t *testing.T) {
|
|
bundle := extension.ProjectContextBundle{Status: extension.ProjectContextReady, ProjectID: "p1", Evidence: []extension.ProjectEvidenceRef{{ID: "ref-1", SourceID: "doc-1", Revision: "r2"}, {ID: strings.Repeat("x", 1000), SourceID: "doc-2"}}}
|
|
text, manifest, err := Assemble(bundle, 180)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(text, "ref-1") || strings.Contains(text, strings.Repeat("x", 1000)) || len(manifest.OfferedReferences) != 1 || manifest.OfferedReferences[0].ID != "ref-1" {
|
|
t.Fatalf("reference offer does not match model input: text=%q manifest=%+v", text, manifest)
|
|
}
|
|
}
|
|
|
|
func TestValidateCurrentRejectsWithdrawnOfferedReference(t *testing.T) {
|
|
ref := extension.ProjectEvidenceRef{ID: "ref-1", SourceID: "doc-1", Revision: "r2"}
|
|
old := extension.ProjectContextBundle{Status: extension.ProjectContextReady, ProjectID: "p1", Evidence: []extension.ProjectEvidenceRef{ref}}
|
|
_, manifest, err := Assemble(old, 180)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
current := extension.ProjectContextBundle{Status: extension.ProjectContextReady, ProjectID: "p1"}
|
|
if err := ValidateCurrent(manifest, current); err == nil {
|
|
t.Fatal("reference withdrawn before model send was still offered")
|
|
}
|
|
}
|
|
|
|
func TestAssembleIncludesUnresolvedMissingStatus(t *testing.T) {
|
|
bundle := extension.ProjectContextBundle{Status: extension.ProjectContextReady, ProjectID: "p1", Missing: []string{"unresolved conflict"}}
|
|
text, manifest, err := Assemble(bundle, 180)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(text, "unresolved conflict") || len(manifest.Missing) != 1 {
|
|
t.Fatalf("missing status hidden from model or receipt: text=%q manifest=%+v", text, manifest)
|
|
}
|
|
}
|