Files
llm-intelligence/scripts/deepseek_pricing_signature_guard_test.go
phamnazage-jpg 88833fac8b
Some checks failed
CI / go-test (push) Has been cancelled
CI / scripts-regression (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / docker-build (push) Has been cancelled
feat(intraday): monitor DeepSeek official page drift
2026-05-27 22:01:20 +08:00

97 lines
4.0 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 (
"os"
"path/filepath"
"strings"
"testing"
"time"
)
func TestRunDeepSeekPricingSignatureGuardInitializesBaseline(t *testing.T) {
tempDir := t.TempDir()
baselinePath := filepath.Join(tempDir, "baseline.signature.json")
fixture := filepath.Join(tempDir, "pricing.html")
if err := os.WriteFile(fixture, []byte(`<html><head><title>DeepSeek</title><meta name="description" content="Join DeepSeek API platform"><meta name="commit-id" content="abc123"><meta property="og:url" content="https://platform.deepseek.com/pricing"></head><body>pricing</body></html>`), 0o644); err != nil {
t.Fatalf("写入 fixture 失败: %v", err)
}
result, err := runDeepSeekPricingSignatureGuard(deepseekPricingSignatureGuardConfig{
SourceKey: "deepseek_pricing_signature",
URL: defaultDeepSeekPricingFetchURL,
Fixture: fixture,
SnapshotDir: tempDir,
BaselinePath: baselinePath,
Timeout: time.Second,
AllowBootstrap: true,
SnapshotBase: "deepseek-pricing",
}, time.Date(2026, 5, 27, 22, 0, 0, 0, time.FixedZone("CST", 8*3600)))
if err != nil {
t.Fatalf("runDeepSeekPricingSignatureGuard 返回错误: %v", err)
}
if !result.BaselineInitialized {
t.Fatal("期望初始化 baseline")
}
}
func TestRunDeepSeekPricingSignatureGuardDetectsDrift(t *testing.T) {
tempDir := t.TempDir()
baselinePath := filepath.Join(tempDir, "baseline.signature.json")
fixture := filepath.Join(tempDir, "pricing.html")
if err := os.WriteFile(fixture, []byte(`<html><head><title>DeepSeek</title><meta name="description" content="Join DeepSeek API platform"><meta name="commit-id" content="abc123"><meta property="og:url" content="https://platform.deepseek.com/pricing"></head><body>pricing</body></html>`), 0o644); err != nil {
t.Fatalf("写入 fixture 失败: %v", err)
}
_, err := runDeepSeekPricingSignatureGuard(deepseekPricingSignatureGuardConfig{
SourceKey: "deepseek_pricing_signature",
URL: defaultDeepSeekPricingFetchURL,
Fixture: fixture,
SnapshotDir: tempDir,
BaselinePath: baselinePath,
Timeout: time.Second,
AllowBootstrap: true,
SnapshotBase: "deepseek-pricing",
}, time.Date(2026, 5, 27, 22, 1, 0, 0, time.FixedZone("CST", 8*3600)))
if err != nil {
t.Fatalf("初始化 baseline 失败: %v", err)
}
driftFixture := filepath.Join(tempDir, "pricing-drift.html")
if err := os.WriteFile(driftFixture, []byte(`<html><head><title>DeepSeek Pricing</title><meta name="description" content="Updated DeepSeek pricing"><meta name="commit-id" content="def456"><meta property="og:url" content="https://platform.deepseek.com/pricing"></head><body>pricing update</body></html>`), 0o644); err != nil {
t.Fatalf("写入 drift fixture 失败: %v", err)
}
result, err := runDeepSeekPricingSignatureGuard(deepseekPricingSignatureGuardConfig{
SourceKey: "deepseek_pricing_signature",
URL: defaultDeepSeekPricingFetchURL,
Fixture: driftFixture,
SnapshotDir: tempDir,
BaselinePath: baselinePath,
Timeout: time.Second,
AllowBootstrap: false,
SnapshotBase: "deepseek-pricing",
}, time.Date(2026, 5, 27, 22, 2, 0, 0, time.FixedZone("CST", 8*3600)))
if err == nil {
t.Fatal("期望结构漂移时报错")
}
if !result.DriftDetected {
t.Fatal("期望 driftDetected=true")
}
}
func TestFormatDeepSeekPricingSignatureGuardSummary(t *testing.T) {
result := deepseekPricingSignatureGuardResult{
SnapshotPath: "/tmp/deepseek-pricing.html",
SignaturePath: "/tmp/deepseek-pricing.signature.json",
BaselinePath: "/tmp/baseline.signature.json",
BaselineInitialized: true,
CurrentSignature: deepseekPricingStructureSignature{
StructureSHA256: "abc123",
},
}
summary := formatDeepSeekPricingSignatureGuardSummary("deepseek_pricing_signature", result)
for _, want := range []string{"source=deepseek_pricing_signature", "baseline_initialized=true", "structure_sha256=abc123"} {
if !strings.Contains(summary, want) {
t.Fatalf("summary 缺少 %q实际: %q", want, summary)
}
}
}