Skip to content

Deduplicate public sample path handling - #11727

Merged
Amaury Levé (Evangelink) merged 3 commits into
mainfrom
copilot/duplicate-code-get-sample-relative-path
Oct 3, 2026
Merged

Amaury Levé (Evangelink) merged 3 commits into
mainfrom
copilot/duplicate-code-get-sample-relative-path

Conversation

Copilot AI commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Get-SampleRelativePath was duplicated across the public sample build and test scripts and depended implicitly on script-scoped state.

  • Shared helper
    • Moved the implementation to eng/samples-tools.ps1.
  • Explicit dependency
    • Both callers now provide the samples directory explicitly:
Get-SampleRelativePath -FullPath $project.FullName -SamplesFolder $samplesFolder

This centralizes path normalization and containment validation while preserving existing behavior.

Copilot AI balanced review requested due to automatic review settings October 3, 2026 11:15

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.

Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 3, 2026 11:23
Copilot AI changed the title [WIP] Refactor duplicate Get-SampleRelativePath function into shared module Deduplicate public sample path handling Oct 3, 2026

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.

Copilot review overview

🟡 Changes recommended

The new helper must be classified as sample-affecting so future changes exercise the sample jobs.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Comment thread eng/samples-tools.ps1
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Oct 3, 2026
@github-actions github-actions Bot removed the state/needs-review Awaiting review from the team. label Oct 3, 2026
@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review October 3, 2026 14:09
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) October 3, 2026 14:09
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Oct 3, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 3, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 3, 2026

@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.

Summary

Scope applied: Build, dependencies & scripts (dimensions 20, 22 — PowerShell Scripting Hygiene). All other scopes are not applicable: no public API, no src/test production code, no dependency version changes, no analyzer/IPC/localization surface touched.

This PR extracts the duplicated Get-SampleRelativePath function from eng/build-samples.ps1 and eng/test-samples.ps1 into a new shared eng/samples-tools.ps1, dot-sourced by both. The function signature is changed from an implicit closure over the script-scoped $samplesFolder variable to an explicit -SamplesFolder parameter.

Verdict: CLEAN.

  • Correctness: Both call sites were updated consistently (Get-SampleRelativePath -FullPath $project.FullName -SamplesFolder $samplesFolder in build-samples.ps1, and the equivalent in test-samples.ps1). The function body is copied verbatim aside from replacing the free variable $samplesFolder with the parameter $SamplesFolder, so behavior is unchanged.
  • PowerShell hygiene (dimension 22): This change is itself a positive hygiene fix — removing an implicit closure over a script-scoped variable in favor of an explicit parameter is exactly the "explicit over implicit" principle, and avoids the kind of silent cross-scope coupling that caused confusion in similar scripts elsewhere in eng/. No O(n2) array accumulation, no gh/external-tool duplication, no dry-run/exit-code handling involved. Set-StrictMode -Version Latest remains in effect in both calling scripts (dot-sourcing propagates that into samples-tools.ps1), so no regression there.
  • Dependency Upgrade Assessment: Not applicable — no package/dependency version changed.
  • Scope discipline: Single, well-contained refactor; no unrelated changes mixed in.

No actionable line-level findings; no inline comments posted.

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 3, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 3, 2026
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 3, 2026 14:16
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 3, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 3, 2026

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.

Copilot review overview

🟢 Approval recommended

The refactor preserves existing behavior and correctly updates both callers and CI classification coverage.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Oct 3, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Oct 3, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit 7e52054 into main Oct 3, 2026
23 of 27 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the copilot/duplicate-code-get-sample-relative-path branch October 3, 2026 16:08
@github-actions github-actions Bot removed the state/approved Proposal approved; ready for implementation. label Oct 3, 2026
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.

[duplicate-code] Duplicate Code: Get-SampleRelativePath Function Duplicated in build-samples.ps1 and test-samples.ps1

4 participants