mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-05 16:36:52 +00:00
Move service state into InstanceState, flatten service facades (#18483)
This commit is contained in:
@@ -320,3 +320,134 @@ test("list - returns empty when no pending", async () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test("questions stay isolated by directory", async () => {
|
||||
await using one = await tmpdir({ git: true })
|
||||
await using two = await tmpdir({ git: true })
|
||||
|
||||
const p1 = Instance.provide({
|
||||
directory: one.path,
|
||||
fn: () =>
|
||||
Question.ask({
|
||||
sessionID: SessionID.make("ses_one"),
|
||||
questions: [
|
||||
{
|
||||
question: "Question 1?",
|
||||
header: "Q1",
|
||||
options: [{ label: "A", description: "A" }],
|
||||
},
|
||||
],
|
||||
}),
|
||||
})
|
||||
|
||||
const p2 = Instance.provide({
|
||||
directory: two.path,
|
||||
fn: () =>
|
||||
Question.ask({
|
||||
sessionID: SessionID.make("ses_two"),
|
||||
questions: [
|
||||
{
|
||||
question: "Question 2?",
|
||||
header: "Q2",
|
||||
options: [{ label: "B", description: "B" }],
|
||||
},
|
||||
],
|
||||
}),
|
||||
})
|
||||
|
||||
const onePending = await Instance.provide({
|
||||
directory: one.path,
|
||||
fn: () => Question.list(),
|
||||
})
|
||||
const twoPending = await Instance.provide({
|
||||
directory: two.path,
|
||||
fn: () => Question.list(),
|
||||
})
|
||||
|
||||
expect(onePending.length).toBe(1)
|
||||
expect(twoPending.length).toBe(1)
|
||||
expect(onePending[0].sessionID).toBe(SessionID.make("ses_one"))
|
||||
expect(twoPending[0].sessionID).toBe(SessionID.make("ses_two"))
|
||||
|
||||
await Instance.provide({
|
||||
directory: one.path,
|
||||
fn: () => Question.reject(onePending[0].id),
|
||||
})
|
||||
await Instance.provide({
|
||||
directory: two.path,
|
||||
fn: () => Question.reject(twoPending[0].id),
|
||||
})
|
||||
|
||||
await p1.catch(() => {})
|
||||
await p2.catch(() => {})
|
||||
})
|
||||
|
||||
test("pending question rejects on instance dispose", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
|
||||
const ask = Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: () => {
|
||||
return Question.ask({
|
||||
sessionID: SessionID.make("ses_dispose"),
|
||||
questions: [
|
||||
{
|
||||
question: "Dispose me?",
|
||||
header: "Dispose",
|
||||
options: [{ label: "Yes", description: "Yes" }],
|
||||
},
|
||||
],
|
||||
})
|
||||
},
|
||||
})
|
||||
const result = ask.then(
|
||||
() => "resolved" as const,
|
||||
(err) => err,
|
||||
)
|
||||
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const pending = await Question.list()
|
||||
expect(pending).toHaveLength(1)
|
||||
await Instance.dispose()
|
||||
},
|
||||
})
|
||||
|
||||
expect(await result).toBeInstanceOf(Question.RejectedError)
|
||||
})
|
||||
|
||||
test("pending question rejects on instance reload", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
|
||||
const ask = Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: () => {
|
||||
return Question.ask({
|
||||
sessionID: SessionID.make("ses_reload"),
|
||||
questions: [
|
||||
{
|
||||
question: "Reload me?",
|
||||
header: "Reload",
|
||||
options: [{ label: "Yes", description: "Yes" }],
|
||||
},
|
||||
],
|
||||
})
|
||||
},
|
||||
})
|
||||
const result = ask.then(
|
||||
() => "resolved" as const,
|
||||
(err) => err,
|
||||
)
|
||||
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const pending = await Question.list()
|
||||
expect(pending).toHaveLength(1)
|
||||
await Instance.reload({ directory: tmp.path })
|
||||
},
|
||||
})
|
||||
|
||||
expect(await result).toBeInstanceOf(Question.RejectedError)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user