Skip to content

Commit 90a545b

Browse files
authored
refactor(slack): trim internal exports (#106794)
1 parent 9b8fa12 commit 90a545b

58 files changed

Lines changed: 466 additions & 1152 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎extensions/slack/src/approval-native-gates.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const DEFAULT_APPROVAL_FORWARDING_MODE: ApprovalForwardingMode = "session";
5656
const SLACK_DM_CHANNEL_ID_RE = /^D[A-Z0-9]{8,}$/i;
5757
const SLACK_USER_ID_RE = /^[UW][A-Z0-9]{8,}$/i;
5858

59-
export function resolveSlackApprovalKind(request: SlackNativeApprovalRequest): SlackApprovalKind {
59+
function resolveSlackApprovalKind(request: SlackNativeApprovalRequest): SlackApprovalKind {
6060
const isExec = "command" in request.request;
6161
const isPlugin = "title" in request.request && "description" in request.request;
6262
if (isExec === isPlugin) {

‎extensions/slack/src/approval-native.test.ts‎

Lines changed: 37 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
66
import { upsertSessionEntry } from "openclaw/plugin-sdk/session-store-runtime";
77
import { closeOpenClawAgentDatabasesForTest } from "openclaw/plugin-sdk/sqlite-runtime-testing";
88
import { afterEach, describe, expect, it } from "vitest";
9-
import { resolveSlackApprovalKind } from "./approval-native-gates.js";
10-
import { slackApprovalCapability, testing } from "./approval-native.js";
9+
import { slackApprovalCapability } from "./approval-native.js";
1110

1211
function buildConfig(
1312
overrides?: Partial<NonNullable<NonNullable<OpenClawConfig["channels"]>["slack"]>>,
@@ -98,26 +97,6 @@ async function resolvePluginOriginTarget(sessionKey: string) {
9897
}
9998

10099
describe("slack native approval adapter", () => {
101-
it("derives approval ownership from payload shape instead of id spelling", () => {
102-
expect(
103-
resolveSlackApprovalKind({
104-
...createExecApprovalRequest(),
105-
id: "plugin:misleading-exec-id",
106-
}),
107-
).toBe("exec");
108-
expect(
109-
resolveSlackApprovalKind({
110-
id: "opaque-plugin-id",
111-
request: {
112-
title: "Plugin approval",
113-
description: "Allow access",
114-
},
115-
createdAtMs: 0,
116-
expiresAtMs: 1000,
117-
}),
118-
).toBe("plugin");
119-
});
120-
121100
it("subscribes the native runtime to exec and plugin approval events", () => {
122101
expect(slackApprovalCapability.nativeRuntime?.eventKinds).toEqual(["exec", "plugin"]);
123102
});
@@ -235,15 +214,6 @@ describe("slack native approval adapter", () => {
235214
});
236215
});
237216

238-
it("rejects origin delivery when Slack thread ids differ in the fractional timestamp", () => {
239-
expect(
240-
testing.slackTargetsMatch(
241-
{ to: "channel:C123", threadId: "1712345678.123456" },
242-
{ to: "channel:C123", threadId: "1712345678.1234567" },
243-
),
244-
).toBe(false);
245-
});
246-
247217
it("resolves approver dm targets", async () => {
248218
const targets = await slackApprovalCapability.native?.resolveApproverDmTargets?.({
249219
cfg: buildConfig(),
@@ -749,18 +719,6 @@ describe("slack native approval adapter", () => {
749719
).toBe(true);
750720
});
751721

752-
it("falls back to the session-bound origin target for plugin approvals", () => {
753-
expect(
754-
testing.resolveSessionSlackOriginTarget({
755-
to: "channel:C123",
756-
threadId: "1712345678.123456",
757-
}),
758-
).toEqual({
759-
to: "channel:C123",
760-
threadId: "1712345678.123456",
761-
});
762-
});
763-
764722
it("resolves Slack app conversation plugin approvals to the live D-channel thread", async () => {
765723
const target = await slackApprovalCapability.native?.resolveOriginTarget?.({
766724
cfg: buildConfig({ allowFrom: ["U123OWNER"] }),
@@ -788,55 +746,6 @@ describe("slack native approval adapter", () => {
788746
});
789747
});
790748

791-
it("prefers Slack app conversation D-channel turn source over user-scoped session route", () => {
792-
expect(
793-
testing.resolveTurnSourceSlackOriginTarget({
794-
id: "plugin:req-1",
795-
request: {
796-
title: "Plugin approval",
797-
description: "Allow access",
798-
sessionKey: "agent:main:slack:direct:u123owner:thread:1712345678.123456",
799-
turnSourceChannel: "slack",
800-
turnSourceTo: "D0ACP6B1T8V",
801-
turnSourceAccountId: "default",
802-
turnSourceThreadId: "1712345678.123456",
803-
},
804-
createdAtMs: 0,
805-
expiresAtMs: 1000,
806-
}),
807-
).toEqual({
808-
to: "channel:D0ACP6B1T8V",
809-
threadId: "1712345678.123456",
810-
});
811-
});
812-
813-
it("does not treat Slack D-channel and user route targets as matching across threads", () => {
814-
expect(
815-
testing.slackTargetsMatch(
816-
{ to: "channel:D0ACP6B1T8V", threadId: "1712349999.123456" },
817-
{ to: "user:U123OWNER", threadId: "1712345678.123456" },
818-
),
819-
).toBe(false);
820-
});
821-
822-
it("does not treat same-second Slack D-channel and user route targets as the same thread", () => {
823-
expect(
824-
testing.slackTargetsMatch(
825-
{ to: "channel:D0ACP6B1T8V", threadId: "1712345678.999999" },
826-
{ to: "user:U123OWNER", threadId: "1712345678.123456" },
827-
),
828-
).toBe(false);
829-
});
830-
831-
it("does not treat same-second Slack channel route targets as the same thread", () => {
832-
expect(
833-
testing.slackTargetsMatch(
834-
{ to: "channel:C123ROOM", threadId: "1712345678.999999" },
835-
{ to: "channel:C123ROOM", threadId: "1712345678.123456" },
836-
),
837-
).toBe(false);
838-
});
839-
840749
it("falls back to the session-key origin target for plugin approvals when the store is missing", async () => {
841750
const target = await resolvePluginOriginTarget(
842751
"agent:main:slack:channel:c08gqh53ejm:thread:1712345678.123456",
@@ -1094,16 +1003,44 @@ describe("slack native approval adapter", () => {
10941003
).toBe(true);
10951004
});
10961005

1097-
it("suppresses plugin forwarding fallback for the persisted native origin target", () => {
1006+
it("keeps plugin forwarding fallback when the native origin thread timestamp differs", () => {
1007+
const shouldSuppress = slackApprovalCapability.delivery?.shouldSuppressForwardingFallback;
1008+
if (!shouldSuppress) {
1009+
throw new Error("slack native delivery suppression unavailable");
1010+
}
1011+
10981012
expect(
1099-
testing.slackTargetsMatch(
1100-
{ to: "channel:CSTORED", threadId: "1712345678.123456" },
1101-
testing.resolveSessionSlackOriginTarget({
1102-
to: "channel:CSTORED",
1103-
threadId: "1712345678.123456",
1013+
shouldSuppress({
1014+
cfg: buildConfig({
1015+
allowFrom: ["U123OWNER"],
1016+
execApprovals: {
1017+
enabled: true,
1018+
approvers: ["U999EXEC"],
1019+
target: "dm",
1020+
},
11041021
}),
1105-
),
1106-
).toBe(true);
1022+
approvalKind: "plugin",
1023+
target: {
1024+
channel: "slack",
1025+
to: "channel:C123ROOM",
1026+
accountId: "default",
1027+
threadId: "1712345678.1234567",
1028+
},
1029+
request: {
1030+
id: "plugin:approval-1",
1031+
request: {
1032+
title: "Plugin approval",
1033+
description: "Allow access",
1034+
turnSourceChannel: "slack",
1035+
turnSourceTo: "channel:C123ROOM",
1036+
turnSourceAccountId: "default",
1037+
turnSourceThreadId: "1712345678.123456",
1038+
},
1039+
createdAtMs: 0,
1040+
expiresAtMs: 1_000,
1041+
},
1042+
}),
1043+
).toBe(false);
11071044
});
11081045

11091046
it("suppresses explicit plugin forwarding targets when native Slack plugin delivery is active", () => {

‎extensions/slack/src/approval-native.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,3 @@ export const slackApprovalCapability: ChannelApprovalCapability = {
225225
}
226226
: undefined,
227227
};
228-
229-
export const testing = {
230-
resolveSessionSlackOriginTarget,
231-
resolveTurnSourceSlackOriginTarget,
232-
slackTargetsMatch,
233-
};

‎extensions/slack/src/channel-migration.test.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Slack tests cover channel migration plugin behavior.
22
import { expectDefined } from "@openclaw/normalization-core";
33
import { describe, expect, it } from "vitest";
4-
import { migrateSlackChannelConfig, migrateSlackChannelsInPlace } from "./channel-migration.js";
4+
import { migrateSlackChannelConfig } from "./channel-migration.js";
55

66
function createSlackGlobalChannelConfig(channels: Record<string, Record<string, unknown>>) {
77
return {
@@ -110,15 +110,4 @@ describe("migrateSlackChannelConfig", () => {
110110
C999: { requireMention: false },
111111
});
112112
});
113-
114-
it("no-ops when old and new channel ids are the same", () => {
115-
const channels = {
116-
C123: { requireMention: true },
117-
};
118-
const result = migrateSlackChannelsInPlace(channels, "C123", "C123");
119-
expect(result).toEqual({ migrated: false, skippedExisting: false });
120-
expect(channels).toEqual({
121-
C123: { requireMention: true },
122-
});
123-
});
124113
});

‎extensions/slack/src/channel-migration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function resolveAccountChannels(
3636
return { channels: matchKey ? accounts[matchKey]?.channels : undefined };
3737
}
3838

39-
export function migrateSlackChannelsInPlace(
39+
function migrateSlackChannelsInPlace(
4040
channels: SlackChannels | undefined,
4141
oldChannelId: string,
4242
newChannelId: string,

‎extensions/slack/src/channel.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { slackPlugin } from "./channel.js";
55
import { slackOutbound } from "./outbound-adapter.js";
66
import * as probeModule from "./probe.js";
77
import type { OpenClawConfig } from "./runtime-api.js";
8-
import { clearSlackRuntime, setSlackRuntime } from "./runtime.js";
8+
import { setSlackRuntime } from "./runtime.js";
99

1010
const { handleSlackActionMock } = vi.hoisted(() => ({
1111
handleSlackActionMock: vi.fn(),
@@ -472,13 +472,13 @@ describe("slackPlugin actions", () => {
472472

473473
describe("slackPlugin status", () => {
474474
it("uses the direct Slack probe helper when runtime is not initialized", async () => {
475+
setSlackRuntime(null as never);
475476
const probeSpy = vi.spyOn(probeModule, "probeSlack").mockResolvedValueOnce({
476477
ok: true,
477478
status: 200,
478479
bot: { id: "B1", name: "openclaw-bot" },
479480
team: { id: "T1", name: "OpenClaw" },
480481
});
481-
clearSlackRuntime();
482482
const cfg = {
483483
channels: {
484484
slack: {

‎extensions/slack/src/conversation-bindings.enterprise.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { afterEach, beforeEach, describe, expect, it } from "vitest";
1515
import { slackPlugin } from "./channel.js";
1616
import type { OpenClawConfig } from "./runtime-api.js";
17-
import { clearSlackRuntime, setSlackRuntime } from "./runtime.js";
17+
import { setSlackRuntime } from "./runtime.js";
1818

1919
const CONVERSATION = {
2020
channel: "slack",
@@ -42,7 +42,7 @@ describe("Slack Enterprise Grid runtime conversation bindings", () => {
4242
afterEach(async () => {
4343
sessionBindingTesting.resetSessionBindingAdaptersForTests();
4444
closeOpenClawStateDatabaseForTest();
45-
clearSlackRuntime();
45+
setSlackRuntime(null as never);
4646
if (previousStateDir === undefined) {
4747
delete process.env.OPENCLAW_STATE_DIR;
4848
} else {

‎extensions/slack/src/data-table.test.ts‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { describe, expect, it } from "vitest";
22
import {
33
buildSlackDataTableBlock,
4-
canRenderSlackDataTable,
54
countSlackDataTableBlocksCellCharacters,
65
countSlackDataTableCellCharacters,
76
hasSlackDataTableBlock,
@@ -54,30 +53,30 @@ describe("Slack data table blocks", () => {
5453
headers: ["Value"],
5554
rows: [["ok"]],
5655
};
57-
expect(canRenderSlackDataTable(base)).toBe(true);
56+
expect(buildSlackDataTableBlock(base)).toBeDefined();
5857
expect(
59-
canRenderSlackDataTable({
58+
buildSlackDataTableBlock({
6059
...base,
6160
headers: Array.from({ length: 21 }, (_, index) => `H${String(index)}`),
6261
rows: [Array.from({ length: 21 }, () => "value")],
6362
}),
64-
).toBe(false);
63+
).toBeUndefined();
6564
expect(
66-
canRenderSlackDataTable({
65+
buildSlackDataTableBlock({
6766
...base,
6867
rows: Array.from({ length: 101 }, () => ["value"]),
6968
}),
70-
).toBe(false);
69+
).toBeUndefined();
7170
expect(
72-
canRenderSlackDataTable(base, {
71+
buildSlackDataTableBlock(base, {
7372
cellCharacterCountOffset: SLACK_DATA_TABLE_CELL_CHARACTERS_MAX - 7,
7473
}),
75-
).toBe(true);
74+
).toBeDefined();
7675
expect(
77-
canRenderSlackDataTable(base, {
76+
buildSlackDataTableBlock(base, {
7877
cellCharacterCountOffset: SLACK_DATA_TABLE_CELL_CHARACTERS_MAX - 6,
7978
}),
80-
).toBe(false);
79+
).toBeUndefined();
8180
});
8281

8382
it("counts display text across raw tables and reports malformed native tables", () => {

‎extensions/slack/src/data-table.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function resolvePortableTableCellCharacterCount(
254254
}
255255

256256
/** True when a portable table fits Slack's per-table and per-message contracts. */
257-
export function canRenderSlackDataTable(
257+
function canRenderSlackDataTable(
258258
block: MessagePresentationTableBlock,
259259
options: SlackDataTableBuildOptions = {},
260260
): boolean {

‎extensions/slack/src/delivery-trace.test.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ vi.mock("./client.js", async (importOriginal) => {
135135
};
136136
});
137137

138-
import {
139-
dispatchPreparedSlackMessage,
140-
resetSlackStreamRecipientTeamCacheForTests,
141-
} from "./monitor/message-handler/dispatch.js";
138+
import { dispatchPreparedSlackMessage } from "./monitor/message-handler/dispatch.js";
142139

143140
afterAll(() => {
144141
vi.doUnmock("./monitor/reply.runtime.js");
@@ -158,9 +155,6 @@ afterEach(async () => {
158155
traceState.turnOutcome = null;
159156
traceState.dispatchDone = null;
160157
traceState.rejectStartStreamCode = undefined;
161-
// The recipient-team cache is module-global; without a reset the users.info
162-
// lookup would only appear in the first recorded scenario.
163-
resetSlackStreamRecipientTeamCacheForTests();
164158
});
165159

166160
const CHANNEL_ID = "C0TRACE";

0 commit comments

Comments
 (0)