lutaml-model 0.8.203 → 0.8.204

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 (112) 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/_references/lml-conformance.adoc +78 -0
  8. data/docs/_references/lml-contract.adoc +290 -0
  9. data/lib/lutaml/model/lml/artifact_verifier.rb +205 -0
  10. data/lib/lutaml/model/lml/bundle.rb +171 -0
  11. data/lib/lutaml/model/lml/document.rb +46 -10
  12. data/lib/lutaml/model/lml/document_validator.rb +840 -0
  13. data/lib/lutaml/model/lml/exporter/v1_projector.rb +102 -0
  14. data/lib/lutaml/model/lml/exporter/v2_projector.rb +401 -0
  15. data/lib/lutaml/model/lml/exporter.rb +223 -87
  16. data/lib/lutaml/model/lml/graph_exporter.rb +248 -0
  17. data/lib/lutaml/model/lml/importer.rb +180 -0
  18. data/lib/lutaml/model/lml/mapping_compiler.rb +401 -0
  19. data/lib/lutaml/model/lml/materialization.rb +257 -0
  20. data/lib/lutaml/model/lml/ordered_content.rb +577 -0
  21. data/lib/lutaml/model/lml/portable_json.rb +385 -0
  22. data/lib/lutaml/model/lml/rejected_error.rb +64 -15
  23. data/lib/lutaml/model/lml/round_trip.rb +86 -0
  24. data/lib/lutaml/model/lml/value_declarations.rb +84 -0
  25. data/lib/lutaml/model/lml.rb +61 -0
  26. data/lib/lutaml/model/schema/definitions/attribute.rb +4 -2
  27. data/lib/lutaml/model/schema/registry_generator.rb +1 -1
  28. data/lib/lutaml/model/schema/renderers/member_decls.rb +1 -0
  29. data/lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb +10 -0
  30. data/lib/lutaml/model/sequence.rb +7 -0
  31. data/lib/lutaml/model/version.rb +1 -1
  32. data/lib/lutaml/xml/leptris/native_emission.rb +4 -0
  33. data/lib/lutaml/xml/leptris/plan_serializer.rb +14 -9
  34. data/schema/lml/document.schema.json +179 -0
  35. data/scripts/lml/export_choices.rb +57 -0
  36. data/scripts/lml/export_conformance.rb +23 -0
  37. data/scripts/lml/export_mml.rb +253 -0
  38. data/scripts/lml/export_preservation.rb +421 -0
  39. data/scripts/lml/verify_artifacts.rb +31 -0
  40. data/spec/fixtures/lml_artifacts/model.json +1 -0
  41. data/spec/fixtures/lml_artifacts/valid.json +1 -0
  42. data/spec/fixtures/lml_artifacts/valid.sha256 +1 -0
  43. data/spec/fixtures/lml_conformance/core/index.json +1 -0
  44. data/spec/fixtures/lml_conformance/core/manifest.json +1 -0
  45. data/spec/fixtures/lml_conformance/core/schema.json +1 -0
  46. data/spec/fixtures/lml_conformance/core/schema.yaml +79 -0
  47. data/spec/fixtures/lml_conformance/float_vectors.generator.rb +60 -0
  48. data/spec/fixtures/lml_conformance/float_vectors.json +21550 -0
  49. data/spec/fixtures/lml_conformance/preservation/index.json +1 -0
  50. data/spec/fixtures/lml_conformance/preservation/manifest.json +1 -0
  51. data/spec/fixtures/lml_conformance/preservation/schema.json +1 -0
  52. data/spec/fixtures/lml_conformance/preservation/schema.yaml +319 -0
  53. data/spec/fixtures/lml_conformance/r2_refusals.generator.rb +153 -0
  54. data/spec/fixtures/lml_conformance/r2_refusals.json +1662 -0
  55. data/spec/fixtures/lml_conformance/ruby_portable_interop.generator.rb +40 -0
  56. data/spec/fixtures/lml_conformance/ruby_portable_interop.json +1 -0
  57. data/spec/fixtures/lml_contract/bundle.json +81 -0
  58. data/spec/fixtures/lml_contract/manifest.json +30 -0
  59. data/spec/fixtures/lml_contract/v1_unit.canonical.json +1 -0
  60. data/spec/fixtures/lml_contract/v1_unit.json +1 -0
  61. data/spec/fixtures/lml_contract/v2_node.canonical.json +1 -0
  62. data/spec/fixtures/lml_contract/v2_node.json +32 -0
  63. data/spec/fixtures/lml_mml/inventory.json +1 -0
  64. data/spec/fixtures/lml_mml/manifest.json +1 -0
  65. data/spec/fixtures/lml_mml/oracle.json +1 -0
  66. data/spec/fixtures/lml_mml/v3-mi-mixed.json +1 -0
  67. data/spec/fixtures/lml_mml/v3-mi-mixed.yaml +970 -0
  68. data/spec/fixtures/lml_mml/v4-mi-mixed.json +1 -0
  69. data/spec/fixtures/lml_mml/v4-mi-mixed.yaml +1516 -0
  70. data/spec/fixtures/lml_mml_materialization/replay.rb +37 -0
  71. data/spec/lutaml/model/lml_any_attribute_spec.rb +91 -0
  72. data/spec/lutaml/model/lml_artifact_verifier_spec.rb +86 -0
  73. data/spec/lutaml/model/lml_builtin_types_spec.rb +49 -0
  74. data/spec/lutaml/model/lml_conformance_spec.rb +178 -0
  75. data/spec/lutaml/model/lml_document_spec.rb +279 -0
  76. data/spec/lutaml/model/lml_export_validation_spec.rb +96 -0
  77. data/spec/lutaml/model/lml_exporter_spec.rb +127 -5
  78. data/spec/lutaml/model/lml_graph_exporter_spec.rb +205 -0
  79. data/spec/lutaml/model/lml_importer_spec.rb +290 -0
  80. data/spec/lutaml/model/lml_input_hardening_spec.rb +156 -0
  81. data/spec/lutaml/model/lml_mapping_compiler_spec.rb +256 -0
  82. data/spec/lutaml/model/lml_materialization_spec.rb +138 -0
  83. data/spec/lutaml/model/lml_mml_materialization_spec.rb +54 -0
  84. data/spec/lutaml/model/lml_mml_pilot_spec.rb +150 -0
  85. data/spec/lutaml/model/lml_model_choices_spec.rb +88 -0
  86. data/spec/lutaml/model/lml_ordered_content_spec.rb +243 -0
  87. data/spec/lutaml/model/lml_portable_json_spec.rb +310 -0
  88. data/spec/lutaml/model/lml_preservation_spec.rb +211 -0
  89. data/spec/lutaml/model/lml_review_export_spec.rb +247 -0
  90. data/spec/lutaml/model/lml_review_import_spec.rb +390 -0
  91. data/spec/lutaml/model/lml_review_misc_spec.rb +152 -0
  92. data/spec/lutaml/model/lml_review_round4_spec.rb +200 -0
  93. data/spec/lutaml/model/lml_review_round5_spec.rb +194 -0
  94. data/spec/lutaml/model/lml_ruby_interop_fixture_spec.rb +37 -0
  95. data/spec/lutaml/model/lml_shared_corpus_spec.rb +132 -0
  96. data/spec/lutaml/model/lml_value_declarations_spec.rb +128 -0
  97. data/spec/lutaml/model/schema/class_loader_spec.rb +51 -0
  98. data/spec/lutaml/model/schema/xml_compiler_runtime_spec.rb +20 -0
  99. data/spec/lutaml/model/sequence_spec.rb +48 -0
  100. data/spec/lutaml/xml/cdata_emission_spec.rb +68 -0
  101. data/spec/support/lml_any_attribute_fixtures.rb +26 -0
  102. data/spec/support/lml_conformance.rb +292 -0
  103. data/spec/support/lml_corpus.rb +75 -0
  104. data/spec/support/lml_export_fixtures.rb +190 -0
  105. data/spec/support/lml_graph_fixtures.rb +108 -0
  106. data/spec/support/lml_import_fixtures.rb +52 -0
  107. data/spec/support/lml_mapping_fixtures.rb +170 -0
  108. data/spec/support/lml_materialization_fixtures.rb +53 -0
  109. data/spec/support/lml_model_choices_fixtures.rb +150 -0
  110. data/spec/support/lml_order_fixtures.rb +151 -0
  111. metadata +92 -2
  112. data/lib/lutaml/model/schema/schema_builder/nokogiri.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d56a455e638084b3c3373c78a2be2d53a759a71601e4b1fc019fa8b289d68087
4
- data.tar.gz: e6c4b3d25dc38f58a9c8aa4ad2c0c38c2bf0e8fc24da3d149858a43e3cbb1510
3
+ metadata.gz: 230c2c513344d8665bb44607cefc80663100ac9707ee8ce63146e5b8ed6cbdbc
4
+ data.tar.gz: 2ac13fcbc47d3b7011c3957a6d988d3c996cf10fee05fe04040f82979b89d928
5
5
  SHA512:
6
- metadata.gz: 1895519a0829dc535771a764109f7ecc3bc58b947a9e0f3bb8b919f1db871ed07027376466f8845d926605941fff42c2663fab8db427b9769d02ad9f2692d25f
7
- data.tar.gz: a0986405eadf06fa748f91fb53d73a69e3c064988fefe9890dce9d497e75fc529ae42da587cbfabc143dedc12520b58397240127a22c18bb292cd26eacc3dc5b
6
+ metadata.gz: 1d0a5e9ac99b9ef4f68b6eb629ade317097f72d6d54187b3521f7007ccdfda47a4c03d7143040fe86987072b992d7e4741ef62c8b1a683f310b5191c391489bc
7
+ data.tar.gz: a0300c85e81232f5a07151c12d69575d0d0caf38c2540268baffcffe57d7d8744802a89030be6fd597f0109f148eaa9fcceddfcee2cb90f04fcade9696cab5ac
data/.gitattributes ADDED
@@ -0,0 +1,5 @@
1
+ # LML fixtures are pinned by byte checksums: never convert line endings.
2
+ spec/fixtures/lml_conformance/** -text
3
+ spec/fixtures/lml_contract/** -text
4
+ spec/fixtures/lml_artifacts/** -text
5
+ spec/fixtures/lml_mml/** -text
@@ -0,0 +1,71 @@
1
+ name: LML conformance
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ concurrency:
12
+ group: ${{ github.workflow }}-${{ github.ref }}
13
+ cancel-in-progress: true
14
+
15
+ jobs:
16
+ ruby:
17
+ runs-on: ubuntu-latest
18
+ env:
19
+ LML_MML_ROOT: ${{ github.workspace }}/.lml-inputs/mml
20
+ steps:
21
+ - uses: actions/checkout@v6
22
+ with:
23
+ submodules: recursive
24
+ - name: Check out the pinned source for available MML pilots
25
+ if: ${{ hashFiles('scripts/lml/export_mml.rb') != '' }}
26
+ uses: actions/checkout@v6
27
+ with:
28
+ repository: plurimath/mml
29
+ ref: d826d80f6b1477569c8320ccd945268a6ce1062f
30
+ path: .lml-inputs/mml
31
+ persist-credentials: false
32
+ - uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: "3.4"
35
+ bundler-cache: false
36
+ - name: Install dependencies
37
+ run: bundle install
38
+ - name: Replay pinned core and preservation packages
39
+ run: |
40
+ bundle exec ruby scripts/lml/export_conformance.rb --check
41
+ bundle exec ruby scripts/lml/export_preservation.rb --check
42
+ - name: Verify deterministic oracle regeneration
43
+ run: |
44
+ bundle exec ruby scripts/lml/export_conformance.rb --package "$RUNNER_TEMP/lml-core"
45
+ bundle exec ruby scripts/lml/export_preservation.rb --package "$RUNNER_TEMP/lml-preservation"
46
+ diff -r spec/fixtures/lml_conformance/core "$RUNNER_TEMP/lml-core"
47
+ diff -r spec/fixtures/lml_conformance/preservation "$RUNNER_TEMP/lml-preservation"
48
+ - name: Validate schema compatibility and fresh-process reconstruction
49
+ run: |
50
+ bundle exec ruby -rrspec/core -e 'RSpec.configure { |config| config.fail_if_no_examples = true }; exit RSpec::Core::Runner.run(ARGV)' -- spec/lutaml/model/lml_*_spec.rb
51
+ - name: Verify available MML pilot packages
52
+ run: |
53
+ if [[ -f scripts/lml/export_mml.rb ]]; then
54
+ test -f spec/lutaml/model/lml_mml_pilot_spec.rb
55
+ bundle exec ruby scripts/lml/export_mml.rb --check
56
+ bundle exec ruby -rrspec/core -e 'RSpec.configure { |config| config.fail_if_no_examples = true }; exit RSpec::Core::Runner.run(ARGV)' -- spec/lutaml/model/lml_mml_pilot_spec.rb
57
+ if [[ -f spec/lutaml/model/lml_mml_materialization_spec.rb ]]; then
58
+ bundle exec ruby -rrspec/core -e 'RSpec.configure { |config| config.fail_if_no_examples = true }; exit RSpec::Core::Runner.run(ARGV)' -- spec/lutaml/model/lml_mml_materialization_spec.rb
59
+ fi
60
+ else
61
+ echo "MML pilot package is not present in this revision."
62
+ fi
63
+ - name: Ensure verification leaves fixtures unchanged
64
+ run: |
65
+ git diff --exit-code -- spec/fixtures scripts/lml
66
+ untracked="$(git status --porcelain -- spec/fixtures scripts/lml)"
67
+ if [ -n "$untracked" ]; then
68
+ echo "Verification left untracked or modified files:"
69
+ echo "$untracked"
70
+ exit 1
71
+ fi
data/.gitignore CHANGED
@@ -12,6 +12,13 @@
12
12
  # rspec failure tracking
13
13
  .rspec_status
14
14
 
15
+ # LML mml pilot payloads: fetched from lutaml/lutaml-model-corpus at a
16
+ # pinned commit and verified against spec/fixtures/lml_mml/manifest.json
17
+ /spec/fixtures/lml_mml/v3-math-nested.json
18
+ /spec/fixtures/lml_mml/v3-math-nested.yaml
19
+ /spec/fixtures/lml_mml/v4-math-nested.json
20
+ /spec/fixtures/lml_mml/v4-math-nested.yaml
21
+
15
22
  # Direnv
16
23
  .direnv/
17
24
 
data/README.adoc CHANGED
@@ -59,6 +59,7 @@ link:docs/migration-guides/0-1-0-migrate-from-shale.adoc[Migrating from Shale to
59
59
  * Deep object comparison and visual diff generation with similarity scoring
60
60
  * Generate serialization schemas from model definitions (<<schema-generation>>)
61
61
  * Import serialization schemas to define models (<<schema-import>>)
62
+ * Export portable, versioned model declarations with the opt-in link:docs/_guides/lml-cross-language.adoc[LML cross-language contract]
62
63
  * Create custom adapters for additional data formats (see <<custom-adapters>>)
63
64
  * Dynamically modify model attribute types using registers (see <<custom-registers>>)
64
65
  * Per-class default register for versioned schemas (e.g., MathML v2, v3)
@@ -0,0 +1,128 @@
1
+ = Cross-language models with LML
2
+
3
+ LML (LutaML Model Language) is the opt-in boundary between a model declaration
4
+ and target-specific code. A Ruby exporter can describe attributes and format
5
+ mappings as neutral data. A consumer in another language can validate that data
6
+ and materialize its own model and writers. The contract is effective now; v2
7
+ bundle import, reconstruction, generators, and CLI commands are still landing.
8
+ See the link:../_references/lml-contract[LML contract reference] for the exact
9
+ wire format and current capability status.
10
+
11
+ == Start with the current Ruby projection
12
+
13
+ The Ruby v1 API exports a supported `Serializable` model and verifies it against
14
+ the current source class:
15
+
16
+ [source,ruby]
17
+ ----
18
+ document = Lutaml::Model::Lml.export(Catalog::Item)
19
+ File.write("item.lml.json", document.to_json)
20
+ Lutaml::Model::Lml.verify(document)
21
+ ----
22
+
23
+ `verify` is a source-drift check: it resolves the Ruby class named by the
24
+ document, exports that class again, and compares canonical declarations. It does
25
+ not build a replacement class. This v1 API does not yet export a portable v2
26
+ graph bundle.
27
+
28
+ == Planned portable workflow
29
+
30
+ The v2 workflow is opt-in and validates a complete dependency graph before
31
+ building target classes. Model IDs combine the portable model identity with its
32
+ effective register. References, nested models, value types, and discriminator
33
+ cases resolve by ID, so a target may choose different local class names.
34
+
35
+ The intended consumer sequence is:
36
+
37
+ . Export roots and their graph into a versioned LML bundle.
38
+ . Validate document versions, IDs, references, defaults, capabilities, and
39
+ checksums.
40
+ . Verify the pinned manifest, generator, source, corpus, dependencies, and file
41
+ hashes before loading artifacts.
42
+ . Materialize classes using trusted target bindings, then apply mappings.
43
+ . Run the pinned replay cases and report expected/executed IDs and counts.
44
+
45
+ The Ruby bundle exporter/importer, standalone TypeScript and Rust package
46
+ commands, artifact verification command, and CLI syntax are **PENDING**. The
47
+ contract names the operations, but their invocation syntax is not shipped. Do
48
+ not copy a pending command into a build or release script as if it were usable.
49
+
50
+ == Versions and target capabilities
51
+
52
+ |===
53
+ | Contract surface | Version and opt-in boundary | Availability at base `8a8ef040`
54
+
55
+ | Existing Ruby export
56
+ | v1 document; existing checksum rules
57
+ | Available as `Lutaml::Model::Lml.export` and `.verify`.
58
+
59
+ | Portable document
60
+ | v2 model documents in a v1 bundle; explicit opt-in exact codecs
61
+ | Contract effective; bundle producer/validator pending.
62
+
63
+ | Artifact
64
+ | Manifest v1, schema v2, pinned generator, target, capability and file digests
65
+ | Verifier and consumer loading pending.
66
+
67
+ | Ruby generation/reconstruction
68
+ | Validate, materialize, then apply mappings
69
+ | Pending; current `verify` only checks for source drift.
70
+
71
+ | TypeScript / Rust / WASM
72
+ | Same stable model IDs and semantic source/corpus pins; target-specific bytes
73
+ | Generators and consumer packages pending at this base.
74
+
75
+ | CLI
76
+ | Import, export, and compile operations
77
+ | Pending; no stable command syntax yet.
78
+ |===
79
+
80
+ Capabilities are declared as a sorted unique list. A consumer must reject a
81
+ missing required capability with `capability_missing`; it must not silently
82
+ ignore a mapping or type it cannot implement. Exact portable values use decimal
83
+ strings at cross-language boundaries, preserving precision and authored lexical
84
+ form. Portable codecs are opt-in and do not change existing Ruby serializers.
85
+
86
+ == Keep behavior in the target package
87
+
88
+ LML contains data, not Ruby method bodies or callbacks. Custom constructors,
89
+ Proc defaults, imperative element-order behavior, and custom serialization code
90
+ remain handwritten and produce named rejections when they cannot be represented
91
+ faithfully. Generated files contain the model and mapping declarations only;
92
+ the target application owns writers and behavior.
93
+
94
+ A compile-time PARG binding hook can associate a grammar rule with a stable LML
95
+ class ID for coradoc M2. Keep the binding outside the LML document so the same
96
+ schema can be consumed in Ruby, TypeScript, Rust, or WASM. A Ruby consumer may
97
+ prepend an external handwritten behavior module to a class produced by
98
+ `Schema::ClassLoader`; the module remains consumer-owned and is not folded into
99
+ the generated artifact. The hook and command/API details are **PENDING** until
100
+ they land.
101
+
102
+ Keep each consumer package standalone, with its own manifest, dependency pins,
103
+ replay corpus index, and CI. This permits future package relocation without
104
+ changing LML IDs or making the core repository a runtime dependency.
105
+
106
+ === Generated corpora live outside the working tree
107
+
108
+ The real mml pilot's exported graph payloads are hundreds of thousands of
109
+ lines, so they are not carried in this repository. They live in
110
+ link:https://github.com/lutaml/lutaml-model-corpus[lutaml/lutaml-model-corpus],
111
+ and `spec/support/lml_corpus.rb` fetches them at a pinned commit into
112
+ `spec/fixtures/lml_mml/` (gitignored) before the pilot and materialization
113
+ specs, or `scripts/lml/export_mml.rb --check`, read them. Every fetched file is
114
+ verified against the sha256 entries of
115
+ `spec/fixtures/lml_mml/manifest.json`; a mismatch is an error, never a silent
116
+ rewrite. The package's small files and the manifest stay in this repository.
117
+
118
+ To publish a regenerated corpus: run `bundle exec ruby scripts/lml/export_mml.rb`
119
+ (the mml source is pinned inside that script), copy the payload files into
120
+ lutaml-model-corpus under `lml_mml/`, merge them there, then point `REVISION` in
121
+ `spec/support/lml_corpus.rb` at the merged commit and commit the regenerated
122
+ manifest in the same change.
123
+
124
+ == See also
125
+
126
+ * link:../_references/lml-contract[LML contract reference]
127
+ * link:../_guides/grammar-backed-formats[Grammar-backed string formats]
128
+ * link:../_guides/gem-integration[Integrating lutaml-model in a gem]
@@ -0,0 +1,78 @@
1
+ = LML core conformance replay
2
+
3
+ The independently owned `spec/fixtures/lml_conformance/core` package is generated
4
+ by Ruby declarations in `spec/support/lml_conformance.rb`. It does not import a
5
+ parallel exporter's output as its oracle. `core-v2` pins the source baseline,
6
+ contract-authored v2 schema, Ruby parse/serialize results and negative results.
7
+ Changes to case meaning require a new generation and reviewed fixture updates.
8
+ Other corpus packages own separate indices and generators; there is no master
9
+ index and this generator never rewrites another package.
10
+
11
+ Run from the repository root:
12
+
13
+ [source,sh]
14
+ ----
15
+ bundle exec ruby -Ilib scripts/lml/export_conformance.rb --check
16
+ bundle exec rspec spec/lutaml/model/lml_conformance_spec.rb
17
+ ----
18
+
19
+ Without `--check`, the script regenerates the core package. `--package DIRECTORY`
20
+ selects an explicit copy of this package for replay or regeneration. The checker
21
+ never writes, and exits nonzero on missing, duplicate, unknown, changed or corrupt
22
+ cases/files. Its JSON report lists expected/executed IDs, both counts and errors
23
+ identified by case ID (or `package/PATH` for file failures). The runner executes
24
+ all supported cases, including expected failures, instead of treating an index
25
+ entry as evidence of implementation.
26
+
27
+ `index.json` follows corpus version 1, with generation, source revision, model ID,
28
+ semantic bundle checksum, input, normalized expected data, expected output,
29
+ comparison and structured expected error. `schema.json` and safely parsed
30
+ `schema.yaml` must describe the same neutral tree. Canonical JSON is UTF-8 compact
31
+ JSON with recursively sorted object keys, original array order, no BOM/trailing
32
+ newline and no Unicode normalization. The bundle checksum excludes provenance.
33
+ `manifest.json` version 1 hashes each payload's actual bytes, the index generation,
34
+ and the baseline gemspec dependency; it does not hash itself. Its external digest
35
+ is `sha256:` followed by SHA-256 of the complete canonical manifest bytes.
36
+
37
+ Every case explicitly names its `wire_profile` and `data_profile`. The four
38
+ original cases use `ruby-native-v1`: the existing Ruby XML/JSON mappings with the
39
+ Nokogiri XML adapter explicitly scoped for each execution. Their inputs and
40
+ outputs retain the original bytes, including numeric JSON `count:42`.
41
+ `data_profile:exact-values-decimal-v1` normalizes integer data to decimal strings;
42
+ booleans remain JSON booleans. Native numeric JSON is not portable exact JSON.
43
+ Model YAML I/O is not claimed. YAML here is a schema representation only.
44
+
45
+ `core-json-portable-exact` uses `wire_profile:portable-exact-json-v1` with the same
46
+ model/schema ID. Its input and expected output both contain the JSON string
47
+ `"count":"9007199254740993"`, above binary64's exact-integer range. A deliberately
48
+ small opt-in boundary for this three-field Ruby Record validates decimal-string
49
+ syntax, parses with `Integer(value, 10)`, supplies already typed data to the native
50
+ model, and emits the model's integer as a decimal string. It never uses Float and
51
+ rejects numeric input; it does not change existing serializers. This also avoids
52
+ the native String integer cast's Float conversion. Generated string-only codecs
53
+ can replay this case directly, without accepting native numeric wire values.
54
+
55
+ The index's `profiles` table lists `required_case_ids`; `target_profiles` requires
56
+ both profiles for Ruby and `portable-exact-json-v1` for Rust/TS. Consumers must
57
+ report the required profiles, expected/executed IDs and errors for each missing
58
+ required case. Passing native cases cannot substitute for the portable case.
59
+ Native-only IDs are explicitly outside Rust/TS's JSON profile, not silently
60
+ skipped. That JSON profile alone makes no XML replay claim. The Ruby `coverage`
61
+ helper demonstrates the same rule; its full replay requires all five cases.
62
+ All comparison modes still verify normalized data, and the portable case also
63
+ compares its actual string-valued JSON output to the expected output.
64
+
65
+ The pinned XML tree profile `expanded-names-text-v1` compares expanded namespace
66
+ URI/local names, sorted expanded attributes, significant decoded text and child
67
+ order. Namespace declarations and prefix spelling are excluded. Adjacent text
68
+ and CDATA merge into text. Whitespace is significant; DTDs, entity declarations,
69
+ processing instructions and unsupported nodes refuse. This is a restricted tree
70
+ profile, not W3C C14N. Separate `core-xml-bytes` assertions compare the serializer's
71
+ actual UTF-8 bytes, preserving declaration, prefix, escaping and formatting
72
+ choices. Tree equality never satisfies a required byte assertion.
73
+
74
+ The five baseline cases are `core-json`, `core-xml-tree`, `core-xml-bytes`,
75
+ `core-json-invalid` and `core-json-portable-exact`. They execute real Ruby models and preserve false, Unicode,
76
+ XML escaping, integer normalization and named parser failure. Namespace/state/
77
+ ordered-content preservation belongs to the independently generated preservation
78
+ package and is not claimed by this basic core corpus.
@@ -0,0 +1,290 @@
1
+ = LutaML Model Language (LML) contract
2
+
3
+ LML is a versioned, language-neutral description of model declarations. It carries
4
+ model data and mappings; it does not carry executable defaults, serializers,
5
+ constructors, or application behavior. This reference records the effective v2
6
+ contract from issue #1033. A contract being effective does not mean every
7
+ producer, consumer, or command has shipped; see the capability status below.
8
+
9
+ == Versions and identities
10
+
11
+ Existing valid v1 documents and their `.export` checksums retain their current
12
+ meaning. A v1 document is a single Ruby model projection. `Document.from_hash`
13
+ validates the supplied version; it does not silently rewrite it.
14
+
15
+ Portable graphs use document version 2 inside a version-1 bundle. The bundle
16
+ contains `roots`, `models`, `value_types`, `capabilities`, and `provenance`.
17
+ Every model is keyed by a stable ID formed as
18
+ `<qualified-model-name>@<effective-register>`. In v2, a missing or default
19
+ register is normalized to `default`; v1 identity is unchanged. Names that cannot
20
+ be represented portably are rejected. A consumer may materialize a Ruby class
21
+ under a different constant name while preserving the schema ID.
22
+
23
+ [source,json]
24
+ ----
25
+ {
26
+ "lml_bundle": 1,
27
+ "roots": ["Example::Node@default"],
28
+ "models": {
29
+ "Example::Node@default": {
30
+ "lml": 2,
31
+ "model": "Example::Node",
32
+ "register": "default",
33
+ "attributes": [],
34
+ "mappings": {},
35
+ "ordered_content": {"member": "__lml_content", "version": 1}
36
+ }
37
+ },
38
+ "value_types": {},
39
+ "capabilities": ["json", "xml"],
40
+ "provenance": {"source_revision": "SOURCE_SHA"}
41
+ }
42
+ ----
43
+
44
+ The example abbreviates attributes and mappings. Graph closure includes model,
45
+ import, reference, and discriminator targets in the effective register context.
46
+ Duplicate IDs with different definitions, dangling references, unknown versions,
47
+ and implicit global-context changes are errors. Models and value types are
48
+ key-sorted; roots and capabilities are sorted unique arrays. Attribute, rule,
49
+ enum, and sequence arrays keep declaration order.
50
+
51
+ == Attributes, values, and mappings
52
+
53
+ An attribute has a name, a tagged type, and only the optional declarations that
54
+ apply to it. Types are explicit: `{kind:"builtin",name:"string"}`;
55
+ `{kind:"model",id:"Example::Child@default"}`; or
56
+ `{kind:"value",id:"Example::Code@default"}`. A value type records a builtin
57
+ base and its facets. Trusted target bindings are supplied separately by stable
58
+ ID; a document never supplies code to evaluate.
59
+
60
+ A scalar omits `collection`. A collection has inclusive `min` and `max` bounds;
61
+ `max:null` means unbounded. Defaults distinguish absent from present-null:
62
+ `{"present":false}` versus `{"present":true,"value":null}`. False and empty
63
+ values are also preserved. Enum values keep their types. Polymorphism uses an
64
+ explicit discriminator attribute and a map from wire values to model IDs.
65
+ References identify their target model ID.
66
+
67
+ XML mappings may declare a root, namespace policy, ordered or mixed content,
68
+ sequence/choice bounds, and element, attribute, or content rules. Namespace
69
+ policy is exactly one of `{"mode":"inherit"}`,
70
+ `{"mode":"unqualified"}`, or
71
+ `{"mode":"uri","uri":"…","prefix":"…"}`. An absent namespace
72
+ policy means the documented Ruby default; it is not inferred from truthiness.
73
+ Aliases and sequence members preserve their declared order. JSON and YAML
74
+ mappings use key rules plus typed neutral `root_mappings` and `child_mappings`.
75
+
76
+ Ordinary declarative ordered and mixed content are supported by the contract.
77
+ Per-instance order uses the reserved `__lml_content` member, version 1. Its
78
+ tokens refer to a member and collection index, or carry literal text/CDATA.
79
+ Tokens control serialization order; grouped member traversal does not. Missing
80
+ indices, duplicate or inconsistent references, a source member with the reserved
81
+ name, or imperative order callbacks are rejected. This representation does not
82
+ change MML or replace instance order with a fixed sequence.
83
+
84
+ == Portable types and exact values
85
+
86
+ |===
87
+ | LML type | Portable representation | Notes
88
+
89
+ | String-like values, including token, URI, email, hostname, and IP
90
+ | UTF-8 string
91
+ | Declared lexical facets are retained.
92
+
93
+ | Boolean
94
+ | JSON boolean
95
+ | XML uses its declared lexical form.
96
+
97
+ | Integer and exact integer
98
+ | Decimal digits as a string at exact-value boundaries
99
+ | Structural bounds remain JSON integers; no IEEE-754 intermediate is allowed.
100
+
101
+ | Decimal and exact rational
102
+ | Decimal string
103
+ | Preserve authored lexical zeros where relevant. A reduced rational with a denominator containing primes other than 2 or 5 raises `nonterminating_rational` for decimal output.
104
+
105
+ | Date/time/duration
106
+ | Original declared lexical form
107
+ | Preserve timezone and lexical distinctions.
108
+
109
+ | QName
110
+ | Namespace URI and local-name pair
111
+ | The XML mapping resolves prefixes.
112
+
113
+ | Binary
114
+ | Declared base64 or hex string
115
+ | Runtime targets use byte containers.
116
+
117
+ | Symbol, hash, model, reference, union, enum, named XML ID/custom type
118
+ | Typed value, neutral tree, or stable ID as appropriate
119
+ | A custom type needs a trusted target binding and declared base/facets.
120
+
121
+ | Float, double, or unsupported platform type
122
+ | No lossy portable fallback
123
+ | Reject as `unsupported_type` unless an explicit lossless lexical contract exists.
124
+ |===
125
+
126
+ Portable exact codecs are opt-in and do not change existing Ruby serializers.
127
+ Missing and null remain distinct in every target. Source lexical values are kept
128
+ separately when precision or trailing zeros matter.
129
+
130
+ == Canonical bytes and checksums
131
+
132
+ Canonical JSON is compact UTF-8, has no BOM or trailing newline, sorts object
133
+ keys recursively, and preserves array order. It uses only JSON-required escapes:
134
+ `/` and non-ASCII characters are not escaped, and strings are not Unicode
135
+ normalized. Strings must contain valid Unicode; structural numbers are bounded
136
+ integers and exact values are strings. YAML input must safely parse to the same
137
+ tree without classes or aliases.
138
+
139
+ A v1 checksum follows its existing rules. A v2 model checksum covers the full
140
+ model document. A bundle semantic checksum covers the bundle except `provenance`.
141
+ Both use `sha256:<lowercase-hex>`. Documents and bundles are immutable snapshots,
142
+ so caller mutation cannot silently change a pinned identity.
143
+
144
+ == Errors and manifests
145
+
146
+ Validation and projection errors expose `reason`, `model_id`, optional attribute,
147
+ format, or rule, and a JSON pointer `location`; legacy `reason`, `klass`, and
148
+ `detail` remain available. Contract error codes include `unsupported_version`,
149
+ `invalid_document`, `duplicate_id`, `dangling_reference`, `unknown_type`,
150
+ `unsupported_type`, `missing_type_binding`, `unsupported_format`,
151
+ `unsupported_mapping`, `non_serializable_default`, `lambda_default`,
152
+ `custom_initialize`, `imperative_element_order`, `invalid_ordered_content`,
153
+ `reserved_member`, `nonterminating_rational`, `unknown_discriminator`,
154
+ `round_trip_mismatch`, `checksum_mismatch`, `capability_missing`, and
155
+ `not_serializable`. A producer or consumer must fail with a named error rather
156
+ than silently dropping a declaration.
157
+
158
+ Artifact manifest version 1 records the LML bundle checksum, schema version 2,
159
+ pinned generator version, target (`ruby`, `ts`, `rust`, or `wasm`), capabilities,
160
+ corpus generation and digest, file paths and actual-byte digests, and dependency
161
+ revisions and digests. File and dependency entries are sorted. The manifest
162
+ digest is external and covers the complete canonical manifest, avoiding
163
+ self-reference. A consumer supplies the expected digest and version and verifies
164
+ files, corpus, and dependencies before loading. Paths stay inside the artifact
165
+ root; traversal and symlink escapes fail. Generated bytes may differ by target,
166
+ while semantic source and corpus identity agree. Provenance does not change
167
+ schema identity.
168
+
169
+ Replay indexes pin generation, source revision, model ID, LML checksum, format,
170
+ input, expected data/output, comparison mode, and expected error. Comparison is
171
+ `data`, `xml_tree` under a pinned canonicalization profile, or `bytes`. Byte
172
+ sensitive cases assert bytes separately. A runner reports expected and executed
173
+ case IDs and counts and exits nonzero for missing, unimplemented, or corrupt
174
+ cases. Each standalone package owns its index and manifest; no shared mutable
175
+ master index is required.
176
+
177
+ == Capability status and opt-in entry points
178
+
179
+ The contract is effective; command availability follows the implementation in
180
+ your installed release. The status below is anchored to issue #1033 base
181
+ `8a8ef040` and must be updated as implementation cards merge.
182
+
183
+ |===
184
+ | Surface | Status at the documented base
185
+
186
+ | Ruby v1 model export and source-drift verification
187
+ | Available through `Lutaml::Model::Lml.export` and `.verify`; v1 checksums remain stable.
188
+
189
+ | Validated v2 documents, graph bundles, manifests, and reconstruction
190
+ | Contract defined; implementation pending.
191
+
192
+ | TypeScript and Rust bundle consumers and generators
193
+ | Contract defined; implementation and package commands pending.
194
+
195
+ | WASM consumers and artifact verification
196
+ | Contract defined; implementation and package commands pending.
197
+
198
+ | CLI import/export/compile commands
199
+ | Pending; no stable command syntax is published yet.
200
+ |===
201
+
202
+ Use the current Ruby API to export a supported v1 projection and check that it
203
+ still matches its source class:
204
+
205
+ [source,ruby]
206
+ ----
207
+ document = Lutaml::Model::Lml.export(Example::Node)
208
+ puts document.to_json
209
+ puts document.checksum
210
+ Lutaml::Model::Lml.verify(document)
211
+ ----
212
+
213
+ This verification resolves the recorded Ruby model and re-exports its current
214
+ declarations. It detects source drift; it does not reconstruct a new class from
215
+ the document. The portable v2 graph exporter, validator, artifact verifier,
216
+ materializer, mapping compiler, and CLI are separate opt-in capabilities. Their
217
+ commands are pending implementation and will be documented with exact syntax
218
+ when they land. Import must validate first, then materialize models and apply
219
+ mappings; it must not evaluate document-provided code.
220
+
221
+ == Target-local behavior and package boundaries
222
+
223
+ LML stores declarations and mappings, not executable application behavior.
224
+ Custom initializers, Proc/delegated defaults, imperative ordered-element
225
+ callbacks, and custom serialization methods have no declarative equivalent and
226
+ remain named rejections. Keep writers, constructors, and application methods
227
+ handwritten in the target package and outside generated artifacts.
228
+
229
+ A compiler may bind a PARG rule to a stable LML class ID at compile time. For
230
+ coradoc M2, this hook lets grammar rules name model identities without embedding
231
+ Ruby constants or runtime code in an LML document. Ruby consumers may prepend an
232
+ external handwritten behavior module to a `Schema::ClassLoader`-generated class;
233
+ the behavior module belongs to the consumer and remains outside the pinned
234
+ artifact. Binding and prepend command/API details are pending until their
235
+ implementation lands.
236
+
237
+ Cross-language packages stay standalone: each owns its dependencies, manifest,
238
+ corpus pins, and CI. This keeps the contract usable if packages later move out of
239
+ `lutaml-model`.
240
+
241
+
242
+ == Explicit model choices (version 1)
243
+
244
+ A v2 model document may contain `choices` with `version: 1`,
245
+ `validation: "explicit"`, and an ordered `groups` array. Bundles containing
246
+ this field require the `model.choices.v1` capability. Documents without
247
+ choices retain their previous canonical form.
248
+
249
+ Each group contains nonnegative integer `min`, integer or null `max`
250
+ (null means unbounded), `format` (null or `"xml"`), and ordered `members`.
251
+ A member contains exactly one of `attribute` (a declared attribute name)
252
+ or `choice` (another complete group). XML sequence choices remain mapping
253
+ compositors and are independent of these model validation groups.
254
+
255
+ Import restores native Choice objects. Model choices run during explicit
256
+ `validate`/`validate!`, rather than adding group validation to construction
257
+ or codec I/O. Existing field/type validation remains independent. Nested
258
+ lower-bound failures mean that alternative is absent; nested upper-bound
259
+ failures propagate. A valid nested group counts as one alternative,
260
+ including a valid empty group. False and whitespace are present values.
261
+ Finite collection batches, optional collection emptiness, and XML render
262
+ policies retain the native Choice algorithm; vector lengths must not be
263
+ summed as alternative counts. Unsupported versions, formats, or missing
264
+ members are refused rather than discarded.
265
+
266
+
267
+ == Trusted named-value export declarations
268
+
269
+ `ValueDeclarations.new({ ScalarClass => { "base" => "string",
270
+ "facets" => { "enumeration" => ["a", "b"] } } }, version: 1)` is an
271
+ opt-in, caller-owned registry. Pass it as `value_declarations:` to
272
+ `Lml.export_bundle`. Registry keys are exact named source Class objects;
273
+ strings, aliases, and subclasses do not acquire a declaration by inference.
274
+ Declarations contain neutral data only. They never serialize or evaluate
275
+ cast callbacks. The caller must prove each declared base/facet projection
276
+ matches the source class in the exported attribute context.
277
+
278
+ The emitted graph retains the existing v2 named-value reference and
279
+ `value_types` base/facets representation. Registry versioning is separate
280
+ from the IR version. `registry.to_h` records version and source class names
281
+ for producer manifests. Canonical bundle identity includes the emitted
282
+ value-type definitions. A missing declaration keeps the existing refusal.
283
+
284
+ Ruby import still requires explicit native `type_bindings` by value-type
285
+ ID. Target bindings stay separate from declaration bytes. Unsupported or
286
+ non-equivalent scalar behavior needs an honest trusted target binding;
287
+ it must not be replaced by an inferred XSD normalization. Qualified
288
+ attribute QNames are exported using the native namespace resolver and
289
+ restored with explicit qualified form when the attribute belongs to its
290
+ model namespace. Unrelated URI mappings remain refused by the Ruby DSL.