fix: test

This commit is contained in:
Adam
2026-02-26 18:11:01 -06:00
parent adabad19f1
commit 37d42595cf

View File

@@ -98,7 +98,7 @@ describe("pty", () => {
}) })
}) })
test("does not leak output when socket data mutates in-place", async () => { test("treats in-place socket data mutation as the same connection", async () => {
await using dir = await tmpdir({ git: true }) await using dir = await tmpdir({ git: true })
await Instance.provide({ await Instance.provide({
@@ -106,15 +106,14 @@ describe("pty", () => {
fn: async () => { fn: async () => {
const a = await Pty.create({ command: "cat", title: "a" }) const a = await Pty.create({ command: "cat", title: "a" })
try { try {
const outA: string[] = [] const out: string[] = []
const outB: string[] = []
const ctx = { connId: 1 } const ctx = { connId: 1 }
const ws = { const ws = {
readyState: 1, readyState: 1,
data: ctx, data: ctx,
send: (data: unknown) => { send: (data: unknown) => {
outA.push(typeof data === "string" ? data : Buffer.from(data as Uint8Array).toString("utf8")) out.push(typeof data === "string" ? data : Buffer.from(data as Uint8Array).toString("utf8"))
}, },
close: () => { close: () => {
// no-op // no-op
@@ -122,19 +121,16 @@ describe("pty", () => {
} }
Pty.connect(a.id, ws as any) Pty.connect(a.id, ws as any)
outA.length = 0 out.length = 0
// Simulate the runtime mutating per-connection data without // Mutating fields on ws.data should not look like a new
// swapping the reference (ws.data stays the same object). // connection lifecycle when the object identity stays stable.
ctx.connId = 2 ctx.connId = 2
ws.send = (data: unknown) => {
outB.push(typeof data === "string" ? data : Buffer.from(data as Uint8Array).toString("utf8"))
}
Pty.write(a.id, "AAA\n") Pty.write(a.id, "AAA\n")
await Bun.sleep(100) await Bun.sleep(100)
expect(outB.join("")).not.toContain("AAA") expect(out.join("")).toContain("AAA")
} finally { } finally {
await Pty.remove(a.id) await Pty.remove(a.id)
} }