/** * 逐顆查詢的回應要自我說明分支用法(SDD workflow-discovery 3.11;總管 08-01 抽驗第 3 點) * * 判準(leo/總管一致):**AI 只看那一顆的回應,就知道怎麼接下一步**—— * 不必回頭讀 skill、不必猜。看得到分支說明才算數。 * * 取證背景(08-01 prod):逐顆查 if_control 只回 * status/componentId/type/source/input_schema{condition,input}/success_rate/stability * ⇒ **沒有任何欄位說明分支怎麼接** ⇒ 走 n8n 式逐顆查的 AI 只好寫 code。 * * 本檔直接驗 `branchHintFor()`(回應裡那個欄位的來源),並把 AI 實際會看到的內容印出來。 */ import { describe, it, expect } from 'vitest'; import { branchHintFor } from '../src/lib/branch-hints'; describe('三顆分支零件的查詢回應自帶用法(AI 看一眼就知道怎麼接)', () => { for (const id of ['if_control', 'switch', 'try_catch']) { it(`${id}:回應含 branch_field/branches/edge_types/usage/example`, () => { const hint = branchHintFor(id); expect(hint).toBeDefined(); // 這一顆會輸出哪個欄位當分支標籤 expect(hint!.branch_field).toBe('data.branch'); // 接下游要用哪些邊型 expect(hint!.edge_types.length).toBeGreaterThan(0); // 一行說明 + 可照抄範例(缺任一個,AI 都得自己猜) expect(hint!.usage.length).toBeGreaterThan(0); expect(hint!.example.length).toBeGreaterThan(0); // eslint-disable-next-line no-console console.log( `\n──────── 逐顆查 ${id} 時,AI 會看到的 branch_hint ────────\n` + JSON.stringify(hint, null, 2), ); }); } it('if_control 明說 ON_TRUE/ON_FALSE 兩條邊', () => { const h = branchHintFor('if_control')!; expect(h.edge_types).toContain('ON_TRUE'); expect(h.edge_types).toContain('ON_FALSE'); expect(h.branches).toEqual(['true', 'false']); // 明說「不需要自己寫 code 判斷」——這句是防腹語術的關鍵 expect(h.usage).toContain('不需要自己寫 code'); }); it('switch 明說用 ON_BRANCH 並在邊上標 case 名,且 default 不需特別邊型', () => { const h = branchHintFor('switch')!; expect(h.edge_types).toContain('ON_BRANCH'); expect(h.usage).toContain('ON_BRANCH'); expect(h.usage).toContain('default_branch'); // branches 是動態的(由 cases 決定),要誠實說明而非給死清單 expect(typeof h.branches).toBe('string'); }); it('try_catch 明說 try/catch 兩條標籤,錯誤處理不必寫 code', () => { const h = branchHintFor('try_catch')!; expect(h.branches).toEqual(['try', 'catch']); expect(h.edge_types).toContain('ON_BRANCH'); expect(h.usage).toContain('不需要寫 code'); }); it('不分岔的零件沒有 branch_hint(不加噪音)', () => { expect(branchHintFor('http_request')).toBeUndefined(); expect(branchHintFor('code')).toBeUndefined(); expect(branchHintFor(undefined)).toBeUndefined(); }); });