@@ -71,6 +71,19 @@ async function project(files: Record<string, string | Buffer>, options = {}) {
7171}
7272
7373/** Undoes the newest change still in effect, whoever made it; Cmd+Z steps only over the caller's own. */
74+ /** What 0.8.123 leaves: a log whose baseline never names the media ledger and carries no marker. */
75+ function asWrittenBy0_8_123 ( logFile : string ) {
76+ const lines = readFileSync ( logFile , "utf-8" )
77+ . trim ( )
78+ . split ( "\n" )
79+ . map ( ( line ) => JSON . parse ( line ) ) ;
80+ for ( const record of lines . filter ( ( line ) => line . type === "baseline" ) ) {
81+ delete record . files [ ".media/manifest.jsonl" ] ;
82+ delete record . keepsLedger ;
83+ }
84+ writeFileSync ( logFile , lines . map ( ( record ) => JSON . stringify ( record ) ) . join ( "\n" ) + "\n" ) ;
85+ }
86+
7487async function undoNewest ( history : ProjectHistory ) {
7588 const newest = [ ...history . list ( ) ] . reverse ( ) . find ( ( entry ) => ! entry . undoes && ! entry . undone ) ;
7689 return history . undo ( newest ! . id , { who : you } ) ;
@@ -208,21 +221,31 @@ describe("openProjectHistory", () => {
208221 } ) ;
209222 await change ( history , you , "Your edit" , ( ) => write ( "index.html" , "B" ) ) ;
210223 await history . close ( ) ;
211- const logFile = join ( historyRoot , history . projectId , "log.jsonl" ) ;
212- const lines = readFileSync ( logFile , "utf-8" )
213- . trim ( )
214- . split ( "\n" )
215- . map ( ( line ) => JSON . parse ( line ) ) ;
216- for ( const record of lines . filter ( ( line ) => line . type === "baseline" ) ) {
217- delete record . files [ ".media/manifest.jsonl" ] ;
218- delete record . keepsLedger ;
219- }
220- writeFileSync ( logFile , lines . map ( ( record ) => JSON . stringify ( record ) ) . join ( "\n" ) + "\n" ) ;
224+ asWrittenBy0_8_123 ( join ( historyRoot , history . projectId , "log.jsonl" ) ) ;
221225 const reopened = await open ( projectDir , historyRoot ) ;
222226 expect ( await reopened . step ( "back" , you ) ) . toMatchObject ( { ok : true } ) ;
223227 expect ( [ read ( "index.html" ) , read ( ".media/manifest.jsonl" ) ] ) . toEqual ( [ "A" , "{}\n" ] ) ;
224228 } ) ;
225229
230+ // Windows needs a privilege to create symlinks.
231+ it . skipIf ( process . platform === "win32" ) (
232+ "a log 0.8.123 wrote never takes in a ledger behind a link" ,
233+ async ( ) => {
234+ const { history, projectDir, historyRoot } = await project (
235+ { "index.html" : "A" } ,
236+ { quietMs : 30 } ,
237+ ) ;
238+ await history . close ( ) ;
239+ asWrittenBy0_8_123 ( join ( historyRoot , history . projectId , "log.jsonl" ) ) ;
240+ const outside = tempDir ( "hf-history-linked-" ) ;
241+ writeFileSync ( join ( outside , "manifest.jsonl" ) , "{}\n" ) ;
242+ symlinkSync ( outside , join ( projectDir , ".media" ) , "dir" ) ;
243+ const reopened = await open ( projectDir , historyRoot , { quietMs : 30 } ) ;
244+ await reopened . flush ( ) ;
245+ expect ( reopened . list ( ) ) . toEqual ( [ ] ) ;
246+ } ,
247+ ) ;
248+
226249 it ( "a ledger made while the project was closed is a change like any file, once a log keeps the ledger" , async ( ) => {
227250 const { history, write, read, has, projectDir, historyRoot } = await project (
228251 { "index.html" : "A" } ,
@@ -250,8 +273,10 @@ describe("openProjectHistory", () => {
250273 const cutout = await change ( history , agent , "Cut out the logo" , ( ) => {
251274 write ( "index.html" , "<h1>Hello</h1><img src='logo.png'>" ) ;
252275 write ( ".media/manifest.jsonl" , '{}\n{"id":"logo"}\n' ) ;
276+ write ( ".media/images/logo.png" , "png" ) ;
277+ write ( ".tools/manifest.jsonl" , "{}\n" ) ;
253278 } ) ;
254- expect ( cutout . files . map ( ( file ) => file . path ) ) . toContain ( ".media/manifest.jsonl" ) ;
279+ expect ( cutout . files . map ( ( file ) => file . path ) ) . toEqual ( [ ".media/manifest.jsonl" , "index.html" ] ) ;
255280 expect ( ( await history . undo ( cutout . id , { who : you } ) ) . ok ) . toBe ( true ) ;
256281 expect ( read ( ".media/manifest.jsonl" ) ) . toBe ( "{}\n" ) ;
257282 } ) ;
0 commit comments