Skip to content

Commit 63caab0

Browse files
committed
perf(test): consolidate channel artifact parity
1 parent d60a98e commit 63caab0

7 files changed

Lines changed: 200 additions & 91 deletions

‎scripts/test-projects.test-support.mts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,27 @@ const CHANNEL_CONTRACT_REGISTRY_BACKED_TARGETS = [
584584
`src/channels/plugins/contracts/${suite}.registry-backed-shard-${shard}.contract.test.ts`,
585585
),
586586
);
587+
const CHANNEL_PLUGIN_SHAPE_PARITY_TEST_TARGET =
588+
"src/channels/plugins/contracts/plugin-shape.contract.test.ts";
589+
const CHANNEL_PLUGIN_SHAPE_PARITY_WIRING_PATHS = new Set([
590+
"extensions/imessage/message-tool-api.ts",
591+
"extensions/imessage/src/actions.ts",
592+
"extensions/imessage/src/channel.ts",
593+
"extensions/slack/message-tool-api.ts",
594+
"extensions/slack/src/channel-actions.ts",
595+
"extensions/slack/src/channel.ts",
596+
"extensions/mattermost/gateway-auth-api.ts",
597+
"extensions/mattermost/src/channel.ts",
598+
"extensions/feishu/session-key-api.ts",
599+
"extensions/feishu/src/channel.ts",
600+
"extensions/telegram/session-key-api.ts",
601+
"extensions/telegram/src/channel.ts",
602+
"extensions/discord/session-key-api.ts",
603+
"extensions/discord/thread-binding-api.ts",
604+
"extensions/discord/src/channel.ts",
605+
"extensions/matrix/thread-binding-api.ts",
606+
"extensions/matrix/src/channel.ts",
607+
]);
587608
const TEST_HELPER_NORMALIZE_TEXT_TARGETS = [
588609
"src/auto-reply/reply/commands-status.test.ts",
589610
"src/auto-reply/status.test.ts",
@@ -3084,12 +3105,16 @@ export function resolveChangedTestTargetPlan(
30843105
const targets = [];
30853106
const skippedBroadFallbackPaths = [];
30863107
for (const changedPath of executableChangedPaths) {
3108+
const needsPluginShapeParity = CHANNEL_PLUGIN_SHAPE_PARITY_WIRING_PATHS.has(changedPath);
30873109
const preciseTargets = resolvePreciseChangedTestTargets(changedPath, {
30883110
...options,
30893111
skipImportGraph,
30903112
});
30913113
if (preciseTargets) {
30923114
targets.push(...preciseTargets);
3115+
if (needsPluginShapeParity) {
3116+
targets.push(CHANNEL_PLUGIN_SHAPE_PARITY_TEST_TARGET);
3117+
}
30933118
continue;
30943119
}
30953120
const needsBroadFallback = shouldKeepBroadChangedRun([changedPath]) || changedLanes.lanes.all;
@@ -3103,6 +3128,9 @@ export function resolveChangedTestTargetPlan(
31033128
if (isRoutableChangedTarget(changedPath)) {
31043129
targets.push(changedPath);
31053130
}
3131+
if (needsPluginShapeParity) {
3132+
targets.push(CHANNEL_PLUGIN_SHAPE_PARITY_TEST_TARGET);
3133+
}
31063134
}
31073135
if (
31083136
useBroadFallback &&

‎src/channels/plugins/contracts/gateway-auth-artifact.contract.test.ts‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
// Gateway-auth artifact parity contract for bundled channel plugins.
1+
// Gateway-auth lightweight artifact contract for bundled channel plugins.
22
//
33
// Core resolves unauthenticated Gateway callback paths from lightweight
44
// `gateway-auth-api` artifacts (src/channels/plugins/gateway-auth-bypass.ts),
5-
// which invoke the export with a `{ cfg }` params object. This suite pins each
6-
// artifact export to the exact function the loaded plugin's gateway surface
7-
// uses and pins the params-object call shape core relies on.
5+
// which invoke the export with a `{ cfg }` params object. This shard owns
6+
// inventory, export shape, and that invocation contract; loaded-plugin parity
7+
// lives in plugin-shape.contract.test.ts.
88
import { beforeAll, describe, expect, it } from "vitest";
99
import {
1010
getBundledChannelGatewayAuthArtifactAsync,
11-
getBundledChannelPluginAsync,
1211
listBundledChannelPluginIds,
1312
} from "./test-helpers/bundled-channel-plugin-loader.js";
1413

@@ -29,19 +28,11 @@ describe("bundled channel gateway-auth artifact parity", () => {
2928

3029
it("keeps the artifact table in sync with bundled channels that ship one", () => {
3130
expect([...artifactResolvers.keys()].toSorted()).toEqual([...GATEWAY_AUTH_ARTIFACT_PLUGIN_IDS]);
31+
for (const id of GATEWAY_AUTH_ARTIFACT_PLUGIN_IDS) {
32+
expect(typeof artifactResolvers.get(id)).toBe("function");
33+
}
3234
});
3335

34-
it.each(GATEWAY_AUTH_ARTIFACT_PLUGIN_IDS)(
35-
"keeps the %s artifact resolver identical to the plugin gateway surface",
36-
async (id) => {
37-
const resolveGatewayAuthBypassPaths = artifactResolvers.get(id);
38-
expect(typeof resolveGatewayAuthBypassPaths).toBe("function");
39-
40-
const plugin = await getBundledChannelPluginAsync(id);
41-
expect(plugin?.gateway?.resolveGatewayAuthBypassPaths).toBe(resolveGatewayAuthBypassPaths);
42-
},
43-
);
44-
4536
it("resolves mattermost bypass paths through core's { cfg } call shape", () => {
4637
// Regression pin: the artifact once took `cfg` positionally, so core's
4738
// `{ cfg }` invocation silently dropped configured callback paths.
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
// Message-tool artifact parity contract for bundled channel plugins.
1+
// Message-tool lightweight artifact contract for bundled channel plugins.
22
//
33
// Core discovers message-tool schemas from lightweight `message-tool-api`
44
// artifacts without loading full channel plugins
5-
// (src/channels/plugins/message-tool-api.ts). This suite pins each artifact
6-
// export to the exact function the loaded plugin's action surface uses so
7-
// discovery cannot drift from runtime behavior.
5+
// (src/channels/plugins/message-tool-api.ts). This shard owns artifact inventory
6+
// and export shape; loaded-plugin parity lives in plugin-shape.contract.test.ts.
87
import { beforeAll, describe, expect, it } from "vitest";
98
import {
109
getBundledChannelMessageToolArtifactAsync,
11-
getBundledChannelPluginAsync,
1210
listBundledChannelPluginIds,
1311
} from "./test-helpers/bundled-channel-plugin-loader.js";
1412

@@ -31,16 +29,8 @@ describe("bundled channel message-tool artifact parity", () => {
3129
expect([...artifactDescribers.keys()].toSorted()).toEqual([
3230
...MESSAGE_TOOL_ARTIFACT_PLUGIN_IDS,
3331
]);
32+
for (const id of MESSAGE_TOOL_ARTIFACT_PLUGIN_IDS) {
33+
expect(typeof artifactDescribers.get(id)).toBe("function");
34+
}
3435
});
35-
36-
it.each(MESSAGE_TOOL_ARTIFACT_PLUGIN_IDS)(
37-
"keeps the %s artifact describer identical to the plugin action surface",
38-
async (id) => {
39-
const describeMessageTool = artifactDescribers.get(id);
40-
expect(typeof describeMessageTool).toBe("function");
41-
42-
const plugin = await getBundledChannelPluginAsync(id);
43-
expect(plugin?.actions?.describeMessageTool).toBe(describeMessageTool);
44-
},
45-
);
4636
});

‎src/channels/plugins/contracts/plugin-shape.contract.test.ts‎

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking"
44
// Catalog routing keys off plugin ids, docs surfaces render `meta.docsPath`,
55
// and capability flags gate feature discovery, so every bundled channel must
66
// keep identity metadata aligned with its catalog id and capability flags
7-
// coherent with the adapters that implement them. Per-surface behavior checks
8-
// live in the registry-backed shard suites; this suite pins the static shape.
7+
// coherent with the adapters that implement them. This suite already loads
8+
// every bundled plugin, so it also owns loaded-plugin parity for lightweight
9+
// artifacts while the artifact shards pin inventory, exports, and invocation.
910
//
1011
// Capability rules verified against every bundled channel before pinning.
1112
// Dropped for legitimate exceptions rather than special-casing:
@@ -18,7 +19,11 @@ import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking"
1819
import { beforeAll, describe, expect, it } from "vitest";
1920
import { listBundledPackageChannelMetadata } from "../../../plugins/bundled-package-channel-metadata.js";
2021
import {
22+
getBundledChannelGatewayAuthArtifactAsync,
23+
getBundledChannelMessageToolArtifactAsync,
2124
getBundledChannelPluginAsync,
25+
getBundledChannelSessionKeyArtifactAsync,
26+
getBundledChannelThreadBindingArtifactAsync,
2227
listBundledChannelPluginIds,
2328
} from "./test-helpers/bundled-channel-plugin-loader.js";
2429

@@ -37,14 +42,46 @@ const SHARED_SANITIZER_CHANNEL_IDS = [
3742
"matrix",
3843
"slack",
3944
] as const;
45+
const MESSAGE_TOOL_ARTIFACT_PLUGIN_IDS = ["imessage", "slack"] as const;
46+
const SESSION_CONVERSATION_ARTIFACT_PLUGIN_IDS = ["feishu", "telegram"] as const;
47+
const THREAD_BINDING_ARTIFACT_PLUGIN_IDS = ["discord", "matrix"] as const;
48+
49+
type ExplicitSessionKeyNormalizer = (
50+
sessionKey: string,
51+
ctx: { ChatType?: string; From?: string; SenderId?: string },
52+
) => string;
4053

4154
describe("bundled channel plugin shape coherence", () => {
4255
const plugins = new Map<string, Awaited<ReturnType<typeof getBundledChannelPluginAsync>>>();
56+
const messageToolArtifacts = new Map<
57+
string,
58+
Awaited<ReturnType<typeof getBundledChannelMessageToolArtifactAsync>>
59+
>();
60+
const sessionKeyArtifacts = new Map<
61+
string,
62+
Awaited<ReturnType<typeof getBundledChannelSessionKeyArtifactAsync>>
63+
>();
64+
const threadBindingArtifacts = new Map<
65+
string,
66+
Awaited<ReturnType<typeof getBundledChannelThreadBindingArtifactAsync>>
67+
>();
68+
let gatewayAuthArtifact: Awaited<ReturnType<typeof getBundledChannelGatewayAuthArtifactAsync>> =
69+
null;
4370

4471
beforeAll(async () => {
4572
for (const id of bundledChannelPluginIds) {
4673
plugins.set(id, await getBundledChannelPluginAsync(id));
4774
}
75+
for (const id of MESSAGE_TOOL_ARTIFACT_PLUGIN_IDS) {
76+
messageToolArtifacts.set(id, await getBundledChannelMessageToolArtifactAsync(id));
77+
}
78+
gatewayAuthArtifact = await getBundledChannelGatewayAuthArtifactAsync("mattermost");
79+
for (const id of ["discord", ...SESSION_CONVERSATION_ARTIFACT_PLUGIN_IDS] as const) {
80+
sessionKeyArtifacts.set(id, await getBundledChannelSessionKeyArtifactAsync(id));
81+
}
82+
for (const id of THREAD_BINDING_ARTIFACT_PLUGIN_IDS) {
83+
threadBindingArtifacts.set(id, await getBundledChannelThreadBindingArtifactAsync(id));
84+
}
4885
});
4986

5087
it("discovers bundled channel plugins from the catalog", () => {
@@ -74,6 +111,80 @@ describe("bundled channel plugin shape coherence", () => {
74111
},
75112
);
76113

114+
it.each(MESSAGE_TOOL_ARTIFACT_PLUGIN_IDS)(
115+
"keeps the %s message-tool artifact identical to the loaded plugin action surface",
116+
(id) => {
117+
const artifactDescribeMessageTool = messageToolArtifacts.get(id)?.describeMessageTool;
118+
const pluginDescribeMessageTool = plugins.get(id)?.actions?.describeMessageTool;
119+
120+
expect(typeof artifactDescribeMessageTool).toBe("function");
121+
expect(typeof pluginDescribeMessageTool).toBe("function");
122+
expect(artifactDescribeMessageTool).toBe(pluginDescribeMessageTool);
123+
},
124+
);
125+
126+
it("keeps the mattermost gateway-auth artifact identical to the loaded plugin gateway surface", () => {
127+
const artifactResolveGatewayAuthBypassPaths =
128+
gatewayAuthArtifact?.resolveGatewayAuthBypassPaths;
129+
const pluginResolveGatewayAuthBypassPaths =
130+
plugins.get("mattermost")?.gateway?.resolveGatewayAuthBypassPaths;
131+
132+
expect(typeof artifactResolveGatewayAuthBypassPaths).toBe("function");
133+
expect(typeof pluginResolveGatewayAuthBypassPaths).toBe("function");
134+
expect(artifactResolveGatewayAuthBypassPaths).toBe(pluginResolveGatewayAuthBypassPaths);
135+
});
136+
137+
it.each(SESSION_CONVERSATION_ARTIFACT_PLUGIN_IDS)(
138+
"keeps the %s session-conversation artifact identical to the loaded plugin messaging hook",
139+
(id) => {
140+
const artifactResolveSessionConversation =
141+
sessionKeyArtifacts.get(id)?.resolveSessionConversation;
142+
const pluginResolveSessionConversation =
143+
plugins.get(id)?.messaging?.resolveSessionConversation;
144+
145+
expect(typeof artifactResolveSessionConversation).toBe("function");
146+
expect(typeof pluginResolveSessionConversation).toBe("function");
147+
expect(artifactResolveSessionConversation).toBe(pluginResolveSessionConversation);
148+
},
149+
);
150+
151+
it("keeps the discord session-key artifact behavior aligned with the loaded plugin adapter", () => {
152+
const normalize = sessionKeyArtifacts.get("discord")?.normalizeExplicitDiscordSessionKey as
153+
| ExplicitSessionKeyNormalizer
154+
| undefined;
155+
const pluginNormalize = plugins.get("discord")?.messaging?.normalizeExplicitSessionKey;
156+
157+
expect(typeof normalize).toBe("function");
158+
expect(typeof pluginNormalize).toBe("function");
159+
if (typeof normalize !== "function" || typeof pluginNormalize !== "function") {
160+
throw new Error("Missing discord session-key normalizer parity surface");
161+
}
162+
163+
// The plugin hook adapts core's params-object shape onto the artifact's
164+
// positional export, so pin behavioral parity over representative keys.
165+
const cases = [
166+
{ sessionKey: "discord:channel:123", ctx: { ChatType: "direct", SenderId: "123" } },
167+
{ sessionKey: "discord:dm:42", ctx: { ChatType: "dm", From: "discord:42" } },
168+
{ sessionKey: "agent:m:discord:channel:9", ctx: { ChatType: "direct", From: "discord:9" } },
169+
{ sessionKey: "Discord:Channel:77", ctx: { ChatType: "group", SenderId: "77" } },
170+
] as const;
171+
for (const { sessionKey, ctx } of cases) {
172+
expect(pluginNormalize({ sessionKey, ctx })).toBe(normalize(sessionKey, ctx));
173+
}
174+
});
175+
176+
it.each(THREAD_BINDING_ARTIFACT_PLUGIN_IDS)(
177+
"keeps the %s thread-binding artifact equal to the loaded plugin default",
178+
(id) => {
179+
const artifactPlacement = threadBindingArtifacts.get(id)?.defaultTopLevelPlacement;
180+
const pluginPlacement = plugins.get(id)?.conversationBindings?.defaultTopLevelPlacement;
181+
182+
expect(["current", "child"]).toContain(artifactPlacement);
183+
expect(["current", "child"]).toContain(pluginPlacement);
184+
expect(artifactPlacement).toBe(pluginPlacement);
185+
},
186+
);
187+
77188
describe.each(bundledChannelPluginIds)("%s", (id) => {
78189
it("keeps plugin identity aligned with the catalog id", () => {
79190
const plugin = plugins.get(id);
Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
// Session-key artifact parity contract for bundled channel plugins.
1+
// Session-key lightweight artifact contract for bundled channel plugins.
22
//
33
// Core resolves threaded session conversations from lightweight `session-key-api`
44
// artifacts before full plugin loading (src/channels/plugins/session-conversation.ts).
5-
// This suite pins each artifact export to the exact function the loaded plugin's
6-
// messaging surface uses so the fast path cannot drift from plugin behavior.
5+
// This shard owns artifact inventory and export shape; loaded-plugin identity and
6+
// adapter behavior parity live in plugin-shape.contract.test.ts.
77
//
88
// Artifact exports are intentionally non-uniform: telegram/feishu ship the
99
// `resolveSessionConversation` hook core probes, while discord ships only its
1010
// explicit session-key normalizer. Pin what each channel ships instead of
1111
// forcing one shape.
1212
import { beforeAll, describe, expect, it } from "vitest";
1313
import {
14-
getBundledChannelPluginAsync,
1514
getBundledChannelSessionKeyArtifactAsync,
1615
listBundledChannelPluginIds,
1716
} from "./test-helpers/bundled-channel-plugin-loader.js";
@@ -20,11 +19,6 @@ import {
2019
const SESSION_KEY_ARTIFACT_PLUGIN_IDS = ["discord", "feishu", "telegram"] as const;
2120
const SESSION_CONVERSATION_ARTIFACT_PLUGIN_IDS = ["feishu", "telegram"] as const;
2221

23-
type ExplicitSessionKeyNormalizer = (
24-
sessionKey: string,
25-
ctx: { ChatType?: string; From?: string; SenderId?: string },
26-
) => string;
27-
2822
describe("bundled channel session-key artifact parity", () => {
2923
const artifacts = new Map<string, Record<string, unknown>>();
3024

@@ -39,39 +33,9 @@ describe("bundled channel session-key artifact parity", () => {
3933

4034
it("keeps the artifact table in sync with bundled channels that ship one", () => {
4135
expect([...artifacts.keys()].toSorted()).toEqual([...SESSION_KEY_ARTIFACT_PLUGIN_IDS]);
42-
});
43-
44-
it.each(SESSION_CONVERSATION_ARTIFACT_PLUGIN_IDS)(
45-
"keeps the %s artifact resolver identical to the plugin messaging hook",
46-
async (id) => {
47-
const resolveSessionConversation = artifacts.get(id)?.resolveSessionConversation;
48-
expect(typeof resolveSessionConversation).toBe("function");
49-
50-
const plugin = await getBundledChannelPluginAsync(id);
51-
expect(plugin?.messaging?.resolveSessionConversation).toBe(resolveSessionConversation);
52-
},
53-
);
54-
55-
it("keeps the discord artifact normalizer behind the plugin messaging hook", async () => {
56-
const normalize = artifacts.get("discord")?.normalizeExplicitDiscordSessionKey as
57-
| ExplicitSessionKeyNormalizer
58-
| undefined;
59-
expect(typeof normalize).toBe("function");
60-
61-
const plugin = await getBundledChannelPluginAsync("discord");
62-
const pluginNormalize = plugin?.messaging?.normalizeExplicitSessionKey;
63-
expect(typeof pluginNormalize).toBe("function");
64-
65-
// The plugin hook adapts core's params-object shape onto the artifact's
66-
// positional export, so pin behavioral parity over representative keys.
67-
const cases = [
68-
{ sessionKey: "discord:channel:123", ctx: { ChatType: "direct", SenderId: "123" } },
69-
{ sessionKey: "discord:dm:42", ctx: { ChatType: "dm", From: "discord:42" } },
70-
{ sessionKey: "agent:m:discord:channel:9", ctx: { ChatType: "direct", From: "discord:9" } },
71-
{ sessionKey: "Discord:Channel:77", ctx: { ChatType: "group", SenderId: "77" } },
72-
] as const;
73-
for (const { sessionKey, ctx } of cases) {
74-
expect(pluginNormalize?.({ sessionKey, ctx })).toBe(normalize?.(sessionKey, ctx));
36+
for (const id of SESSION_CONVERSATION_ARTIFACT_PLUGIN_IDS) {
37+
expect(typeof artifacts.get(id)?.resolveSessionConversation).toBe("function");
7538
}
39+
expect(typeof artifacts.get("discord")?.normalizeExplicitDiscordSessionKey).toBe("function");
7640
});
7741
});

‎src/channels/plugins/contracts/thread-binding-artifact.contract.test.ts‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// Thread-binding artifact parity contract for bundled channel plugins.
1+
// Thread-binding lightweight artifact contract for bundled channel plugins.
22
//
33
// Core resolves default thread placement from lightweight `thread-binding-api`
44
// artifacts before full plugin loading (src/channels/plugins/thread-binding-api.ts).
5-
// This suite pins artifact exports to the runtime plugin's conversationBindings
6-
// so the fast path cannot drift from loaded-plugin behavior.
5+
// This shard owns artifact inventory and placement shape; loaded-plugin parity
6+
// lives in plugin-shape.contract.test.ts.
77
import { beforeAll, describe, expect, it } from "vitest";
88
import {
9-
getBundledChannelPluginAsync,
109
getBundledChannelThreadBindingArtifactAsync,
1110
listBundledChannelPluginIds,
1211
} from "./test-helpers/bundled-channel-plugin-loader.js";
@@ -30,16 +29,8 @@ describe("bundled channel thread-binding artifact parity", () => {
3029
expect([...artifactPlacements.keys()].toSorted()).toEqual([
3130
...THREAD_BINDING_ARTIFACT_PLUGIN_IDS,
3231
]);
32+
for (const id of THREAD_BINDING_ARTIFACT_PLUGIN_IDS) {
33+
expect(["current", "child"]).toContain(artifactPlacements.get(id));
34+
}
3335
});
34-
35-
it.each(THREAD_BINDING_ARTIFACT_PLUGIN_IDS)(
36-
"keeps the %s artifact placement equal to the runtime plugin default",
37-
async (id) => {
38-
const artifactPlacement = artifactPlacements.get(id);
39-
expect(["current", "child"]).toContain(artifactPlacement);
40-
41-
const plugin = await getBundledChannelPluginAsync(id);
42-
expect(plugin?.conversationBindings?.defaultTopLevelPlacement).toBe(artifactPlacement);
43-
},
44-
);
4536
});

0 commit comments

Comments
 (0)