Skip to content

Commit 57014d4

Browse files
committed
fix(snapshots): preserve registry overlays in direct mode
1 parent 2423811 commit 57014d4

5 files changed

Lines changed: 43 additions & 5 deletions

File tree

‎crates/vp_cli_snapshots/tests/cli_snapshots/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ response cache. `VP_SNAP_REGISTRY_MODE=direct` restores the original routing for
170170
an independent wall-time baseline, but cannot log traffic that bypasses the
171171
local registry. Keep builds unchanged and use fresh response directories.
172172
Local tarball URLs can cause snapshot differences in comparison modes.
173-
Locally authored packages remain local in both comparison modes because no
174-
published version exists. Cases that use them must set `local-registry = true`
175-
so `direct` mode also starts their registry.
173+
Fixture overlays remain active in both comparison modes. Cases with a
174+
`mock-manifest.json` or `tarballs/` start a private registry even in `direct`
175+
mode, so fixed templates remain the same test inputs. Cases that use shared
176+
locally authored packages must set `local-registry = true` so `direct` mode
177+
also starts their registry; these packages have no published version.
176178

177179
With `VP_SNAP_ARTIFACTS_DIR` set, each runner process creates a unique `run-*`
178180
directory. `runner/timing.json` records discovery, test execution, and final
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import assert from 'node:assert/strict';
2+
import { createHash } from 'node:crypto';
3+
4+
const registry = process.env.NPM_CONFIG_REGISTRY;
5+
assert.ok(registry, 'Fixture overlay registry was not started');
6+
assert.equal(new URL(registry).hostname, '127.0.0.1');
7+
8+
const metadataResponse = await fetch(`${registry}/@vp-smoke/hello`);
9+
assert.equal(metadataResponse.status, 200);
10+
const metadata = await metadataResponse.json();
11+
assert.equal(metadata.name, '@vp-smoke/hello');
12+
assert.equal(metadata['dist-tags'].latest, '1.0.0');
13+
14+
const { dist } = metadata.versions['1.0.0'];
15+
assert.equal(new URL(dist.tarball).origin, new URL(registry).origin);
16+
const tarballResponse = await fetch(dist.tarball);
17+
assert.equal(tarballResponse.status, 200);
18+
const tarball = Buffer.from(await tarballResponse.arrayBuffer());
19+
assert.equal(`sha512-${createHash('sha512').update(tarball).digest('base64')}`, dist.integrity);
20+
console.log('Fixture metadata and tarball integrity verified');

‎crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/local_registry/snapshots.toml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ steps = [
77
{ argv = ["npm", "install", "@vp-smoke/hello", "--no-save", "--no-audit", "--no-fund"], comment = "install a package served only by the local registry", snapshot = false, continue-on-failure = true },
88
{ argv = ["vpt", "print-file", "node_modules/@vp-smoke/hello/package.json"], comment = "the local registry served the packument and its tarball (integrity verified by npm)", continue-on-failure = true },
99
]
10+
11+
[[case]]
12+
name = "local_registry_overlay"
13+
vp = "global"
14+
# No local-registry flag: fixture overlays must also work in direct mode
15+
# without opting into packed checkout packages.
16+
steps = [["node", "assert-overlay.mjs"]]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# local_registry_overlay
2+
3+
## `node assert-overlay.mjs`
4+
5+
```
6+
Fixture metadata and tarball integrity verified
7+
```

‎crates/vp_cli_snapshots/tests/cli_snapshots/main.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,8 @@ fn run_case(
13021302
case_env.get("PATH").cloned().unwrap_or_else(|| case_install.path_env.clone());
13031303

13041304
// Cases without overlays share the HTTP server, but keep package-manager
1305-
// caches isolated. Fixture overlays retain a per-case server. Neither
1306-
// registry environment changes PATH.
1305+
// caches isolated. Fixture overlays retain a per-case server in every
1306+
// mode, including direct mode. Neither registry environment changes PATH.
13071307
let registry_phase = report.phase("registry-startup");
13081308
let mut shared_bun_cache = None;
13091309
let (registry_env, registry) = if let Some(env) = shared_registry_env {
@@ -1330,6 +1330,8 @@ fn run_case(
13301330
shared_bun_cache = Some(cache);
13311331
(env, None)
13321332
} else if case.local_registry
1333+
|| stage.join("mock-manifest.json").exists()
1334+
|| stage.join("tarballs").exists()
13331335
|| std::env::var("VP_SNAP_REGISTRY_MODE").as_deref() != Ok("direct")
13341336
{
13351337
let cache_dir = std::env::var_os("VP_SNAP_REGISTRY_CACHE_DIR")

0 commit comments

Comments
 (0)