Repository navigation
Conversation
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? |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughLockfile reads now follow symlinks for ChangesSymlinked lockfile handling
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant pnpmCLI
participant lockfileReader
participant lockfileWriter
participant filesystem
pnpmCLI->>lockfileReader: read pnpm-lock.yaml
lockfileReader->>filesystem: follow symlink and load content
filesystem-->>lockfileReader: lockfile content
pnpmCLI->>lockfileWriter: save computed lockfile
lockfileWriter->>lockfileWriter: compare resulting bytes
alt content unchanged
lockfileWriter-->>pnpmCLI: skip write
else content changed
lockfileWriter->>filesystem: reject symlink or atomically replace regular file
filesystem-->>lockfileWriter: write result
lockfileWriter-->>pnpmCLI: save result
end
Possibly related issues
Suggested labels: Suggested reviewers: ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Confidence Score: 5/5Safe to merge — reads following symlinks introduces no new attack surface since lockfile content is untrusted regardless, and changed-content writes still refuse symlinks via a guard that rename() semantics make impossible to bypass. Both stacks implement the same logic with matching behavior, the idempotency comparison is correct for LF and CRLF files alike, the double symlink guard in writeWantedLockfileAtomic is sound, and the PR includes integration-level tests that reproduce the exact reported failure and fail without the fix. No files require special attention. Reviews (8): Last reviewed commit: "docs(lockfile): let the tests carry the ..." | Re-trigger Greptile |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pnpm11/lockfile/fs/src/yamlDocuments.ts (1)
21-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the unused
filePathparameter from the internal helper.The
filePathparameter is passed intostreamReadFirstYamlDocumentWithOpen, but it is not used anywhere within the function body. The path is already securely captured by theopenFileclosure from the outer scope. Removing it simplifies the helper's signature.♻️ Proposed refactor
export async function streamReadFirstYamlDocument (filePath: string, readBufferSize = READ_BUFFER_SIZE): Promise<string | null> { - return streamReadFirstYamlDocumentWithOpen(filePath, readBufferSize, () => open(filePath, constants.O_RDONLY)) + return streamReadFirstYamlDocumentWithOpen(readBufferSize, () => open(filePath, constants.O_RDONLY)) } export async function streamReadFirstYamlDocumentNoFollow (filePath: string, readBufferSize = READ_BUFFER_SIZE): Promise<string | null> { - return streamReadFirstYamlDocumentWithOpen(filePath, readBufferSize, () => openLockfileNoFollow(filePath)) + return streamReadFirstYamlDocumentWithOpen(readBufferSize, () => openLockfileNoFollow(filePath)) } -async function streamReadFirstYamlDocumentWithOpen (filePath: string, readBufferSize: number, openFile: () => Promise<FileHandle>): Promise<string | null> { +async function streamReadFirstYamlDocumentWithOpen (readBufferSize: number, openFile: () => Promise<FileHandle>): Promise<string | null> { let fileHandle: FileHandle | undefined🤖 Prompt for 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. In `@pnpm11/lockfile/fs/src/yamlDocuments.ts` around lines 21 - 34, Remove the unused filePath parameter from streamReadFirstYamlDocumentWithOpen and update both streamReadFirstYamlDocument and streamReadFirstYamlDocumentNoFollow call sites to pass only readBufferSize and the openFile callback.
🤖 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.
Nitpick comments:
In `@pnpm11/lockfile/fs/src/yamlDocuments.ts`:
- Around line 21-34: Remove the unused filePath parameter from
streamReadFirstYamlDocumentWithOpen and update both streamReadFirstYamlDocument
and streamReadFirstYamlDocumentNoFollow call sites to pass only readBufferSize
and the openFile callback.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ee5228b2-3228-4c69-9536-d319be1ca685
📒 Files selected for processing (7)
.changeset/allow-symlinked-lockfile-reads.mdpnpm/crates/lockfile/src/env_lockfile.rspnpm/crates/lockfile/src/env_lockfile/tests.rspnpm11/lockfile/fs/src/write.tspnpm11/lockfile/fs/src/yamlDocuments.tspnpm11/lockfile/fs/test/envLockfile.test.tspnpm11/lockfile/fs/test/yamlDocuments.test.ts
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13075 +/- ##
==========================================
- Coverage 85.59% 85.49% -0.11%
==========================================
Files 499 501 +2
Lines 79945 80508 +563
==========================================
+ Hits 68431 68831 +400
- Misses 11514 11677 +163 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Commit: Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.5583370798,
"stddev": 0.18955050430998874,
"median": 2.4522256571999996,
"user": 1.67801112,
"system": 1.3683564999999998,
"min": 2.3983393157,
"max": 2.8566800747,
"times": [
2.4284927787,
2.4130195117,
2.5552579167,
2.8566800747,
2.8289994427,
2.4759585357,
2.4117052477,
2.3983393157,
2.4280163227,
2.7869016517
]
},
{
"command": "pacquet@main",
"mean": 2.4907915808999994,
"stddev": 0.13561195877200277,
"median": 2.4444739686999997,
"user": 1.64966382,
"system": 1.4015752,
"min": 2.3376497367,
"max": 2.7622717727,
"times": [
2.7622717727,
2.5112157117000002,
2.4034798897,
2.3376497367,
2.4344127007,
2.3986284187,
2.4711390537,
2.7001705876999997,
2.4363506867,
2.4525972507
]
},
{
"command": "pnpr@HEAD",
"mean": 1.5614867943,
"stddev": 0.16511785712532362,
"median": 1.5395933412,
"user": 1.1869633199999998,
"system": 1.2201746,
"min": 1.3614348836999999,
"max": 1.8109792697,
"times": [
1.7538984917,
1.8109792697,
1.5877380127,
1.4309023406999999,
1.3712460257,
1.7380009947000001,
1.4490371576999999,
1.4914486697,
1.3614348836999999,
1.6201820967
]
},
{
"command": "pnpr@main",
"mean": 1.6267049795,
"stddev": 0.19690466247452879,
"median": 1.6149781092,
"user": 1.34161872,
"system": 1.409887,
"min": 1.3819812276999999,
"max": 1.9122585317,
"times": [
1.7933220817,
1.6269630476999999,
1.6029931707,
1.5894174426999998,
1.3819812276999999,
1.9122585317,
1.8651416447,
1.3948420437,
1.3835738777,
1.7165567267
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.28555452588,
"stddev": 0.02265676537477688,
"median": 0.27743723838,
"user": 0.24335069999999998,
"system": 0.55904712,
"min": 0.26383184088,
"max": 0.33406477488,
"times": [
0.30466635888000004,
0.27180728788,
0.27552191888,
0.26641644888,
0.28602196188,
0.26781036688000004,
0.26383184088,
0.30605174188,
0.33406477488,
0.27935255788
]
},
{
"command": "pacquet@main",
"mean": 0.29515050668000004,
"stddev": 0.05197603887696918,
"median": 0.28232157238,
"user": 0.26519339999999997,
"system": 0.7772986199999999,
"min": 0.22152748088000002,
"max": 0.39436537588000004,
"times": [
0.22152748088000002,
0.27488633488,
0.24469506788,
0.33890380988,
0.26131696488,
0.30786153488,
0.39436537588000004,
0.34412855888000005,
0.28975680988,
0.27406312888
]
},
{
"command": "pnpr@HEAD",
"mean": 0.3196837014800001,
"stddev": 0.03191558825278512,
"median": 0.31500009888,
"user": 0.25991050000000004,
"system": 0.5895217199999999,
"min": 0.27908657888,
"max": 0.39132372988,
"times": [
0.39132372988,
0.31843789888,
0.34869077288,
0.33286578188000004,
0.31805393788,
0.31194625988,
0.29887531588,
0.29818062088,
0.29937611788,
0.27908657888
]
},
{
"command": "pnpr@main",
"mean": 0.26721680898,
"stddev": 0.031830984463567566,
"median": 0.25771423888,
"user": 0.2326756,
"system": 0.6565432199999999,
"min": 0.23925333188,
"max": 0.34287805888,
"times": [
0.24351079288000002,
0.24425690388000001,
0.25867070088,
0.25675777688,
0.23925333188,
0.27925700788,
0.25133799188,
0.29690813888,
0.34287805888,
0.25933738588
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.87295957826,
"stddev": 0.12083133190964608,
"median": 2.86423707606,
"user": 2.00128082,
"system": 1.5486594,
"min": 2.7265560485600004,
"max": 3.0997822465600002,
"times": [
2.8278643525600002,
2.8608841345600005,
2.86759001756,
3.0997822465600002,
3.0375243475600002,
2.90370103956,
2.8917058675600003,
2.73422288656,
2.7265560485600004,
2.77976484156
]
},
{
"command": "pacquet@main",
"mean": 2.8992348990600005,
"stddev": 0.13283636146469427,
"median": 2.86201180906,
"user": 2.0188763199999995,
"system": 1.5337503,
"min": 2.7546364585600003,
"max": 3.1904429595600003,
"times": [
2.8189343705600005,
2.7800304615600004,
2.8183043475600003,
2.97556909656,
2.8182528805600002,
2.9050892475600003,
2.7546364585600003,
3.1904429595600003,
3.01390676356,
2.91718240456
]
},
{
"command": "pnpr@HEAD",
"mean": 1.59858092936,
"stddev": 0.14059764858371218,
"median": 1.60018715556,
"user": 1.31990682,
"system": 1.4884903999999999,
"min": 1.42189635156,
"max": 1.81279559156,
"times": [
1.47940768056,
1.6044244485599999,
1.6168744555599999,
1.81279559156,
1.5959498625600002,
1.49492490056,
1.70588094156,
1.42189635156,
1.45023147156,
1.8034235895600002
]
},
{
"command": "pnpr@main",
"mean": 1.6734244532600002,
"stddev": 0.1842550285223946,
"median": 1.67698522906,
"user": 1.26548402,
"system": 1.4425801,
"min": 1.44123855156,
"max": 1.90943856856,
"times": [
1.76212234356,
1.48790763356,
1.90943856856,
1.49945031556,
1.89497144056,
1.44123855156,
1.82615687956,
1.51224942756,
1.80886125756,
1.59184811456
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.76198860306,
"stddev": 0.04605735528625471,
"median": 0.7725024713599999,
"user": 0.99546938,
"system": 0.7925347400000001,
"min": 0.68743621536,
"max": 0.85312175936,
"times": [
0.75127461436,
0.7218655873600001,
0.85312175936,
0.77634241236,
0.78687130936,
0.68743621536,
0.7165811453600001,
0.76941023536,
0.77559470736,
0.78138804436
]
},
{
"command": "pacquet@main",
"mean": 0.64105751676,
"stddev": 0.04076523822262947,
"median": 0.63567445136,
"user": 0.8167391799999999,
"system": 0.6927165399999999,
"min": 0.59345457936,
"max": 0.7063430753600001,
"times": [
0.6733043173600001,
0.67874964136,
0.7063430753600001,
0.67406654136,
0.65552373336,
0.61582516936,
0.6067377323600001,
0.60275508736,
0.60381529036,
0.59345457936
]
},
{
"command": "pnpr@HEAD",
"mean": 0.31522321725999997,
"stddev": 0.03235326195030757,
"median": 0.30790322086,
"user": 0.21389718000000002,
"system": 0.5445565400000001,
"min": 0.28721950736,
"max": 0.38947377736,
"times": [
0.33449726336,
0.38947377736,
0.34183041336,
0.31117923236,
0.31345188436,
0.30462720936,
0.29069856435999997,
0.28925623336,
0.28999808736,
0.28721950736
]
},
{
"command": "pnpr@main",
"mean": 0.25327107886,
"stddev": 0.01031098803849034,
"median": 0.25219093336,
"user": 0.19357988,
"system": 0.5200199400000001,
"min": 0.23851446736,
"max": 0.26989434836,
"times": [
0.23851446736,
0.24849563436000002,
0.24015303636000002,
0.25917394235999996,
0.25102822335999997,
0.24802572236,
0.25335364336,
0.26989434836,
0.26687485435999997,
0.25719691635999997
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.0427905655,
"stddev": 0.06501677778579305,
"median": 2.0275477083,
"user": 1.2076832199999996,
"system": 0.8774343799999998,
"min": 1.9755673393000002,
"max": 2.1578429013,
"times": [
1.9755673393000002,
2.0509619443,
2.0041334723,
2.0789795762999996,
1.9935593303,
2.0015279553,
2.1578429013,
2.1365681302999997,
1.9764137103000001,
2.0523512953
]
},
{
"command": "pacquet@main",
"mean": 1.9814589726000005,
"stddev": 0.01986340874983789,
"median": 1.9835196283000003,
"user": 1.12408912,
"system": 0.79571948,
"min": 1.9397545073000002,
"max": 2.0040991973,
"times": [
1.9981016773,
1.9975838533,
1.9706341483,
1.9864276783,
1.9984557413000001,
1.9740850623000001,
2.0040991973,
1.9648362823,
1.9806115783000002,
1.9397545073000002
]
},
{
"command": "pnpr@HEAD",
"mean": 0.34926832790000006,
"stddev": 0.0424558676650878,
"median": 0.3437646828,
"user": 0.23899261999999996,
"system": 0.61676988,
"min": 0.3018665603,
"max": 0.4485532223,
"times": [
0.3723855543,
0.4485532223,
0.3671819453,
0.3573408213,
0.3478021453,
0.3305590513,
0.3397272203,
0.3239943853,
0.3018665603,
0.3032723733
]
},
{
"command": "pnpr@main",
"mean": 0.26632023709999997,
"stddev": 0.01418307033404827,
"median": 0.26734183479999996,
"user": 0.19511662,
"system": 0.5575638800000001,
"min": 0.24495824630000002,
"max": 0.2893397793,
"times": [
0.2701343873,
0.2585613293,
0.2750086273,
0.26454928229999997,
0.2736386833,
0.24838182930000002,
0.24495824630000002,
0.2575349503,
0.2893397793,
0.2810952563
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.40449552850000003,
"stddev": 0.06473679041624969,
"median": 0.3751130065,
"user": 0.39618916000000004,
"system": 0.06588575999999999,
"min": 0.3369437665,
"max": 0.5215060755,
"times": [
0.41069929150000006,
0.37209814150000003,
0.3369437665,
0.3468267695,
0.37812787150000005,
0.36918371350000007,
0.35476723150000006,
0.47874991650000004,
0.47605250750000005,
0.5215060755
]
},
{
"command": "pacquet@main",
"mean": 0.46305249569999996,
"stddev": 0.060351107898656865,
"median": 0.4328995925000001,
"user": 0.45223506,
"system": 0.07647295999999999,
"min": 0.41050186150000006,
"max": 0.5873831445000001,
"times": [
0.5873831445000001,
0.5248976485000001,
0.41050186150000006,
0.5197627695000001,
0.46313536150000006,
0.4163971705,
0.43683385650000006,
0.41896591650000004,
0.4289653285000001,
0.42368189950000007
]
},
{
"command": "pnpr@HEAD",
"mean": 0.08442840362121212,
"stddev": 0.002668504042999616,
"median": 0.0842480275,
"user": 0.016462547878787884,
"system": 0.010946520606060606,
"min": 0.0808791865,
"max": 0.0932959505,
"times": [
0.0857925395,
0.0821890875,
0.0883042795,
0.0869346255,
0.0837074215,
0.0866641575,
0.0831994365,
0.0849673895,
0.08675566950000001,
0.0836369985,
0.0827287615,
0.0816886675,
0.0860126625,
0.0842480275,
0.0845455265,
0.0827106575,
0.0867179595,
0.0932959505,
0.0818589975,
0.0820295375,
0.0808791865,
0.0817095975,
0.0875171705,
0.0860374495,
0.0811535315,
0.0858902035,
0.0824189095,
0.0855597925,
0.0860513255,
0.0817673955,
0.0817496525,
0.0854345865,
0.08198016550000001
]
},
{
"command": "pnpr@main",
"mean": 0.0829690368888889,
"stddev": 0.002973515471398451,
"median": 0.08228869550000001,
"user": 0.016910065555555555,
"system": 0.009177866111111111,
"min": 0.0777785405,
"max": 0.0918594605,
"times": [
0.0790974065,
0.0777785405,
0.0808266275,
0.0821384325,
0.0821515475,
0.0819888815,
0.08224677650000001,
0.0876871805,
0.0823306145,
0.0793277415,
0.0826317905,
0.0818183405,
0.0823592875,
0.0802114215,
0.0828065685,
0.0852614315,
0.0805023985,
0.0809845445,
0.0872819285,
0.0918594605,
0.0868768575,
0.0850497635,
0.0799034815,
0.0813450215,
0.0806205795,
0.0850909715,
0.0837307145,
0.0806911325,
0.0807220705,
0.0830160615,
0.0828923595,
0.0866754795,
0.0883961925,
0.0816864235,
0.0846942555,
0.0842030425
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.704427422139999,
"stddev": 0.09330976997549684,
"median": 4.717729459939999,
"user": 2.5164295000000005,
"system": 1.8716117199999995,
"min": 4.527536950439999,
"max": 4.864808238439999,
"times": [
4.864808238439999,
4.773917701439999,
4.714333788439999,
4.69586949844,
4.527536950439999,
4.712876179439999,
4.72970545744,
4.722307563439999,
4.58179371244,
4.72112513144
]
},
{
"command": "pacquet@main",
"mean": 4.731916929839999,
"stddev": 0.1510376268904435,
"median": 4.75160470044,
"user": 2.1417523,
"system": 1.6477613199999996,
"min": 4.536000104439999,
"max": 4.94615876644,
"times": [
4.94615876644,
4.894529061439999,
4.54663416844,
4.8071821544399995,
4.69602724644,
4.8320693734399995,
4.56935286244,
4.654859451439999,
4.83635610944,
4.536000104439999
]
},
{
"command": "pnpr@HEAD",
"mean": 3.6536818589399997,
"stddev": 0.11072966351968622,
"median": 3.61030846494,
"user": 1.6512562,
"system": 1.6524283199999998,
"min": 3.56395542644,
"max": 3.8866968394400003,
"times": [
3.59267387544,
3.62086919144,
3.56395542644,
3.61404626944,
3.6110075584400003,
3.60960937144,
3.6016846994400002,
3.8866968394400003,
3.83401864444,
3.60225671344
]
},
{
"command": "pnpr@main",
"mean": 3.5808876897400004,
"stddev": 0.12956436359124116,
"median": 3.5458581584399997,
"user": 1.2985049,
"system": 1.3431429199999998,
"min": 3.45935949444,
"max": 3.89274695744,
"times": [
3.58643476144,
3.6550332944400004,
3.52066409044,
3.64916529644,
3.48067464044,
3.51905024744,
3.45935949444,
3.57105222644,
3.89274695744,
3.47469588844
]
}
]
} |
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1.
|
PR Code Suggestions ✨Latest suggestions up to d2a62ae Warning
Previous suggestionsSuggestions up to commit 84d7acb
Suggestions up to commit d2a05cc
Suggestions
|
|||||||||||||||||||||||||||||||||||||||
|
| Branch | pr/13075 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 1,598.58 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 349.27 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 315.22 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 84.43 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,561.49 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,653.68 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 319.68 ms |
Allowing symlinked reads did not fix #13073. The reported `--frozen-lockfile --lockfile-only` install fails on the *write*: tryFrozenInstall rewrites an already up-to-date pnpm-lock.yaml, and the write path refuses a symlink before it writes. Skip a byte-identical rewrite instead. An up-to-date install -- every frozen run -- no longer touches the lockfile at all, so one staged as a symlink (Bazel, Nix) installs cleanly, while a write that changes bytes still refuses the symlink: write-file-atomic resolves the target with realpath, so writing through one redirects onto any file the user can write. Reading through a symlink stays allowed. That guard was never justified on its own -- it arrived as a "consider this too" aside alongside the write fix in #12821 -- and planting the symlink already requires write access to the working tree. Close the same clobber in pacquet: save_value_to_path wrote the wanted lockfile with fs::write, which follows symlinks and had no guard. It now refuses a symlinked lockfile and writes atomically, carrying the target's mode across the rename and flushing before it, matching write-file-atomic. Share the symlink guard between both write paths rather than duplicate it. Add install-level regression coverage for the reported command; the existing unit tests passed while the bug remained.
|
Thanks — all four findings were valid and are fixed in b12578d. Since that review the PR also grew well beyond its original scope, so here's what changed and why. The findings
Both error strings are reachable only from write paths now, so the wording is accurate. The bigger issue: this PR did not fix #13073Worth flagging, because the review confidence score rested on the read/write boundary being the whole story. It wasn't. Building the bundle and running the issue's exact repro still failed:
The fix is to skip a byte-identical rewrite: an up-to-date install now writes nothing at all, so the guard is never reached over a write that changes no bytes. Genuine writes through a symlink are still refused. A vulnerability found along the waypacquet's On test coverageThe most useful lesson here: this PR's original tests all passed while the reported command stayed broken. They covered the read path in isolation and never exercised an install. Coverage is now at the level that actually reproduces the issue ( Written by an agent (Claude Code, claude-opus-4-8). |
|
Code review by qodo was updated up to the latest commit b12578d |
PR Code Suggestions ✨Warning
|
||||||||||||
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
pnpm/crates/lockfile/src/save_lockfile/tests.rs (1)
455-470: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd a CRLF regression case alongside this LF-only env-document test.
This test hard-codes
env_docwith only\nline endings, so it wouldn't catch the CRLF-comparison bug flagged onsave_value_to_path(lines 87-98 ofsave_lockfile.rs): ifexistingon disk used CRLF anywhere, the unchanged-write check would spuriously fail. A companion test using\r\nin the prependedenv_doc/existing content would pin this behavior down once fixed.🤖 Prompt for 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. In `@pnpm/crates/lockfile/src/save_lockfile/tests.rs` around lines 455 - 470, Add a companion regression test next to save_leaves_an_unchanged_lockfile_with_env_document_untouched using \r\n line endings throughout the prepended env_doc and existing lockfile content. Reuse the same save_to_path flow and assert the file modification time remains unchanged on the second save, covering the CRLF comparison behavior in save_value_to_path.
🤖 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 `@pnpm11/lockfile/fs/src/write.ts`:
- Around line 95-108: Normalize the existing lockfile content from CRLF to LF
once in writeLockfileDoc before both extractEnvDocument and the existing ===
content comparison, so unchanged files skip writing. Apply the same
normalization in pnpm/crates/lockfile/src/save_lockfile.rs within
save_value_to_path before extract_env_document and the existing.as_deref()
comparison; both sites must preserve the existing symlink-protection behavior.
In `@pnpm11/lockfile/fs/src/yamlDocuments.ts`:
- Around line 137-139: The symlinked-lockfile refusal message has inconsistent
capitalization between implementations. Update the message in
pnpm11/lockfile/fs/src/yamlDocuments.ts lines 137-139 and
pnpm/crates/lockfile/src/save_lockfile.rs lines 117-121 so
symlinkedLockfileError and the Rust save-lockfile path emit exactly matching
text, preserving the existing error code and behavior.
- Around line 73-86: Update readLockfileToString to remove a leading UTF-8 BOM
from the string returned by readFile, matching streamReadFirstYamlDocument
before extractEnvDocument processes it. Preserve the existing ENOENT-to-null
behavior and rethrow all other errors.
In `@pnpm11/lockfile/fs/test/write.test.ts`:
- Around line 452-461: Strengthen the no-op assertion in the test
“writeWantedLockfile() accepts a symlinked lockfile when nothing changes” by
recording the symlink target’s content and modification time before the second
write, then asserting both remain unchanged afterward. Keep the existing
symlink-preservation assertion and follow the analogous unchanged-lockfile tests
for the comparison approach.
---
Nitpick comments:
In `@pnpm/crates/lockfile/src/save_lockfile/tests.rs`:
- Around line 455-470: Add a companion regression test next to
save_leaves_an_unchanged_lockfile_with_env_document_untouched using \r\n line
endings throughout the prepended env_doc and existing lockfile content. Reuse
the same save_to_path flow and assert the file modification time remains
unchanged on the second save, covering the CRLF comparison behavior in
save_value_to_path.
🪄 Autofix (Beta)
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: CHILL
Plan: Pro Plus
Run ID: 500b843d-c728-4d37-84f4-01669da54fc9
📒 Files selected for processing (9)
.changeset/allow-symlinked-lockfile-reads.mdpnpm/crates/lockfile/src/env_lockfile.rspnpm/crates/lockfile/src/save_lockfile.rspnpm/crates/lockfile/src/save_lockfile/tests.rspnpm11/installing/deps-installer/test/lockfile.tspnpm11/lockfile/fs/src/write.tspnpm11/lockfile/fs/src/yamlDocuments.tspnpm11/lockfile/fs/test/write.test.tspnpm11/lockfile/fs/test/yamlDocuments.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- .changeset/allow-symlinked-lockfile-reads.md
- pnpm/crates/lockfile/src/env_lockfile.rs
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pnpm11/lockfile/fs/test/write.test.ts (2)
468-469: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
WANTED_LOCKFILEconstant for consistency.The subsequent test uses
WANTED_LOCKFILEwhen definingrealLockfile. Consider using it here as well for consistency.♻️ Proposed refactor
const realDir = temporaryDirectory() - const realLockfile = path.join(realDir, 'pnpm-lock.yaml') + const realLockfile = path.join(realDir, WANTED_LOCKFILE)🤖 Prompt for 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. In `@pnpm11/lockfile/fs/test/write.test.ts` around lines 468 - 469, Update the realLockfile definition in the affected test to join realDir with the existing WANTED_LOCKFILE constant instead of duplicating the literal lockfile name, preserving the current temporary-directory setup and path behavior.
491-493: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueAssert that the symlink is preserved.
Similar to the previous test, ensure that the symlink itself was not silently replaced by a regular file during the execution.
✅ Proposed refactor
await expect(writeWantedLockfile(projectPath, upToDateLockfile)).resolves.toBeTruthy() + expect(fs.lstatSync(path.join(projectPath, WANTED_LOCKFILE)).isSymbolicLink()).toBe(true) expect(fs.readFileSync(realLockfile, 'utf8')).toBe(crlfContent) expect(fs.statSync(realLockfile).mtimeMs).toBe(mtimeBefore)🤖 Prompt for 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. In `@pnpm11/lockfile/fs/test/write.test.ts` around lines 491 - 493, Extend the test around writeWantedLockfile to verify that realLockfile remains a symbolic link after the write, using the filesystem metadata or symlink assertion already established by the preceding test. Keep the existing content and mtime checks unchanged.
🤖 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.
Nitpick comments:
In `@pnpm11/lockfile/fs/test/write.test.ts`:
- Around line 468-469: Update the realLockfile definition in the affected test
to join realDir with the existing WANTED_LOCKFILE constant instead of
duplicating the literal lockfile name, preserving the current
temporary-directory setup and path behavior.
- Around line 491-493: Extend the test around writeWantedLockfile to verify that
realLockfile remains a symbolic link after the write, using the filesystem
metadata or symlink assertion already established by the preceding test. Keep
the existing content and mtime checks unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 42f81d41-a39f-4d31-bb11-2275a0f273ef
📒 Files selected for processing (6)
pnpm/crates/lockfile/src/save_lockfile.rspnpm/crates/lockfile/src/save_lockfile/tests.rspnpm11/lockfile/fs/src/write.tspnpm11/lockfile/fs/src/yamlDocuments.tspnpm11/lockfile/fs/test/write.test.tspnpm11/lockfile/fs/test/yamlDocuments.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- pnpm/crates/lockfile/src/save_lockfile/tests.rs
- pnpm/crates/lockfile/src/save_lockfile.rs
- pnpm11/lockfile/fs/src/write.ts
- pnpm11/lockfile/fs/src/yamlDocuments.ts
Replacing pnpm-lock.yaml through a temp file and rename drops what the previous write-file-atomic call preserved: it stats the target and restores its owner onto the replacement. Without that, an install running as another user -- root in a container over a bind-mounted repo is the common case -- leaves the lockfile owned by root, and its owner can no longer write it. Carry the target's ownership across, tolerating an ownership change we lack the privileges for exactly as write-file-atomic does: the file simply stays ours rather than failing the install. Cover the mode against a umask that would strip it, which the create-time mode argument alone does not survive.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pnpm11/lockfile/fs/test/write.test.ts (1)
559-564: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueStrengthen the temp-file cleanup test to cover the update path.
The current test successfully verifies that temporary files are cleaned up during the initial lockfile creation. To ensure they are also cleaned up during a lockfile rewrite (which executes additional
chownandchmodlogic), consider triggering an update by callingwriteWantedLockfileagain with changed content before the assertion.♻️ Proposed strengthening
testOnNonWindows('writeWantedLockfile() leaves no temp file behind', async () => { const projectPath = temporaryDirectory() await writeWantedLockfile(projectPath, upToDateLockfile) + await writeWantedLockfile(projectPath, changedLockfile) expect(fs.readdirSync(projectPath)).toStrictEqual([WANTED_LOCKFILE]) })🤖 Prompt for 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. In `@pnpm11/lockfile/fs/test/write.test.ts` around lines 559 - 564, Strengthen the test “writeWantedLockfile() leaves no temp file behind” by calling writeWantedLockfile a second time with changed lockfile content before inspecting the directory. Keep the final readdirSync assertion verifying that only WANTED_LOCKFILE remains, covering cleanup during the rewrite path and its chown/chmod logic.
🤖 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.
Nitpick comments:
In `@pnpm11/lockfile/fs/test/write.test.ts`:
- Around line 559-564: Strengthen the test “writeWantedLockfile() leaves no temp
file behind” by calling writeWantedLockfile a second time with changed lockfile
content before inspecting the directory. Keep the final readdirSync assertion
verifying that only WANTED_LOCKFILE remains, covering cleanup during the rewrite
path and its chown/chmod logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 668508eb-0b96-40ab-b755-c94778799ebb
📒 Files selected for processing (3)
pnpm11/lockfile/fs/src/write.tspnpm11/lockfile/fs/src/yamlDocuments.tspnpm11/lockfile/fs/test/write.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- pnpm11/lockfile/fs/src/write.ts
- pnpm11/lockfile/fs/src/yamlDocuments.ts
…nfig A repository commits the lockfile symlink, so it decides where the link points. If its pnpm-workspace.yaml could also allow writing through the link, a cloned repository could overwrite any file the user can write, even with scripts disabled. The refusal kept by #13075 exists to prevent exactly that. Treat the setting as machine-only, like tools and ci: it is honored from the global config.yaml and PNPM_CONFIG_ALLOW_SYMLINKED_LOCKFILE, and dropped from pnpm-workspace.yaml and config dependency entries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nfig A repository commits the lockfile symlink, so it decides where the link points. If its pnpm-workspace.yaml could also allow writing through the link, a cloned repository could overwrite any file the user can write, even with scripts disabled. The refusal kept by #13075 exists to prevent exactly that. Treat the setting as machine-only, like tools and ci: it is honored from the global config.yaml and PNPM_CONFIG_ALLOW_SYMLINKED_LOCKFILE, and dropped from pnpm-workspace.yaml and config dependency entries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nfig A repository commits the lockfile symlink, so it decides where the link points. If its pnpm-workspace.yaml could also allow writing through the link, a cloned repository could overwrite any file the user can write, even with scripts disabled. The refusal kept by #13075 exists to prevent exactly that. Treat the setting as machine-only, like tools and ci: it is honored from the global config.yaml and PNPM_CONFIG_ALLOW_SYMLINKED_LOCKFILE, and dropped from pnpm-workspace.yaml and config dependency entries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
pnpm installfails withERR_PNPM_LOCKFILE_IS_SYMLINKwhenpnpm-lock.yamlis a symlink, breaking build sandboxes (Bazel, Nix) that stage the lockfile that way. This restores those workflows while keeping the protection that matters.Two halves, from opposite directions:
readWantedLockfilereads the same file with a plainreadFileand has always followed the link, so refusing it on the env-document read only broke sandboxes. A hostile repo can commit a hostile lockfile as a plain file regardless — lockfile content is untrusted either way. The guard arrived as a "consider this too" aside alongside the genuine write fix in fix: switch pacquet to project package manager version #12821.tryFrozenInstallrewrites an already up-to-datepnpm-lock.yaml, so--frozen-lockfile --lockfile-onlydied on the write, not the read. Skipping a byte-identical rewrite means a frozen install never writes at all — and it's a small win for every frozen install, symlink or not.Writing a changed lockfile through a symlink is still refused:
write-file-atomicresolves the target withrealpath, so writing through one redirects onto any file the user can write.The same clobber is now closed in pacquet, where
save_value_to_pathwrote the wanted lockfile withfs::write— following symlinks, with no guard at all. It now refuses a symlinked lockfile and writes atomically.Fixes #13073
Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Notes for reviewers
Refusing to read or write symlinked lockfile→Refusing to write symlinked lockfile, since only writes refuse now.ERR_PNPM_LOCKFILE_IS_SYMLINKis unchanged, but it is a released string that tooling could match on.fs::write. The shared writer carries the target's mode across the rename and flushes before it —fs::writetruncated in place and kept the mode, so a naive rename would have silently resetpnpm-lock.yamlto the umask default. Both mirrorwrite-file-atomic. One consequence of rename semantics: writing a read-only lockfile now succeeds, as it already does in the TypeScript CLI.frozen lockfile-only install succeeds when pnpm-lock.yaml is a symlinkreproduces the issue and fails without this change. Atomicity itself is not directly unit-testable; the write now goes through the writer that already has error-path and temp-cleanup coverage.Written by an agent (Claude Code, claude-opus-4-8).
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by CodeRabbit
pnpm-lock.yamlfiles no longer fail to read, including--frozen-lockfileinstalls when no lockfile changes are required.