Apply setting_sources default at runtime instead of via YAML default

Keeps the input default empty so claude_args --setting-sources is not
shadowed; the wrapper applies user,project,local as the runtime fallback,
base-action applies user.

🏠 Remote-Dev: homespace
This commit is contained in:
Octavian Guzu 2026-04-23 17:19:03 +00:00
parent 625ab08afd
commit 12f457aad8
No known key found for this signature in database
5 changed files with 46 additions and 6 deletions

View File

@ -63,9 +63,9 @@ inputs:
required: false
default: ""
setting_sources:
description: "Comma-separated list of setting sources to load (user, project, local). Defaults to 'user,project,local' — project settings are safe here because .claude/ is restored from the PR base branch before execution. Set to 'user' to ignore in-repo settings entirely."
description: "Comma-separated list of setting sources to load (user, project, local). When unset, the action applies 'user,project,local' at runtime — project settings are safe here because .claude/ is restored from the PR base branch before execution. Set to 'user' to ignore in-repo settings entirely."
required: false
default: "user,project,local"
default: ""
# Auth configuration
anthropic_api_key:

View File

@ -272,14 +272,16 @@ export function parseSdkOptions(options: ClaudeOptions): ParsedSdkOptions {
env,
// Setting sources precedence: direct input > --setting-sources in claude_args > default.
// Default is ["user"] only: project/local settings additively merge permissions with
// allowedTools, which silently expands a workflow's intended allow-set. Workflows that
// want project settings must opt in explicitly.
// The default is supplied by the caller (base-action uses ["user"]; the wrapper action
// uses ["user","project","local"]). Both action.yml files leave the YAML default empty
// so that --setting-sources in claude_args is reachable when the input is not set.
settingSources: (options.settingSources
? options.settingSources.split(",").map((s) => s.trim())
: extraArgs["setting-sources"]
? extraArgs["setting-sources"].split(",").map((s) => s.trim())
: ["user"]) as SdkOptions["settingSources"],
: (options.defaultSettingSources ?? [
"user",
])) as SdkOptions["settingSources"],
};
// Remove setting-sources from extraArgs to avoid passing it twice

View File

@ -1,6 +1,7 @@
import { runClaudeWithSdk } from "./run-claude-sdk";
import type { ClaudeRunResult } from "./run-claude-sdk";
import { parseSdkOptions } from "./parse-sdk-options";
import type { Options as SdkOptions } from "@anthropic-ai/claude-agent-sdk";
export type ClaudeOptions = {
claudeArgs?: string;
@ -15,6 +16,7 @@ export type ClaudeOptions = {
fallbackModel?: string;
showFullOutput?: string;
settingSources?: string;
defaultSettingSources?: SdkOptions["settingSources"];
};
export async function runClaude(

View File

@ -476,5 +476,40 @@ describe("parseSdkOptions", () => {
"local",
]);
});
test("should use defaultSettingSources when nothing else is set", () => {
const options: ClaudeOptions = {
defaultSettingSources: ["user", "project", "local"],
};
const result = parseSdkOptions(options);
expect(result.sdkOptions.settingSources).toEqual([
"user",
"project",
"local",
]);
});
test("--setting-sources in claudeArgs should win over defaultSettingSources", () => {
const options: ClaudeOptions = {
claudeArgs: "--setting-sources user",
defaultSettingSources: ["user", "project", "local"],
};
const result = parseSdkOptions(options);
expect(result.sdkOptions.settingSources).toEqual(["user"]);
});
test("empty-string settingSources falls through to claudeArgs then default", () => {
// YAML default: "" — INPUT_SETTING_SOURCES is "" when the user doesn't set the input
const options: ClaudeOptions = {
settingSources: "",
claudeArgs: "--setting-sources user,project",
defaultSettingSources: ["user", "project", "local"],
};
const result = parseSdkOptions(options);
expect(result.sdkOptions.settingSources).toEqual(["user", "project"]);
});
});
});

View File

@ -279,6 +279,7 @@ async function run() {
pathToClaudeCodeExecutable: claudeExecutable,
showFullOutput: process.env.INPUT_SHOW_FULL_OUTPUT,
settingSources: process.env.INPUT_SETTING_SOURCES,
defaultSettingSources: ["user", "project", "local"],
});
claudeSuccess = claudeResult.conclusion === "success";