@zabaca/zbc 0.13.0 → 0.14.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 +117 -6
- package/package.json +5 -2
- package/src/commands/add.ts +13 -0
- package/src/commands/init.ts +1 -0
- package/src/engine/apply.ts +60 -21
- package/src/engine/destroy.ts +183 -14
- package/src/engine/discover.ts +1 -1
- package/src/engine/resolve.ts +56 -11
- package/src/utils/copy-template.ts +10 -0
- package/templates/apps/inbox/package.json +3 -1
- package/templates/apps/inbox/tsconfig.json +3 -1
- package/templates/apps/inbox/worker/api.ts +197 -0
- package/templates/apps/inbox/worker/commands.ts +299 -0
- package/templates/apps/inbox/worker/inbox-do.ts +53 -10
- package/templates/apps/inbox/worker/index.ts +15 -202
- package/templates/apps/inbox/worker/mcp.ts +49 -100
- package/templates/infra/modules/cloudflare/index.ts +25 -70
- package/templates/infra/modules/cloudflare-access/index.ts +3 -3
- package/templates/infra/modules/cloudflare-api/index.ts +144 -32
- package/templates/infra/modules/cloudflare-api/registry.json +1 -1
- package/templates/infra/modules/cloudflare-email/index.ts +103 -144
- package/templates/infra/modules/cloudflare-email/registry.json +1 -1
- package/templates/infra/modules/cloudflare-token/index.ts +10 -30
- package/templates/infra/modules/cloudflare-token/registry.json +1 -1
- package/templates/infra/modules/cloudflare-tunnel/index.ts +3 -3
- package/templates/infra/modules/cloudflare-zone/index.ts +2 -2
- package/templates/infra/modules/fly/index.ts +17 -34
- package/templates/infra/modules/host-file/index.ts +6 -7
- package/templates/infra/modules/provision-core/index.ts +21 -15
- package/templates/infra/modules/r2/index.ts +38 -55
- package/templates/infra/modules/r2/registry.json +1 -1
- package/templates/infra/modules/remote-provision/index.ts +1 -3
- package/templates/infra/modules/turso/index.ts +2 -4
- package/templates/infra/modules/vm-provision/index.ts +10 -3
- package/templates/infra/src/context.ts +115 -0
- package/templates/infra/src/define-module.ts +8 -2
- package/templates/infra/src/index.ts +11 -1
- package/templates/infra/src/types.ts +72 -3
- package/src/commands/add-registry.test.ts +0 -92
- package/src/commands/secret.test.ts +0 -717
- package/src/commands/vendor-mode.test.ts +0 -183
- package/src/infra-types.ts +0 -38
- package/src/utils/subtree.test.ts +0 -127
- package/templates/apps/inbox/worker/send-op.ts +0 -174
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { afterEach, expect, test } from 'bun:test'
|
|
2
|
-
import { spawnSync } from 'node:child_process'
|
|
3
|
-
import * as fs from 'node:fs'
|
|
4
|
-
import * as os from 'node:os'
|
|
5
|
-
import * as path from 'node:path'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* `zbc add <unknown>` tells the caller what it could have asked for, and that
|
|
9
|
-
* sentence is the only place the built-in registry is enumerated for a human.
|
|
10
|
-
*
|
|
11
|
-
* It was a hand-written literal, and it went stale the first time modules were
|
|
12
|
-
* added to `templates/infra/modules/` — the four host primitives contributed
|
|
13
|
-
* contributed later resolved perfectly well and were named nowhere, so
|
|
14
|
-
* the only way to discover them was to already know they existed. Every other
|
|
15
|
-
* "Available:" in this CLI computes its list (`apply.ts`, `destroy.ts`,
|
|
16
|
-
* `engine/resolve.ts` all join a live array); this one is now the same shape,
|
|
17
|
-
* and this file is what stops it drifting back.
|
|
18
|
-
*
|
|
19
|
-
* The census is walked here with `readdirSync`, where the implementation globs
|
|
20
|
-
* through `Bun.file(...).exists()`. Two different mechanisms on purpose: a test
|
|
21
|
-
* that recomputed the implementation would agree with it while both were wrong.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
const CLI = path.resolve(import.meta.dir, '../index.ts')
|
|
25
|
-
const MODULES = path.resolve(import.meta.dir, '../../templates/infra/modules')
|
|
26
|
-
const APPS = path.resolve(import.meta.dir, '../../templates/apps')
|
|
27
|
-
|
|
28
|
-
const roots: string[] = []
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
for (const r of roots.splice(0)) fs.rmSync(r, { recursive: true, force: true })
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
/** Directories holding a registry.json — what `zbc add` can actually resolve. */
|
|
34
|
-
function census(dir: string): string[] {
|
|
35
|
-
return fs
|
|
36
|
-
.readdirSync(dir, { withFileTypes: true })
|
|
37
|
-
.filter((e) => e.isDirectory() && fs.existsSync(path.join(dir, e.name, 'registry.json')))
|
|
38
|
-
.map((e) => e.name)
|
|
39
|
-
.toSorted()
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** The smallest tree `zbc add` will get as far as resolution in. */
|
|
43
|
-
function project(): string {
|
|
44
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'zbc-add-registry-'))
|
|
45
|
-
roots.push(dir)
|
|
46
|
-
fs.writeFileSync(
|
|
47
|
-
path.join(dir, 'zbc.config.ts'),
|
|
48
|
-
"export default { project: 'p', environments: ['production'] }\n",
|
|
49
|
-
)
|
|
50
|
-
fs.mkdirSync(path.join(dir, 'packages/infra'), { recursive: true })
|
|
51
|
-
fs.writeFileSync(path.join(dir, 'packages/infra/package.json'), '{"name":"@p/infra"}\n')
|
|
52
|
-
return dir
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** citty wraps and colours its error line, so flatten before matching — a
|
|
56
|
-
* line-oriented match cannot see a claim that wrapped. */
|
|
57
|
-
function addUnknown(): string {
|
|
58
|
-
const res = spawnSync('bun', [CLI, 'add', 'no-such-module', '--no-prompt'], {
|
|
59
|
-
cwd: project(),
|
|
60
|
-
encoding: 'utf8',
|
|
61
|
-
})
|
|
62
|
-
expect(res.status).not.toBe(0)
|
|
63
|
-
return `${res.stdout}\n${res.stderr}`.replace(/\s+/g, ' ')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
test('the built-in registry census is non-empty and holds the promoted host primitives', () => {
|
|
67
|
-
const modules = census(MODULES)
|
|
68
|
-
const apps = census(APPS)
|
|
69
|
-
// Floors, because every assertion below is vacuously true against an empty
|
|
70
|
-
// walk — a mistyped MODULES would otherwise pass silently.
|
|
71
|
-
expect(modules.length).toBeGreaterThanOrEqual(12)
|
|
72
|
-
expect(apps.length).toBeGreaterThanOrEqual(3)
|
|
73
|
-
// Named rather than counted: the group this file exists because of.
|
|
74
|
-
expect(modules).toContain('host-dir')
|
|
75
|
-
expect(modules).toContain('host-exec')
|
|
76
|
-
expect(modules).toContain('host-symlink')
|
|
77
|
-
expect(modules).toContain('systemd-mask')
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
test('`zbc add <unknown>` names every module and app it could have resolved', () => {
|
|
81
|
-
const expected = [...census(MODULES), ...census(APPS)].toSorted()
|
|
82
|
-
const listed = addUnknown()
|
|
83
|
-
.match(/Available: ([^.]+)\./)?.[1]
|
|
84
|
-
.split(',')
|
|
85
|
-
.map((s) => s.trim())
|
|
86
|
-
.toSorted()
|
|
87
|
-
|
|
88
|
-
// Set equality, not substring containment: "cloudflare" is a prefix of
|
|
89
|
-
// "cloudflare-token", so a `toContain` sweep passes on a list missing the
|
|
90
|
-
// short name entirely.
|
|
91
|
-
expect(listed).toEqual(expected)
|
|
92
|
-
})
|