//go:build llm_script package main import ( "bytes" "os" "path/filepath" "strings" "testing" ) func TestParseBedrockPricingCatalogBuildsRecords(t *testing.T) { raw, err := os.ReadFile(filepath.Join("testdata", "bedrock_pricing_sample.html")) if err != nil { t.Fatalf("读取 fixture 失败: %v", err) } records, err := parseBedrockPricingCatalog(string(raw)) if err != nil { t.Fatalf("parseBedrockPricingCatalog 返回错误: %v", err) } if len(records) != 4 { t.Fatalf("期望 4 条 Bedrock 价格记录,实际 %d", len(records)) } if records[0].ProviderName != "Amazon" { t.Fatalf("Nova provider 归一化错误: %q", records[0].ProviderName) } if records[1].OutputPrice != 0.4 { t.Fatalf("Nova Lite 输出价错误: %v", records[1].OutputPrice) } if records[2].Region != "Europe (Frankfurt) and Asia Pacific (Jakarta)" { t.Fatalf("Qwen region 错误: %q", records[2].Region) } } func TestRunBedrockPricingImportDryRunPrintsSummary(t *testing.T) { var out bytes.Buffer err := runBedrockPricingImport(bedrockPricingImportConfig{ URL: defaultBedrockPricingURL, Fixture: filepath.Join("testdata", "bedrock_pricing_sample.html"), DryRun: true, }, nil, &out) if err != nil { t.Fatalf("runBedrockPricingImport 返回错误: %v", err) } output := out.String() for _, want := range []string{ "source=bedrock-pricing-import", "models=4", "operator=Amazon Bedrock", "dry_run=true", } { if !strings.Contains(output, want) { t.Fatalf("输出缺少 %q,实际: %q", want, output) } } } func TestParseBedrockPricingCatalogPrefersFirstTierForSameModelAndRegion(t *testing.T) { raw := `
Regions: US East (N. Virginia)
| Anthropic models | Price per 1M input tokens | Price per 1M output tokens |
| Claude Sonnet 4.5 | $3.00 | $15.00 |
| Anthropic models | Price per 1M input tokens | Price per 1M output tokens |
| Claude Sonnet 4.5 | $6.00 | $30.00 |
Regions: Europe (Frankfurt) and Asia Pacific (Jakarta)
Qwen models Price per 1M input tokens Price per 1M output tokens Qwen3 Coder Next $ 0.60 $ 1.44Region: Asia Pacific (Sydney)
Qwen models Price per 1M input tokens Price per 1M output tokens Qwen3 Next 80B A3B $ 0.1545 $ 1.2360 `) records := parseBedrockPricingTextFallback(raw) if len(records) != 2 { t.Fatalf("期望 fallback 解析 2 条记录,实际 %d", len(records)) } if records[0].Region != "Europe (Frankfurt) and Asia Pacific (Jakarta)" { t.Fatalf("fallback region 错误: %q", records[0].Region) } if records[1].InputPrice != 0.1545 || records[1].OutputPrice != 1.2360 { t.Fatalf("fallback 价格错误: %+v", records[1]) } }