package cli import ( "errors" "fmt" "io/fs" "os" "path/filepath" "strings" "testing" ) func TestOversizedNPCRegistryFailsBeforeModelWorkAndPublication(t *testing.T) { root := t.TempDir() npcPath := filepath.Join(root, "npcs.json") if err := os.WriteFile(npcPath, []byte(strings.Repeat("x", 1048577)), 0600); err != nil { t.Fatal(err) } outputRoot, cacheRoot := filepath.Join(root, "output"), filepath.Join(root, "cache") content := fmt.Sprintf(`version: 6 output: {directory: %q} cache_directory: %q pipelines: dnd-session: input: {module: seriatim} artifacts: spells: extract: module: dnd/spells references: npc_registry: {path: %q} normalize: {module: dnd/spells} `, outputRoot, cacheRoot, npcPath) configPath := writeProductionContractConfig(t, content) client := &productionFakeLLMClient{} var stdout, stderr strings.Builder code := RunWithOptions([]string{"run", "dnd-session", "--config", configPath, "--input-file", repositoryPath("examples", "dnd-minimal", "transcript.json")}, &stdout, &stderr, productionRunOptions(t, client)) for _, fragment := range []string{`pipeline "dnd-session"`, `reference slot "npc_registry"`, "1048577 bytes", "limit 1048576"} { if code == 0 || !strings.Contains(stderr.String(), fragment) { t.Fatalf("status=%d stderr=%q, want %q", code, stderr.String(), fragment) } } if len(client.requestsSnapshot()) != 0 || stdout.Len() != 0 { t.Fatal("invalid reference reached provider or completion reporting") } for _, path := range []string{outputRoot, cacheRoot} { if _, err := os.Stat(path); !errors.Is(err, fs.ErrNotExist) { t.Fatalf("state allocated before invalid reference: %s: %v", path, err) } } }