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:
claude[bot]
2025-06-04 01:03:26 +00:00
committed by GitHub
parent e0dcb85d34
commit 1d100f7832
5 changed files with 133 additions and 22 deletions

View File

@@ -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");
});
});
});