|
2 | 2 | * @vitest-environment node |
3 | 3 | */ |
4 | 4 | import { execFile } from 'node:child_process' |
5 | | -import { mkdir, mkdtemp, rm, symlink, writeFile as writeLocalFile } from 'node:fs/promises' |
| 5 | +import { mkdir, mkdtemp, rm, writeFile as writeLocalFile } from 'node:fs/promises' |
6 | 6 | import { tmpdir } from 'node:os' |
7 | 7 | import { join } from 'node:path' |
8 | 8 | import { promisify } from 'node:util' |
@@ -61,70 +61,6 @@ describe('cloud review tools', () => { |
61 | 61 | expect(source).not.toContain('--unified=20') |
62 | 62 | }) |
63 | 63 |
|
64 | | - it('enforces read-size and canonical path bounds in the actual helper', async () => { |
65 | | - await installCloudReviewTools(runner) |
66 | | - const source = writeFile.mock.calls[0][1] as string |
67 | | - const testDir = await mkdtemp(join(tmpdir(), 'sim-review-tools-')) |
68 | | - const repoDir = join(testDir, 'repo') |
69 | | - const scriptPath = join(testDir, 'review-tools.py') |
70 | | - const outsidePath = join(testDir, 'outside.txt') |
71 | | - |
72 | | - try { |
73 | | - await mkdir(repoDir) |
74 | | - await writeLocalFile( |
75 | | - scriptPath, |
76 | | - source.replace( |
77 | | - "pathlib.Path('/workspace/repo')", |
78 | | - `pathlib.Path(${JSON.stringify(repoDir)})` |
79 | | - ) |
80 | | - ) |
81 | | - await writeLocalFile(join(repoDir, 'safe.txt'), 'one\ntwo\n') |
82 | | - await writeLocalFile(outsidePath, 'secret') |
83 | | - await symlink(outsidePath, join(repoDir, 'escape.txt')) |
84 | | - await mkdir(join(repoDir, '.git')) |
85 | | - await writeLocalFile(join(repoDir, '.git', 'secret.txt'), 'DO_NOT_EXPOSE') |
86 | | - |
87 | | - const execute = (operation: string, args: Record<string, unknown>) => |
88 | | - execFileAsync('python3', [scriptPath], { |
89 | | - env: { |
90 | | - ...process.env, |
91 | | - REVIEW_TOOL_OPERATION: operation, |
92 | | - REVIEW_TOOL_ARGS: JSON.stringify(args), |
93 | | - }, |
94 | | - }) |
95 | | - |
96 | | - await expect( |
97 | | - execute('read', { path: 'safe.txt', offset: 1, limit: 2 }) |
98 | | - ).resolves.toMatchObject({ |
99 | | - stdout: '1: one\n2: two', |
100 | | - }) |
101 | | - await expect(execute('read', { path: '../outside.txt' })).rejects.toMatchObject({ |
102 | | - stderr: expect.stringContaining('path must stay within the repository'), |
103 | | - }) |
104 | | - await expect(execute('read', { path: 'escape.txt' })).rejects.toMatchObject({ |
105 | | - stderr: expect.stringContaining('path resolves outside the repository'), |
106 | | - }) |
107 | | - |
108 | | - const found = await execute('find', { path: '.', pattern: '**/*', limit: 20 }) |
109 | | - expect(found.stdout).toContain('safe.txt') |
110 | | - expect(found.stdout).not.toContain('.git') |
111 | | - const searched = await execute('search', { |
112 | | - path: '.', |
113 | | - pattern: 'DO_NOT_EXPOSE', |
114 | | - glob: '**/*', |
115 | | - literal: true, |
116 | | - }) |
117 | | - expect(searched.stdout).toBe('No matches found') |
118 | | - |
119 | | - await writeLocalFile(join(repoDir, 'large.bin'), Buffer.alloc(5_000_001)) |
120 | | - await expect(execute('read', { path: 'large.bin' })).rejects.toMatchObject({ |
121 | | - stderr: expect.stringContaining('exceeds the 5 MB read limit'), |
122 | | - }) |
123 | | - } finally { |
124 | | - await rm(testDir, { recursive: true, force: true }) |
125 | | - } |
126 | | - }) |
127 | | - |
128 | 64 | it('validates inline coordinates against an exact local diff', async () => { |
129 | 65 | await installCloudReviewTools(runner) |
130 | 66 | const source = writeFile.mock.calls[0][1] as string |
|
0 commit comments