@@ -7,8 +7,8 @@ import { existsSync, mkdtempSync } from "node:fs";
77import { tmpdir } from "node:os" ;
88import { join } from "node:path" ;
99import { test } from "node:test" ;
10- import { recordLessonEvent , shadowFact } from "../src/ledger_bridge.js" ;
11- import { ledgerLessons , mergedLessons } from "../src/ledger_read.js" ;
10+ import { reconcileFacts , recordLessonEvent , shadowFact } from "../src/ledger_bridge.js" ;
11+ import { ledgerFacts , ledgerLessons , mergedLessons } from "../src/ledger_read.js" ;
1212import { newLesson } from "../src/lessons.js" ;
1313import { lessonsDir , save } from "../src/lessons_store.js" ;
1414import { add , list , readFact } from "../src/recall.js" ;
@@ -36,7 +36,12 @@ const makeLesson = (id) =>
3636 newLesson (
3737 {
3838 id,
39- trigger : { symbols : [ "verifyToken" ] , files : [ ] , keywords : [ ] , action : "edit" } ,
39+ trigger : {
40+ symbols : [ "verifyToken" ] ,
41+ files : [ ] ,
42+ keywords : [ ] ,
43+ action : "edit" ,
44+ } ,
4045 scope : "symbol" ,
4146 whatWentWrong : "forgot to check expiry" ,
4247 correctedBehavior : "assert exp before trusting the token" ,
@@ -90,3 +95,20 @@ test("ledger-only: recall.add writes no fact file; readFact + list resolve from
9095 assert . ok ( list ( store ) . includes ( res . slug ) , "merged list includes the ledger fact" ) ;
9196 } ) ;
9297} ) ;
98+
99+ test ( "ledger-only: reconcileFacts is a no-op and never tombstones ledger facts (no data loss)" , ( ) => {
100+ withEnv ( { FORGE_LEDGER_ONLY : "1" , FORGE_AUTHOR : "Tester <t@example.com>" } , ( ) => {
101+ const store = tmpRoot ( ) ;
102+ const ledgerDir = join ( store , "ledger" ) ;
103+ // Two facts live only in the ledger (no fact files exist under ledger-only).
104+ shadowFact ( ledgerDir , "API base" , "https://api.example.com" , 0 ) ;
105+ shadowFact ( ledgerDir , "DB host" , "db.example.com" , 0 ) ;
106+ assert . equal ( ledgerFacts ( ledgerDir ) . length , 2 , "two live facts before reconcile" ) ;
107+ // Under the file-store model this would tombstone BOTH (no backing file); under
108+ // ledger-only it must leave them untouched.
109+ const r = reconcileFacts ( store , ledgerDir , 1 ) ;
110+ assert . equal ( r . ok , true ) ;
111+ assert . equal ( r . removed , 0 , "reconcile removes nothing under ledger-only" ) ;
112+ assert . equal ( ledgerFacts ( ledgerDir ) . length , 2 , "both facts survive — no memory wiped" ) ;
113+ } ) ;
114+ } ) ;
0 commit comments