test(broker): smoke test for hello + direct message flow
Some checks failed
CI / Tests / 🧪 Test (push) Has been cancelled
Some checks failed
CI / Tests / 🧪 Test (push) Has been cancelled
Adds scripts/{seed-test-mesh,peer-a,peer-b,smoke-test}.ts|.sh that
prove an end-to-end message flow works against a real Postgres:
- seed-test-mesh.ts creates user+mesh+2 members with deterministic
hex pubkeys ("aa..aa", "bb..bb"), writes seed JSON to stdout
- peer-a.ts sends hello then a direct "send" message to peer B's
pubkey with fake ciphertext "hello-from-a"
- peer-b.ts sends hello, waits up to 5s for a push, asserts
senderPubkey matches peer A, exits 0/1
- smoke-test.sh wires the three together
Verified flow: hello registers presence row → send queues into
mesh.message_queue → fanout matches connected peer by pubkey →
drainForMember joins on mesh.member for senderPubkey → push lands
with ciphertext + correct sender attribution.
Also fixes a date-serialization bug that blocked the first run:
applyPendingHookStatus used `sql${col} >= ${jsDate}` which passed
JS Date.toString() to Postgres (failed to parse). Replaced raw
sql`` template with typed gte/desc/isNotNull operators from
drizzle-orm. Same fix applied in sweepPendingStatuses.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,18 @@
|
||||
* - Message envelopes are opaque ciphertext (client-side crypto).
|
||||
*/
|
||||
|
||||
import { and, asc, eq, inArray, isNull, lt, or, sql } from "drizzle-orm";
|
||||
import {
|
||||
and,
|
||||
asc,
|
||||
desc,
|
||||
eq,
|
||||
gte,
|
||||
inArray,
|
||||
isNotNull,
|
||||
isNull,
|
||||
lt,
|
||||
or,
|
||||
} from "drizzle-orm";
|
||||
import { db } from "./db";
|
||||
import {
|
||||
meshMember as memberTable,
|
||||
@@ -154,7 +165,7 @@ export async function handleHookSetStatus(
|
||||
.select({ id: presence.id, status: presence.status })
|
||||
.from(presence)
|
||||
.where(activeFilter)
|
||||
.orderBy(sql`${presence.connectedAt} DESC`)
|
||||
.orderBy(desc(presence.connectedAt))
|
||||
.limit(1);
|
||||
row = r as { id: string; status: PeerStatus } | undefined;
|
||||
}
|
||||
@@ -197,10 +208,10 @@ export async function applyPendingHookStatus(
|
||||
eq(pendingStatus.pid, pid),
|
||||
eq(pendingStatus.cwd, cwd),
|
||||
isNull(pendingStatus.appliedAt),
|
||||
sql`${pendingStatus.createdAt} >= ${cutoff}`,
|
||||
gte(pendingStatus.createdAt, cutoff),
|
||||
),
|
||||
)
|
||||
.orderBy(sql`${pendingStatus.createdAt} DESC`)
|
||||
.orderBy(desc(pendingStatus.createdAt))
|
||||
.limit(1);
|
||||
if (!row) return;
|
||||
await writeStatus(presenceId, row.status as PeerStatus, "hook", now);
|
||||
@@ -241,10 +252,7 @@ export async function sweepPendingStatuses(): Promise<void> {
|
||||
await db
|
||||
.delete(pendingStatus)
|
||||
.where(
|
||||
or(
|
||||
lt(pendingStatus.createdAt, cutoff),
|
||||
sql`${pendingStatus.appliedAt} IS NOT NULL`,
|
||||
)!,
|
||||
or(lt(pendingStatus.createdAt, cutoff), isNotNull(pendingStatus.appliedAt))!,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user