@@ -40,7 +40,7 @@ function mockQueries(blocks: any[][], pages: any[][]) {
4040 . mockResolvedValueOnce ( pages ) ; // page query
4141}
4242
43- const defaultPage = { id : 10 , name : "test-page" , originalName : "Test Page" , properties : { } } ;
43+ const defaultPage = { id : 10 , name : "test-page" , originalName : "Test Page" , properties : { } , "updated-at" : 1000 } ;
4444
4545beforeEach ( async ( ) => {
4646 vi . clearAllMocks ( ) ;
@@ -58,7 +58,7 @@ beforeEach(async () => {
5858describe ( "indexBlocks" , ( ) => {
5959 it ( "skips unchanged blocks" , async ( ) => {
6060 const blocks = [
61- [ { id : 1 , uuid : "u1" , content : "Hello world this is a test block" , page : { id : 10 } , parent : { id : 10 } } ] ,
61+ [ { id : 1 , uuid : "u1" , content : "Hello world this is a test block" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ,
6262 ] ;
6363 const pages = [ [ defaultPage ] ] ;
6464
@@ -69,7 +69,7 @@ describe("indexBlocks", () => {
6969 await indexBlocks ( ) ;
7070 expect ( mockEmbedTexts ) . toHaveBeenCalledTimes ( 1 ) ;
7171
72- // Second index - same content , should skip
72+ // Second index - same timestamps , should skip
7373 mockEmbedTexts . mockClear ( ) ;
7474 mockQueries ( blocks , pages ) ;
7575 await indexBlocks ( ) ;
@@ -80,16 +80,16 @@ describe("indexBlocks", () => {
8080 const pages = [ [ defaultPage ] ] ;
8181
8282 mockQueries (
83- [ [ { id : 1 , uuid : "u1" , content : "Hello world this is a test block" , page : { id : 10 } , parent : { id : 10 } } ] ] ,
83+ [ [ { id : 1 , uuid : "u1" , content : "Hello world this is a test block" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ] ,
8484 pages ,
8585 ) ;
8686 mockEmbedTexts . mockResolvedValue ( [ [ 0.1 , 0.2 , 0.3 ] ] ) ;
8787
8888 await indexBlocks ( ) ;
8989
90- // Change content
90+ // Change content — updated-at changes
9191 mockQueries (
92- [ [ { id : 1 , uuid : "u1" , content : "Changed content that is different" , page : { id : 10 } , parent : { id : 10 } } ] ] ,
92+ [ [ { id : 1 , uuid : "u1" , content : "Changed content that is different" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 2000 } ] ] ,
9393 pages ,
9494 ) ;
9595 mockEmbedTexts . mockClear ( ) ;
@@ -103,11 +103,11 @@ describe("indexBlocks", () => {
103103 // batchSize is 2
104104 mockQueries (
105105 [
106- [ { id : 1 , uuid : "u1" , content : "First block with enough content" , page : { id : 10 } , parent : { id : 10 } } ] ,
107- [ { id : 2 , uuid : "u2" , content : "Second block with enough content" , page : { id : 10 } , parent : { id : 10 } } ] ,
108- [ { id : 3 , uuid : "u3" , content : "Third block with enough content" , page : { id : 11 } , parent : { id : 11 } } ] ,
106+ [ { id : 1 , uuid : "u1" , content : "First block with enough content" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ,
107+ [ { id : 2 , uuid : "u2" , content : "Second block with enough content" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ,
108+ [ { id : 3 , uuid : "u3" , content : "Third block with enough content" , page : { id : 11 } , parent : { id : 11 } , "updated-at" : 1000 } ] ,
109109 ] ,
110- [ [ defaultPage ] , [ { id : 11 , name : "page-2" , originalName : "Page 2" , properties : { } } ] ] ,
110+ [ [ defaultPage ] , [ { id : 11 , name : "page-2" , originalName : "Page 2" , properties : { } , "updated-at" : 1000 } ] ] ,
111111 ) ;
112112
113113 mockEmbedTexts
@@ -124,8 +124,8 @@ describe("indexBlocks", () => {
124124 it ( "tracks progress" , async ( ) => {
125125 mockQueries (
126126 [
127- [ { id : 1 , uuid : "u1" , content : "Block one with enough content" , page : { id : 10 } , parent : { id : 10 } } ] ,
128- [ { id : 2 , uuid : "u2" , content : "Block two with enough content" , page : { id : 10 } , parent : { id : 10 } } ] ,
127+ [ { id : 1 , uuid : "u1" , content : "Block one with enough content" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ,
128+ [ { id : 2 , uuid : "u2" , content : "Block two with enough content" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ,
129129 ] ,
130130 [ [ defaultPage ] ] ,
131131 ) ;
@@ -141,7 +141,7 @@ describe("indexBlocks", () => {
141141
142142 it ( "clears embeddings on model change" , async ( ) => {
143143 const blocks = [
144- [ { id : 1 , uuid : "u1" , content : "Hello world this is a test block" , page : { id : 10 } , parent : { id : 10 } } ] ,
144+ [ { id : 1 , uuid : "u1" , content : "Hello world this is a test block" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ,
145145 ] ;
146146 const pages = [ [ defaultPage ] ] ;
147147
@@ -170,12 +170,13 @@ describe("indexBlocks", () => {
170170 name : "meeting-notes" ,
171171 originalName : "Meeting Notes" ,
172172 properties : { tags : [ "project-x" , "planning" ] } ,
173+ "updated-at" : 1000 ,
173174 } ;
174175
175176 mockQueries (
176177 [
177- [ { id : 4 , uuid : "u4" , content : "## Project X Updates" , page : { id : 10 } , parent : { id : 10 } } ] ,
178- [ { id : 5 , uuid : "u5" , content : "Discussed timeline and budget" , page : { id : 10 } , parent : { id : 4 } } ] ,
178+ [ { id : 4 , uuid : "u4" , content : "## Project X Updates" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ,
179+ [ { id : 5 , uuid : "u5" , content : "Discussed timeline and budget" , page : { id : 10 } , parent : { id : 4 } , "updated-at" : 1000 } ] ,
179180 ] ,
180181 [ [ meetingPage ] ] ,
181182 ) ;
@@ -199,18 +200,18 @@ describe("indexBlocks", () => {
199200
200201 it ( "re-embeds when page is renamed" , async ( ) => {
201202 const blocks = [
202- [ { id : 1 , uuid : "u1" , content : "Hello world this is a test block" , page : { id : 10 } , parent : { id : 10 } } ] ,
203+ [ { id : 1 , uuid : "u1" , content : "Hello world this is a test block" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ,
203204 ] ;
204205
205- mockQueries ( blocks , [ [ { id : 10 , name : "old-name" , originalName : "Old Name" , properties : { } } ] ] ) ;
206+ mockQueries ( blocks , [ [ { id : 10 , name : "old-name" , originalName : "Old Name" , properties : { } , "updated-at" : 1000 } ] ] ) ;
206207 mockEmbedTexts . mockResolvedValue ( [ [ 0.1 , 0.2 , 0.3 ] ] ) ;
207208
208209 await indexBlocks ( ) ;
209210 expect ( mockEmbedTexts ) . toHaveBeenCalledTimes ( 1 ) ;
210211
211- // Same block, but page renamed
212+ // Same block, but page renamed — page updated-at changes
212213 mockEmbedTexts . mockClear ( ) ;
213- mockQueries ( blocks , [ [ { id : 10 , name : "new-name" , originalName : "New Name" , properties : { } } ] ] ) ;
214+ mockQueries ( blocks , [ [ { id : 10 , name : "new-name" , originalName : "New Name" , properties : { } , "updated-at" : 2000 } ] ] ) ;
214215 mockEmbedTexts . mockResolvedValue ( [ [ 0.4 , 0.5 , 0.6 ] ] ) ;
215216
216217 await indexBlocks ( ) ;
@@ -223,8 +224,8 @@ describe("indexBlocks", () => {
223224 // Initial: block 5 is child of block 4
224225 mockQueries (
225226 [
226- [ { id : 4 , uuid : "u4" , content : "Original parent content here" , page : { id : 10 } , parent : { id : 10 } } ] ,
227- [ { id : 5 , uuid : "u5" , content : "Child block content unchanged" , page : { id : 10 } , parent : { id : 4 } } ] ,
227+ [ { id : 4 , uuid : "u4" , content : "Original parent content here" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ,
228+ [ { id : 5 , uuid : "u5" , content : "Child block content unchanged" , page : { id : 10 } , parent : { id : 4 } , "updated-at" : 1000 } ] ,
228229 ] ,
229230 pages ,
230231 ) ;
@@ -233,12 +234,12 @@ describe("indexBlocks", () => {
233234 await indexBlocks ( ) ;
234235 expect ( mockEmbedTexts ) . toHaveBeenCalledTimes ( 1 ) ;
235236
236- // Parent content changes, child stays the same
237+ // Parent content changes (updated-at changes) , child stays the same
237238 mockEmbedTexts . mockClear ( ) ;
238239 mockQueries (
239240 [
240- [ { id : 4 , uuid : "u4" , content : "Updated parent content here" , page : { id : 10 } , parent : { id : 10 } } ] ,
241- [ { id : 5 , uuid : "u5" , content : "Child block content unchanged" , page : { id : 10 } , parent : { id : 4 } } ] ,
241+ [ { id : 4 , uuid : "u4" , content : "Updated parent content here" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 2000 } ] ,
242+ [ { id : 5 , uuid : "u5" , content : "Child block content unchanged" , page : { id : 10 } , parent : { id : 4 } , "updated-at" : 1000 } ] ,
242243 ] ,
243244 pages ,
244245 ) ;
@@ -251,9 +252,9 @@ describe("indexBlocks", () => {
251252 expect ( texts ) . toHaveLength ( 2 ) ;
252253 } ) ;
253254
254- it ( "stores contextHashes in embedding records" , async ( ) => {
255+ it ( "stores timestamps in embedding records" , async ( ) => {
255256 mockQueries (
256- [ [ { id : 1 , uuid : "u1" , content : "Hello world this is a test block" , page : { id : 10 } , parent : { id : 10 } } ] ] ,
257+ [ [ { id : 1 , uuid : "u1" , content : "Hello world this is a test block" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ] ,
257258 [ [ defaultPage ] ] ,
258259 ) ;
259260 mockEmbedTexts . mockResolvedValue ( [ [ 0.1 , 0.2 , 0.3 ] ] ) ;
@@ -262,14 +263,13 @@ describe("indexBlocks", () => {
262263
263264 const stored = await getAllEmbeddings ( ) ;
264265 expect ( stored ) . toHaveLength ( 1 ) ;
265- expect ( stored [ 0 ] . contextHashes ) . toBeDefined ( ) ;
266- expect ( Array . isArray ( stored [ 0 ] . contextHashes ) ) . toBe ( true ) ;
267- expect ( stored [ 0 ] . contextHashes . length ) . toBeGreaterThan ( 0 ) ;
266+ expect ( stored [ 0 ] . blockUpdatedAt ) . toBe ( 1000 ) ;
267+ expect ( stored [ 0 ] . pageUpdatedAt ) . toBe ( 1000 ) ;
268268 } ) ;
269269
270270 it ( "handles cancellation" , async ( ) => {
271271 mockQueries (
272- [ [ { id : 1 , uuid : "u1" , content : "Block one with enough content" , page : { id : 10 } , parent : { id : 10 } } ] ] ,
272+ [ [ { id : 1 , uuid : "u1" , content : "Block one with enough content" , page : { id : 10 } , parent : { id : 10 } , "updated-at" : 1000 } ] ] ,
273273 [ [ defaultPage ] ] ,
274274 ) ;
275275
0 commit comments