tailtest_pick_template
Returns a testing template tailored to the source file's framework, including baseline scenarios and test file path patterns. Falls back to language baseline if framework is unrecognized.
Instructions
Return the full framework R2 template for a given source file: language baseline scenarios, framework baseline scenarios, framework-specific test pattern (e.g., NestJS Test.createTestingModule, Spring @WebMvcTest, Flask test_client), and test file path pattern. Returns just language baseline when no framework matches.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Relative or absolute path to the source file under test. | |
| project_root | No | Project root directory. Defaults to the current working directory. |
Implementation Reference
- The pick_template() function is the core handler that returns the full framework R2 template for a given source file. It detects language via filter.detect_language, detects framework via _detect_framework, then returns language baseline scenarios, framework template (if matched), test file path pattern, and prose instructions.
def pick_template(file_path: str, project_root: str | None = None) -> dict[str, Any]: """Return the full framework R2 template for the given source file. Args: file_path: relative or absolute path to the source file. project_root: project root for framework detection. Defaults to cwd. Returns: Dict with: language, framework (or None), language_baseline, framework_template (or None), test_file_path_pattern, instructions. If no framework matches, returns just the language baseline. """ project_root = project_root or os.getcwd() language = detect_language(file_path) or "unknown" framework = _detect_framework(language, project_root) language_baseline = LANGUAGE_BASELINES.get(language, []) framework_template = FRAMEWORK_TEMPLATES.get(framework) if framework else None instructions = ( f"Use the language baseline scenarios for {language}: " f"{', '.join(language_baseline) or 'none specified'}. " ) if framework_template: instructions += ( f"Add framework-specific scenarios for {framework} on top: " f"{'; '.join(framework_template['baseline_scenarios'])}. " f"Follow the test pattern: {framework_template['test_pattern']} " ) else: instructions += "No framework template matched; use language baseline only. " return { "file_path": file_path, "language": language, "framework": framework, "language_baseline": language_baseline, "framework_template": framework_template, "test_file_path_pattern": ( framework_template["test_file_path"] if framework_template else None ), "instructions": instructions, } - Input schema registration for tailtest_pick_template. Defines the tool's MCP input schema with required 'file_path' (string) and optional 'project_root' (string) properties.
Tool( name="tailtest_pick_template", description=( "Return the full framework R2 template for a given source file: language " "baseline scenarios, framework baseline scenarios, framework-specific test " "pattern (e.g., NestJS Test.createTestingModule, Spring @WebMvcTest, Flask " "test_client), and test file path pattern. Returns just language baseline " "when no framework matches." ), inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Relative or absolute path to the source file under test.", }, "project_root": { "type": "string", "description": "Project root directory. Defaults to the current working directory.", }, }, "required": ["file_path"], "additionalProperties": False, }, ), - mcp_server/src/tailtest_mcp/server.py:87-111 (registration)Tool registration entry in the list_tools() function. Registers 'tailtest_pick_template' as an MCP Tool with description and inputSchema.
Tool( name="tailtest_pick_template", description=( "Return the full framework R2 template for a given source file: language " "baseline scenarios, framework baseline scenarios, framework-specific test " "pattern (e.g., NestJS Test.createTestingModule, Spring @WebMvcTest, Flask " "test_client), and test file path pattern. Returns just language baseline " "when no framework matches." ), inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Relative or absolute path to the source file under test.", }, "project_root": { "type": "string", "description": "Project root directory. Defaults to the current working directory.", }, }, "required": ["file_path"], "additionalProperties": False, }, ), - Helper _detect_framework() function that examines project files (requirements.txt, pyproject.toml, setup.py, package.json, pom.xml, build.gradle, .csproj) to detect which framework (flask, fastapi, django, nestjs, spring, kotlin, csharp) is used by a given project.
def _detect_framework(language: str, project_root: str) -> str | None: """Detect framework from project files. V14.2 lightweight version.""" if language == "python": for f in ("requirements.txt", "pyproject.toml", "setup.py"): path = os.path.join(project_root, f) if os.path.exists(path): try: with open(path) as fh: text = fh.read().lower() if "fastapi" in text: return "fastapi" if "flask" in text: return "flask" if "django" in text: return "django" except OSError: pass elif language == "typescript": pkg = os.path.join(project_root, "package.json") if os.path.exists(pkg): try: with open(pkg) as fh: text = fh.read().lower() if "@nestjs/" in text: return "nestjs" except OSError: pass elif language == "java": pom = os.path.join(project_root, "pom.xml") gradle = os.path.join(project_root, "build.gradle") for path in (pom, gradle): if os.path.exists(path): try: with open(path) as fh: text = fh.read().lower() if "spring-boot" in text or "springframework" in text: return "spring" except OSError: pass elif language == "kotlin": gradle = os.path.join(project_root, "build.gradle.kts") if os.path.exists(gradle): return "kotlin" elif language == "csharp": # Any .csproj triggers the C# template for f in os.listdir(project_root) if os.path.isdir(project_root) else []: if f.endswith(".csproj"): return "csharp" return None - Dispatch handler in call_tool() that imports pick_template from .tools.pick_template and invokes it with the arguments, returning JSON-serialized result.
if name == "tailtest_pick_template": from .tools.pick_template import pick_template import json as _json result = pick_template( file_path=arguments["file_path"], project_root=arguments.get("project_root"), ) return [TextContent(type="text", text=_json.dumps(result, indent=2))]