microsoft/TypeAgent
Publicmirrored from https://github.com/microsoft/TypeAgentAvailable
ts/packages/agentSdkWrapper/testCalendar.js
90lines · modecode
| 1 | #!/usr/bin/env node |
| 2 | // Copyright (c) Microsoft Corporation. |
| 3 | // Licensed under the MIT License. |
| 4 | |
| 5 | // Test script for calendar grammar generation |
| 6 | |
| 7 | import { ClaudeGrammarGenerator } from "./dist/grammarGenerator.js"; |
| 8 | import { loadTestCases, loadSchemasForTests } from "./dist/testRunner.js"; |
| 9 | |
| 10 | async function main() { |
| 11 | console.log("Loading calendar test cases..."); |
| 12 | const testCases = loadTestCases("./tests/calendarTests.jsonl"); |
| 13 | console.log(`Loaded ${testCases.length} test cases\n`); |
| 14 | |
| 15 | console.log("Loading schemas..."); |
| 16 | const schemas = loadSchemasForTests(testCases); |
| 17 | console.log(`Loaded ${schemas.size} schemas\n`); |
| 18 | |
| 19 | const generator = new ClaudeGrammarGenerator(); |
| 20 | |
| 21 | for (const [index, testCase] of testCases.entries()) { |
| 22 | console.log(`\n${"=".repeat(80)}`); |
| 23 | console.log( |
| 24 | `Test ${index + 1}/${testCases.length}: "${testCase.request}"`, |
| 25 | ); |
| 26 | console.log(`Action: ${testCase.action.actionName}`); |
| 27 | console.log( |
| 28 | `Parameters: ${JSON.stringify(testCase.action.parameters)}`, |
| 29 | ); |
| 30 | console.log(`Note: ${testCase.note || "N/A"}`); |
| 31 | console.log(`${"=".repeat(80)}`); |
| 32 | |
| 33 | try { |
| 34 | const schemaInfo = schemas.get(testCase.schemaName); |
| 35 | if (!schemaInfo) { |
| 36 | console.error(`❌ Schema not found: ${testCase.schemaName}`); |
| 37 | continue; |
| 38 | } |
| 39 | |
| 40 | const analysis = await generator.generateGrammar( |
| 41 | testCase, |
| 42 | schemaInfo, |
| 43 | ); |
| 44 | |
| 45 | if (analysis.shouldGenerateGrammar) { |
| 46 | console.log("\n✅ ACCEPTED - Grammar should be generated"); |
| 47 | console.log("\nGrammar Pattern:"); |
| 48 | console.log(` ${analysis.grammarPattern}`); |
| 49 | |
| 50 | console.log("\nParameter Mappings:"); |
| 51 | for (const mapping of analysis.parameterMappings) { |
| 52 | console.log(` ${mapping.parameterName}:`); |
| 53 | console.log(` Source: "${mapping.sourceText}"`); |
| 54 | console.log( |
| 55 | ` Value: ${JSON.stringify(mapping.targetValue)}`, |
| 56 | ); |
| 57 | console.log(` Wildcard: ${mapping.isWildcard}`); |
| 58 | if (mapping.conversion) { |
| 59 | console.log( |
| 60 | ` Conversion: ${mapping.conversion.type} - ${mapping.conversion.description}`, |
| 61 | ); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | console.log("\nFixed Phrases:"); |
| 66 | console.log(` ${analysis.fixedPhrases.join(", ")}`); |
| 67 | |
| 68 | const grammarRule = generator.formatAsGrammarRule( |
| 69 | testCase, |
| 70 | analysis, |
| 71 | ); |
| 72 | console.log("\nFull Grammar Rule:"); |
| 73 | console.log(grammarRule); |
| 74 | } else { |
| 75 | console.log("\n❌ REJECTED - Grammar should NOT be generated"); |
| 76 | console.log(`Reason: ${analysis.rejectionReason}`); |
| 77 | } |
| 78 | |
| 79 | console.log("\nReasoning:"); |
| 80 | console.log(` ${analysis.reasoning}`); |
| 81 | } catch (error) { |
| 82 | console.error(`\n❌ ERROR: ${error.message}`); |
| 83 | if (error.stack) { |
| 84 | console.error(error.stack); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | main().catch(console.error); |
| 91 | |