test(deadcode): reuse gateway restart intent writer

This commit is contained in:
Vincent Koc
2026-06-21 19:38:48 +08:00
parent 89a73d08c8
commit e366349730
+2 -22
View File
@@ -6,6 +6,7 @@ import { tmpdir } from "node:os";
import path from "node:path";
import { performance } from "node:perf_hooks";
import { pathToFileURL } from "node:url";
import { writeGatewayRestartIntentSync } from "../src/infra/restart.js";
import { parseStrictIntegerOption } from "./lib/dev-tooling-safety.ts";
import { delay, stopChild, type StopChildResult } from "./lib/gateway-bench-child.ts";
import {
@@ -177,7 +178,6 @@ const DEFAULT_RESTARTS = 5;
const DEFAULT_TIMEOUT_MS = 30_000;
const DEFAULT_POST_READY_DELAY_MS = 250;
const DEFAULT_ENTRY = "dist/entry.js";
const RESTART_INTENT_FILENAME = "gateway-restart-intent.json";
const BOOLEAN_FLAGS = new Set(["--allow-failures", "--help", "-h", "--json"]);
const VALUE_FLAGS = new Set([
"--case",
@@ -833,27 +833,7 @@ function sanitizedEnv(
}
function writeRestartIntent(env: NodeJS.ProcessEnv, targetPid: number, reason: string): boolean {
const stateDir = env.OPENCLAW_STATE_DIR;
if (!stateDir) {
return false;
}
try {
mkdirSync(stateDir, { recursive: true });
const intentPath = path.join(stateDir, RESTART_INTENT_FILENAME);
writeFileSync(
intentPath,
`${JSON.stringify({
kind: "gateway-restart",
pid: targetPid,
createdAt: Date.now(),
reason,
})}\n`,
{ mode: 0o600 },
);
return true;
} catch {
return false;
}
return writeGatewayRestartIntentSync({ env, reason, targetPid });
}
function readProcessFdCount(pid: number | undefined): number | null {