Skip to content

Record

sh
ruby-anything record <repo> <unit-id>                         # generated edge cases
ruby-anything record <repo> <unit-id> --inputs real.jsonl     # {"fn": name, "args": [...]} per line
ruby-anything record <repo> <unit-id> --from-tests -- pytest  # or: npx jest, npx vitest run, node --test
ruby-anything record <repo> <unit-id> --pin-clock             # time and dates read 2026-01-01T00:00:00Z

record 會用產生的輸入與給定的輸入執行原版,並把每次呼叫的回傳值、拋出的例外與輸出存到 rails/port/cases/*.jsonl。這些案例就是移植版必須符合的規格。

你的測試會變成案例

--from-tests -- <test command> 會在函式被插樁的狀態下執行原版自己的測試套件(Python、TypeScript、JavaScript),測試過程中每一次不同的呼叫都會變成案例,和產生的案例放在一起(使用 --no-generate 則只保留這些)。之後原始檔會逐位元組還原,即使中途當掉也一樣。

時鐘

當函式會讀取時鐘(datetime.now、Date.now、time.time、date.today)時,請加上 --pin-clock 錄製。原版看到的時間會是 2026-01-01T00:00:00Z,而 diff 執行移植版時,Time.now、Date.today 與 DateTime.now 也會凍結在同一個時間點。

亂數無法跨語言一致:請改成把隨機值當作參數(或注入一個產生器)。

在 GitHub 上編輯此頁 →