Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Phone web app yamux: refuse a second FIN before granting window; the computer refuses GoAway(removed)
Bugfixer 21417cd55ae4d
diff --git a/src/lib/e2e/yamux.test.ts b/src/lib/e2e/yamux.test.tsindex 2287b56770..ac15c22cf3 100644--- a/src/lib/e2e/yamux.test.ts+++ b/src/lib/e2e/yamux.test.ts@@ -5,6 +5,7 @@ import { concat, utf8 } from "./bytes.ts";import {decodeFrame,encodeFrame,+ GO_AWAY,INITIAL_WINDOW,MAX_DATA_PAYLOAD,Mux,@@ -241,4 +242,34 @@ describe("the browser mux, after the peer's FIN and inside callbacks", () => {writable.mux.receive({ type: 1, flags: 4, streamId: second, length: 10 });expect(writable.log).toEqual(["accepted 1", "writable 1", "reset 1"]);});++ it("refuses a second FIN on a WindowUpdate before granting its window", () => {+ const { mux, log } = phoneWith();+ const id = mux.open();+ mux.receive({ type: 1, flags: 2 | 4, streamId: id, length: 0 });+ expect(() => mux.receive({ type: 1, flags: 4, streamId: id, length: 10 })).toThrow(YamuxError);+ expect(log).toEqual(["accepted 1", "ended 1"]);+ });+});++describe("the browser mux, GoAway(removed)", () => {+ const withGoAway = (role: Role) => {+ const codes: number[] = [];+ const mux = new Mux(role, { send: () => {}, data: () => {}, ended: () => {}, reset: () => {}, writable: () => {}, goAway: (code) => codes.push(code) });+ return { mux, codes };+ };++ it("the phone takes GoAway(3) from the computer", () => {+ const { mux, codes } = withGoAway("phone");+ mux.receive({ type: 3, flags: 0, streamId: 0, length: GO_AWAY.removed });+ expect(codes).toEqual([GO_AWAY.removed]);+ });++ it("the computer refuses GoAway(3) from a phone as a protocol error", () => {+ const { mux, codes } = withGoAway("computer");+ expect(() => mux.receive({ type: 3, flags: 0, streamId: 0, length: GO_AWAY.removed })).toThrow(YamuxError);+ expect(codes).toEqual([]);+ mux.receive({ type: 3, flags: 0, streamId: 0, length: GO_AWAY.normal });+ expect(codes).toEqual([GO_AWAY.normal]);+ });});diff --git a/src/lib/e2e/yamux.ts b/src/lib/e2e/yamux.tsindex c0fc1c9c33..44d699a64b 100644--- a/src/lib/e2e/yamux.ts+++ b/src/lib/e2e/yamux.ts@@ -255,6 +255,7 @@ export class Mux {return;}if (frame.type === TYPE.goAway) {+ if (this.role === "computer" && frame.length === GO_AWAY.removed) throw new YamuxError("phone_removed");this.#peerGoneAway = true;this.#events.goAway?.(frame.length);return;@@ -317,8 +318,8 @@ export class Mux {this.#events.reset(streamId);return;}+ if (stream.remoteFin && (frame.type === TYPE.data || frame.flags & FLAG.fin)) throw new YamuxError("data_after_fin");if (frame.type === TYPE.data) {- if (stream.remoteFin) throw new YamuxError("data_after_fin");if (frame.length > stream.receiveWindow) throw new YamuxError("window_exceeded");stream.receiveWindow -= frame.length;if (frame.length > 0) this.#events.data(streamId, frame.data as Uint8Array);@@ -328,7 +329,6 @@ export class Mux {}if (!this.#still(streamId, stream)) return;if (frame.flags & FLAG.fin) {- if (stream.remoteFin) throw new YamuxError("data_after_fin");stream.remoteFin = true;this.#events.ended(streamId);this.#closeIfDone(streamId, stream);