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 Instance.provide({
@@ -106,15 +106,14 @@ describe("pty", () => {
fn: async () => {
const a = await Pty.create({ command: "cat", title: "a" })
try {
const outA: string[] = []
const outB: string[] = []
const out: string[] = []
const ctx = { connId: 1 }
const ws = {
readyState: 1,
data: ctx,
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: () => {
// no-op
@@ -122,19 +121,16 @@ describe("pty", () => {
}
Pty.connect(a.id, ws as any)
outA.length = 0
out.length = 0
// Simulate the runtime mutating per-connection data without
// swapping the reference (ws.data stays the same object).
// Mutating fields on ws.data should not look like a new
// connection lifecycle when the object identity stays stable.
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")
await Bun.sleep(100)
expect(outB.join("")).not.toContain("AAA")
expect(out.join("")).toContain("AAA")
} finally {
await Pty.remove(a.id)
}