test(pty): migrate shell tests to Effect runner (#27238)

This commit is contained in:
Kit Langton
2026-05-12 23:20:20 -04:00
committed by GitHub
parent 77e51b0a32
commit 8249baeb4e

View File

@@ -1,39 +1,35 @@
import { describe, expect, test } from "bun:test" import { describe, expect } from "bun:test"
import { AppRuntime } from "../../src/effect/app-runtime"
import { Effect } from "effect" import { Effect } from "effect"
import { Instance } from "../../src/project/instance"
import { WithInstance } from "../../src/project/with-instance"
import { Pty } from "../../src/pty" import { Pty } from "../../src/pty"
import { Shell } from "../../src/shell/shell" import { Shell } from "../../src/shell/shell"
import { tmpdir } from "../fixture/fixture" import { testEffect } from "../lib/effect"
Shell.preferred.reset() Shell.preferred.reset()
const it = testEffect(Pty.defaultLayer)
const createPty = (input: Pty.CreateInput) =>
Effect.acquireRelease(
Effect.gen(function* () {
const pty = yield* Pty.Service
const info = yield* pty.create(input)
return { pty, info }
}),
({ pty, info }) => pty.remove(info.id).pipe(Effect.ignore),
).pipe(Effect.map(({ info }) => info))
describe("pty shell args", () => { describe("pty shell args", () => {
if (process.platform !== "win32") return if (process.platform !== "win32") return
const ps = Bun.which("pwsh") || Bun.which("powershell") const ps = Bun.which("pwsh") || Bun.which("powershell")
if (ps) { if (ps) {
test( it.instance(
"does not add login args to pwsh", "does not add login args to pwsh",
async () => { () =>
await using dir = await tmpdir() Effect.gen(function* () {
await WithInstance.provide({ const info = yield* createPty({ command: ps, title: "pwsh" })
directory: dir.path, expect(info.args).toEqual([])
fn: () => }),
AppRuntime.runPromise(
Effect.gen(function* () {
const pty = yield* Pty.Service
const info = yield* pty.create({ command: ps, title: "pwsh" })
try {
expect(info.args).toEqual([])
} finally {
yield* pty.remove(info.id)
}
}),
),
})
},
{ timeout: 30000 }, { timeout: 30000 },
) )
} }
@@ -44,62 +40,36 @@ describe("pty shell args", () => {
return Shell.gitbash() return Shell.gitbash()
})() })()
if (bash) { if (bash) {
test( it.instance(
"adds login args to bash", "adds login args to bash",
async () => { () =>
await using dir = await tmpdir() Effect.gen(function* () {
await WithInstance.provide({ const info = yield* createPty({ command: bash, title: "bash" })
directory: dir.path, expect(info.args).toEqual(["-l"])
fn: () => }),
AppRuntime.runPromise(
Effect.gen(function* () {
const pty = yield* Pty.Service
const info = yield* pty.create({ command: bash, title: "bash" })
try {
expect(info.args).toEqual(["-l"])
} finally {
yield* pty.remove(info.id)
}
}),
),
})
},
{ timeout: 30000 }, { timeout: 30000 },
) )
} }
}) })
describe("pty configured shell", () => { describe("pty configured shell", () => {
test( const configured = process.platform === "win32" ? Bun.which("pwsh") || Bun.which("powershell") : Bun.which("bash")
"uses configured shell for default PTY command",
async () => {
const configured = process.platform === "win32" ? Bun.which("pwsh") || Bun.which("powershell") : Bun.which("bash")
if (!configured) return
await using dir = await tmpdir({ it.instance(
config: { shell: Shell.name(configured) }, "uses configured shell for default PTY command",
}) () =>
await WithInstance.provide({ Effect.gen(function* () {
directory: dir.path, if (!configured) return
fn: () =>
AppRuntime.runPromise( const info = yield* createPty({ title: "configured" })
Effect.gen(function* () { if (process.platform === "win32") {
const pty = yield* Pty.Service expect(info.command.toLowerCase()).toBe(configured.toLowerCase())
const info = yield* pty.create({ title: "configured" }) } else {
try { expect(info.command).toBe(configured)
if (process.platform === "win32") { }
expect(info.command.toLowerCase()).toBe(configured.toLowerCase()) expect(info.args).toEqual(process.platform === "win32" ? [] : ["-l"])
} else { }),
expect(info.command).toBe(configured) configured ? { config: { shell: Shell.name(configured) } } : undefined,
}
expect(info.args).toEqual(process.platform === "win32" ? [] : ["-l"])
} finally {
yield* pty.remove(info.id)
}
}),
),
})
},
{ timeout: 30000 }, { timeout: 30000 },
) )
}) })