docs: document agent cache auth tests · openclaw/openclaw@ddc832e
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Tests diagnostic cache-trace event writing, redaction, and stream wrapping. */ |
1 | 2 | import crypto from "node:crypto"; |
2 | 3 | import { describe, expect, it } from "vitest"; |
3 | 4 | import type { OpenClawConfig } from "../config/config.js"; |
@@ -7,6 +8,8 @@ import { createCacheTrace } from "./cache-trace.js";
|
7 | 8 | describe("createCacheTrace", () => { |
8 | 9 | function createMemoryTraceForTest() { |
9 | 10 | const lines: string[] = []; |
| 11 | +// In-memory writer keeps cache trace assertions deterministic without |
| 12 | +// touching real diagnostic log paths. |
10 | 13 | const trace = createCacheTrace({ |
11 | 14 | cfg: { |
12 | 15 | diagnostics: { |
@@ -266,7 +269,8 @@ describe("createCacheTrace", () => {
|
266 | 269 | |
267 | 270 | const parent: Record<string, unknown> = { role: "user", content: "hello" }; |
268 | 271 | const child: Record<string, unknown> = { ref: parent }; |
269 | | -parent.child = child; // circular reference |
| 272 | +// Cache tracing must fingerprint cyclic prompt payloads instead of recursing forever. |
| 273 | +parent.child = child; |
270 | 274 | |
271 | 275 | trace?.recordStage("prompt:images", { |
272 | 276 | messages: [parent] as unknown as [], |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Tests SQLite-backed scoped agent cache entries and adapter ownership. */ |
1 | 2 | import fs from "node:fs"; |
2 | 3 | import os from "node:os"; |
3 | 4 | import path from "node:path"; |
@@ -24,6 +25,8 @@ function createTempStateDir(): string {
|
24 | 25 | } |
25 | 26 | |
26 | 27 | afterEach(() => { |
| 28 | +// SQLite handles are shared by state dir/agent id; close them so temp dirs can |
| 29 | +// be removed and tests cannot leak rows across cases. |
27 | 30 | closeOpenClawAgentDatabasesForTest(); |
28 | 31 | closeOpenClawStateDatabaseForTest(); |
29 | 32 | }); |
@@ -231,6 +234,7 @@ describe("SQLite agent cache store", () => {
|
231 | 234 | database.db |
232 | 235 | .prepare("update cache_entries set expires_at = ? where scope = ? and key = ?") |
233 | 236 | .run(Number.MAX_SAFE_INTEGER, "runtime", "invalid"); |
| 237 | +// Simulate a corrupted persisted timestamp that the public writer rejects. |
234 | 238 | |
235 | 239 | expect( |
236 | 240 | readSqliteAgentCacheEntry({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Tests channel action discovery from plugin message-tool descriptors. */ |
1 | 2 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | import type { ChannelPlugin } from "../channels/plugins/types.js"; |
3 | 4 | import type { OpenClawConfig } from "../config/config.js"; |
@@ -14,6 +15,8 @@ describe("channel tools", () => {
|
14 | 15 | const errorSpy = vi.spyOn(defaultRuntime, "error").mockImplementation(() => undefined); |
15 | 16 | |
16 | 17 | beforeEach(() => { |
| 18 | +// A throwing plugin verifies discovery degrades and logs once instead of |
| 19 | +// making all channel tooling unavailable. |
17 | 20 | const plugin: ChannelPlugin = { |
18 | 21 | id: "test", |
19 | 22 | meta: { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Tests Chutes OAuth token exchange and refresh HTTP flows. */ |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import { withFetchPreconnect } from "../test-utils/fetch-mock.js"; |
3 | 4 | import { |
@@ -30,6 +31,8 @@ function expectRefreshedCredential(
|
30 | 31 | refreshed: Awaited<ReturnType<typeof refreshChutesTokens>>, |
31 | 32 | now: number, |
32 | 33 | ) { |
| 34 | +// Refresh responses may omit refresh_token; the stored token remains valid and |
| 35 | +// expiry keeps the safety skew applied. |
33 | 36 | expect(refreshed.access).toBe("at_new"); |
34 | 37 | expect(refreshed.refresh).toBe("rt_old"); |
35 | 38 | expect(refreshed.expires).toBe(now + 1800 * 1000 - 5 * 60 * 1000); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Tests Chutes OAuth callback parsing and PKCE generation. */ |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import { generateChutesPkce, parseOAuthCallbackInput } from "./chutes-oauth.js"; |
3 | 4 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +/** Tests CLI auth epoch stability across token refreshes and identity changes. */ |
1 | 2 | import { afterEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | import type { AuthProfileStore } from "./auth-profiles/types.js"; |
3 | 4 | import { |
@@ -15,6 +16,8 @@ describe("resolveCliAuthEpoch", () => {
|
15 | 16 | epoch: Awaited<ReturnType<typeof resolveCliAuthEpoch>>, |
16 | 17 | label = "auth epoch", |
17 | 18 | ): asserts epoch is string { |
| 19 | +// Epochs are cache/session keys, so tests assert hash shape without caring |
| 20 | +// about the exact digest value. |
18 | 21 | expect(typeof epoch, label).toBe("string"); |
19 | 22 | expect(epoch, label).toMatch(/^[a-f0-9]{64}$/); |
20 | 23 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。