chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
4
test/fixtures/child-process-bridge/child.js
vendored
4
test/fixtures/child-process-bridge/child.js
vendored
@@ -7,7 +7,9 @@ const server = http.createServer((_, res) => {
|
||||
|
||||
server.listen(0, "127.0.0.1", () => {
|
||||
const addr = server.address();
|
||||
if (!addr || typeof addr === "string") throw new Error("unexpected address");
|
||||
if (!addr || typeof addr === "string") {
|
||||
throw new Error("unexpected address");
|
||||
}
|
||||
process.stdout.write(`${addr.port}\n`);
|
||||
});
|
||||
|
||||
|
||||
@@ -181,7 +181,9 @@ const stopGatewayInstance = async (inst: GatewayInstance) => {
|
||||
}
|
||||
const exited = await Promise.race([
|
||||
new Promise<boolean>((resolve) => {
|
||||
if (inst.child.exitCode !== null) return resolve(true);
|
||||
if (inst.child.exitCode !== null) {
|
||||
return resolve(true);
|
||||
}
|
||||
inst.child.once("exit", () => resolve(true));
|
||||
}),
|
||||
sleep(5_000).then(() => false),
|
||||
@@ -299,17 +301,23 @@ const connectNode = async (
|
||||
commands: ["system.run"],
|
||||
deviceIdentity,
|
||||
onHelloOk: () => {
|
||||
if (settled) return;
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
resolveReady?.();
|
||||
},
|
||||
onConnectError: (err) => {
|
||||
if (settled) return;
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
rejectReady?.(err);
|
||||
},
|
||||
onClose: (code, reason) => {
|
||||
if (settled) return;
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
rejectReady?.(new Error(`gateway closed (${code}): ${reason}`));
|
||||
},
|
||||
@@ -341,7 +349,9 @@ const waitForNodeStatus = async (inst: GatewayInstance, nodeId: string, timeoutM
|
||||
},
|
||||
)) as NodeListPayload;
|
||||
const match = list.nodes?.find((n) => n.nodeId === nodeId);
|
||||
if (match?.connected && match?.paired) return;
|
||||
if (match?.connected && match?.paired) {
|
||||
return;
|
||||
}
|
||||
await sleep(50);
|
||||
}
|
||||
throw new Error(`timeout waiting for node status for ${nodeId}`);
|
||||
|
||||
@@ -41,8 +41,12 @@ function formatZonedTimestamp(date: Date, timeZone?: string): string {
|
||||
|
||||
export function formatEnvelopeTimestamp(date: Date, zone: EnvelopeTimestampZone = "utc"): string {
|
||||
const normalized = zone.trim().toLowerCase();
|
||||
if (normalized === "utc" || normalized === "gmt") return formatUtcTimestamp(date);
|
||||
if (normalized === "local" || normalized === "host") return formatZonedTimestamp(date);
|
||||
if (normalized === "utc" || normalized === "gmt") {
|
||||
return formatUtcTimestamp(date);
|
||||
}
|
||||
if (normalized === "local" || normalized === "host") {
|
||||
return formatZonedTimestamp(date);
|
||||
}
|
||||
return formatZonedTimestamp(date, zone);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,15 +8,21 @@ function stripAnsi(input: string): string {
|
||||
}
|
||||
|
||||
const next = input[i + 1];
|
||||
if (next !== "[") continue;
|
||||
if (next !== "[") {
|
||||
continue;
|
||||
}
|
||||
i += 1;
|
||||
|
||||
while (i + 1 < input.length) {
|
||||
i += 1;
|
||||
const c = input[i];
|
||||
if (!c) break;
|
||||
if (!c) {
|
||||
break;
|
||||
}
|
||||
const isLetter = (c >= "A" && c <= "Z") || (c >= "a" && c <= "z") || c === "~";
|
||||
if (isLetter) break;
|
||||
if (isLetter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
|
||||
@@ -17,7 +17,9 @@ export async function pollUntil<T>(
|
||||
|
||||
while (Date.now() - start < timeoutMs) {
|
||||
const value = await fn();
|
||||
if (value !== null && value !== undefined) return value;
|
||||
if (value !== null && value !== undefined) {
|
||||
return value;
|
||||
}
|
||||
await sleep(intervalMs);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,11 @@ function snapshotEnv(): EnvSnapshot {
|
||||
|
||||
function restoreEnv(snapshot: EnvSnapshot) {
|
||||
const restoreKey = (key: string, value: string | undefined) => {
|
||||
if (value === undefined) delete process.env[key];
|
||||
else process.env[key] = value;
|
||||
if (value === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = value;
|
||||
}
|
||||
};
|
||||
restoreKey("HOME", snapshot.home);
|
||||
restoreKey("USERPROFILE", snapshot.userProfile);
|
||||
@@ -36,14 +39,19 @@ function restoreEnv(snapshot: EnvSnapshot) {
|
||||
|
||||
function snapshotExtraEnv(keys: string[]): Record<string, string | undefined> {
|
||||
const snapshot: Record<string, string | undefined> = {};
|
||||
for (const key of keys) snapshot[key] = process.env[key];
|
||||
for (const key of keys) {
|
||||
snapshot[key] = process.env[key];
|
||||
}
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
function restoreExtraEnv(snapshot: Record<string, string | undefined>) {
|
||||
for (const [key, value] of Object.entries(snapshot)) {
|
||||
if (value === undefined) delete process.env[key];
|
||||
else process.env[key] = value;
|
||||
if (value === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,9 +60,13 @@ function setTempHome(base: string) {
|
||||
process.env.USERPROFILE = base;
|
||||
process.env.OPENCLAW_STATE_DIR = path.join(base, ".openclaw");
|
||||
|
||||
if (process.platform !== "win32") return;
|
||||
if (process.platform !== "win32") {
|
||||
return;
|
||||
}
|
||||
const match = base.match(/^([A-Za-z]:)(.*)$/);
|
||||
if (!match) return;
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
process.env.HOMEDRIVE = match[1];
|
||||
process.env.HOMEPATH = match[2] || "\\";
|
||||
}
|
||||
@@ -78,8 +90,11 @@ export async function withTempHome<T>(
|
||||
if (opts.env) {
|
||||
for (const [key, raw] of Object.entries(opts.env)) {
|
||||
const value = typeof raw === "function" ? raw(base) : raw;
|
||||
if (value === undefined) delete process.env[key];
|
||||
else process.env[key] = value;
|
||||
if (value === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,11 +83,16 @@ async function connectClient(params: { url: string; token: string }) {
|
||||
return await new Promise<InstanceType<typeof GatewayClient>>((resolve, reject) => {
|
||||
let settled = false;
|
||||
const stop = (err?: Error, client?: InstanceType<typeof GatewayClient>) => {
|
||||
if (settled) return;
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
if (err) reject(err);
|
||||
else resolve(client as InstanceType<typeof GatewayClient>);
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(client as InstanceType<typeof GatewayClient>);
|
||||
}
|
||||
};
|
||||
const client = new GatewayClient({
|
||||
url: params.url,
|
||||
@@ -146,7 +151,9 @@ describe("provider timeouts (e2e)", () => {
|
||||
return buildOpenAIResponsesSse("fallback-ok");
|
||||
}
|
||||
|
||||
if (!originalFetch) throw new Error(`fetch is not available (url=${url})`);
|
||||
if (!originalFetch) {
|
||||
throw new Error(`fetch is not available (url=${url})`);
|
||||
}
|
||||
return await originalFetch(input, init);
|
||||
};
|
||||
(globalThis as unknown as { fetch: unknown }).fetch = fetchImpl;
|
||||
@@ -263,20 +270,41 @@ describe("provider timeouts (e2e)", () => {
|
||||
await server.close({ reason: "timeout fallback test complete" });
|
||||
await fs.rm(tempHome, { recursive: true, force: true });
|
||||
(globalThis as unknown as { fetch: unknown }).fetch = originalFetch;
|
||||
if (prev.home === undefined) delete process.env.HOME;
|
||||
else process.env.HOME = prev.home;
|
||||
if (prev.configPath === undefined) delete process.env.OPENCLAW_CONFIG_PATH;
|
||||
else process.env.OPENCLAW_CONFIG_PATH = prev.configPath;
|
||||
if (prev.token === undefined) delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
else process.env.OPENCLAW_GATEWAY_TOKEN = prev.token;
|
||||
if (prev.skipChannels === undefined) delete process.env.OPENCLAW_SKIP_CHANNELS;
|
||||
else process.env.OPENCLAW_SKIP_CHANNELS = prev.skipChannels;
|
||||
if (prev.skipGmail === undefined) delete process.env.OPENCLAW_SKIP_GMAIL_WATCHER;
|
||||
else process.env.OPENCLAW_SKIP_GMAIL_WATCHER = prev.skipGmail;
|
||||
if (prev.skipCron === undefined) delete process.env.OPENCLAW_SKIP_CRON;
|
||||
else process.env.OPENCLAW_SKIP_CRON = prev.skipCron;
|
||||
if (prev.skipCanvas === undefined) delete process.env.OPENCLAW_SKIP_CANVAS_HOST;
|
||||
else process.env.OPENCLAW_SKIP_CANVAS_HOST = prev.skipCanvas;
|
||||
if (prev.home === undefined) {
|
||||
delete process.env.HOME;
|
||||
} else {
|
||||
process.env.HOME = prev.home;
|
||||
}
|
||||
if (prev.configPath === undefined) {
|
||||
delete process.env.OPENCLAW_CONFIG_PATH;
|
||||
} else {
|
||||
process.env.OPENCLAW_CONFIG_PATH = prev.configPath;
|
||||
}
|
||||
if (prev.token === undefined) {
|
||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
} else {
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN = prev.token;
|
||||
}
|
||||
if (prev.skipChannels === undefined) {
|
||||
delete process.env.OPENCLAW_SKIP_CHANNELS;
|
||||
} else {
|
||||
process.env.OPENCLAW_SKIP_CHANNELS = prev.skipChannels;
|
||||
}
|
||||
if (prev.skipGmail === undefined) {
|
||||
delete process.env.OPENCLAW_SKIP_GMAIL_WATCHER;
|
||||
} else {
|
||||
process.env.OPENCLAW_SKIP_GMAIL_WATCHER = prev.skipGmail;
|
||||
}
|
||||
if (prev.skipCron === undefined) {
|
||||
delete process.env.OPENCLAW_SKIP_CRON;
|
||||
} else {
|
||||
process.env.OPENCLAW_SKIP_CRON = prev.skipCron;
|
||||
}
|
||||
if (prev.skipCanvas === undefined) {
|
||||
delete process.env.OPENCLAW_SKIP_CANVAS_HOST;
|
||||
} else {
|
||||
process.env.OPENCLAW_SKIP_CANVAS_HOST = prev.skipCanvas;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -83,7 +83,9 @@ const createStubPlugin = (params: {
|
||||
listAccountIds: (cfg: OpenClawConfig) => {
|
||||
const channels = cfg.channels as Record<string, unknown> | undefined;
|
||||
const entry = channels?.[params.id];
|
||||
if (!entry || typeof entry !== "object") return [];
|
||||
if (!entry || typeof entry !== "object") {
|
||||
return [];
|
||||
}
|
||||
const accounts = (entry as { accounts?: Record<string, unknown> }).accounts;
|
||||
const ids = accounts ? Object.keys(accounts).filter(Boolean) : [];
|
||||
return ids.length > 0 ? ids : ["default"];
|
||||
@@ -91,7 +93,9 @@ const createStubPlugin = (params: {
|
||||
resolveAccount: (cfg: OpenClawConfig, accountId: string) => {
|
||||
const channels = cfg.channels as Record<string, unknown> | undefined;
|
||||
const entry = channels?.[params.id];
|
||||
if (!entry || typeof entry !== "object") return {};
|
||||
if (!entry || typeof entry !== "object") {
|
||||
return {};
|
||||
}
|
||||
const accounts = (entry as { accounts?: Record<string, unknown> }).accounts;
|
||||
const match = accounts?.[accountId];
|
||||
return (match && typeof match === "object") || typeof match === "string" ? match : entry;
|
||||
|
||||
@@ -7,14 +7,19 @@ type RestoreEntry = { key: string; value: string | undefined };
|
||||
|
||||
function restoreEnv(entries: RestoreEntry[]): void {
|
||||
for (const { key, value } of entries) {
|
||||
if (value === undefined) delete process.env[key];
|
||||
else process.env[key] = value;
|
||||
if (value === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadProfileEnv(): void {
|
||||
const profilePath = path.join(os.homedir(), ".profile");
|
||||
if (!fs.existsSync(profilePath)) return;
|
||||
if (!fs.existsSync(profilePath)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const output = execFileSync(
|
||||
"/bin/bash",
|
||||
@@ -24,11 +29,17 @@ function loadProfileEnv(): void {
|
||||
const entries = output.split("\0");
|
||||
let applied = 0;
|
||||
for (const entry of entries) {
|
||||
if (!entry) continue;
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
const idx = entry.indexOf("=");
|
||||
if (idx <= 0) continue;
|
||||
if (idx <= 0) {
|
||||
continue;
|
||||
}
|
||||
const key = entry.slice(0, idx);
|
||||
if (!key || (process.env[key] ?? "") !== "") continue;
|
||||
if (!key || (process.env[key] ?? "") !== "") {
|
||||
continue;
|
||||
}
|
||||
process.env[key] = entry.slice(idx + 1);
|
||||
applied += 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user