@@ -177,10 +177,13 @@ describe('Logs', () => {
177177 projectName : 'test-project' ,
178178 logStoreName : 'test-logstore' ,
179179 topic : 'FCLogs:test-function' ,
180+ topicFilter : '__topic__:"FCLogs:test-function"' ,
180181 query : '' ,
181182 search : '' ,
182183 qualifier : '' ,
183184 match : '' ,
185+ requestId : '' ,
186+ instanceId : '' ,
184187 } ;
185188 // Call the single iteration method
186189 await this . _realtimeOnce ( params ) ;
@@ -212,6 +215,8 @@ describe('Logs', () => {
212215 projectName : 'test-project' ,
213216 logStoreName : 'test-logstore' ,
214217 topic : 'FCLogs:test-function' ,
218+ topicFilter : '__topic__:"FCLogs:test-function"' ,
219+ functionName : 'test-function' ,
215220 } ) ,
216221 ) ;
217222 } ) ;
@@ -244,8 +249,29 @@ describe('Logs', () => {
244249 const props = await ( logs as any ) . getInputs ( ) ;
245250
246251 expect ( props . topic ) . toBe ( 'test-function' ) ;
252+ expect ( props . topicFilter ) . toBe ( '__topic__:"test-function"' ) ;
247253 expect ( props . query ) . toBe ( 'LATEST' ) ;
248254 } ) ;
255+
256+ it ( 'should include FCInstanceEvents topic when instance-id is specified' , async ( ) => {
257+ mockInputs . args = [ '--instance-id' , 'c-69f8a959-15f8e4fe-b867da209124' ] ;
258+ logs = new Logs ( mockInputs ) ;
259+
260+ const props = await ( logs as any ) . getInputs ( ) ;
261+
262+ expect ( props . topicFilter ) . toBe (
263+ '(__topic__:"FCLogs:test-function" or __topic__:"FCInstanceEvents:/test-function")' ,
264+ ) ;
265+ } ) ;
266+
267+ it ( 'should not unset LATEST qualifier' , async ( ) => {
268+ mockInputs . args = [ '--qualifier' , 'LATEST' ] ;
269+ logs = new Logs ( mockInputs ) ;
270+
271+ const props = await ( logs as any ) . getInputs ( ) ;
272+
273+ expect ( props . qualifier ) . toBe ( 'LATEST' ) ;
274+ } ) ;
249275 } ) ;
250276
251277 describe ( 'getFunction' , ( ) => {
@@ -291,6 +317,7 @@ describe('Logs', () => {
291317 projectName : 'test-project' ,
292318 logStoreName : 'test-logstore' ,
293319 topic : 'FCLogs:test-function' ,
320+ topicFilter : '__topic__:"FCLogs:test-function"' ,
294321 query : '' ,
295322 search : '' ,
296323 type : '' ,
@@ -299,6 +326,7 @@ describe('Logs', () => {
299326 qualifier : '' ,
300327 startTime : '' ,
301328 endTime : '' ,
329+ functionName : 'test-function' ,
302330 } ;
303331
304332 const result = await ( logs as any ) . history ( params ) ;
@@ -318,6 +346,7 @@ describe('Logs', () => {
318346 projectName : 'test-project' ,
319347 logStoreName : 'test-logstore' ,
320348 topic : 'FCLogs:test-function' ,
349+ topicFilter : '__topic__:"FCLogs:test-function"' ,
321350 query : '' ,
322351 search : '' ,
323352 type : '' ,
@@ -326,6 +355,7 @@ describe('Logs', () => {
326355 qualifier : '' ,
327356 startTime : '2023-01-01T00:00:00Z' ,
328357 endTime : '2023-01-01T01:00:00Z' ,
358+ functionName : 'test-function' ,
329359 } ;
330360
331361 const result = await ( logs as any ) . history ( params ) ;
@@ -338,6 +368,7 @@ describe('Logs', () => {
338368 projectName : 'test-project' ,
339369 logStoreName : 'test-logstore' ,
340370 topic : 'FCLogs:test-function' ,
371+ topicFilter : '__topic__:"FCLogs:test-function"' ,
341372 query : '' ,
342373 search : '' ,
343374 type : '' ,
@@ -346,6 +377,7 @@ describe('Logs', () => {
346377 qualifier : '' ,
347378 startTime : 'invalid-date' ,
348379 endTime : 'also-invalid' ,
380+ functionName : 'test-function' ,
349381 } ;
350382
351383 await expect ( ( logs as any ) . history ( params ) ) . rejects . toThrow (
@@ -367,10 +399,13 @@ describe('Logs', () => {
367399 projectName : 'test-project' ,
368400 logStoreName : 'test-logstore' ,
369401 topic : 'FCLogs:test-function' ,
402+ topicFilter : '__topic__:"FCLogs:test-function"' ,
370403 query : '' ,
371404 search : '' ,
372405 qualifier : '' ,
373406 match : '' ,
407+ requestId : '' ,
408+ instanceId : '' ,
374409 } ;
375410
376411 // We'll only run one iteration in the test
@@ -526,9 +561,12 @@ describe('Logs', () => {
526561 'LATEST' ,
527562 'req-123' ,
528563 'inst-456' ,
564+ '__topic__:"FCLogs:test-function"' ,
529565 ) ;
530566
531- expect ( result ) . toBe ( 'baseQuery and searchTerm and LATEST and inst-456 and req-123' ) ;
567+ expect ( result ) . toBe (
568+ '__topic__:"FCLogs:test-function" and baseQuery and searchTerm and qualifier: "LATEST" and instanceID: "inst-456" and requestId: "req-123"' ,
569+ ) ;
532570 } ) ;
533571
534572 it ( 'should generate SLS query with some parameters' , ( ) => {
@@ -542,6 +580,47 @@ describe('Logs', () => {
542580
543581 expect ( result ) . toBe ( '' ) ;
544582 } ) ;
583+
584+ it ( 'should generate topicFilter with FCInstanceEvents when instanceId is specified' , ( ) => {
585+ const result = ( logs as any ) . getSlsQuery (
586+ null ,
587+ null ,
588+ null ,
589+ null ,
590+ 'inst-456' ,
591+ '(__topic__:"FCLogs:test-function" or __topic__:"FCInstanceEvents:/test-function")' ,
592+ ) ;
593+
594+ expect ( result ) . toBe (
595+ '(__topic__:"FCLogs:test-function" or __topic__:"FCInstanceEvents:/test-function") and instanceID: "inst-456"' ,
596+ ) ;
597+ } ) ;
598+
599+ it ( 'should generate query with topicFilter only' , ( ) => {
600+ const result = ( logs as any ) . getSlsQuery (
601+ null ,
602+ null ,
603+ null ,
604+ null ,
605+ null ,
606+ '__topic__:"FCLogs:test-function"' ,
607+ ) ;
608+
609+ expect ( result ) . toBe ( '__topic__:"FCLogs:test-function"' ) ;
610+ } ) ;
611+
612+ it ( 'should use field-specific syntax for qualifier' , ( ) => {
613+ const result = ( logs as any ) . getSlsQuery (
614+ null ,
615+ null ,
616+ 'LATEST' ,
617+ null ,
618+ null ,
619+ '__topic__:"FCLogs:test-function"' ,
620+ ) ;
621+
622+ expect ( result ) . toBe ( '__topic__:"FCLogs:test-function" and qualifier: "LATEST"' ) ;
623+ } ) ;
545624 } ) ;
546625
547626 describe ( 'compareLogConfig' , ( ) => {
0 commit comments