Files
bot/src/agents/workspace.bootstrap-cache.test.ts
zeekay acaeda400a Eradicate OpenClaw — resolve merge conflicts and finish the rebrand
Three coordinated things:

1. Resolve the committed upstream/main merge conflicts. 94 files were
   sitting with raw <<<<<<< HEAD ... >>>>>>> upstream/main blocks. Every
   conflict had HanzoBot/Bot on HEAD and OpenClaw on upstream. Resolved
   by keeping HEAD everywhere — 540 conflict blocks.

2. Rewrite remaining OpenClaw text refs.
     OPENCLAW   → HANZO_BOT
     OpenClaw   → HanzoBot          (PascalCase type identifiers)
     openclaw   → bot               (codebase convention — botToken,
                                    botUsername etc.; avoids invalid
                                    hyphenated JS identifiers)
     openclaw[_]/openclaw[A-Z] → bot[_]/bot[A-Z]   (compound)
     ai.openclaw.x → ai.hanzo.bot.x  (JVM package path)

3. Delete or rename openclaw-named file paths (116 of them). Dead
   duplicates with a Bot-named canonical from the partial migration:
   deleted. Otherwise renamed.
     ai/openclaw/**           → deleted (ai/hanzo/bot/** canonical)
     Sources/OpenClaw*/       → deleted (Sources/Bot* canonical)
     Tests/OpenClawIPCTests/  → deleted (Tests/BotIPCTests canonical)
     OpenClawKit/             → deleted (BotKit canonical)
     openclaw-tools.*.ts      → deleted (bot-tools.*.ts canonical)
     openclaw-root.ts etc.    → deleted (bot-root.ts canonical)
     types.openclaw.ts        → deleted (types.bot.ts canonical)
     extensions/*/openclaw.plugin.json → renamed hanzo-bot.plugin.json
     docs/start/openclaw.md   → renamed hanzo-bot.md (+ zh-CN)
     docs/assets/openclaw-*.png, whatsapp-openclaw*.jpg → deleted
     scripts/.../openclaw-*   → deleted (bot/hanzo-bot parallels)
     openclaw.mjs             → deleted (hanzo-bot.mjs is package.bin)

Then patched 65 broken JS/TS import strings where hanzo-bot had ended
up inside an import path ('./types.hanzo-bot.js' → './types.bot.js'
etc., since the on-disk filename uses the brand-neutral bot- prefix).

Pre-existing lint debt cleaned up to get oxlint --type-aware to 0/0:
removed the dead i18n test that referenced a path no longer existing;
defined the missing DIDConfig and WalletConfig types in types.base.ts
(they were imported but never declared); dropped unused imports;
collapsed redundant type assertion and a tautological meta.bot lookup
that the openclaw→bot rename made redundant.

The a2ui.bundle.js generated artifact is kept at its pre-rebrand
contents — it gets regenerated by 'pnpm canvas:a2ui:bundle' from
sources I cannot rebuild in this commit; the source side is clean.

Verified: 0 occurrences of openclaw (case-insensitive) in tree source
content, 0 file or directory paths with openclaw in the name; oxlint
--type-aware src test reports 0/0.
2026-05-11 17:56:29 -07:00

169 lines
5.9 KiB
TypeScript

import fs from "node:fs/promises";
import path from "node:path";
import { describe, expect, it, beforeEach } from "vitest";
import { makeTempWorkspace, writeWorkspaceFile } from "../test-helpers/workspace.js";
import { loadWorkspaceBootstrapFiles, DEFAULT_AGENTS_FILENAME } from "./workspace.js";
describe("workspace bootstrap file caching", () => {
let workspaceDir: string;
beforeEach(async () => {
workspaceDir = await makeTempWorkspace("bot-bootstrap-cache-test-");
});
const loadAgentsFile = async (dir: string) => {
const result = await loadWorkspaceBootstrapFiles(dir);
return result.find((f) => f.name === DEFAULT_AGENTS_FILENAME);
};
const expectAgentsContent = (
agentsFile: Awaited<ReturnType<typeof loadAgentsFile>>,
content: string,
) => {
expect(agentsFile?.content).toBe(content);
expect(agentsFile?.missing).toBe(false);
};
it("returns cached content when mtime unchanged", async () => {
const content1 = "# Initial content";
await writeWorkspaceFile({
dir: workspaceDir,
name: DEFAULT_AGENTS_FILENAME,
content: content1,
});
// First load
const agentsFile1 = await loadAgentsFile(workspaceDir);
expectAgentsContent(agentsFile1, content1);
// Second load should use cached content (same mtime)
const agentsFile2 = await loadAgentsFile(workspaceDir);
expectAgentsContent(agentsFile2, content1);
// Verify both calls returned the same content without re-reading
expect(agentsFile1?.content).toBe(agentsFile2?.content);
});
it("invalidates cache when mtime changes", async () => {
const content1 = "# Initial content";
const content2 = "# Updated content";
const filePath = path.join(workspaceDir, DEFAULT_AGENTS_FILENAME);
await writeWorkspaceFile({
dir: workspaceDir,
name: DEFAULT_AGENTS_FILENAME,
content: content1,
});
// First load
const agentsFile1 = await loadAgentsFile(workspaceDir);
expectAgentsContent(agentsFile1, content1);
// Modify the file
await writeWorkspaceFile({
dir: workspaceDir,
name: DEFAULT_AGENTS_FILENAME,
content: content2,
});
// Some filesystems have coarse mtime precision; bump it explicitly.
const bumpedTime = new Date(Date.now() + 1_000);
await fs.utimes(filePath, bumpedTime, bumpedTime);
// Second load should detect the change and return new content
const agentsFile2 = await loadAgentsFile(workspaceDir);
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);
await writeWorkspaceFile({ dir: workspaceDir, name: DEFAULT_AGENTS_FILENAME, content });
// First load
const agentsFile1 = await loadAgentsFile(workspaceDir);
expectAgentsContent(agentsFile1, content);
// Delete the file
await fs.unlink(filePath);
// Second load should handle deletion gracefully
const result2 = await loadWorkspaceBootstrapFiles(workspaceDir);
const agentsFile2 = result2.find((f) => f.name === DEFAULT_AGENTS_FILENAME);
expect(agentsFile2?.missing).toBe(true);
expect(agentsFile2?.content).toBeUndefined();
});
it("handles concurrent access", async () => {
const content = "# Concurrent test content";
await writeWorkspaceFile({ dir: workspaceDir, name: DEFAULT_AGENTS_FILENAME, content });
// Multiple concurrent loads should all succeed
const promises = Array.from({ length: 10 }, () => loadWorkspaceBootstrapFiles(workspaceDir));
const results = await Promise.all(promises);
// All results should be identical
for (const result of results) {
const agentsFile = result.find((f) => f.name === DEFAULT_AGENTS_FILENAME);
expectAgentsContent(agentsFile, content);
}
});
it("caches files independently by path", async () => {
const content1 = "# File 1 content";
const content2 = "# File 2 content";
// Create two different workspace directories
const workspace1 = await makeTempWorkspace("bot-cache-test1-");
const workspace2 = await makeTempWorkspace("bot-cache-test2-");
await writeWorkspaceFile({ dir: workspace1, name: DEFAULT_AGENTS_FILENAME, content: content1 });
await writeWorkspaceFile({ dir: workspace2, name: DEFAULT_AGENTS_FILENAME, content: content2 });
// Load from both workspaces
const result1 = await loadWorkspaceBootstrapFiles(workspace1);
const result2 = await loadWorkspaceBootstrapFiles(workspace2);
const agentsFile1 = result1.find((f) => f.name === DEFAULT_AGENTS_FILENAME);
const agentsFile2 = result2.find((f) => f.name === DEFAULT_AGENTS_FILENAME);
expect(agentsFile1?.content).toBe(content1);
expect(agentsFile2?.content).toBe(content2);
});
it("returns missing=true when bootstrap file never existed", async () => {
const agentsFile = await loadAgentsFile(workspaceDir);
expect(agentsFile?.missing).toBe(true);
expect(agentsFile?.content).toBeUndefined();
});
});