Expose native configuration inspection scopes
This commit is contained in:
@@ -3,7 +3,6 @@ package app
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@@ -253,19 +252,8 @@ func TestAssembledSplitBundleCommandsUseOneEffectiveFamilyConfiguration(t *testi
|
||||
t.Fatalf("example workspace stat = %v, want absent", err)
|
||||
}
|
||||
|
||||
var validated bytes.Buffer
|
||||
if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &validated); err != nil {
|
||||
t.Fatalf("validate production base: %v", err)
|
||||
}
|
||||
if !strings.Contains(validated.String(), "overlay=none") {
|
||||
t.Fatalf("validate output = %q, want production base", validated.String())
|
||||
}
|
||||
for _, command := range []func(context.Context, []string, io.Writer) error{ConfigShow, ConfigSources} {
|
||||
if err := command(context.Background(), []string{
|
||||
"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing",
|
||||
}, io.Discard); err != nil {
|
||||
t.Fatalf("testing inspection command %T: %v", command, err)
|
||||
}
|
||||
for _, operation := range []string{"validate", "show", "sources"} {
|
||||
nativeInspectionForTest(t, []string{"config", operation, "--config", pipelinePath, "--overlay", "testing"})
|
||||
}
|
||||
var diff bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{
|
||||
|
||||
@@ -23,7 +23,9 @@ import (
|
||||
func TestSelectedPartyCatalogDrivesBoundedAnalysis(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
pipelinePath := filepath.Join(dir, "pipeline.yml")
|
||||
mustWriteTestFile(t, pipelinePath, `workspace:
|
||||
mustWriteTestFile(t, pipelinePath, `whisperx:
|
||||
transcribe_url: https://transcription.example.test/transcribe
|
||||
workspace:
|
||||
root: `+filepath.Join(dir, "work")+`
|
||||
scriptorium:
|
||||
artifact_families:
|
||||
|
||||
@@ -16,6 +16,7 @@ func NewApplication() (*commandkit.App, error) {
|
||||
func newApplication(deps commandDependencies, executor pipelineExecutor) (*commandkit.App, error) {
|
||||
return commandkit.New(
|
||||
commandkit.Identity{Name: "narratio", Version: buildinfo.Version},
|
||||
configurationCommand(deps),
|
||||
commandkit.Group("artifacts", "Inspect and regenerate configured artifacts."),
|
||||
commandkit.Group("session", "Manage and inspect sessions."),
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -100,156 +99,6 @@ func TestConfigArtifactsReportsOverlayFamilyContributors(t *testing.T) {
|
||||
t.Fatalf("generated family definitions = %#v", got)
|
||||
}
|
||||
|
||||
var sources bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), args, &sources); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := "scriptorium.artifacts.character_note_arannis.prompt_id\tfamily\t" + overlayPath
|
||||
if !strings.Contains(sources.String(), want) {
|
||||
t.Fatalf("sources output missing overlay family contributor %q:\n%s", want, sources.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigInspectionReportsInheritedCompositeSources(t *testing.T) {
|
||||
t.Setenv("NARRATIO_CONFIG_INSPECTION_KEY", "synthetic-inspection-secret")
|
||||
pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
|
||||
dir := filepath.Dir(pipelinePath)
|
||||
parentPath := filepath.Join(dir, "families", "parent.yml")
|
||||
childPath := filepath.Join(dir, "families", "child.yml")
|
||||
overlayPath := filepath.Join(dir, "overlays", "testing.yml")
|
||||
mustWriteTestFile(t, pipelinePath, `config:
|
||||
imports:
|
||||
- path: families/parent.yml
|
||||
- path: families/child.yml
|
||||
workspace:
|
||||
root: `+filepath.Join(dir, "workspace")+`
|
||||
campaigns:
|
||||
root: `+filepath.Join(dir, "campaigns")+`
|
||||
whisperx:
|
||||
transcribe_url: https://transcription.example.com/transcribe
|
||||
audita:
|
||||
credentials: [NARRATIO_CONFIG_INSPECTION_KEY]
|
||||
scriptorium:
|
||||
extends: audita
|
||||
`)
|
||||
mustWriteTestFile(t, parentPath, `scriptorium:
|
||||
artifact_families:
|
||||
character_meta:
|
||||
enabled: false
|
||||
for_each: party.characters
|
||||
prompt_id: dnd.character_meta
|
||||
profile_id: production
|
||||
output_path_pattern: artifacts/characters/{character_id}/meta.md
|
||||
artifacts:
|
||||
notes:
|
||||
enabled: false
|
||||
prompt_id: dnd.notes
|
||||
`)
|
||||
mustWriteTestFile(t, childPath, `scriptorium:
|
||||
artifact_families:
|
||||
character_note:
|
||||
extends: character_meta
|
||||
profile_id: testing
|
||||
output_path_pattern: artifacts/characters/{character_id}/note.md
|
||||
artifacts:
|
||||
notes:
|
||||
output_path: artifacts/notes.md
|
||||
`)
|
||||
mustWriteTestFile(t, overlayPath, `scriptorium:
|
||||
artifact_families:
|
||||
character_note:
|
||||
prompt_id: dnd.character_note.testing
|
||||
artifacts:
|
||||
notes:
|
||||
output_path: artifacts/notes-testing.md
|
||||
`)
|
||||
expandedOverlayPath := filepath.Join(dir, "overlays", "expanded.yml")
|
||||
mustWriteTestFile(t, expandedOverlayPath, `scriptorium:
|
||||
extends: null
|
||||
credentials: [NARRATIO_CONFIG_INSPECTION_KEY]
|
||||
artifact_families:
|
||||
character_note:
|
||||
enabled: false
|
||||
for_each: party.characters
|
||||
prompt_id: dnd.character_note.testing
|
||||
profile_id: testing
|
||||
output_path_pattern: artifacts/characters/{character_id}/note.md
|
||||
artifacts:
|
||||
notes:
|
||||
output_path: artifacts/notes-testing.md
|
||||
`)
|
||||
args := []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing"}
|
||||
if err := ConfigValidate(context.Background(), args, io.Discard); err != nil {
|
||||
t.Fatalf("ConfigValidate() error = %v", err)
|
||||
}
|
||||
var effective bytes.Buffer
|
||||
if err := ConfigShow(context.Background(), args, &effective); err != nil {
|
||||
t.Fatalf("ConfigShow() error = %v", err)
|
||||
}
|
||||
for _, want := range []string{"NARRATIO_CONFIG_INSPECTION_KEY", "character_note_arannis:", "dnd.character_note.testing", "artifacts/characters/arannis/note.md"} {
|
||||
if !strings.Contains(effective.String(), want) {
|
||||
t.Errorf("effective show omitted %q:\n%s", want, effective.String())
|
||||
}
|
||||
}
|
||||
if strings.Contains(effective.String(), "synthetic-inspection-secret") {
|
||||
t.Fatal("effective show exposed a credential value")
|
||||
}
|
||||
|
||||
var catalog bytes.Buffer
|
||||
if err := ConfigArtifacts(context.Background(), args, &catalog); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
records := catalogRecordsByKey(t, catalog.String())
|
||||
notes := records["notes"]
|
||||
if strings.Contains(catalog.String(), "synthetic-inspection-secret") {
|
||||
t.Fatal("artifact catalog exposed a credential value")
|
||||
}
|
||||
if notes[4] != "artifacts/notes-testing.md" {
|
||||
t.Fatalf("composed artifact output = %#v", notes)
|
||||
}
|
||||
for _, contributor := range []string{parentPath, childPath, overlayPath} {
|
||||
if !strings.Contains(notes[2], contributor) {
|
||||
t.Errorf("composed artifact definitions %q omit %q", notes[2], contributor)
|
||||
}
|
||||
}
|
||||
|
||||
note := records["character_note_arannis"]
|
||||
if note[4] != "artifacts/characters/arannis/note.md" || note[6] != "character_note" || note[7] != "arannis" {
|
||||
t.Fatalf("inherited family catalog identity and output = %#v", note)
|
||||
}
|
||||
for _, contributor := range []string{parentPath, childPath, overlayPath} {
|
||||
if !strings.Contains(note[2], contributor) || !strings.Contains(note[8], contributor) {
|
||||
t.Errorf("family provenance = definitions %q, family sources %q; want %q", note[2], note[8], contributor)
|
||||
}
|
||||
}
|
||||
|
||||
var sources bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), args, &sources); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"scriptorium.artifacts.notes.output_path\toverlay\t" + overlayPath,
|
||||
"scriptorium.artifacts.character_note_arannis.output_path\tfamily\t" + childPath,
|
||||
"scriptorium.artifacts.character_note_arannis.prompt_id\tfamily\t" + overlayPath,
|
||||
"scriptorium.credentials\troot\t" + pipelinePath,
|
||||
} {
|
||||
if !strings.Contains(sources.String(), want) {
|
||||
t.Errorf("effective source output missing %q:\n%s", want, sources.String())
|
||||
}
|
||||
}
|
||||
if strings.Contains(sources.String(), "synthetic-inspection-secret") {
|
||||
t.Fatal("source inspection exposed a credential value")
|
||||
}
|
||||
var diff bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{"testing", "expanded", "--config", pipelinePath, "--campaign-file", campaignPath}, &diff); err != nil {
|
||||
t.Fatalf("ConfigDiff() error = %v", err)
|
||||
}
|
||||
if diff.String() != "no differences\n" {
|
||||
t.Fatalf("equivalent inherited/expanded overlays diff = %q", diff.String())
|
||||
}
|
||||
if strings.Contains(diff.String(), "synthetic-inspection-secret") {
|
||||
t.Fatal("configuration diff exposed a credential value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigArtifactsReportsBaseAndOverlayContributors(t *testing.T) {
|
||||
|
||||
@@ -30,125 +30,6 @@ type inspectionConfig struct {
|
||||
ArtifactCatalog *config.ArtifactCatalog
|
||||
}
|
||||
|
||||
// Config dispatches read-only pipeline configuration commands.
|
||||
func Config(ctx context.Context, args []string, out io.Writer) error {
|
||||
return configWithDependencies(ctx, args, out, commandDependencies{})
|
||||
}
|
||||
|
||||
func configWithDependencies(ctx context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
||||
deps = normalizeCommandDependencies(deps)
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("config: expected subcommand: validate|show|sources|artifacts|diff")
|
||||
}
|
||||
if args[0] == "--help" || args[0] == "-h" {
|
||||
writeConfigCommandUsage(out)
|
||||
return nil
|
||||
}
|
||||
switch args[0] {
|
||||
case "validate":
|
||||
return configValidateWithDependencies(ctx, args[1:], out, deps)
|
||||
case "show":
|
||||
return configShowWithDependencies(ctx, args[1:], out, deps)
|
||||
case "sources":
|
||||
return configSourcesWithDependencies(ctx, args[1:], out, deps)
|
||||
case "artifacts":
|
||||
return configArtifactsWithDependencies(ctx, args[1:], out, deps)
|
||||
case "diff":
|
||||
return configDiffWithDependencies(ctx, args[1:], out, deps)
|
||||
default:
|
||||
return fmt.Errorf("config: unknown subcommand %q", args[0])
|
||||
}
|
||||
}
|
||||
|
||||
// ConfigValidate validates one fully resolved effective pipeline without
|
||||
// loading session state or constructing runtime collaborators.
|
||||
func ConfigValidate(ctx context.Context, args []string, out io.Writer) error {
|
||||
return configValidateWithDependencies(ctx, args, out, commandDependencies{})
|
||||
}
|
||||
|
||||
func configValidateWithDependencies(_ context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
||||
flags, err := parseInspectionFlags("config validate", args, out)
|
||||
if err != nil {
|
||||
if errors.Is(err, flag.ErrHelp) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
resolved, err := resolveInspectionConfigWithDependencies(flags, deps)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config validate: %w", err)
|
||||
}
|
||||
_, err = fmt.Fprintf(out, "Configuration valid: root=%s; overlay=%s; digest=%s\n",
|
||||
inspectionRootPath(resolved), inspectionOverlay(resolved.Pipeline), config.EffectivePipelineDigest(resolved.Pipeline))
|
||||
return err
|
||||
}
|
||||
|
||||
// ConfigShow validates and renders one fully resolved effective pipeline
|
||||
// without loading session state or constructing runtime collaborators.
|
||||
func ConfigShow(ctx context.Context, args []string, out io.Writer) error {
|
||||
return configShowWithDependencies(ctx, args, out, commandDependencies{})
|
||||
}
|
||||
|
||||
func configShowWithDependencies(_ context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
||||
flags, err := parseInspectionFlags("config show", args, out)
|
||||
if err != nil {
|
||||
if errors.Is(err, flag.ErrHelp) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
resolved, err := resolveInspectionConfigWithDependencies(flags, deps)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config show: %w", err)
|
||||
}
|
||||
data, err := config.MarshalEffectivePipeline(resolved.Pipeline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config show: %w", err)
|
||||
}
|
||||
_, err = out.Write(data)
|
||||
return err
|
||||
}
|
||||
|
||||
// ConfigSources validates and reports deterministic effective configuration
|
||||
// ownership without loading session state or runtime collaborators.
|
||||
func ConfigSources(ctx context.Context, args []string, out io.Writer) error {
|
||||
return configSourcesWithDependencies(ctx, args, out, commandDependencies{})
|
||||
}
|
||||
|
||||
func configSourcesWithDependencies(_ context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
||||
flags, err := parseInspectionFlags("config sources", args, out)
|
||||
if err != nil {
|
||||
if errors.Is(err, flag.ErrHelp) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
resolved, err := resolveInspectionConfigWithDependencies(flags, deps)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config sources: %w", err)
|
||||
}
|
||||
records, err := config.EffectivePipelineSources(resolved.Pipeline, resolved.Party)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config sources: %w", err)
|
||||
}
|
||||
records = append(records, config.EffectiveCampaignSources(resolved.CampaignPath, resolved.Campaign, resolved.Party)...)
|
||||
sortInspectionSourceRecords(records)
|
||||
if err := writeInspectionSourceHeader(out, resolved); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, record := range records {
|
||||
if _, err := fmt.Fprintf(out, "%s\t%s\t%s\n", record.Path, record.Role, record.Source); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, selection := range config.EffectiveEmptyImports(resolved.Pipeline, resolved.Campaign) {
|
||||
if _, err := fmt.Fprintf(out, "empty_import\t%s\t%s\t%s:%d:%d\n", selection.Path, selection.Selector, selection.Source, selection.Line, selection.Column); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfigArtifacts validates and reports the effective concrete artifact catalog
|
||||
// without loading session state or runtime collaborators.
|
||||
func ConfigArtifacts(ctx context.Context, args []string, out io.Writer) error {
|
||||
@@ -312,82 +193,3 @@ func validateInspectionCampaign(path string, campaign *config.CampaignConfig) er
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func inspectionRootPath(resolved *inspectionConfig) string {
|
||||
if resolved == nil {
|
||||
return ""
|
||||
}
|
||||
if root := config.EffectivePipelineRootPath(resolved.Pipeline); root != "" {
|
||||
return root
|
||||
}
|
||||
return resolved.PipelinePath
|
||||
}
|
||||
|
||||
func inspectionOverlay(pipeline *config.PipelineConfig) string {
|
||||
if overlay, ok := config.SelectedPipelineOverlay(pipeline); ok {
|
||||
return overlay.Name
|
||||
}
|
||||
return "none"
|
||||
}
|
||||
|
||||
func writeConfigCommandUsage(out io.Writer) {
|
||||
fmt.Fprintln(out, "Usage: narratio config <validate|show|sources|artifacts|diff>")
|
||||
fmt.Fprintln(out)
|
||||
fmt.Fprintln(out, "Use config validate to check an effective pipeline, config show to print normalized YAML, config sources to report ownership, config artifacts to list concrete artifacts, or config diff to compare two overlays.")
|
||||
}
|
||||
|
||||
func writeInspectionSourceHeader(out io.Writer, resolved *inspectionConfig) error {
|
||||
if _, err := fmt.Fprintf(out, "root: %s\n", inspectionRootPath(resolved)); err != nil {
|
||||
return err
|
||||
}
|
||||
imports := config.EffectivePipelineImports(resolved.Pipeline)
|
||||
if len(imports) == 0 {
|
||||
if _, err := fmt.Fprintln(out, "imports: none"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, imported := range imports {
|
||||
if _, err := fmt.Fprintf(out, "import: %s\n", config.NormalizedConfigurationPath(imported)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if overlay, ok := config.SelectedPipelineOverlay(resolved.Pipeline); ok {
|
||||
if _, err := fmt.Fprintf(out, "overlay: name=%s selection=%s path=%s\n", overlay.Name, overlay.Source, config.NormalizedConfigurationPath(overlay.OverlayPath)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if _, err := fmt.Fprintln(out, "overlay: none"); err != nil {
|
||||
return err
|
||||
}
|
||||
if resolved.Campaign == nil {
|
||||
if _, err := fmt.Fprintln(out, "campaign: none"); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprintln(out, "party: none"); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := fmt.Fprintf(out, "campaign: id=%s source=%s\n", config.CampaignID(resolved.Campaign), config.NormalizedConfigurationPath(resolved.CampaignPath)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, "party: source=%s\n", config.NormalizedConfigurationPath(resolved.Party.Source.Path)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, "digest: %s\n", config.EffectivePipelineDigest(resolved.Pipeline)); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := fmt.Fprintln(out, "path\trole\tsource")
|
||||
return err
|
||||
}
|
||||
|
||||
func sortInspectionSourceRecords(records []config.EffectivePipelineSourceRecord) {
|
||||
sort.Slice(records, func(left, right int) bool {
|
||||
if records[left].Path != records[right].Path {
|
||||
return records[left].Path < records[right].Path
|
||||
}
|
||||
if records[left].Role != records[right].Role {
|
||||
return records[left].Role < records[right].Role
|
||||
}
|
||||
return records[left].Source < records[right].Source
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -15,47 +13,12 @@ import (
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestConfigCommandHelpAndDispatch(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
args []string
|
||||
want string
|
||||
code int
|
||||
}{
|
||||
{name: "top level help", args: []string{"config", "--help"}, want: "Usage: narratio config <validate|show|sources|artifacts|diff>"},
|
||||
{name: "validate help", args: []string{"config", "validate", "--help"}, want: "Usage: narratio config validate"},
|
||||
{name: "show help", args: []string{"config", "show", "--help"}, want: "Usage: narratio config show"},
|
||||
{name: "sources help", args: []string{"config", "sources", "--help"}, want: "Usage: narratio config sources"},
|
||||
{name: "artifacts help", args: []string{"config", "artifacts", "--help"}, want: "Usage: narratio config artifacts"},
|
||||
{name: "diff help", args: []string{"config", "diff", "--help"}, want: "Usage: narratio config diff"},
|
||||
{name: "unknown", args: []string{"config", "unknown"}, want: `config: unknown subcommand "unknown"`, code: 1},
|
||||
{name: "missing", args: []string{"config"}, want: "config: expected subcommand: validate|show|sources|artifacts|diff", code: 1},
|
||||
{name: "session flag", args: []string{"config", "validate", "--session", "session.yml"}, want: "flag provided but not defined", code: 1},
|
||||
{name: "stage flag", args: []string{"config", "show", "--from", "prepare"}, want: "flag provided but not defined", code: 1},
|
||||
{name: "force flag", args: []string{"config", "show", "--force"}, want: "flag provided but not defined", code: 1},
|
||||
{name: "artifact flag", args: []string{"config", "show", "--artifacts", "recap"}, want: "flag provided but not defined", code: 1},
|
||||
{name: "retired selector", args: []string{"config", "validate", "--profile", "testing"}, want: "flag provided but not defined", code: 1},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var stdout, stderr bytes.Buffer
|
||||
code := executeForTest(test.args, &stdout, &stderr)
|
||||
if code != test.code {
|
||||
t.Fatalf("exit code = %d, want %d; stdout=%q stderr=%q", code, test.code, stdout.String(), stderr.String())
|
||||
}
|
||||
combined := stdout.String() + stderr.String()
|
||||
if !strings.Contains(combined, test.want) {
|
||||
t.Fatalf("output = %q, want %q", combined, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecuteConfigUsesInvocationPipelineLoader(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
pipelinePath := filepath.Join(dir, "pipeline.yml")
|
||||
mustWriteTestFile(t, pipelinePath, "workspace:\n root: "+filepath.Join(dir, "workspace")+"\nwhisperx:\n transcribe_url: https://transcription.example.com/transcribe\n")
|
||||
|
||||
for _, subcommand := range []string{"validate", "show", "sources", "artifacts"} {
|
||||
for _, subcommand := range []string{"validate", "show", "sources"} {
|
||||
t.Run(subcommand, func(t *testing.T) {
|
||||
calls := 0
|
||||
deps := commandDependencies{
|
||||
@@ -82,68 +45,6 @@ func TestExecuteConfigUsesInvocationPipelineLoader(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigValidateAndShowPipelineOnlyAreSideEffectFree(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
workspaceRoot := filepath.Join(dir, "workspace-does-not-exist")
|
||||
pipelinePath := filepath.Join(dir, "pipeline.yml")
|
||||
secretsDir := filepath.Join(dir, "secrets")
|
||||
const secret = "inspection-secret-must-not-escape"
|
||||
mustWriteTestFile(t, filepath.Join(secretsDir, "INSPECTION_SECRET"), secret+"\n")
|
||||
calls := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { calls++ }))
|
||||
defer server.Close()
|
||||
mustWriteTestFile(t, pipelinePath, `workspace:
|
||||
root: `+workspaceRoot+`
|
||||
whisperx:
|
||||
transcribe_url: `+server.URL+`
|
||||
`)
|
||||
t.Setenv("INSPECTION_SECRET", secret)
|
||||
|
||||
var validateOut bytes.Buffer
|
||||
if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath}, &validateOut); err != nil {
|
||||
t.Fatalf("ConfigValidate() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(validateOut.String(), "Configuration valid: root=") || !strings.Contains(validateOut.String(), "; overlay=none; digest=") {
|
||||
t.Fatalf("validate output = %q", validateOut.String())
|
||||
}
|
||||
|
||||
var showOut bytes.Buffer
|
||||
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath}, &showOut); err != nil {
|
||||
t.Fatalf("ConfigShow() error = %v", err)
|
||||
}
|
||||
show := showOut.String()
|
||||
if !strings.HasSuffix(show, "\n") || !strings.Contains(show, "workspace:\n") || !strings.Contains(show, "root: "+workspaceRoot) {
|
||||
t.Fatalf("show output = %q", show)
|
||||
}
|
||||
if strings.Contains(show, "artifact_families") || strings.Contains(show, "resolution") {
|
||||
t.Fatalf("show output leaked resolution-only fields: %q", show)
|
||||
}
|
||||
if strings.Contains(show, secret) {
|
||||
t.Fatalf("show output leaked a raw secret: %q", show)
|
||||
}
|
||||
var sourcesOut bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), []string{"--config", pipelinePath}, &sourcesOut); err != nil {
|
||||
t.Fatalf("ConfigSources() error = %v", err)
|
||||
}
|
||||
if strings.Contains(sourcesOut.String(), secret) {
|
||||
t.Fatalf("sources output leaked a raw secret: %q", sourcesOut.String())
|
||||
}
|
||||
writeInspectionOverlays(t, pipelinePath, "whisperx:\n language: en\n", "whisperx:\n language: fr\n")
|
||||
var diffOut bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{"production", "testing", "--config", pipelinePath}, &diffOut); err != nil {
|
||||
t.Fatalf("ConfigDiff() error = %v", err)
|
||||
}
|
||||
if strings.Contains(diffOut.String(), secret) {
|
||||
t.Fatalf("diff output leaked a raw secret: %q", diffOut.String())
|
||||
}
|
||||
if calls != 0 {
|
||||
t.Fatalf("inspection invoked configured external endpoint %d time(s)", calls)
|
||||
}
|
||||
if _, err := os.Stat(workspaceRoot); !os.IsNotExist(err) {
|
||||
t.Fatalf("workspace root stat error = %v, want absent", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDiffReportsSemanticOverlayChanges(t *testing.T) {
|
||||
workspaceRoot := t.TempDir()
|
||||
pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot)
|
||||
@@ -208,56 +109,6 @@ scriptorium:
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigShowPreservesNullAndEmptyCollections(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
pipelinePath := filepath.Join(dir, "pipeline.yml")
|
||||
mustWriteTestFile(t, pipelinePath, `workspace:
|
||||
root: /tmp/narratio-work
|
||||
whisperx:
|
||||
transcribe_url: https://transcription.example.test/transcribe
|
||||
audita:
|
||||
modules: null
|
||||
scriptorium:
|
||||
artifacts: null
|
||||
`)
|
||||
mustWriteTestFile(t, filepath.Join(dir, "overlays", "empty.yml"), `audita:
|
||||
modules: []
|
||||
scriptorium:
|
||||
artifacts: {}
|
||||
`)
|
||||
|
||||
var base, empty bytes.Buffer
|
||||
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath}, &base); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "empty"}, &empty); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{"modules: null\n", "artifacts: null\n"} {
|
||||
if !strings.Contains(base.String(), want) {
|
||||
t.Fatalf("base show output missing %q:\n%s", want, base.String())
|
||||
}
|
||||
}
|
||||
for _, want := range []string{"modules: []\n", "artifacts: {}\n"} {
|
||||
if !strings.Contains(empty.String(), want) {
|
||||
t.Fatalf("empty-overlay show output missing %q:\n%s", want, empty.String())
|
||||
}
|
||||
}
|
||||
|
||||
var diff bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{"default", "empty", "--config", pipelinePath}, &diff); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"changed\t/audita/modules\tnull\t[]\n",
|
||||
"changed\t/scriptorium/artifacts\tnull\t{}\n",
|
||||
} {
|
||||
if !strings.Contains(diff.String(), want) {
|
||||
t.Fatalf("diff output missing %q:\n%s", want, diff.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDiffComparesExpandedFamiliesAndPublishRules(t *testing.T) {
|
||||
pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
|
||||
writeInspectionOverlays(t, pipelinePath, `scriptorium:
|
||||
@@ -374,126 +225,6 @@ func TestConfigDiffBootstrapsSecretsOnceForBothOverlays(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigInspectionOutputsNeverExposeResolvedCredentialValues(t *testing.T) {
|
||||
const firstCanary = "inspection-credential-canary-one"
|
||||
const secondCanary = "inspection-credential-canary-two"
|
||||
for name, value := range map[string]string{
|
||||
"NARRATIO_INSPECT_ACCESS": firstCanary,
|
||||
"NARRATIO_INSPECT_SECRET": firstCanary,
|
||||
"NARRATIO_INSPECT_LLM_ONE": firstCanary,
|
||||
"NARRATIO_INSPECT_LLM_TWO": secondCanary,
|
||||
"NARRATIO_INSPECT_NOTARIUS_ONE": firstCanary,
|
||||
"NARRATIO_INSPECT_NOTARIUS_TWO": secondCanary,
|
||||
} {
|
||||
t.Setenv(name, value)
|
||||
}
|
||||
workspaceRoot := t.TempDir()
|
||||
pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot)
|
||||
pipelineData, err := os.ReadFile(pipelinePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pipelineYAML := strings.Replace(string(pipelineData), " bucket: test-bucket\n", ` bucket: test-bucket
|
||||
access_key_id: NARRATIO_INSPECT_ACCESS
|
||||
secret_access_key: NARRATIO_INSPECT_SECRET
|
||||
`, 1)
|
||||
pipelineYAML += `notarius:
|
||||
enabled: false
|
||||
credentials: [NARRATIO_INSPECT_NOTARIUS_ONE]
|
||||
`
|
||||
if err := os.WriteFile(pipelinePath, []byte(pipelineYAML), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeInspectionOverlays(t, pipelinePath,
|
||||
"audita:\n proposal_profile: production\n credentials: [NARRATIO_INSPECT_LLM_ONE]\n",
|
||||
"audita:\n proposal_profile: testing\n credentials: [NARRATIO_INSPECT_LLM_TWO]\nnotarius:\n credentials: [NARRATIO_INSPECT_NOTARIUS_TWO]\n",
|
||||
)
|
||||
mustWriteTestFile(t, filepath.Join(filepath.Dir(pipelinePath), "overlays", "without-notarius-key.yml"), "notarius:\n credentials: []\n")
|
||||
|
||||
var validate bytes.Buffer
|
||||
if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &validate); err != nil {
|
||||
t.Fatalf("config validate: %v", err)
|
||||
}
|
||||
|
||||
var show bytes.Buffer
|
||||
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &show); err != nil {
|
||||
t.Fatalf("config show: %v", err)
|
||||
}
|
||||
var sources bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &sources); err != nil {
|
||||
t.Fatalf("config sources: %v", err)
|
||||
}
|
||||
var catalog bytes.Buffer
|
||||
if err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &catalog); err != nil {
|
||||
t.Fatalf("config artifacts: %v", err)
|
||||
}
|
||||
var diff bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{"production", "testing", "--config", pipelinePath}, &diff); err != nil {
|
||||
t.Fatalf("config diff: %v", err)
|
||||
}
|
||||
var removed bytes.Buffer
|
||||
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "without-notarius-key"}, &removed); err != nil {
|
||||
t.Fatalf("config show with removed Notarius credential: %v", err)
|
||||
}
|
||||
for label, output := range map[string]string{"show": show.String(), "sources": sources.String(), "artifacts": catalog.String(), "diff": diff.String()} {
|
||||
if strings.Contains(output, firstCanary) || strings.Contains(output, secondCanary) {
|
||||
t.Fatalf("%s output exposed credential value: %q", label, output)
|
||||
}
|
||||
}
|
||||
for _, reference := range []string{"NARRATIO_INSPECT_ACCESS", "NARRATIO_INSPECT_SECRET", "NARRATIO_INSPECT_LLM_ONE", "NARRATIO_INSPECT_NOTARIUS_ONE"} {
|
||||
if !strings.Contains(show.String(), reference) {
|
||||
t.Fatalf("show omitted safe credential reference %q: %q", reference, show.String())
|
||||
}
|
||||
}
|
||||
if !strings.Contains(diff.String(), "NARRATIO_INSPECT_LLM_ONE") || !strings.Contains(diff.String(), "NARRATIO_INSPECT_LLM_TWO") ||
|
||||
!strings.Contains(diff.String(), "NARRATIO_INSPECT_NOTARIUS_ONE") || !strings.Contains(diff.String(), "NARRATIO_INSPECT_NOTARIUS_TWO") {
|
||||
t.Fatalf("diff omitted safe credential references: %q", diff.String())
|
||||
}
|
||||
if !strings.Contains(sources.String(), "notarius.credentials") {
|
||||
t.Fatalf("sources omitted Notarius credential ownership: %q", sources.String())
|
||||
}
|
||||
if strings.Contains(removed.String(), "NARRATIO_INSPECT_NOTARIUS_ONE") {
|
||||
t.Fatalf("empty overlay did not remove Notarius credential: %q", removed.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigValidateRejectsUnavailableNotariusCredential(t *testing.T) {
|
||||
const envName = "NARRATIO_INSPECT_NOTARIUS_MISSING"
|
||||
restoreEnvAfterTest(t, envName)
|
||||
path := filepath.Join(t.TempDir(), "pipeline.yml")
|
||||
mustWriteTestFile(t, path, "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+envName+"]\n")
|
||||
err := ConfigValidate(context.Background(), []string{"--config", path}, io.Discard)
|
||||
if err == nil || !strings.Contains(err.Error(), "secret.unset") {
|
||||
t.Fatalf("ConfigValidate() error = %v, want unavailable credential failure", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigCommandsInspectMaintainedSplitBundleWithoutRuntimeState(t *testing.T) {
|
||||
examplesDir := filepath.Join("..", "..", "examples")
|
||||
pipelinePath := filepath.Join(examplesDir, "production-testing", "pipeline.yml")
|
||||
campaignPath := filepath.Join(examplesDir, "campaigns", "sample-campaign", "campaign.yml")
|
||||
workspacePath := filepath.Join(examplesDir, "production-testing", "workspace")
|
||||
if _, err := os.Stat(workspacePath); !os.IsNotExist(err) {
|
||||
t.Fatalf("example workspace stat = %v, want absent", err)
|
||||
}
|
||||
|
||||
for _, command := range []func(context.Context, []string, io.Writer) error{ConfigValidate, ConfigShow, ConfigSources, ConfigArtifacts} {
|
||||
if err := command(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, io.Discard); err != nil {
|
||||
t.Fatalf("inspection command %T error = %v", command, err)
|
||||
}
|
||||
}
|
||||
var diff bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{"default", "testing", "--config", pipelinePath, "--campaign-file", campaignPath}, &diff); err != nil {
|
||||
t.Fatalf("ConfigDiff() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(diff.String(), "/audita/proposal_profile") {
|
||||
t.Fatalf("split bundle overlay diff = %q, want proposal profile change", diff.String())
|
||||
}
|
||||
if _, err := os.Stat(workspacePath); !os.IsNotExist(err) {
|
||||
t.Fatalf("inspection created example workspace: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func writeInspectionOverlays(t *testing.T, pipelinePath, production, testing string) {
|
||||
t.Helper()
|
||||
overlaysDir := filepath.Join(filepath.Dir(pipelinePath), "overlays")
|
||||
@@ -501,278 +232,6 @@ func writeInspectionOverlays(t *testing.T, pipelinePath, production, testing str
|
||||
mustWriteTestFile(t, filepath.Join(overlaysDir, "testing.yml"), testing)
|
||||
}
|
||||
|
||||
func TestConfigCommandsSelectOverlaysAndCampaigns(t *testing.T) {
|
||||
workspaceRoot := t.TempDir()
|
||||
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
|
||||
enableCommandTestOverlays(t, pipelinePath)
|
||||
|
||||
var defaultOut bytes.Buffer
|
||||
if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath}, &defaultOut); err != nil {
|
||||
t.Fatalf("default ConfigValidate() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(defaultOut.String(), "overlay=none") {
|
||||
t.Fatalf("default output = %q", defaultOut.String())
|
||||
}
|
||||
|
||||
var explicitOut bytes.Buffer
|
||||
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "testing"}, &explicitOut); err != nil {
|
||||
t.Fatalf("explicit ConfigShow() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(explicitOut.String(), "language: fr") {
|
||||
t.Fatalf("explicit show output = %q", explicitOut.String())
|
||||
}
|
||||
|
||||
for _, args := range [][]string{
|
||||
{"--config", pipelinePath, "--campaign", "sample-campaign"},
|
||||
{"--config", pipelinePath, "--campaign-file", campaignPath},
|
||||
} {
|
||||
var out bytes.Buffer
|
||||
if err := ConfigValidate(context.Background(), args, &out); err != nil {
|
||||
t.Fatalf("ConfigValidate(%q) error = %v", args, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigCommandsExpandFamiliesAndRequireCampaign(t *testing.T) {
|
||||
pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
|
||||
|
||||
for _, command := range []func(context.Context, []string, io.Writer) error{ConfigValidate, ConfigShow, ConfigArtifacts} {
|
||||
var out bytes.Buffer
|
||||
err := command(context.Background(), []string{"--config", pipelinePath}, &out)
|
||||
if err == nil || !strings.Contains(err.Error(), "artifact_families requires a campaign") {
|
||||
t.Fatalf("family command without campaign error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
var show bytes.Buffer
|
||||
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &show); err != nil {
|
||||
t.Fatalf("ConfigShow() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(show.String(), "character_note_arannis:") || strings.Contains(show.String(), "artifact_families") {
|
||||
t.Fatalf("expanded show output = %q", show.String())
|
||||
}
|
||||
|
||||
loadedPipeline, err := config.LoadPipeline(pipelinePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loadedCampaign, err := config.LoadCampaign(campaignPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := config.LoadPipelineCampaign(pipelinePath, loadedPipeline, campaignPath, loadedCampaign)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var validateOut bytes.Buffer
|
||||
if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &validateOut); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(validateOut.String(), "digest="+config.EffectivePipelineDigest(loaded.Pipeline)) {
|
||||
t.Fatalf("inspection digest = %q, want %q", validateOut.String(), config.EffectivePipelineDigest(loaded.Pipeline))
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigValidateReportsCanonicalPartyAndImportErrors(t *testing.T) {
|
||||
pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
|
||||
mustWriteTestFile(t, filepath.Join(filepath.Dir(campaignPath), "party.yml"), "schema_version: narratio.party.v2\ncharacters: {}\n")
|
||||
if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, io.Discard); err == nil || !strings.Contains(err.Error(), "unsupported") {
|
||||
t.Fatalf("canonical party error = %v", err)
|
||||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
rootPath := filepath.Join(dir, "pipeline.yml")
|
||||
mustWriteTestFile(t, rootPath, `config:
|
||||
imports:
|
||||
- path: conf.yml
|
||||
workspace:
|
||||
root: /one
|
||||
whisperx:
|
||||
transcribe_url: https://transcription.example.com/transcribe
|
||||
`)
|
||||
mustWriteTestFile(t, filepath.Join(dir, "conf.yml"), "workspace:\n root: /two\n")
|
||||
err := ConfigValidate(context.Background(), []string{"--config", rootPath}, io.Discard)
|
||||
if err == nil || !strings.Contains(err.Error(), "/workspace/root") || !strings.Contains(err.Error(), "pipeline.yml") || !strings.Contains(err.Error(), "conf.yml") {
|
||||
t.Fatalf("import diagnostic = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSourcesReportsStableOwnership(t *testing.T) {
|
||||
workspaceRoot := t.TempDir()
|
||||
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
|
||||
enableCommandTestOverlays(t, pipelinePath)
|
||||
|
||||
args := []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing"}
|
||||
var first, second bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), args, &first); err != nil {
|
||||
t.Fatalf("first ConfigSources() error = %v", err)
|
||||
}
|
||||
if err := ConfigSources(context.Background(), args, &second); err != nil {
|
||||
t.Fatalf("second ConfigSources() error = %v", err)
|
||||
}
|
||||
if first.String() != second.String() {
|
||||
t.Fatalf("sources output is not deterministic:\nfirst=%q\nsecond=%q", first.String(), second.String())
|
||||
}
|
||||
output := first.String()
|
||||
for _, want := range []string{
|
||||
"root: ",
|
||||
"imports: none",
|
||||
"overlay: name=testing selection=explicit path=",
|
||||
"campaign: id=sample-campaign source=",
|
||||
"party: source=",
|
||||
"digest: ",
|
||||
"path\trole\tsource\n",
|
||||
"workspace.root\troot\t",
|
||||
"whisperx.language\toverlay\t",
|
||||
"derived.players\tparty\t",
|
||||
"trim.enabled\tdefault\tdefault",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("sources output missing %q:\n%s", want, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSourcesReportsCanonicalFamilyAndPublishOrigins(t *testing.T) {
|
||||
pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
|
||||
var out bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &out); err != nil {
|
||||
t.Fatalf("ConfigSources() error = %v", err)
|
||||
}
|
||||
output := out.String()
|
||||
partyPath := filepath.Join(filepath.Dir(campaignPath), "party.yml")
|
||||
for _, want := range []string{
|
||||
"party: source=" + partyPath,
|
||||
"derived.players\tparty\t" + partyPath,
|
||||
"scriptorium.artifacts.character_note_arannis.enabled\tfamily\t" + pipelinePath,
|
||||
"scriptorium.artifacts.character_note_arannis.enabled\tparty\t" + partyPath,
|
||||
"scriptorium.artifacts.character_note_arannis.depends_on\tfamily\t" + pipelinePath,
|
||||
"scriptorium.artifacts.character_note_arannis.inputs.prior.source\tparty\t" + partyPath,
|
||||
"publish.outputs[",
|
||||
"\tfamily\t" + pipelinePath,
|
||||
"\tparty\t" + partyPath,
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("sources output missing %q:\n%s", want, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSourcesPreservesOverlayOwnershipThroughFamilyExpansion(t *testing.T) {
|
||||
pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
|
||||
overlayPath := filepath.Join(filepath.Dir(pipelinePath), "overlays", "testing.yml")
|
||||
mustWriteTestFile(t, overlayPath, `scriptorium:
|
||||
artifact_families:
|
||||
character_note:
|
||||
enabled: true
|
||||
prompt_id: dnd.character_note
|
||||
`)
|
||||
|
||||
var out bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing"}, &out); err != nil {
|
||||
t.Fatalf("ConfigSources() error = %v", err)
|
||||
}
|
||||
want := "scriptorium.artifacts.character_note_arannis.enabled\tfamily\t" + overlayPath
|
||||
if !strings.Contains(out.String(), want) {
|
||||
t.Fatalf("sources output missing overlay-generated ownership %q:\n%s", want, out.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSourcesAttributesInferredArtifactDependencies(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
pipelinePath := filepath.Join(dir, "pipeline.yml")
|
||||
inputPath := filepath.Join(dir, "input-only.yml")
|
||||
overlayPath := filepath.Join(dir, "overlays", "testing.yml")
|
||||
mustWriteTestFile(t, pipelinePath, `config:
|
||||
imports:
|
||||
- path: input-only.yml
|
||||
workspace:
|
||||
root: /srv/narratio
|
||||
whisperx:
|
||||
transcribe_url: https://transcription.example.test/transcribe
|
||||
scriptorium:
|
||||
artifacts:
|
||||
first:
|
||||
enabled: false
|
||||
output_path: artifacts/first.md
|
||||
second:
|
||||
enabled: false
|
||||
output_path: artifacts/second.md
|
||||
mixed:
|
||||
enabled: false
|
||||
output_path: artifacts/mixed.md
|
||||
depends_on: [first]
|
||||
`)
|
||||
mustWriteTestFile(t, inputPath, `scriptorium:
|
||||
artifacts:
|
||||
input_only:
|
||||
enabled: false
|
||||
output_path: artifacts/input-only.md
|
||||
inputs:
|
||||
prior:
|
||||
source: narratio.artifact.first
|
||||
`)
|
||||
mustWriteTestFile(t, overlayPath, `scriptorium:
|
||||
artifacts:
|
||||
mixed:
|
||||
inputs:
|
||||
prior:
|
||||
source: narratio.artifact.second
|
||||
`)
|
||||
|
||||
var out bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--overlay", "testing"}, &out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"scriptorium.artifacts.input_only.depends_on\timport\t" + inputPath,
|
||||
"scriptorium.artifacts.mixed.depends_on\troot\t" + pipelinePath,
|
||||
"scriptorium.artifacts.mixed.depends_on\toverlay\t" + overlayPath,
|
||||
} {
|
||||
if !strings.Contains(out.String(), want) {
|
||||
t.Fatalf("sources output missing dependency contributor %q:\n%s", want, out.String())
|
||||
}
|
||||
}
|
||||
if strings.Contains(out.String(), "scriptorium.artifacts.input_only.depends_on\tdefault\tdefault") {
|
||||
t.Fatalf("inferred dependency retained default attribution:\n%s", out.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSourcesReportsRootImportOverlayAndDefaultOwnership(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
rootPath := filepath.Join(dir, "pipeline.yml")
|
||||
importPath := filepath.Join(dir, "base.yml")
|
||||
overlayPath := filepath.Join(dir, "overlays", "testing.yml")
|
||||
mustWriteTestFile(t, rootPath, `config:
|
||||
imports:
|
||||
- path: base.yml
|
||||
workspace:
|
||||
root: /srv/narratio
|
||||
whisperx:
|
||||
transcribe_url: https://transcription.example.com/transcribe
|
||||
`)
|
||||
mustWriteTestFile(t, importPath, "storage:\n backend: local\n")
|
||||
mustWriteTestFile(t, overlayPath, "whisperx:\n language: fr\n")
|
||||
|
||||
var out bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), []string{"--config", rootPath, "--overlay", "testing"}, &out); err != nil {
|
||||
t.Fatalf("ConfigSources() error = %v", err)
|
||||
}
|
||||
output := out.String()
|
||||
for _, want := range []string{
|
||||
"import: " + importPath,
|
||||
"overlay: name=testing selection=explicit path=" + overlayPath,
|
||||
"workspace.root\troot\t" + rootPath,
|
||||
"storage.backend\timport\t" + importPath,
|
||||
"whisperx.language\toverlay\t" + overlayPath,
|
||||
"trim.enabled\tdefault\tdefault",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("sources output missing %q:\n%s", want, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func writeInspectionFamilyConfig(t *testing.T) (string, string) {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
@@ -859,29 +318,23 @@ func TestNativeBundleInspectionAndExecutionAgree(t *testing.T) {
|
||||
t.Chdir(root)
|
||||
campaign := filepath.Join(bundle, "campaigns", "sample-campaign", "campaign.yml")
|
||||
common := []string{"--campaign-file", campaign, "--secrets-dir", secrets}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
run func(context.Context, []string, io.Writer) error
|
||||
want []string
|
||||
}{
|
||||
{"validate", ConfigValidate, []string{pipeline}},
|
||||
{"show", ConfigShow, []string{"NARRATIO_BUNDLE_TEST_KEY", "character_meta_arannis"}},
|
||||
{"sources", ConfigSources, []string{"empty_import", "brenna.yml"}},
|
||||
{"artifacts", ConfigArtifacts, []string{"session_recap", "character_meta_arannis"}},
|
||||
} {
|
||||
var out bytes.Buffer
|
||||
if err := tc.run(context.Background(), common, &out); err != nil {
|
||||
t.Fatalf("%s: %v", tc.name, err)
|
||||
for _, operation := range []string{"validate", "show", "sources"} {
|
||||
args := []string{"config", operation, "--secrets-dir", secrets}
|
||||
out := nativeInspectionForTest(t, args)
|
||||
if strings.Contains(out, secretValue) {
|
||||
t.Fatalf("%s exposed credential value", operation)
|
||||
}
|
||||
for _, want := range tc.want {
|
||||
if !strings.Contains(out.String(), want) {
|
||||
t.Errorf("%s output missing %q: %s", tc.name, want, out.String())
|
||||
}
|
||||
}
|
||||
if strings.Contains(out.String(), secretValue) {
|
||||
t.Errorf("%s exposed credential value", tc.name)
|
||||
if operation == "show" && !strings.Contains(out, "artifact_families") {
|
||||
t.Fatal("native show omitted authored families")
|
||||
}
|
||||
}
|
||||
var catalog bytes.Buffer
|
||||
if err := ConfigArtifacts(context.Background(), common, &catalog); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(catalog.String(), "character_meta_arannis") {
|
||||
t.Fatal("domain catalog omitted concrete family member")
|
||||
}
|
||||
var diff bytes.Buffer
|
||||
args := append([]string{"default", "testing"}, common...)
|
||||
if err := ConfigDiff(context.Background(), args, &diff); err != nil {
|
||||
|
||||
@@ -23,18 +23,3 @@ func TestConfigDiffUsesEscapedPointersAndAtomicLists(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSourcesReportsEmptyOptionalImportAndNormalization(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
root := filepath.Join(dir, "pipeline.yml")
|
||||
mustWriteTestFile(t, root, "config:\n imports:\n - path: absent.yml\nworkspace: {root: ./work}\nwhisperx: {transcribe_url: 'https://example.test/transcribe'}\n")
|
||||
var output bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), []string{"--config", root}, &output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{"empty_import\t/config/imports/0\tpath\t" + root, "workspace.root\tresolution\tresolution", "workspace.root\troot\t" + root} {
|
||||
if !strings.Contains(output.String(), want) {
|
||||
t.Fatalf("sources lack %q: %s", want, output.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
83
internal/app/configuration_commands.go
Normal file
83
internal/app/configuration_commands.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
type configurationInspectionState struct {
|
||||
deps commandDependencies
|
||||
acquisitions map[configurationSelection]*configurationAcquisition
|
||||
}
|
||||
|
||||
func (s *configurationInspectionState) acquisition(selection ckconfig.Selection, input configurationSelection) *configurationAcquisition {
|
||||
input.Config, input.Overlay = selection.Config, selection.Overlay
|
||||
acquired := s.acquisitions[input]
|
||||
if acquired == nil {
|
||||
acquired = newConfigurationAcquisition(input, s.deps)
|
||||
s.acquisitions[input] = acquired
|
||||
}
|
||||
return acquired
|
||||
}
|
||||
|
||||
func configurationCommand(deps commandDependencies) commandkit.Command {
|
||||
flags := newConfigurationFlags(func(input *configurationSelection) *configurationSelection { return input })
|
||||
app := ckconfig.FromConfigKit("app", "Application pipeline configuration.", func(ctx context.Context, selection ckconfig.Selection, input configurationSelection, state *configurationInspectionState) (*configkit.Result[config.PipelineConfig], error) {
|
||||
acquired := state.acquisition(selection, input)
|
||||
cfg, err := acquired.Pipeline(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg.ConfigKitResult(), nil
|
||||
})
|
||||
campaign := ckconfig.FromConfigKit("campaign", "Campaign configuration.", func(ctx context.Context, selection ckconfig.Selection, input configurationSelection, state *configurationInspectionState) (*configkit.Result[config.CampaignConfig], error) {
|
||||
acquired := state.acquisition(selection, input)
|
||||
cfg, err := acquired.Campaign(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg.ConfigKitResult(), nil
|
||||
})
|
||||
session := ckconfig.FromConfigKit("session", "Session configuration and campaign defaults.", func(ctx context.Context, selection ckconfig.Selection, input configurationSelection, state *configurationInspectionState) (result *configkit.Result[config.SessionConfig], err error) {
|
||||
acquired := state.acquisition(selection, input)
|
||||
defer func() { err = errors.Join(err, acquired.Close()) }()
|
||||
cfg, err := acquired.Session(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg.ConfigKitResult(), nil
|
||||
})
|
||||
party := ckconfig.FromConfigKit("party", "Selected party configuration.", func(ctx context.Context, selection ckconfig.Selection, input configurationSelection, state *configurationInspectionState) (*configkit.Result[config.PartyConfig], error) {
|
||||
acquired := state.acquisition(selection, input)
|
||||
cfg, err := acquired.Party(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg.Canonical.ConfigKitResult(), nil
|
||||
})
|
||||
return ckconfig.Command(ckconfig.Suite[configurationSelection, *configurationInspectionState]{
|
||||
NewState: func() *configurationInspectionState {
|
||||
invocationDeps := normalizeCommandDependencies(deps)
|
||||
invocationDeps.secretsBootstrap = &secretsBootstrap{}
|
||||
return &configurationInspectionState{deps: invocationDeps, acquisitions: make(map[configurationSelection]*configurationAcquisition)}
|
||||
},
|
||||
CheckInput: func(_ string, selection ckconfig.Selection, input configurationSelection) error {
|
||||
input.Config, input.Overlay = selection.Config, selection.Overlay
|
||||
return checkConfigurationSelection(input)
|
||||
},
|
||||
Selectors: []ckconfig.Selector[configurationSelection]{
|
||||
{Binding: flags.Campaign, Scopes: []string{"campaign", "session", "party"}},
|
||||
{Binding: flags.CampaignFile, Scopes: []string{"campaign", "session", "party"}},
|
||||
{Binding: flags.Session, Scopes: []string{"session"}},
|
||||
{Binding: flags.SessionFile, Scopes: []string{"session"}},
|
||||
{Binding: flags.PartyFile, Scopes: []string{"party"}},
|
||||
{Binding: flags.SecretsDir, Scopes: []string{"app", "campaign", "session", "party"}},
|
||||
},
|
||||
Scopes: []ckconfig.Scope[configurationSelection, *configurationInspectionState]{app, campaign, session, party},
|
||||
})
|
||||
}
|
||||
169
internal/app/configuration_commands_test.go
Normal file
169
internal/app/configuration_commands_test.go
Normal file
@@ -0,0 +1,169 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestConfigurationCommandsExposeNativeScopesLazily(t *testing.T) {
|
||||
app, err := newApplication(commandDependencies{
|
||||
loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||
t.Fatal("discovery loaded config")
|
||||
return nil, nil
|
||||
},
|
||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) {
|
||||
t.Fatal("discovery bootstrapped secrets")
|
||||
return nil, nil
|
||||
},
|
||||
}, executePlan)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, args := range [][]string{{"config", "scopes", "--format", "json"}, {"config", "--help"}, {"config", "show", "--help"}} {
|
||||
var out, diagnostic bytes.Buffer
|
||||
result := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if result.Status != 0 {
|
||||
t.Fatalf("%v: %v %s", args, result, diagnostic.String())
|
||||
}
|
||||
if args[1] == "scopes" {
|
||||
var inventory struct {
|
||||
Scopes []struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"scopes"`
|
||||
}
|
||||
if err := json.Unmarshal(out.Bytes(), &inventory); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(inventory.Scopes) != 4 {
|
||||
t.Fatalf("scopes=%s", out.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigurationCommandsInspectActualDocuments(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
campaignCfg, err := config.LoadCampaign(campaign)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
party, err := config.ResolveParty(campaign, campaignCfg, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
scope, field string
|
||||
selectors []string
|
||||
}{
|
||||
{"app", "workspace", []string{"--config", pipeline}},
|
||||
{"campaign", "campaign_id", []string{"--campaign-file", campaign}},
|
||||
{"session", "session_id", []string{"--campaign-file", campaign, "--session-file", session}},
|
||||
{"party", "characters", []string{"--party-file", party.Source.Path}},
|
||||
} {
|
||||
t.Run(test.scope, func(t *testing.T) {
|
||||
var out, diagnostic bytes.Buffer
|
||||
args := append([]string{"config", "show", "--scope", test.scope, "--format", "json"}, test.selectors...)
|
||||
result := Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if result.Status != 0 {
|
||||
t.Fatalf("status=%d diagnostics=%s", result.Status, diagnostic.String())
|
||||
}
|
||||
var document map[string]any
|
||||
if err := json.Unmarshal(out.Bytes(), &document); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := document[test.field]; !ok {
|
||||
t.Fatalf("missing %s: %s", test.field, out.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigurationCommandsUseNativeSourcesAndValidation(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
root := filepath.Join(dir, "pipeline.yml")
|
||||
imported := filepath.Join(dir, "platform.yml")
|
||||
if err := os.WriteFile(root, []byte("config:\n imports:\n - path: platform.yml\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(imported, []byte("workspace: {root: ./workspace}\nwhisperx: {transcribe_url: https://transcription.example.test/transcribe}\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var out, diagnostic bytes.Buffer
|
||||
result := Execute(context.Background(), []string{"config", "sources", "--config", root, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if result.Status != 0 || !strings.Contains(out.String(), "platform.yml") {
|
||||
t.Fatalf("sources=%s diagnostics=%s", out.String(), diagnostic.String())
|
||||
}
|
||||
if err := os.WriteFile(imported, []byte("workspace: {unrecognized: value}\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out.Reset()
|
||||
diagnostic.Reset()
|
||||
result = Execute(context.Background(), []string{"config", "validate", "--config", root}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if result.Status != 2 || !strings.Contains(diagnostic.String(), "decode.unknown_field") {
|
||||
t.Fatalf("status=%d diagnostics=%s", result.Status, diagnostic.String())
|
||||
}
|
||||
}
|
||||
|
||||
func nativeInspectionForTest(t *testing.T, args []string) string {
|
||||
t.Helper()
|
||||
var out, diagnostic bytes.Buffer
|
||||
outcome := Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if outcome.Status != 0 {
|
||||
t.Fatalf("%v: status=%d error=%v diagnostics=%s", args, outcome.Status, outcome.Cause, diagnostic.String())
|
||||
}
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func TestConfigurationCommandsExposeNativePathEvidence(t *testing.T) {
|
||||
pipeline, _, _ := writeValidConfigFiles(t, t.TempDir())
|
||||
for _, args := range [][]string{
|
||||
{"show", "--path", "/workspace/root"},
|
||||
{"explain", "--path", "/workspace/root"},
|
||||
{"explain", "--list", "--under", "/workspace", "--historical"},
|
||||
} {
|
||||
command := append([]string{"config"}, args...)
|
||||
command = append(command, "--config", pipeline, "--format", "json")
|
||||
output := nativeInspectionForTest(t, command)
|
||||
if !json.Valid([]byte(output)) {
|
||||
t.Fatalf("invalid native report: %s", output)
|
||||
}
|
||||
if args[0] == "explain" && !strings.Contains(output, "/workspace/root") {
|
||||
t.Fatalf("missing native path evidence: %s", output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigurationValidationFiltersDoNotHideFailure(t *testing.T) {
|
||||
pipeline := filepath.Join(t.TempDir(), "pipeline.yml")
|
||||
mustWriteTestFile(t, pipeline, "whisperx: {transcribe_url: https://transcription.example.test/transcribe, timeout: invalid}\n")
|
||||
var out, diagnostic bytes.Buffer
|
||||
outcome := Execute(context.Background(), []string{"config", "validate", "--config", pipeline, "--details", "--severity", "warning", "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if outcome.Status != 2 {
|
||||
t.Fatalf("status=%d diagnostics=%s", outcome.Status, diagnostic.String())
|
||||
}
|
||||
if !json.Valid(out.Bytes()) || !strings.Contains(out.String(), "filtered") {
|
||||
t.Fatalf("filtered failure report=%s", out.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigurationAggregateDoesNotOmitUnavailableContext(t *testing.T) {
|
||||
pipeline := filepath.Join(t.TempDir(), "pipeline.yml")
|
||||
mustWriteTestFile(t, pipeline, "whisperx: {transcribe_url: https://transcription.example.test/transcribe}\n")
|
||||
var out, diagnostic bytes.Buffer
|
||||
outcome := Execute(context.Background(), []string{"config", "validate", "--scope", "all", "--config", pipeline, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||
if outcome.Status == 0 || outcome.Cause == nil {
|
||||
t.Fatalf("missing context was silently omitted: %s", out.String())
|
||||
}
|
||||
if !strings.Contains(out.String(), "campaign") {
|
||||
t.Fatalf("missing aggregate scope report: %s", out.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user