diff --git a/src/appdistribution/yaml_helper.ts b/src/appdistribution/yaml_helper.ts index 466467dafdc..eebaf432d91 100644 --- a/src/appdistribution/yaml_helper.ts +++ b/src/appdistribution/yaml_helper.ts @@ -31,7 +31,9 @@ function extractIdFromResourceName(name: string): string { function toYamlTestCases(testCases: TestCase[]): YamlTestCase[] { return testCases.map((testCase) => ({ displayName: testCase.displayName, - id: extractIdFromResourceName(testCase.name!), // resource name is retured by server + ...(testCase.name && { + id: extractIdFromResourceName(testCase.name), + }), ...(testCase.prerequisiteTestCase && { prerequisiteTestCaseId: extractIdFromResourceName(testCase.prerequisiteTestCase), }), diff --git a/src/mcp/tools/apptesting/index.ts b/src/mcp/tools/apptesting/index.ts index e2fb94dc5b6..12d277bc987 100644 --- a/src/mcp/tools/apptesting/index.ts +++ b/src/mcp/tools/apptesting/index.ts @@ -1,9 +1,9 @@ import { isEnabled } from "../../../experiments"; import type { ServerTool } from "../../tool"; -import { check_status, run_tests } from "./tests"; +import { check_status, run_tests, testcase_export } from "./tests"; export const apptestingTools: ServerTool[] = []; if (isEnabled("mcpalpha")) { - apptestingTools.push(...[run_tests, check_status]); + apptestingTools.push(...[run_tests, check_status, testcase_export]); } diff --git a/src/mcp/tools/apptesting/tests.ts b/src/mcp/tools/apptesting/tests.ts index 57548b2a0e7..8ac20675c09 100644 --- a/src/mcp/tools/apptesting/tests.ts +++ b/src/mcp/tools/apptesting/tests.ts @@ -1,6 +1,8 @@ import { z } from "zod"; +import * as fs from "fs-extra"; import { ApplicationIdSchema } from "../../../crashlytics/filters"; import { upload, Distribution } from "../../../appdistribution/distribution"; +import { toYaml } from "../../../appdistribution/yaml_helper"; import { tool } from "../../tool"; import { toContent } from "../../util"; @@ -74,6 +76,32 @@ export const run_tests = tool( }, ); +export const testcase_export = tool( + "apptesting", + { + name: "testcase_export", + description: "Use this to export a testcase to a file.", + inputSchema: z.object({ + outputFile: z.string().describe("The path to the file."), + testCases: z.array( + z.object({ + displayName: z.string(), + aiInstructions: z.object({ + steps: z.array(AIStepSchema), + }), + }), + ), + }), + annotations: { + title: "Export testcases to a file.", + readOnlyHint: false, + }, + }, + async ({ outputFile, testCases }) => { + return toContent(fs.writeFileSync(outputFile, toYaml(testCases), "utf8")); + }, +); + export const check_status = tool( "apptesting", {