Skip to content

Commit 7cbab59

Browse files
fix(test): make GET /api/sessions/:id/files error-path test deterministic (#241)
Race condition fix surfaced by the post-merge CI on dc8a4a5: macOS arm64 Node 24 lost the race between fs.rmSync and the PTY exit callback, so the session was removed from the Map before the GET landed and we got 404 instead of the 500 the route returns when readdirSync fails. Switching from rm to rename keeps the inode alive (PTY happy) while still making the path-based readdir fail. 1199/1199 tests still pass locally. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent dc8a4a5 commit 7cbab59

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

test/server/routes.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4216,11 +4216,13 @@ describe('Routes', () => {
42164216
after(async () => {
42174217
inst?.shutdown();
42184218
await safeCleanup(path.join(process.cwd(), '.termbeam-test-files-err'));
4219+
await safeCleanup(path.join(process.cwd(), '.termbeam-test-files-err-moved'));
42194220
});
42204221

42214222
it('should return 500 when session cwd no longer exists', async () => {
42224223
inst = await startServer({ password: null });
42234224
const tmpDir = path.join(process.cwd(), '.termbeam-test-files-err');
4225+
const movedDir = path.join(process.cwd(), '.termbeam-test-files-err-moved');
42244226
fs.mkdirSync(tmpDir, { recursive: true });
42254227

42264228
const body = JSON.stringify({ name: 'files-err', cwd: tmpDir });
@@ -4239,7 +4241,13 @@ describe('Routes', () => {
42394241
);
42404242
const sessionId = JSON.parse(createRes.data).id;
42414243

4242-
fs.rmSync(tmpDir, { recursive: true, force: true });
4244+
// Rename (don't rm) so the PTY's cwd inode stays alive — otherwise on
4245+
// fast macOS arm64 the shell exits before the GET arrives, removing the
4246+
// session and yielding a 404 instead of the 500 we want to assert.
4247+
try {
4248+
fs.rmSync(movedDir, { recursive: true, force: true });
4249+
} catch {}
4250+
fs.renameSync(tmpDir, movedDir);
42434251

42444252
const res = await httpRequest({
42454253
hostname: '127.0.0.1',

0 commit comments

Comments
 (0)