Files
llm-intelligence/scripts/import_cloudflare_pricing_test.go
phamnazage-jpg 256975e10c feat(audit): add pricing signature guards and reporting
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.
2026-05-15 22:34:22 +08:00

82 lines
2.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//go:build llm_script
package main
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)
func TestParseCloudflarePricingCatalogBuildsRecords(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("testdata", "cloudflare_pricing_sample.md"))
if err != nil {
t.Fatalf("读取 fixture 失败: %v", err)
}
records, err := parseCloudflarePricingCatalog(string(raw))
if err != nil {
t.Fatalf("parseCloudflarePricingCatalog 返回错误: %v", err)
}
if len(records) != 4 {
t.Fatalf("期望 4 条 Cloudflare 价格记录,实际 %d", len(records))
}
if records[0].ModelID != "cloudflare-cf-meta-llama-3-2-1b-instruct" {
t.Fatalf("首条 modelID 错误: %q", records[0].ModelID)
}
if records[1].OutputPrice != 2.253 {
t.Fatalf("第二条输出价错误: %v", records[1].OutputPrice)
}
if records[3].ProviderName != "Moonshot AI" {
t.Fatalf("Kimi provider 归一化错误: %q", records[3].ProviderName)
}
}
func TestRunCloudflarePricingImportDryRunPrintsSummary(t *testing.T) {
var out bytes.Buffer
err := runCloudflarePricingImport(cloudflarePricingImportConfig{
URL: defaultCloudflarePricingFetchURL,
Fixture: filepath.Join("testdata", "cloudflare_pricing_sample.md"),
DryRun: true,
}, nil, &out)
if err != nil {
t.Fatalf("runCloudflarePricingImport 返回错误: %v", err)
}
output := out.String()
for _, want := range []string{
"source=cloudflare-pricing-import",
"models=4",
"operator=Cloudflare Workers AI",
"dry_run=true",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}
func TestParseCloudflarePricingCatalogAcceptsFlexibleSectionBoundary(t *testing.T) {
raw := `
## LLM pricing
| Model | Price in Tokens | Price in Neurons |
| --- | --- | --- |
| @cf/meta/llama-3.1-8b-instruct | $0.200 per M input tokens $1.000 per M output tokens | ignored |
## Image generation pricing
`
records, err := parseCloudflarePricingCatalog(raw)
if err != nil {
t.Fatalf("parseCloudflarePricingCatalog 返回错误: %v", err)
}
if len(records) != 1 {
t.Fatalf("期望 1 条 Cloudflare 价格记录,实际 %d", len(records))
}
if records[0].ModelName != "@cf/meta/llama-3.1-8b-instruct" {
t.Fatalf("模型名错误: %q", records[0].ModelName)
}
}