lutaml-model 0.8.203 → 0.8.205

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +5 -0
  3. data/.github/workflows/lml-conformance.yml +71 -0
  4. data/.gitignore +7 -0
  5. data/README.adoc +1 -0
  6. data/docs/_guides/lml-cross-language.adoc +128 -0
  7. data/docs/_guides/native-engines.adoc +10 -0
  8. data/docs/_references/lml-conformance.adoc +78 -0
  9. data/docs/_references/lml-contract.adoc +290 -0
  10. data/lib/lutaml/model/lml/artifact_verifier.rb +205 -0
  11. data/lib/lutaml/model/lml/bundle.rb +171 -0
  12. data/lib/lutaml/model/lml/document.rb +46 -10
  13. data/lib/lutaml/model/lml/document_validator.rb +840 -0
  14. data/lib/lutaml/model/lml/exporter/v1_projector.rb +102 -0
  15. data/lib/lutaml/model/lml/exporter/v2_projector.rb +401 -0
  16. data/lib/lutaml/model/lml/exporter.rb +223 -87
  17. data/lib/lutaml/model/lml/graph_exporter.rb +248 -0
  18. data/lib/lutaml/model/lml/importer.rb +180 -0
  19. data/lib/lutaml/model/lml/mapping_compiler.rb +401 -0
  20. data/lib/lutaml/model/lml/materialization.rb +257 -0
  21. data/lib/lutaml/model/lml/ordered_content.rb +577 -0
  22. data/lib/lutaml/model/lml/portable_json.rb +385 -0
  23. data/lib/lutaml/model/lml/rejected_error.rb +64 -15
  24. data/lib/lutaml/model/lml/round_trip.rb +86 -0
  25. data/lib/lutaml/model/lml/value_declarations.rb +84 -0
  26. data/lib/lutaml/model/lml.rb +61 -0
  27. data/lib/lutaml/model/schema/definitions/attribute.rb +4 -2
  28. data/lib/lutaml/model/schema/registry_generator.rb +1 -1
  29. data/lib/lutaml/model/schema/renderers/member_decls.rb +1 -0
  30. data/lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb +10 -0
  31. data/lib/lutaml/model/sequence.rb +7 -0
  32. data/lib/lutaml/model/serialize/format_conversion.rb +22 -8
  33. data/lib/lutaml/model/serialize/initialization.rb +2 -0
  34. data/lib/lutaml/model/version.rb +1 -1
  35. data/lib/lutaml/xml/leptris/native_emission.rb +85 -3
  36. data/lib/lutaml/xml/leptris/plan_compiler.rb +190 -45
  37. data/lib/lutaml/xml/leptris/plan_hydrator.rb +209 -56
  38. data/lib/lutaml/xml/leptris/plan_serializer.rb +533 -102
  39. data/lib/lutaml/xml/leptris/plan_walk.rb +1 -0
  40. data/lib/lutaml/xml/schema/builder/moxml.rb +7 -3
  41. data/lib/lutaml/xml/transformation/order_reconciler.rb +4 -0
  42. data/lib/lutaml/xml/transformation/ordered_applier.rb +8 -7
  43. data/schema/lml/document.schema.json +179 -0
  44. data/scripts/lml/export_choices.rb +57 -0
  45. data/scripts/lml/export_conformance.rb +23 -0
  46. data/scripts/lml/export_mml.rb +253 -0
  47. data/scripts/lml/export_preservation.rb +421 -0
  48. data/scripts/lml/verify_artifacts.rb +31 -0
  49. data/spec/fixtures/lml_artifacts/model.json +1 -0
  50. data/spec/fixtures/lml_artifacts/valid.json +1 -0
  51. data/spec/fixtures/lml_artifacts/valid.sha256 +1 -0
  52. data/spec/fixtures/lml_conformance/core/index.json +1 -0
  53. data/spec/fixtures/lml_conformance/core/manifest.json +1 -0
  54. data/spec/fixtures/lml_conformance/core/schema.json +1 -0
  55. data/spec/fixtures/lml_conformance/core/schema.yaml +79 -0
  56. data/spec/fixtures/lml_conformance/float_vectors.generator.rb +60 -0
  57. data/spec/fixtures/lml_conformance/float_vectors.json +21550 -0
  58. data/spec/fixtures/lml_conformance/preservation/index.json +1 -0
  59. data/spec/fixtures/lml_conformance/preservation/manifest.json +1 -0
  60. data/spec/fixtures/lml_conformance/preservation/schema.json +1 -0
  61. data/spec/fixtures/lml_conformance/preservation/schema.yaml +319 -0
  62. data/spec/fixtures/lml_conformance/r2_refusals.generator.rb +153 -0
  63. data/spec/fixtures/lml_conformance/r2_refusals.json +1662 -0
  64. data/spec/fixtures/lml_conformance/ruby_portable_interop.generator.rb +40 -0
  65. data/spec/fixtures/lml_conformance/ruby_portable_interop.json +1 -0
  66. data/spec/fixtures/lml_contract/bundle.json +81 -0
  67. data/spec/fixtures/lml_contract/manifest.json +30 -0
  68. data/spec/fixtures/lml_contract/v1_unit.canonical.json +1 -0
  69. data/spec/fixtures/lml_contract/v1_unit.json +1 -0
  70. data/spec/fixtures/lml_contract/v2_node.canonical.json +1 -0
  71. data/spec/fixtures/lml_contract/v2_node.json +32 -0
  72. data/spec/fixtures/lml_mml/inventory.json +1 -0
  73. data/spec/fixtures/lml_mml/manifest.json +1 -0
  74. data/spec/fixtures/lml_mml/oracle.json +1 -0
  75. data/spec/fixtures/lml_mml/v3-mi-mixed.json +1 -0
  76. data/spec/fixtures/lml_mml/v3-mi-mixed.yaml +970 -0
  77. data/spec/fixtures/lml_mml/v4-mi-mixed.json +1 -0
  78. data/spec/fixtures/lml_mml/v4-mi-mixed.yaml +1516 -0
  79. data/spec/fixtures/lml_mml_materialization/replay.rb +37 -0
  80. data/spec/lutaml/model/lml_any_attribute_spec.rb +91 -0
  81. data/spec/lutaml/model/lml_artifact_verifier_spec.rb +86 -0
  82. data/spec/lutaml/model/lml_builtin_types_spec.rb +49 -0
  83. data/spec/lutaml/model/lml_conformance_spec.rb +178 -0
  84. data/spec/lutaml/model/lml_document_spec.rb +279 -0
  85. data/spec/lutaml/model/lml_export_validation_spec.rb +96 -0
  86. data/spec/lutaml/model/lml_exporter_spec.rb +127 -5
  87. data/spec/lutaml/model/lml_graph_exporter_spec.rb +205 -0
  88. data/spec/lutaml/model/lml_importer_spec.rb +290 -0
  89. data/spec/lutaml/model/lml_input_hardening_spec.rb +156 -0
  90. data/spec/lutaml/model/lml_mapping_compiler_spec.rb +256 -0
  91. data/spec/lutaml/model/lml_materialization_spec.rb +138 -0
  92. data/spec/lutaml/model/lml_mml_materialization_spec.rb +54 -0
  93. data/spec/lutaml/model/lml_mml_pilot_spec.rb +150 -0
  94. data/spec/lutaml/model/lml_model_choices_spec.rb +88 -0
  95. data/spec/lutaml/model/lml_ordered_content_spec.rb +243 -0
  96. data/spec/lutaml/model/lml_portable_json_spec.rb +310 -0
  97. data/spec/lutaml/model/lml_preservation_spec.rb +211 -0
  98. data/spec/lutaml/model/lml_review_export_spec.rb +247 -0
  99. data/spec/lutaml/model/lml_review_import_spec.rb +390 -0
  100. data/spec/lutaml/model/lml_review_misc_spec.rb +152 -0
  101. data/spec/lutaml/model/lml_review_round4_spec.rb +200 -0
  102. data/spec/lutaml/model/lml_review_round5_spec.rb +194 -0
  103. data/spec/lutaml/model/lml_ruby_interop_fixture_spec.rb +37 -0
  104. data/spec/lutaml/model/lml_shared_corpus_spec.rb +132 -0
  105. data/spec/lutaml/model/lml_value_declarations_spec.rb +128 -0
  106. data/spec/lutaml/model/schema/class_loader_spec.rb +51 -0
  107. data/spec/lutaml/model/schema/xml_compiler_runtime_spec.rb +20 -0
  108. data/spec/lutaml/model/sequence_spec.rb +48 -0
  109. data/spec/lutaml/xml/cdata_emission_spec.rb +68 -0
  110. data/spec/lutaml/xml/production_lane_parity_spec.rb +632 -0
  111. data/spec/support/lml_any_attribute_fixtures.rb +26 -0
  112. data/spec/support/lml_conformance.rb +292 -0
  113. data/spec/support/lml_corpus.rb +75 -0
  114. data/spec/support/lml_export_fixtures.rb +190 -0
  115. data/spec/support/lml_graph_fixtures.rb +108 -0
  116. data/spec/support/lml_import_fixtures.rb +52 -0
  117. data/spec/support/lml_mapping_fixtures.rb +170 -0
  118. data/spec/support/lml_materialization_fixtures.rb +53 -0
  119. data/spec/support/lml_model_choices_fixtures.rb +150 -0
  120. data/spec/support/lml_order_fixtures.rb +151 -0
  121. metadata +94 -3
  122. data/lib/lutaml/model/schema/schema_builder/nokogiri.rb +0 -41
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Invoked in a new Ruby process; never load the original mml library.
4
+ require_relative "../../../scripts/lml/export_mml"
5
+
6
+ package = ARGV.fetch(0)
7
+ raise "source Mml constants were already loaded" if Object.const_defined?(:Mml, false)
8
+
9
+ manifest = JSON.parse(File.read(File.join(package, "manifest.json")))
10
+ manifest.fetch("files").each do |entry|
11
+ bytes = File.binread(File.join(package, entry.fetch("path")))
12
+ unless LmlPreservation.digest(bytes) == entry.fetch("sha256")
13
+ raise "payload digest mismatch: #{entry.fetch('path')}"
14
+ end
15
+ end
16
+
17
+ oracles = JSON.parse(File.read(File.join(package, "oracle.json"))).fetch("cases")
18
+ results = oracles.each_with_index.map do |entry, index|
19
+ id = entry.fetch("id")
20
+ graph = manifest.fetch("graphs").fetch(id)
21
+ # A refused closure is reported by name, never reconstructed from a pruned graph.
22
+ next({ "id" => id, "refused" => graph.fetch("refusal") }) if graph.key?("refusal")
23
+
24
+ bundle = Lutaml::Model::Lml::Importer.bundle(File.read(File.join(package, "#{id}.json")))
25
+ raise "bundle checksum mismatch: #{id}" unless bundle.checksum == graph.fetch("checksum")
26
+
27
+ derived = Lutaml::Model::Lml.verify_materialization(bundle)
28
+ holder = Object.const_set("LmlMmlRebuilt#{index}", Module.new)
29
+ classes = Lutaml::Model::Lml.import_bundle(bundle, namespace: holder)
30
+ identities = classes.to_h { |model_id, klass| [klass, model_id] }
31
+ { "id" => id, "model_count" => classes.size, "checksum" => derived.checksum,
32
+ "actual" => LmlMml.replay(entry, classes.fetch(entry.fetch("model_id")), identities) }
33
+ end
34
+
35
+ raise "materialization loaded source Mml constants" if Object.const_defined?(:Mml, false)
36
+
37
+ File.write(ARGV.fetch(1), LmlPreservation.json("source_constants_loaded" => false, "cases" => results))
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "json"
5
+ require_relative "../../support/lml_any_attribute_fixtures"
6
+
7
+ # lutaml-model#1033 card 02g: the XML catch-all attribute mapping
8
+ # (map_all_attributes) is carried as {kind:"any_attribute", to:<attr>}.
9
+ RSpec.describe "LML any_attribute rule" do
10
+ let(:lml) { Lutaml::Model::Lml }
11
+ let(:fx) { LmlAnyAttributeFixtures }
12
+ let(:rejected) { lml::RejectedError }
13
+ let(:document) { lml::Exporter.project(fx::Tag) }
14
+ let(:rules) { document.dig("mappings", "xml", "rules") }
15
+
16
+ def refusal
17
+ yield
18
+ nil
19
+ rescue rejected => e
20
+ e
21
+ end
22
+
23
+ def validate(hash)
24
+ Lutaml::Model::Lml::DocumentValidator.validate!(hash, kind: :document)
25
+ end
26
+
27
+ def with_rules(extra, attributes: nil)
28
+ copy = JSON.parse(JSON.generate(document))
29
+ copy["attributes"] = attributes if attributes
30
+ copy["mappings"]["xml"]["rules"] = extra
31
+ copy
32
+ end
33
+
34
+ it "exports the catch-all as the last rule, naming the hash attribute" do
35
+ expect(rules.last).to eq("kind" => "any_attribute", "to" => "other_attributes")
36
+ expect(rules.map { |r| r["kind"] }).to eq(%w[attribute any_attribute])
37
+ end
38
+
39
+ it "leaves the v1 export unchanged" do
40
+ expect(lml.export(fx::Tag).to_h.dig("mappings", "xml", "rules").map { |r| r["kind"] }).to eq(%w[attribute])
41
+ end
42
+
43
+ it "validates the exported document and the schema lists the kind" do
44
+ expect(refusal { validate(document) }).to be_nil
45
+ schema = JSON.parse(File.read(File.expand_path("../../../schema/lml/document.schema.json", __dir__)))
46
+ expect(schema.dig("$defs", "rule", "properties", "kind", "enum")).to include("any_attribute")
47
+ end
48
+
49
+ it "refuses a second any_attribute rule by name" do
50
+ two = with_rules(rules + [{ "kind" => "any_attribute", "to" => "other_attributes" }])
51
+ expect(refusal { validate(two) }.reason).to eq(:unsupported_mapping)
52
+ end
53
+
54
+ it "refuses a target that is not a declared attribute" do
55
+ bad = with_rules([{ "kind" => "any_attribute", "to" => "nope" }])
56
+ expect(refusal { validate(bad) }.reason).to eq(:dangling_reference)
57
+ end
58
+
59
+ it "refuses a target that is not a hash attribute" do
60
+ bad = with_rules([{ "kind" => "any_attribute", "to" => "id" }])
61
+ expect(refusal { validate(bad) }.reason).to eq(:unsupported_mapping)
62
+ end
63
+
64
+ it "refuses extra keys on the rule" do
65
+ bad = with_rules([{ "kind" => "any_attribute", "to" => "other_attributes", "name" => ["x"] }])
66
+ expect(refusal { validate(bad) }.reason).to eq(:unsupported_mapping)
67
+ end
68
+
69
+ it "refuses map_all_attributes matching: instead of dropping the filter" do
70
+ error = refusal { lml::Exporter.project(fx::Filtered) }
71
+ expect(error.reason).to eq(:unsupported_mapping)
72
+ expect(error.message).to include("map_all_attributes matching:")
73
+ end
74
+
75
+ describe "round trip in a rebuilt model" do
76
+ let(:bundle) { lml.export_bundle(fx::Tag) }
77
+ let(:xml) { '<tag xmlns:x="urn:u" id="1" x:a="2" b="3"/>' }
78
+
79
+ it "verifies the materialization and reproduces catch-all behaviour" do
80
+ expect(lml.verify_materialization(bundle).checksum).to eq(bundle.checksum)
81
+
82
+ classes = lml.import_bundle(bundle, namespace: stub_const("LmlAnyAttrImported", Module.new))
83
+ imported = classes.fetch("LmlAnyAttributeFixtures::Tag@default")
84
+ parsed = imported.from_xml(xml)
85
+ expect(parsed.id).to eq("1")
86
+ # Pinned Ruby behaviour: the prefix is dropped, only the local name is kept.
87
+ expect(parsed.other_attributes).to eq("a" => "2", "b" => "3")
88
+ expect(parsed.to_xml).to eq(fx::Tag.from_xml(xml).to_xml)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tmpdir"
4
+ require "fileutils"
5
+ require_relative "../../../lib/lutaml/model/lml/artifact_verifier"
6
+
7
+ RSpec.describe Lutaml::Model::Lml::ArtifactVerifier do
8
+ let(:fixtures) { File.expand_path("../../fixtures/lml_artifacts", __dir__) }
9
+ let(:manifest) { JSON.parse(File.read(File.join(fixtures, "valid.json"))) }
10
+ let(:pin) { File.read(File.join(fixtures, "valid.sha256")).strip }
11
+ let(:artifact_root) { Dir.mktmpdir("lml-artifact") }
12
+ let(:verifier) { described_class.new(root: artifact_root, expected_sha256: pin) }
13
+
14
+ before { FileUtils.cp(File.join(fixtures, "model.json"), artifact_root) }
15
+ after { FileUtils.remove_entry(artifact_root) }
16
+
17
+ it "verifies the caller-pinned fixture and freezes the verified manifest" do
18
+ verified = verifier.verify(manifest)
19
+ expect(verified).to equal(manifest)
20
+ expect(verified.fetch("files").first).to be_frozen
21
+ expect { verified.fetch("files") << {} }.to raise_error(FrozenError)
22
+ end
23
+
24
+ it "ignores object key order but preserves semantic array order in checksums" do
25
+ expect(described_class.checksum(manifest.to_a.reverse.to_h)).to eq(pin)
26
+ expect(described_class.checksum(["xml", "json"])).not_to eq(described_class.checksum(["json", "xml"]))
27
+ end
28
+
29
+ it "rejects a wrong expected manifest digest before using files" do
30
+ verifier = described_class.new(root: artifact_root, expected_sha256: "sha256:#{'0' * 64}")
31
+ expect { verifier.verify(manifest) }.to raise_error(described_class::Error, %r{checksum_mismatch: /manifest})
32
+ end
33
+
34
+ %w[lml_checksum generator_version target corpora dependencies].each do |field|
35
+ it "rejects an altered #{field} pin" do
36
+ changed = manifest.merge(field => case field
37
+ when "corpora", "dependencies" then []
38
+ when "lml_checksum" then "sha256:#{'1' * 64}"
39
+ when "target" then "wasm"
40
+ else "changed"
41
+ end)
42
+ expect { verifier.verify(changed) }.to raise_error(described_class::Error, /checksum_mismatch/)
43
+ end
44
+ end
45
+
46
+ it "rejects an unsupported schema version with a named error" do
47
+ expect { verifier.verify(manifest.merge("schema_version" => 999)) }
48
+ .to raise_error(described_class::Error, %r{unsupported_version: /schema_version})
49
+ end
50
+
51
+ it "rejects corrupt artifact bytes" do
52
+ File.write(File.join(artifact_root, "model.json"), "changed")
53
+ expect { verifier.verify(manifest) }.to raise_error(described_class::Error, %r{checksum_mismatch: /files/0})
54
+ end
55
+
56
+ it "rejects absent artifact files" do
57
+ FileUtils.rm(File.join(artifact_root, "model.json"))
58
+ expect { verifier.verify(manifest) }.to raise_error(described_class::Error, /invalid_document/)
59
+ end
60
+
61
+ ["../outside", "/absolute", "nested/../outside", "a//b", "C:/outside", "a\\b"].each do |path|
62
+ it "rejects non-relative artifact path #{path.inspect}" do
63
+ changed = manifest.merge("files" => [{ "path" => path, "sha256" => manifest["files"][0]["sha256"] }])
64
+ pinned = described_class.new(root: artifact_root, expected_sha256: described_class.checksum(changed))
65
+ expect { pinned.verify(changed) }.to raise_error(described_class::Error, /invalid_document/)
66
+ end
67
+ end
68
+
69
+ it "rejects a symlink that escapes the artifact root" do
70
+ outside = File.join(fixtures, "model.json")
71
+ FileUtils.rm(File.join(artifact_root, "model.json"))
72
+ File.symlink(outside, File.join(artifact_root, "model.json"))
73
+ expect { verifier.verify(manifest) }.to raise_error(described_class::Error, /invalid_document/)
74
+ end
75
+
76
+ it "compares supplied consumer pins even when a different manifest is validly checksummed" do
77
+ strict = described_class.new(root: artifact_root, expected_sha256: pin,
78
+ target: "rust", lml_checksum: manifest["lml_checksum"])
79
+ expect { strict.verify(manifest) }.to raise_error(described_class::Error, %r{checksum_mismatch: /target})
80
+ end
81
+
82
+ it "refuses non-neutral values and ambiguous object keys" do
83
+ expect { described_class.checksum("value" => 0.1) }.to raise_error(described_class::Error, /non-neutral/)
84
+ expect { described_class.checksum(value: "x") }.to raise_error(described_class::Error, /keys must be strings/)
85
+ end
86
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ # lutaml-model#1033: every builtin name the exporter can write must be a
6
+ # name the importer accepts (the LML builtin list is not allowed to drift
7
+ # from Lutaml::Model::Type's registry).
8
+ RSpec.describe "LML builtin type names" do
9
+ let(:lml) { Lutaml::Model::Lml }
10
+ let(:registry_names) { Lutaml::Model::Type::TYPE_CODES.keys.map(&:to_s) }
11
+ # double, int and q_name are aliases: the exporter writes the first
12
+ # registered name of each type class.
13
+ let(:emitted) do
14
+ Lutaml::Model::Type::TYPE_CODES.group_by { |_, klass| klass }
15
+ .values.map { |pairs| pairs.first.first.to_s }
16
+ end
17
+
18
+ def model_with(type)
19
+ Class.new(Lutaml::Model::Serializable) do
20
+ def self.name = "EveryBuiltin"
21
+ end.tap { |klass| klass.attribute :x, type }
22
+ end
23
+
24
+ it "accepts every name the exporter writes for a registered builtin" do
25
+ klass = Class.new(Lutaml::Model::Serializable) do
26
+ def self.name = "EveryBuiltin"
27
+ end
28
+ registry_names.each { |type| klass.attribute :"a_#{type}", type.to_sym }
29
+
30
+ bundle = lml.export_bundle(klass)
31
+ written = bundle.to_h["models"].values.first["attributes"].map { |a| a["type"]["name"] }
32
+
33
+ expect(written.uniq.sort).to eq(emitted.sort)
34
+ expect(lml::DocumentValidator::BUILTIN_TYPES).to include(*emitted)
35
+ imported = lml::Importer.bundle(bundle.canonical_json)
36
+ expect(imported.to_h).to eq(bundle.to_h)
37
+ end
38
+
39
+ it "imports each registered builtin on its own" do
40
+ emitted.each do |type|
41
+ bundle = lml.export_bundle(model_with(type.to_sym))
42
+ expect { lml::Importer.bundle(bundle.canonical_json) }.not_to raise_error, type
43
+ end
44
+ end
45
+
46
+ it "still refuses double, which is never written" do
47
+ expect(lml::DocumentValidator::BUILTIN_TYPES).not_to include("double")
48
+ end
49
+ end
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require_relative "../../support/lml_conformance"
5
+ require "tmpdir"
6
+ require "fileutils"
7
+ require "open3"
8
+
9
+ RSpec.describe LmlConformance do
10
+ let(:directory) { File.expand_path("../../fixtures/lml_conformance/core", __dir__) }
11
+ let(:index) { JSON.parse(File.read(File.join(directory, "index.json"))) }
12
+ let(:temporary) { Dir.mktmpdir("lml-conformance") }
13
+
14
+ after { FileUtils.remove_entry(temporary) }
15
+
16
+ it "replays all five pinned Ruby cases and reports their identities" do
17
+ report = described_class.check(directory)
18
+ expect(report).to include("expected_count" => 5, "executed_count" => 5, "errors" => [])
19
+ expect(report.fetch("executed_ids")).to eq(%w[core-json core-xml-tree core-xml-bytes core-json-invalid core-json-portable-exact])
20
+ end
21
+
22
+ it "pins normalized exact integer strings and false without stringifying booleans" do
23
+ entry = index.fetch("cases").first
24
+ expect(entry.fetch("expected_data")).to eq("label" => "café & tea", "count" => "42", "enabled" => false)
25
+ expect(described_class.execute(entry).fetch("data")).to eq(entry.fetch("expected_data"))
26
+ end
27
+
28
+ it "pins named negative results without exception messages" do
29
+ entry = index.fetch("cases").find { |item| item.fetch("id") == "core-json-invalid" }
30
+ expect(entry.fetch("expected_error")).to eq(
31
+ "reason" => "invalid_document", "model_id" => "LmlConformance::Record@default",
32
+ "format" => "json", "location" => "/input"
33
+ )
34
+ expect(described_class.execute(entry).fetch("error")).to eq(entry.fetch("expected_error"))
35
+ end
36
+
37
+ it "labels native wire truth without changing the numeric Ruby serializer" do
38
+ entry = index.fetch("cases").first
39
+ expect(entry.fetch("wire_profile")).to eq("ruby-native-v1")
40
+ expect(entry.fetch("input")).to eq('{"label":"café & tea","count":42,"enabled":false}')
41
+ expect(entry.fetch("expected_output")).to eq('{"label":"café & tea","count":42,"enabled":false}')
42
+ expect(entry.fetch("data_profile")).to eq("exact-values-decimal-v1")
43
+ end
44
+
45
+ it "executes the portable exact-string boundary without a floating-point intermediate" do
46
+ entry = index.fetch("cases").last
47
+ expect(entry.fetch("id")).to eq("core-json-portable-exact")
48
+ expect(entry.fetch("wire_profile")).to eq("portable-exact-json-v1")
49
+ expect(JSON.parse(entry.fetch("input"))).to include("count" => "9007199254740993")
50
+ result = described_class.execute(entry)
51
+ expect(result.fetch("data")).to eq("label" => "beyond binary64", "count" => "9007199254740993", "enabled" => false)
52
+ expect(JSON.parse(result.fetch("output"))).to eq(result.fetch("data"))
53
+ expect(result.fetch("output")).to eq(entry.fetch("expected_output"))
54
+ expect(described_class.compare(entry, result)).to be_nil
55
+ end
56
+
57
+ it "refuses numeric input to the portable exact-string profile" do
58
+ entry = index.fetch("cases").last.merge("input" => '{"label":"number","count":9007199254740993,"enabled":false}')
59
+ expect { described_class.execute(entry) }.to raise_error(ArgumentError, "portable integer requires decimal string")
60
+ end
61
+
62
+ it "requires explicit portable case coverage for generated Rust and TS codecs" do
63
+ %w[rust ts].each do |target|
64
+ missing = described_class.coverage(index, target: target, executed_ids: ["core-json"])
65
+ expect(missing.fetch("required_profiles")).to eq(["portable-exact-json-v1"])
66
+ expect(missing.fetch("errors")).to eq([{ "id" => "core-json-portable-exact", "error" => "required case not executed" }])
67
+ complete = described_class.coverage(index, target: target, executed_ids: ["core-json-portable-exact"])
68
+ expect(complete.fetch("errors")).to be_empty
69
+ end
70
+ expect(described_class.coverage(index, target: "ruby", executed_ids: ["core-json-portable-exact"]).fetch("errors").size).to eq(4)
71
+ end
72
+
73
+ it "fails an omitted portable case even when every native case executed" do
74
+ index.fetch("cases").pop
75
+ report = described_class.replay(index)
76
+ expect(report.fetch("errors")).to include(
77
+ { "id" => "core-json-portable-exact", "error" => "missing case" },
78
+ { "id" => "core-json-portable-exact", "error" => "required case not executed" },
79
+ )
80
+ end
81
+
82
+ it "regenerates exactly the checked-in bytes and manifest digests" do
83
+ described_class.files.each do |path, bytes|
84
+ expect(File.binread(File.join(directory, path))).to eq(bytes.b)
85
+ end
86
+ manifest = JSON.parse(File.read(File.join(directory, "manifest.json")))
87
+ manifest.fetch("files").each do |entry|
88
+ expect(described_class.digest(File.binread(File.join(directory, entry.fetch("path"))))).to eq(entry.fetch("sha256"))
89
+ end
90
+ end
91
+
92
+ it "pins gemspec source independently of Windows line endings" do
93
+ gemspec_path = File.expand_path("../../../lutaml-model.gemspec", __dir__)
94
+ source = File.binread(gemspec_path)
95
+ crlf_source = source.gsub(/\r?\n/, "\r\n")
96
+ allow(File).to receive(:binread).and_call_original
97
+ allow(File).to receive(:binread).with(gemspec_path).and_return(crlf_source)
98
+
99
+ generated = described_class.files
100
+ manifest = JSON.parse(generated.fetch("manifest.json"))
101
+ dependency = manifest.fetch("dependencies").find { |entry| entry.fetch("name") == "lutaml-model" }
102
+ expect(dependency.fetch("sha256")).to eq(described_class.digest(source.gsub("\r\n", "\n")))
103
+ generated.each do |path, bytes|
104
+ expect(bytes.b).to eq(File.binread(File.join(directory, path)))
105
+ end
106
+ end
107
+
108
+ it "loads JSON and safe YAML schemas as identical neutral trees" do
109
+ expect(YAML.safe_load_file(File.join(directory, "schema.yaml"), aliases: false)).to eq(
110
+ JSON.parse(File.read(File.join(directory, "schema.json"))),
111
+ )
112
+ end
113
+
114
+ it "fails missing cases by ID" do
115
+ index.fetch("cases").shift
116
+ expect(described_class.replay(index).fetch("errors")).to include("id" => "core-json", "error" => "missing case")
117
+ end
118
+
119
+ it "fails unknown cases by ID" do
120
+ index.fetch("cases") << index.fetch("cases").first.merge("id" => "future-case")
121
+ expect(described_class.replay(index).fetch("errors")).to include("id" => "future-case", "error" => "unknown case")
122
+ end
123
+
124
+ it "fails changed and duplicate cases by ID" do
125
+ index.fetch("cases").first["input"] = "{}"
126
+ index.fetch("cases") << index.fetch("cases").find { |item| item.fetch("id") == "core-json-invalid" }.dup
127
+ expect(described_class.replay(index).fetch("errors")).to include(
128
+ { "id" => "core-json", "error" => "changed case" },
129
+ { "id" => "core-json-invalid", "error" => "duplicate case" },
130
+ )
131
+ end
132
+
133
+ it "detects actual execution drift against unchanged pinned expectations" do
134
+ allow(described_class).to receive(:execute).and_call_original
135
+ entry = index.fetch("cases").first
136
+ allow(described_class).to receive(:execute).with(entry).and_return("data" => {}, "output" => "{}")
137
+ # Freeze the authored reference independently of the simulated runtime drift.
138
+ allow(described_class).to receive(:oracle_cases).and_return(index.fetch("cases"))
139
+ expect(described_class.replay(index).fetch("errors")).to include("id" => "core-json", "error" => "typed data mismatch")
140
+ end
141
+
142
+ it "compares expanded XML names while preserving attributes, child order and text" do
143
+ expect(described_class.xml_tree('<a:r xmlns:a="urn:r" b="2" a="1"><x>café</x></a:r>')).to eq(
144
+ described_class.xml_tree('<z:r a="1" b="2" xmlns:z="urn:r"><x>café</x></z:r>'),
145
+ )
146
+ expect(described_class.xml_tree("<r><a/><b/></r>")).not_to eq(described_class.xml_tree("<r><b/><a/></r>"))
147
+ expect(described_class.xml_tree("<r> x </r>")).not_to eq(described_class.xml_tree("<r>x</r>"))
148
+ expect(described_class.xml_tree('<r xmlns="urn:a"/>')).not_to eq(described_class.xml_tree('<r xmlns="urn:b"/>'))
149
+ end
150
+
151
+ it "treats CDATA as tree text and checks lexical bytes separately" do
152
+ expect(described_class.xml_tree("<r><![CDATA[x]]></r>")).to eq(described_class.xml_tree("<r>x</r>"))
153
+ entry = { "expected_data" => {}, "expected_output" => "<r><![CDATA[x]]></r>", "comparison" => "bytes" }
154
+ expect(described_class.compare(entry, "data" => {}, "output" => "<r>x</r>")).to eq("output mismatch")
155
+ end
156
+
157
+ it "rejects DTD input under the pinned tree profile" do
158
+ expect { described_class.xml_tree('<!DOCTYPE r [<!ENTITY a "x">]><r>&a;</r>') }.to raise_error(ArgumentError)
159
+ end
160
+
161
+ it "reports corrupt files and does not rewrite them during check" do
162
+ FileUtils.cp_r("#{directory}/.", temporary)
163
+ File.write(File.join(temporary, "schema.yaml"), "corrupt")
164
+ expect(described_class.check(temporary).fetch("errors")).to include(
165
+ "id" => "package/schema.yaml", "error" => "missing or changed file",
166
+ )
167
+ expect(File.read(File.join(temporary, "schema.yaml"))).to eq("corrupt")
168
+ end
169
+
170
+ it "returns nonzero and a case ID for a missing case through the CLI" do
171
+ FileUtils.cp_r("#{directory}/.", temporary)
172
+ index.fetch("cases").shift
173
+ File.write(File.join(temporary, "index.json"), JSON.generate(index))
174
+ output, status = Open3.capture2(RbConfig.ruby, "-Ilib", "scripts/lml/export_conformance.rb", "--check", "--package", temporary)
175
+ expect(status.exitstatus).to eq(1)
176
+ expect(JSON.parse(output).fetch("errors")).to include("id" => "core-json", "error" => "missing case")
177
+ end
178
+ end