mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 11:21:07 +00:00
fix(regression): tolerate legacy skill source metadata
This commit is contained in:
24
src/agents/skills.source.test.ts
Normal file
24
src/agents/skills.source.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveSkillSource } from "./skills/source.js";
|
||||
|
||||
describe("resolveSkillSource", () => {
|
||||
it("prefers sourceInfo.source when present", () => {
|
||||
expect(
|
||||
resolveSkillSource({
|
||||
sourceInfo: { source: "openclaw-bundled" },
|
||||
} as never),
|
||||
).toBe("openclaw-bundled");
|
||||
});
|
||||
|
||||
it("falls back to legacy top-level source", () => {
|
||||
expect(
|
||||
resolveSkillSource({
|
||||
source: "openclaw-managed",
|
||||
} as never),
|
||||
).toBe("openclaw-managed");
|
||||
});
|
||||
|
||||
it("returns unknown when neither source shape is present", () => {
|
||||
expect(resolveSkillSource({} as never)).toBe("unknown");
|
||||
});
|
||||
});
|
||||
@@ -9,5 +9,12 @@ type SkillSourceShapeCompat = Skill & {
|
||||
|
||||
export function resolveSkillSource(skill: Skill): string {
|
||||
const compatSkill = skill as SkillSourceShapeCompat;
|
||||
return compatSkill.source ?? compatSkill.sourceInfo?.source ?? "unknown";
|
||||
const sourceInfoSource =
|
||||
typeof compatSkill.sourceInfo?.source === "string" ? compatSkill.sourceInfo.source.trim() : "";
|
||||
if (sourceInfoSource) {
|
||||
return sourceInfoSource;
|
||||
}
|
||||
const legacySource =
|
||||
typeof compatSkill.source === "string" ? compatSkill.source.trim() : "";
|
||||
return legacySource || "unknown";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user