
























@@ -713,6 +713,56 @@ describe("ensureAgentWorkspace", () => {
713713"# Add tasks below when you want the agent to check something periodically.",
714714);
715715});
716+717+it("does not recreate optional bootstrap files when workspace setup is already completed", async () => {
718+const tempDir = await makeTempWorkspace("openclaw-workspace-");
719+720+// First call: set up the workspace and complete setup by customizing profile files.
721+await ensureAgentWorkspace({ dir: tempDir, ensureBootstrapFiles: true });
722+await writeWorkspaceFile({
723+dir: tempDir,
724+name: DEFAULT_IDENTITY_FILENAME,
725+content: "custom identity",
726+});
727+await writeWorkspaceFile({
728+dir: tempDir,
729+name: DEFAULT_USER_FILENAME,
730+content: "custom user",
731+});
732+// Delete BOOTSTRAP.md to trigger completion on next ensure call.
733+await fs.unlink(path.join(tempDir, DEFAULT_BOOTSTRAP_FILENAME));
734+await ensureAgentWorkspace({ dir: tempDir, ensureBootstrapFiles: true });
735+736+// Verify setup is completed.
737+const state = await readWorkspaceState(tempDir);
738+expect(state.setupCompletedAt).toMatch(/\d{4}-\d{2}-\d{2}T/);
739+740+// Delete optional bootstrap files and customize AGENTS.md to simulate
741+// a repository workspace where optional files only exist under agent
742+// subdirectories but the root still has customized required files.
743+await fs.unlink(path.join(tempDir, DEFAULT_SOUL_FILENAME));
744+await fs.unlink(path.join(tempDir, DEFAULT_IDENTITY_FILENAME));
745+await fs.unlink(path.join(tempDir, DEFAULT_USER_FILENAME));
746+await fs.unlink(path.join(tempDir, DEFAULT_HEARTBEAT_FILENAME));
747+await writeWorkspaceFile({
748+dir: tempDir,
749+name: DEFAULT_AGENTS_FILENAME,
750+content: "custom agents instructions\n",
751+});
752+753+// Third call: should NOT recreate optional files for an already-configured workspace.
754+await ensureAgentWorkspace({ dir: tempDir, ensureBootstrapFiles: true });
755+756+// Verify optional files are NOT recreated at the root level.
757+await expectPathMissing(path.join(tempDir, DEFAULT_SOUL_FILENAME));
758+await expectPathMissing(path.join(tempDir, DEFAULT_IDENTITY_FILENAME));
759+await expectPathMissing(path.join(tempDir, DEFAULT_USER_FILENAME));
760+await expectPathMissing(path.join(tempDir, DEFAULT_HEARTBEAT_FILENAME));
761+762+// Verify required files (AGENTS.md, TOOLS.md) still exist.
763+await expect(fs.access(path.join(tempDir, DEFAULT_AGENTS_FILENAME))).resolves.toBeUndefined();
764+await expect(fs.access(path.join(tempDir, DEFAULT_TOOLS_FILENAME))).resolves.toBeUndefined();
765+});
716766});
717767718768describe("loadWorkspaceBootstrapFiles", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。