@@ -58,7 +58,8 @@ describe("freeze-frame route", () => {
5858 target : { id : "talk" } ,
5959 playhead : 2.5 ,
6060 } ) ;
61- const body : { before ?: string ; after ?: string ; imageSrc ?: string } = await res . json ( ) ;
61+ const body : { before ?: string ; after ?: string ; imageSrc ?: string ; stillPath ?: string } =
62+ await res . json ( ) ;
6263 expect ( res . status ) . toBe ( 200 ) ;
6364 const output = calls [ 0 ] ?. at ( - 1 ) ?? "" ;
6465 expect ( calls [ 0 ] ) . toEqual ( [
@@ -74,6 +75,7 @@ describe("freeze-frame route", () => {
7475 expect ( dirname ( output ) ) . toBe ( join ( dir , "assets/freeze" ) ) ;
7576 expect ( basename ( output ) ) . toMatch ( / ^ t a l k - [ 0 - 9 a - f ] { 10 } - 2 5 0 0 - [ 0 - 9 a - f ] { 8 } \. p n g $ / ) ;
7677 expect ( body . imageSrc ) . toBe ( `assets/freeze/${ basename ( output ) } ` ) ;
78+ expect ( body . stillPath ) . toBe ( `assets/freeze/${ basename ( output ) } ` ) ;
7779 expect ( body . before ) . toBe ( html ) ;
7880 expect ( readFileSync ( join ( dir , "index.html" ) , "utf-8" ) ) . toBe ( body . after ) ;
7981 expect ( body . after ) . toContain ( 'id="talk-freeze"' ) ;
@@ -107,6 +109,25 @@ describe("freeze-frame route", () => {
107109 expect ( readFileSync ( join ( dir , "index.html" ) , "utf-8" ) ) . toBe ( html ) ;
108110 } ) ;
109111
112+ it ( "removes the still it extracted when the page changed before the write" , async ( ) => {
113+ let still = "" ;
114+ const { dir, post } = setup ( async ( args ) => {
115+ still = args . at ( - 1 ) ?? "" ;
116+ writeFileSync ( still , "png" ) ;
117+ writeFileSync ( join ( dir , "index.html" ) , `${ html } \n<!-- edited meanwhile -->` ) ;
118+ return { ok : true } ;
119+ } ) ;
120+ const res = await post ( {
121+ path : "index.html" ,
122+ expectedVersion : fileContentVersion ( html ) ,
123+ target : { id : "talk" } ,
124+ playhead : 2.5 ,
125+ } ) ;
126+ expect ( res . status ) . toBe ( 409 ) ;
127+ expect ( still ) . not . toBe ( "" ) ;
128+ expect ( existsSync ( still ) ) . toBe ( false ) ;
129+ } ) ;
130+
110131 it ( "keeps a traversal clip id inside assets/freeze, for the ffmpeg output and the still's src" , async ( ) => {
111132 const evil = html . replace ( 'id="talk"' , 'id="../../../../outside/frame"' ) ;
112133 const calls : string [ ] [ ] = [ ] ;
@@ -123,9 +144,11 @@ describe("freeze-frame route", () => {
123144 target : { id : "../../../../outside/frame" } ,
124145 playhead : 2.5 ,
125146 } ) ;
126- const body : { imageSrc ?: string ; after ?: string } = await res . json ( ) ;
147+ const body : { imageSrc ?: string ; after ?: string ; stillPath ?: string } = await res . json ( ) ;
127148 expect ( res . status ) . toBe ( 200 ) ;
128149 const output = calls [ 0 ] ?. at ( - 1 ) ?? "" ;
150+ // The history names project files from the project root, not from the page that shows the still.
151+ expect ( body . stillPath ) . toBe ( `assets/freeze/${ basename ( output ) } ` ) ;
129152 expect ( basename ( output ) ) . toMatch ( / ^ _ _ _ _ _ _ _ _ _ _ _ _ o u t s i d e _ f r a m e - [ 0 - 9 a - f ] { 10 } - 2 5 0 0 - / ) ;
130153 expect ( dirname ( output ) ) . toBe ( join ( dir , "assets/freeze" ) ) ;
131154 expect ( body . imageSrc ) . toBe ( `../assets/freeze/${ basename ( output ) } ` ) ;
@@ -199,16 +222,16 @@ describe("freeze-frame route", () => {
199222 expect ( readFileSync ( outputs [ 0 ] ?? "" , "utf-8" ) ) . toBe ( first ) ;
200223 } ) ;
201224
202- it ( "gives concurrent requests distinct stills" , async ( ) => {
225+ it ( "gives concurrent requests distinct stills and keeps only the one the page uses " , async ( ) => {
203226 const outputs : string [ ] = [ ] ;
204227 const { dir, post } = setup ( writingExtractor ( outputs ) ) ;
205228 const results = await Promise . all ( [ freeze ( post , dir , "talk" ) , freeze ( post , dir , "talk" ) ] ) ;
206229 expect ( results . map ( ( res ) => res . status ) . sort ( ) ) . toEqual ( [ 200 , 409 ] ) ;
207230 expect ( new Set ( outputs ) . size ) . toBe ( 2 ) ;
208- expect ( outputs . map ( ( output ) => readFileSync ( output , "utf-8" ) ) ) . toEqual ( [
209- expect . stringContaining ( "#" ) ,
210- expect . stringContaining ( "#" ) ,
211- ] ) ;
231+ const kept = outputs . filter ( ( output ) => existsSync ( output ) ) ;
232+ expect ( kept ) . toHaveLength ( 1 ) ;
233+ expect ( readFileSync ( kept [ 0 ] ?? "" , "utf-8" ) ) . toContain ( "#" ) ;
234+ expect ( readFileSync ( join ( dir , "index.html" ) , "utf-8" ) ) . toContain ( basename ( kept [ 0 ] ?? "" ) ) ;
212235 } ) ;
213236
214237 it ( "refuses, without extracting, when the still's name is already taken" , async ( ) => {
0 commit comments