





























@@ -97,6 +97,18 @@ function getJoinedRuntimeLogs() {
9797return getRuntimeLogs().join("\n");
9898}
9999100+function expectLogsInclude(logs: readonly string[], fragment: string) {
101+expect(logs.some((log) => log.includes(fragment))).toBe(true);
102+}
103+104+function expectLogsExclude(logs: readonly string[], fragment: string) {
105+expect(logs.some((log) => log.includes(fragment))).toBe(false);
106+}
107+108+function expectLogsMatch(logs: readonly string[], pattern: RegExp) {
109+expect(logs.some((log) => pattern.test(log))).toBe(true);
110+}
111+100112async function runStatusAndGetLogs(args: Parameters<typeof statusCommand>[0] = {}) {
101113runtimeLogMock.mockClear();
102114await statusCommand(args, runtime as never);
@@ -1001,13 +1013,10 @@ describe("statusCommand", () => {
10011013count: 0,
10021014warnings: [],
10031015});
1004-expect(payload.tasks).toEqual(
1005-expect.objectContaining({
1006-total: 0,
1007-active: 0,
1008-byStatus: expect.objectContaining({ queued: 0, running: 0 }),
1009-}),
1010-);
1016+expect(payload.tasks.total).toBe(0);
1017+expect(payload.tasks.active).toBe(0);
1018+expect(payload.tasks.byStatus.queued).toBe(0);
1019+expect(payload.tasks.byStatus.running).toBe(0);
10111020expect(mocks.runSecurityAudit).not.toHaveBeenCalled();
1012102110131022runtimeLogMock.mockClear();
@@ -1016,12 +1025,9 @@ describe("statusCommand", () => {
10161025const allPayload = JSON.parse(getRuntimeLog(0));
10171026expect(allPayload.securityAudit.summary.critical).toBe(1);
10181027expect(allPayload.securityAudit.summary.warn).toBe(1);
1019-expect(mocks.runSecurityAudit).toHaveBeenCalledWith(
1020-expect.objectContaining({
1021-includeFilesystem: true,
1022-includeChannelSecurity: true,
1023-}),
1024-);
1028+const auditParams = mocks.runSecurityAudit.mock.calls[0]?.[0];
1029+expect(auditParams?.includeFilesystem).toBe(true);
1030+expect(auditParams?.includeChannelSecurity).toBe(true);
10251031});
1026103210271033it("scopes usage resolution to the scanned config", async () => {
@@ -1040,8 +1046,8 @@ describe("statusCommand", () => {
10401046resolveUsage?: (input: { config: unknown; timeoutMs?: number }) => Promise<unknown>;
10411047}
10421048| undefined;
1043-expect(params).toBeDefined();
1044-expect(params).toMatchObject({ usage: true, timeoutMs: 1234 });
1049+expect(params?.usage).toBe(true);
1050+expect(params?.timeoutMs).toBe(1234);
10451051if (!params?.resolveUsage) {
10461052throw new Error("missing status usage resolver");
10471053}
@@ -1131,21 +1137,13 @@ describe("statusCommand", () => {
11311137"Troubleshooting:",
11321138"Next steps:",
11331139]) {
1134-expect(logs).toEqual(expect.arrayContaining([expect.stringContaining(token)]));
1140+expectLogsInclude(logs, token);
11351141}
1136-expect(logs).toEqual(
1137-expect.arrayContaining([
1138-expect.stringContaining("legacy-plugin still uses legacy before_agent_start"),
1139-]),
1140-);
1141-expect(logs).toEqual(
1142-expect.arrayContaining([
1143-expect.stringMatching(/openclaw (?:--profile isolated )?status --all/),
1144-]),
1145-);
1146-expect(logs).toEqual(expect.arrayContaining([expect.stringContaining("Cache")]));
1147-expect(logs).toEqual(expect.arrayContaining([expect.stringContaining("40% hit")]));
1148-expect(logs).toEqual(expect.arrayContaining([expect.stringContaining("read 2.0k")]));
1142+expectLogsInclude(logs, "legacy-plugin still uses legacy before_agent_start");
1143+expectLogsMatch(logs, /openclaw (?:--profile isolated )?status --all/);
1144+expectLogsInclude(logs, "Cache");
1145+expectLogsInclude(logs, "40% hit");
1146+expectLogsInclude(logs, "read 2.0k");
11491147});
1150114811511149it("shows a maintenance hint when task audit errors are present", async () => {
@@ -1200,8 +1198,8 @@ describe("statusCommand", () => {
12001198},
12011199});
12021200const logs = await runStatusAndGetLogs();
1203-expect(logs).toEqual(expect.arrayContaining([expect.stringContaining("100% cached")]));
1204-expect(logs).not.toEqual(expect.arrayContaining([expect.stringContaining("120% cached")]));
1201+expectLogsInclude(logs, "100% cached");
1202+expectLogsExclude(logs, "120% cached");
1205120312061204mocks.loadSessionStore.mockReturnValue({
12071205"+1000": {
@@ -1213,12 +1211,9 @@ describe("statusCommand", () => {
12131211},
12141212});
12151213const promptSideLogs = await runStatusAndGetLogs();
1216-expect(promptSideLogs).toEqual(expect.arrayContaining([expect.stringContaining("67% cached")]));
1217-expect(promptSideLogs).not.toEqual(
1218-expect.arrayContaining([expect.stringContaining("40% cached")]),
1219-);
1214+expectLogsInclude(promptSideLogs, "67% cached");
1215+expectLogsExclude(promptSideLogs, "40% cached");
12201216});
1221-12221217it("shows node-only gateway info when no local gateway service is installed", async () => {
12231218mocks.resolveGatewayService.mockReturnValueOnce({
12241219label: "LaunchAgent",
@@ -1261,7 +1256,7 @@ describe("statusCommand", () => {
12611256presence: [],
12621257});
12631258const logs = await runStatusAndGetLogs();
1264-expect(logs).toEqual(expect.arrayContaining([expect.stringContaining("auth token")]));
1259+expectLogsInclude(logs, "auth token");
12651260});
12661261});
12671262此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。