mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
feat: add workflow cancellation detection and update comment
When a workflow is cancelled, the comment now shows "Claude's task was cancelled" instead of the generic "Claude encountered an error" message. This provides clearer feedback to users about why the workflow stopped. Changes: - Add CLAUDE_CANCELLED environment variable using cancelled() function in action.yml - Implement cancellation detection logic in update-comment-link.ts - Update comment-logic.ts to show specific cancellation message - Add comprehensive tests for cancellation handling Fixes #123 Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
This commit is contained in:
@@ -418,4 +418,48 @@ describe("updateCommentBody", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("cancellation handling", () => {
|
||||
it("shows cancellation message when actionCancelled is true", () => {
|
||||
const input = {
|
||||
...baseInput,
|
||||
currentBody: "Claude Code is working…",
|
||||
actionCancelled: true,
|
||||
executionDetails: { duration_ms: 30000 }, // 30s
|
||||
triggerUsername: "test-user",
|
||||
};
|
||||
|
||||
const result = updateCommentBody(input);
|
||||
expect(result).toContain("**Claude's task was cancelled after 30s**");
|
||||
expect(result).not.toContain("Claude encountered an error");
|
||||
expect(result).not.toContain("Claude finished");
|
||||
});
|
||||
|
||||
it("shows cancellation message without duration when duration is missing", () => {
|
||||
const input = {
|
||||
...baseInput,
|
||||
currentBody: "Claude Code is working…",
|
||||
actionCancelled: true,
|
||||
triggerUsername: "test-user",
|
||||
};
|
||||
|
||||
const result = updateCommentBody(input);
|
||||
expect(result).toContain("**Claude's task was cancelled**");
|
||||
expect(result).not.toContain("after");
|
||||
});
|
||||
|
||||
it("prioritizes cancellation over failure", () => {
|
||||
const input = {
|
||||
...baseInput,
|
||||
currentBody: "Claude Code is working…",
|
||||
actionCancelled: true,
|
||||
actionFailed: true, // Both are true, cancellation should take precedence
|
||||
executionDetails: { duration_ms: 45000 },
|
||||
};
|
||||
|
||||
const result = updateCommentBody(input);
|
||||
expect(result).toContain("**Claude's task was cancelled after 45s**");
|
||||
expect(result).not.toContain("Claude encountered an error");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user