From 259a4a4e184ecaddebf01822e3ce964c7174cbc2 Mon Sep 17 00:00:00 2001 From: troioi-vn Date: Tue, 24 Nov 2026 15:55:09 +0700 Subject: [PATCH 1/2] fix: keep the ClawHub checkout out of repository-root skills --- .github/workflows/skill-publish.yml | 10 +- .../security/skill-publish-workflow.test.ts | 117 ++++++++++++------ src/__tests__/skill-publish-workflow.test.ts | 21 ++++ 3 files changed, 108 insertions(+), 40 deletions(-) diff --git a/.github/workflows/skill-publish.yml b/.github/workflows/skill-publish.yml index ff286edee3..be2421304a 100644 --- a/.github/workflows/skill-publish.yml +++ b/.github/workflows/skill-publish.yml @@ -158,8 +158,14 @@ jobs: ref: ${{ steps.clawhub_source.outputs.ref }} path: clawhub-source + # actions/checkout only writes inside the caller's workspace. A skill published from the + # repository root (skill_path: ".") would then contain this checkout and upload it as + # skill files, so move it out before anything is installed into it. + - name: Move ClawHub source out of the caller workspace + run: mv "$GITHUB_WORKSPACE/clawhub-source" "$RUNNER_TEMP/clawhub-source" + - name: Install ClawHub CLI dependencies - working-directory: clawhub-source + working-directory: ${{ runner.temp }}/clawhub-source run: bun install --frozen-lockfile - name: Validate publish mode inputs @@ -224,7 +230,7 @@ jobs: from pathlib import Path workspace = Path(os.environ["GITHUB_WORKSPACE"]).resolve() - cli_entry = workspace / "clawhub-source" / "packages" / "clawhub" / "src" / "cli.ts" + cli_entry = Path(os.environ["RUNNER_TEMP"]) / "clawhub-source" / "packages" / "clawhub" / "src" / "cli.ts" if not cli_entry.is_file(): raise SystemExit(f"Missing ClawHub CLI entrypoint at {cli_entry}") diff --git a/scripts/security/skill-publish-workflow.test.ts b/scripts/security/skill-publish-workflow.test.ts index 5eadfe11c6..9e08a3545b 100644 --- a/scripts/security/skill-publish-workflow.test.ts +++ b/scripts/security/skill-publish-workflow.test.ts @@ -1,7 +1,7 @@ /* @vitest-environment node */ import { spawnSync } from "node:child_process"; import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; -import { join } from "node:path"; +import { join, relative } from "node:path"; import { describe, expect, it } from "vitest"; import { parse as parseYaml } from "yaml"; @@ -11,56 +11,80 @@ const workflow = parseYaml(readFileSync(".github/workflows/skill-publish.yml", " const publishStep = workflow.jobs.publish.steps.find( (step: { name?: string }) => step.name === "Run skill publishes", ); +const moveStep = workflow.jobs.publish.steps.find( + (step: { name?: string }) => step.name === "Move ClawHub source out of the caller workspace", +); -function runPublish(stdout: string) { +function runPublish(stdout: string, { skillPath = "" } = {}) { mkdirSync(".artifacts", { recursive: true }); - const workspace = mkdtempSync(join(process.cwd(), ".artifacts/skill-publish-test-")); + const root = mkdtempSync(join(process.cwd(), ".artifacts/skill-publish-test-")); try { - const bin = join(workspace, "bin"); + // Separate dirs, as on a real runner. actions/checkout puts the ClawHub source inside the + // caller's workspace; the workflow must move it to RUNNER_TEMP before publishing, or a skill + // at the repository root uploads it as its own files. + const workspace = join(root, "workspace"); + const runnerTemp = join(root, "runner-temp"); + mkdirSync(runnerTemp, { recursive: true }); + const bin = join(root, "bin"); mkdirSync(bin); const fakeBun = join(bin, "bun"); writeFileSync( fakeBun, - '#!/usr/bin/env python3\nimport os\nprint(os.environ["PUBLISH_TEST_STDOUT"])\n', + [ + "#!/usr/bin/env python3", + "import json, os, sys", + 'seen = {"argv": sys.argv[1:], "checkoutInWorkspace": os.path.exists("clawhub-source")}', + 'open(os.environ["PUBLISH_TEST_SEEN"], "w").write(json.dumps(seen))', + 'print(os.environ["PUBLISH_TEST_STDOUT"])', + "", + ].join("\n"), ); chmodSync(fakeBun, 0o755); - mkdirSync(join(workspace, "skills", "demo"), { recursive: true }); - writeFileSync(join(workspace, "skills", "demo", "SKILL.md"), "# Demo\n"); + const skillDir = skillPath ? join(workspace, skillPath) : join(workspace, "skills", "demo"); + mkdirSync(skillDir, { recursive: true }); + writeFileSync(join(skillDir, "SKILL.md"), "# Demo\n"); + const seenFile = join(runnerTemp, "bun-seen.json"); const cliDir = join(workspace, "clawhub-source", "packages", "clawhub", "src"); mkdirSync(cliDir, { recursive: true }); writeFileSync(join(cliDir, "cli.ts"), "// CLI subprocess is a receipt fixture.\n"); - if (!publishStep?.run) throw new Error("Missing skill publish workflow step"); - const child = spawnSync("bash", ["-c", publishStep.run], { - cwd: workspace, - encoding: "utf8", - env: { - ...process.env, - PATH: `${bin}:${process.env.PATH}`, - GITHUB_WORKSPACE: workspace, - RUNNER_TEMP: workspace, - INPUT_SKILL_PATH: "", - INPUT_ROOT: "skills", - INPUT_DRY_RUN: "false", - INPUT_OWNER: "", - INPUT_TAGS: "", - INPUT_CHANGELOG: "", - INPUT_CATEGORIES: "", - INPUT_TOPICS: "", - INPUT_CLEAR_CATEGORIES: "false", - INPUT_CLEAR_TOPICS: "false", - INPUT_SITE: "https://example.invalid", - INPUT_REGISTRY: "https://example.invalid", - INPUT_REF: "", - SOURCE_REF: "refs/heads/main", - SOURCE_REPOSITORY: "fixture/demo", - PUBLISH_TEST_STDOUT: stdout, - }, - }); - if (child.error) throw child.error; - const output = JSON.parse(readFileSync(join(workspace, "skill-publish.json"), "utf8")); - return { status: child.status, output }; + if (!publishStep?.run || !moveStep?.run) throw new Error("Missing skill publish workflow step"); + const env = { + ...process.env, + PATH: `${bin}:${process.env.PATH}`, + GITHUB_WORKSPACE: workspace, + RUNNER_TEMP: runnerTemp, + INPUT_SKILL_PATH: skillPath, + INPUT_ROOT: "skills", + INPUT_DRY_RUN: "false", + INPUT_OWNER: "", + INPUT_TAGS: "", + INPUT_CHANGELOG: "", + INPUT_CATEGORIES: "", + INPUT_TOPICS: "", + INPUT_CLEAR_CATEGORIES: "false", + INPUT_CLEAR_TOPICS: "false", + INPUT_SITE: "https://example.invalid", + INPUT_REGISTRY: "https://example.invalid", + INPUT_REF: "", + SOURCE_REF: "refs/heads/main", + SOURCE_REPOSITORY: "fixture/demo", + PUBLISH_TEST_STDOUT: stdout, + PUBLISH_TEST_SEEN: seenFile, + }; + let status: number | null = null; + for (const step of [moveStep, publishStep]) { + const child = spawnSync("bash", ["-c", step.run], { cwd: workspace, encoding: "utf8", env }); + if (child.error) throw child.error; + if (step === publishStep) status = child.status; + } + const output = JSON.parse(readFileSync(join(runnerTemp, "skill-publish.json"), "utf8")); + const seen = JSON.parse(readFileSync(seenFile, "utf8")) as { + argv: string[]; + checkoutInWorkspace: boolean; + }; + return { status, output, seen, workspace }; } finally { - rmSync(workspace, { recursive: true, force: true }); + rmSync(root, { recursive: true, force: true }); } } @@ -87,4 +111,21 @@ describe("skill publish workflow receipts", () => { expect(result.output.ok).toBe(false); expect(result.output.summary.failed).toBe(1); }); + + it("publishes a repository-root skill with the CLI outside the caller workspace", () => { + const receipt = { + status: "published", + slug: "demo", + version: "1.0.0", + attemptId: "fixture-attempt", + }; + const result = runPublish(JSON.stringify(receipt), { skillPath: "." }); + expect(result.status).toBe(0); + expect(result.output.published).toEqual([receipt]); + expect(result.seen.checkoutInWorkspace).toBe(false); + const [cliEntry, , workdir] = result.seen.argv; + expect(workdir).toBe(result.workspace); + expect(relative(result.workspace, cliEntry).startsWith("..")).toBe(true); + expect(result.seen.argv[result.seen.argv.indexOf("publish") + 1]).toBe("."); + }); }); diff --git a/src/__tests__/skill-publish-workflow.test.ts b/src/__tests__/skill-publish-workflow.test.ts index 2f53c6ebb6..52a74b7c8a 100644 --- a/src/__tests__/skill-publish-workflow.test.ts +++ b/src/__tests__/skill-publish-workflow.test.ts @@ -138,4 +138,25 @@ describe("skill publish workflow", () => { expect(workflow).toContain("uses: actions/upload-artifact@v7\n if: ${{ always() }}"); expect(workflow).toContain("if-no-files-found: ignore"); }); + + it("keeps the ClawHub checkout out of a repository-root skill", () => { + const workflow = readFileSync(resolve(".github/workflows/skill-publish.yml"), "utf8"); + const steps = ( + parseYaml(workflow) as { + jobs: { + publish: { steps: Array<{ name?: string; run?: string; "working-directory"?: string }> }; + }; + } + ).jobs.publish.steps; + const names = steps.map((step) => step.name); + const move = steps.find( + (step) => step.name === "Move ClawHub source out of the caller workspace", + ); + const install = steps.find((step) => step.name === "Install ClawHub CLI dependencies"); + + expect(move?.run).toBe('mv "$GITHUB_WORKSPACE/clawhub-source" "$RUNNER_TEMP/clawhub-source"'); + expect(names.indexOf(move?.name)).toBeLessThan(names.indexOf(install?.name)); + expect(install?.["working-directory"]).toBe("${{ runner.temp }}/clawhub-source"); + expect(workflow).toContain('cli_entry = Path(os.environ["RUNNER_TEMP"]) / "clawhub-source"'); + }); }); From 35e69f31daf7c043d45722eb41bbe3609c44878f Mon Sep 17 00:00:00 2001 From: troioi-vn Date: Tue, 24 Nov 2026 17:29:02 +0700 Subject: [PATCH 2/2] test: drop string-pinning assertions --- src/__tests__/skill-publish-workflow.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/__tests__/skill-publish-workflow.test.ts b/src/__tests__/skill-publish-workflow.test.ts index 52a74b7c8a..18ef1e6466 100644 --- a/src/__tests__/skill-publish-workflow.test.ts +++ b/src/__tests__/skill-publish-workflow.test.ts @@ -154,9 +154,8 @@ describe("skill publish workflow", () => { ); const install = steps.find((step) => step.name === "Install ClawHub CLI dependencies"); - expect(move?.run).toBe('mv "$GITHUB_WORKSPACE/clawhub-source" "$RUNNER_TEMP/clawhub-source"'); + expect(move).toBeDefined(); expect(names.indexOf(move?.name)).toBeLessThan(names.indexOf(install?.name)); expect(install?.["working-directory"]).toBe("${{ runner.temp }}/clawhub-source"); - expect(workflow).toContain('cli_entry = Path(os.environ["RUNNER_TEMP"]) / "clawhub-source"'); }); });