@vellumai/assistant 0.10.12-dev.202607242227.e52a30c → 0.10.12-dev.202607250047.75b9ec6
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/package.json
CHANGED
|
@@ -34,7 +34,7 @@ let fetchCalls: Array<{ url: string; init?: RequestInit }>;
|
|
|
34
34
|
let fetchHandler: (
|
|
35
35
|
url: string,
|
|
36
36
|
init?: RequestInit,
|
|
37
|
-
) => { ok: boolean; body: unknown };
|
|
37
|
+
) => { ok: boolean; body: unknown; scopes?: string };
|
|
38
38
|
|
|
39
39
|
beforeEach(() => {
|
|
40
40
|
mockSecureKeys = {};
|
|
@@ -45,10 +45,17 @@ beforeEach(() => {
|
|
|
45
45
|
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
46
46
|
const url = typeof input === "string" ? input : input.toString();
|
|
47
47
|
fetchCalls.push({ url, init });
|
|
48
|
-
const { ok, body } = fetchHandler(url, init);
|
|
48
|
+
const { ok, body, scopes } = fetchHandler(url, init);
|
|
49
|
+
const headers: Record<string, string> = {
|
|
50
|
+
"content-type": "application/json",
|
|
51
|
+
};
|
|
52
|
+
// Slack stamps the granted scopes on every Web API response.
|
|
53
|
+
if (scopes !== undefined) {
|
|
54
|
+
headers["x-oauth-scopes"] = scopes;
|
|
55
|
+
}
|
|
49
56
|
return new Response(JSON.stringify(body), {
|
|
50
57
|
status: ok ? 200 : 500,
|
|
51
|
-
headers
|
|
58
|
+
headers,
|
|
52
59
|
});
|
|
53
60
|
}) as typeof globalThis.fetch;
|
|
54
61
|
});
|
|
@@ -147,3 +154,144 @@ describe("slack remote probe (auth.test)", () => {
|
|
|
147
154
|
expect(authTest.message).toMatch(/ECONNREFUSED/);
|
|
148
155
|
});
|
|
149
156
|
});
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Slack can install an app with a fraction of the manifest's scopes while
|
|
160
|
+
* auth.test still succeeds — a live install produced 2 of 18, and the first
|
|
161
|
+
* real API call failed with missing_scope. auth.test passing is therefore not
|
|
162
|
+
* evidence the install is usable.
|
|
163
|
+
*/
|
|
164
|
+
describe("slack auth.test response validation", () => {
|
|
165
|
+
test("reports an unexpected shape instead of trusting the field types", async () => {
|
|
166
|
+
mockSecureKeys[credentialKey("slack_channel", "bot_token")] = "xoxb-fake";
|
|
167
|
+
// `ok` as a string slips past a cast and makes `!data.ok` decide on a
|
|
168
|
+
// truthy string rather than a boolean.
|
|
169
|
+
fetchHandler = () => ({ ok: true, body: { ok: "yes" } });
|
|
170
|
+
|
|
171
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
172
|
+
const authTest = snapshot.remoteChecks!.find(
|
|
173
|
+
(c) => c.name === "auth_test",
|
|
174
|
+
)!;
|
|
175
|
+
|
|
176
|
+
expect(authTest.passed).toBe(false);
|
|
177
|
+
expect(authTest.message).toMatch(/unexpected response shape/i);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("tolerates unknown fields Slack adds over time", async () => {
|
|
181
|
+
mockSecureKeys[credentialKey("slack_channel", "bot_token")] = "xoxb-fake";
|
|
182
|
+
fetchHandler = () => ({
|
|
183
|
+
ok: true,
|
|
184
|
+
body: { ok: true, team: "acme", user: "bot", some_new_field: 42 },
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
188
|
+
const authTest = snapshot.remoteChecks!.find(
|
|
189
|
+
(c) => c.name === "auth_test",
|
|
190
|
+
)!;
|
|
191
|
+
|
|
192
|
+
expect(authTest.passed).toBe(true);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe("slack scope-grant check", () => {
|
|
197
|
+
const ALL_REQUIRED = [
|
|
198
|
+
"app_mentions:read",
|
|
199
|
+
"assistant:write",
|
|
200
|
+
"channels:history",
|
|
201
|
+
"channels:read",
|
|
202
|
+
"chat:write",
|
|
203
|
+
"groups:history",
|
|
204
|
+
"groups:read",
|
|
205
|
+
"im:history",
|
|
206
|
+
"im:read",
|
|
207
|
+
"im:write",
|
|
208
|
+
"mpim:history",
|
|
209
|
+
"mpim:read",
|
|
210
|
+
"users:read",
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
function okWithScopes(scopes: string) {
|
|
214
|
+
return () => ({
|
|
215
|
+
ok: true,
|
|
216
|
+
body: { ok: true, team_id: "T123", team: "acme", user: "apollobot" },
|
|
217
|
+
scopes,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
test("passes when every required scope was granted", async () => {
|
|
222
|
+
mockSecureKeys[credentialKey("slack_channel", "bot_token")] = "xoxb-fake";
|
|
223
|
+
fetchHandler = okWithScopes(ALL_REQUIRED.join(","));
|
|
224
|
+
|
|
225
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
226
|
+
const scopeCheck = snapshot.remoteChecks!.find(
|
|
227
|
+
(c) => c.name === "scopes_granted",
|
|
228
|
+
)!;
|
|
229
|
+
|
|
230
|
+
expect(scopeCheck.passed).toBe(true);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("ignores declinable scopes the workspace opted out of", async () => {
|
|
234
|
+
mockSecureKeys[credentialKey("slack_channel", "bot_token")] = "xoxb-fake";
|
|
235
|
+
// No files:read / reactions:* / channels:join — all marked optional in the
|
|
236
|
+
// manifest, so declining them is a choice, not a fault.
|
|
237
|
+
fetchHandler = okWithScopes(ALL_REQUIRED.join(","));
|
|
238
|
+
|
|
239
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
240
|
+
const scopeCheck = snapshot.remoteChecks!.find(
|
|
241
|
+
(c) => c.name === "scopes_granted",
|
|
242
|
+
)!;
|
|
243
|
+
|
|
244
|
+
expect(scopeCheck.passed).toBe(true);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test("catches the silent drop that auth.test reports as healthy", async () => {
|
|
248
|
+
mockSecureKeys[credentialKey("slack_channel", "bot_token")] = "xoxb-fake";
|
|
249
|
+
// The live symptom: token came back with a couple of scopes.
|
|
250
|
+
fetchHandler = okWithScopes("channels:history,chat:write");
|
|
251
|
+
|
|
252
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
253
|
+
const authTest = snapshot.remoteChecks!.find(
|
|
254
|
+
(c) => c.name === "auth_test",
|
|
255
|
+
)!;
|
|
256
|
+
const scopeCheck = snapshot.remoteChecks!.find(
|
|
257
|
+
(c) => c.name === "scopes_granted",
|
|
258
|
+
)!;
|
|
259
|
+
|
|
260
|
+
// auth.test is happy — that is exactly why this check has to exist.
|
|
261
|
+
expect(authTest.passed).toBe(true);
|
|
262
|
+
expect(scopeCheck.passed).toBe(false);
|
|
263
|
+
expect(scopeCheck.message).toContain("assistant:write");
|
|
264
|
+
expect(scopeCheck.message).not.toContain("chat:write,");
|
|
265
|
+
// Recovery order matters: the update prompt gates the reinstall.
|
|
266
|
+
expect(scopeCheck.message).toMatch(/update prompt/i);
|
|
267
|
+
expect(scopeCheck.message).toMatch(/Reinstall to Workspace/i);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("stays passing when Slack sends no scope header", async () => {
|
|
271
|
+
mockSecureKeys[credentialKey("slack_channel", "bot_token")] = "xoxb-fake";
|
|
272
|
+
fetchHandler = () => ({
|
|
273
|
+
ok: true,
|
|
274
|
+
body: { ok: true, team_id: "T123", team: "acme", user: "apollobot" },
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
278
|
+
const scopeCheck = snapshot.remoteChecks!.find(
|
|
279
|
+
(c) => c.name === "scopes_granted",
|
|
280
|
+
)!;
|
|
281
|
+
|
|
282
|
+
expect(scopeCheck.passed).toBe(true);
|
|
283
|
+
expect(scopeCheck.message).toMatch(/skipped/i);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("tolerates whitespace in the comma-separated header", async () => {
|
|
287
|
+
mockSecureKeys[credentialKey("slack_channel", "bot_token")] = "xoxb-fake";
|
|
288
|
+
fetchHandler = okWithScopes(` ${ALL_REQUIRED.join(" , ")} ,, `);
|
|
289
|
+
|
|
290
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
291
|
+
const scopeCheck = snapshot.remoteChecks!.find(
|
|
292
|
+
(c) => c.name === "scopes_granted",
|
|
293
|
+
)!;
|
|
294
|
+
|
|
295
|
+
expect(scopeCheck.passed).toBe(true);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { describe, expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The required-scope list in `channel-readiness-service.ts` is a third copy of
|
|
7
|
+
* data owned by the Slack manifest — the web helper and the skill script hold
|
|
8
|
+
* the other two. Copies drift silently, and a stale list here would either miss
|
|
9
|
+
* a real gap or flag a scope the manifest stopped asking for, so pin it to the
|
|
10
|
+
* canonical source rather than trusting a comment to hold the line.
|
|
11
|
+
*/
|
|
12
|
+
const REPO_ROOT = join(import.meta.dir, "..", "..", "..");
|
|
13
|
+
|
|
14
|
+
const MANIFEST_SOURCE = readFileSync(
|
|
15
|
+
join(REPO_ROOT, "skills/slack-app-setup/scripts/build-manifest.ts"),
|
|
16
|
+
"utf-8",
|
|
17
|
+
);
|
|
18
|
+
const READINESS_SOURCE = readFileSync(
|
|
19
|
+
join(import.meta.dir, "..", "runtime", "channel-readiness-service.ts"),
|
|
20
|
+
"utf-8",
|
|
21
|
+
);
|
|
22
|
+
const WEB_HELPER_SOURCE = readFileSync(
|
|
23
|
+
join(REPO_ROOT, "clients/web/src/utils/slack-manifest.ts"),
|
|
24
|
+
"utf-8",
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
/** Pull the quoted strings out of the array introduced by `opener`. */
|
|
28
|
+
function scopeArrayAfter(source: string, opener: string): string[] {
|
|
29
|
+
const start = source.indexOf(opener);
|
|
30
|
+
if (start === -1) {
|
|
31
|
+
throw new Error(`Not found: ${opener}`);
|
|
32
|
+
}
|
|
33
|
+
const from = start + opener.length;
|
|
34
|
+
const end = source.indexOf("]", from);
|
|
35
|
+
if (end === -1) {
|
|
36
|
+
throw new Error(`Unterminated array after: ${opener}`);
|
|
37
|
+
}
|
|
38
|
+
return [...source.slice(from, end).matchAll(/"([^"]+)"/g)].map((m) => m[1]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const bot = scopeArrayAfter(MANIFEST_SOURCE, "bot: [");
|
|
42
|
+
const botOptional = scopeArrayAfter(MANIFEST_SOURCE, "bot_optional: [");
|
|
43
|
+
const required = scopeArrayAfter(
|
|
44
|
+
READINESS_SOURCE,
|
|
45
|
+
"const SLACK_REQUIRED_BOT_SCOPES = [",
|
|
46
|
+
);
|
|
47
|
+
const webBot = scopeArrayAfter(
|
|
48
|
+
WEB_HELPER_SOURCE,
|
|
49
|
+
"export const SLACK_MANIFEST_BOT_SCOPES = [",
|
|
50
|
+
);
|
|
51
|
+
const webBotOptional = scopeArrayAfter(
|
|
52
|
+
WEB_HELPER_SOURCE,
|
|
53
|
+
"const SLACK_MANIFEST_BOT_SCOPES_OPTIONAL = [",
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
describe("required Slack scopes stay in sync with the manifest", () => {
|
|
57
|
+
test("the manifest source parses into usable scope arrays", () => {
|
|
58
|
+
expect(bot.length).toBeGreaterThan(0);
|
|
59
|
+
expect(botOptional.length).toBeGreaterThan(0);
|
|
60
|
+
// Guards the extraction itself, and the manifest's own subset contract.
|
|
61
|
+
expect(botOptional.every((scope) => bot.includes(scope))).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("readiness requires exactly the non-declinable bot scopes", () => {
|
|
65
|
+
const expected = bot.filter((scope) => !botOptional.includes(scope)).sort();
|
|
66
|
+
|
|
67
|
+
expect([...required].sort()).toEqual(expected);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("readiness never demands a scope the workspace may decline", () => {
|
|
71
|
+
expect(required.filter((scope) => botOptional.includes(scope))).toEqual([]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// The web helper is the third copy. Both mirrors are asserted to emit
|
|
75
|
+
// identical manifest JSON elsewhere, but that check lives in the web package
|
|
76
|
+
// and cannot see this one, so pin the scope arrays here too.
|
|
77
|
+
test("the web helper requests the same bot scopes as the skill script", () => {
|
|
78
|
+
expect([...webBot].sort()).toEqual([...bot].sort());
|
|
79
|
+
expect([...webBotOptional].sort()).toEqual([...botOptional].sort());
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
normalizePublicBaseUrl,
|
|
4
4
|
resolveTwilioPublicBaseUrl,
|
|
5
5
|
} from "@vellumai/service-contracts/twilio-ingress";
|
|
6
|
+
import { z } from "zod";
|
|
6
7
|
|
|
7
8
|
import { resolveTwilioPhoneNumber } from "../calls/twilio-config.js";
|
|
8
9
|
import { hasTwilioCredentials } from "../calls/twilio-rest.js";
|
|
@@ -23,6 +24,97 @@ import type {
|
|
|
23
24
|
/** Remote check results are cached for 5 minutes before being considered stale. */
|
|
24
25
|
export const REMOTE_TTL_MS = 5 * 60 * 1000;
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Bot scopes the Slack manifest requests that the app cannot work without.
|
|
29
|
+
*
|
|
30
|
+
* Slack's install flow can return a token carrying a fraction of the manifest's
|
|
31
|
+
* scopes while `auth.test` still succeeds — a live install produced 2 of 18, and
|
|
32
|
+
* the first real API call failed with `missing_scope`. `auth.test` passing is
|
|
33
|
+
* therefore not evidence the install is usable; the granted set has to be read
|
|
34
|
+
* off the `x-oauth-scopes` response header and compared.
|
|
35
|
+
*
|
|
36
|
+
* Mirrors the non-optional half of `oauth_config.scopes.bot` in
|
|
37
|
+
* `skills/slack-app-setup/scripts/build-manifest.ts` (and its copy in
|
|
38
|
+
* `clients/web/src/utils/slack-manifest.ts`). Scopes the manifest marks
|
|
39
|
+
* declinable are deliberately absent: a workspace may refuse those at the
|
|
40
|
+
* consent screen, and flagging that choice as a fault would be noise.
|
|
41
|
+
*/
|
|
42
|
+
const SLACK_REQUIRED_BOT_SCOPES = [
|
|
43
|
+
"app_mentions:read",
|
|
44
|
+
"assistant:write",
|
|
45
|
+
"channels:history",
|
|
46
|
+
"channels:read",
|
|
47
|
+
"chat:write",
|
|
48
|
+
"groups:history",
|
|
49
|
+
"groups:read",
|
|
50
|
+
"im:history",
|
|
51
|
+
"im:read",
|
|
52
|
+
"im:write",
|
|
53
|
+
"mpim:history",
|
|
54
|
+
"mpim:read",
|
|
55
|
+
"users:read",
|
|
56
|
+
] as const;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Shape of a Slack `auth.test` response.
|
|
60
|
+
*
|
|
61
|
+
* Validated rather than cast: this crosses a runtime boundary, so a `ok` that
|
|
62
|
+
* arrives as a string would slip past a cast and make `!data.ok` decide on the
|
|
63
|
+
* wrong value. Unknown keys are ignored — Slack adds fields over time and a
|
|
64
|
+
* new one is not a reason to report the integration broken.
|
|
65
|
+
*/
|
|
66
|
+
const AuthTestResponseSchema = z.object({
|
|
67
|
+
ok: z.boolean(),
|
|
68
|
+
error: z.string().optional(),
|
|
69
|
+
team_id: z.string().optional(),
|
|
70
|
+
team: z.string().optional(),
|
|
71
|
+
user: z.string().optional(),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/** Slack returns `x-oauth-scopes` as a comma-separated list on every response. */
|
|
75
|
+
function parseGrantedScopes(raw: string | null): string[] | null {
|
|
76
|
+
if (raw === null) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const scopes = raw
|
|
80
|
+
.split(",")
|
|
81
|
+
.map((scope) => scope.trim())
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
return scopes.length > 0 ? scopes : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Compare what Slack granted against what the app needs.
|
|
88
|
+
*
|
|
89
|
+
* Passes when the header is unreadable: a check that cannot see the grant must
|
|
90
|
+
* not report a fault it has no evidence for. Reinstalling re-grants the scopes
|
|
91
|
+
* to the same token, so recovery needs no new credentials — but Slack forces an
|
|
92
|
+
* app "update" prompt first, and skipping it leaves the scopes unchanged.
|
|
93
|
+
*/
|
|
94
|
+
function scopeGrantCheck(rawHeader: string | null): ReadinessCheckResult {
|
|
95
|
+
const granted = parseGrantedScopes(rawHeader);
|
|
96
|
+
if (granted === null) {
|
|
97
|
+
return check(
|
|
98
|
+
"scopes_granted",
|
|
99
|
+
true,
|
|
100
|
+
"Slack did not report granted scopes — skipped",
|
|
101
|
+
"Slack did not report granted scopes — skipped",
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const grantedSet = new Set(granted);
|
|
106
|
+
const missing = SLACK_REQUIRED_BOT_SCOPES.filter(
|
|
107
|
+
(scope) => !grantedSet.has(scope),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return check(
|
|
111
|
+
"scopes_granted",
|
|
112
|
+
missing.length === 0,
|
|
113
|
+
`Bot token carries all ${SLACK_REQUIRED_BOT_SCOPES.length} required scopes`,
|
|
114
|
+
`Bot token is missing ${missing.length} of ${SLACK_REQUIRED_BOT_SCOPES.length} required scopes (${missing.join(", ")}) — open the app at https://api.slack.com/apps, accept the update prompt, then OAuth & Permissions → Reinstall to Workspace`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
26
118
|
function hasIngressConfigured(options: { twilio?: boolean } = {}): boolean {
|
|
27
119
|
try {
|
|
28
120
|
const raw = loadRawConfig();
|
|
@@ -298,13 +390,18 @@ const slackProbe: ChannelProbe = {
|
|
|
298
390
|
method: "POST",
|
|
299
391
|
headers: { Authorization: `Bearer ${botToken}` },
|
|
300
392
|
});
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
393
|
+
const parsed = AuthTestResponseSchema.safeParse(await res.json());
|
|
394
|
+
if (!parsed.success) {
|
|
395
|
+
return [
|
|
396
|
+
check(
|
|
397
|
+
"auth_test",
|
|
398
|
+
false,
|
|
399
|
+
"Slack auth.test ok",
|
|
400
|
+
`Slack auth.test returned an unexpected response shape: ${parsed.error.issues.map((i) => i.path.join(".") || "(root)").join(", ")}`,
|
|
401
|
+
),
|
|
402
|
+
];
|
|
403
|
+
}
|
|
404
|
+
const data = parsed.data;
|
|
308
405
|
if (!data.ok) {
|
|
309
406
|
return [
|
|
310
407
|
check(
|
|
@@ -334,6 +431,7 @@ const slackProbe: ChannelProbe = {
|
|
|
334
431
|
"Stored workspace matches bot token",
|
|
335
432
|
`Stored workspace ${storedTeamId} does not match bot token's workspace ${data.team_id ?? "unknown"} — run 'assistant channels slack reconnect' to refresh metadata`,
|
|
336
433
|
),
|
|
434
|
+
scopeGrantCheck(res.headers.get("x-oauth-scopes")),
|
|
337
435
|
];
|
|
338
436
|
} catch (err) {
|
|
339
437
|
const message = err instanceof Error ? err.message : String(err);
|