Add snapshot, signature, and drift guard support for Vertex AI, Cloudflare Workers AI, and Perplexity API, backed by a queryable audit table and recent-window view. This commit also wires the audit query layer into daily signal materialization and report generation so structure drift becomes a first-class signal instead of a log-only artifact.
81 lines
2.1 KiB
Go
81 lines
2.1 KiB
Go
//go:build llm_script
|
||
|
||
package main
|
||
|
||
import (
|
||
"bytes"
|
||
"strings"
|
||
"testing"
|
||
"time"
|
||
)
|
||
|
||
func TestBuildOfficialImportSignatureAuditViewQueryIncludesWindowAndFilters(t *testing.T) {
|
||
query, args := buildOfficialImportSignatureAuditViewQuery(5, "vertex_pricing_signature", true)
|
||
for _, want := range []string{
|
||
"FROM official_import_signature_audit_recent_view",
|
||
"recent_rank <= $1",
|
||
"source_key = $2",
|
||
"structure_changed = TRUE",
|
||
} {
|
||
if !strings.Contains(query, want) {
|
||
t.Fatalf("query 缺少 %q,实际: %s", want, query)
|
||
}
|
||
}
|
||
if len(args) != 2 {
|
||
t.Fatalf("参数个数错误: %d", len(args))
|
||
}
|
||
if args[0] != 5 || args[1] != "vertex_pricing_signature" {
|
||
t.Fatalf("参数错误: %#v", args)
|
||
}
|
||
}
|
||
|
||
func TestRenderOfficialImportSignatureAuditReportPrintsSummaryAndRows(t *testing.T) {
|
||
summaries := []officialImportSignatureAuditSourceSummary{
|
||
{
|
||
SourceKey: "cloudflare_pricing_signature",
|
||
RunsInWindow: 5,
|
||
ChangedRuns: 2,
|
||
LatestCheckedAt: time.Date(2026, 5, 15, 20, 0, 0, 0, time.UTC),
|
||
LatestStatus: "passed",
|
||
LatestStructureState: "stable",
|
||
},
|
||
}
|
||
rows := []officialImportSignatureAuditViewRow{
|
||
{
|
||
SourceKey: "cloudflare_pricing_signature",
|
||
RecentRank: 1,
|
||
CheckedAt: time.Date(2026, 5, 15, 20, 0, 0, 0, time.UTC),
|
||
Status: "passed",
|
||
StructureState: "stable",
|
||
StructureChanged: false,
|
||
StructureSHA256: "abc123",
|
||
},
|
||
{
|
||
SourceKey: "cloudflare_pricing_signature",
|
||
RecentRank: 2,
|
||
CheckedAt: time.Date(2026, 5, 14, 20, 0, 0, 0, time.UTC),
|
||
Status: "drift_detected",
|
||
StructureState: "changed",
|
||
StructureChanged: true,
|
||
StructureSHA256: "def456",
|
||
},
|
||
}
|
||
|
||
var out bytes.Buffer
|
||
renderOfficialImportSignatureAuditReport(&out, 5, "", false, summaries, rows)
|
||
output := out.String()
|
||
for _, want := range []string{
|
||
"Official Import Signature Audit Report",
|
||
"window_per_source=5",
|
||
"cloudflare_pricing_signature",
|
||
"changed_runs=2",
|
||
"recent_rank=2",
|
||
"state=changed",
|
||
"sha=def456",
|
||
} {
|
||
if !strings.Contains(output, want) {
|
||
t.Fatalf("输出缺少 %q,实际: %q", want, output)
|
||
}
|
||
}
|
||
}
|