// Regression tests for the lazy-loading boundaries introduced for Slack // startup-perf work (see PR #69317). Each test asserts both: // - that the lazy module is reached (call mocks fire), and // - that the inputs forwarded into the lazy module are correct, and // - that the lazy module's return value is propagated back through the // plugin surface unchanged. // // Together these guard against: // - dynamic-import path/specifier drift on cold paths, // - silent contract drift between the channel and its lazy modules, // - and accidental loss of the perf intent (re-introducing eager imports // without updating the seam).
import { beforeEach, describe, expect, it, vi } from "vitest"; import { slackPlugin } from "./channel.js"; import type { OpenClawConfig } from "./runtime-api.js"; import { setSlackRuntime } from "./runtime.js";
// --- Hoisted mocks for lazy seams ------------------------------------------------
vi.mock("openclaw/plugin-sdk/target-resolver-runtime", async (orig) => { // Preserve any sibling exports so importers that touch unrelated helpers // do not break; only override the function the channel actually calls. const original = (await orig()) as Record<string, unknown>; return {
...original,
resolveTargetsWithOptionalToken: resolveTargetsWithOptionalTokenMock,
};
});
vi.mock("openclaw/plugin-sdk/extension-shared", async (orig) => { const original = (await orig()) as Record<string, unknown>; return {
...original,
buildPassiveProbedChannelStatusSummary: buildPassiveProbedChannelStatusSummaryMock,
};
});
// --- Test setup -----------------------------------------------------------------
describe("slackPlugin.status.buildChannelSummary lazy SDK forwarding", () => {
it("calls the lazy extension-shared SDK helper with the snapshot and token sources, and returns its output unchanged", async () => { const buildChannelSummary = slackPlugin.status?.buildChannelSummary; if (!buildChannelSummary) { thrownew Error("slackPlugin.status.buildChannelSummary should be exposed");
}
const result = await buildChannelSummary({
account: { accountId: "default" } as never,
snapshot,
cfg: makeMinimalSlackConfig({ botToken: "xoxb-test" }),
runtime: undefined,
} as never);
expect(buildPassiveProbedChannelStatusSummaryMock).toHaveBeenCalledTimes(1); const [forwardedSnapshot, forwardedExtras] =
buildPassiveProbedChannelStatusSummaryMock.mock.calls[0] ?? []; // Snapshot must be forwarded by reference / structurally intact.
expect(forwardedSnapshot).toBe(snapshot); // The channel must forward the (possibly fallback'd) token sources.
expect(forwardedExtras).toEqual({ botTokenSource: "config", appTokenSource: "config"}); // The SDK return value must be propagated through unchanged.
expect(result).toBe(sentinelSummary);
});
it("falls back to 'none' for missing token sources before forwarding to the SDK helper", async () => { const buildChannelSummary = slackPlugin.status?.buildChannelSummary; if (!buildChannelSummary) { thrownew Error("slackPlugin.status.buildChannelSummary should be exposed");
}
describe("slackPlugin.status.buildCapabilitiesDiagnostics lazy scopes loader", () => {
it("invokes fetchSlackScopes once when only a bot token is present", async () => { const buildDiagnostics = slackPlugin.status?.buildCapabilitiesDiagnostics; if (!buildDiagnostics) { thrownew Error("slackPlugin.status.buildCapabilitiesDiagnostics should be exposed");
}
it("invokes fetchSlackScopes twice (bot and user) when both tokens are present", async () => { const buildDiagnostics = slackPlugin.status?.buildCapabilitiesDiagnostics; if (!buildDiagnostics) { thrownew Error("slackPlugin.status.buildCapabilitiesDiagnostics should be exposed");
}
it("does not invoke fetchSlackScopes when no bot token is present and reports a missing-token diagnostic", async () => { const buildDiagnostics = slackPlugin.status?.buildCapabilitiesDiagnostics; if (!buildDiagnostics) { thrownew Error("slackPlugin.status.buildCapabilitiesDiagnostics should be exposed");
}
describe("slackPlugin.security.collectAuditFindings lazy module forwarding", () => {
it("delegates to the lazy security-audit module with the original params and returns its output", async () => { const collectAuditFindings = slackPlugin.security?.collectAuditFindings; if (!collectAuditFindings) { thrownew Error("slackPlugin.security.collectAuditFindings should be exposed");
}
describe("slackPlugin.resolver.resolveTargets lazy SDK forwarding", () => {
it("forwards user inputs and the configured token to the lazy SDK helper and returns its output", async () => { const resolveTargets = slackPlugin.resolver?.resolveTargets; if (!resolveTargets) { thrownew Error("slackPlugin.resolver.resolveTargets should be exposed");
}
it("prefers the user token over the bot token when both are configured", async () => { const resolveTargets = slackPlugin.resolver?.resolveTargets; if (!resolveTargets) { thrownew Error("slackPlugin.resolver.resolveTargets should be exposed");
}
it("uses the same lazy SDK helper for kind='group'", async () => { const resolveTargets = slackPlugin.resolver?.resolveTargets; if (!resolveTargets) { thrownew Error("slackPlugin.resolver.resolveTargets should be exposed");
}
// Setup-wizard proxy delegation is unit-tested directly in // setup-core.lazy-proxy.test.ts so it can be type-safe against the wider // ChannelSetupWizard contract returned by createSlackSetupWizardProxy.
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet am 2026-06-05)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.