package cli import ( "context" "errors" "fmt" "testing/fstest" "gitea.maximumdirect.net/eric/notarius/internal/core/config" "gitea.maximumdirect.net/eric/promptkit" ) const profileCheckPromptID = "notarius.profile.check" var profileCheckPromptFS = fstest.MapFS{ "prompts/profile-check.yaml": &fstest.MapFile{Data: []byte(`id: notarius.profile.check version: "1.0.0" default_profile: mistral-small-3 inputs: - name: transcript required: true messages: - role: user content: "{{input \"transcript\"}}" output: format: text validation_mode: none repair_attempts: 0 `)}, } func validateExplicitPromptKitProfiles(ctx context.Context, cfg config.Config, profileIDs []string) error { if len(profileIDs) == 0 { return nil } engine, err := newProfileValidationEngine(cfg) if err != nil { return fmt.Errorf("load PromptKit profiles: %w", err) } for _, profileID := range profileIDs { if _, err := engine.Prepare(ctx, promptkit.RunRequest{ PromptID: profileCheckPromptID, ProfileID: profileID, Inputs: map[string]promptkit.ArtifactRef{ "transcript": promptkit.Inline("profile check"), }, }); err != nil { if errors.Is(err, promptkit.ErrProfileNotFound) { return fmt.Errorf("PromptKit profile %q is not configured", profileID) } return fmt.Errorf("validate PromptKit profile %q: %w", profileID, err) } } return nil } func newProfileValidationEngine(cfg config.Config) (*promptkit.Engine, error) { opts := []promptkit.Option{ promptkit.WithPromptFS(profileCheckPromptFS, "prompts"), } if cfg.PromptKit.ProfileFile != "" { opts = append(opts, promptkit.WithProfileFile(cfg.PromptKit.ProfileFile)) } return promptkit.NewEngine(promptkit.Config{ PromptDir: "unused", ProfileDir: cfg.PromptKit.ProfileDir, }, opts...) }