From 65d9b310c78772a9809119a8c782abfe069088f3 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Mon, 11 Aug 2025 07:51:09 -0700 Subject: [PATCH] tests, typecheck, format --- src/modes/tag/index.ts | 18 +++++++++--------- test/modes/agent.test.ts | 36 ++++++++++++++++-------------------- test/modes/registry.test.ts | 10 ++++++++++ 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/modes/tag/index.ts b/src/modes/tag/index.ts index 4e8e277..28aa84b 100644 --- a/src/modes/tag/index.ts +++ b/src/modes/tag/index.ts @@ -115,12 +115,12 @@ export const tagMode: Mode = { }); // Don't output mcp_config separately anymore - include in claude_args - + // Build claude_args for tag mode with required tools // Tag mode REQUIRES these tools to function properly const tagModeTools = [ "Edit", - "MultiEdit", + "MultiEdit", "Glob", "Grep", "LS", @@ -128,7 +128,7 @@ export const tagMode: Mode = { "Write", "mcp__github_comment__update_claude_comment", ]; - + // Add git commands when not using commit signing if (!context.inputs.useCommitSigning) { tagModeTools.push( @@ -138,28 +138,28 @@ export const tagMode: Mode = { "Bash(git status:*)", "Bash(git diff:*)", "Bash(git log:*)", - "Bash(git rm:*)" + "Bash(git rm:*)", ); } else { // When using commit signing, use MCP file ops tools tagModeTools.push( "mcp__github_file_ops__commit_files", - "mcp__github_file_ops__delete_files" + "mcp__github_file_ops__delete_files", ); } - + const userClaudeArgs = process.env.CLAUDE_ARGS || ""; - + // Build complete claude_args with MCP config (as JSON string), tools, and user args // Note: Once Claude supports multiple --mcp-config flags, we can pass as file path // Escape single quotes in JSON to prevent shell injection const escapedMcpConfig = mcpConfig.replace(/'/g, "'\\''"); let claudeArgs = `--mcp-config '${escapedMcpConfig}' `; - claudeArgs += `--allowedTools "${tagModeTools.join(',')}" `; + claudeArgs += `--allowedTools "${tagModeTools.join(",")}" `; if (userClaudeArgs) { claudeArgs += userClaudeArgs; } - + core.setOutput("claude_args", claudeArgs.trim()); return { diff --git a/test/modes/agent.test.ts b/test/modes/agent.test.ts index 2e0b789..198535a 100644 --- a/test/modes/agent.test.ts +++ b/test/modes/agent.test.ts @@ -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 exportVariableSpy.mockClear(); setOutputSpy.mockClear(); - const contextWithCustomTools = createMockAutomationContext({ + const contextWithCustomArgs = createMockAutomationContext({ 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 result = await agentMode.prepare({ - context: contextWithCustomTools, + context: contextWithCustomArgs, octokit: mockOctokit, githubToken: "test-token", }); - // Verify that both ALLOWED_TOOLS and DISALLOWED_TOOLS are set - expect(exportVariableSpy).toHaveBeenCalledWith( - "ALLOWED_TOOLS", - "Edit,MultiEdit,Glob,Grep,LS,Read,Write,CustomTool1,CustomTool2", + // Verify claude_args is passed through + expect(setOutputSpy).toHaveBeenCalledWith( + "claude_args", + "--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 expect(result).toEqual({ @@ -136,15 +130,17 @@ describe("Agent Mode", () => { }, mcpConfig: expect.any(String), }); + + // Clean up + delete process.env.CLAUDE_ARGS; }); test("prepare method creates prompt file with correct content", async () => { const contextWithPrompts = createMockAutomationContext({ eventName: "workflow_dispatch", }); - contextWithPrompts.inputs.overridePrompt = "Custom override prompt"; - contextWithPrompts.inputs.directPrompt = - "Direct prompt (should be ignored)"; + // In v1-dev, we only have the unified prompt field + contextWithPrompts.inputs.prompt = "Custom prompt content"; const mockOctokit = {} as any; await agentMode.prepare({ @@ -155,6 +151,6 @@ describe("Agent Mode", () => { // Note: We can't easily test file creation in this unit test, // but we can verify the method completes without errors - expect(setOutputSpy).toHaveBeenCalledWith("mcp_config", expect.any(String)); + expect(setOutputSpy).toHaveBeenCalledWith("claude_args", ""); }); }); diff --git a/test/modes/registry.test.ts b/test/modes/registry.test.ts index a81323c..91746d5 100644 --- a/test/modes/registry.test.ts +++ b/test/modes/registry.test.ts @@ -82,6 +82,10 @@ describe("Mode Registry", () => { }); 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({ eventName: "issue_comment", payload: { @@ -92,11 +96,17 @@ describe("Mode Registry", () => { } as any, inputs: { triggerPhrase: "@claude", + prompt: "", } as any, }); const mode = getMode(contextWithMention); expect(mode).toBe(tagMode); 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