Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 78 additions & 47 deletions actions/setup/js/handle_noop_message.test.cjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
// @ts-check

import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";

// Mock load_agent_output at the module level
vi.mock("./load_agent_output.cjs", () => ({
loadAgentOutput: vi.fn(),
}));
import fs from "fs";
import path from "path";
import os from "os";

describe("handle_noop_message", () => {
let mockCore;
let mockGithub;
let mockContext;
let originalEnv;
let mockLoadAgentOutput;
let tempDir;

beforeEach(async () => {
// Save original environment
originalEnv = { ...process.env };

// Get the mocked loadAgentOutput
const loadModule = await import("./load_agent_output.cjs");
mockLoadAgentOutput = loadModule.loadAgentOutput;
// Create temp directory for test files
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "handle-noop-test-"));

// Mock core
mockCore = {
Expand Down Expand Up @@ -59,6 +56,12 @@ describe("handle_noop_message", () => {
afterEach(() => {
// Restore environment
process.env = originalEnv;

// Clean up temp directory
if (tempDir && fs.existsSync(tempDir)) {
fs.rmSync(tempDir, { recursive: true, force: true });
}

vi.clearAllMocks();
});

Expand Down Expand Up @@ -94,14 +97,18 @@ describe("handle_noop_message", () => {
process.env.GH_AW_NOOP_MESSAGE = "Some message";
process.env.GH_AW_AGENT_CONCLUSION = "success";

// Mock loadAgentOutput to return noop + other outputs
mockLoadAgentOutput.mockReturnValue({
success: true,
items: [
{ type: "noop", message: "No action needed" },
{ type: "create_issue", title: "Some issue" },
],
});
// Create agent output file with noop + other outputs
const outputFile = path.join(tempDir, "agent_output.json");
fs.writeFileSync(
outputFile,
JSON.stringify({
items: [
{ type: "noop", message: "No action needed" },
{ type: "create_issue", title: "Some issue" },
],
})
);
process.env.GH_AW_AGENT_OUTPUT = outputFile;
Comment on lines +100 to +111
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same agent-output fixture setup (compute outputFile path, write JSON, set GH_AW_AGENT_OUTPUT) is duplicated across many test cases in this file. Consider extracting a small helper (e.g., writeAgentOutput(items) returning the file path and setting the env var) to reduce repetition and make future test additions less error-prone.

Copilot uses AI. Check for mistakes.

const { main } = await import("./handle_noop_message.cjs?t=" + Date.now());
await main();
Expand All @@ -116,11 +123,15 @@ describe("handle_noop_message", () => {
process.env.GH_AW_NOOP_MESSAGE = "No updates needed";
process.env.GH_AW_AGENT_CONCLUSION = "success";

// Mock loadAgentOutput to return only noop outputs
mockLoadAgentOutput.mockReturnValue({
success: true,
items: [{ type: "noop", message: "No updates needed" }],
});
// Create agent output file with only noop outputs
const outputFile = path.join(tempDir, "agent_output.json");
fs.writeFileSync(
outputFile,
JSON.stringify({
items: [{ type: "noop", message: "No updates needed" }],
})
);
process.env.GH_AW_AGENT_OUTPUT = outputFile;

// Mock search to return no results
mockGithub.rest.search.issuesAndPullRequests.mockResolvedValue({
Expand Down Expand Up @@ -176,11 +187,15 @@ describe("handle_noop_message", () => {
process.env.GH_AW_NOOP_MESSAGE = "Everything is up to date";
process.env.GH_AW_AGENT_CONCLUSION = "success";

// Mock loadAgentOutput to return only noop outputs
mockLoadAgentOutput.mockReturnValue({
success: true,
items: [{ type: "noop", message: "Everything is up to date" }],
});
// Create agent output file with only noop outputs
const outputFile = path.join(tempDir, "agent_output.json");
fs.writeFileSync(
outputFile,
JSON.stringify({
items: [{ type: "noop", message: "Everything is up to date" }],
})
);
process.env.GH_AW_AGENT_OUTPUT = outputFile;

// Mock search to return existing issue
mockGithub.rest.search.issuesAndPullRequests.mockResolvedValue({
Expand Down Expand Up @@ -223,11 +238,15 @@ describe("handle_noop_message", () => {
process.env.GH_AW_NOOP_MESSAGE = "No action required";
process.env.GH_AW_AGENT_CONCLUSION = "success";

// Mock loadAgentOutput to return only noop outputs
mockLoadAgentOutput.mockReturnValue({
success: true,
items: [{ type: "noop", message: "No action required" }],
});
// Create agent output file with only noop outputs
const outputFile = path.join(tempDir, "agent_output.json");
fs.writeFileSync(
outputFile,
JSON.stringify({
items: [{ type: "noop", message: "No action required" }],
})
);
process.env.GH_AW_AGENT_OUTPUT = outputFile;

// Mock existing issue
mockGithub.rest.search.issuesAndPullRequests.mockResolvedValue({
Expand All @@ -253,11 +272,15 @@ describe("handle_noop_message", () => {
process.env.GH_AW_NOOP_MESSAGE = "All checks passed";
process.env.GH_AW_AGENT_CONCLUSION = "success";

// Mock loadAgentOutput to return only noop outputs
mockLoadAgentOutput.mockReturnValue({
success: true,
items: [{ type: "noop", message: "All checks passed" }],
});
// Create agent output file with only noop outputs
const outputFile = path.join(tempDir, "agent_output.json");
fs.writeFileSync(
outputFile,
JSON.stringify({
items: [{ type: "noop", message: "All checks passed" }],
})
);
process.env.GH_AW_AGENT_OUTPUT = outputFile;

// Mock no existing issue
mockGithub.rest.search.issuesAndPullRequests.mockResolvedValue({
Expand All @@ -280,11 +303,15 @@ describe("handle_noop_message", () => {
process.env.GH_AW_NOOP_MESSAGE = "Done";
process.env.GH_AW_AGENT_CONCLUSION = "success";

// Mock loadAgentOutput to return only noop outputs
mockLoadAgentOutput.mockReturnValue({
success: true,
items: [{ type: "noop", message: "Done" }],
});
// Create agent output file with only noop outputs
const outputFile = path.join(tempDir, "agent_output.json");
fs.writeFileSync(
outputFile,
JSON.stringify({
items: [{ type: "noop", message: "Done" }],
})
);
process.env.GH_AW_AGENT_OUTPUT = outputFile;

mockGithub.rest.search.issuesAndPullRequests.mockResolvedValue({
data: { total_count: 1, items: [{ number: 1, node_id: "ID", html_url: "url" }] },
Expand All @@ -305,11 +332,15 @@ describe("handle_noop_message", () => {
process.env.GH_AW_NOOP_MESSAGE = "Clean";
process.env.GH_AW_AGENT_CONCLUSION = "success";

// Mock loadAgentOutput to return only noop outputs
mockLoadAgentOutput.mockReturnValue({
success: true,
items: [{ type: "noop", message: "Clean" }],
});
// Create agent output file with only noop outputs
const outputFile = path.join(tempDir, "agent_output.json");
fs.writeFileSync(
outputFile,
JSON.stringify({
items: [{ type: "noop", message: "Clean" }],
})
);
process.env.GH_AW_AGENT_OUTPUT = outputFile;

mockGithub.rest.search.issuesAndPullRequests.mockResolvedValue({
data: { total_count: 1, items: [{ number: 1, node_id: "ID", html_url: "url" }] },
Expand Down
Loading