mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
Split ParsedGitHubContext into entity-specific and automation contexts: - ParsedGitHubContext: For entity events (issues/PRs) with required entityNumber and isPR - AutomationContext: For workflow_dispatch/schedule events without entity fields - GitHubContext: Union type for all contexts This eliminates ~20 null checks throughout the codebase and provides better type safety. Entity-specific code paths are now guaranteed to have the required fields. Co-Authored-By: Claude <noreply@anthropic.com>
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { describe, test, expect, beforeEach } from "bun:test";
|
|
import { agentMode } from "../../src/modes/agent";
|
|
import type { GitHubContext } from "../../src/github/context";
|
|
import { createMockContext, createMockAutomationContext } from "../mockContext";
|
|
|
|
describe("Agent Mode", () => {
|
|
let mockContext: GitHubContext;
|
|
|
|
beforeEach(() => {
|
|
mockContext = createMockAutomationContext({
|
|
eventName: "workflow_dispatch",
|
|
});
|
|
});
|
|
|
|
test("agent mode has correct properties", () => {
|
|
expect(agentMode.name).toBe("agent");
|
|
expect(agentMode.description).toBe(
|
|
"Automation mode for workflow_dispatch and schedule events",
|
|
);
|
|
expect(agentMode.shouldCreateTrackingComment()).toBe(false);
|
|
expect(agentMode.getAllowedTools()).toEqual([]);
|
|
expect(agentMode.getDisallowedTools()).toEqual([]);
|
|
});
|
|
|
|
test("prepareContext returns minimal data", () => {
|
|
const context = agentMode.prepareContext(mockContext);
|
|
|
|
expect(context.mode).toBe("agent");
|
|
expect(context.githubContext).toBe(mockContext);
|
|
// Agent mode doesn't use comment tracking or branch management
|
|
expect(Object.keys(context)).toEqual(["mode", "githubContext"]);
|
|
});
|
|
|
|
test("agent mode only triggers for workflow_dispatch and schedule events", () => {
|
|
// Should trigger for automation events
|
|
const workflowDispatchContext = createMockAutomationContext({
|
|
eventName: "workflow_dispatch",
|
|
});
|
|
expect(agentMode.shouldTrigger(workflowDispatchContext)).toBe(true);
|
|
|
|
const scheduleContext = createMockAutomationContext({
|
|
eventName: "schedule",
|
|
});
|
|
expect(agentMode.shouldTrigger(scheduleContext)).toBe(true);
|
|
|
|
// Should NOT trigger for entity events
|
|
const entityEvents = [
|
|
"issue_comment",
|
|
"pull_request",
|
|
"pull_request_review",
|
|
"issues",
|
|
] as const;
|
|
|
|
entityEvents.forEach((eventName) => {
|
|
const context = createMockContext({ eventName });
|
|
expect(agentMode.shouldTrigger(context)).toBe(false);
|
|
});
|
|
});
|
|
});
|