mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-08 06:54:24 +00:00
test: speed up signal reconnect and temp path guard scans
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import ts from "typescript";
|
||||
@@ -104,6 +105,56 @@ async function listTsFiles(dir: string): Promise<string[]> {
|
||||
return out;
|
||||
}
|
||||
|
||||
function parsePathList(stdout: string): Set<string> {
|
||||
const out = new Set<string>();
|
||||
for (const line of stdout.split(/\r?\n/)) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) {
|
||||
continue;
|
||||
}
|
||||
out.add(path.resolve(trimmed));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function prefilterLikelyTmpdirJoinFiles(root: string): Set<string> | null {
|
||||
const commonArgs = [
|
||||
"--files-with-matches",
|
||||
"--glob",
|
||||
"*.ts",
|
||||
"--glob",
|
||||
"*.tsx",
|
||||
"--glob",
|
||||
"!**/*.test.ts",
|
||||
"--glob",
|
||||
"!**/*.test.tsx",
|
||||
"--glob",
|
||||
"!**/*.e2e.ts",
|
||||
"--glob",
|
||||
"!**/*.e2e.tsx",
|
||||
"--glob",
|
||||
"!**/*.d.ts",
|
||||
"--no-messages",
|
||||
];
|
||||
const joined = spawnSync("rg", [...commonArgs, "path\\.join", root], { encoding: "utf8" });
|
||||
if (joined.error || (joined.status !== 0 && joined.status !== 1)) {
|
||||
return null;
|
||||
}
|
||||
const tmpdir = spawnSync("rg", [...commonArgs, "os\\.tmpdir", root], { encoding: "utf8" });
|
||||
if (tmpdir.error || (tmpdir.status !== 0 && tmpdir.status !== 1)) {
|
||||
return null;
|
||||
}
|
||||
const joinMatches = parsePathList(joined.stdout);
|
||||
const tmpdirMatches = parsePathList(tmpdir.stdout);
|
||||
const intersection = new Set<string>();
|
||||
for (const file of joinMatches) {
|
||||
if (tmpdirMatches.has(file)) {
|
||||
intersection.add(file);
|
||||
}
|
||||
}
|
||||
return intersection;
|
||||
}
|
||||
|
||||
describe("temp path guard", () => {
|
||||
it("skips test helper filename variants", () => {
|
||||
expect(shouldSkip("src/commands/test-helpers.ts")).toBe(true);
|
||||
@@ -139,7 +190,8 @@ describe("temp path guard", () => {
|
||||
|
||||
for (const root of RUNTIME_ROOTS) {
|
||||
const absRoot = path.join(repoRoot, root);
|
||||
const files = await listTsFiles(absRoot);
|
||||
const rgPrefiltered = prefilterLikelyTmpdirJoinFiles(absRoot);
|
||||
const files = rgPrefiltered ? [...rgPrefiltered] : await listTsFiles(absRoot);
|
||||
for (const file of files) {
|
||||
const relativePath = path.relative(repoRoot, file);
|
||||
if (shouldSkip(relativePath)) {
|
||||
|
||||
@@ -99,9 +99,15 @@ describe("monitorSignalProvider tool results", () => {
|
||||
autoStart: false,
|
||||
baseUrl: "http://127.0.0.1:8080",
|
||||
abortSignal: abortController.signal,
|
||||
reconnectPolicy: {
|
||||
initialMs: 1,
|
||||
maxMs: 1,
|
||||
factor: 1,
|
||||
jitter: 0,
|
||||
},
|
||||
});
|
||||
|
||||
await vi.advanceTimersByTimeAsync(1_000);
|
||||
await vi.advanceTimersByTimeAsync(5);
|
||||
await monitorPromise;
|
||||
|
||||
expect(streamMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
warnMissingProviderGroupPolicyFallbackOnce,
|
||||
} from "../config/runtime-group-policy.js";
|
||||
import type { SignalReactionNotificationMode } from "../config/types.js";
|
||||
import type { BackoffPolicy } from "../infra/backoff.js";
|
||||
import { waitForTransportReady } from "../infra/transport-ready.js";
|
||||
import { saveMediaBuffer } from "../media/store.js";
|
||||
import { createNonExitingRuntime, type RuntimeEnv } from "../runtime.js";
|
||||
@@ -46,6 +47,7 @@ export type MonitorSignalOpts = {
|
||||
allowFrom?: Array<string | number>;
|
||||
groupAllowFrom?: Array<string | number>;
|
||||
mediaMaxMb?: number;
|
||||
reconnectPolicy?: Partial<BackoffPolicy>;
|
||||
};
|
||||
|
||||
function resolveRuntime(opts: MonitorSignalOpts): RuntimeEnv {
|
||||
@@ -449,6 +451,7 @@ export async function monitorSignalProvider(opts: MonitorSignalOpts = {}): Promi
|
||||
account,
|
||||
abortSignal: daemonLifecycle.abortSignal,
|
||||
runtime,
|
||||
policy: opts.reconnectPolicy,
|
||||
onEvent: (event) => {
|
||||
void handleEvent(event).catch((err) => {
|
||||
runtime.error?.(`event handler failed: ${String(err)}`);
|
||||
|
||||
Reference in New Issue
Block a user