(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestProcessInputValidation(t *testing.T) { |
| 12 | t.Parallel() |
| 13 | |
| 14 | t.Run("Should reject ambiguous agh-prefixed source filenames", func(t *testing.T) { |
| 15 | t.Parallel() |
| 16 | |
| 17 | srcDir := t.TempDir() |
| 18 | dstDir := filepath.Join(t.TempDir(), "output") |
| 19 | sourcePath := filepath.Join(srcDir, "aghost.md") |
| 20 | if err := os.WriteFile(sourcePath, []byte("## aghost\n\nBad input\n"), 0o600); err != nil { |
| 21 | t.Fatalf("write ambiguous source file: %v", err) |
| 22 | } |
| 23 | |
| 24 | err := Process(context.Background(), srcDir, dstDir) |
| 25 | if err == nil || !strings.Contains(err.Error(), "must be 'agh.md' or start with 'agh_'") { |
| 26 | t.Fatalf("Process() error = %v, want ambiguous source filename rejection", err) |
| 27 | } |
| 28 | if _, statErr := os.Stat(filepath.Join(dstDir, "agh.mdx")); !os.IsNotExist(statErr) { |
| 29 | t.Fatalf("Process() wrote root output for rejected filename, stat err = %v", statErr) |
| 30 | } |
| 31 | }) |
| 32 | |
| 33 | t.Run("Should preserve existing generated output when source validation fails", func(t *testing.T) { |
| 34 | t.Parallel() |
| 35 | |
| 36 | srcDir := t.TempDir() |
| 37 | dstDir := t.TempDir() |
| 38 | if err := os.WriteFile( |
| 39 | filepath.Join(srcDir, "aghost.md"), |
| 40 | []byte("## aghost\n\nBad input\n"), |
| 41 | 0o600, |
| 42 | ); err != nil { |
| 43 | t.Fatalf("write ambiguous source file: %v", err) |
| 44 | } |
| 45 | seeded := map[string]string{ |
| 46 | "index.mdx": "editorial index", |
| 47 | "meta.json": "{\"title\":\"CLI Reference\"}", |
| 48 | "agh.mdx": "previous root", |
| 49 | "agent/index.mdx": "previous agent index", |
| 50 | "agent/list.mdx": "previous agent list", |
| 51 | "agent/meta.json": "{\"title\":\"Agent\"}", |
| 52 | } |
| 53 | for rel, body := range seeded { |
| 54 | path := filepath.Join(dstDir, rel) |
| 55 | if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { |
| 56 | t.Fatalf("mkdir %s: %v", rel, err) |
| 57 | } |
| 58 | if err := os.WriteFile(path, []byte(body), 0o600); err != nil { |
| 59 | t.Fatalf("write %s: %v", rel, err) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | err := Process(context.Background(), srcDir, dstDir) |
| 64 | if err == nil || !strings.Contains(err.Error(), "must be 'agh.md' or start with 'agh_'") { |
| 65 | t.Fatalf("Process() error = %v, want ambiguous source filename rejection", err) |
| 66 | } |
| 67 | for rel, want := range seeded { |
| 68 | got, readErr := os.ReadFile(filepath.Join(dstDir, rel)) |
nothing calls this directly
no test coverage detected