From 810c3510ee6102e7a263553f871a11233708e275 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 10 Aug 2026 12:58:30 -0700 Subject: [PATCH] fix: reject invalid memory parents and trim test facades (#121696) * test(scripts): trim dead testing facades * test(memory): align non-directory path contract * test(discord): drop stale progress callback ids * fix: repair current main validation failures * fix(gateway): remove redundant setup admission generic * test(gateway): await setup admission settlement --- ...age-handler.process.draft-progress.test.ts | 2 -- .../src/host/read-file.test.ts | 7 ++-- .../memory-host-sdk/src/host/read-file.ts | 4 +-- scripts/anthropic-prompt-probe.ts | 3 -- scripts/debug-claude-usage.ts | 3 -- scripts/e2e/npm-telegram-live-runner.ts | 2 -- scripts/write-cli-startup-metadata.ts | 7 ++-- src/infra/sqlite-snapshot.test.ts | 5 +-- .../write-cli-startup-metadata.test.ts | 36 +++++++++---------- 9 files changed, 28 insertions(+), 41 deletions(-) diff --git a/extensions/discord/src/monitor/message-handler.process.draft-progress.test.ts b/extensions/discord/src/monitor/message-handler.process.draft-progress.test.ts index 518f20cbcf09..3b4547ee94e1 100644 --- a/extensions/discord/src/monitor/message-handler.process.draft-progress.test.ts +++ b/extensions/discord/src/monitor/message-handler.process.draft-progress.test.ts @@ -802,12 +802,10 @@ describe("processDiscordMessage draft streaming progress", () => { dispatchInboundMessage.mockImplementationOnce(async (params?: DispatchInboundParams) => { await params?.replyOptions?.onToolStart?.({ - toolCallId: "call-1", name: "exec", phase: "start", }); await params?.replyOptions?.onCommandOutput?.({ - toolCallId: "call-1", phase: "end", title: "pnpm test -- --watch=false", name: "exec", diff --git a/packages/memory-host-sdk/src/host/read-file.test.ts b/packages/memory-host-sdk/src/host/read-file.test.ts index bb229525bf79..7a7d44704fe6 100644 --- a/packages/memory-host-sdk/src/host/read-file.test.ts +++ b/packages/memory-host-sdk/src/host/read-file.test.ts @@ -19,7 +19,7 @@ async function createDirectorySymlink(target: string, linkPath: string): Promise } describe("readMemoryFile", () => { - it("returns empty text for missing files under extra path directories", async () => { + it("returns empty text for absent extra paths and rejects non-directory parents", async () => { const tmpRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-read-file-")); try { const workspaceDir = path.join(tmpRoot, "workspace"); @@ -47,10 +47,7 @@ describe("readMemoryFile", () => { extraPaths: [extraDir], relPath: nonDirectoryParentPath, }), - ).resolves.toEqual({ - text: "", - path: path.relative(workspaceDir, nonDirectoryParentPath).replace(/\\/g, "/"), - }); + ).rejects.toThrow("path required"); } finally { await fs.rm(tmpRoot, { recursive: true, force: true }); } diff --git a/packages/memory-host-sdk/src/host/read-file.ts b/packages/memory-host-sdk/src/host/read-file.ts index c00a1e35444f..8dbd92c1f474 100644 --- a/packages/memory-host-sdk/src/host/read-file.ts +++ b/packages/memory-host-sdk/src/host/read-file.ts @@ -41,8 +41,8 @@ async function isAllowedAdditionalDirectoryPath( } try { await assertNoSymlinkParents({ rootDir: additionalPath, targetPath: absPath }); - } catch (err) { - return isFileMissingError(err); + } catch { + return false; } if (!isPathInsideWithRealpath(additionalPath, absPath)) { try { diff --git a/scripts/anthropic-prompt-probe.ts b/scripts/anthropic-prompt-probe.ts index c2169cec70f3..ca6e5519bdb9 100644 --- a/scripts/anthropic-prompt-probe.ts +++ b/scripts/anthropic-prompt-probe.ts @@ -1007,7 +1007,6 @@ async function main() { export const testing = { cleanupPromptProbeTmpDir, installGatewayPromptParentSignalHandlers, - matchesExtraUsage400, promptProbeTmpResult, readLogTail, readRequestBody, @@ -1015,8 +1014,6 @@ export const testing = { runDirectPrompt, startAnthropicProxy, stopGatewayPromptChild, - summarizeCapture, - summarizeText, }; if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) { diff --git a/scripts/debug-claude-usage.ts b/scripts/debug-claude-usage.ts index a7795df26a1a..3d1b36ccffda 100644 --- a/scripts/debug-claude-usage.ts +++ b/scripts/debug-claude-usage.ts @@ -542,11 +542,8 @@ const main = async (argv = process.argv.slice(2)) => { export const testing = { CLAUDE_COOKIE_HOST_SQL, - CLAUDE_FIREFOX_COOKIE_HOST_SQL, FETCH_RESPONSE_MAX_BYTES, - browserRootLabel, fetchAnthropicOAuthUsage, - mask, parseArgs, readBoundedResponseText, resolveFetchTimeoutMs, diff --git a/scripts/e2e/npm-telegram-live-runner.ts b/scripts/e2e/npm-telegram-live-runner.ts index da9b710eaa41..9b9aa84c4436 100644 --- a/scripts/e2e/npm-telegram-live-runner.ts +++ b/scripts/e2e/npm-telegram-live-runner.ts @@ -269,13 +269,11 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) } export const testing = { - parsePositiveIntegerEnv, resolvePackageTelegramOutputDir, resolveCredentialRole, resolveCredentialSource, createRoundTripProbe, prioritizeRoundTripProbeScenario, - projectExtendedStable2026_6_35QaConfig, resolveRttOptions, resolveTrustedOpenClawCommand, shouldFailPackageTelegramRun, diff --git a/scripts/write-cli-startup-metadata.ts b/scripts/write-cli-startup-metadata.ts index b85f2c1e5219..9b91e2ca33fc 100644 --- a/scripts/write-cli-startup-metadata.ts +++ b/scripts/write-cli-startup-metadata.ts @@ -626,7 +626,7 @@ async function spawnText( }); } -export async function renderBundledRootHelpText( +async function renderBundledRootHelpText( _distDirOverride: string = distDir, renderContext?: RootHelpRenderContext, ): Promise { @@ -755,7 +755,7 @@ async function renderSourceSubcommandHelpTextRecord( ) as PrecomputedSubcommandHelpText; } -export async function writeCliStartupMetadata(options?: { +async function writeCliStartupMetadata(options?: { distDir?: string; outputPath?: string; extensionsDir?: string; @@ -981,10 +981,9 @@ export const testing = { renderSourceRootHelpText, signalCliStartupMetadataProcessTree, spawnText, + writeCliStartupMetadata, }; -export { testing as __testing }; - if (process.argv[1] && path.resolve(process.argv[1]) === scriptPath) { await writeCliStartupMetadata(); process.exit(0); diff --git a/src/infra/sqlite-snapshot.test.ts b/src/infra/sqlite-snapshot.test.ts index 2b3fb1a9e344..e80c85404350 100644 --- a/src/infra/sqlite-snapshot.test.ts +++ b/src/infra/sqlite-snapshot.test.ts @@ -612,12 +612,13 @@ describe("createVerifiedSqliteSnapshot", () => { linked = true; } }); - vi.spyOn(fs, "lstat").mockImplementation(async (filePath) => { + vi.spyOn(fs, "lstat").mockImplementation(async (...args) => { + const [filePath] = args; if (linked && !failedInspection && path.resolve(String(filePath)) === targetPath) { failedInspection = true; throw Object.assign(new Error("target inspection failed"), { code: "EIO" }); } - return await originalLstat(filePath); + return await originalLstat(...args); }); await expectSnapshotFailureWithoutTarget( diff --git a/test/scripts/write-cli-startup-metadata.test.ts b/test/scripts/write-cli-startup-metadata.test.ts index 1546cf547f26..c3247a704af2 100644 --- a/test/scripts/write-cli-startup-metadata.test.ts +++ b/test/scripts/write-cli-startup-metadata.test.ts @@ -7,7 +7,7 @@ import { PassThrough } from "node:stream"; import { pathToFileURL } from "node:url"; import { describe, expect, it, vi } from "vitest"; import { resolveWindowsTaskkillPath } from "../../scripts/lib/windows-taskkill.mjs"; -import { __testing, writeCliStartupMetadata } from "../../scripts/write-cli-startup-metadata.ts"; +import { testing } from "../../scripts/write-cli-startup-metadata.ts"; import { createScriptTestHarness } from "./test-helpers.js"; vi.mock("node:child_process", async (importOriginal) => { @@ -131,7 +131,7 @@ describe("write-cli-startup-metadata", () => { }); }); - const render = __testing.renderSourceRootHelpText(); + const render = testing.renderSourceRootHelpText(); child.stdout.write("Usage: openclaw\n"); setImmediate(() => { child.emit("close", 0, null); @@ -156,7 +156,7 @@ describe("write-cli-startup-metadata", () => { it("fails command help rendering when captured output exceeds the byte limit", async () => { await expect( - __testing.spawnText(["--eval", "process.stdout.write('x'.repeat(2048))"], { + testing.spawnText(["--eval", "process.stdout.write('x'.repeat(2048))"], { cwd: process.cwd(), env: process.env, failureMessage: "render failed", @@ -174,7 +174,7 @@ describe("write-cli-startup-metadata", () => { const spawnProcess = vi.fn(() => child as unknown as ReturnType); const streamError = new Error(`${streamName} pipe failed`); - const render = __testing.spawnText(["--help"], { + const render = testing.spawnText(["--help"], { cwd: process.cwd(), env: process.env, failureMessage: "render failed", @@ -198,7 +198,7 @@ describe("write-cli-startup-metadata", () => { it("preserves an output-limit failure when shutdown also errors a stream", async () => { const child = createSpawnTextChild(); const spawnProcess = vi.fn(() => child as unknown as ReturnType); - const render = __testing.spawnText(["--help"], { + const render = testing.spawnText(["--help"], { cwd: process.cwd(), env: process.env, failureMessage: "render failed", @@ -219,7 +219,7 @@ describe("write-cli-startup-metadata", () => { const childKill = vi.fn(() => true); const runTaskkill = vi.fn(() => ({ error: undefined, status: 0 })); - __testing.signalCliStartupMetadataProcessTree({ pid: 123, kill: childKill }, "SIGTERM", { + testing.signalCliStartupMetadataProcessTree({ pid: 123, kill: childKill }, "SIGTERM", { platform: "win32", runTaskkill, }); @@ -227,7 +227,7 @@ describe("write-cli-startup-metadata", () => { stdio: "ignore", }); - __testing.signalCliStartupMetadataProcessTree({ pid: 123, kill: childKill }, "SIGKILL", { + testing.signalCliStartupMetadataProcessTree({ pid: 123, kill: childKill }, "SIGKILL", { platform: "win32", runTaskkill, }); @@ -249,7 +249,7 @@ describe("write-cli-startup-metadata", () => { .mockReturnValueOnce({ error: undefined, status: 1 }) .mockReturnValueOnce({ error: undefined, status: 0 }); - __testing.signalCliStartupMetadataProcessTree({ pid: 123, kill: childKill }, "SIGTERM", { + testing.signalCliStartupMetadataProcessTree({ pid: 123, kill: childKill }, "SIGTERM", { platform: "win32", runTaskkill, }); @@ -287,7 +287,7 @@ describe("write-cli-startup-metadata", () => { ].join("\n"); await expect( - __testing.spawnText(["--input-type=module", "--eval", parentScript], { + testing.spawnText(["--input-type=module", "--eval", parentScript], { cwd: tempRoot, env: process.env, failureMessage: "render failed", @@ -343,10 +343,10 @@ describe("write-cli-startup-metadata", () => { tempRoot, "runner.mjs", [ - `const { __testing } = await import(${JSON.stringify( + `const { testing } = await import(${JSON.stringify( pathToFileURL(path.resolve("scripts/write-cli-startup-metadata.ts")).href, )});`, - "void __testing.spawnText(", + "void testing.spawnText(", ` [${JSON.stringify(fastCommandPath)}],`, " {", ` cwd: ${JSON.stringify(tempRoot)},`, @@ -357,7 +357,7 @@ describe("write-cli-startup-metadata", () => { " timeoutMs: 30_000,", " },", ").catch(() => undefined);", - "void __testing.spawnText(", + "void testing.spawnText(", ` [${JSON.stringify(commandPath)}],`, " {", ` cwd: ${JSON.stringify(tempRoot)},`, @@ -438,7 +438,7 @@ describe("write-cli-startup-metadata", () => { "utf8", ); - await writeCliStartupMetadata({ + await testing.writeCliStartupMetadata({ distDir, outputPath, extensionsDir, @@ -513,7 +513,7 @@ describe("write-cli-startup-metadata", () => { "async function outputRootHelp() { process.stdout.write('Usage: bundled renderer\\n'); }\nexport { outputRootHelp };\n", ); - await writeCliStartupMetadata({ + await testing.writeCliStartupMetadata({ distDir, outputPath, extensionsDir, @@ -575,7 +575,7 @@ describe("write-cli-startup-metadata", () => { throw new Error(`startup help renderers did not start concurrently: ${started.join(", ")}`); }; - const writePromise = writeCliStartupMetadata({ + const writePromise = testing.writeCliStartupMetadata({ distDir, outputPath, extensionsDir, @@ -631,7 +631,7 @@ describe("write-cli-startup-metadata", () => { writeStartupMetadataSourceSignatureFixture(tempRoot); writeFixtureFile(distDir, "root-help-fixture.js", "export function outputRootHelp() {}\n"); - const writeMetadata = writeCliStartupMetadata({ + const writeMetadata = testing.writeCliStartupMetadata({ distDir, outputPath, extensionsDir, @@ -695,7 +695,7 @@ describe("write-cli-startup-metadata", () => { writeFixtureFile(distDir, "root-help-fixture.js", "export function outputRootHelp() {}\n"); const writeMetadata = async (): Promise => { - await writeCliStartupMetadata({ + await testing.writeCliStartupMetadata({ distDir, outputPath, extensionsDir, @@ -776,7 +776,7 @@ describe("write-cli-startup-metadata", () => { writeFixtureFile(distDir, "root-help-fixture.js", "export function outputRootHelp() {}\n"); const writeMetadata = async (): Promise => { - await writeCliStartupMetadata({ + await testing.writeCliStartupMetadata({ distDir, outputPath, extensionsDir,