Skip to content

Commit 4dde6cf

Browse files
dmealingclaude
andcommitted
chore(conformance): pre-merge simplifier pass — harness polish
Tighten the harness changes added in e682311 without touching behavior or the cross-port assertion shape. All four ports' conformance suites stay green (TS 182 / C# 302 / Java 182 / Python 94). TS adapter.ts — extract a single `relativize()` for the envelope file normalization (it was duplicated across two near-identical json/yaml + merged/resolved branches) and collapse those branches into one block now that the only divergence (an optional jsonPath on resolved) is handled by a single conditional spread. C# ConformanceAdapter.BuildEnvelope — replace the if/return ladder with a `switch` expression and a local `Rel(files)` helper so the per-format-source mapping is one column. YamlConformanceTests — unify BuildYamlEnvelope and BuildYamlEnvelopeFromException to share a single switch expression (their inputs differ only in the carrier type). Java FixtureLint — collapse the two-arg `readJson(path, bytes)` helper (the `path` was unused) into a single-arg `readJsonFile(Path)` that does its own file read. ConformanceTest — drop the unused `import java.util.Arrays`. YamlConformanceTest — drop the unused `parseExpectedErrors(Path)` helper (only the envelope variant is still called). Python conformance_adapter._build_envelope — pull the repeated `tuple(_relativize(...) for f in env.files)` into a nested `rel_files()` so the four format branches each fit on one line. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c0fc085 commit 4dde6cf

7 files changed

Lines changed: 50 additions & 82 deletions

File tree

server/csharp/MetaObjects.Conformance.Tests/ConformanceAdapter.cs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,18 @@ public static LoadOutcome LoadFixture(string inputDir, IReadOnlyList<string> pro
8282
private static ErrorEnvelopeRecord BuildEnvelope(MetaError err, string inputDir)
8383
{
8484
var code = err.Code.ToString();
85-
var src = err.Envelope;
86-
if (src is JsonSource js)
85+
IReadOnlyList<string> Rel(IEnumerable<string> files) =>
86+
files.Select(f => RelativizeFile(f, inputDir)).ToList();
87+
return err.Envelope switch
8788
{
88-
return new ErrorEnvelopeRecord(code, "json", js.Files.Select(f => RelativizeFile(f, inputDir)).ToList(), js.JsonPath);
89-
}
90-
if (src is YamlSource ys)
91-
{
92-
return new ErrorEnvelopeRecord(code, "yaml", ys.Files.Select(f => RelativizeFile(f, inputDir)).ToList(), ys.JsonPath);
93-
}
94-
if (src is MergedSource ms)
95-
{
96-
return new ErrorEnvelopeRecord(code, "merged", ms.Files.Select(f => RelativizeFile(f, inputDir)).ToList(), ms.JsonPath);
97-
}
98-
if (src is ResolvedSource rs)
99-
{
100-
return new ErrorEnvelopeRecord(code, "resolved", rs.Files.Select(f => RelativizeFile(f, inputDir)).ToList(), rs.JsonPath);
101-
}
102-
if (src is CodeSource)
103-
{
104-
return new ErrorEnvelopeRecord(code, "code", new List<string>(), null);
105-
}
106-
// Pre-FR5a fallback: no envelope. Synthesize a minimal $-rooted JSON shape.
107-
return new ErrorEnvelopeRecord(code, "json", new List<string>(), "$");
89+
JsonSource js => new ErrorEnvelopeRecord(code, "json", Rel(js.Files), js.JsonPath),
90+
YamlSource ys => new ErrorEnvelopeRecord(code, "yaml", Rel(ys.Files), ys.JsonPath),
91+
MergedSource ms => new ErrorEnvelopeRecord(code, "merged", Rel(ms.Files), ms.JsonPath),
92+
ResolvedSource rs => new ErrorEnvelopeRecord(code, "resolved", Rel(rs.Files), rs.JsonPath),
93+
CodeSource => new ErrorEnvelopeRecord(code, "code", new List<string>(), null),
94+
// Pre-FR5a fallback: no envelope. Synthesize a minimal $-rooted JSON shape.
95+
_ => new ErrorEnvelopeRecord(code, "json", new List<string>(), "$"),
96+
};
10897
}
10998

11099
private static string RelativizeFile(string filePath, string inputDir)

server/csharp/MetaObjects.Conformance.Tests/YamlConformanceTests.cs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -394,29 +394,20 @@ void AddEnvelope(MetaError err)
394394
/// YAML fixtures' file token is always "input.yaml" (the authoring file
395395
/// the consumer sees), not the per-port internal source id.
396396
/// </summary>
397-
private static ErrorEnvelopeRecord BuildYamlEnvelope(MetaError err)
398-
{
399-
var code = err.Code.ToString();
400-
var env = err.Envelope;
401-
return env switch
397+
private static ErrorEnvelopeRecord BuildYamlEnvelope(MetaError err) =>
398+
BuildYamlEnvelope(err.Code.ToString(), err.Envelope);
399+
400+
private static ErrorEnvelopeRecord BuildYamlEnvelopeFromException(ParseException ex) =>
401+
BuildYamlEnvelope(ex.Code.ToString(), ex.Envelope);
402+
403+
private static ErrorEnvelopeRecord BuildYamlEnvelope(string code, ErrorSource? envelope) =>
404+
envelope switch
402405
{
403-
JsonSource js => new ErrorEnvelopeRecord(code, "json", new[] { "input.yaml" }, js.JsonPath),
404-
YamlSource ys => new ErrorEnvelopeRecord(code, "yaml", new[] { "input.yaml" }, ys.JsonPath),
405-
MergedSource ms => new ErrorEnvelopeRecord(code, "merged", ms.Files, ms.JsonPath),
406+
JsonSource js => new ErrorEnvelopeRecord(code, "json", new[] { "input.yaml" }, js.JsonPath),
407+
YamlSource ys => new ErrorEnvelopeRecord(code, "yaml", new[] { "input.yaml" }, ys.JsonPath),
408+
MergedSource ms => new ErrorEnvelopeRecord(code, "merged", ms.Files, ms.JsonPath),
406409
ResolvedSource rs => new ErrorEnvelopeRecord(code, "resolved", rs.Files, rs.JsonPath),
407-
CodeSource => new ErrorEnvelopeRecord(code, "code", Array.Empty<string>(), null),
408-
_ => new ErrorEnvelopeRecord(code, "yaml", new[] { "input.yaml" }, "$"),
410+
CodeSource => new ErrorEnvelopeRecord(code, "code", Array.Empty<string>(), null),
411+
_ => new ErrorEnvelopeRecord(code, "yaml", new[] { "input.yaml" }, "$"),
409412
};
410-
}
411-
412-
private static ErrorEnvelopeRecord BuildYamlEnvelopeFromException(ParseException ex)
413-
{
414-
var code = ex.Code.ToString();
415-
var env = ex.Envelope;
416-
if (env is JsonSource js)
417-
return new ErrorEnvelopeRecord(code, "json", new[] { "input.yaml" }, js.JsonPath);
418-
if (env is YamlSource ys)
419-
return new ErrorEnvelopeRecord(code, "yaml", new[] { "input.yaml" }, ys.JsonPath);
420-
return new ErrorEnvelopeRecord(code, "yaml", new[] { "input.yaml" }, "$");
421-
}
422413
}

server/java/metadata/src/test/java/com/metaobjects/conformance/ConformanceTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.nio.file.Path;
3737
import java.nio.file.Paths;
3838
import java.util.ArrayList;
39-
import java.util.Arrays;
4039
import java.util.Collection;
4140
import java.util.Collections;
4241
import java.util.LinkedHashSet;

server/java/metadata/src/test/java/com/metaobjects/conformance/FixtureLint.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public static List<String> lintFixture(FixtureDiscovery.Fixture fix,
6262
// expected-errors.json — each code must be in the registry
6363
if (fix.hasExpectedErrors) {
6464
try {
65-
JsonElement parsed = readJson(fix.dir.resolve("expected-errors.json").toString(),
66-
Files.readAllBytes(fix.dir.resolve("expected-errors.json")));
65+
JsonElement parsed = readJsonFile(fix.dir.resolve("expected-errors.json"));
6766
List<String> codes = parseExpectedErrors(parsed);
6867
for (String code : codes) {
6968
if (!registeredErrorCodes.contains(code)) {
@@ -79,8 +78,7 @@ public static List<String> lintFixture(FixtureDiscovery.Fixture fix,
7978
// script.json — shape + navigate-segment grammar
8079
if (fix.hasScript) {
8180
try {
82-
JsonElement parsed = readJson(fix.dir.resolve("script.json").toString(),
83-
Files.readAllBytes(fix.dir.resolve("script.json")));
81+
JsonElement parsed = readJsonFile(fix.dir.resolve("script.json"));
8482
lintScriptShape(fix, parsed, problems);
8583
} catch (Exception ex) {
8684
problems.add(fix.name + ": malformed script.json — " + ex.getMessage());
@@ -94,8 +92,9 @@ public static List<String> lintFixture(FixtureDiscovery.Fixture fix,
9492
// helpers
9593
// ---------------------------------------------------------------------
9694

97-
private static JsonElement readJson(String path, byte[] bytes) {
98-
return JsonParser.parseString(new String(bytes, StandardCharsets.UTF_8));
95+
private static JsonElement readJsonFile(java.nio.file.Path path) throws IOException {
96+
return JsonParser.parseString(
97+
new String(Files.readAllBytes(path), StandardCharsets.UTF_8));
9998
}
10099

101100
/**

server/java/metadata/src/test/java/com/metaobjects/conformance/YamlConformanceTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,6 @@ private static String scanMessageForErrorCode(String message) {
380380
return ErrorCode.ERR_UNKNOWN.name();
381381
}
382382

383-
private static List<String> parseExpectedErrors(Path file) {
384-
try {
385-
JsonElement el = JsonParser.parseString(new String(
386-
Files.readAllBytes(file), StandardCharsets.UTF_8));
387-
return FixtureLint.parseExpectedErrors(el);
388-
} catch (IOException ex) {
389-
throw new AssertionError("expected-errors.json read error: " + ex.getMessage(), ex);
390-
}
391-
}
392-
393383
/** Parse the YAML fixture's expected-errors.json into the FR5a envelope shape. */
394384
private static FixtureLint.ExpectedErrorsEnvelope parseExpectedErrorsEnvelope(Path file) {
395385
try {

server/python/tests/conformance/conformance_adapter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ def _build_envelope(err, input_dir: Path) -> ErrorEnvelopeRecord:
4949
"""Convert a Python MetaError into the cross-port envelope record."""
5050
code = err.code.name
5151
env = err.envelope
52+
53+
def rel_files() -> tuple[str, ...]:
54+
return tuple(_relativize(f, input_dir) for f in env.files)
55+
5256
if isinstance(env, JsonSource):
53-
files = tuple(_relativize(f, input_dir) for f in env.files)
54-
return ErrorEnvelopeRecord(code, "json", files, env.json_path)
57+
return ErrorEnvelopeRecord(code, "json", rel_files(), env.json_path)
5558
if isinstance(env, YamlSource):
56-
files = tuple(_relativize(f, input_dir) for f in env.files)
57-
return ErrorEnvelopeRecord(code, "yaml", files, env.json_path)
59+
return ErrorEnvelopeRecord(code, "yaml", rel_files(), env.json_path)
5860
if isinstance(env, MergedSource):
59-
files = tuple(_relativize(f, input_dir) for f in env.files)
60-
return ErrorEnvelopeRecord(code, "merged", files, env.json_path)
61+
return ErrorEnvelopeRecord(code, "merged", rel_files(), env.json_path)
6162
if isinstance(env, ResolvedSource):
62-
files = tuple(_relativize(f, input_dir) for f in env.files)
63-
return ErrorEnvelopeRecord(code, "resolved", files, env.json_path)
63+
return ErrorEnvelopeRecord(code, "resolved", rel_files(), env.json_path)
6464
if isinstance(env, CodeSource):
6565
return ErrorEnvelopeRecord(code, "code", (), None)
6666
# No envelope — synthesize a minimal root-level shape.

server/typescript/packages/metadata/test/conformance/adapter.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,23 @@ export const tsAdapter: ConformanceAdapter = {
6262
// relative to the fixture's inputDir so the cross-port assertion has a
6363
// portable file token. Errors without an envelope (rare; only non-ParseError)
6464
// synthesize a minimal $-rooted shape.
65+
function relativize(f: string): string {
66+
const fwd = f.replace(/\\/g, "/");
67+
return f.startsWith(inputDir) ? relative(inputDir, f).replace(/\\/g, "/") : fwd;
68+
}
6569
const envelopes: ErrorEnvelopeRecord[] = result.errors.map((err) => {
6670
if (err instanceof ParseError) {
6771
const src = err.source;
68-
if (src.format === "json" || src.format === "yaml") {
69-
const files = src.files.map((f) => {
70-
if (f.startsWith(inputDir)) return relative(inputDir, f).replace(/\\/g, "/");
71-
return f.replace(/\\/g, "/");
72-
});
73-
return { code: err.code, source: { format: src.format, files, jsonPath: src.jsonPath } };
74-
}
75-
if (src.format === "merged" || src.format === "resolved") {
76-
const files = src.files.map((f) => {
77-
if (f.startsWith(inputDir)) return relative(inputDir, f).replace(/\\/g, "/");
78-
return f.replace(/\\/g, "/");
79-
});
72+
if (src.format === "json" || src.format === "yaml"
73+
|| src.format === "merged" || src.format === "resolved") {
74+
const files = src.files.map(relativize);
8075
const jp = (src as { jsonPath?: string }).jsonPath;
81-
return { code: err.code, source: jp !== undefined ? { format: src.format, files, jsonPath: jp } : { format: src.format, files } };
76+
return {
77+
code: err.code,
78+
source: jp !== undefined
79+
? { format: src.format, files, jsonPath: jp }
80+
: { format: src.format, files },
81+
};
8282
}
8383
return { code: err.code, source: { format: src.format, files: [] } };
8484
}

0 commit comments

Comments
 (0)