Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions actions/setup/js/mcp_handler_go.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function createGoHandler(server, toolName, scriptPath, timeoutSeconds = 60) {
["run", scriptPath],
{
env: process.env,
cwd: process.env.GITHUB_WORKSPACE || process.cwd(),
timeout: timeoutSeconds * 1000, // Convert to milliseconds
maxBuffer: 10 * 1024 * 1024, // 10MB buffer
},
Expand Down
39 changes: 39 additions & 0 deletions actions/setup/js/mcp_handler_go.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,43 @@ func main() {
const output = JSON.parse(result.content[0].text);
expect(output).toEqual(complexInput);
}, 30000); // Increase timeout to allow for Go compilation

it("should execute script from GITHUB_WORKSPACE directory", async () => {
// Save original GITHUB_WORKSPACE
const originalWorkspace = process.env.GITHUB_WORKSPACE;

// Set GITHUB_WORKSPACE to tempDir
process.env.GITHUB_WORKSPACE = tempDir;

try {
// Create a Go script that outputs current working directory
testScriptPath = path.join(tempDir, "test-cwd.go");
const goCode = `package main

import (
"encoding/json"
"os"
)

func main() {
cwd, _ := os.Getwd()
result := map[string]interface{}{"cwd": cwd}
json.NewEncoder(os.Stdout).Encode(result)
}`;
fs.writeFileSync(testScriptPath, goCode);

const handler = createGoHandler(mockServer, "cwd-tool", testScriptPath);
const result = await handler({});

const output = JSON.parse(result.content[0].text);
expect(output.cwd).toBe(tempDir);
} finally {
// Restore original GITHUB_WORKSPACE
if (originalWorkspace === undefined) {
delete process.env.GITHUB_WORKSPACE;
} else {
process.env.GITHUB_WORKSPACE = originalWorkspace;
}
}
}, 30000); // Increase timeout to allow for Go compilation
});
1 change: 1 addition & 0 deletions actions/setup/js/mcp_handler_javascript.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function createJavaScriptHandler(server, toolName, scriptPath, timeoutSeconds =
[scriptPath],
{
env: process.env,
cwd: process.env.GITHUB_WORKSPACE || process.cwd(),
timeout: timeoutSeconds * 1000, // Convert to milliseconds
maxBuffer: 10 * 1024 * 1024, // 10MB buffer
},
Expand Down
84 changes: 58 additions & 26 deletions actions/setup/js/mcp_handler_javascript.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -149,34 +149,66 @@ process.stdin.on('end', () => {
expect(output).toEqual(complexInput);
});

it("should handle async operations", async () => {
testScriptPath = path.join(tempDir, "async.cjs");
const jsCode = `
let input = '';
process.stdin.on('data', chunk => {
input += chunk;
});

process.stdin.on('end', async () => {
const inputs = JSON.parse(input);

// Simulate async operation
await new Promise(resolve => setTimeout(resolve, 100));

const result = {
message: "Async completed",
input: inputs
};
console.log(JSON.stringify(result));
});
it("should execute script from GITHUB_WORKSPACE directory", async () => {
// Save original GITHUB_WORKSPACE
const originalWorkspace = process.env.GITHUB_WORKSPACE;

// Set GITHUB_WORKSPACE to tempDir
process.env.GITHUB_WORKSPACE = tempDir;

try {
// Create a JavaScript script that outputs current working directory
testScriptPath = path.join(tempDir, "test-cwd.cjs");
const jsCode = `
const result = { cwd: process.cwd() };
console.log(JSON.stringify(result));
`;
fs.writeFileSync(testScriptPath, jsCode);
fs.writeFileSync(testScriptPath, jsCode);

const handler = createJavaScriptHandler(mockServer, "cwd-tool", testScriptPath);
const result = await handler({});

const output = JSON.parse(result.content[0].text);
expect(output.cwd).toBe(tempDir);
} finally {
// Restore original GITHUB_WORKSPACE
if (originalWorkspace === undefined) {
delete process.env.GITHUB_WORKSPACE;
} else {
process.env.GITHUB_WORKSPACE = originalWorkspace;
}
}
});

const handler = createJavaScriptHandler(mockServer, "async-tool", testScriptPath);
const result = await handler({ test: "data" });
it("should use process.cwd() when GITHUB_WORKSPACE is not set", async () => {
// Save original GITHUB_WORKSPACE
const originalWorkspace = process.env.GITHUB_WORKSPACE;

const output = JSON.parse(result.content[0].text);
expect(output.message).toBe("Async completed");
expect(output.input).toEqual({ test: "data" });
// Unset GITHUB_WORKSPACE
delete process.env.GITHUB_WORKSPACE;

try {
// Create a JavaScript script that outputs current working directory
testScriptPath = path.join(tempDir, "test-default-cwd.cjs");
const jsCode = `
const result = { cwd: process.cwd() };
console.log(JSON.stringify(result));
`;
fs.writeFileSync(testScriptPath, jsCode);

const handler = createJavaScriptHandler(mockServer, "default-cwd-tool", testScriptPath);
const result = await handler({});

const output = JSON.parse(result.content[0].text);
// When GITHUB_WORKSPACE is not set, should use process.cwd()
expect(output.cwd).toBe(process.cwd());
} finally {
// Restore original GITHUB_WORKSPACE
if (originalWorkspace === undefined) {
delete process.env.GITHUB_WORKSPACE;
} else {
process.env.GITHUB_WORKSPACE = originalWorkspace;
}
}
});
});
1 change: 1 addition & 0 deletions actions/setup/js/mcp_handler_python.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function createPythonHandler(server, toolName, scriptPath, timeoutSeconds = 60)
[scriptPath],
{
env: process.env,
cwd: process.env.GITHUB_WORKSPACE || process.cwd(),
timeout: timeoutSeconds * 1000, // Convert to milliseconds
maxBuffer: 10 * 1024 * 1024, // 10MB buffer
},
Expand Down
1 change: 1 addition & 0 deletions actions/setup/js/mcp_handler_shell.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function createShellHandler(server, toolName, scriptPath, timeoutSeconds = 60) {
[],
{
env,
cwd: process.env.GITHUB_WORKSPACE || process.cwd(),
timeout: timeoutSeconds * 1000, // Convert to milliseconds
maxBuffer: 10 * 1024 * 1024, // 10MB buffer
},
Expand Down