@zabaca/zbc 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -0
- package/package.json +2 -1
- package/templates/apps/inbox/package.json +1 -1
- package/templates/apps/walgit/CONTEXT.md +135 -0
- package/templates/apps/walgit/Dockerfile +40 -18
- package/templates/apps/walgit/README.md +518 -55
- package/templates/apps/walgit/e2e/README.md +100 -6
- package/templates/apps/walgit/e2e/harness.ts +262 -1
- package/templates/apps/walgit/e2e/live.ts +588 -0
- package/templates/apps/walgit/e2e/scenarios.ts +367 -5
- package/templates/apps/walgit/e2e/suite.ts +5 -5
- package/templates/apps/walgit/examples/watch.ts +209 -0
- package/templates/apps/walgit/package.json +12 -3
- package/templates/apps/walgit/registry.json +6 -11
- package/templates/apps/walgit/shared/capabilities.ts +189 -0
- package/templates/apps/walgit/shared/container-env.ts +114 -0
- package/templates/apps/walgit/shared/credentials.ts +81 -0
- package/templates/apps/walgit/shared/events.ts +277 -0
- package/templates/apps/walgit/shared/landing.ts +1241 -0
- package/templates/apps/walgit/shared/llms.ts +463 -0
- package/templates/apps/walgit/shared/outbox.ts +266 -0
- package/templates/apps/walgit/shared/policy.ts +59 -0
- package/templates/apps/walgit/shared/protocol.ts +197 -0
- package/templates/apps/walgit/shared/provenance.ts +154 -0
- package/templates/apps/walgit/shared/ref-cache.ts +181 -0
- package/templates/apps/walgit/shared/telemetry.ts +219 -0
- package/templates/apps/walgit/src/announce-main.ts +37 -0
- package/templates/apps/walgit/src/announce.ts +98 -0
- package/templates/apps/walgit/src/append-only.ts +112 -0
- package/templates/apps/walgit/src/cache.ts +172 -0
- package/templates/apps/walgit/src/cli.ts +493 -0
- package/templates/apps/walgit/src/compact.ts +25 -23
- package/templates/apps/walgit/src/delete-repo.ts +237 -0
- package/templates/apps/walgit/src/expire.ts +248 -0
- package/templates/apps/walgit/src/gc.ts +8 -16
- package/templates/apps/walgit/src/git-backend.ts +29 -0
- package/templates/apps/walgit/src/git.ts +78 -0
- package/templates/apps/walgit/src/hook-main.ts +259 -17
- package/templates/apps/walgit/src/hooks.ts +4 -3
- package/templates/apps/walgit/src/http.ts +237 -45
- package/templates/apps/walgit/src/instructions.ts +240 -0
- package/templates/apps/walgit/src/keys.ts +126 -0
- package/templates/apps/walgit/src/limits.ts +158 -0
- package/templates/apps/walgit/src/materialize.bench.ts +10 -10
- package/templates/apps/walgit/src/materialize.ts +48 -40
- package/templates/apps/walgit/src/mkdir-lock.ts +66 -0
- package/templates/apps/walgit/src/orphans.ts +2 -5
- package/templates/apps/walgit/src/pending.ts +201 -0
- package/templates/apps/walgit/src/push-cert.ts +254 -0
- package/templates/apps/walgit/src/push.ts +233 -46
- package/templates/apps/walgit/src/reconcile.ts +5 -8
- package/templates/apps/walgit/src/repo.ts +22 -77
- package/templates/apps/walgit/src/server.ts +148 -26
- package/templates/apps/walgit/src/signers.ts +577 -0
- package/templates/apps/walgit/src/store-env.ts +5 -4
- package/templates/apps/walgit/src/store.ts +47 -24
- package/templates/apps/walgit/src/usage.ts +404 -0
- package/templates/apps/walgit/src/verify.ts +171 -0
- package/templates/apps/walgit/src/wal-index.ts +189 -11
- package/templates/apps/walgit/tsconfig.json +8 -2
- package/templates/apps/walgit/tsconfig.worker.json +24 -0
- package/templates/apps/walgit/worker/events-do.ts +259 -0
- package/templates/apps/walgit/worker/index.ts +572 -0
- package/templates/apps/walgit/wrangler.jsonc +95 -0
- package/templates/apps/warehouse/package.json +1 -1
- package/templates/infra/modules/cloudflare/index.ts +77 -6
- package/templates/infra/modules/fly/index.ts +150 -10
- package/templates/infra/modules/turso/index.ts +43 -3
- package/templates/infra/package.json +1 -1
- package/templates/apps/walgit/entrypoint.sh +0 -59
- package/templates/apps/walgit/fly.toml +0 -52
- package/templates/apps/walgit/src/ssh-shell.ts +0 -36
- package/templates/apps/walgit/sshd_config +0 -38
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Signer Lists, against a walgit that is actually running.
|
|
4
|
+
*
|
|
5
|
+
* bun run e2e/live.ts --origin https://walgit.example.com # a deployment
|
|
6
|
+
* bun run e2e/live.ts --origin https://… --expect-unclaimed
|
|
7
|
+
* bun run e2e/live.ts --local # boot src/server.ts here
|
|
8
|
+
*
|
|
9
|
+
* The MECHANISM is proven in `src/push.e2e.test.ts` — claim, grant, revoke, the
|
|
10
|
+
* atomic list-and-branch steal, and the orphan assertions, all over real HTTP
|
|
11
|
+
* with real keys. Nothing here duplicates that, and this file must not grow
|
|
12
|
+
* into a second copy of it.
|
|
13
|
+
*
|
|
14
|
+
* What it proves instead is the one thing no test in the package can:
|
|
15
|
+
* **`--origin` says a DEPLOYMENT has ownership turned on.**
|
|
16
|
+
* `WALGIT_SIGNER_LISTS` is instance configuration (docs/adr/0012), so only a
|
|
17
|
+
* request to the running service can tell you the flag reached the container,
|
|
18
|
+
* that the nonce seed is there to sign against, and that a stranger is refused
|
|
19
|
+
* over the public network rather than in a test's imagination.
|
|
20
|
+
*
|
|
21
|
+
* `--local` is the same run against a node this file boots. It is a smoke test
|
|
22
|
+
* for this file — pointing it at a deployment and discovering it was broken is
|
|
23
|
+
* an expensive way to find that out — and asserts nothing about any instance.
|
|
24
|
+
*
|
|
25
|
+
* ## The two assertions
|
|
26
|
+
*
|
|
27
|
+
* They are assertions about an origin, not verbosity levels, and exactly one of
|
|
28
|
+
* them is true of any deployment that advertises signed pushes at all:
|
|
29
|
+
*
|
|
30
|
+
* - default — **this origin enforces Signer Lists.** Claims a free name,
|
|
31
|
+
* reads the list back, is refused from an unlisted key and from an unsigned
|
|
32
|
+
* push, and clones the claimed repository with no credential.
|
|
33
|
+
* - `--expect-unclaimed` — **this origin does not.** Pins the untouched path:
|
|
34
|
+
* an unsigned push to a free name lands and clones back byte-identical, a
|
|
35
|
+
* signed push from a key nothing knows lands too, and `/llms.txt` says in
|
|
36
|
+
* its own words that this host keeps no list of allowed signers.
|
|
37
|
+
*
|
|
38
|
+
* Each exits 0 only when its assertion holds, so neither can be mistaken for
|
|
39
|
+
* the other by a script. There is no mode that merely reports what it found:
|
|
40
|
+
* "whatever this deployment does is fine" is not a check.
|
|
41
|
+
*
|
|
42
|
+
* ## Exit codes
|
|
43
|
+
*
|
|
44
|
+
* | 0 | the assertion holds |
|
|
45
|
+
* | 1 | it does not, or the run could not reach the origin |
|
|
46
|
+
* | 64 | the arguments were wrong |
|
|
47
|
+
*
|
|
48
|
+
* ## What it leaves behind
|
|
49
|
+
*
|
|
50
|
+
* Repositories named `walgit-live-<random>`, on `--origin` only — under
|
|
51
|
+
* `--local` the whole node is thrown away. They are collected by the
|
|
52
|
+
* deployment's retention window if it has one; on a deployment without one they
|
|
53
|
+
* are permanent, and the claimed one is claimed forever, which is ADR-0012's
|
|
54
|
+
* own consequence rather than a defect here. The names are printed on the way
|
|
55
|
+
* out.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
import { spawn } from 'node:child_process'
|
|
59
|
+
import * as fs from 'node:fs'
|
|
60
|
+
import * as os from 'node:os'
|
|
61
|
+
import * as path from 'node:path'
|
|
62
|
+
|
|
63
|
+
import { PROVENANCE_PATH, SIGNERS_REF } from '../shared/protocol'
|
|
64
|
+
import { APP_ROOT, git, gitOk, sleep } from './harness'
|
|
65
|
+
|
|
66
|
+
// ── Arguments ───────────────────────────────────────────────────────────────
|
|
67
|
+
|
|
68
|
+
const argv = process.argv.slice(2)
|
|
69
|
+
|
|
70
|
+
function usage(problem: string): never {
|
|
71
|
+
console.error(problem)
|
|
72
|
+
console.error('')
|
|
73
|
+
console.error('usage: bun run e2e/live.ts (--origin <url> | --local) [--expect-unclaimed]')
|
|
74
|
+
console.error('')
|
|
75
|
+
console.error(' --origin <url> a running walgit; also read from WALGIT_LIVE_ORIGIN')
|
|
76
|
+
console.error(' --local boot src/server.ts with ownership on and run against it')
|
|
77
|
+
console.error(' --expect-unclaimed assert the origin does NOT enforce Signer Lists')
|
|
78
|
+
process.exit(64)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const flag = (name: string) => argv.includes(`--${name}`)
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The value after `--name`, and never the next FLAG.
|
|
85
|
+
*
|
|
86
|
+
* `--origin --expect-unclaimed` would otherwise read as an origin literally
|
|
87
|
+
* spelled `--expect-unclaimed`, and the run would die reporting a URL it could
|
|
88
|
+
* not parse rather than the argument mistake the caller actually made.
|
|
89
|
+
*/
|
|
90
|
+
const value = (name: string) => {
|
|
91
|
+
const i = argv.indexOf(`--${name}`)
|
|
92
|
+
if (i === -1) return null
|
|
93
|
+
const next = argv[i + 1]
|
|
94
|
+
if (next === undefined || next.startsWith('--')) usage(`--${name} needs a value.`)
|
|
95
|
+
return next
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (flag('help')) usage('walgit live check')
|
|
99
|
+
|
|
100
|
+
const local = flag('local')
|
|
101
|
+
const expectUnclaimed = flag('expect-unclaimed')
|
|
102
|
+
// The environment fallback is consulted only where an origin is wanted: a shell
|
|
103
|
+
// that exports `WALGIT_LIVE_ORIGIN` must not make `--local` fail as though the
|
|
104
|
+
// caller had passed a flag they did not.
|
|
105
|
+
const originArg = local ? value('origin') : (value('origin') ?? process.env.WALGIT_LIVE_ORIGIN)
|
|
106
|
+
|
|
107
|
+
if (local && originArg) usage('--local and --origin are mutually exclusive: --local IS the origin.')
|
|
108
|
+
if (!local && !originArg) usage('nothing to check: pass --origin <url> or --local.')
|
|
109
|
+
if (local && expectUnclaimed) {
|
|
110
|
+
// The local node is booted by this file with the flag on, so the assertion
|
|
111
|
+
// would be about this file's own argv rather than about a deployment.
|
|
112
|
+
usage('--expect-unclaimed is about a deployment; --local boots one with the flag ON.')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function normalizeOrigin(raw: string): string {
|
|
116
|
+
let url: URL
|
|
117
|
+
try {
|
|
118
|
+
url = new URL(raw)
|
|
119
|
+
} catch {
|
|
120
|
+
usage(`--origin ${JSON.stringify(raw)} is not a URL.`)
|
|
121
|
+
}
|
|
122
|
+
// Scheme-checked rather than assumed: git reads an origin with no scheme as a
|
|
123
|
+
// path on this disk, and would report a missing local repository.
|
|
124
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
125
|
+
usage(`--origin ${JSON.stringify(raw)} must be http or https.`)
|
|
126
|
+
}
|
|
127
|
+
return raw.replace(/\/+$/, '')
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ── Repositories, keys, and working copies ──────────────────────────────────
|
|
131
|
+
|
|
132
|
+
const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'walgit-live-'))
|
|
133
|
+
/** Names that a push actually created, so the report names nothing imaginary. */
|
|
134
|
+
const created: string[] = []
|
|
135
|
+
let node: { stop: () => void } | null = null
|
|
136
|
+
|
|
137
|
+
/** `ssh-keygen -lf` prints `<bits> SHA256:… <comment> (ED25519)`. */
|
|
138
|
+
function fingerprintOf(pub: string): string {
|
|
139
|
+
const printed = Bun.spawnSync(['ssh-keygen', '-lf', pub]).stdout.toString()
|
|
140
|
+
const found = printed.split(/\s+/).find((word) => word.startsWith('SHA256:'))
|
|
141
|
+
if (!found) throw new Error(`no fingerprint in ${JSON.stringify(printed)}`)
|
|
142
|
+
return found
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function keypair(name: string): { pub: string; fingerprint: string } {
|
|
146
|
+
const file = path.join(scratch, `key-${name}`)
|
|
147
|
+
const keygen = Bun.spawnSync(['ssh-keygen', '-t', 'ed25519', '-N', '', '-C', name, '-f', file])
|
|
148
|
+
if (keygen.exitCode !== 0) throw new Error(`ssh-keygen failed: ${keygen.stderr.toString()}`)
|
|
149
|
+
return { pub: `${file}.pub`, fingerprint: fingerprintOf(`${file}.pub`) }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const remote = (origin: string, repoId: string) => `${origin}/${repoId}.git`
|
|
153
|
+
|
|
154
|
+
/** A name no concurrent run can collide with, in the grammar `REPO_ID` allows. */
|
|
155
|
+
const freshName = () => `walgit-live-${crypto.randomUUID().replace(/-/g, '').slice(0, 12)}`
|
|
156
|
+
|
|
157
|
+
let workdirs = 0
|
|
158
|
+
|
|
159
|
+
/** An empty repository on `branch`. A failed setup step throws here, not later. */
|
|
160
|
+
async function emptyWorkdir(kind: string, branch: string): Promise<string> {
|
|
161
|
+
workdirs += 1
|
|
162
|
+
const dir = path.join(scratch, `work-${workdirs}-${kind}`)
|
|
163
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
164
|
+
await gitOk(dir, 'init', '--quiet', `--initial-branch=${branch}`)
|
|
165
|
+
return dir
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** A repository with one commit, ready to push. Never cloned — the name is new. */
|
|
169
|
+
async function workdir(kind: string, body: string): Promise<string> {
|
|
170
|
+
const dir = await emptyWorkdir(kind, 'main')
|
|
171
|
+
fs.writeFileSync(path.join(dir, 'README'), body)
|
|
172
|
+
await gitOk(dir, 'add', 'README')
|
|
173
|
+
await gitOk(dir, 'commit', '--quiet', '-m', 'live check')
|
|
174
|
+
return dir
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* A working copy of the list itself, with no history in common with anything
|
|
179
|
+
* else — because the list is its own ref, and an agent claiming a free name has
|
|
180
|
+
* nothing to clone.
|
|
181
|
+
*/
|
|
182
|
+
const listWorkdir = () => emptyWorkdir('list', 'signers')
|
|
183
|
+
|
|
184
|
+
/** Commit a `signers` file naming exactly `keys`. */
|
|
185
|
+
async function writeList(dir: string, keys: string[], message: string): Promise<void> {
|
|
186
|
+
fs.writeFileSync(path.join(dir, 'signers'), keys.map((k) => `${k}\n`).join(''))
|
|
187
|
+
await gitOk(dir, 'add', 'signers')
|
|
188
|
+
await gitOk(dir, 'commit', '--quiet', '-m', message)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const pushSigned = (dir: string, pub: string, url: string, ...refspecs: string[]) =>
|
|
192
|
+
git(
|
|
193
|
+
dir,
|
|
194
|
+
'-c',
|
|
195
|
+
'gpg.format=ssh',
|
|
196
|
+
'-c',
|
|
197
|
+
`user.signingkey=${pub}`,
|
|
198
|
+
'push',
|
|
199
|
+
'--signed=yes',
|
|
200
|
+
url,
|
|
201
|
+
...refspecs,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
// ── The local node, when there is no deployment to point at ─────────────────
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* `src/server.ts` in a child process, configured the way a deployment that has
|
|
208
|
+
* turned ownership on is configured.
|
|
209
|
+
*
|
|
210
|
+
* The seed is generated per run and the store is a directory: neither is a
|
|
211
|
+
* credential, and needing one would put this behind the thing it is meant to be
|
|
212
|
+
* runnable without. It is the same process the container runs — spawned rather
|
|
213
|
+
* than imported, so what answers is a server that read its environment once at
|
|
214
|
+
* start, exactly as the container does.
|
|
215
|
+
*/
|
|
216
|
+
async function startLocalNode(): Promise<string> {
|
|
217
|
+
// Ask the kernel for a free port and hand it straight to the child. There is
|
|
218
|
+
// a window between releasing it and the child binding it, which is why the
|
|
219
|
+
// readiness failure below names a collision as one of its two causes: a child
|
|
220
|
+
// that exits immediately did not fail to serve, it failed to listen.
|
|
221
|
+
const probe = Bun.serve({ port: 0, fetch: () => new Response('') })
|
|
222
|
+
const port = probe.port
|
|
223
|
+
probe.stop(true)
|
|
224
|
+
|
|
225
|
+
const reposDir = path.join(scratch, 'repos')
|
|
226
|
+
const storeDir = path.join(scratch, 'store')
|
|
227
|
+
fs.mkdirSync(reposDir, { recursive: true })
|
|
228
|
+
fs.mkdirSync(storeDir, { recursive: true })
|
|
229
|
+
|
|
230
|
+
// Ambient `WALGIT_*` stripped for the reason `git` is run with no global
|
|
231
|
+
// config: a shell that already exports a bucket or a retention window would
|
|
232
|
+
// make this run prove something about the machine rather than the mechanism.
|
|
233
|
+
const ambient = Object.fromEntries(
|
|
234
|
+
Object.entries(process.env).filter(([name]) => !name.startsWith('WALGIT_')),
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
const child = spawn('bun', [path.join(APP_ROOT, 'src', 'server.ts')], {
|
|
238
|
+
cwd: APP_ROOT,
|
|
239
|
+
// Its own process group, exactly as `WalgitNode` does it in harness.ts: the
|
|
240
|
+
// node forks `git-http-backend` and the hooks, and a kill that reaches only
|
|
241
|
+
// the bun process leaves them holding the port and the repos directory.
|
|
242
|
+
detached: true,
|
|
243
|
+
env: {
|
|
244
|
+
...ambient,
|
|
245
|
+
PORT: String(port),
|
|
246
|
+
WALGIT_REPOS_DIR: reposDir,
|
|
247
|
+
WALGIT_STORE_DIR: storeDir,
|
|
248
|
+
WALGIT_PUBLIC: '1',
|
|
249
|
+
WALGIT_APPEND_ONLY: '1',
|
|
250
|
+
WALGIT_SIGNER_LISTS: '1',
|
|
251
|
+
WALGIT_PUSH_CERT_SEED: crypto.randomUUID(),
|
|
252
|
+
},
|
|
253
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
254
|
+
})
|
|
255
|
+
// Registered BEFORE the wait, not after it: a node that never becomes healthy
|
|
256
|
+
// still has to be killed, and killing it has to happen before `cleanup()`
|
|
257
|
+
// deletes the repos and store directories from under a process still running.
|
|
258
|
+
node = {
|
|
259
|
+
stop: () => {
|
|
260
|
+
if (child.pid === undefined) return
|
|
261
|
+
try {
|
|
262
|
+
process.kill(-child.pid, 'SIGKILL')
|
|
263
|
+
} catch {
|
|
264
|
+
/* already gone */
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
}
|
|
268
|
+
// The node's own log, behind the same switch the suite gates its nodes on, so
|
|
269
|
+
// a passing run is the checks and nothing else.
|
|
270
|
+
child.stdout?.on('data', () => {})
|
|
271
|
+
child.stderr?.on('data', (chunk: Buffer) => {
|
|
272
|
+
if (process.env.WALGIT_E2E_VERBOSE) process.stderr.write(chunk)
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
const origin = `http://127.0.0.1:${port}`
|
|
276
|
+
const deadline = Date.now() + 20_000
|
|
277
|
+
for (;;) {
|
|
278
|
+
if (child.exitCode !== null) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
`local node exited with ${child.exitCode} — it refused to boot, or something ` +
|
|
281
|
+
`else took port ${port} between this process releasing it and the child binding it ` +
|
|
282
|
+
'(WALGIT_E2E_VERBOSE=1 to see its log)',
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
const res = await fetch(`${origin}/_walgit/health`)
|
|
287
|
+
if (res.ok) break
|
|
288
|
+
} catch {
|
|
289
|
+
// Not listening yet.
|
|
290
|
+
}
|
|
291
|
+
if (Date.now() > deadline) throw new Error(`local node never became healthy on ${origin}`)
|
|
292
|
+
await sleep(100)
|
|
293
|
+
}
|
|
294
|
+
return origin
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// ── Checks ──────────────────────────────────────────────────────────────────
|
|
298
|
+
|
|
299
|
+
let ran = 0
|
|
300
|
+
let failures = 0
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* One check, and what it OBSERVED rather than merely that it passed — the rule
|
|
304
|
+
* `e2e/suite.ts` states and this file keeps: a green tick over a weakened
|
|
305
|
+
* assertion is indistinguishable from a green tick over a real one.
|
|
306
|
+
*/
|
|
307
|
+
async function check(name: string, body: (note: (line: string) => void) => Promise<void>) {
|
|
308
|
+
const notes: string[] = []
|
|
309
|
+
ran += 1
|
|
310
|
+
try {
|
|
311
|
+
await body((line) => notes.push(line))
|
|
312
|
+
console.log(` ok ${name}`)
|
|
313
|
+
} catch (err) {
|
|
314
|
+
failures += 1
|
|
315
|
+
notes.push(`FAILED: ${(err as Error).message}`)
|
|
316
|
+
console.log(` FAIL ${name}`)
|
|
317
|
+
}
|
|
318
|
+
for (const line of notes) console.log(` ${line}`)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function must(condition: unknown, message: string): asserts condition {
|
|
322
|
+
if (!condition) throw new Error(message)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* The origin's own account of itself, which is rendered from the flags.
|
|
327
|
+
*
|
|
328
|
+
* `/llms.txt` is the WORKER's document and `GET /` is the container's, so a
|
|
329
|
+
* container-only origin (`--local`) has the second and not the first. That is
|
|
330
|
+
* reported as an absence rather than assumed away: `llms` is null only where
|
|
331
|
+
* this file knows there is no Worker in front, and a real deployment answering
|
|
332
|
+
* 404 there is a failure like any other.
|
|
333
|
+
*/
|
|
334
|
+
async function frontDoors(
|
|
335
|
+
origin: string,
|
|
336
|
+
hasWorker: boolean,
|
|
337
|
+
): Promise<{ llms: string | null; terse: string }> {
|
|
338
|
+
const terseRes = await fetch(`${origin}/`, { headers: { accept: 'text/plain' } })
|
|
339
|
+
must(terseRes.ok, `GET ${origin}/ answered ${terseRes.status}`)
|
|
340
|
+
const terse = await terseRes.text()
|
|
341
|
+
if (!hasWorker) return { llms: null, terse }
|
|
342
|
+
const llmsRes = await fetch(`${origin}/llms.txt`)
|
|
343
|
+
must(llmsRes.ok, `GET ${origin}/llms.txt answered ${llmsRes.status}`)
|
|
344
|
+
return { llms: await llmsRes.text(), terse }
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* An unsigned push to a name nobody has claimed, and a clone of it back.
|
|
349
|
+
*
|
|
350
|
+
* Run under BOTH assertions, because it is the promise ownership must not have
|
|
351
|
+
* broken: turning the flag on changes nothing for a name with no list, which is
|
|
352
|
+
* every name until someone writes one.
|
|
353
|
+
*/
|
|
354
|
+
async function anonymousPushLands(origin: string): Promise<void> {
|
|
355
|
+
await check('an unclaimed name takes an unsigned push, and clones back', async (note) => {
|
|
356
|
+
const repoId = freshName()
|
|
357
|
+
const body = `anonymous ${repoId}\n`
|
|
358
|
+
const dir = await workdir('anon', body)
|
|
359
|
+
const pushed = await git(dir, 'push', remote(origin, repoId), 'HEAD:refs/heads/main')
|
|
360
|
+
must(pushed.status === 0, `push refused (${pushed.status}):\n${pushed.out}`)
|
|
361
|
+
created.push(repoId)
|
|
362
|
+
note(`pushed to ${repoId} with no key and no credential`)
|
|
363
|
+
|
|
364
|
+
const clone = path.join(scratch, `clone-${repoId}`)
|
|
365
|
+
const cloned = await git(scratch, 'clone', '--quiet', remote(origin, repoId), clone)
|
|
366
|
+
must(cloned.status === 0, `clone failed (${cloned.status}):\n${cloned.out}`)
|
|
367
|
+
const read = fs.readFileSync(path.join(clone, 'README'), 'utf8')
|
|
368
|
+
must(read === body, `clone read back ${JSON.stringify(read)}, not ${JSON.stringify(body)}`)
|
|
369
|
+
note('cloned back byte-identical, with no credential')
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** The whole of the flag-on assertion, on one repository, in the order an agent meets it. */
|
|
374
|
+
async function ownershipEnforced(origin: string, hasWorker: boolean): Promise<void> {
|
|
375
|
+
const alice = keypair('alice')
|
|
376
|
+
const bob = keypair('bob')
|
|
377
|
+
const repoId = freshName()
|
|
378
|
+
const url = remote(origin, repoId)
|
|
379
|
+
|
|
380
|
+
await check('a real signed push claims a free name', async (note) => {
|
|
381
|
+
const list = await listWorkdir()
|
|
382
|
+
await writeList(list, [alice.fingerprint], 'claim')
|
|
383
|
+
const claimed = await pushSigned(list, alice.pub, url, `HEAD:${SIGNERS_REF}`)
|
|
384
|
+
must(claimed.status === 0, `claim refused (${claimed.status}):\n${claimed.out}`)
|
|
385
|
+
created.push(repoId)
|
|
386
|
+
note(`${repoId} claimed by ${alice.fingerprint} on ${SIGNERS_REF}`)
|
|
387
|
+
|
|
388
|
+
const ls = await git(list, 'ls-remote', url, SIGNERS_REF)
|
|
389
|
+
must(
|
|
390
|
+
ls.status === 0 && ls.out.includes(SIGNERS_REF),
|
|
391
|
+
`ls-remote did not show the list:\n${ls.out}`,
|
|
392
|
+
)
|
|
393
|
+
note('the ref reads back with `git ls-remote`, uncredentialed')
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
await check('the list reads back from the Provenance endpoint', async (note) => {
|
|
397
|
+
const res = await fetch(`${origin}${PROVENANCE_PATH}?repo=${repoId}`)
|
|
398
|
+
must(res.ok, `GET ${PROVENANCE_PATH} answered ${res.status}`)
|
|
399
|
+
const body = (await res.json()) as { claim?: { signers?: string[]; ts?: string } }
|
|
400
|
+
must(body.claim !== undefined, `no claim in ${JSON.stringify(body)}`)
|
|
401
|
+
must(
|
|
402
|
+
JSON.stringify(body.claim?.signers) === JSON.stringify([alice.fingerprint]),
|
|
403
|
+
`claim names ${JSON.stringify(body.claim?.signers)}, not [${alice.fingerprint}]`,
|
|
404
|
+
)
|
|
405
|
+
note(`claim.signers = [${alice.fingerprint}], claimed at ${body.claim?.ts}`)
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
await check("a listed key's push lands", async (note) => {
|
|
409
|
+
const dir = await workdir('alice', `alice ${repoId}\n`)
|
|
410
|
+
const pushed = await pushSigned(dir, alice.pub, url, 'HEAD:refs/heads/main')
|
|
411
|
+
must(pushed.status === 0, `refused (${pushed.status}):\n${pushed.out}`)
|
|
412
|
+
note('refs/heads/main written by the key the list names')
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
await check('an unlisted key is refused, in words an agent can act on', async (note) => {
|
|
416
|
+
const dir = await workdir('bob', `bob ${repoId}\n`)
|
|
417
|
+
const refused = await pushSigned(dir, bob.pub, url, 'HEAD:refs/heads/bob')
|
|
418
|
+
must(refused.status !== 0, `a stranger's push LANDED:\n${refused.out}`)
|
|
419
|
+
must(
|
|
420
|
+
refused.out.includes(`${repoId} is held by a Signer List`),
|
|
421
|
+
`refusal did not say the name is held:\n${refused.out}`,
|
|
422
|
+
)
|
|
423
|
+
must(
|
|
424
|
+
refused.out.includes(bob.fingerprint),
|
|
425
|
+
`refusal did not name the key that pushed:\n${refused.out}`,
|
|
426
|
+
)
|
|
427
|
+
must(
|
|
428
|
+
new RegExp(`${repoId}-[0-9a-f]{8}\\.git`).test(refused.out),
|
|
429
|
+
`refusal did not suggest a free name:\n${refused.out}`,
|
|
430
|
+
)
|
|
431
|
+
must(
|
|
432
|
+
refused.out.includes(SIGNERS_REF),
|
|
433
|
+
`refusal did not say where the list lives:\n${refused.out}`,
|
|
434
|
+
)
|
|
435
|
+
note(`refused ${bob.fingerprint}: named the key, a free name to use, and ${SIGNERS_REF}`)
|
|
436
|
+
})
|
|
437
|
+
|
|
438
|
+
await check('an unsigned push to a claimed name is refused too', async (note) => {
|
|
439
|
+
// Fail-open's one exception, and the reason it has to exist: if breaking
|
|
440
|
+
// verification landed the push, breaking it would BE the way past the gate.
|
|
441
|
+
const dir = await workdir('unsigned', `unsigned ${repoId}\n`)
|
|
442
|
+
const refused = await git(dir, 'push', url, 'HEAD:refs/heads/unsigned')
|
|
443
|
+
must(refused.status !== 0, `an unsigned push to a claimed name LANDED:\n${refused.out}`)
|
|
444
|
+
must(
|
|
445
|
+
refused.out.includes('carries no signature'),
|
|
446
|
+
`refusal did not name the missing signature:\n${refused.out}`,
|
|
447
|
+
)
|
|
448
|
+
note('refused, and told to push --signed=yes')
|
|
449
|
+
})
|
|
450
|
+
|
|
451
|
+
await check('the claimed repository is still world-readable', async (note) => {
|
|
452
|
+
const clone = path.join(scratch, `clone-claimed-${repoId}`)
|
|
453
|
+
const cloned = await git(scratch, 'clone', '--quiet', url, clone)
|
|
454
|
+
must(
|
|
455
|
+
cloned.status === 0,
|
|
456
|
+
`clone of a claimed repository failed (${cloned.status}):\n${cloned.out}`,
|
|
457
|
+
)
|
|
458
|
+
const read = fs.readFileSync(path.join(clone, 'README'), 'utf8')
|
|
459
|
+
must(read === `alice ${repoId}\n`, `clone read back ${JSON.stringify(read)}`)
|
|
460
|
+
note('cloned with no credential — reads are not gated by a claim')
|
|
461
|
+
})
|
|
462
|
+
|
|
463
|
+
await check(
|
|
464
|
+
'/llms.txt describes Signer Lists; the terse front door gains no section',
|
|
465
|
+
async (note) => {
|
|
466
|
+
const { llms, terse } = await frontDoors(origin, hasWorker)
|
|
467
|
+
if (llms === null) {
|
|
468
|
+
note("NOT CHECKED: /llms.txt is the Worker's document, and this origin is the container")
|
|
469
|
+
} else {
|
|
470
|
+
must(llms.includes('Signer List'), '/llms.txt does not mention a Signer List')
|
|
471
|
+
must(llms.includes(SIGNERS_REF), `/llms.txt does not name ${SIGNERS_REF}`)
|
|
472
|
+
must(
|
|
473
|
+
!llms.includes('keeps no list of allowed signers'),
|
|
474
|
+
'/llms.txt still says this host keeps no list of allowed signers',
|
|
475
|
+
)
|
|
476
|
+
note(`/llms.txt names ${SIGNERS_REF} and what a name that holds one refuses`)
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// ADR-0012 put discovery in `/llms.txt` and in the refusal, not here: the
|
|
480
|
+
// terse page has a byte budget, and the clause is all ownership buys on
|
|
481
|
+
// it. Pinned by the REF rather than by a heading, because any section
|
|
482
|
+
// teaching an agent to claim a name would have to name the ref to be of
|
|
483
|
+
// any use, whatever it called itself.
|
|
484
|
+
must(!terse.includes(SIGNERS_REF), `GET / grew a section: it names ${SIGNERS_REF}`)
|
|
485
|
+
must(
|
|
486
|
+
terse.includes('Unsigned is fine unless a name holds a Signer List'),
|
|
487
|
+
'GET / still promises that nothing is refused for being unsigned',
|
|
488
|
+
)
|
|
489
|
+
// The byte budget is REPORTED here and asserted in `src/llms.test.ts`,
|
|
490
|
+
// which renders this deployment's maximal policy. Asserting it here too
|
|
491
|
+
// would make an unrelated copy edit report itself as ownership being off.
|
|
492
|
+
note(`GET / is ${terse.length} bytes, carries the clause and names no ref`)
|
|
493
|
+
},
|
|
494
|
+
)
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** The flag-off assertion: the untouched path, pinned. */
|
|
498
|
+
async function ownershipAbsent(origin: string): Promise<void> {
|
|
499
|
+
await check('this host says in its own words that it keeps no list of signers', async (note) => {
|
|
500
|
+
// Always with the Worker: `--expect-unclaimed` is only ever pointed at a
|
|
501
|
+
// deployment, and `--local` boots one with the flag on.
|
|
502
|
+
const { llms, terse } = await frontDoors(origin, true)
|
|
503
|
+
// The POSITIVE sentence, not the absence of the other one. `/llms.txt` drops
|
|
504
|
+
// the whole signing section on a host with no nonce seed, so "it does not
|
|
505
|
+
// say Signer List" is also true of a deployment that has ownership ON and no
|
|
506
|
+
// seed — the misconfiguration in which every claimed name is unpushable.
|
|
507
|
+
// Requiring the sentence makes that case fail here instead of passing as
|
|
508
|
+
// "ownership is off".
|
|
509
|
+
must(llms !== null, '/llms.txt was not served')
|
|
510
|
+
must(
|
|
511
|
+
llms!.includes('keeps no list of allowed signers'),
|
|
512
|
+
'/llms.txt does not say this host keeps no list of allowed signers — either ' +
|
|
513
|
+
'ownership is ON here, or this host advertises no signed pushes at all and ' +
|
|
514
|
+
'nothing can be concluded from its front door',
|
|
515
|
+
)
|
|
516
|
+
must(!terse.includes(SIGNERS_REF), `GET / names ${SIGNERS_REF}`)
|
|
517
|
+
must(!terse.includes('Signer List'), 'GET / mentions a Signer List')
|
|
518
|
+
note(`GET / is ${terse.length} bytes and silent on ownership; /llms.txt says so outright`)
|
|
519
|
+
})
|
|
520
|
+
|
|
521
|
+
await check('a signed push from a key nothing knows lands on a free name', async (note) => {
|
|
522
|
+
const stranger = keypair('stranger')
|
|
523
|
+
const repoId = freshName()
|
|
524
|
+
const dir = await workdir('stranger', `stranger ${repoId}\n`)
|
|
525
|
+
const url = remote(origin, repoId)
|
|
526
|
+
const pushed = await pushSigned(dir, stranger.pub, url, 'HEAD:refs/heads/main')
|
|
527
|
+
must(pushed.status === 0, `refused (${pushed.status}):\n${pushed.out}`)
|
|
528
|
+
created.push(repoId)
|
|
529
|
+
note(`${stranger.fingerprint} pushed to ${repoId} with nothing registered anywhere`)
|
|
530
|
+
})
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// ── Run ─────────────────────────────────────────────────────────────────────
|
|
534
|
+
|
|
535
|
+
let cleaned = false
|
|
536
|
+
function cleanup() {
|
|
537
|
+
if (cleaned) return
|
|
538
|
+
cleaned = true
|
|
539
|
+
node?.stop()
|
|
540
|
+
fs.rmSync(scratch, { recursive: true, force: true })
|
|
541
|
+
}
|
|
542
|
+
for (const signal of ['SIGINT', 'SIGTERM'] as const) {
|
|
543
|
+
process.on(signal, () => {
|
|
544
|
+
cleanup()
|
|
545
|
+
process.exit(130)
|
|
546
|
+
})
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
try {
|
|
550
|
+
const origin = local ? await startLocalNode() : normalizeOrigin(originArg!)
|
|
551
|
+
|
|
552
|
+
const assertion = expectUnclaimed
|
|
553
|
+
? 'this origin does NOT enforce Signer Lists'
|
|
554
|
+
: 'this origin ENFORCES Signer Lists'
|
|
555
|
+
console.log(`walgit live check — ${origin}`)
|
|
556
|
+
console.log(`asserting: ${assertion}`)
|
|
557
|
+
if (local) {
|
|
558
|
+
console.log(
|
|
559
|
+
'NOTE: --local. A node this file booted, not a deployment. It exercises this ' +
|
|
560
|
+
'file against a real server and asserts nothing about any instance; the ' +
|
|
561
|
+
'mechanism itself is proven in src/push.e2e.test.ts.',
|
|
562
|
+
)
|
|
563
|
+
}
|
|
564
|
+
console.log('')
|
|
565
|
+
|
|
566
|
+
await anonymousPushLands(origin)
|
|
567
|
+
if (expectUnclaimed) await ownershipAbsent(origin)
|
|
568
|
+
else await ownershipEnforced(origin, !local)
|
|
569
|
+
|
|
570
|
+
console.log('')
|
|
571
|
+
if (!local && created.length > 0) {
|
|
572
|
+
console.log(
|
|
573
|
+
`left behind on ${origin}: ${created.join(', ')} — collected by this deployment's ` +
|
|
574
|
+
'retention window, if it has one.',
|
|
575
|
+
)
|
|
576
|
+
}
|
|
577
|
+
console.log(
|
|
578
|
+
failures > 0
|
|
579
|
+
? `FAILED — ${failures} of ${ran} checks say ${assertion} is not true of ${origin}`
|
|
580
|
+
: `PASSED — ${ran} checks, and ${assertion}`,
|
|
581
|
+
)
|
|
582
|
+
cleanup()
|
|
583
|
+
process.exit(failures > 0 ? 1 : 0)
|
|
584
|
+
} catch (err) {
|
|
585
|
+
console.error(`\nlive check could not run: ${(err as Error).message}`)
|
|
586
|
+
cleanup()
|
|
587
|
+
process.exit(1)
|
|
588
|
+
}
|