Files
writer-work-flow/apps/web/lib/toolbox/ingest.test.ts
Yaojia Wang f43ccd293f feat(toolbox): T6 创作工具箱通用生成器框架 — 8 新生成器 + 声明驱动落地页 + P2 收尾
通用执行路径驱动全部生成器("加生成器=加一份声明"):
- @llm: ww_agents +7 输出 schema + 7 spec(book-title/blurb/name/golden-finger/
  glossary/opening/fine-outline,只声明 tier)+ build_outline_chapter_context
- @backend: ww_skills GeneratorTool 描述符 + TOOLBOX(11) + get_tool;3 通用端点
  GET /skills/toolbox · POST .../skills/{tool_key}/generate(预览不写库,仅记账) ·
  POST .../ingest(复用 continuity 409 + partition_writes 白名单);纯 context 派发
- @frontend: 工具箱落地页 RSC + 声明驱动 GeneratorRunner + lib/toolbox 纯函数
  + LeftNav「工具箱」+ ⌘K nav-toolbox/action-gen-*;legacy 3 跳现页
- @qa: tests/test_t6_toolbox_e2e.py 5 用例真 pg + mock 网关零 token,无端点 bug
- P2 收尾: 限流→decisions.md 记延后(单用户原型);noopener/Committable 早已修

守不变量 #2(只声明 tier)/#3(预览不写库,入库经验收 gate)/#9(缓存前缀)。无 DB 迁移。
门禁绿: 后端 ruff/format/mypy 195/alembic 无漂移/pytest 583;前端 lint/tsc/vitest 279/build。
spec 回写 PRODUCT_SPEC §7 + ARCHITECTURE §7.2 端点表。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 20:37:55 +02:00

90 lines
2.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildIngestRequest, ingestTable } from "./ingest";
describe("ingestTable", () => {
it("maps ingestable kinds to their target table", () => {
expect(ingestTable("GoldenFingerResult")).toBe("world_entities");
expect(ingestTable("GlossaryResult")).toBe("world_entities");
expect(ingestTable("DetailedOutlineResult")).toBe("outline");
});
it("returns null for non-ingestable kinds", () => {
expect(ingestTable("IdeaListResult")).toBeNull();
expect(ingestTable("unknown")).toBeNull();
});
});
describe("buildIngestRequest", () => {
it("maps golden finger rows into world_entities with merged rules", () => {
const body = buildIngestRequest({
outputKind: "GoldenFingerResult",
rows: [
{ name: "吞噬系统", mechanism: "吞噬获取", growth: "等级提升", limits: "需进食" },
],
acknowledgeConflicts: true,
});
expect(body).toEqual({
world_entities: [
{
type: "力量体系",
name: "吞噬系统",
rules: ["吞噬获取", "等级提升", "需进食"],
},
],
acknowledge_conflicts: true,
});
});
it("drops blank rule parts for golden finger", () => {
const body = buildIngestRequest({
outputKind: "GoldenFingerResult",
rows: [{ name: "x", mechanism: "m", growth: "", limits: "" }],
});
expect(body?.world_entities?.[0]?.rules).toEqual(["m"]);
});
it("maps glossary rows preserving type and rules array", () => {
const body = buildIngestRequest({
outputKind: "GlossaryResult",
rows: [{ name: "灵气", type: "概念", rules: ["不可逆"] }],
});
expect(body?.world_entities?.[0]).toEqual({
type: "概念",
name: "灵气",
rules: ["不可逆"],
});
});
it("defaults glossary type to 概念 when missing", () => {
const body = buildIngestRequest({
outputKind: "GlossaryResult",
rows: [{ name: "灵气" }],
});
expect(body?.world_entities?.[0]?.type).toBe("概念");
});
it("maps detailed outline rows to scenes with chapter_no", () => {
const body = buildIngestRequest({
outputKind: "DetailedOutlineResult",
rows: [
{ idx: 2, beat: "对峙", purpose: "立威", conflict: "正反", hook: "悬念" },
{ beat: "收束" },
],
chapterNo: 7,
});
expect(body?.chapter_no).toBe(7);
expect(body?.scenes).toEqual([
{ idx: 2, beat: "对峙", purpose: "立威", conflict: "正反", hook: "悬念" },
{ idx: 1, beat: "收束", purpose: "", conflict: "", hook: "" },
]);
expect(body?.acknowledge_conflicts).toBe(false);
});
it("returns null for non-ingestable output kind", () => {
expect(
buildIngestRequest({ outputKind: "IdeaListResult", rows: [] }),
).toBeNull();
});
});