mml 2.4.7 → 2.4.9

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.
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Export the actual versioned model graphs through the upstream LML API.
4
+ require "json"
5
+ require "digest"
6
+ require "fileutils"
7
+ require "open3"
8
+ $stdout.sync = true
9
+
10
+ ROOT = File.expand_path("..", __dir__)
11
+ FRAMEWORK_REVISION = "fd2989fd8478b1ecb2508d98fa2d66792c09c72b"
12
+ MODEL_SOURCE_REVISION = "a88197810737e7eb809bbb5f887703a25beac3db"
13
+ framework = ENV.fetch("LUTAML_MODEL_SOURCE") do
14
+ abort "set LUTAML_MODEL_SOURCE to the pinned upstream source checkout"
15
+ end
16
+ revision, status = Open3.capture2("git", "-C", framework, "rev-parse", "HEAD")
17
+ abort "unexpected model framework revision" unless status.success? && revision.strip == FRAMEWORK_REVISION
18
+ changes, status = Open3.capture2("git", "-C", framework, "status", "--porcelain")
19
+ abort "the model framework checkout must be clean" unless status.success? && changes.empty?
20
+ $LOAD_PATH.unshift(File.join(File.expand_path(framework), "lib"))
21
+ $LOAD_PATH.unshift(File.join(ROOT, "lib"))
22
+ require "mml"
23
+ require "mml/version"
24
+ require "lutaml/model/lml"
25
+
26
+ abort "usage: ruby scripts/export_portable_models.rb OUTPUT_DIRECTORY" unless ARGV.length == 1
27
+ abort "the portable LML bundle API is unavailable" unless Lutaml::Model::Lml.respond_to?(:export_bundle)
28
+ if framework
29
+ source = Lutaml::Model::Lml.method(:export_bundle).source_location.first
30
+ expected = File.join(File.expand_path(framework), "lib/lutaml/model/lml.rb")
31
+ abort "a different model framework was loaded" unless File.realpath(source) == File.realpath(expected)
32
+ end
33
+
34
+ output = File.expand_path(ARGV.first)
35
+ FileUtils.mkdir_p(output)
36
+ manifest = {
37
+ "format" => "mml-portable-models/1",
38
+ "source_repository" => "https://github.com/plurimath/mml",
39
+ "source_revision" => MODEL_SOURCE_REVISION,
40
+ "source_version" => Mml::VERSION,
41
+ "framework_repository" => "https://github.com/lutaml/lutaml-model",
42
+ "framework_revision" => FRAMEWORK_REVISION,
43
+ "framework_status" => "open candidate; not a released dependency",
44
+ "versions" => {},
45
+ }
46
+
47
+ [3, 4].each do |version|
48
+ namespace = Mml.const_get("V#{version}")
49
+ config = namespace::Configuration
50
+ config.populate_context! unless config.context
51
+ register = config.context_id
52
+ bundle = Lutaml::Model::Lml.export_bundle(namespace::Math, register: register)
53
+ bytes = "#{JSON.generate(bundle.to_h)}\n"
54
+ filename = "mathml-v#{version}.bundle.json"
55
+ File.write(File.join(output, filename), bytes)
56
+ manifest["versions"][version.to_s] = {
57
+ "path" => filename,
58
+ "sha256" => Digest::SHA256.hexdigest(bytes),
59
+ "bundle_checksum" => bundle.checksum,
60
+ "models" => bundle.to_h.fetch("models").size,
61
+ "root" => bundle.to_h.fetch("roots").first,
62
+ "capabilities" => bundle.to_h.fetch("capabilities"),
63
+ }
64
+ puts "MathML #{version}: #{manifest['versions'][version.to_s]['models']} models, #{bundle.checksum}"
65
+ end
66
+ File.write(File.join(output, "manifest.json"), "#{JSON.pretty_generate(manifest)}\n")
@@ -0,0 +1,467 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Replays the plurimath-testsuite mathml stage generation pinned in
4
+ # spec/fixtures/testsuite-pin.yml at the gem's own boundary, model-roundtrip.
5
+ #
6
+ # Usage:
7
+ # bundle exec ruby scripts/replay_corpus.rb --testsuite PATH [--pin FILE] \
8
+ # [--language mathml] [--generation N] [--report FILE]
9
+ #
10
+ # Before any row runs it checks the pin: its schema and fields, that the
11
+ # checkout is at the pinned commit with no uncommitted stage files, that the
12
+ # ledger has the pinned generation with the pinned snapshot digest, that the
13
+ # digest recomputed from the generation's files is the same and that every
14
+ # payload has its recorded checksum. --language and --generation, when given,
15
+ # must equal the pin's. Then every row of every model-roundtrip payload is
16
+ # parsed with Mml.parse, its model written in the canonical tagged form that
17
+ # the testsuite's scripts/generate-xml-stage-cases.rb writes, serialized with
18
+ # to_xml, and the outcome (or the refusal) must equal the row's expected
19
+ # value. Payloads at other boundaries (the facade-output rows) are skipped.
20
+ # Any pin failure, any difference or a generation with no model-roundtrip
21
+ # rows exits 1.
22
+
23
+ require "bigdecimal"
24
+ require "digest"
25
+ require "fileutils"
26
+ require "json"
27
+ require "open3"
28
+ require "optparse"
29
+ require "yaml"
30
+ require "mml"
31
+
32
+ module MmlReplayCorpus
33
+ class Error < StandardError; end
34
+
35
+ ROOT = File.expand_path("..", __dir__)
36
+ DEFAULT_PIN = File.join(ROOT, "spec", "fixtures", "testsuite-pin.yml")
37
+ PIN_SCHEMA = "plurimath-stage/pin/1"
38
+ PIN_KEYS = %w[schema repository commit language generation
39
+ snapshot_digest].freeze
40
+ REPOSITORY = "https://github.com/plurimath/plurimath-testsuite"
41
+ LANGUAGE = "mathml"
42
+ BOUNDARY = "model-roundtrip"
43
+ RUN_OPTIONS = %i[language generation report].freeze
44
+ OPTIONS = [
45
+ [:testsuite, "--testsuite PATH"], [:pin, "--pin FILE"],
46
+ [:language, "--language NAME"], [:generation, "--generation N", Integer],
47
+ [:report, "--report FILE"]
48
+ ].freeze
49
+
50
+ # Each pin field's check, in order, with the message when it fails.
51
+ PIN_CHECKS = [
52
+ ["schema", ->(v) { v == PIN_SCHEMA },
53
+ ->(_) { "schema is not #{PIN_SCHEMA}" }],
54
+ ["repository", ->(v) { v == REPOSITORY },
55
+ ->(_) { "repository is not #{REPOSITORY}" }],
56
+ ["commit", ->(v) { v.is_a?(String) && v.match?(/\A\h{40}\z/) },
57
+ ->(_) { "commit is not a 40-hex commit" }],
58
+ ["language", ->(v) { v == LANGUAGE },
59
+ ->(v) { "language #{v.inspect} is not #{LANGUAGE}" }],
60
+ ["generation", ->(v) { v.is_a?(Integer) && v >= 1 },
61
+ ->(_) { "generation is not a positive integer" }],
62
+ ["snapshot_digest",
63
+ ->(v) { v.is_a?(String) && v.match?(/\Asha256:\h{64}\z/) },
64
+ ->(_) { "snapshot_digest is not sha256:<64 hex>" }],
65
+ ].freeze
66
+
67
+ Pin = Struct.new(:commit, :language, :generation, :digest,
68
+ keyword_init: true)
69
+
70
+ module_function
71
+
72
+ # The pin at +path+, its fields checked against plurimath-stage/pin/1.
73
+ def load_pin(path)
74
+ doc = YAML.safe_load_file(path, aliases: false)
75
+ raise Error, "#{path}: not a mapping" unless doc.is_a?(Hash)
76
+
77
+ check_pin_keys(path, doc)
78
+ check_pin_fields(path, doc)
79
+ Pin.new(commit: doc["commit"], language: doc["language"],
80
+ generation: doc["generation"], digest: doc["snapshot_digest"])
81
+ rescue Psych::Exception, Errno::ENOENT => e
82
+ raise Error, "#{path}: #{e.message}"
83
+ end
84
+
85
+ def check_pin_fields(path, doc)
86
+ PIN_CHECKS.each do |key, valid, message|
87
+ next if valid.call(doc[key])
88
+
89
+ raise Error, "#{path}: #{message.call(doc[key])}"
90
+ end
91
+ end
92
+
93
+ def check_pin_keys(path, doc)
94
+ missing = PIN_KEYS - doc.keys
95
+ extra = doc.keys - PIN_KEYS
96
+ raise Error, "#{path}: missing #{missing.join(', ')}" unless missing.empty?
97
+ raise Error, "#{path}: unknown keys #{extra.join(', ')}" unless extra.empty?
98
+ end
99
+
100
+ def git(dir, *args)
101
+ out, err, status = Open3.capture3("git", "-C", dir, *args)
102
+ unless status.success?
103
+ raise Error, "git #{args.join(' ')} in #{dir}: #{err.strip}"
104
+ end
105
+
106
+ out.strip
107
+ end
108
+
109
+ # The testsuite's snapshot digest of a generation's { path => bytes }.
110
+ def snapshot_digest(files)
111
+ lines = files.sort_by { |path, _| path.b }.map do |path, bytes|
112
+ "#{Digest::SHA256.hexdigest(bytes)} #{path}\n"
113
+ end
114
+ "sha256:#{Digest::SHA256.hexdigest(lines.join.encode('UTF-8'))}"
115
+ end
116
+
117
+ # [generation dir, { payload path => bytes }] once the checkout matches +pin+.
118
+ def verify(testsuite, pin)
119
+ check_checkout(testsuite, pin)
120
+ entry = ledger_entry(testsuite, pin)
121
+ files = generation_files(testsuite, entry, pin)
122
+ listed = check_provenance(entry, files)
123
+ [entry["path"], listed.to_h { |p| [p["path"], files.fetch(p["path"])] }]
124
+ rescue KeyError, Psych::Exception => e
125
+ raise Error, e.message
126
+ end
127
+
128
+ def check_checkout(testsuite, pin)
129
+ head = git(testsuite, "rev-parse", "HEAD")
130
+ unless head == pin.commit
131
+ raise Error, "pin commit #{pin.commit} is not the checkout's HEAD #{head}"
132
+ end
133
+
134
+ dirty = git(testsuite, "status", "--porcelain", "--", "stages",
135
+ "generations")
136
+ return if dirty.empty?
137
+
138
+ raise Error, "testsuite checkout has uncommitted stage files:\n#{dirty}"
139
+ end
140
+
141
+ def ledger_entry(testsuite, pin)
142
+ ledger_path = File.join(testsuite, "generations", "#{pin.language}.yaml")
143
+ raise Error, "#{ledger_path} does not exist" unless File.file?(ledger_path)
144
+
145
+ entries = YAML.safe_load_file(ledger_path, aliases: false).fetch("entries")
146
+ entry = entries.find { |e| e["generation"] == pin.generation }
147
+ unless entry
148
+ raise Error, "generations/#{pin.language}.yaml has no generation " \
149
+ "#{pin.generation}"
150
+ end
151
+ check_ledger_digest(entry, pin)
152
+ entry
153
+ end
154
+
155
+ def check_ledger_digest(entry, pin)
156
+ return if entry["snapshot_digest"] == pin.digest
157
+
158
+ raise Error, "ledger digest #{entry['snapshot_digest']} of generation " \
159
+ "#{pin.generation} is not the expected #{pin.digest}"
160
+ end
161
+
162
+ # { path => bytes } of the generation's files, its digest checked.
163
+ def generation_files(testsuite, entry, pin)
164
+ dir = File.join(testsuite, entry.fetch("path"))
165
+ files = generation_paths(dir, entry).to_h do |p|
166
+ [p, File.binread(File.join(dir, p))]
167
+ end
168
+ digest = snapshot_digest(files)
169
+ return files if digest == pin.digest
170
+
171
+ raise Error, "#{entry['path']}: digest #{digest} does not match the " \
172
+ "ledger's #{pin.digest}"
173
+ end
174
+
175
+ # The generation's file paths, none of them a symlink.
176
+ def generation_paths(dir, entry)
177
+ paths = Dir.glob("**/*", File::FNM_DOTMATCH, base: dir)
178
+ paths = paths.reject { |p| File.directory?(File.join(dir, p)) }
179
+ paths.each do |p|
180
+ next unless File.symlink?(File.join(dir, p))
181
+
182
+ raise Error, "#{entry['path']}/#{p} is a symlink"
183
+ end
184
+ paths
185
+ end
186
+
187
+ # The provenance's payload list, checked against the generation's files.
188
+ def check_provenance(entry, files)
189
+ provenance = YAML.safe_load(files.fetch("provenance.yaml") do
190
+ raise Error, "#{entry['path']} has no provenance.yaml"
191
+ end)
192
+ listed = provenance.fetch("payloads")
193
+ check_listed(entry, files, listed)
194
+ listed.each { |p| check_checksum(entry, files, p) }
195
+ listed
196
+ end
197
+
198
+ def check_listed(entry, files, listed)
199
+ payload_paths = (files.keys - ["provenance.yaml"]).sort
200
+ return if listed.map { |p| p["path"] }.sort == payload_paths
201
+
202
+ raise Error, "#{entry['path']}: provenance does not list exactly the " \
203
+ "payload files"
204
+ end
205
+
206
+ def check_checksum(entry, files, payload)
207
+ actual = Digest::SHA256.hexdigest(files.fetch(payload["path"]))
208
+ return if actual == payload["sha256"]
209
+
210
+ raise Error, "#{entry['path']}/#{payload['path']}: sha256 #{actual} " \
211
+ "is not #{payload['sha256']}"
212
+ end
213
+
214
+ # Every model-roundtrip row of the generation, with its payload path.
215
+ # Append-only supersession: a row whose id has an -r2 sibling is kept
216
+ # for history and is superseded by that sibling; only the sibling runs.
217
+ def roundtrip_rows(payloads)
218
+ rows = payloads.flat_map do |rel, bytes|
219
+ doc = YAML.safe_load(bytes, aliases: false)
220
+ next [] unless doc["boundary"] == BOUNDARY
221
+
222
+ doc.fetch("cases").map { |row| [rel, row] }
223
+ end
224
+ superseded = superseding_ids(rows)
225
+ rows.reject { |_, row| superseded.key?(row["id"]) }
226
+ end
227
+
228
+ # The ids superseded by their -r2 siblings, keyed by the original id.
229
+ def superseding_ids(rows)
230
+ ids = rows.map { |_, row| row["id"] }.select { |id| id.include?("-r2") }
231
+ ids.to_h { |id| [id.sub("-r2", ""), id] }
232
+ end
233
+
234
+ def decode(row, where)
235
+ value = row.fetch("input")
236
+ unless canonical?(value)
237
+ raise Error, "#{where}: input is not a canonical string"
238
+ end
239
+ unless row.fetch("options", {}).empty?
240
+ raise Error,
241
+ "#{where}: unsupported options #{row['options'].keys.join(', ')}"
242
+ end
243
+
244
+ value["str"]
245
+ end
246
+
247
+ def canonical?(value)
248
+ value.is_a?(Hash) && value.keys == ["str"] && value["str"].is_a?(String)
249
+ end
250
+
251
+ SCALAR_TAGS = {
252
+ NilClass => ->(_) { { "nil" => true } },
253
+ TrueClass => ->(v) { { "bool" => v } },
254
+ FalseClass => ->(v) { { "bool" => v } },
255
+ Integer => ->(v) { { "int" => v.to_s } },
256
+ Float => ->(v) { { "float" => v.inspect } },
257
+ BigDecimal => ->(v) { { "decimal" => v.to_s } },
258
+ Symbol => ->(v) { { "sym" => v.to_s } },
259
+ }.freeze
260
+
261
+ # The canonical tagged form of docs/tree-parity-contract.adoc, as
262
+ # scripts/generate-xml-stage-cases.rb writes it.
263
+ def tag(value, path = [])
264
+ case value
265
+ when String then tag_string(value)
266
+ when Array then { "array" => value.map { |v| tag(v, path) } }
267
+ when Hash then tag_hash(value, path)
268
+ when Lutaml::Model::Serializable then tag_model(value, path)
269
+ else tag_scalar(value)
270
+ end
271
+ end
272
+
273
+ def tag_scalar(value)
274
+ _, tagger = SCALAR_TAGS.find { |klass, _| value.is_a?(klass) }
275
+ raise Error, "no tagged form for #{value.class}" unless tagger
276
+
277
+ tagger.call(value)
278
+ end
279
+
280
+ def tag_hash(value, path)
281
+ { "hash" => value.map { |k, v| [tag(k, path), tag(v, path)] } }
282
+ end
283
+
284
+ def tag_string(value)
285
+ if value.encoding == Encoding::UTF_8 && value.valid_encoding?
286
+ { "str" => value.to_s }
287
+ else
288
+ { "bytes" => value.unpack1("H*"), "encoding" => value.encoding.name }
289
+ end
290
+ end
291
+
292
+ def tag_model(model, path)
293
+ if path.any? { |seen| seen.equal?(model) }
294
+ raise Error, "cycle at #{model.class}"
295
+ end
296
+
297
+ fields = model_fields(model, path + [model])
298
+ order = element_order(model)
299
+ fields << ["@element_order", order] if order
300
+ { "node" => model.class.name, "fields" => fields }
301
+ end
302
+
303
+ def element_order(model)
304
+ order = model.element_order if model.respond_to?(:element_order)
305
+ return if order.nil? || order.empty?
306
+
307
+ { "array" => order.map { |e| tag_order(e) } }
308
+ end
309
+
310
+ def model_fields(model, inner)
311
+ model.class.attributes.filter_map do |name, _attribute|
312
+ next if model.using_default?(name)
313
+
314
+ [name.to_s, tag(model.public_send(name), inner)]
315
+ end
316
+ end
317
+
318
+ def tag_order(entry)
319
+ pairs = [["type", entry.type], ["name", entry.name]]
320
+ pairs << ["text", entry.text_content] if entry.node_type == :text
321
+ { "hash" => pairs.map { |k, v| [{ "str" => k }, tag(v)] } }
322
+ end
323
+
324
+ def refusal(category, error)
325
+ { "refusal" => { "category" => category,
326
+ "error_class" => error.class.name } }
327
+ end
328
+
329
+ # The row's outcome, in the form the stage payloads record.
330
+ def outcome(input)
331
+ begin
332
+ model = Mml.parse(input)
333
+ rescue StandardError => e
334
+ return refusal("parse_error", e)
335
+ end
336
+ serialized_outcome(model)
337
+ end
338
+
339
+ def serialized_outcome(model)
340
+ begin
341
+ output = model.to_xml
342
+ rescue StandardError => e
343
+ return refusal("serialize_error", e)
344
+ end
345
+ { "model" => tag(model), "output" => tag_string(output) }
346
+ end
347
+
348
+ def replay(rows)
349
+ rows.filter_map do |rel, row|
350
+ actual = outcome(decode(row, "#{rel} #{row['id']}"))
351
+ next if actual == row.fetch("expected")
352
+
353
+ { "id" => row["id"], "payload" => rel, "expected" => row["expected"],
354
+ "actual" => actual }
355
+ end
356
+ end
357
+
358
+ # Options: language:, generation: (each must equal the pin's) and
359
+ # report: (a file to write the summary to).
360
+ def run(testsuite:, pin: DEFAULT_PIN, log: $stderr, **options)
361
+ check_run_options(options)
362
+ pinned = load_pin(pin)
363
+ check_expected(pinned, options)
364
+ rows, payloads = pinned_rows(testsuite, pinned)
365
+ log.puts "pin ok: #{pinned.language} generation #{pinned.generation} " \
366
+ "at #{pinned.commit}, #{pinned.digest}"
367
+ summary = summarize(pinned, rows, payloads, replay(rows))
368
+ write_report(options[:report], summary)
369
+ finish(log, rows, summary)
370
+ end
371
+
372
+ def check_run_options(options)
373
+ unknown = options.keys - RUN_OPTIONS
374
+ return if unknown.empty?
375
+
376
+ raise ArgumentError, "unknown keywords: #{unknown.join(', ')}"
377
+ end
378
+
379
+ def check_expected(pinned, options)
380
+ language = options[:language]
381
+ generation = options[:generation]
382
+ if language && language != pinned.language
383
+ raise Error, "--language #{language} is not the pinned #{pinned.language}"
384
+ end
385
+ return unless generation && generation != pinned.generation
386
+
387
+ raise Error,
388
+ "--generation #{generation} is not the pinned #{pinned.generation}"
389
+ end
390
+
391
+ def pinned_rows(testsuite, pinned)
392
+ _dir, payloads = verify(File.expand_path(testsuite), pinned)
393
+ rows = roundtrip_rows(payloads)
394
+ return [rows, payloads] unless rows.empty?
395
+
396
+ raise Error, "#{pinned.language} generation #{pinned.generation} has no " \
397
+ "#{BOUNDARY} rows"
398
+ end
399
+
400
+ def summarize(pinned, rows, payloads, failures)
401
+ replayed = rows.map(&:first).uniq.size
402
+ {
403
+ "commit" => pinned.commit, "language" => pinned.language,
404
+ "generation" => pinned.generation, "snapshot_digest" => pinned.digest,
405
+ "gem_version" => Mml::VERSION,
406
+ "#{BOUNDARY}_payloads" => replayed, "#{BOUNDARY}_rows" => rows.size,
407
+ "refusal_rows" => rows.count { |_, row| row["expected"].key?("refusal") },
408
+ "skipped_payloads" => payloads.size - replayed,
409
+ "mismatched_rows" => failures.size, "failures" => failures
410
+ }
411
+ end
412
+
413
+ def write_report(report, summary)
414
+ return unless report
415
+
416
+ FileUtils.mkdir_p(File.dirname(report))
417
+ File.binwrite(report, "#{JSON.pretty_generate(summary, max_nesting: false)}\n")
418
+ end
419
+
420
+ def finish(log, rows, summary)
421
+ failures = summary["failures"]
422
+ log.puts "#{rows.size} #{BOUNDARY} rows (#{summary['refusal_rows']} " \
423
+ "refusals) from #{summary["#{BOUNDARY}_payloads"]} payloads, " \
424
+ "#{summary['skipped_payloads']} other payloads skipped: " \
425
+ "#{failures.size} differ"
426
+ return summary if failures.empty?
427
+
428
+ raise Error, "#{failures.size} rows differ: " \
429
+ "#{failures.map { |f| f['id'] }.join(', ')}"
430
+ end
431
+
432
+ def main(argv)
433
+ options = parse_options(argv)
434
+ run(**options)
435
+ 0
436
+ rescue OptionParser::ParseError => e
437
+ warn e.message
438
+ 2
439
+ rescue Error => e
440
+ warn "replay_corpus: #{e.message}"
441
+ 1
442
+ end
443
+
444
+ def parse_options(argv)
445
+ options = {}
446
+ option_parser(options).parse!(argv)
447
+ unless options[:testsuite]
448
+ raise OptionParser::MissingArgument, "--testsuite"
449
+ end
450
+ raise OptionParser::InvalidOption, argv.join(" ") unless argv.empty?
451
+
452
+ options
453
+ end
454
+
455
+ def option_parser(options)
456
+ OptionParser.new do |o|
457
+ o.banner = "usage: scripts/replay_corpus.rb --testsuite PATH " \
458
+ "[--pin FILE] [--language NAME] [--generation N] " \
459
+ "[--report FILE]"
460
+ OPTIONS.each do |key, *switch|
461
+ o.on(*switch) { |v| options[key] = v }
462
+ end
463
+ end
464
+ end
465
+ end
466
+
467
+ exit MmlReplayCorpus.main(ARGV) if $PROGRAM_NAME == __FILE__
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ framework = ENV.fetch("LUTAML_MODEL_SOURCE")
5
+ $LOAD_PATH.unshift(File.join(File.expand_path(framework), "lib"))
6
+ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
7
+ require "mml"
8
+ require "lutaml/model/lml"
9
+
10
+ Lutaml::Model::Config.xml_adapter_type = :nokogiri
11
+ namespace = "http://www.w3.org/1998/Math/MathML"
12
+ inputs = {
13
+ "mi-mixed" => ["Mi", %(<mi xmlns="#{namespace}">x<malignmark/>y<mglyph src="g.png" alt="g"/>z</mi>)],
14
+ "mi-prefixed" => ["Mi", %(<m:mi xmlns:m="#{namespace}" mathvariant="bold">alpha</m:mi>)],
15
+ "math-nested" => ["Math", %(<math xmlns="#{namespace}" display="block"><mrow><mi>a</mi><mo>+</mo><mfrac><mi>x<malignmark/>y</mi><mrow><mn>1</mn><mo>+</mo><mn>2</mn></mrow></mfrac><mi>b</mi></mrow><mi>c</mi></math>)],
16
+ }
17
+ executed = []
18
+ [3, 4].each do |version|
19
+ mod = Mml.const_get("V#{version}")
20
+ config = mod::Configuration
21
+ config.populate_context! unless config.context
22
+ register = config.context_id
23
+ bundle = Lutaml::Model::Lml::Importer.bundle(Mml::Portable.bundle(version: version))
24
+ classes = Lutaml::Model::Lml.import_bundle(bundle)
25
+ inputs.each do |name, (class_name, input)|
26
+ source = mod.const_get(class_name).from_xml(input, register: register).to_xml(register: register)
27
+ klass = classes.fetch("Mml::V#{version}::#{class_name}@#{register}")
28
+ actual = klass.from_xml(input, register: register).to_xml(register: register)
29
+ abort "v#{version}-#{name}: imported writer differs from source" unless source == actual
30
+ repeated = klass.from_xml(actual, register: register).to_xml(register: register)
31
+ abort "v#{version}-#{name}: writer roundtrip is unstable" unless repeated == actual
32
+
33
+ executed << "v#{version}-#{name}"
34
+ puts "PASS #{executed.last}"
35
+ end
36
+ end
37
+ abort "expected exactly 6 model/writer cases" unless executed.size == 6
38
+ puts JSON.generate(expected: 6, executed: executed.size, failed: 0, case_ids: executed)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mml
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.7
4
+ version: 2.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-02 00:00:00.000000000 Z
11
+ date: 2026-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model
@@ -47,8 +47,11 @@ executables: []
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
+ - ".gitattributes"
51
+ - ".github/workflows/corpus.yml"
50
52
  - ".github/workflows/notify-mml-js.yml"
51
53
  - ".github/workflows/opal.yml"
54
+ - ".github/workflows/portable-models.yml"
52
55
  - ".github/workflows/rake.yml"
53
56
  - ".github/workflows/release.yml"
54
57
  - ".gitignore"
@@ -56,7 +59,6 @@ files:
56
59
  - ".rspec"
57
60
  - ".rubocop.yml"
58
61
  - ".rubocop_todo.yml"
59
- - CLAUDE.md
60
62
  - CODE_OF_CONDUCT.md
61
63
  - Gemfile
62
64
  - README.adoc
@@ -172,6 +174,7 @@ files:
172
174
  - lib/mml/context_options.rb
173
175
  - lib/mml/namespace.rb
174
176
  - lib/mml/opal.rb
177
+ - lib/mml/portable.rb
175
178
  - lib/mml/v2.rb
176
179
  - lib/mml/v2/annotation.rb
177
180
  - lib/mml/v2/annotation_xml.rb
@@ -397,6 +400,9 @@ files:
397
400
  - lib/mml/version.rb
398
401
  - lib/mml/versioned_parser.rb
399
402
  - mml.gemspec
403
+ - model/portable/manifest.json
404
+ - model/portable/mathml-v3.bundle.json
405
+ - model/portable/mathml-v4.bundle.json
400
406
  - reference-docs/mathml-source/pubtext/mathmlspec.dtd
401
407
  - reference-docs/mathml-source/pubtext/xmlspec.dtd
402
408
  - reference-docs/mathml-source/readme.txt
@@ -477,6 +483,9 @@ files:
477
483
  - schemas/mathml4/mathml4.rnc
478
484
  - schemas/mathml4/mathml4.rnc.1
479
485
  - schemas/mathml4/mathml4.rng
486
+ - scripts/export_portable_models.rb
487
+ - scripts/replay_corpus.rb
488
+ - scripts/verify_portable_models.rb
480
489
  - sig/mml.rbs
481
490
  homepage: https://github.com/plurimath/mml
482
491
  licenses: