mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 15:41:23 +00:00
fix: stabilize swift protocol generation and flaky tests
This commit is contained in:
@@ -6,18 +6,36 @@ import {
|
||||
getThreadBindingManager,
|
||||
} from "./thread-bindings.js";
|
||||
|
||||
type ThreadBindingsModule = {
|
||||
getThreadBindingManager: typeof getThreadBindingManager;
|
||||
};
|
||||
|
||||
async function loadThreadBindingsViaAlternateLoader(): Promise<ThreadBindingsModule> {
|
||||
const jiti = createJiti(import.meta.url, {
|
||||
interopDefault: true,
|
||||
});
|
||||
try {
|
||||
return await jiti.import<ThreadBindingsModule>("./thread-bindings.ts");
|
||||
} catch (error) {
|
||||
// jiti@2 can fail under ESM test runners when mutating module.require.
|
||||
if (
|
||||
!(error instanceof TypeError) ||
|
||||
!String(error.message).includes("Cannot set property require")
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
const fallbackPath = "./thread-bindings.ts?vitest-loader-fallback";
|
||||
return (await import(/* @vite-ignore */ fallbackPath)) as ThreadBindingsModule;
|
||||
}
|
||||
}
|
||||
|
||||
describe("thread binding manager state", () => {
|
||||
beforeEach(() => {
|
||||
threadBindingsTesting.resetThreadBindingsForTests();
|
||||
});
|
||||
|
||||
it("shares managers between ESM and Jiti-loaded module instances", () => {
|
||||
const jiti = createJiti(import.meta.url, {
|
||||
interopDefault: true,
|
||||
});
|
||||
const viaJiti = jiti("./thread-bindings.ts") as {
|
||||
getThreadBindingManager: typeof getThreadBindingManager;
|
||||
};
|
||||
it("shares managers between ESM and Jiti-loaded module instances", async () => {
|
||||
const viaJiti = await loadThreadBindingsViaAlternateLoader();
|
||||
|
||||
createThreadBindingManager({
|
||||
accountId: "work",
|
||||
|
||||
@@ -4,7 +4,7 @@ import process from "node:process";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { attachChildProcessBridge } from "./child-process-bridge.js";
|
||||
|
||||
function waitForLine(stream: NodeJS.ReadableStream, timeoutMs = 2000): Promise<string> {
|
||||
function waitForLine(stream: NodeJS.ReadableStream, timeoutMs = 10_000): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let buffer = "";
|
||||
|
||||
@@ -89,11 +89,11 @@ describe("attachChildProcessBridge", () => {
|
||||
addedSigterm("SIGTERM");
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const timeout = setTimeout(() => reject(new Error("timeout waiting for child exit")), 2_000);
|
||||
const timeout = setTimeout(() => reject(new Error("timeout waiting for child exit")), 10_000);
|
||||
child.once("exit", () => {
|
||||
clearTimeout(timeout);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}, 5_000);
|
||||
}, 15_000);
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ describe("process supervisor", () => {
|
||||
backendId: "test",
|
||||
mode: "child",
|
||||
argv: [process.execPath, "-e", 'process.stdout.write("ok")'],
|
||||
timeoutMs: 800,
|
||||
timeoutMs: 2_500,
|
||||
stdinMode: "pipe-closed",
|
||||
});
|
||||
const exit = await run.wait();
|
||||
@@ -54,7 +54,7 @@ describe("process supervisor", () => {
|
||||
replaceExistingScope: true,
|
||||
mode: "child",
|
||||
argv: [process.execPath, "-e", 'process.stdout.write("new")'],
|
||||
timeoutMs: 800,
|
||||
timeoutMs: 2_500,
|
||||
stdinMode: "pipe-closed",
|
||||
});
|
||||
|
||||
@@ -88,7 +88,7 @@ describe("process supervisor", () => {
|
||||
backendId: "test",
|
||||
mode: "child",
|
||||
argv: [process.execPath, "-e", 'process.stdout.write("streamed")'],
|
||||
timeoutMs: 800,
|
||||
timeoutMs: 2_500,
|
||||
stdinMode: "pipe-closed",
|
||||
captureOutput: false,
|
||||
onStdout: (chunk) => {
|
||||
|
||||
Reference in New Issue
Block a user