mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-11-21 21:47:28 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acfe799285 | ||
|
|
3c38c04401 |
@@ -147,7 +147,7 @@ runs:
|
||||
PATH_TO_CLAUDE_CODE_EXECUTABLE: ${{ inputs.path_to_claude_code_executable }}
|
||||
run: |
|
||||
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
||||
CLAUDE_CODE_VERSION="2.1.329"
|
||||
CLAUDE_CODE_VERSION="2.1.330"
|
||||
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
||||
for attempt in 1 2 3; do
|
||||
echo "Installation attempt $attempt..."
|
||||
|
||||
+10
-10
@@ -6,7 +6,7 @@
|
||||
"name": "@anthropic-ai/claude-code-base-action",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.329",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.330",
|
||||
"shell-quote": "^1.8.4",
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -27,23 +27,23 @@
|
||||
|
||||
"@actions/io": ["@actions/[email protected]", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]29", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.329", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.329", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.329", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.329", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.329", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.329", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.329", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.329" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-aKVIgPBmgNHBoNXUFG5eVJXudDd+amObxT6QH9b6R2yGKf4eisPZ3Ij5RSpkFHDvJvaZy8m1AJeEkbKSusTU/Q=="],
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]30", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.330", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.330", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.330", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.330", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.330", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.330", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.330", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.330" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-7om9Xus6tfkeCUCfzg6ilJuN6Z7okkEvJ0mx+ukXa/Id5U/6BGtPkOYni+3ebedwa3b9SVF7A05+ln+/9EoU/w=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]29", "", { "os": "darwin", "cpu": "arm64" }, "sha512-SaVFEDYHofgKftJGX8Uf5oa1wG9d2E9QAQqEpSCtiJrt7Ih82Ekn9b4ir0GufgwoOKx5IOv/CnMsXIWRl9vWrg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]30", "", { "os": "darwin", "cpu": "arm64" }, "sha512-J9nqvcfD2V90O5uoR8At66R51VYtSMKnxSmPc0S4A4F5oX1VbokcpJLXU1yVCOuTtzr/OIHjRr9nn2vKi/S6rQ=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]29", "", { "os": "darwin", "cpu": "x64" }, "sha512-nYtGrz5oe/SK8jMKr/JArzrjEBtTqLWlRBlGu6QLXBoXd4PB5Fdj+Nh7Idnf+LD8OwWz1fqXj8zt0HTIUMSvYA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]30", "", { "os": "darwin", "cpu": "x64" }, "sha512-woe+f9qeZYWML5fACibNyth0xMDf22riNRNDryIYuhdteh7IoWrK6zC31cC2MrZRoqDZcPVtfOLND79+iZbrLA=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]29", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-QvIfyMfjiYU2wkMfQ+tXTSwK76pXh/xSgdAFuqcPOiM3qgfi1kImcCIy/0wUnm9HGn0GZLXu7x0/lBu/PNHxVg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]30", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-2Q+kfzaoTvJv1rsyu+iR4UHDZ3nxiOfdXISk+2ydQShU9DqXNlgQAt3BdJMh0Yx4MrxB66TMphVvVQeRslwwhA=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]29", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-aOf1nA8roGApMzfL/aoEMBDGi11ZKtNV7mvp6OmaU0pgC24qECBeSUdsUuQBu9Z97kf5PDCh12JhkeHVDK+4JA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]30", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-fXmuAEegw31v+kiBd51yn7RVhjs7Rz2lnhfx/+XJXqt5lyqR2v7Ul/U/9r1CQZKuIw8M3ms9jQqGpmKbgKndqQ=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]29", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-TKHcN+kOwG1Q6meOhKu9ZCJPUsXRL4dgx07R1BPgm0vREPpsSxaET5w7LuCs4pLIQgATJdqj6hjWtejDhVszNA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]30", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-9w4uMdA3vNZXocwOUhivOGotXoRDxN/C/xPMkZMY9WPpKLAlj8upMZskNgPjQKlVRXhxPfNagcBijGPUH4WepA=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]29", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-0j1Pu/egb7tbZk570MOd9vUVSlHvxnoA9ccDMdrAFqFGq3qb20IdHf4AvXuo9sbksKFXTx9oeEsvD4iFrL+wlA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]30", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-kooZMdp6tFwNFkDXbGoNTZMgFcPQfJVfG+gZ2qAdkk11S6MFts9ybHRLQmzUK3VrqlahH7T9fmI2mNfzYgOXkw=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]29", "", { "os": "win32", "cpu": "arm64" }, "sha512-lv4VKGQnTWIVToeWNrpekWIzYeTAQtOzDGXsU7krUizvJl3X0J/KiqEUB1Yi/F9VcYs3Aiu81RWtKdATLM5nkA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]30", "", { "os": "win32", "cpu": "arm64" }, "sha512-6jscch7vk/XBSn7mm1i6zwTeiz05q98nKrQ3HdTavQEDGvXycMcB/QxIdMrs3vrdNEjWuoxwrL1qlT1lOyAWLg=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]29", "", { "os": "win32", "cpu": "x64" }, "sha512-Pyn2sQciPirZk9OVh6EshSra84OBk11kJyTXgDv/v5PbHU2n2I+BbBYWkTeHpWeLlfRI61LWkFHtqs9cYOLOkg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]30", "", { "os": "win32", "cpu": "x64" }, "sha512-ooThWbUXlXKTDgj2VgWBXQ/6vSOTaAbBDWPvvCGNHi20haoSkw4uPX9gczkX+HJuVTslvvLiYIfe8zleVPzi7A=="],
|
||||
|
||||
"@anthropic-ai/sdk": ["@anthropic-ai/[email protected]", "", { "dependencies": { "json-schema-to-ts": "^3.1.1" }, "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" }, "optionalPeers": ["zod"], "bin": { "anthropic-ai-sdk": "bin/cli" } }, "sha512-q9vaSZQVFx6B/gPxetGYfLXSJD5v0sOmh0OpZDq7yCrTSA+Rscvrtyol7JJTW40wEpQB4U1B4JXzxQitbQ3CAA=="],
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.329",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.330",
|
||||
"shell-quote": "^1.8.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.329",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.330",
|
||||
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||
"@octokit/graphql": "^8.2.2",
|
||||
"@octokit/rest": "^21.1.1",
|
||||
@@ -37,23 +37,23 @@
|
||||
|
||||
"@actions/io": ["@actions/[email protected]", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]29", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.329", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.329", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.329", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.329", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.329", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.329", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.329", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.329" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-aKVIgPBmgNHBoNXUFG5eVJXudDd+amObxT6QH9b6R2yGKf4eisPZ3Ij5RSpkFHDvJvaZy8m1AJeEkbKSusTU/Q=="],
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]30", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.330", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.330", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.330", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.330", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.330", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.330", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.330", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.330" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-7om9Xus6tfkeCUCfzg6ilJuN6Z7okkEvJ0mx+ukXa/Id5U/6BGtPkOYni+3ebedwa3b9SVF7A05+ln+/9EoU/w=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]29", "", { "os": "darwin", "cpu": "arm64" }, "sha512-SaVFEDYHofgKftJGX8Uf5oa1wG9d2E9QAQqEpSCtiJrt7Ih82Ekn9b4ir0GufgwoOKx5IOv/CnMsXIWRl9vWrg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]30", "", { "os": "darwin", "cpu": "arm64" }, "sha512-J9nqvcfD2V90O5uoR8At66R51VYtSMKnxSmPc0S4A4F5oX1VbokcpJLXU1yVCOuTtzr/OIHjRr9nn2vKi/S6rQ=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]29", "", { "os": "darwin", "cpu": "x64" }, "sha512-nYtGrz5oe/SK8jMKr/JArzrjEBtTqLWlRBlGu6QLXBoXd4PB5Fdj+Nh7Idnf+LD8OwWz1fqXj8zt0HTIUMSvYA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]30", "", { "os": "darwin", "cpu": "x64" }, "sha512-woe+f9qeZYWML5fACibNyth0xMDf22riNRNDryIYuhdteh7IoWrK6zC31cC2MrZRoqDZcPVtfOLND79+iZbrLA=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]29", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-QvIfyMfjiYU2wkMfQ+tXTSwK76pXh/xSgdAFuqcPOiM3qgfi1kImcCIy/0wUnm9HGn0GZLXu7x0/lBu/PNHxVg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]30", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-2Q+kfzaoTvJv1rsyu+iR4UHDZ3nxiOfdXISk+2ydQShU9DqXNlgQAt3BdJMh0Yx4MrxB66TMphVvVQeRslwwhA=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]29", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-aOf1nA8roGApMzfL/aoEMBDGi11ZKtNV7mvp6OmaU0pgC24qECBeSUdsUuQBu9Z97kf5PDCh12JhkeHVDK+4JA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]30", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-fXmuAEegw31v+kiBd51yn7RVhjs7Rz2lnhfx/+XJXqt5lyqR2v7Ul/U/9r1CQZKuIw8M3ms9jQqGpmKbgKndqQ=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]29", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-TKHcN+kOwG1Q6meOhKu9ZCJPUsXRL4dgx07R1BPgm0vREPpsSxaET5w7LuCs4pLIQgATJdqj6hjWtejDhVszNA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]30", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-9w4uMdA3vNZXocwOUhivOGotXoRDxN/C/xPMkZMY9WPpKLAlj8upMZskNgPjQKlVRXhxPfNagcBijGPUH4WepA=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]29", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-0j1Pu/egb7tbZk570MOd9vUVSlHvxnoA9ccDMdrAFqFGq3qb20IdHf4AvXuo9sbksKFXTx9oeEsvD4iFrL+wlA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]30", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-kooZMdp6tFwNFkDXbGoNTZMgFcPQfJVfG+gZ2qAdkk11S6MFts9ybHRLQmzUK3VrqlahH7T9fmI2mNfzYgOXkw=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]29", "", { "os": "win32", "cpu": "arm64" }, "sha512-lv4VKGQnTWIVToeWNrpekWIzYeTAQtOzDGXsU7krUizvJl3X0J/KiqEUB1Yi/F9VcYs3Aiu81RWtKdATLM5nkA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]30", "", { "os": "win32", "cpu": "arm64" }, "sha512-6jscch7vk/XBSn7mm1i6zwTeiz05q98nKrQ3HdTavQEDGvXycMcB/QxIdMrs3vrdNEjWuoxwrL1qlT1lOyAWLg=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]29", "", { "os": "win32", "cpu": "x64" }, "sha512-Pyn2sQciPirZk9OVh6EshSra84OBk11kJyTXgDv/v5PbHU2n2I+BbBYWkTeHpWeLlfRI61LWkFHtqs9cYOLOkg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]30", "", { "os": "win32", "cpu": "x64" }, "sha512-ooThWbUXlXKTDgj2VgWBXQ/6vSOTaAbBDWPvvCGNHi20haoSkw4uPX9gczkX+HJuVTslvvLiYIfe8zleVPzi7A=="],
|
||||
|
||||
"@anthropic-ai/sdk": ["@anthropic-ai/[email protected]", "", { "dependencies": { "json-schema-to-ts": "^3.1.1" }, "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" }, "optionalPeers": ["zod"], "bin": { "anthropic-ai-sdk": "bin/cli" } }, "sha512-q9vaSZQVFx6B/gPxetGYfLXSJD5v0sOmh0OpZDq7yCrTSA+Rscvrtyol7JJTW40wEpQB4U1B4JXzxQitbQ3CAA=="],
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ Everything else in the working tree — including `package.json`, lockfiles, `Ma
|
||||
|
||||
On pull requests from authors without write access, the action also replaces what npm and Bun read from the repository root with the base branch's version, wherever the two differ: `.npmrc`, `bunfig.toml` and tracked files in `node_modules/`. In a `package.json` whose `name`, `bin`, `directories.bin` or `workspaces` change the commands it provides, only `name`, `bin`, `directories` and `workspaces` are replaced, or the whole file if it can't be understood, including in other directories if the base branch uses workspaces. The pull request's versions are kept under `.claude-pr/` for reading, except for `node_modules/`. Claude can't edit `.npmrc`, `bunfig.toml`, `node_modules/` or, where one was replaced, `package.json` on these pull requests, in any directory. Its Bash commands start in the repository root there, because a hook runs in the session's current directory and only the root's files are replaced. The replaced files stay in the working tree for later steps in the job, and if Claude stages everything, its commit can include them, as with the paths above. `restrict_untrusted_prs: false` turns this off.
|
||||
|
||||
On these pull requests, files and directories in the checkout that your workflow's inputs name also come from the base branch where the pull request changes them or a `.gitattributes` that applies to them: `settings`, `plugin_marketplaces`, and in `claude_args` `--settings`, `--mcp-config`, `--plugin-dir`, `--plugin-dir-no-mcp`, `--agents`, `--project-config-root`, `--system-prompt-file`, `--append-system-prompt-file` and `--append-subagent-system-prompt-file`. The pull request's versions are kept under `.claude-pr/` for reading, and Claude can't edit what these inputs name, apart from the paths listed above. The replaced files stay in the working tree here too. A file that only the pull request has is removed. The run stops if an input names the whole repository as a plugin or marketplace, except that a marketplace at the root works if all its plugins are in subdirectories, if it names a path with `..` after another directory, or if it names files in a submodule that the pull request has at another commit. What symbolic links lead to, files that other config names, for example in a `settings.json`, and executables are not covered. Git LFS files are written as pointers.
|
||||
|
||||
This doesn't cover other package managers, the `.env` files and `tsconfig.json` that Bun loads, other files that a hook's own command reads, or a git command that resets the working tree during the session, so keep hooks self-contained as described above. Files that git doesn't track, such as packages an earlier step installed, stay as they are. A file that is the same link on both branches is left as a link.
|
||||
|
||||
Note that the runtime executing the tool also reads project config. `bunx <tool>` runs the tool's script under `node` when `node` is on `PATH` (as it is on GitHub-hosted runners); when only Bun is available, Bun executes the script itself and reads `bunfig.toml` from the checkout — including `preload` entries — which comes from the PR head. On such runners, make sure `node` is on `PATH` for the hook, and treat `bunfig.toml` and `.npmrc` in the checkout as PR-controlled runtime config on pull requests from authors with write access.
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.329",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.330",
|
||||
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||
"@octokit/graphql": "^8.2.2",
|
||||
"@octokit/rest": "^21.1.1",
|
||||
|
||||
+16
-2
@@ -56,6 +56,10 @@ import {
|
||||
restoreToolConfigFromBase,
|
||||
toolConfigDenyRules,
|
||||
} from "../github/operations/tool-config";
|
||||
import {
|
||||
namedConfigPaths,
|
||||
restoreConfigPathsFromBase,
|
||||
} from "../github/operations/config-paths";
|
||||
import { validateBranchName } from "../github/operations/branch";
|
||||
import type { BranchInfo } from "../github/operations/branch";
|
||||
import { collectActionInputsPresence } from "./collect-inputs";
|
||||
@@ -105,7 +109,7 @@ async function installClaudeCode(): Promise<string> {
|
||||
return customExecutable;
|
||||
}
|
||||
|
||||
const claudeCodeVersion = "2.1.329";
|
||||
const claudeCodeVersion = "2.1.330";
|
||||
console.log(`Installing Claude Code v${claudeCodeVersion}...`);
|
||||
|
||||
for (let attempt = 1; attempt <= 3; attempt++) {
|
||||
@@ -332,6 +336,7 @@ async function run() {
|
||||
const isUntrustedCheckout =
|
||||
checkedOutPrHead && untrustedPrDisallowedTools.length > 0;
|
||||
let restoredToolConfig: string[] = [];
|
||||
let configPathDenyRules: string[] = [];
|
||||
|
||||
// On PRs, .claude/ and .mcp.json in the checkout are attacker-controlled.
|
||||
// Restore them from a trusted branch before the CLI reads them.
|
||||
@@ -373,7 +378,15 @@ async function run() {
|
||||
// Before plugins are installed, which can already start package managers here.
|
||||
if (isUntrustedCheckout) {
|
||||
restoredToolConfig = restoreToolConfigFromBase(configBranch);
|
||||
restoredConfigPaths.push(...restoredToolConfig);
|
||||
const configPaths = restoreConfigPathsFromBase(
|
||||
configBranch,
|
||||
namedConfigPaths(prepareResult.claudeArgs),
|
||||
);
|
||||
configPathDenyRules = configPaths.denyRules;
|
||||
restoredConfigPaths.push(
|
||||
...restoredToolConfig,
|
||||
...configPaths.replaced,
|
||||
);
|
||||
}
|
||||
if (isOtherBranch) {
|
||||
// A branch from the base has none of the pull request's version of them.
|
||||
@@ -407,6 +420,7 @@ async function run() {
|
||||
? [
|
||||
...untrustedPrDisallowedTools,
|
||||
...toolConfigDenyRules(restoredToolConfig),
|
||||
...configPathDenyRules,
|
||||
]
|
||||
: [];
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ export async function checkAndCommitOrDeleteBranch(
|
||||
// .claude/settings.json. Excluding those there would silently drop the work.
|
||||
const pathspecArgs =
|
||||
restoredConfigPaths.length > 0
|
||||
? ["--", ".", ...restoredConfigPaths.map((p) => `:(exclude)${p}`)]
|
||||
? ["--", ".", ...restoredConfigPaths.map((p) => `:(exclude,literal)${p}`)]
|
||||
: [];
|
||||
|
||||
if (pathspecArgs.length > 0) {
|
||||
|
||||
@@ -0,0 +1,381 @@
|
||||
import * as core from "@actions/core";
|
||||
import { mkdirSync, symlinkSync, writeFileSync } from "fs";
|
||||
import { isAbsolute, posix, relative, resolve, sep } from "path";
|
||||
import {
|
||||
ACCUMULATE_DELIMITER,
|
||||
parseClaudeArgsToExtraArgs,
|
||||
} from "../../../base-action/src/parse-sdk-options";
|
||||
import { SENSITIVE_PATHS } from "./restore-config";
|
||||
import {
|
||||
fold,
|
||||
fsPath,
|
||||
git,
|
||||
hasRealParents,
|
||||
isFile,
|
||||
isLink,
|
||||
isSubmodule,
|
||||
onDisk,
|
||||
readBlobs,
|
||||
remove,
|
||||
snapshotForReview,
|
||||
} from "./tool-config";
|
||||
import type { Entry } from "./tool-config";
|
||||
|
||||
// The arguments that name config in files.
|
||||
const FILE_FLAGS = new Set([
|
||||
"agents",
|
||||
"append-subagent-system-prompt-file",
|
||||
"append-system-prompt-file",
|
||||
"mcp-config",
|
||||
"plugin-dir",
|
||||
"plugin-dir-no-mcp",
|
||||
"settings",
|
||||
"system-prompt-file",
|
||||
]);
|
||||
// Only the project's config in this directory.
|
||||
const PROJECT_FLAG = "project-config-root";
|
||||
const MARKETPLACE_FILE = ".claude-plugin/marketplace.json";
|
||||
|
||||
// Git's entries by path, relative to the working directory. As in tool-config.ts,
|
||||
// Latin-1 characters stand for bytes.
|
||||
type Entries = Map<string, Entry>;
|
||||
|
||||
const toBytes = (path: string): string => Buffer.from(path).toString("latin1");
|
||||
const toText = (path: string): string => fsPath(path).toString();
|
||||
const isSameOrInside = (path: string, parent: string): boolean =>
|
||||
path === parent || path.startsWith(`${parent}/`);
|
||||
const isSensitive = (path: string): boolean =>
|
||||
SENSITIVE_PATHS.some((sensitive) => isSameOrInside(path, sensitive));
|
||||
|
||||
// Each is "<mode> <other fields>\t<path>".
|
||||
function parseEntries(listing: Buffer, oidField: number): Entries {
|
||||
const entries: Entries = new Map();
|
||||
for (const line of listing.toString("latin1").split("\0")) {
|
||||
const [info, path] = line.split(/\t(.*)/s);
|
||||
if (!info || !path) continue;
|
||||
const fields = info.split(" ");
|
||||
entries.set(path, { mode: fields[0]!, oid: fields[oidField]! });
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* A path as it is relative to the checkout, or undefined if it's outside. Links are not
|
||||
* followed, because the pull request can change them. The workspace can have another
|
||||
* name than the working directory, which is free of links.
|
||||
*/
|
||||
function inCheckout(path: string): string | undefined {
|
||||
const roots = [process.cwd(), process.env.GITHUB_WORKSPACE || process.cwd()];
|
||||
for (const root of roots) {
|
||||
const inRoot = relative(root, resolve(path));
|
||||
if (!isAbsolute(inRoot) && inRoot.split(sep)[0] !== "..") {
|
||||
return toBytes(inRoot.split(sep).join("/"));
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isJson(value: string): boolean {
|
||||
if (!value.startsWith("{")) return false;
|
||||
try {
|
||||
JSON.parse(value);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const WHOLE_REPOSITORY =
|
||||
"The workflow takes a plugin from the whole repository, which can't come from a trusted branch on a pull request from an author without write access. Put the plugin in a subdirectory, or set restrict_untrusted_prs to false.";
|
||||
const UNCLEAR_PATH =
|
||||
'A path in the workflow\'s inputs has ".." after another name, so it can\'t come from a trusted branch on a pull request from an author without write access. Write it without "..", or set restrict_untrusted_prs to false.';
|
||||
|
||||
const OTHER_SUBMODULE =
|
||||
"The pull request and the trusted branch have different commits of a submodule that the workflow's inputs name, so that branch's version can't be used. Bring the pull request up to date, put the files in the repository, or set restrict_untrusted_prs to false.";
|
||||
|
||||
class PathError extends Error {}
|
||||
|
||||
/**
|
||||
* Whether a path has ".." after a name in the checkout, which the pull request could
|
||||
* make a link.
|
||||
*/
|
||||
function goesBack(path: string): boolean {
|
||||
const parts = path.split(/[\\/]/);
|
||||
return parts.some(
|
||||
(part, index) =>
|
||||
part === ".." && !!inCheckout(parts.slice(0, index).join("/") || "/"),
|
||||
);
|
||||
}
|
||||
|
||||
type NamedPaths = { paths: string[]; marketplaces: string[] };
|
||||
|
||||
/** The paths in this checkout that the workflow's inputs name as config. */
|
||||
export function namedConfigPaths(claudeArgs: string): NamedPaths {
|
||||
const args = Object.entries(parseClaudeArgsToExtraArgs(claudeArgs)).flatMap(
|
||||
([key, value]) => {
|
||||
const [flag, inlineValue] = key.split(/=(.*)/s);
|
||||
return [...(value?.split(ACCUMULATE_DELIMITER) ?? []), inlineValue ?? ""]
|
||||
.map((path) => path.trim())
|
||||
.flatMap((path) => (path ? [{ flag: flag!, path }] : []));
|
||||
},
|
||||
);
|
||||
const fromArgs = args.flatMap(({ flag, path }) =>
|
||||
flag === PROJECT_FLAG
|
||||
? SENSITIVE_PATHS.map((name) => `${path}/${name}`)
|
||||
: FILE_FLAGS.has(flag)
|
||||
? [path]
|
||||
: [],
|
||||
);
|
||||
const toPaths = (values: string[]): string[] =>
|
||||
values
|
||||
.map((value) => value.trim())
|
||||
.filter((value) => value && !isJson(value))
|
||||
.flatMap((value) => {
|
||||
if (goesBack(value)) throw new PathError(UNCLEAR_PATH);
|
||||
const path = inCheckout(value);
|
||||
return path === undefined ? [] : [path];
|
||||
});
|
||||
return {
|
||||
paths: toPaths([process.env.INPUT_SETTINGS ?? "", ...fromArgs]),
|
||||
marketplaces: toPaths(
|
||||
(process.env.INPUT_PLUGIN_MARKETPLACES ?? "")
|
||||
.split("\n")
|
||||
.filter((entry) => /^\s*((\.\.?)?\/|[a-z]:[\\/])/i.test(entry)),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
type RestoredPaths = { replaced: string[]; denyRules: string[] };
|
||||
|
||||
/**
|
||||
* On a pull request from an author without write access, takes the files that the
|
||||
* workflow's inputs name from the base branch. Links are restored but not followed. Only
|
||||
* files that the pull request changes, or whose .gitattributes it changes, are replaced,
|
||||
* so what an earlier step created or changed stays. restoreConfigFromBase must run
|
||||
* first, because it fetches the base branch. Like it, this changes the working tree and
|
||||
* not the index.
|
||||
*
|
||||
* @returns The paths that were replaced, all named by the base branch or the workflow,
|
||||
* and rules that stop a session from editing these and the rest of that config.
|
||||
* @throws If the base branch's version can't be put in place.
|
||||
*/
|
||||
export function restoreConfigPathsFromBase(
|
||||
baseBranch: string,
|
||||
named: NamedPaths,
|
||||
): RestoredPaths {
|
||||
if (named.paths.length + named.marketplaces.length === 0) {
|
||||
return { replaced: [], denyRules: [] };
|
||||
}
|
||||
let restored: RestoredPaths;
|
||||
try {
|
||||
restored = restoreConfigPaths(`refs/remotes/origin/${baseBranch}`, named);
|
||||
} catch (error) {
|
||||
if (error instanceof PathError) throw error;
|
||||
const { code, status } = error as { code?: string; status?: number };
|
||||
core.warning(
|
||||
`Could not replace config files (${code ?? `exit code ${status ?? "unknown"}`})`,
|
||||
);
|
||||
throw new Error(
|
||||
"Could not use the trusted branch's version of the files that the workflow's inputs name",
|
||||
);
|
||||
}
|
||||
if (restored.replaced.length > 0) {
|
||||
core.warning(
|
||||
`The pull request and ${baseBranch} differ in files that the workflow's inputs name (${restored.replaced.join(", ")}), so that branch's version is used and Claude can't edit it. See docs/security.md.`,
|
||||
);
|
||||
}
|
||||
return restored;
|
||||
}
|
||||
|
||||
function restoreConfigPaths(ref: string, named: NamedPaths): RestoredPaths {
|
||||
const base = parseEntries(git(["ls-tree", "-r", "-z", ref]), 2);
|
||||
const pr = parseEntries(git(["ls-files", "--stage", "-z"]), 1);
|
||||
|
||||
// The rest of Claude's config has been restored already.
|
||||
const targets = [
|
||||
...named.paths,
|
||||
...named.marketplaces.flatMap((path) => marketplacePaths(path, base)),
|
||||
]
|
||||
.map((path) => posix.join(path || ".").replace(/\/$/, ""))
|
||||
.filter((path) => !isSameOrInside(path, "..") && !isSensitive(path));
|
||||
if (targets.includes(".")) throw new PathError(WHOLE_REPOSITORY);
|
||||
|
||||
const replaced = replaceFiles([...new Set(targets)], base, pr).map(toText);
|
||||
return {
|
||||
replaced,
|
||||
denyRules: [...new Set([...targets.map(toText), ...replaced])]
|
||||
.map((path) => path.replace(/[\\*?[\]]/g, "\\$&"))
|
||||
.flatMap((path) => [`Edit(./${path})`, `Edit(./${path}/**)`]),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* What a local marketplace is made of. One at the root of the repository has only its
|
||||
* own plugins in other directories.
|
||||
*/
|
||||
function marketplacePaths(path: string, base: Entries): string[] {
|
||||
const isManifest = path.endsWith(".json");
|
||||
// The CLI takes the directory above the manifest's as the marketplace's root.
|
||||
if (isManifest && !path.includes("/")) return [path];
|
||||
const root = isManifest
|
||||
? posix.join(posix.dirname(path), "..")
|
||||
: path === ""
|
||||
? "."
|
||||
: path;
|
||||
if (root !== ".") return [root];
|
||||
|
||||
const manifest = isManifest ? path : MARKETPLACE_FILE;
|
||||
const own = isManifest ? path : posix.dirname(MARKETPLACE_FILE);
|
||||
const entry = base.get(manifest);
|
||||
// Without one that the base branch has, there is nothing to take plugins from.
|
||||
if (!entry || !isFile(entry)) return [own];
|
||||
const { plugins, metadata } = JSON.parse(
|
||||
readBlobs([entry])
|
||||
.get(entry.oid)!
|
||||
.toString()
|
||||
.replace(/^\uFEFF/, ""),
|
||||
) as {
|
||||
plugins?: ({ source?: unknown } | null)[];
|
||||
metadata?: { pluginRoot?: unknown };
|
||||
};
|
||||
const pluginRoot =
|
||||
typeof metadata?.pluginRoot === "string" ? metadata.pluginRoot : "";
|
||||
const sources = (plugins ?? []).flatMap((plugin) =>
|
||||
typeof plugin?.source === "string" ? [plugin.source] : [],
|
||||
);
|
||||
return [
|
||||
own,
|
||||
...sources.flatMap((source) =>
|
||||
// A bare name can be in the marketplace's plugin root.
|
||||
[source, ...(pluginRoot ? [posix.join(pluginRoot, source)] : [])].map(
|
||||
(dir) => toBytes(posix.join(".", dir)),
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a path that differs from a target at most in case, or in how a character is
|
||||
* encoded, is in it or above it on this file system.
|
||||
*/
|
||||
function namesSameFile(name: string, target: string): boolean {
|
||||
const names = name.split("/");
|
||||
const targets = target.split("/");
|
||||
const spelled = [
|
||||
...targets.slice(0, names.length),
|
||||
...names.slice(targets.length),
|
||||
].join("/");
|
||||
if (name === spelled) return true;
|
||||
const [stats, other] = [onDisk(name), onDisk(spelled)];
|
||||
return !!stats && !!other && stats.ino === other.ino;
|
||||
}
|
||||
|
||||
/** The directories whose .gitattributes the pull request changes, ignoring case. */
|
||||
function changedAttributes(base: Entries, pr: Entries): string[] {
|
||||
const names = new Set([...base.keys(), ...pr.keys()]);
|
||||
return [...names].flatMap((name) =>
|
||||
fold(posix.basename(name)) === ".gitattributes" &&
|
||||
base.get(name)?.oid !== pr.get(name)?.oid
|
||||
? [fold(posix.dirname(name))]
|
||||
: [],
|
||||
);
|
||||
}
|
||||
|
||||
const isInside = (name: string, foldedDir: string): boolean =>
|
||||
foldedDir === "." || fold(name).startsWith(`${foldedDir}/`);
|
||||
|
||||
/** Puts the base branch's version of these paths in place. Returns those that differed. */
|
||||
function replaceFiles(targets: string[], base: Entries, pr: Entries): string[] {
|
||||
const foldedPr = [...pr.keys()].map((name) => [name, fold(name)] as const);
|
||||
const namesByTarget = new Map(
|
||||
targets.map((target) => {
|
||||
const folded = fold(target);
|
||||
const names = [
|
||||
...[...base.keys()].filter(
|
||||
(name) =>
|
||||
isSameOrInside(name, target) || isSameOrInside(target, name),
|
||||
),
|
||||
// A pull request can also have a file or link where the base branch has a
|
||||
// directory.
|
||||
...foldedPr.flatMap(([name, other]) =>
|
||||
(isSameOrInside(other, folded) || isSameOrInside(folded, other)) &&
|
||||
namesSameFile(name, target)
|
||||
? [name]
|
||||
: [],
|
||||
),
|
||||
];
|
||||
return [target, [...new Set(names)]] as const;
|
||||
}),
|
||||
);
|
||||
const attributes = changedAttributes(base, pr);
|
||||
const differs = (name: string): boolean => {
|
||||
const [ours, theirs] = [base.get(name), pr.get(name)];
|
||||
return (
|
||||
ours?.oid !== theirs?.oid ||
|
||||
ours?.mode !== theirs?.mode ||
|
||||
// Git can write even an unchanged file differently then.
|
||||
(isFile(theirs!) && attributes.some((dir) => isInside(name, dir)))
|
||||
);
|
||||
};
|
||||
const differing = [...namesByTarget].flatMap(([target, names]) => {
|
||||
// Names that differ only in case can be the same file.
|
||||
const folded = new Set(names.filter(differs).map(fold));
|
||||
const changed = names.filter((name) => folded.has(fold(name)));
|
||||
return changed.length > 0 ? [[target, changed] as const] : [];
|
||||
});
|
||||
const changed = [...new Set(differing.flatMap(([, names]) => names))];
|
||||
// Claude Code goes on without a plugin that is missing.
|
||||
if (changed.some((name) => base.has(name) && isSubmodule(base.get(name)!))) {
|
||||
throw new PathError(OTHER_SUBMODULE);
|
||||
}
|
||||
|
||||
// All of these go before anything is written. A directory where the pull request has
|
||||
// a file or link came from an earlier step.
|
||||
const removed = new Set(
|
||||
changed.filter((name) => {
|
||||
const entry = pr.get(name);
|
||||
const stats = entry && onDisk(name);
|
||||
return (
|
||||
stats &&
|
||||
(!stats.isDirectory() || isSubmodule(entry)) &&
|
||||
hasRealParents(name)
|
||||
);
|
||||
}),
|
||||
);
|
||||
for (const name of removed) {
|
||||
const entry = pr.get(name)!;
|
||||
if (entry.oid !== base.get(name)?.oid) snapshotForReview(name, entry);
|
||||
remove(name);
|
||||
}
|
||||
|
||||
// One that the pull request has but is not on disk was left out or deleted by the
|
||||
// workflow. What is on disk now came from an earlier step.
|
||||
const toWrite = changed.flatMap((name) => {
|
||||
const entry = base.get(name);
|
||||
const wanted = pr.has(name) ? removed.has(name) : true;
|
||||
return entry && !isSubmodule(entry) && wanted && !onDisk(name)
|
||||
? [{ name, entry }]
|
||||
: [];
|
||||
});
|
||||
const blobs = readBlobs(toWrite.map(({ entry }) => entry));
|
||||
for (const { name, entry } of toWrite) {
|
||||
if (!hasRealParents(name)) continue;
|
||||
const content = blobs.get(entry.oid);
|
||||
if (!content) throw new Error("missing object");
|
||||
mkdirSync(fsPath(posix.dirname(name)), { recursive: true });
|
||||
if (isLink(entry)) symlinkSync(content, fsPath(name));
|
||||
else {
|
||||
const mode = entry.mode === "100755" ? 0o755 : 0o644;
|
||||
writeFileSync(fsPath(name), content, { mode, flag: "wx" });
|
||||
}
|
||||
}
|
||||
// Where the pull request has a file above a target, that is gone too.
|
||||
return [
|
||||
...new Set(
|
||||
differing.flatMap(([target, names]) => [
|
||||
target,
|
||||
...names.filter((name) => target.startsWith(`${name}/`)),
|
||||
]),
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -329,7 +329,9 @@ export function pinPushBranch(branch: string): void {
|
||||
export function pinRestoredPaths(paths: string[]): void {
|
||||
const pathspecs = paths.map((path) =>
|
||||
// Its commands are replaced in subdirectories too.
|
||||
path === "package.json" ? ":(top,glob)**/package.json" : `:(top)${path}`,
|
||||
path === "package.json"
|
||||
? ":(top,glob)**/package.json"
|
||||
: `:(top,literal)${path}`,
|
||||
);
|
||||
try {
|
||||
writeSessionFile(".restored-paths", `${pathspecs.join("\n")}\n`);
|
||||
|
||||
@@ -32,14 +32,14 @@ const ENCODING = "working-tree-encoding";
|
||||
const MAX_OUTPUT_BYTES = 1024 ** 3;
|
||||
const MAX_PACKAGE_JSON_BYTES = 4 * 1024 * 1024;
|
||||
|
||||
type Entry = { mode: string; oid: string };
|
||||
export type Entry = { mode: string; oid: string };
|
||||
type Replacement = { path: string; entry: Entry; content?: Buffer };
|
||||
|
||||
// File names can be any bytes. Latin-1 keeps each one intact.
|
||||
const fsPath = (path: string): Buffer => Buffer.from(path, "latin1");
|
||||
const isFile = (entry: Entry): boolean => entry.mode.startsWith("100");
|
||||
const isLink = (entry: Entry): boolean => entry.mode === "120000";
|
||||
const isSubmodule = (entry: Entry): boolean => entry.mode === "160000";
|
||||
export const fsPath = (path: string): Buffer => Buffer.from(path, "latin1");
|
||||
export const isFile = (entry: Entry): boolean => entry.mode.startsWith("100");
|
||||
export const isLink = (entry: Entry): boolean => entry.mode === "120000";
|
||||
export const isSubmodule = (entry: Entry): boolean => entry.mode === "160000";
|
||||
|
||||
// No file name or content, which the pull request controls, reaches the log.
|
||||
function warn(what: string, error: unknown): void {
|
||||
@@ -47,7 +47,7 @@ function warn(what: string, error: unknown): void {
|
||||
core.warning(`${what} (${code ?? `exit code ${status ?? "unknown"}`})`);
|
||||
}
|
||||
|
||||
function git(args: string[], input: string | Buffer = ""): Buffer {
|
||||
export function git(args: string[], input: string | Buffer = ""): Buffer {
|
||||
return execFileSync("git", args, {
|
||||
stdio: ["pipe", "pipe", "ignore"],
|
||||
input,
|
||||
@@ -57,7 +57,7 @@ function git(args: string[], input: string | Buffer = ""): Buffer {
|
||||
}
|
||||
|
||||
// A parent that is a file or a looping link means there is nothing there.
|
||||
function onDisk(path: string) {
|
||||
export function onDisk(path: string) {
|
||||
try {
|
||||
return lstatSync(fsPath(path));
|
||||
} catch {
|
||||
@@ -66,7 +66,7 @@ function onDisk(path: string) {
|
||||
}
|
||||
|
||||
// File systems can ignore case, and some the way a character is encoded.
|
||||
const fold = (path: string): string =>
|
||||
export const fold = (path: string): string =>
|
||||
fsPath(path).toString().normalize("NFKC").toLowerCase();
|
||||
|
||||
/**
|
||||
@@ -97,14 +97,14 @@ function rootName(path: string): string | undefined {
|
||||
}
|
||||
|
||||
/** Whether no parent of a path is a link, which could lead out of the checkout. */
|
||||
function hasRealParents(path: string): boolean {
|
||||
export function hasRealParents(path: string): boolean {
|
||||
for (let dir = dirname(path); dir !== "."; dir = dirname(dir)) {
|
||||
if (onDisk(dir)?.isSymbolicLink()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function remove(path: string): void {
|
||||
export function remove(path: string): void {
|
||||
rmSync(fsPath(path), { recursive: true, force: true });
|
||||
// An empty directory would stand in the way of a file of that name.
|
||||
try {
|
||||
@@ -150,7 +150,7 @@ function baseEntries(baseBranch: string): Map<string, Entry> {
|
||||
}
|
||||
|
||||
/** The stored content of each entry, which no .gitattributes has been applied to. */
|
||||
function readBlobs(entries: Entry[]): Map<string, Buffer> {
|
||||
export function readBlobs(entries: Entry[]): Map<string, Buffer> {
|
||||
const blobs = new Map<string, Buffer>();
|
||||
const oids = [...new Set(entries.map(({ oid }) => oid))];
|
||||
if (oids.length === 0) return blobs;
|
||||
@@ -282,7 +282,7 @@ function withBaseCommands(
|
||||
}
|
||||
|
||||
/** Keeps the pull request's version readable, as for the other restored config. */
|
||||
function snapshotForReview(path: string, entry: Entry): void {
|
||||
export function snapshotForReview(path: string, entry: Entry): void {
|
||||
if (!isFile(entry) || rootName(path) === "node_modules") return;
|
||||
try {
|
||||
const content = git(["cat-file", "blob", entry.oid]);
|
||||
|
||||
@@ -313,7 +313,7 @@ describe("in a shallow checkout whose history contains the config branch", () =>
|
||||
);
|
||||
});
|
||||
|
||||
test("run.ts restores both kinds of config from the chosen branch", () => {
|
||||
test("run.ts restores every kind of config from the chosen branch", () => {
|
||||
const source = readFileSync(
|
||||
join(import.meta.dir, "../src/entrypoints/run.ts"),
|
||||
"utf8",
|
||||
@@ -327,5 +327,8 @@ test("run.ts restores both kinds of config from the chosen branch", () => {
|
||||
expect(source).toContain("restoreHeadHistory?.();");
|
||||
expect(source).toContain("pinRestoredPaths(restoredConfigPaths)");
|
||||
expect(source).toContain("restoreToolConfigFromBase(configBranch)");
|
||||
expect(source.replace(/\s+/g, " ")).toContain(
|
||||
"restoreConfigPathsFromBase( configBranch, namedConfigPaths(prepareResult.claudeArgs), )",
|
||||
);
|
||||
expect(source).toContain("fetchBranch(restoreBase)");
|
||||
});
|
||||
|
||||
@@ -0,0 +1,560 @@
|
||||
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
|
||||
import * as core from "@actions/core";
|
||||
import { execFileSync } from "child_process";
|
||||
import {
|
||||
existsSync,
|
||||
lstatSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
readFileSync,
|
||||
readlinkSync,
|
||||
rmSync,
|
||||
symlinkSync,
|
||||
writeFileSync,
|
||||
} from "fs";
|
||||
import { tmpdir } from "os";
|
||||
import { dirname, join } from "path";
|
||||
import {
|
||||
namedConfigPaths,
|
||||
restoreConfigPathsFromBase,
|
||||
} from "../src/github/operations/config-paths";
|
||||
import { restoreConfigFromBase } from "../src/github/operations/restore-config";
|
||||
|
||||
const INPUTS = [
|
||||
"INPUT_SETTINGS",
|
||||
"INPUT_PLUGIN_MARKETPLACES",
|
||||
"GITHUB_WORKSPACE",
|
||||
];
|
||||
|
||||
let originalCwd: string;
|
||||
let tempDir: string;
|
||||
let saved: Record<string, string | undefined>;
|
||||
let warningSpy: any;
|
||||
|
||||
const git = (...args: string[]) =>
|
||||
execFileSync("git", args, { encoding: "utf8", stdio: "pipe" }).trim();
|
||||
const write = (path: string, content: string) => {
|
||||
mkdirSync(dirname(path), { recursive: true });
|
||||
rmSync(path, { recursive: true, force: true });
|
||||
writeFileSync(path, content);
|
||||
};
|
||||
const link = (path: string, target: string) => {
|
||||
mkdirSync(dirname(path), { recursive: true });
|
||||
rmSync(path, { recursive: true, force: true });
|
||||
symlinkSync(target, path);
|
||||
};
|
||||
const read = (path: string) => readFileSync(path, "utf8");
|
||||
const commit = (message: string) => {
|
||||
git("add", "-A", "-f");
|
||||
git("commit", "-qm", message);
|
||||
};
|
||||
|
||||
// Commits the base branch, pushes it and starts the pull request's branch from it.
|
||||
const startPr = () => {
|
||||
commit("base");
|
||||
git("push", "-q", "origin", "main");
|
||||
git("checkout", "-qb", "pr");
|
||||
};
|
||||
|
||||
const restoreAll = (named = { paths: [], marketplaces: [] } as any) => {
|
||||
restoreConfigFromBase("main");
|
||||
return restoreConfigPathsFromBase("main", named);
|
||||
};
|
||||
const named = (...paths: string[]) => ({ paths, marketplaces: [] as string[] });
|
||||
const restore = (named?: any) => restoreAll(named).replaced;
|
||||
|
||||
beforeEach(() => {
|
||||
originalCwd = process.cwd();
|
||||
saved = Object.fromEntries(INPUTS.map((key) => [key, process.env[key]]));
|
||||
INPUTS.forEach((key) => delete process.env[key]);
|
||||
warningSpy = spyOn(core, "warning").mockImplementation(() => {});
|
||||
tempDir = mkdtempSync(join(tmpdir(), "config-paths-"));
|
||||
const remote = join(tempDir, "origin.git");
|
||||
const repo = join(tempDir, "repo");
|
||||
execFileSync("git", ["init", "-q", "--bare", remote]);
|
||||
execFileSync("git", ["init", "-q", "-b", "main", repo]);
|
||||
process.chdir(repo);
|
||||
git("config", "user.email", "[email protected]");
|
||||
git("config", "user.name", "Test User");
|
||||
git("remote", "add", "origin", remote);
|
||||
write("src/index.ts", "base\n");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.chdir(originalCwd);
|
||||
warningSpy.mockRestore();
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
for (const key of INPUTS) {
|
||||
if (saved[key] === undefined) delete process.env[key];
|
||||
else process.env[key] = saved[key];
|
||||
}
|
||||
});
|
||||
|
||||
describe("a named directory", () => {
|
||||
const inputs = () => namedConfigPaths("--plugin-dir ci/plugin");
|
||||
beforeEach(() => write("ci/plugin/a.json", "base\n"));
|
||||
|
||||
test("is left alone if the pull request doesn't change it", () => {
|
||||
startPr();
|
||||
write("src/index.ts", "pr\n");
|
||||
commit("pr");
|
||||
|
||||
expect(restore(inputs())).toEqual([]);
|
||||
expect(git("status", "--porcelain")).toBe("");
|
||||
expect(warningSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("comes from the base branch, without what the pull request adds", () => {
|
||||
startPr();
|
||||
write("ci/plugin/a.json", "pr\n");
|
||||
write("ci/plugin/b.json", "pr\n");
|
||||
write("src/index.ts", "pr\n");
|
||||
commit("pr");
|
||||
write("ci/plugin/generated.json", "by an earlier step\n");
|
||||
|
||||
expect(restore(inputs())).toEqual(["ci/plugin"]);
|
||||
|
||||
expect(read("ci/plugin/a.json")).toBe("base\n");
|
||||
expect(existsSync("ci/plugin/b.json")).toBe(false);
|
||||
expect(read("ci/plugin/generated.json")).toBe("by an earlier step\n");
|
||||
expect(read("src/index.ts")).toBe("pr\n");
|
||||
expect(read(".claude-pr/ci/plugin/a.json")).toBe("pr\n");
|
||||
// Nothing is staged, so a commit doesn't include it.
|
||||
expect(git("diff", "--cached", "--name-only")).toBe("");
|
||||
expect(warningSpy.mock.calls[0][0]).toContain("ci/plugin");
|
||||
});
|
||||
|
||||
test.each(["ci", "ci/plugin", "ci/plugin/a.json"])(
|
||||
"is put back if the pull request has a link at %s",
|
||||
(path) => {
|
||||
startPr();
|
||||
write(join(tempDir, "outside", "keep"), "untouched\n");
|
||||
rmSync(path, { recursive: true });
|
||||
link(path, join(tempDir, "outside"));
|
||||
commit("pr");
|
||||
|
||||
expect(restore(inputs()).sort()).toEqual(
|
||||
path === "ci" ? ["ci", "ci/plugin"] : ["ci/plugin"],
|
||||
);
|
||||
expect(read("ci/plugin/a.json")).toBe("base\n");
|
||||
expect(read(join(tempDir, "outside", "keep"))).toBe("untouched\n");
|
||||
},
|
||||
);
|
||||
|
||||
test("is put back if the pull request has a file in its parent's place", () => {
|
||||
startPr();
|
||||
rmSync("ci", { recursive: true });
|
||||
write("ci", "pr\n");
|
||||
commit("pr");
|
||||
|
||||
expect(restore(inputs()).sort()).toEqual(["ci", "ci/plugin"]);
|
||||
expect(read("ci/plugin/a.json")).toBe("base\n");
|
||||
});
|
||||
|
||||
test("is put back if the pull request makes its parent a submodule", () => {
|
||||
startPr();
|
||||
git("rm", "-rq", "ci");
|
||||
git(
|
||||
"update-index",
|
||||
"--add",
|
||||
"--cacheinfo",
|
||||
`160000,${git("rev-parse", "HEAD")},ci`,
|
||||
);
|
||||
git("commit", "-qm", "pr");
|
||||
mkdirSync("ci");
|
||||
|
||||
expect(restore(inputs()).sort()).toEqual(["ci", "ci/plugin"]);
|
||||
expect(read("ci/plugin/a.json")).toBe("base\n");
|
||||
});
|
||||
|
||||
test("keeps its own links, and loses the pull request's", () => {
|
||||
link("ci/plugin/hooks", "../hooks");
|
||||
startPr();
|
||||
link("ci/plugin/hooks", "../evil");
|
||||
link("ci/plugin/more", "../evil");
|
||||
commit("pr");
|
||||
|
||||
expect(restore(inputs())).toEqual(["ci/plugin"]);
|
||||
expect(readlinkSync("ci/plugin/hooks")).toBe("../hooks");
|
||||
expect(lstatSync("ci/plugin/more", { throwIfNoEntry: false })).toBe(
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("a file that an earlier step created stays", () => {
|
||||
startPr();
|
||||
write("generated/settings.json", "by an earlier step\n");
|
||||
|
||||
expect(restore(named("generated/settings.json"))).toEqual([]);
|
||||
expect(read("generated/settings.json")).toBe("by an earlier step\n");
|
||||
});
|
||||
|
||||
test("a link that the pull request puts above a missing path is removed", () => {
|
||||
startPr();
|
||||
write("evil/settings.json", "pr\n");
|
||||
link("generated", "evil");
|
||||
commit("pr");
|
||||
|
||||
expect(restore(named("generated/settings.json")).sort()).toEqual([
|
||||
"generated",
|
||||
"generated/settings.json",
|
||||
]);
|
||||
expect(existsSync("generated/settings.json")).toBe(false);
|
||||
});
|
||||
|
||||
test("a submodule that the pull request moves stops the run", () => {
|
||||
const add = (oid: string) =>
|
||||
git("update-index", "--add", "--cacheinfo", `160000,${oid},vendor`);
|
||||
commit("first");
|
||||
add(git("rev-parse", "HEAD"));
|
||||
git("commit", "-qm", "base");
|
||||
git("push", "-q", "origin", "main");
|
||||
git("checkout", "-qb", "pr");
|
||||
const inputs = namedConfigPaths("--plugin-dir vendor/plugin");
|
||||
expect(restore(inputs)).toEqual([]);
|
||||
|
||||
add(git("rev-parse", "HEAD"));
|
||||
git("commit", "-qm", "pr");
|
||||
expect(() => restore(inputs)).toThrow("different commits of a submodule");
|
||||
});
|
||||
|
||||
test("the base branch's link above a named path is put back", () => {
|
||||
write("tools/ci/plugin/a.json", "base\n");
|
||||
link("ci", "tools/ci");
|
||||
startPr();
|
||||
rmSync("ci");
|
||||
write("ci/plugin/a.json", "pr\n");
|
||||
commit("pr");
|
||||
|
||||
expect(restore(named("ci/plugin")).sort()).toEqual(["ci", "ci/plugin"]);
|
||||
expect(readlinkSync("ci")).toBe("tools/ci");
|
||||
expect(read("ci/plugin/a.json")).toBe("base\n");
|
||||
});
|
||||
|
||||
test.each(["working-tree-encoding=UTF-16", "text eol=crlf", "ident"])(
|
||||
"a .gitattributes can't make git write a file differently: %s",
|
||||
(attribute) => {
|
||||
write("ci/a.sh", "base $Id$\n");
|
||||
write("ci/b.sh", "base\n");
|
||||
startPr();
|
||||
write("ci/b.sh", "pr\n");
|
||||
commit("pr");
|
||||
write(".gitattributes", `*.sh ${attribute}\n`);
|
||||
git("add", ".gitattributes");
|
||||
git("commit", "-qm", "attributes");
|
||||
rmSync("ci", { recursive: true });
|
||||
git("checkout", "-q", "--", "ci");
|
||||
expect(read("ci/a.sh")).not.toBe("base $Id$\n");
|
||||
|
||||
expect(restore(named("ci/a.sh", "ci/b.sh")).sort()).toEqual([
|
||||
"ci/a.sh",
|
||||
"ci/b.sh",
|
||||
]);
|
||||
expect(read("ci/a.sh")).toBe("base $Id$\n");
|
||||
expect(read("ci/b.sh")).toBe("base\n");
|
||||
},
|
||||
);
|
||||
|
||||
test("the base branch's own .gitattributes are left alone", () => {
|
||||
write("ci/a.sh", "base\n");
|
||||
write(".gitattributes", "*.sh text eol=crlf\n");
|
||||
write("other/.gitattributes", "");
|
||||
startPr();
|
||||
write("other/.gitattributes", "* text\n");
|
||||
commit("pr");
|
||||
rmSync("ci", { recursive: true });
|
||||
git("checkout", "-q", "--", "ci");
|
||||
|
||||
expect(restore(named("ci/a.sh"))).toEqual([]);
|
||||
expect(read("ci/a.sh")).toBe("base\r\n");
|
||||
});
|
||||
|
||||
test("what an earlier step changed stays if the pull request doesn't change it", () => {
|
||||
write("ci/plugin/dist.js", "base\n");
|
||||
write("ci/plugin/a.json", "base\n");
|
||||
startPr();
|
||||
write("ci/plugin/a.json", "pr\n");
|
||||
commit("pr");
|
||||
write("ci/plugin/dist.js", "by an earlier step\n");
|
||||
|
||||
expect(restore(namedConfigPaths("--plugin-dir ci/plugin"))).toEqual([
|
||||
"ci/plugin",
|
||||
]);
|
||||
expect(read("ci/plugin/dist.js")).toBe("by an earlier step\n");
|
||||
expect(read("ci/plugin/a.json")).toBe("base\n");
|
||||
});
|
||||
|
||||
test("a link that leads out of the checkout can't become a file", () => {
|
||||
link("ci/mcp.json", "/opt/shared/mcp.json");
|
||||
startPr();
|
||||
write("ci/mcp.json", "pr\n");
|
||||
commit("pr");
|
||||
|
||||
expect(restore(named("ci/mcp.json"))).toEqual(["ci/mcp.json"]);
|
||||
expect(readlinkSync("ci/mcp.json")).toBe("/opt/shared/mcp.json");
|
||||
});
|
||||
|
||||
test("a path can't go back through a directory", () => {
|
||||
for (const path of [
|
||||
"tools/../ci/s.json",
|
||||
"./a/b/../../s.json",
|
||||
"a/./../s",
|
||||
"tools/../../shared/s.json",
|
||||
join(process.cwd(), "tools") + "/../s.json",
|
||||
]) {
|
||||
process.env.INPUT_SETTINGS = path;
|
||||
expect(() => namedConfigPaths("")).toThrow('Write it without ".."');
|
||||
}
|
||||
for (const path of [
|
||||
"./ci/..s.json",
|
||||
"a..b/s",
|
||||
"../outside/../s.json",
|
||||
process.cwd() + "/../s.json",
|
||||
]) {
|
||||
process.env.INPUT_SETTINGS = path;
|
||||
namedConfigPaths("");
|
||||
}
|
||||
});
|
||||
|
||||
test("a name that differs in case is another file where the file system says so", () => {
|
||||
write("docs/guide.md", "base\n");
|
||||
write("Docs/guide.md/readme", "base\n");
|
||||
const isCaseSensitive = read("docs/guide.md") === "base\n";
|
||||
startPr();
|
||||
if (!isCaseSensitive) return;
|
||||
write("Docs/guide.md/readme", "pr\n");
|
||||
commit("pr");
|
||||
|
||||
expect(restore(named("docs/guide.md"))).toEqual([]);
|
||||
expect(read("Docs/guide.md/readme")).toBe("pr\n");
|
||||
});
|
||||
|
||||
test("names with glob characters are literal in the rules", () => {
|
||||
write("plugins/[ci]/x", "base\n");
|
||||
startPr();
|
||||
write("plugins/[ci]/x", "pr\n");
|
||||
commit("pr");
|
||||
expect(
|
||||
restoreAll(namedConfigPaths("--plugin-dir 'plugins/[ci]'")).denyRules,
|
||||
).toEqual(["Edit(./plugins/\\[ci\\])", "Edit(./plugins/\\[ci\\]/**)"]);
|
||||
});
|
||||
|
||||
test("a workspace reached through a link is the same checkout", () => {
|
||||
write("ci/mcp.json", "base\n");
|
||||
const workspace = join(tempDir, "workspace");
|
||||
symlinkSync(process.cwd(), workspace);
|
||||
process.env.GITHUB_WORKSPACE = workspace;
|
||||
startPr();
|
||||
write("ci/mcp.json", "pr\n");
|
||||
commit("pr");
|
||||
|
||||
expect(
|
||||
restore(namedConfigPaths(`--mcp-config ${workspace}/ci/mcp.json`)),
|
||||
).toEqual(["ci/mcp.json"]);
|
||||
expect(read("ci/mcp.json")).toBe("base\n");
|
||||
});
|
||||
|
||||
test("a session can't edit what the inputs name, changed or not", () => {
|
||||
write("ci/plugin/check.sh", "base\n");
|
||||
write("ci/s.json", "base\n");
|
||||
startPr();
|
||||
write("ci/s.json", "pr\n");
|
||||
commit("pr");
|
||||
|
||||
const { replaced, denyRules } = restoreAll(
|
||||
namedConfigPaths("--plugin-dir ci/plugin --settings ci/s.json"),
|
||||
);
|
||||
expect(replaced).toEqual(["ci/s.json"]);
|
||||
expect(denyRules.sort()).toEqual([
|
||||
"Edit(./ci/plugin)",
|
||||
"Edit(./ci/plugin/**)",
|
||||
"Edit(./ci/s.json)",
|
||||
"Edit(./ci/s.json/**)",
|
||||
]);
|
||||
});
|
||||
|
||||
test("what nothing names stays, also if Claude's config links to it", () => {
|
||||
write("docs/guide.md", "base\n");
|
||||
link("CLAUDE.md", "docs/guide.md");
|
||||
startPr();
|
||||
write("docs/guide.md", "pr\n");
|
||||
commit("pr");
|
||||
|
||||
expect(restoreAll(namedConfigPaths("--model m"))).toEqual({
|
||||
replaced: [],
|
||||
denyRules: [],
|
||||
});
|
||||
});
|
||||
|
||||
describe("what the workflow's inputs name", () => {
|
||||
test("comes from the base branch, or is removed if only the pull request has it", () => {
|
||||
write("ci/settings.json", "base\n");
|
||||
write("ci/plugin/hooks/hooks.json", "base\n");
|
||||
startPr();
|
||||
write("ci/settings.json", "pr\n");
|
||||
write("ci/plugin/hooks/hooks.json", "pr\n");
|
||||
write("ci/mcp.json", "pr\n");
|
||||
write("ci/other.json", "pr\n");
|
||||
commit("pr");
|
||||
process.env.INPUT_SETTINGS = "ci/settings.json";
|
||||
|
||||
const named = namedConfigPaths(
|
||||
"--mcp-config ci/mcp.json --plugin-dir ./ci/plugin",
|
||||
);
|
||||
expect(restore(named).sort()).toEqual([
|
||||
"ci/mcp.json",
|
||||
"ci/plugin",
|
||||
"ci/settings.json",
|
||||
]);
|
||||
|
||||
expect(read("ci/settings.json")).toBe("base\n");
|
||||
expect(read("ci/plugin/hooks/hooks.json")).toBe("base\n");
|
||||
expect(existsSync("ci/mcp.json")).toBe(false);
|
||||
expect(read("ci/other.json")).toBe("pr\n");
|
||||
});
|
||||
|
||||
test("can't be the whole repository", () => {
|
||||
startPr();
|
||||
write("hooks/hooks.json", "pr\n");
|
||||
commit("pr");
|
||||
|
||||
expect(() => restore(namedConfigPaths("--plugin-dir ."))).toThrow(
|
||||
"Put the plugin in a subdirectory",
|
||||
);
|
||||
});
|
||||
|
||||
test("is the manifest and the plugins of a marketplace at the root", () => {
|
||||
write(
|
||||
".claude-plugin/marketplace.json",
|
||||
JSON.stringify({
|
||||
metadata: { pluginRoot: "./more" },
|
||||
plugins: [
|
||||
{ name: "a", source: "./plugins/a/" },
|
||||
{ name: "b", source: "b" },
|
||||
{ name: "d", source: "../d" },
|
||||
{ name: "c", source: { source: "github", repo: "o/c" } },
|
||||
],
|
||||
}),
|
||||
);
|
||||
write("plugins/a/hooks/hooks.json", "base\n");
|
||||
write("more/b/hooks/hooks.json", "base\n");
|
||||
startPr();
|
||||
write(
|
||||
".claude-plugin/marketplace.json",
|
||||
JSON.stringify({ plugins: [{ name: "a", source: "./evil" }] }),
|
||||
);
|
||||
write("plugins/a/hooks/hooks.json", "pr\n");
|
||||
write("more/b/hooks/hooks.json", "pr\n");
|
||||
commit("pr");
|
||||
process.env.INPUT_PLUGIN_MARKETPLACES = "https://example.com/x.git\n./\n";
|
||||
|
||||
expect(restore(namedConfigPaths("")).sort()).toEqual([
|
||||
".claude-plugin",
|
||||
"more/b",
|
||||
"plugins/a",
|
||||
]);
|
||||
expect(read("plugins/a/hooks/hooks.json")).toBe("base\n");
|
||||
expect(read("more/b/hooks/hooks.json")).toBe("base\n");
|
||||
expect(read(".claude-plugin/marketplace.json")).not.toContain("evil");
|
||||
expect(read("src/index.ts")).toBe("base\n");
|
||||
});
|
||||
|
||||
test.each([
|
||||
["ci/marketplace.json", "ci/marketplace.json"],
|
||||
["./", ".claude-plugin/marketplace.json"],
|
||||
])("finds the plugins of a marketplace at %s", (input, path) => {
|
||||
const manifest = JSON.stringify({
|
||||
plugins: [{ name: "a", source: "./plugins/a" }],
|
||||
});
|
||||
write(path, manifest);
|
||||
write("plugins/a/hooks/hooks.json", "base\n");
|
||||
startPr();
|
||||
write("plugins/a/hooks/hooks.json", "pr\n");
|
||||
commit("pr");
|
||||
process.env.INPUT_PLUGIN_MARKETPLACES = input.startsWith(".")
|
||||
? input
|
||||
: `./${input}`;
|
||||
|
||||
expect(restore(namedConfigPaths(""))).toEqual(["plugins/a"]);
|
||||
expect(read("plugins/a/hooks/hooks.json")).toBe("base\n");
|
||||
});
|
||||
|
||||
test("is a whole marketplace in a directory", () => {
|
||||
write("market/.claude-plugin/marketplace.json", "base\n");
|
||||
write("market/a/hooks.json", "base\n");
|
||||
startPr();
|
||||
write("market/a/hooks.json", "pr\n");
|
||||
commit("pr");
|
||||
for (const input of [
|
||||
"./market",
|
||||
"./market/.claude-plugin/marketplace.json",
|
||||
]) {
|
||||
process.env.INPUT_PLUGIN_MARKETPLACES = input;
|
||||
expect(restore(namedConfigPaths(""))).toEqual(["market"]);
|
||||
expect(read("market/a/hooks.json")).toBe("base\n");
|
||||
git("checkout", "-q", "--", "market");
|
||||
}
|
||||
});
|
||||
|
||||
test("can't be a plugin that is the whole repository", () => {
|
||||
write(
|
||||
".claude-plugin/marketplace.json",
|
||||
JSON.stringify({ plugins: [{ name: "a", source: "./" }] }),
|
||||
);
|
||||
startPr();
|
||||
process.env.INPUT_PLUGIN_MARKETPLACES = "./";
|
||||
|
||||
expect(() => restore(namedConfigPaths(""))).toThrow(
|
||||
"Put the plugin in a subdirectory",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("namedConfigPaths", () => {
|
||||
test("finds paths in every input that names files", () => {
|
||||
process.env.INPUT_SETTINGS = " .github/settings.json ";
|
||||
process.env.INPUT_PLUGIN_MARKETPLACES =
|
||||
"./market\n../outside\n/elsewhere\n";
|
||||
expect(
|
||||
namedConfigPaths(
|
||||
`--mcp-config '{"mcpServers":{}}' a.json b.json
|
||||
--plugin-dir=plugin --settings '{"a":1}' --agents agents.json
|
||||
--append-system-prompt-file p.md --system-prompt-file ../x.md
|
||||
--plugin-dir-no-mcp 2024 --append-subagent-system-prompt-file q.md
|
||||
--setting-sources user --json-schema '{}'
|
||||
--allowedTools Read --model m`,
|
||||
),
|
||||
).toEqual({
|
||||
paths: [
|
||||
".github/settings.json",
|
||||
"a.json",
|
||||
"b.json",
|
||||
"plugin",
|
||||
"agents.json",
|
||||
"p.md",
|
||||
"2024",
|
||||
"q.md",
|
||||
],
|
||||
marketplaces: ["market"],
|
||||
});
|
||||
});
|
||||
|
||||
test("finds the project config in a --project-config-root", () => {
|
||||
startPr();
|
||||
const { paths } = namedConfigPaths("--project-config-root app");
|
||||
expect(paths).toContain("app/.claude");
|
||||
expect(paths).toContain("app/.mcp.json");
|
||||
expect(paths).not.toContain("app");
|
||||
expect(restore(namedConfigPaths(`--project-config-root .`))).toEqual([]);
|
||||
});
|
||||
|
||||
test("finds nothing in inputs that name no files in the checkout", () => {
|
||||
process.env.INPUT_SETTINGS = '{"permissions":{}}';
|
||||
process.env.INPUT_PLUGIN_MARKETPLACES = "https://example.com/x.git";
|
||||
expect(namedConfigPaths("--mcp-config /etc/mcp.json --settings")).toEqual({
|
||||
paths: [],
|
||||
marketplaces: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -282,7 +282,7 @@ describe("git wrappers", () => {
|
||||
|
||||
describe("with files taken from another branch", () => {
|
||||
const RESTORED =
|
||||
":(top).claude\n:(top)CLAUDE.md\n:(top)AGENTS.md\n:(top).mcp.json\n:(top,glob)**/package.json\n";
|
||||
":(top,literal).claude\n:(top,literal)CLAUDE.md\n:(top,literal)AGENTS.md\n:(top,literal).mcp.json\n:(top,glob)**/package.json\n";
|
||||
const write = (path: string, content: string) => {
|
||||
mkdirSync(join(repo, path, ".."), { recursive: true });
|
||||
writeFileSync(join(repo, path), content);
|
||||
|
||||
@@ -441,7 +441,7 @@ describe("session guard", () => {
|
||||
pinRestoredPaths([".claude", "package.json"]);
|
||||
const restoredFile = join(dir, "scripts/.restored-paths");
|
||||
expect(readFileSync(restoredFile, "utf8")).toBe(
|
||||
":(top).claude\n:(top,glob)**/package.json\n",
|
||||
":(top,literal).claude\n:(top,glob)**/package.json\n",
|
||||
);
|
||||
clearSessionState();
|
||||
expect(existsSync(join(dir, "scripts/.push-branch"))).toBe(false);
|
||||
|
||||
Reference in New Issue
Block a user