Skip to content

Fix/windows installer exceptions - #1229

Merged
Fmarzochi merged 5 commits into
Fmarzochi:mainfrom
Akisolu:fix/windows-installer-exceptions
Aug 7, 2026
Merged

Fix/windows installer exceptions#1229
Fmarzochi merged 5 commits into
Fmarzochi:mainfrom
Akisolu:fix/windows-installer-exceptions

Conversation

@Akisolu

@Akisolu Akisolu commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • PS 5.1 Inline Node SyntaxError (scripts/install.ps1): Extracted inline node -e script execution into a dedicated script (scripts/lib/apply-commit-privacy.js) to avoid PowerShell 5.1 inner quote-stripping issues.
  • crusher-shim.js TypeError (scripts/crusher-shim.js): Added type normalization in printInstallResult() to handle installWindowsPath() single-object returns ({ changed, error }) on Windows and safely wrap them in an array before calling .filter().

Why This Change

  • PowerShell 5.1 stripped inner double quotes when invoking node -e inline scripts in install.ps1, causing path strings to unquote and throwing SyntaxError: Invalid regular expression flags.
  • On Windows, installWindowsPath() returns a single result object rather than an array, causing result.pathResult.filter(...) in crusher-shim.js to crash with a TypeError: result.pathResult.filter is not a function during installation summary printing.
  • Close test(v1.1.18): upgrade or install on Windows and report behavior #1217

Testing Done

  • Manual testing completed
  • Automated tests pass locally (node tests/run-all.js)
  • Edge cases considered and tested
  • If this PR touches a file shared across concurrent EGC processes (encryption key, state files, install-state, lockfiles under ~/.egc/), a concurrent-access test was added or updated

Type of Change

  • fix: Bug fix
  • feat: New feature
  • refactor: Code refactoring
  • docs: Documentation
  • test: Tests
  • chore: Maintenance/tooling
  • ci: CI/CD changes

Security & Quality Checklist

  • No secrets or API keys committed (ghp_, sk-, AKIA, xoxb, xoxp patterns checked)
  • JSON files validate cleanly
  • Shell scripts pass shellcheck (if applicable)
  • Pre-commit hooks pass locally (if configured)
  • No sensitive data exposed in logs or output
  • Follows conventional commits format

Documentation

  • Updated relevant documentation
  • Added comments for complex logic
  • README updated (if needed)

Summary by cubic

Fixes Windows installer errors on PowerShell 5.1 and resolves PATH summary crashes during install and uninstall on Windows. Fixes #1217.

  • Bug Fixes
    • PowerShell 5.1: replaced inline node -e with scripts/lib/apply-commit-privacy.js; restores correct ./memory-filters import and resolves scripts/check-state-leak.js; exit codes respected, failures are non-fatal and logged.
    • scripts/crusher-shim.js: normalize pathResult to an array for both flows, add a default PATH label ("Windows user PATH (registry)"), and guard filtering before printing.

Written for commit 0dc1b8c. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved installer handling when PATH update results are missing, invalid, or returned as a single entry.
    • Changed PATH records are now filtered more safely during installation and removal.
  • Improvements

    • Commit privacy filtering is configured more reliably during PowerShell installation.
    • Setup issues during commit privacy configuration remain non-blocking, allowing installation to continue with a notification.

@Akisolu
Akisolu requested a review from Fmarzochi as a code owner August 7, 2026 19:30
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The installer now uses a dedicated commit-privacy setup CLI. The crusher shim normalizes PATH results before filtering changed entries during installation and uninstallation.

Changes

Installer hardening

Layer / File(s) Summary
Commit-privacy setup flow
scripts/lib/apply-commit-privacy.js, scripts/install.ps1
The installer calls the new CLI with the project root. The CLI resolves scripts/check-state-leak.js, invokes applyCommitPrivacyFilterCli, and prefixes setup logs.
PATH result normalization
scripts/crusher-shim.js
pathResult values are normalized to arrays before nullish entries and changed PATH records are filtered.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant InstallScript as scripts/install.ps1
  participant PrivacyCLI as scripts/lib/apply-commit-privacy.js
  participant PrivacyHelper as applyCommitPrivacyFilterCli
  participant TargetScript as scripts/check-state-leak.js
  InstallScript->>PrivacyCLI: pass project root
  PrivacyCLI->>PrivacyHelper: configure project and target script
  PrivacyHelper->>TargetScript: apply commit-privacy filtering
  PrivacyCLI-->>InstallScript: prefixed logs and status
Loading

Suggested reviewers: fmarzochi

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes directly address Windows installer and PATH-output failures identified while validating issue [#1217].
Out of Scope Changes check ✅ Passed All changes support Windows installation, PATH result handling, or privacy-script execution; no unrelated scope is evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: fixing Windows installer exceptions.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

DCO sign-off missing

One or more commits in this PR are missing a Signed-off-by line (Developer Certificate of Origin).

How to fix:

# Single commit
git commit --amend -s
git push --force-with-lease

# Multiple commits -- replace N with the number of commits in your PR
git rebase --signoff HEAD~N
git push --force-with-lease

Note: This check is informational only -- a maintainer can still merge your PR without sign-off.

@Akisolu
Akisolu force-pushed the fix/windows-installer-exceptions branch from a52d3a1 to 903f3c7 Compare August 7, 2026 19:38

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/crusher-shim.js`:
- Around line 17-21: Update the result normalization and output handling in
scripts/crusher-shim.js around rawPathResult, pathResultArray, and changed to
support the Windows object shape from shim-install.js: preserve a displayable
Windows location when changed is true, and surface rawPathResult.error before
falling back to the generic “already configured” message when no changes
occurred.

In `@scripts/install.ps1`:
- Line 221: Update the commit-privacy setup invocation near
apply-commit-privacy.js so it executes with the user's repository,
$InvokedFromDir, as the working directory while retaining $RootDir for locating
the script and package resources. Ensure process.cwd() resolves to the user's
repository during setup.
- Line 221: Update the install script’s Node executable setup to resolve the
binary once using the established fixed-path-with-PATH-fallback approach, then
reuse that resolved variable when invoking apply-commit-privacy.js. Ensure the
version check and CLI call use the same Node binary, and remove the bare node
invocation.

In `@scripts/lib/apply-commit-privacy.js`:
- Around line 11-14: Replace both console.log calls in the commit-privacy filter
setup and catch path with the repository’s logging abstraction, keeping the
setup message at an informational level and routing the non-fatal failure
message through warning or error logging. Preserve the existing message content
and behavior.
- Around line 13-15: Update the catch block handling applyCommitPrivacyFilterCli
failures to set process.exitCode to 1 after logging the non-fatal error.
Preserve continuation of the installer while ensuring scripts/install.ps1 can
detect the helper failure through the process exit status.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 67314f54-26da-486e-b6df-07df09033d26

📥 Commits

Reviewing files that changed from the base of the PR and between 9446d30 and a52d3a1.

📒 Files selected for processing (3)
  • scripts/crusher-shim.js
  • scripts/install.ps1
  • scripts/lib/apply-commit-privacy.js

Comment thread scripts/crusher-shim.js Outdated
Comment thread scripts/install.ps1 Outdated
Comment thread scripts/lib/apply-commit-privacy.js Outdated
Comment thread scripts/lib/apply-commit-privacy.js Outdated
Akisolu added 2 commits August 7, 2026 15:40
… function

Signed-off-by: Akisolu <morillomiguel2707@gmail.com>
Signed-off-by: Akisolu <morillomiguel2707@gmail.com>
@Akisolu
Akisolu force-pushed the fix/windows-installer-exceptions branch from 903f3c7 to 266e845 Compare August 7, 2026 19:40

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread scripts/crusher-shim.js
Comment thread scripts/lib/apply-commit-privacy.js Outdated
Comment thread scripts/lib/apply-commit-privacy.js
…exit codes

Signed-off-by: Akisolu <morillomiguel2707@gmail.com>

@Fmarzochi Fmarzochi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

First code PR and you killed both crashes for real: end-to-end tested on the exact PowerShell that bit us, rebased cleanly on top of the stdio fix, tight scope, green CI and a passed quality gate. This is exactly the shape a fix PR should have. 👏

Four things to make it land solid, three of them Windows-only edge cases surfaced by the same investigation:

  1. printUninstallResult still has the original crash (scripts/crusher-shim.js:30): it calls result.pathResult.filter(...) just like the install path did, and on Windows uninstallWindowsPath() returns the same single object, so egc crusher-shim uninstall would still throw the exact TypeError you just fixed for install. Suggestion: extract your normalization into a tiny helper (e.g. toPathResultArray(raw)) and use it in both printers, so the contract lives in one place.

  2. The new script call only resolves from the repo root (scripts/install.ps1:221): node scripts/lib/apply-commit-privacy.js $RootDir is relative to the caller's working directory. Running the installer from anywhere else (powershell -File C:\path\to\EGC\scripts\install.ps1 from your home directory, for example) dies with Cannot find module. The original -e form was immune because it received $RootDir and required an absolute path. Fix: node "$RootDir/scripts/lib/apply-commit-privacy.js" $RootDir (the quotes also keep paths with spaces safe).

  3. On Windows the "changed" message prints an empty path: installWindowsPath() returns { changed, error } with no path field, so when the PATH really does get updated, changed.map(r => r.path).join(', ') renders PATH updated in: with nothing after it. Cheapest fix inside your normalization: when wrapping the single object, give it a label, e.g. [{ path: 'Windows user PATH (registry)', ...rawPathResult }].

  4. The try/catch in apply-commit-privacy.js makes the ps1 error check unreachable: catching everything and exiting 0 means if ($LASTEXITCODE -ne 0) on the next line can never fire, and the "non-fatal" note now lives in two places. Simplest is to drop the try/catch entirely: if the module throws, node exits non-zero and install.ps1 already prints the note, which is exactly how the old inline version behaved.

Nit: the new file is missing a trailing newline.

None of this needs re-architecting: all four fit inside the two files you already touched. Ping me when it's pushed and I'll run the full cycle again. 🦾

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread scripts/crusher-shim.js Outdated
Comment thread scripts/lib/apply-commit-privacy.js Outdated
@Fmarzochi

Copy link
Copy Markdown
Owner

Quick sync, since your 691261c and my review crossed mid-air: that commit already resolves my points 3 (path label) and 4 (the exit code now reaches the ps1 check) plus the newline nit. Nice reflexes. 😄

Two corrections and one leftover:

  • Correction on my point 2: I overstated the breakage. install.ps1 line 212 runs Set-Location -Path $RootDir before this block, so the relative node scripts/lib/apply-commit-privacy.js always resolves in the installer's real flow. Making it absolute (node "$RootDir/scripts/lib/apply-commit-privacy.js" $RootDir) is still worth one line as hardening against future reordering, but it is optional, not a blocker. My bad for the dramatic failure scenario.
  • Tiny one: the new inline comment in crusher-shim.js is in Spanish (// <-- Añadimos un label por defecto). The repo sticks to English everywhere, so please translate or drop it.
  • The one remaining blocker is point 1: printUninstallResult (scripts/crusher-shim.js:30) still calls .filter() on the raw pathResult, so egc crusher-shim uninstall on Windows keeps the original crash. Reusing your normalization there (ideally as a small shared helper both printers call) closes it.

After that this is ready to land. 🦾

… shim printer

Signed-off-by: Akisolu <morillomiguel2707@gmail.com>
@Akisolu

Akisolu commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

All 4 points addressed, @Fmarzochi!

  1. Uninstall printer crash: Extracted toPathResultArray() helper and applied it to both printInstallResult and printUninstallResult.

  2. Relative path issue: Updated install.ps1 to invoke node "$RootDir/scripts/lib/apply-commit-privacy.js" $RootDir with absolute paths.

  3. Empty PATH label on Windows: Added fallback path: rawPathResult.path || 'Windows user PATH (registry)' inside the helper so updated PATHs print cleanly.

  4. PowerShell error guard: Removed internal try/catch from apply-commit-privacy.js so Node exits non-zero on error, allowing $LASTEXITCODE -ne 0 in install.ps1 to handle the non-fatal note as intended.

Trailing newline added as well. Pushed and ready for the cycle! 🚀

@Fmarzochi

Copy link
Copy Markdown
Owner

So close! The toPathResultArray helper is exactly right, both printers are covered, and the absolute path on the ps1 side is in. One real problem slipped into 1859a4a though: apply-commit-privacy.js got rewired to two files that do not exist in the repo:

  • require('./apply-commit-privacy-filter-cli'): there is no such module. The export lives in ./memory-filters (scripts/lib/memory-filters.js:200), which is what your previous commit correctly required.
  • path.resolve(argv[2], 'scripts', 'git-hooks', 'commit-privacy-filter.js'): that path does not exist either. The real filter script is scripts/check-state-leak.js, which is what the original inline version pointed at.

As written, the script dies with MODULE_NOT_FOUND on every run, so the privacy filter would silently never apply on Windows, and CI cannot catch it because nothing exercises this file yet. Restore those two references from your 691261c version, keep everything else from this commit, and this is ready to land.

One mentor note, because it is a classic: if an editor AI suggested those paths, this is the textbook hallucinated import. A quick ls of every path you require before committing catches it in seconds. 🦾

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread scripts/lib/apply-commit-privacy.js Outdated
Comment thread scripts/lib/apply-commit-privacy.js Outdated
Comment thread scripts/crusher-shim.js
Signed-off-by: Akisolu <morillomiguel2707@gmail.com>
@Akisolu

Akisolu commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Good catch, Lesson learned on double-checking AI-suggested import paths against the file system.

Restored the correct references in scripts/lib/apply-commit-privacy.js:

Required ./memory-filters for applyCommitPrivacyFilterCli.

Pointed scriptPath to scripts/check-state-leak.js.

Tested locally with node scripts/lib/apply-commit-privacy.js $PWD and confirmed zero MODULE_NOT_FOUND issues. Pushed and good to go!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/crusher-shim.js`:
- Around line 30-31: Update the reporting logic in scripts/crusher-shim.js
around pathResultArray and changed to inspect each PATH operation result’s error
before evaluating changed or using the normal fallback. Ensure
installWindowsPath errors are reported instead of the generic already-configured
message, and uninstallWindowsPath errors are explicitly reported rather than
producing no output.
- Around line 30-31: Update the changed-result messaging in the flow using
pathResultArray and changed so Windows registry updates do not instruct users to
source the fallback label. Detect the Windows-specific registry result and print
guidance to open a new terminal; retain source instructions only for file-backed
shell updates.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 60ed5285-35bf-4358-a888-8b6b6093bf26

📥 Commits

Reviewing files that changed from the base of the PR and between a52d3a1 and 0dc1b8c.

📒 Files selected for processing (3)
  • scripts/crusher-shim.js
  • scripts/install.ps1
  • scripts/lib/apply-commit-privacy.js

Comment thread scripts/crusher-shim.js
@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@Fmarzochi Fmarzochi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

All review findings addressed and verified against the repo: shared toPathResultArray helper covering both printers, absolute script path, English-only comments, and the module references restored and locally tested. Green CI, quality gate passed. Approving.

@Fmarzochi
Fmarzochi merged commit c867f20 into Fmarzochi:main Aug 7, 2026
42 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in EGC Roadmap Aug 7, 2026
@Akisolu

Akisolu commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Thank you so much for the thorough review, guidance, and patience throughout the entire process.

I'm glad to contribute to EGC and see that both Windows issues have been officially resolved :D

@Akisolu
Akisolu deleted the fix/windows-installer-exceptions branch August 7, 2026 21:17
@Fmarzochi

Copy link
Copy Markdown
Owner

The pleasure was ours, Akisolu. This PR raised the bar for what a first code contribution looks like here: report, diagnosis, fix and verification, all from the same person. The review rounds were fast because you made them fast. See you in the next one. 🦾

@Fmarzochi Fmarzochi added this to the v1.1.19 milestone Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

test(v1.1.18): upgrade or install on Windows and report behavior

2 participants