Summary
assert_checkstyle_well_formed_and_structural in the lib-crate test
helper claims to "assert structural conformance to
tests/fixtures/checkstyle-report-1.0.0.xsd", but it never validates
element nesting/parentage — it only validates each element's own name
and attributes plus overall tag-balance. Any Checkstyle output whose
elements are nested in violation of the XSD containment hierarchy
passes, defeating the only safeguard for the checkstyle output
format.
Location
tests/common/validators.rs:105-202
(assert_checkstyle_well_formed_and_structural + check_element)
Evidence
The XSD (tests/fixtures/checkstyle-report-1.0.0.xsd) defines a strict
containment hierarchy:
checkstyleType (root <checkstyle>) may contain <file>,
<exception>, <error>.
fileType (<file>) may contain <error>, <exception>.
errorType (<error>) is attribute-only — it may contain no
child elements.
The walker tracks only a scalar depth counter and a saw_root flag:
let mut saw_root = false;
let mut depth = 0usize;
...
Event::Start(start) => {
check_element(&start, &mut saw_root, pos);
depth += 1;
}
...
Event::End(end) => {
...
depth = depth.saturating_sub(1);
}
...
assert!(saw_root, "checkstyle: document did not contain a <checkstyle> root element");
assert!(depth == 0, "checkstyle: unbalanced element depth {depth} at EOF");
check_element validates the element's own name and attributes but
is never told its parent. Nothing rejects, for example:
<error> nested inside another <error> (XSD: errorType has no
child elements).
<file> nested inside a <file> or inside an <error>.
<checkstyle> appearing as a non-root element (it only needs to
appear somewhere; <file><checkstyle version="x"/></file> sets
saw_root = true and passes, with no actual <checkstyle> root).
<error> / <file> appearing at arbitrary depth.
The depth check only confirms start/end tags are balanced
(well-formedness), not that they nest per the XSD. The saw_root
flag only confirms a <checkstyle> token appeared, not that it is the
document root.
Relatedly, attr_value calls start.attributes().with_checks(false),
which disables quick-xml's duplicate-attribute detection, and it
returns the first matching attribute — so a writer emitting a
duplicate attribute (<error line="1" line="2" .../>) would silently
validate against the first value.
Expected Behavior
Either:
- The walker tracks the parent element (e.g., a small element stack)
and rejects illegal nesting per the XSD containment rules; or
- The docstring stops claiming "structural conformance to the XSD"
and instead describes what is actually checked — per-element name +
attribute validation plus tag-balance well-formedness, not XSD
nesting.
Actual Behavior
The helper advertises XSD structural conformance but accepts arbitrary
element nesting. A regression in src/output/checkstyle.rs that
nested <error>/<file> incorrectly, or emitted a <checkstyle>
that is not the document root, would pass every checkstyle
integration test in tests/checkstyle_test.rs.
Impact
High blast radius: this helper is the sole automated structural check
for the Checkstyle output format (consumed by all assertions in
tests/checkstyle_test.rs). A too-lenient validator gives false
confidence that the emitted XML conforms to the Checkstyle XSD when it
may not, so a structural writer regression ships undetected. (Distinct
from #899, which concerns the CLI copy's false "byte-for-byte sync"
docstring, not the validator's nesting coverage.)
Summary
assert_checkstyle_well_formed_and_structuralin the lib-crate testhelper claims to "assert structural conformance to
tests/fixtures/checkstyle-report-1.0.0.xsd", but it never validateselement nesting/parentage — it only validates each element's own name
and attributes plus overall tag-balance. Any Checkstyle output whose
elements are nested in violation of the XSD containment hierarchy
passes, defeating the only safeguard for the
checkstyleoutputformat.
Location
tests/common/validators.rs:105-202(
assert_checkstyle_well_formed_and_structural+check_element)Evidence
The XSD (
tests/fixtures/checkstyle-report-1.0.0.xsd) defines a strictcontainment hierarchy:
checkstyleType(root<checkstyle>) may contain<file>,<exception>,<error>.fileType(<file>) may contain<error>,<exception>.errorType(<error>) is attribute-only — it may contain nochild elements.
The walker tracks only a scalar
depthcounter and asaw_rootflag:check_elementvalidates the element's own name and attributes butis never told its parent. Nothing rejects, for example:
<error>nested inside another<error>(XSD: errorType has nochild elements).
<file>nested inside a<file>or inside an<error>.<checkstyle>appearing as a non-root element (it only needs toappear somewhere;
<file><checkstyle version="x"/></file>setssaw_root = trueand passes, with no actual<checkstyle>root).<error>/<file>appearing at arbitrary depth.The
depthcheck only confirms start/end tags are balanced(well-formedness), not that they nest per the XSD. The
saw_rootflag only confirms a
<checkstyle>token appeared, not that it is thedocument root.
Relatedly,
attr_valuecallsstart.attributes().with_checks(false),which disables
quick-xml's duplicate-attribute detection, and itreturns the first matching attribute — so a writer emitting a
duplicate attribute (
<error line="1" line="2" .../>) would silentlyvalidate against the first value.
Expected Behavior
Either:
and rejects illegal nesting per the XSD containment rules; or
and instead describes what is actually checked — per-element name +
attribute validation plus tag-balance well-formedness, not XSD
nesting.
Actual Behavior
The helper advertises XSD structural conformance but accepts arbitrary
element nesting. A regression in
src/output/checkstyle.rsthatnested
<error>/<file>incorrectly, or emitted a<checkstyle>that is not the document root, would pass every
checkstyleintegration test in
tests/checkstyle_test.rs.Impact
High blast radius: this helper is the sole automated structural check
for the Checkstyle output format (consumed by all assertions in
tests/checkstyle_test.rs). A too-lenient validator gives falseconfidence that the emitted XML conforms to the Checkstyle XSD when it
may not, so a structural writer regression ships undetected. (Distinct
from #899, which concerns the CLI copy's false "byte-for-byte sync"
docstring, not the validator's nesting coverage.)