@@ -39,6 +39,7 @@ class ResultStore {
3939 private sharedStorePath : string ;
4040 private hooks ?: LifecycleHooks ;
4141 private initialized = false ;
42+ private currentNamespace : string | null = null ;
4243
4344 constructor ( enableSharedStore = false , customPath ?: string ) {
4445 this . sharedStorePath = customPath ?? ENV_STORE_PATH ?? DEFAULT_SHARED_STORE_PATH ;
@@ -102,6 +103,30 @@ class ResultStore {
102103 return this . sharedStorePath ;
103104 }
104105
106+ /**
107+ * Set the current namespace for isolating test results.
108+ * Keys will be automatically prefixed with the namespace.
109+ */
110+ setNamespace ( namespace : string | null ) : void {
111+ this . currentNamespace = namespace ;
112+ }
113+
114+ /**
115+ * Get the current namespace
116+ */
117+ getNamespace ( ) : string | null {
118+ return this . currentNamespace ;
119+ }
120+
121+ /**
122+ * Get the namespaced key. If namespace is set, prefixes the key.
123+ */
124+ private getNamespacedKey ( key : string ) : string {
125+ if ( ! this . currentNamespace ) return key ;
126+ if ( key . startsWith ( `${ this . currentNamespace } ::` ) ) return key ;
127+ return `${ this . currentNamespace } ::${ key } ` ;
128+ }
129+
105130 /**
106131 * Set lifecycle hooks
107132 */
@@ -121,43 +146,60 @@ class ResultStore {
121146 }
122147
123148 set < T > ( key : string , status : TestStatus , data ?: T , error ?: Error ) : void {
124- this . results . set ( key , { status, data, error, timestamp : Date . now ( ) } ) ;
149+ const nsKey = this . getNamespacedKey ( key ) ;
150+ this . results . set ( nsKey , { status, data, error, timestamp : Date . now ( ) } ) ;
151+ // Also store without namespace for backward compatibility within same namespace
152+ if ( this . currentNamespace && nsKey !== key ) {
153+ this . results . set ( key , { status, data, error, timestamp : Date . now ( ) } ) ;
154+ }
125155 // Persist to shared store for cross-process access
126156 if ( this . useSharedStore ) {
127157 this . saveToSharedStore ( ) ;
128158 }
129159 }
130160
131161 get < T > ( key : string ) : TestResult < T > | undefined {
132- // Try local first, then check shared store
133- if ( ! this . results . has ( key ) && this . useSharedStore ) {
162+ const nsKey = this . getNamespacedKey ( key ) ;
163+ // Try namespaced key first, then original
164+ if ( this . results . has ( nsKey ) ) {
165+ return this . results . get ( nsKey ) as TestResult < T > | undefined ;
166+ }
167+ if ( this . results . has ( key ) ) {
168+ return this . results . get ( key ) as TestResult < T > | undefined ;
169+ }
170+ // Try shared store
171+ if ( this . useSharedStore ) {
134172 this . loadFromSharedStore ( ) ;
173+ return ( this . results . get ( nsKey ) ?? this . results . get ( key ) ) as TestResult < T > | undefined ;
135174 }
136- return this . results . get ( key ) as TestResult < T > | undefined ;
175+ return undefined ;
137176 }
138177
139178 has ( key : string ) : boolean {
140- if ( this . results . has ( key ) ) return true ;
179+ const nsKey = this . getNamespacedKey ( key ) ;
180+ if ( this . results . has ( nsKey ) || this . results . has ( key ) ) return true ;
141181 // Check shared store
142182 if ( this . useSharedStore ) {
143183 this . loadFromSharedStore ( ) ;
144- return this . results . has ( key ) ;
184+ return this . results . has ( nsKey ) || this . results . has ( key ) ;
145185 }
146186 return false ;
147187 }
148188
149189 getStatus ( key : string ) : TestStatus {
150- if ( ! this . results . has ( key ) && this . useSharedStore ) {
190+ const nsKey = this . getNamespacedKey ( key ) ;
191+ if ( ! this . results . has ( nsKey ) && ! this . results . has ( key ) && this . useSharedStore ) {
151192 this . loadFromSharedStore ( ) ;
152193 }
153- return this . results . get ( key ) ?. status ?? 'pending' ;
194+ return this . results . get ( nsKey ) ?. status ?? this . results . get ( key ) ?. status ?? 'pending' ;
154195 }
155196
156197 getData < T > ( key : string ) : T | undefined {
157- if ( ! this . results . has ( key ) && this . useSharedStore ) {
198+ const nsKey = this . getNamespacedKey ( key ) ;
199+ if ( ! this . results . has ( nsKey ) && ! this . results . has ( key ) && this . useSharedStore ) {
158200 this . loadFromSharedStore ( ) ;
159201 }
160- return this . results . get ( key ) ?. data as T | undefined ;
202+ return ( this . results . get ( nsKey ) ?. data ?? this . results . get ( key ) ?. data ) as T | undefined ;
161203 }
162204
163205 /**
0 commit comments