|
| 1 | +import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; |
| 2 | +import { tmpdir } from "node:os"; |
| 3 | +import { join } from "node:path"; |
| 4 | +import { afterEach, beforeEach, describe, expect, it } from "vitest"; |
| 5 | + |
| 6 | +import { parseFrontmatter } from "../../src/install/frontmatter"; |
| 7 | +import { |
| 8 | + applyInstallPlan, |
| 9 | + buildInstallPlan, |
| 10 | + getEmbeddedCommands, |
| 11 | + getEmbeddedSkills, |
| 12 | +} from "../../src/install/install"; |
| 13 | +import { |
| 14 | + buildInvocation, |
| 15 | + isProductionInvocation, |
| 16 | +} from "../../src/util/invocation"; |
| 17 | + |
| 18 | +/** |
| 19 | + * End-to-end companion to `test/stub-description-invocation.test.ts`, run |
| 20 | + * under the `nightly` vitest project (see `vite.config.ts`) so |
| 21 | + * `__TASKLESS_CLI__` is a real pinned `@taskless/cli-nightly@<version>` |
| 22 | + * define, exactly as `build:nightly` produces — not something reachable under |
| 23 | + * this repo's default prod define. |
| 24 | + * |
| 25 | + * taskless/cli#298: a `.claude`/`.agents` stub's frontmatter `description` is |
| 26 | + * copied verbatim from the embedded skill/command source (see `writeSkill` / |
| 27 | + * `writeCommand` in `src/install/install.ts`) and is NEVER passed through |
| 28 | + * `applyCliInvocation` — only a canonical `.taskless/` file gets that rewrite. |
| 29 | + * Before the fix, a description that named the CLI invocation would freeze a |
| 30 | + * stale, unpinned `npx @taskless/cli` reference into every `.claude` stub |
| 31 | + * forever, even though the canonical `.taskless/skills/taskless/SKILL.md` |
| 32 | + * written by the SAME install correctly names this build's pinned nightly. |
| 33 | + * |
| 34 | + * This drives that divergence the way the issue describes it — a real |
| 35 | + * `applyInstallPlan` under a nightly define — without installing the actual |
| 36 | + * `@taskless/cli-nightly` package, which is blocked by a deny rule in this |
| 37 | + * repo. |
| 38 | + */ |
| 39 | +describe("installing a nightly writes a stub description that names no CLI package", () => { |
| 40 | + let cwd: string; |
| 41 | + |
| 42 | + beforeEach(async () => { |
| 43 | + expect(isProductionInvocation()).toBe(false); |
| 44 | + expect(buildInvocation()).toContain("@taskless/cli-nightly@"); |
| 45 | + |
| 46 | + cwd = await mkdtemp(join(tmpdir(), "taskless-nightly-stub-description-")); |
| 47 | + await mkdir(join(cwd, ".taskless"), { recursive: true }); |
| 48 | + await writeFile( |
| 49 | + join(cwd, ".taskless", "taskless.json"), |
| 50 | + JSON.stringify({ version: 2, install: {} }), |
| 51 | + "utf8" |
| 52 | + ); |
| 53 | + }); |
| 54 | + |
| 55 | + afterEach(async () => { |
| 56 | + await rm(cwd, { recursive: true, force: true }); |
| 57 | + }); |
| 58 | + |
| 59 | + const skillStubPath = () => |
| 60 | + join(cwd, ".claude", "skills", "taskless", "SKILL.md"); |
| 61 | + const commandStubPath = () => |
| 62 | + join(cwd, ".claude", "commands", "tskl", "tskl.md"); |
| 63 | + const canonicalSkillPath = () => |
| 64 | + join(cwd, ".taskless", "skills", "taskless", "SKILL.md"); |
| 65 | + |
| 66 | + async function install(): Promise<void> { |
| 67 | + const skills = getEmbeddedSkills(); |
| 68 | + const commands = getEmbeddedCommands(); |
| 69 | + const plan = buildInstallPlan([".claude"], skills, commands); |
| 70 | + await applyInstallPlan(cwd, plan, { cliVersion: "0.0.0-nightly.test" }); |
| 71 | + } |
| 72 | + |
| 73 | + it("names no CLI package in the stub's frontmatter description", async () => { |
| 74 | + await install(); |
| 75 | + |
| 76 | + const skillDescription = parseFrontmatter( |
| 77 | + await readFile(skillStubPath(), "utf8") |
| 78 | + ).data.description as string; |
| 79 | + const commandDescription = parseFrontmatter( |
| 80 | + await readFile(commandStubPath(), "utf8") |
| 81 | + ).data.description as string; |
| 82 | + |
| 83 | + // Not the released package, and not this build's own pinned nightly |
| 84 | + // either — the fix is that description names no package at all, so there |
| 85 | + // is nothing left to go stale on a later, differently-pinned install. |
| 86 | + expect(skillDescription).not.toMatch(/@taskless\/cli/); |
| 87 | + expect(commandDescription).not.toMatch(/@taskless\/cli/); |
| 88 | + }); |
| 89 | + |
| 90 | + it("still correctly pins the canonical file's own invocation", async () => { |
| 91 | + await install(); |
| 92 | + |
| 93 | + // Contrast case: the canonical `.taskless/` copy IS rewritten per build, |
| 94 | + // which is what makes the stub's staleness invisible without this test — |
| 95 | + // the canonical file looks completely correct. |
| 96 | + const canonical = await readFile(canonicalSkillPath(), "utf8"); |
| 97 | + expect(canonical).toContain(buildInvocation()); |
| 98 | + expect(canonical).not.toContain("npx @taskless/cli agent"); |
| 99 | + }); |
| 100 | + |
| 101 | + it("a second install pinned to a different nightly leaves the stub unchanged", async () => { |
| 102 | + await install(); |
| 103 | + const first = await readFile(skillStubPath(), "utf8"); |
| 104 | + |
| 105 | + // Re-running install (same build, so same pin) must not rewrite a stub |
| 106 | + // whose description never carried a version to begin with. |
| 107 | + await install(); |
| 108 | + expect(await readFile(skillStubPath(), "utf8")).toBe(first); |
| 109 | + }); |
| 110 | +}); |
0 commit comments