main
1import assert from 'node:assert/strict'
2import { readFileSync } from 'node:fs'
3import { test } from 'node:test'
4import { homedir } from 'node:os'
5import { delimiter, join } from 'node:path'
6import { defaultRunRoot, defaultTokenFile, loadConfig } from '../scripts/cd/config.ts'
7import { judgeOriginMain, nodeSatisfies, originMainReason, pathWithNodeBin, selectNode } from '../scripts/cd/preflight.ts'
9const MAIN = 'f9a3416001e0f89187cbc293738021c31a289c34'
10const HEAD = '610913e0aabbccddeeff00112233445566778899'
12test('HEAD equal to origin/main may deploy', () => {
13 assert.deepEqual(judgeOriginMain(MAIN, MAIN), { ok: true, sha: MAIN })
14})
16test('any other HEAD is not-on-origin-main', () => {
17 const result = judgeOriginMain(HEAD, MAIN)
18 assert.deepEqual(result, { ok: false, kind: 'not-on-origin-main', head: HEAD, main: MAIN })
19 if (!result.ok) assert.match(originMainReason(result), /^not-on-origin-main: HEAD .+ is not origin\/main .+/)
20})
22test('engines accept 22.23, 24.22, and 26.12, and a newer image is selected for 22.14', () => {
23 const engines = '^22.23.0 || ^24.22.0 || >=26.12.0'
24 assert.equal(nodeSatisfies('v22.23.0', engines), true)
25 assert.equal(nodeSatisfies('v22.22.9', engines), false)
26 assert.equal(nodeSatisfies('v24.22.0', engines), true)
27 assert.equal(nodeSatisfies('v24.21.9', engines), false)
28 assert.equal(nodeSatisfies('v26.12.0', engines), true)
29 assert.equal(nodeSatisfies('v26.11.9', engines), false)
30 assert.equal(nodeSatisfies('v27.0.0', engines), true)
31 assert.equal(nodeSatisfies('v22.14.0', engines), false)
32 const image = '/workspace/node-v24.22.1-linux-x64/bin/node'
33 assert.equal(selectNode('v22.14.0', [{ bin: image, version: 'v24.22.1' }], engines), image)
34 assert.equal(selectNode('v22.23.4', [{ bin: image, version: 'v24.22.1' }], engines), null)
35 assert.equal(selectNode('v22.14.0', [{ bin: image, version: null }], engines), null)
36})
38test('token file, run dir and lock have documented defaults', () => {
39 // The rotated bearer's path (2026-10-30); every run passed PLY_TOKEN_FILE=~/.config/ply/worker-token before 2026-11-08.
40 assert.equal(defaultTokenFile(), join(homedir(), '.config', 'ply', 'worker-token'))
41 assert.equal(loadConfig({}).lockPath, join(homedir(), '.local', 'state', 'ply-cd', 'deploy.lock'))
42 assert.equal(loadConfig({ PLY_CD_LOCK: '/tmp/x.lock' }).lockPath, '/tmp/x.lock')
43 assert.equal(defaultRunRoot(), join(homedir(), '.local', 'state', 'ply-cd', 'runs'))
44 const config = loadConfig({})
45 assert.equal(config.tokenFile, defaultTokenFile())
46 assert.equal(config.runRoot, defaultRunRoot())
47})
49test('the chosen node bin is placed first on PATH', () => {
50 assert.equal(pathWithNodeBin('/workspace/node-v24.22.1-linux-x64/bin/node', '/usr/bin'), `/workspace/node-v24.22.1-linux-x64/bin${delimiter}/usr/bin`)
51 assert.equal(pathWithNodeBin('/opt/node/bin/node', undefined), '/opt/node/bin')
52 const wrapper = readFileSync(new URL('../scripts/cd.sh', import.meta.url), 'utf8')
53 assert.match(wrapper, /PATH="\$node_dir\$\{PATH:\+:\$PATH\}"/)
54})
56test('a missing sha is origin-main-unavailable', () => {
57 const result = judgeOriginMain('HEAD', MAIN)
58 assert.equal(result.ok, false)
59 if (!result.ok) {
60 assert.equal(result.kind, 'origin-main-unavailable')
61 assert.match(originMainReason(result), /^origin-main-unavailable: /)
62 }
63})
Diagnostics4 git calls · 31 ms
CallStatusSizeTime031 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=3 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
fetch2001.2 KiB · hit25 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=25 git.response.bytes=1246 git.response.cache=HIT git.response.duration_ms=25 git.fetch.wants=6155eafd4ff935c738945fbb9694bfa5ba497cd9 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=1246 git.pkt.payload.max=1225 git.sideband.band1.bytes=1224 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
- a5e2f2a0686c7089
- Request
- 3eacf7a5…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format