mirror of https://github.com/openclaw/openclaw.git
test: share workspace skills snapshot helpers
This commit is contained in:
parent
8622395c8b
commit
f0179d3b4a
|
|
@ -43,22 +43,44 @@ function withWorkspaceHome<T>(workspaceDir: string, cb: () => T): T {
|
||||||
return withEnv({ HOME: workspaceDir, PATH: "" }, cb);
|
return withEnv({ HOME: workspaceDir, PATH: "" }, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildSnapshot(
|
||||||
|
workspaceDir: string,
|
||||||
|
options?: Parameters<typeof buildWorkspaceSkillSnapshot>[1],
|
||||||
|
) {
|
||||||
|
return withWorkspaceHome(workspaceDir, () =>
|
||||||
|
buildWorkspaceSkillSnapshot(workspaceDir, {
|
||||||
|
managedSkillsDir: path.join(workspaceDir, ".managed"),
|
||||||
|
bundledSkillsDir: path.join(workspaceDir, ".bundled"),
|
||||||
|
...options,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function cloneTemplateDir(templateDir: string, prefix: string): Promise<string> {
|
async function cloneTemplateDir(templateDir: string, prefix: string): Promise<string> {
|
||||||
const cloned = await fixtureSuite.createCaseDir(prefix);
|
const cloned = await fixtureSuite.createCaseDir(prefix);
|
||||||
await fs.cp(templateDir, cloned, { recursive: true });
|
await fs.cp(templateDir, cloned, { recursive: true });
|
||||||
return cloned;
|
return cloned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function expectSnapshotNamesAndPrompt(
|
||||||
|
snapshot: ReturnType<typeof buildWorkspaceSkillSnapshot>,
|
||||||
|
params: { contains?: string[]; omits?: string[] },
|
||||||
|
) {
|
||||||
|
for (const name of params.contains ?? []) {
|
||||||
|
expect(snapshot.skills.map((skill) => skill.name)).toContain(name);
|
||||||
|
expect(snapshot.prompt).toContain(name);
|
||||||
|
}
|
||||||
|
for (const name of params.omits ?? []) {
|
||||||
|
expect(snapshot.skills.map((skill) => skill.name)).not.toContain(name);
|
||||||
|
expect(snapshot.prompt).not.toContain(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe("buildWorkspaceSkillSnapshot", () => {
|
describe("buildWorkspaceSkillSnapshot", () => {
|
||||||
it("returns an empty snapshot when skills dirs are missing", async () => {
|
it("returns an empty snapshot when skills dirs are missing", async () => {
|
||||||
const workspaceDir = await fixtureSuite.createCaseDir("workspace");
|
const workspaceDir = await fixtureSuite.createCaseDir("workspace");
|
||||||
|
|
||||||
const snapshot = withWorkspaceHome(workspaceDir, () =>
|
const snapshot = buildSnapshot(workspaceDir);
|
||||||
buildWorkspaceSkillSnapshot(workspaceDir, {
|
|
||||||
managedSkillsDir: path.join(workspaceDir, ".managed"),
|
|
||||||
bundledSkillsDir: path.join(workspaceDir, ".bundled"),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(snapshot.prompt).toBe("");
|
expect(snapshot.prompt).toBe("");
|
||||||
expect(snapshot.skills).toEqual([]);
|
expect(snapshot.skills).toEqual([]);
|
||||||
|
|
@ -78,12 +100,7 @@ describe("buildWorkspaceSkillSnapshot", () => {
|
||||||
frontmatterExtra: "disable-model-invocation: true",
|
frontmatterExtra: "disable-model-invocation: true",
|
||||||
});
|
});
|
||||||
|
|
||||||
const snapshot = withWorkspaceHome(workspaceDir, () =>
|
const snapshot = buildSnapshot(workspaceDir);
|
||||||
buildWorkspaceSkillSnapshot(workspaceDir, {
|
|
||||||
managedSkillsDir: path.join(workspaceDir, ".managed"),
|
|
||||||
bundledSkillsDir: path.join(workspaceDir, ".bundled"),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(snapshot.prompt).toContain("visible-skill");
|
expect(snapshot.prompt).toContain("visible-skill");
|
||||||
expect(snapshot.prompt).not.toContain("hidden-skill");
|
expect(snapshot.prompt).not.toContain("hidden-skill");
|
||||||
|
|
@ -204,24 +221,20 @@ describe("buildWorkspaceSkillSnapshot", () => {
|
||||||
body: "x".repeat(5_000),
|
body: "x".repeat(5_000),
|
||||||
});
|
});
|
||||||
|
|
||||||
const snapshot = withWorkspaceHome(workspaceDir, () =>
|
const snapshot = buildSnapshot(workspaceDir, {
|
||||||
buildWorkspaceSkillSnapshot(workspaceDir, {
|
config: {
|
||||||
config: {
|
skills: {
|
||||||
skills: {
|
limits: {
|
||||||
limits: {
|
maxSkillFileBytes: 1000,
|
||||||
maxSkillFileBytes: 1000,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
managedSkillsDir: path.join(workspaceDir, ".managed"),
|
},
|
||||||
bundledSkillsDir: path.join(workspaceDir, ".bundled"),
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(snapshot.skills.map((s) => s.name)).toContain("small-skill");
|
expectSnapshotNamesAndPrompt(snapshot, {
|
||||||
expect(snapshot.skills.map((s) => s.name)).not.toContain("big-skill");
|
contains: ["small-skill"],
|
||||||
expect(snapshot.prompt).toContain("small-skill");
|
omits: ["big-skill"],
|
||||||
expect(snapshot.prompt).not.toContain("big-skill");
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("detects nested skills roots beyond the first 25 entries", async () => {
|
it("detects nested skills roots beyond the first 25 entries", async () => {
|
||||||
|
|
@ -241,26 +254,23 @@ describe("buildWorkspaceSkillSnapshot", () => {
|
||||||
description: "Nested skill discovered late",
|
description: "Nested skill discovered late",
|
||||||
});
|
});
|
||||||
|
|
||||||
const snapshot = withWorkspaceHome(workspaceDir, () =>
|
const snapshot = buildSnapshot(workspaceDir, {
|
||||||
buildWorkspaceSkillSnapshot(workspaceDir, {
|
config: {
|
||||||
config: {
|
skills: {
|
||||||
skills: {
|
load: {
|
||||||
load: {
|
extraDirs: [repoDir],
|
||||||
extraDirs: [repoDir],
|
},
|
||||||
},
|
limits: {
|
||||||
limits: {
|
maxCandidatesPerRoot: 30,
|
||||||
maxCandidatesPerRoot: 30,
|
maxSkillsLoadedPerSource: 30,
|
||||||
maxSkillsLoadedPerSource: 30,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
managedSkillsDir: path.join(workspaceDir, ".managed"),
|
},
|
||||||
bundledSkillsDir: path.join(workspaceDir, ".bundled"),
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(snapshot.skills.map((s) => s.name)).toContain("late-skill");
|
expectSnapshotNamesAndPrompt(snapshot, {
|
||||||
expect(snapshot.prompt).toContain("late-skill");
|
contains: ["late-skill"],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("enforces maxSkillFileBytes for root-level SKILL.md", async () => {
|
it("enforces maxSkillFileBytes for root-level SKILL.md", async () => {
|
||||||
|
|
@ -274,24 +284,21 @@ describe("buildWorkspaceSkillSnapshot", () => {
|
||||||
body: "x".repeat(5_000),
|
body: "x".repeat(5_000),
|
||||||
});
|
});
|
||||||
|
|
||||||
const snapshot = withWorkspaceHome(workspaceDir, () =>
|
const snapshot = buildSnapshot(workspaceDir, {
|
||||||
buildWorkspaceSkillSnapshot(workspaceDir, {
|
config: {
|
||||||
config: {
|
skills: {
|
||||||
skills: {
|
load: {
|
||||||
load: {
|
extraDirs: [rootSkillDir],
|
||||||
extraDirs: [rootSkillDir],
|
},
|
||||||
},
|
limits: {
|
||||||
limits: {
|
maxSkillFileBytes: 1000,
|
||||||
maxSkillFileBytes: 1000,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
managedSkillsDir: path.join(workspaceDir, ".managed"),
|
},
|
||||||
bundledSkillsDir: path.join(workspaceDir, ".bundled"),
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(snapshot.skills.map((s) => s.name)).not.toContain("root-big-skill");
|
expectSnapshotNamesAndPrompt(snapshot, {
|
||||||
expect(snapshot.prompt).not.toContain("root-big-skill");
|
omits: ["root-big-skill"],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue