@mosadd/mcp 3.0.0-alpha.7 → 3.0.1
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 +415 -0
- package/LICENSE +21 -201
- package/README.md +79 -40
- package/dist/bin/mcp.js +132 -8
- package/dist/chunk-J2S44U5R.js +4258 -0
- package/dist/index.d.ts +112 -8
- package/dist/index.js +3 -1
- package/package.json +19 -16
- package/src/__tests__/blob-upload.test.ts +93 -0
- package/src/__tests__/channel-e2ee.test.ts +62 -0
- package/src/__tests__/cli.test.ts +47 -0
- package/src/__tests__/fleet-plaintext.test.ts +243 -0
- package/src/__tests__/golden-path.test.ts +4 -2
- package/src/__tests__/integration.test.ts +50 -11
- package/src/__tests__/knowledge-ingest.test.ts +114 -0
- package/src/__tests__/label-room-owner.test.ts +22 -0
- package/src/__tests__/mdm-e2ee.test.ts +36 -2
- package/src/__tests__/mdm-mcp-readable.test.ts +390 -0
- package/src/__tests__/mirc-invite.test.ts +112 -0
- package/src/__tests__/mirc-voice.test.ts +82 -0
- package/src/__tests__/mrag-search-answer.test.ts +42 -0
- package/src/__tests__/mrag-search-diagnostics.test.ts +78 -0
- package/src/__tests__/no-dead-host.test.ts +37 -0
- package/src/__tests__/presence.test.ts +199 -0
- package/src/__tests__/server.test.ts +11 -7
- package/src/__tests__/serverJsonVersion.test.ts +45 -0
- package/src/__tests__/tool-count-consistency.test.ts +259 -0
- package/src/__tests__/voice-fields.test.ts +24 -0
- package/src/bin/mcp.ts +71 -6
- package/src/cli.ts +100 -0
- package/src/crypto/channel-e2ee.ts +288 -0
- package/src/crypto/mdm-session.ts +479 -40
- package/src/index.ts +2 -2
- package/src/providers/blob-upload.ts +162 -0
- package/src/providers/supabase-dm.ts +102 -7
- package/src/providers/supabase-voice.ts +13 -1
- package/src/providers/supabase.ts +121 -10
- package/src/server.ts +102 -12
- package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -0
- package/src/tools/actions.ts +166 -0
- package/src/tools/attachments.ts +276 -0
- package/src/tools/capabilities.ts +2 -0
- package/src/tools/channel-payload.ts +69 -0
- package/src/tools/embed.ts +110 -0
- package/src/tools/index.ts +136 -6
- package/src/tools/knowledge-graph.ts +186 -0
- package/src/tools/knowledge.ts +205 -12
- package/src/tools/mail-agentbox.ts +155 -0
- package/src/tools/mail-aliases.ts +25 -0
- package/src/tools/mail-provenance.ts +137 -0
- package/src/tools/mail.ts +214 -60
- package/src/tools/mdm-as-agent.ts +137 -0
- package/src/tools/mdm-voice.ts +17 -3
- package/src/tools/mdm.ts +306 -58
- package/src/tools/mirc-edge.ts +12 -6
- package/src/tools/mirc-members.ts +130 -20
- package/src/tools/mirc-messages.ts +109 -40
- package/src/tools/mirc.ts +149 -11
- package/src/tools/mroom-messages.ts +5 -13
- package/src/tools/mtalk.ts +11 -1
- package/src/tools/murl.ts +314 -0
- package/src/tools/presence.ts +442 -0
- package/src/tools/ptt-ingest.ts +99 -0
- package/src/tools/threat.ts +123 -0
- package/src/tools/voice-format.ts +66 -0
- package/src/types.ts +36 -0
- package/src/version.ts +8 -0
- package/dist/chunk-EFTB743G.js +0 -1924
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LOCK "NO ENCRYPTION WITH THE FLEET" (29.09.2026, owner decision 28.09: no encryption on agent-line
|
|
3
|
+
* conversations, in any channel or identity).
|
|
4
|
+
*
|
|
5
|
+
* Two rules of the MCP gateway, both measured as broken on 28–29.09:
|
|
6
|
+
*
|
|
7
|
+
* c1 — CHANNEL DECODER. Open channels have no group key. The app stores channel text
|
|
8
|
+
* as bare UTF-8 in base64 (apps/web ircApi.ts `encodePayload`). The old decoder
|
|
9
|
+
* (`mirc-messages.ts` / `mroom-messages.ts` `unpackPayload`) knew only the JSON envelope, so
|
|
10
|
+
* EVERY post of the owner read as "<ciphertext>" for the agent lines.
|
|
11
|
+
* Now: plain text = text. "<ciphertext>" stays only for a real group-key envelope
|
|
12
|
+
* {iv,ciphertext,hmac} the line holds no key for (and for bytes that are not UTF-8).
|
|
13
|
+
*
|
|
14
|
+
* b1 — mDM_send TO THE FLEET IN THE CLEAR. When either side is an agent line OR it is a note to self
|
|
15
|
+
* (to === selfId), the send takes the plain path: encrypted:false, reason:"fleet_plaintext".
|
|
16
|
+
* Person↔person stays E2EE, unchanged (X3DH + Double Ratchet envelope).
|
|
17
|
+
*
|
|
18
|
+
* Every lock was checked red before the fix (alpha.54 code) and under sabotage after the fix.
|
|
19
|
+
*/
|
|
20
|
+
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
21
|
+
import type { DmProvider, DmListArgs, DmListResult, DmSendResult } from "@mosadd/providers";
|
|
22
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
23
|
+
import type { DmSendArgsExt } from "../providers/supabase-dm.js";
|
|
24
|
+
|
|
25
|
+
// ---- message-list / channel-manage stand-in (the only EFs the list tools call) ----
|
|
26
|
+
|
|
27
|
+
type StoredRow = { id: string; sender_identity_id: string; encrypted_payload: string; created_at: string };
|
|
28
|
+
let storedRows: StoredRow[] = [];
|
|
29
|
+
/** channel id → the line holds that channel's group key and opens these payloads */
|
|
30
|
+
let groupKeyOpens: (channelId: string, payload: string) => string | null = () => null;
|
|
31
|
+
|
|
32
|
+
vi.mock("../providers/supabase.js", async (importOriginal) => ({
|
|
33
|
+
...(await importOriginal<typeof import("../providers/supabase.js")>()),
|
|
34
|
+
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
35
|
+
invokeFunction: async (fn: string) => {
|
|
36
|
+
if (fn === "message-list") return { messages: storedRows, next_before: null };
|
|
37
|
+
throw new Error(`unexpected edge function ${fn}`);
|
|
38
|
+
},
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
vi.mock("../crypto/channel-e2ee.js", async (importOriginal) => ({
|
|
42
|
+
...(await importOriginal<typeof import("../crypto/channel-e2ee.js")>()),
|
|
43
|
+
decryptChannelPayload: async (channelId: string, payload: string) => groupKeyOpens(channelId, payload),
|
|
44
|
+
encryptChannelPayload: async () => null,
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
const { mircMessagesTools } = await import("../tools/mirc-messages.js");
|
|
48
|
+
const { mroomMessagesTools } = await import("../tools/mroom-messages.js");
|
|
49
|
+
const { mdmTools } = await import("../tools/mdm.js");
|
|
50
|
+
const { defaultProviders } = await import("../server.js");
|
|
51
|
+
const { InMemoryVoiceProvider } = await import("../providers/memory-voice.js");
|
|
52
|
+
const { SeededMdmKeyStore, serializePublicBundle, isE2eeEnvelope, decryptFromPeer } = await import(
|
|
53
|
+
"../crypto/mdm-session.js"
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const handler = (list: readonly MosaddTool[], name: string) => {
|
|
57
|
+
const t = list.find((x) => x.name === name);
|
|
58
|
+
if (!t) throw new Error(`tool ${name} not registered`);
|
|
59
|
+
return t.handler;
|
|
60
|
+
};
|
|
61
|
+
const noopLog: MosaddToolContext["log"] = () => {};
|
|
62
|
+
const listCtx = { log: noopLog } as unknown as MosaddToolContext;
|
|
63
|
+
|
|
64
|
+
/** Exactly what the app stores for a channel post: base64 of the UTF-8 bytes (ircApi encodePayload). */
|
|
65
|
+
const appEncode = (text: string) => Buffer.from(new TextEncoder().encode(text)).toString("base64");
|
|
66
|
+
const b64json = (obj: unknown) => Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
|
|
67
|
+
|
|
68
|
+
const CHANNEL = "00000000-0000-4000-8000-000000000001";
|
|
69
|
+
const OWNER = "owner-identity";
|
|
70
|
+
const LINE = "agent-line-identity";
|
|
71
|
+
const PEER = "peer-human-identity";
|
|
72
|
+
// Synthetic (the repo is public — no real message goes into a fixture): Polish
|
|
73
|
+
// diacritics, an em dash, an @mention, a newline and an emoji, like a real owner post.
|
|
74
|
+
const OWNER_TEXT = "Zażółć gęślą jaźń — spotkanie o 9:00 🦞\n@all proszę o potwierdzenie";
|
|
75
|
+
|
|
76
|
+
type ListOut = { messages: Array<{ id: string; text: string }> };
|
|
77
|
+
|
|
78
|
+
async function readChannel(rows: Array<[string, string]>): Promise<string[]> {
|
|
79
|
+
storedRows = rows.map(([id, payload], i) => ({
|
|
80
|
+
id,
|
|
81
|
+
sender_identity_id: OWNER,
|
|
82
|
+
encrypted_payload: payload,
|
|
83
|
+
created_at: new Date(i * 1000).toISOString(),
|
|
84
|
+
}));
|
|
85
|
+
const out = (await handler(mircMessagesTools, "mIRC_list_messages")(
|
|
86
|
+
{ channel_id: CHANNEL, space_id: "space-1", limit: 50 },
|
|
87
|
+
listCtx,
|
|
88
|
+
)) as ListOut;
|
|
89
|
+
return out.messages.map((m) => m.text);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
describe("c1 — channel decoder: the owner's text reads as text, <ciphertext> only for a sealed envelope", () => {
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
storedRows = [];
|
|
95
|
+
groupKeyOpens = () => null;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("an owner post from the app (bare UTF-8 in base64) on an open channel → readable text, not <ciphertext>", async () => {
|
|
99
|
+
const texts = await readChannel([
|
|
100
|
+
["msg-1", appEncode(OWNER_TEXT)],
|
|
101
|
+
["msg-2", appEncode("@all please confirm")],
|
|
102
|
+
]);
|
|
103
|
+
expect(texts).toEqual([OWNER_TEXT, "@all please confirm"]);
|
|
104
|
+
expect(texts).not.toContain("<ciphertext>");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("a mosadd.chat.v1 envelope from the tool (agent lines) → its text, as before", async () => {
|
|
108
|
+
const texts = await readChannel([
|
|
109
|
+
["line-1", b64json({ v: "mosadd.chat.v1", type: "text", text: "line report", reply_to: null })],
|
|
110
|
+
]);
|
|
111
|
+
expect(texts).toEqual(["line report"]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("a group-key envelope {iv,ciphertext,hmac} WITHOUT the key → <ciphertext> stays", async () => {
|
|
115
|
+
const texts = await readChannel([["sealed", b64json({ iv: "AAAAAAAAAAAAAAAA", ciphertext: "c2VhbGVk", hmac: "aG1hYw==" })]]);
|
|
116
|
+
expect(texts).toEqual(["<ciphertext>"]);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("a group-key envelope, the line HAS the key → decrypted text (path unchanged)", async () => {
|
|
120
|
+
const sealed = b64json({ iv: "AAAAAAAAAAAAAAAA", ciphertext: "c2VhbGVk", hmac: "aG1hYw==" });
|
|
121
|
+
groupKeyOpens = (_c, p) => (p === sealed ? JSON.stringify({ v: "mosadd.chat.v1", type: "text", text: "from the key" }) : null);
|
|
122
|
+
expect(await readChannel([["sealed", sealed]])).toEqual(["from the key"]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("an mDM ratchet envelope (v: mosadd.e2ee.*) pasted into a channel → <ciphertext>", async () => {
|
|
126
|
+
const texts = await readChannel([["e2ee", b64json({ v: "mosadd.e2ee.v2", dh: "x", n: 0, ct: "y" })]]);
|
|
127
|
+
expect(texts).toEqual(["<ciphertext>"]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("non-UTF-8 bytes → <ciphertext> (these are not words)", async () => {
|
|
131
|
+
const texts = await readChannel([["bin", Buffer.from([0xff, 0xfe, 0x00, 0x81, 0xc3]).toString("base64")]]);
|
|
132
|
+
expect(texts).toEqual(["<ciphertext>"]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("voice {audio, mime, dur} → voice note marker (formatVoiceIfAny unchanged)", async () => {
|
|
136
|
+
const texts = await readChannel([["voice", b64json({ audio: "A".repeat(2000), mime: "audio/webm", dur: 4200 })]]);
|
|
137
|
+
expect(texts).toEqual(["[voice note — 4s]"]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("mROOM: the same rule — text from the app reads as text", async () => {
|
|
141
|
+
storedRows = [{ id: "r1", sender_identity_id: OWNER, encrypted_payload: appEncode(OWNER_TEXT), created_at: new Date(0).toISOString() }];
|
|
142
|
+
const out = (await handler(mroomMessagesTools, "mROOM_list_messages")({ room_id: "room-1" }, listCtx)) as ListOut;
|
|
143
|
+
expect(out.messages.map((m) => m.text)).toEqual([OWNER_TEXT]);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// ---- b1: mDM_send — an in-memory backend shaped like message-send / identities / prekeys ----
|
|
148
|
+
|
|
149
|
+
type Row = { senderId: string; to: string; threadId: string; payload: Uint8Array; messageType: string };
|
|
150
|
+
|
|
151
|
+
class Backend {
|
|
152
|
+
readonly rows: Row[] = [];
|
|
153
|
+
readonly bundles = new Map<string, Uint8Array>();
|
|
154
|
+
readonly kinds = new Map<string, string>();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
class Lane implements DmProvider {
|
|
158
|
+
constructor(private readonly b: Backend, private readonly me: string) {}
|
|
159
|
+
async selfId() { return this.me; }
|
|
160
|
+
async selfKind() { return this.b.kinds.get(this.me) ?? null; }
|
|
161
|
+
async peerKind(id: string) { return this.b.kinds.get(id) ?? null; }
|
|
162
|
+
async send(args: DmSendArgsExt): Promise<DmSendResult> {
|
|
163
|
+
this.b.rows.push({ senderId: this.me, to: args.to, threadId: args.threadId, payload: args.payload, messageType: args.messageType ?? "text" });
|
|
164
|
+
return { id: `m${this.b.rows.length}`, deliveredAt: new Date(0).toISOString() };
|
|
165
|
+
}
|
|
166
|
+
async list(_args: DmListArgs): Promise<DmListResult> { return { messages: [], nextCursor: null }; }
|
|
167
|
+
async publishPrekeyBundle(bundle: Uint8Array) { this.b.bundles.set(this.me, bundle); }
|
|
168
|
+
async fetchPrekeyBundle(peerId: string) { return this.b.bundles.get(peerId) ?? null; }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const KEY = "mosadd_sk_live_0123456789abcdef0123456789abcdef";
|
|
172
|
+
const gatewayRequest = (b: Backend, me: string): MosaddToolContext => ({
|
|
173
|
+
options: { mode: "cloud", hubUrl: "https://mcp.mosadd.com", apiKey: KEY },
|
|
174
|
+
providers: defaultProviders({ dm: new Lane(b, me), voice: new InMemoryVoiceProvider(me) }, { mdmSecret: KEY }),
|
|
175
|
+
log: noopLog,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/** A person with the app: kind human, prekey bundle published by the app at login. */
|
|
179
|
+
async function person(b: Backend, id: string, seedByte: number) {
|
|
180
|
+
const keys = new SeededMdmKeyStore(new Uint8Array(32).fill(seedByte));
|
|
181
|
+
b.bundles.set(id, serializePublicBundle(await keys.getOwnMaterial()));
|
|
182
|
+
b.kinds.set(id, "human");
|
|
183
|
+
return keys;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
type SendOut = { encrypted: boolean; reason?: string; mode: string };
|
|
187
|
+
const send = (b: Backend, from: string, to: string, text: string) =>
|
|
188
|
+
handler(mdmTools, "mDM_send")({ to, text }, gatewayRequest(b, from)) as Promise<SendOut>;
|
|
189
|
+
const plain = (row: Row) => new TextDecoder().decode(row.payload);
|
|
190
|
+
|
|
191
|
+
describe("b1 — mDM_send: with fleet lines and with the owner always in the clear, person↔person E2EE", () => {
|
|
192
|
+
it("agent line → owner: encrypted:false, reason fleet_plaintext, the owner reads bare text", async () => {
|
|
193
|
+
const b = new Backend();
|
|
194
|
+
b.kinds.set(LINE, "agent");
|
|
195
|
+
await person(b, OWNER, 7);
|
|
196
|
+
const s = await send(b, LINE, OWNER, "report");
|
|
197
|
+
expect(s).toMatchObject({ encrypted: false, reason: "fleet_plaintext" });
|
|
198
|
+
expect(b.rows.at(-1)!.messageType).toBe("txt");
|
|
199
|
+
expect(plain(b.rows.at(-1)!)).toBe("report");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("owner (a person's key) → agent line: in the clear, even though the line has an old bundle", async () => {
|
|
203
|
+
const b = new Backend();
|
|
204
|
+
b.kinds.set(LINE, "agent");
|
|
205
|
+
await person(b, OWNER, 7);
|
|
206
|
+
b.bundles.set(LINE, serializePublicBundle(await new SeededMdmKeyStore(new Uint8Array(32).fill(9)).getOwnMaterial()));
|
|
207
|
+
const s = await send(b, OWNER, LINE, "instruction");
|
|
208
|
+
expect(s).toMatchObject({ encrypted: false, reason: "fleet_plaintext" });
|
|
209
|
+
expect(plain(b.rows.at(-1)!)).toBe("instruction");
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("the owner writes to SELF (to === selfId) through MCP: in the clear — zero envelopes in the own thread", async () => {
|
|
213
|
+
const b = new Backend();
|
|
214
|
+
await person(b, OWNER, 7);
|
|
215
|
+
const s = await send(b, OWNER, OWNER, "note to self");
|
|
216
|
+
expect(s).toMatchObject({ encrypted: false, reason: "fleet_plaintext" });
|
|
217
|
+
const row = b.rows.at(-1)!;
|
|
218
|
+
expect(row.threadId).toBe(`dm:${OWNER}:${OWNER}`);
|
|
219
|
+
expect(isE2eeEnvelope(row.payload)).toBe(false);
|
|
220
|
+
expect(plain(row)).toBe("note to self");
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("person → person: E2EE stays — ratchet envelope, text not visible, the recipient opens it", async () => {
|
|
224
|
+
const b = new Backend();
|
|
225
|
+
await person(b, OWNER, 7);
|
|
226
|
+
const peerKeys = await person(b, PEER, 5);
|
|
227
|
+
const s = await send(b, OWNER, PEER, "secret");
|
|
228
|
+
expect(s).toMatchObject({ encrypted: true, mode: "e2ee" });
|
|
229
|
+
expect(s.reason).not.toBe("fleet_plaintext");
|
|
230
|
+
const row = b.rows.at(-1)!;
|
|
231
|
+
expect(isE2eeEnvelope(row.payload)).toBe(true);
|
|
232
|
+
expect(plain(row)).not.toContain("secret");
|
|
233
|
+
expect(new TextDecoder().decode(await decryptFromPeer(peerKeys, OWNER, row.payload))).toBe("secret");
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("tool descriptions: mDM_send_unencrypted is not 'DEPRECATED / prefer mDM_send', both say: fleet always in the clear", () => {
|
|
237
|
+
const d = (n: string) => mdmTools.find((t) => t.name === n)!.description;
|
|
238
|
+
expect(d("mDM_send_unencrypted")).not.toMatch(/DEPRECATED|Prefer mDM_send|Will be removed/i);
|
|
239
|
+
for (const n of ["mDM_send", "mDM_send_unencrypted"]) {
|
|
240
|
+
expect(d(n)).toMatch(/Conversations with fleet lines and with the [A-Za-z ]+: ALWAYS in the clear/);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
});
|
|
@@ -111,8 +111,10 @@ describe("golden path — host injects transport under mDM", () => {
|
|
|
111
111
|
expect(result.message_id).toBe("radio-1");
|
|
112
112
|
|
|
113
113
|
// The payload is opaque to the provider but carries our text under the hood.
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
// 2026-08-25: plaintext lane is RAW utf8 text (native app format), not a JSON
|
|
115
|
+
// envelope — packPlaintextPayload change, unpack tolerates both shapes.
|
|
116
|
+
const decoded = Buffer.from(radio.sent[0]!.payload).toString("utf8");
|
|
117
|
+
expect(decoded).toBe("rendezvous at grid 4471, 0600");
|
|
116
118
|
});
|
|
117
119
|
|
|
118
120
|
it("step 5: mDM_list round-trips the message back through the same provider", async () => {
|
|
@@ -9,11 +9,36 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
12
|
+
import { mkdtempSync } from "node:fs";
|
|
13
|
+
import { homedir, tmpdir } from "node:os";
|
|
12
14
|
import { join } from "node:path";
|
|
13
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
15
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
14
16
|
|
|
15
17
|
const MCP_BIN = join(__dirname, "..", "..", "dist", "bin", "mcp.js");
|
|
16
18
|
|
|
19
|
+
// Every test boots a fresh node process (dist/bin/mcp.js) and waits for it on stdout. On a busy machine (this package's
|
|
20
|
+
// other test files in parallel, the other packages' suites under `pnpm -r test`, antivirus scanning node's module loads)
|
|
21
|
+
// that boot took more than 7 s on 2026-11-14: two of the three tests timed out at 5 s in each of two full runs, and
|
|
22
|
+
// passed in about 2 s each when this file ran alone, and in about 14 s each in a full run that gave them the time.
|
|
23
|
+
// The assertions are unchanged; only how long they may wait is. A server that never answers still fails.
|
|
24
|
+
const REQUEST_TIMEOUT_MS = 45_000;
|
|
25
|
+
vi.setConfig({ testTimeout: 120_000, hookTimeout: 30_000 });
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The child server runs with an EMPTY home and no MOSADD_* variables.
|
|
29
|
+
*
|
|
30
|
+
* Until 2026-09-29 it inherited the developer's environment: on a machine with a `mosadd login` session
|
|
31
|
+
* (~/.mosadd/session.json) the "tool handler throws" case below sent a REAL mDM_send through that account
|
|
32
|
+
* (to 11111111-…, failing only on the missing prekey bundle), so running the suite wrote to production.
|
|
33
|
+
* Sealed, the server finds no credentials and every networked tool stops at MissingSupabaseEnvError.
|
|
34
|
+
*/
|
|
35
|
+
export function sealedEnv(parent: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
|
|
36
|
+
const home = mkdtempSync(join(tmpdir(), "mosadd-mcp-it-"));
|
|
37
|
+
const env: NodeJS.ProcessEnv = {};
|
|
38
|
+
for (const [k, v] of Object.entries(parent)) if (!/^(MOSADD_|SUPABASE_)/i.test(k)) env[k] = v;
|
|
39
|
+
return { ...env, HOME: home, USERPROFILE: home, HOMEDRIVE: "", HOMEPATH: "" };
|
|
40
|
+
}
|
|
41
|
+
|
|
17
42
|
interface JsonRpcMessage {
|
|
18
43
|
jsonrpc: "2.0";
|
|
19
44
|
id?: number | string;
|
|
@@ -30,7 +55,7 @@ class McpClient {
|
|
|
30
55
|
private nextId = 1;
|
|
31
56
|
|
|
32
57
|
async start(): Promise<void> {
|
|
33
|
-
this.proc = spawn("node", [MCP_BIN], { stdio: ["pipe", "pipe", "pipe"] });
|
|
58
|
+
this.proc = spawn("node", [MCP_BIN], { stdio: ["pipe", "pipe", "pipe"], env: sealedEnv() });
|
|
34
59
|
|
|
35
60
|
this.proc.stdout.on("data", (chunk: Buffer) => {
|
|
36
61
|
this.buffer += chunk.toString("utf8");
|
|
@@ -74,7 +99,7 @@ class McpClient {
|
|
|
74
99
|
await new Promise<void>((resolve) => this.proc.on("close", () => resolve()));
|
|
75
100
|
}
|
|
76
101
|
|
|
77
|
-
async send(method: string, params?: unknown, timeoutMs =
|
|
102
|
+
async send(method: string, params?: unknown, timeoutMs = REQUEST_TIMEOUT_MS): Promise<JsonRpcMessage> {
|
|
78
103
|
const id = this.nextId++;
|
|
79
104
|
const req: JsonRpcMessage = { jsonrpc: "2.0", id, method, params };
|
|
80
105
|
return new Promise((resolve, reject) => {
|
|
@@ -91,6 +116,19 @@ class McpClient {
|
|
|
91
116
|
}
|
|
92
117
|
}
|
|
93
118
|
|
|
119
|
+
describe("integration child environment (no real session, no real messages)", () => {
|
|
120
|
+
it("is sealed: no MOSADD_*/SUPABASE_* variable and a home that is not the developer's", () => {
|
|
121
|
+
const env = sealedEnv({ ...process.env, MOSADD_API_KEY: "mosadd_sk_live_x", MOSADD_USER_JWT: "jwt", SUPABASE_URL: "https://x", PATH: "p" });
|
|
122
|
+
expect(Object.keys(env).filter((k) => /^(MOSADD_|SUPABASE_)/i.test(k))).toEqual([]);
|
|
123
|
+
expect(env.PATH).toBe("p");
|
|
124
|
+
for (const k of ["HOME", "USERPROFILE"] as const) {
|
|
125
|
+
expect(env[k]).toBeTruthy();
|
|
126
|
+
expect(env[k]).not.toBe(homedir());
|
|
127
|
+
expect(env[k]!.startsWith(tmpdir())).toBe(true);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
94
132
|
describe("@mosadd/mcp — integration (real stdio)", () => {
|
|
95
133
|
let client: McpClient;
|
|
96
134
|
|
|
@@ -134,11 +172,12 @@ describe("@mosadd/mcp — integration (real stdio)", () => {
|
|
|
134
172
|
const result = resp.result as { tools?: Array<{ name: string }> };
|
|
135
173
|
const names = result.tools?.map((t) => t.name) ?? [];
|
|
136
174
|
|
|
137
|
-
// All
|
|
175
|
+
// All live channels surface their tools
|
|
138
176
|
expect(names).toContain("mDM_send");
|
|
139
177
|
expect(names).toContain("mIRC_create");
|
|
140
|
-
expect(names).toContain("
|
|
141
|
-
expect(names).toContain("
|
|
178
|
+
expect(names).toContain("mURL_post"); // mURL revived module (2026-06-27)
|
|
179
|
+
expect(names).toContain("mAYL_send"); // mAYL = email 3.0 (was mp0st); threat_catalog/threat_classify ARE registered
|
|
180
|
+
expect(names).not.toContain("mp0st_send"); // mp0st_* aliases RETIRED 2026-07-15 — mAYL only
|
|
142
181
|
expect(names).toContain("mTALK_press"); // mTALK PTT now shipped
|
|
143
182
|
expect(names).toContain("mRAG_search"); // mRAG RAG-for-devs now shipped
|
|
144
183
|
expect(names).toContain("mIRC_post_message"); // channel messaging now shipped
|
|
@@ -161,10 +200,10 @@ describe("@mosadd/mcp — integration (real stdio)", () => {
|
|
|
161
200
|
clientInfo: { name: "vitest", version: "1.0" },
|
|
162
201
|
});
|
|
163
202
|
|
|
164
|
-
// mDM_send
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
203
|
+
// mDM_send to a nonexistent peer MUST fail — but as a normal `isError: true`
|
|
204
|
+
// content block, not a JSON-RPC error (that would crash the agent loop).
|
|
205
|
+
// The child runs sealed (sealedEnv), so it has no credentials on any machine and the
|
|
206
|
+
// call stops at MissingSupabaseEnvError before any network request.
|
|
168
207
|
const resp = await client.send("tools/call", {
|
|
169
208
|
name: "mDM_send",
|
|
170
209
|
arguments: { to: "11111111-1111-1111-1111-111111111111", text: "hi" },
|
|
@@ -173,6 +212,6 @@ describe("@mosadd/mcp — integration (real stdio)", () => {
|
|
|
173
212
|
expect(resp.error).toBeUndefined(); // JSON-RPC level OK
|
|
174
213
|
const result = resp.result as { isError?: boolean; content?: Array<{ text?: string }> };
|
|
175
214
|
expect(result.isError).toBe(true);
|
|
176
|
-
expect(result.content?.[0]?.text).
|
|
215
|
+
expect(result.content?.[0]?.text ?? "").toMatch(/Missing/i);
|
|
177
216
|
});
|
|
178
217
|
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mRAG_ingest — what actually reaches rag-index.
|
|
3
|
+
*
|
|
4
|
+
* Two things are pinned here, both found by measuring production on 2026-08-14:
|
|
5
|
+
*
|
|
6
|
+
* 1. THE GRAPH FIELDS ARE FORWARDED. The knowledge graph builds its nodes from
|
|
7
|
+
* metadata.sender / .recipient / .occurred_at and NOTHING else. This tool used to send only a
|
|
8
|
+
* title, so a corpus could be fully indexed and mRAG_graph_overview still come back empty —
|
|
9
|
+
* silently, with every call returning success. If these assertions ever go green-but-empty
|
|
10
|
+
* again, that failure is back.
|
|
11
|
+
*
|
|
12
|
+
* 2. A NON-UUID source_id DOES NOT BLOW UP THE CALL. `user_embeddings.source_id` is a uuid column,
|
|
13
|
+
* so passing the natural thing (a path, a case number) made the whole ingest fail with an
|
|
14
|
+
* opaque "rag-index (500): Internal error". Non-UUIDs are folded into a deterministic UUIDv5;
|
|
15
|
+
* real UUIDs pass through untouched.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
19
|
+
|
|
20
|
+
const sent: Record<string, unknown>[] = [];
|
|
21
|
+
|
|
22
|
+
vi.mock("../providers/supabase.js", () => ({
|
|
23
|
+
readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
|
|
24
|
+
invokeFunction: (_fn: string, body: Record<string, unknown>) => {
|
|
25
|
+
sent.push(body);
|
|
26
|
+
return Promise.resolve({ indexed: 1, chunk_count: 1 });
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
const { knowledgeTools } = await import("../tools/knowledge.js");
|
|
31
|
+
const ingest = knowledgeTools.find((t) => t.name === "mRAG_ingest")!;
|
|
32
|
+
const ctx = { log: () => {} } as never;
|
|
33
|
+
const call = (input: Record<string, unknown>) => ingest.handler(input, ctx);
|
|
34
|
+
const last = () => sent[sent.length - 1];
|
|
35
|
+
|
|
36
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
37
|
+
|
|
38
|
+
describe("mRAG_ingest", () => {
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
sent.length = 0;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("forwards the parties and the event date as TOP-LEVEL fields (where rag-index reads them)", async () => {
|
|
44
|
+
await call({
|
|
45
|
+
content_text: "Pismo procesowe.",
|
|
46
|
+
sender: { kind: "email", ref: "kancelaria@example.invalid", label: "Kancelaria" },
|
|
47
|
+
recipient: { kind: "unknown", ref: "sad-rejonowy", label: "Sąd Rejonowy" },
|
|
48
|
+
occurred_at: "2019-03-11T10:00:00.000Z",
|
|
49
|
+
direction: "in",
|
|
50
|
+
labels: ["M-01"],
|
|
51
|
+
name: "pozew.pdf",
|
|
52
|
+
mime: "application/pdf",
|
|
53
|
+
size: 1234,
|
|
54
|
+
});
|
|
55
|
+
expect(last()).toMatchObject({
|
|
56
|
+
sender: { kind: "email", ref: "kancelaria@example.invalid" },
|
|
57
|
+
recipient: { kind: "unknown", ref: "sad-rejonowy" },
|
|
58
|
+
occurred_at: "2019-03-11T10:00:00.000Z",
|
|
59
|
+
direction: "in",
|
|
60
|
+
labels: ["M-01"],
|
|
61
|
+
name: "pozew.pdf",
|
|
62
|
+
mime: "application/pdf",
|
|
63
|
+
size: 1234,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("keeps caller metadata AND the title, without dropping either", async () => {
|
|
68
|
+
await call({
|
|
69
|
+
content_text: "x",
|
|
70
|
+
title: "Pozew z 11.03.2019",
|
|
71
|
+
metadata: { case_id: "M-01", jurisdiction: "PL", pii_flag: true },
|
|
72
|
+
});
|
|
73
|
+
expect(last().metadata).toMatchObject({
|
|
74
|
+
case_id: "M-01",
|
|
75
|
+
jurisdiction: "PL",
|
|
76
|
+
pii_flag: true,
|
|
77
|
+
title: "Pozew z 11.03.2019",
|
|
78
|
+
ingested_via: "mRAG_ingest",
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("a caller that passes nothing extra sends the same request shape as before", async () => {
|
|
83
|
+
await call({ content_text: "x", source_type: "note" });
|
|
84
|
+
expect(last()).toEqual({
|
|
85
|
+
source_type: "file", // "note" maps to "file" backend-side, unchanged behaviour
|
|
86
|
+
source_id: null,
|
|
87
|
+
thread_id: null,
|
|
88
|
+
content_text: "x",
|
|
89
|
+
metadata: { ingested_via: "mRAG_ingest" },
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("folds a non-UUID source_id into a stable uuid and keeps the original visible", async () => {
|
|
94
|
+
await call({ content_text: "x", source_id: "C:/LAW/M-01/pozew.pdf" });
|
|
95
|
+
const id = last().source_id as string;
|
|
96
|
+
expect(id).toMatch(UUID_RE);
|
|
97
|
+
expect(last().metadata).toMatchObject({ source_ref: "C:/LAW/M-01/pozew.pdf" });
|
|
98
|
+
|
|
99
|
+
// Deterministic: the same document re-ingested groups with itself rather than forking.
|
|
100
|
+
await call({ content_text: "y", source_id: "C:/LAW/M-01/pozew.pdf" });
|
|
101
|
+
expect(last().source_id).toBe(id);
|
|
102
|
+
|
|
103
|
+
// …and a different document does not collide with it.
|
|
104
|
+
await call({ content_text: "z", source_id: "C:/LAW/M-01/odpowiedz.pdf" });
|
|
105
|
+
expect(last().source_id).not.toBe(id);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("passes a real UUID through untouched, with no rewrite marker", async () => {
|
|
109
|
+
const uuid = "b228b6ae-dda6-4823-9882-40ea91ed1530";
|
|
110
|
+
await call({ content_text: "x", source_id: uuid });
|
|
111
|
+
expect(last().source_id).toBe(uuid);
|
|
112
|
+
expect(last().metadata).not.toHaveProperty("source_ref");
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// 15.11.2026 — pokój PTT z etykietą ma właściciela w nazwie (bramka: mosADD livekit-token/labelRoom.ts).
|
|
2
|
+
// Było `mosadd-room-<etykieta>`: jedna nazwa dla wszystkich kont, bez właściciela → 403 dla każdego,
|
|
3
|
+
// a wersja „pierwszy wchodzący zajmuje” pozwalała obcemu przejąć pokój.
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { labelRoomId } from "../providers/supabase-voice.js";
|
|
6
|
+
|
|
7
|
+
const G = "68f326ac-3e8b-468e-9bac-328a930de541";
|
|
8
|
+
|
|
9
|
+
describe("labelRoomId", () => {
|
|
10
|
+
it("etykieta → mosadd-room-<id otwierającego>-<slug>", () => {
|
|
11
|
+
expect(labelRoomId(G, "Field Team")).toBe(`mosadd-room-${G}-field-team`);
|
|
12
|
+
});
|
|
13
|
+
it("bez etykiety → pokój osobisty (goły id, jak dotąd)", () => {
|
|
14
|
+
expect(labelRoomId(G)).toBe(`mosadd-room-${G}`);
|
|
15
|
+
});
|
|
16
|
+
it("dwa konta z tą samą etykietą dostają RÓŻNE pokoje (koniec wspólnej nazwy dla wszystkich)", () => {
|
|
17
|
+
expect(labelRoomId(G, "ops")).not.toBe(labelRoomId("1acbb607-9f66-4074-8295-17c4fb84832c", "ops"));
|
|
18
|
+
});
|
|
19
|
+
it("etykieta z samych znaków specjalnych nie robi z pokoju osobistego", () => {
|
|
20
|
+
expect(labelRoomId(G, "!!!")).toBe(`mosadd-room-${G}-room`);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* mDM E2EE golden path
|
|
2
|
+
* mDM E2EE golden path — the "done" bar.
|
|
3
3
|
*
|
|
4
4
|
* Two parties (alice, bob) sharing ONE backend that acts as both the message
|
|
5
5
|
* store AND the key directory (decision "1a": prekey bundles ride the same
|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
import { mdmTools } from "../tools/mdm.js";
|
|
22
22
|
import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
|
|
23
23
|
import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
|
|
24
|
+
import { createMosaddServer } from "../server.js";
|
|
24
25
|
import type { MosaddToolContext } from "../types.js";
|
|
25
26
|
|
|
26
27
|
/** Shared store: message log + key directory, both keyed in one place. */
|
|
@@ -104,7 +105,7 @@ describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", (
|
|
|
104
105
|
const wire = backend.messages[0]!.payload;
|
|
105
106
|
const wireStr = Buffer.from(wire).toString("utf8");
|
|
106
107
|
expect(wireStr).not.toContain("first contact");
|
|
107
|
-
expect(wireStr).toContain("mosadd.e2ee.
|
|
108
|
+
expect(wireStr).toContain("mosadd.e2ee.v2"); // DH-ratchet sealed envelope (PCS)
|
|
108
109
|
|
|
109
110
|
// 4. Bob lists the thread and decrypts Alice's message.
|
|
110
111
|
const bobView = (await tool("mDM_list")({ contact_id: "alice" }, bob)) as {
|
|
@@ -176,3 +177,36 @@ describe("mDM E2EE golden path — X3DH handshake + ratchet, both directions", (
|
|
|
176
177
|
);
|
|
177
178
|
});
|
|
178
179
|
});
|
|
180
|
+
|
|
181
|
+
describe("auto-publish prekeys on startup (cold-start fix)", () => {
|
|
182
|
+
it("publishes the local prekey bundle when autoPublishKeys is set", async () => {
|
|
183
|
+
const backend = new SharedBackend();
|
|
184
|
+
createMosaddServer({
|
|
185
|
+
mode: "local",
|
|
186
|
+
autoPublishKeys: true,
|
|
187
|
+
providers: {
|
|
188
|
+
dm: new ClientProvider(backend, "self-agent"),
|
|
189
|
+
keys: new InMemoryMdmKeyStore(),
|
|
190
|
+
voice: new InMemoryVoiceProvider("self-agent"),
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
// fire-and-forget; getOwnMaterial() does async key generation, so flush.
|
|
194
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
195
|
+
expect(backend.bundles.has("self-agent")).toBe(true);
|
|
196
|
+
expect(backend.bundles.get("self-agent")!.byteLength).toBeGreaterThan(0);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("does NOT publish when autoPublishKeys is unset (hosted/default)", async () => {
|
|
200
|
+
const backend = new SharedBackend();
|
|
201
|
+
createMosaddServer({
|
|
202
|
+
mode: "local",
|
|
203
|
+
providers: {
|
|
204
|
+
dm: new ClientProvider(backend, "quiet-agent"),
|
|
205
|
+
keys: new InMemoryMdmKeyStore(),
|
|
206
|
+
voice: new InMemoryVoiceProvider("quiet-agent"),
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
210
|
+
expect(backend.bundles.has("quiet-agent")).toBe(false);
|
|
211
|
+
});
|
|
212
|
+
});
|