mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 15:24:58 +00:00
refactor: unify boundary-safe reads for bootstrap and includes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { makeTempWorkspace, writeWorkspaceFile } from "../test-helpers/workspace.js";
|
||||
@@ -142,6 +143,37 @@ describe("loadWorkspaceBootstrapFiles", () => {
|
||||
const files = await loadWorkspaceBootstrapFiles(tempDir);
|
||||
expect(getMemoryEntries(files)).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("treats hardlinked bootstrap aliases as missing", async () => {
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
}
|
||||
const rootDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-workspace-hardlink-"));
|
||||
try {
|
||||
const workspaceDir = path.join(rootDir, "workspace");
|
||||
const outsideDir = path.join(rootDir, "outside");
|
||||
await fs.mkdir(workspaceDir, { recursive: true });
|
||||
await fs.mkdir(outsideDir, { recursive: true });
|
||||
const outsideFile = path.join(outsideDir, DEFAULT_AGENTS_FILENAME);
|
||||
const linkPath = path.join(workspaceDir, DEFAULT_AGENTS_FILENAME);
|
||||
await fs.writeFile(outsideFile, "outside", "utf-8");
|
||||
try {
|
||||
await fs.link(outsideFile, linkPath);
|
||||
} catch (err) {
|
||||
if ((err as NodeJS.ErrnoException).code === "EXDEV") {
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
const files = await loadWorkspaceBootstrapFiles(workspaceDir);
|
||||
const agents = files.find((file) => file.name === DEFAULT_AGENTS_FILENAME);
|
||||
expect(agents?.missing).toBe(true);
|
||||
expect(agents?.content).toBeUndefined();
|
||||
} finally {
|
||||
await fs.rm(rootDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("filterBootstrapFilesForSession", () => {
|
||||
|
||||
Reference in New Issue
Block a user