Skip to content

Refuse mistyped npm dry-run flags, answer --help, roll up on every early stop, and stop passing Google credentials to cron collectors (#63) - #64

Merged
thebenignhacker merged 1 commit into
mainfrom
integrate/2026-10-07-r8
Oct 7, 2026
Merged

thebenignhacker merged 1 commit into
mainfrom
integrate/2026-10-07-r8

Conversation

@thebenignhacker

Copy link
Copy Markdown
Contributor

This pull request carries one commit. In scripts/collect-pypi-country-stats.js, --help and -h print the usage and exit 0. An npm_config_ variable whose name after that prefix, with - and _ removed, starts with dry or is within an edit distance of two of dryrun is refused with exit code 2 before a run starts, except npm_config_dry_run, which selects the dry run when it is true; any other flag given without the -- is left to npm, and the run collects as normal. The early-stop helper and the error handler in collect() call the 30-day rollup without the former daysFetched > 0 condition, so a run that stops on a cap, a refusal or an error runs the rollup whether or not it landed a day (the error handler only when the store was opened, and the rollup itself writes nothing when no day is stored); a run that ends skipped_no_credentials opens the store read-only and does not run the rollup. The cron route's collector list and environment allowlist move to lib/cron.js, and the allowlist drops GOOGLE_APPLICATION_CREDENTIALS and GOOGLE_APPLICATION_CREDENTIALS_JSON; the generate-summary.js step that follows the collectors is spawned as before, without an env option. The telemetry collector tests spawn the collector in the fixture's temporary directory, and the README and two code comments about the month-to-date figure say that, without the ledger file, a billed query that failed is not counted. The commit message carries Fixes #63, so landing it closes that issue, which lists the six follow-up items these changes correspond to.

Included

Verified on this exact tree

Commit 14ec144a485b7a1ff54680b2afd7b96cfed2ce60 on base 8784facd9e24acc0a9d5938781293aa39f362929, with Node v24.21.0 and npm 11.19.0 (the repository's workflows pin Node 24). The build, the tests and the two commands quoted below ran with an environment reduced to PATH, HOME, TMPDIR, LANG, TERM and CI=true; the install ran with PATH and HOME only.

  • Install: npm ci --no-audit --no-fund exited 0 (added 205 packages).
  • Build: npm run build (next build, Next.js 16.2.7) exited 0 with Compiled successfully and static pages (3/3).
  • Typecheck: the repository has no typecheck script and no tsconfig.json, so none was run.
  • Lint: the repository has no lint script, so none was run.
  • Changelog check: the repository has no changelog file and no changelog check, so none was run.
  • Tests: node --test --test-concurrency=4 test/*.test.js, which is the npm test command limited to four test files at a time, exited 0 over 18 test files: tests 237, pass 237, fail 0, cancelled 0, skipped 0, todo 0.
  • git status --porcelain printed nothing after the build and after the tests.
  • No test failed, so there is no pre-existing or load-related failure to report.

Cases the tests added by this commit assert, all in the run above:

  • --help, -h and --help --dry-run each exit 0, print the usage on stdout with an empty stderr, and leave the fixture directory's database, budget file and run-status file unchanged (the test compares them byte for byte before and after).
  • npm_config_dryrun=true, npm_config_dry_rn=true and npm_config_dyrrun=true each exit 2, name the variable and print the usage on stderr, and leave the same three files unchanged.
  • parseArgs returns { dryRun: false } for an environment that holds the npm_config_ variables allow_scripts, cache, global_prefix, globalconfig, init_module, local_prefix, loglevel, node_gyp, noproxy, npm_version, prefix, user_agent and userconfig together, and { dryRun: true } once npm_config_dry_run=true is added to it.
  • With one stored day whose rollup is empty and one day missing, a run that lands nothing ends with exit code 1, daysFetched 0, asOf equal to the stored day and that day's row in pypi_country_downloads, in five cases: a dry-run estimate over the per-query cap (refused_cap), a billed job refused at the byte ceiling (refused_cap), an estimate that would pass the monthly cap (capped_month), an unreadable dry-run estimate (error) and a failing billed call (error).
  • collectorEnv, given PATH, NPM_PACKAGES, GOOGLE_APPLICATION_CREDENTIALS, GOOGLE_APPLICATION_CREDENTIALS_JSON, GOOGLE_CLOUD_PROJECT and CRON_SECRET, returns only PATH and NPM_PACKAGES; each allowlisted name other than PATH, NODE_ENV and HOME appears in the source of a collector script the route runs; and the route's collector list does not contain collect-pypi-country-stats.js.
  • The telemetry collector, spawned with REGISTRY_URL removed from its environment and a .env in the fixture directory that points at the fixture server, makes one request to that server and exits 0.

Two commands run on this tree, with their output:

$ node scripts/collect-pypi-country-stats.js --help
Usage: npm run collect:pypi-countries -- [--dry-run | --help]

Without an argument it collects up to 3 missing closed days from BigQuery,
within a 128 GiB per-query cap and a 768 GiB monthly cap.

  --dry-run  measure what the next run would scan against both caps;
             bills nothing and writes nothing
  --help     print this message
(exit code 0)

$ npm run collect:pypi-countries --dryrun
npm warn Unknown cli config "--dryrun". This will stop working in the next major version of npm.

> github-analytics-tracker@1.0.0 collect:pypi-countries
> node scripts/collect-pypi-country-stats.js

Unrecognised npm option(s): npm_config_dryrun. A flag given without the -- separator goes to npm, which passed it on under that name; the dry-run flag is --dry-run.
Usage: npm run collect:pypi-countries -- [--dry-run | --help]
(exit code 2)

After the second command git status --porcelain printed nothing, with and without --ignored -- data.

Not included

None.

How to merge

Rebase and merge, so that each change stays its own commit on main.

…rly stop, and stop passing Google credentials to cron collectors (#63)

Fixes #63
@vercel

vercel Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
github-analytics-tracker Ready Ready Preview Oct 7, 2026 11:26pm UTC

Request Review

@thebenignhacker
thebenignhacker merged commit c765234 into main Oct 7, 2026
3 checks passed
@thebenignhacker
thebenignhacker deleted the integrate/2026-10-07-r8 branch October 7, 2026 23:27

This branch was successfully deployed

1 active deployment
Preview — 14ec144a Deployed Oct 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant