/specengine:spec-04-generate-test-stubfrom SpecEngine
Generates deterministic red-light step definitions, driver interfaces, and fixture wiring from formalized .feature files, following architecture-manifest.md declarations for BDD framework, directory structure, and binding layer.
Ships in SpecEngine. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
把 .feature 的每個步驟綁成真正可執行的 Step Definition,並建立 step 與被測系統之間的綁定契約(Driver 介面)。產出全部拋確定性失敗,建立 TDD 紅燈基準。spec-05 要做的事因此從「呼叫產品碼」變成「實作明確的介面」。
.claude/spec/architecture-manifest.md 第 1、3、5 節,本 Skill 不預設任何技術棧。driver 與 direct 之間選擇並填入 manifest,再繼續。這是團隊決策,不可代選。.feature 步驟文字一致,雙引號參數一律以 {string} 接收(見 contract-rules 第 3.3 條)。這些字串就是 spec-05 期間 spec-guard.js 凍結的對象。driver 時):step 函式體只做「參數型別轉換 → 呼叫 Driver 介面方法 → 斷言」,不含任何 Playwright、HTTP、ORM 細節。所有技術細節都在 Driver 實作裡。Contract Not Implemented(或該語言對應的例外)。en(預設)時用英文識別字與 kebab-case 英文檔名、中文放註解;zh-TW 時用領域中文識別字與中文檔名。範例檔兩種都有示範。@binds 必須指向真的存在的方法:spec-guard.js snapshot 會逐一驗證 step 檔的 @binds X.y 在 Driver 介面檔中找得到 y,找不到會 Fail Loud,spec-05 開不了工。產出後自己先跑一次 snapshot 確認。取得 Step Definitions Directory、Driver Directory、Binding Layer、BDD Execution Framework、Assertion Library、Test Data Seeding Strategy、命名規範。檢查框架安裝狀態與 Binding Layer(硬性約束 2、3)。
優先用框架本身的 dry-run 取得未定義步驟清單與函式樣板,而非由 LLM 從 .feature 轉寫:
--dry-run --format snippets(輸出會逐 Scenario 重複,先依句型去重)npx bddgen,再執行測試取得 undefined step 報告框架無 dry-run 能力時,才退回解析 .feature 自行產生。
.feature 的 Rule/Scenario/Background 階層與 @rule: tag。erm.dbml 實體屬性表,供 @schema 註解。每個不重複的步驟一個函式,寫入 Step Definitions Directory,檔名依 manifest 第 3 節。每個 Step 上方三行註解:
// @rule R-XXXX-NNN, R-XXXX-MMM(多條以逗號分隔,寫完整 ID;全模組共用的 Step 寫 R-<MODULE_ID>-*)
// @schema Entity.column: type(無資料綁定寫 none)
// @binds <Driver 介面>.<方法>(direct 模式寫 <Service>.<方法>)
函式體:driver 模式呼叫 Driver 介面;direct 模式直接拋例外,由 spec-05 接 Service。結構 Read references/typescript-stub-example.md,API 依 manifest 框架替換。
driver 時)<Driver Directory>/<模組名稱>.driver.<副檔名>:依 Step 3 的 @binds 彙整出所有方法,只有簽章與一行說明。有 interface 的語言用 interface;沒有的語言(JavaScript、Python)用「全部方法拋 Contract Not Implemented 的基底類別」當介面檔。檔名與識別字語言依硬性約束 8。此檔會被 spec-guard 全字節凍結。<模組名稱>.inprocess.<副檔名>:實作介面,每個方法拋 Contract Not Implemented。spec-05 的紅綠迴路用它。<模組名稱>.ui.<副檔名> 或 .api.<副檔名>,同樣全部拋例外。兩欄皆〔待確認〕則不產,彙報註明「僅 in-process」。<Test Root Directory>/fixtures.<副檔名> 不存在則建立,依環境變數(例如 BINDING=inprocess|ui)選擇 Driver 實作並注入 step。已存在則只追加本模組的 fixture。確認框架真的會載入它:檢查框架設定檔(例如 cucumber 的 require/import 路徑、playwright 的 testDir)是否涵蓋 fixture 檔;不涵蓋就在 step 檔內 require/import 它,並在彙報註明。Binding Layer 為 direct 時跳過本步驟。
將 overview.md 本模組狀態 FORMALIZED → STUBBED。
.feature 一致,附 @rule、@schema、@bindsdriver 模式:介面檔、至少一個實作、fixture 接線已產出;step 內不含技術細節spec-guard.js snapshot 可成功建立(@binds 全部有效)STUBBED[Phase 04: Generate Test Stub] 執行完成!模組:<MODULE_ID>
1. 框架:<框架>(已安裝 | 未安裝,已提示);Binding Layer:<driver | direct>
2. 產出:
- <Step Definitions Directory>/<檔名>(Step X 個)
- <Driver Directory>/<模組>.driver.<ext>(方法 Y 個)
- <Driver Directory>/<模組>.inprocess.<ext>、<模組>.ui.<ext>
- <Test Root>/fixtures.<ext>(新建 | 追加)
3. 對齊 DBML 欄位 Z 個,100% Red Stage
4. 模組階段狀態:STUBBED(已寫回 .specengine/sdd/overview.md)
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub yi-luan/specengine-plugin --plugin specengine12 skills in this plugin
/spec-00-scope-split當使用者輸入 /spec-00 [path]、/spec-run(帶來新需求時),或說「評估需求大小」「這個需求要不要切」「幫我切分需求」「拆成幾個模組」時使用。在 spec-01 之前評估一份新需求的大小:未超過門檻就以單一模組繼續;超過門檻就自動決定切分方案並落盤,只有不確定之處會改變下一個要跑的模組範圍時才停下來問,其餘疑點放進待人檢視清單、不阻擋流程。之後 spec-01 一次只掃一個模組。/spec-01-discovery-bootstrap當使用者輸入 /spec-01 [path]、/spec-run,或說「冷啟動」「掃需求」「幫我分析這個需求」時使用。對新需求靜態掃描:鎖定核心業務切片、抽取行為矩陣與 DBML 草稿、初始化術語表、套用既有組織慣例、以高風險探測清單找盲點並轉成 MCQ 佇列。純掃描器角色,唯一允許問的是「這屬於哪個模組」。新需求必須先經 spec-00 確認切分方案,本階段一次只掃方案中的一個模組。/spec-02-interactive-clarify當使用者輸入 /spec-02 [MODULE_ID]、/spec-run,或說「釐清」「回答問題」「繼續問我」時使用。把 .specengine/sdd/ 佇列裡的未決問題以白話選擇題分組詢問使用者(優先用 AskUserQuestion 工具),每題答完立即把決策寫回行為矩陣、刻意不做清單或 .specengine/spec/。未答的題一律掛起為 PARKED。/spec-03-formalize-gherkin當使用者輸入 /spec-03 [MODULE_ID]、/spec-run,或說「形式化」「產生 feature 檔」「寫 Gherkin」時使用。把已釐清並通過流程對齊的模組矩陣形式化為 Gherkin,逐列核對 Examples 可由矩陣推導,產出 .specengine/spec/features/*.feature,並以 feature-lint.js 實際驗證。/spec-05-coder-implement當使用者輸入 /spec-05 [MODULE_ID]、/spec-run,或說「開始實作」「寫代碼」「紅轉綠」時使用。把 spec-04 產出的紅燈測試改為綠燈:先實作 Driver 介面接產品碼,再寫產品碼。以 spec-guard.js 凍結規格、Step 句型與 Driver 介面;完工後 lock。/spec-06-drift-audit當使用者輸入 /spec-06,或說「巡檢」「規格漂移」「檢查跟現實有沒有脫鉤」時使用。比對 .specengine/spec/erm.dbml 與實際資料庫 Schema、比對 Rule 覆蓋率與測試結果,找出漂移並推入佇列。純唯讀巡檢,不自動修正任一邊。不屬於 spec-run 串接範圍。Other plugins' skills for the same job