11// Qa Matrix plugin module implements message scenario runtime E2EE behavior.
22import { randomUUID } from "node:crypto" ;
3- import { startMatrixQaFaultProxy } from "../substrate/fault-proxy.js" ;
43import {
54 buildMatrixQaImageUnderstandingPrompt ,
65 createMatrixQaSplitColorImagePng ,
76 hasMatrixQaExpectedColorReply ,
87 MATRIX_QA_IMAGE_ATTACHMENT_FILENAME ,
98} from "./scenario-media-fixtures.js" ;
10- import {
11- patchMatrixQaGatewayMatrixAccount ,
12- readMatrixQaGatewayMatrixAccount ,
13- replaceMatrixQaGatewayMatrixAccount ,
14- } from "./scenario-runtime-config.js" ;
159import {
1610 buildMatrixE2eeReplyArtifact ,
1711 buildSyncStateAfterMissingEncryptionFaultRule ,
@@ -24,7 +18,6 @@ import {
2418 MATRIX_QA_SYNC_STATE_AFTER_FAULT_RULE_ID ,
2519 MATRIX_QA_SYNC_STATE_AFTER_PARAM ,
2620 isMatrixQaE2eeNoticeTriggeredSutReply ,
27- requireMatrixQaGatewayConfigPath ,
2821 resolveMatrixQaE2eeScenarioGroupRoom ,
2922} from "./scenario-runtime-e2ee-shared.js" ;
3023import {
@@ -67,43 +60,25 @@ export async function runMatrixQaE2eeStateAfterMissingEncryptionScenario(
6760 if ( ! context . restartGatewayAfterStateMutation ) {
6861 throw new Error ( "Matrix E2EE state_after QA scenario requires hard gateway restart support" ) ;
6962 }
63+ if ( ! context . installFaultRule ) {
64+ throw new Error ( "Matrix E2EE state_after QA scenario requires in-place fault injection" ) ;
65+ }
7066 const accountId = context . sutAccountId ?? "sut" ;
71- const configPath = requireMatrixQaGatewayConfigPath ( context ) ;
72- const originalAccountConfig = await readMatrixQaGatewayMatrixAccount ( {
73- accountId,
74- configPath,
75- } ) ;
76- const proxy = await startMatrixQaFaultProxy ( {
77- targetBaseUrl : context . faultProxyTargetBaseUrl ?? context . baseUrl ,
78- ...context . faultProxyObserver ,
79- rules : [ buildSyncStateAfterMissingEncryptionFaultRule ( context . sutAccessToken ) ] ,
80- } ) ;
81- let gatewayPatched = false ;
67+ const faultRule = context . installFaultRule (
68+ buildSyncStateAfterMissingEncryptionFaultRule ( context . sutAccessToken ) ,
69+ ) ;
8270 try {
83- await context . restartGatewayAfterStateMutation (
84- async ( ) => {
85- await patchMatrixQaGatewayMatrixAccount ( {
86- accountId,
87- accountPatch : {
88- homeserver : proxy . baseUrl ,
89- network : {
90- dangerouslyAllowPrivateNetwork : true ,
91- } ,
92- } ,
93- configPath,
94- } ) ;
95- gatewayPatched = true ;
96- } ,
97- {
98- timeoutMs : context . timeoutMs ,
99- waitAccountId : accountId ,
100- } ,
101- ) ;
71+ // Keep the configured homeserver URL stable so the Matrix client reuses
72+ // its existing crypto identity while every post-restart /sync crosses the fault rule.
73+ await context . restartGatewayAfterStateMutation ( async ( ) => undefined , {
74+ timeoutMs : context . timeoutMs ,
75+ waitAccountId : accountId ,
76+ } ) ;
10277 const result = await runMatrixQaE2eeTopLevelScenario ( context , {
10378 scenarioId : "matrix-e2ee-state-after-missing-encryption" ,
10479 tokenPrefix : "MATRIX_QA_E2EE_STATE_AFTER" ,
10580 } ) ;
106- const stateAfterHits = proxy
81+ const stateAfterHits = faultRule
10782 . hits ( )
10883 . filter ( ( hit ) => hit . ruleId === MATRIX_QA_SYNC_STATE_AFTER_FAULT_RULE_ID ) ;
10984 if ( stateAfterHits . length > 0 ) {
@@ -114,7 +89,7 @@ export async function runMatrixQaE2eeStateAfterMissingEncryptionScenario(
11489 return {
11590 artifacts : {
11691 driverEventId : result . driverEventId ,
117- faultProxyBaseUrl : proxy . baseUrl ,
92+ faultProxyBaseUrl : context . baseUrl ,
11893 reply : result . reply ,
11994 roomKey : result . roomKey ,
12095 roomId : result . roomId ,
@@ -126,30 +101,13 @@ export async function runMatrixQaE2eeStateAfterMissingEncryptionScenario(
126101 `encrypted room key: ${ result . roomKey } ` ,
127102 `encrypted room id: ${ result . roomId } ` ,
128103 `driver event: ${ result . driverEventId } ` ,
129- `fault proxy: ${ proxy . baseUrl } ` ,
104+ `fault proxy: ${ context . baseUrl } ` ,
130105 `state_after sync opt-in hits: ${ stateAfterHits . length } ` ,
131106 ...buildMatrixReplyDetails ( "E2EE state_after reply" , result . reply ) ,
132107 ] . join ( "\n" ) ,
133108 } ;
134109 } finally {
135- if ( gatewayPatched ) {
136- await context
137- . restartGatewayAfterStateMutation (
138- async ( ) => {
139- await replaceMatrixQaGatewayMatrixAccount ( {
140- accountConfig : originalAccountConfig ,
141- accountId,
142- configPath,
143- } ) ;
144- } ,
145- {
146- timeoutMs : context . timeoutMs ,
147- waitAccountId : accountId ,
148- } ,
149- )
150- . catch ( ( ) => undefined ) ;
151- }
152- await proxy . stop ( ) . catch ( ( ) => undefined ) ;
110+ faultRule . remove ( ) ;
153111 }
154112}
155113
0 commit comments