mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
Simplify agent mode and re-add additional_permissions input
- Agent mode now only triggers when explicit prompt is provided - Removed automatic triggering for workflow_dispatch/schedule without prompt - Re-added additional_permissions input for requesting GitHub permissions - Fixed TypeScript types for mock context helpers to properly handle partial inputs - Updated documentation to reflect simplified mode behavior
This commit is contained in:
@@ -27,8 +27,12 @@ const defaultRepository = {
|
||||
full_name: "test-owner/test-repo",
|
||||
};
|
||||
|
||||
type MockContextOverrides = Omit<Partial<ParsedGitHubContext>, 'inputs'> & {
|
||||
inputs?: Partial<ParsedGitHubContext['inputs']>;
|
||||
};
|
||||
|
||||
export const createMockContext = (
|
||||
overrides: Partial<ParsedGitHubContext> = {},
|
||||
overrides: MockContextOverrides = {},
|
||||
): ParsedGitHubContext => {
|
||||
const baseContext: ParsedGitHubContext = {
|
||||
runId: "1234567890",
|
||||
@@ -42,15 +46,19 @@ export const createMockContext = (
|
||||
inputs: defaultInputs,
|
||||
};
|
||||
|
||||
if (overrides.inputs) {
|
||||
overrides.inputs = { ...defaultInputs, ...overrides.inputs };
|
||||
}
|
||||
const mergedInputs = overrides.inputs
|
||||
? { ...defaultInputs, ...overrides.inputs }
|
||||
: defaultInputs;
|
||||
|
||||
return { ...baseContext, ...overrides };
|
||||
return { ...baseContext, ...overrides, inputs: mergedInputs };
|
||||
};
|
||||
|
||||
type MockAutomationOverrides = Omit<Partial<AutomationContext>, 'inputs'> & {
|
||||
inputs?: Partial<AutomationContext['inputs']>;
|
||||
};
|
||||
|
||||
export const createMockAutomationContext = (
|
||||
overrides: Partial<AutomationContext> = {},
|
||||
overrides: MockAutomationOverrides = {},
|
||||
): AutomationContext => {
|
||||
const baseContext: AutomationContext = {
|
||||
runId: "1234567890",
|
||||
@@ -62,7 +70,11 @@ export const createMockAutomationContext = (
|
||||
inputs: defaultInputs,
|
||||
};
|
||||
|
||||
return { ...baseContext, ...overrides };
|
||||
const mergedInputs = overrides.inputs
|
||||
? { ...defaultInputs, ...overrides.inputs }
|
||||
: defaultInputs;
|
||||
|
||||
return { ...baseContext, ...overrides, inputs: mergedInputs };
|
||||
};
|
||||
|
||||
export const mockIssueOpenedContext: ParsedGitHubContext = {
|
||||
|
||||
@@ -15,7 +15,7 @@ describe("Agent Mode", () => {
|
||||
test("agent mode has correct properties", () => {
|
||||
expect(agentMode.name).toBe("agent");
|
||||
expect(agentMode.description).toBe(
|
||||
"Automation mode for workflow_dispatch and schedule events",
|
||||
"Direct automation mode for explicit prompts",
|
||||
);
|
||||
expect(agentMode.shouldCreateTrackingComment()).toBe(false);
|
||||
expect(agentMode.getAllowedTools()).toEqual([]);
|
||||
@@ -31,19 +31,19 @@ describe("Agent Mode", () => {
|
||||
expect(Object.keys(context)).toEqual(["mode", "githubContext"]);
|
||||
});
|
||||
|
||||
test("agent mode only triggers for workflow_dispatch and schedule events", () => {
|
||||
// Should trigger for automation events
|
||||
test("agent mode only triggers when prompt is provided", () => {
|
||||
// Should NOT trigger for automation events without prompt
|
||||
const workflowDispatchContext = createMockAutomationContext({
|
||||
eventName: "workflow_dispatch",
|
||||
});
|
||||
expect(agentMode.shouldTrigger(workflowDispatchContext)).toBe(true);
|
||||
expect(agentMode.shouldTrigger(workflowDispatchContext)).toBe(false);
|
||||
|
||||
const scheduleContext = createMockAutomationContext({
|
||||
eventName: "schedule",
|
||||
});
|
||||
expect(agentMode.shouldTrigger(scheduleContext)).toBe(true);
|
||||
expect(agentMode.shouldTrigger(scheduleContext)).toBe(false);
|
||||
|
||||
// Should NOT trigger for entity events
|
||||
// Should NOT trigger for entity events without prompt
|
||||
const entityEvents = [
|
||||
"issue_comment",
|
||||
"pull_request",
|
||||
@@ -52,8 +52,32 @@ describe("Agent Mode", () => {
|
||||
] as const;
|
||||
|
||||
entityEvents.forEach((eventName) => {
|
||||
const context = createMockContext({ eventName });
|
||||
expect(agentMode.shouldTrigger(context)).toBe(false);
|
||||
const contextNoPrompt = createMockContext({ eventName });
|
||||
expect(agentMode.shouldTrigger(contextNoPrompt)).toBe(false);
|
||||
});
|
||||
|
||||
// Should trigger for ANY event when prompt is provided
|
||||
const allEvents = [
|
||||
"workflow_dispatch",
|
||||
"schedule",
|
||||
"issue_comment",
|
||||
"pull_request",
|
||||
"pull_request_review",
|
||||
"issues",
|
||||
] as const;
|
||||
|
||||
allEvents.forEach((eventName) => {
|
||||
const contextWithPrompt =
|
||||
eventName === "workflow_dispatch" || eventName === "schedule"
|
||||
? createMockAutomationContext({
|
||||
eventName,
|
||||
inputs: { prompt: "Do something" },
|
||||
})
|
||||
: createMockContext({
|
||||
eventName,
|
||||
inputs: { prompt: "Do something" },
|
||||
});
|
||||
expect(agentMode.shouldTrigger(contextWithPrompt)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user