@@ -59,6 +59,34 @@ describeOrSkip('Log Filtering (ignoreContains)', () => {
5959 return null
6060 }
6161
62+ const captureLogsForReason = async (
63+ reasonPrefix : string ,
64+ normalMarker : string ,
65+ emitMessages : ( ) => Promise < void >
66+ ) => {
67+ for ( let attempt = 1 ; attempt <= 3 ; attempt ++ ) {
68+ await emitMessages ( )
69+ // Give Sponge time to flush command output to latest.log before snapshotting logs on report.
70+ await sleep ( 1500 )
71+
72+ const reportReason = `${ reasonPrefix } attempt-${ attempt } ${ Date . now ( ) } `
73+ reporterBot . clearSystemMessages ( )
74+ await reporterBot . sendChat ( `/report FilterTarget ${ reportReason } ` )
75+
76+ const report = await waitForReportByReason ( reportReason )
77+ if ( report == null ) {
78+ continue
79+ }
80+
81+ const logs = await waitForReportLogs ( report . id , normalMarker )
82+ if ( logs . some ( log => log . message . includes ( normalMarker ) ) ) {
83+ return logs
84+ }
85+ }
86+
87+ return null
88+ }
89+
6290 beforeAll ( async ( ) => {
6391 reporterBot = await createBot ( 'FilterReporter' )
6492 await sleep ( 2000 )
@@ -85,153 +113,119 @@ describeOrSkip('Log Filtering (ignoreContains)', () => {
85113 test ( 'normal messages appear in report logs' , async ( ) => {
86114 const uniqueId = Date . now ( )
87115 const normalMessage = `NormalTestMessage_${ uniqueId } `
88- const reportReason = `Testing log capture ${ uniqueId } `
89-
90- // Generate a normal (non-filtered) log message
91- await sendCommand ( `say ${ normalMessage } ` )
92- await sleep ( 500 )
93-
94- // Create a report to trigger log persistence
95- reporterBot . clearSystemMessages ( )
96- await reporterBot . sendChat ( `/report FilterTarget ${ reportReason } ` )
97-
98- const report = await waitForReportByReason ( reportReason )
99- expect ( report ) . not . toBeNull ( )
100-
101- if ( report != null ) {
102- const logs = await waitForReportLogs ( report . id , normalMessage )
103- console . log ( `Report ${ report . id } has ${ logs . length } associated logs` )
116+ const logs = await captureLogsForReason (
117+ 'Testing log capture' ,
118+ normalMessage ,
119+ async ( ) => {
120+ await sendCommand ( `say ${ normalMessage } ` )
121+ }
122+ )
104123
105- // Verify the normal message is in the logs
124+ expect ( logs ) . not . toBeNull ( )
125+ if ( logs != null ) {
126+ console . log ( `Found ${ logs . length } associated logs for normal message test` )
106127 const found = logs . some ( log => log . message . includes ( normalMessage ) )
107128 expect ( found ) . toBe ( true )
108129 }
109- } , 30000 )
130+ } , 60000 )
110131
111132 test ( '[BanManager] messages are filtered from report logs' , async ( ) => {
112133 const uniqueId = Date . now ( )
113134 const bmMessage = `[BanManager] FilteredMessage_${ uniqueId } `
114135 const normalMessage = `NormalMarker_${ uniqueId } `
115- const reportReason = `Testing BanManager filter ${ uniqueId } `
116-
117- // Generate both a filtered and a normal message
118- await sendCommand ( `say ${ bmMessage } ` )
119- await sendCommand ( `say ${ normalMessage } ` )
120- await sleep ( 500 )
121-
122- // Create a report to trigger log persistence
123- reporterBot . clearSystemMessages ( )
124- await reporterBot . sendChat ( `/report FilterTarget ${ reportReason } ` )
125-
126- const report = await waitForReportByReason ( reportReason )
127- expect ( report ) . not . toBeNull ( )
128-
129- if ( report != null ) {
130- const logs = await waitForReportLogs ( report . id , normalMessage )
131- console . log ( `Report ${ report . id } has ${ logs . length } associated logs` )
136+ const logs = await captureLogsForReason (
137+ 'Testing BanManager filter' ,
138+ normalMessage ,
139+ async ( ) => {
140+ await sendCommand ( `say ${ bmMessage } ` )
141+ await sendCommand ( `say ${ normalMessage } ` )
142+ }
143+ )
132144
133- // Verify [BanManager] message is NOT in logs (filtered)
145+ expect ( logs ) . not . toBeNull ( )
146+ if ( logs != null ) {
134147 const bmFound = logs . some ( log => log . message . includes ( bmMessage ) )
135148 expect ( bmFound ) . toBe ( false )
136149
137- // Verify normal message IS in logs (to confirm logs were captured)
138150 const normalFound = logs . some ( log => log . message . includes ( normalMessage ) )
139151 expect ( normalFound ) . toBe ( true )
140152
141- console . log ( ` [BanManager] messages correctly filtered, normal messages captured` )
153+ console . log ( ' [BanManager] messages correctly filtered, normal messages captured' )
142154 }
143- } , 30000 )
155+ } , 60000 )
144156
145157 test ( 'Metrics messages are filtered from report logs' , async ( ) => {
146158 const uniqueId = Date . now ( )
147159 const metricsMessage = `Metrics data test_${ uniqueId } `
148160 const normalMessage = `NormalMarkerMet_${ uniqueId } `
149- const reportReason = `Testing Metrics filter ${ uniqueId } `
150-
151- await sendCommand ( `say ${ metricsMessage } ` )
152- await sendCommand ( `say ${ normalMessage } ` )
153- await sleep ( 500 )
154-
155- reporterBot . clearSystemMessages ( )
156- await reporterBot . sendChat ( `/report FilterTarget ${ reportReason } ` )
157-
158- const report = await waitForReportByReason ( reportReason )
159- expect ( report ) . not . toBeNull ( )
160-
161- if ( report != null ) {
162- const logs = await waitForReportLogs ( report . id , normalMessage )
161+ const logs = await captureLogsForReason (
162+ 'Testing Metrics filter' ,
163+ normalMessage ,
164+ async ( ) => {
165+ await sendCommand ( `say ${ metricsMessage } ` )
166+ await sendCommand ( `say ${ normalMessage } ` )
167+ }
168+ )
163169
164- // Metrics message should be filtered
170+ expect ( logs ) . not . toBeNull ( )
171+ if ( logs != null ) {
165172 const metricsFound = logs . some ( log => log . message . includes ( metricsMessage ) )
166173 expect ( metricsFound ) . toBe ( false )
167174
168- // Normal message should exist
169175 const normalFound = logs . some ( log => log . message . includes ( normalMessage ) )
170176 expect ( normalFound ) . toBe ( true )
171177
172- console . log ( ` Metrics messages correctly filtered` )
178+ console . log ( ' Metrics messages correctly filtered' )
173179 }
174- } , 30000 )
180+ } , 60000 )
175181
176182 test ( '[PlugMan] messages are filtered from report logs' , async ( ) => {
177183 const uniqueId = Date . now ( )
178184 const plugmanMessage = `[PlugMan] Action test_${ uniqueId } `
179185 const normalMessage = `NormalMarkerPlugMan_${ uniqueId } `
180- const reportReason = `Testing PlugMan filter ${ uniqueId } `
181-
182- await sendCommand ( `say ${ plugmanMessage } ` )
183- await sendCommand ( `say ${ normalMessage } ` )
184- await sleep ( 500 )
185-
186- reporterBot . clearSystemMessages ( )
187- await reporterBot . sendChat ( `/report FilterTarget ${ reportReason } ` )
188-
189- const report = await waitForReportByReason ( reportReason )
190- expect ( report ) . not . toBeNull ( )
191-
192- if ( report != null ) {
193- const logs = await waitForReportLogs ( report . id , normalMessage )
186+ const logs = await captureLogsForReason (
187+ 'Testing PlugMan filter' ,
188+ normalMessage ,
189+ async ( ) => {
190+ await sendCommand ( `say ${ plugmanMessage } ` )
191+ await sendCommand ( `say ${ normalMessage } ` )
192+ }
193+ )
194194
195- // [PlugMan] message should be filtered
195+ expect ( logs ) . not . toBeNull ( )
196+ if ( logs != null ) {
196197 const plugmanFound = logs . some ( log => log . message . includes ( plugmanMessage ) )
197198 expect ( plugmanFound ) . toBe ( false )
198199
199- // Normal message should exist
200200 const normalFound = logs . some ( log => log . message . includes ( normalMessage ) )
201201 expect ( normalFound ) . toBe ( true )
202202
203- console . log ( ` [PlugMan] messages correctly filtered` )
203+ console . log ( ' [PlugMan] messages correctly filtered' )
204204 }
205- } , 30000 )
205+ } , 60000 )
206206
207207 test ( 'report command output is filtered from report logs' , async ( ) => {
208208 const uniqueId = Date . now ( )
209209 const reportMessage = 'issued server command: /report'
210210 const normalMessage = `NormalMarkerReport_${ uniqueId } `
211- const reportReason = `Testing report cmd filter ${ uniqueId } `
212-
213- await sendCommand ( `say ${ reportMessage } ` )
214- await sendCommand ( `say ${ normalMessage } ` )
215- await sleep ( 500 )
216-
217- reporterBot . clearSystemMessages ( )
218- await reporterBot . sendChat ( `/report FilterTarget ${ reportReason } ` )
219-
220- const report = await waitForReportByReason ( reportReason )
221- expect ( report ) . not . toBeNull ( )
222-
223- if ( report != null ) {
224- const logs = await waitForReportLogs ( report . id , normalMessage )
211+ const logs = await captureLogsForReason (
212+ 'Testing report cmd filter' ,
213+ normalMessage ,
214+ async ( ) => {
215+ await sendCommand ( `say ${ reportMessage } ` )
216+ await sendCommand ( `say ${ normalMessage } ` )
217+ }
218+ )
225219
226- // Report command message should be filtered
220+ expect ( logs ) . not . toBeNull ( )
221+ if ( logs != null ) {
227222 const reportCmdFound = logs . some ( log => log . message . includes ( reportMessage ) )
228223 expect ( reportCmdFound ) . toBe ( false )
229224
230- // Normal message should exist
231225 const normalFound = logs . some ( log => log . message . includes ( normalMessage ) )
232226 expect ( normalFound ) . toBe ( true )
233227
234- console . log ( ` Report command output correctly filtered` )
228+ console . log ( ' Report command output correctly filtered' )
235229 }
236- } , 30000 )
230+ } , 60000 )
237231} )
0 commit comments