Skip to content

Commit ea3a4de

Browse files
authored
Merge branch 'main' into jesse/fix-stale-approval-modal
2 parents 5a848d4 + acbb06e commit ea3a4de

11 files changed

Lines changed: 377 additions & 41 deletions

‎extensions/discord/src/voice/manager.e2e.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,11 @@ describe("DiscordVoiceManager", () => {
21152115

21162116
await manager.join({ guildId: "g1", channelId: "1001" });
21172117

2118-
expect(entersStateMock).toHaveBeenCalledWith(connection, "ready", 45_000);
2118+
const readyCall = entersStateMock.mock.calls[0];
2119+
expect(readyCall?.[0]).toBe(connection);
2120+
expect(readyCall?.[1]).toBe("ready");
2121+
expect(readyCall?.[2]).toBeGreaterThanOrEqual(44_900);
2122+
expect(readyCall?.[2]).toBeLessThanOrEqual(45_000);
21192123

21202124
entersStateMock.mockClear();
21212125
entersStateMock.mockRejectedValueOnce(new Error("still disconnected"));

‎extensions/memory-core/src/dreaming.ts‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,12 @@ import {
2525
uniqueStrings,
2626
} from "openclaw/plugin-sdk/string-coerce-runtime";
2727
import { peekSystemEventEntries } from "openclaw/plugin-sdk/system-event-runtime";
28-
import { writeDeepDreamingReport } from "./dreaming-markdown.js";
29-
import {
30-
generateAndAppendDreamNarrative,
31-
type NarrativePhaseData,
32-
runDetachedDreamNarrative,
33-
} from "./dreaming-narrative.js";
34-
import { runDreamingSweepPhases } from "./dreaming-phases.js";
28+
import type { NarrativePhaseData } from "./dreaming-narrative.js";
3529
import {
3630
formatErrorMessage,
3731
includesSystemEventToken,
3832
normalizeTrimmedString,
3933
} from "./dreaming-shared.js";
40-
import {
41-
applyShortTermPromotions,
42-
repairShortTermPromotionArtifacts,
43-
rankShortTermPromotionCandidates,
44-
} from "./short-term-promotion.js";
4534

4635
const RUNTIME_CRON_RECONCILE_INTERVAL_MS = 60_000;
4736
const STARTUP_CRON_RETRY_DELAY_MS = 5_000;
@@ -500,7 +489,7 @@ export async function runShortTermDreamingPromotionIfTriggered(params: {
500489
cfg?: OpenClawConfig;
501490
config: ShortTermPromotionDreamingConfig;
502491
logger: Logger;
503-
subagent?: Parameters<typeof generateAndAppendDreamNarrative>[0]["subagent"];
492+
subagent?: OpenClawPluginApi["runtime"]["subagent"];
504493
}): Promise<{ handled: true; reason: string } | undefined> {
505494
if (params.trigger !== "heartbeat" && params.trigger !== "cron") {
506495
return undefined;
@@ -554,6 +543,21 @@ export async function runShortTermDreamingPromotionIfTriggered(params: {
554543
let failedWorkspaces = 0;
555544
const pluginConfig = params.cfg ? resolveMemoryCorePluginConfig(params.cfg) : undefined;
556545
const detachNarratives = params.trigger === "cron";
546+
const [
547+
{ writeDeepDreamingReport },
548+
{ generateAndAppendDreamNarrative, runDetachedDreamNarrative },
549+
{ runDreamingSweepPhases },
550+
{
551+
applyShortTermPromotions,
552+
repairShortTermPromotionArtifacts,
553+
rankShortTermPromotionCandidates,
554+
},
555+
] = await Promise.all([
556+
import("./dreaming-markdown.js"),
557+
import("./dreaming-narrative.js"),
558+
import("./dreaming-phases.js"),
559+
import("./short-term-promotion.js"),
560+
]);
557561
for (const workspaceDir of workspaces) {
558562
try {
559563
const sweepNowMs = Date.now();

‎extensions/telegram/src/bot.media.e2e-harness.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { mkdtempSync, rmSync } from "node:fs";
2+
import os from "node:os";
13
import path from "node:path";
24
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
35
import { resetInboundDedupe } from "openclaw/plugin-sdk/reply-runtime";
46
import type { GetReplyOptions, MsgContext } from "openclaw/plugin-sdk/reply-runtime";
5-
import { beforeEach, vi, type Mock } from "vitest";
7+
import { afterEach, beforeEach, vi, type Mock } from "vitest";
68
import type { TelegramBotDeps } from "./bot-deps.js";
79
import {
810
resetTopicNameCacheForTest,
@@ -72,6 +74,20 @@ async function defaultSaveMediaBuffer(buffer: Buffer, contentType?: string) {
7274
}
7375

7476
const saveMediaBufferSpy: Mock = vi.fn(defaultSaveMediaBuffer);
77+
let mediaHarnessStoreRoot: string | undefined;
78+
79+
function ensureMediaHarnessStoreRoot(): string {
80+
mediaHarnessStoreRoot ??= mkdtempSync(path.join(os.tmpdir(), "openclaw-telegram-media-e2e-"));
81+
return mediaHarnessStoreRoot;
82+
}
83+
84+
function cleanupMediaHarnessStoreRoot(): void {
85+
if (!mediaHarnessStoreRoot) {
86+
return;
87+
}
88+
rmSync(mediaHarnessStoreRoot, { recursive: true, force: true });
89+
mediaHarnessStoreRoot = undefined;
90+
}
7591

7692
export function setNextSavedMediaPath(params: {
7793
path: string;
@@ -181,7 +197,7 @@ export const telegramBotDepsForTest: TelegramBotDeps = {
181197
channels: { telegram: { dmPolicy: "open", allowFrom: ["*"] } },
182198
}) as OpenClawConfig) as TelegramBotDeps["getRuntimeConfig"],
183199
resolveStorePath: vi.fn(
184-
(storePath?: string) => storePath ?? "/tmp/telegram-media-sessions.json",
200+
(storePath?: string) => storePath ?? path.join(ensureMediaHarnessStoreRoot(), "sessions.json"),
185201
) as TelegramBotDeps["resolveStorePath"],
186202
readChannelAllowFromStore: vi.fn(async () => []) as TelegramBotDeps["readChannelAllowFromStore"],
187203
upsertChannelPairingRequest: vi.fn(async () => ({
@@ -201,6 +217,8 @@ export const telegramBotDepsForTest: TelegramBotDeps = {
201217
};
202218

203219
beforeEach(() => {
220+
cleanupMediaHarnessStoreRoot();
221+
ensureMediaHarnessStoreRoot();
204222
resetInboundDedupe();
205223
topicNameStoresForTest.clear();
206224
resetTopicNameCacheForTest();
@@ -209,6 +227,10 @@ beforeEach(() => {
209227
resetReadRemoteMediaBufferMock();
210228
});
211229

230+
afterEach(() => {
231+
cleanupMediaHarnessStoreRoot();
232+
});
233+
212234
vi.doMock("./bot.runtime.js", () => ({
213235
...telegramBotRuntimeForTest,
214236
}));
@@ -262,7 +284,8 @@ vi.doMock("./bot-message-context.session.runtime.js", async () => {
262284
return {
263285
...actual,
264286
readSessionUpdatedAt: () => undefined,
265-
resolveStorePath: (storePath?: string) => storePath ?? "/tmp/sessions.json",
287+
resolveStorePath: (storePath?: string) =>
288+
storePath ?? path.join(ensureMediaHarnessStoreRoot(), "sessions.json"),
266289
};
267290
});
268291

‎src/cli/gateway-cli/run.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,9 @@ export async function runGatewayCommand(opts: GatewayRunOpts) {
807807
gatewayLog.info("starting...");
808808
startupTrace.mark("cli.gateway-loop");
809809
let startupConfigSnapshotReadForNextStart = startupConfigSnapshotRead;
810+
const deferStartupSidecars =
811+
isTruthyEnvValue(process.env.OPENCLAW_SKIP_CHANNELS) ||
812+
isTruthyEnvValue(process.env.OPENCLAW_SKIP_PROVIDERS);
810813
const startLoop = async () =>
811814
await runGatewayLoop({
812815
runtime: defaultRuntime,
@@ -823,6 +826,7 @@ export async function runGatewayCommand(opts: GatewayRunOpts) {
823826
...(startupConfigSnapshotReadForThisStart
824827
? { startupConfigSnapshotRead: startupConfigSnapshotReadForThisStart }
825828
: {}),
829+
...(deferStartupSidecars ? { deferStartupSidecars: true } : {}),
826830
});
827831
},
828832
});

‎src/docker-setup.e2e.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ async function createDockerSetupSandbox(): Promise<DockerSetupSandbox> {
7777
join(repoRoot, "scripts", "lib", "docker-e2e-logs.sh"),
7878
join(rootDir, "scripts", "lib", "docker-e2e-logs.sh"),
7979
);
80+
await copyFile(
81+
join(repoRoot, "scripts", "lib", "docker-e2e-container.sh"),
82+
join(rootDir, "scripts", "lib", "docker-e2e-container.sh"),
83+
);
8084
await chmod(scriptPath, 0o755);
8185
await writeFile(dockerfilePath, "FROM scratch\n");
8286
await writeFile(
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
import fs from "node:fs/promises";
2+
import os from "node:os";
3+
import path from "node:path";
4+
import { afterEach, describe, expect, it } from "vitest";
5+
import { clearConfigCache, clearRuntimeConfigSnapshot } from "../config/config.js";
6+
import { clearSessionStoreCacheForTest } from "../config/sessions/store.js";
7+
import type { OpenClawConfig } from "../config/types.openclaw.js";
8+
import { captureEnv } from "../test-utils/env.js";
9+
import { ADMIN_SCOPE, APPROVALS_SCOPE } from "./method-scopes.js";
10+
import { withOperatorApprovalsGatewayClient } from "./operator-approvals-client.js";
11+
import { startGatewayServer } from "./server.js";
12+
import {
13+
connectGatewayClient,
14+
disconnectGatewayClient,
15+
getFreeGatewayPort,
16+
} from "./test-helpers.e2e.js";
17+
18+
const TEST_ENV_KEYS = [
19+
"HOME",
20+
"OPENCLAW_STATE_DIR",
21+
"OPENCLAW_CONFIG_PATH",
22+
"OPENCLAW_GATEWAY_URL",
23+
"OPENCLAW_GATEWAY_TOKEN",
24+
"OPENCLAW_GATEWAY_PASSWORD",
25+
"OPENCLAW_GATEWAY_PORT",
26+
];
27+
28+
type Cleanup = () => Promise<void> | void;
29+
30+
async function requestExecApproval(params: {
31+
requester: Awaited<ReturnType<typeof connectGatewayClient>>;
32+
id: string;
33+
}): Promise<void> {
34+
await expect(
35+
params.requester.request("exec.approval.request", {
36+
id: params.id,
37+
command: "printf smoke",
38+
cwd: "/tmp",
39+
host: "local",
40+
ask: "always",
41+
twoPhase: true,
42+
timeoutMs: 60_000,
43+
}),
44+
).resolves.toMatchObject({
45+
status: "accepted",
46+
id: params.id,
47+
});
48+
}
49+
50+
describe("operator approval gateway client runtime token source", () => {
51+
const cleanup: Cleanup[] = [];
52+
53+
afterEach(async () => {
54+
for (const step of cleanup.splice(0).toReversed()) {
55+
await step();
56+
}
57+
clearRuntimeConfigSnapshot();
58+
clearConfigCache();
59+
clearSessionStoreCacheForTest();
60+
});
61+
62+
it("uses runtime authority only for generated local gateway URLs", async () => {
63+
const envSnapshot = captureEnv(TEST_ENV_KEYS);
64+
cleanup.push(() => envSnapshot.restore());
65+
delete process.env.OPENCLAW_CONFIG_PATH;
66+
delete process.env.OPENCLAW_GATEWAY_URL;
67+
delete process.env.OPENCLAW_GATEWAY_TOKEN;
68+
delete process.env.OPENCLAW_GATEWAY_PASSWORD;
69+
70+
const tempHome = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-approval-client-e2e-"));
71+
cleanup.push(() => fs.rm(tempHome, { recursive: true, force: true, maxRetries: 5 }));
72+
73+
const stateDir = path.join(tempHome, ".openclaw");
74+
await fs.mkdir(stateDir, { recursive: true });
75+
process.env.HOME = tempHome;
76+
process.env.OPENCLAW_STATE_DIR = stateDir;
77+
78+
const port = await getFreeGatewayPort();
79+
const token = "approval-client-e2e-token";
80+
const url = `ws://127.0.0.1:${port}`;
81+
process.env.OPENCLAW_GATEWAY_PORT = String(port);
82+
83+
const server = await startGatewayServer(port, {
84+
bind: "loopback",
85+
auth: { mode: "token", token },
86+
controlUiEnabled: false,
87+
deferStartupSidecars: true,
88+
});
89+
cleanup.push(() => server.close());
90+
91+
const admin = await connectGatewayClient({
92+
url,
93+
token,
94+
clientDisplayName: "approval admin",
95+
scopes: [ADMIN_SCOPE],
96+
timeoutMs: 60_000,
97+
});
98+
cleanup.push(() => disconnectGatewayClient(admin));
99+
100+
const requester = await connectGatewayClient({
101+
url,
102+
token,
103+
clientDisplayName: "approval requester",
104+
scopes: [APPROVALS_SCOPE],
105+
timeoutMs: 60_000,
106+
});
107+
cleanup.push(() => disconnectGatewayClient(requester));
108+
109+
const localConfig = {
110+
gateway: {
111+
port,
112+
auth: { mode: "token", token },
113+
},
114+
} satisfies OpenClawConfig;
115+
116+
await requestExecApproval({ requester, id: "local-source-approval" });
117+
await withOperatorApprovalsGatewayClient(
118+
{
119+
config: localConfig,
120+
clientDisplayName: "local source approval resolver",
121+
},
122+
async (client) => {
123+
await client.request(
124+
"exec.approval.resolve",
125+
{ id: "local-source-approval", decision: "allow-once" },
126+
{ timeoutMs: 10_000 },
127+
);
128+
},
129+
);
130+
131+
const remoteLoopbackConfig = {
132+
gateway: {
133+
mode: "remote",
134+
remote: { url },
135+
auth: { mode: "token", token },
136+
},
137+
} satisfies OpenClawConfig;
138+
139+
await requestExecApproval({ requester, id: "remote-loopback-approval" });
140+
await expect(
141+
withOperatorApprovalsGatewayClient(
142+
{
143+
config: remoteLoopbackConfig,
144+
clientDisplayName: "remote loopback approval resolver",
145+
},
146+
async (client) => {
147+
await client.request(
148+
"exec.approval.resolve",
149+
{ id: "remote-loopback-approval", decision: "allow-once" },
150+
{ timeoutMs: 10_000 },
151+
);
152+
},
153+
),
154+
).rejects.toMatchObject({
155+
gatewayCode: "INVALID_REQUEST",
156+
details: { reason: "APPROVAL_NOT_FOUND" },
157+
});
158+
159+
await admin.request(
160+
"exec.approval.resolve",
161+
{ id: "remote-loopback-approval", decision: "deny" },
162+
{ timeoutMs: 10_000 },
163+
);
164+
}, 120_000);
165+
});

0 commit comments

Comments
 (0)