|
4 | 4 | "encoding/json" |
5 | 5 | "os" |
6 | 6 | "testing" |
| 7 | + |
| 8 | + "github.com/GoCodeAlone/workflow/plugin" |
7 | 9 | ) |
8 | 10 |
|
9 | 11 | // TestModuleSchemas verifies that the plugin's SchemaProvider returns schema |
@@ -77,7 +79,7 @@ func TestPluginStepSchemasJSON(t *testing.T) { |
77 | 79 | // Locate plugin.json relative to the repository root (one level up from internal/). |
78 | 80 | data, err := os.ReadFile("../plugin.json") |
79 | 81 | if err != nil { |
80 | | - t.Skipf("plugin.json not found (skipping in isolated test environments): %v", err) |
| 82 | + t.Fatalf("plugin.json not found — every build must ship a contract manifest: %v", err) |
81 | 83 | } |
82 | 84 |
|
83 | 85 | var manifest struct { |
@@ -110,3 +112,35 @@ func TestPluginStepSchemasJSON(t *testing.T) { |
110 | 112 | len(manifest.StepSchemas), len(manifest.StepTypes)) |
111 | 113 | } |
112 | 114 | } |
| 115 | + |
| 116 | +// TestPluginManifestEngineValidation verifies that plugin.json is parseable as a |
| 117 | +// workflow engine PluginManifest and that Validate() passes required-field checks. |
| 118 | +func TestPluginManifestEngineValidation(t *testing.T) { |
| 119 | + m, err := plugin.LoadManifest("../plugin.json") |
| 120 | + if err != nil { |
| 121 | + t.Fatalf("plugin.LoadManifest: %v", err) |
| 122 | + } |
| 123 | + if err := m.Validate(); err != nil { |
| 124 | + t.Fatalf("plugin.json fails engine manifest validation: %v", err) |
| 125 | + } |
| 126 | + // Strict contract requirements: must declare at least one module or step type. |
| 127 | + if len(m.ModuleTypes) == 0 && len(m.StepTypes) == 0 { |
| 128 | + t.Error("plugin.json: must advertise at least one moduleType or stepType for strict contracts") |
| 129 | + } |
| 130 | + // StepSchemas must be present when step types are declared. |
| 131 | + if len(m.StepTypes) > 0 && len(m.StepSchemas) == 0 { |
| 132 | + t.Error("plugin.json: stepSchemas is required when stepTypes are declared (missing_step_contract_descriptor)") |
| 133 | + } |
| 134 | + // Every step type must have a schema entry. |
| 135 | + schemaSet := make(map[string]bool, len(m.StepSchemas)) |
| 136 | + for _, s := range m.StepSchemas { |
| 137 | + if s != nil { |
| 138 | + schemaSet[s.Type] = true |
| 139 | + } |
| 140 | + } |
| 141 | + for _, st := range m.StepTypes { |
| 142 | + if !schemaSet[st] { |
| 143 | + t.Errorf("plugin.json: stepType %q has no stepSchema (missing_step_contract_descriptor)", st) |
| 144 | + } |
| 145 | + } |
| 146 | +} |
0 commit comments