mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 12:14:58 +00:00
test(agents): dedupe agent and cron test scaffolds
This commit is contained in:
@@ -44,18 +44,41 @@ async function readOnboardingState(dir: string): Promise<{
|
||||
};
|
||||
}
|
||||
|
||||
async function expectBootstrapSeeded(dir: string) {
|
||||
await expect(fs.access(path.join(dir, DEFAULT_BOOTSTRAP_FILENAME))).resolves.toBeUndefined();
|
||||
const state = await readOnboardingState(dir);
|
||||
expect(state.bootstrapSeededAt).toMatch(/\d{4}-\d{2}-\d{2}T/);
|
||||
}
|
||||
|
||||
async function expectCompletedWithoutBootstrap(dir: string) {
|
||||
await expect(fs.access(path.join(dir, DEFAULT_IDENTITY_FILENAME))).resolves.toBeUndefined();
|
||||
await expect(fs.access(path.join(dir, DEFAULT_BOOTSTRAP_FILENAME))).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
const state = await readOnboardingState(dir);
|
||||
expect(state.onboardingCompletedAt).toMatch(/\d{4}-\d{2}-\d{2}T/);
|
||||
}
|
||||
|
||||
function expectSubagentAllowedBootstrapNames(files: WorkspaceBootstrapFile[]) {
|
||||
const names = files.map((file) => file.name);
|
||||
expect(names).toContain("AGENTS.md");
|
||||
expect(names).toContain("TOOLS.md");
|
||||
expect(names).toContain("SOUL.md");
|
||||
expect(names).toContain("IDENTITY.md");
|
||||
expect(names).toContain("USER.md");
|
||||
expect(names).not.toContain("HEARTBEAT.md");
|
||||
expect(names).not.toContain("BOOTSTRAP.md");
|
||||
expect(names).not.toContain("MEMORY.md");
|
||||
}
|
||||
|
||||
describe("ensureAgentWorkspace", () => {
|
||||
it("creates BOOTSTRAP.md and records a seeded marker for brand new workspaces", async () => {
|
||||
const tempDir = await makeTempWorkspace("openclaw-workspace-");
|
||||
|
||||
await ensureAgentWorkspace({ dir: tempDir, ensureBootstrapFiles: true });
|
||||
|
||||
await expect(
|
||||
fs.access(path.join(tempDir, DEFAULT_BOOTSTRAP_FILENAME)),
|
||||
).resolves.toBeUndefined();
|
||||
const state = await readOnboardingState(tempDir);
|
||||
expect(state.bootstrapSeededAt).toMatch(/\d{4}-\d{2}-\d{2}T/);
|
||||
expect(state.onboardingCompletedAt).toBeUndefined();
|
||||
await expectBootstrapSeeded(tempDir);
|
||||
expect((await readOnboardingState(tempDir)).onboardingCompletedAt).toBeUndefined();
|
||||
});
|
||||
|
||||
it("recovers partial initialization by creating BOOTSTRAP.md when marker is missing", async () => {
|
||||
@@ -64,11 +87,7 @@ describe("ensureAgentWorkspace", () => {
|
||||
|
||||
await ensureAgentWorkspace({ dir: tempDir, ensureBootstrapFiles: true });
|
||||
|
||||
await expect(
|
||||
fs.access(path.join(tempDir, DEFAULT_BOOTSTRAP_FILENAME)),
|
||||
).resolves.toBeUndefined();
|
||||
const state = await readOnboardingState(tempDir);
|
||||
expect(state.bootstrapSeededAt).toMatch(/\d{4}-\d{2}-\d{2}T/);
|
||||
await expectBootstrapSeeded(tempDir);
|
||||
});
|
||||
|
||||
it("does not recreate BOOTSTRAP.md after completion, even when a core file is recreated", async () => {
|
||||
@@ -129,12 +148,7 @@ describe("ensureAgentWorkspace", () => {
|
||||
|
||||
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/);
|
||||
await expectCompletedWithoutBootstrap(tempDir);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -233,27 +247,11 @@ describe("filterBootstrapFilesForSession", () => {
|
||||
|
||||
it("filters to allowlist for subagent sessions", () => {
|
||||
const result = filterBootstrapFilesForSession(mockFiles, "agent:default:subagent:task-1");
|
||||
const names = result.map((f) => f.name);
|
||||
expect(names).toContain("AGENTS.md");
|
||||
expect(names).toContain("TOOLS.md");
|
||||
expect(names).toContain("SOUL.md");
|
||||
expect(names).toContain("IDENTITY.md");
|
||||
expect(names).toContain("USER.md");
|
||||
expect(names).not.toContain("HEARTBEAT.md");
|
||||
expect(names).not.toContain("BOOTSTRAP.md");
|
||||
expect(names).not.toContain("MEMORY.md");
|
||||
expectSubagentAllowedBootstrapNames(result);
|
||||
});
|
||||
|
||||
it("filters to allowlist for cron sessions", () => {
|
||||
const result = filterBootstrapFilesForSession(mockFiles, "agent:default:cron:daily-check");
|
||||
const names = result.map((f) => f.name);
|
||||
expect(names).toContain("AGENTS.md");
|
||||
expect(names).toContain("TOOLS.md");
|
||||
expect(names).toContain("SOUL.md");
|
||||
expect(names).toContain("IDENTITY.md");
|
||||
expect(names).toContain("USER.md");
|
||||
expect(names).not.toContain("HEARTBEAT.md");
|
||||
expect(names).not.toContain("BOOTSTRAP.md");
|
||||
expect(names).not.toContain("MEMORY.md");
|
||||
expectSubagentAllowedBootstrapNames(result);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user