Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
relay: slow sockets open together in the fuzz suite; admission-set update tests
milind-soni9e2d95bd28f4
diff --git a/relay/test/fuzz.test.ts b/relay/test/fuzz.test.tsindex 8dc5115b5c..1502a9e192 100644--- a/relay/test/fuzz.test.ts+++ b/relay/test/fuzz.test.ts@@ -265,6 +265,7 @@ describe("malformed frames before auth", () => {describe(`${SLOW_SOCKETS} slow sockets`, () => {test("upgraded sockets that say nothing, half-sent headers and half-sent frames are all gone within the deadlines", async () => {+ const opening = performance.now();const silent = await inBatches(SLOW_SOCKETS, () => Client.open(t.url, pick(PATHS)));const halfHeaders = await inBatches(Math.min(SLOW_SOCKETS, 500), async () => {const socket = await connected();@@ -273,24 +274,23 @@ describe(`${SLOW_SOCKETS} slow sockets`, () => {socket.once("close", () => (clearTimeout(timer), resolve(true)));});socket.write("GET /v1/phone HTTP/1.1\r\nHost: relay\r\nUpgrade: websocket\r\n");- return ended;+ return { ended };});const halfFrames = await inBatches(Math.min(SLOW_SOCKETS, 500), async () => {const socket = await rawUpgrade();const code = closeCodeOf(socket, 15_000);socket.write(frame(0x1, Buffer.alloc(2_000)).subarray(0, 100));- return code;+ return { code };});- const lastOpened = performance.now();const [silentCodes, frameCodes, headerEnds] = await Promise.all([Promise.all(silent.map((client) => client.closeCode(15_000))),- Promise.all(halfFrames),- Promise.all(halfHeaders),+ Promise.all(halfFrames.map(({ code }) => code)),+ Promise.all(halfHeaders.map(({ ended }) => ended)),]);assert.ok(silentCodes.every((code) => code === Close.Malformed), JSON.stringify([...new Set(silentCodes)]));assert.ok(frameCodes.every((code) => code === Close.Malformed), JSON.stringify([...new Set(frameCodes)]));assert.ok(headerEnds.every(Boolean), "a half-sent request outlived the header deadline");- assert.ok(performance.now() - lastOpened < 10_000);+ assert.ok(performance.now() - opening < 15_000, "every slow socket was opened before the first deadline and gone soon after it");for (let i = 0; i < 50 && t.relay.sockets().size > 0; i++) await sleep(100);assert.equal(t.relay.sockets().size, 0);});diff --git a/relay/test/splice.test.ts b/relay/test/splice.test.tsindex a970461e31..a471d0c109 100644--- a/relay/test/splice.test.ts+++ b/relay/test/splice.test.ts@@ -131,6 +131,38 @@ describe("limits that need a short clock", () => {}});+ test("a new set that still holds a phone leaves its session alone; only the set that drops it closes it", async () => {+ const t = await startTestRelay();+ try {+ const { phone, data, host, adm } = await splicedPair(t.url, t.key);+ const others = Array.from({ length: 31 }, () => randomBytes(32));+ host.admit([...others, adm]);+ host.admit([adm, ...others]);+ phone.sendBinary(Buffer.from("kept"));+ assert.equal((await data.next()).data.toString(), "kept");+ host.admit(others);+ assert.equal(await phone.closeCode(), Close.NotFound);+ assert.equal(await data.closeCode(), Close.NotFound);+ host.control.ws.close();+ } finally {+ await t.stop();+ }+ });++ test("a full set of 32 admits the phone in its last slot", async () => {+ const t = await startTestRelay();+ try {+ const adm = randomBytes(32);+ const host = await fakeHost(t.url, t.key, [...Array.from({ length: 31 }, () => randomBytes(32)), adm]);+ const phone = await phoneHello(t.url, host.hidText, adm);+ assert.equal((await host.control.json()).t, "open");+ phone.ws.close();+ host.control.ws.close();+ } finally {+ await t.stop();+ }+ });+test("an admit set that drops a phone closes its pending session too", async () => {const t = await startTestRelay();try {