main
1// The CD post-deploy span check (scripts/cd/span-check.ts, issue #67).
2import assert from 'node:assert/strict'
3import { readFileSync } from 'node:fs'
4import { test } from 'node:test'
5import { lifecycle } from '../scripts/cd/lifecycle.ts'
6import { checkEditSpans, pollEditSpans, TRACED_EDIT_SPANS, TRACED_EDIT_STEP } from '../scripts/cd/span-check.ts'
7import { unwrapEvents, type SmokeRequest } from '../scripts/cd/telemetry.ts'
9type SpanEvent = { $metadata: { rayId: string; traceId: string; transactionName: string; spanName: string; type: string }; source: { name: string } }
11/** Real span events from a prod canary window (2026-11-01): Workers' request and fetch spans, and no ply span. */
12const PROD = unwrapEvents(JSON.parse(readFileSync(new URL('./fixtures/cd/canary-spans.json', import.meta.url), 'utf8'))) as SpanEvent[]
13const EDIT = PROD.find(event => event.source.name === 'POST' && event.$metadata.transactionName.endsWith('/v1/edit'))
14if (!EDIT) throw new Error('fixture has no POST /v1/edit span')
15const RAY = `${EDIT.$metadata.rayId}-SJC`
16const TRACE = EDIT.$metadata.traceId
18function traced(ray: string | null): SmokeRequest {
19 return { id: '11111111-1111-4111-8111-111111111111', version: 'v', step: TRACED_EDIT_STEP, status: 200, expected: [200], ray }
20}
22/** A ply span as Workers Observability would index it: same trace and ray as the request span. */
23function plySpan(name: string, i: number) {
24 return { $metadata: { id: `ply-${i}`, type: 'span', spanName: name, traceId: TRACE, rayId: EDIT && EDIT.$metadata.rayId, service: 'ply' }, source: { name } }
25}
27const PLY = TRACED_EDIT_SPANS.map(plySpan)
29test('the smoke sends edit-traced as a single-file find/replace on /v1/edit before refs-final', () => {
30 const steps = lifecycle()
31 const at = steps.findIndex(step => step.name === TRACED_EDIT_STEP)
32 const step = steps[at]
33 assert.ok(step && at < steps.findIndex(s => s.name === 'refs-final'))
34 assert.equal(step.method, 'POST')
35 assert.equal(step.path, '/v1/edit')
36 const body = step.body ? step.body({}) as Record<string, unknown> : {}
37 assert.equal(typeof body.path, 'string')
38 assert.equal(typeof body.find, 'string')
39 assert.equal('changes' in body, false, 'changes[] is git.commit, not editFile')
40})
42test('the prod trace of #67 fails: the edit was traced (POST and fetch spans) and no ply span was exported', () => {
43 const check = checkEditSpans([traced(RAY)], PROD)
44 assert.equal(check.kind, 'worker')
45 if (check.kind !== 'worker') return
46 assert.deepEqual(check.missing, [...TRACED_EDIT_SPANS])
47 assert.deepEqual(check.traceIds, [TRACE])
48 assert.ok(check.names.includes('POST') && check.names.includes('fetch'))
49 assert.match(check.line, /^spans: edit-traced \S+ trace [0-9a-f]{32} is missing ply spans git\.edit, git\.edit\.tree, git\.edit\.blob, git\.upload-pack fetch, git\.receive-pack; saw /)
50})
52test('every expected ply span in the edit\'s trace passes; the trace joins on cf-ray, then traceId', () => {
53 const check = checkEditSpans([traced(RAY)], [...PROD, ...PLY])
54 assert.equal(check.kind, 'pass')
55 assert.equal(check.line, `spans: edit-traced 11111111-1111-4111-8111-111111111111 trace ${TRACE} has ${TRACED_EDIT_SPANS.join(', ')} (${PROD.filter(e => e.$metadata.traceId === TRACE).length + PLY.length} span events)`)
56 // A ply span that carries only the trace id still counts.
57 const traceOnly = PLY.map(event => ({ ...event, $metadata: { ...event.$metadata, rayId: null } }))
58 assert.equal(checkEditSpans([traced(RAY)], [...PROD, ...traceOnly]).kind, 'pass')
59 // One missing name is named.
60 const short = checkEditSpans([traced(RAY)], [...PROD, ...PLY.filter(e => e.source.name !== 'git.edit.blob')])
61 assert.equal(short.kind, 'worker')
62 assert.match(short.line, /missing ply spans git\.edit\.blob;/)
63})
65test('a check that cannot be evaluated is a harness fault, never a pass', () => {
66 assert.equal(checkEditSpans([traced('0123456789abcdef-IAD')], PROD).kind, 'harness_fault')
67 assert.equal(checkEditSpans([traced(null)], PROD).kind, 'harness_fault')
68 assert.equal(checkEditSpans([{ ...traced(RAY), step: 'commit' }], PROD).kind, 'harness_fault')
69 assert.match(checkEditSpans([traced('0123456789abcdef-IAD')], PROD).line, /no span event joined to edit-traced .* cannot be checked/)
70})
72test('polling waits for late span events and stops at the deadline with the last verdict', async () => {
73 let clock = 0
74 const slept: number[] = []
75 let pages: unknown[][] = [PROD, PROD, [...PROD, ...PLY]]
76 let calls = 0
77 const poll = (waitMs: number) => ({
78 query: async () => pages[Math.min(calls++, pages.length - 1)] as unknown[],
79 sleep: async (ms: number) => { slept.push(ms); clock += ms },
80 now: () => clock,
81 pollsMs: [5_000, 10_000],
82 waitMs,
83 })
84 assert.equal((await pollEditSpans([traced(RAY)], poll(60_000))).kind, 'pass')
85 assert.deepEqual(slept, [5_000, 10_000])
86 // The ply spans would arrive on the fourth query; the deadline is at the third.
87 calls = 0; clock = 0; slept.length = 0
88 pages = [PROD, PROD, PROD, [...PROD, ...PLY]]
89 const late = await pollEditSpans([traced(RAY)], poll(12_000))
90 assert.equal(late.kind, 'worker')
91 assert.deepEqual(slept, [5_000, 7_000])
92 assert.equal(calls, 3)
93 // Nothing to wait for: no edit-traced request.
94 calls = 0; clock = 0; slept.length = 0
95 assert.equal((await pollEditSpans([], poll(60_000))).kind, 'harness_fault')
96 assert.deepEqual(slept, [])
97})
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 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 1020040 KiB · hit3 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=41349 git.response.cache=HIT git.response.duration_ms=3 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=526b305930b8ef382f2d7a1f9c0238730a585921 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=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2002.0 KiB · hit22 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=22 git.response.bytes=2069 git.response.cache=HIT git.response.duration_ms=22 git.fetch.wants=f87a03d2ffab5f3084c6b872988491c74b801e8d 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=2069 git.pkt.payload.max=2048 git.sideband.band1.bytes=2047 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-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e2f055d8cdfda9
- Request
- ee3fe195…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format