ci / vet-and-test (pull_request) Successful in 40s
Why: User rulings 4/5 plus the P2-P4 live evidence. Keyword scoring dimensions (readability, actionability) kept failing valid documents - normal Chinese section headings flagged as column titles, loops of 4 corrections - because they grade writing preferences, not verifiable facts. Unverified numbers (~10-13 per run) remained the largest quality leak through every phase. And the verifier runs on the same model as the worker (lightweight falls back to chat), so "independent" verification was self-review. Separately, svc seeding after boot never registered the tavily tools until a restart because keys were snapshotted at startup. Changes: quality.HardFacts (lint actually ran + zero errors) replaces the full ScoreBytes projection in CheckArtifacts - keyword dimensions remain in ScoreBytes for eval visibility only. New fact-consistency check (runtime.factCheck, default on): extract percentages/dates/large numbers from deliverable text, trace each against the material corpus (attachment text + tool evidence); misses get exactly one correction round (fix, drop, or mark as target/estimate), never a loop. runVerifier skips same-source model verification unless runtime.verifierSameModel is set (hard facts + fact check still run). Search tools now register lazily, reading tavily keys per call (settings/seeding take effect immediately). Evidence: SELF - TestHardFactsIgnoresKeywordDimensions, TestHardFactsKeepsLintUnavailableBlocking, TestUnverifiedFactsAndNotice, TestFactCheckContinuationOnce (fact note fires, corrected run passes); go vet + go test ./... pass; live before/after on the golden task set recorded on the phase05 task card per the policy clause. Impact: Gate stops rejecting valid documents on stylistic grounds; invented figures get one forced correction round; same-model verification no longer pretends to be independent; tavily config is hot. No contract or storage changes.
76 lines
2.4 KiB
Go
76 lines
2.4 KiB
Go
package tools
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
core "agent-system-core"
|
|
)
|
|
|
|
type dummyCtx struct{ project string }
|
|
|
|
func (dummyCtx) ProjectID() string { return "" }
|
|
func (dummyCtx) ConversationID() string { return "" }
|
|
func (dummyCtx) Retrieve(q core.RetrievalQuery) ([]core.RetrievalHit, error) { return nil, nil }
|
|
func (dummyCtx) WriteArtifact(name, kind, mime string, content []byte) (core.Artifact, error) {
|
|
return core.Artifact{}, nil
|
|
}
|
|
func (dummyCtx) PeerConversations() ([]core.Conversation, error) { return nil, nil }
|
|
func (dummyCtx) PeerConversationMessages(id string, limit int) ([]core.Message, error) {
|
|
return nil, nil
|
|
}
|
|
func (dummyCtx) OwnerID() string { return "o" }
|
|
func (dummyCtx) WorkspaceRoot() string { return "" }
|
|
func (dummyCtx) SettingBool(string, bool) bool { return false }
|
|
|
|
// TestHTTPExecutorTemplateAndPath:模板变量注入、结果路径裁剪、错误状态。
|
|
func TestHTTPExecutorTemplateAndPath(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/translate" {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Write([]byte(`{"data":[{"translated":"hello","src":"你好"}],"meta":{"n":1}}`))
|
|
}))
|
|
defer srv.Close()
|
|
|
|
spec := core.HTTPToolSpec{
|
|
Method: "POST", URL: srv.URL + "/translate",
|
|
BodyTemplate: `{"q":"{{param.text}}"}`, ResultPath: "data.0.translated",
|
|
}
|
|
exec := HTTPExecutor(spec, nil)
|
|
out, err := exec(dummyCtx{}, []byte(`{"text":"你好"}`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if out != `"hello"` && out != "hello" {
|
|
t.Errorf("result: %q", out)
|
|
}
|
|
|
|
// ResultPath 不存在 → 显式错误。
|
|
specBad := spec
|
|
specBad.ResultPath = "missing.path"
|
|
if _, err := HTTPExecutor(specBad, nil)(dummyCtx{}, []byte(`{}`)); err == nil {
|
|
t.Error("missing path should error")
|
|
}
|
|
|
|
// 404 → 错误带状态码。
|
|
spec404 := spec
|
|
spec404.URL = srv.URL + "/nope"
|
|
spec404.ResultPath = ""
|
|
if _, err := HTTPExecutor(spec404, nil)(dummyCtx{}, nil); err == nil {
|
|
t.Error("404 should error")
|
|
}
|
|
}
|
|
|
|
func TestExpandTemplate(t *testing.T) {
|
|
got := expandTemplate(`{{param.a}}/{{param.b.c}}/{{param.unknown}}`, map[string]any{
|
|
"a": "x", "b": map[string]any{"c": "y"},
|
|
})
|
|
if got != "x/y/" {
|
|
t.Errorf("expand: %q", got)
|
|
}
|
|
}
|