lutaml-model 0.8.167 → 0.8.169

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6fcc4e9c561155b0b5b78a09ee81e231f66c581d3b34668c8baa3e15e21aea2
4
- data.tar.gz: be9b8132335d16b9c187b73f70f7daa9844be7c27cf6b40a3906178f7d377945
3
+ metadata.gz: 1d8fca1d96bc08f40af1b381d9965fc0e2c36062f7245de7775a9ded2dd9a242
4
+ data.tar.gz: fba1bcd46c3ea01561ee96ce0a13d45076104ca79c53b7380e6803f1f4534df6
5
5
  SHA512:
6
- metadata.gz: dd3a488a8ef78f804f7e1c06fa076d3fb751a670849ac9aecad20131c2b997af3c98246ee80a6728d83d0d571aa0715b85c1b7b44fba08ff4f9ffc864fa24f33
7
- data.tar.gz: 4236bfee9b6d9a5eb7d50efa5c700599cca6321c1938ce6f3399df16b13f0bc7ee54927fc66743bb636a275c1157073586e74f1f3dd26790af70093c9c649bc4
6
+ metadata.gz: 5803ee2c167d61899821d9ef07e7709394dbb231fcd17f54a872ce4089911e87f0cf80b07933da0ffd76a87f302e911f14d39b33f7e76ef7445131951279484c
7
+ data.tar.gz: 9b4bd16dc52d8dd7b2b236c3059816f85df179e8efc26f7abafab1b9087f3357c6335cacf38d0114114d5eded3528541737e1b65f0ed793667cb91d4ef1cf701
@@ -185,6 +185,11 @@ jobs:
185
185
  # create-pull-request push 403s on every main push (#1128).
186
186
  permissions:
187
187
  contents: write
188
+ # create-pull-request opens the baseline PR through the API —
189
+ # the git push (contents:write) authenticates, but PR creation
190
+ # needs its own grant ("Resource not accessible by
191
+ # integration").
192
+ pull-requests: write
188
193
  steps:
189
194
  # persist-credentials: false — checkout's persisted Authorization
190
195
  # extraheader collides with create-pull-request's own token on the
data/Gemfile CHANGED
@@ -49,7 +49,7 @@ gem "rexml"
49
49
  # exact-URI attribute rows, nested-attribute capture, wildcard rows,
50
50
  # walk-side ns retention and leniency, :unqualified rows, and the
51
51
  # address-based text attach all ride it.
52
- gem "leptris", ">= 1.9.407.0" # RAW op (leptris#1941) + the attr ns_prefix deep-copy fix (leptris#1967/#1968): the emission lane gates engines below 1.9.407 to the DOM lane
52
+ gem "leptris", ">= 1.9.406.0" # RAW op (leptris#1941) — matches MIN_LEPTRIS_VERSION, the single capability line; the emission lane additionally version-gates namespaced trees to >= 1.9.407.0 (attr ns_prefix deep-copy, leptris#1967/#1968)
53
53
  gem "teptris"
54
54
  gem "yeptris" unless Gem.win_platform?
55
55
  # TODO: revert rng branch to main when lutaml/rng#32 is merged
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.167"
5
+ VERSION = "0.8.169"
6
6
  end
7
7
  end
@@ -35,6 +35,7 @@ module Lutaml
35
35
  ORDERED_ROW_KINDS = %i[scalar collection_native collection_cb
36
36
  nested ordered_deferred].freeze
37
37
  DEFERRED_ROW_KINDS = %i[raw ordered_deferred].freeze
38
+ PLANNED_ROW_KINDS = %i[nested ordered_deferred].freeze
38
39
  NESTED_ROW_KINDS = %i[nested ordered_deferred].freeze
39
40
  NS_EMITTABLE_ROW_KINDS = %i[scalar collection nested
40
41
  collection_native
@@ -52,16 +53,17 @@ module Lutaml
52
53
  :lutaml_model_leptris_native_emission_op_buffer_base
53
54
 
54
55
  class << self
55
- # The RAW-splice capability rides engine 1.9.406.0: the gem
56
- # maps PLAN_OP_RAW and the :raw row-op kind (both ship in
57
- # the same release). Probing the public constant tracks the
58
- # LOADED gem — a bundle pinned to an older engine (the
59
- # metanorma consumer matrix resolves 1.9.405.0) takes the
60
- # DOM lane instead of splicing :raw ops the engine cannot
61
- # parse (which emitted empty fragments and died on the
62
- # round-trip parse).
63
- def raw_op_supported?(ffi = ::Leptris::XML::FFI)
64
- ffi.const_defined?(:PLAN_OP_RAW)
56
+ # plan: the compiled plan; instance: the emitting instance.
57
+ # A nil instance runs the static checks only.
58
+ def compatible?(plan, instance = nil, register = nil)
59
+ return false if plan.nil?
60
+ return false if namespaced_tree?(plan[:tree]) &&
61
+ !engine_ns_prefix_safe?
62
+ return false unless ordered_ns_emittable?(plan, instance)
63
+ return false if plan[:ordered] && instance.is_a?(::Lutaml::Model::Serialize) &&
64
+ instance.element_order.nil?
65
+
66
+ subtree_gate_ok?(plan, instance, register)
65
67
  end
66
68
 
67
69
  # The engine's attr-row ns_prefix deep-copy fix rides
@@ -69,11 +71,12 @@ module Lutaml
69
71
  # engines keep the binding's freed FFI anchor pointer in the
70
72
  # built plan and read freed heap bytes at serialize time —
71
73
  # garbage prefixes (CT_RPr:val) and empty output (the
72
- # lutaml-model#1126 uniword signatures). There is no
73
- # capability constant to probe for a pure bugfix release, so
74
- # the gate reads the binding version. Namespace-less trees
75
- # never consult the descriptor's ns rows and stay on the
76
- # lane regardless.
74
+ # lutaml-model#1126 uniword signatures) on every EXACT-ns
75
+ # row the ops lane emits. A pure bugfix release ships no
76
+ # capability constant, so this is a version-floor gate like
77
+ # MIN_LEPTRIS_VERSION — the floor is the capability line.
78
+ # Namespace-less trees never consult the descriptor's ns
79
+ # rows and stay on the lane regardless.
77
80
  def engine_ns_prefix_safe?(version = ::Leptris::VERSION)
78
81
  Gem::Version.new(version.to_s) >=
79
82
  Gem::Version.new("1.9.407.0")
@@ -95,27 +98,13 @@ module Lutaml
95
98
 
96
99
  (tree[:children] || []).any? do |r|
97
100
  next true if r[:ns].is_a?(::Hash)
98
- next false unless r[:kind] == :nested && r[:plan]
101
+ next false unless r[:plan] &&
102
+ PLANNED_ROW_KINDS.include?(r[:kind])
99
103
 
100
104
  namespaced_tree?(r[:plan])
101
105
  end
102
106
  end
103
107
 
104
- # plan: the compiled plan; instance: the emitting instance.
105
- # A nil instance runs the static checks only.
106
- def compatible?(plan, instance = nil, register = nil)
107
- return false if plan.nil?
108
- return false unless raw_op_supported?
109
- return false if namespaced_tree?(plan[:tree]) &&
110
- !engine_ns_prefix_safe?
111
- return false unless ordered_ns_emittable?(plan, instance)
112
- return false if plan[:ordered] && instance.is_a?(::Lutaml::Model::Serialize) &&
113
- instance.element_order.nil?
114
-
115
- subtree_gate_ok?(plan, instance, register,
116
- prefixed_source?(instance))
117
- end
118
-
119
108
  # Prefixed spelling is only faithful when the ROOT instance
120
109
  # preserves a prefixed source: the DOM lane inherits the
121
110
  # root's prefix spelling down the tree (nested children
@@ -135,20 +124,35 @@ module Lutaml
135
124
  # it. The identity map mirrors that numbering exactly —
136
125
  # op plan_index values are these absolute slots.
137
126
  def emission_graph_for(plan, register)
127
+ slot_map(emission_tree_for(plan, register))
128
+ end
129
+
130
+ # THE slot numbering (leptris#1966 SSOT): every consumer
131
+ # numbering the tree — the emission graph, the flat layout,
132
+ # the ruby gem's flatten_plan — must derive from THIS walk:
133
+ # identity-memoized pre-order over planned rows. Shared
134
+ # subtrees (memoized plans reachable from many parents —
135
+ # the theme docx's clrScheme/fontScheme shapes) get ONE
136
+ # slot at first encounter; occurrence-arithmetic (counting
137
+ # a shared subtree's size at every reference) drifts 70/75
138
+ # nodes on that document and handed the engine op streams
139
+ # whose plan_index pointed at the wrong plan.
140
+ def slot_map(tree)
138
141
  map = {}.compare_by_identity
139
142
  counter = [0]
140
- walk = lambda do |tree|
141
- return map[tree] if map.key?(tree)
143
+ walk = lambda do |t|
144
+ return map[t] if map.key?(t)
142
145
 
143
146
  idx = counter[0]
144
147
  counter[0] += 1
145
- map[tree] = idx
146
- (tree[:children] || []).each do |r|
147
- walk.call(r[:plan]) if r[:kind] == :nested && r[:plan]
148
+ map[t] = idx
149
+ (t[:children] || []).each do |r|
150
+ walk.call(r[:plan]) if r[:plan] &&
151
+ PLANNED_ROW_KINDS.include?(r[:kind])
148
152
  end
149
153
  idx
150
154
  end
151
- walk.call(emission_tree_for(plan, register))
155
+ walk.call(tree)
152
156
  map
153
157
  end
154
158
 
@@ -159,9 +163,7 @@ module Lutaml
159
163
  # clrScheme → color → ordered srgbClr) must ride the
160
164
  # emission descriptor + identity graph — ops against the
161
165
  # parse descriptor reference child plans the compiled tree
162
- # never materialized (:raw rows carry no plan), and the
163
- # engine rejects the program (INVALID_ARG, -5) or cross-
164
- # wires subtree slots.
166
+ # never materialized (:raw rows carry no plan).
165
167
  def deferred_rows?(tree)
166
168
  (tree[:children] || []).any? do |r|
167
169
  next true if DEFERRED_ROW_KINDS.include?(r[:kind])
@@ -178,10 +180,7 @@ module Lutaml
178
180
  # instance must carry a pristine parse-built element_order
179
181
  # with Element/Text entries only (comments and PIs keep the
180
182
  # DOM lane; mutation reroutes through the reconciler).
181
- def subtree_gate_ok?(plan, instance, register,
182
- prefixed_source = nil)
183
- prefixed_source = prefixed_source?(instance) if
184
- prefixed_source.nil?
183
+ def subtree_gate_ok?(plan, instance, register)
185
184
  return false unless plan[:rows].all? do |row|
186
185
  gate_row_kind?(row, register)
187
186
  end
@@ -198,33 +197,35 @@ module Lutaml
198
197
 
199
198
  return true unless instance.is_a?(::Lutaml::Model::Serialize)
200
199
 
201
- plan[:rows].each do |(rule, attr, kind, _sp, delegate, type)|
200
+ plan[:rows].each do |(rule, attr, kind, _sp, delegate, _type)|
202
201
  next unless rule.name
203
- next if kind == :child_deferred
202
+
203
+ if kind == :child_deferred
204
+ # A VALUED cycle-point row keeps the DOM lane: the
205
+ # native ordered replay has no ops spelling for it —
206
+ # the island's nested rows render as scalar
207
+ # placeholders and the data drops (lutaml-model#1130,
208
+ # the OOXML bibliography's Author→author recursion).
209
+ # Empty deferred rows ride the native lane untouched.
210
+ value = value_of(instance, attr, delegate)
211
+ return false unless Array(value).empty?
212
+
213
+ next
214
+ end
204
215
  next unless NESTED_ROW_KINDS.include?(kind)
205
216
 
206
217
  value = value_of(instance, attr, delegate)
207
218
  Array(value).each do |item|
208
219
  next unless item
209
220
 
210
- child_type = begin
211
- type || attr.type(register)
212
- rescue StandardError
213
- nil
214
- end
215
- child_plan = child_type.is_a?(Class) &&
216
- PlanCompiler.compile(child_type, register)
221
+ # leptris#1966: the emit compiles the ITEM CLASS's
222
+ # plan (nested_plans[[item.class, name]]) — the gate
223
+ # must gate exactly what emit emits. Unknown classes
224
+ # refuse here: the doc takes the DOM lane.
225
+ child_plan = PlanCompiler.compile(item.class, register)
217
226
  return false unless child_plan
218
- # The ns gate is per-tree and per-instance: a
219
- # namespace-less parent can nest namespaced children
220
- # whose EXACT rows would still spell prefix:local,
221
- # and each child preserves (or not) its own source
222
- # prefix.
223
- return false unless ordered_ns_emittable?(child_plan,
224
- prefixed_source)
225
227
  return false unless subtree_gate_ok?(child_plan, item,
226
- register,
227
- prefixed_source)
228
+ register)
228
229
  end
229
230
  end
230
231
  true
@@ -276,18 +277,19 @@ module Lutaml
276
277
  end
277
278
  end
278
279
 
279
- # Only two shapes ride the ops lane:
280
- # - nil (:none) and :unqualified — the unwritten local
281
- # spelling, nothing to declare;
282
- # - EXACT Hash forms, but ONLY under a prefixed-preserved
283
- # root. The engine's plan serializer spells prefix:local
284
- # for every EXACT row and cannot express the default-xmlns
285
- # form — so admitting constructed or default-parsed
286
- # instances flipped the pinned output format (uniword
287
- # bold `<b xmlns=...>` and custprops `<property>`
288
- # regressions). A prefixed-parsed root pins the prefixed
289
- # form itself — Priority 1 format preservation — and the
290
- # ops spelling matches it, inherited down the tree.
280
+ # Only two shapes ride the ops lane: nil (:none) and
281
+ # :unqualified — the unwritten local spelling, nothing to
282
+ # declare — and EXACT Hash forms, ONLY under a
283
+ # prefixed-preserved root. The engine's plan serializer
284
+ # spells prefix:local for every EXACT row and cannot
285
+ # express the default-xmlns form (a prefix-less EXACT row
286
+ # emits a bare name with NO declaration, changing element
287
+ # identity), so admitting constructed or default-parsed
288
+ # instances flipped the pinned output format (uniword
289
+ # bold `<b xmlns=...>` and custprops `<property>`
290
+ # regressions). A prefixed-parsed root pins the prefixed
291
+ # form itself — Priority 1 format preservation — and the
292
+ # ops spelling matches it, inherited down the tree.
291
293
  def ns_emittable?(ns_form, prefixed_source = nil)
292
294
  return true if ns_form.nil? || ns_form == :unqualified
293
295
  return false unless ns_form.is_a?(Hash) && ns_form[:prefix] &&
@@ -308,7 +310,6 @@ module Lutaml
308
310
  base = (Thread.current[OP_BUFFER_BASE_KEY] ||= 0)
309
311
  len = base
310
312
  result = nil
311
- bailed = false
312
313
  begin
313
314
  op_slot(buf, len)
314
315
  buf[len][:kind] = :element
@@ -324,17 +325,14 @@ module Lutaml
324
325
  emit_element(buf, len + 1, instance, plan, register,
325
326
  root_index, graph)
326
327
  end
327
- # A nil walk means the bail signal (a valued cycle-point
328
- # row the ops lane cannot spell — #1130): reset the
329
- # buffer tail and hand the instance back to the caller's
330
- # DOM-lane fallback. The ensure's trim uses the last
331
- # known-good length.
328
+ # A nil walk is the bail signal: a valued cycle-point or
329
+ # type-only row the ops lane cannot spell (#1130).
330
+ # Reset the buffer tail and hand the instance back to
331
+ # the caller's DOM-lane fallback. The ensure's trim uses
332
+ # the last known-good length.
332
333
  if len.nil?
333
- bailed = true
334
334
  len = base
335
- end
336
-
337
- unless bailed
335
+ else
338
336
  op_slot(buf, len)
339
337
  buf[len][:kind] = :end
340
338
  len += 1
@@ -351,8 +349,6 @@ module Lutaml
351
349
  buf.slice!(len..) if buf.size > len
352
350
  Thread.current[OP_BUFFER_BASE_KEY] = base
353
351
  end
354
- return nil if bailed
355
-
356
352
  result
357
353
  end
358
354
 
@@ -386,7 +382,20 @@ module Lutaml
386
382
  # materialize without a register).
387
383
  return build.call if register.nil?
388
384
 
389
- plan[:emission_tree] ||= build.call
385
+ # leptris#1966: a memoized tree whose planned-children
386
+ # count no longer matches the plan's rows is STALE — the
387
+ # first build ran while the plan's rows were still
388
+ # filling. Rebuild and invalidate the memos derived from
389
+ # the tree.
390
+ cached = plan[:emission_tree]
391
+ if cached && (cached[:children] || []).length == plan[:rows].length
392
+ return cached
393
+ end
394
+
395
+ plan[:emission_tree] = build.call
396
+ plan[:emission_descriptor] = nil
397
+ plan[:flat_layout_emission] = nil
398
+ plan[:emission_tree]
390
399
  end
391
400
 
392
401
  def emission_descriptor_for(plan, register)
@@ -543,7 +552,7 @@ module Lutaml
543
552
  tree = emission_tree_for(child_plan, register)
544
553
  graph[tree]
545
554
  else
546
- compiled_graph_for(plan)[child_plan[:tree]]
555
+ flat_layout_for(plan, instance, register)[row_index]&.last
547
556
  end
548
557
  next unless child_index
549
558
 
@@ -636,6 +645,7 @@ module Lutaml
636
645
  def emit_element(buf, len, instance, plan, register, plan_index,
637
646
  graph = nil)
638
647
  my_index = plan_index
648
+ layout = flat_layout_for(plan, instance, register)
639
649
 
640
650
  len = emit_attributes(buf, len, instance, plan, my_index, register)
641
651
 
@@ -717,7 +727,7 @@ module Lutaml
717
727
  tree = emission_tree_for(child_plan, register)
718
728
  graph[tree]
719
729
  else
720
- compiled_graph_for(plan)[child_plan[:tree]]
730
+ layout[row_index]&.last
721
731
  end
722
732
  next unless child_index
723
733
 
@@ -758,34 +768,59 @@ module Lutaml
758
768
  out || item.to_xml
759
769
  end
760
770
 
761
- # Mirror of Descriptor.flatten_plan numbering over the
762
- # COMPILED tree: pre-order, identity-deduped — the same
763
- # plan_index space leptris_plan_build assigns when building
764
- # plan[:descriptor]. The per-parent relative-offset layout
765
- # this replaces agreed with the engine only at depth 0 on
766
- # share-free trees: nested emission passed raw offsets as
767
- # absolute indices (uniword clrScheme cross-wired dk1/sysClr
768
- # onto accent2's slots → INVALID_ARG -5), and shared child
769
- # plans (one SysClr tree under twelve color rows) make
770
- # per-parent pre-order diverge from the engine's deduped
771
- # numbering entirely.
772
- def compiled_graph_for(plan)
773
- plan[:compiled_graph] ||= begin
774
- map = {}.compare_by_identity
775
- counter = [0]
776
- walk = lambda do |tree|
777
- next map[tree] if map.key?(tree)
778
-
779
- idx = counter[0]
780
- counter[0] += 1
781
- map[tree] = idx
782
- (tree[:children] || []).each do |r|
783
- walk.call(r[:plan]) if r[:kind] == :nested && r[:plan]
784
- end
785
- idx
771
+ # {nested row_index => [child tree, relative flat index]} —
772
+ # children of this plan occupy slots my_index+1 .. in row
773
+ # order, each nested row's subtree sized once.
774
+ # leptris#1966 SSOT: the layout world MUST be the same
775
+ # world the ops' descriptor comes from — emission_lane?
776
+ # picks `d` in emit, so it picks the layout here too. The
777
+ # old plan-only predicate let an ordered plan with a
778
+ # built (element_order-less) instance number ops against
779
+ # the EMISSION tree while build_result ran on the PARSE
780
+ # descriptor (75 vs 93 slots — the theme-docx -5).
781
+ def flat_layout_for(plan, instance = nil, register = nil)
782
+ if instance && emission_lane?(plan, instance)
783
+ # Never memoize a nil-register build: child types can
784
+ # only materialize with a register (an early nil-register
785
+ # call would cache an EMPTY layout and every later
786
+ # emission would drop the subtrees).
787
+ return build_flat_layout(emission_tree_for(plan, register)) if
788
+ register.nil?
789
+
790
+ plan[:flat_layout_emission] ||= build_flat_layout(
791
+ emission_tree_for(plan, register),
792
+ )
793
+ return plan[:flat_layout_emission]
794
+ end
795
+
796
+ plan[:flat_layout] ||= build_flat_layout(plan[:tree])
797
+ end
798
+
799
+ def build_flat_layout(tree)
800
+
801
+ slots = slot_map(tree)
802
+ layout = {}
803
+ (tree[:children] || []).each_with_index do |row, i|
804
+ next unless row[:plan] &&
805
+ PLANNED_ROW_KINDS.include?(row[:kind])
806
+
807
+ layout[i] = [row[:plan], slots[row[:plan]]]
808
+ end
809
+ layout
810
+
811
+ end
812
+
813
+ def subtree_size(tree)
814
+ # Mirror flatten_plan's allocation: every planned row kind
815
+ # costs its full subtree (:nested AND :ordered_deferred —
816
+ # counting deferred children as 1 shifted every later slot
817
+ # after the first deferred subtree, leptris#1966).
818
+ 1 + (tree[:children] || []).sum do |row|
819
+ if row[:plan] && PLANNED_ROW_KINDS.include?(row[:kind])
820
+ subtree_size(row[:plan])
821
+ else
822
+ 0
786
823
  end
787
- walk.call(plan[:tree])
788
- map
789
824
  end
790
825
  end
791
826
 
@@ -809,6 +844,10 @@ module Lutaml
809
844
  attr_rows.each do |rule, attr, _sp, delegate|
810
845
  value = value_of(instance, attr, delegate)
811
846
  next if value.nil?
847
+ # The DOM lane's write_attribute contract: render_default:
848
+ # false suppresses an attribute whose value is still the
849
+ # default (a parse that omitted it), derived rules excepted.
850
+ next unless rule.render?(value, instance)
812
851
 
813
852
  name = rule.name.to_s
814
853
  row_index = row_indices[name]
@@ -837,9 +876,11 @@ module Lutaml
837
876
  entry = by_name[name]
838
877
  next unless entry
839
878
 
840
- _rule, attr, delegate = entry
879
+ rule, attr, delegate = entry
841
880
  value = value_of(instance, attr, delegate)
842
881
  next if value.nil?
882
+ # Same render_default contract as the plain path.
883
+ next unless rule.render?(value, instance)
843
884
 
844
885
  row_index = row_indices[name]
845
886
  next unless row_index
@@ -343,15 +343,6 @@ module Lutaml
343
343
  attributes: plan_attrs, children: rows }
344
344
  tree[:ns] = model_ns if model_ns
345
345
  tree[:flags] = flags unless flags.empty?
346
- begin
347
- # Lazy: the Opal boot loads this file, and leptris is a
348
- # native gem there — the require only belongs on the
349
- # engines-enabled path.
350
- require "leptris/xml/descriptor"
351
- descriptor = ::Leptris::XML::Descriptor.build(**tree)
352
- rescue StandardError
353
- return nil
354
- end
355
346
 
356
347
  return opt_out!(:attr_ns_claim_conflict) if attr_local_claims
357
348
  .any? { |_, c| c[:ns].positive? && c[:plain].positive? }
@@ -379,6 +370,23 @@ module Lutaml
379
370
  type_tag: wildcard_tag }
380
371
  end
381
372
 
373
+ # leptris#1966: the descriptor freezes the tree's slot
374
+ # table — it must see the tree FINAL. The wildcard
375
+ # catch-all above used to append to `rows` AFTER this
376
+ # build, so every slot past the wildcard shifted one and
377
+ # the ops lane wrote children into leaf slots (status=-5
378
+ # on the theme docx). The tree is complete here; freeze
379
+ # now.
380
+ begin
381
+ # Lazy: the Opal boot loads this file, and leptris is a
382
+ # native gem there — the require only belongs on the
383
+ # engines-enabled path.
384
+ require "leptris/xml/descriptor"
385
+ descriptor = ::Leptris::XML::Descriptor.build(**tree)
386
+ rescue StandardError
387
+ return nil
388
+ end
389
+
382
390
  { descriptor: descriptor, tree: tree, rows: compiled,
383
391
  attr_rows: attr_rows, mapping: mapping,
384
392
  row_tags: row_tags, namespaced: namespaced,
@@ -16,10 +16,14 @@ module Lutaml
16
16
  # form (#1560, 1.9.323), build_result with the address-based
17
17
  # text attach (#408, 1.9.334/1.9.336), and the plan-value
18
18
  # attributes batch face (PlanValue#attributes_snapshot,
19
- # leptris-ruby#447). Bundles resolving an older gem keep the
20
- # interpretive path — PlanCompiler.compile answers nil — the
21
- # opt-out protocol.
22
- MIN_LEPTRIS_VERSION = "1.9.366.2"
19
+ # leptris-ruby#447), and — the binding addition — the RAW op +
20
+ # emission row identity the ordered/deferred splice rides
21
+ # (leptris#1941, 1.9.406). Bundles resolving an older gem keep
22
+ # the interpretive path — PlanCompiler.compile answers nil —
23
+ # the opt-out protocol; a bundle pinned below the floor (e.g.
24
+ # the metanorma consumer matrix at 1.9.405.0) never sees the
25
+ # ops lane, so it cannot splice ops the engine cannot parse.
26
+ MIN_LEPTRIS_VERSION = "1.9.406.0"
23
27
 
24
28
  # Memoized: the compiler consults this on every cache hit (per
25
29
  # child row per node), and the comparison minted a Gem::Version
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lutaml-model#1130: a VALUED :child_deferred row (the cycle-point
4
+ # spelling — the OOXML bibliography's Author → author same-class
5
+ # recursion) must keep the DOM lane. The native ordered replay has no
6
+ # ops spelling for the island: its nested rows render as scalar
7
+ # placeholders and the data drops (<b:Author/>). The gate previously
8
+ # skipped child_deferred rows outright, admitting the native lane for
9
+ # exactly the shape it cannot address.
10
+
11
+ require "lutaml/model"
12
+ require "lutaml/xml/leptris"
13
+
14
+ module Bib1130
15
+ class BNamespace < Lutaml::Xml::Namespace
16
+ uri "http://schemas.openxmlformats.org/officeDocument/2006/bibliography"
17
+ prefix_default "b"
18
+ end
19
+
20
+ class Person < Lutaml::Model::Serializable
21
+ attribute :last, :string
22
+ attribute :first, :string
23
+ attribute :middle, :string
24
+
25
+ xml do
26
+ element "Person"
27
+ namespace BNamespace
28
+ mixed_content
29
+ map_element "Last", to: :last
30
+ map_element "First", to: :first, render_nil: false
31
+ map_element "Middle", to: :middle, render_nil: false
32
+ end
33
+ end
34
+
35
+ class NameList < Lutaml::Model::Serializable
36
+ attribute :person, Person, collection: true, initialize_empty: true
37
+
38
+ xml do
39
+ element "NameList"
40
+ namespace BNamespace
41
+ mixed_content
42
+ map_element "Person", to: :person, render_nil: false
43
+ end
44
+ end
45
+
46
+ class Author < Lutaml::Model::Serializable
47
+ attribute :name_list, NameList
48
+ attribute :author, Author
49
+
50
+ xml do
51
+ element "Author"
52
+ namespace BNamespace
53
+ mixed_content
54
+ map_element "NameList", to: :name_list, render_nil: false
55
+ map_element "Author", to: :author, render_nil: false
56
+ end
57
+ end
58
+
59
+ class Source < Lutaml::Model::Serializable
60
+ attribute :source_type, :string
61
+ attribute :author, Author
62
+ attribute :title, :string
63
+
64
+ xml do
65
+ element "Source"
66
+ namespace BNamespace
67
+ mixed_content
68
+ map_element "SourceType", to: :source_type, render_nil: false
69
+ map_element "Author", to: :author, render_nil: false
70
+ map_element "Title", to: :title, render_nil: false
71
+ end
72
+ end
73
+
74
+ class Sources < Lutaml::Model::Serializable
75
+ attribute :source, Source, collection: true
76
+
77
+ xml do
78
+ element "Sources"
79
+ namespace BNamespace
80
+ mixed_content
81
+ map_element "Source", to: :source, render_nil: false
82
+ end
83
+ end
84
+ end
85
+
86
+ RSpec.describe "valued child_deferred rows keep the DOM lane (#1130)" do
87
+ let(:xml) do
88
+ <<~XML
89
+ <b:Sources xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography">
90
+ <b:Source><b:SourceType>Book</b:SourceType>
91
+ <b:Author><b:Author><b:NameList><b:Person><b:Last>Last Name</b:Last><b:First>First,</b:First><b:Middle>Middle</b:Middle></b:Person></b:NameList></b:Author></b:Author>
92
+ <b:Title>Book Title</b:Title>
93
+ </b:Source>
94
+ </b:Sources>
95
+ XML
96
+ end
97
+
98
+ it "round-trips the nested same-element chain with both fast-path states" do
99
+ [true, false].each do |fast|
100
+ Lutaml::Model::Config.instance.xml_plan_fast_path = fast
101
+ parsed = Bib1130::Sources.from_xml(xml)
102
+ inner = parsed.source.first.author.author
103
+
104
+ expect(inner.name_list.person.first.last).to eq("Last Name")
105
+
106
+ out = parsed.to_xml
107
+ expect(out).not_to include("<b:Author/>")
108
+ expect(out).to include("Last Name")
109
+ end
110
+ ensure
111
+ Lutaml::Model::Config.instance.xml_plan_fast_path = true
112
+ end
113
+
114
+ it "refuses the native lane for the valued deferred plan" do
115
+ Lutaml::Model::Config.instance.xml_plan_fast_path = true
116
+ parsed = Bib1130::Sources.from_xml(xml)
117
+ src = parsed.source.first
118
+ plan = Lutaml::Xml::Leptris::PlanCompiler.compile(
119
+ src.class, Lutaml::Model::Config.default_register
120
+ )
121
+ expect(
122
+ Lutaml::Xml::Leptris::NativeEmission.compatible?(
123
+ plan, src, Lutaml::Model::Config.default_register
124
+ ),
125
+ ).to be(false)
126
+ ensure
127
+ Lutaml::Model::Config.instance.xml_plan_fast_path = true
128
+ end
129
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # leptris#1966 root cause: the emission graph numbered :nested rows
4
+ # only, but emission_rows_for materializes :ordered_deferred rows
5
+ # WITH child :plan trees (the deferred subtree is fully materialized
6
+ # — the recursive gate guarantees it). A valued deferred row under
7
+ # an ordered parent (uniword's theme/styles shapes) then looked up
8
+ # graph[tree] at emit time, got nil, and the element op carried
9
+ # plan_index=nil — the engine rejected the stream with -5. The
10
+ # graph must number every row kind that carries a plan.
11
+ RSpec.describe Lutaml::Xml::Leptris::NativeEmission,
12
+ ".emission_graph_for numbers deferred subtrees" do
13
+ let(:child_tree) do
14
+ { name: "p", children: [{ name: "t", kind: :scalar }] }
15
+ end
16
+ let(:tree) do
17
+ { name: "root", children: [
18
+ { name: "body", kind: :ordered_deferred, plan: child_tree },
19
+ ] }
20
+ end
21
+ let(:fake_row) do
22
+ rule = Struct.new(:name).new("body")
23
+ [rule, nil, :scalar]
24
+ end
25
+ let(:plan) do
26
+ { ordered: true, tree: tree, emission_tree: tree, rows: [fake_row] }
27
+ end
28
+
29
+ it "assigns the deferred subtree a graph slot" do
30
+ graph = described_class.emission_graph_for(plan, :register)
31
+ expect(graph[tree]).to eq(0)
32
+ expect(graph[child_tree]).to eq(1)
33
+ end
34
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lutaml-model#1136: the native emission lane ignored the DOM lane's
4
+ # render contract for attributes — an attribute whose value is still
5
+ # the default (a parse that omitted it from the source) must not
6
+ # emit when the mapping declares render_default: false. uniword's
7
+ # Style round-trip caught it: a parsed style without w:default came
8
+ # back with the ghost `w:default="0"` (the custom boolean type's
9
+ # serialization of its default).
10
+
11
+ require "lutaml/model"
12
+ require "lutaml/xml/leptris"
13
+
14
+ RSpec.describe "native emission honors the attribute render contract" do
15
+ let(:flag_type) do
16
+ Class.new(Lutaml::Model::Type::Value) do
17
+ def self.cast(value)
18
+ return true if ["1", true].include?(value)
19
+ return false if ["0", false].include?(value)
20
+
21
+ value
22
+ end
23
+
24
+ def serialize(_format, _register = nil)
25
+ self.class.cast(@value) ? "1" : "0"
26
+ end
27
+
28
+ def self.name
29
+ "EmissionRenderFlag"
30
+ end
31
+ end
32
+ end
33
+
34
+ let(:model_class) do
35
+ flag = flag_type
36
+ klass = Class.new(Lutaml::Model::Serializable) do
37
+ attribute :name, :string
38
+ attribute :default, flag
39
+ attribute :custom_style, flag
40
+
41
+ xml do
42
+ element "style"
43
+ map_attribute "name", to: :name
44
+ map_attribute "default", to: :default, render_default: false,
45
+ render_nil: false
46
+ map_attribute "customStyle", to: :custom_style,
47
+ render_default: false
48
+ end
49
+
50
+ def self.name
51
+ "EmissionRenderStyle"
52
+ end
53
+ end
54
+ stub_const("EmissionRender::Style", klass)
55
+ klass
56
+ end
57
+
58
+ let(:source) do
59
+ '<style xmlns="http://example.com/style" name="H1"/>'
60
+ end
61
+
62
+ around do |example|
63
+ Lutaml::Model::Config.with_adapter(xml: :leptris) { example.run }
64
+ end
65
+
66
+ it "omits parsed-omitted attributes that carry render_default: false" do
67
+ instance = model_class.from_xml(source)
68
+ xml = instance.to_xml
69
+ expect(xml).to include("name=\"H1\"")
70
+ expect(xml).not_to include("default")
71
+ expect(xml).not_to include("customStyle")
72
+ end
73
+
74
+ it "still emits attributes the source actually carried" do
75
+ xml = model_class.from_xml(
76
+ '<style xmlns="http://example.com/style" name="H1" default="1"/>',
77
+ ).to_xml
78
+ expect(xml).to include("default=")
79
+ end
80
+
81
+ it "keeps the DOM lane's contract on the recorded-order path" do
82
+ instance = model_class.from_xml(
83
+ '<style xmlns="http://example.com/style" customStyle="1" name="A"/>',
84
+ )
85
+ xml = instance.to_xml
86
+ expect(xml).to include("customStyle=")
87
+ expect(xml).not_to include("default=")
88
+ end
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.167
4
+ version: 0.8.169
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -2018,10 +2018,12 @@ files:
2018
2018
  - spec/lutaml/xml/general_namespace_spec.rb
2019
2019
  - spec/lutaml/xml/html_entities_spec.rb
2020
2020
  - spec/lutaml/xml/indent_spec.rb
2021
+ - spec/lutaml/xml/leptris/child_deferred_gate_spec.rb
2022
+ - spec/lutaml/xml/leptris/emission_graph_deferred_spec.rb
2021
2023
  - spec/lutaml/xml/leptris/native_emission_nested_sharing_spec.rb
2022
2024
  - spec/lutaml/xml/leptris/native_emission_ns_parity_spec.rb
2023
2025
  - spec/lutaml/xml/leptris/native_emission_ordered_spec.rb
2024
- - spec/lutaml/xml/leptris/native_emission_raw_gate_spec.rb
2026
+ - spec/lutaml/xml/leptris/native_emission_render_contract_spec.rb
2025
2027
  - spec/lutaml/xml/leptris/plan_hydrator_ns_snapshot_spec.rb
2026
2028
  - spec/lutaml/xml/leptris_string_encoding_spec.rb
2027
2029
  - spec/lutaml/xml/line_ending_spec.rb
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # leptris#1941 consumer-gap law: the RAW-splice capability rides
4
- # engine 1.9.406.0 (PLAN_OP_RAW + row identity). A bundle resolving
5
- # an OLDER leptris gem — e.g. the metanorma consumer matrix pinned to
6
- # 1.9.405.0 — must take the DOM lane, not the ops lane: splicing
7
- # :raw without the engine constant emitted EMPTY fragments and the
8
- # round-trip parse died on "empty input". The gate probes the FFI
9
- # constant, so capability tracks the loaded gem, not a version
10
- # table that drifts.
11
- RSpec.describe Lutaml::Xml::Leptris::NativeEmission, ".raw_op_supported?" do
12
- it "is false for an FFI surface without the RAW op" do
13
- plain = Class.new
14
- expect(described_class.raw_op_supported?(plain)).to be(false)
15
- end
16
-
17
- it "is true when PLAN_OP_RAW is defined" do
18
- with_raw = Class.new
19
- with_raw.const_set(:PLAN_OP_RAW, 4)
20
- expect(described_class.raw_op_supported?(with_raw)).to be(true)
21
- end
22
-
23
- it "probes the loaded gem by default (harness runs 1.9.406.0)" do
24
- expect(described_class.raw_op_supported?).to be(true)
25
- end
26
- end