Skip to content

feat(vis): answer the downloads marshall of vis inspect natively - #262

Open
prisis wants to merge 2 commits into
nextfrom
t3/native-inspect-downloads
Open

prisis wants to merge 2 commits into
nextfrom
t3/native-inspect-downloads

Conversation

@prisis

@prisis prisis commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What

vis inspect <package> --json runs the downloads marshall natively. Base: next. This is the first of four stacked PRs: #262 (this: downloads) → #264 (archivedRepo) → #265 (signatures) → #266 (expiredDomains, which makes the default vis inspect --json native). On its own it does not make the default set native: archivedRepo and expiredDomains still run in Node.

Behaviour

  • Reads ~/.vis/cache/downloads/<encodeURIComponent(name)>.json (24 hours). Without a fresh entry it asks https://api.npmjs.org/downloads/point/last-month/<name> once, then writes {"createdAt","downloads","observedAt","ttlMs"} in the bytes JSON.stringify writes. An expired entry is removed first, as Node does.
  • Count under 20: error; under 10000: warning (Only N downloads in the past month.). A 404, any other status, or a body without a numeric downloads: one "npm stats API returned no monthly download data." warning, nothing cached.
  • The launcher gate (bin/route.mjs, INSPECT_NATIVE_MARSHALLS) accepts downloads. route.rs needs no change (it only holds the command-level entry); the routing fixture rows and native-routes.snap are updated.

Handed to Node before any output or write

A request that fails before an answer (DNS, connect, TLS, timeout), a redirect, a body that is not JSON the binary reads (including a byte-order mark), a count that is not a whole number up to 2^53, a cache entry that is not a numeric count, a cache file that is not valid JSON or has no numeric createdAt/ttlMs. Node reports a failed request as "no data" too, but whether a request fails depends on the machine, so the run stays Node's to repeat.

No environment override for the API address: the base URL is a field of the run's Context, set to the real address in production and to a loopback stub in the unit tests.

Proof

  • cargo test -p vis-cli: unit tests against a loopback stub (every status class, the exact cache bytes, stale and fresh entries, hand-overs) and the existing routing/snapshot tests. cargo fmt --all --check, cargo clippy -p vis-cli --all-targets -- -D warnings, cargo deny check clean; no dependency added.
  • __tests__/native/inspect-parity.test.ts (native vs Node, binary level): seeded fresh cache entries from 0 to 3,000,000 including a scoped name, the exit status, and hand-overs of entries Node reads through JavaScript coercion ("7", 5.5, -1; exit 70 on the declined run, nothing touched).
  • The same file runs Node with fetch replaced and asserts the findings, exit status and cache bytes for each API answer; the Rust unit tests assert the same text, so the two sides are pinned to the same bytes.
  • Once against the live API, in a scratch workspace with separate temp homes, for left-pad and @types/node: identical stdout and identical cache bytes (apart from the clock), native run without a Node fallback.
  • Unverified locally: Linux (TLS roots come from the bundled Mozilla set, as for the other HTTP commands).

🤖 Generated with Claude Code

prisis and others added 2 commits November 26, 2026 00:55
…vely

`vis inspect <package> --json --only downloads` now runs without Node. The
marshall reads the cached monthly count (`~/.vis/cache/downloads`, 24 hours) or
asks the registry's download API once, flags a count under 20 as an error and one
under 10000 as a warning, and caches a fresh count in the bytes Node writes.

An answer without a count (404, any other status, a body with no numeric
`downloads`) is the same "no monthly download data" warning and caches nothing.
Everything the binary cannot read the way Node does goes to Node before any
output or write: a request that fails before an answer, a redirect, a body that
is not JSON, a count that is not a whole number, an entry that is not a count.

The launcher gate accepts `downloads` in `--only` and in a run that disables the
other service marshalls; a run that executes `archivedRepo`, `expiredDomains` or
`signatures` still stays in Node.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…the hand-overs

Adds routing rows for `--only downloads,author` and for the default set with the
other two service marshalls switched off, regenerates the route snapshot, covers
a cached count Node reads through JavaScript coercion (a string, a fraction, a
negative number) that the binary hands over, and makes the "nothing listens"
unit test reach the transport failure instead of the address check.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5d1804d6-23a0-4dcd-b4ab-9c4baf8bef0e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@qodo-code-review

qodo-code-review Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Run inspect downloads checks natively with Node parity safeguards

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Run eligible vis inspect --json downloads checks natively, using the existing 24-hour cache and
 npm stats API.
• Preserve Node findings, exit status, and cache format; hand over requests the binary cannot
 reproduce safely.
• Extend routing and parity tests for download counts, API responses, cache behavior, and handovers.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 0 capabilities

  • Fault-specific containment limits risk to the originating changed behavior.
Behavioral complexity 🔴 High 🧩 Compatibility cases, State transitions

  • Before, Node handled API statuses, JSON parsing, cache recovery, and the final threshold finding.
  • After, Rust reproduces those decisions and selectively hands unsupported cases back to Node.
  • The new correctness conditions are that fresh, stale, missing, malformed, status-error, redirect, non-JSON, non-number, and threshold cases must agree while cache removal and writes occur in the right order.
  • The service-cache state machine is newly introduced for this marshall; no new concurrency protocol is established.
Potential damage 🟡 Medium 🩹 Incorrect results

  • Conservative damage bound for the originating changed behavior; downstream capabilities remain contained.
  • If native behavior diverges from Node, a package may receive a missing, incorrect, or incorrectly severe download finding.
  • This affects inspection output rather than package data or external registry state.
  • Reverting stops new native decisions, but an incorrect cached count may need deletion or expiry before Node produces fresh output.
  • The report can be regenerated after reverting or clearing the downloads cache; cached data is local and time-limited, so repair is needed for already-written incorrect entries.
Assessed commit 60bdb3e
Diagram

graph TD
  L["Launcher gate"] --> I["Native inspect"] --> P["Packument lookup"] --> D{"Fresh downloads cache?"} --> C["Download count"] --> R["JSON report"]
  D --> A["npm stats API"] --> C
  I --> N["Node fallback"]
  D --> N
  A --> N
Loading
High-Level Assessment

Keep the conservative native implementation. Reusing the existing inspect planning and deferred cache actions preserves report behavior, while handing ambiguous cache values and network responses to Node avoids asserting parity the binary cannot guarantee. Directly accepting those cases natively would increase divergence risk.

Files changed (9) +649 / -30

Enhancement (4) +273 / -15
route.mjsAdmit downloads through the native inspect gate +5/-4

Admit downloads through the native inspect gate

• Adds downloads to the launcher’s native marshall set. Requests requiring expiredDomains, archivedRepo, or signatures remain Node-routed.

packages/tooling/vis/bin/route.mjs

downloads.rsImplement the native downloads marshall +130/-0

Implement the native downloads marshall

• Reads or fetches monthly counts, applies the existing severity thresholds, and prepares Node-compatible 24-hour cache entries. Returns no-data warnings for responses without a count and declines cases whose behavior may differ from Node.

packages/tooling/vis/native/cli/src/inspect/downloads.rs

mod.rsWire downloads into native inspect planning +53/-11

Wire downloads into native inspect planning

• Allows downloads among native marshalls and runs it within the existing report and deferred-cache plan. Adds a production API address to the run context so tests can supply a loopback service without an environment override.

packages/tooling/vis/native/cli/src/inspect/mod.rs

service_cache.rsRead service cache entries with conservative TTL checks +85/-0

Read service cache entries with conservative TTL checks

• Introduces a cache reader that distinguishes fresh, stale, and missing entries. It declines malformed or unsupported files rather than guessing how Node would handle them.

packages/tooling/vis/native/cli/src/inspect/service_cache.rs

Refactor (1) +1 / -1
packument.rsShare scoped-name encoding with downloads +1/-1

Share scoped-name encoding with downloads

• Exposes the existing package-name encoder within inspect so the downloads cache and API use the same encoded scoped names.

packages/tooling/vis/native/cli/src/inspect/packument.rs

Tests (4) +375 / -14
inspect-parity.test.tsProve downloads parity and handover behavior +141/-13

Prove downloads parity and handover behavior

• Adds binary-level comparisons for cached counts, a scoped cache name, finding order, exit status, and counts that must go to Node. Stubbed Node API responses pin report text and cache bytes alongside the Rust tests; downloads is removed from unconditional handover cases.

packages/tooling/vis/tests/native/inspect-parity.test.ts

tests.rsTest native downloads against a loopback API +230/-0

Test native downloads against a loopback API

• Covers thresholds, request paths, response classes, exact cache bytes, stale and fresh entries, and handovers for redirects, request failures, and unsupported values. Tests also check finding order and exit status.

packages/tooling/vis/native/cli/src/inspect/tests.rs

native-routes.snapRecord the mixed downloads routing case +1/-0

Record the mixed downloads routing case

• Adds the inspect route snapshot entry for a downloads-and-author selection.

packages/tooling/vis/native/cli/tests/fixtures/native-routes.snap

routing.jsonExpect native admission for downloads selections +3/-1

Expect native admission for downloads selections

• Changes downloads-only routing to pass the launcher gate and adds mixed-marshall and default-set cases. Fixture runs still reach Node when the configured registry cannot answer.

packages/tooling/vis/native/cli/tests/fixtures/routing.json

@github-actions github-actions Bot added package: vis vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list. labels Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1)

Grey Divider


View low (1)
Informational
1. Download cache failures are reported as packument failures 🐞 Bug
Description
commit and remove in inspect/mod.rs describe every failed write or removal as "the packument
cache cannot be written/removed", and plan now adds downloads cache changes
(~/.vis/cache/downloads/<name>.json) to the same list. So when a downloads cache change fails and
the run goes to Node, the reason shown under VIS_DEBUG_DECLINE names the wrong cache directory.
Code

packages/tooling/vis/native/cli/src/inspect/mod.rs[R284-286]

+                let (found, changes) = downloads::run(client, base, &context.cache_dir, &flags.name, context.now_ms)?;
+
+                cache.extend(changes);
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`commit`/`remove` in the inspect module report every failed cache change as a packument cache failure. Since this PR they also apply changes to the downloads cache, so the reason shown when the run goes to Node is misleading.

## Fix Focus Areas
- packages/tooling/vis/native/cli/src/inspect/mod.rs[300-324]

## Recommended Fix
Change the messages to name the file, e.g. `format!("the cache file {} cannot be written: {error}", file.display())`, and do the same in `remove`, so a failure is attributed to the right cache.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Tip of the day
💡 Did you know, you can tweak Display settings with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@prisis
prisis deployed to benchmarks November 26, 2026 00:07 — with GitHub Actions Active
@github-actions github-actions Bot added the size:XL Size of the change, tests and generated files excluded. label Nov 26, 2026
@codspeed

codspeed Bot commented Nov 26, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

🆕 3 new benchmarks
⏩ 113 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 transform/transform_ts[470] N/A 355.3 µs N/A
🆕 transform/transform_ts[47000] N/A 16 ms N/A
🆕 transform/transform_ts[9400] N/A 3.3 ms N/A

Comparing t3/native-inspect-downloads (60bdb3e) with next (1078fa9)2

Open in CodSpeed

Footnotes

  1. 113 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on next (c8c3ce2) during the generation of this report, so 65c051d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

This branch was successfully deployed

1 active deployment
benchmarks — 60bdb3e1 Deployed Nov 26, 2026 by prisis via Bench native (vis) #443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: vis size:XL Size of the change, tests and generated files excluded. vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant