Skip to main content
Glama

improve_test_case

Analyze test cases to identify issues and apply improvements with detailed suggestions and optional automatic fixes for better quality assurance.

Instructions

🔧 Analyze and improve a test case with detailed suggestions and optional automatic fixes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectKeyYesProject key (e.g., 'android' or 'ANDROID')
caseKeyYesTest case key (e.g., 'ANDROID-29')
rulesFilePathNoPath to custom rules markdown file
checkpointsFilePathNoPath to custom checkpoints markdown file
formatNoOutput formatmarkdown
applyHighConfidenceChangesNoAutomatically apply high-confidence improvements
include_clickable_linksNoInclude clickable links to Zebrunner web UI

Implementation Reference

  • The primary MCP tool handler for the 'improve_test_case' tool. Fetches the test case by key, validates it using TestCaseValidator, applies improvements via TestCaseImprover, optionally applies high-confidence changes, and formats the detailed improvement report.
    async improveTestCase(input: z.infer<typeof ImproveTestCaseInputSchema>) {
      const { projectKey, caseKey, rulesFilePath, checkpointsFilePath, format, applyHighConfidenceChanges } = input;
      
      try {
        // Get the test case data first
        const testCase = await this.client.getTestCaseByKey(projectKey, caseKey);
        
        // Initialize validator with dynamic rules
        let validator: TestCaseValidator;
        if (rulesFilePath && checkpointsFilePath) {
          // Use custom rules from files - validate paths first
          try {
            const resolvedRulesPath = validateFilePath(rulesFilePath, process.cwd());
            const resolvedCheckpointsPath = validateFilePath(checkpointsFilePath, process.cwd());
            validator = await TestCaseValidator.fromMarkdownFiles(resolvedRulesPath, resolvedCheckpointsPath);
          } catch (error) {
            throw new Error(`Invalid file path provided: ${error instanceof Error ? error.message : error}`);
          }
        } else {
          // Use default rules, but try to load from standard files if they exist
          const defaultRulesPath = path.resolve(process.cwd(), 'test_case_review_rules.md');
          const defaultCheckpointsPath = path.resolve(process.cwd(), 'test_case_analysis_checkpoints.md');
          
          try {
            validator = await TestCaseValidator.fromMarkdownFiles(defaultRulesPath, defaultCheckpointsPath);
          } catch (error) {
            // Fall back to default rules if files don't exist
            validator = new TestCaseValidator();
          }
        }
        
        // Validate the test case first
        const validationResult = await validator.validateTestCase(testCase);
        
        // Attempt improvement
        const improver = new TestCaseImprover();
        const improvementResult = await improver.improveTestCase(testCase, validationResult);
        
        // Apply high-confidence changes if requested
        let finalTestCase = testCase;
        if (applyHighConfidenceChanges && improvementResult.improvedTestCase) {
          finalTestCase = improvementResult.improvedTestCase;
        }
        
        // Format the result
        let formattedResult: string;
        
        if (format === 'markdown') {
          formattedResult = this.formatImprovementResultAsMarkdown(
            validationResult, 
            improvementResult, 
            finalTestCase, 
            applyHighConfidenceChanges
          );
        } else if (format === 'string') {
          formattedResult = this.formatImprovementResultAsString(
            validationResult, 
            improvementResult, 
            finalTestCase, 
            applyHighConfidenceChanges
          );
        } else {
          formattedResult = JSON.stringify({
            validation: validationResult,
            improvement: improvementResult,
            finalTestCase,
            changesApplied: applyHighConfidenceChanges
          }, null, 2);
        }
        
        return {
          content: [
            {
              type: "text" as const,
              text: formattedResult
            }
          ]
        };
      } catch (error: any) {
        const errorMsg = sanitizeErrorMessage(error, 'Error improving test case', 'improveTestCase');
        return {
          content: [
            {
              type: "text" as const,
              text: errorMsg
            }
          ]
        };
      }
    }
  • Zod input schema defining parameters for the improve_test_case tool: projectKey, caseKey, optional rules/checkpoints files, output format, and whether to auto-apply high-confidence improvements.
    export const ImproveTestCaseInputSchema = z.object({
      projectKey: z.string().min(1),
      caseKey: z.string().min(1),
      rulesFilePath: z.string().optional(),
      checkpointsFilePath: z.string().optional(),
      format: z.enum(['dto', 'json', 'string', 'markdown']).default('markdown'),
      applyHighConfidenceChanges: z.boolean().default(true)
    });
  • Core helper function in TestCaseImprover class that analyzes validation issues and generates targeted improvements (title fixes, preconditions, expected results, language clarity, structure). Applies automatic changes and flags human-needed ones.
    async improveTestCase(
      originalTestCase: ZebrunnerTestCase, 
      validationResult: ValidationResult
    ): Promise<ImprovementResult> {
      const improvements: ImprovementSuggestion[] = [];
      const humanHelpReasons: string[] = [];
      let improvedTestCase = JSON.parse(JSON.stringify(originalTestCase)); // Deep clone
      let canImprove = false;
      let requiresHumanHelp = false;
    
      // Process each validation issue
      for (const issue of validationResult.issues) {
        const improvement = await this.processIssue(issue, originalTestCase, improvedTestCase);
        
        if (improvement) {
          improvements.push(improvement);
          canImprove = true;
          
          // Apply the improvement if it's automatic or high confidence
          if (improvement.type === 'automatic' || improvement.confidence === 'high') {
            this.applyImprovement(improvement, improvedTestCase);
          }
        } else {
          // Issue requires human help
          requiresHumanHelp = true;
          humanHelpReasons.push(`${issue.category}: ${issue.description}`);
        }
      }
    
      // Additional structural improvements
      const structuralImprovements = this.suggestStructuralImprovements(originalTestCase);
      improvements.push(...structuralImprovements);
      
      if (structuralImprovements.length > 0) {
        canImprove = true;
        // Apply high-confidence structural improvements
        structuralImprovements
          .filter(imp => imp.confidence === 'high')
          .forEach(imp => this.applyImprovement(imp, improvedTestCase));
      }
    
      // Determine overall confidence
      const overallConfidence = this.calculateOverallConfidence(improvements);
    
      return {
        canImprove,
        requiresHumanHelp,
        confidence: overallConfidence,
        improvements,
        improvedTestCase: canImprove ? improvedTestCase : undefined,
        humanHelpReasons
      };
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/maksimsarychau/mcp-zebrunner'

If you have feedback or need assistance with the MCP directory API, please join our Discord server