test: tighten plugin contract async callbacks

This commit is contained in:
Peter Steinberger
2026-05-08 20:02:43 +01:00
parent 2322c47901
commit 848ffe90e6
2 changed files with 10 additions and 6 deletions

View File

@@ -372,15 +372,13 @@ async function resolveDemoLocalApiKey(params: {
storedKeys: string[];
configuredApiKey: string;
}) {
let resolved!: Awaited<ReturnType<typeof resolveApiKeyForProvider>>;
await withEnvAsync({ DEMO_LOCAL_API_KEY: params.envApiKey }, async () => {
resolved = await resolveApiKeyForProvider({
return await withEnvAsync({ DEMO_LOCAL_API_KEY: params.envApiKey }, async () => {
return await resolveApiKeyForProvider({
provider: "demo-local",
store: buildDemoLocalStore(params.storedKeys),
cfg: buildDemoLocalProviderCfg(params.configuredApiKey),
});
});
return resolved;
}
describe("getApiKeyForModel", () => {

View File

@@ -1976,7 +1976,7 @@ describe("host-hook fixture plugin contract", () => {
it("does not let stale scheduler cleanup delete a newer job generation", async () => {
let releaseCleanup: (() => void) | undefined;
let markCleanupStarted!: () => void;
let markCleanupStarted: (() => void) | undefined;
const cleanupStartedPromise = new Promise<void>((resolve) => {
markCleanupStarted = resolve;
});
@@ -1994,6 +1994,9 @@ describe("host-hook fixture plugin contract", () => {
sessionKey: "agent:main:main",
kind: "monitor",
cleanup: async () => {
if (!markCleanupStarted) {
throw new Error("Expected scheduler cleanup start callback to be initialized");
}
markCleanupStarted();
await new Promise<void>((resolve) => {
releaseCleanup = resolve;
@@ -2027,7 +2030,10 @@ describe("host-hook fixture plugin contract", () => {
},
});
releaseCleanup?.();
if (!releaseCleanup) {
throw new Error("Expected scheduler cleanup release callback to be initialized");
}
releaseCleanup();
await expect(cleanupPromise).resolves.toMatchObject({ failures: [] });
expect(listPluginSessionSchedulerJobs("scheduler-race")).toEqual([
{