Skip to content

Skip settings schema validation on PowerShell versions less than 7#2231

Open
Copilot wants to merge 17 commits into
mainfrom
copilot/fix-pwsh-exe-filename-warning
Open

Skip settings schema validation on PowerShell versions less than 7#2231
Copilot wants to merge 17 commits into
mainfrom
copilot/fix-pwsh-exe-filename-warning

Conversation

Copilot AI commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

❔What, Why & How

On PS5.1, ValidateSettings shells out to pwsh.exe passing the full settings JSON as a command-line argument. For repositories with many projects/settings, the JSON can exceed the ~32K Windows command-line limit, producing:

Error validating settings. Error: Program 'pwsh.exe' failed to run: The filename or extension is too long

Fix: Silently skip schema validation entirely when $PSVersionTable.PSVersion.Major -lt 7. The ValidateSettings function now performs a hard return at the very beginning of its Process block on PS < 7, avoiding any JSON serialization or pwsh invocation. On PS7+, Test-Json is called directly (the previous Invoke-Command wrapper has been removed since it's no longer needed with the early exit guard).

✅ Checklist

  • Add tests (E2E, unit tests) — added Pester test verifying Test-Json is called on PS7+ and skipped on PS < 7, with no warnings produced
  • Update RELEASENOTES.md
  • Update documentation (e.g. for new settings or scenarios)
  • Add telemetry

Copilot AI and others added 3 commits April 30, 2026 13:31
Write settings JSON to a temp file instead of passing it as a
command-line argument to pwsh.exe, which exceeds the Windows
command-line length limit (~32K chars) for large settings.

Agent-Logs-Url: https://github.com/microsoft/AL-Go/sessions/90f81e6b-6fa6-4fa5-9a16-4c43637c704d

Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
…th limit

Instead of writing to a temp file, simply skip the validation when
the settings JSON is too large (>30K chars) for the Windows
command-line limit.

Agent-Logs-Url: https://github.com/microsoft/AL-Go/sessions/333f25d2-8e08-4ebf-8b95-fc6fe2001579

Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
@mazhelez mazhelez marked this pull request as ready for review April 30, 2026 13:51
@mazhelez mazhelez requested a review from a team as a code owner April 30, 2026 13:51
Copilot AI review requested due to automatic review settings April 30, 2026 13:51

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 addresses a Windows PowerShell 5.1 limitation where ValidateSettings shells out to pwsh and can exceed the Windows ~32K command-line length limit when passing large settings JSON, causing validation to fail.

Changes:

  • Add a PS5.1 guard to skip settings schema validation when the serialized settings JSON is larger than 30,000 characters.
  • Update release notes to document the fix for the “filename or extension is too long” validation error.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
RELEASENOTES.md Documents the PS5.1 validation-length-limit fix in the Issues list.
Actions/.Modules/ReadSettings.psm1 Adds an early-exit condition in ValidateSettings for PS5.1 when settings JSON is very large.

Comment thread Actions/.Modules/ReadSettings.psm1 Outdated
Comment thread Actions/.Modules/ReadSettings.psm1 Outdated
Comment thread Actions/.Modules/ReadSettings.psm1 Outdated
@mazhelez

Copy link
Copy Markdown
Collaborator

@copilot apply changes based on the comments in this thread

Copilot AI commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Applied all three changes from the review in commit bb500e1:

  1. Changed returncontinue in the Process block so subsequent piped items still get validated.
  2. Added an OutputWarning explaining that schema validation was skipped due to the PS5.1 command-line length limit.
  3. Added a unit test in Tests/ReadSettings.Test.ps1 that verifies oversized JSON skips validation (with warning on PS5.1, or runs in-process without skipping on PS7+). All 12 ReadSettings tests pass.

Copilot AI requested a review from mazhelez April 30, 2026 15:05
Comment thread Actions/.Modules/ReadSettings.psm1 Outdated
Copilot AI requested a review from mazhelez April 30, 2026 20:14
Comment thread Tests/ReadSettings.Test.ps1 Outdated
Copilot AI requested a review from mazhelez April 30, 2026 20:20

Copilot AI commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflict in RELEASENOTES.md (kept both entries) in 5828c83.

Copilot AI requested a review from mazhelez May 6, 2026 14:46
@mazhelez

Copy link
Copy Markdown
Collaborator

@copilot Actually, let's skip the validation altogether if the PS version is less than 7.
Please update the PR.

Copilot AI commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Actually, let's skip the validation altogether if the PS version is less than 7.
Please update the PR.

Done in d3d942c — validation is now skipped entirely when $PSVersionTable.PSVersion.Major -lt 7. Removed the length check and pwsh invocation; the test now verifies the skip happens for any settings on PS < 7.

Copilot AI changed the title Skip settings schema validation on PS5.1 when JSON exceeds command-line length limit Skip settings schema validation on PowerShell versions less than 7 May 20, 2026
Comment thread Actions/.Modules/ReadSettings.psm1 Outdated
Copilot AI requested a review from mazhelez May 20, 2026 08:55
Comment thread Actions/.Modules/ReadSettings.psm1 Outdated
Copilot AI requested a review from mazhelez May 20, 2026 09:26
@mazhelez

Copy link
Copy Markdown
Collaborator

@copilot can you please make sure the tests are up to date as well?

Copilot AI commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot can you please make sure the tests are up to date as well?

Updated in 209cefe — the test now mocks and asserts on Test-Json directly (verifying it's called once on PS7+ and zero times on PS < 7), removing the outdated pwsh mock and Invoke-Command references. All 12 tests pass.

@mazhelez

Copy link
Copy Markdown
Collaborator

@copilot when I try to update the PR branch, I get the following error:

"Head branch was modified. Review and try the merge again."

Please investigate and eventually update the branch.

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.

3 participants