Skip to content

Commit 8d546c0

Browse files
Copilotpelikhan
andauthored
[WIP] Fix issues in JavaScript tests (#8955)
* Initial plan * Fix check_command_position tests to use GH_AW_COMMANDS array format Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * Apply Prettier formatting to test files Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 24c6eab commit 8d546c0

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

actions/setup/js/check_command_position.test.cjs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,79 +34,79 @@ const mockCore = {
3434
describe("check_command_position.cjs", () => {
3535
let checkCommandPositionScript, originalEnv;
3636
(beforeEach(() => {
37-
(vi.clearAllMocks(), (originalEnv = { GH_AW_COMMAND: process.env.GH_AW_COMMAND }));
37+
(vi.clearAllMocks(), (originalEnv = { GH_AW_COMMANDS: process.env.GH_AW_COMMANDS }));
3838
const scriptPath = path.join(__dirname, "check_command_position.cjs");
3939
((checkCommandPositionScript = fs.readFileSync(scriptPath, "utf8")), (mockContext.eventName = "issues"), (mockContext.payload = {}));
4040
}),
4141
afterEach(() => {
42-
void 0 !== originalEnv.GH_AW_COMMAND ? (process.env.GH_AW_COMMAND = originalEnv.GH_AW_COMMAND) : delete process.env.GH_AW_COMMAND;
42+
void 0 !== originalEnv.GH_AW_COMMANDS ? (process.env.GH_AW_COMMANDS = originalEnv.GH_AW_COMMANDS) : delete process.env.GH_AW_COMMANDS;
4343
}),
44-
it("should fail when GH_AW_COMMAND is not set", async () => {
45-
(delete process.env.GH_AW_COMMAND, await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`), expect(mockCore.setFailed).toHaveBeenCalledWith("Configuration error: GH_AW_COMMAND not specified."));
44+
it("should fail when GH_AW_COMMANDS is not set", async () => {
45+
(delete process.env.GH_AW_COMMANDS, await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`), expect(mockCore.setFailed).toHaveBeenCalledWith("Configuration error: GH_AW_COMMANDS not specified."));
4646
}),
4747
it("should pass when command is the first word in issue body", async () => {
48-
((process.env.GH_AW_COMMAND = "test-bot"),
48+
((process.env.GH_AW_COMMANDS = JSON.stringify(["test-bot"])),
4949
(mockContext.eventName = "issues"),
5050
(mockContext.payload = { issue: { body: "/test-bot please help with this issue" } }),
5151
await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`),
5252
expect(mockCore.setOutput).toHaveBeenCalledWith("command_position_ok", "true"),
53-
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("Command '/test-bot' is at the start")));
53+
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("matched at the start")));
5454
}),
5555
it("should fail when command is not the first word in issue body", async () => {
56-
((process.env.GH_AW_COMMAND = "test-bot"),
56+
((process.env.GH_AW_COMMANDS = JSON.stringify(["test-bot"])),
5757
(mockContext.eventName = "issues"),
5858
(mockContext.payload = { issue: { body: "Please help with /test-bot this issue" } }),
5959
await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`),
6060
expect(mockCore.setOutput).toHaveBeenCalledWith("command_position_ok", "false"),
61-
expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("Command '/test-bot' is not the first word")));
61+
expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("None of the commands")));
6262
}),
6363
it("should pass when command is first word after whitespace", async () => {
64-
((process.env.GH_AW_COMMAND = "helper"),
64+
((process.env.GH_AW_COMMANDS = JSON.stringify(["helper"])),
6565
(mockContext.eventName = "issue_comment"),
6666
(mockContext.payload = { comment: { body: " \n /helper analyze this code" } }),
6767
await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`),
6868
expect(mockCore.setOutput).toHaveBeenCalledWith("command_position_ok", "true"));
6969
}),
7070
it("should pass for non-comment events", async () => {
71-
((process.env.GH_AW_COMMAND = "test-bot"),
71+
((process.env.GH_AW_COMMANDS = JSON.stringify(["test-bot"])),
7272
(mockContext.eventName = "workflow_dispatch"),
7373
(mockContext.payload = {}),
7474
await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`),
7575
expect(mockCore.setOutput).toHaveBeenCalledWith("command_position_ok", "true"),
7676
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("does not require command position check")));
7777
}),
7878
it("should handle pull_request event with command at start", async () => {
79-
((process.env.GH_AW_COMMAND = "review-bot"),
79+
((process.env.GH_AW_COMMANDS = JSON.stringify(["review-bot"])),
8080
(mockContext.eventName = "pull_request"),
8181
(mockContext.payload = { pull_request: { body: "/review-bot please review my changes" } }),
8282
await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`),
8383
expect(mockCore.setOutput).toHaveBeenCalledWith("command_position_ok", "true"));
8484
}),
8585
it("should pass when text is empty", async () => {
86-
((process.env.GH_AW_COMMAND = "test-bot"),
86+
((process.env.GH_AW_COMMANDS = JSON.stringify(["test-bot"])),
8787
(mockContext.eventName = "issues"),
8888
(mockContext.payload = { issue: { body: "" } }),
8989
await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`),
90-
expect(mockCore.setOutput).toHaveBeenCalledWith("command_position_ok", "true"),
91-
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("No command")));
90+
expect(mockCore.setOutput).toHaveBeenCalledWith("command_position_ok", "false"),
91+
expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("None of the commands")));
9292
}),
9393
it("should pass when text does not contain the command", async () => {
94-
((process.env.GH_AW_COMMAND = "test-bot"),
94+
((process.env.GH_AW_COMMANDS = JSON.stringify(["test-bot"])),
9595
(mockContext.eventName = "issues"),
9696
(mockContext.payload = { issue: { body: "This is a regular issue without any command" } }),
9797
await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`),
98-
expect(mockCore.setOutput).toHaveBeenCalledWith("command_position_ok", "true"),
99-
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("No command")));
98+
expect(mockCore.setOutput).toHaveBeenCalledWith("command_position_ok", "false"),
99+
expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("None of the commands")));
100100
}),
101101
it("should handle discussion events", async () => {
102-
((process.env.GH_AW_COMMAND = "discuss-bot"),
102+
((process.env.GH_AW_COMMANDS = JSON.stringify(["discuss-bot"])),
103103
(mockContext.eventName = "discussion"),
104104
(mockContext.payload = { discussion: { body: "/discuss-bot help needed here" } }),
105105
await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`),
106106
expect(mockCore.setOutput).toHaveBeenCalledWith("command_position_ok", "true"));
107107
}),
108108
it("should handle discussion_comment events", async () => {
109-
((process.env.GH_AW_COMMAND = "discuss-bot"),
109+
((process.env.GH_AW_COMMANDS = JSON.stringify(["discuss-bot"])),
110110
(mockContext.eventName = "discussion_comment"),
111111
(mockContext.payload = { comment: { body: "/discuss-bot analyze this" } }),
112112
await eval(`(async () => { ${checkCommandPositionScript}; await main(); })()`),

actions/setup/js/mcp_server_core.test.cjs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,7 @@ process.stdin.on('end', () => {
580580

581581
// Create a handler that exits with error code (separate process)
582582
const handlerPath = path.join(tempDir, "error_handler.cjs");
583-
fs.writeFileSync(
584-
handlerPath,
585-
`process.exit(1);`
586-
);
583+
fs.writeFileSync(handlerPath, `process.exit(1);`);
587584

588585
const tools = [
589586
{
@@ -695,10 +692,7 @@ process.stdin.on('end', () => {
695692

696693
// Create a handler - in separate process, we just output string directly
697694
const handlerPath = path.join(tempDir, "circular_handler.cjs");
698-
fs.writeFileSync(
699-
handlerPath,
700-
`console.log("[object Object]");`
701-
);
695+
fs.writeFileSync(handlerPath, `console.log("[object Object]");`);
702696

703697
const tools = [
704698
{

actions/setup/js/safe_inputs_mcp_server_http.test.cjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ describe("safe_inputs_mcp_server_http.cjs integration", () => {
3030
(req.on("error", reject), req.write(data), req.end());
3131
});
3232
}
33-
(fs.writeFileSync(handlerPath, 'let input = "";\nprocess.stdin.on("data", chunk => { input += chunk; });\nprocess.stdin.on("end", () => {\n const args = JSON.parse(input);\n const result = { echo: args.message || "empty", timestamp: Date.now() };\n console.log(JSON.stringify(result));\n});'),
33+
(fs.writeFileSync(
34+
handlerPath,
35+
'let input = "";\nprocess.stdin.on("data", chunk => { input += chunk; });\nprocess.stdin.on("end", () => {\n const args = JSON.parse(input);\n const result = { echo: args.message || "empty", timestamp: Date.now() };\n console.log(JSON.stringify(result));\n});'
36+
),
3437
fs.writeFileSync(
3538
configPath,
3639
JSON.stringify({

0 commit comments

Comments
 (0)