feat(agent): 场景胶囊 - 为会话挂载预设技能组合 (#608)

This commit is contained in:
Wyatt_K
2026-09-23 16:15:34 +08:00
committed by ddCat
parent ec81a1b92b
commit 67cbda6cd6
5 changed files with 391 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
import { expect, test } from "bun:test";
import { apiClient } from "@/services/api/request";
import { listAddedSkills } from "@/services/api/skills";
import { addSkill, listAddedSkills } from "@/services/api/skills";
test("added Skills retries a transient backend proxy failure", async () => {
const original = apiClient.request;
@@ -25,3 +25,31 @@ test("added Skills retries a transient backend proxy failure", async () => {
apiClient.request = original;
}
});
test("a pending skills response cannot replace the cache after installation", async () => {
const original = apiClient.request;
let resolveStale: ((value: unknown) => void) | undefined;
const staleResponse = new Promise((resolve) => { resolveStale = resolve; });
let reads = 0;
const envelope = (skills: unknown[]) => ({ data: { code: 0, data: { skills }, msg: "ok" }, status: 200, headers: {} });
apiClient.request = (async (config) => {
if (config.method === "post") return envelope([]);
reads += 1;
return reads === 1 ? staleResponse : envelope([{ skillId: "preset", isAdded: true }]);
}) as typeof apiClient.request;
try {
await addSkill("preset"); // Invalidate a cache left by another reader.
const pending = listAddedSkills();
await addSkill("preset");
const fresh = await listAddedSkills();
resolveStale?.(envelope([]));
await pending;
expect(fresh.skills).toEqual([{ skillId: "preset", isAdded: true }]);
expect((await listAddedSkills()).skills).toEqual(fresh.skills);
expect(reads).toBe(2);
} finally {
resolveStale?.(envelope([]));
apiClient.request = original;
}
});