Files
bot/scripts/test-force.ts
zooqueen 071e3f1082 rebrand: openclaw -> hanzo bot across entire codebase
Automated rebrand of all openclaw references to hanzo bot:
- Package: openclaw -> @hanzo/bot
- Binary: openclaw -> hanzo-bot
- Config: ~/.openclaw -> ~/.hanzo/bot
- Docker: ghcr.io/hanzoai/bot
- Env vars: OPENCLAW_* -> BOT_*
- Bundle IDs: ai.hanzo.bot.*
- Product name: Hanzo Bot
2026-03-19 13:52:32 -07:00

60 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env -S node --import tsx
import { spawnSync } from "node:child_process";
import os from "node:os";
import path from "node:path";
import { forceFreePort, type PortProcess } from "../src/cli/ports.js";
const DEFAULT_PORT = 18789;
function killGatewayListeners(port: number): PortProcess[] {
try {
const killed = forceFreePort(port);
if (killed.length > 0) {
console.log(
`freed port ${port}; terminated: ${killed
.map((p) => `${p.command} (pid ${p.pid})`)
.join(", ")}`,
);
} else {
console.log(`port ${port} already free`);
}
return killed;
} catch (err) {
console.error(`failed to free port ${port}: ${String(err)}`);
return [];
}
}
function runTests() {
const isolatedLock =
process.env.BOT_GATEWAY_LOCK ??
path.join(os.tmpdir(), `openclaw-gateway.lock.test.${Date.now()}`);
const result = spawnSync("pnpm", ["vitest", "run"], {
stdio: "inherit",
env: {
...process.env,
BOT_GATEWAY_LOCK: isolatedLock,
},
});
if (result.error) {
console.error(`pnpm test failed to start: ${String(result.error)}`);
process.exit(1);
}
process.exit(result.status ?? 1);
}
function main() {
const port = Number.parseInt(process.env.BOT_GATEWAY_PORT ?? `${DEFAULT_PORT}`, 10);
console.log(`🧹 test:force - clearing gateway on port ${port}`);
const killed = killGatewayListeners(port);
if (killed.length === 0) {
console.log("no listeners to kill");
}
console.log("running pnpm test…");
runTests();
}
main();