tpmjs/packages/tools/official/test-case-generate/README.md
Ajax Davis 5d2096fb5d feat: add 100+ official TPMJS tools
Implements a comprehensive suite of AI SDK v6 tools across multiple categories:

- Research (5): page-brief, compare-pages, source-credibility, claim-checklist, timeline-from-text
- Web (10): fetch-text, links-catalog, extract-meta, extract-json-ld, redirect-trace, sitemap-read, rss-read, table-extract, robots-policy, url-normalize
- Data (15): csv-parse, csv-stringify, json-repair, json-schema-validate, yaml-parse, yaml-stringify, text-chunk, normalize-whitespace, dedupe-by-key, pivot, rows-filter, rows-sort, rows-group-aggregate, rows-join, schema-infer
- Doc (12): toc-generate, glossary-build, faq-from-text, executive-brief, decision-record-adr, prd-outline, acceptance-criteria, style-rewrite
- Eng (12): diff-text-unified, env-var-docs-generate, dependency-audit-lite, conventional-commit-suggest, markdown-lint-basic, test-case-generate, stacktrace-parse, release-notes, changelog-entry, release-checklist
- Security (7): redact-secrets, secret-scan-text, url-risk-heuristic, csp-compose, hardening-checklist-web, access-control-matrix, data-classification-heuristic
- Stats (9): effect-size-suite, bootstrap-ci, permutation-test, multiple-testing-adjust, linear-regression-ols, logistic-regression, time-series-decompose-lite, anomaly-detect-mad
- Ops (7): slo-draft, runbook-draft, postmortem-draft, postmortem-action-extractor, error-log-triage, coverage-tracker, monitoring-gap-analysis
- Agent (15): prompt-to-workflow-skeleton, workflow-validate-io, workflow-explain, workflow-cost-estimate, tool-call-accuracy-score, eval-fixture-build, guardrail-policy-draft, workflow-auto-repair, tool-selection-plan, novelty-score-workflow, workflow-variant-generate, config-normalize, recipe-*
- Utility (8): base64-encode, base64-decode, hash-text, regex-extract, template-render, date-parse, json-path-query, url-parse
- HTML (3): html-sanitize, html-to-markdown, markdown-to-html

All tools follow AI SDK v6 pattern with tool() and jsonSchema<T>().

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-31 22:55:56 +10:00

5 KiB

Test Case Generate Tool

Generates comprehensive test case outlines from function signatures, including normal cases, edge cases, and error cases.

Installation

npm install @tpmjs/tools-test-case-generate

Usage

import { testCaseGenerateTool } from '@tpmjs/tools-test-case-generate';

const result = await testCaseGenerateTool.execute({
  functionName: 'calculateTotal',
  params: [
    { name: 'items', type: 'Array<number>' },
    { name: 'discount', type: 'number' },
    { name: 'taxRate', type: 'optional number' }
  ],
  returnType: 'number'
});

console.log(result);
// {
//   testCases: [
//     {
//       name: 'should handle valid inputs',
//       description: 'Test calculateTotal with standard valid inputs',
//       input: { items: [1, 2, 3], discount: 42, taxRate: 42 },
//       expectedBehavior: 'Should return number successfully',
//       category: 'normal'
//     },
//     // ... more test cases
//   ],
//   edgeCases: [
//     {
//       name: 'should handle items as empty array',
//       description: 'Test calculateTotal when items is empty array',
//       input: { items: [], discount: 42, taxRate: 42 },
//       expectedBehavior: 'Should handle gracefully and return number',
//       category: 'edge'
//     },
//     // ... more edge cases
//   ],
//   summary: {
//     totalCases: 25,
//     normalCases: 1,
//     edgeCases: 18,
//     errorCases: 6,
//     coverageAreas: [
//       'Happy path with valid inputs',
//       'Boundary values (min/max)',
//       'Array edge cases (empty, single element, large size)',
//       'Type validation and error handling'
//     ]
//   },
//   recommendations: [
//     'Verify immutability - ensure function does not mutate input arrays',
//     'Test floating-point precision edge cases (e.g., 0.1 + 0.2)',
//     'Use property-based testing for comprehensive coverage',
//     // ... more recommendations
//   ]
// }

Features

  • Type-Aware Generation: Automatically generates relevant test cases based on parameter types
  • Edge Case Detection: Identifies boundary conditions, empty values, and special cases
  • Error Case Coverage: Generates tests for invalid inputs and error conditions
  • Smart Recommendations: Provides testing best practices based on function signature
  • Coverage Analysis: Identifies areas of test coverage needed

Supported Types

The tool intelligently generates test cases for:

  • Primitives: string, number, boolean
  • Arrays: Array<T>, T[]
  • Objects: object, Record<K,V>, custom types
  • Dates: Date, date strings
  • Async: Promise<T>, async functions
  • Optional: optional T, T?, T | null | undefined

Input

{
  functionName: string;          // Name of the function
  params: Array<{
    name: string;                // Parameter name
    type: string;                // Parameter type (TypeScript syntax)
  }>;
  returnType: string;            // Return type
}

Output

{
  testCases: Array<{
    name: string;                // Test case name
    description: string;         // Detailed description
    input: Record<string, any>;  // Test input values
    expectedBehavior: string;    // Expected outcome
    category: 'normal' | 'edge' | 'error';
  }>;
  edgeCases: TestCase[];         // Additional edge cases
  summary: {
    totalCases: number;
    normalCases: number;
    edgeCases: number;
    errorCases: number;
    coverageAreas: string[];     // Areas of coverage
  };
  recommendations: string[];     // Testing best practices
}

Examples

Simple Function

const result = await testCaseGenerateTool.execute({
  functionName: 'isValidEmail',
  params: [
    { name: 'email', type: 'string' }
  ],
  returnType: 'boolean'
});
// Generates tests for:
// - Valid email
// - Empty string
// - Whitespace
// - Very long email
// - Unicode characters

Async Function

const result = await testCaseGenerateTool.execute({
  functionName: 'fetchUser',
  params: [
    { name: 'userId', type: 'string' }
  ],
  returnType: 'Promise<User>'
});
// Generates additional async tests:
// - Concurrent calls
// - Timeout scenarios
// - Promise rejection

Complex Function

const result = await testCaseGenerateTool.execute({
  functionName: 'processData',
  params: [
    { name: 'data', type: 'Array<Record<string, any>>' },
    { name: 'options', type: 'optional object' }
  ],
  returnType: 'object'
});
// Generates comprehensive coverage including:
// - Empty arrays
// - Large datasets
// - Nested objects
// - Missing optional params
// - Immutability tests

Best Practices

  1. Use Generated Cases as Templates: The tool provides outlines - add specific assertions and mocks
  2. Combine with Property-Based Testing: Use tools like fast-check for exhaustive testing
  3. Review Edge Cases: Some edge cases may not apply to your function's domain logic
  4. Add Integration Tests: Generated tests focus on unit testing - add integration tests separately

License

MIT