11import { SpawnStatus , SudoRequestData , SudoRequestResponseData } from 'codify-schemas' ;
22
33import { Plan } from '../../../src/entities/plan.js' ;
4- import { ImportResult , RequiredParameters , UserSuppliedParameters } from '../../../src/orchestrators/import.js' ;
4+ import { ResourceConfig } from '../../../src/entities/resource-config.js' ;
5+ import { ResourceInfo } from '../../../src/entities/resource-info.js' ;
6+ import { ImportResult } from '../../../src/orchestrators/import.js' ;
57import { prettyFormatPlan } from '../../../src/ui/plan-pretty-printer.js' ;
6- import { Reporter } from '../../../src/ui/reporters/reporter.js' ;
8+ import { PromptType , Reporter } from '../../../src/ui/reporters/reporter.js' ;
9+ import { FileModificationResult } from '../../../src/utils/file-modification-calculator.js' ;
710
811export interface MockReporterConfig {
912 validatePlan ?: ( plan : Plan ) => Promise < void > | void ;
10- validateApplyComplete ?: ( message : string [ ] ) => Promise < void > | void ;
13+ validateMessage ?: ( message : string ) => Promise < void > | void ;
1114 validateImport ?: ( result : ImportResult ) => Promise < void > | void ;
1215 promptApplyConfirmation ?: ( ) => boolean ;
13- askRequiredParametersForImport ?: ( requiredParameters : RequiredParameters ) => Promise < UserSuppliedParameters > | UserSuppliedParameters ;
16+ promptOptions ?: ( message : string , options : string [ ] ) => string ;
17+ promptUserForValues ?: ( resourceInfo : ResourceInfo [ ] ) => Promise < ResourceConfig [ ] > | ResourceConfig [ ] ;
1418 displayImportResult ?: ( importResult : ImportResult ) => Promise < void > | void ;
19+ displayFileModifications ?: ( diff : { file : string ; modification : FileModificationResult ; } [ ] ) => void ,
1520}
1621
1722export class MockReporter implements Reporter {
@@ -21,9 +26,17 @@ export class MockReporter implements Reporter {
2126 this . config = config ?? null ;
2227 }
2328
24- async displayApplyComplete ( message : string [ ] ) : Promise < void > {
29+ async promptOptions ( message : string , options : string [ ] ) : Promise < string > {
30+ return this . config ?. promptOptions ?.( message , options ) ?? options [ 0 ] ;
31+ }
32+
33+ async displayFileModifications ( diff : { file : string ; modification : FileModificationResult ; } [ ] ) : Promise < void > {
34+ this . config ?. displayFileModifications ?.( diff ) ;
35+ }
36+
37+ async displayMessage ( message : string ) : Promise < void > {
2538 console . log ( JSON . stringify ( message , null , 2 ) ) ;
26- await this . config ?. validateApplyComplete ?.( message ) ;
39+ await this . config ?. validateMessage ?.( message ) ;
2740 }
2841
2942 async displayPlan ( plan : Plan ) : Promise < void > {
@@ -42,18 +55,12 @@ export class MockReporter implements Reporter {
4255 }
4356 }
4457
45- async promptUserForParameterValues ( requiredParameters : RequiredParameters ) : Promise < UserSuppliedParameters > {
46- if ( this . config ?. askRequiredParametersForImport ) {
47- return this . config . askRequiredParametersForImport ( requiredParameters ) ;
48- }
49-
50- const result = new Map < string , Record < string , string > > ( ) ;
51-
52- for ( const parameter of requiredParameters ) {
53- result . set ( parameter [ 0 ] , Object . fromEntries ( parameter [ 1 ] . map ( ( p ) => [ p , '' ] ) ) )
58+ async promptUserForValues ( resourceInfo : ResourceInfo [ ] , promptType : PromptType ) : Promise < ResourceConfig [ ] > {
59+ if ( this . config ?. promptUserForValues ) {
60+ return this . config . promptUserForValues ( resourceInfo ) ;
5461 }
5562
56- return result ;
63+ return resourceInfo . map ( ( i ) => new ResourceConfig ( { type : i . type } ) )
5764 }
5865
5966 displayImportResult ( importResult : ImportResult ) : void {
0 commit comments