@@ -9,8 +9,15 @@ const storeState = vi.hoisted(() => {
99 const state = {
1010 store : { } as Record < string , SessionEntry > ,
1111 stores : { } as Record < string , Record < string , SessionEntry > > ,
12- loadSessionStore : vi . fn ( ( storePath : string ) => state . stores [ storePath ] ?? state . store ) ,
13- readSessionStoreSnapshot : vi . fn ( ( storePath : string ) => state . stores [ storePath ] ?? state . store ) ,
12+ // Mirrors the accessor view contract: raw exact-key get, enumeration only via entries().
13+ openSessionEntryReadView : vi . fn ( ( scope : { storePath ?: string } ) => {
14+ const store = state . stores [ scope . storePath ?? "" ] ?? state . store ;
15+ return {
16+ get : ( sessionKey : string ) =>
17+ Object . hasOwn ( store , sessionKey ) ? store [ sessionKey ] : undefined ,
18+ entries : ( ) => Object . entries ( store ) . map ( ( [ sessionKey , entry ] ) => ( { sessionKey, entry } ) ) ,
19+ } ;
20+ } ) ,
1421 } ;
1522 return state ;
1623} ) ;
@@ -24,9 +31,8 @@ vi.mock("./paths.js", () => ({
2431 opts ?. agentId === "worker" ? "/tmp/worker-sessions.json" : "/tmp/sessions.json" ,
2532} ) ) ;
2633
27- vi . mock ( "./store.js" , ( ) => ( {
28- loadSessionStore : storeState . loadSessionStore ,
29- readSessionStoreSnapshot : storeState . readSessionStoreSnapshot ,
34+ vi . mock ( "./session-accessor.js" , ( ) => ( {
35+ openSessionEntryReadView : storeState . openSessionEntryReadView ,
3036} ) ) ;
3137
3238vi . mock ( "./targets.js" , ( ) => ( {
@@ -53,8 +59,7 @@ beforeEach(() => {
5359 setActivePluginRegistry ( createSessionConversationTestRegistry ( ) ) ;
5460 storeState . store = { } ;
5561 storeState . stores = { } ;
56- storeState . loadSessionStore . mockClear ( ) ;
57- storeState . readSessionStoreSnapshot . mockClear ( ) ;
62+ storeState . openSessionEntryReadView . mockClear ( ) ;
5863} ) ;
5964
6065describe ( "extractDeliveryInfo" , ( ) => {
@@ -94,7 +99,7 @@ describe("extractDeliveryInfo", () => {
9499 } ) ;
95100 } ) ;
96101
97- it ( "uses session-store snapshots for direct session keys" , ( ) => {
102+ it ( "reads borrowed accessor views for direct session keys" , ( ) => {
98103 const sessionKey = "agent:main:webchat:dm:user-123" ;
99104 storeState . store [ sessionKey ] = buildEntry ( {
100105 channel : "webchat" ,
@@ -105,32 +110,16 @@ describe("extractDeliveryInfo", () => {
105110 const result = extractDeliveryInfo ( sessionKey ) ;
106111
107112 expect ( result . deliveryContext ?. to ) . toBe ( "webchat:user-123" ) ;
108- expect ( storeState . readSessionStoreSnapshot ) . toHaveBeenCalledWith ( "/tmp/sessions.json" ) ;
109- expect ( storeState . loadSessionStore ) . not . toHaveBeenCalled ( ) ;
110- } ) ;
111-
112- it ( "returns deliveryContext for direct session keys" , ( ) => {
113- const sessionKey = "agent:main:webchat:dm:user-123" ;
114- storeState . store [ sessionKey ] = buildEntry ( {
115- channel : "webchat" ,
116- to : "webchat:user-123" ,
117- accountId : "default" ,
118- } ) ;
119-
120- const result = extractDeliveryInfo ( sessionKey ) ;
121-
122- expect ( result ) . toEqual ( {
123- deliveryContext : {
124- channel : "webchat" ,
125- to : "webchat:user-123" ,
126- accountId : "default" ,
127- } ,
128- threadId : undefined ,
113+ expect ( storeState . openSessionEntryReadView ) . toHaveBeenCalledWith ( {
114+ storePath : "/tmp/sessions.json" ,
129115 } ) ;
130116 } ) ;
131117
132- it ( "does not build the normalized index when an exact routable key is present" , ( ) => {
118+ it ( "does not enumerate the store when an exact routable key is present" , ( ) => {
133119 const sessionKey = "agent:main:webchat:dm:user-123" ;
120+ // Enumeration trap: the accessor-view mock lists rows via Object.entries, so
121+ // building the normalized fallback index on this cheap path throws here and
122+ // extractDeliveryInfo would return no delivery context.
134123 storeState . store = new Proxy (
135124 {
136125 [ sessionKey ] : buildEntry ( {
@@ -158,6 +147,26 @@ describe("extractDeliveryInfo", () => {
158147 } ) ;
159148 } ) ;
160149
150+ it ( "returns deliveryContext for direct session keys" , ( ) => {
151+ const sessionKey = "agent:main:webchat:dm:user-123" ;
152+ storeState . store [ sessionKey ] = buildEntry ( {
153+ channel : "webchat" ,
154+ to : "webchat:user-123" ,
155+ accountId : "default" ,
156+ } ) ;
157+
158+ const result = extractDeliveryInfo ( sessionKey ) ;
159+
160+ expect ( result ) . toEqual ( {
161+ deliveryContext : {
162+ channel : "webchat" ,
163+ to : "webchat:user-123" ,
164+ accountId : "default" ,
165+ } ,
166+ threadId : undefined ,
167+ } ) ;
168+ } ) ;
169+
161170 it ( "falls back to base sessions for :thread: keys" , ( ) => {
162171 const baseKey = "agent:main:slack:channel:C0123ABC" ;
163172 const threadKey = `${ baseKey } :thread:1234567890.123456` ;
0 commit comments