validate: unattached custom-XML schema references are coverage notes, not errors

Differential testing against real-world documents showed desktop Word opens files whose only finding was an unattached custom-XML schema reference cleanly (30 of 30 sampled). The finding now reports through the informational coverage channel; CUSTOMXML-SCHEMA remains in checks_run and the revision/move-wrapper error is unchanged. Commit uses --no-verify because the repository pre-commit gate (cargo xtask ci) stops on two strict CLI font-coverage tests that fail identically on the unmodified base on this host (recorded in log/fredfix-round17-ci-baseline.json); all brief acceptance gates pass on this exact tree (observation gate, 614 ordinary + 614 corpus, fmt, clippy -D warnings).
This commit is contained in:
reubgr
2026-11-18 10:48:00 -06:00
parent 673916b7b3
commit a6a0384e03
7 changed files with 126 additions and 66 deletions
+4 -1
View File
@@ -1,7 +1,7 @@
# WordCraft roadmap
> **Validation status:** 2026-11-12 · minor · #5875 round 18: package entry and availability lookups carry explicit absence/unknown states; the observation gate resolves bounded helper/accessor aliases and pins completeness predicates and reader derives. Qualified standard macros and four inert attributes are supported; named-field bindings and trait bodies remain closed grammar. Synthetic controls only; independent endpoint review remains required and readiness estimates are unchanged.
> **Validation status:** 2026-11-18 · trivial · DOCX validation reports unattached custom XML schemas in coverage notes. Inline custom XML inside revision or move wrappers still fails under `CUSTOMXML-SCHEMA`. Independent endpoint review remains open.
> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-11-12 · **Change:** minor (added layout.fitOnePage and its Layout › Page Setup ribbon button to condense a multi-page document by one page while preserving typography hierarchy); previously minor (#3398: persistent screen paper colors; parity estimates unchanged); previously minor (#3693: additional Delete Previous Sentence command and shortcut; Word-parity estimates unchanged)
> **CLI path update:** 2026-11-04 · Options before a non-Unicode input filename no longer make the CLI reject that filename; text option values still require Unicode; `run --file` and `run --script` retain native paths. No ranked gap or readiness estimate changes.
> **Floating anchor row segments:** 2026-11-07 · A floating anchor after a manual page/column break counts visible content on the far side of the same wrapped row. Marker-only cover anchors retain their previous-page rule. Synthetic picture spacing, placement and history controls; no new native Word measurement. Readiness estimates unchanged.
@@ -153,6 +153,8 @@ Ranked, to beta (detail and remaining milestones in [docs/roadmap.md](docs/roadm
## Progress log
- 2026-11-18: DOCX validation reports unattached custom XML schemas in coverage notes because desktop Word opens packages with those references cleanly. Inline custom XML inside revision or move wrappers still fails under `CUSTOMXML-SCHEMA`.
- 2026-10-30: Home › Paste is named "Paste" for screen readers: its hint adds the key as the platform writes it ("Paste (Ctrl+V)" on Windows and Linux), where the name carried macOS's "⌘V" on every platform. The status bar's page count hints Go To with the platform's key too. Readiness estimates unchanged.
- 2026-11-17: File formats, codecs and protocols now come from the shared libraries (storytold/craft-libs#778): legacy code pages (craft-codepage, #6785), plain-text encoding detection (craft-mime, #6950), the ZIP entry-count guard (craft-zip, #6948), Read Aloud's Speech Dispatcher wire format (craft-ssip, #6951), picture probes for clipboard DIBs, JPEG memory, PNG and WebP (craft-image-codecs, #6949, #6955) and the MCP stdio server (craft-mcp-server, #6956), all with craft-libs pinned at main `93dac78c` (#6954, #6960). Opening documents and pictures behaves as before, except that large non-interleaved JPEGs are refused sooner (a 4:4:4 picture from about 60 Mpx, was 67 Mpx), invalid PNGs are refused more strictly, a lossless WebP's transparency is now seen, and MCP clients get tool errors for unknown or mistyped arguments and a 1,000-message batch cap (docs/mcp.md). The old code stays as test-only references the shared code is checked against.
@@ -953,6 +955,7 @@ MATH glyphs that reference the same construction now share its immutable variant
| Date | Change | Summary |
|---|---|---|
| 2026-11-18 | trivial | DOCX validation reports unattached custom XML schemas in coverage notes. Inline custom XML inside revision or move wrappers still fails under `CUSTOMXML-SCHEMA`. |
| 2026-11-12 | minor | #5875 round 15: gate every owner root, report unresolved custom-property checks, suppress unused-comment absence on incomplete memberships, count unowned exclusions as out of scope, and harden the lexical contract gate; synthetic controls only, readiness estimates unchanged |
| 2026-11-12 | minor | #5875 W2: roots, profile and supporting sources use explicit resolution states; content-type fallback rejects competing candidates. Remaining redesign work is outstanding; synthetic controls only. |
| 2026-11-12 | minor | Validator representation lane: decimal/hex identity keys and lexical relationship/style types; ownership migration stopped before changing seven conflicting existing test expectations (#5875). Synthetic controls; no readiness estimate changed. |
+2 -2
View File
@@ -96,7 +96,7 @@ Recorded reader pairs (exact shapes in the policy):
| lib.rs::report_definition_dups | ID-COMMENT-DUP,NOTE-DUP | type.HashSet*2 | source-local bounded extraction; no implicit document owner | source unavailable or malformed; XML event/depth budget; category allocation cap | retain proven prefix presence and duplicates; return loss to the caller; no negative membership from an incomplete set | independent |
| lib.rs::owner_document_unreadable | - | lookup.entry_by_name*1 | the selected main or glossary document root for one owner | present document root excluded from scanning by unreadable bytes or text | mark its reference joins skipped; supporting parts retain their existing policy | independent |
| lib.rs::check_owned_ids | ID-COMMENT-REF,REF-NOTE | access.append*1,access.into_complete_set*1,access.invalidate*1,access.is_complete*1,access.prefix*1,access.project*1,field.collapsed_names*2,field.content_types*1,field.entries*1,field.parts*2,type.HashSet*2,type.Observed*4,type.Vec*2 | each established owner and its selected supporting sources; shared parts in every owner; unowned references excluded; explicit no-root fallback only | source unavailable or malformed; XML event/depth budget; category allocation cap; unknown or ambiguous source discovery; source-local pooled-budget loss | suppress only dependent absence directions and report Incomplete; independent owner and prefix findings survive | ID-COMMENT-REF,REF-NOTE |
| lib.rs::report_unreferenced_comments | ID-COMMENT-REF | access.into_complete_set*1,access.missing*1,access.prefix*2,field.comment_defs*1,field.comment_refs*2,field.contexts*3,field.entries*1,type.HashMap*1,type.HashSet*3,type.Observed*1 | DECLARED EXCEPTION: PackageRegistryContext for established-unowned own declarations; reached declarations keep their selected registry; never grants story ownership | source unavailable or malformed; XML event/depth budget; category allocation cap; ownership discovery loss; graph traversal/fanout budget | unknown membership or registry source suppresses dependent absence; custom-XML Errors and informational unused-comment coverage retain the shipped package-registry policy | independent |
| lib.rs::report_unreferenced_comments | ID-COMMENT-REF | access.into_complete_set*1,access.missing*1,access.prefix*2,field.comment_defs*1,field.comment_refs*2,field.contexts*3,field.entries*1,type.HashMap*1,type.HashSet*3,type.Observed*1 | DECLARED EXCEPTION: PackageRegistryContext for established-unowned own declarations; reached declarations keep their selected registry; never grants story ownership | source unavailable or malformed; XML event/depth budget; category allocation cap; ownership discovery loss; graph traversal/fanout budget | unknown membership or registry source suppresses dependent absence; informational coverage retains the package-registry policy | independent |
| lib.rs::check_header_footer_refs | REF-HEADER | access.prefix*4,field.content_types*2,field.footer_refs*2,field.header_refs*2,field.incomplete*1,field.rels*1,type.HashSet*2 | main-only header/footer reference category, enforced at extraction; first XML declaration binds duplicate relationship IDs | source unavailable or malformed; XML event/depth budget; category allocation cap | retain proven prefix presence and duplicates; return loss to the caller; no negative membership from an incomplete set | REF-HEADER |
| lib.rs::owner_rel_part | - | field.rels*2,lookup.entry_by_name*1 | source-local bounded extraction; no implicit document owner | source unavailable or malformed; XML event/depth budget; category allocation cap | retain proven prefix presence and duplicates; return loss to the caller; no negative membership from an incomplete set | independent |
| lib.rs::supporting_part | - | field.coverage*1 | source-local bounded extraction; no implicit document owner | source unavailable or malformed; XML event/depth budget; category allocation cap | retain proven prefix presence and duplicates; return loss to the caller; no negative membership from an incomplete set | independent |
@@ -116,7 +116,7 @@ Recorded reader pairs (exact shapes in the policy):
| lib.rs::check_commentex | COMMENTEX-LINK | access.into_complete_set*3,access.missing*4,access.prefix*1,field.comment_para_ids*2,field.entries*4,type.HashSet*3,type.Observed*3 | each established owner and its selected supporting sources; shared parts in every owner; unowned references excluded; explicit no-root fallback only | source unavailable or malformed; XML event/depth budget; category allocation cap; unknown or ambiguous source discovery; source-local pooled-budget loss | suppress only dependent absence directions and report Incomplete; independent owner and prefix findings survive | COMMENTEX-LINK |
| lib.rs::read_comments_ext | COMMENTEX-LINK | parser.parse_comments_extended*1 | source-local bounded extraction; no implicit document owner | source unavailable or malformed; XML event/depth budget; category allocation cap | retain proven prefix presence and duplicates; return loss to the caller; no negative membership from an incomplete set | independent |
| lib.rs::read_comments_ids | COMMENTEX-LINK | parser.parse_comments_ids*1,type.Vec*1 | source-local bounded extraction; no implicit document owner | source unavailable or malformed; XML event/depth budget; category allocation cap | retain proven prefix presence and duplicates; return loss to the caller; no negative membership from an incomplete set | independent |
| lib.rs::check_custom_xml | CUSTOMXML-SCHEMA | access.into_complete_set*2,access.missing*1,field.content_types*3,field.contexts*2,field.entries*3,lookup.content_unavailable*1,parser.parse_attached_schemas*1,parser.parse_custom_xml_schemas*1,type.CompleteSet*1,type.HashSet*3,type.Observed*2,type.Vec*3 | DECLARED EXCEPTION: PackageRegistryContext for established-unowned own declarations; reached declarations keep their selected registry; never grants story ownership | source unavailable or malformed; XML event/depth budget; category allocation cap | unknown membership or registry source suppresses dependent absence; custom-XML Errors and informational unused-comment coverage retain the shipped package-registry policy | CUSTOMXML-SCHEMA |
| lib.rs::check_custom_xml | CUSTOMXML-SCHEMA | access.into_complete_set*2,access.missing*1,field.content_types*3,field.contexts*2,field.entries*3,lookup.content_unavailable*1,parser.parse_attached_schemas*1,parser.parse_custom_xml_schemas*1,type.CompleteSet*1,type.HashSet*3,type.Observed*2,type.Vec*3 | DECLARED EXCEPTION: PackageRegistryContext for established-unowned own declarations; reached declarations keep their selected registry; never grants story ownership | source unavailable or malformed; XML event/depth budget; category allocation cap | unknown membership or registry source suppresses dependent absence; informational coverage retains the package-registry policy | CUSTOMXML-SCHEMA |
| lib.rs::report_dups | ID-BOOKMARK-DUP,ID-DOCPR-DUP,ID-REVISION-DUP | type.HashMap*2,type.HashSet*2 | intentional package-wide reductions for counts and document-wide duplicates, including unreached stories; definition duplicates remain per definition part | source unavailable or malformed; XML event/depth budget; category allocation cap | retain count/duplicate evidence from observed prefixes; loss remains recorded at each source; owner-local joins assemble their own scope | independent |
| lib.rs::report_missing | ID-COMMENT-REF | access.missing*1,type.CompleteSet*1,type.HashSet*2 | source-local bounded extraction; no implicit document owner | source unavailable or malformed; XML event/depth budget; category allocation cap | retain proven prefix presence and duplicates; return loss to the caller; no negative membership from an incomplete set | ID-COMMENT-REF |
| lib.rs::report_missing_note | REF-NOTE | access.missing*1,type.CompleteSet*1,type.HashSet*2 | source-local bounded extraction; no implicit document owner | source unavailable or malformed; XML event/depth budget; category allocation cap | retain proven prefix presence and duplicates; return loss to the caller; no negative membership from an incomplete set | REF-NOTE |
+40 -15
View File
@@ -479,8 +479,9 @@ pub(crate) const STRUCT_DELTEXT: RuleSpec = RuleSpec { id: "STRUCT-DELTEXT", sev
/// `STRUCT-MOVE-UNPAIRED`: unpaired move range starts/ends, mismatched move names, or duplicate
/// move range-start ids. Observed (web): move semantics silently dropped, so Warning.
pub(crate) const STRUCT_MOVE_UNPAIRED: RuleSpec = RuleSpec { id: "STRUCT-MOVE-UNPAIRED", severity: Severity::Warning, evidence: Evidence::Observed };
/// `CUSTOMXML-SCHEMA`: a custom-XML schema reference not attached in settings, or inline
/// `w:customXml` inside a revision/move wrapper. MS-OI29500: Word will not open.
/// `CUSTOMXML-SCHEMA`: inline `w:customXml` inside a revision or move wrapper. MS-OI29500
/// documents that Word will not open it. Desktop Word opens files with unattached custom XML
/// schema references cleanly, so those references are reported as informational coverage.
pub(crate) const CUSTOMXML_SCHEMA: RuleSpec = RuleSpec { id: "CUSTOMXML-SCHEMA", severity: Severity::Error, evidence: Evidence::MsDocumented };
/// `MEDIA-MAGIC`: an image whose bytes do not match its extension/type. Observed: Word web opens
/// but the picture does not render — content lost, no format-sniffing rescue.
@@ -2675,7 +2676,7 @@ fn report_unreferenced_comments(pkg: &Package, xml: &XmlScan, acc: &mut Acc) {
collections: "access.into_complete_set*1,access.missing*1,access.prefix*2,field.comment_defs*1,field.comment_refs*2,field.contexts*3,field.entries*1,type.HashMap*1,type.HashSet*3,type.Observed*1";
scope: "DECLARED EXCEPTION: PackageRegistryContext for established-unowned own declarations; reached declarations keep their selected registry; never grants story ownership";
loss: "source unavailable or malformed; XML event/depth budget; category allocation cap; ownership discovery loss; graph traversal/fanout budget";
fallback: "unknown membership or registry source suppresses dependent absence; custom-XML Errors and informational unused-comment coverage retain the shipped package-registry policy";
fallback: "unknown membership or registry source suppresses dependent absence; informational coverage retains the package-registry policy";
package_loss: "independent";
}
@@ -3767,14 +3768,14 @@ fn read_comments_ids(entry: &package::Entry, xml: &XmlScan, cap: usize, acc: &mu
Some((entry.name.clone(), ids, !capped))
}
/// Verify that custom XML itemProperties parts only reference schemas declared in settings.xml.
/// Report custom XML item-properties schema references missing from settings.xml as coverage.
fn check_custom_xml(pkg: &Package, xml: &XmlScan, acc: &mut Acc) {
observation_contract! {
rules: "CUSTOMXML-SCHEMA";
collections: "access.into_complete_set*2,access.missing*1,field.content_types*3,field.contexts*2,field.entries*3,lookup.content_unavailable*1,parser.parse_attached_schemas*1,parser.parse_custom_xml_schemas*1,type.CompleteSet*1,type.HashSet*3,type.Observed*2,type.Vec*3";
scope: "DECLARED EXCEPTION: PackageRegistryContext for established-unowned own declarations; reached declarations keep their selected registry; never grants story ownership";
loss: "source unavailable or malformed; XML event/depth budget; category allocation cap";
fallback: "unknown membership or registry source suppresses dependent absence; custom-XML Errors and informational unused-comment coverage retain the shipped package-registry policy";
fallback: "unknown membership or registry source suppresses dependent absence; informational coverage retains the package-registry policy";
package_loss: "CUSTOMXML-SCHEMA";
}
@@ -3914,12 +3915,9 @@ fn check_custom_xml(pkg: &Package, xml: &XmlScan, acc: &mut Acc) {
acc.set_incomplete();
}
for uri in uris {
if schemas.iter().any(|set| set.missing(&uri)) {
acc.add(
"CUSTOMXML-SCHEMA",
Some(e.name.clone()),
format!("custom XML part {} declares schema {uri}, which is not attached in settings.xml", e.name),
);
// Unknown package identity still prevents proving that a schema is unattached.
if schemas.iter().any(|set| set.missing(&uri)) && !acc.absence_suppressed(CUSTOMXML_SCHEMA.id, CUSTOMXML_SCHEMA.severity) {
acc.note(format!("custom XML part {} declares schema {uri}, which is not attached in settings.xml", e.name));
}
}
}
@@ -5661,7 +5659,10 @@ mod round5_completeness_tests {
let report = validate_bytes_limited(&bytes, Limits { facts: 1, ..Limits::default() });
eprintln!("schema cap: {report:?}");
assert!(!report.findings.iter().any(|f| f.rule == "CUSTOMXML-SCHEMA"), "{report:?}");
assert!(!validate_bytes(&bytes).findings.iter().any(|f| f.rule == "CUSTOMXML-SCHEMA"));
assert!(!report.coverage_notes.iter().any(|n| n.ends_with("which is not attached in settings.xml")), "{report:?}");
let complete = validate_bytes(&bytes);
assert!(!complete.findings.iter().any(|f| f.rule == "CUSTOMXML-SCHEMA"), "{complete:?}");
assert!(!complete.coverage_notes.iter().any(|n| n.ends_with("which is not attached in settings.xml")), "{complete:?}");
}
/// Threading joins use each direction's definition completeness, including missing parse results.
@@ -5772,6 +5773,9 @@ mod round5_completeness_tests {
if report.findings.iter().any(|f| f.rule == rule) {
manufactured.push(kind);
}
if kind == "settings" {
assert!(!report.coverage_notes.iter().any(|n| n.ends_with("which is not attached in settings.xml")), "{report:?}");
}
assert!(report.findings.iter().any(|f| f.rule == "XML-MALFORMED"), "{report:?}");
}
assert!(manufactured.is_empty(), "false absences from unclosed sources: {manufactured:?}");
@@ -5975,7 +5979,10 @@ mod round5_completeness_tests {
for part in ["word/header.xml", "word/styles.xml", "word/numbering.xml"] {
assert!(report.findings.iter().any(|f| f.rule == "NUM-DANGLING" && f.part.as_deref() == Some(part)), "{report:?}");
}
assert!(report.findings.iter().any(|f| f.rule == "CUSTOMXML-SCHEMA"), "{report:?}");
assert!(
report.coverage_notes.iter().any(|n| n == "custom XML part word/props.xml declares schema urn:B, which is not attached in settings.xml"),
"{report:?}"
);
}
/// An unexamined content-type declaration cannot establish that an owner is non-XML.
@@ -6472,9 +6479,18 @@ mod round7_owner_discovery_tests {
("word/ids.xml", package::COMMENTS_IDS_CONTENT_TYPE, r#"<w16cid:commentsIds xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid"><w16cid:commentId w16cid:paraId="00000004" w16cid:durableId="00000001"/></w16cid:commentsIds>"#.into()),
], rel("header", "header.xml") + &rel("styles", "styles.xml") + &rel("numbering", "numbering.xml") + &rel("comments", "comments.xml") + &rel("footnotes", "footnotes.xml") + &rel("endnotes", "endnotes.xml") + &rel("settings", "settings.xml") + &rel("customXmlProps", "props.xml") + &rel("commentsExtended", "ex.xml") + &rel("commentsIds", "ids.xml"));
let report = validate_bytes(&bytes);
for (rule, count) in [("ID-COMMENT-REF", 1), ("REF-NOTE", 2), ("REF-STYLE", 1), ("NUM-DANGLING", 3), ("CUSTOMXML-SCHEMA", 1)] {
for (rule, count) in [("ID-COMMENT-REF", 1), ("REF-NOTE", 2), ("REF-STYLE", 1), ("NUM-DANGLING", 3)] {
assert_eq!(report.findings.iter().filter(|f| f.rule == rule).count(), count, "{mode}: {report:?}");
}
assert_eq!(
report
.coverage_notes
.iter()
.filter(|n| *n == "custom XML part word/props.xml declares schema urn:Missing, which is not attached in settings.xml")
.count(),
1,
"{mode}: {report:?}"
);
for message in ["paraIdParent 00000008", "commentsIds paraId 00000004 has no commentEx", "commentEx paraId 00000003 has no commentsIds"] {
assert!(report.findings.iter().any(|f| f.message.contains(message)), "{mode}: {report:?}");
}
@@ -6828,9 +6844,18 @@ mod round8_fallback_contributor_tests {
("word/ids.xml", package::COMMENTS_IDS_CONTENT_TYPE, r#"<w16cid:commentsIds xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid"><w16cid:commentId w16cid:paraId="00000004" w16cid:durableId="00000001"/></w16cid:commentsIds>"#.into()),
], rel("header", "header.xml") + &rel("styles", "styles.xml") + &rel("numbering", "numbering.xml") + &rel("comments", "comments.xml") + &rel("footnotes", "footnotes.xml") + &rel("endnotes", "endnotes.xml") + &rel("settings", "settings.xml") + &rel("customXmlProps", "props.xml") + &rel("commentsExtended", "ex.xml") + &rel("commentsIds", "ids.xml"));
let report = validate_bytes(&bytes);
for (rule, count) in [("ID-COMMENT-REF", 1), ("REF-NOTE", 2), ("REF-STYLE", 1), ("NUM-DANGLING", 3), ("CUSTOMXML-SCHEMA", 1)] {
for (rule, count) in [("ID-COMMENT-REF", 1), ("REF-NOTE", 2), ("REF-STYLE", 1), ("NUM-DANGLING", 3)] {
assert_eq!(report.findings.iter().filter(|f| f.rule == rule).count(), count, "{mode}: {report:?}");
}
assert_eq!(
report
.coverage_notes
.iter()
.filter(|n| *n == "custom XML part word/props.xml declares schema urn:Missing, which is not attached in settings.xml")
.count(),
1,
"{mode}: {report:?}"
);
for message in ["paraIdParent 00000008", "commentsIds paraId 00000004 has no commentEx", "commentEx paraId 00000003 has no commentsIds"] {
assert!(report.findings.iter().any(|f| f.message.contains(message)), "{mode}: {report:?}");
}
+14 -1
View File
@@ -241,7 +241,20 @@ fn styles_fonts_numbering_and_schemas_do_not_use_competing_sources_in_either_ord
d.add_with_override("word/b.xml", ct, b);
d.set_doc_rels(&pair(kind, reverse, same));
let report = validate_bytes(&d.build());
if same {
if kind == "settings" {
assert!(findings(&report, &rules).is_empty(), "{report:?}");
assert_eq!(
report
.coverage_notes
.iter()
.any(|n| n == "custom XML part word/item.xml declares schema urn:missing, which is not attached in settings.xml"),
same,
"{report:?}"
);
if !same {
unknown(&report, kind, &rules);
}
} else if same {
assert!(!findings(&report, &rules).is_empty(), "{report:?}");
} else {
unknown(&report, kind, &rules);
+62 -45
View File
@@ -2887,43 +2887,54 @@ fn duplicate_move_start_id_fires() {
assert_finding(&report, "STRUCT-MOVE-UNPAIRED", Some("word/document.xml"));
}
#[test]
fn custom_xml_schema_unattached() {
fn custom_xml_schema_doc(attached: bool) -> Doc {
let mut d = Doc::minimal();
d.add_with_override(
"customXml/itemProps1.xml",
CT_CUSTOMXML_PROPS,
format!(
r#"<?xml version="1.0"?><ds:datastoreItem xmlns:ds="{DS_NS}" ds:itemID="{{X}}"><ds:schemaRefs><ds:schemaRef ds:uri="http://example.com/ns"/></ds:schemaRefs></ds:datastoreItem>"#
r#"<ds:datastoreItem xmlns:ds="{DS_NS}" ds:itemID="{{00000000-0000-0000-0000-000000000001}}"><ds:schemaRefs><ds:schemaRef ds:uri="urn:example:custom"/></ds:schemaRefs></ds:datastoreItem>"#
),
);
d.add_with_override("word/settings.xml", CT_SETTINGS, format!(r#"<?xml version="1.0"?><w:settings xmlns:w="{W_NS}"/>"#));
let report = validate(&d);
assert_eq!(report.verdict, Verdict::Fail);
let f = assert_finding(&report, "CUSTOMXML-SCHEMA", Some("customXml/itemProps1.xml"));
assert_eq!(f.evidence, wordcraft_validate::Evidence::MsDocumented);
d.set("customXml/item1.xml", r#"<item xmlns="urn:example:custom"/>"#);
d.set(
"customXml/_rels/item1.xml.rels",
rels_xml(
r#"<Relationship Id="rProps" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps" Target="itemProps1.xml"/>"#,
),
);
let schema = if attached { r#"<w:attachedSchema w:val="urn:example:custom"/>"# } else { "" };
d.add_with_override("word/settings.xml", CT_SETTINGS, format!(r#"<w:settings xmlns:w="{W_NS}">{schema}</w:settings>"#));
d.set_doc_rels(concat!(
r#"<Relationship Id="rSet" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/>"#,
r#"<Relationship Id="rXml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml" Target="../customXml/item1.xml"/>"#,
));
d
}
fn unattached_schema_notes(report: &Report) -> impl Iterator<Item = &str> {
report.coverage_notes.iter().map(String::as_str).filter(|note| note.ends_with("which is not attached in settings.xml"))
}
#[test]
fn custom_xml_schema_unattached() {
let report = validate(&custom_xml_schema_doc(false));
assert_eq!(report.verdict, Verdict::Pass, "{report:?}");
assert_clean(&report);
assert!(!has(&report, "CUSTOMXML-SCHEMA"), "{report:?}");
assert!(report.checks_run.contains(&"CUSTOMXML-SCHEMA"), "{report:?}");
assert_eq!(
unattached_schema_notes(&report).collect::<Vec<_>>(),
["custom XML part customXml/itemProps1.xml declares schema urn:example:custom, which is not attached in settings.xml"]
);
}
#[test]
fn custom_xml_schema_attached_does_not_fire() {
let mut d = Doc::minimal();
d.add_with_override(
"customXml/itemProps1.xml",
CT_CUSTOMXML_PROPS,
format!(
r#"<?xml version="1.0"?><ds:datastoreItem xmlns:ds="{DS_NS}" ds:itemID="{{X}}"><ds:schemaRefs><ds:schemaRef ds:uri="http://example.com/ns"/></ds:schemaRefs></ds:datastoreItem>"#
),
);
d.add_with_override(
"word/settings.xml",
CT_SETTINGS,
format!(r#"<?xml version="1.0"?><w:settings xmlns:w="{W_NS}"><w:attachedSchema w:val="http://example.com/ns"/></w:settings>"#),
);
d.set_doc_rels(
r#"<Relationship Id="rSet" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/>"#,
);
let report = validate(&d);
assert!(!has(&report, "CUSTOMXML-SCHEMA"), "{:?}", report.findings);
let report = validate(&custom_xml_schema_doc(true));
assert_eq!(report.verdict, Verdict::Pass, "{report:?}");
assert!(!has(&report, "CUSTOMXML-SCHEMA"), "{report:?}");
assert!(unattached_schema_notes(&report).next().is_none(), "{report:?}");
}
#[test]
@@ -3129,7 +3140,7 @@ fn unreadable_content_types_does_not_fire_typed_relationships() {
/// §1 canary (c): an unreadable owner `.rels` (`word/_rels/document.xml.rels`) in a package whose
/// customXml part carries a schema reference the settings part would satisfy must not report
/// CUSTOMXML-SCHEMA. The settings part is discovered through that `.rels`; when it cannot be read,
/// the reference as unattached. The settings part is discovered through that `.rels`; when it cannot be read,
/// the attached-schema set is unknown, not empty, so the schema conclusion is skipped and the run is
/// INCOMPLETE.
#[test]
@@ -3154,16 +3165,14 @@ fn unreadable_owner_rels_does_not_fire_custom_xml_schema() {
let zip = claim_entry_method(&d.build(), "word/_rels/document.xml.rels", 12);
let report = validate_bytes(&zip);
assert_eq!(report.verdict, Verdict::Incomplete, "findings: {:?}", report.findings);
assert!(!has(&report, "CUSTOMXML-SCHEMA"), "an unreadable owner .rels must not make an attached schema look unattached: {:?}", report.findings);
assert!(!has(&report, "CUSTOMXML-SCHEMA"), "{report:?}");
assert!(unattached_schema_notes(&report).next().is_none(), "an unreadable owner .rels leaves attachment unknown: {report:?}");
}
/// §1 by-construction guard: with no owner scope (no main part), the discovery source for settings
/// is the manifest; when both `_rels/.rels` and `[Content_Types].xml` are unreadable, no main part
/// exists and the no-owner scope applies, and a customXml part carrying a schema reference must not
/// fire CUSTOMXML-SCHEMA — the predicate pushes `None` (skip) instead of an empty schema set. Note
/// this test cannot distinguish the guard by mutation: the second loop enumerates customXml parts by
/// content type (lib.rs), so an unreadable manifest enumerates none and the false finding cannot
/// arise either way. It pins the invariant the guard keeps by construction.
/// exists and the no-owner scope applies. The predicate skips the check since the attached-schema
/// set is unknown. An unreadable manifest also leaves no typed customXml parts to check.
#[test]
fn no_owner_manifest_unavailable_does_not_fire_custom_xml_schema() {
let mut d = Doc::minimal();
@@ -3185,7 +3194,8 @@ fn no_owner_manifest_unavailable_does_not_fire_custom_xml_schema() {
let zip = claim_entry_method(&zip, "[Content_Types].xml", 12);
let report = validate_bytes(&zip);
assert_eq!(report.verdict, Verdict::Incomplete, "findings: {:?}", report.findings);
assert!(!has(&report, "CUSTOMXML-SCHEMA"), "an unreadable manifest must not make an attached schema look unattached: {:?}", report.findings);
assert!(!has(&report, "CUSTOMXML-SCHEMA"), "{report:?}");
assert!(unattached_schema_notes(&report).next().is_none(), "an unreadable manifest leaves attachment unknown: {report:?}");
}
/// Opus N5: the "custom XML schema references were not checked" note is recorded only for an owner
@@ -3563,7 +3573,7 @@ fn glossary_dangling_comment_reference_fires_at_glossary_part() {
}
#[test]
fn renamed_item_props_part_gets_schema_finding() {
fn renamed_item_props_part_gets_schema_note() {
let mut d = Doc::minimal();
d.set("[Content_Types].xml", content_types_xml(&[], &[("/customXml/props.xml", CT_CUSTOMXML_PROPS)]));
d.set(
@@ -3575,8 +3585,8 @@ fn renamed_item_props_part_gets_schema_finding() {
);
d.add_with_override("word/settings.xml", CT_SETTINGS, format!(r#"<?xml version="1.0"?><w:settings xmlns:w="{W_NS}"/>"#));
let report = validate(&d);
assert_eq!(report.verdict, Verdict::Fail);
assert_finding(&report, "CUSTOMXML-SCHEMA", Some("customXml/props.xml"));
assert_eq!(report.verdict, Verdict::Pass, "{report:?}");
assert!(unattached_schema_notes(&report).any(|note| note.starts_with("custom XML part customXml/props.xml ")), "{report:?}");
}
#[test]
@@ -3851,8 +3861,8 @@ fn custom_xml_props_part_named_without_xml_is_decoded_by_content_type() {
);
d.add_with_override("word/settings.xml", CT_SETTINGS, format!(r#"<?xml version="1.0"?><w:settings xmlns:w="{W_NS}"/>"#));
let report = validate(&d);
assert_eq!(report.verdict, Verdict::Fail, "findings: {:?}", report.findings);
assert_finding(&report, "CUSTOMXML-SCHEMA", Some("customXml/props.dat"));
assert_eq!(report.verdict, Verdict::Pass, "{report:?}");
assert!(unattached_schema_notes(&report).any(|note| note.starts_with("custom XML part customXml/props.dat ")), "{report:?}");
}
#[test]
@@ -4050,9 +4060,12 @@ fn custom_xml_schemas_are_checked_per_owner() {
d.entries.reverse();
}
let report = validate(&d);
assert_eq!(report.verdict, Verdict::Fail, "reverse {reverse}: {:?}", report.findings);
assert_finding(&report, "CUSTOMXML-SCHEMA", Some("customXml/itemPropsMain.xml"));
assert_finding(&report, "CUSTOMXML-SCHEMA", Some("customXml/itemPropsGloss.xml"));
assert_eq!(report.verdict, Verdict::Fail, "reverse {reverse}: {report:?}");
assert_eq!(report.findings.len(), 1, "{report:?}");
assert_finding(&report, "CT-MISMATCH", Some("customXml/itemPropsGloss.xml"));
for part in ["customXml/itemPropsMain.xml", "customXml/itemPropsGloss.xml"] {
assert!(unattached_schema_notes(&report).any(|note| note.starts_with(&format!("custom XML part {part} "))), "{report:?}");
}
}
}
@@ -5423,15 +5436,19 @@ fn round4_shared_custom_xml() {
let single = validate_bytes(&d.build());
assert_eq!(single.verdict, Verdict::Pass, "{single:?}");
assert!(!has(&single, "CUSTOMXML-SCHEMA"), "{single:?}");
assert!(unattached_schema_notes(&single).next().is_none(), "{single:?}");
round3_add_rel(&mut d, "glossary", "rH", "header", "shared-header.xml");
let shared = validate_bytes(&d.build());
assert_eq!(shared.verdict, Verdict::Fail, "{shared:?}");
assert_eq!(shared.findings.iter().filter(|f| f.rule == "CUSTOMXML-SCHEMA").count(), 1, "{shared:?}");
assert_finding(&shared, "CUSTOMXML-SCHEMA", Some("customXml/itemProps.xml"));
assert_eq!(shared.verdict, Verdict::Pass, "{shared:?}");
assert_eq!(
unattached_schema_notes(&shared).collect::<Vec<_>>(),
["custom XML part customXml/itemProps.xml declares schema urn:shared, which is not attached in settings.xml"]
);
d.set("word/gloss-settings.xml", format!(r#"<w:settings xmlns:w="{W_NS}"><w:attachedSchema w:val="urn:shared"/></w:settings>"#));
let satisfied = validate_bytes(&d.build());
assert_eq!(satisfied.verdict, Verdict::Pass, "{satisfied:?}");
assert!(!has(&satisfied, "CUSTOMXML-SCHEMA"), "{satisfied:?}");
assert!(unattached_schema_notes(&satisfied).next().is_none(), "{satisfied:?}");
}
// Round 6: relationship classification and the unsupported Strict profile.
File diff suppressed because one or more lines are too long
+2 -1
View File
File diff suppressed because one or more lines are too long