Repository navigation
fix(cmd-shim): handle unicode paths on windows - #16205
Conversation
Decode non-ASCII CMD launcher text using UTF-8 in both implementations. Restore the caller's code page and return the tool's actual exit status. Leave ASCII-only launcher output unchanged. Add execution regressions under code pages 437, 936 and 65001, including argument forwarding, failure status, and inherited ERRORLEVEL overrides. Closes pnpm#6999
|
💖 Thanks for opening this pull request! 💖 |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: pnpm/pnpm/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe Rust and TypeScript command-shim generators now wrap scripts containing non-ASCII characters with UTF-8 code-page handling. Tests cover generated scripts and Windows execution under several code pages. ChangesUnicode Windows command shims
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Assessment against linked issues
Suggested labels: Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue remains; batch targets return to the shim so it can restore the code page. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The launchers restore the previous encoding and preserve the tool’s exit status during normal execution. If a launcher is interrupted, however, it can leave the console using a different encoding. No privilege-boundary expansion has been established. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
pnpm11/bins/cmd-shim/src/index.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. pnpm11/bins/cmd-shim/test/e2e.test.jsESLint skipped: the matched ESLint configuration already failed (missing-dependency). 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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16205 +/- ##
==========================================
+ Coverage 92.03% 92.04% +0.01%
==========================================
Files 1484 1484
Lines 199999 200016 +17
==========================================
+ Hits 184070 184108 +38
+ Misses 15929 15908 -21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Same-run regression checkHEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval. Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.
Integrated-Benchmark Report (Linux)Commit: Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked-workspace scenario compares current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD. The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.4781751244400003,
"stddev": 0.13078060393845423,
"median": 2.4548922615400004,
"user": 1.6506414800000002,
"system": 1.83659574,
"min": 2.3396900895400004,
"max": 2.6815580965400003
},
{
"command": "pacquet@main",
"mean": 2.44606733214,
"stddev": 0.12312314529703412,
"median": 2.39148204304,
"user": 1.5833659800000002,
"system": 1.83838634,
"min": 2.3390532415400003,
"max": 2.6749210155400003
},
{
"command": "pnpr@HEAD",
"mean": 1.48128577764,
"stddev": 0.1309365233752559,
"median": 1.45996873504,
"user": 1.48074008,
"system": 1.6035849399999997,
"min": 1.34470822054,
"max": 1.70026595654
},
{
"command": "pnpr@main",
"mean": 1.4529986426399997,
"stddev": 0.11580924873959408,
"median": 1.4187441390399997,
"user": 1.4904070800000002,
"system": 1.6008623399999997,
"min": 1.34878697054,
"max": 1.69943922454
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.23739233458000006,
"stddev": 0.03232573118968215,
"median": 0.22705236178000002,
"user": 0.27408788,
"system": 0.55076112,
"min": 0.20412373728000002,
"max": 0.30942871128000005
},
{
"command": "pacquet@main",
"mean": 0.23067780287999998,
"stddev": 0.010511795193079909,
"median": 0.23193595678,
"user": 0.24723187999999996,
"system": 0.57930562,
"min": 0.21801041528,
"max": 0.25058202528
},
{
"command": "pnpr@HEAD",
"mean": 0.2382212470800001,
"stddev": 0.01586624816448822,
"median": 0.23692352628000002,
"user": 0.25720448,
"system": 0.53757322,
"min": 0.21656601428000002,
"max": 0.26495591828000004
},
{
"command": "pnpr@main",
"mean": 0.24850636988000002,
"stddev": 0.012581232625148443,
"median": 0.24826520628000004,
"user": 0.28113768,
"system": 0.55456692,
"min": 0.22538688128,
"max": 0.26854595528
}
]
}Scenario: Isolated linker: repeat install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.010322452051182792,
"stddev": 0.0009859609846067411,
"median": 0.01019890532,
"user": 0.005254597275985662,
"system": 0.005773128888888884,
"min": 0.00845049332,
"max": 0.01393595932
},
{
"command": "pacquet@main",
"mean": 0.010218207008259103,
"stddev": 0.0009288320173515519,
"median": 0.01011282732,
"user": 0.005538776761133601,
"system": 0.005369586234817815,
"min": 0.00802380532,
"max": 0.01376158932
},
{
"command": "pnpr@HEAD",
"mean": 0.009950727795655435,
"stddev": 0.0007608493428307323,
"median": 0.00985930732,
"user": 0.005067024194756554,
"system": 0.005569144868913854,
"min": 0.00855520332,
"max": 0.01270028532
},
{
"command": "pnpr@main",
"mean": 0.015323632696425863,
"stddev": 0.0033976923051116,
"median": 0.01543311032,
"user": 0.008495049201520909,
"system": 0.007707940684410644,
"min": 0.00914671932,
"max": 0.025426974320000004
}
]
}Scenario: Isolated linker: repeat install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.011266828846796117,
"stddev": 0.004589200388788242,
"median": 0.00950951874,
"user": 0.006282225242718449,
"system": 0.005806689320388344,
"min": 0.00783115174,
"max": 0.027998136740000002
},
{
"command": "pacquet@main",
"mean": 0.008953656541687768,
"stddev": 0.0007421408566724426,
"median": 0.00897597974,
"user": 0.004894178902953586,
"system": 0.004781493670886079,
"min": 0.00754719374,
"max": 0.010648034740000001
},
{
"command": "pnpr@HEAD",
"mean": 0.00964844464295359,
"stddev": 0.0007664559471241281,
"median": 0.009636677740000002,
"user": 0.0053142810126582275,
"system": 0.00505540928270042,
"min": 0.007843491740000002,
"max": 0.012360009740000002
},
{
"command": "pnpr@main",
"mean": 0.009799707641287552,
"stddev": 0.0006273455783061785,
"median": 0.009734347740000001,
"user": 0.005573406008583688,
"system": 0.004931542918454937,
"min": 0.008540560740000001,
"max": 0.01283939874
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.5440343631399998,
"stddev": 0.037501689420676346,
"median": 2.5480455062400003,
"user": 1.9180259800000001,
"system": 1.55066688,
"min": 2.47441175824,
"max": 2.58996905324
},
{
"command": "pacquet@main",
"mean": 2.54045971174,
"stddev": 0.025526981104387406,
"median": 2.5302320917400003,
"user": 1.9528166800000002,
"system": 1.5852533799999997,
"min": 2.5159633342400003,
"max": 2.58465360224
},
{
"command": "pnpr@HEAD",
"mean": 1.55519434014,
"stddev": 0.1320417605847444,
"median": 1.5050427827400001,
"user": 1.18025008,
"system": 1.23378248,
"min": 1.41062065524,
"max": 1.75400187924
},
{
"command": "pnpr@main",
"mean": 1.5075149626400002,
"stddev": 0.13046722405983538,
"median": 1.44221352424,
"user": 1.13632328,
"system": 1.15850088,
"min": 1.38737756624,
"max": 1.72002055424
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.50083639374,
"stddev": 0.025626789567056097,
"median": 0.49957439534000003,
"user": 0.6744830599999998,
"system": 0.77512306,
"min": 0.45928866784,
"max": 0.5408742788400001
},
{
"command": "pacquet@main",
"mean": 0.46331124203999996,
"stddev": 0.03007058239662229,
"median": 0.45279071884,
"user": 0.6539168599999999,
"system": 0.7090813600000001,
"min": 0.42933177384,
"max": 0.5198699228400001
},
{
"command": "pnpr@HEAD",
"mean": 0.29376001643999994,
"stddev": 0.01624721023449311,
"median": 0.29698049033999996,
"user": 0.24142086000000001,
"system": 0.57511756,
"min": 0.26313184684,
"max": 0.32225606384
},
{
"command": "pnpr@main",
"mean": 0.29477293374,
"stddev": 0.02921498377477965,
"median": 0.27963519284000005,
"user": 0.24660696,
"system": 0.5464662600000001,
"min": 0.26442858184,
"max": 0.35308252184
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.6363769377400001,
"stddev": 0.03988259784589322,
"median": 1.62253020774,
"user": 0.87430568,
"system": 0.8045715799999998,
"min": 1.59736053524,
"max": 1.71925516424
},
{
"command": "pacquet@main",
"mean": 1.6340292780399999,
"stddev": 0.037175588327080754,
"median": 1.62108018824,
"user": 0.9319438799999998,
"system": 0.82089038,
"min": 1.59777539624,
"max": 1.72335686624
},
{
"command": "pnpr@HEAD",
"mean": 0.28191932434,
"stddev": 0.009918214855228681,
"median": 0.27872630374,
"user": 0.24446868,
"system": 0.52498708,
"min": 0.27089322324000004,
"max": 0.29994809024
},
{
"command": "pnpr@main",
"mean": 0.30987253344,
"stddev": 0.03270802196201745,
"median": 0.29490584374000006,
"user": 0.26391178000000004,
"system": 0.60256848,
"min": 0.27593491924,
"max": 0.38376609624
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.20181637188000004,
"stddev": 0.010836367374522735,
"median": 0.19927605208000002,
"user": 0.20649991333333334,
"system": 0.06962106,
"min": 0.18603533608,
"max": 0.21936189108
},
{
"command": "pacquet@main",
"mean": 0.20866496258000003,
"stddev": 0.01285220767188271,
"median": 0.20496127808,
"user": 0.21946836333333333,
"system": 0.06574597666666666,
"min": 0.18660797308000002,
"max": 0.23274881308
},
{
"command": "pnpr@HEAD",
"mean": 0.09154679537032259,
"stddev": 0.0019410950306655126,
"median": 0.09164238708,
"user": 0.03334229612903226,
"system": 0.014073185161290322,
"min": 0.08796142508,
"max": 0.09680248908
},
{
"command": "pnpr@main",
"mean": 0.09209532692375001,
"stddev": 0.0046096362029495516,
"median": 0.09171457258,
"user": 0.03239362375,
"system": 0.014071966249999996,
"min": 0.08677053608,
"max": 0.10589296208
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.8802180266200001,
"stddev": 0.2618363404020793,
"median": 0.88336584862,
"user": 0.9079872733333334,
"system": 0.16910947333333332,
"min": 0.53304472062,
"max": 1.2318945426199999
},
{
"command": "pacquet@main",
"mean": 0.6615334833977778,
"stddev": 0.12129137935395277,
"median": 0.63451130862,
"user": 0.6760294955555556,
"system": 0.16823947333333333,
"min": 0.42232463062000003,
"max": 0.83508489362
},
{
"command": "pnpm@HEAD",
"mean": 3.0250544286200003,
"stddev": 0.28298266418491685,
"median": 2.87966646562,
"user": 4.661223162222222,
"system": 0.22588036222222221,
"min": 2.7897881356200003,
"max": 3.6252851066200003
}
]
}Scenario: Isolated linker: linked-workspace resolve, hot cache, offline
Confirmation (reversed target order)
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.32876524154000003,
"stddev": 0.01957509092474283,
"median": 0.33041616494000003,
"user": 0.2634423,
"system": 0.12786483999999995,
"min": 0.29250755794,
"max": 0.35261057594
},
{
"command": "pacquet@main",
"mean": 0.2269472151542857,
"stddev": 0.0207539540644709,
"median": 0.22368196544000002,
"user": 0.1821666714285714,
"system": 0.08634212571428569,
"min": 0.20393897194000002,
"max": 0.27655424394
}
],
"confirmation": {
"results": [
{
"command": "pacquet@main",
"mean": 0.2150352901923077,
"stddev": 0.0105221069636107,
"median": 0.2142312995,
"user": 0.16934334769230766,
"system": 0.0881388323076923,
"min": 0.2029897815,
"max": 0.2395771475
},
{
"command": "pacquet@HEAD",
"mean": 0.2134777245,
"stddev": 0.0065415065591330245,
"median": 0.2134377415,
"user": 0.1689716553846154,
"system": 0.08737621692307693,
"min": 0.2022953435,
"max": 0.2221886965
}
]
}
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.601765757120001,
"stddev": 0.19535282171978058,
"median": 4.56909500212,
"user": 1.85455176,
"system": 2.02422474,
"min": 4.40847049262,
"max": 4.87096657062
},
{
"command": "pacquet@main",
"mean": 4.52818976332,
"stddev": 0.13478890695533716,
"median": 4.460532605120001,
"user": 1.77459906,
"system": 2.0090266399999996,
"min": 4.40468071262,
"max": 4.787714089620001
},
{
"command": "pnpr@HEAD",
"mean": 3.5356753774199996,
"stddev": 0.15414343247003273,
"median": 3.48134298262,
"user": 1.64096486,
"system": 1.7834989399999999,
"min": 3.4172875566200003,
"max": 3.83121722962
},
{
"command": "pnpr@main",
"mean": 3.5085594267199993,
"stddev": 0.07577601185118774,
"median": 3.48540417462,
"user": 1.62232186,
"system": 1.8021042399999998,
"min": 3.41022251562,
"max": 3.6276916326200004
}
]
}Scenario: GVS linker: fresh restore, hot cache + hot storeSame install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.15222822248222226,
"stddev": 0.006845121488098054,
"median": 0.15070536276000002,
"user": 0.18632797555555555,
"system": 0.16588645333333332,
"min": 0.14277935576,
"max": 0.16680887876
},
{
"command": "pacquet@main",
"mean": 0.1454944611975,
"stddev": 0.008800009602329616,
"median": 0.14427235226000001,
"user": 0.18378210749999999,
"system": 0.14240261999999998,
"min": 0.12409281376,
"max": 0.16271074076
},
{
"command": "pnpr@HEAD",
"mean": 0.1601005196975,
"stddev": 0.009187591875389178,
"median": 0.15916904626,
"user": 0.1904773575,
"system": 0.14696718250000002,
"min": 0.14796871076,
"max": 0.17915967776
},
{
"command": "pnpr@main",
"mean": 0.1480236719364706,
"stddev": 0.011056838603571335,
"median": 0.15098329476,
"user": 0.1737948905882353,
"system": 0.14162206117647058,
"min": 0.12900057276000002,
"max": 0.16737225976
}
]
} |
Check an ASCII target with a Unicode NODE_PATH so Linux coverage exercises the encoding switch. Verify ordering, percent escaping, and CRLF output.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
The Written by an agent (Claude Code, claude-opus-5-5). |
Windows PowerShell 5.1 decodes a script that has no byte order mark using the ANSI code page, so non-ASCII text in a PowerShell shim, such as a bin path under a directory named 工具, reaches Node.js corrupted and the command fails with MODULE_NOT_FOUND. PowerShell 7 reads such scripts as UTF-8, so only Windows PowerShell 5.1 is affected. Start the .ps1 text with a UTF-8 BOM when it contains non-ASCII characters, in both the Rust and the TypeScript generators, the way pnpm#16205 switches .cmd shims to UTF-8. ASCII-only shims stay byte-for-byte unchanged. The Rust generator runs only on Windows, and the TypeScript one adds the BOM only there, because on other platforms the shebang has to stay at the start of the file. Add regressions that run a shim for a Unicode target under Windows PowerShell 5.1 and check its arguments and exit status, and check that only non-ASCII shims get the BOM. Closes pnpm#16217 Co-Authored-By: Claude Opus 5.5 <[email protected]>
) Windows PowerShell 5.1 decodes a script that has no byte order mark using the ANSI code page, so non-ASCII text in a PowerShell shim, such as a bin path under a directory named 工具, reaches Node.js corrupted and the command fails with MODULE_NOT_FOUND. PowerShell 7 reads such scripts as UTF-8, so only Windows PowerShell 5.1 is affected. Start the .ps1 text with a UTF-8 BOM when it contains non-ASCII characters, in both the Rust and the TypeScript generators, the way #16205 switches .cmd shims to UTF-8. ASCII-only shims stay byte-for-byte unchanged. Both generators add the BOM only on Windows, because on other platforms the shebang has to stay at the start of the file. Add regressions that run a shim for a Unicode target under Windows PowerShell 5.1 and check its arguments and exit status, check that only non-ASCII shims get the BOM, and check that a non-ASCII shim written on POSIX keeps its shebang at the start. Closes #16217 --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Zoltan Kochan <[email protected]>
Summary
Windows CMD launchers are written as UTF-8, but CMD decodes them using the active console code page. A relative target such as
工具/cli.jsis corrupted under legacy code pages, causing the installed tool to fail withMODULE_NOT_FOUND.Both CMD generators now switch to UTF-8 when their generated text contains non-ASCII characters. They restore the caller's code page and preserve the tool's exit status. ASCII-only launcher output is unchanged. The patch is limited to these generators, matching regression tests, and a changeset; it adds no dependencies.
close #6999
Squash Commit Body
Validation
pnpm --filter @pnpm/bins.cmd-shim test: 82 passed.pnpm test:rust -p pnpm-cmd-shim: 127 passed, 5 platform-specific tests skipped on Windows.NODE_PATH; it fails on the unfixed generator and runs in the Linux coverage job.pnpm-cmd-shim, including its tests.RUSTDOCFLAGS=-D warnings.The Windows pre-push strict dylint check fails in the unchanged
pnpm-executorfunctionshort_path(pnpm/crates/executor/src/script_working_dir.rs:85): 43 lines exceed its limit of 40. I reproduced the failure separately and verified this file is byte-for-byte identical to current main. No unrelated executor changes are included. The CI dylint job runs on Linux, where this Windows-only function is excluded. After completing all checks and recording this failure, I published withgit push --no-verify, the exception explicitly offered bypnpm/scripts/pre-push-rust.sh. Commit hooks ran normally.Checklist
Written by an agent (Codex, GPT-6). This PR was written with the help of an AI agent.
Summary by CodeRabbit