mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 01:31:08 +00:00
test: stabilize scoped runners and qa ports
This commit is contained in:
@@ -1,9 +1,35 @@
|
||||
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { createServer } from "node:net";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { runQaDockerUp } from "./docker-up.runtime.js";
|
||||
|
||||
async function occupyPortOrAcceptExisting(port: number): Promise<{ close: () => Promise<void> }> {
|
||||
const server = createServer();
|
||||
const listening = await new Promise<boolean>((resolve, reject) => {
|
||||
server.once("error", (error: NodeJS.ErrnoException) => {
|
||||
if (error.code === "EADDRINUSE") {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
server.listen(port, "127.0.0.1", () => resolve(true));
|
||||
});
|
||||
|
||||
return {
|
||||
close: async () => {
|
||||
if (!listening) {
|
||||
return;
|
||||
}
|
||||
await new Promise<void>((resolve, reject) =>
|
||||
server.close((error) => (error ? reject(error) : resolve())),
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("runQaDockerUp", () => {
|
||||
it("builds the QA UI, writes the harness, starts compose, and waits for health", async () => {
|
||||
const calls: string[] = [];
|
||||
@@ -109,6 +135,8 @@ describe("runQaDockerUp", () => {
|
||||
}
|
||||
return preferredPort;
|
||||
});
|
||||
const gatewayPortReservation = await occupyPortOrAcceptExisting(18789);
|
||||
const qaLabPortReservation = await occupyPortOrAcceptExisting(43124);
|
||||
|
||||
try {
|
||||
const result = await runQaDockerUp(
|
||||
@@ -138,6 +166,8 @@ describe("runQaDockerUp", () => {
|
||||
expect(result.gatewayUrl).toBe("http://127.0.0.1:28001/");
|
||||
expect(result.qaLabUrl).toBe("http://127.0.0.1:28002");
|
||||
} finally {
|
||||
await gatewayPortReservation.close();
|
||||
await qaLabPortReservation.close();
|
||||
await rm(outputDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -440,6 +440,7 @@ describe("dispatchReplyFromConfig ACP abort", () => {
|
||||
acpMocks.listAcpSessionEntries.mockReset().mockResolvedValue([]);
|
||||
acpMocks.readAcpSessionEntry.mockReset().mockReturnValue(null);
|
||||
acpMocks.upsertAcpSessionMeta.mockReset().mockResolvedValue(null);
|
||||
acpMocks.getAcpRuntimeBackend.mockReset();
|
||||
acpMocks.requireAcpRuntimeBackend.mockReset();
|
||||
sessionBindingMocks.listBySession.mockReset().mockReturnValue([]);
|
||||
sessionBindingMocks.resolveByConversation.mockReset().mockReturnValue(null);
|
||||
|
||||
@@ -617,6 +617,7 @@ describe("dispatchReplyFromConfig", () => {
|
||||
acpMocks.readAcpSessionEntry.mockReturnValue(null);
|
||||
acpMocks.upsertAcpSessionMeta.mockReset();
|
||||
acpMocks.upsertAcpSessionMeta.mockResolvedValue(null);
|
||||
acpMocks.getAcpRuntimeBackend.mockReset();
|
||||
acpMocks.requireAcpRuntimeBackend.mockReset();
|
||||
agentEventMocks.emitAgentEvent.mockReset();
|
||||
agentEventMocks.onAgentEvent.mockReset();
|
||||
|
||||
@@ -635,10 +635,10 @@ describe("test-projects args", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("routes browser extension targets to the extension channel config", () => {
|
||||
it("routes browser extension targets to the extensions config", () => {
|
||||
expect(buildVitestRunPlans(["extensions/browser/index.test.ts"])).toEqual([
|
||||
{
|
||||
config: "vitest.extension-channels.config.ts",
|
||||
config: "vitest.extensions.config.ts",
|
||||
forwardedArgs: [],
|
||||
includePatterns: ["extensions/browser/index.test.ts"],
|
||||
watchMode: false,
|
||||
|
||||
@@ -313,7 +313,6 @@ describe("scoped vitest configs", () => {
|
||||
expect(defaultExtensionChannelsConfig.test?.dir).toBe("extensions");
|
||||
expect(defaultExtensionChannelsConfig.test?.include).toEqual(
|
||||
expect.arrayContaining([
|
||||
"browser/**/*.test.ts",
|
||||
"discord/**/*.test.ts",
|
||||
"line/**/*.test.ts",
|
||||
"slack/**/*.test.ts",
|
||||
|
||||
@@ -16,7 +16,6 @@ export const channelTestRoots = [
|
||||
bundledPluginRoot("slack"),
|
||||
bundledPluginRoot("signal"),
|
||||
bundledPluginRoot("imessage"),
|
||||
bundledPluginRoot("browser"),
|
||||
bundledPluginRoot("line"),
|
||||
];
|
||||
|
||||
|
||||
@@ -35,6 +35,94 @@ export function resolveVitestIsolation(
|
||||
return false;
|
||||
}
|
||||
|
||||
const SCOPED_PROJECT_GROUP_ORDER_BY_NAME = new Map(
|
||||
[
|
||||
"acp",
|
||||
"agents",
|
||||
"auto-reply",
|
||||
"auto-reply-core",
|
||||
"auto-reply-reply",
|
||||
"auto-reply-top-level",
|
||||
"boundary",
|
||||
"bundled",
|
||||
"channels",
|
||||
"cli",
|
||||
"commands",
|
||||
"commands-light",
|
||||
"cron",
|
||||
"daemon",
|
||||
"extension-acpx",
|
||||
"extension-bluebubbles",
|
||||
"extension-channels",
|
||||
"extension-diffs",
|
||||
"extension-feishu",
|
||||
"extension-irc",
|
||||
"extension-mattermost",
|
||||
"extension-matrix",
|
||||
"extension-memory",
|
||||
"extension-messaging",
|
||||
"extension-msteams",
|
||||
"extension-providers",
|
||||
"extension-telegram",
|
||||
"extension-voice-call",
|
||||
"extension-whatsapp",
|
||||
"extension-zalo",
|
||||
"extensions",
|
||||
"gateway",
|
||||
"hooks",
|
||||
"infra",
|
||||
"logging",
|
||||
"media",
|
||||
"media-understanding",
|
||||
"plugin-sdk",
|
||||
"plugin-sdk-light",
|
||||
"plugins",
|
||||
"process",
|
||||
"runtime-config",
|
||||
"secrets",
|
||||
"shared-core",
|
||||
"tasks",
|
||||
"tooling",
|
||||
"tui",
|
||||
"ui",
|
||||
"unit-fast",
|
||||
"unit-security",
|
||||
"unit-src",
|
||||
"unit-support",
|
||||
"unit-ui",
|
||||
"utils",
|
||||
"wizard",
|
||||
].map((name, index) => [name, index + 10]),
|
||||
);
|
||||
|
||||
function hashFallbackScopedProjectGroupOrder(key: string): number {
|
||||
let hash = 0;
|
||||
for (const char of key) {
|
||||
hash = (hash * 33 + char.charCodeAt(0)) % 10_000;
|
||||
}
|
||||
return hash + 1_000;
|
||||
}
|
||||
|
||||
function resolveScopedProjectGroupOrder(
|
||||
name?: string,
|
||||
dir?: string,
|
||||
include?: string[],
|
||||
): number | undefined {
|
||||
const normalizedName = name?.trim();
|
||||
if (normalizedName) {
|
||||
return (
|
||||
SCOPED_PROJECT_GROUP_ORDER_BY_NAME.get(normalizedName) ??
|
||||
hashFallbackScopedProjectGroupOrder(normalizedName)
|
||||
);
|
||||
}
|
||||
const normalizedInclude = include?.map(normalizePathPattern).join("|") ?? "";
|
||||
const key = [dir?.trim(), normalizedInclude].filter(Boolean).join("|");
|
||||
if (!key) {
|
||||
return undefined;
|
||||
}
|
||||
return hashFallbackScopedProjectGroupOrder(key);
|
||||
}
|
||||
|
||||
export function createScopedVitestConfig(
|
||||
include: string[],
|
||||
options?: {
|
||||
@@ -73,6 +161,7 @@ export function createScopedVitestConfig(
|
||||
];
|
||||
const useNonIsolatedRunner = options?.useNonIsolatedRunner ?? !isolate;
|
||||
const runner = useNonIsolatedRunner ? "./test/non-isolated-runner.ts" : undefined;
|
||||
const scopedGroupOrder = resolveScopedProjectGroupOrder(options?.name, scopedDir, include);
|
||||
|
||||
return defineConfig({
|
||||
...base,
|
||||
@@ -88,6 +177,14 @@ export function createScopedVitestConfig(
|
||||
include: relativizeScopedPatterns(includeFromEnv ?? cliInclude ?? include, scopedDir),
|
||||
exclude,
|
||||
...(options?.pool ? { pool: options.pool } : {}),
|
||||
...(scopedGroupOrder === undefined
|
||||
? {}
|
||||
: {
|
||||
sequence: {
|
||||
...baseTest.sequence,
|
||||
groupOrder: scopedGroupOrder,
|
||||
},
|
||||
}),
|
||||
...(options?.passWithNoTests !== undefined || cliInclude !== null
|
||||
? { passWithNoTests: options?.passWithNoTests ?? true }
|
||||
: {}),
|
||||
|
||||
Reference in New Issue
Block a user