backend-test
Generate backend tests (unit, integration, mocks) for existing code. Auto-invoke when user says "write test for", "add test", "test this", or "create test".
What this skill does
# Backend Test Generator
Generate backend tests for **existing code** — typically code that was written without tests, or where additional coverage is needed beyond what a code-writing skill (`backend-endpoint`) already produced.
> **When to use this vs. `backend-endpoint`**: `backend-endpoint` generates tests as part of creating a new endpoint. Use `backend-test` when the code already exists and you need to add or expand its tests.
## When to Invoke
Auto-invoke when user says:
- "Write test for [file/function]"
- "Add test" / "Add tests"
- "Test this"
- "Create test for [thing]"
- "Test the [api/service/function]"
## Execution Steps
### Step 0: Check Existing Patterns (Phase 0)
Query the knowledge graph for what we know about testing in this project:
```bash
PLUGIN_DIR="${CLAUDE_PLUGIN_ROOT:-$HOME/.claude/plugins/cache/navigator-marketplace/navigator}"
[ -d "$PLUGIN_DIR" ] || PLUGIN_DIR="$HOME/.claude/plugins/marketplaces/navigator-marketplace"
python3 "$PLUGIN_DIR/skills/nav-graph/functions/graph_manager.py" \
--action query --concept testing \
--graph-path .agent/knowledge/graph.json 2>/dev/null | head -40
```
Surface patterns (preferred frameworks, mocking conventions) and pitfalls (flaky-test gotchas). If the graph returns nothing, proceed without it.
### Step 1: Locate Code Under Test
If the user named a specific file, use it. Otherwise, ask:
```
What should I test?
- File path (e.g., src/services/userService.ts)
- Function name (e.g., authenticateUser)
- API endpoint (e.g., POST /api/login)
```
Read the target file in full so the generated tests cover its actual behavior, not assumed behavior.
### Step 2: Detect Test Framework
```bash
# Jest
grep -q '"jest"' package.json 2>/dev/null && echo "Jest detected"
# Vitest
grep -q '"vitest"' package.json 2>/dev/null && echo "Vitest detected"
# Mocha
grep -q '"mocha"' package.json 2>/dev/null && echo "Mocha detected"
# Node test runner (built-in)
[ -f "package.json" ] && grep -q '"test":\s*"node --test' package.json && echo "node:test detected"
```
Detect existing test patterns by reading a peer test file under `__tests__/`, `tests/`, or `*.test.ts` alongside the target.
### Step 3: Generate Test File
**File location**: place tests where existing tests live (mirror the project's convention — colocated `*.test.ts` next to source, or under a `tests/` directory).
**Structure (Jest/Vitest)**:
```typescript
import { describe, it, expect, beforeEach, vi } from 'vitest'; // or 'jest'
import { {FUNCTION_NAME} } from '{TARGET_PATH}';
describe('{FUNCTION_NAME}', () => {
describe('happy path', () => {
it('returns expected result for valid input', () => {
const result = {FUNCTION_NAME}({VALID_INPUT});
expect(result).toEqual({EXPECTED});
});
});
describe('error cases', () => {
it('throws on invalid input', () => {
expect(() => {FUNCTION_NAME}({INVALID_INPUT})).toThrow();
});
});
describe('edge cases', () => {
it('handles empty input', () => { /* ... */ });
it('handles boundary values', () => { /* ... */ });
});
});
```
**For API/integration tests** (supertest pattern):
```typescript
import request from 'supertest';
import { app } from '{APP_PATH}';
describe('{METHOD} {PATH}', () => {
it('returns 200 for valid request', async () => {
const response = await request(app).{method}('{PATH}').send({BODY});
expect(response.status).toBe(200);
expect(response.body).toMatchObject({EXPECTED_SHAPE});
});
it('returns 4xx for invalid request', async () => {
const response = await request(app).{method}('{PATH}').send({BAD_BODY});
expect(response.status).toBe(400);
});
});
```
### Step 4: Verify
Run the generated tests:
```bash
{TEST_COMMAND} {TEST_FILE_PATH}
```
If any fail because tests assume incorrect behavior, **fix the tests, not the source** — unless the source has an actual bug. If the source is buggy, surface that to the user; don't silently change it.
### Step 5: Emit Execution Summary (Graph Ingestion)
```json
{
"execution_summary": {
"skill": "backend-test",
"task": "tests for {TARGET}",
"files_created": ["{test file path}"],
"files_modified": [],
"tests_added": ["{test file path}"],
"stack_detected": "{e.g. vitest+supertest}",
"patterns_followed": [
{"summary": "{e.g. supertest pattern for HTTP integration tests}", "concepts": ["testing", "api"], "confidence": 0.8}
],
"decisions_made": [
{"summary": "{e.g. mocked the DB client because tests must run offline}", "concepts": ["testing"], "confidence": 0.75}
],
"pitfalls_avoided": [],
"assumptions_made": ["{e.g. project uses Vitest globals — no explicit import needed}"]
}
}
```
Ingest:
```bash
PLUGIN_DIR="${CLAUDE_PLUGIN_ROOT:-$HOME/.claude/plugins/cache/navigator-marketplace/navigator}"
[ -d "$PLUGIN_DIR" ] || PLUGIN_DIR="$HOME/.claude/plugins/marketplaces/navigator-marketplace"
echo '<execution_summary JSON>' | python3 "$PLUGIN_DIR/skills/nav-graph/functions/execution_to_graph.py" -
```
## Success Criteria
- [ ] Test file located where the project keeps tests (mirrors convention)
- [ ] Happy path, error cases, and at least one edge case covered
- [ ] Mocks isolate the unit under test
- [ ] All generated tests pass on first run (or surface real bugs in the source)
- [ ] Execution summary emitted
## When NOT to Use This Skill
- You're creating a new endpoint from scratch — use `backend-endpoint` (it generates tests as part of its workflow)
- You want to test a UI component — use `frontend-test`
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.