Comprehensive developer toolkit providing reusable skills for Java/Spring Boot, TypeScript/NestJS/React/Next.js, Python, PHP, AWS CloudFormation, AI/RAG, DevOps, and more.
90
90%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Risky
Do not use without reviewing
#!/usr/bin/env python3
"""Error handling and alternative flows for /specs:task-tdd (TASK-012).
Provides small, testable helpers that consolidate common error checks used by
other specs hooks (parser, generator, red-phase, updater). The module raises
SpecsTddError with structured codes for programmatic handling.
"""
from __future__ import annotations
import json
import os
import shutil
import subprocess
from dataclasses import dataclass
from pathlib import Path
from typing import Iterable, List
class SpecsTddError(ValueError):
"""Structured error used across specs/task-tdd hooks.
Attributes:
code: Short error code (E1-E5, A1-A4) per spec.
"""
def __init__(self, message: str, *, code: str) -> None:
super().__init__(message)
self.code = code
@dataclass
class ExistingFileChoices:
path: str
exists: bool
suggested_actions: List[str]
SUPPORTED_LANGUAGES = {
"java",
"spring",
"typescript",
"nestjs",
"react",
"python",
"php",
"general",
}
def ensure_task_file_exists(task_path: str) -> None:
path = Path(task_path)
if not path.exists():
raise SpecsTddError(
(
f"Task file not found: {task_path}. "
"Provide a valid task file path or run '/specs:spec-to-tasks' first."
),
code="E1",
)
if not os.access(str(path), os.R_OK):
raise SpecsTddError(f"Task file not readable: {task_path}. Check file permissions.", code="E4")
def ensure_project_root(project_root: str) -> None:
root = Path(project_root)
if not root.exists() or not root.is_dir():
raise SpecsTddError(f"Project root not found: {project_root}", code="E1")
def validate_language_supported(language: str) -> None:
if language not in SUPPORTED_LANGUAGES:
raise SpecsTddError(f"Language '{language}' is not supported for RED verification.", code="A2")
def ensure_test_framework(language: str, project_root: str) -> None:
"""Detect likely test framework presence for the given language.
Raises E2 when a likely test framework cannot be found.
"""
root = Path(project_root)
if language == "general":
raise SpecsTddError(
"General mode is non-executable: RED verification requires a concrete language.",
code="E2",
)
# Language-specific heuristic checks
if language in {"python"}:
# Check for pytest on PATH or pyproject/pytest.ini present
if shutil.which("pytest") or (root / "pyproject.toml").exists() or (root / "pytest.ini").exists():
return
raise SpecsTddError(
"Pytest not found in project or PATH. Install/configure pytest before RED verification.",
code="E2",
)
if language in {"typescript", "nestjs", "react"}:
# Check for package.json and node_modules or npm availability
if (root / "package.json").exists() or shutil.which("npm"):
return
raise SpecsTddError(
"Node/Jest not detected. Ensure package.json or npm is available for RED verification.",
code="E2",
)
if language in {"java", "spring"}:
# Check for maven/gradle wrapper or mvn/gradle in PATH
if (root / "mvnw").exists() or (root / "gradlew").exists() or shutil.which("mvn") or shutil.which("gradle"):
return
raise SpecsTddError(
"Maven/Gradle not detected. Install or add build wrapper (mvnw/gradlew) for RED verification.",
code="E2",
)
if language == "php":
if (root / "composer.json").exists() or shutil.which("phpunit"):
return
raise SpecsTddError(
"PHPUnit not detected. Install or configure PHPUnit before RED verification.",
code="E2",
)
# Fallback: unknown but treated as missing framework
raise SpecsTddError("Test framework not found for specified language.", code="E2")
def detect_existing_test_file(test_path: str) -> ExistingFileChoices:
path = Path(test_path)
if path.exists():
return ExistingFileChoices(
path=str(path), exists=True, suggested_actions=["overwrite", "skip", "cancel"]
)
return ExistingFileChoices(path=str(path), exists=False, suggested_actions=["create"])
def detect_missing_test_instructions(warnings: Iterable[object]) -> bool:
"""Return True when parser warnings indicate missing test instructions (A3)."""
for w in warnings:
# Accept both ParseWarning-like objects or simple dicts
code = getattr(w, "code", None) if not isinstance(w, dict) else w.get("code")
if code == "A3":
return True
return False
def analyze_unexpected_pass(red_result: object) -> str | None:
"""Given a RedPhaseResult-like object or dict, return an actionable warning when tests pass.
Returns a short message or None.
"""
status = getattr(red_result, "status", None) if not isinstance(red_result, dict) else red_result.get("status")
if status == "unexpected-pass":
return (
"Generated tests passed unexpectedly. Consider confirming if the implementation already exists, "
"reviewing assertions, or reverting test generation."
)
return None
def format_error_json(exc: SpecsTddError) -> str:
payload = {"error": {"code": exc.code, "message": str(exc)}}
return json.dumps(payload, indent=2)docs
plugins
developer-kit-ai
developer-kit-aws
agents
docs
skills
aws
aws-cli-beast
aws-cost-optimization
aws-drawio-architecture-diagrams
aws-sam-bootstrap
aws-cloudformation
aws-cloudformation-auto-scaling
aws-cloudformation-bedrock
aws-cloudformation-cloudfront
aws-cloudformation-cloudwatch
aws-cloudformation-dynamodb
aws-cloudformation-ec2
aws-cloudformation-ecs
aws-cloudformation-elasticache
references
aws-cloudformation-iam
references
aws-cloudformation-lambda
aws-cloudformation-rds
aws-cloudformation-s3
aws-cloudformation-security
aws-cloudformation-task-ecs-deploy-gh
aws-cloudformation-vpc
references
developer-kit-core
agents
commands
skills
developer-kit-devops
developer-kit-java
agents
commands
docs
skills
aws-lambda-java-integration
aws-rds-spring-boot-integration
aws-sdk-java-v2-bedrock
aws-sdk-java-v2-core
aws-sdk-java-v2-dynamodb
aws-sdk-java-v2-kms
aws-sdk-java-v2-lambda
aws-sdk-java-v2-messaging
aws-sdk-java-v2-rds
aws-sdk-java-v2-s3
aws-sdk-java-v2-secrets-manager
clean-architecture
graalvm-native-image
langchain4j-ai-services-patterns
references
langchain4j-mcp-server-patterns
references
langchain4j-rag-implementation-patterns
references
langchain4j-spring-boot-integration
langchain4j-testing-strategies
langchain4j-tool-function-calling-patterns
langchain4j-vector-stores-configuration
references
qdrant
references
spring-ai-mcp-server-patterns
spring-boot-actuator
spring-boot-cache
spring-boot-crud-patterns
spring-boot-dependency-injection
spring-boot-event-driven-patterns
spring-boot-openapi-documentation
spring-boot-project-creator
spring-boot-resilience4j
spring-boot-rest-api-standards
spring-boot-saga-pattern
spring-boot-security-jwt
assets
references
scripts
spring-boot-test-patterns
spring-data-jpa
references
spring-data-neo4j
references
unit-test-application-events
unit-test-bean-validation
unit-test-boundary-conditions
unit-test-caching
unit-test-config-properties
references
unit-test-controller-layer
unit-test-exception-handler
references
unit-test-json-serialization
unit-test-mapper-converter
references
unit-test-parameterized
unit-test-scheduled-async
references
unit-test-service-layer
references
unit-test-utility-methods
unit-test-wiremock-rest-api
references
developer-kit-php
developer-kit-project-management
developer-kit-python
developer-kit-specs
commands
docs
hooks
test-templates
tests
skills
developer-kit-tools
developer-kit-typescript
agents
docs
hooks
rules
skills
aws-cdk
aws-lambda-typescript-integration
better-auth
clean-architecture
drizzle-orm-patterns
dynamodb-toolbox-patterns
references
nestjs
nestjs-best-practices
nestjs-code-review
nestjs-drizzle-crud-generator
nextjs-app-router
nextjs-authentication
nextjs-code-review
nextjs-data-fetching
nextjs-deployment
nextjs-performance
nx-monorepo
react-code-review
react-patterns
shadcn-ui
tailwind-css-patterns
tailwind-design-system
references
turborepo-monorepo
typescript-docs
typescript-security-review
zod-validation-utilities
references
github-spec-kit