feat(imports): add real pricing and subscription collectors

Add plan catalog and subscription schema support, seed baselines, and real importers for core domestic subscriptions plus stable official pricing sources.

This commit also hardens the shared fetch layers so the importers can support live collection and database writes instead of relying on manual placeholders alone.
This commit is contained in:
phamnazage-jpg
2026-05-15 22:32:57 +08:00
parent dd58c18fe3
commit 958245537a
91 changed files with 10474 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
//go:build llm_script
package main
import (
"net/http"
"net/http/httptest"
"testing"
"time"
)
type assertiveError string
func (e assertiveError) Error() string {
return string(e)
}
func TestFetchSubscriptionPageRetriesForbiddenThenSucceeds(t *testing.T) {
attempts := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
attempts++
if attempts == 1 {
w.WriteHeader(http.StatusForbidden)
_, _ = w.Write([]byte("blocked"))
return
}
_, _ = w.Write([]byte("<html><body>套餐价格</body></html>"))
}))
defer server.Close()
client := &http.Client{Timeout: 2 * time.Second}
body, err := fetchSubscriptionPage(server.URL, "", client)
if err != nil {
t.Fatalf("fetchSubscriptionPage 返回错误: %v", err)
}
if body != "套餐价格" {
t.Fatalf("返回体归一化错误: %q", body)
}
if attempts != 2 {
t.Fatalf("期望重试 1 次后成功,实际请求 %d 次", attempts)
}
}
func TestIsRetriableSubscriptionFetchErrorRecognizesForbidden(t *testing.T) {
if !isRetriableSubscriptionFetchError(assertiveError("unexpected status 403")) {
t.Fatalf("403 应被视作可重试错误")
}
}