mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
simplify: remove workflow_dispatch/schedule from create-prompt
- Remove workflow_dispatch and schedule event handling from create-prompt since agent mode doesn't use the standard prompt generation flow - Enforce mode compatibility at selection time in the registry instead of runtime validation in tag mode - Add explanatory comment in agent mode about why prompt file is needed - Update tests to reflect simplified event handling This reduces code duplication and makes the separation between tag mode (entity-based events) and agent mode (automation events) clearer.
This commit is contained in:
@@ -3,23 +3,60 @@ import { getMode, isValidMode } from "../../src/modes/registry";
|
||||
import type { ModeName } from "../../src/modes/types";
|
||||
import { tagMode } from "../../src/modes/tag";
|
||||
import { agentMode } from "../../src/modes/agent";
|
||||
import { createMockContext } from "../mockContext";
|
||||
|
||||
describe("Mode Registry", () => {
|
||||
test("getMode returns tag mode by default", () => {
|
||||
const mode = getMode("tag");
|
||||
const mockContext = createMockContext({
|
||||
eventName: "issue_comment",
|
||||
});
|
||||
|
||||
const mockWorkflowDispatchContext = createMockContext({
|
||||
eventName: "workflow_dispatch",
|
||||
});
|
||||
|
||||
const mockScheduleContext = createMockContext({
|
||||
eventName: "schedule",
|
||||
});
|
||||
|
||||
test("getMode returns tag mode for standard events", () => {
|
||||
const mode = getMode("tag", mockContext);
|
||||
expect(mode).toBe(tagMode);
|
||||
expect(mode.name).toBe("tag");
|
||||
});
|
||||
|
||||
test("getMode returns agent mode", () => {
|
||||
const mode = getMode("agent");
|
||||
const mode = getMode("agent", mockContext);
|
||||
expect(mode).toBe(agentMode);
|
||||
expect(mode.name).toBe("agent");
|
||||
});
|
||||
|
||||
test("getMode throws error for tag mode with workflow_dispatch event", () => {
|
||||
expect(() => getMode("tag", mockWorkflowDispatchContext)).toThrow(
|
||||
"Tag mode cannot handle workflow_dispatch events. Use 'agent' mode for automation events.",
|
||||
);
|
||||
});
|
||||
|
||||
test("getMode throws error for tag mode with schedule event", () => {
|
||||
expect(() => getMode("tag", mockScheduleContext)).toThrow(
|
||||
"Tag mode cannot handle schedule events. Use 'agent' mode for automation events.",
|
||||
);
|
||||
});
|
||||
|
||||
test("getMode allows agent mode for workflow_dispatch event", () => {
|
||||
const mode = getMode("agent", mockWorkflowDispatchContext);
|
||||
expect(mode).toBe(agentMode);
|
||||
expect(mode.name).toBe("agent");
|
||||
});
|
||||
|
||||
test("getMode allows agent mode for schedule event", () => {
|
||||
const mode = getMode("agent", mockScheduleContext);
|
||||
expect(mode).toBe(agentMode);
|
||||
expect(mode.name).toBe("agent");
|
||||
});
|
||||
|
||||
test("getMode throws error for invalid mode", () => {
|
||||
const invalidMode = "invalid" as unknown as ModeName;
|
||||
expect(() => getMode(invalidMode)).toThrow(
|
||||
expect(() => getMode(invalidMode, mockContext)).toThrow(
|
||||
"Invalid mode 'invalid'. Valid modes are: 'tag', 'agent'. Please check your workflow configuration.",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -29,83 +29,6 @@ describe("parseEnvVarsWithContext", () => {
|
||||
process.env = originalEnv;
|
||||
});
|
||||
|
||||
describe("workflow_dispatch event", () => {
|
||||
beforeEach(() => {
|
||||
process.env = {
|
||||
...BASE_ENV,
|
||||
BASE_BRANCH: "main",
|
||||
};
|
||||
});
|
||||
|
||||
test("should parse workflow_dispatch event correctly", () => {
|
||||
const mockWorkflowDispatchContext = createMockContext({
|
||||
eventName: "workflow_dispatch",
|
||||
payload: {
|
||||
inputs: {
|
||||
task: "Run automated task",
|
||||
},
|
||||
repository: {
|
||||
name: "test-repo",
|
||||
owner: {
|
||||
login: "test-owner",
|
||||
},
|
||||
},
|
||||
sender: {
|
||||
login: "test-user",
|
||||
},
|
||||
workflow: "test.yml",
|
||||
},
|
||||
});
|
||||
|
||||
const result = prepareContext(
|
||||
mockWorkflowDispatchContext,
|
||||
"",
|
||||
"main",
|
||||
undefined,
|
||||
);
|
||||
|
||||
expect(result.repository).toBe("test-owner/test-repo");
|
||||
expect(result.eventData.eventName).toBe("workflow_dispatch");
|
||||
expect(result.eventData.isPR).toBe(false);
|
||||
expect(result.eventData.baseBranch).toBe("main");
|
||||
// triggerUsername is not extracted for workflow_dispatch events
|
||||
expect(result.triggerUsername).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("schedule event", () => {
|
||||
beforeEach(() => {
|
||||
process.env = {
|
||||
...BASE_ENV,
|
||||
BASE_BRANCH: "main",
|
||||
};
|
||||
});
|
||||
|
||||
test("should parse schedule event correctly", () => {
|
||||
const mockScheduleContext = createMockContext({
|
||||
eventName: "schedule",
|
||||
payload: {
|
||||
schedule: "0 0 * * *",
|
||||
repository: {
|
||||
name: "test-repo",
|
||||
owner: {
|
||||
login: "test-owner",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = prepareContext(mockScheduleContext, "", "main", undefined);
|
||||
|
||||
expect(result.repository).toBe("test-owner/test-repo");
|
||||
expect(result.eventData.eventName).toBe("schedule");
|
||||
expect(result.eventData.isPR).toBe(false);
|
||||
expect(result.eventData.baseBranch).toBe("main");
|
||||
// triggerUsername is not extracted for schedule events
|
||||
expect(result.triggerUsername).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("issue_comment event", () => {
|
||||
describe("on issue", () => {
|
||||
beforeEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user