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 |
development
Compare an existing PR's title and body against the actual branch diff and report drift — false claims, missing major changes, stale scope, missing risk callouts. Use after pushing changes to a branch with an open PR, or before requesting review. Read-only by default; add --fix to delegate to kramme:pr:generate-description for an updated description. Complements kramme:pr:code-review (which checks description accuracy as one signal among many code-quality checks) by being a fast, focused, single-purpose check that runs in seconds.
tools
Reviews plugin skills for focused scope, progressive disclosure, portability, safety, retry behavior, and documentation quality. Use when auditing a SKILL.md, skill directory, or proposed skill text against skill-authoring standards. Not for creating new skills, editing skills, or reviewing ordinary application code.
tools
Reviews recent agent session transcripts to find repeated manual workflows or repeated user asks, then proposes and optionally scaffolds only useful new skills or custom subagents. Use when the user asks to inspect recent sessions, find automation opportunities, or create reusable workflows from repeated work. Not for summarizing one session, general retrospectives, or codebase refactoring.
data-ai
Remove all DONE issues and renumber remaining issues within each prefix group. Not for editing live issue content, archiving still-open issues, or moving issues between prefix groups.