fix(skills): repair renameSkill directory resolution after merge
Use getRequestDirectory and x-opencode-directory like the other skill mutations, and pin renamable list/store mapping with focused tests. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
This commit is contained in:
co-authored by
Serhii Dziupin
parent
5b9a8c4bef
commit
0d24d0a167
@@ -98,9 +98,94 @@ describe('useSkillsStore directory resolution', () => {
|
||||
source: 'agents',
|
||||
description: 'Repository local',
|
||||
group: undefined,
|
||||
renamable: false,
|
||||
}]);
|
||||
});
|
||||
|
||||
test('loadSkills maps authoritative renamable from the list response', async () => {
|
||||
runtimeFetchImpl = async () => new Response(JSON.stringify({
|
||||
skills: [
|
||||
{
|
||||
name: 'managed-skill',
|
||||
path: `${activeProjectPath}/.opencode/skills/managed-skill/SKILL.md`,
|
||||
scope: 'project',
|
||||
source: 'opencode',
|
||||
renamable: true,
|
||||
sources: { md: { description: 'Managed' } },
|
||||
},
|
||||
{
|
||||
name: 'cache-skill',
|
||||
path: '/home/ubuntu/.cache/opencode/skills/hash/cache-skill/SKILL.md',
|
||||
scope: 'user',
|
||||
source: 'opencode',
|
||||
renamable: false,
|
||||
sources: { md: { description: 'Cache' } },
|
||||
},
|
||||
],
|
||||
}), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
expect(await useSkillsStore.getState().loadSkills()).toBe(true);
|
||||
expect(useSkillsStore.getState().skills).toEqual([
|
||||
{
|
||||
name: 'managed-skill',
|
||||
path: `${activeProjectPath}/.opencode/skills/managed-skill/SKILL.md`,
|
||||
scope: 'project',
|
||||
source: 'opencode',
|
||||
description: 'Managed',
|
||||
group: undefined,
|
||||
renamable: true,
|
||||
},
|
||||
{
|
||||
name: 'cache-skill',
|
||||
path: '/home/ubuntu/.cache/opencode/skills/hash/cache-skill/SKILL.md',
|
||||
scope: 'user',
|
||||
source: 'opencode',
|
||||
description: 'Cache',
|
||||
group: 'hash',
|
||||
renamable: false,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('renameSkill uses getRequestDirectory query and x-opencode-directory header', async () => {
|
||||
runtimeFetchImpl = async (_url, init) => {
|
||||
if (init?.method === 'PATCH') {
|
||||
return new Response(JSON.stringify({
|
||||
success: true,
|
||||
requiresReload: false,
|
||||
}), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
skills: [{
|
||||
name: 'new-skill',
|
||||
path: `${activeProjectPath}/.opencode/skills/new-skill/SKILL.md`,
|
||||
scope: 'project',
|
||||
source: 'opencode',
|
||||
renamable: true,
|
||||
sources: { md: { description: 'Renamed' } },
|
||||
}],
|
||||
}), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
};
|
||||
|
||||
const renamed = await useSkillsStore.getState().renameSkill('old-skill', 'new-skill');
|
||||
expect(renamed).toBe(true);
|
||||
|
||||
const renameCall = runtimeFetchCalls.find((call) => String(call.url).includes('/api/config/skills/old-skill'));
|
||||
expect(renameCall).toBeTruthy();
|
||||
expect(renameCall?.url).toContain(`directory=${encodeURIComponent(activeProjectPath)}`);
|
||||
|
||||
const headers = new Headers(renameCall?.headers);
|
||||
expect(headers.get('content-type')).toBe('application/json');
|
||||
expect(headers.get('x-opencode-directory')).toBe(activeProjectPath);
|
||||
});
|
||||
|
||||
test('invalidateSkillsLoadCache() with no argument clears the active-project cache key used by loadSkills', async () => {
|
||||
expect(await useSkillsStore.getState().loadSkills()).toBe(true);
|
||||
expect(runtimeFetchCalls.length).toBe(1);
|
||||
|
||||
@@ -408,12 +408,15 @@ export const useSkillsStore = create<SkillsStore>()(
|
||||
startConfigUpdate("Renaming skill...");
|
||||
let requiresReload = false;
|
||||
try {
|
||||
const currentDirectory = getCurrentDirectory();
|
||||
const queryParams = currentDirectory ? `?directory=${encodeURIComponent(currentDirectory)}` : '';
|
||||
const directory = getRequestDirectory();
|
||||
const queryParams = directory ? `?directory=${encodeURIComponent(directory)}` : '';
|
||||
|
||||
const response = await runtimeFetch(`/api/config/skills/${encodeURIComponent(name)}${queryParams}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(directory ? { 'x-opencode-directory': directory } : {}),
|
||||
},
|
||||
body: JSON.stringify({ renameTo: newName }),
|
||||
});
|
||||
|
||||
@@ -424,7 +427,7 @@ export const useSkillsStore = create<SkillsStore>()(
|
||||
}
|
||||
|
||||
const needsReload = payload?.requiresReload ?? false;
|
||||
invalidateSkillsLoadCache(currentDirectory);
|
||||
invalidateSkillsLoadCache(directory);
|
||||
if (needsReload) {
|
||||
requiresReload = true;
|
||||
await refreshSkillsAfterOpenCodeRestart({
|
||||
|
||||
Reference in New Issue
Block a user