package promptdef import ( "context" "errors" "os" "path/filepath" "testing" "gitea.maximumdirect.net/eric/scriptorium/internal/domain" ) func TestFilesystemRepository_GetPromptDefinition(t *testing.T) { tmpDir, err := os.MkdirTemp("", "promptdef_test") if err != nil { t.Fatal(err) } defer os.RemoveAll(tmpDir) testDataDir := "testdata" files, err := os.ReadDir(testDataDir) if err != nil { t.Fatalf("failed to read testdata: %v", err) } for _, f := range files { src := filepath.Join(testDataDir, f.Name()) dst := filepath.Join(tmpDir, f.Name()) data, err := os.ReadFile(src) if err != nil { t.Fatal(err) } if err := os.WriteFile(dst, data, 0644); err != nil { t.Fatal(err) } } repo := NewFilesystemRepository(tmpDir) ctx := context.Background() t.Run("valid prompt definition", func(t *testing.T) { p, err := repo.GetPromptDefinition(ctx, "test-profile", "") if err != nil { t.Fatalf("expected no error, got %v", err) } if p == nil || p.ID != "test-profile" { t.Errorf("expected prompt definition test-profile, got %v", p) } if p.Version != "1.0.0" { t.Fatalf("expected version 1.0.0, got %q", p.Version) } if len(p.Inputs) != 2 || p.Inputs[0].Name != "transcript" || p.Inputs[1].Name != "glossary" { t.Fatalf("unexpected inputs: %#v", p.Inputs) } if len(p.Templates) != 2 { t.Fatalf("expected 2 templates, got %d", len(p.Templates)) } if p.Templates[0].Role != "system" || p.Templates[1].Role != "user" { t.Fatalf("unexpected template roles: %#v", p.Templates) } if p.OutputFormat != domain.FormatMarkdown { t.Fatalf("expected output format markdown, got %q", p.OutputFormat) } if p.Validation.ValidationMode != domain.ValidationBasic { t.Fatalf("expected validation mode basic, got %q", p.Validation.ValidationMode) } if p.DefaultProfile != "test-exec" { t.Fatalf("expected default profile test-exec, got %q", p.DefaultProfile) } }) t.Run("invalid YAML", func(t *testing.T) { _, err := repo.GetPromptDefinition(ctx, "invalid_yaml", "") if !errors.Is(err, ErrInvalidYAML) { t.Errorf("expected ErrInvalidYAML, got %v", err) } }) t.Run("missing ID", func(t *testing.T) { _, err := repo.GetPromptDefinition(ctx, "missing-id", "") if !errors.Is(err, ErrPromptDefinitionNotFound) { t.Errorf("expected ErrPromptDefinitionNotFound for profile with missing ID, got %v", err) } }) t.Run("no templates", func(t *testing.T) { _, err := repo.GetPromptDefinition(ctx, "no-templates", "") if !errors.Is(err, ErrInvalidPromptDefinition) { t.Errorf("expected ErrInvalidPromptDefinition for profile with no templates, got %v", err) } }) t.Run("json schema mode missing schema path", func(t *testing.T) { _, err := repo.GetPromptDefinition(ctx, "json-schema-missing-path", "") if !errors.Is(err, ErrInvalidPromptDefinition) { t.Errorf("expected ErrInvalidPromptDefinition for json_schema profile without schema_path, got %v", err) } }) t.Run("prompt definition not found", func(t *testing.T) { _, err := repo.GetPromptDefinition(ctx, "unknown", "") if !errors.Is(err, ErrPromptDefinitionNotFound) { t.Errorf("expected ErrPromptDefinitionNotFound, got %v", err) } }) }