@vellumai/assistant 0.10.2-dev.202606241938.e233a07 → 0.10.2-dev.202606242023.5e459ba
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/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +44 -0
- package/package.json +1 -1
- package/src/__tests__/inbound-invite-redemption.test.ts +28 -0
- package/src/__tests__/invite-redemption-service.test.ts +155 -0
- package/src/__tests__/mtime-cache.test.ts +1 -130
- package/src/__tests__/voice-invite-redemption.test.ts +33 -0
- package/src/cli/commands/plugins.ts +18 -24
- package/src/contacts/__tests__/contacts-write-revoke-relay.test.ts +129 -0
- package/src/contacts/__tests__/member-write-relay.test.ts +202 -0
- package/src/contacts/member-write-relay.ts +189 -0
- package/src/daemon/__tests__/conversation-tool-setup-exclude.test.ts +0 -35
- package/src/daemon/conversation-tool-setup.ts +8 -25
- package/src/plugins/mtime-cache.ts +52 -126
- package/src/runtime/invite-redemption-service.ts +148 -169
- package/src/tools/registry.ts +0 -13
|
@@ -137,6 +137,50 @@ export type MarkChannelVerifiedIpcResponse = z.infer<
|
|
|
137
137
|
typeof MarkChannelVerifiedIpcResponseSchema
|
|
138
138
|
>;
|
|
139
139
|
|
|
140
|
+
export const UpsertVerifiedChannelIpcParamsSchema = z.object({
|
|
141
|
+
type: z.string().min(1),
|
|
142
|
+
address: z.string().min(1),
|
|
143
|
+
externalChatId: z.string().min(1),
|
|
144
|
+
displayName: z.string().optional(),
|
|
145
|
+
username: z.string().optional(),
|
|
146
|
+
// Audit source for the verification. Free text (DB column is text) so the
|
|
147
|
+
// invite-activation path can pass "invite"; do not narrow to an enum.
|
|
148
|
+
verifiedVia: z.string().optional(),
|
|
149
|
+
// Target contact to bind the channel to (invite redemption). When set, an
|
|
150
|
+
// existing channel for the same (type,address) under a different contact is
|
|
151
|
+
// reassigned to this contact, mirroring the assistant's
|
|
152
|
+
// reassignConflictingChannels.
|
|
153
|
+
contactId: z.string().min(1).optional(),
|
|
154
|
+
// Relax the revoked refusal guard so a valid invite can reactivate a revoked
|
|
155
|
+
// member. Blocked actors are refused regardless.
|
|
156
|
+
allowRevokedReactivation: z.boolean().optional(),
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
export type UpsertVerifiedChannelIpcParams = z.infer<
|
|
160
|
+
typeof UpsertVerifiedChannelIpcParamsSchema
|
|
161
|
+
>;
|
|
162
|
+
|
|
163
|
+
export const UpsertVerifiedChannelIpcResponseSchema = z.object({
|
|
164
|
+
ok: z.boolean(),
|
|
165
|
+
verified: z.boolean(),
|
|
166
|
+
// Present only when verified — a blocked/revoked skip omits the channel.
|
|
167
|
+
channel: z
|
|
168
|
+
.object({
|
|
169
|
+
id: z.string(),
|
|
170
|
+
contactId: z.string(),
|
|
171
|
+
type: z.string(),
|
|
172
|
+
address: z.string(),
|
|
173
|
+
status: z.string(),
|
|
174
|
+
verifiedAt: z.number().nullable(),
|
|
175
|
+
verifiedVia: z.string().nullable(),
|
|
176
|
+
})
|
|
177
|
+
.optional(),
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
export type UpsertVerifiedChannelIpcResponse = z.infer<
|
|
181
|
+
typeof UpsertVerifiedChannelIpcResponseSchema
|
|
182
|
+
>;
|
|
183
|
+
|
|
140
184
|
export const MarkChannelRevokedIpcParamsSchema = z.object({
|
|
141
185
|
contactChannelId: z.string().min(1),
|
|
142
186
|
// Audit reason for the downgrade. The verification-revoke flow passes
|
package/package.json
CHANGED
|
@@ -64,6 +64,28 @@ mock.module("../runtime/approval-message-composer.js", () => ({
|
|
|
64
64
|
composeApprovalMessageGenerative: async () => "mock generative message",
|
|
65
65
|
}));
|
|
66
66
|
|
|
67
|
+
// Stub the gateway IPC so redemption claims + activation relays resolve
|
|
68
|
+
// deterministically without a running gateway socket.
|
|
69
|
+
const gatewayIpcCalls: Array<{
|
|
70
|
+
method: string;
|
|
71
|
+
params?: Record<string, unknown>;
|
|
72
|
+
}> = [];
|
|
73
|
+
mock.module("../ipc/gateway-client.js", () => ({
|
|
74
|
+
ipcCallPersistent: async (
|
|
75
|
+
method: string,
|
|
76
|
+
params?: Record<string, unknown>,
|
|
77
|
+
) => {
|
|
78
|
+
gatewayIpcCalls.push({ method, params });
|
|
79
|
+
if (method === "record_invite_redemption") {
|
|
80
|
+
return { ok: true, updated: true, mirrored: true };
|
|
81
|
+
}
|
|
82
|
+
if (method === "upsert_verified_channel") {
|
|
83
|
+
return { ok: true, verified: true };
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
},
|
|
87
|
+
}));
|
|
88
|
+
|
|
67
89
|
import {
|
|
68
90
|
findContactChannel,
|
|
69
91
|
upsertContact,
|
|
@@ -98,6 +120,7 @@ function resetState(): void {
|
|
|
98
120
|
db.run("DELETE FROM contacts");
|
|
99
121
|
emitSignalCalls.length = 0;
|
|
100
122
|
deliverReplyCalls.length = 0;
|
|
123
|
+
gatewayIpcCalls.length = 0;
|
|
101
124
|
msgCounter = 0;
|
|
102
125
|
}
|
|
103
126
|
|
|
@@ -177,6 +200,11 @@ describe("inbound invite redemption intercept", () => {
|
|
|
177
200
|
expect(result).not.toBeNull();
|
|
178
201
|
expect(result!.channel.status).toBe("active");
|
|
179
202
|
|
|
203
|
+
// The activation is written to the gateway via upsert_verified_channel.
|
|
204
|
+
expect(
|
|
205
|
+
gatewayIpcCalls.some((c) => c.method === "upsert_verified_channel"),
|
|
206
|
+
).toBe(true);
|
|
207
|
+
|
|
180
208
|
// Verify a welcome reply was delivered
|
|
181
209
|
expect(deliverReplyCalls.length).toBe(1);
|
|
182
210
|
const replyText = (deliverReplyCalls[0].payload as Record<string, unknown>)
|
|
@@ -7,6 +7,26 @@ mock.module("../util/logger.js", () => ({
|
|
|
7
7
|
}),
|
|
8
8
|
}));
|
|
9
9
|
|
|
10
|
+
// Wrap the real contacts-write so a test can force the best-effort local mirror
|
|
11
|
+
// to fail (simulating a gateway-verified activation whose local DB row failed),
|
|
12
|
+
// while normal setup keeps the real implementation. Capture the concrete real
|
|
13
|
+
// function BEFORE registering the mock so the wrapper never recurses into
|
|
14
|
+
// itself via the (now live) module namespace.
|
|
15
|
+
const contactsWriteState = { mirrorThrows: false };
|
|
16
|
+
const realContactsWrite = await import("../contacts/contacts-write.js");
|
|
17
|
+
const realUpsertContactChannel = realContactsWrite.upsertContactChannel;
|
|
18
|
+
mock.module("../contacts/contacts-write.js", () => ({
|
|
19
|
+
...realContactsWrite,
|
|
20
|
+
upsertContactChannel: (
|
|
21
|
+
params: Parameters<typeof realUpsertContactChannel>[0],
|
|
22
|
+
) => {
|
|
23
|
+
if (contactsWriteState.mirrorThrows) {
|
|
24
|
+
throw new Error("local mirror exploded");
|
|
25
|
+
}
|
|
26
|
+
return realUpsertContactChannel(params);
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
|
|
10
30
|
// Mock the gateway IPC bridge used by the redemption service for the
|
|
11
31
|
// authoritative pre-mutation claim (record_invite_redemption). Tests drive the
|
|
12
32
|
// claim result via `gatewayIpc`.
|
|
@@ -17,6 +37,12 @@ const gatewayIpc = {
|
|
|
17
37
|
mirrored: boolean;
|
|
18
38
|
},
|
|
19
39
|
claimThrows: false,
|
|
40
|
+
// Drives the upsert_verified_channel relay verdict. When false the gateway
|
|
41
|
+
// refuses the actor (blocked/revoked) and the activation is refused.
|
|
42
|
+
activationVerified: true,
|
|
43
|
+
// Gateway channel returned on a verified activation, surfaced as the memberId
|
|
44
|
+
// when the local mirror produces no row.
|
|
45
|
+
activationChannelId: "gw-channel-id" as string | undefined,
|
|
20
46
|
calls: [] as { method: string; params?: Record<string, unknown> }[],
|
|
21
47
|
};
|
|
22
48
|
|
|
@@ -28,16 +54,45 @@ mock.module("../ipc/gateway-client.js", () => ({
|
|
|
28
54
|
gatewayIpc.calls.push({ method, params });
|
|
29
55
|
if (method === "record_invite_redemption") {
|
|
30
56
|
if (gatewayIpc.claimThrows) throw new Error("gateway unreachable");
|
|
57
|
+
onGatewayClaim?.();
|
|
31
58
|
return gatewayIpc.claim;
|
|
32
59
|
}
|
|
60
|
+
if (method === "upsert_verified_channel") {
|
|
61
|
+
if (!gatewayIpc.activationVerified) {
|
|
62
|
+
return { ok: true, verified: false };
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
ok: true,
|
|
66
|
+
verified: true,
|
|
67
|
+
channel: gatewayIpc.activationChannelId
|
|
68
|
+
? {
|
|
69
|
+
id: gatewayIpc.activationChannelId,
|
|
70
|
+
contactId: (params?.contactId as string) ?? "gw-contact",
|
|
71
|
+
type: (params?.type as string) ?? "telegram",
|
|
72
|
+
address: (params?.address as string) ?? "gw-addr",
|
|
73
|
+
status: "active",
|
|
74
|
+
verifiedAt: 1,
|
|
75
|
+
verifiedVia: (params?.verifiedVia as string) ?? "invite",
|
|
76
|
+
}
|
|
77
|
+
: undefined,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
33
80
|
return undefined;
|
|
34
81
|
},
|
|
35
82
|
}));
|
|
36
83
|
|
|
84
|
+
// Lets a test inject a side-effect into the gateway claim — runs after the
|
|
85
|
+
// service's pre-validation but before the assistant use-bump, so it can race a
|
|
86
|
+
// revoke into the window that makes `recordInviteUse` return false.
|
|
87
|
+
let onGatewayClaim: (() => void) | null = null;
|
|
88
|
+
|
|
37
89
|
function resetGatewayIpc() {
|
|
38
90
|
gatewayIpc.claim = { ok: true, updated: true, mirrored: true };
|
|
39
91
|
gatewayIpc.claimThrows = false;
|
|
92
|
+
gatewayIpc.activationVerified = true;
|
|
93
|
+
gatewayIpc.activationChannelId = "gw-channel-id";
|
|
40
94
|
gatewayIpc.calls = [];
|
|
95
|
+
onGatewayClaim = null;
|
|
41
96
|
}
|
|
42
97
|
|
|
43
98
|
import type { TrustVerdict } from "@vellumai/gateway-client";
|
|
@@ -79,6 +134,7 @@ describe("invite-redemption-service", () => {
|
|
|
79
134
|
beforeEach(() => {
|
|
80
135
|
resetTables();
|
|
81
136
|
resetGatewayIpc();
|
|
137
|
+
contactsWriteState.mirrorThrows = false;
|
|
82
138
|
});
|
|
83
139
|
|
|
84
140
|
test("redeems a valid invite and returns typed outcome", async () => {
|
|
@@ -102,6 +158,11 @@ describe("invite-redemption-service", () => {
|
|
|
102
158
|
memberId: expect.any(String),
|
|
103
159
|
inviteId: invite.id,
|
|
104
160
|
});
|
|
161
|
+
|
|
162
|
+
// The activation is written to the gateway via upsert_verified_channel.
|
|
163
|
+
expect(
|
|
164
|
+
gatewayIpc.calls.some((c) => c.method === "upsert_verified_channel"),
|
|
165
|
+
).toBe(true);
|
|
105
166
|
});
|
|
106
167
|
|
|
107
168
|
test("marks channel as verified via invite on redemption", async () => {
|
|
@@ -360,6 +421,18 @@ describe("invite-redemption-service", () => {
|
|
|
360
421
|
expect(outcome.ok).toBe(true);
|
|
361
422
|
expect((outcome as { type: string }).type).toBe("redeemed");
|
|
362
423
|
|
|
424
|
+
// Gateway-first: the activation relays the target contactId so the gateway
|
|
425
|
+
// binds the channel to Mom (not the guardian) — the binding is not lost.
|
|
426
|
+
const upsert = gatewayIpc.calls.find(
|
|
427
|
+
(c) => c.method === "upsert_verified_channel",
|
|
428
|
+
);
|
|
429
|
+
expect(upsert).toBeDefined();
|
|
430
|
+
expect(upsert!.params).toMatchObject({
|
|
431
|
+
type: "telegram",
|
|
432
|
+
address: "guardian-tg-id",
|
|
433
|
+
contactId: momContact.id,
|
|
434
|
+
});
|
|
435
|
+
|
|
363
436
|
// Verify the redeemer's Telegram ID is now bound to Mom's contact
|
|
364
437
|
const result = findContactChannel({
|
|
365
438
|
channelType: "telegram",
|
|
@@ -631,6 +704,39 @@ describe("invite-redemption-service", () => {
|
|
|
631
704
|
).toBeNull();
|
|
632
705
|
});
|
|
633
706
|
|
|
707
|
+
test("does not activate the member when recordInviteUse loses the race (returns false)", async () => {
|
|
708
|
+
const targetContactId = createTargetContact();
|
|
709
|
+
const { rawToken, invite } = createInvite({
|
|
710
|
+
sourceChannel: "telegram",
|
|
711
|
+
contactId: targetContactId,
|
|
712
|
+
maxUses: 1,
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
// Legacy gateway row so the claim proceeds past the gateway gate. Revoke
|
|
716
|
+
// the assistant invite during the claim — after pre-validation, before the
|
|
717
|
+
// use-bump — so `recordInviteUse` sees a non-active row and returns false.
|
|
718
|
+
gatewayIpc.claim = { ok: true, updated: false, mirrored: false };
|
|
719
|
+
onGatewayClaim = () => {
|
|
720
|
+
revokeStoreFn(invite.id);
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
const outcome = await redeemInvite({
|
|
724
|
+
rawToken,
|
|
725
|
+
sourceChannel: "telegram",
|
|
726
|
+
externalUserId: "raced-user",
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
expect(outcome).toEqual({ ok: false, reason: "invalid_token" });
|
|
730
|
+
|
|
731
|
+
// The member was NOT activated: no gateway upsert and no active channel.
|
|
732
|
+
expect(
|
|
733
|
+
gatewayIpc.calls.some((c) => c.method === "upsert_verified_channel"),
|
|
734
|
+
).toBe(false);
|
|
735
|
+
expect(
|
|
736
|
+
findContactChannel({ channelType: "telegram", address: "raced-user" }),
|
|
737
|
+
).toBeNull();
|
|
738
|
+
});
|
|
739
|
+
|
|
634
740
|
test("proceeds and mutates when the gateway claim is consumed (updated:true)", async () => {
|
|
635
741
|
const targetContactId = createTargetContact();
|
|
636
742
|
const { rawToken, invite } = createInvite({
|
|
@@ -765,6 +871,55 @@ describe("invite-redemption-service", () => {
|
|
|
765
871
|
}),
|
|
766
872
|
).toBeNull();
|
|
767
873
|
});
|
|
874
|
+
|
|
875
|
+
test("returns invalid_token (no throw) when the gateway refuses the activation", async () => {
|
|
876
|
+
const targetContactId = createTargetContact();
|
|
877
|
+
const { rawToken } = createInvite({
|
|
878
|
+
sourceChannel: "telegram",
|
|
879
|
+
contactId: targetContactId,
|
|
880
|
+
maxUses: 1,
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
// Gateway claim consumes the row, then refuses the channel activation
|
|
884
|
+
// (blocked/revoked actor). The committed use is acceptable for this rare
|
|
885
|
+
// blocked-backstop path; the outcome must be the branch failure, not a 500.
|
|
886
|
+
gatewayIpc.activationVerified = false;
|
|
887
|
+
|
|
888
|
+
const outcome = await redeemInvite({
|
|
889
|
+
rawToken,
|
|
890
|
+
sourceChannel: "telegram",
|
|
891
|
+
externalUserId: "refused-user",
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
expect(outcome).toEqual({ ok: false, reason: "invalid_token" });
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
test("redeems with the gateway channel id when the gateway verifies but the local mirror fails", async () => {
|
|
898
|
+
const targetContactId = createTargetContact();
|
|
899
|
+
const { rawToken, invite } = createInvite({
|
|
900
|
+
sourceChannel: "telegram",
|
|
901
|
+
contactId: targetContactId,
|
|
902
|
+
maxUses: 1,
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
// Gateway verifies and returns its channel; the best-effort local mirror
|
|
906
|
+
// throws. The activation must still stand using the gateway channel id.
|
|
907
|
+
gatewayIpc.activationChannelId = "gw-verified-channel";
|
|
908
|
+
contactsWriteState.mirrorThrows = true;
|
|
909
|
+
|
|
910
|
+
const outcome = await redeemInvite({
|
|
911
|
+
rawToken,
|
|
912
|
+
sourceChannel: "telegram",
|
|
913
|
+
externalUserId: "mirrorless-user",
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
expect(outcome).toEqual({
|
|
917
|
+
ok: true,
|
|
918
|
+
type: "redeemed",
|
|
919
|
+
memberId: "gw-verified-channel",
|
|
920
|
+
inviteId: invite.id,
|
|
921
|
+
});
|
|
922
|
+
});
|
|
768
923
|
});
|
|
769
924
|
|
|
770
925
|
describe("resolveMemberGateStatus", () => {
|
|
@@ -7,14 +7,7 @@
|
|
|
7
7
|
* cache miss (changed mtime → re-import), plugin deletion (eviction),
|
|
8
8
|
* and hook collection across multiple plugins.
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
11
|
-
existsSync,
|
|
12
|
-
mkdirSync,
|
|
13
|
-
readFileSync,
|
|
14
|
-
rmSync,
|
|
15
|
-
utimesSync,
|
|
16
|
-
writeFileSync,
|
|
17
|
-
} from "node:fs";
|
|
10
|
+
import { mkdirSync, rmSync, utimesSync, writeFileSync } from "node:fs";
|
|
18
11
|
import { tmpdir } from "node:os";
|
|
19
12
|
import { join } from "node:path";
|
|
20
13
|
import {
|
|
@@ -34,11 +27,6 @@ import {
|
|
|
34
27
|
populateCacheAtBoot,
|
|
35
28
|
resetPluginCacheForTests,
|
|
36
29
|
} from "../plugins/mtime-cache.js";
|
|
37
|
-
import {
|
|
38
|
-
getAllToolDefinitions,
|
|
39
|
-
getPluginToolDefinitions,
|
|
40
|
-
getToolOwner,
|
|
41
|
-
} from "../tools/registry.js";
|
|
42
30
|
|
|
43
31
|
// ─── Test fixtures ───────────────────────────────────────────────────────────
|
|
44
32
|
|
|
@@ -526,120 +514,3 @@ describe("workspace hooks (<workspace>/hooks/)", () => {
|
|
|
526
514
|
expect(rf(sentinel, "utf8")).toBe("x");
|
|
527
515
|
});
|
|
528
516
|
});
|
|
529
|
-
|
|
530
|
-
// ─── Runtime activation (hot-reload without a daemon restart) ──────────────────
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Write a hook that appends `token` to `markerPath` each time it runs, so a
|
|
534
|
-
* test can count how many times `init`/`shutdown` fired.
|
|
535
|
-
*/
|
|
536
|
-
function writeMarkerHook(
|
|
537
|
-
dir: string,
|
|
538
|
-
hookName: string,
|
|
539
|
-
markerPath: string,
|
|
540
|
-
token: string,
|
|
541
|
-
): void {
|
|
542
|
-
writeHook(
|
|
543
|
-
dir,
|
|
544
|
-
hookName,
|
|
545
|
-
`import { appendFileSync } from "node:fs";\nexport default () => { appendFileSync(${JSON.stringify(markerPath)}, ${JSON.stringify(`${token}\n`)}); };`,
|
|
546
|
-
);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
const TOOL_SRC = (name: string) =>
|
|
550
|
-
`export default { name: ${JSON.stringify(name)}, description: "test", parameters: { type: "object", properties: {} } };`;
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* Simulate the per-turn plugin hook dispatch that drives runtime reconciliation
|
|
554
|
-
* in production: any `getUserHooksFor` call runs `scanPlugins`, which activates
|
|
555
|
-
* newly present plugins and deactivates removed ones. The hook name is
|
|
556
|
-
* irrelevant — the scan runs regardless of whether a plugin defines that hook.
|
|
557
|
-
*/
|
|
558
|
-
async function triggerScan(): Promise<void> {
|
|
559
|
-
await getUserHooksFor("user-prompt-submit");
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
describe("plugin runtime activation", () => {
|
|
563
|
-
test("a plugin installed after boot becomes live on the next scan", async () => {
|
|
564
|
-
await populateCacheAtBoot(); // empty plugins dir
|
|
565
|
-
expect(getAllToolDefinitions().some((t) => t.name === "late-tool")).toBe(
|
|
566
|
-
false,
|
|
567
|
-
);
|
|
568
|
-
|
|
569
|
-
const dir = freshPluginDir("late-plugin");
|
|
570
|
-
writePackageJson(dir, { ...SIMPLE_PKG, name: "late-plugin" });
|
|
571
|
-
writeTool(dir, "late-tool", TOOL_SRC("late-tool"));
|
|
572
|
-
const initMarker = join(ROOT, "late-init.log");
|
|
573
|
-
writeMarkerHook(dir, "init", initMarker, "init");
|
|
574
|
-
|
|
575
|
-
await triggerScan();
|
|
576
|
-
|
|
577
|
-
// Registered into the global registry as a plugin-owned tool, and exposed
|
|
578
|
-
// to the per-turn resolver via getPluginToolDefinitions().
|
|
579
|
-
expect(getToolOwner("late-tool")).toEqual({
|
|
580
|
-
kind: "plugin",
|
|
581
|
-
id: "late-plugin",
|
|
582
|
-
});
|
|
583
|
-
expect(getAllToolDefinitions().some((t) => t.name === "late-tool")).toBe(
|
|
584
|
-
true,
|
|
585
|
-
);
|
|
586
|
-
expect(getPluginToolDefinitions().some((t) => t.name === "late-tool")).toBe(
|
|
587
|
-
true,
|
|
588
|
-
);
|
|
589
|
-
// init ran exactly once.
|
|
590
|
-
expect(readFileSync(initMarker, "utf8").trim().split("\n")).toHaveLength(1);
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
test("activation is idempotent — repeated scans do not re-run init", async () => {
|
|
594
|
-
const dir = freshPluginDir("idem-plugin");
|
|
595
|
-
writePackageJson(dir, { ...SIMPLE_PKG, name: "idem-plugin" });
|
|
596
|
-
writeTool(dir, "idem-tool", TOOL_SRC("idem-tool"));
|
|
597
|
-
const initMarker = join(ROOT, "idem-init.log");
|
|
598
|
-
writeMarkerHook(dir, "init", initMarker, "init");
|
|
599
|
-
|
|
600
|
-
await populateCacheAtBoot();
|
|
601
|
-
await triggerScan();
|
|
602
|
-
await triggerScan();
|
|
603
|
-
|
|
604
|
-
expect(readFileSync(initMarker, "utf8").trim().split("\n")).toHaveLength(1);
|
|
605
|
-
// Registered exactly once (no refcount inflation from re-registration).
|
|
606
|
-
expect(getToolOwner("idem-tool")).toEqual({
|
|
607
|
-
kind: "plugin",
|
|
608
|
-
id: "idem-plugin",
|
|
609
|
-
});
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
test("removing a plugin directory deactivates it (unregister + shutdown)", async () => {
|
|
613
|
-
const dir = freshPluginDir("temp-plugin");
|
|
614
|
-
writePackageJson(dir, { ...SIMPLE_PKG, name: "temp-plugin" });
|
|
615
|
-
writeTool(dir, "temp-tool", TOOL_SRC("temp-tool"));
|
|
616
|
-
const shutdownMarker = join(ROOT, "temp-shutdown.log");
|
|
617
|
-
writeMarkerHook(dir, "shutdown", shutdownMarker, "bye");
|
|
618
|
-
|
|
619
|
-
await populateCacheAtBoot();
|
|
620
|
-
expect(getToolOwner("temp-tool")?.kind).toBe("plugin");
|
|
621
|
-
|
|
622
|
-
rmSync(dir, { recursive: true, force: true });
|
|
623
|
-
await triggerScan();
|
|
624
|
-
|
|
625
|
-
expect(getToolOwner("temp-tool")).toBeUndefined();
|
|
626
|
-
expect(getPluginToolDefinitions().some((t) => t.name === "temp-tool")).toBe(
|
|
627
|
-
false,
|
|
628
|
-
);
|
|
629
|
-
expect(existsSync(shutdownMarker)).toBe(true);
|
|
630
|
-
});
|
|
631
|
-
|
|
632
|
-
test("disabling a plugin at runtime tears down its tools", async () => {
|
|
633
|
-
const dir = freshPluginDir("disable-plugin");
|
|
634
|
-
writePackageJson(dir, { ...SIMPLE_PKG, name: "disable-plugin" });
|
|
635
|
-
writeTool(dir, "disable-tool", TOOL_SRC("disable-tool"));
|
|
636
|
-
|
|
637
|
-
await populateCacheAtBoot();
|
|
638
|
-
expect(getToolOwner("disable-tool")?.kind).toBe("plugin");
|
|
639
|
-
|
|
640
|
-
writeFileSync(join(dir, ".disabled"), "");
|
|
641
|
-
await triggerScan();
|
|
642
|
-
|
|
643
|
-
expect(getToolOwner("disable-tool")).toBeUndefined();
|
|
644
|
-
});
|
|
645
|
-
});
|
|
@@ -14,6 +14,8 @@ const gatewayIpc = {
|
|
|
14
14
|
mirrored: boolean;
|
|
15
15
|
},
|
|
16
16
|
claimThrows: false,
|
|
17
|
+
// Drives the upsert_verified_channel relay verdict; false refuses the actor.
|
|
18
|
+
activationVerified: true,
|
|
17
19
|
calls: [] as { method: string; params?: Record<string, unknown> }[],
|
|
18
20
|
};
|
|
19
21
|
|
|
@@ -27,6 +29,12 @@ mock.module("../ipc/gateway-client.js", () => ({
|
|
|
27
29
|
if (gatewayIpc.claimThrows) throw new Error("gateway unreachable");
|
|
28
30
|
return gatewayIpc.claim;
|
|
29
31
|
}
|
|
32
|
+
if (method === "upsert_verified_channel") {
|
|
33
|
+
if (!gatewayIpc.activationVerified) {
|
|
34
|
+
return { ok: true, verified: false };
|
|
35
|
+
}
|
|
36
|
+
return { ok: true, verified: true };
|
|
37
|
+
}
|
|
30
38
|
return undefined;
|
|
31
39
|
},
|
|
32
40
|
}));
|
|
@@ -34,6 +42,7 @@ mock.module("../ipc/gateway-client.js", () => ({
|
|
|
34
42
|
function resetGatewayIpc() {
|
|
35
43
|
gatewayIpc.claim = { ok: true, updated: true, mirrored: true };
|
|
36
44
|
gatewayIpc.claimThrows = false;
|
|
45
|
+
gatewayIpc.activationVerified = true;
|
|
37
46
|
gatewayIpc.calls = [];
|
|
38
47
|
}
|
|
39
48
|
|
|
@@ -204,6 +213,13 @@ describe("redeemVoiceInviteCode", () => {
|
|
|
204
213
|
);
|
|
205
214
|
expect(claim).toBeDefined();
|
|
206
215
|
expect(claim!.params).toMatchObject({ redeemedByExternalUserId: phone });
|
|
216
|
+
|
|
217
|
+
// The activation is written to the gateway via upsert_verified_channel.
|
|
218
|
+
const upsert = gatewayIpc.calls.find(
|
|
219
|
+
(c) => c.method === "upsert_verified_channel",
|
|
220
|
+
);
|
|
221
|
+
expect(upsert).toBeDefined();
|
|
222
|
+
expect(upsert!.params).toMatchObject({ type: "phone", address: phone });
|
|
207
223
|
});
|
|
208
224
|
|
|
209
225
|
test("rejects voice redemption when the gateway claim is not consumable (no mutation)", async () => {
|
|
@@ -223,6 +239,23 @@ describe("redeemVoiceInviteCode", () => {
|
|
|
223
239
|
expect(findContactChannel({ channelType: "phone", address: phone })).toBeNull();
|
|
224
240
|
});
|
|
225
241
|
|
|
242
|
+
test("returns invalid_or_expired (no throw) when the gateway refuses the activation", async () => {
|
|
243
|
+
const phone = "+15551234567";
|
|
244
|
+
const { code } = createVoiceInvite({ callerPhone: phone });
|
|
245
|
+
|
|
246
|
+
// Gateway claim consumes the row, then refuses the channel activation
|
|
247
|
+
// (blocked/revoked actor). The branch returns its generic failure, not a 500.
|
|
248
|
+
gatewayIpc.activationVerified = false;
|
|
249
|
+
|
|
250
|
+
const result = await redeemVoiceInviteCode({
|
|
251
|
+
callerExternalUserId: phone,
|
|
252
|
+
sourceChannel: "phone",
|
|
253
|
+
code,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
expect(result).toEqual({ ok: false, reason: "invalid_or_expired" });
|
|
257
|
+
});
|
|
258
|
+
|
|
226
259
|
test("proceeds for a legacy voice invite the gateway has never seen (mirrored:false)", async () => {
|
|
227
260
|
const phone = "+15551234567";
|
|
228
261
|
const { code } = createVoiceInvite({ callerPhone: phone });
|
|
@@ -71,19 +71,6 @@ import { getCliLogger } from "../logger.js";
|
|
|
71
71
|
|
|
72
72
|
const log = getCliLogger("plugins");
|
|
73
73
|
|
|
74
|
-
/**
|
|
75
|
-
* A running assistant re-scans its plugins directory on its next turn (the
|
|
76
|
-
* per-turn plugin hook dispatch reaches `scanPlugins`), so a just-installed or
|
|
77
|
-
* just-removed plugin takes effect without a restart — its tools are activated
|
|
78
|
-
* and surfaced to conversations dynamically. This message tells the user that.
|
|
79
|
-
*
|
|
80
|
-
* Exception: Bun caches dynamic `import()` by URL for the process lifetime, so
|
|
81
|
-
* an in-place code *upgrade* at an already-imported path is not hot-swapped;
|
|
82
|
-
* the `upgrade` command keeps its explicit restart guidance.
|
|
83
|
-
*/
|
|
84
|
-
const PICKED_UP_AUTOMATICALLY =
|
|
85
|
-
"A running assistant will pick this up automatically on its next turn — no restart needed.";
|
|
86
|
-
|
|
87
74
|
export function registerPluginsCommand(program: Command): void {
|
|
88
75
|
registerCommand(program, {
|
|
89
76
|
name: "plugins",
|
|
@@ -174,7 +161,7 @@ Examples:
|
|
|
174
161
|
console.log(
|
|
175
162
|
`Installed plugin "${result.name}" (${result.fileCount} file${result.fileCount === 1 ? "" : "s"})${pinned} → ${result.target}`,
|
|
176
163
|
);
|
|
177
|
-
console.log(
|
|
164
|
+
console.log("Restart the assistant to pick up the new plugin.");
|
|
178
165
|
} catch (err) {
|
|
179
166
|
if (err instanceof PluginAlreadyInstalledError) {
|
|
180
167
|
console.error(`${err.message}\nPass --force to overwrite.`);
|
|
@@ -258,7 +245,9 @@ Examples:
|
|
|
258
245
|
|
|
259
246
|
plugins
|
|
260
247
|
.command("list")
|
|
261
|
-
.description(
|
|
248
|
+
.description(
|
|
249
|
+
"List plugins installed in your workspace.",
|
|
250
|
+
)
|
|
262
251
|
.option("--json", "Emit machine-readable JSON instead of a table")
|
|
263
252
|
.option(
|
|
264
253
|
"--all",
|
|
@@ -287,7 +276,8 @@ Examples:
|
|
|
287
276
|
const nameW = Math.max(4, ...rows.map((r) => r.name.length));
|
|
288
277
|
const versionW = Math.max(7, ...rows.map((r) => r.version.length));
|
|
289
278
|
const sourceW = Math.max(6, ...rows.map((r) => r.source.length));
|
|
290
|
-
const pad = (s: string, w: number) =>
|
|
279
|
+
const pad = (s: string, w: number) =>
|
|
280
|
+
s + " ".repeat(w - s.length);
|
|
291
281
|
console.log(
|
|
292
282
|
`${pad("NAME", nameW)} ${pad("VERSION", versionW)} ${pad("SOURCE", sourceW)} STATUS`,
|
|
293
283
|
);
|
|
@@ -304,7 +294,9 @@ Examples:
|
|
|
304
294
|
console.log(
|
|
305
295
|
`${all.length} plugin${all.length === 1 ? "" : "s"} ` +
|
|
306
296
|
`(${userCount} user, ${defaultCount} default` +
|
|
307
|
-
(disabledCount > 0
|
|
297
|
+
(disabledCount > 0
|
|
298
|
+
? `, ${disabledCount} disabled`
|
|
299
|
+
: "") +
|
|
308
300
|
`).`,
|
|
309
301
|
);
|
|
310
302
|
return;
|
|
@@ -548,7 +540,7 @@ Examples:
|
|
|
548
540
|
console.log(
|
|
549
541
|
`Uninstalled plugin "${result.name}" from ${result.target}`,
|
|
550
542
|
);
|
|
551
|
-
console.log(
|
|
543
|
+
console.log("Restart the assistant to drop the plugin.");
|
|
552
544
|
} catch (err) {
|
|
553
545
|
if (err instanceof InvalidPluginNameError) {
|
|
554
546
|
console.error(err.message);
|
|
@@ -569,14 +561,15 @@ Examples:
|
|
|
569
561
|
plugins
|
|
570
562
|
.command("disable <name>")
|
|
571
563
|
.description(
|
|
572
|
-
"Disable a plugin by creating a .disabled sentinel file. Works for both user-installed and default plugins.
|
|
564
|
+
"Disable a plugin by creating a .disabled sentinel file. Works for both user-installed and default plugins. Restart the assistant for the change to take effect.",
|
|
573
565
|
)
|
|
574
566
|
.action((name: string) => {
|
|
575
567
|
try {
|
|
576
568
|
const result = disablePlugin(name);
|
|
577
569
|
log.info({ name: result.name }, "plugin disabled");
|
|
578
|
-
console.log(
|
|
579
|
-
|
|
570
|
+
console.log(
|
|
571
|
+
`Disabled plugin "${result.name}". Restart the assistant for the change to take effect.`,
|
|
572
|
+
);
|
|
580
573
|
} catch (err) {
|
|
581
574
|
if (
|
|
582
575
|
err instanceof PluginAlreadyInStateException ||
|
|
@@ -596,14 +589,15 @@ Examples:
|
|
|
596
589
|
plugins
|
|
597
590
|
.command("enable <name>")
|
|
598
591
|
.description(
|
|
599
|
-
"Re-enable a disabled plugin by removing the .disabled sentinel file.
|
|
592
|
+
"Re-enable a disabled plugin by removing the .disabled sentinel file. Restart the assistant for the change to take effect.",
|
|
600
593
|
)
|
|
601
594
|
.action((name: string) => {
|
|
602
595
|
try {
|
|
603
596
|
const result = enablePlugin(name);
|
|
604
597
|
log.info({ name: result.name }, "plugin enabled");
|
|
605
|
-
console.log(
|
|
606
|
-
|
|
598
|
+
console.log(
|
|
599
|
+
`Enabled plugin "${result.name}". Restart the assistant for the change to take effect.`,
|
|
600
|
+
);
|
|
607
601
|
} catch (err) {
|
|
608
602
|
if (
|
|
609
603
|
err instanceof PluginAlreadyInStateException ||
|