kramme-cc-workflow/skills/kramme:test:generate/SKILL.md
(experimental) Generate tests for existing code by analyzing project test patterns and conventions. Use when adding test coverage to untested files or generating test stubs.
npx skillsauth add abildtoft/kramme-cc-workflow kramme:test:generateInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Generate tests for existing code by analyzing the project's test framework, conventions, and patterns. Produces test files that match the existing style.
IMPORTANT: This skill creates new test files and runs them. It does NOT modify source code — if a generated test fails, the test is fixed, not the source.
When to use: Adding coverage to existing, untested code. For test-first new logic or bug reproduction, use kramme:test:tdd instead. Generate E2E specs only when explicitly asked — default to the project's unit test framework.
Parse $ARGUMENTS for --auto before Step 1.
AUTO_MODE=true and remove the flag from the remaining input.--auto means: infer the test framework, generate unit tests for the public API surface, and use happy path + error cases depth./kramme:test:generate src/utils/parser.ts [--auto]
|
v
[Step 1: Parse Arguments] -> File path, directory, or ask
|
v
[Step 2: Detect Test Framework] -> Jest/Vitest/Pytest/Go/Rust/Bats/etc.
|
v
[Step 3: Analyze Test Patterns] -> Read 3-5 existing tests, extract conventions
|
v
[Step 4: Analyze Target Code] -> Exports, functions, edge cases, dependencies
|
v
[Step 5: User Configuration] -> Test type, scope, edge case depth
|
v
[Step 6: Generate Tests] -> Write test files following detected conventions
|
v
[Step 7: Run and Verify] -> Execute, fix failures (max 3 iterations)
|
v
[Step 8: Summary] -> Files created, pass/fail, next steps
$ARGUMENTS matches a file path: validate it exists.$ARGUMENTS is a directory: discover source files without existing tests.
$ARGUMENTS is a glob pattern: expand and collect matching files.$ARGUMENTS is empty and AUTO_MODE=true, auto-detect target files by selecting source files changed in the working tree relative to the base branch (git diff) that do not already have matching tests.
$ARGUMENTS is empty and AUTO_MODE is false, ask the user:AskUserQuestion
header: Target Selection
question: Which file or directory should I generate tests for?
options:
- (freeform) Enter a file path, directory, or glob pattern
Store as TARGET_FILES.
Read the detection heuristics from references/framework-detection.md.
Check for framework-specific config files:
jest.config.*, vitest.config.*, pytest.ini, pyproject.toml (pytest section), Cargo.toml, *.bats, karma.conf.*, playwright.config.*, cypress.config.*, .mocharc.*Check package.json for test scripts and devDependencies.
Detect test file naming convention from existing test files:
*.test.ts, *.spec.ts, *_test.py, *_test.go, test_*.pyDetect directory convention:
__tests__/ subdirectorytests/ or test/ directoryIf multiple frameworks detected:
If AUTO_MODE=true, choose the framework with the strongest local convention signal (nearest matching tests first, then the framework with the clearest config and runner command).
Otherwise:
AskUserQuestion
header: Multiple Test Frameworks
question: I found multiple test frameworks. Which should I use?
options:
- "{framework 1} — {description}"
- "{framework 2} — {description}"
Store detected configuration as FRAMEWORK_CONFIG (framework, runner command, file naming, directory convention).
Read the conventions guide from references/test-conventions-guide.md.
Find 3-5 existing test files similar to the target:
Read each test file and extract:
Produce a Test Convention Profile using the template from assets/convention-profile.md. Use concrete examples from the project, not generic samples.
If no existing tests found: use sensible framework defaults. Note in the summary that conventions are assumed.
Read the target file(s) in full. Identify:
Classify each testable unit and estimate the number of test cases based on Step 5 depth.
If AUTO_MODE=true, skip these prompts and use:
Otherwise:
AskUserQuestion
header: Test Type
question: What type of tests should I generate?
options:
- Unit tests only — isolated with mocked dependencies
- Integration tests — real dependencies where possible
- Both unit and integration
AskUserQuestion
header: Scope
question: What should I cover?
options:
- All exported functions and classes
- Public API surface only
- Specific functions — I'll tell you which
AskUserQuestion
header: Edge Case Depth
question: How thorough should the tests be?
options:
- Happy path only — get coverage started quickly
- Happy path + error cases — cover success and failure
- Comprehensive — happy, error, boundary, null/undefined
For each target, compute its conventional test path from FRAMEWORK_CONFIG and check whether a test file already exists there before writing.
--auto modes already exclude tested files in Step 1; this guard covers explicit file-path and glob targets.)Then:
FRAMEWORK_CONFIG naming and directory conventions.describe block per function or classit/test block per scenarioRun the generated tests using the detected runner command. Examples (path-filter flags are version-dependent — prefer the project's own runner invocation):
npx jest --testPathPattern="path/to/test" (Jest ≥30 uses --testPathPatterns)npx vitest run path/to/testpytest path/to/test_file.pygo test ./path/to/package/ -run TestFunctionNamecargo test module_nameIf tests fail — analyze the failure and fix the test (not the source code):
Maximum 3 fix iterations. After 3 attempts, present remaining failures to user.
Test Generation Complete
Target: {TARGET_FILES}
Framework: {FRAMEWORK_CONFIG.framework}
Convention: {FRAMEWORK_CONFIG.naming_pattern} ({FRAMEWORK_CONFIG.directory_convention})
Files Created:
{test_file_path} ({N} tests)
Results:
Passing: {passing}/{total}
Failing: {failing} (see errors below)
{if failing > 0}
Remaining Failures:
- {test name}: {error summary}
{/if}
{if suspected_source_defects}
Suspected Source Defects (test left red, source NOT modified):
- {location}: {what the code does vs. what the contract implies}
{/if}
{if conventions_assumed}
Note: No existing test files found. Conventions assumed from
{framework} defaults. Review and adjust as needed.
{/if}
Next Steps:
- Review generated tests for correctness
- Run /kramme:verify:run for full verification
STOP — Do not continue beyond this point. Wait for user review.
| Scenario | Action |
| --- | --- |
| Target file not found | Abort: Target file not found: {path} |
| Test file already exists at the target path | Ask whether to overwrite, merge cases in, or skip (Step 6). Never overwrite silently |
| Directory target has no untested files | Report that there is nothing to generate and stop |
| No test framework detected | If AUTO_MODE=true, abort with a clear error. Otherwise AskUserQuestion to choose a framework and test command |
| No existing tests to learn from | Use framework defaults; note in summary |
| Multiple test frameworks detected | If AUTO_MODE=true, choose the strongest local convention signal. Otherwise AskUserQuestion to select |
| Generated tests have syntax errors | Fix in Step 7 iteration |
| Test runner not installed | Inform user, suggest install command |
| Target has no exportable units | Warn; offer smoke test or skip |
tools
Requires Linear MCP. Implements one Linear issue end to end, selects applicable code-review, convention, and PR-refactor gates, runs them to bounded convergence, verifies, and optionally opens the PR and iterates on CI and review feedback until green. Use when the user wants a single Linear issue taken from implementation through a clean Pull Request. Not for implementation-only work, SIW-tracked issues, stacked PRs, existing PR updates, or post-merge rollout.
development
Reviews PR and local changes for convention drift and overcaution against documented rules and mined peer-file practice. Use for new patterns, dependencies, abstractions, or defensive complexity that departs from established practice; every finding cites evidence. Supports --inline. Not for general code quality (use kramme:pr:code-review) or spec review (use kramme:siw:spec-audit --team).
testing
Charts huge or foggy initiatives into a local `.context` decision map and resolves one typed frontier ticket per session until the work is ready for SIW or another execution workflow. Use when the route to a destination cannot fit in one agent session or parallel workspaces need coordinated planning state. Not for clear specs, ordinary issue decomposition, implementation, or Linear-native tracking.
development
Investigates a question against primary sources and saves one cited Markdown artifact. Use for reading legwork: official docs/API facts, source-code or spec checks, standards, and first-party service behavior before planning or implementation. Not for making product or architecture decisions, implementing code, broad web search, secondary blog summaries, or uncited answers.