TypeScript
fix(server): terminal labels keep the whole name of a command with spaces (#23140)
MarcoDotIO207faa28c645
diff --git a/apps/server/src/terminal/Manager.test.ts b/apps/server/src/terminal/Manager.test.tsindex 8e1a2d2f7ec..2b08e4f51e5 100644--- a/apps/server/src/terminal/Manager.test.ts+++ b/apps/server/src/terminal/Manager.test.ts@@ -765,6 +765,30 @@ it.layer(}),);+ it.effect("labels a running command by its whole process name, spaces included", () =>+ Effect.gen(function* () {+ const { manager } = yield* createManager(5, {+ subprocessPollIntervalMs: 1_000,+ processKillGraceMs: 0,+ processTable: Effect.succeed([+ { pid: 9000, ppid: 1, name: "zsh" },+ { pid: 200, ppid: 9000, name: "Google Chrome" },+ ]),+ }).pipe(Effect.provide(layerWithHostPlatform("darwin")));+ const label = yield* Deferred.make<string>();+ const unsubscribe = yield* manager.subscribe((event) =>+ event.type === "activity"+ ? Deferred.succeed(label, event.label).pipe(Effect.asVoid)+ : Effect.void,+ );+ yield* Effect.addFinalizer(() => Effect.sync(unsubscribe));+ yield* manager.open(openInput());+ yield* TestClock.adjust("1 second");++ expect(yield* Deferred.await(label)).toBe("Google Chrome");+ }).pipe(Effect.provide(TestClock.layer())),+ );+// Answers process-table queries after `queryDuration`, honoring the caller's// timeout the way ProcessRunner's `timedOutResult` mode does.const slowProcessTable = (diff --git a/apps/server/src/terminal/Manager.ts b/apps/server/src/terminal/Manager.tsindex 9d3942c6cb6..c881dbd7b19 100644--- a/apps/server/src/terminal/Manager.ts+++ b/apps/server/src/terminal/Manager.ts@@ -365,10 +365,9 @@ function normalizeChildCommandName(raw: string, platform: NodeJS.Platform): stri) {trimmed = trimmed.slice(1, -1).trim();}- const firstToken = (trimmed.split(/\s+/)[0] ?? trimmed).trim();- if (firstToken.length === 0) return null;+ // Process names and macOS `comm` paths can contain spaces ("Google Chrome").const separators = platform === "win32" ? /[\\/]/ : /\//;- const base = firstToken.split(separators).at(-1) ?? firstToken;+ const base = (trimmed.split(separators).at(-1) ?? trimmed).trim();const withoutExe =platform === "win32" && base.toLowerCase().endsWith(".exe") ? base.slice(0, -4) : base;return withoutExe.length > 0 ? withoutExe : null;