test: speed up signal reconnect and temp path guard scans
This commit is contained in:
parent
142c0a7f7d
commit
a0d0104a86
@ -1,3 +1,4 @@
|
|||||||
|
import { spawnSync } from "node:child_process";
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import ts from "typescript";
|
import ts from "typescript";
|
||||||
@ -104,6 +105,56 @@ async function listTsFiles(dir: string): Promise<string[]> {
|
|||||||
return out;
|
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", () => {
|
describe("temp path guard", () => {
|
||||||
it("skips test helper filename variants", () => {
|
it("skips test helper filename variants", () => {
|
||||||
expect(shouldSkip("src/commands/test-helpers.ts")).toBe(true);
|
expect(shouldSkip("src/commands/test-helpers.ts")).toBe(true);
|
||||||
@ -139,7 +190,8 @@ describe("temp path guard", () => {
|
|||||||
|
|
||||||
for (const root of RUNTIME_ROOTS) {
|
for (const root of RUNTIME_ROOTS) {
|
||||||
const absRoot = path.join(repoRoot, root);
|
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) {
|
for (const file of files) {
|
||||||
const relativePath = path.relative(repoRoot, file);
|
const relativePath = path.relative(repoRoot, file);
|
||||||
if (shouldSkip(relativePath)) {
|
if (shouldSkip(relativePath)) {
|
||||||
|
|||||||
@ -99,9 +99,15 @@ describe("monitorSignalProvider tool results", () => {
|
|||||||
autoStart: false,
|
autoStart: false,
|
||||||
baseUrl: "http://127.0.0.1:8080",
|
baseUrl: "http://127.0.0.1:8080",
|
||||||
abortSignal: abortController.signal,
|
abortSignal: abortController.signal,
|
||||||
|
reconnectPolicy: {
|
||||||
|
initialMs: 1,
|
||||||
|
maxMs: 1,
|
||||||
|
factor: 1,
|
||||||
|
jitter: 0,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await vi.advanceTimersByTimeAsync(1_000);
|
await vi.advanceTimersByTimeAsync(5);
|
||||||
await monitorPromise;
|
await monitorPromise;
|
||||||
|
|
||||||
expect(streamMock).toHaveBeenCalledTimes(2);
|
expect(streamMock).toHaveBeenCalledTimes(2);
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import {
|
|||||||
warnMissingProviderGroupPolicyFallbackOnce,
|
warnMissingProviderGroupPolicyFallbackOnce,
|
||||||
} from "../config/runtime-group-policy.js";
|
} from "../config/runtime-group-policy.js";
|
||||||
import type { SignalReactionNotificationMode } from "../config/types.js";
|
import type { SignalReactionNotificationMode } from "../config/types.js";
|
||||||
|
import type { BackoffPolicy } from "../infra/backoff.js";
|
||||||
import { waitForTransportReady } from "../infra/transport-ready.js";
|
import { waitForTransportReady } from "../infra/transport-ready.js";
|
||||||
import { saveMediaBuffer } from "../media/store.js";
|
import { saveMediaBuffer } from "../media/store.js";
|
||||||
import { createNonExitingRuntime, type RuntimeEnv } from "../runtime.js";
|
import { createNonExitingRuntime, type RuntimeEnv } from "../runtime.js";
|
||||||
@ -46,6 +47,7 @@ export type MonitorSignalOpts = {
|
|||||||
allowFrom?: Array<string | number>;
|
allowFrom?: Array<string | number>;
|
||||||
groupAllowFrom?: Array<string | number>;
|
groupAllowFrom?: Array<string | number>;
|
||||||
mediaMaxMb?: number;
|
mediaMaxMb?: number;
|
||||||
|
reconnectPolicy?: Partial<BackoffPolicy>;
|
||||||
};
|
};
|
||||||
|
|
||||||
function resolveRuntime(opts: MonitorSignalOpts): RuntimeEnv {
|
function resolveRuntime(opts: MonitorSignalOpts): RuntimeEnv {
|
||||||
@ -449,6 +451,7 @@ export async function monitorSignalProvider(opts: MonitorSignalOpts = {}): Promi
|
|||||||
account,
|
account,
|
||||||
abortSignal: daemonLifecycle.abortSignal,
|
abortSignal: daemonLifecycle.abortSignal,
|
||||||
runtime,
|
runtime,
|
||||||
|
policy: opts.reconnectPolicy,
|
||||||
onEvent: (event) => {
|
onEvent: (event) => {
|
||||||
void handleEvent(event).catch((err) => {
|
void handleEvent(event).catch((err) => {
|
||||||
runtime.error?.(`event handler failed: ${String(err)}`);
|
runtime.error?.(`event handler failed: ${String(err)}`);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user