From 77884f99b8ffedaf12e8d63b63a8e5e62ff8a068 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Mon, 29 Jun 2026 10:44:43 +0200 Subject: [PATCH] test(schema): make the libxml2 differential seed configurable via DIFF_SEED (#385) The three generated-vs-libxml2 differentials (instance, facet, determinism) each ran a single hardcoded seed, so they characterised one fixed slice of the open input space rather than sampling it. Each now reads an optional DIFF_SEED environment override (defaulting to its existing seed, so the default run is unchanged), turning the fixed smoke test into an open-space fuzzer: a sweep over many seeds explores far more of the unbounded schema/instance space than the finite XSTS corpus, which is the production-readiness "uncharacterized correctness" stopper. A 12-seed sweep of the instance differential immediately surfaced a genuine content-matcher false positive (cardinal-rule violation) at DIFF_SEED=13371337: the model `( (choice(a*|(c*)+)){1,3}, b? ){1,3}` rejects ` ` ("element 'c' is not allowed here") though libxml2 accepts it. A nested nullable-repetition edge in the graph-structured-stack matcher, captured for a focused fix; the default seed and every other swept seed hold false positives at 0. --- Tests/DeterminismDifferentialTests.swift | 3 ++- Tests/FacetValidationDifferentialTests.swift | 3 ++- Tests/InstanceValidationDifferentialTests.swift | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Tests/DeterminismDifferentialTests.swift b/Tests/DeterminismDifferentialTests.swift index 2d6c1f9..3d51c1b 100644 --- a/Tests/DeterminismDifferentialTests.swift +++ b/Tests/DeterminismDifferentialTests.swift @@ -87,7 +87,8 @@ struct DeterminismDifferentialTests { @Test("PureXML's UPA verdict agrees with libxml2 over generated content models") func test_determinismDifferential() { guard enabled, let xmllint else { return } - var generator = DeterminismSchemaGenerator(seed: 0xDE7E_5A11_C0DE_F00D) + let seed = ProcessInfo.processInfo.environment["DIFF_SEED"].flatMap { UInt64($0) } ?? 0xDE7E_5A11_C0DE_F00D + var generator = DeterminismSchemaGenerator(seed: seed) var falsePositives: [String] = [] var falseNegatives: [String] = [] var compared = 0 diff --git a/Tests/FacetValidationDifferentialTests.swift b/Tests/FacetValidationDifferentialTests.swift index bcedfdd..a52cef7 100644 --- a/Tests/FacetValidationDifferentialTests.swift +++ b/Tests/FacetValidationDifferentialTests.swift @@ -114,7 +114,8 @@ struct FacetValidationDifferentialTests { @Test("PureXML's facet-validity verdict agrees with libxml2 over generated values") func test_facetDifferential() { guard enabled, let xmllint else { return } - var generator = FacetSchemaGenerator(seed: 0xFACE_7D1F_F00D_C0DE) + let seed = ProcessInfo.processInfo.environment["DIFF_SEED"].flatMap { UInt64($0) } ?? 0xFACE_7D1F_F00D_C0DE + var generator = FacetSchemaGenerator(seed: seed) var tally = Tally() let schemaFile = NSTemporaryDirectory() + "facet-diff-schema.xsd" for _ in 0 ..< 2000 { diff --git a/Tests/InstanceValidationDifferentialTests.swift b/Tests/InstanceValidationDifferentialTests.swift index fe543fb..dee8c6f 100644 --- a/Tests/InstanceValidationDifferentialTests.swift +++ b/Tests/InstanceValidationDifferentialTests.swift @@ -107,7 +107,8 @@ struct InstanceValidationDifferentialTests { @Test("PureXML's instance-validity verdict agrees with libxml2 over generated documents") func test_instanceDifferential() { guard enabled, let xmllint else { return } - var generator = InstanceSchemaGenerator(seed: 0x1A57_C0DE_5EED_BEEF) + let seed = ProcessInfo.processInfo.environment["DIFF_SEED"].flatMap { UInt64($0) } ?? 0x1A57_C0DE_5EED_BEEF + var generator = InstanceSchemaGenerator(seed: seed) var tally = Tally() let schemaFile = NSTemporaryDirectory() + "inst-diff-schema.xsd" for _ in 0 ..< 1500 {