惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
月光博客
月光博客
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
Vercel News
Vercel News
量子位
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
腾讯CDC
有赞技术团队
有赞技术团队

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor: share operator approval client test setup · ope...
vincentkoc · 2026-06-02 · via Recent Commits to openclaw:main

@@ -68,6 +68,27 @@ vi.mock("./client.js", () => ({

68686969

const { withOperatorApprovalsGatewayClient } = await import("./operator-approvals-client.js");

707071+

const DEFAULT_APPROVAL_CLIENT_DISPLAY_NAME = "Matrix approval (@owner:example.org)";

72+73+

async function runOperatorApprovalsGatewayClient(

74+

params: { gatewayUrl?: string } = {},

75+

callback: Parameters<typeof withOperatorApprovalsGatewayClient>[1] = async () => undefined,

76+

) {

77+

await withOperatorApprovalsGatewayClient(

78+

{

79+

config: {} as never,

80+

clientDisplayName: DEFAULT_APPROVAL_CLIENT_DISPLAY_NAME,

81+

...params,

82+

},

83+

callback,

84+

);

85+

}

86+87+

function expectRuntimeTokenApprovalClient(): void {

88+

expect(typeof clientState.options?.approvalRuntimeToken).toBe("string");

89+

expect(clientState.options?.deviceIdentity).toBeNull();

90+

}

91+7192

describe("withOperatorApprovalsGatewayClient", () => {

7293

beforeEach(() => {

7394

clientState.options = null;

@@ -82,18 +103,12 @@ describe("withOperatorApprovalsGatewayClient", () => {

82103

});

8310484105

it("waits for hello before running the callback and stops cleanly", async () => {

85-

await withOperatorApprovalsGatewayClient(

86-

{

87-

config: {} as never,

88-

clientDisplayName: "Matrix approval (@owner:example.org)",

89-

},

90-

async (client) => {

91-

await client.request("exec.approval.resolve", {

92-

id: "req-123",

93-

decision: "allow-once",

94-

});

95-

},

96-

);

106+

await runOperatorApprovalsGatewayClient({}, async (client) => {

107+

await client.request("exec.approval.resolve", {

108+

id: "req-123",

109+

decision: "allow-once",

110+

});

111+

});

9711298113

expect(clientState.options?.scopes).toEqual(["operator.approvals"]);

99114

expect(typeof clientState.options?.approvalRuntimeToken).toBe("string");

@@ -109,134 +124,72 @@ describe("withOperatorApprovalsGatewayClient", () => {

109124

bootstrapState.url = "wss://gateway.example/ws";

110125

bootstrapState.urlSource = "config gateway.remote.url";

111126112-

await withOperatorApprovalsGatewayClient(

113-

{

114-

config: {} as never,

115-

clientDisplayName: "Matrix approval (@owner:example.org)",

116-

},

117-

async () => undefined,

118-

);

127+

await runOperatorApprovalsGatewayClient();

119128120129

expect(clientState.options).not.toHaveProperty("deviceIdentity", null);

121130

expect(clientState.options?.deviceIdentity).toBeUndefined();

122131

});

123132124-

it("omits approval runtime token for explicit loopback gateway URL overrides", async () => {

125-

bootstrapState.urlSource = "cli --url";

126-127-

await withOperatorApprovalsGatewayClient(

128-

{

129-

config: {} as never,

130-

gatewayUrl: "ws://127.0.0.1:18789",

131-

clientDisplayName: "Matrix approval (@owner:example.org)",

132-

},

133-

async () => undefined,

134-

);

135-136-

expect(clientState.options).not.toHaveProperty("approvalRuntimeToken");

137-

});

138-139-

it("omits approval runtime token for remote explicit gateway URL overrides", async () => {

140-

bootstrapState.url = "wss://gateway.example/ws";

141-

bootstrapState.urlSource = "cli --url";

142-143-

await withOperatorApprovalsGatewayClient(

144-

{

145-

config: {} as never,

146-

gatewayUrl: "wss://gateway.example/ws",

147-

clientDisplayName: "Matrix approval (@owner:example.org)",

148-

},

149-

async () => undefined,

150-

);

151-152-

expect(clientState.options).not.toHaveProperty("approvalRuntimeToken");

153-

});

154-155-

it("omits approval runtime token for configured remote loopback gateway URLs", async () => {

156-

bootstrapState.url = "ws://127.0.0.1:18789";

157-

bootstrapState.urlSource = "config gateway.remote.url";

158-159-

await withOperatorApprovalsGatewayClient(

160-

{

161-

config: {} as never,

162-

clientDisplayName: "Matrix approval (@owner:example.org)",

163-

},

164-

async () => undefined,

165-

);

166-167-

expect(clientState.options).not.toHaveProperty("approvalRuntimeToken");

168-

});

169-170-

it("omits approval runtime token for env loopback gateway URL overrides", async () => {

171-

bootstrapState.url = "ws://127.0.0.1:18789";

172-

bootstrapState.urlSource = "env OPENCLAW_GATEWAY_URL";

173-174-

await withOperatorApprovalsGatewayClient(

175-

{

176-

config: {} as never,

177-

clientDisplayName: "Matrix approval (@owner:example.org)",

178-

},

179-

async () => undefined,

180-

);

181-133+

it.each([

134+

{

135+

name: "explicit loopback gateway URL overrides",

136+

url: "ws://127.0.0.1:18789",

137+

urlSource: "cli --url",

138+

gatewayUrl: "ws://127.0.0.1:18789",

139+

},

140+

{

141+

name: "remote explicit gateway URL overrides",

142+

url: "wss://gateway.example/ws",

143+

urlSource: "cli --url",

144+

gatewayUrl: "wss://gateway.example/ws",

145+

},

146+

{

147+

name: "configured remote loopback gateway URLs",

148+

url: "ws://127.0.0.1:18789",

149+

urlSource: "config gateway.remote.url",

150+

},

151+

{

152+

name: "env loopback gateway URL overrides",

153+

url: "ws://127.0.0.1:18789",

154+

urlSource: "env OPENCLAW_GATEWAY_URL",

155+

},

156+

])("omits approval runtime token for $name", async ({ url, urlSource, gatewayUrl }) => {

157+

bootstrapState.url = url;

158+

bootstrapState.urlSource = urlSource;

159+160+

await runOperatorApprovalsGatewayClient(gatewayUrl ? { gatewayUrl } : {});

182161

expect(clientState.options).not.toHaveProperty("approvalRuntimeToken");

183162

});

184163185164

it("keeps approval runtime token for local fallback gateway URLs", async () => {

186165

bootstrapState.url = "ws://127.0.0.1:18789";

187166

bootstrapState.urlSource = "missing gateway.remote.url (fallback local)";

188167189-

await withOperatorApprovalsGatewayClient(

190-

{

191-

config: {} as never,

192-

clientDisplayName: "Matrix approval (@owner:example.org)",

193-

},

194-

async () => undefined,

195-

);

168+

await runOperatorApprovalsGatewayClient();

196169197-

expect(typeof clientState.options?.approvalRuntimeToken).toBe("string");

198-

expect(clientState.options?.deviceIdentity).toBeNull();

170+

expectRuntimeTokenApprovalClient();

199171

});

200172201173

it("omits stored device identity for local runtime-token approval clients without shared auth", async () => {

202174

bootstrapState.auth = { token: undefined, password: undefined };

203175204-

await withOperatorApprovalsGatewayClient(

205-

{

206-

config: {} as never,

207-

clientDisplayName: "Matrix approval (@owner:example.org)",

208-

},

209-

async () => undefined,

210-

);

176+

await runOperatorApprovalsGatewayClient();

211177212-

expect(typeof clientState.options?.approvalRuntimeToken).toBe("string");

213-

expect(clientState.options?.deviceIdentity).toBeNull();

178+

expectRuntimeTokenApprovalClient();

214179

});

215180216181

it("surfaces close failures before hello", async () => {

217182

clientState.startMode = "close";

218183219-

await expect(

220-

withOperatorApprovalsGatewayClient(

221-

{

222-

config: {} as never,

223-

clientDisplayName: "Matrix approval (@owner:example.org)",

224-

},

225-

async () => undefined,

226-

),

227-

).rejects.toThrow("gateway closed (1008): pairing required");

184+

await expect(runOperatorApprovalsGatewayClient()).rejects.toThrow(

185+

"gateway closed (1008): pairing required",

186+

);

228187

});

229188230189

it("falls back to stop when stopAndWait rejects", async () => {

231190

clientState.stopAndWaitSpy.mockRejectedValueOnce(new Error("close failed"));

232191233-

await withOperatorApprovalsGatewayClient(

234-

{

235-

config: {} as never,

236-

clientDisplayName: "Matrix approval (@owner:example.org)",

237-

},

238-

async () => undefined,

239-

);

192+

await runOperatorApprovalsGatewayClient();

240193241194

expect(clientState.stopAndWaitSpy).toHaveBeenCalledTimes(1);

242195

expect(clientState.stopSpy).toHaveBeenCalledTimes(1);