@@ -21,21 +21,24 @@ test("issue#89: store.lastDreamRunAt recovers the last run timestamp (with run_t
2121 store . saveDreamRun ( { status : "ok" , snapshot_hash : "h2" , input_count : 1 , receipt : "r" , created_at : "2026-09-09T20:00:00.000Z" , run_type : "sleep" } ) ;
2222 assert . equal ( store . lastDreamRunAt ( ) , Date . parse ( "2026-09-10T01:05:23.640Z" ) , "latest run regardless of type" ) ;
2323 assert . equal ( store . lastDreamRunAt ( "sleep" ) , Date . parse ( "2026-09-09T20:00:00.000Z" ) , "filtered by run_type" ) ;
24+ assert . equal ( store . lastDreamRunAt ( "auto" ) , Date . parse ( "2026-09-10T01:05:23.640Z" ) , "auto filter ignores sleep rows" ) ;
2425 store . close ( ) ;
2526} ) ;
2627
2728test ( "issue#89: dream scheduler seeded from the audit trail — restart no longer bypasses the min interval" , async ( ) => {
2829 const store = createStore ( ":memory:" ) ;
2930 const service = createService ( { store, mirror : null , config : { } } ) ;
3031 // 模拟上一进程刚跑过一轮(10ms 前开跑)并留下审计行,然后「重启」:
32+ // minIntervalMs 取 1min——断言窗口远宽于用例执行时间,真实时钟抖动(调度、
33+ // 慢盘)不会把 10ms 偏移推出闸门外造成间歇性假失败。
3134 store . saveDreamRun ( {
3235 status : "ok" , snapshot_hash : "h" , input_count : 1 , receipt : "r" ,
3336 created_at : new Date ( Date . now ( ) - 10 ) . toISOString ( ) , run_type : "auto"
3437 } ) ;
3538 const dream = createDreamScheduler ( {
3639 onRun : async ( ) => ( { ok : false , error : "llm failed" } ) ,
37- thresholdCount : 1 , thresholdChars : 0 , delayMs : 0 , minIntervalMs : 5000 ,
38- lastRunAtSeed : store . lastDreamRunAt ( ) ,
40+ thresholdCount : 1 , thresholdChars : 0 , delayMs : 0 , minIntervalMs : 60000 ,
41+ lastRunAtSeed : store . lastDreamRunAt ( "auto" ) ,
3942 logger : { warn : ( ) => { } }
4043 } ) ;
4144 service . saveWithDedupe ( { type : "project" , title : "a" , content : "x" } ) ;
@@ -72,3 +75,27 @@ test("issue#89: sleep scheduler seeded — cooldown survives a restart", async (
7275 assert . ok ( rearm , "re-armed for the remaining cooldown window (not dropped, #187 semantics)" ) ;
7376 assert . equal ( rearm . at , lastRunAt + 3_600_000 + 1000 , "re-arms at CD expiry (+1s guard)" ) ;
7477} ) ;
78+
79+ // --- CodeRabbit #291 findings 5/6:index.js 的 seed 注入是单行无分支接线,仓库
80+ // 没有插件级挂载 harness(apply 需要完整宿主 ctx),起全量挂载只为准两条断言
81+ // 不成比例——改为源码级锁:删掉 index.js 的对应注入行即红。import 用绝对路径,
82+ // 不依赖测试进程 CWD。
83+ import { readFileSync } from "node:fs" ;
84+ import { fileURLToPath } from "node:url" ;
85+ const indexSrc = readFileSync ( fileURLToPath ( new URL ( "../src/index.js" , import . meta. url ) ) , "utf8" ) ;
86+
87+ test ( "issue#89: index.js wires the dream scheduler seed from the audit trail" , ( ) => {
88+ assert . match (
89+ indexSrc ,
90+ / l a s t R u n A t S e e d : \s * s t o r e \. l a s t D r e a m R u n A t \( " a u t o " \) / ,
91+ "dream scheduler must seed its min-interval gate from dream_runs (run_type='auto') — remove this line and restart-bypass returns"
92+ ) ;
93+ } ) ;
94+
95+ test ( "issue#89: index.js wires the sleep scheduler seed from the audit trail" , ( ) => {
96+ assert . match (
97+ indexSrc ,
98+ / l a s t R u n A t S e e d : \s * s t o r e \. l a s t D r e a m R u n A t \( " s l e e p " \) / ,
99+ "sleep scheduler must seed its cooldown gate from dream_runs (run_type='sleep') — remove this line and restart-bypass returns"
100+ ) ;
101+ } ) ;
0 commit comments