fix: stabilize windows queue + pairing tests
This commit is contained in:
@@ -2,6 +2,7 @@ import path from "node:path";
|
|||||||
|
|
||||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
import { pollUntil } from "../../test/helpers/poll.js";
|
||||||
import { withTempHome as withTempHomeBase } from "../../test/helpers/temp-home.js";
|
import { withTempHome as withTempHomeBase } from "../../test/helpers/temp-home.js";
|
||||||
import {
|
import {
|
||||||
isEmbeddedPiRunActive,
|
isEmbeddedPiRunActive,
|
||||||
@@ -109,7 +110,6 @@ describe("queue followups", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("summarizes dropped followups when cap is exceeded", async () => {
|
it("summarizes dropped followups when cap is exceeded", async () => {
|
||||||
vi.useFakeTimers();
|
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
const prompts: string[] = [];
|
const prompts: string[] = [];
|
||||||
vi.mocked(runEmbeddedPiAgent).mockImplementation(async (params) => {
|
vi.mocked(runEmbeddedPiAgent).mockImplementation(async (params) => {
|
||||||
@@ -133,8 +133,10 @@ describe("queue followups", () => {
|
|||||||
vi.mocked(isEmbeddedPiRunActive).mockReturnValue(false);
|
vi.mocked(isEmbeddedPiRunActive).mockReturnValue(false);
|
||||||
await getReplyFromConfig({ Body: "three", From: "+1002", To: "+2000" }, {}, cfg);
|
await getReplyFromConfig({ Body: "three", From: "+1002", To: "+2000" }, {}, cfg);
|
||||||
|
|
||||||
await vi.runAllTimersAsync();
|
await pollUntil(
|
||||||
await Promise.resolve();
|
async () => (prompts.some((p) => p.includes("[Queue overflow]")) ? true : null),
|
||||||
|
{ timeoutMs: 2000 },
|
||||||
|
);
|
||||||
|
|
||||||
expect(prompts.some((p) => p.includes("[Queue overflow]"))).toBe(true);
|
expect(prompts.some((p) => p.includes("[Queue overflow]"))).toBe(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -323,6 +323,11 @@ describe("node bridge server", { timeout: suiteTimeoutMs }, () => {
|
|||||||
resolveDisconnected = resolve;
|
resolveDisconnected = resolve;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let pendingRequest: {
|
||||||
|
requestId: string;
|
||||||
|
nodeId: string;
|
||||||
|
ts: number;
|
||||||
|
} | null = null;
|
||||||
const server = await startNodeBridgeServer({
|
const server = await startNodeBridgeServer({
|
||||||
host: "127.0.0.1",
|
host: "127.0.0.1",
|
||||||
port: 0,
|
port: 0,
|
||||||
@@ -330,6 +335,13 @@ describe("node bridge server", { timeout: suiteTimeoutMs }, () => {
|
|||||||
onAuthenticated: async (node) => {
|
onAuthenticated: async (node) => {
|
||||||
lastAuthed = node;
|
lastAuthed = node;
|
||||||
},
|
},
|
||||||
|
onPairRequested: async (request) => {
|
||||||
|
pendingRequest = {
|
||||||
|
requestId: request.requestId,
|
||||||
|
nodeId: request.nodeId,
|
||||||
|
ts: request.ts,
|
||||||
|
};
|
||||||
|
},
|
||||||
onDisconnected: async (node) => {
|
onDisconnected: async (node) => {
|
||||||
disconnected = node;
|
disconnected = node;
|
||||||
resolveDisconnected?.();
|
resolveDisconnected?.();
|
||||||
@@ -351,13 +363,7 @@ describe("node bridge server", { timeout: suiteTimeoutMs }, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Approve the pending request from the gateway side.
|
// Approve the pending request from the gateway side.
|
||||||
const pending = await pollUntil(
|
const pending = await pollUntil(async () => pendingRequest, { timeoutMs: pairingTimeoutMs });
|
||||||
async () => {
|
|
||||||
const list = await listNodePairing(baseDir);
|
|
||||||
return list.pending.find((p) => p.nodeId === "n4");
|
|
||||||
},
|
|
||||||
{ timeoutMs: pairingTimeoutMs },
|
|
||||||
);
|
|
||||||
expect(pending).toBeTruthy();
|
expect(pending).toBeTruthy();
|
||||||
if (!pending) throw new Error("expected a pending request");
|
if (!pending) throw new Error("expected a pending request");
|
||||||
const approved = await approveNodePairing(pending.requestId, baseDir);
|
const approved = await approveNodePairing(pending.requestId, baseDir);
|
||||||
|
|||||||
Reference in New Issue
Block a user