mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
fix: improve workflow status detection in comment updates
- Changed CLAUDE_SUCCESS check from !== "false" to === "true" for more explicit handling - This ensures undefined or empty values are treated as failures - Moved status check before output file parsing to ensure consistent behavior - Added comprehensive tests for various workflow status scenarios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -156,7 +156,14 @@ async function run() {
|
||||
actionFailed = true;
|
||||
errorDetails = prepareError;
|
||||
} else {
|
||||
// Check for existence of output file and parse it if available
|
||||
// Check if the Claude action failed
|
||||
// CLAUDE_SUCCESS is set to the result of: steps.claude-code.outputs.conclusion == 'success'
|
||||
// If the step didn't run or didn't set outputs.conclusion, CLAUDE_SUCCESS will be "false"
|
||||
// If the step succeeded, CLAUDE_SUCCESS will be "true"
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS === "true";
|
||||
actionFailed = !claudeSuccess;
|
||||
|
||||
// Try to read execution details from output file
|
||||
try {
|
||||
const outputFile = process.env.OUTPUT_FILE;
|
||||
if (outputFile) {
|
||||
@@ -179,14 +186,10 @@ async function run() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the Claude action failed
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS !== "false";
|
||||
actionFailed = !claudeSuccess;
|
||||
} catch (error) {
|
||||
console.error("Error reading output file:", error);
|
||||
// If we can't read the file, check for any failure markers
|
||||
actionFailed = process.env.CLAUDE_SUCCESS === "false";
|
||||
// Error reading output file doesn't change the action status
|
||||
// We already determined actionFailed based on CLAUDE_SUCCESS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
110
test/update-comment-link-logic.test.ts
Normal file
110
test/update-comment-link-logic.test.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
|
||||
|
||||
describe("update-comment-link workflow status detection", () => {
|
||||
let originalEnv: NodeJS.ProcessEnv;
|
||||
|
||||
beforeEach(() => {
|
||||
originalEnv = { ...process.env };
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
});
|
||||
|
||||
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");
|
||||
});
|
||||
|
||||
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 {
|
||||
// When CLAUDE_SUCCESS is undefined, it's not === "true", so claudeSuccess = false
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS === "true";
|
||||
actionFailed = !claudeSuccess;
|
||||
}
|
||||
|
||||
expect(actionFailed).toBe(true);
|
||||
});
|
||||
|
||||
test("should handle undefined PREPARE_SUCCESS as success", () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user