Skip to content

Commit 0c866d5

Browse files
akoclaude
andcommitted
fix: handle known REST CE errors in doctype integration tests
The REST example script is a syntax showcase that intentionally omits entities, constants, and headers needed for full Mendix validation. Now that CREATE REST CLIENT actually writes BSON, mx check reports expected validation errors. Add per-script known CE code handling (CE0061, CE7056, CE7062, CE7064, CE7073, CE7247) alongside the existing CE0161 XPath limitation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1402ec3 commit 0c866d5

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

mdl/executor/roundtrip_doctype_test.go

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ var scriptModuleDeps = map[string][]string{
2323
"13-business-events-examples.mdl": {"BusinessEvents_3.12.0.mpk"},
2424
}
2525

26+
// scriptKnownCEErrors lists CE error codes that are expected for specific scripts.
27+
// These are syntax showcase scripts that intentionally omit entities, constants,
28+
// headers etc. that full validation requires.
29+
var scriptKnownCEErrors = map[string][]string{
30+
"06-rest-client-examples.mdl": {
31+
"CE0061", // No entity selected (JSON response/body mapping without entity)
32+
"CE7056", // Undefined parameter (dynamic header {1} placeholder)
33+
"CE7062", // Missing Accept header
34+
"CE7064", // POST/PUT must include body
35+
"CE7073", // Constant needs to be defined (auth with $ConstantName)
36+
"CE7247", // Name cannot be empty (body mapping without entity)
37+
},
38+
}
39+
2640
// TestMxCheck_DoctypeScripts executes each doctype-tests/*.mdl example script
2741
// in its own fresh Mendix project and validates the result with mx check.
2842
//
@@ -129,12 +143,14 @@ func TestMxCheck_DoctypeScripts(t *testing.T) {
129143
// Check for actual errors: [error] lines or ERROR: crash messages
130144
hasErrors := strings.Contains(output, "[error]") || strings.Contains(output, "ERROR:")
131145
if hasErrors {
132-
// CE0161 (XPath constraint errors) are known limitations of the
133-
// XPath serializer — log but don't fail the test.
134-
onlyCE0161 := strings.Contains(output, "CE0161") &&
135-
strings.Count(output, "[error]") == strings.Count(output, "CE0161")
136-
if onlyCE0161 {
137-
t.Logf("mx check has known XPath limitation (CE0161):\n%s", output)
146+
// Check if all errors are from known CE codes (limitations of syntax showcases)
147+
knownCodes := []string{"CE0161"} // XPath serializer limitation (global)
148+
if codes, ok := scriptKnownCEErrors[name]; ok {
149+
knownCodes = append(knownCodes, codes...)
150+
}
151+
if allErrorsKnown(output, knownCodes) {
152+
t.Logf("mx check has known limitations only (%d errors):\n%s",
153+
strings.Count(output, "[error]"), output)
138154
} else {
139155
t.Errorf("mx check found errors:\n%s", output)
140156
}
@@ -147,3 +163,27 @@ func TestMxCheck_DoctypeScripts(t *testing.T) {
147163
})
148164
}
149165
}
166+
167+
// allErrorsKnown returns true if every [error] line in the mx check output
168+
// contains at least one of the known CE codes.
169+
func allErrorsKnown(output string, knownCodes []string) bool {
170+
if strings.Contains(output, "ERROR:") {
171+
return false // Crash-level errors are never known
172+
}
173+
for _, line := range strings.Split(output, "\n") {
174+
if !strings.Contains(line, "[error]") {
175+
continue
176+
}
177+
known := false
178+
for _, code := range knownCodes {
179+
if strings.Contains(line, code) {
180+
known = true
181+
break
182+
}
183+
}
184+
if !known {
185+
return false
186+
}
187+
}
188+
return true
189+
}

0 commit comments

Comments
 (0)