Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion plugins/tasks/lifecycle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,4 @@ export async function registerLifecycle(
});

await reconcileTrackedThreads(bb, store);
await reconcileTrackedThreads(bb, store);
}
19 changes: 15 additions & 4 deletions plugins/tasks/lifecycle/lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ function trackedThreadFixture(
}

describe("task thread lifecycle", () => {
it("reconciles each non-terminal task thread once during startup", async () => {
const fixture = trackedThreadFixture("working", "active");

await registerLifecycle(fixture.bb, fixture.store);

expect(fixture.harness.sdk.callsTo("threads.get")).toEqual([
[{ threadId: "thr_worker" }],
]);

await fixture.harness.dispose();
});

it("moves a working thread to completed, comments, and publishes", async () => {
const fixture = trackedThreadFixture("working", "active");
await registerLifecycle(fixture.bb, fixture.store);
Expand Down Expand Up @@ -149,7 +161,6 @@ describe("task thread lifecycle", () => {

expect(fixture.harness.sdk.callsTo("threads.get")).toEqual([
[{ threadId: "thr_worker" }],
[{ threadId: "thr_worker" }],
]);
expect(
fixture.store.tasks.getTaskThread(fixture.taskThreadId)?.liveStatus,
Expand Down Expand Up @@ -210,7 +221,7 @@ describe("task thread lifecycle", () => {
"thread.failed": 1,
"thread.deleted": 1,
});
expect(host.harness.sdk.callsTo("threads.get")).toHaveLength(2);
expect(host.harness.sdk.callsTo("threads.get")).toHaveLength(1);
expect(store.tasks.getTaskThread(tracked.id)?.liveStatus).toBe("starting");

await host.harness.dispose();
Expand All @@ -231,7 +242,7 @@ describe("task thread lifecycle", () => {
expect(
fixture.store.tasks.getTaskThread(fixture.taskThreadId)?.liveStatus,
).toBe("working");
expect(fixture.harness.sdk.callsTo("threads.get")).toHaveLength(2);
expect(fixture.harness.sdk.callsTo("threads.get")).toHaveLength(1);
expect(fixture.harness.sdk.callsTo("subscribe")).toEqual([]);

await fixture.harness.dispose();
Expand All @@ -248,7 +259,7 @@ describe("task thread lifecycle", () => {
reads += 1;
return makeThreadResponse({
id: "thr_safety_net",
status: reads <= 2 ? "starting" : "active",
status: reads === 1 ? "starting" : "active",
});
},
},
Expand Down
Loading