From 13bc7037b1b29dade52b3dfd43e575445a00ef80 Mon Sep 17 00:00:00 2001 From: Shakker Date: Mon, 11 May 2026 17:23:42 +0100 Subject: [PATCH] test: verify infra generated values --- src/agents/cli-auth-epoch.test.ts | 3 ++- src/infra/diagnostic-trace-context.test.ts | 8 ++++++-- src/infra/exec-approvals-analysis.test.ts | 3 ++- src/infra/exec-command-resolution.test.ts | 2 +- src/infra/install-flow.test.ts | 5 ++++- src/infra/net/proxy/proxy-lifecycle.test.ts | 6 +++++- src/infra/push-apns-http2.test.ts | 6 +++--- src/infra/update-startup.test.ts | 3 ++- 8 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/agents/cli-auth-epoch.test.ts b/src/agents/cli-auth-epoch.test.ts index f0e873e7f71..0c41fd636a7 100644 --- a/src/agents/cli-auth-epoch.test.ts +++ b/src/agents/cli-auth-epoch.test.ts @@ -15,7 +15,8 @@ describe("resolveCliAuthEpoch", () => { epoch: Awaited>, label = "auth epoch", ): asserts epoch is string { - expect(epoch, label).toEqual(expect.stringMatching(/\S/)); + expect(typeof epoch, label).toBe("string"); + expect(epoch?.trim().length, label).toBeGreaterThan(0); } it("returns undefined when no local or auth-profile credentials exist", async () => { diff --git a/src/infra/diagnostic-trace-context.test.ts b/src/infra/diagnostic-trace-context.test.ts index 0b07cfa8af5..e50e023425c 100644 --- a/src/infra/diagnostic-trace-context.test.ts +++ b/src/infra/diagnostic-trace-context.test.ts @@ -180,8 +180,12 @@ describe("diagnostic-trace-context", () => { }); }); - expect(createDiagnosticTraceContextFromActiveScope({ spanId: CHILD_SPAN_ID })).toEqual({ - traceId: expect.stringMatching(/^[0-9a-f]{32}$/), + const fallbackScoped = createDiagnosticTraceContextFromActiveScope({ spanId: CHILD_SPAN_ID }); + expect(typeof fallbackScoped.traceId).toBe("string"); + expect(fallbackScoped.traceId).toHaveLength(32); + expect(/^[0-9a-f]+$/.test(fallbackScoped.traceId)).toBe(true); + expect(fallbackScoped).toEqual({ + traceId: fallbackScoped.traceId, spanId: CHILD_SPAN_ID, traceFlags: "01", }); diff --git a/src/infra/exec-approvals-analysis.test.ts b/src/infra/exec-approvals-analysis.test.ts index f3fc7ae08e2..c3d8a7a31b6 100644 --- a/src/infra/exec-approvals-analysis.test.ts +++ b/src/infra/exec-approvals-analysis.test.ts @@ -1004,7 +1004,8 @@ describe("Windows rebuildShellCommandFromSource", () => { platform: "win32", }); expect(result.ok).toBe(true); - expect(result.command).toEqual(expect.stringMatching(/\S/)); + expect(typeof result.command).toBe("string"); + expect(result.command?.trim().length).toBeGreaterThan(0); }); it("rejects Windows commands with unsafe tokens", () => { diff --git a/src/infra/exec-command-resolution.test.ts b/src/infra/exec-command-resolution.test.ts index f1f77f43fb8..ef1113c8f5c 100644 --- a/src/infra/exec-command-resolution.test.ts +++ b/src/infra/exec-command-resolution.test.ts @@ -215,7 +215,7 @@ describe("exec-command-resolution", () => { fs.chmodSync(busybox, 0o755); const shellResolution = resolveCommandResolutionFromArgv(["sh", "-lc", "echo hi"]); - expect(shellResolution?.execution.resolvedPath).toEqual(expect.stringMatching(/sh$/)); + expect(shellResolution?.execution.resolvedPath.endsWith("sh")).toBe(true); const wrappedResolution = resolveCommandResolutionFromArgv([busybox, "sh", "-lc", "echo hi"]); const evalResult = evaluateExecAllowlist({ diff --git a/src/infra/install-flow.test.ts b/src/infra/install-flow.test.ts index a7091d751fa..976de9998e9 100644 --- a/src/infra/install-flow.test.ts +++ b/src/infra/install-flow.test.ts @@ -75,7 +75,10 @@ describe("withExtractedArchiveRoot", () => { onExtracted, }); - expect(withTempDirSpy).toHaveBeenCalledWith("openclaw-plugin-", expect.any(Function)); + expect(withTempDirSpy).toHaveBeenCalledTimes(1); + const withTempDirCall = withTempDirSpy.mock.calls[0]; + expect(withTempDirCall?.[0]).toBe("openclaw-plugin-"); + expect(typeof withTempDirCall?.[1]).toBe("function"); expect(extractSpy).toHaveBeenCalledOnce(); expect(extractSpy.mock.calls[0]?.[0]?.archivePath).toBe(archivePath); expect(resolveRootSpy).toHaveBeenCalledWith(extractDir, { diff --git a/src/infra/net/proxy/proxy-lifecycle.test.ts b/src/infra/net/proxy/proxy-lifecycle.test.ts index d27d18fbc28..35f1adbc158 100644 --- a/src/infra/net/proxy/proxy-lifecycle.test.ts +++ b/src/infra/net/proxy/proxy-lifecycle.test.ts @@ -241,7 +241,11 @@ describe("startProxy", () => { expect(mockLogInfo).toHaveBeenCalledWith( "proxy: routing process HTTP traffic through external proxy http://127.0.0.1:3128", ); - expect(mockLogInfo).not.toHaveBeenCalledWith(expect.stringContaining("user:pass")); + expect( + mockLogInfo.mock.calls.some((call) => + call.some((value) => typeof value === "string" && value.includes("user:pass")), + ), + ).toBe(false); }); it("clears NO_PROXY so internal destinations do not bypass the filtering proxy", async () => { diff --git a/src/infra/push-apns-http2.test.ts b/src/infra/push-apns-http2.test.ts index 6c96e36057f..db4365b275c 100644 --- a/src/infra/push-apns-http2.test.ts +++ b/src/infra/push-apns-http2.test.ts @@ -163,13 +163,13 @@ describe("connectApnsHttp2Session", () => { expect(tunnelCall?.targetHost).toBe("api.push.apple.com"); expect(tunnelCall?.targetPort).toBe(443); expect(tunnelCall?.timeoutMs).toBe(10_000); - expect(connectSpy).toHaveBeenCalledWith("https://api.push.apple.com", { - createConnection: expect.any(Function), - }); + expect(connectSpy).toHaveBeenCalledTimes(1); const connectCall = connectSpy.mock.calls.at(-1) as | [string, http2.ClientSessionOptions] | undefined; + expect(connectCall?.[0]).toBe("https://api.push.apple.com"); const createConnection = connectCall?.[1].createConnection; + expect(typeof createConnection).toBe("function"); expect(createConnection?.(new URL("https://api.push.apple.com"), {})).toBe(fakeTlsSocket); }); diff --git a/src/infra/update-startup.test.ts b/src/infra/update-startup.test.ts index cc7f63f9f8f..afa0653ca3f 100644 --- a/src/infra/update-startup.test.ts +++ b/src/infra/update-startup.test.ts @@ -1,6 +1,7 @@ import fs from "node:fs/promises"; import path from "node:path"; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { formatCliCommand } from "../cli/command-format.js"; import { createSuiteTempRootTracker } from "../test-helpers/temp-dir.js"; import { captureEnv } from "../test-utils/env.js"; import type { UpdateCheckResult } from "./update-check.js"; @@ -226,7 +227,7 @@ describe("update-startup", () => { const { log, parsed } = await runUpdateCheckAndReadState(channel); expect(log.info).toHaveBeenCalledWith( - expect.stringContaining("update available (latest): v2.0.0"), + `update available (latest): v2.0.0 (current v1.0.0). Run: ${formatCliCommand("openclaw update")}`, ); expect(parsed.lastNotifiedVersion).toBe("2.0.0"); expect(parsed.lastAvailableVersion).toBe("2.0.0");