@kodelyth/feishu 2026.5.42 → 2026.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/klaw.plugin.json +1712 -47
- package/package.json +19 -6
- package/api.ts +0 -32
- package/channel-entry.ts +0 -20
- package/channel-plugin-api.ts +0 -1
- package/contract-api.ts +0 -16
- package/index.ts +0 -82
- package/runtime-api.ts +0 -52
- package/secret-contract-api.ts +0 -5
- package/security-contract-api.ts +0 -1
- package/session-key-api.ts +0 -1
- package/setup-api.ts +0 -3
- package/setup-entry.test.ts +0 -19
- package/setup-entry.ts +0 -13
- package/src/accounts.test.ts +0 -480
- package/src/accounts.ts +0 -333
- package/src/agent-config.ts +0 -21
- package/src/app-registration.ts +0 -331
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -25
- package/src/async.test.ts +0 -35
- package/src/async.ts +0 -104
- package/src/audio-preflight.runtime.ts +0 -9
- package/src/bitable.test.ts +0 -136
- package/src/bitable.ts +0 -762
- package/src/bot-content.ts +0 -485
- package/src/bot-group-name.test.ts +0 -116
- package/src/bot-runtime-api.ts +0 -12
- package/src/bot-sender-name.ts +0 -125
- package/src/bot.broadcast.test.ts +0 -523
- package/src/bot.card-action.test.ts +0 -552
- package/src/bot.checkBotMentioned.test.ts +0 -265
- package/src/bot.helpers.test.ts +0 -135
- package/src/bot.stripBotMention.test.ts +0 -126
- package/src/bot.test.ts +0 -3671
- package/src/bot.ts +0 -1703
- package/src/card-action.ts +0 -447
- package/src/card-interaction.test.ts +0 -131
- package/src/card-interaction.ts +0 -159
- package/src/card-test-helpers.ts +0 -54
- package/src/card-ux-approval.ts +0 -65
- package/src/card-ux-launcher.test.ts +0 -106
- package/src/card-ux-launcher.ts +0 -121
- package/src/card-ux-shared.ts +0 -33
- package/src/channel-runtime-api.ts +0 -16
- package/src/channel.runtime.ts +0 -47
- package/src/channel.test.ts +0 -1151
- package/src/channel.ts +0 -1423
- package/src/chat-schema.ts +0 -25
- package/src/chat.test.ts +0 -240
- package/src/chat.ts +0 -188
- package/src/client-timeout.ts +0 -42
- package/src/client.test.ts +0 -447
- package/src/client.ts +0 -262
- package/src/comment-dispatcher-runtime-api.ts +0 -6
- package/src/comment-dispatcher.test.ts +0 -185
- package/src/comment-dispatcher.ts +0 -107
- package/src/comment-handler-runtime-api.ts +0 -3
- package/src/comment-handler.test.ts +0 -592
- package/src/comment-handler.ts +0 -303
- package/src/comment-reaction.test.ts +0 -138
- package/src/comment-reaction.ts +0 -259
- package/src/comment-shared.test.ts +0 -183
- package/src/comment-shared.ts +0 -406
- package/src/comment-target.ts +0 -44
- package/src/config-schema.test.ts +0 -326
- package/src/config-schema.ts +0 -335
- package/src/conversation-id.test.ts +0 -18
- package/src/conversation-id.ts +0 -199
- package/src/dedup-runtime-api.ts +0 -1
- package/src/dedup.ts +0 -141
- package/src/dedupe-key.ts +0 -72
- package/src/directory.static.ts +0 -61
- package/src/directory.test.ts +0 -141
- package/src/directory.ts +0 -124
- package/src/doc-schema.ts +0 -182
- package/src/docx-batch-insert.test.ts +0 -116
- package/src/docx-batch-insert.ts +0 -223
- package/src/docx-color-text.ts +0 -154
- package/src/docx-table-ops.test.ts +0 -53
- package/src/docx-table-ops.ts +0 -316
- package/src/docx-types.ts +0 -38
- package/src/docx.account-selection.test.ts +0 -95
- package/src/docx.test.ts +0 -701
- package/src/docx.ts +0 -1596
- package/src/drive-schema.ts +0 -92
- package/src/drive.test.ts +0 -1237
- package/src/drive.ts +0 -829
- package/src/dynamic-agent.test.ts +0 -155
- package/src/dynamic-agent.ts +0 -143
- package/src/event-types.ts +0 -45
- package/src/external-keys.test.ts +0 -20
- package/src/external-keys.ts +0 -19
- package/src/lifecycle.test-support.ts +0 -220
- package/src/media.test.ts +0 -955
- package/src/media.ts +0 -1105
- package/src/mention-target.types.ts +0 -5
- package/src/mention.ts +0 -114
- package/src/message-action-contract.ts +0 -13
- package/src/monitor-state-runtime-api.ts +0 -7
- package/src/monitor-transport-runtime-api.ts +0 -10
- package/src/monitor.account.ts +0 -492
- package/src/monitor.acp-init-failure.lifecycle.test-support.ts +0 -219
- package/src/monitor.bot-identity.ts +0 -86
- package/src/monitor.bot-menu-handler.ts +0 -165
- package/src/monitor.bot-menu.lifecycle.test-support.ts +0 -224
- package/src/monitor.bot-menu.test.ts +0 -188
- package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +0 -264
- package/src/monitor.card-action.lifecycle.test-support.ts +0 -421
- package/src/monitor.cleanup.test.ts +0 -383
- package/src/monitor.comment-notice-handler.ts +0 -105
- package/src/monitor.comment.test.ts +0 -967
- package/src/monitor.comment.ts +0 -1386
- package/src/monitor.lifecycle.test.ts +0 -4
- package/src/monitor.message-handler.ts +0 -350
- package/src/monitor.reaction.lifecycle.test-support.ts +0 -68
- package/src/monitor.reaction.test.ts +0 -739
- package/src/monitor.startup.test.ts +0 -213
- package/src/monitor.startup.ts +0 -74
- package/src/monitor.state.defaults.test.ts +0 -46
- package/src/monitor.state.ts +0 -170
- package/src/monitor.synthetic-error.ts +0 -18
- package/src/monitor.test-mocks.ts +0 -46
- package/src/monitor.transport.ts +0 -451
- package/src/monitor.ts +0 -100
- package/src/monitor.webhook-e2e.test.ts +0 -279
- package/src/monitor.webhook-security.test.ts +0 -389
- package/src/monitor.webhook.test-helpers.ts +0 -116
- package/src/outbound-runtime-api.ts +0 -1
- package/src/outbound.test.ts +0 -1118
- package/src/outbound.ts +0 -785
- package/src/perm-schema.ts +0 -52
- package/src/perm.ts +0 -170
- package/src/pins.ts +0 -108
- package/src/policy.test.ts +0 -223
- package/src/policy.ts +0 -318
- package/src/post.test.ts +0 -105
- package/src/post.ts +0 -275
- package/src/probe.test.ts +0 -283
- package/src/probe.ts +0 -166
- package/src/processing-claims.ts +0 -59
- package/src/qr-terminal.ts +0 -1
- package/src/reactions.ts +0 -123
- package/src/reasoning-preview.test.ts +0 -113
- package/src/reasoning-preview.ts +0 -28
- package/src/reply-dispatcher-runtime-api.ts +0 -7
- package/src/reply-dispatcher.test.ts +0 -1513
- package/src/reply-dispatcher.ts +0 -748
- package/src/runtime.ts +0 -9
- package/src/secret-contract.ts +0 -145
- package/src/secret-input.ts +0 -1
- package/src/security-audit-shared.ts +0 -69
- package/src/security-audit.test.ts +0 -59
- package/src/security-audit.ts +0 -1
- package/src/send-result.ts +0 -80
- package/src/send-target.test.ts +0 -86
- package/src/send-target.ts +0 -35
- package/src/send.reply-fallback.test.ts +0 -417
- package/src/send.test.ts +0 -621
- package/src/send.ts +0 -861
- package/src/sequential-key.test.ts +0 -72
- package/src/sequential-key.ts +0 -25
- package/src/sequential-queue.test.ts +0 -165
- package/src/sequential-queue.ts +0 -86
- package/src/session-conversation.ts +0 -42
- package/src/session-route.ts +0 -48
- package/src/setup-core.ts +0 -51
- package/src/setup-surface.test.ts +0 -484
- package/src/setup-surface.ts +0 -618
- package/src/streaming-card.test.ts +0 -397
- package/src/streaming-card.ts +0 -571
- package/src/subagent-hooks.test.ts +0 -627
- package/src/subagent-hooks.ts +0 -413
- package/src/targets.ts +0 -97
- package/src/test-support/lifecycle-test-support.ts +0 -454
- package/src/thread-bindings.test.ts +0 -180
- package/src/thread-bindings.ts +0 -331
- package/src/tool-account-routing.test.ts +0 -250
- package/src/tool-account.test.ts +0 -44
- package/src/tool-account.ts +0 -93
- package/src/tool-factory-test-harness.ts +0 -79
- package/src/tool-result.test.ts +0 -32
- package/src/tool-result.ts +0 -16
- package/src/tools-config.test.ts +0 -21
- package/src/tools-config.ts +0 -22
- package/src/types.ts +0 -106
- package/src/typing.test.ts +0 -144
- package/src/typing.ts +0 -214
- package/src/wiki-schema.ts +0 -69
- package/src/wiki.ts +0 -270
- package/subagent-hooks-api.ts +0 -31
- package/tsconfig.json +0 -16
package/src/accounts.test.ts
DELETED
|
@@ -1,480 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
FeishuSecretRefUnavailableError,
|
|
4
|
-
inspectFeishuCredentials,
|
|
5
|
-
listFeishuAccountIds,
|
|
6
|
-
resolveDefaultFeishuAccountId,
|
|
7
|
-
resolveDefaultFeishuAccountSelection,
|
|
8
|
-
resolveFeishuAccount,
|
|
9
|
-
resolveFeishuCredentials,
|
|
10
|
-
resolveFeishuRuntimeAccount,
|
|
11
|
-
} from "./accounts.js";
|
|
12
|
-
import type { FeishuConfig } from "./types.js";
|
|
13
|
-
|
|
14
|
-
function makeDefaultAndRouterAccounts() {
|
|
15
|
-
return {
|
|
16
|
-
default: { appId: "cli_default", appSecret: "secret_default" }, // pragma: allowlist secret
|
|
17
|
-
"router-d": { appId: "cli_router", appSecret: "secret_router" }, // pragma: allowlist secret
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function expectExplicitDefaultAccountSelection(
|
|
22
|
-
account: ReturnType<typeof resolveFeishuAccount>,
|
|
23
|
-
appId: string,
|
|
24
|
-
) {
|
|
25
|
-
expect(account.accountId).toBe("router-d");
|
|
26
|
-
expect(account.selectionSource).toBe("explicit-default");
|
|
27
|
-
expect(account.configured).toBe(true);
|
|
28
|
-
expect(account.appId).toBe(appId);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function withEnvVar(key: string, value: string | undefined, run: () => void) {
|
|
32
|
-
const prev = process.env[key];
|
|
33
|
-
if (value === undefined) {
|
|
34
|
-
delete process.env[key];
|
|
35
|
-
} else {
|
|
36
|
-
process.env[key] = value;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
run();
|
|
40
|
-
} finally {
|
|
41
|
-
if (prev === undefined) {
|
|
42
|
-
delete process.env[key];
|
|
43
|
-
} else {
|
|
44
|
-
process.env[key] = prev;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function asConfig(config: Partial<FeishuConfig>): FeishuConfig {
|
|
50
|
-
return config as unknown as FeishuConfig;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function expectUnresolvedEnvSecretRefError(key: string) {
|
|
54
|
-
expect(() =>
|
|
55
|
-
resolveFeishuCredentials(
|
|
56
|
-
asConfig({
|
|
57
|
-
appId: "cli_123",
|
|
58
|
-
appSecret: { source: "env", provider: "default", id: key } as never,
|
|
59
|
-
}),
|
|
60
|
-
),
|
|
61
|
-
).toThrow(/unresolved SecretRef/i);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
describe("resolveDefaultFeishuAccountId", () => {
|
|
65
|
-
it("preserves top-level default account when named accounts are configured", () => {
|
|
66
|
-
const cfg = {
|
|
67
|
-
channels: {
|
|
68
|
-
feishu: {
|
|
69
|
-
appId: "cli_default",
|
|
70
|
-
appSecret: "secret_default",
|
|
71
|
-
accounts: {
|
|
72
|
-
work: { enabled: false },
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
expect(listFeishuAccountIds(cfg as never)).toEqual(["default", "work"]);
|
|
79
|
-
expect(resolveDefaultFeishuAccountId(cfg as never)).toBe("default");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("prefers channels.feishu.defaultAccount when configured", () => {
|
|
83
|
-
const cfg = {
|
|
84
|
-
channels: {
|
|
85
|
-
feishu: {
|
|
86
|
-
defaultAccount: "router-d",
|
|
87
|
-
accounts: makeDefaultAndRouterAccounts(),
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
expect(resolveDefaultFeishuAccountId(cfg as never)).toBe("router-d");
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("normalizes configured defaultAccount before lookup", () => {
|
|
96
|
-
const cfg = {
|
|
97
|
-
channels: {
|
|
98
|
-
feishu: {
|
|
99
|
-
defaultAccount: "Router D",
|
|
100
|
-
accounts: {
|
|
101
|
-
"router-d": { appId: "cli_router", appSecret: "secret_router" }, // pragma: allowlist secret
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
expect(resolveDefaultFeishuAccountId(cfg as never)).toBe("router-d");
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("keeps configured defaultAccount even when not present in accounts map", () => {
|
|
111
|
-
const cfg = {
|
|
112
|
-
channels: {
|
|
113
|
-
feishu: {
|
|
114
|
-
defaultAccount: "router-d",
|
|
115
|
-
accounts: {
|
|
116
|
-
default: { appId: "cli_default", appSecret: "secret_default" }, // pragma: allowlist secret
|
|
117
|
-
zeta: { appId: "cli_zeta", appSecret: "secret_zeta" }, // pragma: allowlist secret
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
expect(resolveDefaultFeishuAccountId(cfg as never)).toBe("router-d");
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("falls back to literal default account id when present", () => {
|
|
127
|
-
const cfg = {
|
|
128
|
-
channels: {
|
|
129
|
-
feishu: {
|
|
130
|
-
accounts: {
|
|
131
|
-
default: { appId: "cli_default", appSecret: "secret_default" }, // pragma: allowlist secret
|
|
132
|
-
zeta: { appId: "cli_zeta", appSecret: "secret_zeta" }, // pragma: allowlist secret
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
expect(resolveDefaultFeishuAccountId(cfg as never)).toBe("default");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("reports selection source for configured defaults and mapped defaults", () => {
|
|
142
|
-
const explicitDefaultCfg = {
|
|
143
|
-
channels: {
|
|
144
|
-
feishu: {
|
|
145
|
-
defaultAccount: "router-d",
|
|
146
|
-
accounts: {},
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
expect(resolveDefaultFeishuAccountSelection(explicitDefaultCfg as never)).toEqual({
|
|
151
|
-
accountId: "router-d",
|
|
152
|
-
source: "explicit-default",
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
const mappedDefaultCfg = {
|
|
156
|
-
channels: {
|
|
157
|
-
feishu: {
|
|
158
|
-
accounts: {
|
|
159
|
-
default: { appId: "cli_default", appSecret: "secret_default" }, // pragma: allowlist secret
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
expect(resolveDefaultFeishuAccountSelection(mappedDefaultCfg as never)).toEqual({
|
|
165
|
-
accountId: "default",
|
|
166
|
-
source: "mapped-default",
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
describe("resolveFeishuCredentials", () => {
|
|
172
|
-
it("throws unresolved SecretRef errors by default for unsupported secret sources", () => {
|
|
173
|
-
expect(() =>
|
|
174
|
-
resolveFeishuCredentials(
|
|
175
|
-
asConfig({
|
|
176
|
-
appId: "cli_123",
|
|
177
|
-
appSecret: { source: "file", provider: "default", id: "path/to/secret" } as never,
|
|
178
|
-
}),
|
|
179
|
-
),
|
|
180
|
-
).toThrow(/unresolved SecretRef/i);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it("returns null (without throwing) when unresolved SecretRef is allowed", () => {
|
|
184
|
-
const creds = resolveFeishuCredentials(
|
|
185
|
-
asConfig({
|
|
186
|
-
appId: "cli_123",
|
|
187
|
-
appSecret: { source: "file", provider: "default", id: "path/to/secret" } as never,
|
|
188
|
-
}),
|
|
189
|
-
{ allowUnresolvedSecretRef: true },
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
expect(creds).toBeNull();
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("supports explicit inspect mode for unresolved SecretRefs", () => {
|
|
196
|
-
const creds = resolveFeishuCredentials(
|
|
197
|
-
asConfig({
|
|
198
|
-
appId: "cli_123",
|
|
199
|
-
appSecret: { source: "file", provider: "default", id: "path/to/secret" } as never,
|
|
200
|
-
}),
|
|
201
|
-
{ mode: "inspect" },
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
expect(creds).toBeNull();
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("throws unresolved SecretRef error when env SecretRef points to missing env var", () => {
|
|
208
|
-
const key = "FEISHU_APP_SECRET_MISSING_TEST";
|
|
209
|
-
withEnvVar(key, undefined, () => {
|
|
210
|
-
expectUnresolvedEnvSecretRefError(key);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("resolves env SecretRef objects when unresolved refs are allowed", () => {
|
|
215
|
-
const key = "FEISHU_APP_SECRET_TEST";
|
|
216
|
-
const prev = process.env[key];
|
|
217
|
-
process.env[key] = " secret_from_env ";
|
|
218
|
-
|
|
219
|
-
try {
|
|
220
|
-
const creds = resolveFeishuCredentials(
|
|
221
|
-
asConfig({
|
|
222
|
-
appId: "cli_123",
|
|
223
|
-
appSecret: { source: "env", provider: "default", id: key } as never,
|
|
224
|
-
}),
|
|
225
|
-
{ allowUnresolvedSecretRef: true },
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
expect(creds).toEqual({
|
|
229
|
-
appId: "cli_123",
|
|
230
|
-
appSecret: "secret_from_env", // pragma: allowlist secret
|
|
231
|
-
encryptKey: undefined,
|
|
232
|
-
verificationToken: undefined,
|
|
233
|
-
domain: "feishu",
|
|
234
|
-
});
|
|
235
|
-
} finally {
|
|
236
|
-
if (prev === undefined) {
|
|
237
|
-
delete process.env[key];
|
|
238
|
-
} else {
|
|
239
|
-
process.env[key] = prev;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it("resolves env SecretRef with custom provider alias when unresolved refs are allowed", () => {
|
|
245
|
-
const key = "FEISHU_APP_SECRET_CUSTOM_PROVIDER_TEST";
|
|
246
|
-
const prev = process.env[key];
|
|
247
|
-
process.env[key] = " secret_from_env_alias ";
|
|
248
|
-
|
|
249
|
-
try {
|
|
250
|
-
const creds = resolveFeishuCredentials(
|
|
251
|
-
asConfig({
|
|
252
|
-
appId: "cli_123",
|
|
253
|
-
appSecret: { source: "env", provider: "corp-env", id: key } as never,
|
|
254
|
-
}),
|
|
255
|
-
{ allowUnresolvedSecretRef: true },
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
expect(creds?.appSecret).toBe("secret_from_env_alias");
|
|
259
|
-
} finally {
|
|
260
|
-
if (prev === undefined) {
|
|
261
|
-
delete process.env[key];
|
|
262
|
-
} else {
|
|
263
|
-
process.env[key] = prev;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it("preserves unresolved SecretRef diagnostics for env refs in default mode", () => {
|
|
269
|
-
const key = "FEISHU_APP_SECRET_POLICY_TEST";
|
|
270
|
-
withEnvVar(key, "secret_from_env", () => {
|
|
271
|
-
expectUnresolvedEnvSecretRefError(key);
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("trims and returns credentials when values are valid strings", () => {
|
|
276
|
-
const creds = resolveFeishuCredentials(
|
|
277
|
-
asConfig({
|
|
278
|
-
appId: " cli_123 ",
|
|
279
|
-
appSecret: " secret_456 ",
|
|
280
|
-
encryptKey: " enc ",
|
|
281
|
-
verificationToken: " vt ",
|
|
282
|
-
}),
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
expect(creds).toEqual({
|
|
286
|
-
appId: "cli_123",
|
|
287
|
-
appSecret: "secret_456", // pragma: allowlist secret
|
|
288
|
-
encryptKey: "enc",
|
|
289
|
-
verificationToken: "vt",
|
|
290
|
-
domain: "feishu",
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it("does not resolve encryptKey SecretRefs outside webhook mode", () => {
|
|
295
|
-
const creds = resolveFeishuCredentials(
|
|
296
|
-
asConfig({
|
|
297
|
-
connectionMode: "websocket",
|
|
298
|
-
appId: "cli_123",
|
|
299
|
-
appSecret: "secret_456",
|
|
300
|
-
encryptKey: { source: "file", provider: "default", id: "path/to/secret" } as never,
|
|
301
|
-
}),
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
expect(creds).toEqual({
|
|
305
|
-
appId: "cli_123",
|
|
306
|
-
appSecret: "secret_456", // pragma: allowlist secret
|
|
307
|
-
encryptKey: undefined,
|
|
308
|
-
verificationToken: undefined,
|
|
309
|
-
domain: "feishu",
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it("keeps required credentials when optional event SecretRefs are unresolved in inspect mode", () => {
|
|
314
|
-
const creds = inspectFeishuCredentials(
|
|
315
|
-
asConfig({
|
|
316
|
-
appId: "cli_123",
|
|
317
|
-
appSecret: "secret_456",
|
|
318
|
-
verificationToken: { source: "file", provider: "default", id: "path/to/token" } as never,
|
|
319
|
-
}),
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
expect(creds).toEqual({
|
|
323
|
-
appId: "cli_123",
|
|
324
|
-
appSecret: "secret_456", // pragma: allowlist secret
|
|
325
|
-
encryptKey: undefined,
|
|
326
|
-
verificationToken: undefined,
|
|
327
|
-
domain: "feishu",
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
describe("resolveFeishuAccount", () => {
|
|
333
|
-
it("uses top-level credentials with configured default account id even without account map entry", () => {
|
|
334
|
-
const cfg = {
|
|
335
|
-
channels: {
|
|
336
|
-
feishu: {
|
|
337
|
-
defaultAccount: "router-d",
|
|
338
|
-
appId: "top_level_app",
|
|
339
|
-
appSecret: "top_level_secret", // pragma: allowlist secret
|
|
340
|
-
accounts: {
|
|
341
|
-
default: { appId: "cli_default", appSecret: "secret_default" }, // pragma: allowlist secret
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
},
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
const account = resolveFeishuAccount({ cfg: cfg as never, accountId: undefined });
|
|
348
|
-
expectExplicitDefaultAccountSelection(account, "top_level_app");
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
it("uses configured default account when accountId is omitted", () => {
|
|
352
|
-
const cfg = {
|
|
353
|
-
channels: {
|
|
354
|
-
feishu: {
|
|
355
|
-
defaultAccount: "router-d",
|
|
356
|
-
accounts: {
|
|
357
|
-
default: { enabled: true },
|
|
358
|
-
"router-d": { appId: "cli_router", appSecret: "secret_router", enabled: true }, // pragma: allowlist secret
|
|
359
|
-
},
|
|
360
|
-
},
|
|
361
|
-
},
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
const account = resolveFeishuAccount({ cfg: cfg as never, accountId: undefined });
|
|
365
|
-
expectExplicitDefaultAccountSelection(account, "cli_router");
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
it("keeps explicit accountId selection", () => {
|
|
369
|
-
const cfg = {
|
|
370
|
-
channels: {
|
|
371
|
-
feishu: {
|
|
372
|
-
defaultAccount: "router-d",
|
|
373
|
-
accounts: makeDefaultAndRouterAccounts(),
|
|
374
|
-
},
|
|
375
|
-
},
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
const account = resolveFeishuAccount({ cfg: cfg as never, accountId: "default" });
|
|
379
|
-
expect(account.accountId).toBe("default");
|
|
380
|
-
expect(account.selectionSource).toBe("explicit");
|
|
381
|
-
expect(account.appId).toBe("cli_default");
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
it("treats unresolved SecretRef as not configured in account resolution", () => {
|
|
385
|
-
const account = resolveFeishuAccount({
|
|
386
|
-
cfg: {
|
|
387
|
-
channels: {
|
|
388
|
-
feishu: {
|
|
389
|
-
accounts: {
|
|
390
|
-
main: {
|
|
391
|
-
appId: "cli_123",
|
|
392
|
-
appSecret: { source: "file", provider: "default", id: "path/to/secret" },
|
|
393
|
-
} as never,
|
|
394
|
-
},
|
|
395
|
-
},
|
|
396
|
-
},
|
|
397
|
-
} as never,
|
|
398
|
-
accountId: "main",
|
|
399
|
-
});
|
|
400
|
-
expect(account.configured).toBe(false);
|
|
401
|
-
expect(account.appSecret).toBeUndefined();
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
it("keeps account configured when optional event SecretRefs are unresolved in inspect mode", () => {
|
|
405
|
-
const account = resolveFeishuAccount({
|
|
406
|
-
cfg: {
|
|
407
|
-
channels: {
|
|
408
|
-
feishu: {
|
|
409
|
-
accounts: {
|
|
410
|
-
main: {
|
|
411
|
-
appId: "cli_123",
|
|
412
|
-
appSecret: "secret_456",
|
|
413
|
-
verificationToken: {
|
|
414
|
-
source: "file",
|
|
415
|
-
provider: "default",
|
|
416
|
-
id: "path/to/token",
|
|
417
|
-
},
|
|
418
|
-
} as never,
|
|
419
|
-
},
|
|
420
|
-
},
|
|
421
|
-
},
|
|
422
|
-
} as never,
|
|
423
|
-
accountId: "main",
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
expect(account.configured).toBe(true);
|
|
427
|
-
expect(account.appSecret).toBe("secret_456");
|
|
428
|
-
expect(account.verificationToken).toBeUndefined();
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
it("throws typed SecretRef errors in runtime account resolution", () => {
|
|
432
|
-
let caught: unknown;
|
|
433
|
-
try {
|
|
434
|
-
resolveFeishuRuntimeAccount({
|
|
435
|
-
cfg: {
|
|
436
|
-
channels: {
|
|
437
|
-
feishu: {
|
|
438
|
-
accounts: {
|
|
439
|
-
main: {
|
|
440
|
-
appId: "cli_123",
|
|
441
|
-
appSecret: { source: "file", provider: "default", id: "path/to/secret" },
|
|
442
|
-
} as never,
|
|
443
|
-
},
|
|
444
|
-
},
|
|
445
|
-
},
|
|
446
|
-
} as never,
|
|
447
|
-
accountId: "main",
|
|
448
|
-
});
|
|
449
|
-
} catch (error) {
|
|
450
|
-
caught = error;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
expect(caught).toBeInstanceOf(FeishuSecretRefUnavailableError);
|
|
454
|
-
expect((caught as Error).message).toMatch(/channels\.feishu\.appSecret: unresolved SecretRef/i);
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
it("ignores non-string account names", () => {
|
|
458
|
-
const account = resolveFeishuAccount({
|
|
459
|
-
cfg: {
|
|
460
|
-
channels: {
|
|
461
|
-
feishu: {
|
|
462
|
-
accounts: {
|
|
463
|
-
main: {
|
|
464
|
-
name: { bad: true },
|
|
465
|
-
appId: "cli_123",
|
|
466
|
-
appSecret: "secret_456", // pragma: allowlist secret
|
|
467
|
-
} as never,
|
|
468
|
-
},
|
|
469
|
-
},
|
|
470
|
-
},
|
|
471
|
-
} as never,
|
|
472
|
-
accountId: "main",
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
expect(account.accountId).toBe("main");
|
|
476
|
-
expect(account.appId).toBe("cli_123");
|
|
477
|
-
expect(account.appSecret).toBe("secret_456");
|
|
478
|
-
expect(account.name).toBeUndefined();
|
|
479
|
-
});
|
|
480
|
-
});
|