11import type { AgentDeviceClient , CommandRequestResult } from '../../client.ts' ;
2- import { announceReplayTestRun } from '../../cli-test.ts' ;
2+ import { announceReplayTestRun , renderReplayTestResponse } from '../../cli-test.ts' ;
33import {
44 runSemanticCliCommand ,
55 runSemanticCliCommandWithOutput ,
@@ -10,8 +10,9 @@ import {
1010 type SemanticCliCommand ,
1111} from '../../commands/semantic-command-surface.ts' ;
1212import type { SemanticCliOutput } from '../../commands/semantic-contract.ts' ;
13+ import type { ReplaySuiteResult } from '../../daemon/types.ts' ;
1314import type { CliFlags } from '../../utils/command-schema.ts' ;
14- import { writeCommandCliOutput } from './output .ts' ;
15+ import { readCommandMessage } from '../../utils/success-text .ts' ;
1516import { writeCommandOutput } from './shared.ts' ;
1617import type { PublicCommandName } from '../../command-catalog.ts' ;
1718import type { ClientCommandHandler } from './router-types.ts' ;
@@ -31,18 +32,6 @@ const formattedSemanticCommandHandlers = Object.fromEntries(
3132
3233export const dedicatedSemanticCommandHandlers = formattedSemanticCommandHandlers ;
3334
34- const clientMethodCommandNames = commandNameSet ( [
35- 'wait' ,
36- 'alert' ,
37- 'appstate' ,
38- 'back' ,
39- 'home' ,
40- 'rotate' ,
41- 'app-switcher' ,
42- 'keyboard' ,
43- 'clipboard' ,
44- ] as const satisfies readonly SemanticCliCommand [ ] ) ;
45-
4635const semanticGenericCommands = listSemanticCommandNames ( ) . filter ( isGenericSemanticCliCommand ) ;
4736
4837const genericClientCommandRunners = Object . fromEntries (
@@ -73,14 +62,33 @@ function createGenericClientCommandHandler(
7362) : ClientCommandHandler {
7463 return async ( { positionals, flags, client } ) => {
7564 const data = await run ( { client, positionals, flags } ) ;
76- const exitCode = writeCommandCliOutput ( command , positionals , flags , data ) ;
65+ const exitCode = writeGenericSemanticCliOutput ( command , flags , data ) ;
7766 if ( exitCode !== 0 ) {
7867 process . exit ( exitCode ) ;
7968 }
8069 return true ;
8170 } ;
8271}
8372
73+ function writeGenericSemanticCliOutput (
74+ command : PublicCommandName ,
75+ flags : CliFlags ,
76+ data : CommandRequestResult ,
77+ ) : number {
78+ if ( command === 'test' ) {
79+ return renderReplayTestResponse ( {
80+ suite : data as ReplaySuiteResult ,
81+ verbose : flags . verbose ,
82+ json : flags . json ,
83+ reportJunit : flags . reportJunit ,
84+ } ) ;
85+ }
86+ writeCommandOutput ( flags , data , ( ) =>
87+ readCommandMessage ( data as Record < string , unknown > | undefined ) ,
88+ ) ;
89+ return 0 ;
90+ }
91+
8492function createFormattedSemanticHandler ( command : SemanticCliCommand ) : ClientCommandHandler {
8593 return async ( { positionals, flags, client } ) => {
8694 const { cliOutput } = await runSemanticCliCommandWithOutput ( {
@@ -110,13 +118,6 @@ function writeSemanticCliOutput(flags: CliFlags, output: SemanticCliOutput): voi
110118
111119function isGenericSemanticCliCommand ( command : SemanticCliCommand ) : boolean {
112120 return (
113- ! ( command in formattedSemanticCommandHandlers ) &&
114- ! clientMethodCommandNames . has ( command ) &&
115- command !== 'screenshot' &&
116- command !== 'diff'
121+ ! ( command in formattedSemanticCommandHandlers ) && command !== 'screenshot' && command !== 'diff'
117122 ) ;
118123}
119-
120- function commandNameSet < const TName extends string > ( names : readonly TName [ ] ) : ReadonlySet < string > {
121- return new Set ( names ) ;
122- }
0 commit comments