test: tighten non-live object guards · openclaw/openclaw@b703336
steipete
·
2026-05-08
·
via Recent Commits to openclaw:main
File tree
extensions/memory-wiki/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,8 +3,9 @@ import type { ResolvedMemoryWikiConfig } from "./config.js";
|
3 | 3 | import { createWikiApplyTool } from "./tool.js"; |
4 | 4 | |
5 | 5 | function asSchemaObject(value: unknown): Record<string, unknown> { |
6 | | -expect(value).toBeTypeOf("object"); |
| 6 | +expect(typeof value).toBe("object"); |
7 | 7 | expect(value).not.toBeNull(); |
| 8 | +expect(Array.isArray(value)).toBe(false); |
8 | 9 | return value as Record<string, unknown>; |
9 | 10 | } |
10 | 11 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -383,8 +383,11 @@ describe("gateway talk.config", () => {
|
383 | 383 | // the UI keeps the SecretRef context, but every field becomes the |
384 | 384 | // sentinel so no credential material leaks to read-scope callers. |
385 | 385 | const redactedApiKey = talk?.providers?.[GENERIC_TALK_PROVIDER_ID]?.apiKey; |
386 | | -expect(redactedApiKey).toBeTypeOf("object"); |
387 | | -expect((redactedApiKey as SecretRef).id).toBe("__OPENCLAW_REDACTED__"); |
| 386 | +expect(redactedApiKey).toEqual({ |
| 387 | +id: "__OPENCLAW_REDACTED__", |
| 388 | +provider: "__OPENCLAW_REDACTED__", |
| 389 | +source: "__OPENCLAW_REDACTED__", |
| 390 | +}); |
388 | 391 | expect(talk?.resolved?.config?.apiKey).toEqual(redactedApiKey); |
389 | 392 | }); |
390 | 393 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -74,8 +74,7 @@ function getDispatcherClassName(value: unknown): string | null {
|
74 | 74 | } |
75 | 75 | |
76 | 76 | function expectDispatcherAttached(value: unknown): void { |
77 | | -expect(value).toBeTypeOf("object"); |
78 | | -expect(value).not.toBeNull(); |
| 77 | +expect(getDispatcherClassName(value)).toMatch(/^(Agent|Mock)$/u); |
79 | 78 | } |
80 | 79 | |
81 | 80 | function getSecondRequestHeaders(fetchImpl: ReturnType<typeof vi.fn>): Headers { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -34,9 +34,14 @@ describe("cli json stdout contract", () => {
|
34 | 34 | const stdout = result.stdout.trim(); |
35 | 35 | expect(stdout.length).toBeGreaterThan(0); |
36 | 36 | const parsed = JSON.parse(stdout) as unknown; |
37 | | -expect(parsed).toBeTypeOf("object"); |
| 37 | +expect(typeof parsed).toBe("object"); |
38 | 38 | expect(parsed).not.toBeNull(); |
39 | 39 | expect(Array.isArray(parsed)).toBe(false); |
| 40 | +expect(Object.keys(parsed as Record<string, unknown>).sort()).toEqual([ |
| 41 | +"availability", |
| 42 | +"channel", |
| 43 | +"update", |
| 44 | +]); |
40 | 45 | expect(stdout).not.toContain("Doctor warnings"); |
41 | 46 | expect(stdout).not.toContain("Doctor changes"); |
42 | 47 | expect(stdout).not.toContain("Config invalid"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -571,17 +571,20 @@ describe("loadSettings default gateway URL derivation", () => {
|
571 | 571 | |
572 | 572 | const persisted = JSON.parse(localStorage.getItem(scopedKey) ?? "{}"); |
573 | 573 | |
574 | | -expect(persisted.sessionsByGateway).toBeTypeOf("object"); |
575 | | -expect(persisted.sessionsByGateway).not.toBeNull(); |
576 | | -const scopes = Object.keys(persisted.sessionsByGateway); |
| 574 | +const sessionsByGateway = persisted.sessionsByGateway as unknown; |
| 575 | +expect(typeof sessionsByGateway).toBe("object"); |
| 576 | +expect(sessionsByGateway).not.toBeNull(); |
| 577 | +expect(Array.isArray(sessionsByGateway)).toBe(false); |
| 578 | +const scopedSessions = sessionsByGateway as Record<string, unknown>; |
| 579 | +const scopes = Object.keys(scopedSessions); |
577 | 580 | expect(scopes).toHaveLength(10); |
578 | 581 | // oldest stale entries should be evicted |
579 | 582 | expect(scopes).not.toContain("wss://stale-0.example:8443"); |
580 | 583 | expect(scopes).not.toContain("wss://stale-1.example:8443"); |
581 | 584 | // newest stale entries and the current gateway should be retained |
582 | 585 | expect(scopes).toContain("wss://stale-10.example:8443"); |
583 | 586 | expect(scopes).toContain("wss://gateway.example:8443"); |
584 | | -expect(persisted.sessionsByGateway["wss://gateway.example:8443"]).toEqual({ |
| 587 | +expect(scopedSessions["wss://gateway.example:8443"]).toEqual({ |
585 | 588 | sessionKey: "agent:current:main", |
586 | 589 | lastActiveSessionKey: "agent:current:main", |
587 | 590 | }); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。