Files
anomalyco_opencode/packages/drive/test/cli/check.test.ts
T
opencode-agent[bot] 9dd0e39867 chore: generate
2026-08-12 22:03:37 +00:00

30 lines
1.3 KiB
TypeScript

import { describe, expect, test } from "vitest"
import { effectScriptHint } from "../../src/cli/check.js"
const promiseDiagnostic = (line: number) =>
`/tmp/drive.ts:${line}:10 - error TS2322: Type 'Promise<void>' is not assignable to type 'Effect<void>'.`
describe("Effect script check hints", () => {
test.each([
['defineScript({ run: async ({ ui }) => { await ui.submit("Hello") } })', "run: ({ ui }) =>"],
["defineScript({ setup: () => Promise.resolve() })", "setup: ({ fs }) => fs.writeFile"],
[
"defineScript({ run: ({ ui }) => ui.waitFor(() => Promise.resolve(false)) })",
"ui.waitFor((state) => Effect.succeed",
],
])("describes the failing Promise callback", (callback, expected) => {
const source = `import { defineScript } from "opencode-drive"\n${callback}\n`
expect(effectScriptHint(source, promiseDiagnostic(2))).toContain(expected)
})
test("ignores Promise diagnostics on unrelated source lines", () => {
const source = [
'import { defineScript } from "opencode-drive"',
"// run: async () => {}",
"const value: Effect.Effect<void> = Promise.resolve()",
"defineScript({ run: () => Effect.void })",
].join("\n")
expect(effectScriptHint(source, promiseDiagnostic(3))).toBeUndefined()
})
})