@mosadd/mcp 3.0.0-alpha.55 → 3.0.0-alpha.56
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 +5 -11
- package/LICENSE +21 -0
- package/README.md +151 -150
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-IWUGKLDX.js → chunk-T3KDVUAT.js} +14 -10
- package/dist/index.js +1 -1
- package/package.json +10 -10
- 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 +209 -182
- 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 +255 -199
- 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 +202 -202
- package/src/providers/supabase-voice.ts +91 -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 +3 -3
- 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 +28 -28
- package/src/types.ts +121 -121
- package/src/voice/floor.ts +132 -132
|
@@ -1,199 +1,199 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* comms_session_attach — the liveness contract.
|
|
3
|
-
*
|
|
4
|
-
* This tool decides WHO answers the owner: a live agent session, or the 24/7 cloud stand-in.
|
|
5
|
-
* Both answering, or the stand-in answering in a live session's name, is the exact failure that
|
|
6
|
-
* cost the founder his trust in the agent (see the file header in tools/presence.ts). So the
|
|
7
|
-
* things pinned here are the ones that would silently re-open it:
|
|
8
|
-
*
|
|
9
|
-
* 1. attaching writes the liveness row the stand-in reads, under the CALLER'S identity;
|
|
10
|
-
* 2. the hold renews itself on a timer — the model is not asked to remember a clock;
|
|
11
|
-
* 3. the timer is unref()ed, so a held line can never keep a dead session's process alive;
|
|
12
|
-
* 4. re-attaching replaces the beat instead of stacking a second one;
|
|
13
|
-
* 5. release DELETES the row (no backdated timestamp lying in a table other code reads).
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
17
|
-
|
|
18
|
-
const IDENTITY_ID = "b228b6ae-dda6-4823-9882-40ea91ed1530";
|
|
19
|
-
const USER_ID = "b1b6c60a-f5c5-47bd-8772-9e4e387994ad";
|
|
20
|
-
const TEST_SESSION = "test-host:11111111-2222-3333-4444-555555555555";
|
|
21
|
-
const AGENT_ID = "0489d4c6-8727-442f-bf83-68747a469492";
|
|
22
|
-
|
|
23
|
-
/** Calls recorded by the fake Supabase client, so assertions read like the wire traffic. */
|
|
24
|
-
const calls = {
|
|
25
|
-
upserts: [] as Record<string, unknown>[],
|
|
26
|
-
deletes: [] as string[],
|
|
27
|
-
rpcs: [] as { name: string; args: Record<string, unknown> }[],
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Minimal query-builder stand-in: every method returns the builder, `maybeSingle()` resolves the
|
|
32
|
-
* identity row, and the builder is thenable so `await delete().eq()` works like PostgREST's.
|
|
33
|
-
*/
|
|
34
|
-
function makeBuilder(table: string) {
|
|
35
|
-
const builder: Record<string, unknown> = {};
|
|
36
|
-
let pendingDelete = false;
|
|
37
|
-
const self = () => builder;
|
|
38
|
-
Object.assign(builder, {
|
|
39
|
-
select: self,
|
|
40
|
-
is: self,
|
|
41
|
-
or: self,
|
|
42
|
-
upsert: (row: Record<string, unknown>) => {
|
|
43
|
-
calls.upserts.push({ table, ...row });
|
|
44
|
-
return Promise.resolve({ error: null });
|
|
45
|
-
},
|
|
46
|
-
delete: () => {
|
|
47
|
-
pendingDelete = true;
|
|
48
|
-
return builder;
|
|
49
|
-
},
|
|
50
|
-
// ⛔ KASOWANIE MA TERAZ DWA WARUNKI: (konto, sesja). Atrapa musi dać się złożyć w łańcuch
|
|
51
|
-
// `.delete().eq(user).eq(session)`, więc zwracany obiekt jest JEDNOCZEŚNIE budowniczym i
|
|
52
|
-
// obietnicą — inaczej test przechodziłby tylko dlatego, że atrapa nie umie tego, co produkcja.
|
|
53
|
-
eq: (_col: string, val: string) => {
|
|
54
|
-
if (pendingDelete) {
|
|
55
|
-
calls.deletes.push(val);
|
|
56
|
-
return Object.assign(
|
|
57
|
-
{ eq: (_c2: string, v2: string) => { calls.deletes.push(v2); return Promise.resolve({ error: null }); } },
|
|
58
|
-
{ then: (res: (v: { error: null }) => unknown) => Promise.resolve({ error: null }).then(res) },
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
return builder;
|
|
62
|
-
},
|
|
63
|
-
// resolveOwnedAgentLine path: .or(...).limit(2) → the caller's ONE owned agent.
|
|
64
|
-
limit: () =>
|
|
65
|
-
Promise.resolve({
|
|
66
|
-
data: [{ id: AGENT_ID, m0ssad_email: "
|
|
67
|
-
error: null,
|
|
68
|
-
}),
|
|
69
|
-
maybeSingle: () => Promise.resolve({ data: { id: IDENTITY_ID, display_name: "mosADD CTO" }, error: null }),
|
|
70
|
-
});
|
|
71
|
-
return builder;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
vi.mock("../providers/supabase.js", () => ({
|
|
75
|
-
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
76
|
-
// Stała tożsamość sesji — deklaracja linii jest odtąd kluczowana po (konto, sesja), żeby
|
|
77
|
-
// generałowie wpięci tym samym kluczem nie odbierali sobie linii nawzajem.
|
|
78
|
-
sessionId: () => TEST_SESSION,
|
|
79
|
-
getSupabase: () => ({
|
|
80
|
-
auth: { getUser: () => Promise.resolve({ data: { user: { id: USER_ID } }, error: null }) },
|
|
81
|
-
from: (table: string) => makeBuilder(table),
|
|
82
|
-
// release/as_agent path: presence.ts woła mosadd_gateway_binding_release/claim przez rpc —
|
|
83
|
-
// atrapa nagrywa wywołania, żeby asercje czytały się jak prawdziwy wire.
|
|
84
|
-
rpc: (name: string, args: Record<string, unknown>) => {
|
|
85
|
-
calls.rpcs.push({ name, args });
|
|
86
|
-
return Promise.resolve({ error: null, data: { took_over: false, previous_session_id: null } });
|
|
87
|
-
},
|
|
88
|
-
}),
|
|
89
|
-
}));
|
|
90
|
-
|
|
91
|
-
const ctx = { log: () => {} } as never;
|
|
92
|
-
|
|
93
|
-
/** Import after the mock is registered, so the module under test picks it up. */
|
|
94
|
-
const { presenceTools, __clearAttachmentsForTest } = await import("../tools/presence.js");
|
|
95
|
-
const attach = presenceTools[0];
|
|
96
|
-
|
|
97
|
-
async function call(input: Record<string, unknown>) {
|
|
98
|
-
return (await attach.handler(input, ctx)) as Record<string, unknown>;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
describe("comms_session_attach", () => {
|
|
102
|
-
beforeEach(() => {
|
|
103
|
-
calls.upserts = [];
|
|
104
|
-
calls.deletes = [];
|
|
105
|
-
vi.useFakeTimers();
|
|
106
|
-
});
|
|
107
|
-
afterEach(() => {
|
|
108
|
-
__clearAttachmentsForTest();
|
|
109
|
-
vi.useRealTimers();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("is registered as a network tool under the comms_ capability group", () => {
|
|
113
|
-
expect(attach.name).toBe("comms_session_attach");
|
|
114
|
-
expect(attach.requires).toBe("network");
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("claims the line for the CALLER'S identity, with a label the owner can read", async () => {
|
|
118
|
-
const out = await call({ label: "CTO — Claude Code" });
|
|
119
|
-
expect(out.attached).toBe(true);
|
|
120
|
-
expect(out.identity_id).toBe(IDENTITY_ID);
|
|
121
|
-
expect(calls.upserts).toHaveLength(1);
|
|
122
|
-
expect(calls.upserts[0]).toMatchObject({
|
|
123
|
-
table: "agent_bridge_heartbeat",
|
|
124
|
-
identity_id: IDENTITY_ID,
|
|
125
|
-
host: "CTO — Claude Code",
|
|
126
|
-
mode: "mcp-session",
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("renews the hold on its own — the model is never asked to keep time", async () => {
|
|
131
|
-
await call({});
|
|
132
|
-
expect(calls.upserts).toHaveLength(1);
|
|
133
|
-
await vi.advanceTimersByTimeAsync(60_000);
|
|
134
|
-
expect(calls.upserts).toHaveLength(2);
|
|
135
|
-
await vi.advanceTimersByTimeAsync(60_000);
|
|
136
|
-
expect(calls.upserts).toHaveLength(3);
|
|
137
|
-
// Every beat is a fresh timestamp, not a replay of the first one.
|
|
138
|
-
expect(calls.upserts[2].last_seen_at).not.toBe(calls.upserts[0].last_seen_at);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("never keeps a finished session's process alive (timer is unref'ed)", async () => {
|
|
142
|
-
const unref = vi.fn();
|
|
143
|
-
const spy = vi.spyOn(globalThis, "setInterval").mockReturnValue({ unref } as never);
|
|
144
|
-
await call({});
|
|
145
|
-
expect(unref).toHaveBeenCalledOnce();
|
|
146
|
-
spy.mockRestore();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("re-attaching replaces the beat instead of stacking a second one", async () => {
|
|
150
|
-
await call({ label: "first" });
|
|
151
|
-
await call({ label: "second" });
|
|
152
|
-
calls.upserts = [];
|
|
153
|
-
await vi.advanceTimersByTimeAsync(60_000);
|
|
154
|
-
expect(calls.upserts).toHaveLength(1);
|
|
155
|
-
expect(calls.upserts[0].host).toBe("second");
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("release DELETES the row and stops beating — the stand-in resumes at once", async () => {
|
|
159
|
-
await call({});
|
|
160
|
-
const out = await call({ release: true });
|
|
161
|
-
expect(out.attached).toBe(false);
|
|
162
|
-
// Zwolnienie kasuje puls linii (po identity) i puszcza deklarację TEJ sesji RPC-em
|
|
163
|
-
// (konto ORAZ sesja po stronie SQL — nie kasujemy po samym koncie, bo to zabierało
|
|
164
|
-
// linię wszystkim innym generałom na tym samym kluczu).
|
|
165
|
-
expect(calls.deletes).toEqual([IDENTITY_ID]);
|
|
166
|
-
expect(calls.rpcs).toEqual([{ name: "mosadd_gateway_binding_release", args: { p_session_id: TEST_SESSION } }]);
|
|
167
|
-
calls.upserts = [];
|
|
168
|
-
await vi.advanceTimersByTimeAsync(180_000);
|
|
169
|
-
expect(calls.upserts).toHaveLength(0);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("as_agent declares the line: binding upsert + beat on the AGENT's identity, not the key's", async () => {
|
|
173
|
-
const out = await call({ as_agent: "
|
|
174
|
-
expect(out.attached).toBe(true);
|
|
175
|
-
expect(out.identity_id).toBe(AGENT_ID);
|
|
176
|
-
expect((out.speaking_as as { address: string }).address).toBe("
|
|
177
|
-
// The signing declaration message-send reads — arbitrowana w SQL (LINEAR-5879):
|
|
178
|
-
// claim RPC-em, nie surowym upsertem.
|
|
179
|
-
expect(calls.rpcs).toContainEqual({
|
|
180
|
-
name: "mosadd_gateway_binding_claim",
|
|
181
|
-
args: {
|
|
182
|
-
p_session_id: TEST_SESSION,
|
|
183
|
-
p_agent_identity_id: AGENT_ID,
|
|
184
|
-
p_agent_address: "
|
|
185
|
-
p_host: "
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
// …and the AGENT's liveness row, so ITS cloud stand-in defers to this session.
|
|
189
|
-
expect(calls.upserts).toContainEqual(
|
|
190
|
-
expect.objectContaining({
|
|
191
|
-
table: "agent_bridge_heartbeat",
|
|
192
|
-
identity_id: AGENT_ID,
|
|
193
|
-
host: "
|
|
194
|
-
}),
|
|
195
|
-
);
|
|
196
|
-
// The key's own line is NOT claimed — attaching as an agent must not silence the owner's lane.
|
|
197
|
-
expect(calls.upserts.some((u) => u.table === "agent_bridge_heartbeat" && u.identity_id === IDENTITY_ID)).toBe(false);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* comms_session_attach — the liveness contract.
|
|
3
|
+
*
|
|
4
|
+
* This tool decides WHO answers the owner: a live agent session, or the 24/7 cloud stand-in.
|
|
5
|
+
* Both answering, or the stand-in answering in a live session's name, is the exact failure that
|
|
6
|
+
* cost the founder his trust in the agent (see the file header in tools/presence.ts). So the
|
|
7
|
+
* things pinned here are the ones that would silently re-open it:
|
|
8
|
+
*
|
|
9
|
+
* 1. attaching writes the liveness row the stand-in reads, under the CALLER'S identity;
|
|
10
|
+
* 2. the hold renews itself on a timer — the model is not asked to remember a clock;
|
|
11
|
+
* 3. the timer is unref()ed, so a held line can never keep a dead session's process alive;
|
|
12
|
+
* 4. re-attaching replaces the beat instead of stacking a second one;
|
|
13
|
+
* 5. release DELETES the row (no backdated timestamp lying in a table other code reads).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
17
|
+
|
|
18
|
+
const IDENTITY_ID = "b228b6ae-dda6-4823-9882-40ea91ed1530";
|
|
19
|
+
const USER_ID = "b1b6c60a-f5c5-47bd-8772-9e4e387994ad";
|
|
20
|
+
const TEST_SESSION = "test-host:11111111-2222-3333-4444-555555555555";
|
|
21
|
+
const AGENT_ID = "0489d4c6-8727-442f-bf83-68747a469492";
|
|
22
|
+
|
|
23
|
+
/** Calls recorded by the fake Supabase client, so assertions read like the wire traffic. */
|
|
24
|
+
const calls = {
|
|
25
|
+
upserts: [] as Record<string, unknown>[],
|
|
26
|
+
deletes: [] as string[],
|
|
27
|
+
rpcs: [] as { name: string; args: Record<string, unknown> }[],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Minimal query-builder stand-in: every method returns the builder, `maybeSingle()` resolves the
|
|
32
|
+
* identity row, and the builder is thenable so `await delete().eq()` works like PostgREST's.
|
|
33
|
+
*/
|
|
34
|
+
function makeBuilder(table: string) {
|
|
35
|
+
const builder: Record<string, unknown> = {};
|
|
36
|
+
let pendingDelete = false;
|
|
37
|
+
const self = () => builder;
|
|
38
|
+
Object.assign(builder, {
|
|
39
|
+
select: self,
|
|
40
|
+
is: self,
|
|
41
|
+
or: self,
|
|
42
|
+
upsert: (row: Record<string, unknown>) => {
|
|
43
|
+
calls.upserts.push({ table, ...row });
|
|
44
|
+
return Promise.resolve({ error: null });
|
|
45
|
+
},
|
|
46
|
+
delete: () => {
|
|
47
|
+
pendingDelete = true;
|
|
48
|
+
return builder;
|
|
49
|
+
},
|
|
50
|
+
// ⛔ KASOWANIE MA TERAZ DWA WARUNKI: (konto, sesja). Atrapa musi dać się złożyć w łańcuch
|
|
51
|
+
// `.delete().eq(user).eq(session)`, więc zwracany obiekt jest JEDNOCZEŚNIE budowniczym i
|
|
52
|
+
// obietnicą — inaczej test przechodziłby tylko dlatego, że atrapa nie umie tego, co produkcja.
|
|
53
|
+
eq: (_col: string, val: string) => {
|
|
54
|
+
if (pendingDelete) {
|
|
55
|
+
calls.deletes.push(val);
|
|
56
|
+
return Object.assign(
|
|
57
|
+
{ eq: (_c2: string, v2: string) => { calls.deletes.push(v2); return Promise.resolve({ error: null }); } },
|
|
58
|
+
{ then: (res: (v: { error: null }) => unknown) => Promise.resolve({ error: null }).then(res) },
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return builder;
|
|
62
|
+
},
|
|
63
|
+
// resolveOwnedAgentLine path: .or(...).limit(2) → the caller's ONE owned agent.
|
|
64
|
+
limit: () =>
|
|
65
|
+
Promise.resolve({
|
|
66
|
+
data: [{ id: AGENT_ID, m0ssad_email: "agent-one@mosadd.com", display_name: "AGENT ONE" }],
|
|
67
|
+
error: null,
|
|
68
|
+
}),
|
|
69
|
+
maybeSingle: () => Promise.resolve({ data: { id: IDENTITY_ID, display_name: "mosADD CTO" }, error: null }),
|
|
70
|
+
});
|
|
71
|
+
return builder;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
vi.mock("../providers/supabase.js", () => ({
|
|
75
|
+
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
76
|
+
// Stała tożsamość sesji — deklaracja linii jest odtąd kluczowana po (konto, sesja), żeby
|
|
77
|
+
// generałowie wpięci tym samym kluczem nie odbierali sobie linii nawzajem.
|
|
78
|
+
sessionId: () => TEST_SESSION,
|
|
79
|
+
getSupabase: () => ({
|
|
80
|
+
auth: { getUser: () => Promise.resolve({ data: { user: { id: USER_ID } }, error: null }) },
|
|
81
|
+
from: (table: string) => makeBuilder(table),
|
|
82
|
+
// release/as_agent path: presence.ts woła mosadd_gateway_binding_release/claim przez rpc —
|
|
83
|
+
// atrapa nagrywa wywołania, żeby asercje czytały się jak prawdziwy wire.
|
|
84
|
+
rpc: (name: string, args: Record<string, unknown>) => {
|
|
85
|
+
calls.rpcs.push({ name, args });
|
|
86
|
+
return Promise.resolve({ error: null, data: { took_over: false, previous_session_id: null } });
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
const ctx = { log: () => {} } as never;
|
|
92
|
+
|
|
93
|
+
/** Import after the mock is registered, so the module under test picks it up. */
|
|
94
|
+
const { presenceTools, __clearAttachmentsForTest } = await import("../tools/presence.js");
|
|
95
|
+
const attach = presenceTools[0];
|
|
96
|
+
|
|
97
|
+
async function call(input: Record<string, unknown>) {
|
|
98
|
+
return (await attach.handler(input, ctx)) as Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
describe("comms_session_attach", () => {
|
|
102
|
+
beforeEach(() => {
|
|
103
|
+
calls.upserts = [];
|
|
104
|
+
calls.deletes = [];
|
|
105
|
+
vi.useFakeTimers();
|
|
106
|
+
});
|
|
107
|
+
afterEach(() => {
|
|
108
|
+
__clearAttachmentsForTest();
|
|
109
|
+
vi.useRealTimers();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("is registered as a network tool under the comms_ capability group", () => {
|
|
113
|
+
expect(attach.name).toBe("comms_session_attach");
|
|
114
|
+
expect(attach.requires).toBe("network");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("claims the line for the CALLER'S identity, with a label the owner can read", async () => {
|
|
118
|
+
const out = await call({ label: "CTO — Claude Code" });
|
|
119
|
+
expect(out.attached).toBe(true);
|
|
120
|
+
expect(out.identity_id).toBe(IDENTITY_ID);
|
|
121
|
+
expect(calls.upserts).toHaveLength(1);
|
|
122
|
+
expect(calls.upserts[0]).toMatchObject({
|
|
123
|
+
table: "agent_bridge_heartbeat",
|
|
124
|
+
identity_id: IDENTITY_ID,
|
|
125
|
+
host: "CTO — Claude Code",
|
|
126
|
+
mode: "mcp-session",
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("renews the hold on its own — the model is never asked to keep time", async () => {
|
|
131
|
+
await call({});
|
|
132
|
+
expect(calls.upserts).toHaveLength(1);
|
|
133
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
134
|
+
expect(calls.upserts).toHaveLength(2);
|
|
135
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
136
|
+
expect(calls.upserts).toHaveLength(3);
|
|
137
|
+
// Every beat is a fresh timestamp, not a replay of the first one.
|
|
138
|
+
expect(calls.upserts[2].last_seen_at).not.toBe(calls.upserts[0].last_seen_at);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("never keeps a finished session's process alive (timer is unref'ed)", async () => {
|
|
142
|
+
const unref = vi.fn();
|
|
143
|
+
const spy = vi.spyOn(globalThis, "setInterval").mockReturnValue({ unref } as never);
|
|
144
|
+
await call({});
|
|
145
|
+
expect(unref).toHaveBeenCalledOnce();
|
|
146
|
+
spy.mockRestore();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("re-attaching replaces the beat instead of stacking a second one", async () => {
|
|
150
|
+
await call({ label: "first" });
|
|
151
|
+
await call({ label: "second" });
|
|
152
|
+
calls.upserts = [];
|
|
153
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
154
|
+
expect(calls.upserts).toHaveLength(1);
|
|
155
|
+
expect(calls.upserts[0].host).toBe("second");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("release DELETES the row and stops beating — the stand-in resumes at once", async () => {
|
|
159
|
+
await call({});
|
|
160
|
+
const out = await call({ release: true });
|
|
161
|
+
expect(out.attached).toBe(false);
|
|
162
|
+
// Zwolnienie kasuje puls linii (po identity) i puszcza deklarację TEJ sesji RPC-em
|
|
163
|
+
// (konto ORAZ sesja po stronie SQL — nie kasujemy po samym koncie, bo to zabierało
|
|
164
|
+
// linię wszystkim innym generałom na tym samym kluczu).
|
|
165
|
+
expect(calls.deletes).toEqual([IDENTITY_ID]);
|
|
166
|
+
expect(calls.rpcs).toEqual([{ name: "mosadd_gateway_binding_release", args: { p_session_id: TEST_SESSION } }]);
|
|
167
|
+
calls.upserts = [];
|
|
168
|
+
await vi.advanceTimersByTimeAsync(180_000);
|
|
169
|
+
expect(calls.upserts).toHaveLength(0);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("as_agent declares the line: binding upsert + beat on the AGENT's identity, not the key's", async () => {
|
|
173
|
+
const out = await call({ as_agent: "agent-one@mosadd.com", label: "agent one — Cowork" });
|
|
174
|
+
expect(out.attached).toBe(true);
|
|
175
|
+
expect(out.identity_id).toBe(AGENT_ID);
|
|
176
|
+
expect((out.speaking_as as { address: string }).address).toBe("agent-one@mosadd.com");
|
|
177
|
+
// The signing declaration message-send reads — arbitrowana w SQL (LINEAR-5879):
|
|
178
|
+
// claim RPC-em, nie surowym upsertem.
|
|
179
|
+
expect(calls.rpcs).toContainEqual({
|
|
180
|
+
name: "mosadd_gateway_binding_claim",
|
|
181
|
+
args: {
|
|
182
|
+
p_session_id: TEST_SESSION,
|
|
183
|
+
p_agent_identity_id: AGENT_ID,
|
|
184
|
+
p_agent_address: "agent-one@mosadd.com",
|
|
185
|
+
p_host: "agent one — Cowork",
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
// …and the AGENT's liveness row, so ITS cloud stand-in defers to this session.
|
|
189
|
+
expect(calls.upserts).toContainEqual(
|
|
190
|
+
expect.objectContaining({
|
|
191
|
+
table: "agent_bridge_heartbeat",
|
|
192
|
+
identity_id: AGENT_ID,
|
|
193
|
+
host: "agent one — Cowork",
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
// The key's own line is NOT claimed — attaching as an agent must not silence the owner's lane.
|
|
197
|
+
expect(calls.upserts.some((u) => u.table === "agent_bridge_heartbeat" && u.identity_id === IDENTITY_ID)).toBe(false);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { allTools, createMosaddServer } from "../index.js";
|
|
3
|
-
|
|
4
|
-
describe("@mosadd/mcp", () => {
|
|
5
|
-
describe("allTools registry", () => {
|
|
6
|
-
it("exposes at least the 4 alpha channels", () => {
|
|
7
|
-
const names = allTools.map((t) => t.name);
|
|
8
|
-
// mDM (6 tools)
|
|
9
|
-
expect(names).toContain("mDM_list_contacts");
|
|
10
|
-
expect(names).toContain("mDM_publish_keys");
|
|
11
|
-
expect(names).toContain("mDM_send");
|
|
12
|
-
expect(names).toContain("mDM_send_unencrypted");
|
|
13
|
-
expect(names).toContain("mDM_list");
|
|
14
|
-
expect(names).toContain("mDM_respond_request");
|
|
15
|
-
// mIRC (5 tools)
|
|
16
|
-
expect(names).toContain("mIRC_create");
|
|
17
|
-
expect(names).toContain("mIRC_delete");
|
|
18
|
-
// mURL (revived module) + mAYL (email 3.0, was mp0st) — threat_* re-registered (LINEAR-3498)
|
|
19
|
-
// (surveillance-era direction killed 2026-06-27; on-device security pillar, not an MCP tool)
|
|
20
|
-
expect(names).toContain("mURL_post");
|
|
21
|
-
expect(names).toContain("mAYL_send");
|
|
22
|
-
// mp0st_* aliases RETIRED 2026-07-15 — mAYL is the one name (mp0st is backend-internal only)
|
|
23
|
-
expect(names.some((n) => n.startsWith("mp0st_"))).toBe(false);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("follows RFC 0001 naming — channel tools m<MODULE>_<operation>, meta tools comms_<op>", () => {
|
|
27
|
-
const channelName = /^m[A-Z][A-Z0-9_]*_[a-z][a-z0-9_]*$/;
|
|
28
|
-
const mailName = /^mp0st_[a-z][a-z0-9_]*$/; // mail module codename (LINEAR-3464)
|
|
29
|
-
const metaName = /^comms_[a-z][a-z0-9_]*$/; // discovery/meta namespace
|
|
30
|
-
const threatName = /^threat_[a-z][a-z0-9_]*$/; // defensive threat engine (LINEAR-3498)
|
|
31
|
-
for (const tool of allTools) {
|
|
32
|
-
expect(tool.name).toMatch(
|
|
33
|
-
new RegExp(`${channelName.source}|${mailName.source}|${metaName.source}|${threatName.source}`),
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("every tool declares a transport requirement (any | radio | network)", () => {
|
|
39
|
-
for (const tool of allTools) {
|
|
40
|
-
expect(["any", "radio", "network"]).toContain(tool.requires);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("every tool ships a description and a Zod schema", () => {
|
|
45
|
-
for (const tool of allTools) {
|
|
46
|
-
expect(typeof tool.description).toBe("string");
|
|
47
|
-
expect(tool.description.length).toBeGreaterThan(20);
|
|
48
|
-
expect(tool.inputSchema).toBeDefined();
|
|
49
|
-
// Zod schemas have _def
|
|
50
|
-
expect((tool.inputSchema as { _def?: unknown })._def).toBeDefined();
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("createMosaddServer", () => {
|
|
56
|
-
it("constructs without throwing in local mode", () => {
|
|
57
|
-
const server = createMosaddServer({ mode: "local", logLevel: "error" });
|
|
58
|
-
expect(server).toBeDefined();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("defaults to local mode when no apiKey", () => {
|
|
62
|
-
const server = createMosaddServer({ logLevel: "error" });
|
|
63
|
-
expect(server).toBeDefined();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("accepts cloud mode with apiKey", () => {
|
|
67
|
-
const server = createMosaddServer({ apiKey: "test", logLevel: "error" });
|
|
68
|
-
expect(server).toBeDefined();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { allTools, createMosaddServer } from "../index.js";
|
|
3
|
+
|
|
4
|
+
describe("@mosadd/mcp", () => {
|
|
5
|
+
describe("allTools registry", () => {
|
|
6
|
+
it("exposes at least the 4 alpha channels", () => {
|
|
7
|
+
const names = allTools.map((t) => t.name);
|
|
8
|
+
// mDM (6 tools)
|
|
9
|
+
expect(names).toContain("mDM_list_contacts");
|
|
10
|
+
expect(names).toContain("mDM_publish_keys");
|
|
11
|
+
expect(names).toContain("mDM_send");
|
|
12
|
+
expect(names).toContain("mDM_send_unencrypted");
|
|
13
|
+
expect(names).toContain("mDM_list");
|
|
14
|
+
expect(names).toContain("mDM_respond_request");
|
|
15
|
+
// mIRC (5 tools)
|
|
16
|
+
expect(names).toContain("mIRC_create");
|
|
17
|
+
expect(names).toContain("mIRC_delete");
|
|
18
|
+
// mURL (revived module) + mAYL (email 3.0, was mp0st) — threat_* re-registered (LINEAR-3498)
|
|
19
|
+
// (surveillance-era direction killed 2026-06-27; on-device security pillar, not an MCP tool)
|
|
20
|
+
expect(names).toContain("mURL_post");
|
|
21
|
+
expect(names).toContain("mAYL_send");
|
|
22
|
+
// mp0st_* aliases RETIRED 2026-07-15 — mAYL is the one name (mp0st is backend-internal only)
|
|
23
|
+
expect(names.some((n) => n.startsWith("mp0st_"))).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("follows RFC 0001 naming — channel tools m<MODULE>_<operation>, meta tools comms_<op>", () => {
|
|
27
|
+
const channelName = /^m[A-Z][A-Z0-9_]*_[a-z][a-z0-9_]*$/;
|
|
28
|
+
const mailName = /^mp0st_[a-z][a-z0-9_]*$/; // mail module codename (LINEAR-3464)
|
|
29
|
+
const metaName = /^comms_[a-z][a-z0-9_]*$/; // discovery/meta namespace
|
|
30
|
+
const threatName = /^threat_[a-z][a-z0-9_]*$/; // defensive threat engine (LINEAR-3498)
|
|
31
|
+
for (const tool of allTools) {
|
|
32
|
+
expect(tool.name).toMatch(
|
|
33
|
+
new RegExp(`${channelName.source}|${mailName.source}|${metaName.source}|${threatName.source}`),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("every tool declares a transport requirement (any | radio | network)", () => {
|
|
39
|
+
for (const tool of allTools) {
|
|
40
|
+
expect(["any", "radio", "network"]).toContain(tool.requires);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("every tool ships a description and a Zod schema", () => {
|
|
45
|
+
for (const tool of allTools) {
|
|
46
|
+
expect(typeof tool.description).toBe("string");
|
|
47
|
+
expect(tool.description.length).toBeGreaterThan(20);
|
|
48
|
+
expect(tool.inputSchema).toBeDefined();
|
|
49
|
+
// Zod schemas have _def
|
|
50
|
+
expect((tool.inputSchema as { _def?: unknown })._def).toBeDefined();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("createMosaddServer", () => {
|
|
56
|
+
it("constructs without throwing in local mode", () => {
|
|
57
|
+
const server = createMosaddServer({ mode: "local", logLevel: "error" });
|
|
58
|
+
expect(server).toBeDefined();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("defaults to local mode when no apiKey", () => {
|
|
62
|
+
const server = createMosaddServer({ logLevel: "error" });
|
|
63
|
+
expect(server).toBeDefined();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("accepts cloud mode with apiKey", () => {
|
|
67
|
+
const server = createMosaddServer({ apiKey: "test", logLevel: "error" });
|
|
68
|
+
expect(server).toBeDefined();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|