feat: route factual questions through bounded research
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package research_runtime_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
researchadapter "git.cin.su/m/Assistant/adapters/research"
|
||||
"git.cin.su/m/Assistant/contracts/epistemics"
|
||||
)
|
||||
|
||||
func TestSearchConnectorReturnsBoundedImmutableEvidence(t *testing.T) {
|
||||
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
_, _ = w.Write([]byte(`<a class="result__a">Verified title</a><a class="result__snippet">Observed source excerpt</a>`))
|
||||
}))
|
||||
defer server.Close()
|
||||
request := epistemics.WebSearchRequest{Plan: epistemics.ResearchPlan{ID: "plan", Question: "current fact", SourceClasses: []string{"web-search"}, FreshnessPolicy: "current"}, PropositionKey: "question-1", Query: "current fact"}
|
||||
connector := researchadapter.SearchConnector{EndpointTemplate: server.URL + "?q=%s", AllowedHosts: map[string]struct{}{"127.0.0.1": {}}, Client: server.Client(), MaxResults: 3}
|
||||
// The production connector requires HTTPS. The test server is HTTPS too;
|
||||
// use its host as the allowlisted value and preserve the same transport.
|
||||
candidates, err := connector.Collect(context.Background(), request, 10)
|
||||
if err != nil {
|
||||
t.Fatalf("collect search evidence: %v", err)
|
||||
}
|
||||
if len(candidates) != 1 || candidates[0].Statement != "Verified title — Observed source excerpt" {
|
||||
t.Fatalf("unexpected candidates: %+v", candidates)
|
||||
}
|
||||
if candidates[0].Evidence != epistemics.EvidenceObserved || candidates[0].Snapshot.ContentDigest == "" || candidates[0].Excerpt.Text == "" {
|
||||
t.Fatalf("candidate lost evidence chain: %+v", candidates[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchConnectorRejectsUnallowlistedEndpoint(t *testing.T) {
|
||||
request := epistemics.WebSearchRequest{Plan: epistemics.ResearchPlan{ID: "plan", Question: "q", SourceClasses: []string{"web-search"}, FreshnessPolicy: "current"}, Query: "q"}
|
||||
_, err := (researchadapter.SearchConnector{EndpointTemplate: "https://example.invalid/?q=%s"}).Collect(context.Background(), request, 10)
|
||||
if err != researchadapter.ErrSearchRejected {
|
||||
t.Fatalf("expected allowlist rejection, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user