Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
test(console): mock the admin rename in pipeline suites and cover it
raullopez-sandboxba0b189a2eeb
diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/os-user-name.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/os-user-name.tsnew file mode 100644index 000000000..81e540a1d--- /dev/null+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/os-user-name.ts@@ -0,0 +1,19 @@+import { userInfo } from 'node:os';+import { execCommand } from '@main/core/app/utils';++/** The OS account's full name (`id -F` on macOS), else its username; null when neither is readable. */+export async function osUserFullName(): Promise<string | null> {+ if (process.platform === 'darwin') {+ try {+ const fullName = (await execCommand('id -F', { timeout: 5_000 })).trim();+ if (fullName) return fullName;+ } catch {+ // Fall through to the username.+ }+ }+ try {+ return userInfo().username;+ } catch {+ return null;+ }+}diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline-matrix-migration.test.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline-matrix-migration.test.tsindex 8d90868aa..b5c89a297 100644--- a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline-matrix-migration.test.ts+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline-matrix-migration.test.ts@@ -72,8 +72,12 @@ vi.mock('@main/core/workspaces/reconcile-workspaces', () => ({reconcileServerWorkspaces: () => Promise.resolve(),}));vi.mock('@main/core/switch-servers/auth', () => ({- passwordLogin: () => Promise.resolve({ success: true }),+ passwordLogin: () =>+ Promise.resolve({ success: true, data: { id: 'u-1', name: 'Ada Lovelace', email: '[email protected]', role: 'admin' } }),}));+// Reaches the reachability store, and through it the database client.+vi.mock('@main/core/switch-servers/gateway-client', () => ({ updateMyName: vi.fn() }));+vi.mock('./os-user-name', () => ({ osUserFullName: () => Promise.resolve('Ada Lovelace') }));vi.mock('./managed-upgrade', () => ({prepareUpgrade: prepareUpgradeMock,finishUpgrade: finishUpgradeMock,diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline-shared-host.test.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline-shared-host.test.tsindex 373d986f1..391f92a21 100644--- a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline-shared-host.test.ts+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline-shared-host.test.ts@@ -40,7 +40,15 @@ const resolvePortsMock = vi.hoisted(() => vi.fn());const readPersistedPortsMock = vi.hoisted(() => vi.fn());const rememberPortsMock = vi.hoisted(() => vi.fn(() => Promise.resolve()));const ensureManagedServerMock = vi.hoisted(() => vi.fn(() => Promise.resolve({ id: 'srv-1' })));-const passwordLoginMock = vi.hoisted(() => vi.fn(() => Promise.resolve({ success: true })));+const passwordLoginMock = vi.hoisted(() =>+ vi.fn(() =>+ Promise.resolve({+ success: true,+ data: { id: 'u-1', name: 'Ada Lovelace', email: '[email protected]', role: 'admin' },+ })+ )+);+const updateMyNameMock = vi.hoisted(() => vi.fn(() => Promise.resolve()));const logError = vi.hoisted(() => vi.fn());const logWarn = vi.hoisted(() => vi.fn());@@ -99,6 +107,9 @@ vi.mock('@main/core/switch-servers/servers-store', () => ({setActiveServerId: vi.fn(() => Promise.resolve()),}));vi.mock('@main/core/switch-servers/auth', () => ({ passwordLogin: passwordLoginMock }));+// Reaches the reachability store, and through it the database client.+vi.mock('@main/core/switch-servers/gateway-client', () => ({ updateMyName: updateMyNameMock }));+vi.mock('./os-user-name', () => ({ osUserFullName: () => Promise.resolve('Ada Lovelace') }));vi.mock('@main/core/workspaces/reconcile-workspaces', () => ({reconcileServerWorkspaces: vi.fn(async () => {}),}));@@ -940,6 +951,39 @@ describe('the paths a shared start or join refuses or degrades on', () => {);});+ it('renames the seeded Admin user to the OS account name after sign-in', async () => {+ inspectStackMock.mockResolvedValue(present());+ passwordLoginMock.mockResolvedValueOnce({+ success: true,+ data: { id: 'u-1', name: 'Admin', email: '[email protected]', role: 'admin' },+ });++ expect(await startStack(startOptions(sharedHost().host))).toMatchObject({ kind: 'started' });+ expect(updateMyNameMock).toHaveBeenCalledWith(expect.anything(), 'Ada Lovelace');+ });++ it('keeps a name the user already chose', async () => {+ inspectStackMock.mockResolvedValue(present());++ expect(await startStack(startOptions(sharedHost().host))).toMatchObject({ kind: 'started' });+ expect(updateMyNameMock).not.toHaveBeenCalled();+ });++ it('warns and carries on when renaming the Admin user fails', async () => {+ inspectStackMock.mockResolvedValue(present());+ passwordLoginMock.mockResolvedValueOnce({+ success: true,+ data: { id: 'u-1', name: 'Admin', email: '[email protected]', role: 'admin' },+ });+ updateMyNameMock.mockRejectedValueOnce(new Error('gateway down'));++ expect(await startStack(startOptions(sharedHost().host))).toMatchObject({ kind: 'started' });+ expect(logWarn).toHaveBeenCalledWith(+ expect.stringMatching(/could not rename default admin user/),+ expect.objectContaining({ error: 'Error: gateway down' })+ );+ });+it('has nothing to adopt on a host whose stack nobody shares', async () => {const { host } = sharedHost();const local = { ...host, sharedState: null } as unknown as ServerHost;diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline.test.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline.test.tsindex 9adb2861c..e02925184 100644--- a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline.test.ts+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline.test.ts@@ -81,8 +81,12 @@ vi.mock('@main/core/workspaces/reconcile-workspaces', () => ({reconcileServerWorkspaces: () => Promise.resolve(),}));vi.mock('@main/core/switch-servers/auth', () => ({- passwordLogin: () => Promise.resolve({ success: true }),+ passwordLogin: () =>+ Promise.resolve({ success: true, data: { id: 'u-1', name: 'Ada Lovelace', email: '[email protected]', role: 'admin' } }),}));+// Reaches the reachability store, and through it the database client.+vi.mock('@main/core/switch-servers/gateway-client', () => ({ updateMyName: vi.fn() }));+vi.mock('./os-user-name', () => ({ osUserFullName: () => Promise.resolve('Ada Lovelace') }));vi.mock('./managed-upgrade', () => ({prepareUpgrade: prepareUpgradeMock,finishUpgrade: finishUpgradeMock,diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline.tsindex d22cd6f85..3259c1b6f 100644--- a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline.ts+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/pipeline.ts@@ -1,4 +1,3 @@-import { userInfo } from 'node:os';import { passwordLogin } from '@main/core/switch-servers/auth';import {assertManagedServerUrlFree,@@ -7,7 +6,6 @@ import {} from '@main/core/switch-servers/servers-store';import { updateMyName } from '@main/core/switch-servers/gateway-client';import { reconcileServerWorkspaces } from '@main/core/workspaces/reconcile-workspaces';-import { execCommand } from '@main/core/app/utils';import { log } from '@main/lib/logger';import { RELEASE_REPO_OWNER } from '@shared/app-identity';import {@@ -38,6 +36,7 @@ import { waitForHealth } from './health';import type { ServerHost } from './host/types';import { finishUpgrade, type OwedUpgrade, prepareUpgrade } from './managed-upgrade';import { crossesMatrixBoundary, runBackfill } from './matrix-migration';+import { osUserFullName } from './os-user-name';import { clearPorts, readPersistedPorts, rememberPorts, resolvePorts } from './ports';import { type LocalServerSecrets, withNewerSecrets } from './secret-values';import { clearSecrets, loadOrCreateSecrets, readSecrets, storeSecrets } from './secrets';@@ -469,23 +468,6 @@ async function registerAndSignIn();}-async function getOsUserFullName(): Promise<string | null> {- if (process.platform === 'darwin') {- try {- const fullName = await execCommand('id -F', { timeout: 5_000 });- const trimmed = fullName.trim();- if (trimmed) return trimmed;- } catch {- // Fall through to username fallback- }- }- try {- return userInfo().username;- } catch {- return null;- }-}-/** {@link registerAndSignIn} with the server's addresses given explicitly, for* a server that is not a compose stack (a native local server runs no* dashboard of its own, so it has no separate dashboard address). */@@ -508,7 +490,7 @@ export async function registerManagedServer(});} else {if (login.data.name === 'Admin') {- const osUserName = await getOsUserFullName();+ const osUserName = await osUserFullName();if (osUserName) {try {await updateMyName(server, osUserName);