package contracts_test import ( "errors" "os" "path/filepath" "strings" "testing" "git.ipao.vip/rogee/go-sip/contracts" ) func TestOneCurrentHumanContractAndArchivedSources(t *testing.T) { entries, err := os.ReadDir(filepath.Join("..", "docs", "thirds")) if err != nil { t.Fatal(err) } if len(entries) != 1 || entries[0].Name() != "saas-dispatcher.md" { t.Fatalf("expected one current human-readable contract, got %v", entries) } for _, path := range []string{filepath.Join("..", "docs", "contracts"), filepath.Join("..", "docs", "plan-saas-dispatcher.md")} { if _, err := os.Stat(path); !errors.Is(err, os.ErrNotExist) { t.Fatalf("redundant current document %s remains or cannot be checked: %v", path, err) } } for _, name := range []string{"v0.4.md", "第三方对接事件与请求消费顺序_v0.1.md", "v0.5-proposal.md", "plan-saas-dispatcher-v05-v0.1.md"} { if _, err := os.Stat(filepath.Join("..", "docs", "archive", "sources", name)); err != nil { t.Fatalf("historical source %s missing from archive: %v", name, err) } } if _, err := contracts.Files.ReadFile("upstream/v1/mq.schema.json"); err == nil { t.Fatal("retired upstream v1 contract still embedded with current runtime contracts") } } func TestCurrentContractDirectoryExcludesHistoricalGenerations(t *testing.T) { entries, err := os.ReadDir("local") if err != nil { t.Fatal(err) } for _, entry := range entries { if entry.IsDir() && strings.HasPrefix(entry.Name(), "v0.") { t.Errorf("historical contract directory %q remains in the current contract root", entry.Name()) } } }