Support independent native configuration comparisons and overrides
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestExecuteConfigUsesInvocationPipelineLoader(t *testing.T) {
|
||||
@@ -45,186 +44,6 @@ func TestExecuteConfigUsesInvocationPipelineLoader(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDiffReportsSemanticOverlayChanges(t *testing.T) {
|
||||
workspaceRoot := t.TempDir()
|
||||
pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot)
|
||||
writeInspectionOverlays(t, pipelinePath, `workspace:
|
||||
cleanup_after_publish: true
|
||||
publish:
|
||||
upload_run: true
|
||||
whisperx:
|
||||
language: en
|
||||
audita:
|
||||
modules: [glossary, grammar]
|
||||
scriptorium:
|
||||
artifacts:
|
||||
production_only:
|
||||
enabled: false
|
||||
output_path: artifacts/production.md
|
||||
`, `workspace:
|
||||
cleanup_after_publish: false
|
||||
whisperx:
|
||||
language: fr
|
||||
audita:
|
||||
modules: []
|
||||
scriptorium:
|
||||
artifacts:
|
||||
testing_only:
|
||||
enabled: false
|
||||
output_path: artifacts/testing.md
|
||||
`)
|
||||
|
||||
args := []string{"production", "testing", "--config", pipelinePath}
|
||||
var first, second bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), args, &first); err != nil {
|
||||
t.Fatalf("ConfigDiff() error = %v", err)
|
||||
}
|
||||
if err := ConfigDiff(context.Background(), args, &second); err != nil {
|
||||
t.Fatalf("second ConfigDiff() error = %v", err)
|
||||
}
|
||||
if first.String() != second.String() {
|
||||
t.Fatalf("diff output is not deterministic:\nfirst=%q\nsecond=%q", first.String(), second.String())
|
||||
}
|
||||
output := first.String()
|
||||
for _, want := range []string{
|
||||
"changed\t/audita/modules\t[\"glossary\",\"grammar\"]\t[]\n",
|
||||
"changed\t/workspace/cleanup_after_publish\ttrue\tfalse\n",
|
||||
"changed\t/whisperx/language\t\"en\"\t\"fr\"\n",
|
||||
"removed\t/scriptorium/artifacts/production_only\t{",
|
||||
"added\t/scriptorium/artifacts/testing_only\t{",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("diff output missing %q:\n%s", want, output)
|
||||
}
|
||||
}
|
||||
if strings.Index(output, "/audita/modules") > strings.Index(output, "/workspace/cleanup_after_publish") {
|
||||
t.Fatalf("diff records are not sorted by path:\n%s", output)
|
||||
}
|
||||
var reversed bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{"testing", "production", "--config", pipelinePath}, &reversed); err != nil {
|
||||
t.Fatalf("reversed ConfigDiff() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(reversed.String(), "changed\t/whisperx/language\t\"fr\"\t\"en\"\n") {
|
||||
t.Fatalf("reversed diff did not independently resolve overlays:\n%s", reversed.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDiffComparesExpandedFamiliesAndPublishRules(t *testing.T) {
|
||||
pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
|
||||
writeInspectionOverlays(t, pipelinePath, `scriptorium:
|
||||
artifact_families:
|
||||
character_note:
|
||||
enabled: false
|
||||
member_vars:
|
||||
character_name: character.name
|
||||
publish:
|
||||
enabled: true
|
||||
required: false
|
||||
`, `scriptorium:
|
||||
artifact_families:
|
||||
character_note:
|
||||
enabled: true
|
||||
prompt_id: dnd.character_note
|
||||
member_vars:
|
||||
character_name: character.class_summary
|
||||
publish:
|
||||
enabled: true
|
||||
required: true
|
||||
`)
|
||||
|
||||
var out bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{
|
||||
"production", "testing", "--config", pipelinePath, "--campaign-file", campaignPath,
|
||||
}, &out); err != nil {
|
||||
t.Fatalf("ConfigDiff() error = %v", err)
|
||||
}
|
||||
output := out.String()
|
||||
for _, want := range []string{
|
||||
"changed\t/scriptorium/artifacts/character_note_arannis/enabled\tfalse\ttrue\n",
|
||||
"changed\t/scriptorium/artifacts/character_note_arannis/vars/character_name\t\"Arannis\"\t\"wizard\"\n",
|
||||
"changed\t/publish/outputs\t",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("family diff output missing %q:\n%s", want, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDiffReportsEqualityAndRejectsInvalidInput(t *testing.T) {
|
||||
workspaceRoot := t.TempDir()
|
||||
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
|
||||
writeInspectionOverlays(t, pipelinePath, "whisperx:\n language: en\n", "whisperx:\n language: en\n")
|
||||
|
||||
var equal bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{"production", "testing", "--config", pipelinePath}, &equal); err != nil {
|
||||
t.Fatalf("ConfigDiff() equal overlays error = %v", err)
|
||||
}
|
||||
if got := equal.String(); got != "no differences\n" {
|
||||
t.Fatalf("equal diff output = %q", got)
|
||||
}
|
||||
|
||||
for _, args := range [][]string{
|
||||
{"production", "testing", "extra", "--config", pipelinePath},
|
||||
{"production", "--config", pipelinePath},
|
||||
{"production", "production", "--config", pipelinePath},
|
||||
{"unknown", "testing", "--config", pipelinePath},
|
||||
{"production", "testing", "--config", pipelinePath, "--overlay", "production"},
|
||||
{"production", "testing", "--config", pipelinePath, "--config", pipelinePath},
|
||||
{"production", "testing", "--config", pipelinePath, "--campaign", "sample-campaign", "--campaign-file", campaignPath},
|
||||
} {
|
||||
if err := ConfigDiff(context.Background(), args, io.Discard); err == nil {
|
||||
t.Fatalf("ConfigDiff(%q) succeeded, want error", args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDiffBootstrapsSecretsOnceForBothOverlays(t *testing.T) {
|
||||
workspaceRoot := t.TempDir()
|
||||
pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot)
|
||||
writeInspectionOverlays(t, pipelinePath, "whisperx:\n language: en\n", "whisperx:\n language: fr\n")
|
||||
secretsDir := t.TempDir()
|
||||
const secretName = "NARRATIO_DIFF_BOOTSTRAP_REPORT"
|
||||
restoreEnvAfterTest(t, secretName)
|
||||
if err := os.Unsetenv(secretName); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mustWriteSecretFile(t, filepath.Join(secretsDir, secretName), "diff-secret-must-not-appear\n")
|
||||
bootstrapCalls := 0
|
||||
var loadedPaths []string
|
||||
var diagnostics bytes.Buffer
|
||||
deps := commandDependencies{loadSecretsDir: func(got string) (*configkit.SecretsReport, error) {
|
||||
bootstrapCalls++
|
||||
if got != secretsDir {
|
||||
t.Fatalf("secrets directory = %q, want %q", got, secretsDir)
|
||||
}
|
||||
return configkit.LoadSecretsIntoEnvironment(got)
|
||||
}, diagnostics: &diagnostics}
|
||||
search := configkit.SearchPaths(pipelinePath)
|
||||
deps.pipelineSearch = &search
|
||||
deps.loadPipelineConfig = func(path string, opts config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||
loadedPaths = append(loadedPaths, path)
|
||||
return config.LoadPipelineWithOptions(path, opts)
|
||||
}
|
||||
|
||||
if err := configDiffWithDependencies(context.Background(), []string{
|
||||
"production", "testing", "--secrets-dir", secretsDir,
|
||||
}, io.Discard, deps); err != nil {
|
||||
t.Fatalf("config diff: %v", err)
|
||||
}
|
||||
if bootstrapCalls != 1 {
|
||||
t.Fatalf("bootstrap calls = %d, want 1", bootstrapCalls)
|
||||
}
|
||||
if len(loadedPaths) != 2 || loadedPaths[0] != "" || loadedPaths[1] != pipelinePath {
|
||||
t.Fatalf("pipeline load paths = %q, want discovery then selected root %q", loadedPaths, pipelinePath)
|
||||
}
|
||||
if got := diagnostics.String(); strings.Count(got, `name="`+secretName+`"`) != 1 {
|
||||
t.Fatalf("bootstrap report count = %d, want 1; diagnostics = %q", strings.Count(got, `name="`+secretName+`"`), got)
|
||||
}
|
||||
if strings.Contains(diagnostics.String(), "diff-secret-must-not-appear") {
|
||||
t.Fatalf("bootstrap diagnostics exposed secret value: %q", diagnostics.String())
|
||||
}
|
||||
}
|
||||
|
||||
func writeInspectionOverlays(t *testing.T, pipelinePath, production, testing string) {
|
||||
t.Helper()
|
||||
overlaysDir := filepath.Join(filepath.Dir(pipelinePath), "overlays")
|
||||
@@ -335,13 +154,9 @@ func TestNativeBundleInspectionAndExecutionAgree(t *testing.T) {
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(diff.String(), "/audita/proposal_profile") || strings.Contains(diff.String(), secretValue) {
|
||||
t.Fatalf("unexpected diff: %s", diff.String())
|
||||
diff := nativeInspectionForTest(t, []string{"config", "diff", "--details", "--against-overlay", "testing", "--secrets-dir", secrets, "--format", "json"})
|
||||
if !strings.Contains(diff, "/audita/proposal_profile") || strings.Contains(diff, secretValue) {
|
||||
t.Fatalf("unexpected diff: %s", diff)
|
||||
}
|
||||
workspace := filepath.Join(root, "conf.d", "workspace")
|
||||
if _, err := os.Stat(workspace); !os.IsNotExist(err) {
|
||||
|
||||
Reference in New Issue
Block a user