Verify native configuration workflows end to end

This commit is contained in:
2026-11-17 22:49:22 +00:00
parent 413b0d7134
commit 39a958675d
2 changed files with 102 additions and 1 deletions

View File

@@ -823,3 +823,104 @@ characters:
`)
return pipelinePath, campaignPath
}
func TestNativeBundleInspectionAndExecutionAgree(t *testing.T) {
examples, err := filepath.Abs(filepath.Join("..", "..", "examples"))
if err != nil {
t.Fatal(err)
}
bundle := t.TempDir()
if err := os.CopyFS(bundle, os.DirFS(examples)); err != nil {
t.Fatal(err)
}
root := filepath.Join(bundle, "production-testing")
pipeline := filepath.Join(root, "narratio.yml")
if err := os.Rename(filepath.Join(root, "pipeline.yml"), pipeline); err != nil {
t.Fatal(err)
}
f, err := os.OpenFile(pipeline, os.O_APPEND|os.O_WRONLY, 0)
if err != nil {
t.Fatal(err)
}
if _, err := f.WriteString("\naudita:\n credentials: [NARRATIO_BUNDLE_TEST_KEY]\n"); err != nil {
t.Fatal(err)
}
if err := f.Close(); err != nil {
t.Fatal(err)
}
const secretName = "NARRATIO_BUNDLE_TEST_KEY"
const secretValue = "synthetic-bundle-secret"
restoreEnvAfterTest(t, secretName)
if err := os.Unsetenv(secretName); err != nil {
t.Fatal(err)
}
secrets := filepath.Join(bundle, "secrets")
mustWriteSecretFile(t, filepath.Join(secrets, secretName), secretValue)
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 _, 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)
}
}
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())
}
workspace := filepath.Join(root, "conf.d", "workspace")
if _, err := os.Stat(workspace); !os.IsNotExist(err) {
t.Fatalf("inspection created workspace: %v", err)
}
var execution *config.Config
executor := func(_ context.Context, cfg *config.Config, _ BoundedPlan, _ RunOptions) (*RunSummary, error) {
execution = cfg
return &RunSummary{SessionID: "2026-05-03"}, nil
}
runArgs := append([]string{"2026-05-03", "--session", filepath.Join(bundle, "session.local-audio.yml"), "--overlay", "testing"}, common...)
var plan bytes.Buffer
planArgs := append(append([]string{}, runArgs...), "--from", "prepare", "--through", "prepare")
if err := Plan(context.Background(), planArgs, &plan); err != nil {
t.Fatal(err)
}
if !strings.Contains(plan.String(), "prepare: run") {
t.Fatalf("unexpected plan: %s", plan.String())
}
if _, err := os.Stat(workspace); !os.IsNotExist(err) {
t.Fatalf("plan created workspace: %v", err)
}
if err := runWithPipelineExecutor(context.Background(), runArgs, io.Discard, executor); err != nil {
t.Fatal(err)
}
if execution == nil || execution.Session.Inputs.AudioDir != filepath.Join(bundle, "audio") || execution.Campaign.Inputs.PartyFile != filepath.Join(bundle, "campaigns", "sample-campaign", "party.yml") {
t.Fatalf("execution did not resolve imported session and campaign resources: %+v", execution)
}
if execution.Pipeline.Audita.ProposalProfile != "narratio-testing-model-placeholder" {
t.Fatalf("execution did not use the inspected overlay: %q", execution.Pipeline.Audita.ProposalProfile)
}
if _, ok := execution.Pipeline.Scriptorium.Artifacts["character_meta_arannis"]; !ok {
t.Fatal("execution did not expand the inspected party family")
}
}