Skip to content

Commit e468614

Browse files
committed
Auto-merge upstream openclaw/openclaw
2 parents fb0feed + 4d2ea43 commit e468614

11 files changed

Lines changed: 443 additions & 32 deletions

scripts/openclaw-npm-postpublish-verify.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ export function collectInstalledPackageErrors(params: {
7878
packageRoot: string;
7979
}): string[] {
8080
const errors: string[] = [];
81+
const installedVersion = normalizeInstalledBinaryVersion(params.installedVersion);
8182

82-
if (params.installedVersion !== params.expectedVersion) {
83+
if (installedVersion !== params.expectedVersion) {
8384
errors.push(
8485
`installed package version mismatch: expected ${params.expectedVersion}, found ${params.installedVersion || "<missing>"}.`,
8586
);
@@ -96,6 +97,12 @@ export function collectInstalledPackageErrors(params: {
9697
return errors;
9798
}
9899

100+
export function normalizeInstalledBinaryVersion(output: string): string {
101+
const trimmed = output.trim();
102+
const versionMatch = /\b\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+|-beta\.\d+)?\b/u.exec(trimmed);
103+
return versionMatch?.[0] ?? trimmed;
104+
}
105+
99106
export function resolveInstalledBinaryPath(prefixDir: string, platform = process.platform): string {
100107
return platform === "win32"
101108
? join(prefixDir, "openclaw.cmd")
@@ -109,6 +116,25 @@ function collectRuntimeDependencySpecs(packageJson: InstalledPackageJson): Map<s
109116
]);
110117
}
111118

119+
function collectExpectedBundledExtensionPackageIds(
120+
sourceExtensionsDir = join(process.cwd(), "extensions"),
121+
): ReadonlySet<string> | null {
122+
if (!existsSync(sourceExtensionsDir)) {
123+
return null;
124+
}
125+
126+
const ids = new Set<string>();
127+
for (const entry of readdirSync(sourceExtensionsDir, { withFileTypes: true })) {
128+
if (!entry.isDirectory()) {
129+
continue;
130+
}
131+
if (existsSync(join(sourceExtensionsDir, entry.name, "package.json"))) {
132+
ids.add(entry.name);
133+
}
134+
}
135+
return ids;
136+
}
137+
112138
function readBundledExtensionPackageJsons(packageRoot: string): {
113139
manifests: InstalledBundledExtensionManifestRecord[];
114140
errors: string[];
@@ -120,6 +146,7 @@ function readBundledExtensionPackageJsons(packageRoot: string): {
120146

121147
const manifests: InstalledBundledExtensionManifestRecord[] = [];
122148
const errors: string[] = [];
149+
const expectedPackageIds = collectExpectedBundledExtensionPackageIds();
123150

124151
for (const entry of readdirSync(extensionsDir, { withFileTypes: true })) {
125152
if (!entry.isDirectory()) {
@@ -129,7 +156,9 @@ function readBundledExtensionPackageJsons(packageRoot: string): {
129156
const extensionDirPath = join(extensionsDir, entry.name);
130157
const packageJsonPath = join(extensionsDir, entry.name, "package.json");
131158
if (!existsSync(packageJsonPath)) {
132-
errors.push(`installed bundled extension manifest missing: ${packageJsonPath}.`);
159+
if (expectedPackageIds === null || expectedPackageIds.has(entry.name)) {
160+
errors.push(`installed bundled extension manifest missing: ${packageJsonPath}.`);
161+
}
133162
continue;
134163
}
135164

@@ -281,7 +310,7 @@ function verifyScenario(version: string, scenario: PublishedInstallScenario): vo
281310
});
282311
const installedBinaryVersion = readInstalledBinaryVersion(prefixDir, workingDir);
283312

284-
if (installedBinaryVersion !== scenario.expectedVersion) {
313+
if (normalizeInstalledBinaryVersion(installedBinaryVersion) !== scenario.expectedVersion) {
285314
errors.push(
286315
`installed openclaw binary version mismatch: expected ${scenario.expectedVersion}, found ${installedBinaryVersion || "<missing>"}.`,
287316
);

scripts/test-projects.test-support.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const EXTENSION_VOICE_CALL_VITEST_CONFIG = "vitest.extension-voice-call.config.t
6262
const EXTENSION_WHATSAPP_VITEST_CONFIG = "vitest.extension-whatsapp.config.ts";
6363
const EXTENSION_ZALO_VITEST_CONFIG = "vitest.extension-zalo.config.ts";
6464
const EXTENSIONS_VITEST_CONFIG = "vitest.extensions.config.ts";
65+
const FULL_EXTENSIONS_VITEST_CONFIG = "vitest.full-extensions.config.ts";
6566
const GATEWAY_VITEST_CONFIG = "vitest.gateway.config.ts";
6667
const HOOKS_VITEST_CONFIG = "vitest.hooks.config.ts";
6768
const INFRA_VITEST_CONFIG = "vitest.infra.config.ts";
@@ -621,6 +622,12 @@ export function buildFullSuiteVitestRunPlans(args, cwd = process.cwd()) {
621622
}
622623
const expandToProjectConfigs = process.env.OPENCLAW_TEST_PROJECTS_LEAF_SHARDS === "1";
623624
return fullSuiteVitestShards.flatMap((shard) => {
625+
if (
626+
process.env.OPENCLAW_TEST_SKIP_FULL_EXTENSIONS_SHARD === "1" &&
627+
shard.config === FULL_EXTENSIONS_VITEST_CONFIG
628+
) {
629+
return [];
630+
}
624631
const configs = expandToProjectConfigs ? shard.projects : [shard.config];
625632
return configs.map((config) => ({
626633
config,

src/auto-reply/reply/commands-status.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ async function buildStatusReplyForTest(params: { sessionKey?: string; verbose?:
4747
resolveDefaultThinkingLevel: commandParams.resolveDefaultThinkingLevel,
4848
isGroup: commandParams.isGroup,
4949
defaultGroupActivation: commandParams.defaultGroupActivation,
50+
modelAuthOverride: "api-key",
51+
activeModelAuthOverride: "api-key",
5052
});
5153
}
5254

@@ -473,6 +475,8 @@ describe("buildStatusReply subagent summary", () => {
473475
resolveDefaultThinkingLevel: async () => undefined,
474476
isGroup: false,
475477
defaultGroupActivation: () => "mention",
478+
modelAuthOverride: "api-key",
479+
activeModelAuthOverride: "api-key",
476480
});
477481

478482
expect(normalizeTestText(text)).toContain("Context: 1.0k/32k");

src/auto-reply/reply/commands-status.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ export async function buildStatusReply(params: {
110110
isGroup: boolean;
111111
defaultGroupActivation: () => "always" | "mention";
112112
mediaDecisions?: MediaUnderstandingDecision[];
113+
modelAuthOverride?: string;
114+
activeModelAuthOverride?: string;
113115
}): Promise<ReplyPayload | undefined> {
114116
const { command } = params;
115117
if (!command.isAuthorizedSender) {
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
import fs from "node:fs";
2+
import os from "node:os";
3+
import path from "node:path";
4+
import { beforeEach, describe, expect, it, vi } from "vitest";
5+
import type { OpenClawConfig } from "../config/config.js";
6+
import type { RuntimeEnv } from "../runtime.js";
7+
import type { agentCliCommand as AgentCliCommand } from "./agent-via-gateway.js";
8+
import type { agentCommand as AgentCommand } from "./agent.js";
9+
10+
const loadConfig = vi.hoisted(() => vi.fn());
11+
const callGateway = vi.hoisted(() => vi.fn());
12+
const agentCommand = vi.hoisted(() => vi.fn());
13+
14+
let agentCliCommand: typeof AgentCliCommand;
15+
16+
const runtime: RuntimeEnv = {
17+
log: vi.fn(),
18+
error: vi.fn(),
19+
exit: vi.fn(),
20+
};
21+
22+
function mockConfig(storePath: string, overrides?: Partial<OpenClawConfig>) {
23+
loadConfig.mockReturnValue({
24+
agents: {
25+
defaults: {
26+
timeoutSeconds: 600,
27+
...overrides?.agents?.defaults,
28+
},
29+
},
30+
session: {
31+
store: storePath,
32+
mainKey: "main",
33+
...overrides?.session,
34+
},
35+
gateway: overrides?.gateway,
36+
});
37+
}
38+
39+
async function withTempStore(
40+
fn: (ctx: { dir: string; store: string }) => Promise<void>,
41+
overrides?: Partial<OpenClawConfig>,
42+
) {
43+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-agent-cli-"));
44+
const store = path.join(dir, "sessions.json");
45+
mockConfig(store, overrides);
46+
try {
47+
await fn({ dir, store });
48+
} finally {
49+
fs.rmSync(dir, { recursive: true, force: true });
50+
}
51+
}
52+
53+
function mockGatewaySuccessReply(text = "hello") {
54+
callGateway.mockResolvedValue({
55+
runId: "idem-1",
56+
status: "ok",
57+
result: {
58+
payloads: [{ text }],
59+
meta: { stub: true },
60+
},
61+
});
62+
}
63+
64+
function mockLocalAgentReply(text = "local") {
65+
agentCommand.mockImplementationOnce(async (_opts, rt) => {
66+
rt?.log?.(text);
67+
return {
68+
payloads: [{ text }],
69+
meta: { durationMs: 1, agentMeta: { sessionId: "s", provider: "p", model: "m" } },
70+
} as unknown as Awaited<ReturnType<typeof AgentCommand>>;
71+
});
72+
}
73+
74+
beforeEach(async () => {
75+
vi.clearAllMocks();
76+
vi.resetModules();
77+
vi.doMock("../config/config.js", () => ({ loadConfig }));
78+
vi.doMock("../gateway/call.js", () => ({
79+
callGateway,
80+
randomIdempotencyKey: () => "idem-1",
81+
}));
82+
vi.doMock("./agent.js", () => ({ agentCommand }));
83+
({ agentCliCommand } = await import("./agent-via-gateway.js"));
84+
});
85+
86+
describe("agentCliCommand", () => {
87+
it("uses a timer-safe max gateway timeout when --timeout is 0", async () => {
88+
await withTempStore(async () => {
89+
mockGatewaySuccessReply();
90+
91+
await agentCliCommand({ message: "hi", to: "+1555", timeout: "0" }, runtime);
92+
93+
expect(callGateway).toHaveBeenCalledTimes(1);
94+
const request = callGateway.mock.calls[0]?.[0] as { timeoutMs?: number };
95+
expect(request.timeoutMs).toBe(2_147_000_000);
96+
});
97+
});
98+
99+
it("uses gateway by default", async () => {
100+
await withTempStore(async () => {
101+
mockGatewaySuccessReply();
102+
103+
await agentCliCommand({ message: "hi", to: "+1555" }, runtime);
104+
105+
expect(callGateway).toHaveBeenCalledTimes(1);
106+
expect(agentCommand).not.toHaveBeenCalled();
107+
expect(runtime.log).toHaveBeenCalledWith("hello");
108+
});
109+
});
110+
111+
it("falls back to embedded agent when gateway fails", async () => {
112+
await withTempStore(async () => {
113+
callGateway.mockRejectedValue(new Error("gateway not connected"));
114+
mockLocalAgentReply();
115+
116+
await agentCliCommand({ message: "hi", to: "+1555" }, runtime);
117+
118+
expect(callGateway).toHaveBeenCalledTimes(1);
119+
expect(agentCommand).toHaveBeenCalledTimes(1);
120+
expect(runtime.log).toHaveBeenCalledWith("local");
121+
});
122+
});
123+
124+
it("skips gateway when --local is set", async () => {
125+
await withTempStore(async () => {
126+
mockLocalAgentReply();
127+
128+
await agentCliCommand(
129+
{
130+
message: "hi",
131+
to: "+1555",
132+
local: true,
133+
},
134+
runtime,
135+
);
136+
137+
expect(callGateway).not.toHaveBeenCalled();
138+
expect(agentCommand).toHaveBeenCalledTimes(1);
139+
expect(agentCommand.mock.calls[0]?.[0]).toMatchObject({
140+
cleanupBundleMcpOnRunEnd: true,
141+
});
142+
expect(runtime.log).toHaveBeenCalledWith("local");
143+
});
144+
});
145+
146+
it("does not force bundle MCP cleanup on gateway fallback", async () => {
147+
await withTempStore(async () => {
148+
callGateway.mockRejectedValue(new Error("gateway not connected"));
149+
mockLocalAgentReply();
150+
151+
await agentCliCommand({ message: "hi", to: "+1555" }, runtime);
152+
153+
expect(agentCommand).toHaveBeenCalledTimes(1);
154+
expect(agentCommand.mock.calls[0]?.[0]).not.toMatchObject({
155+
cleanupBundleMcpOnRunEnd: true,
156+
});
157+
});
158+
});
159+
});

src/plugins/bundled-capability-metadata.test.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
13
import { describe, expect, it } from "vitest";
2-
import { listBundledPluginMetadata } from "./bundled-plugin-metadata.js";
4+
import { normalizeBundledPluginStringList } from "./bundled-plugin-scan.js";
35
import {
46
BUNDLED_AUTO_ENABLE_PROVIDER_PLUGIN_IDS,
57
BUNDLED_LEGACY_PLUGIN_ID_ALIASES,
68
BUNDLED_PLUGIN_CONTRACT_SNAPSHOTS,
79
} from "./contracts/inventory/bundled-capability-metadata.js";
810
import { uniqueStrings } from "./contracts/shared.js";
11+
import { pluginTestRepoRoot as repoRoot } from "./generated-plugin-test-helpers.js";
12+
import type { PluginManifest } from "./manifest.js";
13+
14+
function readManifestRecords(): PluginManifest[] {
15+
const extensionsDir = path.join(repoRoot, "extensions");
16+
return fs
17+
.readdirSync(extensionsDir, { withFileTypes: true })
18+
.filter((entry) => entry.isDirectory())
19+
.map((entry) => path.join(extensionsDir, entry.name))
20+
.filter((pluginDir) => {
21+
const packagePath = path.join(pluginDir, "package.json");
22+
if (!fs.existsSync(packagePath)) {
23+
return false;
24+
}
25+
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf-8")) as {
26+
openclaw?: { extensions?: unknown };
27+
};
28+
return normalizeBundledPluginStringList(packageJson.openclaw?.extensions).length > 0;
29+
})
30+
.map(
31+
(pluginDir) =>
32+
JSON.parse(
33+
fs.readFileSync(path.join(pluginDir, "openclaw.plugin.json"), "utf-8"),
34+
) as PluginManifest,
35+
)
36+
.toSorted((left, right) => left.id.localeCompare(right.id));
37+
}
938

1039
describe("bundled capability metadata", () => {
1140
it("keeps contract snapshots aligned with bundled plugin manifests", () => {
12-
const expected = listBundledPluginMetadata()
13-
.map(({ manifest }) => ({
41+
const expected = readManifestRecords()
42+
.map((manifest) => ({
1443
pluginId: manifest.id,
1544
cliBackendIds: uniqueStrings(manifest.cliBackends, (value) => value.trim()),
1645
providerIds: uniqueStrings(manifest.providers, (value) => value.trim()),
@@ -70,7 +99,7 @@ describe("bundled capability metadata", () => {
7099
});
71100

72101
it("keeps lightweight alias maps aligned with bundled plugin manifests", () => {
73-
const manifests = listBundledPluginMetadata().map((entry) => entry.manifest);
102+
const manifests = readManifestRecords();
74103
const expectedLegacyAliases = Object.fromEntries(
75104
manifests
76105
.flatMap((manifest) =>

0 commit comments

Comments
 (0)