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:
@@ -14,18 +14,18 @@ describe("update-comment-link workflow status detection", () => {
|
||||
test("should detect prepare step failure", () => {
|
||||
process.env.PREPARE_SUCCESS = "false";
|
||||
process.env.PREPARE_ERROR = "Failed to fetch issue data";
|
||||
|
||||
|
||||
const prepareSuccess = process.env.PREPARE_SUCCESS !== "false";
|
||||
const prepareError = process.env.PREPARE_ERROR;
|
||||
|
||||
|
||||
let actionFailed = false;
|
||||
let errorDetails: string | undefined;
|
||||
|
||||
|
||||
if (!prepareSuccess && prepareError) {
|
||||
actionFailed = true;
|
||||
errorDetails = prepareError;
|
||||
}
|
||||
|
||||
|
||||
expect(actionFailed).toBe(true);
|
||||
expect(errorDetails).toBe("Failed to fetch issue data");
|
||||
});
|
||||
@@ -33,50 +33,50 @@ describe("update-comment-link workflow status detection", () => {
|
||||
test("should detect claude-code step failure when prepare succeeds", () => {
|
||||
process.env.PREPARE_SUCCESS = "true";
|
||||
process.env.CLAUDE_SUCCESS = "false";
|
||||
|
||||
|
||||
const prepareSuccess = process.env.PREPARE_SUCCESS !== "false";
|
||||
const prepareError = process.env.PREPARE_ERROR;
|
||||
|
||||
|
||||
let actionFailed = false;
|
||||
|
||||
|
||||
if (!prepareSuccess && prepareError) {
|
||||
actionFailed = true;
|
||||
} else {
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS === "true";
|
||||
actionFailed = !claudeSuccess;
|
||||
}
|
||||
|
||||
|
||||
expect(actionFailed).toBe(true);
|
||||
});
|
||||
|
||||
test("should detect success when both steps succeed", () => {
|
||||
process.env.PREPARE_SUCCESS = "true";
|
||||
process.env.CLAUDE_SUCCESS = "true";
|
||||
|
||||
|
||||
const prepareSuccess = process.env.PREPARE_SUCCESS !== "false";
|
||||
const prepareError = process.env.PREPARE_ERROR;
|
||||
|
||||
|
||||
let actionFailed = false;
|
||||
|
||||
|
||||
if (!prepareSuccess && prepareError) {
|
||||
actionFailed = true;
|
||||
} else {
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS === "true";
|
||||
actionFailed = !claudeSuccess;
|
||||
}
|
||||
|
||||
|
||||
expect(actionFailed).toBe(false);
|
||||
});
|
||||
|
||||
test("should treat missing CLAUDE_SUCCESS env var as failure", () => {
|
||||
process.env.PREPARE_SUCCESS = "true";
|
||||
delete process.env.CLAUDE_SUCCESS;
|
||||
|
||||
|
||||
const prepareSuccess = process.env.PREPARE_SUCCESS !== "false";
|
||||
const prepareError = process.env.PREPARE_ERROR;
|
||||
|
||||
|
||||
let actionFailed = false;
|
||||
|
||||
|
||||
if (!prepareSuccess && prepareError) {
|
||||
actionFailed = true;
|
||||
} else {
|
||||
@@ -84,7 +84,7 @@ describe("update-comment-link workflow status detection", () => {
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS === "true";
|
||||
actionFailed = !claudeSuccess;
|
||||
}
|
||||
|
||||
|
||||
expect(actionFailed).toBe(true);
|
||||
});
|
||||
|
||||
@@ -92,19 +92,69 @@ describe("update-comment-link workflow status detection", () => {
|
||||
delete process.env.PREPARE_SUCCESS;
|
||||
delete process.env.PREPARE_ERROR;
|
||||
process.env.CLAUDE_SUCCESS = "true";
|
||||
|
||||
|
||||
const prepareSuccess = process.env.PREPARE_SUCCESS !== "false";
|
||||
const prepareError = process.env.PREPARE_ERROR;
|
||||
|
||||
|
||||
let actionFailed = false;
|
||||
|
||||
|
||||
if (!prepareSuccess && prepareError) {
|
||||
actionFailed = true;
|
||||
} else {
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS === "true";
|
||||
actionFailed = !claudeSuccess;
|
||||
}
|
||||
|
||||
|
||||
expect(actionFailed).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
test("should detect cancellation when CLAUDE_CANCELLED is true", () => {
|
||||
process.env.PREPARE_SUCCESS = "true";
|
||||
process.env.CLAUDE_SUCCESS = "false";
|
||||
process.env.CLAUDE_CANCELLED = "true";
|
||||
|
||||
const prepareSuccess = process.env.PREPARE_SUCCESS !== "false";
|
||||
const prepareError = process.env.PREPARE_ERROR;
|
||||
const isCancelled = process.env.CLAUDE_CANCELLED === "true";
|
||||
|
||||
let actionFailed = false;
|
||||
let actionCancelled = false;
|
||||
|
||||
if (!prepareSuccess && prepareError) {
|
||||
actionFailed = true;
|
||||
} else if (isCancelled) {
|
||||
actionCancelled = true;
|
||||
} else {
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS === "true";
|
||||
actionFailed = !claudeSuccess;
|
||||
}
|
||||
|
||||
expect(actionFailed).toBe(false);
|
||||
expect(actionCancelled).toBe(true);
|
||||
});
|
||||
|
||||
test("should not detect cancellation when CLAUDE_CANCELLED is false", () => {
|
||||
process.env.PREPARE_SUCCESS = "true";
|
||||
process.env.CLAUDE_SUCCESS = "false";
|
||||
process.env.CLAUDE_CANCELLED = "false";
|
||||
|
||||
const prepareSuccess = process.env.PREPARE_SUCCESS !== "false";
|
||||
const prepareError = process.env.PREPARE_ERROR;
|
||||
const isCancelled = process.env.CLAUDE_CANCELLED === "true";
|
||||
|
||||
let actionFailed = false;
|
||||
let actionCancelled = false;
|
||||
|
||||
if (!prepareSuccess && prepareError) {
|
||||
actionFailed = true;
|
||||
} else if (isCancelled) {
|
||||
actionCancelled = true;
|
||||
} else {
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS === "true";
|
||||
actionFailed = !claudeSuccess;
|
||||
}
|
||||
|
||||
expect(actionFailed).toBe(true);
|
||||
expect(actionCancelled).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user