GitHubivarvong
ply
main
1// The unit, oracle, space and workerd suites. Fuzzers (test/fuzz/*.mjs) stay node scripts. test/workerd.test.js runs
2// the pipeline inside workerd (a devDependency) and is in CI's shards like any other file (#101).
3import { existsSync, readFileSync } from 'node:fs';
4import { relative } from 'node:path';
5import { fileURLToPath } from 'node:url';
6import { BaseSequencer, type TestSpecification } from 'vitest/node';
7import { defineConfig } from 'vitest/config';
9// Source keeps `.js` specifiers for .ts files. vitest maps them itself; plain node does not, so every process the
10// suite starts (the forks below, worker_threads the space tests spawn, `node` child processes) inherits the resolve
11// hook through NODE_OPTIONS. Set before any pool starts, so the forks get it too (harmless there).
12const hook = `--import=${fileURLToPath(new URL('./test/ts-resolve.mjs', import.meta.url))}`;
13if (!(process.env['NODE_OPTIONS'] ?? '').includes(hook)) process.env['NODE_OPTIONS'] = [process.env['NODE_OPTIONS'], hook].filter(Boolean).join(' ');
15// Every git process the suite starts is test/git-shim/git (real git with background maintenance off; the reason is
16// in that file). PATH is set here, before any pool starts, because it is what every test hands on to git.
17const shim = fileURLToPath(new URL('./test/git-shim', import.meta.url));
18if (!(process.env['PATH'] ?? '').split(':').includes(shim)) process.env['PATH'] = [shim, process.env['PATH']].filter(Boolean).join(':');
20// `--shard i/N` by measured duration, not vitest's count-based split: longest-processing-time first over
21// test/durations.json (seconds per file on a CI runner: the four test-shard logs of run 42834161805 on 6f2dd469, 2026-11-10;
22// a file added since is its local time rounded up, until the next refresh). A file with no entry
23// weighs as the heaviest known file until it is measured. The plan is a pure function of the file list and the weights,
24// so the N shards of one commit cover every file exactly once. Within a shard, files start heaviest first.
25const WEIGHTS = 'test/durations.json';
26const ROOT = fileURLToPath(new URL('.', import.meta.url));
27const weights = (): Readonly<Record<string, number>> => (existsSync(WEIGHTS) ? JSON.parse(readFileSync(WEIGHTS, 'utf8')) : {});
28const fileOf = (spec: TestSpecification): string => relative(ROOT, spec.moduleId).split('\\').join('/');
30class WeightedSequencer extends BaseSequencer {
31 override async shard(files: TestSpecification[]): Promise<TestSpecification[]> {
32 const { index, count } = this.ctx.config.shard ?? { index: 1, count: 1 };
33 const known = weights();
34 const heaviest = Math.max(1, ...Object.values(known));
35 const weighted = files.map(spec => ({ spec, file: fileOf(spec), weight: known[fileOf(spec)] ?? heaviest }))
36 .sort((a, b) => b.weight - a.weight || a.file.localeCompare(b.file));
37 const shards = Array.from({ length: count }, () => ({ specs: [] as TestSpecification[], weight: 0 }));
38 for (const { spec, weight } of weighted) {
39 let best = 0;
40 for (let i = 1; i < count; i++) if (shards[i]!.weight < shards[best]!.weight) best = i;
41 shards[best]!.specs.push(spec);
42 shards[best]!.weight += weight;
43 }
44 return shards[index - 1]!.specs;
45 }
46 override async sort(files: TestSpecification[]): Promise<TestSpecification[]> {
47 const known = weights();
48 return [...files].sort((a, b) => (known[fileOf(b)] ?? 0) - (known[fileOf(a)] ?? 0));
49 }
50}
52// Gate c (test/space/failsite-hook.mjs): with PLY_FAILSITES set, src/errors.ts is served instrumented to the test
53// files too, and each fork names its test file as the runner of what it records. Without it, nothing changes.
54const failsites = Boolean(process.env['PLY_FAILSITES']);
55const { ERRORS, instrument } = failsites ? await import('./test/space/failsite-instrument.mjs') : { ERRORS: '', instrument: (s: string): string => s };
57// `npm run coverage`: test/coverage.mjs reads V8's counts against src/*.ts byte offsets, so the files run under node's
58// own import (type stripping keeps every offset) instead of vite's module runner, and each fork flushes its counts.
59const coverage = Boolean(process.env['NODE_V8_COVERAGE']);
61export default defineConfig({
62 plugins: failsites ? [{
63 name: 'ply-failsite',
64 enforce: 'pre',
65 // same line, columns after the insertion only: no source map needed for errors.ts (its own frames are not sites)
66 transform: (code: string, id: string) => (id === ERRORS ? { code: instrument(code), map: null } : null),
67 }] : [],
68 test: {
69 // quirks-reset: no remembered per-remote quirks leak between tests (#136)
70 setupFiles: [
71 'test/quirks-reset.js',
72 ...(failsites ? ['test/space/failsite-setup.js'] : []),
73 ...(coverage ? ['test/coverage-flush.js'] : []),
74 ],
75 include: ['test/**/*.test.js'],
76 exclude: ['**/node_modules/**'],
77 // node:test had no default timeout and the space/oracle tests run for minutes; a test that needs a bound states it
78 // in its own options ({ timeout }), exactly as before. 0 disables vitest's 5 s / 10 s defaults.
79 testTimeout: 0,
80 hookTimeout: 0,
81 // One file per child process, files in parallel (node --test's model). The tests spawn git, http servers and
82 // worker_threads that load src/*.ts under node's type stripping; `forks` measured faster than `threads` here
83 // (scripts/to-vitest.mjs header, PR body) and keeps process-global state (process.on('exit'), env) per file.
84 pool: 'forks',
85 fileParallelism: true,
86 // Tests run in declaration order within a file, as under node:test.
87 sequence: { concurrent: false, sequencer: WeightedSequencer },
88 experimental: { viteModuleRunner: !coverage },
89 },
90});
Diagnostics5 git calls · 290 ms
CallStatusSizeTime0290 ms
discover200191 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=191 git.server.agent=git/github-9922ec520325-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=191 git.pkt.payload.max=36
ls-refs20012 KiB · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=11990 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=152 git.pkt.data=151 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=11990 git.pkt.payload.max=122 git.ls_refs.count=151 git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=4347 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4347 git.pkt.payload.max=4247 git.sideband.band1.bytes=4247 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=10 git.pack.bytes=4247 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400 git.pack.full=10Open pack map
fetchtree:0200919 B · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=919 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=919 git.pkt.payload.max=892 git.sideband.band1.bytes=892 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=892 git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76eOpen pack map
fetch2002.6 KiB284 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=283 git.response.bytes=2617 git.response.cache=MISS git.response.duration_ms=284 git.fetch.wants=b74f68f70d6ceb590ee5c1c8e64785aafeca97c5 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2617 git.pkt.payload.max=2590 git.sideband.band1.bytes=2590 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://github.com/ivarvong/ply
- Ref
- refs/heads/main
- Commit
- 19912563f540228593df0c489082e5e2508e21e4
- cf-ray
- a5e0e967e998a140
- Request
- 54178fad…
- Protocol
- v2 · sha1
- Agent
- git/github-9922ec520325-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format