Repository navigation
test(pacquet): move module-level shared-mutable test statics into per-test-local state - #13256
Conversation
…-test-local state pacquet's dependency-injection convention (CODE_STYLE_GUIDE.md, "Dependency injection for tests", principle 3) keeps a stateful test fake's state in an interior-mutable static declared inside each `#[test]` body, so tests get independent buffers and never race on it. Several test modules still hoisted such state to module scope (a `thread_local!` block or a column-0 static), where it was shared and reconfigured across tests. Move each into the per-test-local form. Where a fake is reused across many tests, a module-local macro expands the fn-local state at the top of each test body, mirroring the `web_auth_fake!` macro from pacquet-network-web-auth-testing: - network-web-auth/poll_for_web_auth_token: `poll_fake!` (TIME, SLEEP_BEHAVIOR, SLEEPS, FETCH plus the Clock/Sleep/WebAuthFetch fake). - network-web-auth/prompt_browser_open: `browser_fake!` (STDIN_TTY, LISTEN_OUTCOME, OPEN_OUTCOME, ... plus the StdinIsTty/OpenUrl/EnterKeyListener fake); the tests that poked the thread-locals directly now go through `set_stdin_tty` / `set_listen_outcome` / `set_open_outcome` helpers. - config: `fake_env!` (FAKE_ENV / FAKE_CWD plus the FakeEnv Sys fake). - config/store_path: `prefix_probe!` (ALLOW_PREFIXES plus the PrefixProbe LinkProbe fake). Localizing the allowlist removes the need for the PREFIX_PROBE_SCENARIO_LOCK serialization lock, which existed only to keep parallel tests from racing a process-global allowlist. - env-installer: the single-use CONFIG_DEP_EVENTS recording reporter moves into its one test body. - package-manager/installability: `recording_reporter!` moves RECORDED_EVENTS from a module-level `thread_local!` to a fn-local `static Mutex<Vec<LogEvent>>`, matching the crate's other recording-reporter tests. Test-only change; no runtime behavior changes. Resolves #12779. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_013BcmJgTLC8oQzWVLaRL8cy
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR replaces module-level mutable test fakes, event buffers, and synchronization locks with per-test macro-generated or function-local state across CLI, configuration, web-auth, installer, and package-manager test suites. ChangesPer-test Rust test harnesses
Estimated code review effort: 3 (Moderate) | ~25 minutes Assessment against linked issues
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Micro-Benchmark ResultsLinux |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13256 +/- ##
=======================================
Coverage 86.91% 86.91%
=======================================
Files 530 530
Lines 90785 90785
=======================================
Hits 78902 78902
Misses 11883 11883 ☔ 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. The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time). Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.67798093514,
"stddev": 0.13709480575297397,
"median": 2.66335336214,
"user": 2.2448535799999996,
"system": 1.7218190399999997,
"min": 2.49775299964,
"max": 2.88560768064,
"times": [
2.74575609564,
2.74141354964,
2.56727713964,
2.87388525764,
2.49775299964,
2.65127955564,
2.67542716864,
2.88560768064,
2.49798240964,
2.64342749464
]
},
{
"command": "pacquet@main",
"mean": 2.5241240594399996,
"stddev": 0.08320043115333704,
"median": 2.50961704764,
"user": 1.86965928,
"system": 1.4416091399999997,
"min": 2.41777942264,
"max": 2.67261618164,
"times": [
2.51845029764,
2.54417821264,
2.6157731916399998,
2.41777942264,
2.43078140264,
2.4704351776399998,
2.67261618164,
2.50078379764,
2.59735586464,
2.47308704564
]
},
{
"command": "pnpr@HEAD",
"mean": 1.6114774730400003,
"stddev": 0.1860765182055682,
"median": 1.65122266414,
"user": 1.11207678,
"system": 1.1842984399999998,
"min": 1.39324854164,
"max": 1.8449520586400001,
"times": [
1.4085597476400002,
1.7826228986400001,
1.7647183636400001,
1.4321297386400003,
1.4170670686400002,
1.8449520586400001,
1.7450133136400001,
1.7690309846400003,
1.39324854164,
1.55743201464
]
},
{
"command": "pnpr@main",
"mean": 1.5647105378400004,
"stddev": 0.16706413055615027,
"median": 1.5810919026400003,
"user": 1.1044946800000002,
"system": 1.2516667399999999,
"min": 1.35209560664,
"max": 1.8070153506400002,
"times": [
1.44960133464,
1.35209560664,
1.6437042726400002,
1.3578467226400002,
1.6112232556400001,
1.41637179464,
1.5509605496400003,
1.67186673764,
1.7864197536400002,
1.8070153506400002
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.2602509082400001,
"stddev": 0.008292139187536251,
"median": 0.26014781384,
"user": 0.22012359999999997,
"system": 0.5250427599999999,
"min": 0.24465485284000002,
"max": 0.27059786884000003,
"times": [
0.26962271184000003,
0.26740677084000003,
0.26492180584,
0.25132357784000003,
0.25837918684,
0.24465485284000002,
0.26024277684,
0.27059786884000003,
0.26005285084,
0.25530667984
]
},
{
"command": "pacquet@main",
"mean": 0.26146165344000005,
"stddev": 0.015797544197256683,
"median": 0.25639334084,
"user": 0.21226669999999997,
"system": 0.5344589599999999,
"min": 0.24456970284000001,
"max": 0.29704876684000003,
"times": [
0.25623943684,
0.24456970284000001,
0.24849006784000002,
0.26882011684,
0.24938521484,
0.26979373284,
0.29704876684000003,
0.27198204284000005,
0.25174020784,
0.25654724484
]
},
{
"command": "pnpr@HEAD",
"mean": 0.27709119734,
"stddev": 0.00653895348507229,
"median": 0.27609251384,
"user": 0.2212325,
"system": 0.5408589599999998,
"min": 0.26986557684,
"max": 0.28840760684,
"times": [
0.27216313084000004,
0.27778221984,
0.27802005384,
0.26986557684,
0.28366434984,
0.27147066384,
0.27062350584,
0.28451205784,
0.27440280784000004,
0.28840760684
]
},
{
"command": "pnpr@main",
"mean": 0.27811819704000007,
"stddev": 0.00527296280726453,
"median": 0.27915986034000007,
"user": 0.22227889999999997,
"system": 0.53417186,
"min": 0.26907353384000005,
"max": 0.28796428684,
"times": [
0.27324021884000005,
0.27932701384,
0.27899270684000005,
0.27330131384,
0.26907353384000005,
0.28796428684,
0.28042055284,
0.28109687984000004,
0.27702257684000003,
0.28074288684000004
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.85930860448,
"stddev": 0.05510005143516351,
"median": 2.8594081116799996,
"user": 1.90192746,
"system": 1.4258357999999998,
"min": 2.78310060768,
"max": 2.95925919668,
"times": [
2.88223172968,
2.8921820826799998,
2.84524852768,
2.90991505568,
2.85927763168,
2.95925919668,
2.85953859168,
2.78701673568,
2.78310060768,
2.81531588568
]
},
{
"command": "pacquet@main",
"mean": 2.82970695328,
"stddev": 0.035426020704316434,
"median": 2.81990053618,
"user": 1.8819857599999998,
"system": 1.3660292999999997,
"min": 2.79244031668,
"max": 2.8968015766799997,
"times": [
2.79340124768,
2.82379274868,
2.81162131468,
2.85655274768,
2.79294912068,
2.85572449468,
2.81600832368,
2.8577776416800003,
2.8968015766799997,
2.79244031668
]
},
{
"command": "pnpr@HEAD",
"mean": 1.62936284848,
"stddev": 0.13294536642205093,
"median": 1.6007262331799998,
"user": 1.0837592600000001,
"system": 1.117074,
"min": 1.44330071268,
"max": 1.82687513368,
"times": [
1.73393312868,
1.82687513368,
1.5661794066799999,
1.54275881668,
1.53717349168,
1.82620311368,
1.6352730596799998,
1.51101551168,
1.44330071268,
1.6709161096799998
]
},
{
"command": "pnpr@main",
"mean": 1.7071718874800001,
"stddev": 0.16191211016938253,
"median": 1.68589070168,
"user": 1.1699175600000002,
"system": 1.3163498999999999,
"min": 1.4785358686799999,
"max": 1.96116803368,
"times": [
1.55084874268,
1.81355195068,
1.82677788068,
1.4785358686799999,
1.8931380626799998,
1.70130080868,
1.96116803368,
1.53945972468,
1.6704805946799999,
1.63645720768
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.6344556276200001,
"stddev": 0.049638600163982624,
"median": 0.61814093822,
"user": 0.7518407,
"system": 0.7337576799999999,
"min": 0.5839874207200001,
"max": 0.7363454477200001,
"times": [
0.7363454477200001,
0.6239231437200001,
0.6073350227200001,
0.62272177372,
0.6387977157200001,
0.5839874207200001,
0.61113160472,
0.7105944647200001,
0.6135601027200001,
0.5961595797200001
]
},
{
"command": "pacquet@main",
"mean": 0.6091770858200001,
"stddev": 0.03142190270217875,
"median": 0.6022859142200001,
"user": 0.745607,
"system": 0.6713698799999999,
"min": 0.57188863972,
"max": 0.66608988572,
"times": [
0.6205075057200001,
0.66608988572,
0.6407287727200001,
0.6372965327200001,
0.6131631377200001,
0.5914086907200001,
0.5877652467200001,
0.5842476777200001,
0.57188863972,
0.5786747687200001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.29722676932000003,
"stddev": 0.010840426688328492,
"median": 0.29639208772000003,
"user": 0.2024828,
"system": 0.5030195799999999,
"min": 0.28519151372,
"max": 0.32011644972000003,
"times": [
0.28519151372,
0.29306862772000003,
0.28647743172,
0.29109583272,
0.30149961972,
0.30580736872000003,
0.30196339972,
0.29971554772000003,
0.32011644972000003,
0.28733190172
]
},
{
"command": "pnpr@main",
"mean": 0.31089392922000003,
"stddev": 0.018599678098992895,
"median": 0.30792446972,
"user": 0.19168929999999998,
"system": 0.54796578,
"min": 0.28714840872,
"max": 0.35959873372,
"times": [
0.35959873372,
0.31170450472,
0.30509829072,
0.31093831972,
0.31230397672000004,
0.30439750772,
0.30845794472,
0.30190061072,
0.30739099472000003,
0.28714840872
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.9871676686600002,
"stddev": 0.03168995362956608,
"median": 1.97986191026,
"user": 1.0562912199999999,
"system": 0.8075189799999999,
"min": 1.9490131452600001,
"max": 2.0371508122599997,
"times": [
2.03365072726,
1.97067283326,
1.95332797726,
1.9490131452600001,
2.01061563126,
2.0371508122599997,
1.98905098726,
1.9955013802600001,
1.96921699726,
1.9634761952600002
]
},
{
"command": "pacquet@main",
"mean": 1.9813993423600003,
"stddev": 0.026235430962562027,
"median": 1.9815517067600001,
"user": 1.07122132,
"system": 0.81054928,
"min": 1.9461794572600002,
"max": 2.0286423062599996,
"times": [
2.00433305226,
2.0286423062599996,
1.99510886526,
2.00162919826,
1.9824445942600002,
1.9461794572600002,
1.95784542826,
1.98065881926,
1.95789095326,
1.95926074926
]
},
{
"command": "pnpr@HEAD",
"mean": 0.32632466926000003,
"stddev": 0.0049870208839796395,
"median": 0.32517436676,
"user": 0.20484032000000002,
"system": 0.5696996799999998,
"min": 0.31991143326000004,
"max": 0.33733764426,
"times": [
0.32792496326000004,
0.31991143326000004,
0.33733764426,
0.32315390826,
0.32246939426000004,
0.32646269526000005,
0.32767560826000003,
0.32388603826,
0.33071770426,
0.32370730326
]
},
{
"command": "pnpr@main",
"mean": 0.31790877766000003,
"stddev": 0.010947112849999843,
"median": 0.31576250276000006,
"user": 0.20386902,
"system": 0.5571443800000001,
"min": 0.30175336226000005,
"max": 0.33461289126000004,
"times": [
0.30175336226000005,
0.33214513826000003,
0.31001071926,
0.31669550026000004,
0.30804406526,
0.33461289126000004,
0.32212441826000004,
0.32788510826,
0.31482950526000003,
0.31098706826
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.39249612460000005,
"stddev": 0.006132529949523271,
"median": 0.3935099939,
"user": 0.38884924,
"system": 0.05971854,
"min": 0.3816927579,
"max": 0.4021783219,
"times": [
0.3866924499,
0.3960752199,
0.39621092290000004,
0.39718377590000004,
0.39543114290000003,
0.3865858739,
0.39132193590000003,
0.3816927579,
0.4021783219,
0.3915888449
]
},
{
"command": "pacquet@main",
"mean": 0.3961447295,
"stddev": 0.015480035386245075,
"median": 0.3967032004,
"user": 0.38453474,
"system": 0.06034373999999999,
"min": 0.3728331319,
"max": 0.42098390890000004,
"times": [
0.42098390890000004,
0.3761756939,
0.3877347859,
0.3728331319,
0.4087337709,
0.38676722290000004,
0.4062726619,
0.4001326599,
0.40853971790000004,
0.3932737409
]
},
{
"command": "pnpr@HEAD",
"mean": 0.088891137025,
"stddev": 0.002195248876816312,
"median": 0.08849876790000001,
"user": 0.023136415,
"system": 0.00857417125,
"min": 0.08559805890000001,
"max": 0.09284659690000001,
"times": [
0.08886153190000001,
0.08842963290000001,
0.08596045790000001,
0.08672988790000001,
0.0889645059,
0.09284659690000001,
0.0921671539,
0.0895128319,
0.08839750290000001,
0.09115200290000001,
0.0872364679,
0.0913548019,
0.0881381779,
0.09129226590000002,
0.09154983790000001,
0.08696934790000001,
0.08751310590000001,
0.0865559129,
0.08687015290000001,
0.0875381129,
0.09071861090000001,
0.08824404590000001,
0.09196651890000002,
0.09227903290000002,
0.09093124890000001,
0.0865840669,
0.08858471390000001,
0.09082004190000001,
0.08559805890000001,
0.08608434990000001,
0.08856790290000001,
0.08609750390000001
]
},
{
"command": "pnpr@main",
"mean": 0.08784384138484852,
"stddev": 0.0024824812651319393,
"median": 0.08699038790000001,
"user": 0.021501873333333334,
"system": 0.009851146666666668,
"min": 0.0851629239,
"max": 0.09779300390000001,
"times": [
0.0851629239,
0.08613589590000001,
0.09173545490000001,
0.08991376390000001,
0.08779385190000001,
0.0867008439,
0.08643488690000001,
0.08689975790000001,
0.0859345199,
0.08725882990000002,
0.0867720279,
0.0866960959,
0.0864359179,
0.08762700990000001,
0.08688128290000001,
0.08753125090000001,
0.09142073590000001,
0.08662495190000001,
0.08699038790000001,
0.08560411990000001,
0.08809989590000002,
0.0863080489,
0.0880310469,
0.08673579090000001,
0.08679210590000001,
0.08731565690000001,
0.0877377569,
0.0866608199,
0.08736931690000001,
0.09284948290000002,
0.09779300390000001,
0.08948074190000001,
0.08711858790000002
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.542388229579999,
"stddev": 0.04282176529455234,
"median": 4.54836416028,
"user": 2.14618802,
"system": 1.60139902,
"min": 4.4800505482799995,
"max": 4.5982800272799995,
"times": [
4.489938060279999,
4.527819710279999,
4.4800505482799995,
4.590442597279999,
4.49843570728,
4.5748310632799996,
4.53190541428,
4.5982800272799995,
4.56735626128,
4.56482290628
]
},
{
"command": "pacquet@main",
"mean": 4.575821948379999,
"stddev": 0.06046841905419221,
"median": 4.56554425228,
"user": 2.1170959199999997,
"system": 1.55860802,
"min": 4.4841832112799995,
"max": 4.67330614828,
"times": [
4.602831954279999,
4.53171170128,
4.60867077228,
4.4841832112799995,
4.55576892528,
4.52514750528,
4.575319579279999,
4.6600141192799995,
4.67330614828,
4.54126556728
]
},
{
"command": "pnpr@HEAD",
"mean": 3.6023183245800006,
"stddev": 0.11674620749002905,
"median": 3.59870529028,
"user": 1.29065932,
"system": 1.33853312,
"min": 3.48272650028,
"max": 3.81059334628,
"times": [
3.48272650028,
3.61493819428,
3.60686255428,
3.81059334628,
3.60717729328,
3.54559534328,
3.59054802628,
3.78959464428,
3.4908718312800002,
3.48427551228
]
},
{
"command": "pnpr@main",
"mean": 3.5756584880799998,
"stddev": 0.0842031559490526,
"median": 3.55954890078,
"user": 1.37832162,
"system": 1.3963696200000002,
"min": 3.46067797028,
"max": 3.70451056828,
"times": [
3.46067797028,
3.68864851928,
3.51557593728,
3.52184766728,
3.58822943228,
3.57245727128,
3.66171267228,
3.54664053028,
3.49628431228,
3.70451056828
]
}
]
} |
|
| Branch | pr/13256 |
| 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,443.30 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 319.91 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 285.19 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 85.60 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,393.25 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,482.73 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 269.87 ms |
The poll_fake! / browser_fake! / fake_env! / prefix_probe! / recording_reporter! macro doc comments described the refactor's rationale — the per-test isolation motivation and a citation of the CODE_STYLE_GUIDE.md "Dependency injection for tests" rule they follow. A rustdoc comment should state only the item's final-state contract, not why the change was made, so each is reduced to what the macro is and which items it brings into the test function. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_013BcmJgTLC8oQzWVLaRL8cy
A completeness scan turned up two module-level shared-mutable test statics matching the same anti-pattern #12779 targets, which the issue's enumerated list did not name: - cli/src/cli_args/bugs/tests.rs: the OPENED_URLS thread-local and the RecordingBrowser OpenUrl fake, shared across seven tests, become a per-test recording_browser! macro. - package-manager/src/minimum_release_age/tests.rs: the module-level EVENTS recording-reporter buffer and its TEST_LOCK serialization guard become a per-test recording_reporter! macro. Once each test owns its own EVENTS there is nothing left to serialize, so TEST_LOCK is gone; this also closes a latent race in which a writer-only test emitted into the shared buffer without holding the lock and could corrupt the reader tests' captured events. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_013BcmJgTLC8oQzWVLaRL8cy
There was a problem hiding this comment.
🧹 Nitpick comments (4)
pnpm/crates/config/src/store_path/tests.rs (1)
74-81: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse concise regular comments for private test-harness rationale.
These rustdoc blocks narrate macro expansion rather than documenting a public API contract. Retain only the non-obvious isolation invariant as
//comments.
pnpm/crates/config/src/store_path/tests.rs#L74-L81: replace the expansion walkthrough with a short rationale for per-test probe isolation.pnpm/crates/config/src/tests.rs#L96-L103: replace generated-item documentation with a short rationale for isolated fake environment state.pnpm/crates/config/src/tests.rs#L140-L143: convert the useful retry-isolation rationale to a regular comment.As per coding guidelines, use rustdoc for public API contracts and regular comments only for non-obvious rationale or invariants. As per path instructions, test-harness comments should preserve contract through names rather than narrating behavior.
🤖 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/config/src/store_path/tests.rs` around lines 74 - 81, Replace the private test-harness rustdoc with concise regular comments preserving only non-obvious isolation rationale: in pnpm/crates/config/src/store_path/tests.rs:74-81, explain per-test probe isolation; in pnpm/crates/config/src/tests.rs:96-103, explain isolated fake environment state; and in pnpm/crates/config/src/tests.rs:140-143, convert the retry-isolation rationale to a regular comment. Do not narrate macro expansion or generated-item behavior.Sources: Coding guidelines, Path instructions
pnpm/crates/package-manager/src/installability/tests.rs (1)
16-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace expansion-narration rustdoc with a short rationale comment.
Both private test macros document their generated items line by line. Keep only the non-obvious isolation contract as a regular comment, or remove the comments.
pnpm/crates/package-manager/src/installability/tests.rs#L16-L21: replace the macro-expansion rustdoc with a brief regular comment explaining per-test event isolation.pnpm/crates/package-manager/src/minimum_release_age/tests.rs#L50-L56: replace the macro-expansion rustdoc with a brief regular comment explaining per-test reporter isolation.As per coding guidelines, “Do not write comments that merely restate code … or narrate the function body.” As per path instructions, comments should explain “non-obvious reasons or invariants.”
🤖 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/package-manager/src/installability/tests.rs` around lines 16 - 21, The comments above the private test macros are narrating their expansions instead of documenting the invariant. In pnpm/crates/package-manager/src/installability/tests.rs lines 16-21, replace the rustdoc with a brief regular comment explaining per-test event isolation; make the same change in pnpm/crates/package-manager/src/minimum_release_age/tests.rs lines 50-56, explaining per-test reporter isolation. Remove the comments if no concise rationale is needed.Sources: Coding guidelines, Path instructions
pnpm/crates/env-installer/src/tests.rs (1)
877-883: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRecord raw
LogEvents in the reporter fake.This stores only derived statuses. Capture
Mutex<Vec<LogEvent>>and filter/assertInstallingConfigDepsevents afterward, matching the required reporter-test harness contract.As per path instructions, “when asserting reporter output, use a recording-fake reporter capturing into a static
Mutex<Vec<LogEvent>>declared inside the#[test]body.”🤖 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/env-installer/src/tests.rs` around lines 877 - 883, Update the RecordingReporter test harness to store raw LogEvent values in a static Mutex<Vec<LogEvent>> declared inside each relevant #[test] body, rather than extracting InstallingConfigDepsStatus during emit. Filter the recorded events afterward when asserting InstallingConfigDeps output, and update the reporter tests to use this raw-event collection.Source: Path instructions
pnpm/crates/network-web-auth/src/prompt_browser_open/tests.rs (1)
34-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
static Mutex<Vec<LogEvent>>for the reporter capture, per convention.
EMITTEDis athread_local! RefCell<Vec<(LogLevel, String)>>andRecordingReporter::emitdestructures only theGlobalvariant, whereas the documented convention for reporter/log-event testing is astatic Mutex<Vec<LogEvent>>capturing the fullLogEvent. Functionally harmless under the current single-threadedLocalSettests, but it diverges from the pattern used elsewhere (e.g.CONFIG_DEP_EVENTSinpnpm/crates/env-installer/src/tests.rs) and loses event-variant information that aMutex<Vec<LogEvent>>would retain.As per pnpm/AGENTS.md: "when asserting reporter output, use a recording-fake reporter capturing into a static Mutex<Vec> declared inside the #[test] body; reset/clear at test start so retries and parallel runs can't interfere."
♻️ Sketch of the convention-aligned capture
- static EMITTED: RefCell<Vec<(LogLevel, String)>> = const { RefCell::new(Vec::new()) }; + static EMITTED: Mutex<Vec<LogEvent>> = Mutex::new(Vec::new());- struct RecordingReporter; - - impl Reporter for RecordingReporter { - fn emit(event: &LogEvent) { - if let LogEvent::Global(GlobalLog { level, message }) = event { - EMITTED.with(|emitted| emitted.borrow_mut().push((*level, message.clone()))); - } - } - } + struct RecordingReporter; + + impl Reporter for RecordingReporter { + fn emit(event: &LogEvent) { + EMITTED.lock().unwrap().push(event.clone()); + } + }(then have
infos/warns/messages_atfilterLogEvent::Globalentries out of the lockedVec<LogEvent>instead of the pre-filtered tuple.)Also applies to: 97-105
🤖 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/network-web-auth/src/prompt_browser_open/tests.rs` around lines 34 - 42, Replace the thread-local EMITTED tuple capture with the convention-aligned static Mutex<Vec<LogEvent>> inside each test, clearing it at test start. Update RecordingReporter::emit to store the complete LogEvent, and adjust infos, warns, and messages_at to lock the capture and filter Global variants when asserting output.Source: Path instructions
🤖 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 `@pnpm/crates/config/src/store_path/tests.rs`:
- Around line 74-81: Replace the private test-harness rustdoc with concise
regular comments preserving only non-obvious isolation rationale: in
pnpm/crates/config/src/store_path/tests.rs:74-81, explain per-test probe
isolation; in pnpm/crates/config/src/tests.rs:96-103, explain isolated fake
environment state; and in pnpm/crates/config/src/tests.rs:140-143, convert the
retry-isolation rationale to a regular comment. Do not narrate macro expansion
or generated-item behavior.
In `@pnpm/crates/env-installer/src/tests.rs`:
- Around line 877-883: Update the RecordingReporter test harness to store raw
LogEvent values in a static Mutex<Vec<LogEvent>> declared inside each relevant
#[test] body, rather than extracting InstallingConfigDepsStatus during emit.
Filter the recorded events afterward when asserting InstallingConfigDeps output,
and update the reporter tests to use this raw-event collection.
In `@pnpm/crates/network-web-auth/src/prompt_browser_open/tests.rs`:
- Around line 34-42: Replace the thread-local EMITTED tuple capture with the
convention-aligned static Mutex<Vec<LogEvent>> inside each test, clearing it at
test start. Update RecordingReporter::emit to store the complete LogEvent, and
adjust infos, warns, and messages_at to lock the capture and filter Global
variants when asserting output.
In `@pnpm/crates/package-manager/src/installability/tests.rs`:
- Around line 16-21: The comments above the private test macros are narrating
their expansions instead of documenting the invariant. In
pnpm/crates/package-manager/src/installability/tests.rs lines 16-21, replace the
rustdoc with a brief regular comment explaining per-test event isolation; make
the same change in pnpm/crates/package-manager/src/minimum_release_age/tests.rs
lines 50-56, explaining per-test reporter isolation. Remove the comments if no
concise rationale is needed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 0ebb9c48-48ac-49c4-b1c3-4aa0c562f3de
📒 Files selected for processing (8)
pnpm/crates/cli/src/cli_args/bugs/tests.rspnpm/crates/config/src/store_path/tests.rspnpm/crates/config/src/tests.rspnpm/crates/env-installer/src/tests.rspnpm/crates/network-web-auth/src/poll_for_web_auth_token/tests.rspnpm/crates/network-web-auth/src/prompt_browser_open/tests.rspnpm/crates/package-manager/src/installability/tests.rspnpm/crates/package-manager/src/minimum_release_age/tests.rs
KSXGitHub
left a comment
There was a problem hiding this comment.
Claude Code,
Below are many different reviews. Each may belong to different categories.
I wish that you do not collapse all the unrelated tasks into a single commit.
You shall analyze the reviews. You shall make groups of related reviews.
Each group of related reviews correspond to a task and a git commit.
A git commit should have its purpose clear and focused.
If there would be multiple groups of related reviews, then I expect multiple commits.
…ents The test-fake macros' doc comments listed every item each macro expands and narrated the expansion, which restates the code below them and drifts as the macros change. These private test macros are not a rustdoc-visible API, so state only the non-obvious per-test isolation rationale, and do so in regular `//` comments rather than `///` rustdoc. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_013BcmJgTLC8oQzWVLaRL8cy
… allows The test-fake macros emitted their whole helper surface into every test, so each test's unused helpers forced a blanket `#[allow(dead_code)]` on the generated functions. Follow the `login_fake!` technique instead: emit the always-used core unconditionally, and generate each optional helper from a macro argument, so every test names exactly the helpers it drives and no emitted helper is left unused. This drops every `dead_code` allow from these macros. An unknown helper name now expands to a `compile_error!` naming the valid helpers. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_013BcmJgTLC8oQzWVLaRL8cy
The reporter-test convention keeps a recording fake's capture in a `Mutex<Vec<LogEvent>>` holding the raw events. Two fakes diverged: prompt_browser_open kept a `thread_local! RefCell<Vec<(LogLevel, String)>>` and env-installer stored the projected `InstallingConfigDepsStatus`. Capture the full `LogEvent` in both and project or filter at the assertion site, so the fakes match the convention and retain the complete event variant. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_013BcmJgTLC8oQzWVLaRL8cy
This comment was marked as resolved.
This comment was marked as resolved.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains within the scope of this follow-up review. Reviews (3): Last reviewed commit: "refactor(pacquet): use a silent reporter..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
This PR refactors pacquet (Rust) tests to follow the repository’s test dependency-injection convention (DI principle 3): mutable fake state is moved from module-level shared statics/thread-locals into per-#[test] function-local state to prevent cross-test races under parallel execution.
Changes:
- Replaced module-level shared mutable test state with per-test-local fakes (often via small
macro_rules!helpers that expand fn-local statics and optional helpers). - Removed test-wide serialization locks (e.g.
TEST_LOCK,PREFIX_PROBE_SCENARIO_LOCK) by eliminating shared state that required them. - Standardized “recording reporter / browser” fakes to capture into fn-local
Mutex<Vec<...>>buffers and filter at assertion sites.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pnpm/crates/package-manager/src/minimum_release_age/tests.rs | Introduces a per-test recording reporter macro and removes a global reporter buffer + async lock. |
| pnpm/crates/package-manager/src/installability/tests.rs | Reworks the recording reporter from module-level thread-local state into per-test-local state via a helper macro. |
| pnpm/crates/network-web-auth/src/prompt_browser_open/tests.rs | Moves stdin/browser/open/enter fakes + log capture into per-test-local state via a macro, avoiding module-level thread_locals. |
| pnpm/crates/network-web-auth/src/poll_for_web_auth_token/tests.rs | Localizes clock/sleep/fetch fake state into fn-local thread_locals via a per-test macro. |
| pnpm/crates/env-installer/src/tests.rs | Makes the config-deps recording reporter’s buffer test-local and filters the captured LogEvents at assertion time. |
| pnpm/crates/config/src/tests.rs | Replaces module-level fake env thread_locals with a per-test macro that expands the env fake and optional helpers. |
| pnpm/crates/config/src/store_path/tests.rs | Replaces shared allowlist + scenario lock with a per-test prefix_probe! macro and test-local allowlist state. |
| pnpm/crates/cli/src/cli_args/bugs/tests.rs | Converts the browser URL recorder from module-level thread-local state to a per-test macro-based fake. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…s and warns The `infos` and `warns` accessors in the `browser_fake!` test macro each inlined the same `Global`-log-by-level filter, differing only in the level. Move that projection into a module-level `global_messages_at` helper that both delegate to. It stays live without a `dead_code` allow because a module-level item is used as long as any test drives `infos` or `warns`. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_013BcmJgTLC8oQzWVLaRL8cy
`non_interactive_strict_mode_reports_every_immature_pick` asserts only on the returned error and the prompt messages; it never inspects reporter events. Drive it with `SilentReporter` instead of the `recording_reporter!` fake, so it no longer spins up a capture buffer nothing reads — matching the env-installer tests, which record only when they assert on the recording. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_013BcmJgTLC8oQzWVLaRL8cy
Summary
A test-only refactor implementing pacquet's dependency-injection convention (
pnpm/CODE_STYLE_GUIDE.md, "Dependency injection for tests", principle 3): a stateful test fake keeps its state in an interior-mutablestaticinside each#[test]body, so tests get independent storage and can't race on it. Several test modules still hoisted that state to module scope — athread_local!block or a column-0staticreconfigured across tests — and this moves each into per-test-local form.Where a fake is shared across many tests, a module-local
macro_rules!expands the fn-local state at the top of each test body, generating the helpers that only some tests use from named macro arguments (thelogin_fake!technique) so none needs an#[allow(dead_code)]. Recording-reporter fakes capture into a fn-localMutex<Vec<LogEvent>>and filter at the assertion site, per the reporter-test convention.Localizing the state also removes two serialization locks —
store_path'sPREFIX_PROBE_SCENARIO_LOCKandminimum_release_age'sTEST_LOCK— the latter closing a latent race where a writer-only test wrote the shared buffer without holding the lock.Resolves #12779.
Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting. — Test-only; no user-visible behavior, so no TypeScript-CLI counterpart is needed.Summary by CodeRabbit