refactor: unify boundary-safe reads for bootstrap and includes

This commit is contained in:
Peter Steinberger
2026-02-26 12:42:06 +01:00
parent 199ef9f8ea
commit 242188b7b1
8 changed files with 374 additions and 100 deletions

View File

@@ -74,6 +74,34 @@ describe("workspace bootstrap file caching", () => {
expectAgentsContent(agentsFile2, content2);
});
it("invalidates cache when inode changes with same mtime", async () => {
if (process.platform === "win32") {
return;
}
const content1 = "# old-content";
const content2 = "# new-content";
const filePath = path.join(workspaceDir, DEFAULT_AGENTS_FILENAME);
const tempPath = path.join(workspaceDir, ".AGENTS.tmp");
await writeWorkspaceFile({
dir: workspaceDir,
name: DEFAULT_AGENTS_FILENAME,
content: content1,
});
const originalStat = await fs.stat(filePath);
const agentsFile1 = await loadAgentsFile(workspaceDir);
expectAgentsContent(agentsFile1, content1);
await fs.writeFile(tempPath, content2, "utf-8");
await fs.utimes(tempPath, originalStat.atime, originalStat.mtime);
await fs.rename(tempPath, filePath);
await fs.utimes(filePath, originalStat.atime, originalStat.mtime);
const agentsFile2 = await loadAgentsFile(workspaceDir);
expectAgentsContent(agentsFile2, content2);
});
it("handles file deletion gracefully", async () => {
const content = "# Some content";
const filePath = path.join(workspaceDir, DEFAULT_AGENTS_FILENAME);