@archipelagolab/lobi 1.0.0
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 +164 -0
- package/ENDOFFILE +0 -0
- package/EOF +0 -0
- package/LICENSE +21 -0
- package/SPEC-SUPPORT.md +116 -0
- package/YAMLEND +0 -0
- package/api.ts +18 -0
- package/archipelagolab-lobi-1.0.0.tgz +0 -0
- package/auth-presence.ts +56 -0
- package/channel-plugin-api.ts +3 -0
- package/cli-metadata.ts +11 -0
- package/contract-api.ts +17 -0
- package/docs/CHECKLIST.md +83 -0
- package/docs/FORK_SDK_GUIDE.md +279 -0
- package/helper-api.ts +3 -0
- package/index.test.ts +61 -0
- package/index.ts +65 -0
- package/openclaw.plugin.json +23 -0
- package/package.json +52 -0
- package/plugin-entry.handlers.runtime.ts +1 -0
- package/runtime-api.ts +54 -0
- package/runtime-heavy-api.ts +1 -0
- package/scripts/migrate-to-lobi.sh +72 -0
- package/secret-contract-api.ts +5 -0
- package/setup-entry.ts +13 -0
- package/src/account-selection.test.ts +124 -0
- package/src/account-selection.ts +226 -0
- package/src/actions.account-propagation.test.ts +251 -0
- package/src/actions.test.ts +251 -0
- package/src/actions.ts +336 -0
- package/src/approval-auth.test.ts +23 -0
- package/src/approval-auth.ts +25 -0
- package/src/approval-handler.runtime.test.ts +46 -0
- package/src/approval-handler.runtime.ts +400 -0
- package/src/approval-ids.ts +6 -0
- package/src/approval-native.test.ts +329 -0
- package/src/approval-native.ts +336 -0
- package/src/approval-reactions.test.ts +107 -0
- package/src/approval-reactions.ts +158 -0
- package/src/auth-precedence.ts +61 -0
- package/src/channel-account-paths.ts +92 -0
- package/src/channel.account-paths.test.ts +102 -0
- package/src/channel.directory.test.ts +601 -0
- package/src/channel.resolve.test.ts +38 -0
- package/src/channel.runtime.ts +16 -0
- package/src/channel.setup.test.ts +269 -0
- package/src/channel.ts +570 -0
- package/src/cli-metadata.ts +19 -0
- package/src/cli.test.ts +1015 -0
- package/src/cli.ts +1198 -0
- package/src/config-adapter.ts +41 -0
- package/src/config-schema.test.ts +90 -0
- package/src/config-schema.ts +114 -0
- package/src/directory-live.test.ts +200 -0
- package/src/directory-live.ts +238 -0
- package/src/doctor-contract.ts +287 -0
- package/src/doctor.test.ts +440 -0
- package/src/doctor.ts +262 -0
- package/src/env-vars.ts +92 -0
- package/src/exec-approval-resolver.test.ts +68 -0
- package/src/exec-approval-resolver.ts +23 -0
- package/src/exec-approvals.test.ts +483 -0
- package/src/exec-approvals.ts +290 -0
- package/src/group-mentions.ts +41 -0
- package/src/legacy-crypto-inspector-availability.test.ts +81 -0
- package/src/legacy-crypto-inspector-availability.ts +60 -0
- package/src/legacy-crypto.test.ts +234 -0
- package/src/legacy-crypto.ts +549 -0
- package/src/legacy-state.test.ts +86 -0
- package/src/legacy-state.ts +156 -0
- package/src/matrix/account-config.ts +150 -0
- package/src/matrix/accounts.readiness.test.ts +27 -0
- package/src/matrix/accounts.test.ts +757 -0
- package/src/matrix/accounts.ts +194 -0
- package/src/matrix/actions/client.test.ts +215 -0
- package/src/matrix/actions/client.ts +31 -0
- package/src/matrix/actions/devices.test.ts +114 -0
- package/src/matrix/actions/devices.ts +34 -0
- package/src/matrix/actions/limits.test.ts +15 -0
- package/src/matrix/actions/limits.ts +6 -0
- package/src/matrix/actions/messages.test.ts +289 -0
- package/src/matrix/actions/messages.ts +123 -0
- package/src/matrix/actions/pins.test.ts +74 -0
- package/src/matrix/actions/pins.ts +64 -0
- package/src/matrix/actions/polls.test.ts +71 -0
- package/src/matrix/actions/polls.ts +109 -0
- package/src/matrix/actions/profile.test.ts +109 -0
- package/src/matrix/actions/profile.ts +37 -0
- package/src/matrix/actions/reactions.test.ts +135 -0
- package/src/matrix/actions/reactions.ts +59 -0
- package/src/matrix/actions/room.test.ts +79 -0
- package/src/matrix/actions/room.ts +71 -0
- package/src/matrix/actions/summary.test.ts +87 -0
- package/src/matrix/actions/summary.ts +88 -0
- package/src/matrix/actions/types.ts +82 -0
- package/src/matrix/actions/verification.test.ts +105 -0
- package/src/matrix/actions/verification.ts +237 -0
- package/src/matrix/actions.ts +37 -0
- package/src/matrix/active-client.ts +26 -0
- package/src/matrix/async-lock.ts +18 -0
- package/src/matrix/backup-health.ts +115 -0
- package/src/matrix/client/config-runtime-api.ts +14 -0
- package/src/matrix/client/config-secret-input.runtime.ts +1 -0
- package/src/matrix/client/config.ts +982 -0
- package/src/matrix/client/create-client.test.ts +115 -0
- package/src/matrix/client/create-client.ts +101 -0
- package/src/matrix/client/env-auth.ts +6 -0
- package/src/matrix/client/file-sync-store.test.ts +265 -0
- package/src/matrix/client/file-sync-store.ts +289 -0
- package/src/matrix/client/logging.ts +123 -0
- package/src/matrix/client/migration-snapshot.runtime.ts +1 -0
- package/src/matrix/client/private-network-host.ts +56 -0
- package/src/matrix/client/runtime.ts +4 -0
- package/src/matrix/client/shared.test.ts +344 -0
- package/src/matrix/client/shared.ts +306 -0
- package/src/matrix/client/storage.test.ts +634 -0
- package/src/matrix/client/storage.ts +544 -0
- package/src/matrix/client/types.ts +50 -0
- package/src/matrix/client-bootstrap.test.ts +84 -0
- package/src/matrix/client-bootstrap.ts +164 -0
- package/src/matrix/client-resolver.test-helpers.ts +147 -0
- package/src/matrix/client.test.ts +1521 -0
- package/src/matrix/client.ts +23 -0
- package/src/matrix/config-paths.ts +31 -0
- package/src/matrix/config-update.test.ts +237 -0
- package/src/matrix/config-update.ts +291 -0
- package/src/matrix/credentials-read.ts +206 -0
- package/src/matrix/credentials-write.runtime.ts +26 -0
- package/src/matrix/credentials.test.ts +501 -0
- package/src/matrix/credentials.ts +95 -0
- package/src/matrix/deps.test.ts +74 -0
- package/src/matrix/deps.ts +225 -0
- package/src/matrix/device-health.test.ts +45 -0
- package/src/matrix/device-health.ts +31 -0
- package/src/matrix/direct-management.test.ts +350 -0
- package/src/matrix/direct-management.ts +347 -0
- package/src/matrix/direct-room.test.ts +61 -0
- package/src/matrix/direct-room.ts +128 -0
- package/src/matrix/draft-stream.test.ts +406 -0
- package/src/matrix/draft-stream.ts +216 -0
- package/src/matrix/encryption-guidance.ts +27 -0
- package/src/matrix/errors.ts +21 -0
- package/src/matrix/format.test.ts +340 -0
- package/src/matrix/format.ts +428 -0
- package/src/matrix/legacy-crypto-inspector.ts +95 -0
- package/src/matrix/media-errors.ts +20 -0
- package/src/matrix/media-text.ts +169 -0
- package/src/matrix/monitor/access-state.test.ts +45 -0
- package/src/matrix/monitor/access-state.ts +77 -0
- package/src/matrix/monitor/ack-config.test.ts +57 -0
- package/src/matrix/monitor/ack-config.ts +26 -0
- package/src/matrix/monitor/allowlist.test.ts +45 -0
- package/src/matrix/monitor/allowlist.ts +94 -0
- package/src/matrix/monitor/auto-join.test.ts +203 -0
- package/src/matrix/monitor/auto-join.ts +86 -0
- package/src/matrix/monitor/config.test.ts +197 -0
- package/src/matrix/monitor/config.ts +303 -0
- package/src/matrix/monitor/context-summary.ts +43 -0
- package/src/matrix/monitor/direct.test.ts +529 -0
- package/src/matrix/monitor/direct.ts +270 -0
- package/src/matrix/monitor/events.test.ts +1524 -0
- package/src/matrix/monitor/events.ts +213 -0
- package/src/matrix/monitor/handler.body-for-agent.test.ts +396 -0
- package/src/matrix/monitor/handler.group-history.test.ts +648 -0
- package/src/matrix/monitor/handler.media-failure.test.ts +267 -0
- package/src/matrix/monitor/handler.test-helpers.ts +308 -0
- package/src/matrix/monitor/handler.test.ts +2952 -0
- package/src/matrix/monitor/handler.thread-root-media.test.ts +82 -0
- package/src/matrix/monitor/handler.ts +1679 -0
- package/src/matrix/monitor/inbound-dedupe.test.ts +146 -0
- package/src/matrix/monitor/inbound-dedupe.ts +267 -0
- package/src/matrix/monitor/index.test.ts +920 -0
- package/src/matrix/monitor/index.ts +434 -0
- package/src/matrix/monitor/legacy-crypto-restore.test.ts +206 -0
- package/src/matrix/monitor/legacy-crypto-restore.ts +139 -0
- package/src/matrix/monitor/location.ts +100 -0
- package/src/matrix/monitor/media.test.ts +159 -0
- package/src/matrix/monitor/media.ts +119 -0
- package/src/matrix/monitor/mentions.test.ts +289 -0
- package/src/matrix/monitor/mentions.ts +177 -0
- package/src/matrix/monitor/reaction-events.test.ts +326 -0
- package/src/matrix/monitor/reaction-events.ts +187 -0
- package/src/matrix/monitor/recent-invite.test.ts +92 -0
- package/src/matrix/monitor/recent-invite.ts +30 -0
- package/src/matrix/monitor/replies.test.ts +265 -0
- package/src/matrix/monitor/replies.ts +136 -0
- package/src/matrix/monitor/reply-context.test.ts +276 -0
- package/src/matrix/monitor/reply-context.ts +92 -0
- package/src/matrix/monitor/room-history.test.ts +258 -0
- package/src/matrix/monitor/room-history.ts +301 -0
- package/src/matrix/monitor/room-info.test.ts +201 -0
- package/src/matrix/monitor/room-info.ts +126 -0
- package/src/matrix/monitor/rooms.test.ts +121 -0
- package/src/matrix/monitor/rooms.ts +52 -0
- package/src/matrix/monitor/route.test.ts +255 -0
- package/src/matrix/monitor/route.ts +178 -0
- package/src/matrix/monitor/runtime-api.ts +31 -0
- package/src/matrix/monitor/startup-verification.test.ts +294 -0
- package/src/matrix/monitor/startup-verification.ts +237 -0
- package/src/matrix/monitor/startup.test.ts +257 -0
- package/src/matrix/monitor/startup.ts +218 -0
- package/src/matrix/monitor/status.ts +111 -0
- package/src/matrix/monitor/sync-lifecycle.test.ts +224 -0
- package/src/matrix/monitor/sync-lifecycle.ts +91 -0
- package/src/matrix/monitor/task-runner.ts +38 -0
- package/src/matrix/monitor/thread-context.test.ts +149 -0
- package/src/matrix/monitor/thread-context.ts +108 -0
- package/src/matrix/monitor/threads.test.ts +68 -0
- package/src/matrix/monitor/threads.ts +85 -0
- package/src/matrix/monitor/types.ts +30 -0
- package/src/matrix/monitor/verification-events.ts +627 -0
- package/src/matrix/monitor/verification-utils.test.ts +47 -0
- package/src/matrix/monitor/verification-utils.ts +46 -0
- package/src/matrix/outbound-media-runtime.ts +1 -0
- package/src/matrix/poll-summary.ts +110 -0
- package/src/matrix/poll-types.test.ts +205 -0
- package/src/matrix/poll-types.ts +433 -0
- package/src/matrix/probe.runtime.ts +4 -0
- package/src/matrix/probe.test.ts +154 -0
- package/src/matrix/probe.ts +96 -0
- package/src/matrix/profile.test.ts +154 -0
- package/src/matrix/profile.ts +184 -0
- package/src/matrix/reaction-common.test.ts +96 -0
- package/src/matrix/reaction-common.ts +147 -0
- package/src/matrix/sdk/crypto-bootstrap.test.ts +505 -0
- package/src/matrix/sdk/crypto-bootstrap.ts +341 -0
- package/src/matrix/sdk/crypto-facade.test.ts +197 -0
- package/src/matrix/sdk/crypto-facade.ts +207 -0
- package/src/matrix/sdk/crypto-node.runtime.test.ts +27 -0
- package/src/matrix/sdk/crypto-node.runtime.ts +9 -0
- package/src/matrix/sdk/crypto-runtime.ts +11 -0
- package/src/matrix/sdk/decrypt-bridge.ts +356 -0
- package/src/matrix/sdk/event-helpers.test.ts +60 -0
- package/src/matrix/sdk/event-helpers.ts +71 -0
- package/src/matrix/sdk/http-client.test.ts +134 -0
- package/src/matrix/sdk/http-client.ts +87 -0
- package/src/matrix/sdk/idb-persistence-lock.ts +51 -0
- package/src/matrix/sdk/idb-persistence.lock-order.test.ts +108 -0
- package/src/matrix/sdk/idb-persistence.test-helpers.ts +88 -0
- package/src/matrix/sdk/idb-persistence.test.ts +149 -0
- package/src/matrix/sdk/idb-persistence.ts +283 -0
- package/src/matrix/sdk/logger.test.ts +25 -0
- package/src/matrix/sdk/logger.ts +108 -0
- package/src/matrix/sdk/read-response-with-limit.ts +19 -0
- package/src/matrix/sdk/recovery-key-store.test.ts +385 -0
- package/src/matrix/sdk/recovery-key-store.ts +430 -0
- package/src/matrix/sdk/transport.test.ts +161 -0
- package/src/matrix/sdk/transport.ts +344 -0
- package/src/matrix/sdk/types.ts +236 -0
- package/src/matrix/sdk/verification-manager.test.ts +509 -0
- package/src/matrix/sdk/verification-manager.ts +694 -0
- package/src/matrix/sdk/verification-status.ts +23 -0
- package/src/matrix/sdk.test.ts +2568 -0
- package/src/matrix/sdk.ts +1789 -0
- package/src/matrix/send/client.test.ts +174 -0
- package/src/matrix/send/client.ts +90 -0
- package/src/matrix/send/formatting.ts +189 -0
- package/src/matrix/send/media.ts +244 -0
- package/src/matrix/send/targets.test.ts +254 -0
- package/src/matrix/send/targets.ts +104 -0
- package/src/matrix/send/types.ts +134 -0
- package/src/matrix/send.test.ts +958 -0
- package/src/matrix/send.ts +609 -0
- package/src/matrix/session-store-metadata.ts +108 -0
- package/src/matrix/startup-abort.ts +44 -0
- package/src/matrix/sync-state.ts +27 -0
- package/src/matrix/target-ids.ts +102 -0
- package/src/matrix/thread-bindings-shared.ts +201 -0
- package/src/matrix/thread-bindings.test.ts +673 -0
- package/src/matrix/thread-bindings.ts +577 -0
- package/src/matrix-migration.runtime.ts +9 -0
- package/src/migration-config.test.ts +228 -0
- package/src/migration-config.ts +243 -0
- package/src/migration-snapshot-backup.ts +117 -0
- package/src/migration-snapshot.test.ts +184 -0
- package/src/migration-snapshot.ts +55 -0
- package/src/onboarding.resolve.test.ts +55 -0
- package/src/onboarding.test-harness.ts +158 -0
- package/src/onboarding.test.ts +665 -0
- package/src/onboarding.ts +773 -0
- package/src/outbound.test.ts +173 -0
- package/src/outbound.ts +78 -0
- package/src/plugin-entry.runtime.js +159 -0
- package/src/plugin-entry.runtime.test.ts +108 -0
- package/src/plugin-entry.runtime.ts +68 -0
- package/src/profile-update.ts +68 -0
- package/src/record-shared.ts +3 -0
- package/src/resolve-targets.test.ts +178 -0
- package/src/resolve-targets.ts +175 -0
- package/src/resolver.ts +21 -0
- package/src/runtime-api.ts +144 -0
- package/src/runtime.ts +7 -0
- package/src/secret-contract.ts +174 -0
- package/src/session-route.test.ts +315 -0
- package/src/session-route.ts +113 -0
- package/src/setup-bootstrap.ts +94 -0
- package/src/setup-config.ts +222 -0
- package/src/setup-contract.ts +89 -0
- package/src/setup-core.test.ts +326 -0
- package/src/setup-core.ts +50 -0
- package/src/setup-surface.ts +4 -0
- package/src/startup-maintenance.test.ts +227 -0
- package/src/startup-maintenance.ts +114 -0
- package/src/storage-paths.ts +92 -0
- package/src/test-helpers.ts +42 -0
- package/src/test-mocks.ts +55 -0
- package/src/test-runtime.ts +72 -0
- package/src/test-support/monitor-route-test-support.ts +8 -0
- package/src/tool-actions.runtime.ts +1 -0
- package/src/tool-actions.test.ts +422 -0
- package/src/tool-actions.ts +498 -0
- package/src/types.ts +230 -0
- package/test-api.ts +2 -0
- package/thread-bindings-runtime.ts +4 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
|
2
|
+
import type { PluginRuntime, RuntimeLogger } from "../../runtime-api.js";
|
|
3
|
+
import type { CoreConfig } from "../../types.js";
|
|
4
|
+
import type { MatrixAuth } from "../client.js";
|
|
5
|
+
import { formatMatrixEncryptedEventDisabledWarning } from "../encryption-guidance.js";
|
|
6
|
+
import type { MatrixClient } from "../sdk.js";
|
|
7
|
+
import type { MatrixRawEvent } from "./types.js";
|
|
8
|
+
import { EventType } from "./types.js";
|
|
9
|
+
import { createMatrixVerificationEventRouter } from "./verification-events.js";
|
|
10
|
+
|
|
11
|
+
function formatMatrixSelfDecryptionHint(accountId: string): string {
|
|
12
|
+
return (
|
|
13
|
+
"matrix: failed to decrypt a message from this same Matrix user. " +
|
|
14
|
+
"This usually means another Matrix device did not share the room key, or another OpenClaw runtime is using the same account. " +
|
|
15
|
+
`Check 'openclaw matrix verify status --verbose --account ${accountId}' and 'openclaw matrix devices list --account ${accountId}'.`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function resolveMatrixSelfUserId(
|
|
20
|
+
client: MatrixClient,
|
|
21
|
+
logVerboseMessage: (message: string) => void,
|
|
22
|
+
): Promise<string | null> {
|
|
23
|
+
if (typeof client.getUserId !== "function") {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return (await client.getUserId()) ?? null;
|
|
28
|
+
} catch (err) {
|
|
29
|
+
logVerboseMessage(`matrix: failed resolving self user id for decrypt warning: ${String(err)}`);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function registerMatrixMonitorEvents(params: {
|
|
35
|
+
cfg: CoreConfig;
|
|
36
|
+
client: MatrixClient;
|
|
37
|
+
auth: MatrixAuth;
|
|
38
|
+
allowFrom: string[];
|
|
39
|
+
dmEnabled: boolean;
|
|
40
|
+
dmPolicy: "open" | "pairing" | "allowlist" | "disabled";
|
|
41
|
+
readStoreAllowFrom: () => Promise<string[]>;
|
|
42
|
+
directTracker?: {
|
|
43
|
+
invalidateRoom: (roomId: string) => void;
|
|
44
|
+
rememberInvite?: (roomId: string, remoteUserId: string) => void;
|
|
45
|
+
};
|
|
46
|
+
logVerboseMessage: (message: string) => void;
|
|
47
|
+
warnedEncryptedRooms: Set<string>;
|
|
48
|
+
warnedCryptoMissingRooms: Set<string>;
|
|
49
|
+
logger: RuntimeLogger;
|
|
50
|
+
formatNativeDependencyHint: PluginRuntime["system"]["formatNativeDependencyHint"];
|
|
51
|
+
onRoomMessage: (roomId: string, event: MatrixRawEvent) => void | Promise<void>;
|
|
52
|
+
runDetachedTask?: (label: string, task: () => Promise<void>) => Promise<void>;
|
|
53
|
+
}): void {
|
|
54
|
+
const {
|
|
55
|
+
cfg,
|
|
56
|
+
client,
|
|
57
|
+
auth,
|
|
58
|
+
allowFrom,
|
|
59
|
+
dmEnabled,
|
|
60
|
+
dmPolicy,
|
|
61
|
+
readStoreAllowFrom,
|
|
62
|
+
directTracker,
|
|
63
|
+
logVerboseMessage,
|
|
64
|
+
warnedEncryptedRooms,
|
|
65
|
+
warnedCryptoMissingRooms,
|
|
66
|
+
logger,
|
|
67
|
+
formatNativeDependencyHint,
|
|
68
|
+
onRoomMessage,
|
|
69
|
+
runDetachedTask,
|
|
70
|
+
} = params;
|
|
71
|
+
const { routeVerificationEvent, routeVerificationSummary } = createMatrixVerificationEventRouter({
|
|
72
|
+
client,
|
|
73
|
+
allowFrom,
|
|
74
|
+
dmEnabled,
|
|
75
|
+
dmPolicy,
|
|
76
|
+
readStoreAllowFrom,
|
|
77
|
+
logVerboseMessage,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const runMonitorTask = (label: string, task: () => Promise<void>) => {
|
|
81
|
+
if (runDetachedTask) {
|
|
82
|
+
return runDetachedTask(label, task);
|
|
83
|
+
}
|
|
84
|
+
return Promise.resolve()
|
|
85
|
+
.then(task)
|
|
86
|
+
.catch((error) => {
|
|
87
|
+
logVerboseMessage(`matrix: ${label} failed (${String(error)})`);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
client.on("room.message", (roomId: string, event: MatrixRawEvent) => {
|
|
92
|
+
if (routeVerificationEvent(roomId, event)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
void runMonitorTask(
|
|
96
|
+
`room message handler room=${roomId} id=${event.event_id ?? "unknown"}`,
|
|
97
|
+
async () => {
|
|
98
|
+
await onRoomMessage(roomId, event);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
client.on("room.encrypted_event", (roomId: string, event: MatrixRawEvent) => {
|
|
104
|
+
const eventId = event?.event_id ?? "unknown";
|
|
105
|
+
const eventType = event?.type ?? "unknown";
|
|
106
|
+
logVerboseMessage(`matrix: encrypted event room=${roomId} type=${eventType} id=${eventId}`);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
client.on("room.decrypted_event", (roomId: string, event: MatrixRawEvent) => {
|
|
110
|
+
const eventId = event?.event_id ?? "unknown";
|
|
111
|
+
const eventType = event?.type ?? "unknown";
|
|
112
|
+
logVerboseMessage(`matrix: decrypted event room=${roomId} type=${eventType} id=${eventId}`);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
client.on(
|
|
116
|
+
"room.failed_decryption",
|
|
117
|
+
async (roomId: string, event: MatrixRawEvent, error: Error) => {
|
|
118
|
+
const selfUserId = await resolveMatrixSelfUserId(client, logVerboseMessage);
|
|
119
|
+
const sender = typeof event.sender === "string" ? event.sender : null;
|
|
120
|
+
const senderMatchesOwnUser = Boolean(selfUserId && sender && selfUserId === sender);
|
|
121
|
+
logger.warn("Failed to decrypt message", {
|
|
122
|
+
roomId,
|
|
123
|
+
eventId: event.event_id,
|
|
124
|
+
sender,
|
|
125
|
+
senderMatchesOwnUser,
|
|
126
|
+
error: error.message,
|
|
127
|
+
});
|
|
128
|
+
if (senderMatchesOwnUser) {
|
|
129
|
+
logger.warn(formatMatrixSelfDecryptionHint(auth.accountId), {
|
|
130
|
+
roomId,
|
|
131
|
+
eventId: event.event_id,
|
|
132
|
+
sender,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
logVerboseMessage(
|
|
136
|
+
`matrix: failed decrypt room=${roomId} id=${event.event_id ?? "unknown"} error=${error.message}`,
|
|
137
|
+
);
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
client.on("verification.summary", (summary) => {
|
|
142
|
+
void runMonitorTask("verification summary handler", async () => {
|
|
143
|
+
await routeVerificationSummary(summary);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
client.on("room.invite", (roomId: string, event: MatrixRawEvent) => {
|
|
148
|
+
directTracker?.invalidateRoom(roomId);
|
|
149
|
+
const eventId = event?.event_id ?? "unknown";
|
|
150
|
+
const sender = event?.sender ?? "unknown";
|
|
151
|
+
const invitee = normalizeOptionalString(event?.state_key) ?? "";
|
|
152
|
+
const senderIsInvitee =
|
|
153
|
+
Boolean(invitee) && (normalizeOptionalString(event?.sender) ?? "") === invitee;
|
|
154
|
+
const isDirect = (event?.content as { is_direct?: boolean } | undefined)?.is_direct === true;
|
|
155
|
+
const rememberedSender = normalizeOptionalString(event?.sender);
|
|
156
|
+
if (rememberedSender && !senderIsInvitee) {
|
|
157
|
+
directTracker?.rememberInvite?.(roomId, rememberedSender);
|
|
158
|
+
}
|
|
159
|
+
logVerboseMessage(
|
|
160
|
+
`matrix: invite room=${roomId} sender=${sender} direct=${String(isDirect)} id=${eventId}`,
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
client.on("room.join", (roomId: string, event: MatrixRawEvent) => {
|
|
165
|
+
directTracker?.invalidateRoom(roomId);
|
|
166
|
+
const eventId = event?.event_id ?? "unknown";
|
|
167
|
+
logVerboseMessage(`matrix: join room=${roomId} id=${eventId}`);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
client.on("room.event", (roomId: string, event: MatrixRawEvent) => {
|
|
171
|
+
const eventType = event?.type ?? "unknown";
|
|
172
|
+
if (eventType === EventType.RoomMessageEncrypted) {
|
|
173
|
+
logVerboseMessage(
|
|
174
|
+
`matrix: encrypted raw event room=${roomId} id=${event?.event_id ?? "unknown"}`,
|
|
175
|
+
);
|
|
176
|
+
if (auth.encryption !== true && !warnedEncryptedRooms.has(roomId)) {
|
|
177
|
+
warnedEncryptedRooms.add(roomId);
|
|
178
|
+
const warning = formatMatrixEncryptedEventDisabledWarning(cfg, auth.accountId);
|
|
179
|
+
logger.warn(warning, { roomId });
|
|
180
|
+
}
|
|
181
|
+
if (auth.encryption === true && !client.crypto && !warnedCryptoMissingRooms.has(roomId)) {
|
|
182
|
+
warnedCryptoMissingRooms.add(roomId);
|
|
183
|
+
const hint = formatNativeDependencyHint({
|
|
184
|
+
packageName: "@matrix-org/matrix-sdk-crypto-nodejs",
|
|
185
|
+
manager: "pnpm",
|
|
186
|
+
downloadCommand: "node node_modules/@matrix-org/matrix-sdk-crypto-nodejs/download-lib.js",
|
|
187
|
+
});
|
|
188
|
+
const warning = `matrix: encryption enabled but crypto is unavailable; ${hint}`;
|
|
189
|
+
logger.warn(warning, { roomId });
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (eventType === EventType.RoomMember) {
|
|
194
|
+
directTracker?.invalidateRoom(roomId);
|
|
195
|
+
const membership = (event?.content as { membership?: string } | undefined)?.membership;
|
|
196
|
+
const stateKey = (event as { state_key?: string }).state_key ?? "";
|
|
197
|
+
logVerboseMessage(
|
|
198
|
+
`matrix: member event room=${roomId} stateKey=${stateKey} membership=${membership ?? "unknown"}`,
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
if (eventType === EventType.Reaction) {
|
|
202
|
+
void runMonitorTask(
|
|
203
|
+
`reaction handler room=${roomId} id=${event.event_id ?? "unknown"}`,
|
|
204
|
+
async () => {
|
|
205
|
+
await onRoomMessage(roomId, event);
|
|
206
|
+
},
|
|
207
|
+
);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
routeVerificationEvent(roomId, event);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { installMatrixMonitorTestRuntime } from "../../test-runtime.js";
|
|
3
|
+
import type { MatrixClient } from "../sdk.js";
|
|
4
|
+
import {
|
|
5
|
+
createMatrixHandlerTestHarness,
|
|
6
|
+
createMatrixTextMessageEvent,
|
|
7
|
+
} from "./handler.test-helpers.js";
|
|
8
|
+
import type { MatrixRawEvent } from "./types.js";
|
|
9
|
+
|
|
10
|
+
describe("createMatrixRoomMessageHandler inbound body formatting", () => {
|
|
11
|
+
type MatrixHandlerHarness = ReturnType<typeof createMatrixHandlerTestHarness>;
|
|
12
|
+
type FinalizedReplyContext = {
|
|
13
|
+
ReplyToBody?: string;
|
|
14
|
+
ReplyToSender?: string;
|
|
15
|
+
ThreadStarterBody?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function createQuotedReplyVisibilityHarness(contextVisibility: "allowlist" | "allowlist_quote") {
|
|
19
|
+
return createMatrixHandlerTestHarness({
|
|
20
|
+
client: {
|
|
21
|
+
getEvent: async () =>
|
|
22
|
+
createMatrixTextMessageEvent({
|
|
23
|
+
eventId: "$quoted",
|
|
24
|
+
sender: "@mallory:example.org",
|
|
25
|
+
body: "Quoted payload",
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
isDirectMessage: false,
|
|
29
|
+
cfg: {
|
|
30
|
+
channels: {
|
|
31
|
+
matrix: {
|
|
32
|
+
contextVisibility,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
groupPolicy: "allowlist",
|
|
37
|
+
groupAllowFrom: ["@alice:example.org"],
|
|
38
|
+
roomsConfig: { "*": {} },
|
|
39
|
+
replyToMode: "all",
|
|
40
|
+
getMemberDisplayName: async (_roomId, userId) =>
|
|
41
|
+
userId === "@alice:example.org" ? "Alice" : "Mallory",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function sendQuotedReply(handler: MatrixHandlerHarness["handler"]) {
|
|
46
|
+
await handler(
|
|
47
|
+
"!room:example.org",
|
|
48
|
+
createMatrixTextMessageEvent({
|
|
49
|
+
eventId: "$reply1",
|
|
50
|
+
sender: "@alice:example.org",
|
|
51
|
+
body: "@room follow up",
|
|
52
|
+
relatesTo: {
|
|
53
|
+
"m.in_reply_to": { event_id: "$quoted" },
|
|
54
|
+
},
|
|
55
|
+
mentions: { room: true },
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function latestFinalizedReplyContext(
|
|
61
|
+
finalizeInboundContext: MatrixHandlerHarness["finalizeInboundContext"],
|
|
62
|
+
) {
|
|
63
|
+
return vi.mocked(finalizeInboundContext).mock.calls.at(-1)?.[0] as FinalizedReplyContext;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
installMatrixMonitorTestRuntime({
|
|
68
|
+
matchesMentionPatterns: () => false,
|
|
69
|
+
saveMediaBuffer: vi.fn(),
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("records thread metadata for group thread messages", async () => {
|
|
74
|
+
const { handler, finalizeInboundContext, recordInboundSession } =
|
|
75
|
+
createMatrixHandlerTestHarness({
|
|
76
|
+
client: {
|
|
77
|
+
getEvent: async () =>
|
|
78
|
+
createMatrixTextMessageEvent({
|
|
79
|
+
eventId: "$thread-root",
|
|
80
|
+
sender: "@alice:example.org",
|
|
81
|
+
body: "Root topic",
|
|
82
|
+
}),
|
|
83
|
+
},
|
|
84
|
+
isDirectMessage: false,
|
|
85
|
+
getMemberDisplayName: async (_roomId, userId) =>
|
|
86
|
+
userId === "@alice:example.org" ? "Alice" : "sender",
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
await handler(
|
|
90
|
+
"!room:example.org",
|
|
91
|
+
createMatrixTextMessageEvent({
|
|
92
|
+
eventId: "$reply1",
|
|
93
|
+
body: "@room follow up",
|
|
94
|
+
relatesTo: {
|
|
95
|
+
rel_type: "m.thread",
|
|
96
|
+
event_id: "$thread-root",
|
|
97
|
+
"m.in_reply_to": { event_id: "$thread-root" },
|
|
98
|
+
},
|
|
99
|
+
mentions: { room: true },
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(finalizeInboundContext).toHaveBeenCalledWith(
|
|
104
|
+
expect.objectContaining({
|
|
105
|
+
MessageThreadId: "$thread-root",
|
|
106
|
+
ThreadStarterBody: "Matrix thread root $thread-root from Alice:\nRoot topic",
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
// Thread messages get thread-scoped session keys (thread isolation feature).
|
|
110
|
+
expect(recordInboundSession).toHaveBeenCalledWith(
|
|
111
|
+
expect.objectContaining({
|
|
112
|
+
sessionKey: "agent:ops:main:thread:$thread-root",
|
|
113
|
+
}),
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("starts the thread-scoped session from the triggering message when threadReplies is always", async () => {
|
|
118
|
+
const { handler, finalizeInboundContext, recordInboundSession } =
|
|
119
|
+
createMatrixHandlerTestHarness({
|
|
120
|
+
isDirectMessage: false,
|
|
121
|
+
threadReplies: "always",
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
await handler(
|
|
125
|
+
"!room:example.org",
|
|
126
|
+
createMatrixTextMessageEvent({
|
|
127
|
+
eventId: "$thread-root",
|
|
128
|
+
body: "@room start thread",
|
|
129
|
+
mentions: { room: true },
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(finalizeInboundContext).toHaveBeenCalledWith(
|
|
134
|
+
expect.objectContaining({
|
|
135
|
+
MessageThreadId: "$thread-root",
|
|
136
|
+
ReplyToId: undefined,
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
expect(recordInboundSession).toHaveBeenCalledWith(
|
|
140
|
+
expect.objectContaining({
|
|
141
|
+
sessionKey: "agent:ops:main:thread:$thread-root",
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("records formatted poll results for inbound poll response events", async () => {
|
|
147
|
+
const { handler, finalizeInboundContext, recordInboundSession } =
|
|
148
|
+
createMatrixHandlerTestHarness({
|
|
149
|
+
client: {
|
|
150
|
+
getEvent: async () => ({
|
|
151
|
+
event_id: "$poll",
|
|
152
|
+
sender: "@bot:example.org",
|
|
153
|
+
type: "m.poll.start",
|
|
154
|
+
origin_server_ts: 1,
|
|
155
|
+
content: {
|
|
156
|
+
"m.poll.start": {
|
|
157
|
+
question: { "m.text": "Lunch?" },
|
|
158
|
+
kind: "m.poll.disclosed",
|
|
159
|
+
max_selections: 1,
|
|
160
|
+
answers: [
|
|
161
|
+
{ id: "a1", "m.text": "Pizza" },
|
|
162
|
+
{ id: "a2", "m.text": "Sushi" },
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
}),
|
|
167
|
+
getRelations: async () => ({
|
|
168
|
+
events: [
|
|
169
|
+
{
|
|
170
|
+
type: "m.poll.response",
|
|
171
|
+
event_id: "$vote1",
|
|
172
|
+
sender: "@user:example.org",
|
|
173
|
+
origin_server_ts: 2,
|
|
174
|
+
content: {
|
|
175
|
+
"m.poll.response": { answers: ["a1"] },
|
|
176
|
+
"m.relates_to": { rel_type: "m.reference", event_id: "$poll" },
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
nextBatch: null,
|
|
181
|
+
prevBatch: null,
|
|
182
|
+
}),
|
|
183
|
+
} as unknown as Partial<MatrixClient>,
|
|
184
|
+
isDirectMessage: true,
|
|
185
|
+
getMemberDisplayName: async (_roomId, userId) =>
|
|
186
|
+
userId === "@bot:example.org" ? "Bot" : "sender",
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
await handler("!room:example.org", {
|
|
190
|
+
type: "m.poll.response",
|
|
191
|
+
sender: "@user:example.org",
|
|
192
|
+
event_id: "$vote1",
|
|
193
|
+
origin_server_ts: 2,
|
|
194
|
+
content: {
|
|
195
|
+
"m.poll.response": { answers: ["a1"] },
|
|
196
|
+
"m.relates_to": { rel_type: "m.reference", event_id: "$poll" },
|
|
197
|
+
},
|
|
198
|
+
} as MatrixRawEvent);
|
|
199
|
+
|
|
200
|
+
expect(finalizeInboundContext).toHaveBeenCalledWith(
|
|
201
|
+
expect.objectContaining({
|
|
202
|
+
RawBody: expect.stringMatching(/1\. Pizza \(1 vote\)[\s\S]*Total voters: 1/),
|
|
203
|
+
}),
|
|
204
|
+
);
|
|
205
|
+
expect(recordInboundSession).toHaveBeenCalledWith(
|
|
206
|
+
expect.objectContaining({
|
|
207
|
+
sessionKey: "agent:ops:main",
|
|
208
|
+
}),
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("records reply context for quoted poll start events inside always-threaded replies", async () => {
|
|
213
|
+
const { handler, finalizeInboundContext } = createMatrixHandlerTestHarness({
|
|
214
|
+
client: {
|
|
215
|
+
getEvent: async (_roomId: string, eventId: string) => {
|
|
216
|
+
if (eventId === "$thread-root") {
|
|
217
|
+
return createMatrixTextMessageEvent({
|
|
218
|
+
eventId: "$thread-root",
|
|
219
|
+
sender: "@bob:example.org",
|
|
220
|
+
body: "Root topic",
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return {
|
|
225
|
+
event_id: "$poll",
|
|
226
|
+
sender: "@alice:example.org",
|
|
227
|
+
type: "m.poll.start",
|
|
228
|
+
origin_server_ts: 1,
|
|
229
|
+
content: {
|
|
230
|
+
"m.poll.start": {
|
|
231
|
+
question: { "m.text": "Lunch?" },
|
|
232
|
+
kind: "m.poll.disclosed",
|
|
233
|
+
max_selections: 1,
|
|
234
|
+
answers: [
|
|
235
|
+
{ id: "a1", "m.text": "Pizza" },
|
|
236
|
+
{ id: "a2", "m.text": "Sushi" },
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
} satisfies MatrixRawEvent;
|
|
241
|
+
},
|
|
242
|
+
} as unknown as Partial<MatrixClient>,
|
|
243
|
+
isDirectMessage: false,
|
|
244
|
+
threadReplies: "always",
|
|
245
|
+
getMemberDisplayName: async (_roomId, userId) => {
|
|
246
|
+
if (userId === "@alice:example.org") {
|
|
247
|
+
return "Alice";
|
|
248
|
+
}
|
|
249
|
+
if (userId === "@bob:example.org") {
|
|
250
|
+
return "Bob";
|
|
251
|
+
}
|
|
252
|
+
return "sender";
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
await handler(
|
|
257
|
+
"!room:example.org",
|
|
258
|
+
createMatrixTextMessageEvent({
|
|
259
|
+
eventId: "$reply1",
|
|
260
|
+
body: "@room follow up",
|
|
261
|
+
relatesTo: {
|
|
262
|
+
rel_type: "m.thread",
|
|
263
|
+
event_id: "$thread-root",
|
|
264
|
+
"m.in_reply_to": { event_id: "$poll" },
|
|
265
|
+
},
|
|
266
|
+
mentions: { room: true },
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
expect(finalizeInboundContext).toHaveBeenCalledWith(
|
|
271
|
+
expect.objectContaining({
|
|
272
|
+
MessageThreadId: "$thread-root",
|
|
273
|
+
ReplyToId: undefined,
|
|
274
|
+
ReplyToSender: "Alice",
|
|
275
|
+
ReplyToBody: "[Poll]\nLunch?\n\n1. Pizza\n2. Sushi",
|
|
276
|
+
ThreadStarterBody: "Matrix thread root $thread-root from Bob:\nRoot topic",
|
|
277
|
+
}),
|
|
278
|
+
);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("reuses the fetched thread root when reply context points at the same event", async () => {
|
|
282
|
+
const getEvent = vi.fn(async () =>
|
|
283
|
+
createMatrixTextMessageEvent({
|
|
284
|
+
eventId: "$thread-root",
|
|
285
|
+
sender: "@alice:example.org",
|
|
286
|
+
body: "Root topic",
|
|
287
|
+
}),
|
|
288
|
+
);
|
|
289
|
+
const getMemberDisplayName = vi.fn(async (_roomId: string, userId: string) =>
|
|
290
|
+
userId === "@alice:example.org" ? "Alice" : "sender",
|
|
291
|
+
);
|
|
292
|
+
const { handler, finalizeInboundContext } = createMatrixHandlerTestHarness({
|
|
293
|
+
client: { getEvent },
|
|
294
|
+
isDirectMessage: false,
|
|
295
|
+
threadReplies: "always",
|
|
296
|
+
getMemberDisplayName,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
await handler(
|
|
300
|
+
"!room:example.org",
|
|
301
|
+
createMatrixTextMessageEvent({
|
|
302
|
+
eventId: "$reply1",
|
|
303
|
+
body: "@room follow up",
|
|
304
|
+
relatesTo: {
|
|
305
|
+
rel_type: "m.thread",
|
|
306
|
+
event_id: "$thread-root",
|
|
307
|
+
"m.in_reply_to": { event_id: "$thread-root" },
|
|
308
|
+
},
|
|
309
|
+
mentions: { room: true },
|
|
310
|
+
}),
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
expect(finalizeInboundContext).toHaveBeenCalledWith(
|
|
314
|
+
expect.objectContaining({
|
|
315
|
+
MessageThreadId: "$thread-root",
|
|
316
|
+
ReplyToId: undefined,
|
|
317
|
+
ReplyToSender: "Alice",
|
|
318
|
+
ReplyToBody: "Root topic",
|
|
319
|
+
ThreadStarterBody: "Matrix thread root $thread-root from Alice:\nRoot topic",
|
|
320
|
+
}),
|
|
321
|
+
);
|
|
322
|
+
expect(getEvent).toHaveBeenCalledTimes(1);
|
|
323
|
+
expect(getMemberDisplayName).toHaveBeenCalledTimes(2);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it("drops thread and reply context fetched from non-allowlisted room senders", async () => {
|
|
327
|
+
const { handler, finalizeInboundContext } = createMatrixHandlerTestHarness({
|
|
328
|
+
client: {
|
|
329
|
+
getEvent: async () =>
|
|
330
|
+
createMatrixTextMessageEvent({
|
|
331
|
+
eventId: "$thread-root",
|
|
332
|
+
sender: "@mallory:example.org",
|
|
333
|
+
body: "Malicious root topic",
|
|
334
|
+
}),
|
|
335
|
+
},
|
|
336
|
+
isDirectMessage: false,
|
|
337
|
+
cfg: {
|
|
338
|
+
channels: {
|
|
339
|
+
matrix: {
|
|
340
|
+
contextVisibility: "allowlist",
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
groupPolicy: "allowlist",
|
|
345
|
+
groupAllowFrom: ["@alice:example.org"],
|
|
346
|
+
roomsConfig: { "*": {} },
|
|
347
|
+
getMemberDisplayName: async (_roomId, userId) =>
|
|
348
|
+
userId === "@alice:example.org" ? "Alice" : "Mallory",
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
await handler(
|
|
352
|
+
"!room:example.org",
|
|
353
|
+
createMatrixTextMessageEvent({
|
|
354
|
+
eventId: "$reply1",
|
|
355
|
+
sender: "@alice:example.org",
|
|
356
|
+
body: "@room follow up",
|
|
357
|
+
relatesTo: {
|
|
358
|
+
rel_type: "m.thread",
|
|
359
|
+
event_id: "$thread-root",
|
|
360
|
+
"m.in_reply_to": { event_id: "$thread-root" },
|
|
361
|
+
},
|
|
362
|
+
mentions: { room: true },
|
|
363
|
+
}),
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
const finalized = vi.mocked(finalizeInboundContext).mock.calls.at(-1)?.[0] as {
|
|
367
|
+
ReplyToBody?: string;
|
|
368
|
+
ReplyToSender?: string;
|
|
369
|
+
ThreadStarterBody?: string;
|
|
370
|
+
};
|
|
371
|
+
expect(finalized.ThreadStarterBody).toBeUndefined();
|
|
372
|
+
expect(finalized.ReplyToBody).toBeUndefined();
|
|
373
|
+
expect(finalized.ReplyToSender).toBeUndefined();
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it("drops quoted reply context fetched from non-allowlisted room senders", async () => {
|
|
377
|
+
const { handler, finalizeInboundContext } = createQuotedReplyVisibilityHarness("allowlist");
|
|
378
|
+
|
|
379
|
+
await sendQuotedReply(handler);
|
|
380
|
+
|
|
381
|
+
const finalized = latestFinalizedReplyContext(finalizeInboundContext);
|
|
382
|
+
expect(finalized.ReplyToBody).toBeUndefined();
|
|
383
|
+
expect(finalized.ReplyToSender).toBeUndefined();
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it("keeps quoted reply context in allowlist_quote mode", async () => {
|
|
387
|
+
const { handler, finalizeInboundContext } =
|
|
388
|
+
createQuotedReplyVisibilityHarness("allowlist_quote");
|
|
389
|
+
|
|
390
|
+
await sendQuotedReply(handler);
|
|
391
|
+
|
|
392
|
+
const finalized = latestFinalizedReplyContext(finalizeInboundContext);
|
|
393
|
+
expect(finalized.ReplyToBody).toBe("Quoted payload");
|
|
394
|
+
expect(finalized.ReplyToSender).toBe("Mallory");
|
|
395
|
+
});
|
|
396
|
+
});
|