moxml 0.6.2 → 0.6.4
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/bench/calibrate_520.rb +89 -0
- data/docs/_pages/divergences.adoc +31 -0
- data/lib/moxml/adapter/leptris.rb +444 -34
- data/lib/moxml/config.rb +43 -10
- data/lib/moxml/context.rb +31 -9
- data/lib/moxml/version.rb +1 -1
- data/lib/moxml/xsd.rb +436 -2
- data/spec/moxml/adapter/leptris_attribute_packet_spec.rb +79 -0
- data/spec/moxml/adapter/leptris_children_address_spec.rb +171 -0
- data/spec/moxml/adapter/leptris_composed_schema_spec.rb +126 -0
- data/spec/moxml/adapter/leptris_spec.rb +0 -6
- data/spec/moxml/config_degradation_spec.rb +84 -12
- data/spec/moxml/xsd_composed_spec.rb +183 -0
- metadata +7 -3
- data/spec/moxml/adapter/leptris_children_columnar_spec.rb +0 -146
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require "leptris"
|
|
5
|
+
rescue LoadError
|
|
6
|
+
# Leptris gem not available - skip all specs in this file
|
|
7
|
+
return
|
|
8
|
+
end
|
|
9
|
+
return unless Leptris::XML::Document.respond_to?(:create)
|
|
10
|
+
# The address-native lane rides the binding's shadow faces
|
|
11
|
+
# (children_addrs / walk_addresses, leptris-ruby#587/#589/#591);
|
|
12
|
+
# older bindings keep the columnar per-subtree crossing, so the
|
|
13
|
+
# routing cannot be pinned there.
|
|
14
|
+
return unless defined?(Leptris::XML::Native) &&
|
|
15
|
+
Leptris::XML::Native.respond_to?(:children_addrs)
|
|
16
|
+
|
|
17
|
+
require "moxml/adapter/leptris"
|
|
18
|
+
|
|
19
|
+
RSpec.describe "Moxml::Adapter::Leptris address-native children (shadow lane)" do
|
|
20
|
+
around do |example|
|
|
21
|
+
Moxml.with_config(:leptris, true, "UTF-8") do
|
|
22
|
+
example.run
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:xml) do
|
|
27
|
+
<<~XML
|
|
28
|
+
<?xml version="1.0"?><r><a x="1">t</a><b/><c><d/></c><tail>z</tail></r>
|
|
29
|
+
XML
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
let(:doc) { Moxml.parse(xml) }
|
|
33
|
+
let(:root) { doc.root }
|
|
34
|
+
let(:root_native) { root.native }
|
|
35
|
+
|
|
36
|
+
# Counts real Native.children_addrs C crossings inside the block —
|
|
37
|
+
# no stubs, the actual boundary traffic the address lane pays.
|
|
38
|
+
def with_crossing_count(method_id = :children_addrs)
|
|
39
|
+
calls = 0
|
|
40
|
+
tp = TracePoint.new(:c_call) do |t|
|
|
41
|
+
calls += 1 if t.method_id == method_id
|
|
42
|
+
end
|
|
43
|
+
result = nil
|
|
44
|
+
tp.enable { result = yield }
|
|
45
|
+
[calls, result]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "the address gate" do
|
|
49
|
+
it "face-probes the shadow faces on the binding" do
|
|
50
|
+
expect(Moxml::Adapter::Leptris::ADDRESS_NATIVE).to be(true)
|
|
51
|
+
expect(Leptris::XML::Native.respond_to?(:children_addrs)).to be(true)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "plain children reads" do
|
|
56
|
+
it "answer address tokens matching the native children face" do
|
|
57
|
+
got = Moxml::Adapter::Leptris.children(root_native)
|
|
58
|
+
expected = Leptris::XML::NativeNode
|
|
59
|
+
.instance_method(:children).bind_call(root_native).to_a
|
|
60
|
+
expect(got).to all(be_a(Moxml::Adapter::Leptris::AddressNode))
|
|
61
|
+
expect(got.size).to eq(expected.size)
|
|
62
|
+
expect(got.map { |n| Moxml::Adapter::Leptris.node_name(n) })
|
|
63
|
+
.to eq(expected.map(&:name))
|
|
64
|
+
got.each_with_index do |token, i|
|
|
65
|
+
# Address equality: the token stands for the same C node.
|
|
66
|
+
expect(token.address).to eq(expected[i].address)
|
|
67
|
+
expect(Moxml::Adapter::Leptris.node_type(token))
|
|
68
|
+
.to eq(Moxml::Adapter::Leptris.node_type(expected[i]))
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "hand back the SAME token per address across traversals" do
|
|
73
|
+
first = Moxml::Adapter::Leptris.children(root_native)
|
|
74
|
+
second = Moxml::Adapter::Leptris.children(root_native)
|
|
75
|
+
expect(second).to eq(first)
|
|
76
|
+
expect(second.first).to equal(first.first)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Parsed-document wrappers mint with Identity::ChildReads above
|
|
80
|
+
# Moxml::Node, so consumer iteration on those wrappers dispatches
|
|
81
|
+
# to the binding's C read layer. The address face pays one
|
|
82
|
+
# children_addrs crossing per element receiver — the token mint
|
|
83
|
+
# replaces the TypedData wrap + identity-cache write the columnar
|
|
84
|
+
# lane pays per node in C.
|
|
85
|
+
it "pay one crossing per element receiver, none on repeat reads" do
|
|
86
|
+
calls, = with_crossing_count do
|
|
87
|
+
walk_face = lambda do |token|
|
|
88
|
+
Moxml::Adapter::Leptris.children(token).each do |child|
|
|
89
|
+
walk_face.call(child)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
walk_face.call(root_native)
|
|
93
|
+
end
|
|
94
|
+
# The subtree has 6 elements (r, a, b, c, d, tail): one crossing
|
|
95
|
+
# each, no walk_columnar at all.
|
|
96
|
+
expect(calls).to eq(6)
|
|
97
|
+
calls2, = with_crossing_count do
|
|
98
|
+
Moxml::Adapter::Leptris.children(root_native)
|
|
99
|
+
end
|
|
100
|
+
expect(calls2).to eq(1)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "serve element reads through the address-keyed faces" do
|
|
104
|
+
target = Moxml::Adapter::Leptris.children(root_native)
|
|
105
|
+
.find { |t| Moxml::Adapter::Leptris.node_name(t) == "a" }
|
|
106
|
+
expect(Moxml::Adapter::Leptris.bare_attr_value(target, "x")).to eq("1")
|
|
107
|
+
expect(Moxml::Adapter::Leptris.text_content(target)).to eq("t")
|
|
108
|
+
expect(Moxml::Adapter::Leptris.attributes(target).map(&:value))
|
|
109
|
+
.to eq(["1"])
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "keep the document assembly path on document receivers" do
|
|
113
|
+
calls, doc_children = with_crossing_count do
|
|
114
|
+
Moxml::Adapter::Leptris.children(doc.native)
|
|
115
|
+
end
|
|
116
|
+
# No token crossings: the document's child list rides the
|
|
117
|
+
# assembly path (declaration/doctype kinds are outside the
|
|
118
|
+
# address lane's WS enum).
|
|
119
|
+
expect(calls).to eq(0)
|
|
120
|
+
expect(doc_children.map do |n|
|
|
121
|
+
Moxml::Adapter::Leptris.node_name(n)
|
|
122
|
+
end).to include("r")
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
describe "mutation invalidation" do
|
|
127
|
+
# Read back through the adapter face: the token map must never
|
|
128
|
+
# serve a list a mutation has invalidated.
|
|
129
|
+
def face_children_names
|
|
130
|
+
Moxml::Adapter::Leptris.children(root_native)
|
|
131
|
+
.map { |n| Moxml::Adapter::Leptris.node_name(n) }
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "sees children added after the map was primed" do
|
|
135
|
+
face_children_names # prime the map
|
|
136
|
+
root.add_child(doc.create_element("late"))
|
|
137
|
+
expect(face_children_names).to include("late")
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "sees children removed after the map was primed" do
|
|
141
|
+
face_children_names # prime the map
|
|
142
|
+
root.children.to_a.first.remove
|
|
143
|
+
expect(face_children_names).not_to include("a")
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "sees sibling insertions after the map was primed" do
|
|
147
|
+
face_children_names # prime the map
|
|
148
|
+
anchor = root.children.to_a.first
|
|
149
|
+
anchor.add_previous_sibling(doc.create_element("before2"))
|
|
150
|
+
expect(face_children_names).to include("before2")
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it "sees replace after the map was primed" do
|
|
154
|
+
face_children_names # prime the map
|
|
155
|
+
victim = root.children.to_a.find { |n| n.name == "b" }
|
|
156
|
+
victim.replace(doc.create_element("swapped"))
|
|
157
|
+
expect(face_children_names).to include("swapped")
|
|
158
|
+
expect(face_children_names).not_to include("b")
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "sees content rewrites after the map was primed" do
|
|
162
|
+
face_children_names # prime the map
|
|
163
|
+
target = root.children.to_a.find { |n| n.name == "a" }
|
|
164
|
+
target.content = "rewritten"
|
|
165
|
+
names = face_children_names
|
|
166
|
+
expect(names).to include("a")
|
|
167
|
+
expect(root.children.to_a.find { |n| n.name == "a" }.text)
|
|
168
|
+
.to eq("rewritten")
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
require "tempfile"
|
|
6
|
+
|
|
7
|
+
# moxml#522 re-audit on the current stack: the three composed-schema
|
|
8
|
+
# families (attribute admission through included attributeGroups,
|
|
9
|
+
# chameleon type binding, substitution heads across includes) all
|
|
10
|
+
# validate through the composition-capable faces — xsd_file (the
|
|
11
|
+
# engine resolves schemaLocation against the file's directory) and
|
|
12
|
+
# compile_set. The bare STRING face cannot chase files, so it
|
|
13
|
+
# refuses composition with actionable guidance instead of the
|
|
14
|
+
# misleading "not declared (strict)" cascade (#522's original
|
|
15
|
+
# evidence).
|
|
16
|
+
RSpec.describe "composed-schema validation (moxml#522)" do
|
|
17
|
+
let(:ctx) { Moxml.new(:leptris) }
|
|
18
|
+
|
|
19
|
+
def with_schema_dir(&block)
|
|
20
|
+
dir = Dir.mktmpdir
|
|
21
|
+
File.write(File.join(dir, "group.xsd"), <<~XSD)
|
|
22
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
23
|
+
<xs:attributeGroup name="g">
|
|
24
|
+
<xs:attribute name="foo" type="xs:string"/>
|
|
25
|
+
<xs:attribute name="bar" type="xs:integer"/>
|
|
26
|
+
</xs:attributeGroup>
|
|
27
|
+
<xs:element name="head" type="xs:string"/>
|
|
28
|
+
</xs:schema>
|
|
29
|
+
XSD
|
|
30
|
+
File.write(File.join(dir, "doc.xsd"), <<~XSD)
|
|
31
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
32
|
+
<xs:include schemaLocation="group.xsd"/>
|
|
33
|
+
<xs:element name="doc">
|
|
34
|
+
<xs:complexType>
|
|
35
|
+
<xs:attributeGroup ref="g"/>
|
|
36
|
+
</xs:complexType>
|
|
37
|
+
</xs:element>
|
|
38
|
+
<xs:element name="container">
|
|
39
|
+
<xs:complexType>
|
|
40
|
+
<xs:sequence>
|
|
41
|
+
<xs:element ref="head"/>
|
|
42
|
+
</xs:sequence>
|
|
43
|
+
</xs:complexType>
|
|
44
|
+
</xs:element>
|
|
45
|
+
<xs:element name="member" type="xs:string"
|
|
46
|
+
substitutionGroup="head"/>
|
|
47
|
+
</xs:schema>
|
|
48
|
+
XSD
|
|
49
|
+
yield dir
|
|
50
|
+
ensure
|
|
51
|
+
FileUtils.remove_entry(dir) if dir
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "with the composition-capable faces" do
|
|
55
|
+
it "validates attributeGroup composition across an include" do
|
|
56
|
+
with_schema_dir do |dir|
|
|
57
|
+
schema = ctx.xsd_file(File.join(dir, "doc.xsd"))
|
|
58
|
+
expect(schema).to be_valid(%(<doc foo="hello" bar="42"/>))
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "validates a substitution member under an included head" do
|
|
63
|
+
with_schema_dir do |dir|
|
|
64
|
+
schema = ctx.xsd_file(File.join(dir, "doc.xsd"))
|
|
65
|
+
expect(schema).to be_valid(%(<container><member>v</member></container>))
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "rejects a non-member where the head is required" do
|
|
70
|
+
with_schema_dir do |dir|
|
|
71
|
+
schema = ctx.xsd_file(File.join(dir, "doc.xsd"))
|
|
72
|
+
expect(schema).not_to be_valid(
|
|
73
|
+
%(<container><stranger>v</stranger></container>),
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "validates chameleon type binding through compile_set" do
|
|
79
|
+
dir = Dir.mktmpdir
|
|
80
|
+
File.write(File.join(dir, "types.xsd"), <<~XSD)
|
|
81
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
82
|
+
<xs:simpleType name="code">
|
|
83
|
+
<xs:restriction base="xs:string">
|
|
84
|
+
<xs:pattern value="[A-Z]{3}"/>
|
|
85
|
+
</xs:restriction>
|
|
86
|
+
</xs:simpleType>
|
|
87
|
+
</xs:schema>
|
|
88
|
+
XSD
|
|
89
|
+
File.write(File.join(dir, "cham.xsd"), <<~XSD)
|
|
90
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
91
|
+
targetNamespace="urn:d" xmlns:d="urn:d"
|
|
92
|
+
elementFormDefault="qualified">
|
|
93
|
+
<xs:include schemaLocation="types.xsd"/>
|
|
94
|
+
<xs:element name="a1" type="d:code"/>
|
|
95
|
+
</xs:schema>
|
|
96
|
+
XSD
|
|
97
|
+
schema = ctx.xsd_set(File.join(dir, "types.xsd"),
|
|
98
|
+
File.join(dir, "cham.xsd"))
|
|
99
|
+
expect(schema).to be_valid(%(<a1 xmlns="urn:d">ABC</a1>))
|
|
100
|
+
ensure
|
|
101
|
+
FileUtils.remove_entry(dir) if dir
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context "with the bare string face" do
|
|
106
|
+
it "refuses composition with actionable guidance" do
|
|
107
|
+
source = <<~XSD
|
|
108
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
109
|
+
<xs:include schemaLocation="group.xsd"/>
|
|
110
|
+
<xs:element name="doc" type="xs:string"/>
|
|
111
|
+
</xs:schema>
|
|
112
|
+
XSD
|
|
113
|
+
expect { ctx.xsd(source) }
|
|
114
|
+
.to raise_error(ArgumentError, %r{xsd_file|compile_set})
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "keeps accepting self-contained sources" do
|
|
118
|
+
schema = ctx.xsd(<<~XSD)
|
|
119
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
120
|
+
<xs:element name="doc" type="xs:string"/>
|
|
121
|
+
</xs:schema>
|
|
122
|
+
XSD
|
|
123
|
+
expect(schema).to be_valid(%(<doc>hi</doc>))
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -53,10 +53,6 @@ RSpec.describe Moxml::Adapter::Leptris do
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
it "evaluates attribute-node queries with proper wrappers" do
|
|
56
|
-
# Native since 1.9.105 (leptris-ruby#153: ResultAttr with
|
|
57
|
-
# name/value); earlier bindings returned generic nodes whose
|
|
58
|
-
# #name raised, so the Ruby engine owned them.
|
|
59
|
-
skip "requires native attr results (leptris 1.9.105+)" unless described_class::ATTR_RESULT_NATIVE
|
|
60
56
|
attrs = doc.xpath("//item/@id")
|
|
61
57
|
expect(attrs.map(&:name)).to eq(%w[id id])
|
|
62
58
|
expect(attrs.map(&:value)).to eq(%w[1 2])
|
|
@@ -759,8 +755,6 @@ RSpec.describe Moxml::Adapter::Leptris do
|
|
|
759
755
|
let(:ctx) { Moxml.new(:leptris) }
|
|
760
756
|
|
|
761
757
|
it "answers engine source positions for parsed nodes" do
|
|
762
|
-
skip "requires leptris 1.9.181" unless described_class::NATIVE_SOURCE_POSITION
|
|
763
|
-
|
|
764
758
|
doc = ctx.parse("<root>\n <child>text</child>\n</root>")
|
|
765
759
|
expect(doc.root.source_position).to include(line: 1)
|
|
766
760
|
expect(doc.root.source_position).to be_a(Hash)
|
|
@@ -8,17 +8,38 @@ require "spec_helper"
|
|
|
8
8
|
# itself; an install without the gem at all stays silent (a normal
|
|
9
9
|
# deployment shape).
|
|
10
10
|
RSpec.describe "Config default-adapter degradation" do
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
# Cold selection without ivar access: the public reset clears the
|
|
12
|
+
# memoized probe verdict, resolved default name, and default
|
|
13
|
+
# Config instance (moxml#523 seam). The ambient default name is
|
|
14
|
+
# captured before the reset and re-pinned through the public
|
|
15
|
+
# writer afterwards — the surrounding suite may depend on a
|
|
16
|
+
# default pinned at require time (canon pins nokogiri).
|
|
17
|
+
def with_cold_selection
|
|
18
|
+
ambient = Moxml::Config.default_adapter
|
|
19
|
+
Moxml::Config.reset_adapter_selection!
|
|
18
20
|
yield
|
|
19
21
|
ensure
|
|
20
|
-
Moxml::Config.
|
|
21
|
-
|
|
22
|
+
Moxml::Config.default_adapter = ambient
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# The state a broken install produces: the gem is present and
|
|
26
|
+
# loads, but the engine's native build fails — simulated at the
|
|
27
|
+
# probe seam the selection actually consults (#523). A broken lane
|
|
28
|
+
# ENDS on the fallback adapter, so after the example the broken
|
|
29
|
+
# examples leave nokogiri pinned (the state consumers actually
|
|
30
|
+
# run under) — pinned AFTER with_cold_selection's ambient restore.
|
|
31
|
+
def with_broken_leptris
|
|
32
|
+
with_cold_selection do
|
|
33
|
+
allow(Moxml::Config).to receive(:leptris_native_probe).and_raise(
|
|
34
|
+
Moxml::AdapterError.new(
|
|
35
|
+
"plan result build failed (status=-5)",
|
|
36
|
+
adapter: :leptris,
|
|
37
|
+
operation: "probe",
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
yield
|
|
41
|
+
end
|
|
42
|
+
Moxml::Config.default_adapter = :nokogiri
|
|
22
43
|
end
|
|
23
44
|
|
|
24
45
|
it "warns loudly and names the fallback" do
|
|
@@ -36,8 +57,59 @@ RSpec.describe "Config default-adapter degradation" do
|
|
|
36
57
|
end
|
|
37
58
|
|
|
38
59
|
it "keeps a working leptris install silent" do
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
60
|
+
with_cold_selection do
|
|
61
|
+
expect do
|
|
62
|
+
Moxml::Config.default_adapter
|
|
63
|
+
end.not_to output(/unusable/).to_stderr
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# moxml#523: bundle presence is not capability. Under broken-ABI
|
|
68
|
+
# rubies (Ruby 4.0 plan builds answer status=-5, leptris#1966) a
|
|
69
|
+
# present leptris poisoned the whole lane. Selection now runs a
|
|
70
|
+
# one-shot parse+serialize probe and treats failure as
|
|
71
|
+
# present-but-unusable: loud warning, nokogiri fallback.
|
|
72
|
+
describe "native capability probe (#523)" do
|
|
73
|
+
before do
|
|
74
|
+
present = Gem::Specification.find_by_name("leptris")
|
|
75
|
+
skip "leptris gem not available" unless present
|
|
76
|
+
rescue Gem::LoadError
|
|
77
|
+
skip "leptris gem not available"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def with_failing_native_probe
|
|
81
|
+
with_cold_selection do
|
|
82
|
+
allow(Moxml::Adapter::Leptris).to receive(:parse).and_raise(
|
|
83
|
+
Moxml::AdapterError.new(
|
|
84
|
+
"plan result build failed (status=-5)",
|
|
85
|
+
adapter: :leptris,
|
|
86
|
+
operation: "parse",
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
yield
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "falls back loudly when the native build fails the probe" do
|
|
94
|
+
with_failing_native_probe do
|
|
95
|
+
expect do
|
|
96
|
+
expect(Moxml::Config.default_adapter).to eq(:nokogiri)
|
|
97
|
+
end.to output(/leptris adapter is installed but unusable/).to_stderr
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "memoizes the failed probe (one run per process)" do
|
|
102
|
+
with_failing_native_probe do
|
|
103
|
+
expect(Moxml::Config.leptris_preferred_available?).to eq(:broken)
|
|
104
|
+
expect(Moxml::Adapter::Leptris).not_to(receive(:parse))
|
|
105
|
+
expect(Moxml::Config.leptris_preferred_available?).to eq(:broken)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "keeps leptris when the probe passes on a healthy stack" do
|
|
110
|
+
with_cold_selection do
|
|
111
|
+
expect(Moxml::Config.default_adapter).to eq(:leptris)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
42
114
|
end
|
|
43
115
|
end
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require "tmpdir"
|
|
6
|
+
|
|
7
|
+
# moxml#522: composed-schema strict admission. The facade owns the
|
|
8
|
+
# composition — it resolves the instance's xsi:schemaLocation hints
|
|
9
|
+
# against the schema's own path, walks the schema graph
|
|
10
|
+
# (include/import/redefine) for the unit closure, and dismisses
|
|
11
|
+
# engine "not declared (strict)" rows the composed declaration index
|
|
12
|
+
# refutes — global declarations AND attributeGroup members. The
|
|
13
|
+
# engine admission gap itself is RESOLVED in leptris 1.9.409
|
|
14
|
+
# (leptris#1964 — register entry D-23). The 1.9.409 namespace-aware
|
|
15
|
+
# particle wave carries an upstream schG2 lexical regression
|
|
16
|
+
# (leptris#1976, residual leptris#1979 — register entry D-24); its rows are lexical, not
|
|
17
|
+
# admission rows, and pass through untouched here.
|
|
18
|
+
RSpec.describe "Moxml::XSD::Schema composed-schema validation (#522)" do
|
|
19
|
+
let(:ctx) { Moxml.new(:leptris) }
|
|
20
|
+
let(:main_xsd) do
|
|
21
|
+
<<~XSD
|
|
22
|
+
<?xml version="1.0"?>
|
|
23
|
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
|
24
|
+
<xsd:attribute name="att1" type="xsd:string"/>
|
|
25
|
+
<xsd:element name="doc">
|
|
26
|
+
<xsd:complexType>
|
|
27
|
+
<xsd:attributeGroup ref="main"/>
|
|
28
|
+
</xsd:complexType>
|
|
29
|
+
</xsd:element>
|
|
30
|
+
<xsd:attributeGroup name="main">
|
|
31
|
+
<xsd:attribute ref="att1"/>
|
|
32
|
+
<xsd:anyAttribute namespace="##any"/>
|
|
33
|
+
</xsd:attributeGroup>
|
|
34
|
+
</xsd:schema>
|
|
35
|
+
XSD
|
|
36
|
+
end
|
|
37
|
+
# The auxiliary unit: a global declaration the head unit never saw.
|
|
38
|
+
let(:aux_xsd) do
|
|
39
|
+
<<~XSD
|
|
40
|
+
<?xml version="1.0"?>
|
|
41
|
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
42
|
+
targetNamespace="http://aux">
|
|
43
|
+
<xsd:attribute name="ext" type="xsd:string"/>
|
|
44
|
+
</xsd:schema>
|
|
45
|
+
XSD
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Per-example fixture tempdir: created by the let, removed in the
|
|
49
|
+
# after hook. Plain lets + methods keep the suite ivar-free
|
|
50
|
+
# (house law).
|
|
51
|
+
let(:dir) { Dir.mktmpdir("moxml522") }
|
|
52
|
+
|
|
53
|
+
after { FileUtils.remove_entry(dir) }
|
|
54
|
+
|
|
55
|
+
def unit(name)
|
|
56
|
+
File.join(dir, name)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
before do
|
|
60
|
+
File.write(unit("main.xsd"), main_xsd)
|
|
61
|
+
File.write(unit("aux.xsd"), aux_xsd)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "unions the instance's hint documents into the validation" do
|
|
65
|
+
schema = ctx.xsd_file(unit("main.xsd"))
|
|
66
|
+
doc = ctx.parse(
|
|
67
|
+
'<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' \
|
|
68
|
+
'xmlns:e="http://aux" xsi:noNamespaceSchemaLocation="main.xsd" ' \
|
|
69
|
+
'xsi:schemaLocation="http://aux aux.xsd" att1="x" e:ext="y"/>',
|
|
70
|
+
)
|
|
71
|
+
expect(schema.validate(doc)).to be_empty
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "dismisses the engine's not-declared rows the union refutes" do
|
|
75
|
+
# Without the union the engine reports the aux attribute as
|
|
76
|
+
# undeclared; with it, the composed declaration index refutes
|
|
77
|
+
# the row. The engine may carry either the attribute-level row
|
|
78
|
+
# or the element-level root row (mixed-tns mis-admission) —
|
|
79
|
+
# both are refutable.
|
|
80
|
+
schema = ctx.xsd_file(unit("main.xsd"))
|
|
81
|
+
doc = ctx.parse(
|
|
82
|
+
'<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' \
|
|
83
|
+
'xmlns:e="http://aux" xsi:noNamespaceSchemaLocation="main.xsd" ' \
|
|
84
|
+
'xsi:schemaLocation="http://aux aux.xsd" att1="x" e:ext="y">text</doc>',
|
|
85
|
+
)
|
|
86
|
+
errors = schema.validate(doc)
|
|
87
|
+
expect(errors.map(&:message)).not_to include(
|
|
88
|
+
/not declared \(strict\)/,
|
|
89
|
+
)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "keeps genuinely undeclared attribute rows" do
|
|
93
|
+
schema = ctx.xsd_file(unit("main.xsd"))
|
|
94
|
+
doc = ctx.parse(
|
|
95
|
+
'<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' \
|
|
96
|
+
'xsi:noNamespaceSchemaLocation="main.xsd" att1="x" ghost="z"/>',
|
|
97
|
+
)
|
|
98
|
+
# `ghost` is declared nowhere: the strict row (when the engine
|
|
99
|
+
# emits one) must survive the dismissal.
|
|
100
|
+
errors = schema.validate(doc).map(&:message)
|
|
101
|
+
expect(errors.grep_v(/ghost.*not declared/)).to be_empty
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "does not build a union for string-compiled schemas" do
|
|
105
|
+
schema = ctx.xsd(main_xsd)
|
|
106
|
+
doc = ctx.parse("<doc att1=\"x\"/>")
|
|
107
|
+
expect(schema.validate(doc)).to be_empty
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# The attgC class (moxml#522): the attribute is a member of an
|
|
111
|
+
# attributeGroup reached through xs:redefine (the body hooks the
|
|
112
|
+
# original with a self-ref — 4.2.2) and an import. The instance
|
|
113
|
+
# carries no xsi hints; the composed unit closure must see the
|
|
114
|
+
# redefined/imported documents through the schema graph alone.
|
|
115
|
+
describe "group-member admission through the schema graph" do
|
|
116
|
+
let(:group_xsd) do
|
|
117
|
+
<<~XSD
|
|
118
|
+
<?xml version="1.0"?>
|
|
119
|
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
120
|
+
xmlns:imp="http://imported">
|
|
121
|
+
<xsd:import namespace="http://imported" schemaLocation="group.imp"/>
|
|
122
|
+
<xsd:redefine schemaLocation="group.red">
|
|
123
|
+
<xsd:attributeGroup name="car">
|
|
124
|
+
<xsd:attributeGroup ref="car"/>
|
|
125
|
+
<xsd:attributeGroup ref="imp:bar"/>
|
|
126
|
+
</xsd:attributeGroup>
|
|
127
|
+
</xsd:redefine>
|
|
128
|
+
<xsd:element name="doc" type="test"/>
|
|
129
|
+
<xsd:complexType name="test">
|
|
130
|
+
<xsd:attributeGroup ref="car"/>
|
|
131
|
+
</xsd:complexType>
|
|
132
|
+
</xsd:schema>
|
|
133
|
+
XSD
|
|
134
|
+
end
|
|
135
|
+
let(:group_red_xsd) do
|
|
136
|
+
<<~XSD
|
|
137
|
+
<?xml version="1.0"?>
|
|
138
|
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
|
139
|
+
<xsd:attributeGroup name="car">
|
|
140
|
+
<xsd:attribute name="att1" type="xsd:int"/>
|
|
141
|
+
</xsd:attributeGroup>
|
|
142
|
+
</xsd:schema>
|
|
143
|
+
XSD
|
|
144
|
+
end
|
|
145
|
+
let(:group_imp_xsd) do
|
|
146
|
+
<<~XSD
|
|
147
|
+
<?xml version="1.0"?>
|
|
148
|
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
149
|
+
targetNamespace="http://imported">
|
|
150
|
+
<xsd:attributeGroup name="bar">
|
|
151
|
+
<xsd:attribute name="att4" type="xsd:int"/>
|
|
152
|
+
</xsd:attributeGroup>
|
|
153
|
+
</xsd:schema>
|
|
154
|
+
XSD
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
before do
|
|
158
|
+
File.write(unit("group.xsd"), group_xsd)
|
|
159
|
+
File.write(unit("group.red"), group_red_xsd)
|
|
160
|
+
File.write(unit("group.imp"), group_imp_xsd)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it "admits redefined and imported group members on the element" do
|
|
164
|
+
schema = ctx.xsd_file(unit("group.xsd"))
|
|
165
|
+
doc = ctx.parse(
|
|
166
|
+
'<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' \
|
|
167
|
+
'xmlns:imp="http://imported" ' \
|
|
168
|
+
'xsi:noNamespaceSchemaLocation="group.xsd" att1="1" imp:att4="2"/>',
|
|
169
|
+
)
|
|
170
|
+
expect(schema.validate(doc)).to be_empty
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "keeps rows for attributes no unit of the composition declares" do
|
|
174
|
+
schema = ctx.xsd_file(unit("group.xsd"))
|
|
175
|
+
doc = ctx.parse(
|
|
176
|
+
'<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' \
|
|
177
|
+
'xsi:noNamespaceSchemaLocation="group.xsd" att1="1" ghost="z"/>',
|
|
178
|
+
)
|
|
179
|
+
errors = schema.validate(doc).map(&:message)
|
|
180
|
+
expect(errors.grep_v(/ghost.*not declared/)).to be_empty
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moxml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.4
|
|
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-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |
|
|
14
14
|
Moxml is a unified XML manipulation library that provides a common API
|
|
@@ -40,6 +40,7 @@ files:
|
|
|
40
40
|
- LICENSE.md
|
|
41
41
|
- README.adoc
|
|
42
42
|
- Rakefile
|
|
43
|
+
- bench/calibrate_520.rb
|
|
43
44
|
- benchmark/README.md
|
|
44
45
|
- benchmark/pipeline_bench.rb
|
|
45
46
|
- benchmark/plan_bench.rb
|
|
@@ -474,9 +475,11 @@ files:
|
|
|
474
475
|
- spec/moxml/adapter/headed_ox_spec.rb
|
|
475
476
|
- spec/moxml/adapter/leptris_adoption_spec.rb
|
|
476
477
|
- spec/moxml/adapter/leptris_append_gc_spec.rb
|
|
478
|
+
- spec/moxml/adapter/leptris_attribute_packet_spec.rb
|
|
477
479
|
- spec/moxml/adapter/leptris_attribute_snapshot_spec.rb
|
|
478
480
|
- spec/moxml/adapter/leptris_binding_cap_spec.rb
|
|
479
|
-
- spec/moxml/adapter/
|
|
481
|
+
- spec/moxml/adapter/leptris_children_address_spec.rb
|
|
482
|
+
- spec/moxml/adapter/leptris_composed_schema_spec.rb
|
|
480
483
|
- spec/moxml/adapter/leptris_contract_reads_spec.rb
|
|
481
484
|
- spec/moxml/adapter/leptris_crossdoc_replace_spec.rb
|
|
482
485
|
- spec/moxml/adapter/leptris_detached_text_spec.rb
|
|
@@ -623,6 +626,7 @@ files:
|
|
|
623
626
|
- spec/moxml/xpath_capabilities_spec.rb
|
|
624
627
|
- spec/moxml/xpath_spec.rb
|
|
625
628
|
- spec/moxml/xsd_builtin_lexical_spec.rb
|
|
629
|
+
- spec/moxml/xsd_composed_spec.rb
|
|
626
630
|
- spec/moxml/xsd_conformance_cases_spec.rb
|
|
627
631
|
- spec/moxml/xsd_engine_meta_spec.rb
|
|
628
632
|
- spec/moxml/xsd_error_contract_spec.rb
|