Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

test(platform): give fakePlatform a fresh mkdtemp userDataDir

Claude Codebe872ab0e9a2
diff --git a/src/core/platform-fake.ts b/src/core/platform-fake.ts
index 80b65612b..f9435c7db 100644
--- a/src/core/platform-fake.ts
+++ b/src/core/platform-fake.ts
@@ -1,3 +1,6 @@
+import { mkdtempSync } from 'fs'
+import os from 'os'
+import path from 'path'
import type { CorePlatform } from './platform'
export interface FakePlatform extends CorePlatform {
@@ -10,10 +13,20 @@ export interface FakePlatform extends CorePlatform {
clients: number[]
}
-/** In-memory CorePlatform for tests. Not a mock library — plain recording object. */
+/**
+ * In-memory CorePlatform for tests. Not a mock library — plain recording object.
+ *
+ * `userDataDir` defaults to a FRESH `mkdtemp` directory, never a fixed path. It used to be the
+ * literal `/tmp/nodeterm-test`, which was wrong twice over: two test files running in parallel
+ * shared one directory (so one could see or clobber the other's state), and every production
+ * write that resolves through `platform().userDataDir` — the scrollback store, the workspace
+ * store, context-link, the token files — statically reads as a write to a PREDICTABLE temp path,
+ * which is a real symlink-attack shape and which CodeQL flags as `js/insecure-temporary-file`.
+ * Tests that want their own directory still pass one in; this only fixes what they inherit.
+ */
export function fakePlatform(overrides: Partial<CorePlatform> = {}): FakePlatform {
const f: FakePlatform = {
- userDataDir: '/tmp/nodeterm-test',
+ userDataDir: mkdtempSync(path.join(os.tmpdir(), 'nodeterm-fake-')),
appVersion: '0.0.0-test',
isPackaged: false,
handlers: {},