diag: preserve envelope fields and reject JSON key collisions in tests

This commit is contained in:
dev committed 2026-10-07 19:28:36 +03:00
1 parent 8ee0f4c2bf
commit 364eb57bbc
16 files changed
+166 -12

No files matched your search

+17
View File
@@ -292,6 +292,23 @@ test "related locations are typed, ordered and appended after existing fields" {
, w.buffered());
}
/// Regression invariant used by verifier/pipeline tests; never a runtime
/// language check. Payload names cannot hide the stable envelope or each other.
pub fn expectUniqueFields(d: Diagnostic) !void {
try std.testing.expect(hasUniqueFields(d));
}
/// Diagnostic contract validation for test tooling, including final source
/// mappings; not used to make any verifier/runtime acceptance decision.
pub fn hasUniqueFields(d: Diagnostic) bool {
const envelope = [_][]const u8{ "code", "kind", "severity", "file", "line", "col", "message", "repair_candidates", "related_locations" };
for (d.fields, 0..) |f, i| {
for (envelope) |reserved| if (std.mem.eql(u8, f.name, reserved)) return false;
for (d.fields[0..i]) |previous| if (std.mem.eql(u8, previous.name, f.name)) return false;
}
return true;
}
test "registry mirrors docs/reference/error-codes.md" {
const md = @embedFile("error_codes_md");
var seen: usize = 0;