Skip to content

Commit a1dfb00

Browse files
committed
chore: format code with prettier
Apply code formatting changes to test files: - Fix formatting in test-gh-stdin.mjs - Fix formatting in test-stdin-content.mjs - Remove unused imports in shellExecute.test.ts
1 parent 549f0c7 commit a1dfb00

File tree

3 files changed

+49
-44
lines changed

3 files changed

+49
-44
lines changed

packages/agent/src/tools/shell/shellExecute.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, expect, it, vi } from 'vitest';
22

3-
import type { ToolContext } from '../../core/types';
43
import { shellExecuteTool } from './shellExecute';
54

65
// Skip testing for now
@@ -12,23 +11,6 @@ describe.skip('shellExecuteTool', () => {
1211
warn: vi.fn(),
1312
info: vi.fn(),
1413
};
15-
16-
// Create a mock ToolContext with all required properties
17-
const mockToolContext: ToolContext = {
18-
logger: mockLogger as any,
19-
workingDirectory: '/test',
20-
headless: false,
21-
userSession: false,
22-
pageFilter: 'none',
23-
tokenTracker: { trackTokens: vi.fn() } as any,
24-
githubMode: false,
25-
provider: 'anthropic',
26-
maxTokens: 4000,
27-
temperature: 0,
28-
agentTracker: { registerAgent: vi.fn() } as any,
29-
shellTracker: { registerShell: vi.fn(), processStates: new Map() } as any,
30-
browserTracker: { registerSession: vi.fn() } as any,
31-
};
3214

3315
it('should execute a shell command', async () => {
3416
// This is a dummy test that will be skipped

packages/cli/test-gh-stdin.mjs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,28 @@ This content includes special characters like:
3636
console.log('=== Testing GitHub CLI with stdinContent ===');
3737

3838
// Helper function to wait for all tests to complete
39-
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
39+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
4040

4141
// Helper function to execute a command with encoded content
42-
const execWithEncodedContent = async (command, content, isWindows = process.platform === 'win32') => {
42+
const execWithEncodedContent = async (
43+
command,
44+
content,
45+
isWindows = process.platform === 'win32',
46+
) => {
4347
return new Promise((resolve, reject) => {
4448
const encodedContent = Buffer.from(content).toString('base64');
4549
let cmd;
46-
50+
4751
if (isWindows) {
4852
// Windows approach using PowerShell
4953
cmd = `powershell -Command "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${encodedContent}')) | ${command}"`;
5054
} else {
5155
// POSIX approach (Linux/macOS)
5256
cmd = `echo "${encodedContent}" | base64 -d | ${command}`;
5357
}
54-
58+
5559
console.log(`Executing command: ${cmd}`);
56-
60+
5761
exec(cmd, (error, stdout, stderr) => {
5862
if (error) {
5963
reject(error);
@@ -69,14 +73,22 @@ console.log('\n=== Testing with temporary file approach ===');
6973
const tempFile = path.join(os.tmpdir(), `test-gh-content-${Date.now()}.md`);
7074
fs.writeFileSync(tempFile, issueContent);
7175
console.log(`Created temporary file: ${tempFile}`);
72-
console.log(`Command would be: gh issue create --title "Test Issue" --body-file "${tempFile}"`);
73-
console.log('(Not executing actual GitHub command to avoid creating real issues)');
76+
console.log(
77+
`Command would be: gh issue create --title "Test Issue" --body-file "${tempFile}"`,
78+
);
79+
console.log(
80+
'(Not executing actual GitHub command to avoid creating real issues)',
81+
);
7482

7583
// Test with stdinContent approach (new method)
7684
console.log('\n=== Testing with stdinContent approach ===');
77-
console.log('Command would be: gh issue create --title "Test Issue" --body-stdin');
85+
console.log(
86+
'Command would be: gh issue create --title "Test Issue" --body-stdin',
87+
);
7888
console.log('With stdinContent parameter containing the issue content');
79-
console.log('(Not executing actual GitHub command to avoid creating real issues)');
89+
console.log(
90+
'(Not executing actual GitHub command to avoid creating real issues)',
91+
);
8092

8193
// Simulate the execution with a simple echo command
8294
console.log('\n=== Simulating execution with echo command ===');
@@ -96,5 +108,9 @@ fs.unlinkSync(tempFile);
96108
console.log('Temporary file removed');
97109

98110
console.log('\n=== Test completed ===');
99-
console.log('The stdinContent approach successfully preserves all formatting and special characters');
100-
console.log('This can be used with GitHub CLI commands that accept stdin input (--body-stdin flag)');
111+
console.log(
112+
'The stdinContent approach successfully preserves all formatting and special characters',
113+
);
114+
console.log(
115+
'This can be used with GitHub CLI commands that accept stdin input (--body-stdin flag)',
116+
);

packages/cli/test-stdin-content.mjs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,39 @@ const testStrings = [
99
'Simple string',
1010
'String with spaces',
1111
'String with "double quotes"',
12-
'String with \'single quotes\'',
12+
"String with 'single quotes'",
1313
'String with $variable',
1414
'String with `backticks`',
1515
'String with newline\ncharacter',
1616
'String with & and | operators',
1717
'String with > redirect',
1818
'String with * wildcard',
19-
'Complex string with "quotes", \'single\', $var, `backticks`, \n, and special chars &|><*'
19+
'Complex string with "quotes", \'single\', $var, `backticks`, \n, and special chars &|><*',
2020
];
2121

2222
console.log('=== Testing stdinContent approaches ===');
2323

2424
// Helper function to wait for all tests to complete
25-
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
25+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2626

2727
// Helper function to execute a command with encoded content
28-
const execWithEncodedContent = async (command, content, isWindows = process.platform === 'win32') => {
28+
const execWithEncodedContent = async (
29+
command,
30+
content,
31+
isWindows = process.platform === 'win32',
32+
) => {
2933
return new Promise((resolve, reject) => {
3034
const encodedContent = Buffer.from(content).toString('base64');
3135
let cmd;
32-
36+
3337
if (isWindows) {
3438
// Windows approach using PowerShell
3539
cmd = `powershell -Command "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${encodedContent}')) | ${command}"`;
3640
} else {
3741
// POSIX approach (Linux/macOS)
3842
cmd = `echo "${encodedContent}" | base64 -d | ${command}`;
3943
}
40-
44+
4145
exec(cmd, (error, stdout, stderr) => {
4246
if (error) {
4347
reject(error);
@@ -52,7 +56,7 @@ const execWithEncodedContent = async (command, content, isWindows = process.plat
5256
console.log('\n=== Testing Base64 encoding approach ===');
5357
for (const str of testStrings) {
5458
console.log(`\nOriginal: "${str}"`);
55-
59+
5660
try {
5761
// Test the encoded content approach
5862
const { stdout } = await execWithEncodedContent('cat', str);
@@ -61,7 +65,7 @@ for (const str of testStrings) {
6165
} catch (error) {
6266
console.error(`Error: ${error.message}`);
6367
}
64-
68+
6569
// Add a small delay to ensure orderly output
6670
await wait(100);
6771
}
@@ -70,30 +74,33 @@ for (const str of testStrings) {
7074
console.log('\n=== Comparing with temporary file approach ===');
7175
for (const str of testStrings) {
7276
console.log(`\nOriginal: "${str}"`);
73-
77+
7478
// Create a temporary file with the content
7579
const tempFile = path.join(os.tmpdir(), `test-content-${Date.now()}.txt`);
7680
fs.writeFileSync(tempFile, str);
77-
81+
7882
// Execute command using the temporary file
7983
exec(`cat "${tempFile}"`, async (error, stdout, stderr) => {
8084
console.log(`Output (temp file): "${stdout.trim()}"`);
8185
console.log(`Success (temp file): ${stdout.trim() === str}`);
82-
86+
8387
try {
8488
// Test the encoded content approach
85-
const { stdout: encodedStdout } = await execWithEncodedContent('cat', str);
89+
const { stdout: encodedStdout } = await execWithEncodedContent(
90+
'cat',
91+
str,
92+
);
8693
console.log(`Output (encoded): "${encodedStdout.trim()}"`);
8794
console.log(`Success (encoded): ${encodedStdout.trim() === str}`);
8895
console.log(`Match: ${stdout.trim() === encodedStdout.trim()}`);
8996
} catch (error) {
9097
console.error(`Error: ${error.message}`);
9198
}
92-
99+
93100
// Clean up the temporary file
94101
fs.unlinkSync(tempFile);
95102
});
96-
103+
97104
// Add a small delay to ensure orderly output
98105
await wait(300);
99-
}
106+
}

0 commit comments

Comments
 (0)