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

推荐订阅源

Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
博客园_首页
T
Tailwind CSS Blog
美团技术团队
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
MongoDB | Blog
MongoDB | Blog
The Cloudflare Blog
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog

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
test: hoist gateway helper imports · openclaw/openclaw@a7...
shakkernerd · 2026-05-10 · via Recent Commits to openclaw:main

@@ -1,32 +1,28 @@

1-

import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

2-3-

const callGatewayMock = vi.fn();

4-

const configState = vi.hoisted(() => ({

5-

value: {} as Record<string, unknown>,

1+

import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";

2+

import { callGatewayTool, resolveGatewayOptions } from "./gateway.js";

3+4+

const mocks = vi.hoisted(() => ({

5+

callGateway: vi.fn(),

6+

configState: {

7+

value: {} as Record<string, unknown>,

8+

},

69

}));

710

vi.mock("../../config/config.js", () => ({

8-

getRuntimeConfig: () => configState.value,

11+

getRuntimeConfig: () => mocks.configState.value,

912

resolveGatewayPort: () => 18789,

1013

}));

1114

vi.mock("../../gateway/call.js", () => ({

12-

callGateway: (...args: unknown[]) => callGatewayMock(...args),

15+

callGateway: (...args: unknown[]) => mocks.callGateway(...args),

1316

}));

141715-

let callGatewayTool: typeof import("./gateway.js").callGatewayTool;

16-

let resolveGatewayOptions: typeof import("./gateway.js").resolveGatewayOptions;

17-1818

describe("gateway tool defaults", () => {

1919

const envSnapshot = {

2020

openclaw: process.env.OPENCLAW_GATEWAY_TOKEN,

2121

};

222223-

beforeAll(async () => {

24-

({ callGatewayTool, resolveGatewayOptions } = await import("./gateway.js"));

25-

});

26-2723

beforeEach(() => {

28-

callGatewayMock.mockClear();

29-

configState.value = {};

24+

mocks.callGateway.mockClear();

25+

mocks.configState.value = {};

3026

delete process.env.OPENCLAW_GATEWAY_TOKEN;

3127

});

3228

@@ -44,13 +40,13 @@ describe("gateway tool defaults", () => {

4440

});

45414642

it("accepts allowlisted gatewayUrl overrides (SSRF hardening)", async () => {

47-

callGatewayMock.mockResolvedValueOnce({ ok: true });

43+

mocks.callGateway.mockResolvedValueOnce({ ok: true });

4844

await callGatewayTool(

4945

"health",

5046

{ gatewayUrl: "ws://127.0.0.1:18789", gatewayToken: "t", timeoutMs: 5000 },

5147

{},

5248

);

53-

expect(callGatewayMock).toHaveBeenCalledWith(

49+

expect(mocks.callGateway).toHaveBeenCalledWith(

5450

expect.objectContaining({

5551

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

5652

token: "t",

@@ -68,7 +64,7 @@ describe("gateway tool defaults", () => {

6864

});

69657066

it("falls back to config gateway.auth.token when env is unset for local overrides", () => {

71-

configState.value = {

67+

mocks.configState.value = {

7268

gateway: {

7369

auth: { token: "config-token" },

7470

},

@@ -78,7 +74,7 @@ describe("gateway tool defaults", () => {

7874

});

79758076

it("uses gateway.remote.token for allowlisted remote overrides", () => {

81-

configState.value = {

77+

mocks.configState.value = {

8278

gateway: {

8379

remote: {

8480

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

@@ -93,7 +89,7 @@ describe("gateway tool defaults", () => {

93899490

it("does not leak local env/config tokens to remote overrides", () => {

9591

process.env.OPENCLAW_GATEWAY_TOKEN = "local-env-token";

96-

configState.value = {

92+

mocks.configState.value = {

9793

gateway: {

9894

auth: { token: "local-config-token" },

9995

remote: {

@@ -106,7 +102,7 @@ describe("gateway tool defaults", () => {

106102

});

107103108104

it("ignores unresolved local token SecretRef for strict remote overrides", () => {

109-

configState.value = {

105+

mocks.configState.value = {

110106

gateway: {

111107

auth: {

112108

mode: "token",

@@ -128,7 +124,7 @@ describe("gateway tool defaults", () => {

128124129125

it("explicit gatewayToken overrides fallback token resolution", () => {

130126

process.env.OPENCLAW_GATEWAY_TOKEN = "local-env-token";

131-

configState.value = {

127+

mocks.configState.value = {

132128

gateway: {

133129

remote: {

134130

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

@@ -144,9 +140,9 @@ describe("gateway tool defaults", () => {

144140

});

145141146142

it("uses least-privilege write scope for write methods", async () => {

147-

callGatewayMock.mockResolvedValueOnce({ ok: true });

143+

mocks.callGateway.mockResolvedValueOnce({ ok: true });

148144

await callGatewayTool("wake", {}, { mode: "now", text: "hi" });

149-

expect(callGatewayMock).toHaveBeenCalledWith(

145+

expect(mocks.callGateway).toHaveBeenCalledWith(

150146

expect.objectContaining({

151147

method: "wake",

152148

scopes: ["operator.write"],

@@ -155,9 +151,9 @@ describe("gateway tool defaults", () => {

155151

});

156152157153

it("uses admin scope only for admin methods", async () => {

158-

callGatewayMock.mockResolvedValueOnce({ ok: true });

154+

mocks.callGateway.mockResolvedValueOnce({ ok: true });

159155

await callGatewayTool("cron.add", {}, { id: "job-1" });

160-

expect(callGatewayMock).toHaveBeenCalledWith(

156+

expect(mocks.callGateway).toHaveBeenCalledWith(

161157

expect.objectContaining({

162158

method: "cron.add",

163159

scopes: ["operator.admin"],

@@ -166,14 +162,14 @@ describe("gateway tool defaults", () => {

166162

});

167163168164

it("allows explicit scope overrides for dynamic callers", async () => {

169-

callGatewayMock.mockResolvedValueOnce({ ok: true });

165+

mocks.callGateway.mockResolvedValueOnce({ ok: true });

170166

await callGatewayTool(

171167

"node.pair.approve",

172168

{},

173169

{ requestId: "req-1" },

174170

{ scopes: ["operator.admin"] },

175171

);

176-

expect(callGatewayMock).toHaveBeenCalledWith(

172+

expect(mocks.callGateway).toHaveBeenCalledWith(

177173

expect.objectContaining({

178174

method: "node.pair.approve",

179175

scopes: ["operator.admin"],

@@ -182,9 +178,9 @@ describe("gateway tool defaults", () => {

182178

});

183179184180

it("default-denies unknown methods by sending no scopes", async () => {

185-

callGatewayMock.mockResolvedValueOnce({ ok: true });

181+

mocks.callGateway.mockResolvedValueOnce({ ok: true });

186182

await callGatewayTool("nonexistent.method", {}, {});

187-

expect(callGatewayMock).toHaveBeenCalledWith(

183+

expect(mocks.callGateway).toHaveBeenCalledWith(

188184

expect.objectContaining({

189185

method: "nonexistent.method",

190186

scopes: [],