Files
writing-agent/tests/libraries.test.ts
T
chenmoranzhiandCursor 126874b65e 落地偏好库与文风库存盘及注册表,便于创作节点按绑定注入。
先定无检索的节点绑定模型,替代原先未实现的检索方案。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-24 00:58:19 +08:00

55 lines
1.8 KiB
TypeScript

import { describe, expect, it, beforeEach } from "vitest";
import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
describe("libraries registry", () => {
beforeEach(() => {
process.env.WRITING_AGENT_DATA_DIR = mkdtempSync(
path.join(tmpdir(), "wa-lib-"),
);
});
it("formats style-packs and preferences when non-empty", async () => {
const { createStylePack } = await import("../src/style-pack/store.js");
const { ensureStarterPreferences } = await import(
"../src/preference/store.js"
);
const {
formatBoundLibrariesForPrompt,
collectLibraryIdsFromModules,
} = await import("../src/libraries/index.js");
ensureStarterPreferences();
createStylePack({
name: "锋利爽文",
content: "短句推进;示范:他抬眼,门开了。",
});
const style = formatBoundLibrariesForPrompt(["style-packs"]);
expect(style).toContain("【文风库 · 可选用】");
expect(style).toContain("锋利爽文");
const pref = formatBoundLibrariesForPrompt(["preferences"]);
expect(pref).toContain("【偏好库 · 可选用】");
expect(pref).toContain("被 NTR");
expect(formatBoundLibrariesForPrompt(["unknown-lib"])).toBe("");
expect(
collectLibraryIdsFromModules([
{ libraries: ["style-packs"] },
{ libraries: ["preferences", "style-packs"] },
]),
).toEqual(["style-packs", "preferences"]);
});
it("skips empty style-packs library", async () => {
const { formatBoundLibrariesForPrompt } = await import(
"../src/libraries/index.js"
);
// 空文风库 → 空串;偏好库有起步条目仍会有内容
expect(formatBoundLibrariesForPrompt(["style-packs"])).toBe("");
});
});