From 84ccff34ad14575a831017a54cb4aaa14ab3f175 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 17:12:55 +0100 Subject: [PATCH] test: tighten host tilde expansion assertions --- ...pi-tools.read.host-tilde-expansion.test.ts | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/agents/pi-tools.read.host-tilde-expansion.test.ts b/src/agents/pi-tools.read.host-tilde-expansion.test.ts index 6084a625f5f..3be885cd463 100644 --- a/src/agents/pi-tools.read.host-tilde-expansion.test.ts +++ b/src/agents/pi-tools.read.host-tilde-expansion.test.ts @@ -66,6 +66,16 @@ function readWriteOps(): CapturedWriteOperations { return mocks.writeOps; } +async function expectMissingPath(operation: Promise) { + let error: NodeJS.ErrnoException | undefined; + try { + await operation; + } catch (caught) { + error = caught as NodeJS.ErrnoException; + } + expect(error?.code).toBe("ENOENT"); +} + describe("host tool tilde expansion (non-workspace mode)", () => { const tempDirs: string[] = []; @@ -140,11 +150,7 @@ describe("host tool tilde expansion (non-workspace mode)", () => { await readWriteOps().writeFile(toTildePath(testFile), "written via os home"); expect(await fs.readFile(testFile, "utf8")).toBe("written via os home"); - await expect(fs.access(path.join(openclawHome, path.basename(testFile)))).rejects.toMatchObject( - { - code: "ENOENT", - }, - ); + await expectMissingPath(fs.access(path.join(openclawHome, path.basename(testFile)))); }); it("ignores OPENCLAW_HOME for mkdir operations", async () => { @@ -157,9 +163,7 @@ describe("host tool tilde expansion (non-workspace mode)", () => { await readWriteOps().mkdir(toTildePath(newDir)); expect((await fs.stat(newDir)).isDirectory()).toBe(true); - await expect(fs.access(path.join(openclawHome, path.basename(newDir)))).rejects.toMatchObject({ - code: "ENOENT", - }); + await expectMissingPath(fs.access(path.join(openclawHome, path.basename(newDir)))); }); it("ignores OPENCLAW_HOME for readFile operations", async () => { @@ -173,11 +177,7 @@ describe("host tool tilde expansion (non-workspace mode)", () => { const content = await readEditOps().readFile(toTildePath(testFile)); expect(content.toString("utf8")).toBe("OS home content"); - await expect(fs.access(path.join(openclawHome, path.basename(testFile)))).rejects.toMatchObject( - { - code: "ENOENT", - }, - ); + await expectMissingPath(fs.access(path.join(openclawHome, path.basename(testFile)))); }); it("ignores OPENCLAW_HOME for access operations", async () => { @@ -190,10 +190,6 @@ describe("host tool tilde expansion (non-workspace mode)", () => { createHostWorkspaceEditTool(openclawHome, { workspaceOnly: false }); await expect(readEditOps().access(toTildePath(testFile))).resolves.toBeUndefined(); - await expect(fs.access(path.join(openclawHome, path.basename(testFile)))).rejects.toMatchObject( - { - code: "ENOENT", - }, - ); + await expectMissingPath(fs.access(path.join(openclawHome, path.basename(testFile)))); }); });