Skip to content

InstancePropertyOwners is owner-keyed, so a genuinely-attached Grid.* reset in CleanElement is silently classified as an instance property and no test fires #1067

Closed

Description

Summary

PoolResetSetConsistencyTests partitions the properties reset in ElementPool.CleanElement's FE-common block into instance and attached buckets by owner:

// tests/Reactor.Tests/AnalyzerTests/PoolResetSetConsistencyTests.cs
.Where(m => !InstancePropertyOwners.Contains(m.Groups[1].Value))

Grid is in InstancePropertyOwners — correctly, because Grid.Padding and Grid.CornerRadius are ordinary instance DPs. But Grid is a mixed owner: Grid.Row, Grid.Column, Grid.RowSpan, Grid.ColumnSpan are genuine attached DPs.

Owner-level membership cannot express that. The consequence is that every future Grid.* reset — attached or not — is routed to the instance bucket and never reaches Every_Reset_Attached_Property_Is_Classified.

This is latent today: ElementPool currently clears only Grid.Padding and Grid.CornerRadius. It becomes live the moment anyone adds a Grid.Row/Grid.Column reset, which is a plausible thing to want when returning a pooled panel child.

Measured, with a positive control

Three arms against PoolResetSetConsistencyTests (this class reads ElementPool.cs as data at runtime, so --no-build is correct and the mutation need not compile). Each arm asserts the inserted token actually landed inside the scanned region before the verdict is interpreted.

arm inserted into the Grid arm of CleanElement token in scanned region result
ARM0 baseline — False Failed=0 Passed=54 Total=54
ARM1 resetGrid.ClearValue(WinUI.Grid.RowProperty); True Failed=0 Passed=54 — undetected
ARM2 control resetGrid.ClearValue(WinUI.Canvas.LeftProperty); True Failed=1 → Every_Reset_Attached_Property_Is_Classified
restore git checkout -- False Failed=0 Passed=54, porcelain 0

ARM2 proves the guard is live on this exact code path — it fails loudly for an owner outside the list. That is what makes ARM1 hard to notice: the mechanism looks healthy, and the discriminator is purely owner membership.

Why this is a detection regression, not merely a gap

Before Grid was added to InstancePropertyOwners, Grid.Padding/Grid.CornerRadius were claimed by the attached scan and silenced with rows in DeliberatelyExcludedAttached. Under that arrangement a newly-added Grid.Row clear would have failed Every_Reset_Attached_Property_Is_Classified, forcing a triage decision.

Moving Grid to the owner list — which is the right call for Padding/CornerRadius, and which removed the need for those suppression rows — also removed that failure. The hazard was not eliminated; it changed shape:

  • exclusion-list route: a future attached Grid.* reset fails the test, but the two existing Grid.* suppression rows sitting right there invite the wrong triage ("add another row").
  • owner-list route (current): a future attached Grid.* reset produces no failure at all — there is no triage moment to get wrong.

The in-code comment in InstancePropertyOwners argues the first hazard and does not mention the second. It should say both.

Suggested fix

Owner-level classification is the wrong granularity for a mixed owner. Two options:

  1. Property-level classification — key the instance set on Owner.Property pairs rather than bare owners.
  2. A deny-list guard (smaller, test-only) — assert that no known-attached DP name is absorbed by the instance scan:
private static readonly HashSet<string> KnownAttachedOnGridLikeOwners =
    new(StringComparer.Ordinal) { "Grid.Row", "Grid.Column", "Grid.RowSpan", "Grid.ColumnSpan" };

[Fact]
public void Instance_Scan_Does_Not_Absorb_A_Genuinely_Attached_Property()
{
    // reset names that reached the INSTANCE bucket, re-qualified with their owner
    var absorbed = ReadResetInstancePropertiesQualified()
        .Where(KnownAttachedOnGridLikeOwners.Contains)
        .ToList();

    Assert.True(absorbed.Count == 0,
        $"These are attached DPs but were classified as instance properties because their owner " +
        $"is in InstancePropertyOwners: {string.Join(", ", absorbed)}. Owner-level classification " +
        $"cannot express a mixed owner — classify per property.");
}

Whichever is chosen, the test must be validated the way ARM1/ARM2 above were: it should redden when Grid.RowProperty is added to CleanElement and stay green for Grid.Padding.

Relationship to the other classification issue

Same family as the DeliberatelyExcludedAttached silent-revert path filed separately: in both cases a property ends up counted as classified without being correctly classified, and Every_Reset_Attached_Property_Is_Classified passes because it only asks whether something is accounted for, never whether the account is right.

Repro

# insert next to the existing Grid clears in src/Reactor/Core/ElementPool.cs:
#     resetGrid.ClearValue(WinUI.Grid.RowProperty);
dotnet test tests\Reactor.Tests\Reactor.Tests.csproj -c Release -p:Platform=x64 --no-build `
  --filter "FullyQualifiedName~PoolResetSetConsistencyTests"
# -> Failed=0 Passed=54. Swap Grid.RowProperty for Canvas.LeftProperty -> Failed=1.
git checkout -- src/Reactor/Core/ElementPool.cs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions