fix(regression): tolerate legacy skill source metadata

This commit is contained in:
Tak Hoffman
2026-03-27 20:16:20 -05:00
parent 39048e054d
commit 5eb3ea3028
2 changed files with 32 additions and 1 deletions

View 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");
});
});

View File

@@ -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";
}