1414 * limitations under the License.
1515 */
1616
17+ import fs from 'fs' ;
18+ import path from 'path' ;
19+
1720import { z } from '../sdk/bundle' ;
1821import { defineTestTool } from './testTool' ;
1922
@@ -35,3 +38,90 @@ export const setupPage = defineTestTool({
3538 return { content : [ ] } ;
3639 } ,
3740} ) ;
41+
42+ const planSchema = z . object ( {
43+ overview : z . string ( ) . describe ( 'A brief overview of the application to be tested' ) ,
44+ suites : z . array ( z . object ( {
45+ name : z . string ( ) . describe ( 'The name of the suite' ) ,
46+ seedFile : z . string ( ) . describe ( 'A seed file that was used to setup the page for testing.' ) ,
47+ tests : z . array ( z . object ( {
48+ name : z . string ( ) . describe ( 'The name of the test' ) ,
49+ file : z . string ( ) . describe ( 'The file the test should be saved to, for example: "tests/<suite-name>/<test-name>.spec.ts".' ) ,
50+ steps : z . array ( z . string ( ) . describe ( `The steps to be executed to perform the test. For example: 'Click on the "Submit" button'` ) ) ,
51+ expectedResults : z . array ( z . string ( ) . describe ( 'The expected results of the steps for test to verify.' ) ) ,
52+ } ) ) ,
53+ } ) ) ,
54+ } ) ;
55+
56+ export const submitTestPlan = defineTestTool ( {
57+ schema : {
58+ name : 'planner_submit_plan' ,
59+ title : 'Submit test plan' ,
60+ description : 'Submit the test plan to the test planner' ,
61+ inputSchema : planSchema ,
62+ type : 'readOnly' ,
63+ } ,
64+
65+ handle : async ( context , params ) => {
66+ return {
67+ content : [ {
68+ type : 'text' ,
69+ text : JSON . stringify ( params , null , 2 ) ,
70+ } ] ,
71+ } ;
72+ } ,
73+ } ) ;
74+
75+ export const saveTestPlan = defineTestTool ( {
76+ schema : {
77+ name : 'planner_save_plan' ,
78+ title : 'Save test plan as markdown file' ,
79+ description : 'Save the test plan as a markdown file' ,
80+ inputSchema : planSchema . extend ( {
81+ name : z . string ( ) . describe ( 'The name of the test plan, for example: "Test Plan".' ) ,
82+ fileName : z . string ( ) . describe ( 'The file to save the test plan to, for example: "spec/test.plan.md". Relative to the workspace root.' ) ,
83+ } ) ,
84+ type : 'readOnly' ,
85+ } ,
86+
87+ handle : async ( context , params ) => {
88+ const lines : string [ ] = [ ] ;
89+ lines . push ( `# ${ params . name } ` ) ;
90+ lines . push ( `` ) ;
91+ lines . push ( `## Application Overview` ) ;
92+ lines . push ( `` ) ;
93+ lines . push ( params . overview ) ;
94+ lines . push ( `` ) ;
95+ lines . push ( `## Test Scenarios` ) ;
96+ for ( let i = 0 ; i < params . suites . length ; i ++ ) {
97+ lines . push ( `` ) ;
98+ const suite = params . suites [ i ] ;
99+ lines . push ( `### ${ i + 1 } . ${ suite . name } ` ) ;
100+ lines . push ( `` ) ;
101+ lines . push ( `**Seed:** \`${ suite . seedFile } \`` ) ;
102+ for ( let j = 0 ; j < suite . tests . length ; j ++ ) {
103+ lines . push ( `` ) ;
104+ const test = suite . tests [ j ] ;
105+ lines . push ( `#### ${ i + 1 } .${ j + 1 } . ${ test . name } ` ) ;
106+ lines . push ( `` ) ;
107+ lines . push ( `**File:** \`${ test . file } \`` ) ;
108+ lines . push ( `` ) ;
109+ lines . push ( `**Steps:**` ) ;
110+ for ( let k = 0 ; k < test . steps . length ; k ++ )
111+ lines . push ( ` ${ k + 1 } . ${ test . steps [ k ] } ` ) ;
112+ lines . push ( `` ) ;
113+ lines . push ( `**Expected Results:**` ) ;
114+ for ( const result of test . expectedResults )
115+ lines . push ( ` - ${ result } ` ) ;
116+ }
117+ }
118+ lines . push ( `` ) ;
119+ await fs . promises . writeFile ( path . resolve ( context . rootPath , params . fileName ) , lines . join ( '\n' ) ) ;
120+ return {
121+ content : [ {
122+ type : 'text' ,
123+ text : `Test plan saved to ${ params . fileName } ` ,
124+ } ] ,
125+ } ;
126+ } ,
127+ } ) ;
0 commit comments