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.6 KiB
Go
81 lines
2.6 KiB
Go
//go:build llm_script
|
||
|
||
package main
|
||
|
||
import (
|
||
"bytes"
|
||
"os"
|
||
"path/filepath"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
func TestParsePerplexityPricingCatalogBuildsRecords(t *testing.T) {
|
||
raw, err := os.ReadFile(filepath.Join("testdata", "perplexity_pricing_sample.md"))
|
||
if err != nil {
|
||
t.Fatalf("读取 fixture 失败: %v", err)
|
||
}
|
||
|
||
records, err := parsePerplexityPricingCatalog(string(raw))
|
||
if err != nil {
|
||
t.Fatalf("parsePerplexityPricingCatalog 返回错误: %v", err)
|
||
}
|
||
if len(records) != 5 {
|
||
t.Fatalf("期望 5 条 Perplexity 价格记录,实际 %d", len(records))
|
||
}
|
||
if records[0].ModelID != "perplexity-perplexity-sonar" {
|
||
t.Fatalf("首条 modelID 错误: %q", records[0].ModelID)
|
||
}
|
||
if records[1].ProviderName != "Anthropic" {
|
||
t.Fatalf("Anthropic provider 归一化错误: %q", records[1].ProviderName)
|
||
}
|
||
if records[3].ModelSourceURL != "https://ai.google.dev/gemini-api/docs/models#gemini-3.1-pro-preview" {
|
||
t.Fatalf("Gemini 模型文档链接错误: %q", records[3].ModelSourceURL)
|
||
}
|
||
}
|
||
|
||
func TestRunPerplexityPricingImportDryRunPrintsSummary(t *testing.T) {
|
||
var out bytes.Buffer
|
||
err := runPerplexityPricingImport(perplexityPricingImportConfig{
|
||
URL: defaultPerplexityPricingFetchURL,
|
||
Fixture: filepath.Join("testdata", "perplexity_pricing_sample.md"),
|
||
DryRun: true,
|
||
}, nil, &out)
|
||
if err != nil {
|
||
t.Fatalf("runPerplexityPricingImport 返回错误: %v", err)
|
||
}
|
||
output := out.String()
|
||
for _, want := range []string{
|
||
"source=perplexity-pricing-import",
|
||
"models=5",
|
||
"operator=Perplexity API",
|
||
"dry_run=true",
|
||
} {
|
||
if !strings.Contains(output, want) {
|
||
t.Fatalf("输出缺少 %q,实际: %q", want, output)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestParsePerplexityPricingCatalogAcceptsExtraColumnsAndDocAtTail(t *testing.T) {
|
||
raw := "" +
|
||
"\n# Models\n" +
|
||
"\n| Model | Family | Input Price | Output Price | Notes | Provider Documentation |\n" +
|
||
"| --- | --- | --- | --- | --- | --- |\n" +
|
||
"| `openai/gpt-5.5` | GPT-5 | \\$1.25 / 1M tokens | \\$10.00 / 1M tokens | flagship | [GPT-5.5](https://platform.openai.com/docs/models/gpt-5.5) |\n"
|
||
|
||
records, err := parsePerplexityPricingCatalog(raw)
|
||
if err != nil {
|
||
t.Fatalf("parsePerplexityPricingCatalog 返回错误: %v", err)
|
||
}
|
||
if len(records) != 1 {
|
||
t.Fatalf("期望 1 条 Perplexity 价格记录,实际 %d", len(records))
|
||
}
|
||
if records[0].ModelSourceURL != "https://platform.openai.com/docs/models/gpt-5.5" {
|
||
t.Fatalf("文档链接错误: %q", records[0].ModelSourceURL)
|
||
}
|
||
if records[0].InputPrice != 1.25 || records[0].OutputPrice != 10 {
|
||
t.Fatalf("价格解析错误: %v / %v", records[0].InputPrice, records[0].OutputPrice)
|
||
}
|
||
}
|