@vellumai/assistant 0.9.0-dev.202606171903.06eea08 → 0.9.0-dev.202606172240.36dfb94
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 +1 -1
- package/src/__tests__/access-request-card-view.test.ts +98 -0
- package/src/__tests__/access-request-seed-content-blocks.test.ts +2 -4
- package/src/__tests__/agent-loop-mutable-latest-user-message.test.ts +16 -13
- package/src/__tests__/injector-v3-suppression.test.ts +27 -20
- package/src/__tests__/slack-notification-approval-card.test.ts +170 -0
- package/src/__tests__/tool-approval-seed-content-blocks.test.ts +1 -1
- package/src/__tests__/workspace-migration-105-enable-memory-v3-live-for-new-workspaces.test.ts +149 -0
- package/src/agent/loop.ts +2 -2
- package/src/config/feature-flag-registry.json +17 -10
- package/src/config/memory-v3-gate.ts +11 -0
- package/src/config/schemas/__tests__/memory-v3.test.ts +1 -0
- package/src/config/schemas/memory-v3.ts +6 -0
- package/src/daemon/conversation-runtime-assembly.ts +5 -8
- package/src/memory/jobs-worker.ts +2 -1
- package/src/memory/v2/__tests__/consolidation-job.test.ts +8 -0
- package/src/memory/v2/consolidation-job.ts +2 -2
- package/src/notifications/access-request-copy.ts +72 -59
- package/src/notifications/adapters/slack.ts +38 -68
- package/src/notifications/approval-card-data.ts +297 -0
- package/src/notifications/copy-composer.ts +3 -3
- package/src/notifications/decision-engine.ts +4 -2
- package/src/plugins/defaults/memory-retrieval/hooks/user-prompt-submit.ts +2 -2
- package/src/plugins/defaults/memory-v3-shadow/__tests__/carry-integration.test.ts +1 -0
- package/src/plugins/defaults/memory-v3-shadow/__tests__/injection.test.ts +1 -0
- package/src/plugins/defaults/memory-v3-shadow/__tests__/maintain-job.test.ts +14 -7
- package/src/plugins/defaults/memory-v3-shadow/__tests__/selection-log-store.test.ts +4 -1
- package/src/plugins/defaults/memory-v3-shadow/__tests__/shadow-plugin.test.ts +1 -0
- package/src/plugins/defaults/memory-v3-shadow/injector.ts +7 -10
- package/src/plugins/defaults/memory-v3-shadow/maintain-job.ts +4 -4
- package/src/plugins/defaults/memory-v3-shadow/selection-log-store.ts +2 -2
- package/src/plugins/defaults/memory-v3-shadow/shadow-plugin.ts +0 -1
- package/src/workspace/migrations/105-enable-memory-v3-live-for-new-workspaces.ts +63 -0
- package/src/workspace/migrations/registry.ts +2 -0
- package/src/notifications/tool-approval-copy.ts +0 -142
package/package.json
CHANGED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
buildAccessRequestCardView,
|
|
5
|
+
parseAccessRequestPayload,
|
|
6
|
+
} from "../notifications/access-request-copy.js";
|
|
7
|
+
|
|
8
|
+
function view(raw: Record<string, unknown>) {
|
|
9
|
+
return buildAccessRequestCardView(parseAccessRequestPayload(raw));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const TAB = String.fromCharCode(9);
|
|
13
|
+
|
|
14
|
+
describe("buildAccessRequestCardView", () => {
|
|
15
|
+
test("prefers actorDisplayName, falls back to senderIdentifier then 'Someone'", () => {
|
|
16
|
+
expect(
|
|
17
|
+
view({ actorDisplayName: "Alice", senderIdentifier: "U999" }).displayName,
|
|
18
|
+
).toBe("Alice");
|
|
19
|
+
expect(view({ senderIdentifier: "U999" }).displayName).toBe("U999");
|
|
20
|
+
expect(view({}).displayName).toBe("Someone");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("sanitizes identity fields (strips control characters)", () => {
|
|
24
|
+
const v = view({
|
|
25
|
+
actorDisplayName: `Al${TAB}ice`,
|
|
26
|
+
actorUsername: `a${TAB}lice`,
|
|
27
|
+
actorExternalId: `U9${TAB}99`,
|
|
28
|
+
});
|
|
29
|
+
expect(v.displayName).toBe("Al ice");
|
|
30
|
+
expect(v.username).toBe("a lice");
|
|
31
|
+
expect(v.externalId).toBe("U9 99");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("username and externalId are undefined when absent", () => {
|
|
35
|
+
const v = view({ actorDisplayName: "Alice" });
|
|
36
|
+
expect(v.username).toBeUndefined();
|
|
37
|
+
expect(v.externalId).toBeUndefined();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("detects Slack DM conversations", () => {
|
|
41
|
+
expect(
|
|
42
|
+
view({ sourceChannel: "slack", conversationExternalId: "D01XYZ" })
|
|
43
|
+
.isSlackDm,
|
|
44
|
+
).toBe(true);
|
|
45
|
+
expect(
|
|
46
|
+
view({ sourceChannel: "slack", conversationExternalId: "C01ABC" })
|
|
47
|
+
.isSlackDm,
|
|
48
|
+
).toBe(false);
|
|
49
|
+
expect(
|
|
50
|
+
view({ sourceChannel: "telegram", conversationExternalId: "D01XYZ" })
|
|
51
|
+
.isSlackDm,
|
|
52
|
+
).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("builds a Slack permalink only with slack source + conversation + ts", () => {
|
|
56
|
+
expect(
|
|
57
|
+
view({
|
|
58
|
+
sourceChannel: "slack",
|
|
59
|
+
conversationExternalId: "C01ABC",
|
|
60
|
+
messageTs: "1700000000.000100",
|
|
61
|
+
}).messagePermalink,
|
|
62
|
+
).toBe("https://slack.com/archives/C01ABC/p1700000000000100");
|
|
63
|
+
expect(
|
|
64
|
+
view({ sourceChannel: "slack", conversationExternalId: "C01ABC" })
|
|
65
|
+
.messagePermalink,
|
|
66
|
+
).toBeUndefined();
|
|
67
|
+
expect(
|
|
68
|
+
view({
|
|
69
|
+
sourceChannel: "telegram",
|
|
70
|
+
conversationExternalId: "C01ABC",
|
|
71
|
+
messageTs: "1.2",
|
|
72
|
+
}).messagePermalink,
|
|
73
|
+
).toBeUndefined();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("sanitizes message preview and yields undefined when blank after sanitizing", () => {
|
|
77
|
+
expect(view({ messagePreview: " hello " }).messagePreview).toBe("hello");
|
|
78
|
+
// Blank / control-character-only previews sanitize to empty → undefined
|
|
79
|
+
// (no empty quote block is rendered downstream).
|
|
80
|
+
expect(view({ messagePreview: "" }).messagePreview).toBeUndefined();
|
|
81
|
+
expect(view({ messagePreview: " " }).messagePreview).toBeUndefined();
|
|
82
|
+
expect(view({}).messagePreview).toBeUndefined();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("collects trust/security warnings", () => {
|
|
86
|
+
const v = view({
|
|
87
|
+
isStranger: true,
|
|
88
|
+
isRestricted: true,
|
|
89
|
+
previousMemberStatus: "revoked",
|
|
90
|
+
});
|
|
91
|
+
expect(v.warnings).toEqual([
|
|
92
|
+
"This user was previously revoked.",
|
|
93
|
+
"External Slack user (not in this workspace).",
|
|
94
|
+
"Guest / restricted account.",
|
|
95
|
+
]);
|
|
96
|
+
expect(view({}).warnings).toEqual([]);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
parseAccessRequestPayload,
|
|
6
|
-
} from "../notifications/access-request-copy.js";
|
|
3
|
+
import { parseAccessRequestPayload } from "../notifications/access-request-copy.js";
|
|
4
|
+
import { buildAccessRequestSeedContentBlocks } from "../notifications/approval-card-data.js";
|
|
7
5
|
|
|
8
6
|
describe("buildAccessRequestSeedContentBlocks", () => {
|
|
9
7
|
const basePayload: Record<string, unknown> = {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Verifies that the
|
|
3
|
-
* `SendMessageOptions.config` the loop emits. When
|
|
2
|
+
* Verifies that the memory-v3-live cache-anchor signal surfaces on every
|
|
3
|
+
* `SendMessageOptions.config` the loop emits. When v3-live is on, the latest
|
|
4
4
|
* user message carries a volatile `<memory>` block, so the loop sets
|
|
5
5
|
* `providerConfig.mutableLatestUserMessage` to tell the provider to anchor its
|
|
6
6
|
* long-TTL cache breakpoint on the most recent STABLE message instead.
|
|
7
7
|
*
|
|
8
|
-
* The loop reads
|
|
9
|
-
* signal is sourced from
|
|
10
|
-
* off the field is omitted (not `false`/`undefined`) so
|
|
11
|
-
* byte-identical to today.
|
|
8
|
+
* The loop reads `config.memory.v3.live` directly where it assembles
|
|
9
|
+
* `providerConfig`, so the signal is sourced from config rather than a run
|
|
10
|
+
* option. When v3-live is off the field is omitted (not `false`/`undefined`) so
|
|
11
|
+
* the wire stays byte-identical to today.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { afterEach, describe, expect, mock, test } from "bun:test";
|
|
@@ -19,11 +19,14 @@ mock.module("../util/logger.js", () => ({
|
|
|
19
19
|
getLogger: () => makeMockLogger(),
|
|
20
20
|
}));
|
|
21
21
|
|
|
22
|
+
// AgentLoop reads the v3-live gate (`config.memory.v3.live`) via
|
|
23
|
+
// `isMemoryV3Live` to decide the cache-anchor signal; drive it per-test.
|
|
24
|
+
let memoryV3LiveSlot = false;
|
|
25
|
+
mock.module("../config/memory-v3-gate.js", () => ({
|
|
26
|
+
isMemoryV3Live: () => memoryV3LiveSlot,
|
|
27
|
+
}));
|
|
28
|
+
|
|
22
29
|
import { AgentLoop } from "../agent/loop.js";
|
|
23
|
-
import {
|
|
24
|
-
clearCachedOverrides,
|
|
25
|
-
setCachedOverrides,
|
|
26
|
-
} from "../config/feature-flag-cache.js";
|
|
27
30
|
import type {
|
|
28
31
|
Message,
|
|
29
32
|
Provider,
|
|
@@ -82,12 +85,12 @@ function makeRecordingProvider(responses: ProviderResponse[]): {
|
|
|
82
85
|
|
|
83
86
|
describe("AgentLoop.run — mutableLatestUserMessage from memory-v3-live", () => {
|
|
84
87
|
afterEach(() => {
|
|
85
|
-
|
|
88
|
+
memoryV3LiveSlot = false;
|
|
86
89
|
});
|
|
87
90
|
|
|
88
91
|
test("sets mutableLatestUserMessage on every LLM call when memory-v3-live is on (multi-turn)", async () => {
|
|
89
92
|
// GIVEN memory-v3-live is enabled
|
|
90
|
-
|
|
93
|
+
memoryV3LiveSlot = true;
|
|
91
94
|
|
|
92
95
|
// AND a provider that records the config of each LLM call across a tool round-trip
|
|
93
96
|
const { provider, configs } = makeRecordingProvider([
|
|
@@ -131,7 +134,7 @@ describe("AgentLoop.run — mutableLatestUserMessage from memory-v3-live", () =>
|
|
|
131
134
|
|
|
132
135
|
test("omits mutableLatestUserMessage when memory-v3-live is off (flag-off byte-identity)", async () => {
|
|
133
136
|
// GIVEN memory-v3-live is off (no override; registry default is false)
|
|
134
|
-
|
|
137
|
+
memoryV3LiveSlot = false;
|
|
135
138
|
|
|
136
139
|
// AND a provider that records the config of each LLM call
|
|
137
140
|
const { provider, configs } = makeRecordingProvider([textResponse("hi")]);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Tests for the memory-v3 step-0 branch in `applyRuntimeInjections`:
|
|
3
3
|
* spotlight strip + v2 tail suppression.
|
|
4
4
|
*
|
|
5
|
-
* When
|
|
5
|
+
* When `memory.v3.live` is on AND the v3 injector (id `memory-v3`,
|
|
6
6
|
* placement `after-memory-prefix`) produces a block — possibly EMPTY-TEXT on
|
|
7
7
|
* an all-repeat turn — runtime assembly strips the v2 `<memory>` prefix from
|
|
8
8
|
* the TAIL user message only before splicing the v3 block. Historical user
|
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
* block lands at the tail.
|
|
17
17
|
*
|
|
18
18
|
* v2 suppression stays keyed off whether v3 produced a block, NOT off the
|
|
19
|
-
*
|
|
20
|
-
* (fallback-to-v2). The
|
|
19
|
+
* gate alone: a v3 failure (`produce()` → null) leaves v2's block intact
|
|
20
|
+
* (fallback-to-v2). The v3-off path must be byte-for-byte identical to
|
|
21
21
|
* today — that is the load-bearing regression guard. `applyRuntimeInjections`
|
|
22
|
-
* reads the
|
|
22
|
+
* reads the v3-live gate itself, so these tests drive it through the
|
|
23
|
+
* `isMemoryV3Live` mock slot.
|
|
23
24
|
*
|
|
24
25
|
* The strip discriminates v2's dynamic block by IDENTITY, not by prefix: v2's
|
|
25
26
|
* `INJECTION_HEADER` and v3's `V3_CARDS_INJECTION_HEADER` are deliberately
|
|
@@ -42,7 +43,6 @@ import type {
|
|
|
42
43
|
TurnContext,
|
|
43
44
|
} from "../plugins/types.js";
|
|
44
45
|
import type { Message } from "../providers/types.js";
|
|
45
|
-
import { setOverridesForTesting } from "./feature-flag-test-helpers.js";
|
|
46
46
|
|
|
47
47
|
// Drive the suppression branch by controlling the static injector chain that
|
|
48
48
|
// `applyRuntimeInjections` walks. The slot is mutated per-test to stand in for
|
|
@@ -52,6 +52,13 @@ mock.module("../plugins/defaults/memory-retrieval/injector-chain.js", () => ({
|
|
|
52
52
|
getInjectorChain: () => injectorChainSlot,
|
|
53
53
|
}));
|
|
54
54
|
|
|
55
|
+
// `applyRuntimeInjections` reads the v3-live gate (`config.memory.v3.live`)
|
|
56
|
+
// via `isMemoryV3Live`; drive it directly through this slot per-test.
|
|
57
|
+
let memoryV3LiveSlot = false;
|
|
58
|
+
mock.module("../config/memory-v3-gate.js", () => ({
|
|
59
|
+
isMemoryV3Live: () => memoryV3LiveSlot,
|
|
60
|
+
}));
|
|
61
|
+
|
|
55
62
|
const { applyRuntimeInjections } =
|
|
56
63
|
await import("../daemon/conversation-runtime-assembly.js");
|
|
57
64
|
|
|
@@ -141,9 +148,9 @@ function tailTexts(messages: Message[]): string[] {
|
|
|
141
148
|
describe("memory-v3-live v2 suppression", () => {
|
|
142
149
|
beforeEach(() => {
|
|
143
150
|
injectorChainSlot.length = 0;
|
|
144
|
-
// Clean baseline:
|
|
145
|
-
//
|
|
146
|
-
|
|
151
|
+
// Clean baseline: v3-live off (registry/config default). Each test seeds
|
|
152
|
+
// the gate value it needs.
|
|
153
|
+
memoryV3LiveSlot = false;
|
|
147
154
|
});
|
|
148
155
|
|
|
149
156
|
afterEach(() => {
|
|
@@ -152,7 +159,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
152
159
|
});
|
|
153
160
|
|
|
154
161
|
test("flag ON + v3 produced a block → TAIL v2 stripped, historical memory blocks frozen in place", async () => {
|
|
155
|
-
|
|
162
|
+
memoryV3LiveSlot = true;
|
|
156
163
|
injectorChainSlot.push(v3Injector("net-new cards"));
|
|
157
164
|
seedV2Identity("fresh recalled fact");
|
|
158
165
|
|
|
@@ -194,7 +201,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
194
201
|
});
|
|
195
202
|
|
|
196
203
|
test("flag ON + EMPTY-TEXT v3 block (all-repeat turn) → tail v2 stripped, nothing attached", async () => {
|
|
197
|
-
|
|
204
|
+
memoryV3LiveSlot = true;
|
|
198
205
|
injectorChainSlot.push(v3Injector(""));
|
|
199
206
|
seedV2Identity("fresh recalled fact");
|
|
200
207
|
|
|
@@ -217,7 +224,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
217
224
|
});
|
|
218
225
|
|
|
219
226
|
test("stale spotlight blocks are stripped from EVERY user message; the new spotlight lands at the tail", async () => {
|
|
220
|
-
|
|
227
|
+
memoryV3LiveSlot = true;
|
|
221
228
|
injectorChainSlot.push(v3Injector(""), spotlightInjector("fresh sections"));
|
|
222
229
|
|
|
223
230
|
const staleSpotlight = {
|
|
@@ -253,7 +260,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
253
260
|
});
|
|
254
261
|
|
|
255
262
|
test("convergence re-entry: a tail leading with this turn's frozen v3 cards (and <info>) is NOT stripped", async () => {
|
|
256
|
-
|
|
263
|
+
memoryV3LiveSlot = true;
|
|
257
264
|
// Re-entry shape: the memo returns the same selections, every slug is now
|
|
258
265
|
// in the everInjected store, so the injector produces an EMPTY block —
|
|
259
266
|
// while the tail still carries the v3 card block frozen on first entry
|
|
@@ -292,7 +299,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
292
299
|
});
|
|
293
300
|
|
|
294
301
|
test("first entry with a v2 prefix AND a frozen v3 block strips ONLY the v2 block", async () => {
|
|
295
|
-
|
|
302
|
+
memoryV3LiveSlot = true;
|
|
296
303
|
injectorChainSlot.push(v3Injector(""));
|
|
297
304
|
seedV2Identity("fresh recalled fact");
|
|
298
305
|
|
|
@@ -319,7 +326,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
319
326
|
});
|
|
320
327
|
|
|
321
328
|
test("REGRESSION: a v2 block leading with the REAL summary header (byte-identical to v3's) is stripped; v3 cards and <info> survive (first entry)", async () => {
|
|
322
|
-
|
|
329
|
+
memoryV3LiveSlot = true;
|
|
323
330
|
injectorChainSlot.push(v3Injector(""));
|
|
324
331
|
|
|
325
332
|
// The collision this guards: v2's router block leads with
|
|
@@ -358,7 +365,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
358
365
|
});
|
|
359
366
|
|
|
360
367
|
test("REGRESSION: re-entry with a header-bearing v2 identity keeps the first entry's frozen v3 cards", async () => {
|
|
361
|
-
|
|
368
|
+
memoryV3LiveSlot = true;
|
|
362
369
|
// Re-entry: produce() returns the EMPTY block (cards already claimed by
|
|
363
370
|
// the store) while the tail carries the FIRST entry's v3 block — and the
|
|
364
371
|
// graph handle still holds the summary-bearing v2 identity from this
|
|
@@ -391,7 +398,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
391
398
|
});
|
|
392
399
|
|
|
393
400
|
test("v2 memory-image groups and legacy <memory __injected> blocks are stripped even without an identity", async () => {
|
|
394
|
-
|
|
401
|
+
memoryV3LiveSlot = true;
|
|
395
402
|
injectorChainSlot.push(v3Injector("net-new cards"));
|
|
396
403
|
// No live graph handle: identity unknown (null). Image groups and legacy
|
|
397
404
|
// blocks are unambiguously v2's and are stripped regardless; the shared
|
|
@@ -430,7 +437,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
430
437
|
});
|
|
431
438
|
|
|
432
439
|
test("the v3 block's attachment-commit callback fires on a user tail", async () => {
|
|
433
|
-
|
|
440
|
+
memoryV3LiveSlot = true;
|
|
434
441
|
const commit = mock(() => {});
|
|
435
442
|
injectorChainSlot.push(v3Injector("net-new cards", commit));
|
|
436
443
|
|
|
@@ -443,7 +450,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
443
450
|
});
|
|
444
451
|
|
|
445
452
|
test("the commit callback is SKIPPED when the tail is not a user message (block never attaches)", async () => {
|
|
446
|
-
|
|
453
|
+
memoryV3LiveSlot = true;
|
|
447
454
|
const commit = mock(() => {});
|
|
448
455
|
injectorChainSlot.push(v3Injector("net-new cards", commit));
|
|
449
456
|
|
|
@@ -465,7 +472,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
465
472
|
});
|
|
466
473
|
|
|
467
474
|
test("flag ON but v3 produced NOTHING → v2 block left intact (fallback-to-v2)", async () => {
|
|
468
|
-
|
|
475
|
+
memoryV3LiveSlot = true;
|
|
469
476
|
injectorChainSlot.push(v3Injector(null));
|
|
470
477
|
|
|
471
478
|
const runMessages: Message[] = [
|
|
@@ -524,7 +531,7 @@ describe("memory-v3-live v2 suppression", () => {
|
|
|
524
531
|
test("no v3 injector registered + flag ON → no stripping, messages untouched", async () => {
|
|
525
532
|
// No injector named memory-v3 at all (e.g. plugin not loaded): the
|
|
526
533
|
// suppression branch keys off the produced block, so nothing is stripped.
|
|
527
|
-
|
|
534
|
+
memoryV3LiveSlot = true;
|
|
528
535
|
expect(injectorChainSlot).toHaveLength(0);
|
|
529
536
|
|
|
530
537
|
const runMessages: Message[] = [
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { parseAccessRequestPayload } from "../notifications/access-request-copy.js";
|
|
4
|
+
import { buildApprovalNotificationBlocks } from "../notifications/adapters/slack.js";
|
|
5
|
+
import type { ChannelDeliveryPayload } from "../notifications/types.js";
|
|
6
|
+
import type { ApprovalUIMetadata } from "../runtime/channel-approval-types.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Pins the Slack approval-card block contract: the title, identity subtitle,
|
|
10
|
+
* quoted-preview body, action callback ids, source/permalink and requester-id
|
|
11
|
+
* context blocks, warning subtext, and guardian verification note that
|
|
12
|
+
* `buildApprovalNotificationBlocks` emits for an access request.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const APPROVAL: ApprovalUIMetadata = {
|
|
16
|
+
requestId: "req-123",
|
|
17
|
+
actions: [
|
|
18
|
+
{ id: "approve_once", label: "Approve once" },
|
|
19
|
+
{ id: "reject", label: "Reject" },
|
|
20
|
+
],
|
|
21
|
+
plainTextFallback: 'Reply "ABC123 approve" or "ABC123 reject"',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function buildPayload(
|
|
25
|
+
raw: Record<string, unknown>,
|
|
26
|
+
approval: ApprovalUIMetadata = APPROVAL,
|
|
27
|
+
): ChannelDeliveryPayload {
|
|
28
|
+
return {
|
|
29
|
+
sourceEventName: "ingress.access_request",
|
|
30
|
+
copy: { title: "Access Request", body: "Someone is requesting access" },
|
|
31
|
+
urgency: "high",
|
|
32
|
+
approvalContext: approval,
|
|
33
|
+
accessRequestContext: parseAccessRequestPayload(raw),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type Block = Record<string, unknown>;
|
|
38
|
+
|
|
39
|
+
function card(blocks: unknown[]): Block {
|
|
40
|
+
const c = (blocks as Block[]).find((b) => b.type === "card");
|
|
41
|
+
if (!c) throw new Error("no card block");
|
|
42
|
+
return c;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function contextTexts(blocks: unknown[]): string[] {
|
|
46
|
+
return (blocks as Block[])
|
|
47
|
+
.filter((b) => b.type === "context")
|
|
48
|
+
.map((b) => {
|
|
49
|
+
const elements = b.elements as Array<{ text: string }>;
|
|
50
|
+
return elements.map((e) => e.text).join("");
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function text(node: unknown): string {
|
|
55
|
+
return (node as { text: string }).text;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const BASE: Record<string, unknown> = {
|
|
59
|
+
requestId: "req-123",
|
|
60
|
+
requestCode: "ABC123",
|
|
61
|
+
sourceChannel: "slack",
|
|
62
|
+
conversationExternalId: "C01ABC",
|
|
63
|
+
actorExternalId: "U999",
|
|
64
|
+
actorDisplayName: "Alice",
|
|
65
|
+
actorUsername: "alice",
|
|
66
|
+
senderIdentifier: "U999",
|
|
67
|
+
messagePreview: "Hello, I need help with something",
|
|
68
|
+
messageTs: "1700000000.000100",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
describe("Slack access-request card blocks", () => {
|
|
72
|
+
test("card carries title, identity subtitle, and quoted preview body", () => {
|
|
73
|
+
const c = card(buildApprovalNotificationBlocks(buildPayload(BASE), "msg"));
|
|
74
|
+
expect(text(c.title)).toBe("Access Request");
|
|
75
|
+
expect(text(c.subtitle)).toBe("Alice (@alice) via slack");
|
|
76
|
+
expect(text(c.body)).toBe('> _"Hello, I need help with something"_');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("card actions encode the apr:<requestId>:<action> callback ids", () => {
|
|
80
|
+
const c = card(buildApprovalNotificationBlocks(buildPayload(BASE), "msg"));
|
|
81
|
+
const actions = c.actions as Array<Record<string, unknown>>;
|
|
82
|
+
expect(actions).toHaveLength(2);
|
|
83
|
+
expect(actions[0].action_id).toBe("apr:req-123:approve_once");
|
|
84
|
+
expect(actions[0].style).toBe("primary");
|
|
85
|
+
expect(actions[1].action_id).toBe("apr:req-123:reject");
|
|
86
|
+
expect(actions[1].style).toBe("danger");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("source context renders a channel mention with permalink", () => {
|
|
90
|
+
const texts = contextTexts(
|
|
91
|
+
buildApprovalNotificationBlocks(buildPayload(BASE), "msg"),
|
|
92
|
+
);
|
|
93
|
+
expect(texts).toContain(
|
|
94
|
+
"Source: Slack — <#C01ABC> · <https://slack.com/archives/C01ABC/p1700000000000100|View message>",
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("DM source renders as Direct message", () => {
|
|
99
|
+
const blocks = buildApprovalNotificationBlocks(
|
|
100
|
+
buildPayload({ ...BASE, conversationExternalId: "D01XYZ" }),
|
|
101
|
+
"msg",
|
|
102
|
+
);
|
|
103
|
+
expect(contextTexts(blocks)).toContain(
|
|
104
|
+
"Source: Slack — Direct message · <https://slack.com/archives/D01XYZ/p1700000000000100|View message>",
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("requester id block appears when external id adds info", () => {
|
|
109
|
+
const texts = contextTexts(
|
|
110
|
+
buildApprovalNotificationBlocks(buildPayload(BASE), "msg"),
|
|
111
|
+
);
|
|
112
|
+
expect(texts).toContain("ID: U999");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("invite directive context block is always present", () => {
|
|
116
|
+
const texts = contextTexts(
|
|
117
|
+
buildApprovalNotificationBlocks(buildPayload(BASE), "msg"),
|
|
118
|
+
);
|
|
119
|
+
expect(texts).toContain(
|
|
120
|
+
'Reply "open invite flow" to start Trusted Contacts invite flow.',
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("warnings render in the card subtext", () => {
|
|
125
|
+
const c = card(
|
|
126
|
+
buildApprovalNotificationBlocks(
|
|
127
|
+
buildPayload({
|
|
128
|
+
...BASE,
|
|
129
|
+
isStranger: true,
|
|
130
|
+
isRestricted: true,
|
|
131
|
+
previousMemberStatus: "revoked",
|
|
132
|
+
}),
|
|
133
|
+
"msg",
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
const subtext = text(c.subtext);
|
|
137
|
+
expect(subtext).toContain(":warning: This user was previously revoked.");
|
|
138
|
+
expect(subtext).toContain(
|
|
139
|
+
":warning: External Slack user (not in this workspace).",
|
|
140
|
+
);
|
|
141
|
+
expect(subtext).toContain(":warning: Guest / restricted account.");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("no subtext when there are no warnings", () => {
|
|
145
|
+
const c = card(buildApprovalNotificationBlocks(buildPayload(BASE), "msg"));
|
|
146
|
+
expect(c.subtext).toBeUndefined();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("body falls back to a default label when no preview", () => {
|
|
150
|
+
const c = card(
|
|
151
|
+
buildApprovalNotificationBlocks(
|
|
152
|
+
buildPayload({ ...BASE, messagePreview: undefined }),
|
|
153
|
+
"msg",
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
expect(text(c.body)).toBe("Requesting access to the assistant");
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("guardian verification note appears for fallback guardian resolution", () => {
|
|
160
|
+
const texts = contextTexts(
|
|
161
|
+
buildApprovalNotificationBlocks(
|
|
162
|
+
buildPayload({ ...BASE, guardianResolutionSource: "vellum-anchor" }),
|
|
163
|
+
"msg",
|
|
164
|
+
),
|
|
165
|
+
);
|
|
166
|
+
expect(
|
|
167
|
+
texts.some((t) => t.includes("haven't verified your identity on slack")),
|
|
168
|
+
).toBe(true);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
|
|
3
|
-
import { buildToolApprovalSeedContentBlocks } from "../notifications/
|
|
3
|
+
import { buildToolApprovalSeedContentBlocks } from "../notifications/approval-card-data.js";
|
|
4
4
|
|
|
5
5
|
describe("buildToolApprovalSeedContentBlocks", () => {
|
|
6
6
|
const toolApprovalPayload: Record<string, unknown> = {
|
package/src/__tests__/workspace-migration-105-enable-memory-v3-live-for-new-workspaces.test.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for workspace migration `105-enable-memory-v3-live-for-new-workspaces`.
|
|
3
|
+
*
|
|
4
|
+
* The schema default for `memory.v3.live` is false so existing assistants stay
|
|
5
|
+
* on v2. The migration persists `memory.v3.live = true` for FRESH workspaces
|
|
6
|
+
* only (switching new assistants onto memory-v3 at creation), creating
|
|
7
|
+
* `config.json` when it does not exist, leaving existing workspaces and
|
|
8
|
+
* explicit values untouched, and being idempotent.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
existsSync,
|
|
13
|
+
mkdtempSync,
|
|
14
|
+
readFileSync,
|
|
15
|
+
rmSync,
|
|
16
|
+
writeFileSync,
|
|
17
|
+
} from "node:fs";
|
|
18
|
+
import { tmpdir } from "node:os";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
21
|
+
|
|
22
|
+
import { MemoryV3ConfigSchema } from "../config/schemas/memory-v3.js";
|
|
23
|
+
import { enableMemoryV3LiveForNewWorkspacesMigration } from "../workspace/migrations/105-enable-memory-v3-live-for-new-workspaces.js";
|
|
24
|
+
import type { MigrationRunContext } from "../workspace/migrations/types.js";
|
|
25
|
+
|
|
26
|
+
const NEW_WORKSPACE_CTX: MigrationRunContext = { isNewWorkspace: true };
|
|
27
|
+
const UPGRADE_CTX: MigrationRunContext = { isNewWorkspace: false };
|
|
28
|
+
|
|
29
|
+
let workspaceDir: string;
|
|
30
|
+
let configPath: string;
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
workspaceDir = mkdtempSync(join(tmpdir(), "vellum-migration-105-test-"));
|
|
34
|
+
configPath = join(workspaceDir, "config.json");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
if (existsSync(workspaceDir)) {
|
|
39
|
+
rmSync(workspaceDir, { recursive: true, force: true });
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function readConfig(): Record<string, unknown> {
|
|
44
|
+
return JSON.parse(readFileSync(configPath, "utf-8"));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe("105-enable-memory-v3-live-for-new-workspaces migration", () => {
|
|
48
|
+
test("has correct id and description", () => {
|
|
49
|
+
expect(enableMemoryV3LiveForNewWorkspacesMigration.id).toBe(
|
|
50
|
+
"105-enable-memory-v3-live-for-new-workspaces",
|
|
51
|
+
);
|
|
52
|
+
expect(enableMemoryV3LiveForNewWorkspacesMigration.description).toContain(
|
|
53
|
+
"memory.v3.live",
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("schema default is off so existing assistants stay on v2", () => {
|
|
58
|
+
expect(MemoryV3ConfigSchema.parse({}).live).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("creates config.json with memory.v3.live=true for a fresh workspace", () => {
|
|
62
|
+
enableMemoryV3LiveForNewWorkspacesMigration.run(
|
|
63
|
+
workspaceDir,
|
|
64
|
+
NEW_WORKSPACE_CTX,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(readConfig()).toEqual({ memory: { v3: { live: true } } });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("adds memory.v3.live to a fresh workspace's existing config, preserving siblings", () => {
|
|
71
|
+
writeFileSync(
|
|
72
|
+
configPath,
|
|
73
|
+
JSON.stringify({ name: "Assistant", memory: { enabled: true } }),
|
|
74
|
+
"utf-8",
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
enableMemoryV3LiveForNewWorkspacesMigration.run(
|
|
78
|
+
workspaceDir,
|
|
79
|
+
NEW_WORKSPACE_CTX,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(readConfig()).toEqual({
|
|
83
|
+
name: "Assistant",
|
|
84
|
+
memory: { enabled: true, v3: { live: true } },
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("skips existing workspaces so they stay on v2 (no config written)", () => {
|
|
89
|
+
enableMemoryV3LiveForNewWorkspacesMigration.run(workspaceDir, UPGRADE_CTX);
|
|
90
|
+
|
|
91
|
+
expect(existsSync(configPath)).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("treats a missing context as an existing workspace", () => {
|
|
95
|
+
enableMemoryV3LiveForNewWorkspacesMigration.run(workspaceDir);
|
|
96
|
+
|
|
97
|
+
expect(existsSync(configPath)).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("leaves an explicit memory.v3.live value untouched on a fresh workspace", () => {
|
|
101
|
+
const original = JSON.stringify({ memory: { v3: { live: false } } });
|
|
102
|
+
writeFileSync(configPath, original, "utf-8");
|
|
103
|
+
|
|
104
|
+
enableMemoryV3LiveForNewWorkspacesMigration.run(
|
|
105
|
+
workspaceDir,
|
|
106
|
+
NEW_WORKSPACE_CTX,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
expect(readFileSync(configPath, "utf-8")).toBe(original);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("leaves malformed config.json untouched", () => {
|
|
113
|
+
writeFileSync(configPath, "{ not json", "utf-8");
|
|
114
|
+
|
|
115
|
+
enableMemoryV3LiveForNewWorkspacesMigration.run(
|
|
116
|
+
workspaceDir,
|
|
117
|
+
NEW_WORKSPACE_CTX,
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
expect(readFileSync(configPath, "utf-8")).toBe("{ not json");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("is idempotent", () => {
|
|
124
|
+
enableMemoryV3LiveForNewWorkspacesMigration.run(
|
|
125
|
+
workspaceDir,
|
|
126
|
+
NEW_WORKSPACE_CTX,
|
|
127
|
+
);
|
|
128
|
+
const afterFirst = readFileSync(configPath, "utf-8");
|
|
129
|
+
|
|
130
|
+
enableMemoryV3LiveForNewWorkspacesMigration.run(
|
|
131
|
+
workspaceDir,
|
|
132
|
+
NEW_WORKSPACE_CTX,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
expect(readFileSync(configPath, "utf-8")).toBe(afterFirst);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("down is a no-op", () => {
|
|
139
|
+
enableMemoryV3LiveForNewWorkspacesMigration.run(
|
|
140
|
+
workspaceDir,
|
|
141
|
+
NEW_WORKSPACE_CTX,
|
|
142
|
+
);
|
|
143
|
+
const before = readFileSync(configPath, "utf-8");
|
|
144
|
+
|
|
145
|
+
enableMemoryV3LiveForNewWorkspacesMigration.down(workspaceDir);
|
|
146
|
+
|
|
147
|
+
expect(readFileSync(configPath, "utf-8")).toBe(before);
|
|
148
|
+
});
|
|
149
|
+
});
|