22/**
33 * Tests for `get agent` command handler in commands/get.ts.
44 *
5- * Covers the leader-filtering added to list mode and agent lookup:
6- * - `ak get agent` (no id) → calls listAgents, filters out kind === "leader"
5+ * Covers list mode and agent lookup:
6+ * - `ak get agent` (no id) → calls listAgents with worker filter
77 * - `ak get agent <id>` → calls getAgent directly, no filtering
88 * - `ak get agent <username>` → lists versions for that username when no id exists
99 */
@@ -68,29 +68,16 @@ afterEach(() => {
6868
6969// ── Tests: list mode ──────────────────────────────────────────────────────────
7070
71- describe ( "get agent — list mode leader filtering" , ( ) => {
72- it ( "calls listAgents once" , async ( ) => {
71+ describe ( "get agent — list mode filtering" , ( ) => {
72+ it ( "calls listAgents once with worker kind filter " , async ( ) => {
7373 mockListAgents . mockResolvedValue ( [ ] ) ;
7474 await makeProgram ( ) . parseAsync ( [ "get" , "agent" ] , { from : "user" } ) ;
75- expect ( mockListAgents ) . toHaveBeenCalledOnce ( ) ;
76- } ) ;
77-
78- it ( "filters out the agent where kind === 'leader'" , async ( ) => {
79- mockListAgents . mockResolvedValue ( [
80- { id : "a1" , kind : "worker" , name : "Alice" } ,
81- { id : "a2" , kind : "leader" , name : "LeaderBot" } ,
82- { id : "a3" , kind : "worker" , name : "Bob" } ,
83- ] ) ;
84- await makeProgram ( ) . parseAsync ( [ "get" , "agent" ] , { from : "user" } ) ;
85- // output(agents, fmt, formatAgentList, ...) — first arg is the agents array
86- const passed = vi . mocked ( outputModule . output ) . mock . calls [ 0 ] [ 0 ] as any [ ] ;
87- expect ( passed . find ( ( a : any ) => a . kind === "leader" ) ) . toBeUndefined ( ) ;
75+ expect ( mockListAgents ) . toHaveBeenCalledWith ( { kind : "worker" } ) ;
8876 } ) ;
8977
90- it ( "keeps all non-leader agents and preserves their order " , async ( ) => {
78+ it ( "passes through agents returned by the API " , async ( ) => {
9179 mockListAgents . mockResolvedValue ( [
9280 { id : "a1" , kind : "worker" , name : "Alice" } ,
93- { id : "a2" , kind : "leader" , name : "LeaderBot" } ,
9481 { id : "a3" , kind : "worker" , name : "Bob" } ,
9582 ] ) ;
9683 await makeProgram ( ) . parseAsync ( [ "get" , "agent" ] , { from : "user" } ) ;
@@ -99,26 +86,13 @@ describe("get agent — list mode leader filtering", () => {
9986 expect ( passed . map ( ( a : any ) => a . id ) ) . toEqual ( [ "a1" , "a3" ] ) ;
10087 } ) ;
10188
102- it ( "passes an empty array when all agents are leaders" , async ( ) => {
103- mockListAgents . mockResolvedValue ( [
104- { id : "l1" , kind : "leader" , name : "Alpha" } ,
105- { id : "l2" , kind : "leader" , name : "Beta" } ,
106- ] ) ;
89+ it ( "passes an empty array when the API returns no workers" , async ( ) => {
90+ mockListAgents . mockResolvedValue ( [ ] ) ;
10791 await makeProgram ( ) . parseAsync ( [ "get" , "agent" ] , { from : "user" } ) ;
10892 const passed = vi . mocked ( outputModule . output ) . mock . calls [ 0 ] [ 0 ] as any [ ] ;
10993 expect ( passed ) . toHaveLength ( 0 ) ;
11094 } ) ;
11195
112- it ( "passes all agents when none are leaders" , async ( ) => {
113- mockListAgents . mockResolvedValue ( [
114- { id : "w1" , kind : "worker" , name : "Worker1" } ,
115- { id : "w2" , kind : "worker" , name : "Worker2" } ,
116- ] ) ;
117- await makeProgram ( ) . parseAsync ( [ "get" , "agent" ] , { from : "user" } ) ;
118- const passed = vi . mocked ( outputModule . output ) . mock . calls [ 0 ] [ 0 ] as any [ ] ;
119- expect ( passed ) . toHaveLength ( 2 ) ;
120- } ) ;
121-
12296 it ( "does not call getAgent in list mode" , async ( ) => {
12397 mockListAgents . mockResolvedValue ( [ ] ) ;
12498 await makeProgram ( ) . parseAsync ( [ "get" , "agent" ] , { from : "user" } ) ;
@@ -130,6 +104,38 @@ describe("get agent — list mode leader filtering", () => {
130104 await makeProgram ( ) . parseAsync ( [ "get" , "agent" ] , { from : "user" } ) ;
131105 expect ( exitSpy ) . not . toHaveBeenCalled ( ) ;
132106 } ) ;
107+
108+ it ( "filters workers by role" , async ( ) => {
109+ mockListAgents . mockResolvedValue ( [ { id : "a1" , kind : "worker" , name : "Alice" , role : "qa" } ] ) ;
110+ await makeProgram ( ) . parseAsync ( [ "get" , "agent" , "--role" , "qa" ] , { from : "user" } ) ;
111+ expect ( mockListAgents ) . toHaveBeenCalledWith ( { kind : "worker" , role : "qa" } ) ;
112+ const passed = vi . mocked ( outputModule . output ) . mock . calls [ 0 ] [ 0 ] as any [ ] ;
113+ expect ( passed . map ( ( a : any ) => a . id ) ) . toEqual ( [ "a1" ] ) ;
114+ } ) ;
115+
116+ it ( "filters workers by runtime" , async ( ) => {
117+ mockListAgents . mockResolvedValue ( [ { id : "a1" , kind : "worker" , name : "Alice" , runtime : "codex" } ] ) ;
118+ await makeProgram ( ) . parseAsync ( [ "get" , "agent" , "--runtime" , "copilot" ] , { from : "user" } ) ;
119+ expect ( mockListAgents ) . toHaveBeenCalledWith ( { kind : "worker" , runtime : "copilot" } ) ;
120+ const passed = vi . mocked ( outputModule . output ) . mock . calls [ 0 ] [ 0 ] as any [ ] ;
121+ expect ( passed . map ( ( a : any ) => a . id ) ) . toEqual ( [ "a1" ] ) ;
122+ } ) ;
123+
124+ it ( "filters workers by runtime availability" , async ( ) => {
125+ mockListAgents . mockResolvedValue ( [ { id : "a1" , kind : "worker" , name : "Alice" , runtime_available : true } ] ) ;
126+ await makeProgram ( ) . parseAsync ( [ "get" , "agent" , "--available" ] , { from : "user" } ) ;
127+ expect ( mockListAgents ) . toHaveBeenCalledWith ( { kind : "worker" , available : "true" } ) ;
128+ const passed = vi . mocked ( outputModule . output ) . mock . calls [ 0 ] [ 0 ] as any [ ] ;
129+ expect ( passed . map ( ( a : any ) => a . id ) ) . toEqual ( [ "a1" ] ) ;
130+ } ) ;
131+
132+ it ( "combines role, runtime, and availability filters" , async ( ) => {
133+ mockListAgents . mockResolvedValue ( [ { id : "a1" , kind : "worker" , name : "Alice" , role : "qa" , runtime : "codex" , runtime_available : true } ] ) ;
134+ await makeProgram ( ) . parseAsync ( [ "get" , "agent" , "--role" , "qa" , "--runtime" , "codex" , "--available" ] , { from : "user" } ) ;
135+ expect ( mockListAgents ) . toHaveBeenCalledWith ( { kind : "worker" , role : "qa" , runtime : "codex" , available : "true" } ) ;
136+ const passed = vi . mocked ( outputModule . output ) . mock . calls [ 0 ] [ 0 ] as any [ ] ;
137+ expect ( passed . map ( ( a : any ) => a . id ) ) . toEqual ( [ "a1" ] ) ;
138+ } ) ;
133139} ) ;
134140
135141// ── Tests: single-agent fetch ─────────────────────────────────────────────────
0 commit comments