package workflow import ( "fmt" "strings" "testing" ) // TestParseDefinitionRejectsUnknownStepSettings pins the step contract at // save: a settings key the step type does not read is refused, so a misspelt // key cannot be dropped silently. func TestParseDefinitionRejectsUnknownStepSettings(t *testing.T) { types := []StepType{AgentRunStepType(), CommandRunStepType(), DiffRulesStepType(), FinishStepType(), WorkflowCallStepType()} types = append(types, ControlStepTypes()...) types = append(types, RepoStepTypes()...) types = append(types, ReviewStepTypes()...) registry := StepRegistry{} for _, st := range types { registry[st.Name] = st.Factory } tests := []struct { name, step, wantErr string }{ {name: "agent.run", step: `{type: agent.run, settings: {mission: m, readOnly: true}}`, wantErr: "readOnly"}, {name: "command.run", step: `{type: command.run, settings: {run: [{name: build, argv: [make]}], ifEmpty: pass}}`, wantErr: "ifEmpty"}, {name: "workflow.finish", step: `{type: workflow.finish, settings: {status: completed, reason: r}}`, wantErr: "reason"}, {name: "workflow.call", step: `{id: c, type: workflow.call, settings: {workflow: other, wiat: true}}`, wantErr: "wiat"}, {name: "repo.prepare", step: `{type: repo.prepare, settings: {brnach: task}}`, wantErr: "brnach"}, {name: "a step that takes no settings", step: `{type: forge.close-issue, settings: {comment: done}}`, wantErr: "takes no settings"}, {name: "known settings", step: `{type: agent.run, settings: {mission: m, read_only: true}}`}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { src := fmt.Sprintf("id: w\nrepository: required\nsteps:\n - %s\n", tt.step) _, err := ParseDefinition(src, registry) if tt.wantErr == "" { if err != nil { t.Fatalf("err = %v, want none", err) } return } if err == nil || !strings.Contains(err.Error(), tt.wantErr) { t.Fatalf("err = %v, want one naming %q", err, tt.wantErr) } }) } }