11import test from 'node:test' ;
22import assert from 'node:assert/strict' ;
3- import { formatDeploymentsTable , parseDeploymentListArgs } from './list-command.js' ;
3+ import {
4+ formatDeploymentLogEntries ,
5+ formatDeploymentsTable ,
6+ parseDeploymentListArgs ,
7+ parseDeploymentLogsArgs ,
8+ tailLogEntriesFromNewestFiles
9+ } from './list-command.js' ;
410
511test ( 'parseDeploymentListArgs accepts deployment list filters' , ( ) => {
612 assert . deepEqual (
@@ -30,7 +36,8 @@ test('formatDeploymentsTable renders agent rows', () => {
3036 const out = formatDeploymentsTable ( [
3137 {
3238 agentId : 'b2f111111111111111111111e8c2' ,
33- personaId : 'weekly-digest' ,
39+ personaId : '7133e815-8c84-5d05-a08b-e434006b11ac' ,
40+ personaSlug : 'weekly-digest' ,
3441 deployedName : 'Weekly Digest' ,
3542 status : 'active' ,
3643 createdAt : '2026-05-13T09:11:00.000Z' ,
@@ -39,8 +46,66 @@ test('formatDeploymentsTable renders agent rows', () => {
3946 deployedByUserId : 'user-1'
4047 }
4148 ] ) ;
42- assert . match ( out , / a g e n t I d \s + p e r s o n a \s + s t a t u s \s + d e p l o y e d \s + l a s t U s e d / ) ;
49+ assert . match ( out , / n a m e \s + s t a t u s \s + d e p l o y e d \s + l a s t U s e d \s + a g e n t I d / ) ;
4350 assert . match ( out , / b 2 f 1 \. \. \. e 8 c 2 / ) ;
44- assert . match ( out , / w e e k l y - d i g e s t / ) ;
51+ assert . match ( out , / W e e k l y D i g e s t / ) ;
52+ assert . doesNotMatch ( out , / 7 1 3 3 e 8 1 5 / ) ;
4553 assert . match ( out , / 2 0 2 6 - 0 5 - 1 3 0 9 : 1 1 U T C / ) ;
4654} ) ;
55+
56+ test ( 'parseDeploymentLogsArgs accepts selector and log flags' , ( ) => {
57+ assert . deepEqual (
58+ parseDeploymentLogsArgs ( [
59+ 'Weekly Digest' ,
60+ '--workspace=ws-1' ,
61+ '--path' ,
62+ '/_logs/ws-1/2026-05-19.jsonl' ,
63+ '--tail' ,
64+ '25' ,
65+ '--cloud-url' ,
66+ 'https://cloud.example.test' ,
67+ '--json' ,
68+ '--no-prompt'
69+ ] ) ,
70+ {
71+ selector : 'Weekly Digest' ,
72+ workspace : 'ws-1' ,
73+ path : '/_logs/ws-1/2026-05-19.jsonl' ,
74+ tail : 25 ,
75+ cloudUrl : 'https://cloud.example.test' ,
76+ json : true ,
77+ noPrompt : true
78+ }
79+ ) ;
80+ } ) ;
81+
82+ test ( 'formatDeploymentLogEntries renders structured log rows' , ( ) => {
83+ const out = formatDeploymentLogEntries ( [
84+ {
85+ ts : '2026-05-19T13:00:00.000Z' ,
86+ level : 'info' ,
87+ agentId : 'agent-1' ,
88+ msg : 'handled event'
89+ }
90+ ] ) ;
91+ assert . match ( out , / 2 0 2 6 - 0 5 - 1 9 T 1 3 : 0 0 : 0 0 .0 0 0 Z \s + I N F O \s + a g e n t - 1 \s + h a n d l e d e v e n t / ) ;
92+ } ) ;
93+
94+ test ( 'tailLogEntriesFromNewestFiles keeps the newest entries across files' , ( ) => {
95+ const entries = tailLogEntriesFromNewestFiles (
96+ [
97+ [
98+ { ts : '2026-05-19T13:00:00.000Z' , msg : 'newer-a' } ,
99+ { ts : '2026-05-19T14:00:00.000Z' , msg : 'newer-b' } ,
100+ { ts : '2026-05-19T15:00:00.000Z' , msg : 'newer-c' }
101+ ] ,
102+ [
103+ { ts : '2026-05-18T10:00:00.000Z' , msg : 'older-a' } ,
104+ { ts : '2026-05-18T11:00:00.000Z' , msg : 'older-b' }
105+ ]
106+ ] ,
107+ 3
108+ ) ;
109+
110+ assert . deepEqual ( entries . map ( ( entry ) => entry . msg ) , [ 'newer-a' , 'newer-b' , 'newer-c' ] ) ;
111+ } ) ;
0 commit comments