@@ -37,6 +37,7 @@ class DriverService extends BaseService {
37
37
_construct ( ) {
38
38
this . drivers = { } ;
39
39
this . interface_to_implementation = { } ;
40
+ this . interface_to_test_service = { } ;
40
41
}
41
42
42
43
async [ '__on_registry.collections' ] ( ) {
@@ -77,6 +78,10 @@ class DriverService extends BaseService {
77
78
register_driver ( interface_name , implementation ) {
78
79
this . interface_to_implementation [ interface_name ] = implementation ;
79
80
}
81
+
82
+ register_test_service ( interface_name , service_name ) {
83
+ this . interface_to_test_service [ interface_name ] = service_name ;
84
+ }
80
85
81
86
get_interface ( interface_name ) {
82
87
const o = { } ;
@@ -113,7 +118,8 @@ class DriverService extends BaseService {
113
118
async _call ( { driver, iface, method, args } ) {
114
119
console . log ( '??' , driver , iface , method , args ) ;
115
120
const processed_args = await this . _process_args ( iface , method , args ) ;
116
- if ( Context . get ( 'test_mode' ) ) {
121
+ const test_mode = Context . get ( 'test_mode' ) ;
122
+ if ( test_mode ) {
117
123
processed_args . test_mode = true ;
118
124
}
119
125
@@ -141,18 +147,31 @@ class DriverService extends BaseService {
141
147
142
148
driver = driver ?? iface_to_driver [ iface ] ?? iface ;
143
149
150
+ let skip_usage = false ;
151
+ if ( test_mode && this . interface_to_test_service [ iface ] ) {
152
+ driver = this . interface_to_test_service [ iface ] ;
153
+ }
154
+
144
155
const driver_service_exists = ( ( ) => {
156
+ console . log ( 'CHECKING FOR THIS' , driver , iface ) ;
145
157
return this . services . has ( driver ) &&
146
158
this . services . get ( driver ) . list_traits ( )
147
159
. includes ( iface ) ;
148
160
} ) ( ) ;
149
161
if ( driver_service_exists ) {
150
162
const service = this . services . get ( driver ) ;
163
+
164
+ const caps = service . as ( 'driver-capabilities' ) ;
165
+ if ( test_mode && caps && caps . supports_test_mode ( iface , method ) ) {
166
+ skip_usage = true ;
167
+ }
168
+
151
169
return await this . call_new_ ( {
152
170
actor,
153
171
service,
154
172
service_name : driver ,
155
173
iface, method, args : processed_args ,
174
+ skip_usage,
156
175
} ) ;
157
176
}
158
177
@@ -240,6 +259,7 @@ class DriverService extends BaseService {
240
259
service,
241
260
service_name,
242
261
iface, method, args,
262
+ skip_usage,
243
263
} ) {
244
264
const svc_permission = this . services . get ( 'permission' ) ;
245
265
const reading = await svc_permission . scan (
@@ -324,6 +344,8 @@ class DriverService extends BaseService {
324
344
{
325
345
name : 'enforce monthly usage limit' ,
326
346
on_call : async args => {
347
+ if ( skip_usage ) return args ;
348
+
327
349
// Typo-Tolerance
328
350
if ( effective_policy ?. [ 'monthy-limit' ] ) {
329
351
effective_policy [ 'monthly-limit' ] = effective_policy [ 'monthy-limit' ] ;
@@ -343,6 +365,8 @@ class DriverService extends BaseService {
343
365
return args ;
344
366
} ,
345
367
on_return : async result => {
368
+ if ( skip_usage ) return result ;
369
+
346
370
console . log ( 'monthly usage is returning' ) ;
347
371
const svc_monthlyUsage = services . get ( 'monthly-usage' ) ;
348
372
const extra = {
0 commit comments