11import { describe , expect , it } from "vitest" ;
22import { BoardValidationError } from "./board-layout.js" ;
3- import { InMemoryBoardStore } from "./board-store.js" ;
3+ import type { BoardStore } from "./board-store.js" ;
4+ import { createTestBoardStore } from "./board-store.test-support.js" ;
45
5- function putHtml ( store : InMemoryBoardStore , sessionKey : string , name : string , html = "<p>one</p>" ) {
6+ function putHtml ( store : BoardStore , sessionKey : string , name : string , html = "<p>one</p>" ) {
67 return store . putWidget ( { sessionKey, name, content : { kind : "html" , html } } ) ;
78}
89
9- describe ( "in-memory board store" , ( ) => {
10+ describe ( "board store" , ( ) => {
1011 it ( "creates the implicit main tab and bumps board and widget revisions" , ( ) => {
11- const store = new InMemoryBoardStore ( ) ;
12+ const store = createTestBoardStore ( ) ;
1213 const first = putHtml ( store , "agent:main:main" , "status" ) ;
1314 const second = putHtml ( store , "agent:main:main" , "status" , "<p>two</p>" ) ;
1415 expect ( first ) . toMatchObject ( {
@@ -21,23 +22,26 @@ describe("in-memory board store", () => {
2122 } ) ;
2223
2324 it ( "returns immutable snapshots and lists only existing boards" , ( ) => {
24- const store = new InMemoryBoardStore ( ) ;
25+ const store = createTestBoardStore ( ) ;
2526 putHtml ( store , "session-b" , "b" ) ;
2627 putHtml ( store , "session-a" , "a" ) ;
2728 const snapshot = store . getSnapshot ( "session-a" ) ;
2829 snapshot . tabs [ 0 ] ! . title = "Changed" ;
2930 expect ( store . getSnapshot ( "session-a" ) . tabs [ 0 ] ! . title ) . toBe ( "Main" ) ;
30- expect ( store . listSessionsWithBoards ( ) ) . toEqual ( [ "session-a" , "session-b" ] ) ;
31+ expect ( store . listSessionsWithBoards ( ) ) . toEqual ( [
32+ "agent:main:session-a" ,
33+ "agent:main:session-b" ,
34+ ] ) ;
3135 expect ( store . getSnapshot ( "missing" ) ) . toEqual ( {
32- sessionKey : "missing" ,
36+ sessionKey : "agent:main: missing" ,
3337 revision : 0 ,
3438 tabs : [ ] ,
3539 widgets : [ ] ,
3640 } ) ;
3741 } ) ;
3842
3943 it ( "stores HTML bytes with digest and keeps MCP descriptors non-HTML" , ( ) => {
40- const store = new InMemoryBoardStore ( ) ;
44+ const store = createTestBoardStore ( ) ;
4145 putHtml ( store , "session" , "html" , "<main>ok</main>" ) ;
4246 store . putWidget ( {
4347 sessionKey : "session" ,
@@ -74,7 +78,7 @@ describe("in-memory board store", () => {
7478 } ) ;
7579
7680 it ( "transitions declared widgets through pending grants" , ( ) => {
77- const store = new InMemoryBoardStore ( ) ;
81+ const store = createTestBoardStore ( ) ;
7882 const pending = store . putWidget ( {
7983 sessionKey : "session" ,
8084 name : "networked" ,
@@ -92,14 +96,14 @@ describe("in-memory board store", () => {
9296 } ) ;
9397
9498 it ( "survives reset/new boundaries" , ( ) => {
95- const store = new InMemoryBoardStore ( ) ;
99+ const store = createTestBoardStore ( ) ;
96100 putHtml ( store , "session" , "status" ) ;
97101 // Session reset has no BoardStore call; the stable session key remains authoritative.
98102 expect ( store . getSnapshot ( "session" ) . widgets ) . toHaveLength ( 1 ) ;
99103 } ) ;
100104
101105 it ( "rejects stale grant revisions and accepts the current revision" , ( ) => {
102- const store = new InMemoryBoardStore ( ) ;
106+ const store = createTestBoardStore ( ) ;
103107 const pending = store . putWidget ( {
104108 sessionKey : "session" ,
105109 name : "networked" ,
@@ -123,7 +127,7 @@ describe("in-memory board store", () => {
123127 } ) ;
124128
125129 it ( "enforces the board widget count and UTF-8 HTML byte limits" , ( ) => {
126- const store = new InMemoryBoardStore ( ) ;
130+ const store = createTestBoardStore ( ) ;
127131 for ( let index = 0 ; index < 48 ; index += 1 ) {
128132 putHtml ( store , "session" , `widget-${ index } ` , "ok" ) ;
129133 }
@@ -135,13 +139,13 @@ describe("in-memory board store", () => {
135139 expect ( error ) . toMatchObject ( { code : "invalid_operation" } ) ;
136140 expect ( ( error as Error ) . message ) . toContain ( "more than 48 widgets" ) ;
137141 }
138- expect ( ( ) =>
139- putHtml ( new InMemoryBoardStore ( ) , "session" , "large" , "é" . repeat ( 131_073 ) ) ,
140- ) . toThrow ( "262144 UTF-8 bytes" ) ;
142+ expect ( ( ) => putHtml ( createTestBoardStore ( ) , "session" , "large" , "é" . repeat ( 131_073 ) ) ) . toThrow (
143+ "262144 UTF-8 bytes" ,
144+ ) ;
141145 } ) ;
142146
143147 it ( "bumps once per applyOps transaction and removes widget bytes" , ( ) => {
144- const store = new InMemoryBoardStore ( ) ;
148+ const store = createTestBoardStore ( ) ;
145149 putHtml ( store , "session" , "status" ) ;
146150 const snapshot = store . applyOps ( "session" , [
147151 { kind : "widget_resize" , name : "status" , sizeW : 3 , sizeH : 3 } ,
@@ -153,7 +157,7 @@ describe("in-memory board store", () => {
153157 } ) ;
154158
155159 it ( "preserves position on content updates and honors explicit after placement" , ( ) => {
156- const store = new InMemoryBoardStore ( ) ;
160+ const store = createTestBoardStore ( ) ;
157161 putHtml ( store , "session" , "first" ) ;
158162 putHtml ( store , "session" , "second" ) ;
159163 putHtml ( store , "session" , "third" ) ;
0 commit comments