chore: generate

This commit is contained in:
opencode-agent[bot] 2026-05-03 00:32:24 +00:00
commit a6464062b7
3 changed files with 857 additions and 518 deletions

File diff suppressed because it is too large Load diff

View file

@ -61,7 +61,11 @@ const make = <R, E>(testLayer: Layer.Layer<R, E>, liveLayer: Layer.Layer<R, E>)
opts?: number | TestOptions, opts?: number | TestOptions,
) => { ) => {
const args = instanceArgs(options, opts) const args = instanceArgs(options, opts)
return test(name, () => run(body(value).pipe(withTmpdirInstance(args.instanceOptions)), liveLayer), args.testOptions) return test(
name,
() => run(body(value).pipe(withTmpdirInstance(args.instanceOptions)), liveLayer),
args.testOptions,
)
} }
instance.only = <A, E2>( instance.only = <A, E2>(
@ -71,7 +75,11 @@ const make = <R, E>(testLayer: Layer.Layer<R, E>, liveLayer: Layer.Layer<R, E>)
opts?: number | TestOptions, opts?: number | TestOptions,
) => { ) => {
const args = instanceArgs(options, opts) const args = instanceArgs(options, opts)
return test.only(name, () => run(body(value).pipe(withTmpdirInstance(args.instanceOptions)), liveLayer), args.testOptions) return test.only(
name,
() => run(body(value).pipe(withTmpdirInstance(args.instanceOptions)), liveLayer),
args.testOptions,
)
} }
instance.skip = <A, E2>( instance.skip = <A, E2>(
@ -81,7 +89,11 @@ const make = <R, E>(testLayer: Layer.Layer<R, E>, liveLayer: Layer.Layer<R, E>)
opts?: number | TestOptions, opts?: number | TestOptions,
) => { ) => {
const args = instanceArgs(options, opts) const args = instanceArgs(options, opts)
return test.skip(name, () => run(body(value).pipe(withTmpdirInstance(args.instanceOptions)), liveLayer), args.testOptions) return test.skip(
name,
() => run(body(value).pipe(withTmpdirInstance(args.instanceOptions)), liveLayer),
args.testOptions,
)
} }
return { effect, live, instance } return { effect, live, instance }

View file

@ -54,11 +54,36 @@ const waitForPending = (count: number) =>
return yield* Effect.fail(new Error(`timed out waiting for ${count} pending question request(s)`)) return yield* Effect.fail(new Error(`timed out waiting for ${count} pending question request(s)`))
}) })
it.instance("ask - remains pending until answered", () => it.instance(
Effect.gen(function* () { "ask - remains pending until answered",
const fiber = yield* askEffect({ () =>
sessionID: SessionID.make("ses_test"), Effect.gen(function* () {
questions: [ const fiber = yield* askEffect({
sessionID: SessionID.make("ses_test"),
questions: [
{
question: "What would you like to do?",
header: "Action",
options: [
{ label: "Option 1", description: "First option" },
{ label: "Option 2", description: "Second option" },
],
},
],
}).pipe(Effect.forkScoped)
expect(yield* waitForPending(1)).toHaveLength(1)
yield* rejectAll
expect((yield* Fiber.await(fiber))._tag).toBe("Failure")
}),
{ git: true },
)
it.instance(
"ask - adds to pending list",
() =>
Effect.gen(function* () {
const questions = [
{ {
question: "What would you like to do?", question: "What would you like to do?",
header: "Action", header: "Action",
@ -67,81 +92,29 @@ it.instance("ask - remains pending until answered", () =>
{ label: "Option 2", description: "Second option" }, { label: "Option 2", description: "Second option" },
], ],
}, },
], ]
}).pipe(Effect.forkScoped)
expect(yield* waitForPending(1)).toHaveLength(1) const fiber = yield* askEffect({
yield* rejectAll sessionID: SessionID.make("ses_test"),
expect((yield* Fiber.await(fiber))._tag).toBe("Failure") questions,
}), }).pipe(Effect.forkScoped)
{ git: true },
)
it.instance("ask - adds to pending list", () => const pending = yield* waitForPending(1)
Effect.gen(function* () { expect(pending.length).toBe(1)
const questions = [ expect(pending[0].questions).toEqual(questions)
{ yield* rejectAll
question: "What would you like to do?", expect((yield* Fiber.await(fiber))._tag).toBe("Failure")
header: "Action", }),
options: [
{ label: "Option 1", description: "First option" },
{ label: "Option 2", description: "Second option" },
],
},
]
const fiber = yield* askEffect({
sessionID: SessionID.make("ses_test"),
questions,
}).pipe(Effect.forkScoped)
const pending = yield* waitForPending(1)
expect(pending.length).toBe(1)
expect(pending[0].questions).toEqual(questions)
yield* rejectAll
expect((yield* Fiber.await(fiber))._tag).toBe("Failure")
}),
{ git: true }, { git: true },
) )
// reply tests // reply tests
it.instance("reply - resolves the pending ask with answers", () => it.instance(
Effect.gen(function* () { "reply - resolves the pending ask with answers",
const questions = [ () =>
{ Effect.gen(function* () {
question: "What would you like to do?", const questions = [
header: "Action",
options: [
{ label: "Option 1", description: "First option" },
{ label: "Option 2", description: "Second option" },
],
},
]
const fiber = yield* askEffect({
sessionID: SessionID.make("ses_test"),
questions,
}).pipe(Effect.forkScoped)
const pending = yield* waitForPending(1)
const requestID = pending[0].id
yield* replyEffect({
requestID,
answers: [["Option 1"]],
})
expect(yield* Fiber.join(fiber)).toEqual([["Option 1"]])
}),
{ git: true },
)
it.instance("reply - removes from pending list", () =>
Effect.gen(function* () {
const fiber = yield* askEffect({
sessionID: SessionID.make("ses_test"),
questions: [
{ {
question: "What would you like to do?", question: "What would you like to do?",
header: "Action", header: "Action",
@ -150,170 +123,219 @@ it.instance("reply - removes from pending list", () =>
{ label: "Option 2", description: "Second option" }, { label: "Option 2", description: "Second option" },
], ],
}, },
], ]
}).pipe(Effect.forkScoped)
const pending = yield* waitForPending(1) const fiber = yield* askEffect({
expect(pending.length).toBe(1) sessionID: SessionID.make("ses_test"),
questions,
}).pipe(Effect.forkScoped)
yield* replyEffect({ const pending = yield* waitForPending(1)
requestID: pending[0].id, const requestID = pending[0].id
answers: [["Option 1"]],
})
yield* Fiber.join(fiber)
const after = yield* listEffect yield* replyEffect({
expect(after.length).toBe(0) requestID,
}), answers: [["Option 1"]],
})
expect(yield* Fiber.join(fiber)).toEqual([["Option 1"]])
}),
{ git: true }, { git: true },
) )
it.instance("reply - does nothing for unknown requestID", () => it.instance(
replyEffect({ "reply - removes from pending list",
requestID: QuestionID.make("que_unknown"), () =>
answers: [["Option 1"]], Effect.gen(function* () {
}), const fiber = yield* askEffect({
sessionID: SessionID.make("ses_test"),
questions: [
{
question: "What would you like to do?",
header: "Action",
options: [
{ label: "Option 1", description: "First option" },
{ label: "Option 2", description: "Second option" },
],
},
],
}).pipe(Effect.forkScoped)
const pending = yield* waitForPending(1)
expect(pending.length).toBe(1)
yield* replyEffect({
requestID: pending[0].id,
answers: [["Option 1"]],
})
yield* Fiber.join(fiber)
const after = yield* listEffect
expect(after.length).toBe(0)
}),
{ git: true },
)
it.instance(
"reply - does nothing for unknown requestID",
() =>
replyEffect({
requestID: QuestionID.make("que_unknown"),
answers: [["Option 1"]],
}),
{ git: true }, { git: true },
) )
// reject tests // reject tests
it.instance("reject - throws RejectedError", () => it.instance(
Effect.gen(function* () { "reject - throws RejectedError",
const fiber = yield* askEffect({ () =>
sessionID: SessionID.make("ses_test"), Effect.gen(function* () {
questions: [ const fiber = yield* askEffect({
{ sessionID: SessionID.make("ses_test"),
question: "What would you like to do?", questions: [
header: "Action", {
options: [ question: "What would you like to do?",
{ label: "Option 1", description: "First option" }, header: "Action",
{ label: "Option 2", description: "Second option" }, options: [
], { label: "Option 1", description: "First option" },
}, { label: "Option 2", description: "Second option" },
], ],
}).pipe(Effect.forkScoped) },
],
}).pipe(Effect.forkScoped)
const pending = yield* waitForPending(1) const pending = yield* waitForPending(1)
yield* rejectEffect(pending[0].id) yield* rejectEffect(pending[0].id)
const exit = yield* Fiber.await(fiber) const exit = yield* Fiber.await(fiber)
expect(exit._tag).toBe("Failure") expect(exit._tag).toBe("Failure")
if (exit._tag === "Failure") expect(exit.cause.toString()).toContain("QuestionRejectedError") if (exit._tag === "Failure") expect(exit.cause.toString()).toContain("QuestionRejectedError")
}), }),
{ git: true }, { git: true },
) )
it.instance("reject - removes from pending list", () => it.instance(
Effect.gen(function* () { "reject - removes from pending list",
const fiber = yield* askEffect({ () =>
sessionID: SessionID.make("ses_test"), Effect.gen(function* () {
questions: [ const fiber = yield* askEffect({
{ sessionID: SessionID.make("ses_test"),
question: "What would you like to do?", questions: [
header: "Action", {
options: [ question: "What would you like to do?",
{ label: "Option 1", description: "First option" }, header: "Action",
{ label: "Option 2", description: "Second option" }, options: [
], { label: "Option 1", description: "First option" },
}, { label: "Option 2", description: "Second option" },
], ],
}).pipe(Effect.forkScoped) },
],
}).pipe(Effect.forkScoped)
const pending = yield* waitForPending(1) const pending = yield* waitForPending(1)
expect(pending.length).toBe(1) expect(pending.length).toBe(1)
yield* rejectEffect(pending[0].id) yield* rejectEffect(pending[0].id)
expect((yield* Fiber.await(fiber))._tag).toBe("Failure") expect((yield* Fiber.await(fiber))._tag).toBe("Failure")
const after = yield* listEffect const after = yield* listEffect
expect(after.length).toBe(0) expect(after.length).toBe(0)
}), }),
{ git: true }, { git: true },
) )
it.instance("reject - does nothing for unknown requestID", () => rejectEffect(QuestionID.make("que_unknown")), { git: true }) it.instance("reject - does nothing for unknown requestID", () => rejectEffect(QuestionID.make("que_unknown")), {
git: true,
})
// multiple questions tests // multiple questions tests
it.instance("ask - handles multiple questions", () => it.instance(
Effect.gen(function* () { "ask - handles multiple questions",
const questions = [ () =>
{ Effect.gen(function* () {
question: "What would you like to do?", const questions = [
header: "Action", {
options: [ question: "What would you like to do?",
{ label: "Build", description: "Build the project" }, header: "Action",
{ label: "Test", description: "Run tests" }, options: [
], { label: "Build", description: "Build the project" },
}, { label: "Test", description: "Run tests" },
{ ],
question: "Which environment?", },
header: "Env", {
options: [ question: "Which environment?",
{ label: "Dev", description: "Development" }, header: "Env",
{ label: "Prod", description: "Production" }, options: [
], { label: "Dev", description: "Development" },
}, { label: "Prod", description: "Production" },
] ],
},
]
const fiber = yield* askEffect({ const fiber = yield* askEffect({
sessionID: SessionID.make("ses_test"), sessionID: SessionID.make("ses_test"),
questions, questions,
}).pipe(Effect.forkScoped) }).pipe(Effect.forkScoped)
const pending = yield* waitForPending(1) const pending = yield* waitForPending(1)
yield* replyEffect({ yield* replyEffect({
requestID: pending[0].id, requestID: pending[0].id,
answers: [["Build"], ["Dev"]], answers: [["Build"], ["Dev"]],
}) })
expect(yield* Fiber.join(fiber)).toEqual([["Build"], ["Dev"]]) expect(yield* Fiber.join(fiber)).toEqual([["Build"], ["Dev"]])
}), }),
{ git: true }, { git: true },
) )
// list tests // list tests
it.instance("list - returns all pending requests", () => it.instance(
Effect.gen(function* () { "list - returns all pending requests",
const fiber1 = yield* askEffect({ () =>
sessionID: SessionID.make("ses_test1"), Effect.gen(function* () {
questions: [ const fiber1 = yield* askEffect({
{ sessionID: SessionID.make("ses_test1"),
question: "Question 1?", questions: [
header: "Q1", {
options: [{ label: "A", description: "A" }], question: "Question 1?",
}, header: "Q1",
], options: [{ label: "A", description: "A" }],
}).pipe(Effect.forkScoped) },
],
}).pipe(Effect.forkScoped)
const fiber2 = yield* askEffect({ const fiber2 = yield* askEffect({
sessionID: SessionID.make("ses_test2"), sessionID: SessionID.make("ses_test2"),
questions: [ questions: [
{ {
question: "Question 2?", question: "Question 2?",
header: "Q2", header: "Q2",
options: [{ label: "B", description: "B" }], options: [{ label: "B", description: "B" }],
}, },
], ],
}).pipe(Effect.forkScoped) }).pipe(Effect.forkScoped)
const pending = yield* waitForPending(2) const pending = yield* waitForPending(2)
expect(pending.length).toBe(2) expect(pending.length).toBe(2)
yield* rejectAll yield* rejectAll
expect((yield* Fiber.await(fiber1))._tag).toBe("Failure") expect((yield* Fiber.await(fiber1))._tag).toBe("Failure")
expect((yield* Fiber.await(fiber2))._tag).toBe("Failure") expect((yield* Fiber.await(fiber2))._tag).toBe("Failure")
}), }),
{ git: true }, { git: true },
) )
it.instance("list - returns empty when no pending", () => it.instance(
Effect.gen(function* () { "list - returns empty when no pending",
const pending = yield* listEffect () =>
expect(pending.length).toBe(0) Effect.gen(function* () {
}), const pending = yield* listEffect
expect(pending.length).toBe(0)
}),
{ git: true }, { git: true },
) )