mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
tests, typecheck, format
This commit is contained in:
@@ -138,13 +138,13 @@ export const tagMode: Mode = {
|
|||||||
"Bash(git status:*)",
|
"Bash(git status:*)",
|
||||||
"Bash(git diff:*)",
|
"Bash(git diff:*)",
|
||||||
"Bash(git log:*)",
|
"Bash(git log:*)",
|
||||||
"Bash(git rm:*)"
|
"Bash(git rm:*)",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// When using commit signing, use MCP file ops tools
|
// When using commit signing, use MCP file ops tools
|
||||||
tagModeTools.push(
|
tagModeTools.push(
|
||||||
"mcp__github_file_ops__commit_files",
|
"mcp__github_file_ops__commit_files",
|
||||||
"mcp__github_file_ops__delete_files"
|
"mcp__github_file_ops__delete_files",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ export const tagMode: Mode = {
|
|||||||
// Escape single quotes in JSON to prevent shell injection
|
// Escape single quotes in JSON to prevent shell injection
|
||||||
const escapedMcpConfig = mcpConfig.replace(/'/g, "'\\''");
|
const escapedMcpConfig = mcpConfig.replace(/'/g, "'\\''");
|
||||||
let claudeArgs = `--mcp-config '${escapedMcpConfig}' `;
|
let claudeArgs = `--mcp-config '${escapedMcpConfig}' `;
|
||||||
claudeArgs += `--allowedTools "${tagModeTools.join(',')}" `;
|
claudeArgs += `--allowedTools "${tagModeTools.join(",")}" `;
|
||||||
if (userClaudeArgs) {
|
if (userClaudeArgs) {
|
||||||
claudeArgs += userClaudeArgs;
|
claudeArgs += userClaudeArgs;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,36 +95,30 @@ describe("Agent Mode", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("prepare method sets up tools environment variables correctly", async () => {
|
test("prepare method passes through claude_args", async () => {
|
||||||
// Clear any previous calls before this test
|
// Clear any previous calls before this test
|
||||||
exportVariableSpy.mockClear();
|
exportVariableSpy.mockClear();
|
||||||
setOutputSpy.mockClear();
|
setOutputSpy.mockClear();
|
||||||
|
|
||||||
const contextWithCustomTools = createMockAutomationContext({
|
const contextWithCustomArgs = createMockAutomationContext({
|
||||||
eventName: "workflow_dispatch",
|
eventName: "workflow_dispatch",
|
||||||
});
|
});
|
||||||
contextWithCustomTools.inputs.allowedTools = ["CustomTool1", "CustomTool2"];
|
|
||||||
contextWithCustomTools.inputs.disallowedTools = ["BadTool"];
|
// Set CLAUDE_ARGS environment variable
|
||||||
|
process.env.CLAUDE_ARGS = "--model claude-sonnet-4 --max-turns 10";
|
||||||
|
|
||||||
const mockOctokit = {} as any;
|
const mockOctokit = {} as any;
|
||||||
const result = await agentMode.prepare({
|
const result = await agentMode.prepare({
|
||||||
context: contextWithCustomTools,
|
context: contextWithCustomArgs,
|
||||||
octokit: mockOctokit,
|
octokit: mockOctokit,
|
||||||
githubToken: "test-token",
|
githubToken: "test-token",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Verify that both ALLOWED_TOOLS and DISALLOWED_TOOLS are set
|
// Verify claude_args is passed through
|
||||||
expect(exportVariableSpy).toHaveBeenCalledWith(
|
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||||
"ALLOWED_TOOLS",
|
"claude_args",
|
||||||
"Edit,MultiEdit,Glob,Grep,LS,Read,Write,CustomTool1,CustomTool2",
|
"--model claude-sonnet-4 --max-turns 10",
|
||||||
);
|
);
|
||||||
expect(exportVariableSpy).toHaveBeenCalledWith(
|
|
||||||
"DISALLOWED_TOOLS",
|
|
||||||
"WebSearch,WebFetch,BadTool",
|
|
||||||
);
|
|
||||||
|
|
||||||
// Verify MCP config is set
|
|
||||||
expect(setOutputSpy).toHaveBeenCalledWith("mcp_config", expect.any(String));
|
|
||||||
|
|
||||||
// Verify return structure
|
// Verify return structure
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
@@ -136,15 +130,17 @@ describe("Agent Mode", () => {
|
|||||||
},
|
},
|
||||||
mcpConfig: expect.any(String),
|
mcpConfig: expect.any(String),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
delete process.env.CLAUDE_ARGS;
|
||||||
});
|
});
|
||||||
|
|
||||||
test("prepare method creates prompt file with correct content", async () => {
|
test("prepare method creates prompt file with correct content", async () => {
|
||||||
const contextWithPrompts = createMockAutomationContext({
|
const contextWithPrompts = createMockAutomationContext({
|
||||||
eventName: "workflow_dispatch",
|
eventName: "workflow_dispatch",
|
||||||
});
|
});
|
||||||
contextWithPrompts.inputs.overridePrompt = "Custom override prompt";
|
// In v1-dev, we only have the unified prompt field
|
||||||
contextWithPrompts.inputs.directPrompt =
|
contextWithPrompts.inputs.prompt = "Custom prompt content";
|
||||||
"Direct prompt (should be ignored)";
|
|
||||||
|
|
||||||
const mockOctokit = {} as any;
|
const mockOctokit = {} as any;
|
||||||
await agentMode.prepare({
|
await agentMode.prepare({
|
||||||
@@ -155,6 +151,6 @@ describe("Agent Mode", () => {
|
|||||||
|
|
||||||
// Note: We can't easily test file creation in this unit test,
|
// Note: We can't easily test file creation in this unit test,
|
||||||
// but we can verify the method completes without errors
|
// but we can verify the method completes without errors
|
||||||
expect(setOutputSpy).toHaveBeenCalledWith("mcp_config", expect.any(String));
|
expect(setOutputSpy).toHaveBeenCalledWith("claude_args", "");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ describe("Mode Registry", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("getMode uses tag mode for @claude mention without prompt", () => {
|
test("getMode uses tag mode for @claude mention without prompt", () => {
|
||||||
|
// Ensure PROMPT env var is not set (clean up from previous tests)
|
||||||
|
const originalPrompt = process.env.PROMPT;
|
||||||
|
delete process.env.PROMPT;
|
||||||
|
|
||||||
const contextWithMention = createMockContext({
|
const contextWithMention = createMockContext({
|
||||||
eventName: "issue_comment",
|
eventName: "issue_comment",
|
||||||
payload: {
|
payload: {
|
||||||
@@ -92,11 +96,17 @@ describe("Mode Registry", () => {
|
|||||||
} as any,
|
} as any,
|
||||||
inputs: {
|
inputs: {
|
||||||
triggerPhrase: "@claude",
|
triggerPhrase: "@claude",
|
||||||
|
prompt: "",
|
||||||
} as any,
|
} as any,
|
||||||
});
|
});
|
||||||
const mode = getMode(contextWithMention);
|
const mode = getMode(contextWithMention);
|
||||||
expect(mode).toBe(tagMode);
|
expect(mode).toBe(tagMode);
|
||||||
expect(mode.name).toBe("tag");
|
expect(mode.name).toBe("tag");
|
||||||
|
|
||||||
|
// Restore original value if it existed
|
||||||
|
if (originalPrompt !== undefined) {
|
||||||
|
process.env.PROMPT = originalPrompt;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Removed test - explicit mode override no longer supported in v1.0
|
// Removed test - explicit mode override no longer supported in v1.0
|
||||||
|
|||||||
Reference in New Issue
Block a user