fix: preserve claw skill tag settings on upgrades
This commit is contained in:
parent
0a792c7e26
commit
5f5c19f313
@ -222,17 +222,6 @@ export function normalizeCanvasSkillTags(value: unknown): CanvasSkillTag[] {
|
||||
return normalized.slice(0, 30);
|
||||
}
|
||||
|
||||
function mergeCanvasSkillTagsWithDefaultUpdates(value: unknown): CanvasSkillTag[] {
|
||||
const currentTags = normalizeCanvasSkillTags(value);
|
||||
const currentIds = new Set(currentTags.map((tag) => tag.id));
|
||||
const missingDefaultTags = DEFAULT_CANVAS_SKILL_TAGS.filter(
|
||||
(defaultTag) => !currentIds.has(defaultTag.id)
|
||||
);
|
||||
const merged: CanvasSkillTag[] = [...currentTags, ...missingDefaultTags];
|
||||
|
||||
return normalizeCanvasSkillTags(merged);
|
||||
}
|
||||
|
||||
export function normalizeCanvasSkillTagSettings(
|
||||
value: unknown,
|
||||
options: { requireCurrentVersion?: boolean } = {}
|
||||
@ -254,7 +243,7 @@ export function normalizeCanvasSkillTagSettings(
|
||||
return {
|
||||
enabled: row.enabled !== false,
|
||||
title,
|
||||
tags: mergeCanvasSkillTagsWithDefaultUpdates(row.tags),
|
||||
tags: normalizeCanvasSkillTags(row.tags),
|
||||
version: CANVAS_SKILL_TAGS_CONFIG_VERSION,
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import {
|
||||
DEFAULT_CANVAS_SKILL_TAGS,
|
||||
normalizeCanvasSkillTagSettings,
|
||||
type CanvasSkillTag,
|
||||
} from "@/lib/canvas-skill-tags";
|
||||
import {
|
||||
defaultProductPlanningApiConfig,
|
||||
normalizeProductPlanningApiConfig,
|
||||
@ -155,4 +160,40 @@ test.describe.serial("/api/admin/settings", () => {
|
||||
"http://103.118.245.6:6081/v1"
|
||||
);
|
||||
});
|
||||
|
||||
test("canvas skill tag upgrades preserve admin configured tags without restoring defaults", () => {
|
||||
const customTags: CanvasSkillTag[] = [
|
||||
{
|
||||
id: "custom-claw-skill",
|
||||
name: "自定义技能",
|
||||
prompt: "只保留后台手动配置的技能。",
|
||||
placeholder: "后台手动配置",
|
||||
iconName: "message-circle",
|
||||
},
|
||||
];
|
||||
|
||||
const normalized = normalizeCanvasSkillTagSettings(
|
||||
{
|
||||
enabled: true,
|
||||
title: "试试这些 Skills",
|
||||
tags: customTags,
|
||||
version: 1,
|
||||
},
|
||||
{ requireCurrentVersion: true }
|
||||
);
|
||||
|
||||
expect(normalized.title).toBe("试试这些 Skills");
|
||||
expect(normalized.tags).toEqual(customTags);
|
||||
expect(
|
||||
normalized.tags.some((tag) => tag.id === "promotion-diagnosis-db")
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
test("canvas skill tags still use defaults when no stored setting exists", () => {
|
||||
const normalized = normalizeCanvasSkillTagSettings(null, {
|
||||
requireCurrentVersion: true,
|
||||
});
|
||||
|
||||
expect(normalized.tags).toEqual(DEFAULT_CANVAS_SKILL_TAGS);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user