Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(train): the stop/restart test builds its deferred promises itself (#6830)

milind-soni78cc680998a0
diff --git a/server/app-trigger-lifecycle.test.ts b/server/app-trigger-lifecycle.test.ts
index 3b50249528..a5786fc0bc 100644
--- a/server/app-trigger-lifecycle.test.ts
+++ b/server/app-trigger-lifecycle.test.ts
@@ -6,6 +6,13 @@ import { afterEach, expect, it, vi } from "vitest";
import type { AppTriggerBroker, BrokerInventory } from "./app-trigger-broker.ts";
import { AppTriggerManager } from "./app-triggers.ts";
+// tsconfig.server.json targets ES2023: Promise.withResolvers is ES2024.
+function withResolvers<T>() {
+ let resolve!: (value: T | PromiseLike<T>) => void, reject!: (reason?: unknown) => void;
+ const promise = new Promise<T>((done, fail) => { resolve = done; reject = fail; });
+ return { promise, resolve, reject };
+}
+
const folders: string[] = [];
afterEach(() => { for (const dir of folders.splice(0)) rmSync(dir, { recursive: true, force: true }); });
const inventory: BrokerInventory = {
@@ -33,8 +40,8 @@ async function harness(overrides: Partial<AppTriggerBroker>) {
}
it("retires an old loop when restarted during reconciliation and keeps the replacement joinable", async () => {
- const first = Promise.withResolvers<BrokerInventory>(), second = Promise.withResolvers<BrokerInventory>();
- const entered = Promise.withResolvers<void>(), unexpectedPoll = Promise.withResolvers<void>();
+ const first = withResolvers<BrokerInventory>(), second = withResolvers<BrokerInventory>();
+ const entered = withResolvers<void>(), unexpectedPoll = withResolvers<void>();
let inventories = 0;
const { manager } = await harness({
inventory: () => { inventories++; entered.resolve(); return inventories === 1 ? first.promise : second.promise; },
@@ -68,7 +75,7 @@ it("retires an old loop when restarted during reconciliation and keeps the repla
});
it("leaves an aborted poll's late events unacknowledged and unstarted", async () => {
- const received = Promise.withResolvers<Awaited<ReturnType<AppTriggerBroker["poll"]>>>();
+ const received = withResolvers<Awaited<ReturnType<AppTriggerBroker["poll"]>>>();
const seenCursors: number[] = [];
const { manager, enqueue } = await harness({ poll: ({ after }) => { seenCursors.push(after); return received.promise; } });
const controller = new AbortController();
@@ -84,7 +91,7 @@ it("leaves an aborted poll's late events unacknowledged and unstarted", async ()
});
it("keeps start idempotent and lets wake replace only the current wait", async () => {
- const first = Promise.withResolvers<void>(), second = Promise.withResolvers<void>();
+ const first = withResolvers<void>(), second = withResolvers<void>();
const signals: AbortSignal[] = [];
const { manager } = await harness({ poll: async ({ signal }) => {
signals.push(signal!);