Repository navigation
feat(pacquet): port the "ping" command - #12666
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 ChangesPing command and registry client
Workflow checkout credentials
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
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 |
PR Summary by Qodofeat(pacquet): add Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1. Ping leaks registry URL
|
| let registry_url = self.registry.as_deref().unwrap_or(&config.registry); | ||
| // Add a trailing slash before joining so a registry with a path | ||
| // prefix keeps it, matching `new URL('./-/ping', normalizedRegistryUrl)`. | ||
| let normalized_registry_url = if registry_url.ends_with('/') { | ||
| registry_url.to_owned() | ||
| } else { | ||
| format!("{registry_url}/") | ||
| }; | ||
| let ping_url = format!("{normalized_registry_url}-/ping?write=true"); | ||
| let auth_header = config.auth_headers.for_url(&normalized_registry_url); | ||
| let http_client = build_registry_client(config)?; | ||
|
|
||
| // `ping` issues a single attempt with no retries, matching pnpm's | ||
| // `retry: { retries: 0 }`. | ||
| let (time, body) = fetch_ping( | ||
| &ping_url, | ||
| &http_client, | ||
| auth_header.as_deref(), | ||
| RetryOpts { retries: 0, ..RetryOpts::default() }, | ||
| ) | ||
| .await?; | ||
|
|
||
| let mut report = format!("PING {registry_url}\nPONG {time}ms"); | ||
| if let Some(details) = format_details(&body) { | ||
| report.push_str("\nPONG "); | ||
| report.push_str(&details); | ||
| } | ||
| Ok(report) |
There was a problem hiding this comment.
1. Ping leaks registry url 🐞 Bug ⛨ Security
PingArgs::run formats the PING line using the raw registry_url, and the CLI prints it verbatim, so a registry like https://user:pass@host/ will leak embedded credentials (and other control characters) to stdout/CI logs. This bypasses the repo’s existing output-sanitization pattern used by other read-only registry commands.
Agent Prompt
## Issue description
`pacquet ping` prints the registry URL directly in the `PING ...` line. Because pacquet supports inline basic-auth in registry URLs, this can leak secrets (e.g. `https://user:pass@host/`) to terminals and CI logs. Additionally, untrusted `.npmrc`/`--registry` can carry control characters that should not reach the terminal.
## Issue Context
- `ping` currently renders `PING {registry_url}` with `registry_url` taken directly from `--registry` or config.
- The repo already has output sanitization utilities (used by `whoami`) and credential redaction utilities (used for network errors) that should be applied to this success-path output too.
## Fix Focus Areas
- pacquet/crates/cli/src/cli_args/ping.rs[38-67]
- pacquet/crates/cli/src/cli_args.rs[525-545]
- pacquet/crates/cli/src/cli_args/sanitize.rs[1-18]
- pacquet/crates/network/src/auth.rs[180-218]
## Suggested fix
- Before formatting the report, create a *display* registry string:
- apply `pacquet_network::redact_url_credentials(registry_url)` to remove any `user:pass@` userinfo
- strip terminal control characters from the display string (either reuse `cli_args::sanitize`, or introduce a variant suitable for single-line values; for a URL, also ensure `\r`/`\n` don’t allow output injection)
- Use the display string in `PING ...` (and anywhere else the registry is echoed).
- Optionally (belt-and-braces), sanitize the final printed report in `CliCommand::Ping` similarly to `CliCommand::Whoami`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
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/src/cli_args/ping.rs`:
- Around line 111-112: The body-read path in `ping.rs` currently sends the
`reqwest::Response::text()` error through `into_diagnostic()`, which can leak
credentials from the registry URL in the error display. Update the response body
read in the ping flow to match the transport-error handling used earlier in the
same function by mapping failures to `PingError::Unreachable` and passing the
message through `redact_url_credentials` before returning it. Keep the fix
localized around the `response.text().await` handling in the ping command so the
redaction behavior is consistent across all request failure paths.
🪄 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: b517b15a-955b-43a7-8cb7-56dde8a76146
📒 Files selected for processing (5)
pacquet/crates/cli/src/cli_args.rspacquet/crates/cli/src/cli_args/ping.rspacquet/crates/cli/src/cli_args/registry_client.rspacquet/crates/cli/src/cli_args/whoami.rspacquet/crates/cli/tests/ping.rs
|
Code review by qodo was updated up to the latest commit 76f399a |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12666 +/- ##
==========================================
- Coverage 87.48% 87.20% -0.29%
==========================================
Files 370 373 +3
Lines 55767 56296 +529
==========================================
+ Hits 48789 49092 +303
- Misses 6978 7204 +226 ☔ 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": 4.8372924593199995,
"stddev": 0.12071010131360045,
"median": 4.81104406412,
"user": 3.9482655600000003,
"system": 3.4967228999999995,
"min": 4.699647233119999,
"max": 5.04781244212,
"times": [
4.75270321812,
4.9085687911199996,
4.91318876612,
5.04781244212,
4.699647233119999,
4.73107992012,
4.86539318012,
4.75669494812,
4.72433763212,
4.973498462119999
]
},
{
"command": "pacquet@main",
"mean": 4.86184671832,
"stddev": 0.12799138255619838,
"median": 4.82081188812,
"user": 3.9866402599999993,
"system": 3.5444008999999994,
"min": 4.68585472512,
"max": 5.091490880119999,
"times": [
4.84862129112,
4.83123751812,
4.80420957812,
5.091490880119999,
5.02860821312,
4.68585472512,
4.81038625812,
4.79786938812,
4.74888352612,
4.97130580512
]
},
{
"command": "pnpr@HEAD",
"mean": 2.9228427467199998,
"stddev": 0.1674830306654991,
"median": 2.83610252212,
"user": 2.7015189599999996,
"system": 2.9989517999999995,
"min": 2.74247391412,
"max": 3.21847240112,
"times": [
2.8326279651200004,
2.76705854912,
2.8060980411200003,
2.74247391412,
2.83957707912,
2.81229431712,
3.0509131761200003,
3.04882154612,
3.21847240112,
3.11009047812
]
},
{
"command": "pnpr@main",
"mean": 2.8742014629200003,
"stddev": 0.09807681846557302,
"median": 2.83249715112,
"user": 2.75707306,
"system": 2.9945277,
"min": 2.8011743371200004,
"max": 3.08780663512,
"times": [
3.08780663512,
2.8011743371200004,
2.80194294212,
2.8493314521200004,
2.8156628501200003,
2.8131905171200002,
2.8833760061200002,
2.87344616912,
2.80742519512,
3.0086585251200004
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.6394936845400002,
"stddev": 0.01601764658937133,
"median": 0.6349608089400001,
"user": 0.37328482,
"system": 1.33335528,
"min": 0.62091173794,
"max": 0.66746583594,
"times": [
0.66746583594,
0.63900611694,
0.65932024594,
0.63067174894,
0.63656041894,
0.62091173794,
0.65551157594,
0.63089617594,
0.63336119894,
0.62123178994
]
},
{
"command": "pacquet@main",
"mean": 0.65847487304,
"stddev": 0.01230221821809584,
"median": 0.6589852844399999,
"user": 0.37493732,
"system": 1.33725378,
"min": 0.63763316594,
"max": 0.68042332494,
"times": [
0.68042332494,
0.67262973994,
0.66139547094,
0.65836275894,
0.63763316594,
0.65960780994,
0.64648558694,
0.6620664429399999,
0.64984856694,
0.65629586294
]
},
{
"command": "pnpr@HEAD",
"mean": 0.7036373302400001,
"stddev": 0.06824034616317312,
"median": 0.68224723044,
"user": 0.38904322,
"system": 1.3524812799999997,
"min": 0.65713821394,
"max": 0.88581950694,
"times": [
0.71976208494,
0.66177834394,
0.69484106694,
0.66435654394,
0.66517858094,
0.72300449994,
0.69109081594,
0.67340364494,
0.65713821394,
0.88581950694
]
},
{
"command": "pnpr@main",
"mean": 0.7103725248399999,
"stddev": 0.07691327169728085,
"median": 0.68354832194,
"user": 0.38267671999999997,
"system": 1.35134918,
"min": 0.67420878494,
"max": 0.92660050394,
"times": [
0.70245742794,
0.68885576094,
0.68588696194,
0.71114271194,
0.67420878494,
0.68114115594,
0.68120968194,
0.92660050394,
0.67635669994,
0.67586555894
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.744458368679998,
"stddev": 0.051690460047674774,
"median": 4.73954161648,
"user": 3.8046007600000005,
"system": 3.3990100599999997,
"min": 4.65460493498,
"max": 4.8360146869800005,
"times": [
4.8360146869800005,
4.74975689298,
4.73574043898,
4.81799931898,
4.74334279398,
4.74717368898,
4.73014493498,
4.65460493498,
4.72258590798,
4.707220087980001
]
},
{
"command": "pacquet@main",
"mean": 4.74717050598,
"stddev": 0.056289990422602416,
"median": 4.75123595098,
"user": 3.8611159599999993,
"system": 3.3817113599999997,
"min": 4.6406087749800005,
"max": 4.83623190698,
"times": [
4.73315728198,
4.77878654098,
4.739460755980001,
4.69086448498,
4.6406087749800005,
4.76301114598,
4.77254988198,
4.80124563598,
4.71578864998,
4.83623190698
]
},
{
"command": "pnpr@HEAD",
"mean": 3.1869403921800004,
"stddev": 0.11143772304953177,
"median": 3.16708924798,
"user": 2.7816105600000003,
"system": 3.19054316,
"min": 3.05075109498,
"max": 3.3506934679800002,
"times": [
3.1288155249800003,
3.3506934679800002,
3.17768277998,
3.09450622598,
3.29121529698,
3.21361243798,
3.1564957159800002,
3.34665386098,
3.05075109498,
3.05897751598
]
},
{
"command": "pnpr@main",
"mean": 3.16807530078,
"stddev": 0.07521523719882636,
"median": 3.15604137248,
"user": 2.84285606,
"system": 3.1826164599999998,
"min": 3.07182734598,
"max": 3.30588422998,
"times": [
3.20513161498,
3.15653003398,
3.30588422998,
3.11306487398,
3.21273879598,
3.25441390298,
3.10378446998,
3.07182734598,
3.15555271098,
3.10182502898
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.32041645154,
"stddev": 0.009566773205455969,
"median": 1.3168532601399998,
"user": 1.27466566,
"system": 1.6976045800000001,
"min": 1.31104781164,
"max": 1.33976376064,
"times": [
1.31372545264,
1.32853142364,
1.3167697756399999,
1.31211937664,
1.31104781164,
1.33976376064,
1.32496745764,
1.31693674464,
1.31190829664,
1.3283944156399998
]
},
{
"command": "pacquet@main",
"mean": 1.32393020824,
"stddev": 0.0350257911825021,
"median": 1.31594872864,
"user": 1.28941486,
"system": 1.68169238,
"min": 1.29403526964,
"max": 1.42015596664,
"times": [
1.3174430396399999,
1.32385420564,
1.29403526964,
1.42015596664,
1.30253199364,
1.3101819776399999,
1.31546154464,
1.32374062764,
1.31597784364,
1.31591961364
]
},
{
"command": "pnpr@HEAD",
"mean": 1.39408322994,
"stddev": 0.03441596531278615,
"median": 1.3817801806399999,
"user": 0.5590528599999999,
"system": 1.55389048,
"min": 1.36798334464,
"max": 1.48227634764,
"times": [
1.38641197064,
1.48227634764,
1.40130210064,
1.40323498264,
1.4078786696399999,
1.37097382364,
1.36798334464,
1.37059460464,
1.37714839064,
1.37302806464
]
},
{
"command": "pnpr@main",
"mean": 1.40324192744,
"stddev": 0.07094542497621835,
"median": 1.38298678814,
"user": 0.5729957600000001,
"system": 1.5467552799999997,
"min": 1.36095576864,
"max": 1.60257326464,
"times": [
1.38164583664,
1.39423467664,
1.60257326464,
1.3705196846399998,
1.37480932564,
1.38432773964,
1.3990588636399999,
1.36095576864,
1.37557943364,
1.38871468064
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.9716161693,
"stddev": 0.027052902769176053,
"median": 2.9770790516,
"user": 1.7471231399999998,
"system": 1.9466351399999997,
"min": 2.9168553371,
"max": 3.0178473231,
"times": [
2.9817253841,
2.9888158981,
2.9729065211,
2.9812515821,
2.9678725311,
2.9605509510999997,
2.9453169201,
3.0178473231,
2.9830192451,
2.9168553371
]
},
{
"command": "pacquet@main",
"mean": 2.9978082513000004,
"stddev": 0.03271246241872484,
"median": 2.9919177956,
"user": 1.7405230399999998,
"system": 1.9643912399999999,
"min": 2.9574352061,
"max": 3.0552074921,
"times": [
2.9800156291,
2.9716229331,
3.0437612901,
3.0036385991,
3.0144252530999998,
2.9574352061,
2.9801969920999998,
2.9673426391,
3.0044364791,
3.0552074921
]
},
{
"command": "pnpr@HEAD",
"mean": 1.3938316969,
"stddev": 0.017659010201707553,
"median": 1.3985452101000002,
"user": 0.56159504,
"system": 1.5509329399999998,
"min": 1.3696483081000002,
"max": 1.4129112811000002,
"times": [
1.3806865111000002,
1.3782031591000001,
1.3697265361000002,
1.3962145951000002,
1.4123050301000002,
1.4129112811000002,
1.4111704481000003,
1.4065752751,
1.4008758251000002,
1.3696483081000002
]
},
{
"command": "pnpr@main",
"mean": 1.4195993697,
"stddev": 0.10022600409343897,
"median": 1.3875537771,
"user": 0.57187784,
"system": 1.54027074,
"min": 1.3742354261,
"max": 1.7037393911000003,
"times": [
1.3922679201000001,
1.7037393911000003,
1.4045076711000002,
1.3798136371,
1.3887365301,
1.3742354261,
1.3986716731000002,
1.3828330181000001,
1.3863710241,
1.3848174061
]
}
]
} |
|
| Branch | pr/12666 |
| 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,744.46 ms(-0.23%)Baseline: 4,755.17 ms | 5,706.21 ms (83.15%) |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot 🚷 view threshold | 2,971.62 ms(-2.18%)Baseline: 3,037.73 ms | 3,645.27 ms (81.52%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,320.42 ms(-2.33%)Baseline: 1,351.90 ms | 1,622.29 ms (81.39%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,837.29 ms(+1.78%)Baseline: 4,752.46 ms | 5,702.96 ms (84.82%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 639.49 ms(-1.75%)Baseline: 650.92 ms | 781.10 ms (81.87%) |
|
| Branch | pr/12666 |
| 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 | 3,186.94 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 1,393.83 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 1,394.08 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,922.84 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 703.64 ms |
76f399a to
6993fa6
Compare
|
Code review by qodo was updated up to the latest commit 6993fa6 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 6993fa6 |
6993fa6 to
2bcdaf5
Compare
2bcdaf5 to
2cf28ad
Compare
|
Code review by qodo was updated up to the latest commit 2bcdaf5 |
|
Code review by qodo was updated up to the latest commit 2cf28ad |
1 similar comment
|
Code review by qodo was updated up to the latest commit 2cf28ad |
|
Code review by qodo was updated up to the latest commit cd2bd5e |
|
Heads-up: this PR includes a one-line change to That workflow (added in #12673) checks out the repo without The fix is the standard remediation ( Made with the help of Claude Code (Claude Opus 4.8). @zkochan fyi ^ |
|
Code review by qodo was updated up to the latest commit cd2bd5e |
|
Code review by qodo was updated up to the latest commit a6d1944 |
|
Code review by qodo was updated up to the latest commit a6d1944 |
The perfectionist::unit_test_file_layout dylint lint rejects inline
`#[cfg(test)] mod tests { ... }` blocks. Move the redact_and_sanitize
test into src/cli_args/ping/tests.rs and declare it with an external
`mod tests;`, matching the convention used by the other cli_args modules.
|
Code review by qodo was updated up to the latest commit 60ca74d |
1 similar comment
|
Code review by qodo was updated up to the latest commit 60ca74d |
Add `pacquet ping`, ported from pnpm's ping command.
`ping` GETs `<registry>-/ping?write=true` and prints pnpm's PING/PONG
report, plus a pretty-printed `PONG <details>` line when the registry
returns a non-empty JSON body. It resolves the registry from `--registry`
or the configured default, adds a trailing slash before joining so a
registry path prefix is preserved (matching pnpm's
`new URL('./-/ping', ...)`), sends the optional `Authorization` header when
one is configured (unlike whoami it does not require auth), and issues a
single attempt with no retries (pnpm's `retry: { retries: 0 }`). Timing
wraps the request and body read, matching pnpm's `Date.now()` measurement.
Both a transport failure and a non-success status map to the single
`ERR_PNPM_PING_ERROR` code with pnpm's "Failed to reach registry" message;
the transport error message is credential-redacted before it reaches
stderr / CI logs, the same precaution as whoami. Unlike whoami's username
(printed raw, hence sanitized), ping's JSON details are re-serialized
through serde_json, which escapes control characters, so no raw registry
bytes reach the terminal.
Extract the registry-client builder duplicated from whoami into a shared
`cli_args::registry_client::build_registry_client` and switch whoami to it.
---------
Co-authored-by: Zoltan Kochan <[email protected]>
Summary
Ports pnpm's
pingcommand to pacquet.pacquet pingtests connectivityto the configured registry: it GETs
<registry>-/ping?write=trueandprints
plus a pretty-printed
PONG <details>line when the registry returns anon-empty JSON body. Faithful to
ping.ts:--registryoverride with fallback to the configured default, trailing-slashnormalization that preserves a registry path prefix, an optional (not
required)
Authorizationheader, no retries (retry: { retries: 0 }), anda single
ERR_PNPM_PING_ERRORcode for both transport failures andnon-success statuses.
Also dedups the registry-client builder: whoami and ping now share
cli_args::registry_client::build_registry_clientinstead of each keepingits own copy.
Squash Commit Body
Checklist
pacquet/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.
Summary by CodeRabbit
pacquet pingcommand to verify registry connectivity and reportPING/PONGlatency.--registryoverride with URL normalization and appends pretty-printed JSON details when the registry returns non-empty JSON.pacquet ping(success, JSON details, HTTP error handling, URL construction, transport failures, and credential redaction).