plannerTools.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __export = (target, all) => {
  9. for (var name in all)
  10. __defProp(target, name, { get: all[name], enumerable: true });
  11. };
  12. var __copyProps = (to, from, except, desc) => {
  13. if (from && typeof from === "object" || typeof from === "function") {
  14. for (let key of __getOwnPropNames(from))
  15. if (!__hasOwnProp.call(to, key) && key !== except)
  16. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17. }
  18. return to;
  19. };
  20. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  21. // If the importer is in node compatibility mode or this is not an ESM
  22. // file that has been converted to a CommonJS file using a Babel-
  23. // compatible transform (i.e. "__esModule" has not been set), then set
  24. // "default" to the CommonJS "module.exports" for node compatibility.
  25. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  26. mod
  27. ));
  28. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  29. var plannerTools_exports = {};
  30. __export(plannerTools_exports, {
  31. saveTestPlan: () => saveTestPlan,
  32. setupPage: () => setupPage,
  33. submitTestPlan: () => submitTestPlan
  34. });
  35. module.exports = __toCommonJS(plannerTools_exports);
  36. var import_fs = __toESM(require("fs"));
  37. var import_path = __toESM(require("path"));
  38. var import_bundle = require("../sdk/bundle");
  39. var import_testTool = require("./testTool");
  40. const setupPage = (0, import_testTool.defineTestTool)({
  41. schema: {
  42. name: "planner_setup_page",
  43. title: "Setup planner page",
  44. description: "Setup the page for test planning",
  45. inputSchema: import_bundle.z.object({
  46. project: import_bundle.z.string().optional().describe('Project to use for setup. For example: "chromium", if no project is provided uses the first project in the config.'),
  47. seedFile: import_bundle.z.string().optional().describe('A seed file contains a single test that is used to setup the page for testing, for example: "tests/seed.spec.ts". If no seed file is provided, a default seed file is created.')
  48. }),
  49. type: "readOnly"
  50. },
  51. handle: async (context, params) => {
  52. const seed = await context.getOrCreateSeedFile(params.seedFile, params.project);
  53. const { output, status } = await context.runSeedTest(seed.file, seed.projectName);
  54. return { content: [{ type: "text", text: output }], isError: status !== "paused" };
  55. }
  56. });
  57. const planSchema = import_bundle.z.object({
  58. overview: import_bundle.z.string().describe("A brief overview of the application to be tested"),
  59. suites: import_bundle.z.array(import_bundle.z.object({
  60. name: import_bundle.z.string().describe("The name of the suite"),
  61. seedFile: import_bundle.z.string().describe("A seed file that was used to setup the page for testing."),
  62. tests: import_bundle.z.array(import_bundle.z.object({
  63. name: import_bundle.z.string().describe("The name of the test"),
  64. file: import_bundle.z.string().describe('The file the test should be saved to, for example: "tests/<suite-name>/<test-name>.spec.ts".'),
  65. steps: import_bundle.z.array(import_bundle.z.string().describe(`The steps to be executed to perform the test. For example: 'Click on the "Submit" button'`)),
  66. expectedResults: import_bundle.z.array(import_bundle.z.string().describe("The expected results of the steps for test to verify."))
  67. }))
  68. }))
  69. });
  70. const submitTestPlan = (0, import_testTool.defineTestTool)({
  71. schema: {
  72. name: "planner_submit_plan",
  73. title: "Submit test plan",
  74. description: "Submit the test plan to the test planner",
  75. inputSchema: planSchema,
  76. type: "readOnly"
  77. },
  78. handle: async (context, params) => {
  79. return {
  80. content: [{
  81. type: "text",
  82. text: JSON.stringify(params, null, 2)
  83. }]
  84. };
  85. }
  86. });
  87. const saveTestPlan = (0, import_testTool.defineTestTool)({
  88. schema: {
  89. name: "planner_save_plan",
  90. title: "Save test plan as markdown file",
  91. description: "Save the test plan as a markdown file",
  92. inputSchema: planSchema.extend({
  93. name: import_bundle.z.string().describe('The name of the test plan, for example: "Test Plan".'),
  94. fileName: import_bundle.z.string().describe('The file to save the test plan to, for example: "spec/test.plan.md". Relative to the workspace root.')
  95. }),
  96. type: "readOnly"
  97. },
  98. handle: async (context, params) => {
  99. const lines = [];
  100. lines.push(`# ${params.name}`);
  101. lines.push(``);
  102. lines.push(`## Application Overview`);
  103. lines.push(``);
  104. lines.push(params.overview);
  105. lines.push(``);
  106. lines.push(`## Test Scenarios`);
  107. for (let i = 0; i < params.suites.length; i++) {
  108. lines.push(``);
  109. const suite = params.suites[i];
  110. lines.push(`### ${i + 1}. ${suite.name}`);
  111. lines.push(``);
  112. lines.push(`**Seed:** \`${suite.seedFile}\``);
  113. for (let j = 0; j < suite.tests.length; j++) {
  114. lines.push(``);
  115. const test = suite.tests[j];
  116. lines.push(`#### ${i + 1}.${j + 1}. ${test.name}`);
  117. lines.push(``);
  118. lines.push(`**File:** \`${test.file}\``);
  119. lines.push(``);
  120. lines.push(`**Steps:**`);
  121. for (let k = 0; k < test.steps.length; k++)
  122. lines.push(` ${k + 1}. ${test.steps[k]}`);
  123. lines.push(``);
  124. lines.push(`**Expected Results:**`);
  125. for (const result of test.expectedResults)
  126. lines.push(` - ${result}`);
  127. }
  128. }
  129. lines.push(``);
  130. await import_fs.default.promises.writeFile(import_path.default.resolve(context.rootPath, params.fileName), lines.join("\n"));
  131. return {
  132. content: [{
  133. type: "text",
  134. text: `Test plan saved to ${params.fileName}`
  135. }]
  136. };
  137. }
  138. });
  139. // Annotate the CommonJS export names for ESM import in node:
  140. 0 && (module.exports = {
  141. saveTestPlan,
  142. setupPage,
  143. submitTestPlan
  144. });