Artifactspublic-v0

ply

main
ply4 git calls348 ms41 KiB2 cachedprotocol v2
129 lines7.1 KiBRaw
1// Fail-site recorder (gate c). Preloaded with `--import ./test/space/failsite-hook.mjs` (through NODE_OPTIONS, so every
2// process and worker thread the suite starts loads it too) when PLY_FAILSITES names a directory; a no-op otherwise.
3// It never touches src/: src/errors.ts is rewritten as it is loaded (test/space/failsite-instrument.mjs), here by a
4// module-load hook for code node loads itself, and by the vitest plugin in vitest.config.ts for code vitest transforms.
5//
6// Why a load hook and not a branch in plyError: a `globalThis` check in errors.ts would ship in every bundle and run on
7// every error; V8 coverage would also work but says only that a range ran, not through which call chain, so a wrapper
8// (`badTree(why)`, `take(..., code)`) would hide the decision that called it. A stack names every call site on the way,
9// so the wrapper's caller is recorded as the site it is.
10//
11// Reached is not judged: a test that triggers an error and asserts nothing reaches the site too. So the recorder also
12// notes which errors were looked at: the error plyError returns gets its `code` served through an accessor (same
13// value, same enumerability), and the first read made by code outside src/ (a test, a helper, node's assert) marks
14// every src/ frame of that error's stack as observed. ply reading its own error (a classifier) does not count. Only
15// `code`: `message` stays the data property it is, because a structured clone (postMessage from a worker) copies an
16// Error's message only from a data property; `code` is not cloned either way. An error whose frames are all observed already is left as plyError built it, so a space
17// that makes the same error a million times pays for the first one only.
18//
19// Records: <dir>/<pid>-<thread>-<runner>.json = { runner, platform, frames: { "src/x.ts:L:C": n }, observed: [frame] },
20// one count per src/ frame of every recorded stack, rewritten whenever the thread reaches a frame it had not reached (a vitest fork or a
21// worker thread may be stopped without an exit event) and at exit. The runner is the test file: the vitest setup file
22// (test/space/failsite-setup.js) names it and exports it as PLY_FAILSITE_RUNNER to the workers and children it starts;
23// a plain node process is its own script. test/space/holes.js maps frames to inventory sites.
24import { registerHooks } from 'node:module';
25import { writeFileSync, mkdirSync, renameSync } from 'node:fs';
26import { join, relative, isAbsolute } from 'node:path';
27import { fileURLToPath } from 'node:url';
28import { isMainThread, threadId } from 'node:worker_threads';
29import { ROOT, ERRORS_URL, KEY, instrument } from './failsite-instrument.mjs';
31const DIR = process.env.PLY_FAILSITES;
33if (DIR && !globalThis[KEY]) {
34 const out = isAbsolute(DIR) ? DIR : join(ROOT, DIR);
35 mkdirSync(out, { recursive: true });
36 const SRC = `${join(ROOT, 'src')}/`;
37 const byRunner = new Map(); // runner -> Map(frame -> n)
38 const observedBy = new Map(); // runner -> Set(frame): frames of an error whose code or message was read outside src/
39 const FRAME = /\(?((?:file:\/\/)?\/[^\s()]+):(\d+):(\d+)\)?$/;
40 const fileOf = m => (m[1].startsWith('file://') ? fileURLToPath(m[1]) : m[1]);
41 let pending = null; // the stack recorded at the head of the plyError call that is running: { r, keys }
42 let named = null;
43 const runner = () => named ?? process.env.PLY_FAILSITE_RUNNER ?? (process.argv[1] ? relative(ROOT, process.argv[1]) : '(eval)');
44 const thread = isMainThread ? 'm' : `w${threadId}`;
45 // written to a temporary name and renamed (atomic on one filesystem): a process killed mid-write (a test's timeout,
46 // a worker terminated) leaves its previous record or none, never a truncated one the gate cannot parse
47 const save = r => {
48 const file = join(out, `${process.pid}-${thread}-${r.replace(/[^\w.-]+/g, '_')}.json`);
49 writeFileSync(`${file}.tmp`, JSON.stringify({ runner: r, platform: process.platform, frames: Object.fromEntries(byRunner.get(r) ?? []), observed: [...(observedBy.get(r) ?? [])] }));
50 renameSync(`${file}.tmp`, file);
51 };
52 const recorder = holder => {
53 const limit = Error.stackTraceLimit;
54 Error.stackTraceLimit = 40;
55 const o = {};
56 Error.captureStackTrace(o, holder);
57 Error.stackTraceLimit = limit;
58 const r = runner();
59 if (!byRunner.has(r)) byRunner.set(r, new Map());
60 const frames = byRunner.get(r);
61 const seen = new Set();
62 let fresh = false;
63 // node prints file:// URLs; vitest's source-mapped stacks print paths
64 for (const line of o.stack.split('\n').slice(1)) {
65 const m = FRAME.exec(line);
66 if (!m) continue;
67 const file = fileOf(m);
68 if (!file.startsWith(SRC)) continue;
69 const key = `${relative(ROOT, file)}:${m[2]}:${m[3]}`;
70 if (seen.has(key)) continue;
71 seen.add(key);
72 if (!frames.has(key)) fresh = true;
73 frames.set(key, (frames.get(key) ?? 0) + 1);
74 }
75 pending = { r, keys: [...seen] };
76 if (fresh) save(r);
77 };
78 // the error that plyError call built. Its code is read through an accessor until code outside src/ reads it; the
79 // reader is the frame that called the accessor (one frame, captured only while still unobserved)
80 recorder.made = e => {
81 const p = pending;
82 pending = null;
83 if (!p || !p.keys.length) return e;
84 if (!observedBy.has(p.r)) observedBy.set(p.r, new Set());
85 const observed = observedBy.get(p.r);
86 if (p.keys.every(k => observed.has(k))) return e;
87 let open = true;
88 const read = getter => {
89 if (!open) return;
90 const limit = Error.stackTraceLimit;
91 Error.stackTraceLimit = 1;
92 const o = {};
93 Error.captureStackTrace(o, getter);
94 Error.stackTraceLimit = limit;
95 const m = FRAME.exec(o.stack.split('\n')[1] ?? '');
96 if (m && fileOf(m).startsWith(SRC)) return;
97 open = false;
98 let fresh = false;
99 for (const k of p.keys) if (!observed.has(k)) { observed.add(k); fresh = true; }
100 if (fresh) save(p.r);
101 };
102 for (const key of ['code']) {
103 const d = Object.getOwnPropertyDescriptor(e, key);
104 if (!d || !d.configurable || !('value' in d)) continue;
105 let value = d.value;
106 const get = () => { read(get); return value; };
107 Object.defineProperty(e, key, { enumerable: d.enumerable, configurable: true, get, set: v => { value = v; } });
108 }
109 return e;
110 };
111 // the vitest setup file names the test file this process (or thread) is running; written at once, even with no
112 // frames: the record also says which runner ran on which platform (the Linux gate)
113 recorder.runner = r => { named = r; if (!byRunner.has(r)) byRunner.set(r, new Map()); save(r); };
114 globalThis[KEY] = recorder;
115 process.on('exit', () => {
116 // a process that recorded nothing is still a record (it ran), unless it is a tool: npx, vitest's own process
117 const r = runner();
118 if (!byRunner.size && !r.startsWith('..') && !r.startsWith('node_modules')) byRunner.set(r, new Map());
119 for (const k of byRunner.keys()) save(k);
120 });
121 registerHooks({
122 load(url, context, next) {
123 const r = next(url, context);
124 if (url !== ERRORS_URL) return r;
125 const source = typeof r.source === 'string' ? r.source : new TextDecoder().decode(r.source);
126 return { ...r, source: instrument(source) };
127 },
128 });
Diagnostics4 git calls · 348 ms
CallStatusSizeTime0348 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020038 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=38434
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
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=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=38434
git.pkt.payload.max=38339
git.sideband.band1.bytes=38338
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=63
git.pack.bytes=38338
git.pack.ofs_delta=0
git.pack.ref_delta=8
git.pack.chain.max=8
git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77
git.pack.full=55
Open pack map
fetch2003.0 KiB343 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=343
git.response.bytes=3084
git.response.cache=MISS
git.response.duration_ms=343
git.fetch.wants=199c6d62f4a512fbf2bbd38e94e38f44a6a15d5b
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=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=3084
git.pkt.payload.max=3063
git.sideband.band1.bytes=3062
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://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply.git
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e1e049cdbbd96e
Request
dab4ad1f…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format