2026-07-21 03:12:03 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
2026-07-25 15:48:48 +00:00
|
|
|
"fmt"
|
2026-07-21 03:12:03 +00:00
|
|
|
"io/fs"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-22 05:01:09 +00:00
|
|
|
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 {
|
2026-07-21 03:12:03 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-11-22 05:01:09 +00:00
|
|
|
outputRoot, cacheRoot := filepath.Join(root, "output"), filepath.Join(root, "cache")
|
|
|
|
|
content := fmt.Sprintf(`version: 6
|
|
|
|
|
output: {directory: %q}
|
|
|
|
|
cache_directory: %q
|
2026-07-25 15:48:48 +00:00
|
|
|
pipelines:
|
|
|
|
|
dnd-session:
|
2026-11-22 05:01:09 +00:00
|
|
|
input: {module: seriatim}
|
2026-07-25 15:48:48 +00:00
|
|
|
artifacts:
|
|
|
|
|
spells:
|
|
|
|
|
extract:
|
|
|
|
|
module: dnd/spells
|
|
|
|
|
references:
|
2026-11-22 05:01:09 +00:00
|
|
|
npc_registry: {path: %q}
|
|
|
|
|
normalize: {module: dnd/spells}
|
|
|
|
|
`, outputRoot, cacheRoot, npcPath)
|
|
|
|
|
configPath := writeProductionContractConfig(t, content)
|
|
|
|
|
client := &productionFakeLLMClient{}
|
2026-07-21 03:12:03 +00:00
|
|
|
var stdout, stderr strings.Builder
|
2026-11-22 05:45:31 +00:00
|
|
|
code := RunWithOptions([]string{"run", "dnd-session", "--config", configPath, "--input-file", repositoryPath("examples", "dnd-minimal", "transcript.json")}, &stdout, &stderr, productionRunOptions(t, client))
|
2026-08-05 18:38:22 +00:00
|
|
|
for _, fragment := range []string{`pipeline "dnd-session"`, `reference slot "npc_registry"`, "1048577 bytes", "limit 1048576"} {
|
2026-07-21 03:12:03 +00:00
|
|
|
if code == 0 || !strings.Contains(stderr.String(), fragment) {
|
2026-11-22 05:01:09 +00:00
|
|
|
t.Fatalf("status=%d stderr=%q, want %q", code, stderr.String(), fragment)
|
2026-07-21 03:12:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-11-22 05:01:09 +00:00
|
|
|
if len(client.requestsSnapshot()) != 0 || stdout.Len() != 0 {
|
|
|
|
|
t.Fatal("invalid reference reached provider or completion reporting")
|
2026-07-21 03:12:03 +00:00
|
|
|
}
|
2026-11-22 05:01:09 +00:00
|
|
|
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)
|
|
|
|
|
}
|
2026-07-21 03:12:03 +00:00
|
|
|
}
|
|
|
|
|
}
|