omml 0.2.11 → 0.2.12
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.
- checksums.yaml +4 -4
- data/.gitattributes +12 -0
- data/.github/workflows/corpus.yml +106 -0
- data/.github/workflows/portable.yml +47 -0
- data/.github/workflows/release.yml +1 -0
- data/.rubocop.yml +5 -0
- data/README.adoc +27 -0
- data/lib/omml/models/ct_anchor.rb +2 -2
- data/lib/omml/models/ct_on_off.rb +1 -1
- data/lib/omml/models/ct_wordprocessing_on_off.rb +1 -1
- data/lib/omml/models/simple_types/st_hex_color_auto.rb +15 -0
- data/lib/omml/models/simple_types/st_hex_color_rgb.rb +9 -0
- data/lib/omml/models/simple_types/st_lang_code.rb +9 -0
- data/lib/omml/models.rb +3 -0
- data/lib/omml/opal.rb +1 -0
- data/lib/omml/portable.rb +192 -0
- data/lib/omml/version.rb +1 -1
- data/lib/omml.rb +1 -0
- data/model/portable/bindings/coordinate.rs +153 -0
- data/model/portable/bindings/coordinate.ts +74 -0
- data/model/portable/bindings/integer.rs +110 -0
- data/model/portable/bindings/integer.ts +74 -0
- data/model/portable/bindings/token.rs +30 -0
- data/model/portable/bindings/token.ts +16 -0
- data/model/portable/enum-subset-v1.json +1 -0
- data/model/portable/manifest.json +933 -0
- data/model/portable/runtime-graph-v1.json +1 -0
- data/model/portable/scalar-subset-v1.json +1 -0
- data/omml.gemspec +2 -1
- data/scripts/export_portable_models.rb +90 -0
- data/scripts/replay_corpus.rb +458 -0
- metadata +21 -3
- data/CLAUDE.md +0 -74
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"lml_bundle":1,"roots":["Omml::Models::CTHpsMeasure@omml","Omml::Models::CTInteger2@omml","Omml::Models::CTManualBreak@omml","Omml::Models::CTSpacingRule@omml","Omml::Models::CTText@omml","Omml::Models::CTUnSignedInteger@omml","Omml::Models::CTWordprocessingText@omml"],"models":{"Omml::Models::CTHpsMeasure@omml":{"lml":2,"model":"Omml::Models::CTHpsMeasure","register":"omml","attributes":[{"name":"val","type":{"kind":"value","id":"Omml::Models::UnsignedLong@omml"},"required":false,"collection":false,"default":{"present":false},"initialize_empty":false}],"mappings":{"xml":{"root":{"element":"CT_HpsMeasure"},"rules":[{"kind":"attribute","name":["val"],"to":"val","render":{"nil":"omit","empty":"omit","default":false},"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}],"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}}},"Omml::Models::CTInteger2@omml":{"lml":2,"model":"Omml::Models::CTInteger2","register":"omml","attributes":[{"name":"val","type":{"kind":"value","id":"Omml::Models::STInteger2@omml"},"required":false,"collection":false,"default":{"present":false},"initialize_empty":false}],"mappings":{"xml":{"root":{"element":"CT_Integer2"},"rules":[{"kind":"attribute","name":["val"],"to":"val","render":{"nil":"omit","empty":"omit","default":false},"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}],"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}}},"Omml::Models::CTManualBreak@omml":{"lml":2,"model":"Omml::Models::CTManualBreak","register":"omml","attributes":[{"name":"aln_at","type":{"kind":"value","id":"Omml::Models::STInteger255@omml"},"required":false,"collection":false,"default":{"present":false},"initialize_empty":false}],"mappings":{"xml":{"root":{"element":"CT_ManualBreak"},"rules":[{"kind":"attribute","name":["alnAt"],"to":"aln_at","render":{"nil":"omit","empty":"omit","default":false},"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}],"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}}},"Omml::Models::CTSpacingRule@omml":{"lml":2,"model":"Omml::Models::CTSpacingRule","register":"omml","attributes":[{"name":"val","type":{"kind":"value","id":"Omml::Models::STSpacingRule@omml"},"required":false,"collection":false,"default":{"present":false},"initialize_empty":false}],"mappings":{"xml":{"root":{"element":"CT_SpacingRule"},"rules":[{"kind":"attribute","name":["val"],"to":"val","render":{"nil":"omit","empty":"omit","default":false},"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}],"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}}},"Omml::Models::CTText@omml":{"lml":2,"model":"Omml::Models::CTText","register":"omml","attributes":[{"name":"content","type":{"kind":"builtin","name":"string"},"required":false,"collection":false,"default":{"present":false},"initialize_empty":false},{"name":"space","type":{"kind":"value","id":"Lutaml::Xml::W3c::XmlSpaceType@omml"},"required":false,"collection":false,"default":{"present":false},"initialize_empty":false}],"mappings":{"xml":{"root":{"element":"CT_Text"},"rules":[{"kind":"attribute","name":["space"],"to":"space","render":{"nil":"omit","empty":"omit","default":false},"namespace":{"mode":"uri","uri":"http://www.w3.org/XML/1998/namespace","prefix":"xml"}},{"kind":"content","to":"content","render":{"nil":"omit","empty":"omit","default":false}}],"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}}},"Omml::Models::CTUnSignedInteger@omml":{"lml":2,"model":"Omml::Models::CTUnSignedInteger","register":"omml","attributes":[{"name":"val","type":{"kind":"value","id":"Omml::Models::UnsignedInt@omml"},"required":false,"collection":false,"default":{"present":false},"initialize_empty":false}],"mappings":{"xml":{"root":{"element":"CT_UnSignedInteger"},"rules":[{"kind":"attribute","name":["val"],"to":"val","render":{"nil":"omit","empty":"omit","default":false},"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}],"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/officeDocument/2006/math","prefix":"m"}}}},"Omml::Models::CTWordprocessingText@omml":{"lml":2,"model":"Omml::Models::CTWordprocessingText","register":"omml","attributes":[{"name":"content","type":{"kind":"builtin","name":"string"},"required":false,"collection":false,"default":{"present":false},"initialize_empty":false},{"name":"space","type":{"kind":"value","id":"Lutaml::Xml::W3c::XmlSpaceType@omml"},"required":false,"collection":false,"default":{"present":false},"initialize_empty":false}],"mappings":{"xml":{"root":{"element":"CT_Text"},"rules":[{"kind":"attribute","name":["space"],"to":"space","render":{"nil":"omit","empty":"omit","default":false},"namespace":{"mode":"uri","uri":"http://www.w3.org/XML/1998/namespace","prefix":"xml"}},{"kind":"content","to":"content","render":{"nil":"omit","empty":"omit","default":false}}],"namespace":{"mode":"uri","uri":"http://schemas.openxmlformats.org/wordprocessingml/2006/main","prefix":"w"}}}}},"value_types":{"Lutaml::Xml::W3c::XmlSpaceType@omml":{"base":"string","facets":{"enumeration":["default","preserve"]}},"Omml::Models::STInteger255@omml":{"base":"integer","facets":{"min_inclusive":"1","max_inclusive":"255","source_binding_v1":true}},"Omml::Models::STInteger2@omml":{"base":"integer","facets":{"min_inclusive":"-2","max_inclusive":"2","source_binding_v1":true}},"Omml::Models::STSpacingRule@omml":{"base":"integer","facets":{"min_inclusive":"0","max_inclusive":"4","source_binding_v1":true}},"Omml::Models::UnsignedInt@omml":{"base":"integer","facets":{"min_inclusive":"0","max_inclusive":"4294967295","source_binding_v1":true}},"Omml::Models::UnsignedLong@omml":{"base":"integer","facets":{"min_inclusive":"0","max_inclusive":"18446744073709551615","source_binding_v1":true}}},"capabilities":["xml"]}
|
data/omml.gemspec
CHANGED
|
@@ -22,7 +22,8 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
# `git ls-files -z` loads files that have been added to git.
|
|
23
23
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
24
24
|
`git ls-files -z`.split("\x0").reject do |f|
|
|
25
|
-
f.match(%r{^(test|spec|features)/})
|
|
25
|
+
f.match?(%r{^(test|spec|features|\.ci)/}) ||
|
|
26
|
+
f.match?(/\A(?:CLAUDE|AGENTS)\.md\z/)
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
29
|
spec.bindir = "exe"
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "digest"
|
|
5
|
+
require "fileutils"
|
|
6
|
+
require "open3"
|
|
7
|
+
require "omml"
|
|
8
|
+
|
|
9
|
+
root = File.expand_path("..", __dir__)
|
|
10
|
+
destination = ARGV.shift || File.join(root, "model/portable")
|
|
11
|
+
abort("usage: export_portable_models.rb [OUTPUT_DIRECTORY]") unless ARGV.empty?
|
|
12
|
+
framework_source = ENV.fetch("LUTAML_MODEL_SOURCE")
|
|
13
|
+
expected_framework = ENV.fetch("LUTAML_MODEL_COMMIT")
|
|
14
|
+
framework_head, status = Open3.capture2("git", "-C", framework_source,
|
|
15
|
+
"rev-parse", "HEAD")
|
|
16
|
+
unless status.success? && framework_head.strip == expected_framework
|
|
17
|
+
abort("framework source pin mismatch")
|
|
18
|
+
end
|
|
19
|
+
Omml::Portable.value_declarations
|
|
20
|
+
changes, clean = Open3.capture2("git", "-C", framework_source, "status",
|
|
21
|
+
"--porcelain", "--untracked-files=all",
|
|
22
|
+
"--", "lib")
|
|
23
|
+
abort("framework source status unavailable") unless clean.success?
|
|
24
|
+
unless changes.empty?
|
|
25
|
+
abort("framework runtime source contains uncommitted changes")
|
|
26
|
+
end
|
|
27
|
+
registry_class = Lutaml::Model::Lml::ValueDeclarations
|
|
28
|
+
location = registry_class.instance_method(:initialize).source_location.first
|
|
29
|
+
expected_directory = "#{File.expand_path(framework_source)}/lib/"
|
|
30
|
+
unless File.expand_path(location).start_with?(expected_directory)
|
|
31
|
+
abort("framework runtime is not the pinned source checkout")
|
|
32
|
+
end
|
|
33
|
+
FileUtils.mkdir_p(destination)
|
|
34
|
+
runtime_roots = %i[
|
|
35
|
+
CTDrawing CTFFCheckBox CTFFData CTFldChar
|
|
36
|
+
CTMathPr CTPosH CTPosV CTR
|
|
37
|
+
CTRPR CTRunTrackChange CTSdtEndPr CTSdtPr
|
|
38
|
+
EGContentRunContent EGMathContent EGOMathElements EGOMathMathElements
|
|
39
|
+
EGPContent EGRPrMath EGRangeMarkupElements EGRubyContent
|
|
40
|
+
EGRunInnerContent EGRunLevelElts EGWordRunInnerContent EGWrapType
|
|
41
|
+
CTOMath CTOMathPara OMath OMathPara
|
|
42
|
+
].map { |name| Omml::Models.const_get(name, false) }
|
|
43
|
+
subsets = {
|
|
44
|
+
"enum-subset-v1" => [Omml::Models::CTBr],
|
|
45
|
+
"runtime-graph-v1" => runtime_roots,
|
|
46
|
+
"scalar-subset-v1" => [
|
|
47
|
+
Omml::Models::CTHpsMeasure,
|
|
48
|
+
Omml::Models::CTInteger2,
|
|
49
|
+
Omml::Models::CTManualBreak,
|
|
50
|
+
Omml::Models::CTSpacingRule,
|
|
51
|
+
Omml::Models::CTText,
|
|
52
|
+
Omml::Models::CTUnSignedInteger,
|
|
53
|
+
Omml::Models::CTWordprocessingText,
|
|
54
|
+
],
|
|
55
|
+
}
|
|
56
|
+
graphs = subsets.to_h do |id, roots|
|
|
57
|
+
bundle = Omml::Portable.export_bundle(roots)
|
|
58
|
+
filename = "#{id}.json"
|
|
59
|
+
bytes = "#{JSON.generate(bundle.to_h)}\n"
|
|
60
|
+
File.binwrite(File.join(destination, filename), bytes)
|
|
61
|
+
[id, {
|
|
62
|
+
"file" => filename, "sha256" => Digest::SHA256.hexdigest(bytes),
|
|
63
|
+
"lml_checksum" => bundle.checksum, "models" => bundle.models.length,
|
|
64
|
+
"value_types" => bundle.value_types.length
|
|
65
|
+
}]
|
|
66
|
+
end
|
|
67
|
+
binding_directory = File.join(root, "model/portable/bindings")
|
|
68
|
+
binding_files = %w[
|
|
69
|
+
coordinate.rs coordinate.ts integer.rs integer.ts token.rs token.ts
|
|
70
|
+
]
|
|
71
|
+
binding_sources = binding_files.to_h do |filename|
|
|
72
|
+
digest = Digest::SHA256.file(File.join(binding_directory, filename)).hexdigest
|
|
73
|
+
[filename, digest]
|
|
74
|
+
end
|
|
75
|
+
source_head, source_status = Open3.capture2("git", "-C", root, "rev-parse",
|
|
76
|
+
"HEAD")
|
|
77
|
+
abort("source repository unavailable") unless source_status.success?
|
|
78
|
+
manifest = {
|
|
79
|
+
"manifest" => 1, "registry" => Omml::Portable.value_declarations.to_h,
|
|
80
|
+
"graphs" => graphs,
|
|
81
|
+
"binding_sources" => binding_sources,
|
|
82
|
+
"producer" => {
|
|
83
|
+
"source_commit" => source_head.strip,
|
|
84
|
+
"framework_commit" => expected_framework, "ruby" => RUBY_VERSION,
|
|
85
|
+
"scope" => "CTBr, scalar subsets, and the OMML runtime graph"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
File.write(File.join(destination, "manifest.json"),
|
|
89
|
+
"#{JSON.pretty_generate(manifest)}\n")
|
|
90
|
+
puts JSON.generate(graphs)
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Replays the plurimath-testsuite omml 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 omml] [--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 Omml.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 "omml"
|
|
31
|
+
|
|
32
|
+
module OmmlReplayCorpus
|
|
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 = "omml"
|
|
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
|
+
def roundtrip_rows(payloads)
|
|
216
|
+
payloads.flat_map do |rel, bytes|
|
|
217
|
+
doc = YAML.safe_load(bytes, aliases: false)
|
|
218
|
+
next [] unless doc["boundary"] == BOUNDARY
|
|
219
|
+
|
|
220
|
+
doc.fetch("cases").map { |row| [rel, row] }
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def decode(row, where)
|
|
225
|
+
value = row.fetch("input")
|
|
226
|
+
unless canonical?(value)
|
|
227
|
+
raise Error, "#{where}: input is not a canonical string"
|
|
228
|
+
end
|
|
229
|
+
unless row.fetch("options", {}).empty?
|
|
230
|
+
raise Error,
|
|
231
|
+
"#{where}: unsupported options #{row['options'].keys.join(', ')}"
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
value["str"]
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def canonical?(value)
|
|
238
|
+
value.is_a?(Hash) && value.keys == ["str"] && value["str"].is_a?(String)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
SCALAR_TAGS = {
|
|
242
|
+
NilClass => ->(_) { { "nil" => true } },
|
|
243
|
+
TrueClass => ->(v) { { "bool" => v } },
|
|
244
|
+
FalseClass => ->(v) { { "bool" => v } },
|
|
245
|
+
Integer => ->(v) { { "int" => v.to_s } },
|
|
246
|
+
Float => ->(v) { { "float" => v.inspect } },
|
|
247
|
+
BigDecimal => ->(v) { { "decimal" => v.to_s } },
|
|
248
|
+
Symbol => ->(v) { { "sym" => v.to_s } },
|
|
249
|
+
}.freeze
|
|
250
|
+
|
|
251
|
+
# The canonical tagged form of docs/tree-parity-contract.adoc, as
|
|
252
|
+
# scripts/generate-xml-stage-cases.rb writes it.
|
|
253
|
+
def tag(value, path = [])
|
|
254
|
+
case value
|
|
255
|
+
when String then tag_string(value)
|
|
256
|
+
when Array then { "array" => value.map { |v| tag(v, path) } }
|
|
257
|
+
when Hash then tag_hash(value, path)
|
|
258
|
+
when Lutaml::Model::Serializable then tag_model(value, path)
|
|
259
|
+
else tag_scalar(value)
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def tag_scalar(value)
|
|
264
|
+
_, tagger = SCALAR_TAGS.find { |klass, _| value.is_a?(klass) }
|
|
265
|
+
raise Error, "no tagged form for #{value.class}" unless tagger
|
|
266
|
+
|
|
267
|
+
tagger.call(value)
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def tag_hash(value, path)
|
|
271
|
+
{ "hash" => value.map { |k, v| [tag(k, path), tag(v, path)] } }
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def tag_string(value)
|
|
275
|
+
if value.encoding == Encoding::UTF_8 && value.valid_encoding?
|
|
276
|
+
{ "str" => value.to_s }
|
|
277
|
+
else
|
|
278
|
+
{ "bytes" => value.unpack1("H*"), "encoding" => value.encoding.name }
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def tag_model(model, path)
|
|
283
|
+
if path.any? { |seen| seen.equal?(model) }
|
|
284
|
+
raise Error, "cycle at #{model.class}"
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
fields = model_fields(model, path + [model])
|
|
288
|
+
order = element_order(model)
|
|
289
|
+
fields << ["@element_order", order] if order
|
|
290
|
+
{ "node" => model.class.name, "fields" => fields }
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def element_order(model)
|
|
294
|
+
order = model.element_order if model.respond_to?(:element_order)
|
|
295
|
+
return if order.nil? || order.empty?
|
|
296
|
+
|
|
297
|
+
{ "array" => order.map { |e| tag_order(e) } }
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def model_fields(model, inner)
|
|
301
|
+
model.class.attributes.filter_map do |name, _attribute|
|
|
302
|
+
next if model.using_default?(name)
|
|
303
|
+
|
|
304
|
+
[name.to_s, tag(model.public_send(name), inner)]
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
def tag_order(entry)
|
|
309
|
+
pairs = [["type", entry.type], ["name", entry.name]]
|
|
310
|
+
pairs << ["text", entry.text_content] if entry.node_type == :text
|
|
311
|
+
{ "hash" => pairs.map { |k, v| [{ "str" => k }, tag(v)] } }
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
def refusal(category, error)
|
|
315
|
+
{ "refusal" => { "category" => category,
|
|
316
|
+
"error_class" => error.class.name } }
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
# The row's outcome, in the form the stage payloads record.
|
|
320
|
+
def outcome(input)
|
|
321
|
+
begin
|
|
322
|
+
model = Omml.parse(input)
|
|
323
|
+
rescue StandardError => e
|
|
324
|
+
return refusal("parse_error", e)
|
|
325
|
+
end
|
|
326
|
+
serialized_outcome(model)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def serialized_outcome(model)
|
|
330
|
+
begin
|
|
331
|
+
output = model.to_xml
|
|
332
|
+
rescue StandardError => e
|
|
333
|
+
return refusal("serialize_error", e)
|
|
334
|
+
end
|
|
335
|
+
{ "model" => tag(model), "output" => tag_string(output) }
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
def replay(rows)
|
|
339
|
+
rows.filter_map do |rel, row|
|
|
340
|
+
actual = outcome(decode(row, "#{rel} #{row['id']}"))
|
|
341
|
+
next if actual == row.fetch("expected")
|
|
342
|
+
|
|
343
|
+
{ "id" => row["id"], "payload" => rel, "expected" => row["expected"],
|
|
344
|
+
"actual" => actual }
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
# Options: language:, generation: (each must equal the pin's) and
|
|
349
|
+
# report: (a file to write the summary to).
|
|
350
|
+
def run(testsuite:, pin: DEFAULT_PIN, log: $stderr, **options)
|
|
351
|
+
check_run_options(options)
|
|
352
|
+
pinned = load_pin(pin)
|
|
353
|
+
check_expected(pinned, options)
|
|
354
|
+
rows, payloads = pinned_rows(testsuite, pinned)
|
|
355
|
+
log.puts "pin ok: #{pinned.language} generation #{pinned.generation} " \
|
|
356
|
+
"at #{pinned.commit}, #{pinned.digest}"
|
|
357
|
+
summary = summarize(pinned, rows, payloads, replay(rows))
|
|
358
|
+
write_report(options[:report], summary)
|
|
359
|
+
finish(log, rows, summary)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
def check_run_options(options)
|
|
363
|
+
unknown = options.keys - RUN_OPTIONS
|
|
364
|
+
return if unknown.empty?
|
|
365
|
+
|
|
366
|
+
raise ArgumentError, "unknown keywords: #{unknown.join(', ')}"
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
def check_expected(pinned, options)
|
|
370
|
+
language = options[:language]
|
|
371
|
+
generation = options[:generation]
|
|
372
|
+
if language && language != pinned.language
|
|
373
|
+
raise Error, "--language #{language} is not the pinned #{pinned.language}"
|
|
374
|
+
end
|
|
375
|
+
return unless generation && generation != pinned.generation
|
|
376
|
+
|
|
377
|
+
raise Error,
|
|
378
|
+
"--generation #{generation} is not the pinned #{pinned.generation}"
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
def pinned_rows(testsuite, pinned)
|
|
382
|
+
_dir, payloads = verify(File.expand_path(testsuite), pinned)
|
|
383
|
+
rows = roundtrip_rows(payloads)
|
|
384
|
+
return [rows, payloads] unless rows.empty?
|
|
385
|
+
|
|
386
|
+
raise Error, "#{pinned.language} generation #{pinned.generation} has no " \
|
|
387
|
+
"#{BOUNDARY} rows"
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
def summarize(pinned, rows, payloads, failures)
|
|
391
|
+
replayed = rows.map(&:first).uniq.size
|
|
392
|
+
{
|
|
393
|
+
"commit" => pinned.commit, "language" => pinned.language,
|
|
394
|
+
"generation" => pinned.generation, "snapshot_digest" => pinned.digest,
|
|
395
|
+
"gem_version" => Omml::VERSION,
|
|
396
|
+
"#{BOUNDARY}_payloads" => replayed, "#{BOUNDARY}_rows" => rows.size,
|
|
397
|
+
"refusal_rows" => rows.count { |_, row| row["expected"].key?("refusal") },
|
|
398
|
+
"skipped_payloads" => payloads.size - replayed,
|
|
399
|
+
"mismatched_rows" => failures.size, "failures" => failures
|
|
400
|
+
}
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
def write_report(report, summary)
|
|
404
|
+
return unless report
|
|
405
|
+
|
|
406
|
+
FileUtils.mkdir_p(File.dirname(report))
|
|
407
|
+
File.binwrite(report,
|
|
408
|
+
"#{JSON.pretty_generate(summary, max_nesting: false)}\n")
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
def finish(log, rows, summary)
|
|
412
|
+
failures = summary["failures"]
|
|
413
|
+
log.puts "#{rows.size} #{BOUNDARY} rows (#{summary['refusal_rows']} " \
|
|
414
|
+
"refusals) from #{summary["#{BOUNDARY}_payloads"]} payloads, " \
|
|
415
|
+
"#{summary['skipped_payloads']} other payloads skipped: " \
|
|
416
|
+
"#{failures.size} differ"
|
|
417
|
+
return summary if failures.empty?
|
|
418
|
+
|
|
419
|
+
raise Error, "#{failures.size} rows differ: " \
|
|
420
|
+
"#{failures.map { |f| f['id'] }.join(', ')}"
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
def main(argv)
|
|
424
|
+
options = parse_options(argv)
|
|
425
|
+
run(**options)
|
|
426
|
+
0
|
|
427
|
+
rescue OptionParser::ParseError => e
|
|
428
|
+
warn e.message
|
|
429
|
+
2
|
|
430
|
+
rescue Error => e
|
|
431
|
+
warn "replay_corpus: #{e.message}"
|
|
432
|
+
1
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
def parse_options(argv)
|
|
436
|
+
options = {}
|
|
437
|
+
option_parser(options).parse!(argv)
|
|
438
|
+
unless options[:testsuite]
|
|
439
|
+
raise OptionParser::MissingArgument, "--testsuite"
|
|
440
|
+
end
|
|
441
|
+
raise OptionParser::InvalidOption, argv.join(" ") unless argv.empty?
|
|
442
|
+
|
|
443
|
+
options
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
def option_parser(options)
|
|
447
|
+
OptionParser.new do |o|
|
|
448
|
+
o.banner = "usage: scripts/replay_corpus.rb --testsuite PATH " \
|
|
449
|
+
"[--pin FILE] [--language NAME] [--generation N] " \
|
|
450
|
+
"[--report FILE]"
|
|
451
|
+
OPTIONS.each do |key, *switch|
|
|
452
|
+
o.on(*switch) { |v| options[key] = v }
|
|
453
|
+
end
|
|
454
|
+
end
|
|
455
|
+
end
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
exit OmmlReplayCorpus.main(ARGV) if $PROGRAM_NAME == __FILE__
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.12
|
|
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-
|
|
11
|
+
date: 2026-11-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lutaml-model
|
|
@@ -47,13 +47,15 @@ executables: []
|
|
|
47
47
|
extensions: []
|
|
48
48
|
extra_rdoc_files: []
|
|
49
49
|
files:
|
|
50
|
+
- ".gitattributes"
|
|
51
|
+
- ".github/workflows/corpus.yml"
|
|
50
52
|
- ".github/workflows/opal.yml"
|
|
53
|
+
- ".github/workflows/portable.yml"
|
|
51
54
|
- ".github/workflows/rake.yml"
|
|
52
55
|
- ".github/workflows/release.yml"
|
|
53
56
|
- ".gitignore"
|
|
54
57
|
- ".rubocop.yml"
|
|
55
58
|
- ".rubocop_todo.yml"
|
|
56
|
-
- CLAUDE.md
|
|
57
59
|
- CODE_OF_CONDUCT.md
|
|
58
60
|
- Gemfile
|
|
59
61
|
- README.adoc
|
|
@@ -304,6 +306,8 @@ files:
|
|
|
304
306
|
- lib/omml/models/simple_types/st_fld_char_type.rb
|
|
305
307
|
- lib/omml/models/simple_types/st_geom_guide_name.rb
|
|
306
308
|
- lib/omml/models/simple_types/st_hex_color.rb
|
|
309
|
+
- lib/omml/models/simple_types/st_hex_color_auto.rb
|
|
310
|
+
- lib/omml/models/simple_types/st_hex_color_rgb.rb
|
|
307
311
|
- lib/omml/models/simple_types/st_highlight_color.rb
|
|
308
312
|
- lib/omml/models/simple_types/st_hint.rb
|
|
309
313
|
- lib/omml/models/simple_types/st_info_text_type.rb
|
|
@@ -311,6 +315,7 @@ files:
|
|
|
311
315
|
- lib/omml/models/simple_types/st_integer255.rb
|
|
312
316
|
- lib/omml/models/simple_types/st_jc.rb
|
|
313
317
|
- lib/omml/models/simple_types/st_lang.rb
|
|
318
|
+
- lib/omml/models/simple_types/st_lang_code.rb
|
|
314
319
|
- lib/omml/models/simple_types/st_lim_loc.rb
|
|
315
320
|
- lib/omml/models/simple_types/st_lock.rb
|
|
316
321
|
- lib/omml/models/simple_types/st_on_off.rb
|
|
@@ -344,11 +349,24 @@ files:
|
|
|
344
349
|
- lib/omml/namespace.rb
|
|
345
350
|
- lib/omml/opal.rb
|
|
346
351
|
- lib/omml/parser.rb
|
|
352
|
+
- lib/omml/portable.rb
|
|
347
353
|
- lib/omml/type_substitutions.rb
|
|
348
354
|
- lib/omml/version.rb
|
|
349
355
|
- lib/omml/wordprocessing_namespace.rb
|
|
356
|
+
- model/portable/bindings/coordinate.rs
|
|
357
|
+
- model/portable/bindings/coordinate.ts
|
|
358
|
+
- model/portable/bindings/integer.rs
|
|
359
|
+
- model/portable/bindings/integer.ts
|
|
360
|
+
- model/portable/bindings/token.rs
|
|
361
|
+
- model/portable/bindings/token.ts
|
|
362
|
+
- model/portable/enum-subset-v1.json
|
|
363
|
+
- model/portable/manifest.json
|
|
364
|
+
- model/portable/runtime-graph-v1.json
|
|
365
|
+
- model/portable/scalar-subset-v1.json
|
|
350
366
|
- omml.gemspec
|
|
351
367
|
- reference-docs/shared-math.xsd
|
|
368
|
+
- scripts/export_portable_models.rb
|
|
369
|
+
- scripts/replay_corpus.rb
|
|
352
370
|
- sig/omml.rbs
|
|
353
371
|
homepage: https://github.com/plurimath/omml
|
|
354
372
|
licenses:
|