Repository navigation
feat(pacquet): implement find-hash - #12552
Conversation
|
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:
📝 WalkthroughWalkthroughAdds a Changesfind-hash subcommand
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 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 |
PR Summary by Qodofeat(pacquet): add Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1. FrozenStore open mode wrong
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pacquet/crates/cli/tests/find_hash.rs (2)
35-39: ⚡ Quick winAdd logging before multi-line output assertions.
As per CODE_STYLE_GUIDE.md, "log before non-trivial assertions (especially for multi-line outputs/errors)". This helps debug test failures by showing what the command actually produced.
📋 Suggested enhancement
let output = pacquet2.arg("find-hash").arg(&valid_hash).assert().success(); let stdout = String::from_utf8_lossy(&output.get_output().stdout); +eprintln!("find-hash stdout:\n{}", stdout); // Output should contain is-odd assert!(stdout.contains("is-odd"));🤖 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 `@pacquet/crates/cli/tests/find_hash.rs` around lines 35 - 39, Before the assertions that check stdout.contains("is-odd") and stdout.contains("3.0.1"), add a logging statement that prints the actual stdout content. This follows the CODE_STYLE_GUIDE.md requirement to log before non-trivial assertions on multi-line outputs, making it easier to debug test failures by showing what the command actually produced.Source: Coding guidelines
42-58: ⚡ Quick winConsider adding a success test with sha512-base64 format.
Current coverage:
- Test 1: Success with hex digest ✓
- Test 2: Failure with sha512-base64 (hash not found) ✓
- Test 3: Failure with invalid base64 ✓
Missing: Success test with sha512-base64 format to verify the base64-to-hex conversion produces the correct hex and finds the right package. Test 2 exercises base64 decoding but only on the failure path, so it doesn't verify the conversion is correct.
💡 Suggested test case
You could convert the
valid_hashfrom test 1 to base64 format and verify that both formats find the same package:#[test] fn find_hash_works_with_base64() { let CommandTempCwd { mut pacquet, workspace, root: _root, npmrc_info, .. } = CommandTempCwd::init().add_mocked_registry(); pacquet.arg("add").arg("[email protected]").assert().success(); let store_dir = pacquet_store_dir::StoreDir::from(npmrc_info.store_dir); let store_index = StoreIndex::open_readonly_in(&store_dir).unwrap(); let keys = store_index.keys().unwrap(); let entries = store_index.get_many(&keys).unwrap(); // Find a valid hex hash let mut hex_hash = String::new(); for (_key, data) in entries { if let Some(file) = data.files.values().next() { hex_hash = file.digest.clone(); break; } } // Convert hex to base64 and test with sha512-base64 format use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64}; let bytes = hex::decode(&hex_hash).unwrap(); let base64_hash = format!("sha512-{}", BASE64.encode(&bytes)); let mut pacquet2 = std::process::Command::cargo_bin("pacquet").unwrap(); pacquet2.current_dir(&workspace); let output = pacquet2.arg("find-hash").arg(&base64_hash).assert().success(); let stdout = String::from_utf8_lossy(&output.get_output().stdout); assert!(stdout.contains("is-odd")); assert!(stdout.contains("3.0.1")); }🤖 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 `@pacquet/crates/cli/tests/find_hash.rs` around lines 42 - 58, Add a new test function to verify that the find-hash command succeeds with sha512-base64 format. The test should initialize CommandTempCwd, add a package to the registry, extract a valid hex hash from the store index, convert that hex hash to base64 format (prefixed with "sha512-"), run the find-hash command with the base64 hash argument, and assert that the command succeeds and the output contains the expected package name and version. This ensures the base64-to-hex conversion logic works correctly on the success path, not just on failure cases like the existing test for invalid base64.
🤖 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 `@pacquet/crates/cli/tests/find_hash.rs`:
- Around line 35-39: Before the assertions that check stdout.contains("is-odd")
and stdout.contains("3.0.1"), add a logging statement that prints the actual
stdout content. This follows the CODE_STYLE_GUIDE.md requirement to log before
non-trivial assertions on multi-line outputs, making it easier to debug test
failures by showing what the command actually produced.
- Around line 42-58: Add a new test function to verify that the find-hash
command succeeds with sha512-base64 format. The test should initialize
CommandTempCwd, add a package to the registry, extract a valid hex hash from the
store index, convert that hex hash to base64 format (prefixed with "sha512-"),
run the find-hash command with the base64 hash argument, and assert that the
command succeeds and the output contains the expected package name and version.
This ensures the base64-to-hex conversion logic works correctly on the success
path, not just on failure cases like the existing test for invalid base64.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2519d390-b26f-4698-aed6-209a5bf0b67f
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock,!Cargo.lock
📒 Files selected for processing (5)
pacquet/crates/cli/Cargo.tomlpacquet/crates/cli/src/cli_args.rspacquet/crates/cli/src/cli_args/find_hash.rspacquet/crates/cli/tests/find_hash.rspacquet/crates/store-dir/src/lib.rs
|
Code review by qodo was updated up to the latest commit d8b96ac |
kairosci
left a comment
There was a problem hiding this comment.
All review comments are addressed: the println has been removed and a test using base64 engine directly without the hex crate has been added.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@pacquet/crates/cli/tests/find_hash.rs`:
- Around line 73-80: The digest extraction logic takes the first available
digest from any entry in the store_index without checking which package it
belongs to, but the subsequent assertions expect the digest specifically from
the [email protected] package. This causes test flakiness and order-dependency.
Modify the loop in the hex_hash extraction to filter for and bind the digest
specifically from the [email protected] package entry rather than accepting the first
digest found from any package in the entries.
🪄 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: a7e415e8-1011-40c1-898c-4cb1afb29ff9
📒 Files selected for processing (1)
pacquet/crates/cli/tests/find_hash.rs
|
Code review by qodo was updated up to the latest commit a8bd195 |
|
Code review by qodo was updated up to the latest commit a8bd195 |
|
Code review by qodo was updated up to the latest commit d76bc16 |
|
Code review by qodo was updated up to the latest commit d76bc16 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12552 +/- ##
==========================================
+ Coverage 88.02% 88.04% +0.01%
==========================================
Files 321 323 +2
Lines 44941 45238 +297
==========================================
+ Hits 39559 39828 +269
- Misses 5382 5410 +28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code review by qodo was updated up to the latest commit 4a30d87 |
|
Code review by qodo was updated up to the latest commit 4a30d87 |
Integrated-Benchmark Report (Linux)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": 3.8552240544200003,
"stddev": 0.21685544977588658,
"median": 3.76457619182,
"user": 3.60595336,
"system": 3.4267210399999994,
"min": 3.64556283282,
"max": 4.27946609482,
"times": [
3.93967960782,
4.27946609482,
3.73684694682,
3.79230543682,
4.14653754782,
3.70772430382,
3.69828148882,
3.66604175282,
3.93979453182,
3.64556283282
]
},
{
"command": "pacquet@main",
"mean": 3.81542334242,
"stddev": 0.1507697189825743,
"median": 3.82234479782,
"user": 3.6071215600000004,
"system": 3.40414834,
"min": 3.6426947528199998,
"max": 4.03976455282,
"times": [
3.94182267982,
3.93058181482,
3.94797746582,
3.6426947528199998,
3.90296931082,
3.74172028482,
4.03976455282,
3.66549626682,
3.67731970982,
3.6638865858200003
]
},
{
"command": "pnpr@HEAD",
"mean": 2.15884573662,
"stddev": 0.109482321556663,
"median": 2.14297934932,
"user": 2.65936696,
"system": 3.00795654,
"min": 1.98583823382,
"max": 2.32578733182,
"times": [
2.21064838282,
2.08559174982,
1.98583823382,
2.20646829382,
2.32578733182,
2.15066509182,
2.08084741682,
2.32415135382,
2.08316590482,
2.13529360682
]
},
{
"command": "pnpr@main",
"mean": 2.0683396954199997,
"stddev": 0.11035737806362572,
"median": 2.02141426082,
"user": 2.67184126,
"system": 3.0181270400000004,
"min": 1.97270299082,
"max": 2.27565523582,
"times": [
2.06427397682,
2.27565523582,
2.01249433582,
2.06180274582,
2.02614892182,
2.01553650682,
2.26383449982,
1.97270299082,
1.97426814082,
2.01667959982
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.65287501522,
"stddev": 0.01212328169619435,
"median": 0.6522806574200001,
"user": 0.4143603799999999,
"system": 1.3179518,
"min": 0.6379835354200001,
"max": 0.6757759014200001,
"times": [
0.6528753874200001,
0.6757759014200001,
0.6608577164200001,
0.6434463554200001,
0.65548748842,
0.64472100342,
0.6516859274200001,
0.6397448844200001,
0.6379835354200001,
0.66617195242
]
},
{
"command": "pacquet@main",
"mean": 0.6532277383200003,
"stddev": 0.012777521420715133,
"median": 0.6518998719200001,
"user": 0.41742548,
"system": 1.3226456999999998,
"min": 0.6316294214200001,
"max": 0.67193665942,
"times": [
0.6605552404200001,
0.6316294214200001,
0.64849747442,
0.6369546814200001,
0.6501381584200001,
0.6594724674200001,
0.6509470014200001,
0.6528527424200001,
0.67193665942,
0.6692935364200001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.7429441614200001,
"stddev": 0.08754595079067466,
"median": 0.72120128492,
"user": 0.41939788,
"system": 1.3738781999999998,
"min": 0.6856831794200001,
"max": 0.98740355042,
"times": [
0.7323165494200001,
0.6916061814200001,
0.6856831794200001,
0.7248632074200001,
0.70831009442,
0.7375349734200001,
0.7298442854200001,
0.71434023042,
0.71753936242,
0.98740355042
]
},
{
"command": "pnpr@main",
"mean": 0.7488145690200001,
"stddev": 0.10453179488269736,
"median": 0.72195431342,
"user": 0.43632177999999994,
"system": 1.3821451,
"min": 0.6866665014200001,
"max": 1.03923249642,
"times": [
0.6948151534200001,
0.6992426104200001,
0.6866665014200001,
0.6961397004200001,
0.7432595014200001,
0.71524568742,
0.72866293942,
0.7293241544200001,
1.03923249642,
0.7555569454200001
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.27473241796,
"stddev": 0.05222495861756963,
"median": 4.2732190153600005,
"user": 3.7885957600000006,
"system": 3.3514289600000007,
"min": 4.20962438036,
"max": 4.36536172236,
"times": [
4.3300185113600005,
4.2982956983600005,
4.210096286360001,
4.36536172236,
4.309696922360001,
4.223132345360001,
4.254660282360001,
4.270756895360001,
4.20962438036,
4.27568113536
]
},
{
"command": "pacquet@main",
"mean": 4.266781207460001,
"stddev": 0.056310078416206236,
"median": 4.271456435360001,
"user": 3.80955436,
"system": 3.34800936,
"min": 4.150719657360001,
"max": 4.357594968360001,
"times": [
4.277931786360001,
4.267945405360001,
4.150719657360001,
4.328068479360001,
4.26237289536,
4.2749674653600005,
4.21626090136,
4.27818453436,
4.357594968360001,
4.253765981360001
]
},
{
"command": "pnpr@HEAD",
"mean": 2.25069745376,
"stddev": 0.11529693490776532,
"median": 2.28367677486,
"user": 2.47026136,
"system": 2.95171136,
"min": 2.07572108736,
"max": 2.43048254936,
"times": [
2.37249150736,
2.31437334536,
2.29816113636,
2.43048254936,
2.07572108736,
2.27120158236,
2.29615196736,
2.11043594236,
2.16429952636,
2.17365589336
]
},
{
"command": "pnpr@main",
"mean": 2.15267347776,
"stddev": 0.11909806107177291,
"median": 2.11718969086,
"user": 2.50126996,
"system": 2.9013176599999997,
"min": 2.01069213936,
"max": 2.34547761836,
"times": [
2.34547761836,
2.10417380036,
2.33541560336,
2.12143269436,
2.02375472036,
2.01069213936,
2.18960442336,
2.22467733436,
2.11294668736,
2.0585597563599998
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.38042781218,
"stddev": 0.02264522456374274,
"median": 1.3823753081799999,
"user": 1.42222112,
"system": 1.72268564,
"min": 1.34202795968,
"max": 1.41258706268,
"times": [
1.41258706268,
1.35193439668,
1.34202795968,
1.36205851468,
1.38285416568,
1.40052996168,
1.3985434636799998,
1.39476814968,
1.37707799668,
1.38189645068
]
},
{
"command": "pacquet@main",
"mean": 1.4299864884799998,
"stddev": 0.03318998475922451,
"median": 1.42302102068,
"user": 1.4531998199999996,
"system": 1.7595611399999995,
"min": 1.39465543868,
"max": 1.49499391368,
"times": [
1.4602826276799998,
1.39777100068,
1.40051784468,
1.49499391368,
1.42472532768,
1.43202701668,
1.42131671368,
1.39465543868,
1.46339874468,
1.41017625668
]
},
{
"command": "pnpr@HEAD",
"mean": 0.70084424568,
"stddev": 0.06455114882096213,
"median": 0.6801432771800001,
"user": 0.3766194199999999,
"system": 1.3202182399999998,
"min": 0.6593443536800001,
"max": 0.8792877986800001,
"times": [
0.6771600526800001,
0.6898830746800001,
0.8792877986800001,
0.7161901926800001,
0.6831265016800001,
0.67068300568,
0.6873959256800001,
0.66878364168,
0.6593443536800001,
0.67658790968
]
},
{
"command": "pnpr@main",
"mean": 0.7145621305800001,
"stddev": 0.09853423665158946,
"median": 0.68323838668,
"user": 0.38237592,
"system": 1.3210048399999998,
"min": 0.6672934316800001,
"max": 0.9939979226800001,
"times": [
0.67747744468,
0.69620088168,
0.68063962968,
0.6810549476800001,
0.68193826168,
0.6845385116800001,
0.6878616536800001,
0.6672934316800001,
0.69461862068,
0.9939979226800001
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.1275537250200007,
"stddev": 0.060850683375315365,
"median": 3.1252240993200004,
"user": 1.88511006,
"system": 2.01017396,
"min": 3.0466115298200003,
"max": 3.2632022548200004,
"times": [
3.1509486038200003,
3.14578820082,
3.1046599978200002,
3.15978013582,
3.14905734382,
3.0798835538200002,
3.0920151228200004,
3.0835905068200002,
3.2632022548200004,
3.0466115298200003
]
},
{
"command": "pacquet@main",
"mean": 3.09136383862,
"stddev": 0.06512790503496099,
"median": 3.07965359832,
"user": 1.88078076,
"system": 1.9814308600000001,
"min": 3.0382286238200003,
"max": 3.26705196182,
"times": [
3.0382286238200003,
3.04456350382,
3.06093775182,
3.06248337982,
3.08307656182,
3.10575988682,
3.0762306348200004,
3.0887822858200003,
3.26705196182,
3.0865237958200002
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6844900933200001,
"stddev": 0.006595719489534141,
"median": 0.6825362393200001,
"user": 0.37572195999999997,
"system": 1.3209142600000001,
"min": 0.6769306378200001,
"max": 0.6942377838200001,
"times": [
0.6803197648200001,
0.6769306378200001,
0.6920156888200001,
0.67965557082,
0.6777115628200001,
0.6928787348200001,
0.6847527138200001,
0.6798637768200001,
0.6865346988200001,
0.6942377838200001
]
},
{
"command": "pnpr@main",
"mean": 0.6804835499200002,
"stddev": 0.0055833849152947075,
"median": 0.68153075232,
"user": 0.38050806000000004,
"system": 1.31355986,
"min": 0.6689521908200001,
"max": 0.6871372438200001,
"times": [
0.6852931518200001,
0.6689521908200001,
0.68262378582,
0.6804377188200001,
0.6756894868200001,
0.6792374768200001,
0.67643678782,
0.6871372438200001,
0.6855651388200001,
0.6834625178200001
]
}
]
} |
|
| Branch | pr/12552 |
| Testbed | pacquet |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,274.73 ms(+1.20%)Baseline: 4,224.23 ms | 5,069.08 ms (84.33%) |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot 🚷 view threshold | 3,127.55 ms(+3.94%)Baseline: 3,008.96 ms | 3,610.75 ms (86.62%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,380.43 ms(+3.78%)Baseline: 1,330.16 ms | 1,596.20 ms (86.48%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 3,855.22 ms(-3.35%)Baseline: 3,988.96 ms | 4,786.75 ms (80.54%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 652.88 ms(+4.76%)Baseline: 623.21 ms | 747.86 ms (87.30%) |
|
| Branch | pr/12552 |
| 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 | 2,250.70 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 684.49 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 700.84 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,158.85 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 742.94 ms |
- Rename single-letter closure params |m| to |manifest| - Wrap bare color hex references in backticks in comments - Add trailing comma in multi-line macro invocation - Use fmt::Write as _ to follow repo convention - Fix taplo formatting in Cargo.toml
- Fix by moving trailing comma from inside to the macro arg list. - Fix wrapping of and chained calls.
Before opening the store index DB, validate that non-shaN-... inputs are valid hex digests of the expected length (128 chars for sha512). Return a clear 'invalid hash format' error immediately instead of scanning the entire index with a malformed argument.
- Branch on config.frozen_store: use open_immutable for frozen stores, open_readonly_in otherwise; surface DB open errors with context. - Validate shaN- input algorithm prefix: only sha512 is supported. - Accept non-standard base64 padding via fallback to STANDARD_NO_PAD after STANDARD fails (matching Node.js leniency). - Validate decoded base64 payload is 64 bytes for sha512. - Fix should_fail_on_missing_hash test: install package first so index.db exists, then search for a non-matching hash. - Surface store-index open errors instead of mapping everything to INVALID_FILE_HASH.
336ceb9 to
25db237
Compare
|
Code review by qodo was updated up to the latest commit 25db237 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 25db237 |
find-hash printed name@version and the index key with unconditional owo_colors styling, leaking ANSI escapes into piped/captured output. pnpm's chalk disables color when stdout is not a TTY, so emit color only via if_supports_color(Stream::Stdout, ...) and route the store-derived strings through sanitize() to strip control characters. Extract the sanitize helper out of `why` into a shared cli_args::sanitize module so both commands reuse it. Also guard the find-hash success tests against vacuous assertions: the sampled row's manifest is optional, so assert the resolved name/version are non-empty before checking stdout.
|
Code review by qodo was updated up to the latest commit 5ef1d68 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 5ef1d68 |
|
Code review by qodo was updated up to the latest commit 7a50945 |
|
Code review by qodo was updated up to the latest commit 7a50945 |
Reconcile the pack command port with main's new find-hash command (#12552), which touched the same CLI wiring. - cli_args.rs: git auto-merged the non-adjacent additions, so both the Pack and FindHash commands (modules, imports, enum variants, dispatch arms) are present. - cli/Cargo.toml: union the external dependencies — main's rmp-serde and the owo-colors.workspace dotted form, plus this branch's tracing. The other incoming commits (pnpr namespace/toggles, audit, tooling) do not interact with pack. The merged workspace builds, clippy is clean, and the pack / fs-packlist / exportable-manifest tests pass. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01G4k3hPXaosUkKBPbnChg4q
Summary
Implement
pacquet find-hashbased on the requirements described in #11633 (comment).This command allows searching the package index (
v11/index.db) for packages that contain a specific file matching the given integrity hash.Squash Commit Body
Checklist
pacquet/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any published package. Keep it short and written for pnpm users — it becomes a release note.Partially written by an agent (Google Antigravity, gemini-3-1-pro).
Summary by CodeRabbit
find-hashsubcommand to search the local package store index by digest (supports hex and base64-form) and print matchingname@versionresults.