Skip to content

Unify Classic COM contract evidence in JSON registries - #151

Merged
leileizhang (lei9444) merged 3 commits into
mainfrom
lei9444-com-contract-registry
Sep 11, 2026
Merged

leileizhang (lei9444) merged 3 commits into
mainfrom
lei9444-com-contract-registry

Conversation

@lei9444

@lei9444 leileizhang (lei9444) commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Move five evidence families from code-embedded Rust registries into audited, compiled JSON under tools/dynwinrt-codegen/contracts/classic-com. These records augment WinMD method contracts; they are not OS registration or per-interface native implementations.

Grouped file Migrated records Evidence accounting
safearrays.json 209 209 exact; 69 borrowed inputs / 140 owned outputs
null-inputs.json 2 2 exact reserved-native-null inputs
parameter-directions.json 3 3 exact InOut-to-Out corrections
borrowed-handles.json 22 22 exact borrowed HWND outputs
enumerators.json 97 73 exact + 24 COM-standard, unchanged
Total 333 309 exact + 24 COM-standard
  • Extend the shared schema, typed deserializer/semantic validators, compiled file allowlist, manifest SHA-256 enforcement and evidence accounting. Reject unknown/missing fields, kind/family mismatches, duplicate IDs/selectors, unsupported semantic combinations and invalid hashes/provenance. JSON is the single authoritative data source; Rust retains closed semantic types, exact matching, lowering and thin derived adapters under src/contract_registry/adapters.
  • Preserve selectors, entry/family IDs, citations, reasons and existing fingerprints. SAFEARRAY source-shape strings are retained verbatim with an explicit raw-method-shape-v1 format and integrity hash. Null/direction canonical pre-override hashes are unchanged; borrowed/enumerator declarations additionally pin their complete source shapes. Catalog and generated-descriptor fingerprints remain unchanged.
  • Move the four existing nullable SAFEARRAY pointee allowances (GetRuntimeId, GetEmbeddedFragmentRoots, GetSelection, GetGrabbedItems) into structured, cited nullability contracts. Their receiving SAFEARRAY** cells remain required, mutable and Out. Other outputs remain required. VARTYPE, exact interface-IID checks and SafeArrayDestroy behavior are unchanged.
  • Preserve existing semantic diagnostic precedence, while checking the new source-shape pins on safe generation, raw/unsafe classification and exact-catalog collection. The capability.rs changes are limited to that guard and error propagation, not raw descriptor emission.

This is an independent PR based on verified origin/main at e7469c840e6f68310083b23520c6b681601eb276, not stacked on #150. It does not include the sibling generic codegen fixes, migrate borrowed-copy/runtime recipes, native completion, activation policies or other remaining contract families, or change COM/WinRT public APIs. Contract schema/manifest version remains 2; generated binding/support manifest versions are unchanged.

Behavior-preservation evidence

Pinned input: Microsoft.Windows.SDK.Win32Metadata 71.0.14-preview, SHA-256 B64EE4818A7ED9F9D135038D58C51BD08369184D4D5ED428F20E9DE55DF8121D.

Mechanical export/checks compared every migrated record against the original Rust definitions, including IDs, full selectors, source shapes/hashes, directions, ownership, citations and nullability. Baseline/final re-exports were byte-identical. Generation comparison covered 285 declaring/inherited roots, 1,366 safe JS/declaration/extra-file hashes, complete unsafe output/support records, and 4,247 canonical method fingerprints. The combined capture remained byte-identical (7062301D37375D13C499DF610FDFA2C699B6C41C9A164E0076FD132182187E8C). The one-off capture harness was removed from the source tree.

All seven capability-census artifacts, including complete entry/family/kind maps and per-interface dependencies, were byte-identical between baseline and two post-review runs. No census expectations or retained reports were changed.

Metric Before = after
Complete safe / eligible interfaces 5,721 / 7,929
Standard-derived / exact-dependent safe interfaces 5,355 / 366
Registered / metadata-matched exact entries 532 / 532
Distinct safe-consumed exact entries 431
Entry / family interface dependencies 694 / 425
Metadata / COM-standard fact occurrences 6,012 / 26,247

Safe-incomplete raw metadata/manual/blocked buckets also remain 388/1431/389 for x64 and ARM64, and 387/1408/413 for i686. Capability summary SHA-256 remains 90C01DFEED264A8BE50E859CDCC438A763B386B41324279F376BA89D564BAFCC.

Validation

$env:DYNWINRT_WIN32_WINMD = Join-Path $env:USERPROFILE '.nuget\packages\microsoft.windows.sdk.win32metadata\71.0.14-preview\Windows.Win32.winmd'
$env:DYNWINRT_REQUIRE_WIN32_METADATA = '1'
$env:DYNWINRT_REQUIRE_TSC = '1'

cargo test -p dynwinrt-codegen --lib registry
cargo test -p dynwinrt-codegen
cargo check -p dynwinrt-codegen --target x86_64-pc-windows-msvc --target i686-pc-windows-msvc
cargo test -p dynwinrt-codegen --test tsc_check_test --test com_sink_tsc_check_test --test snapshot_test -- --nocapture
cargo run -p dynwinrt-codegen --quiet -- com-capability-census --winmd $env:DYNWINRT_WIN32_WINMD --output-dir <census-output>
  • 37 focused registry tests passed, including real-metadata matching for all 333 records, malformed/duplicate/hash rejection, required receiving cells, inheritance and safe/unsafe/census drift rejection.
  • 734 full codegen tests passed across 35 runners, with required Win32 metadata and TypeScript. Explicit COM/WinRT TypeScript checks and six WinRT snapshots ran without skips. Locked JS dependencies were restored with npm --prefix bindings\js ci --ignore-scripts --no-audit --no-fund after the required compiler check reported the missing dependency; no dependency manifests changed.
  • x64 and i686 compile checks passed. Actual Draft 2020-12 JSON Schema validation passed all 489 grouped records and the exact documentation example; manifest hashes and both repeated census comparisons passed.
  • Independent review found one Serde internally-tagged unit-variant strictness gap. Reproduced it, changed the two nullability cases to empty struct variants, and added regression tests for both ignored-field examples. A focused independent follow-up confirmed the fix and validation paths, with no significant remaining issues.

No live device/UI/audio APIs or runtime cleanup E2Es were invoked: this changes evidence storage and validation, not runtime ABI or cleanup implementation. Existing WinRT output and the npm root surface are unchanged.

Adapter directory organization follow-up

Commit f370c13d062fbbd75ee0ec81f063d57719d7c3f5 organizes the compatibility layer without changing contracts. Relative to 9402f32, all five moves are 100% identical Git renames:

Former file under src/ New file under src/contract_registry/adapters/
com_safe_array_registry.rs safearray.rs
com_null_input_registry.rs null_input.rs
com_parameter_direction_registry.rs parameter_direction.rs
com_borrowed_handle_registry.rs borrowed_handle.rs
com_enumerator_registry.rs enumerator.rs

A crate-private adapters/mod.rs makes the boundary explicit. The old lib.rs module declarations are removed, all 36 production/test references use the new paths, and no old-name re-export shells or path bridges remain. The shared typed loader/schema/hash/provenance code stays in contract_registry; Raw representations, OnceLock caches, matching/validation order and diagnostic precedence stay unchanged. No generic abstraction or adapter-boilerplate rewrite was introduced. Metadata-side tests remain children of com_metadata to exercise private helpers without broadening production visibility. Unmigrated com_activation_registry.rs remains separate and untouched.

The JSON/schema/manifest files, stable IDs, 24 COM-standard enumerators, four nullable pointees with required receiving cells, safe/unsafe/census gates and support ranges are unchanged. The architecture documentation now distinguishes JSON facts, shared typed validation and Raw compatibility adapters.

Organization-specific validation

With the same pinned metadata and required TypeScript settings above:

cargo test -p dynwinrt-codegen --lib registry
cargo test -p dynwinrt-codegen --test win32_com_test --test win32_com_interop_test --test snapshot_test --test tsc_check_test --test com_sink_tsc_check_test -- --nocapture
rustup run 1.98.1-x86_64-pc-windows-msvc cargo fmt --all
rustup run 1.98.1-x86_64-pc-windows-msvc cargo fmt --all -- --check
cargo fmt --all -- --check
git diff --check

37 registry + 113 COM/interop/WinRT snapshot/tsc tests passed without skips. After the moves, the capture was rerun: all 333 re-exported records and all 285 roots (1,366 safe hashes, unsafe/support records, 4,247 method fingerprints) remained byte-identical to the retained baseline. All seven regenerated census artifacts also remained byte-identical, with the same hashes and totals above. Temporary capture source was removed before the final full-repository formatter checks. Repository-wide search found no remaining references to the five old module names.

An independent review limited to the organization delta against 9402f32 found no significant issues and independently ran all 10 relocated adapter tests; the metadata regression gates still compile and are discoverable. No live-device or runtime cleanup E2Es were needed for this organization-only follow-up.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 85.56% 80.92% 85.19% regions
Python aggregate 71.06% n/a 37.9% branches
Python runtime 99.12% n/a 97.37% branches
Generated Python WinRT projections 70.05% n/a 27.07% branches
Generated Python WinRT implementations 72.29% n/a 47.04% branches
JavaScript aggregate 21.98% 25.07% 57.34% branches
JavaScript runtime 38.26% 57.89% 71.01% branches
Generated WinRT projections 22.97% 18.71% 54.94% branches
Generated WinRT implementations 48.66% 59.76% 61.14% branches
Generated Classic COM projections 11.92% 23.97% 54.2% branches

View workflow run and download full HTML/LCOV/XML reports

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@lei9444
leileizhang (lei9444) merged commit 3f23710 into main Sep 11, 2026
24 checks passed
@lei9444
leileizhang (lei9444) deleted the lei9444-com-contract-registry branch September 11, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants