Skip to content

Add [self, nextMajor) upper bound on extensions' Microsoft.Testing.Platform dependency - #9730

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/platform-dep-upper-bounds
Jul 8, 2026
Merged

Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/platform-dep-upper-bounds

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

The Microsoft.Testing.Platform extensions (src/Platform/Microsoft.Testing.Extensions.*, plus Microsoft.Testing.Platform.MSBuild) reference Microsoft.Testing.Platform via a ProjectReference. When packed, NuGet emits that as an open-ended, minimum-version dependency — e.g. Microsoft.Testing.Platform version="2.4.0", which means [2.4.0, ).

That open upper bound lets an extension built against Testing Platform 2.x silently resolve a future, potentially breaking 3.0.0. Since the extensions and the platform are versioned and ship in lockstep, this PR caps the packed dependency at the next major as a safety net:

Microsoft.Testing.Platform version="[2.4.0-…, 3.0.0)"

Changes

  • src/Platform/Directory.Build.props — introduces TestingPlatformNextMajorVersion, computed as (major of TestingPlatformVersionPrefix) + 1 .0.0 (i.e. 3.0.0 for the current 2.x line).
  • src/Platform/Directory.Build.targets (new) — a pack-time target (AfterTargets="_GetProjectReferenceVersions") that rewrites the packed Microsoft.Testing.Platform dependency's version to [self, nextMajor). It:
    • only touches the Microsoft.Testing.Platform entry (sibling deps such as TrxReport.Abstractions, Telemetry, Platform.AI are left open-ended);
    • preserves other dependency metadata (e.g. exclude="Build,Analyzers");
    • is idempotent (skips entries that are already a range);
    • imports the repo-root Directory.Build.targets via GetPathOfFileAbove so nothing is lost by introducing this file.

Verification

Packed several projects locally and inspected the generated .nuspec dependencies:

Package Microsoft.Testing.Platform dep
…Extensions.Retry [2.4.0-dev, 3.0.0) ✅
…Extensions.CrashDump [2.4.0-dev, 3.0.0) (sibling TrxReport.Abstractions stays 2.4.0-dev) ✅
…Extensions.VSTestBridge [2.4.0-dev, 3.0.0) (siblings Telemetry, TrxReport.Abstractions stay open) ✅
Microsoft.Testing.Platform.MSBuild [2.4.0-dev, 3.0.0) ✅
Microsoft.Testing.Platform no self-dependency, unaffected ✅
…Extensions.AzureFoundry references Platform.AI only — unaffected (out of scope) ✅

Scope note: this targets the direct Microsoft.Testing.Platform dependency specifically. Microsoft.Testing.Platform.AI (referenced only by AzureFoundry) is intentionally not bounded here.

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

…atform dependency

Extensions reference Microsoft.Testing.Platform via ProjectReference, which NuGet packs as an open-ended minimum-version dependency (e.g. 2.4.0 == [2.4.0, )). This lets an extension built against Testing Platform 2.x silently resolve a future breaking 3.0.0.

Add a shared pack-time target under src/Platform that rewrites the packed Microsoft.Testing.Platform dependency to a [self, nextMajor) range (e.g. [2.4.0, 3.0.0)) as a safety net, since the extensions and the platform are versioned and ship in lockstep.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 11:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an exclusive upper bound ([self, nextMajor)) to the packed Microsoft.Testing.Platform package dependency emitted by the in-repo MTP extensions (and Microsoft.Testing.Platform.MSBuild). By default, NuGet packs a ProjectReference as an open-ended minimum-version dependency (e.g. 2.4.0 == [2.4.0, )), which would let a 2.x-built extension silently resolve a future breaking 3.0.0. Since the extensions and the platform ship in lockstep, capping at the next major acts as a safety net. The change is confined to build/packaging infrastructure under src/Platform/ and does not touch product code.

Changes:

  • Introduces TestingPlatformNextMajorVersion in src/Platform/Directory.Build.props, computed as (major of TestingPlatformVersionPrefix) + 1 .0.0 (i.e. 3.0.0 today).
  • Adds a new src/Platform/Directory.Build.targets with a pack-time target (AfterTargets="_GetProjectReferenceVersions") that rewrites only the Microsoft.Testing.Platform dependency entry to [self, nextMajor), preserving other metadata and skipping entries that are already a range.
  • The new targets file chains the repo-root Directory.Build.targets via GetPathOfFileAbove so no existing build logic is dropped.
Show a summary per file
File Description
src/Platform/Directory.Build.props Adds TestingPlatformNextMajorVersion property derived from the platform version's major component, used as the exclusive upper bound.
src/Platform/Directory.Build.targets New file; chains the repo-root targets and adds a pack-time target that caps the emitted Microsoft.Testing.Platform dependency at the next major.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Medium

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

Review Summary

Clean, well-documented MSBuild change that solves a real packaging safety concern. The implementation correctly caps the Microsoft.Testing.Platform dependency at the next major version boundary to prevent extensions from silently resolving a breaking future major.

Verification of Key Design Decisions

Aspect Assessment
Version computation (Split('.')[0] + Add) ✅ Correct — "2.4.0".Split('.')[0] → "2", Add("2", 1) → 3, final = 3.0.0
Import chain (GetPathOfFileAbove) ✅ Correct — starts search from src/, finds repo-root Directory.Build.targets (no intermediate one at src/)
Target hook (AfterTargets="_GetProjectReferenceVersions") ✅ Correct hook point for modifying packed dependency versions
Scope filter (%(Filename) == 'Microsoft.Testing.Platform') ✅ Only touches the platform dependency; siblings (TrxReport.Abstractions, Telemetry, Platform.AI) unaffected
Idempotency (StartsWith('[')) ✅ Correctly detects if a range is already applied
Self-reference safety ✅ Microsoft.Testing.Platform.csproj has no self-reference, so the inner condition never matches when it's the project being packed
Pre-release handling ✅ Version like 2.4.0-dev is correctly wrapped to [2.4.0-dev, 3.0.0) — pre-release label stays in the lower bound

Verdict Table

Dimension Status Notes
Threading & Concurrency ✅ N/A MSBuild-only change
Security & IPC Contract Safety ✅ N/A No runtime code
Public API & Binary Compatibility ✅ N/A No public API surface; package dependency metadata only
Algorithmic Correctness ✅ Pass Version arithmetic and string manipulation are correct
Performance & Allocations ✅ N/A Runs only during pack, negligible overhead
Cross-TFM Compatibility ✅ N/A MSBuild targets are TFM-agnostic
Resource & IDisposable Management ✅ N/A No runtime code
Defensive Coding at Boundaries ✅ Pass Guard condition on TestingPlatformNextMajorVersion != ''; idempotency check prevents double-application
Correctness of Tests ⚠️ Note No automated test verifies the nuspec output; manual verification provided in PR description is thorough
Naming & Conventions ✅ Pass _AddTestingPlatformDependencyUpperBound follows private target naming convention
Code Duplication & DRY ✅ Pass Single definition point
Documentation & Comments ✅ Pass Thorough inline comments explain the "why" and the mechanism

Minor Observations (non-blocking)

  1. String.Copy obsolescence — cosmetic only, well-established MSBuild idiom (see inline comment).
  2. Reliance on NuGet-internal targets — pragmatic and documented; a pack-output assertion test would harden against silent regressions (see inline comment).

Overall: LGTM — this is a well-crafted safety net with minimal risk and clear value.

Comment thread src/Platform/Directory.Build.targets Resolved
Comment thread src/Platform/Directory.Build.targets Resolved
…test

- Replace the obsolete System.String::Copy idiom with System.String::new in the pack-time target condition (per review nit).

- Add PackageDependencyUpperBoundTests acceptance test that inspects the produced .nuspec files and asserts every packed Microsoft.Testing.Platform dependency is a closed [min, nextMajor) range. This guards against silent regressions if the NuGet-internal _GetProjectReferenceVersions / _ProjectReferencesWithVersions targets are renamed and the upper-bound target stops firing (per review hardening suggestion).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 12:02
@Evangelink

Copy link
Copy Markdown
Member Author

Addressed the two review suggestions in 2bf3ac1:

  • String.Copy nit — swapped the obsolete System.String::Copy idiom for System.String::new in the pack-time target condition.
  • Pack-verification hardening — added PackageDependencyUpperBoundTests, an acceptance test that opens the produced .nuspec files and asserts every packed Microsoft.Testing.Platform dependency is a closed [min, nextMajor) range (upper bound read from �ng/Versions.props). This fails if the NuGet-internal _GetProjectReferenceVersions / _ProjectReferencesWithVersions targets are ever renamed and the bound silently reverts to open-ended. Verified it passes on the real packages and fails on a bare-version package (3 violations, one per TFM group).

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🧪 Test quality grade — PR #9730

GradeTestNotes
A (90–100) new PackageDependencyUpperBoundTests.
PackedExtensions_
CapMicrosoftTestingPlatformDependency_
AtNextMajor
Two complementary assertions guard against vacuous pass (empty artifacts folder) and malformed version ranges; diagnostic messages are informative — no issues found.

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Re-run with
/grade-tests.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · 43.5 AIC · ⌖ 7.08 AIC · ⊞ 9.5K · [◷]( · ◷)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) July 8, 2026 14:14
@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jul 8, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit ac31ad4 into main Jul 8, 2026
33 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/platform-dep-upper-bounds branch July 8, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants