From cf04b0e3bf83b84d11790945153c5bba3c5a099e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 20 Jan 2026 10:45:59 +0000 Subject: [PATCH] fix: align gateway presence + config defaults tests (#1208) (thanks @24601) --- src/cli/devices-cli.ts | 2 +- src/config/config.identity-defaults.test.ts | 7 +++++-- src/gateway/server.auth.test.ts | 2 +- src/gateway/server/ws-connection/message-handler.ts | 2 +- src/infra/device-pairing.ts | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cli/devices-cli.ts b/src/cli/devices-cli.ts index e7290fe47..d30f2967d 100644 --- a/src/cli/devices-cli.ts +++ b/src/cli/devices-cli.ts @@ -2,7 +2,7 @@ import type { Command } from "commander"; import { callGateway } from "../gateway/call.js"; import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../utils/message-channel.js"; -import { defaultRuntime } from "./runtime.js"; +import { defaultRuntime } from "../runtime.js"; import { withProgress } from "./progress.js"; type DevicesRpcOpts = { diff --git a/src/config/config.identity-defaults.test.ts b/src/config/config.identity-defaults.test.ts index 2792ca229..829264a29 100644 --- a/src/config/config.identity-defaults.test.ts +++ b/src/config/config.identity-defaults.test.ts @@ -1,6 +1,7 @@ import fs from "node:fs/promises"; import path from "node:path"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { DEFAULT_AGENT_MAX_CONCURRENT, DEFAULT_SUBAGENT_MAX_CONCURRENT } from "./agent-limits.js"; import { withTempHome } from "./test-helpers.js"; describe("config identity defaults", () => { @@ -284,7 +285,7 @@ describe("config identity defaults", () => { }); }); - it("does not synthesize agent/session when absent", async () => { + it("does not synthesize agent list/session when absent", async () => { await withTempHome(async (home) => { const configDir = path.join(home, ".clawdbot"); await fs.mkdir(configDir, { recursive: true }); @@ -306,7 +307,9 @@ describe("config identity defaults", () => { expect(cfg.messages?.responsePrefix).toBeUndefined(); expect(cfg.messages?.groupChat?.mentionPatterns).toBeUndefined(); - expect(cfg.agents).toBeUndefined(); + expect(cfg.agents?.list).toBeUndefined(); + expect(cfg.agents?.defaults?.maxConcurrent).toBe(DEFAULT_AGENT_MAX_CONCURRENT); + expect(cfg.agents?.defaults?.subagents?.maxConcurrent).toBe(DEFAULT_SUBAGENT_MAX_CONCURRENT); expect(cfg.session).toBeUndefined(); }); }); diff --git a/src/gateway/server.auth.test.ts b/src/gateway/server.auth.test.ts index 3092a88e3..f48043240 100644 --- a/src/gateway/server.auth.test.ts +++ b/src/gateway/server.auth.test.ts @@ -73,7 +73,7 @@ describe("gateway server auth/connect", () => { }); test("rejects invalid token", async () => { - const { server, ws, port, prevToken } = await startServerWithClient("secret"); + const { server, ws, prevToken } = await startServerWithClient("secret"); const res = await connectReq(ws, { token: "wrong" }); expect(res.ok).toBe(false); expect(res.error?.message ?? "").toContain("unauthorized"); diff --git a/src/gateway/server/ws-connection/message-handler.ts b/src/gateway/server/ws-connection/message-handler.ts index 485577bb3..975e344ce 100644 --- a/src/gateway/server/ws-connection/message-handler.ts +++ b/src/gateway/server/ws-connection/message-handler.ts @@ -551,7 +551,7 @@ export function attachGatewayWsMessageHandler(params: { deviceFamily: connectParams.client.deviceFamily, modelIdentifier: connectParams.client.modelIdentifier, mode: connectParams.client.mode, - instanceId: instanceId ?? connectParams.device?.id, + instanceId: connectParams.device?.id ?? instanceId, reason: "connect", }); incrementPresenceVersion(); diff --git a/src/infra/device-pairing.ts b/src/infra/device-pairing.ts index c5594df34..9f161fea1 100644 --- a/src/infra/device-pairing.ts +++ b/src/infra/device-pairing.ts @@ -399,7 +399,8 @@ export async function verifyDeviceToken(params: { return { ok: false, reason: "scope-mismatch" }; } entry.lastUsedAtMs = Date.now(); - device.tokens = { ...(device.tokens ?? {}), [role]: entry }; + device.tokens ??= {}; + device.tokens[role] = entry; state.pairedByDeviceId[device.deviceId] = device; await persistState(state, params.baseDir); return { ok: true };