Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(console): a dev Console's managed stack follows its data directory (#891)

Louis Amaudruze76c2e33104b
diff --git a/console/apps/switch-console-desktop/src/main/app/configure-app-identity.ts b/console/apps/switch-console-desktop/src/main/app/configure-app-identity.ts
index cc0b54a42..9802ec72d 100644
--- a/console/apps/switch-console-desktop/src/main/app/configure-app-identity.ts
+++ b/console/apps/switch-console-desktop/src/main/app/configure-app-identity.ts
@@ -1,12 +1,7 @@
import { join } from 'node:path';
import { app } from 'electron';
-import { OS_APP_NAME, USER_DATA_DIR_NAME } from '@shared/app-identity';
+import { OS_APP_NAME } from '@shared/app-identity';
+import { userDataDirName } from './user-data-dir';
app.setName(OS_APP_NAME);
-
-// Several dev builds can run side by side on one machine (one per worktree)
-// when each keeps its own userData: the server list, sessions and the local
-// database live there. Dev-only, so a packaged app never reads it.
-const userDataDirName =
- (import.meta.env.DEV && process.env.SWITCH_CONSOLE_USER_DATA_DIR) || USER_DATA_DIR_NAME;
-app.setPath('userData', join(app.getPath('appData'), userDataDirName));
+app.setPath('userData', join(app.getPath('appData'), userDataDirName()));
diff --git a/console/apps/switch-console-desktop/src/main/app/user-data-dir.ts b/console/apps/switch-console-desktop/src/main/app/user-data-dir.ts
new file mode 100644
index 000000000..a23d584f4
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/main/app/user-data-dir.ts
@@ -0,0 +1,13 @@
+import { USER_DATA_DIR_NAME } from '@shared/app-identity';
+
+/**
+ * The folder under the system's app-data directory this run keeps its data in.
+ *
+ * Several dev builds can run side by side on one machine (one per worktree)
+ * when each keeps its own: the server list, sessions, the local database and
+ * the managed local server's files live there. Dev-only, so a packaged app
+ * never reads it.
+ */
+export function userDataDirName(): string {
+ return (import.meta.env.DEV && process.env.SWITCH_CONSOLE_USER_DATA_DIR) || USER_DATA_DIR_NAME;
+}
diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/constants.test.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/constants.test.ts
new file mode 100644
index 000000000..9605381a4
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/constants.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, it } from 'vitest';
+import { stackProjectName } from './constants';
+
+describe('stackProjectName', () => {
+ it('keeps the names existing installs are attached to', () => {
+ expect(stackProjectName('switchdash', 'local')).toBe('switchdash-local');
+ expect(stackProjectName('switchdash', 'remote')).toBe('switchdash-remote');
+ expect(stackProjectName('switchdash-dev', 'local')).toBe('switchdash-dev-local');
+ });
+
+ it('gives each data directory a stack of its own', () => {
+ expect(stackProjectName('switchdash-fresh-20261016-144027', 'local')).toBe(
+ 'switchdash-fresh-20261016-144027-local'
+ );
+ expect(stackProjectName('switchdash-local-cloud', 'local')).not.toBe(
+ stackProjectName('switchdash-dev', 'local')
+ );
+ });
+
+ it('only uses what compose accepts in a project name', () => {
+ expect(stackProjectName('My Data.Dir', 'local')).toBe('my-data-dir-local');
+ expect(stackProjectName('.hidden', 'remote')).toBe('hidden-remote');
+ expect(stackProjectName('...', 'local')).toBe('switchdash-local');
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/constants.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/constants.ts
index dd082ba78..1096390af 100644
--- a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/constants.ts
+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/constants.ts
@@ -1,4 +1,4 @@
-import { USER_DATA_DIR_NAME } from '@shared/app-identity';
+import { userDataDirName } from '../../app/user-data-dir';
/**
* Fixed coordinates for the managed local stack. These mirror the ports and
@@ -7,27 +7,41 @@ import { USER_DATA_DIR_NAME } from '@shared/app-identity';
* Switch Console addresses the resulting server.
*/
+/**
+ * The `docker compose --project-name` of a managed stack kept by the Console
+ * whose data lives in `dataDirName`, made of what compose accepts in a project
+ * name: lowercase letters, digits, `-` and `_`, starting with a letter or digit.
+ */
+export function stackProjectName(dataDirName: string, kind: 'local' | 'remote'): string {
+ const safe = dataDirName
+ .toLowerCase()
+ .replace(/[^a-z0-9_-]+/g, '-')
+ .replace(/^[^a-z0-9]+/, '');
+ return `${safe || 'switchdash'}-${kind}`;
+}
+
/**
* `docker compose --project-name` for the managed stack on this machine, so its
* containers and volumes are isolated and discoverable across app restarts.
*
- * Scoped per build. Each build keeps its generated stack secrets in its own
- * userData dir (see USER_DATA_DIR_NAME), but Postgres only honours
- * POSTGRES_PASSWORD when it initialises a fresh volume — so builds sharing one
- * project name share `pgdata` and every build except the one that created it
+ * One per data directory. Each Console keeps its generated stack secrets and
+ * its chosen ports in its own data directory, but Postgres only honours
+ * POSTGRES_PASSWORD when it initialises a fresh volume — so Consoles sharing one
+ * project name share `pgdata` and every one except the one that created it
* fails authentication. They also fight over the containers themselves,
- * recreating each other's stack on start. Stable keeps the original name so
+ * recreating each other's stack on start with their own ports. That covers
+ * dev builds started side by side with SWITCH_CONSOLE_USER_DATA_DIR, not only
+ * different builds. Stable keeps the original name, `switchdash-local`, so
* existing installs stay attached to the stack they already have.
*/
-export const LOCAL_SERVER_PROJECT_NAME =
- USER_DATA_DIR_NAME === 'switchdash' ? 'switchdash-local' : `${USER_DATA_DIR_NAME}-local`;
+export const LOCAL_SERVER_PROJECT_NAME = stackProjectName(userDataDirName(), 'local');
/** `docker compose --project-name` for a managed stack on a remote host. Each
- * remote host runs its own Docker daemon, so one name per build is enough to
- * isolate + rediscover the stack there — per build for the same reason as
- * {@link LOCAL_SERVER_PROJECT_NAME}, since two builds can target one host. */
-export const REMOTE_SERVER_PROJECT_NAME =
- USER_DATA_DIR_NAME === 'switchdash' ? 'switchdash-remote' : `${USER_DATA_DIR_NAME}-remote`;
+ * remote host runs its own Docker daemon, so one name per data directory is
+ * enough to isolate + rediscover the stack there — per data directory for the
+ * same reason as {@link LOCAL_SERVER_PROJECT_NAME}, since two Consoles can
+ * target one host. */
+export const REMOTE_SERVER_PROJECT_NAME = stackProjectName(userDataDirName(), 'remote');
/**
* The volume holding what every Console sharing a remote stack must agree on: