Deduplicate public sample path handling - #11727
Amaury Levé (Evangelink) merged 3 commits into
Conversation
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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 $samplesFolderinbuild-samples.ps1, and the equivalent intest-samples.ps1). The function body is copied verbatim aside from replacing the free variable$samplesFolderwith 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, nogh/external-tool duplication, no dry-run/exit-code handling involved.Set-StrictMode -Version Latestremains in effect in both calling scripts (dot-sourcing propagates that intosamples-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.
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>

Get-SampleRelativePathwas duplicated across the public sample build and test scripts and depended implicitly on script-scoped state.eng/samples-tools.ps1.This centralizes path normalization and containment validation while preserving existing behavior.
Get-SampleRelativePathFunction Duplicated in build-samples.ps1 and test-samples.ps1 #11723