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

+2
View File
@@ -148,3 +148,5 @@ Q-040 block boundaries (DD-016, cl100k): Quick Reference 8,728 → 8,769 (+41),
DD-017 stable E7006 reasons (cl100k): Quick Reference 8,769 → 8,807 (+38), other source docs 65,012 → 65,799 (+787), full source 73,781 → 74,606 (+1.12%). o200k groups are 8,843 / 66,001 / 74,844; Qwen2.5 9,077 / 67,402 / 76,479. AIR grows 46,300 → 46,937 (+637, +1.38%), 179,282 → 182,254 bytes, because the shared diagnostic registry includes the 28 source categories. library/std.md is unchanged. One structured discriminator replaces prose classification; there is no new code, programming syntax, verifier/runtime state or repair application. Historical reasons remain unknown. No empirical MCC benefit is claimed.
RFC 0037 related positions (cl100k): Quick Reference 8,807 → 8,859 (+52), other source docs 65,799 → 66,195 (+396), full source 74,606 → 75,054 (+0.60%). o200k groups are 8,895 / 66,397 / 75,292; Qwen2.5 9,135 / 67,810 / 76,945. AIR grows 46,937 → 47,328 (+391, +0.83%), 182,254 → 184,060 bytes; library/std.md is unchanged. Two factual roles locate an existing selected conflict or spawn; there is no new programming syntax, diagnostic code, semantic verifier state or runtime rule. One constant-sized origin is carried on each existing task loan. Necessary schema/source-map rules enter the bundles; RFC rationale does not. No empirical MCC benefit is claimed.
DD-019 unique diagnostic fields (cl100k): Quick Reference stays 8,859; other source docs 66,195 → 66,312 (+117), full source 75,054 → 75,171 (+0.16%). o200k groups are 8,895 / 66,517 / 75,412; Qwen2.5 9,135 / 67,933 / 77,068. AIR grows 47,328 → 47,445 (+117, +0.25%), 184,060 → 184,628 bytes; library/std.md is unchanged. Explicit payload names preserve the stable envelope and both guard/borrow identities. No language concept, syntax, code, verifier/runtime state or repair application is added; clients that previously read a capability payload as `kind` use `capability_kind`. No empirical MCC benefit is claimed.
+6
View File
@@ -107,3 +107,9 @@ Reason: a shared code cannot establish whether Copy moves occur often enough to
RFC 0037's implementation/spec integration is prepared under P6-7; formal RFC status remains Proposed for owner adoption. Spec 10 §2 and spec 15 §10 define one typed related record for each identified E2101/E2104 conflict and E4302 task. Definition lookup retains the selected conflict; loan metadata retains the creating spawn even when a cancelled join replaces its SSA handle. Source mapping is independent, and an absent mapping exposes AIR coordinates without a guessed source position. Primary selection, fields and duplicate suppression are unchanged. There is no enclosing-block inference, conflict enumeration or edit.
The invariant is unchanged acceptance, ownership/loan verification and deterministic interpreter behavior; provenance never participates in liveness or transfer decisions. AIR format 0, syntax, effects/capabilities and diagnostic codes are unchanged. Positive/rejected source/AIR fixtures, repeated cancelled joins, CLI/package mapping and typed serialization tests check the contract. Bundle growth is measured in docs/agent/README.md. This improves factual repair context; no measured repair-cost or MCC claim is made, and RFC 0038 stays deferred pending evidence.
## DD-019 — Unique diagnostic fields preserve the machine envelope
Compatibility review found legacy payload collisions: unsupported AIR narrowing and unknown source capability kinds each emitted a second `kind`, and unlock with a live guard borrow emitted `borrow` twice. Ordinary JSON consumers lost the stable machine kind or one identity. Spec 10 §2 requires unique names and reserves envelope fields. Capability payloads use `capability_kind`; unlock reports the selected `borrow` and its `guard` separately, retaining the borrow seen by former last-key-wins readers. Clients must read the capability payload by its new name; stable diagnostic kinds are restored rather than redefined.
These are diagnostic corrections, not new source/AIR or ownership/concurrency rules. Existing rejection codes, positions, conflict selection, guard/loan state and deterministic execution remain unchanged; valid capabilities and guard programs remain accepted. Pipeline/CLI tests reproduce the three cases, the verifier unit helper checks payload uniqueness across its existing rejection tests, and conformance validates every final mapped diagnostic's fields and serialized JSON. The invariant is an unambiguous machine diagnostic without hidden loss of context. Budget growth is recorded in docs/agent/README.md; no repair candidate or measured MCC benefit is introduced.
+2
View File
@@ -51,3 +51,5 @@ Diagnostic JSON is a stable interface. Snapshot tests on the full JSON (not only
`python3 tests/hosted/source_diagnostic_reasons.py` checks stable E7006 categories, generic/package propagation and serialization. From `tools/eval`, `python3 -m unittest discover tests` checks reporting alongside the harness. `ajieval summary` reports observed `(code, reason)` occurrences and affected runs with log coverage; `profile` and `checkpoint` expose per-run pairs. Existing compact code extraction is preserved. Only whole JSON diagnostic lines classify a reason: unparsed or historical records remain unknown; new reason strings are retained. Missing logs are unavailable. These counts cover the recorded command outputs, not a pre-acceptance cutoff or the true frequency of unobserved errors; future cohort methodology must specify those separately.
`python3 tests/hosted/related_locations.py` checks factual E2101/E2104 definitions and E4302 spawns in public AIR/source rejects, exact definition coordinates (including parameters and second split results), independent annotation-map reconstruction, existing source deduplication, generics and explicit packages. Unit tests cover typed JSON/key order, absent related mappings and repeated cancelled-join handle replacement through the lowered-source pipeline. `zig build conformance -- --filter cancel_join --stress 200 --collect-every-step` exercises accepted cancellation counterparts under deterministic schedule seeds and several quanta. These checks add no repair or lifetime inference.
The CLI JSON reader rejects duplicate members instead of silently overwriting them; targeted capability-kind and live-guard cases check the stable machine `kind` and separate payload identities. Pipeline unit tests also parse those records with duplicate fields forbidden. `verifier.expectCodes` checks that all its diagnostics have distinct payload names that do not shadow the envelope (`diag.expectUniqueFields`). The conformance runner validates every final source/AIR diagnostic after lowering and mapping, including frontend-added fields, and parses its serialized JSON with duplicate members forbidden. This adds no production/runtime check.
+6
View File
@@ -176,3 +176,9 @@ Validation: full conformance passes 1,154/1,154; CLI passes 130 checks including
RFC 0037/DD-018 prepares spec integration and implementation of one factual `related_locations` record on identified E2101/E2104 conflicts and E4302 tasks. Existing definition positions identify selected borrows; each task loan carries constant-sized spawn metadata through cancelled-join handle replacement. Typed JSON appends the array after the old envelope. Each related position maps independently, including imports and specializations; absent mappings omit source coordinates while retaining AIR coordinates. Primary fields, first-conflict selection and source duplicate suppression are unchanged; no block/repair inference, code, syntax, feature, transfer rule or runtime change is introduced. RFC 0037 remains Proposed for owner adoption; P6-7 remains open for the remaining span/twin work.
Validation: unit tests and full conformance pass, 1,160/1,160 with no failures or pending tests, including six new source/AIR positive/rejected counterparts and repeated cancelled joins. CLI passes 267 checks/161 context records, covering public rejects, function parameters, second split results, call-result definitions, exact source mapping from public annotations, generics and packages. Unit tests cover typed/key-ordered JSON, missing mappings, two cancelled-handle replacements and deduplication retaining the first conflict. Cancellation conformance passes with collection before every instruction and 200 schedule seeds under multiple quanta. Across 1,199 original public AIR/source/std/example files, removal of only the appended metadata recovers byte-identical outputs and exit codes, including all 701 successful check/lower outputs. Source construct coverage remains 120/120. Independent read-only review by Claude found no implementation issues. Bundle measurements are recorded in docs/agent/README.md; frozen evaluation inputs remain untouched. No repair-cost experiment or RFC 0038 implementation is included.
## P6-7 diagnostic-envelope correction (2026-10-07)
DD-019/spec 10 §2 fixes three legacy duplicate-field emissions discovered during compatibility review: E3202 unsupported narrowing and E7002 unknown source capability kinds use `capability_kind`, preserving the stable envelope `kind`; E2102 unlock with a live child borrow reports `borrow` and `guard` separately. Consumers previously reading a capability payload from the duplicate `kind` must use `capability_kind`; former last-key-wins readers retain the selected E2102 borrow identity. Codes, rejection/transfer rules, primary positions, messages, guard/loan state and deterministic execution are unchanged. No new syntax, feature or repair is introduced; P6-7 remains open.
Validation: the new pipeline test reproduces a failure before correction and passes afterwards; unit tests and full conformance pass, 1,162/1,162 with no failures or pending tests, including a source unknown/known capability pair. All final source/AIR diagnostics are checked for noncolliding fields and parsed as JSON with duplicate members forbidden, after frontend fields and source mapping. CLI passes 271 checks/161 context records with a strict JSON reader and targeted checks for all three corrected forms. Across the 1,199-file compatibility baseline, only the two known legacy AIR collision records change beyond the earlier related metadata; all successful outputs and exit codes remain identical. Independent read-only review by Claude found no missed emission or implementation defect; its recommendation to validate final mapped records is implemented in conformance. Budgets are recorded in docs/agent/README.md; frozen evaluation inputs and historical reports are unchanged.
+2 -2
View File
@@ -47,7 +47,7 @@ Draft registry. Codes are stable once released in a tagged compiler version.
| E3002 | resource.leak | Linear resource has no terminal consumption path |
| E3101 | effect.undeclared | Callee effect absent from caller contract |
| E3201 | capability.missing | Required authority unavailable |
| E3202 | capability.widen | Attempt to widen delegated authority |
| E3202 | capability.widen | Attempt to widen delegated authority; unsupported narrowing forms identify `capability_kind` |
## E4xxx — Concurrency
@@ -87,7 +87,7 @@ Only problems that exist because of the frontend. Everything the verifier decide
| Code | Kind | Meaning |
|---|---|---|
| E7001 | source.syntax | Malformed `.aji` source |
| E7002 | source.unknown_name | Undefined variable, function, type, field or variant |
| E7002 | source.unknown_name | Undefined variable, function, type, field or variant; an unknown capability kind is `capability_kind` |
| E7003 | source.missing_move | Named linear value consumed without `move` |
| E7004 | source.not_exhaustive | `match` misses an outcome, variant or default |
| E7005 | source.type_mismatch | Expression has the wrong type in a source position |
@@ -16,6 +16,8 @@ Every verifier/compiler error has:
Code-specific `reason` values MUST be registered and stable; consumers MUST NOT derive them from human messages. E7006 requires the categories in spec 15 §10 and `reference/error-codes.md`.
Diagnostic JSON objects MUST have unique member names. Code-specific fields MUST NOT shadow envelope names (`code`, `kind`, `severity`, `file`, `line`, `col`, `message`, `repair_candidates`, `related_locations`). E3202 for an unsupported narrowing form and E7002 for an unknown capability kind use `capability_kind`; E2102 for unlock with a live guard borrow identifies `guard` and `borrow` separately. These fields change no rejection or primary-position rule.
`related_locations` MAY provide ordered, non-binding factual context; the covered forms below MUST provide exactly one record for the already selected conflict. Other forms MUST NOT invent a value or task.
| Diagnostic field | Related `role` | Related `value` | Position |
+56
View File
@@ -254,6 +254,62 @@ test "mapped E4302 keeps spawn through repeated cancelled joins and missing mapp
}
}
test "diagnostic payloads preserve stable kinds and distinguish guards from borrows" {
const inputs = [_]struct { file: []const u8, source: []const u8, code: []const u8, field: []const u8, value: []const u8 }{
.{ .file = "unknown.aji", .source = "module t fn main(c:cap<unknown>)->void effects [] {}", .code = "E7002", .field = "capability_kind", .value = "unknown" },
.{ .file = "narrow.air", .source =
\\module t
\\air 0
\\lang 0.1
\\features [capabilities, effects, ownership]
\\fn @f(%c: cap<io.write>, %n: usize) -> void
\\effects []
\\entry:
\\ cap.narrow.budget %c, %n, ok -> @ok, err -> @err
\\ok(%d: cap<io.write>):
\\ ret
\\err(%e: cap_error):
\\ ret
\\
, .code = "E3202", .field = "capability_kind", .value = "io.write" },
.{ .file = "guard.air", .source =
\\module t
\\air 0
\\lang 0.1
\\features [cancellation, effects, ownership, sync, tasks]
\\fn @f(%a: ref<mutex<u64>>) -> void
\\effects [task.wait]
\\entry:
\\ mutex.lock %a, ok -> @locked, cancelled -> @out
\\locked(%g: guard<u64>):
\\ %p = mutex.borrow %g
\\ mutex.unlock %g
\\ borrow.end %p
\\ ret
\\out:
\\ ret
\\
, .code = "E2102", .field = "guard", .value = "%g" },
};
var a: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer a.deinit();
const arena = a.allocator();
for (inputs) |input| {
const report = try checkFile(arena, input.file, input.source);
try std.testing.expectEqual(@as(usize, 1), report.diagnostics.len);
const d = report.diagnostics[0];
try std.testing.expectEqualStrings(input.code, d.code.id);
try diag.expectUniqueFields(d);
var writer: std.Io.Writer.Allocating = .init(arena);
try d.writeJson(&writer.writer);
const parsed = try std.json.parseFromSlice(std.json.Value, arena, writer.written(), .{ .duplicate_field_behavior = .@"error" });
defer parsed.deinit();
try std.testing.expectEqualStrings(d.code.kind, parsed.value.object.get("kind").?.string);
try std.testing.expectEqualStrings(input.value, parsed.value.object.get(input.field).?.string);
if (std.mem.eql(u8, input.code, "E2102")) try std.testing.expectEqualStrings("%p", parsed.value.object.get("borrow").?.string);
}
}
test "standard type diagnostics use the public source name" {
var a = std.heap.ArenaAllocator.init(std.testing.allocator);
defer a.deinit();
+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;
+1 -1
View File
@@ -716,7 +716,7 @@ const Lowerer = struct {
};
},
.cap => |k| {
if (authority.kindIndex(k) == null) return l.fail("E7002", t.span, "unknown capability kind", &.{.{ .name = "kind", .value = k }});
if (authority.kindIndex(k) == null) return l.fail("E7002", t.span, "unknown capability kind", &.{.{ .name = "capability_kind", .value = k }});
return .{ .cap = k };
},
.file => |m| {
+4 -1
View File
@@ -120,7 +120,10 @@ pub fn expectCodes(src: []const u8, codes: []const []const u8) !void {
for (ds) |d| std.debug.print("got {s} {s} at {d}:{d}\n", .{ d.code.id, d.message, d.span.?.line, d.span.?.col });
return error.TestExpectedEqual;
}
for (codes, ds) |c, d| try std.testing.expectEqualStrings(c, d.code.id);
for (codes, ds) |c, d| {
try std.testing.expectEqualStrings(c, d.code.id);
try diag.expectUniqueFields(d);
}
}
pub const test_header = "module t\nair 0\nlang 0.1\nfeatures []\n";
+1 -1
View File
@@ -654,7 +654,7 @@ fn step(w: *Walker, inst: air.Inst) !void {
.mutex_unlock => |g| {
if (!w.live[g]) return w.report("E2002", "linear value consumed twice", g, null);
for (w.live, 0..) |is_live, b| if (is_live and w.info[b] != null and w.info[b].?.root == g) {
try w.report("E2102", "guard unlocked while a borrow from it is live", g, .{ "borrow", @intCast(b) });
try w.report("E2102", "guard unlocked while a borrow from it is live", @intCast(b), .{ "guard", g });
break;
};
w.live[g] = false;
+1 -1
View File
@@ -1165,7 +1165,7 @@ fn checkInst(fc: *FnCtx, inst: air.Inst) !void {
// an attempt to widen (spec 05 §10.4).
if (!air.authority.hasForm(t.cap, x.form)) try fc.c.report("E3202", span, "narrowing form not defined for this capability kind", &.{
.{ .name = "function", .value = .{ .str = f.name } },
.{ .name = "kind", .value = .{ .str = air.authority.kinds[t.cap].name } },
.{ .name = "capability_kind", .value = .{ .str = air.authority.kinds[t.cap].name } },
.{ .name = "form", .value = .{ .str = x.form } },
});
if (std.mem.eql(u8, x.form, "budget")) {
@@ -0,0 +1,5 @@
// expect: accept
// phase: 6
// spec: docs/spec/10-diagnostics-and-agent-protocol.md §2
module diagnostic.known_capability
fn main(c: cap<mem.alloc>) -> void effects [] {}
@@ -0,0 +1,5 @@
// expect: reject E7002
// phase: 6
// spec: docs/spec/10-diagnostics-and-agent-protocol.md §2
module diagnostic.unknown_capability
fn main(c: cap<unknown>) -> void effects [] {}
+27 -6
View File
@@ -20,6 +20,16 @@ def cli(*args, code=0):
return p.stdout
def decode_json(output):
def unique_object(pairs):
result = {}
for key, value in pairs:
assert key not in result, ('duplicate JSON member', key, output)
result[key] = value
return result
return json.loads(output, object_pairs_hook=unique_object)
def related(error, source=False):
global covered
field = 'task' if error['code'] == 'E4302' else 'conflicts_with'
@@ -59,13 +69,13 @@ def air_origin(text, error):
def source_check(root, *args):
errors = [json.loads(line) for line in cli('check', *args, code=1).splitlines()]
errors = [decode_json(line) for line in cli('check', *args, code=1).splitlines()]
assert cli('check', *args, code=1) == cli('check', *args, code=1)
canonical = cli('lower', *args)
annotated = cli('lower', '--annotate', *args)
path = root / 'lowered.air'
path.write_text(canonical)
raw = [json.loads(line) for line in cli('check', path, code=1).splitlines()]
raw = [decode_json(line) for line in cli('check', path, code=1).splitlines()]
# Independently reconstruct the public annotation map, then use the
# unchanged primary-code/location deduplication to predict source output.
mapping = {}
@@ -165,7 +175,7 @@ entry:
text = 'module definitions\nair 0\nlang 0.1\nfeatures [arrays, effects, ownership]\n' + body + callees
path = root / 'definitions.air'
path.write_text(text)
errors = [json.loads(line) for line in cli('check', path, code=1).splitlines()]
errors = [decode_json(line) for line in cli('check', path, code=1).splitlines()]
assert len(errors) == 1 and errors[0]['code'] == 'E2101', errors
air_origin(text, errors[0])
context = errors[0]['related_locations'][0]
@@ -178,7 +188,7 @@ entry:
text = path.read_text()
if not re.search(r'^; expect: reject .*E(?:2101|2104|4302)', text, re.M):
continue
errors = [json.loads(line) for line in cli('check', path, code=1).splitlines()]
errors = [decode_json(line) for line in cli('check', path, code=1).splitlines()]
for error in errors:
air_origin(text, error)
for path in sorted((corpus / 'source').rglob('*.aji')):
@@ -191,7 +201,7 @@ entry:
errors = source_check(root, corpus / 'source/related_locations/borrow_live.aji')
assert errors[0]['line'] == 8 and errors[0]['related_locations'][0]['line'] == 7
assert json.loads(cli('run', '--fuel', '10000', corpus / 'source/related_locations/borrow_ended.aji'))['value'] == 2
assert decode_json(cli('run', '--fuel', '10000', corpus / 'source/related_locations/borrow_ended.aji'))['value'] == 2
# A returned view's definition is the caller's call, not the callee's from.
errors = source_check(root, corpus / 'source/borrow_returns/parent_access.aji')
context = errors[0]['related_locations'][0]
@@ -216,7 +226,18 @@ entry:
# Codes outside the scope keep the old envelope.
other = root / 'other.aji'
other.write_text('module other fn main()->u64 effects [] {return true;}')
assert 'related_locations' not in json.loads(cli('check', other, code=1))
assert 'related_locations' not in decode_json(cli('check', other, code=1))
for fixture, code, kind, field, value in (
('phase2/reject/unknown_narrowing_form.air', 'E3202', 'capability.widen', 'capability_kind', 'io.write'),
('phase3/reject/sync_unlock_live_borrow.air', 'E2102', 'borrow.outlives_owner', 'guard', '%g'),
('source/diagnostic_envelope/capability_kind_unknown.aji', 'E7002', 'source.unknown_name', 'capability_kind', 'unknown'),
):
error = decode_json(cli('check', corpus / fixture, code=1))
assert error['code'] == code and error['kind'] == kind and error[field] == value, error
if field == 'guard':
assert error['borrow'] == '%p', error
cli('check', corpus / 'source/diagnostic_envelope/capability_kind_known.aji')
assert covered > 0
print(f'related location CLI passed ({checks} checks; {covered} context records)')
+29
View File
@@ -161,6 +161,7 @@ fn runSource(arena: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, rel: []const
}
const report = try aji.check.checkWithModules(arena, path, source, modules.items);
if (report.status == .unimplemented) return .{ .outcome = .pending, .detail = report.missing_stage };
if (try diagnosticIssue(arena, report.diagnostics)) |issue| return .{ .outcome = .fail, .detail = issue };
if (report.lowered) |lowered| {
const again = try aji.frontend.compileWithModules(arena, path, source, modules.items);
if (again != .ok or !std.mem.eql(u8, again.ok.air, lowered.air)) return .{ .outcome = .fail, .detail = "lowering is not deterministic" };
@@ -255,6 +256,20 @@ fn label(o: Outcome) []const u8 {
const Result = struct { outcome: Outcome, detail: []const u8 = "" };
/// Validate the final API records, after frontend fields and source mapping.
/// This is a conformance assertion, never a program acceptance rule.
fn diagnosticIssue(arena: std.mem.Allocator, diagnostics: []const aji.diag.Diagnostic) !?[]const u8 {
for (diagnostics) |d| {
if (!aji.diag.hasUniqueFields(d)) return try std.fmt.allocPrint(arena, "{s}: duplicate or reserved diagnostic payload field", .{d.code.id});
var writer: std.Io.Writer.Allocating = .init(arena);
try d.writeJson(&writer.writer);
const parsed = std.json.parseFromSlice(std.json.Value, arena, writer.written(), .{ .duplicate_field_behavior = .@"error" }) catch |err|
return try std.fmt.allocPrint(arena, "{s}: invalid diagnostic JSON: {t}", .{ d.code.id, err });
parsed.deinit();
}
return null;
}
fn runOne(arena: std.mem.Allocator, path: []const u8, source: []const u8) !Result {
const header = parseHeader(arena, source) catch |err|
return .{ .outcome = .fail, .detail = try std.fmt.allocPrint(arena, "bad header: {t}", .{err}) };
@@ -277,6 +292,7 @@ fn runOne(arena: std.mem.Allocator, path: []const u8, source: []const u8) !Resul
const report = try aji.check.checkAir(arena, path, body);
if (report.status == .unimplemented)
return .{ .outcome = .pending, .detail = report.missing_stage };
if (try diagnosticIssue(arena, report.diagnostics)) |issue| return .{ .outcome = .fail, .detail = issue };
var got: std.ArrayList([]const u8) = .empty;
for (report.diagnostics) |d| {
@@ -605,3 +621,16 @@ test parseHeader {
try std.testing.expectEqualStrings("E5001", h.expect.reject[0]);
try std.testing.expectError(error.UnknownCode, parseHeader(arena_state.allocator(), "; expect: reject E9999\n"));
}
test "diagnostic API validation rejects collisions after source mapping" {
var a: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer a.deinit();
const arena = a.allocator();
const valid: aji.diag.Diagnostic = .{ .code = aji.diag.lookup("E7002").?, .fields = &.{.{ .name = "capability_kind", .value = .{ .str = "unknown" } }} };
try std.testing.expect((try diagnosticIssue(arena, &.{valid})) == null);
var bad = valid;
bad.fields = &.{.{ .name = "kind", .value = .{ .str = "unknown" } }};
try std.testing.expect((try diagnosticIssue(arena, &.{bad})) != null);
bad.fields = &.{ .{ .name = "air_line", .value = .{ .int = 3 } }, .{ .name = "air_line", .value = .{ .int = 8 } } };
try std.testing.expect((try diagnosticIssue(arena, &.{bad})) != null);
}