Copilot commented on code in PR #7190: URL: https://github.com/apache/texera/pull/7190#discussion_r3694088994
########## agent-service/src/agent/prompts.spec.ts: ########## @@ -0,0 +1,99 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { describe, expect, test } from "bun:test"; +import type { OperatorSchema } from "../api/backend-api"; +import { buildSystemPrompt } from "./prompts"; +import { WorkflowSystemMetadata } from "./util/workflow-system-metadata"; + +function makeOperatorSchema(operatorType: string, description: string): OperatorSchema { + return { + operatorType, + operatorVersion: "1.0", + jsonSchema: { + properties: { + condition: { type: "string" }, + }, + required: ["condition"], + }, + additionalMetadata: { + userFriendlyName: operatorType, + operatorGroupName: "Test", + operatorDescription: description, + inputPorts: [], + outputPorts: [], + }, + }; +} + +function makeMetadataStore(): WorkflowSystemMetadata { + const metadataStore = new WorkflowSystemMetadata(); + metadataStore.loadFromMetadata({ + operators: [ + makeOperatorSchema("Filter", "Keeps rows that match a condition."), + makeOperatorSchema("PythonUDFV2", "Runs user-defined Python code."), + makeOperatorSchema("RUDF", "Runs user-defined R code."), + ], + groups: [], + }); + return metadataStore; +} + +describe("buildSystemPrompt", () => { + test("renders only explicitly allowed operators with their descriptions and compact schemas", () => { + const prompt = buildSystemPrompt(makeMetadataStore(), ["Filter"]); + + expect(prompt).toContain("## Filter"); + expect(prompt).toContain("Description: Keeps rows that match a condition."); + expect(prompt).toContain('"condition": {\n "type": "string"'); Review Comment: This assertion is overly sensitive to JSON indentation/newline formatting produced by `JSON.stringify` (and could fail on harmless formatting changes while still covering the same behavior). Prefer a regex match so the test validates that the `condition` property includes a `type: "string"` regardless of whitespace. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
