@mosadd/mcp 3.0.0-alpha.55 → 3.0.0-alpha.57
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/CHANGELOG.md +15 -11
- package/README.md +152 -150
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-IWUGKLDX.js → chunk-WEGSITAH.js} +30 -14
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/__tests__/blob-upload.test.ts +93 -93
- package/src/__tests__/channel-e2ee.test.ts +62 -62
- package/src/__tests__/flota-jawnie.test.ts +2 -2
- package/src/__tests__/golden-path.test.ts +139 -139
- package/src/__tests__/integration.test.ts +217 -182
- package/src/__tests__/label-room-owner.test.ts +22 -0
- package/src/__tests__/mdm-e2ee.test.ts +212 -212
- package/src/__tests__/mdm-mcp-readable.test.ts +390 -390
- package/src/__tests__/mirc-invite.test.ts +112 -112
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/presence.test.ts +199 -199
- package/src/__tests__/server.test.ts +71 -71
- package/src/__tests__/tool-count-consistency.test.ts +259 -199
- package/src/__tests__/voice-fields.test.ts +24 -0
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -145
- package/src/config.ts +66 -66
- package/src/crypto/channel-e2ee.ts +288 -288
- package/src/crypto/mdm-session.ts +842 -842
- package/src/index.ts +19 -19
- package/src/observability/sentry.ts +79 -79
- package/src/providers/blob-upload.ts +162 -162
- package/src/providers/memory-voice.ts +79 -79
- package/src/providers/supabase-dm.ts +212 -202
- package/src/providers/supabase-voice.ts +103 -91
- package/src/server.ts +195 -195
- package/src/tools/actions.ts +166 -166
- package/src/tools/attachments.ts +276 -276
- package/src/tools/capabilities.ts +70 -70
- package/src/tools/channel-payload.ts +2 -2
- package/src/tools/embed.ts +110 -110
- package/src/tools/index.ts +181 -181
- package/src/tools/knowledge.ts +344 -344
- package/src/tools/mail-aliases.ts +25 -25
- package/src/tools/mail-provenance.ts +137 -137
- package/src/tools/mail.ts +403 -403
- package/src/tools/mdm-as-agent.ts +138 -126
- package/src/tools/mdm.ts +6 -4
- package/src/tools/mirc-edge.ts +196 -196
- package/src/tools/mirc-members.ts +287 -287
- package/src/tools/mirc-messages.ts +1 -1
- package/src/tools/mirc.ts +308 -308
- package/src/tools/mroom.ts +221 -221
- package/src/tools/mtalk.ts +131 -131
- package/src/tools/presence.ts +442 -442
- package/src/tools/voice-format.ts +43 -28
- package/src/types.ts +121 -121
- package/src/voice/floor.ts +132 -132
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mIRC_invite — the wrapper that lets a channel created from the toolkit STOP being mute.
|
|
3
|
-
*
|
|
4
|
-
* mIRC_join adds the KEY's identity (the account, usually a human) to a channel, while
|
|
5
|
-
* message-send signs channel posts with the AGENT — so until the agent itself is a member
|
|
6
|
-
* every post 403s `agent_not_in_channel`. channel-members-manage `invite` has done the right
|
|
7
|
-
* thing since LINEAR-5596 (own agent → auto_joined, no code); the toolkit just never exposed it.
|
|
8
|
-
*
|
|
9
|
-
* Pinned here, because each would silently regress:
|
|
10
|
-
* 1. the tool exists, is a network tool, and its description names BOTH outcomes;
|
|
11
|
-
* 2. the field-name normalizer does NOT rename `role` → `new_role` for invite — the EF's
|
|
12
|
-
* invite branch reads `body.role`, so the rename would drop every requested role to
|
|
13
|
-
* "member" without an error (set-role keeps the rename: that branch reads `new_role`);
|
|
14
|
-
* 3. mIRC_create's `invite_agents` fan-out never forwards the field to channel-manage,
|
|
15
|
-
* reports per-agent failures in `invites[]`, and never throws the created channel away.
|
|
16
|
-
*/
|
|
17
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
18
|
-
import type { MosaddTool } from "../types.js";
|
|
19
|
-
|
|
20
|
-
const CHANNEL_ID = "6d0f1c1e-1111-4a2b-9c3d-000000000001";
|
|
21
|
-
const AGENT_A = "0489d4c6-8727-442f-bf83-68747a469492";
|
|
22
|
-
const AGENT_B = "b228b6ae-dda6-4823-9882-40ea91ed1530";
|
|
23
|
-
|
|
24
|
-
const calls: { fn: string; body: Record<string, unknown> }[] = [];
|
|
25
|
-
let inviteReply: (body: Record<string, unknown>) => unknown = () => ({ auto_joined: true, member: {} });
|
|
26
|
-
|
|
27
|
-
vi.mock("../providers/supabase.js", () => ({
|
|
28
|
-
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
29
|
-
invokeFunction: async (fn: string, body: Record<string, unknown>) => {
|
|
30
|
-
calls.push({ fn, body });
|
|
31
|
-
if (fn === "channel-manage") return { channel: { id: CHANNEL_ID, name: body.name } };
|
|
32
|
-
if (fn === "channel-members-manage") return inviteReply(body);
|
|
33
|
-
throw new Error(`unexpected edge function ${fn}`);
|
|
34
|
-
},
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
const ctx = { log: () => {} } as never;
|
|
38
|
-
/** Import after the mock is registered, so the modules under test pick it up. */
|
|
39
|
-
const { mircMembersTools } = await import("../tools/mirc-members.js");
|
|
40
|
-
const { mircTools } = await import("../tools/mirc.js");
|
|
41
|
-
|
|
42
|
-
function tool(list: readonly MosaddTool[], name: string): MosaddTool {
|
|
43
|
-
const t = list.find((x) => x.name === name);
|
|
44
|
-
if (!t) throw new Error(`${name} is not registered`);
|
|
45
|
-
return t;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
describe("mIRC_invite", () => {
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
calls.length = 0;
|
|
51
|
-
inviteReply = () => ({ auto_joined: true, member: {} });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("is registered as a network tool whose description names both outcomes", () => {
|
|
55
|
-
const invite = tool(mircMembersTools, "mIRC_invite");
|
|
56
|
-
expect(invite.requires).toBe("network");
|
|
57
|
-
expect(invite.description).toContain("auto_joined");
|
|
58
|
-
expect(invite.description).toContain("invite code");
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("sends `role` under its own name — the EF's invite branch reads body.role, not new_role", async () => {
|
|
62
|
-
const invite = tool(mircMembersTools, "mIRC_invite");
|
|
63
|
-
await invite.handler({ channel_id: CHANNEL_ID, identity_id: AGENT_A, role: "moderator" }, ctx);
|
|
64
|
-
expect(calls).toHaveLength(1);
|
|
65
|
-
expect(calls[0].fn).toBe("channel-members-manage");
|
|
66
|
-
expect(calls[0].body).toMatchObject({ action: "invite", channel_id: CHANNEL_ID, target_identity_id: AGENT_A, role: "moderator" });
|
|
67
|
-
expect(calls[0].body).not.toHaveProperty("new_role");
|
|
68
|
-
expect(calls[0].body).not.toHaveProperty("identity_id");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("keeps the role → new_role rename for set-role (the exemption is invite-only)", async () => {
|
|
72
|
-
const setRole = tool(mircMembersTools, "mIRC_set_role");
|
|
73
|
-
await setRole.handler({ channel_id: CHANNEL_ID, identity_id: AGENT_A, role: "admin" }, ctx);
|
|
74
|
-
expect(calls[0].body).toMatchObject({ action: "set-role", new_role: "admin" });
|
|
75
|
-
expect(calls[0].body).not.toHaveProperty("role");
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("mIRC_create invite_agents fan-out", () => {
|
|
80
|
-
beforeEach(() => {
|
|
81
|
-
calls.length = 0;
|
|
82
|
-
inviteReply = () => ({ auto_joined: true, member: {} });
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("creates first, then invites each agent; a per-agent failure lands in invites[] and never undoes the channel", async () => {
|
|
86
|
-
inviteReply = (body) => {
|
|
87
|
-
if (body.target_identity_id === AGENT_B) throw new Error("channel-members-manage (400): Already a member of this channel");
|
|
88
|
-
return { auto_joined: true, member: { identity_id: body.target_identity_id } };
|
|
89
|
-
};
|
|
90
|
-
const create = tool(mircTools, "mIRC_create");
|
|
91
|
-
const out = (await create.handler({ name: "ops", access_mode: "open", invite_agents: [AGENT_A, AGENT_B] }, ctx)) as {
|
|
92
|
-
channel: { id: string };
|
|
93
|
-
invites: Array<{ identity_id: string; ok: boolean; auto_joined?: boolean; error?: string }>;
|
|
94
|
-
};
|
|
95
|
-
expect(out.channel.id).toBe(CHANNEL_ID);
|
|
96
|
-
expect(calls.map((c) => c.fn)).toEqual(["channel-manage", "channel-members-manage", "channel-members-manage"]);
|
|
97
|
-
// invite_agents is toolkit-side composition — channel-manage must never see it.
|
|
98
|
-
expect(calls[0].body).not.toHaveProperty("invite_agents");
|
|
99
|
-
expect(calls[1].body).toMatchObject({ action: "invite", channel_id: CHANNEL_ID, target_identity_id: AGENT_A });
|
|
100
|
-
expect(out.invites).toHaveLength(2);
|
|
101
|
-
expect(out.invites[0]).toMatchObject({ identity_id: AGENT_A, ok: true, auto_joined: true });
|
|
102
|
-
expect(out.invites[1]).toMatchObject({ identity_id: AGENT_B, ok: false });
|
|
103
|
-
expect(out.invites[1].error).toContain("Already a member");
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("without invite_agents behaves exactly as before — one call, no invites key", async () => {
|
|
107
|
-
const create = tool(mircTools, "mIRC_create");
|
|
108
|
-
const out = (await create.handler({ name: "ops", access_mode: "open" }, ctx)) as Record<string, unknown>;
|
|
109
|
-
expect(calls).toHaveLength(1);
|
|
110
|
-
expect(out).not.toHaveProperty("invites");
|
|
111
|
-
});
|
|
112
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* mIRC_invite — the wrapper that lets a channel created from the toolkit STOP being mute.
|
|
3
|
+
*
|
|
4
|
+
* mIRC_join adds the KEY's identity (the account, usually a human) to a channel, while
|
|
5
|
+
* message-send signs channel posts with the AGENT — so until the agent itself is a member
|
|
6
|
+
* every post 403s `agent_not_in_channel`. channel-members-manage `invite` has done the right
|
|
7
|
+
* thing since LINEAR-5596 (own agent → auto_joined, no code); the toolkit just never exposed it.
|
|
8
|
+
*
|
|
9
|
+
* Pinned here, because each would silently regress:
|
|
10
|
+
* 1. the tool exists, is a network tool, and its description names BOTH outcomes;
|
|
11
|
+
* 2. the field-name normalizer does NOT rename `role` → `new_role` for invite — the EF's
|
|
12
|
+
* invite branch reads `body.role`, so the rename would drop every requested role to
|
|
13
|
+
* "member" without an error (set-role keeps the rename: that branch reads `new_role`);
|
|
14
|
+
* 3. mIRC_create's `invite_agents` fan-out never forwards the field to channel-manage,
|
|
15
|
+
* reports per-agent failures in `invites[]`, and never throws the created channel away.
|
|
16
|
+
*/
|
|
17
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
18
|
+
import type { MosaddTool } from "../types.js";
|
|
19
|
+
|
|
20
|
+
const CHANNEL_ID = "6d0f1c1e-1111-4a2b-9c3d-000000000001";
|
|
21
|
+
const AGENT_A = "0489d4c6-8727-442f-bf83-68747a469492";
|
|
22
|
+
const AGENT_B = "b228b6ae-dda6-4823-9882-40ea91ed1530";
|
|
23
|
+
|
|
24
|
+
const calls: { fn: string; body: Record<string, unknown> }[] = [];
|
|
25
|
+
let inviteReply: (body: Record<string, unknown>) => unknown = () => ({ auto_joined: true, member: {} });
|
|
26
|
+
|
|
27
|
+
vi.mock("../providers/supabase.js", () => ({
|
|
28
|
+
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
29
|
+
invokeFunction: async (fn: string, body: Record<string, unknown>) => {
|
|
30
|
+
calls.push({ fn, body });
|
|
31
|
+
if (fn === "channel-manage") return { channel: { id: CHANNEL_ID, name: body.name } };
|
|
32
|
+
if (fn === "channel-members-manage") return inviteReply(body);
|
|
33
|
+
throw new Error(`unexpected edge function ${fn}`);
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const ctx = { log: () => {} } as never;
|
|
38
|
+
/** Import after the mock is registered, so the modules under test pick it up. */
|
|
39
|
+
const { mircMembersTools } = await import("../tools/mirc-members.js");
|
|
40
|
+
const { mircTools } = await import("../tools/mirc.js");
|
|
41
|
+
|
|
42
|
+
function tool(list: readonly MosaddTool[], name: string): MosaddTool {
|
|
43
|
+
const t = list.find((x) => x.name === name);
|
|
44
|
+
if (!t) throw new Error(`${name} is not registered`);
|
|
45
|
+
return t;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe("mIRC_invite", () => {
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
calls.length = 0;
|
|
51
|
+
inviteReply = () => ({ auto_joined: true, member: {} });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("is registered as a network tool whose description names both outcomes", () => {
|
|
55
|
+
const invite = tool(mircMembersTools, "mIRC_invite");
|
|
56
|
+
expect(invite.requires).toBe("network");
|
|
57
|
+
expect(invite.description).toContain("auto_joined");
|
|
58
|
+
expect(invite.description).toContain("invite code");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("sends `role` under its own name — the EF's invite branch reads body.role, not new_role", async () => {
|
|
62
|
+
const invite = tool(mircMembersTools, "mIRC_invite");
|
|
63
|
+
await invite.handler({ channel_id: CHANNEL_ID, identity_id: AGENT_A, role: "moderator" }, ctx);
|
|
64
|
+
expect(calls).toHaveLength(1);
|
|
65
|
+
expect(calls[0].fn).toBe("channel-members-manage");
|
|
66
|
+
expect(calls[0].body).toMatchObject({ action: "invite", channel_id: CHANNEL_ID, target_identity_id: AGENT_A, role: "moderator" });
|
|
67
|
+
expect(calls[0].body).not.toHaveProperty("new_role");
|
|
68
|
+
expect(calls[0].body).not.toHaveProperty("identity_id");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("keeps the role → new_role rename for set-role (the exemption is invite-only)", async () => {
|
|
72
|
+
const setRole = tool(mircMembersTools, "mIRC_set_role");
|
|
73
|
+
await setRole.handler({ channel_id: CHANNEL_ID, identity_id: AGENT_A, role: "admin" }, ctx);
|
|
74
|
+
expect(calls[0].body).toMatchObject({ action: "set-role", new_role: "admin" });
|
|
75
|
+
expect(calls[0].body).not.toHaveProperty("role");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("mIRC_create invite_agents fan-out", () => {
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
calls.length = 0;
|
|
82
|
+
inviteReply = () => ({ auto_joined: true, member: {} });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("creates first, then invites each agent; a per-agent failure lands in invites[] and never undoes the channel", async () => {
|
|
86
|
+
inviteReply = (body) => {
|
|
87
|
+
if (body.target_identity_id === AGENT_B) throw new Error("channel-members-manage (400): Already a member of this channel");
|
|
88
|
+
return { auto_joined: true, member: { identity_id: body.target_identity_id } };
|
|
89
|
+
};
|
|
90
|
+
const create = tool(mircTools, "mIRC_create");
|
|
91
|
+
const out = (await create.handler({ name: "ops", access_mode: "open", invite_agents: [AGENT_A, AGENT_B] }, ctx)) as {
|
|
92
|
+
channel: { id: string };
|
|
93
|
+
invites: Array<{ identity_id: string; ok: boolean; auto_joined?: boolean; error?: string }>;
|
|
94
|
+
};
|
|
95
|
+
expect(out.channel.id).toBe(CHANNEL_ID);
|
|
96
|
+
expect(calls.map((c) => c.fn)).toEqual(["channel-manage", "channel-members-manage", "channel-members-manage"]);
|
|
97
|
+
// invite_agents is toolkit-side composition — channel-manage must never see it.
|
|
98
|
+
expect(calls[0].body).not.toHaveProperty("invite_agents");
|
|
99
|
+
expect(calls[1].body).toMatchObject({ action: "invite", channel_id: CHANNEL_ID, target_identity_id: AGENT_A });
|
|
100
|
+
expect(out.invites).toHaveLength(2);
|
|
101
|
+
expect(out.invites[0]).toMatchObject({ identity_id: AGENT_A, ok: true, auto_joined: true });
|
|
102
|
+
expect(out.invites[1]).toMatchObject({ identity_id: AGENT_B, ok: false });
|
|
103
|
+
expect(out.invites[1].error).toContain("Already a member");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("without invite_agents behaves exactly as before — one call, no invites key", async () => {
|
|
107
|
+
const create = tool(mircTools, "mIRC_create");
|
|
108
|
+
const out = (await create.handler({ name: "ops", access_mode: "open" }, ctx)) as Record<string, unknown>;
|
|
109
|
+
expect(calls).toHaveLength(1);
|
|
110
|
+
expect(out).not.toHaveProperty("invites");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mTALK PTT golden path — the half-duplex floor discipline (the kill feature).
|
|
3
|
-
*
|
|
4
|
-
* Two participants (alice, bob) share ONE room (one floor). Proves through the
|
|
5
|
-
* actual mTALK tools:
|
|
6
|
-
* 1. first to press PTT is GRANTED the floor,
|
|
7
|
-
* 2. a second presser is DENIED and QUEUED (half-duplex — one talker),
|
|
8
|
-
* 3. releasing the floor PROMOTES the next in the queue automatically,
|
|
9
|
-
* 4. the anti-hog timeout auto-bumps a holder who never releases,
|
|
10
|
-
* 5. join credentials are issued for the media transport.
|
|
11
|
-
*
|
|
12
|
-
* Deterministic: the in-memory voice provider takes an injected clock, so the
|
|
13
|
-
* anti-hog timeout is tested without real time passing.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { describe, expect, it } from "vitest";
|
|
17
|
-
import { mtalkTools } from "../tools/mtalk.js";
|
|
18
|
-
import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
|
|
19
|
-
import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
|
|
20
|
-
import type { DmProvider } from "@mosadd/providers";
|
|
21
|
-
import type { MosaddToolContext } from "../types.js";
|
|
22
|
-
|
|
23
|
-
const tool = (name: string) => {
|
|
24
|
-
const t = mtalkTools.find((x) => x.name === name);
|
|
25
|
-
if (!t) throw new Error(`tool ${name} not found`);
|
|
26
|
-
return t.handler;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// mTALK tools never touch dm/keys; a minimal stub satisfies the type.
|
|
30
|
-
const dmStub = {} as unknown as DmProvider;
|
|
31
|
-
|
|
32
|
-
function ctxFor(voice: InMemoryVoiceProvider): MosaddToolContext {
|
|
33
|
-
return {
|
|
34
|
-
options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
|
|
35
|
-
providers: { dm: dmStub, keys: new InMemoryMdmKeyStore(), voice },
|
|
36
|
-
log: () => {},
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
describe("mTALK PTT floor discipline — half-duplex, queue, promotion, anti-hog", () => {
|
|
41
|
-
it("grants one speaker, queues the next, promotes on release", async () => {
|
|
42
|
-
let now = 1_000;
|
|
43
|
-
const clock = () => now;
|
|
44
|
-
const aliceVoice = new InMemoryVoiceProvider("alice", clock);
|
|
45
|
-
const bobVoice = new InMemoryVoiceProvider("bob", clock);
|
|
46
|
-
aliceVoice.shareRoomsWith(bobVoice); // one shared room/floor
|
|
47
|
-
const alice = ctxFor(aliceVoice);
|
|
48
|
-
const bob = ctxFor(bobVoice);
|
|
49
|
-
|
|
50
|
-
// Open a shared room.
|
|
51
|
-
const { room_id } = (await tool("mTALK_open")({ label: "ops" }, alice)) as { room_id: string };
|
|
52
|
-
expect(room_id).toContain("ops");
|
|
53
|
-
|
|
54
|
-
// 1. Alice presses PTT first → granted.
|
|
55
|
-
const aPress = (await tool("mTALK_press")({ room_id }, alice)) as {
|
|
56
|
-
granted: boolean;
|
|
57
|
-
position: number;
|
|
58
|
-
holder: string | null;
|
|
59
|
-
};
|
|
60
|
-
expect(aPress.granted).toBe(true);
|
|
61
|
-
expect(aPress.holder).toBe("alice");
|
|
62
|
-
|
|
63
|
-
// 2. Bob presses while Alice holds → denied + queued at position 1.
|
|
64
|
-
const bPress = (await tool("mTALK_press")({ room_id }, bob)) as {
|
|
65
|
-
granted: boolean;
|
|
66
|
-
position: number;
|
|
67
|
-
holder: string | null;
|
|
68
|
-
queue: string[];
|
|
69
|
-
};
|
|
70
|
-
expect(bPress.granted).toBe(false);
|
|
71
|
-
expect(bPress.position).toBe(1);
|
|
72
|
-
expect(bPress.holder).toBe("alice");
|
|
73
|
-
expect(bPress.queue).toEqual(["bob"]);
|
|
74
|
-
|
|
75
|
-
// 3. Alice releases → Bob is promoted to holder automatically.
|
|
76
|
-
const released = (await tool("mTALK_release")({ room_id }, alice)) as {
|
|
77
|
-
holder: string | null;
|
|
78
|
-
queue: string[];
|
|
79
|
-
};
|
|
80
|
-
expect(released.holder).toBe("bob");
|
|
81
|
-
expect(released.queue).toEqual([]);
|
|
82
|
-
|
|
83
|
-
// State reads consistently from Bob's side too.
|
|
84
|
-
const state = (await tool("mTALK_state")({ room_id }, bob)) as { holder: string | null };
|
|
85
|
-
expect(state.holder).toBe("bob");
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("auto-bumps a holder who exceeds the anti-hog timeout", async () => {
|
|
89
|
-
let now = 0;
|
|
90
|
-
const clock = () => now;
|
|
91
|
-
const aliceVoice = new InMemoryVoiceProvider("alice", clock);
|
|
92
|
-
const bobVoice = new InMemoryVoiceProvider("bob", clock);
|
|
93
|
-
aliceVoice.shareRoomsWith(bobVoice);
|
|
94
|
-
const alice = ctxFor(aliceVoice);
|
|
95
|
-
const bob = ctxFor(bobVoice);
|
|
96
|
-
|
|
97
|
-
const { room_id } = (await tool("mTALK_open")({ label: "ops" }, alice)) as { room_id: string };
|
|
98
|
-
|
|
99
|
-
await tool("mTALK_press")({ room_id }, alice); // alice holds at t=0
|
|
100
|
-
const bPress = (await tool("mTALK_press")({ room_id }, bob)) as { granted: boolean };
|
|
101
|
-
expect(bPress.granted).toBe(false); // queued behind alice
|
|
102
|
-
|
|
103
|
-
// Advance past the 30s anti-hog ceiling; next floor read auto-promotes bob.
|
|
104
|
-
now = 31_000;
|
|
105
|
-
const state = (await tool("mTALK_state")({ room_id }, bob)) as { holder: string | null };
|
|
106
|
-
expect(state.holder).toBe("bob"); // alice was bumped, bob promoted
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("issues join credentials for the media transport", async () => {
|
|
110
|
-
const voice = new InMemoryVoiceProvider("alice");
|
|
111
|
-
const alice = ctxFor(voice);
|
|
112
|
-
const { room_id } = (await tool("mTALK_open")({}, alice)) as { room_id: string };
|
|
113
|
-
const join = (await tool("mTALK_join")({ room_id }, alice)) as {
|
|
114
|
-
token: string;
|
|
115
|
-
url: string;
|
|
116
|
-
identity: string;
|
|
117
|
-
};
|
|
118
|
-
expect(join.identity).toBe("alice");
|
|
119
|
-
expect(join.token).toBeTruthy();
|
|
120
|
-
expect(join.url).toBeTruthy();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* mTALK PTT golden path — the half-duplex floor discipline (the kill feature).
|
|
3
|
+
*
|
|
4
|
+
* Two participants (alice, bob) share ONE room (one floor). Proves through the
|
|
5
|
+
* actual mTALK tools:
|
|
6
|
+
* 1. first to press PTT is GRANTED the floor,
|
|
7
|
+
* 2. a second presser is DENIED and QUEUED (half-duplex — one talker),
|
|
8
|
+
* 3. releasing the floor PROMOTES the next in the queue automatically,
|
|
9
|
+
* 4. the anti-hog timeout auto-bumps a holder who never releases,
|
|
10
|
+
* 5. join credentials are issued for the media transport.
|
|
11
|
+
*
|
|
12
|
+
* Deterministic: the in-memory voice provider takes an injected clock, so the
|
|
13
|
+
* anti-hog timeout is tested without real time passing.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, it } from "vitest";
|
|
17
|
+
import { mtalkTools } from "../tools/mtalk.js";
|
|
18
|
+
import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
|
|
19
|
+
import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
|
|
20
|
+
import type { DmProvider } from "@mosadd/providers";
|
|
21
|
+
import type { MosaddToolContext } from "../types.js";
|
|
22
|
+
|
|
23
|
+
const tool = (name: string) => {
|
|
24
|
+
const t = mtalkTools.find((x) => x.name === name);
|
|
25
|
+
if (!t) throw new Error(`tool ${name} not found`);
|
|
26
|
+
return t.handler;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// mTALK tools never touch dm/keys; a minimal stub satisfies the type.
|
|
30
|
+
const dmStub = {} as unknown as DmProvider;
|
|
31
|
+
|
|
32
|
+
function ctxFor(voice: InMemoryVoiceProvider): MosaddToolContext {
|
|
33
|
+
return {
|
|
34
|
+
options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
|
|
35
|
+
providers: { dm: dmStub, keys: new InMemoryMdmKeyStore(), voice },
|
|
36
|
+
log: () => {},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe("mTALK PTT floor discipline — half-duplex, queue, promotion, anti-hog", () => {
|
|
41
|
+
it("grants one speaker, queues the next, promotes on release", async () => {
|
|
42
|
+
let now = 1_000;
|
|
43
|
+
const clock = () => now;
|
|
44
|
+
const aliceVoice = new InMemoryVoiceProvider("alice", clock);
|
|
45
|
+
const bobVoice = new InMemoryVoiceProvider("bob", clock);
|
|
46
|
+
aliceVoice.shareRoomsWith(bobVoice); // one shared room/floor
|
|
47
|
+
const alice = ctxFor(aliceVoice);
|
|
48
|
+
const bob = ctxFor(bobVoice);
|
|
49
|
+
|
|
50
|
+
// Open a shared room.
|
|
51
|
+
const { room_id } = (await tool("mTALK_open")({ label: "ops" }, alice)) as { room_id: string };
|
|
52
|
+
expect(room_id).toContain("ops");
|
|
53
|
+
|
|
54
|
+
// 1. Alice presses PTT first → granted.
|
|
55
|
+
const aPress = (await tool("mTALK_press")({ room_id }, alice)) as {
|
|
56
|
+
granted: boolean;
|
|
57
|
+
position: number;
|
|
58
|
+
holder: string | null;
|
|
59
|
+
};
|
|
60
|
+
expect(aPress.granted).toBe(true);
|
|
61
|
+
expect(aPress.holder).toBe("alice");
|
|
62
|
+
|
|
63
|
+
// 2. Bob presses while Alice holds → denied + queued at position 1.
|
|
64
|
+
const bPress = (await tool("mTALK_press")({ room_id }, bob)) as {
|
|
65
|
+
granted: boolean;
|
|
66
|
+
position: number;
|
|
67
|
+
holder: string | null;
|
|
68
|
+
queue: string[];
|
|
69
|
+
};
|
|
70
|
+
expect(bPress.granted).toBe(false);
|
|
71
|
+
expect(bPress.position).toBe(1);
|
|
72
|
+
expect(bPress.holder).toBe("alice");
|
|
73
|
+
expect(bPress.queue).toEqual(["bob"]);
|
|
74
|
+
|
|
75
|
+
// 3. Alice releases → Bob is promoted to holder automatically.
|
|
76
|
+
const released = (await tool("mTALK_release")({ room_id }, alice)) as {
|
|
77
|
+
holder: string | null;
|
|
78
|
+
queue: string[];
|
|
79
|
+
};
|
|
80
|
+
expect(released.holder).toBe("bob");
|
|
81
|
+
expect(released.queue).toEqual([]);
|
|
82
|
+
|
|
83
|
+
// State reads consistently from Bob's side too.
|
|
84
|
+
const state = (await tool("mTALK_state")({ room_id }, bob)) as { holder: string | null };
|
|
85
|
+
expect(state.holder).toBe("bob");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("auto-bumps a holder who exceeds the anti-hog timeout", async () => {
|
|
89
|
+
let now = 0;
|
|
90
|
+
const clock = () => now;
|
|
91
|
+
const aliceVoice = new InMemoryVoiceProvider("alice", clock);
|
|
92
|
+
const bobVoice = new InMemoryVoiceProvider("bob", clock);
|
|
93
|
+
aliceVoice.shareRoomsWith(bobVoice);
|
|
94
|
+
const alice = ctxFor(aliceVoice);
|
|
95
|
+
const bob = ctxFor(bobVoice);
|
|
96
|
+
|
|
97
|
+
const { room_id } = (await tool("mTALK_open")({ label: "ops" }, alice)) as { room_id: string };
|
|
98
|
+
|
|
99
|
+
await tool("mTALK_press")({ room_id }, alice); // alice holds at t=0
|
|
100
|
+
const bPress = (await tool("mTALK_press")({ room_id }, bob)) as { granted: boolean };
|
|
101
|
+
expect(bPress.granted).toBe(false); // queued behind alice
|
|
102
|
+
|
|
103
|
+
// Advance past the 30s anti-hog ceiling; next floor read auto-promotes bob.
|
|
104
|
+
now = 31_000;
|
|
105
|
+
const state = (await tool("mTALK_state")({ room_id }, bob)) as { holder: string | null };
|
|
106
|
+
expect(state.holder).toBe("bob"); // alice was bumped, bob promoted
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("issues join credentials for the media transport", async () => {
|
|
110
|
+
const voice = new InMemoryVoiceProvider("alice");
|
|
111
|
+
const alice = ctxFor(voice);
|
|
112
|
+
const { room_id } = (await tool("mTALK_open")({}, alice)) as { room_id: string };
|
|
113
|
+
const join = (await tool("mTALK_join")({ room_id }, alice)) as {
|
|
114
|
+
token: string;
|
|
115
|
+
url: string;
|
|
116
|
+
identity: string;
|
|
117
|
+
};
|
|
118
|
+
expect(join.identity).toBe("alice");
|
|
119
|
+
expect(join.token).toBeTruthy();
|
|
120
|
+
expect(join.url).toBeTruthy();
|
|
121
|
+
});
|
|
122
|
+
});
|