test(agents): add compaction and workspace reset regressions

This commit is contained in:
Peter Steinberger
2026-02-26 17:40:29 +01:00
parent 0ec7711bc2
commit 53e30475e2
4 changed files with 78 additions and 1 deletions

View File

@@ -121,6 +121,21 @@ describe("ensureAgentWorkspace", () => {
const memoryContent = await fs.readFile(path.join(tempDir, "MEMORY.md"), "utf-8");
expect(memoryContent).toBe("# Long-term memory\nImportant stuff");
});
it("treats git-backed workspaces as existing even when template files are missing", async () => {
const tempDir = await makeTempWorkspace("openclaw-workspace-");
await fs.mkdir(path.join(tempDir, ".git"), { recursive: true });
await fs.writeFile(path.join(tempDir, ".git", "HEAD"), "ref: refs/heads/main\n");
await ensureAgentWorkspace({ dir: tempDir, ensureBootstrapFiles: true });
await expect(fs.access(path.join(tempDir, DEFAULT_IDENTITY_FILENAME))).resolves.toBeUndefined();
await expect(fs.access(path.join(tempDir, DEFAULT_BOOTSTRAP_FILENAME))).rejects.toMatchObject({
code: "ENOENT",
});
const state = await readOnboardingState(tempDir);
expect(state.onboardingCompletedAt).toMatch(/\d{4}-\d{2}-\d{2}T/);
});
});
describe("loadWorkspaceBootstrapFiles", () => {

View File

@@ -408,7 +408,11 @@ export async function ensureAgentWorkspace(params?: {
fs.readFile(userPath, "utf-8"),
]);
const hasUserContent = await (async () => {
const indicators = [path.join(dir, "memory"), path.join(dir, DEFAULT_MEMORY_FILENAME)];
const indicators = [
path.join(dir, "memory"),
path.join(dir, DEFAULT_MEMORY_FILENAME),
path.join(dir, ".git"),
];
for (const indicator of indicators) {
try {
await fs.access(indicator);