test: require core weak guard lookups · openclaw/openclaw@6f26a47
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -15,6 +15,17 @@ function toolNames(tools: ReturnType<typeof createOpenClawTools>): string[] {
|
15 | 15 | return tools.map((tool) => tool.name); |
16 | 16 | } |
17 | 17 | |
| 18 | +function expectToolNamed( |
| 19 | +tools: ReturnType<typeof createOpenClawTools>, |
| 20 | +name: string, |
| 21 | +): ReturnType<typeof createOpenClawTools>[number] { |
| 22 | +const tool = tools.find((candidate) => candidate.name === name); |
| 23 | +if (!tool) { |
| 24 | +throw new Error(`Expected tool ${name} to be registered`); |
| 25 | +} |
| 26 | +return tool; |
| 27 | +} |
| 28 | + |
18 | 29 | function openAiGpt5Params( |
19 | 30 | config: OpenClawConfig, |
20 | 31 | overrides: Partial<UpdatePlanGatingParams> = {}, |
@@ -67,13 +78,9 @@ describe("openclaw-tools update_plan gating", () => {
|
67 | 78 | wrapBeforeToolCallHook: false, |
68 | 79 | }); |
69 | 80 | |
| 81 | +expect(isToolWrappedWithBeforeToolCallHook(expectToolNamed(tools, "sessions_list"))).toBe(true); |
70 | 82 | expect( |
71 | | -isToolWrappedWithBeforeToolCallHook(tools.find((tool) => tool.name === "sessions_list")!), |
72 | | -).toBe(true); |
73 | | -expect( |
74 | | -isToolWrappedWithBeforeToolCallHook( |
75 | | -unwrappedTools.find((tool) => tool.name === "sessions_list")!, |
76 | | -), |
| 83 | +isToolWrappedWithBeforeToolCallHook(expectToolNamed(unwrappedTools, "sessions_list")), |
77 | 84 | ).toBe(false); |
78 | 85 | }); |
79 | 86 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,14 @@ import {
|
12 | 12 | |
13 | 13 | type TestConfig = Record<string, unknown>; |
14 | 14 | |
| 15 | +function parseLastJsonLine(raw: string): unknown { |
| 16 | +const lastLine = raw.trim().split("\n").at(-1); |
| 17 | +if (!lastLine) { |
| 18 | +throw new Error("Expected audit log to contain at least one JSON line"); |
| 19 | +} |
| 20 | +return JSON.parse(lastLine) as unknown; |
| 21 | +} |
| 22 | + |
15 | 23 | const mockConfig = vi.hoisted(() => { |
16 | 24 | const initial = {}; |
17 | 25 | const state = { |
@@ -550,7 +558,7 @@ describe("parseCrestodianOperation", () => {
|
550 | 558 | }); |
551 | 559 | expect(lines.join("\n")).toContain("[crestodian] done: doctor.fix"); |
552 | 560 | const auditPath = path.join(tempDir, "audit", "crestodian.jsonl"); |
553 | | -const audit = JSON.parse((await fs.readFile(auditPath, "utf8")).trim().split("\n").at(-1)!); |
| 561 | +const audit = parseLastJsonLine(await fs.readFile(auditPath, "utf8")); |
554 | 562 | expect(audit).toMatchObject({ |
555 | 563 | operation: "doctor.fix", |
556 | 564 | summary: "Ran doctor repairs", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -14,7 +14,7 @@ describe("security audit deep probe failure", () => {
|
14 | 14 | close?: { code: number; reason: string } | null; |
15 | 15 | }; |
16 | 16 | }; |
17 | | -expectedError?: string; |
| 17 | +expectedError: string; |
18 | 18 | }> = [ |
19 | 19 | { |
20 | 20 | name: "probe returns failed result", |
@@ -50,7 +50,8 @@ describe("security audit deep probe failure", () => {
|
50 | 50 | findings.some((finding) => finding.checkId === "gateway.probe_failed"), |
51 | 51 | testCase.name, |
52 | 52 | ).toBe(true); |
53 | | -expect(findings[0]?.detail).toContain(testCase.expectedError!); |
| 53 | +const probeFailure = findings.find((finding) => finding.checkId === "gateway.probe_failed"); |
| 54 | +expect(probeFailure?.detail, testCase.name).toContain(testCase.expectedError); |
54 | 55 | } |
55 | 56 | }); |
56 | 57 | }); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。