From 926f550177585d5c1c2bb944d2b48d782a32458e Mon Sep 17 00:00:00 2001 From: Asaf Korem Date: Sun, 19 Jan 2025 23:25:21 +0200 Subject: [PATCH] feat(driver): add framework info fields in TestingFrameworkAPICatalog --- src/test-utils/APICatalogTestUtils.ts | 2 ++ src/types.ts | 4 ++++ src/utils/PromptCreator.ts | 19 ++++++++++++++++++- .../__snapshots__/PromptCreator.test.ts.snap | 6 ++++++ website/docs/API/framework-driver.md | 12 ++++++++---- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/test-utils/APICatalogTestUtils.ts b/src/test-utils/APICatalogTestUtils.ts index dd8a73d..9babb9f 100644 --- a/src/test-utils/APICatalogTestUtils.ts +++ b/src/test-utils/APICatalogTestUtils.ts @@ -42,6 +42,8 @@ export const dummyBarContext2 = {bar: jest.fn()}; export const promptCreatorConstructorMockAPI: TestingFrameworkAPICatalog = { context: {}, + name: 'Test Framework', + description: 'A testing framework for unit testing purposes', categories: [ { title: 'Actions', diff --git a/src/types.ts b/src/types.ts index 1747bf0..6ca6af0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -74,10 +74,14 @@ export interface TestingFrameworkDriver { /** * Represents the available API of the testing framework that can be used by Copilot. + * @property name Optional name of the testing framework (e.g. "Detox", "Jest", etc.). + * @property description Optional description of the testing framework's purpose and capabilities. * @property context The available variables of the testing framework (i.e. exposes the matching function, expect, etc.). * @property categories The available categories of the testing framework API. */ export type TestingFrameworkAPICatalog = { + name?: string; + description?: string; context: any; categories: TestingFrameworkAPICatalogCategory[]; } diff --git a/src/utils/PromptCreator.ts b/src/utils/PromptCreator.ts index 2c75891..e24d461 100644 --- a/src/utils/PromptCreator.ts +++ b/src/utils/PromptCreator.ts @@ -50,13 +50,30 @@ export class PromptCreator { } private createBasePrompt(): string[] { - return [ + const basePrompt = [ "# Test Code Generation", "", "You are an AI assistant tasked with generating test code for an application using the provided UI testing framework API.", "Please generate the minimal executable code to perform the desired intent based on the given information and context.", "" ]; + + if (this.apiCatalog.name || this.apiCatalog.description) { + basePrompt.push("## Testing Framework"); + basePrompt.push(""); + + if (this.apiCatalog.name) { + basePrompt.push(`Framework: ${this.apiCatalog.name}`); + basePrompt.push(""); + } + + if (this.apiCatalog.description) { + basePrompt.push(`Description: ${this.apiCatalog.description}`); + basePrompt.push(""); + } + } + + return basePrompt; } private createContext( diff --git a/src/utils/__snapshots__/PromptCreator.test.ts.snap b/src/utils/__snapshots__/PromptCreator.test.ts.snap index b11a72e..3172f88 100644 --- a/src/utils/__snapshots__/PromptCreator.test.ts.snap +++ b/src/utils/__snapshots__/PromptCreator.test.ts.snap @@ -6,6 +6,12 @@ exports[`PromptCreator constructor should merge redundant categories 1`] = ` You are an AI assistant tasked with generating test code for an application using the provided UI testing framework API. Please generate the minimal executable code to perform the desired intent based on the given information and context. +## Testing Framework + +Framework: Test Framework + +Description: A testing framework for unit testing purposes + ## Context ### Intent to perform diff --git a/website/docs/API/framework-driver.md b/website/docs/API/framework-driver.md index 418a571..1f03a57 100644 --- a/website/docs/API/framework-driver.md +++ b/website/docs/API/framework-driver.md @@ -20,10 +20,12 @@ By implementing a custom driver, you enable **Copilot** to communicate with your The `TestingFrameworkDriver` interface defines the essential methods that a driver should implement: - **`captureSnapshotImage`**: Takes a snapshot of the current screen and returns the path to the saved image. If the driver does not support snapshot functionality, it should return `undefined`. -- **`captureViewHierarchyString`**: Returns the current view hierarchy in a string representation, which helps the AI understand the structure of the app’s UI. -- **`apiCatalog`**: Provides access to the available methods of the testing framework's API, such as matchers and actions. +- **`captureViewHierarchyString`**: Returns the current view hierarchy in a string representation, which helps the AI understand the structure of the app's UI. +- **`apiCatalog`**: Provides access to the available methods of the testing framework's API, such as matchers and actions. The catalog can also include optional framework information: + - `name`: The name of the testing framework (e.g., "Detox", "Jest") + - `description`: A description of the framework's purpose and capabilities -Here’s the interface definition for the driver: +Here's the interface definition for the driver: ```typescript /** @@ -42,7 +44,7 @@ export interface TestingFrameworkDriver { captureViewHierarchyString: () => Promise; /** - * The available guides methods of the testing framework. + * The available API methods of the testing framework. */ apiCatalog: TestingFrameworkAPICatalog; } @@ -58,6 +60,8 @@ const detox = require('../..'); const detoxCopilotFrameworkDriver = { apiCatalog: { context: { ...detox, jestExpect }, + name: 'Detox', + description: 'End-to-end testing and automation framework for mobile apps', categories: [ { title: 'Matchers',