Buckets:
| // Copyright (c) 2026 the Zuke contributors | |
| // SPDX-License-Identifier: MIT | |
| /** | |
| * Integration: `zuke register` driven through the real CLI `main()`. Proves the | |
| * command resolves a registry from `ZUKE_REGISTRY_DIR`, writes a descriptor a | |
| * separate reader can load, keeps secrets out, and is idempotent. | |
| */ | |
| import { | |
| assertEquals, | |
| assertStringIncludes, | |
| } from "../../packages/core/tests/_assert.ts"; | |
| import { | |
| Build, | |
| FileSystemBuildRegistry, | |
| parameter, | |
| target, | |
| } from "../../packages/core/mod.ts"; | |
| import { runCli } from "./_harness.ts"; | |
| /** A build with a secret parameter and one target, registered by the tests. */ | |
| class RegBuild extends Build { | |
| apiToken = parameter("api token").secret(); | |
| lint = target().description("Lint").executes(() => {}); | |
| build = target().dependsOn(this.lint).executes(() => {}); | |
| } | |
| /** Run `fn` with a fresh temporary `ZUKE_REGISTRY_DIR`, cleaned up afterwards. */ | |
| async function withRegistryDir( | |
| fn: (dir: string) => Promise<void>, | |
| ): Promise<void> { | |
| const dir = await Deno.makeTempDir({ prefix: "zuke-reg-it-" }); | |
| const prev = Deno.env.get("ZUKE_REGISTRY_DIR"); | |
| Deno.env.set("ZUKE_REGISTRY_DIR", dir); | |
| try { | |
| await fn(dir); | |
| } finally { | |
| if (prev === undefined) Deno.env.delete("ZUKE_REGISTRY_DIR"); | |
| else Deno.env.set("ZUKE_REGISTRY_DIR", prev); | |
| await Deno.remove(dir, { recursive: true }); | |
| } | |
| } | |
| Deno.test("zuke register writes a descriptor a reader can load", async () => { | |
| await withRegistryDir(async (dir) => { | |
| const first = await runCli(RegBuild, ["register"]); | |
| assertEquals(first.code, 0); | |
| assertStringIncludes(first.out, "Registered build"); | |
| // A separate reader reconstructs the descriptor from the same directory. | |
| const registry = new FileSystemBuildRegistry(dir); | |
| const loaded = await registry.getBuild("RegBuild"); | |
| assertEquals(loaded?.descriptor.id, "RegBuild"); | |
| assertEquals( | |
| loaded?.descriptor.surface.targets.map((t) => t.name), | |
| ["lint", "build"], | |
| ); | |
| // The secret parameter is excluded entirely — neither its flag nor a value | |
| // appears anywhere in the descriptor, so it can never become an MCP input. | |
| assertEquals(loaded?.descriptor.surface.parameters, []); | |
| const raw = JSON.stringify(loaded?.descriptor); | |
| assertEquals(raw.includes("api-token"), false); | |
| assertEquals(raw.includes("apiToken"), false); | |
| const createdAt = loaded?.descriptor.createdAt; | |
| // Re-registering is idempotent: createdAt is preserved. | |
| const second = await runCli(RegBuild, ["register"]); | |
| assertEquals(second.code, 0); | |
| const reloaded = await registry.getBuild("RegBuild"); | |
| assertEquals(reloaded?.descriptor.createdAt, createdAt); | |
| assertEquals((await registry.listBuilds({})).length, 1); | |
| }); | |
| }); | |
| Deno.test("zuke register recovers from a mutex marker a killed register left behind", async () => { | |
| await withRegistryDir(async (dir) => { | |
| // A previous `zuke register` was killed mid-write: its lock marker is still | |
| // there, stamped long enough ago to be past the mutex TTL. Every later | |
| // register used to wedge and fail until a human deleted the file; the shared | |
| // mutex reclaims it instead. | |
| const marker = `${dir}/RegBuild.json.lock`; | |
| await Deno.writeTextFile(marker, String(Date.now() - 600_000)); | |
| const res = await runCli(RegBuild, ["register"]); | |
| assertEquals(res.code, 0, res.err); | |
| assertStringIncludes(res.out, "Registered build"); | |
| const loaded = await new FileSystemBuildRegistry(dir).getBuild("RegBuild"); | |
| assertEquals(loaded?.descriptor.id, "RegBuild"); | |
| // Reclaimed, held for the write, then released — not left behind again. | |
| assertEquals(await exists(marker), false); | |
| }); | |
| }); | |
| /** Whether `path` exists, for asserting a marker was cleaned up. */ | |
| async function exists(path: string): Promise<boolean> { | |
| try { | |
| await Deno.lstat(path); | |
| return true; | |
| } catch { | |
| return false; | |
| } | |
| } | |
| Deno.test("zuke register --json prints the written descriptor", async () => { | |
| await withRegistryDir(async () => { | |
| const res = await runCli(RegBuild, ["register", "--json"]); | |
| assertEquals(res.code, 0); | |
| const parsed: unknown = JSON.parse(res.out); | |
| assertEquals(parsed !== null && typeof parsed === "object", true); | |
| assertStringIncludes(res.out, '"id": "RegBuild"'); | |
| }); | |
| }); | |
Xet Storage Details
- Size:
- 4.33 kB
- Xet hash:
- 72f4c4bead34ec34ac365903ae7a2b22c2e14158c6299304caac93de8cab8ffb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.