feat(ux): T4-b 前端 — 本章指令框 + 风格快捷预设传入 draft 生成

新 lib/workbench/directive.ts (STYLE_PRESETS + composeDirective 纯函数+测);useDraftStream.start 加 directive 参数(非空时 POST JSON body);Workbench 加「本章指令」textarea + 风格预设 chips,写本章时 composeDirective 传入。TDD: directive 测。前端门禁绿。docs(progress): 记 Tier4 完成。
This commit is contained in:
Yaojia Wang
2026-06-20 18:27:47 +02:00
parent 2155193cdc
commit cc0aabdd9a
5 changed files with 214 additions and 49 deletions

View File

@@ -0,0 +1,26 @@
import { describe, expect, it } from "vitest";
import { composeDirective, STYLE_PRESETS } from "./directive";
describe("composeDirective", () => {
it("returns empty string when nothing selected", () => {
expect(composeDirective("", [])).toBe("");
expect(composeDirective(" ", [])).toBe("");
});
it("uses free text only when no presets", () => {
expect(composeDirective("多写战斗", [])).toBe("多写战斗");
});
it("combines presets (in canonical order) then free text", () => {
const result = composeDirective("多写战斗", ["fast-pace", "less-ai"]);
const lessAi = STYLE_PRESETS.find((p) => p.id === "less-ai")!.text;
const fastPace = STYLE_PRESETS.find((p) => p.id === "fast-pace")!.text;
expect(result).toBe(`${lessAi}${fastPace};多写战斗`);
});
it("ignores unknown preset ids", () => {
const lessAi = STYLE_PRESETS.find((p) => p.id === "less-ai")!.text;
expect(composeDirective("", ["nope", "less-ai"])).toBe(lessAi);
});
});