test: tighten host tilde expansion assertions

This commit is contained in:
Peter Steinberger
2026-05-09 17:12:55 +01:00
parent 4b1cecdc47
commit 84ccff34ad

View File

@@ -66,6 +66,16 @@ function readWriteOps(): CapturedWriteOperations {
return mocks.writeOps;
}
async function expectMissingPath(operation: Promise<unknown>) {
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))));
});
});