pdf-xfa 1.0.0-beta.6

XFA engine — extraction, layout rendering, font resolution. Experimental and under active development.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
//! Static Adobe compatibility rule registry.

/// Stable identifier for a documented compatibility rule.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum AdobeCompatRuleId {
    /// Suppress data-empty pages only after real visible data binding occurred.
    SuppressEmptyPagesOnlyWhenRealDataBound,
    /// Hidden metadata bindings do not prove user data is present.
    IgnoreInvisibleServerMetadataBindingsForDataBoundSignal,
    /// Non-data widgets are structural and should not drive empty-page drops.
    ExcludeNonDataWidgetsFromPageSuppression,
    /// Saved form DOM page counts cap page suppression.
    CapSuppressionByFormDomPageAreaCount,
    /// Static XFAF surplus host pages can be trimmed under conservative guards.
    TrimStaticXfafExcessPagesWhenLayoutIsSinglePageAndFormDomAllows,
    /// Fields with `<bind match="none">` are template-only and never carry
    /// dataset values; they are excluded from the per-page "has data field"
    /// signal used by page suppression.
    ExcludeBindNoneFieldsFromPageDataSuppression,
    /// Repeating subform instance count is the matched dataset record
    /// count clamped to `[occur.min, occur.max]` (XFA §4.4.3, p186-192).
    /// When data exceeds `occur.max` the count is capped; when data is
    /// below `occur.min` the count is lifted. Acrobat enforces this
    /// clamp on every repeating-subform expansion.
    RepeatingSubformInstanceCountClampedToOccurRange,
    /// Subforms marked `<bind match="none">` are not auto-expanded
    /// from datasets even when their `<occur>` would otherwise allow
    /// repetition. They remain as a single template instance; only
    /// the scriptable `InstanceManager` may add more (XFA §4.4.3).
    BindNoneSubformDoesNotAutoExpand,
    /// When the saved form DOM records more repeating-subform
    /// instances than the template's initial expansion produced,
    /// the engine clones the template instance to match the form
    /// DOM's count. The form DOM is authoritative because it
    /// captures the runtime's `InstanceManager` decisions after
    /// scripts executed (XFA §4.4.3 + §6.4.3).
    FormDomDrivenRepeatInstanceReplication,
}

impl AdobeCompatRuleId {
    /// Stable snake-case identifier.
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::SuppressEmptyPagesOnlyWhenRealDataBound => {
                "suppress_empty_pages_only_when_real_data_bound"
            }
            Self::IgnoreInvisibleServerMetadataBindingsForDataBoundSignal => {
                "ignore_invisible_server_metadata_bindings_for_data_bound_signal"
            }
            Self::ExcludeNonDataWidgetsFromPageSuppression => {
                "exclude_non_data_widgets_from_page_suppression"
            }
            Self::CapSuppressionByFormDomPageAreaCount => {
                "cap_suppression_by_form_dom_page_area_count"
            }
            Self::TrimStaticXfafExcessPagesWhenLayoutIsSinglePageAndFormDomAllows => {
                "trim_static_xfaf_excess_pages_when_layout_is_single_page_and_form_dom_allows"
            }
            Self::ExcludeBindNoneFieldsFromPageDataSuppression => {
                "exclude_bind_none_fields_from_page_data_suppression"
            }
            Self::RepeatingSubformInstanceCountClampedToOccurRange => {
                "repeating_subform_instance_count_clamped_to_occur_range"
            }
            Self::BindNoneSubformDoesNotAutoExpand => "bind_none_subform_does_not_auto_expand",
            Self::FormDomDrivenRepeatInstanceReplication => {
                "form_dom_driven_repeat_instance_replication"
            }
        }
    }
}

/// Broad compatibility behavior category.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AdobeCompatCategory {
    /// Data binding and data-presence interpretation.
    Binding,
    /// Pagination and page suppression.
    Pagination,
    /// Static XFAF and hybrid PDF preservation/trimming.
    StaticPreservation,
}

impl AdobeCompatCategory {
    /// Stable lower-case tag.
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Binding => "binding",
            Self::Pagination => "pagination",
            Self::StaticPreservation => "static_preservation",
        }
    }
}

/// Engine phase where a rule is observed or expected to be traced.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AdobeCompatPhase {
    /// Bind/merge phase.
    Bind,
    /// Pagination/layout phase.
    Paginate,
    /// Page suppression phase.
    Suppress,
    /// Final PDF write/trim phase.
    Write,
}

impl AdobeCompatPhase {
    /// Stable lower-case tag.
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Bind => "bind",
            Self::Paginate => "paginate",
            Self::Suppress => "suppress",
            Self::Write => "write",
        }
    }
}

/// Rule lifecycle.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AdobeCompatStatus {
    /// Existing behavior documented and expected to remain active.
    Active,
    /// Proposed or evidence-only behavior that is not active yet.
    Experimental,
    /// Retained for compatibility history but no longer active.
    Deprecated,
}

impl AdobeCompatStatus {
    /// Stable lower-case tag.
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Active => "active",
            Self::Experimental => "experimental",
            Self::Deprecated => "deprecated",
        }
    }
}

/// Corpus or report reference used as rule evidence.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DocumentRef {
    /// Stable corpus document ID or short report ID.
    pub doc_id: &'static str,
    /// Short reason this document is evidence for the rule.
    pub note: &'static str,
}

/// Metadata for a single Adobe compatibility rule.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AdobeCompatRule {
    /// Stable typed rule identifier.
    pub id: AdobeCompatRuleId,
    /// Rule category.
    pub category: AdobeCompatCategory,
    /// Phase where the behavior is observed.
    pub phase: AdobeCompatPhase,
    /// Lifecycle status.
    pub status: AdobeCompatStatus,
    /// One-line behavior statement.
    pub statement: &'static str,
    /// Documents where this rule is positive evidence.
    pub positive_examples: &'static [DocumentRef],
    /// Documents where naive application of this rule would be wrong.
    pub counterexamples: &'static [DocumentRef],
    /// Report/source documents supporting the rule.
    pub source_docs: &'static [&'static str],
    /// Tests or intended tests related to the rule.
    pub related_tests: &'static [&'static str],
    /// Optional M1 trace reason tag for future runtime linkage.
    pub trace_reason: Option<&'static str>,
}

impl AdobeCompatRule {
    /// Stable single-line metadata rendering for tests and reports.
    pub fn stable_summary(&self) -> String {
        format!(
            "{}|{}|{}|{}|{}|examples:{}|counterexamples:{}|sources:{}|trace:{}",
            self.id.as_str(),
            self.category.as_str(),
            self.phase.as_str(),
            self.status.as_str(),
            self.statement,
            join_doc_ids(self.positive_examples),
            join_doc_ids(self.counterexamples),
            self.source_docs.join(","),
            self.trace_reason.unwrap_or("none"),
        )
    }
}

const RULE_SUPPRESS_EMPTY_PAGES_EXAMPLES: &[DocumentRef] = &[
    DocumentRef {
        doc_id: "13275420",
        note: "data-bound suppression must be bounded by real visible data",
    },
    DocumentRef {
        doc_id: "d9ec06f8",
        note: "rich datasets with empty terminal fields exercise suppression",
    },
];

const RULE_INVISIBLE_METADATA_EXAMPLES: &[DocumentRef] = &[DocumentRef {
    doc_id: "M3B_PAGECOUNT_FIDELITY_WAVE_RESULT",
    note: "AEM server metadata fields are invisible and should not set data-bound signal",
}];

/// M5.2b — counterexamples for `IgnoreInvisibleServerMetadataBindingsForDataBoundSignal`:
/// documents whose visible field bindings MUST set the global
/// data-bound signal so suppression downstream can run.
const RULE_INVISIBLE_METADATA_COUNTEREXAMPLES: &[DocumentRef] = &[DocumentRef {
    doc_id: "XDP_VISIBLE_BOUND_DROPS_EMPTY_PAGE",
    note: "visible CustomerName field with a dataset binding must set any_data_bound=true",
}];

const RULE_WIDGET_COUNTEREXAMPLES: &[DocumentRef] = &[
    DocumentRef {
        doc_id: "778a1138",
        note: "signature-only page is structurally required",
    },
    DocumentRef {
        doc_id: "e0909cf9",
        note: "barcode continuation is an Adobe-specific pagination counterexample",
    },
];

/// M5.2b — counterexamples for `ExcludeNonDataWidgetsFromPageSuppression`:
/// documents whose pages contain regular data fields (text, checkbox,
/// dropdown, etc.) that MUST count as data fields for the suppression
/// heuristic.
const RULE_WIDGET_RULE_COUNTEREXAMPLES: &[DocumentRef] = &[DocumentRef {
    doc_id: "XDP_VISIBLE_BOUND_DROPS_EMPTY_PAGE",
    note:
        "regular Text field on the page must count as a data field; widget rule must not exclude it",
}];

const RULE_FORM_DOM_EXAMPLES: &[DocumentRef] = &[DocumentRef {
    doc_id: "322faac4",
    note: "form DOM declares 17 pages and prevents over-trimming",
}];

/// UX1 counterexamples for the form-DOM cap rule: documents where the cap
/// rule must remain inactive (no form DOM is present, so suppression must
/// stay uncapped — naïvely caching `max_suppress = 0` here would over-preserve
/// pages).
const RULE_FORM_DOM_COUNTEREXAMPLES: &[DocumentRef] = &[DocumentRef {
    doc_id: "7dbbe9d9",
    note: "static XFAF form without form DOM; cap must be uncapped here",
}];

const RULE_STATIC_TRIM_EXAMPLES: &[DocumentRef] = &[DocumentRef {
    doc_id: "fe5de953",
    note: "form DOM present and single-page collapse allows trim of stale placeholders",
}];

const RULE_STATIC_TRIM_COUNTEREXAMPLES: &[DocumentRef] = &[
    DocumentRef {
        doc_id: "322faac4",
        note: "form DOM declares 17 pages > layout 7; trim blocked by form DOM",
    },
    DocumentRef {
        doc_id: "b5bd3a97",
        note: "static multi-page preservation guards against over-trimming",
    },
    DocumentRef {
        doc_id: "7dbbe9d9",
        note: "no form DOM, n_layout=1, host pages preserved (2/2) per Wave 9 None-arm hardening",
    },
    DocumentRef {
        doc_id: "0b86389a",
        note: "no form DOM, n_layout=1, host pages preserved (3/3) per Wave 9 None-arm hardening",
    },
];

/// M5.2 — `ExcludeBindNoneFieldsFromPageDataSuppression` positive evidence.
const RULE_BIND_NONE_EXAMPLES: &[DocumentRef] = &[DocumentRef {
    doc_id: "XDP_BIND_NONE_PAGE_IS_NOT_DROPPED",
    note: "page-1 static <bind match=\"none\"> field must not count as data; page is retained",
}];

/// M5.2 — bind=none counterexamples: pages where a regular (not bind=none)
/// data field IS present and the suppression heuristic must still consider
/// the page as data-bearing.
const RULE_BIND_NONE_COUNTEREXAMPLES: &[DocumentRef] = &[DocumentRef {
    doc_id: "XDP_VISIBLE_BOUND_DROPS_EMPTY_PAGE",
    note:
        "regular data field on page-1 is included in the data-field check; empty page-2 is dropped",
}];

/// M5.3 — positive evidence for the occur-clamp rule: synthetic test
/// templates that already exist in `merger.rs::tests` and exercise the
/// three clamp branches (max-bound, min-bound, unbounded-passthrough).
const RULE_OCCUR_CLAMP_EXAMPLES: &[DocumentRef] = &[
    DocumentRef {
        doc_id: "merger::tests::repeating_subform_clamps_to_occur_max",
        note: "5 data records, occur.max=2 → instance count clamped down to 2",
    },
    DocumentRef {
        doc_id: "merger::tests::repeating_subform_respects_occur_min",
        note: "1 data record, occur.min=3 → instance count lifted up to 3",
    },
];

/// M5.3 — counterexamples for the occur-clamp rule: cases where the
/// rule must NOT trigger a clamp (rule returns the data-driven count
/// unchanged), and cases where the rule never runs because the caller
/// short-circuits.
/// M5.3d — positive evidence for `FormDomDrivenRepeatInstanceReplication`.
const RULE_FORM_DOM_REPEAT_EXAMPLES: &[DocumentRef] = &[DocumentRef {
    doc_id: "XDP_FORM_DOM_THREE_INSTANCES",
    note: "form DOM declares 3 instances; template default is 1 → rule clones 2 more",
}];

/// M5.3d — counterexamples: form DOM count equal to or below the
/// template default (rule decides to add zero clones; trace silent).
const RULE_FORM_DOM_REPEAT_COUNTEREXAMPLES: &[DocumentRef] = &[
    DocumentRef {
        doc_id: "merger::tests::repeating_subform_expands_from_data",
        note: "no form DOM present → rule never consulted; expansion is data-driven only",
    },
    DocumentRef {
        doc_id: "XDP_FORM_DOM_SAME_AS_TEMPLATE",
        note: "form DOM declares same instance count as template → rule fires but clones 0",
    },
];

/// M5.3b — positive evidence for `BindNoneSubformDoesNotAutoExpand`.
const RULE_BIND_NONE_OCCUR_EXAMPLES: &[DocumentRef] = &[DocumentRef {
    doc_id: "XDP_BIND_NONE_OCCUR_REPEATING",
    note: "subform with <bind match=\"none\"/> and <occur max=\"5\"/> stays single-instance",
}];

/// M5.3b — counterexamples: subforms that DO expand because the rule
/// does not apply (no bind=none, or non-repeating occur).
const RULE_BIND_NONE_OCCUR_COUNTEREXAMPLES: &[DocumentRef] = &[
    DocumentRef {
        doc_id: "merger::tests::repeating_subform_expands_from_data",
        note: "no bind=none → rule allows expansion; 3 data records produce 3 instances",
    },
    DocumentRef {
        doc_id: "XDP_BIND_NONE_NON_REPEATING_OCCUR",
        note:
            "bind=none on non-repeating subform → rule fires but had no observable effect (silent)",
    },
];

const RULE_OCCUR_CLAMP_COUNTEREXAMPLES: &[DocumentRef] = &[
    DocumentRef {
        doc_id: "merger::tests::repeating_subform_unbounded_uses_data_count",
        note: "occur.max=-1 (unbounded) → rule returns data_count unchanged",
    },
    DocumentRef {
        doc_id: "XDP_BIND_NONE_PAGE_IS_NOT_DROPPED",
        note: "<bind match=\"none\"> short-circuits expansion → clamp rule never consulted",
    },
];

static REGISTRY: &[AdobeCompatRule] = &[
    AdobeCompatRule {
        id: AdobeCompatRuleId::SuppressEmptyPagesOnlyWhenRealDataBound,
        category: AdobeCompatCategory::Pagination,
        phase: AdobeCompatPhase::Suppress,
        status: AdobeCompatStatus::Active,
        statement: "Suppress data-empty pages only after visible DataDom binding proves real submitted data is present.",
        positive_examples: RULE_SUPPRESS_EMPTY_PAGES_EXAMPLES,
        counterexamples: RULE_WIDGET_COUNTEREXAMPLES,
        source_docs: &[
            "benchmarks/runs/M3B_PAGECOUNT_FIDELITY_WAVE_RESULT.md",
            "benchmarks/runs/M3B_PAGECOUNT_MISMATCH_BUCKETS.md",
            "benchmarks/runs/M5_PAGE_SUPPRESSION_RULES_DOSSIER.md",
        ],
        related_tests: &[
            "crates/pdf-xfa/tests/m3b_phaseD_kappa_page_drop.rs",
            "crates/pdf-xfa/src/adobe_compat/rules.rs::tests",
            "crates/pdf-xfa/tests/m5_page_suppression_rules.rs",
        ],
        trace_reason: Some("suppress_gated_by_data_bound_signal"),
    },
    AdobeCompatRule {
        id: AdobeCompatRuleId::IgnoreInvisibleServerMetadataBindingsForDataBoundSignal,
        category: AdobeCompatCategory::Binding,
        phase: AdobeCompatPhase::Bind,
        status: AdobeCompatStatus::Active,
        statement: "Bindings on invisible, hidden, or inactive fields do not set the global data-bound signal.",
        positive_examples: RULE_INVISIBLE_METADATA_EXAMPLES,
        counterexamples: RULE_INVISIBLE_METADATA_COUNTEREXAMPLES,
        source_docs: &[
            "benchmarks/runs/M3B_PAGECOUNT_FIDELITY_WAVE_RESULT.md",
            "benchmarks/runs/M5_SUPPRESSION_METADATA_RULES_DOSSIER.md",
        ],
        related_tests: &[
            "crates/pdf-xfa/src/merger.rs::parse_field",
            "crates/pdf-xfa/src/adobe_compat/rules.rs::tests",
            "crates/pdf-xfa/tests/m5_suppression_metadata_rules.rs",
        ],
        trace_reason: Some("invisible_field_binding_ignored"),
    },
    AdobeCompatRule {
        id: AdobeCompatRuleId::ExcludeNonDataWidgetsFromPageSuppression,
        category: AdobeCompatCategory::Pagination,
        phase: AdobeCompatPhase::Suppress,
        status: AdobeCompatStatus::Active,
        statement: "Signature, button, and barcode widgets are structural unless another rule proves they are data-empty repeaters.",
        positive_examples: RULE_WIDGET_COUNTEREXAMPLES,
        counterexamples: RULE_WIDGET_RULE_COUNTEREXAMPLES,
        source_docs: &[
            "benchmarks/runs/M3_XFA_NEXT_FIDELITY_TARGETS.md",
            "benchmarks/runs/M3B_PAGECOUNT_WAVE6_RESULT.md",
            "benchmarks/runs/M5_SUPPRESSION_METADATA_RULES_DOSSIER.md",
        ],
        related_tests: &[
            "crates/pdf-xfa/src/merger.rs::detect_field_kind",
            "crates/pdf-xfa/src/adobe_compat/rules.rs::tests",
            "crates/pdf-xfa/tests/m5_suppression_metadata_rules.rs",
        ],
        trace_reason: Some("non_data_widget_excluded_from_data_check"),
    },
    AdobeCompatRule {
        id: AdobeCompatRuleId::CapSuppressionByFormDomPageAreaCount,
        category: AdobeCompatCategory::Pagination,
        phase: AdobeCompatPhase::Suppress,
        status: AdobeCompatStatus::Active,
        statement: "When a saved form DOM declares a page-area count, page suppression must not reduce output below that count.",
        positive_examples: RULE_FORM_DOM_EXAMPLES,
        counterexamples: RULE_FORM_DOM_COUNTEREXAMPLES,
        source_docs: &[
            "benchmarks/runs/M3B_PAGECOUNT_WAVE5_RESULT.md",
            "benchmarks/runs/M3B_PAGECOUNT_CURRENT_STATE_AFTER_WAVE5B.md",
            "benchmarks/runs/UX1_TRACE_COMPAT_DOSSIER.md",
        ],
        related_tests: &[
            "corpus_322faac4_seventeen_pages",
            "crates/pdf-xfa/src/adobe_compat/rules.rs::tests",
            "crates/pdf-xfa/tests/ux1_trace_compat.rs",
        ],
        trace_reason: Some("suppress_capped_by_form_dom"),
    },
    AdobeCompatRule {
        id: AdobeCompatRuleId::TrimStaticXfafExcessPagesWhenLayoutIsSinglePageAndFormDomAllows,
        category: AdobeCompatCategory::StaticPreservation,
        phase: AdobeCompatPhase::Write,
        status: AdobeCompatStatus::Active,
        statement: "Static XFAF surplus host pages may be trimmed only when a saved form DOM corroborates trim intent (form-DOM page count <= layout, or single-page collapse with form DOM present); without a form DOM the host PDF page count is authoritative and no trim is performed.",
        positive_examples: RULE_STATIC_TRIM_EXAMPLES,
        counterexamples: RULE_STATIC_TRIM_COUNTEREXAMPLES,
        source_docs: &[
            "benchmarks/runs/M3B_PAGECOUNT_WAVE5_RESULT.md",
            "benchmarks/runs/M3B_FIDELITY_WAVE7_RESULT.md",
            "benchmarks/runs/M5_PAGE_SUPPRESSION_RULES_DOSSIER.md",
            "benchmarks/runs/PHASE2_WAVE9_RESULT.md",
            "benchmarks/runs/PHASE2_WAVE10_RESULT.md",
        ],
        related_tests: &[
            "corpus_7dbbe9d9_two_pages",
            "corpus_322faac4_seventeen_pages",
            "corpus_fe5de953_one_page",
            "static_xfaf_host_pages_preserved_without_form_dom",
            "static_trim_blocked_when_no_form_dom_present",
            "crates/pdf-xfa/src/adobe_compat/rules.rs::tests",
            "crates/pdf-xfa/tests/m5_page_suppression_rules.rs",
        ],
        trace_reason: Some("static_xfaf_trim_allowed"),
    },
    AdobeCompatRule {
        id: AdobeCompatRuleId::ExcludeBindNoneFieldsFromPageDataSuppression,
        category: AdobeCompatCategory::Pagination,
        phase: AdobeCompatPhase::Suppress,
        status: AdobeCompatStatus::Active,
        statement: "Fields with <bind match=\"none\"> are template-only and never carry dataset values; they are excluded from the per-page \"has data field\" signal used by page suppression.",
        positive_examples: RULE_BIND_NONE_EXAMPLES,
        counterexamples: RULE_BIND_NONE_COUNTEREXAMPLES,
        source_docs: &[
            "benchmarks/runs/M3B_PAGECOUNT_WAVE6_RESULT.md",
            "benchmarks/runs/M5_PAGE_SUPPRESSION_RULES_DOSSIER.md",
        ],
        related_tests: &[
            "bind_none_field_with_data_is_not_dropped",
            "crates/pdf-xfa/src/adobe_compat/rules.rs::tests",
            "crates/pdf-xfa/tests/m5_page_suppression_rules.rs",
        ],
        trace_reason: Some("bind_none_field_excluded_from_data_check"),
    },
    AdobeCompatRule {
        id: AdobeCompatRuleId::RepeatingSubformInstanceCountClampedToOccurRange,
        category: AdobeCompatCategory::Binding,
        phase: AdobeCompatPhase::Bind,
        status: AdobeCompatStatus::Active,
        statement: "Repeating subform instance count is the matched dataset record count clamped to [occur.min, occur.max] (XFA \u{00A7}4.4.3, p186-192). When data exceeds occur.max the count is capped; when data is below occur.min the count is lifted.",
        positive_examples: RULE_OCCUR_CLAMP_EXAMPLES,
        counterexamples: RULE_OCCUR_CLAMP_COUNTEREXAMPLES,
        source_docs: &[
            "benchmarks/runs/M5_OCCUR_RULE_DOSSIER.md",
        ],
        related_tests: &[
            "merger::tests::repeating_subform_clamps_to_occur_max",
            "merger::tests::repeating_subform_unbounded_uses_data_count",
            "merger::tests::repeating_subform_respects_occur_min",
            "crates/pdf-xfa/src/adobe_compat/rules.rs::tests",
            "crates/pdf-xfa/tests/m5_occur_rule.rs",
        ],
        trace_reason: Some("data_count_clamped_by_occur_max"),
    },
    AdobeCompatRule {
        id: AdobeCompatRuleId::BindNoneSubformDoesNotAutoExpand,
        category: AdobeCompatCategory::Binding,
        phase: AdobeCompatPhase::Bind,
        status: AdobeCompatStatus::Active,
        statement: "Subforms marked <bind match=\"none\"> are not auto-expanded from datasets even when their <occur> would otherwise allow repetition. They remain as a single template instance; only the scriptable InstanceManager may add more (XFA \u{00A7}4.4.3).",
        positive_examples: RULE_BIND_NONE_OCCUR_EXAMPLES,
        counterexamples: RULE_BIND_NONE_OCCUR_COUNTEREXAMPLES,
        source_docs: &["benchmarks/runs/M5_OCCUR_BIND_NONE_DOSSIER.md"],
        related_tests: &[
            "crates/pdf-xfa/src/adobe_compat/rules.rs::tests",
            "crates/pdf-xfa/tests/m5_occur_bind_none.rs",
        ],
        trace_reason: Some("bind_none_subform_expansion_skipped"),
    },
    AdobeCompatRule {
        id: AdobeCompatRuleId::FormDomDrivenRepeatInstanceReplication,
        category: AdobeCompatCategory::Binding,
        phase: AdobeCompatPhase::Bind,
        status: AdobeCompatStatus::Active,
        statement: "When the saved form DOM records more repeating-subform instances than the template's initial expansion produced, the engine clones the template instance to match the form DOM's count. The form DOM is authoritative because it captures the runtime's InstanceManager decisions after scripts executed (XFA \u{00A7}4.4.3 + \u{00A7}6.4.3).",
        positive_examples: RULE_FORM_DOM_REPEAT_EXAMPLES,
        counterexamples: RULE_FORM_DOM_REPEAT_COUNTEREXAMPLES,
        source_docs: &["benchmarks/runs/M5_OCCUR_FORMDOM_REPEAT_DOSSIER.md"],
        related_tests: &[
            "crates/pdf-xfa/src/adobe_compat/rules.rs::tests",
            "crates/pdf-xfa/tests/m5_occur_formdom_repeat.rs",
        ],
        trace_reason: Some("subform_materialised_from_data"),
    },
];

/// Return the deterministic v1 registry.
pub fn registry() -> &'static [AdobeCompatRule] {
    REGISTRY
}

fn join_doc_ids(refs: &[DocumentRef]) -> String {
    refs.iter()
        .map(|doc| doc.doc_id)
        .collect::<Vec<_>>()
        .join(",")
}