Initial commit

This commit is contained in:
Zhongwei Li
2025-11-29 18:52:21 +08:00
commit d92b6c4698
18 changed files with 1674 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
# Assets
Bundled resources for api-load-tester skill
- [ ] k6_template.js: Template for k6 load test scripts.
- [ ] gatling_template.scala: Template for Gatling load test scripts.
- [ ] artillery_template.yaml: Template for Artillery load test scripts.
- [ ] example_api_spec.json: Example API specification for load testing.

View File

@@ -0,0 +1,43 @@
# Artillery Load Test Configuration
config:
target: "REPLACE_ME" # URL of the API endpoint to test
phases:
- duration: 60 # Ramp up duration in seconds
arrivalRate: 10 # Number of virtual users to start per second
name: "Ramp Up"
- duration: 300 # Sustain duration in seconds
arrivalRate: 10 # Number of virtual users to maintain
name: "Sustain Load"
defaults:
headers:
Content-Type: "application/json"
#Add any default headers here. Authorization tokens, etc.
#Authorization: "Bearer YOUR_AUTH_TOKEN"
scenarios:
- name: "Basic API Request"
flow:
- get:
url: "/YOUR_ENDPOINT_HERE" # Replace with your API endpoint
# Capture response data to variables
capture:
- json: "$.id"
as: "id"
# Example of using a custom function
# beforeRequest: "myFunction"
- think: 1 # Pause for 1 second between requests
- log: "Request completed. ID: {{ id }}" # Log the captured ID
# Define custom functions (optional, define in separate .js file referenced in config)
# functions: "./my_functions.js"
# Example function (in my_functions.js)
# module.exports.myFunction = function(requestParams, context, ee, next) {
# // Add custom logic here
# return next();
# };
# Variables (can be loaded from CSV or defined inline)
# variables:
# - id: [1, 2, 3, 4, 5]

View File

@@ -0,0 +1,32 @@
{
"skill": {
"name": "skill-name",
"version": "1.0.0",
"enabled": true,
"settings": {
"verbose": false,
"autoActivate": true,
"toolRestrictions": true
}
},
"triggers": {
"keywords": [
"example-trigger-1",
"example-trigger-2"
],
"patterns": []
},
"tools": {
"allowed": [
"Read",
"Grep",
"Bash"
],
"restricted": []
},
"metadata": {
"author": "Plugin Author",
"category": "general",
"tags": []
}
}

View File

@@ -0,0 +1,90 @@
{
"_comment": "Example API specification for load testing with k6, Gatling, or Artillery.",
"api_name": "Example API",
"description": "A simple API endpoint for demonstrating load testing configurations.",
"endpoints": [
{
"name": "Get User",
"method": "GET",
"url": "https://example.com/api/users/123",
"_comment": "Example URL. Replace with your actual API endpoint.",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer <your_api_key>"
},
"body": null,
"expected_status_code": 200,
"assertions": [
{
"type": "json_path",
"path": "$.id",
"operator": "eq",
"value": 123,
"_comment": "Verify user ID is 123."
}
]
},
{
"name": "Create User",
"method": "POST",
"url": "https://example.com/api/users",
"headers": {
"Content-Type": "application/json"
},
"body": {
"name": "John Doe",
"email": "john.doe@example.com"
},
"expected_status_code": 201,
"assertions": [
{
"type": "json_path",
"path": "$.name",
"operator": "eq",
"value": "John Doe",
"_comment": "Verify user name is John Doe."
}
]
},
{
"name": "Update User",
"method": "PUT",
"url": "https://example.com/api/users/123",
"headers": {
"Content-Type": "application/json"
},
"body": {
"name": "Jane Doe",
"email": "jane.doe@example.com"
},
"expected_status_code": 200,
"assertions": [
{
"type": "json_path",
"path": "$.name",
"operator": "eq",
"value": "Jane Doe",
"_comment": "Verify user name is Jane Doe."
}
]
},
{
"name": "Delete User",
"method": "DELETE",
"url": "https://example.com/api/users/123",
"headers": {},
"body": null,
"expected_status_code": 204,
"assertions": []
}
],
"load_profile": {
"tool": "k6",
"_comment": "Can be k6, gatling, or artillery",
"options": {
"vus": 10,
"duration": "10s",
"_comment": "k6 options, see k6 documentation for details"
}
}
}

View File

@@ -0,0 +1,59 @@
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class APILoadTest extends Simulation {
// --- Configuration ---
// Configure the target URL and request parameters here.
val baseURL = "${BASE_URL}" // e.g., "http://example.com"
val endpoint = "${ENDPOINT}" // e.g., "/api/resource"
val requestName = "Get Resource" // Descriptive name for the request
val requestBody = """${REQUEST_BODY}""" // JSON request body (optional)
// --- HTTP Protocol Configuration ---
val httpProtocol = http
.baseUrl(baseURL)
.acceptHeader("application/json")
.contentTypeHeader("application/json")
// Add any other headers or configurations you need here.
// .userAgentHeader("Gatling/3.7.0") // Example User-Agent header
// --- Scenario Definition ---
val scn = scenario("API Load Test Scenario")
.exec(
http(requestName)
.get(endpoint) // Or .post(endpoint).body(StringBody(requestBody)) if it's a POST request
//.headers(Map("Custom-Header" -> "value")) // Example custom header
.check(status.is(200)) // Validate the response status
// Add more checks as needed to validate the response data.
// .check(jsonPath("$.someField").is("expectedValue"))
)
// --- Simulation Setup ---
setUp(
scn.inject(
// Define your load profile here. Examples:
// - Constant load of 10 users per second for 30 seconds
// constantUsersPerSec(10).during(30.seconds),
// - Ramp up from 1 to 10 users over 20 seconds
// rampUsersPerSec(1).to(10).during(20.seconds),
// - Constant load for a period, then a ramp-up, then another constant load
// constantUsersPerSec(5).during(10.seconds),
// rampUsersPerSec(5).to(15).during(10.seconds),
// constantUsersPerSec(15).during(10.seconds)
// Placeholders for easy adjustments. Replace these with your desired values.
constantUsersPerSec(${USERS_PER_SECOND}).during(${DURATION_SECONDS}.seconds)
).protocols(httpProtocol)
)
// Add global assertions if needed. For example:
// .assertions(
// global.responseTime.max.lt(1000), // Ensure maximum response time is less than 1000ms
// global.successfulRequests.percent.gt(95) // Ensure success rate is greater than 95%
// )
}

View File

@@ -0,0 +1,52 @@
// k6 load test script template
import http from 'k6/http';
import { check, sleep } from 'k6';
// Configuration options
export const options = {
stages: [
{ duration: '10s', target: 10 }, // Ramp up to 10 virtual users (VUs) over 10 seconds
{ duration: '30s', target: 10 }, // Stay at 10 VUs for 30 seconds
{ duration: '10s', target: 0 }, // Ramp down to 0 VUs over 10 seconds
],
thresholds: {
http_req_duration: ['p95<500'], // 95% of requests must complete below 500ms
http_req_failed: ['rate<0.01'], // Error rate must be less than 1%
},
};
// Virtual User (VU) function
export default function () {
// Replace with your API endpoint
const url = 'YOUR_API_ENDPOINT';
// Replace with your request body (if needed)
const payload = JSON.stringify({
key1: 'value1',
key2: 'value2',
});
// Replace with your request headers (if needed)
const params = {
headers: {
'Content-Type': 'application/json',
},
};
// Make the HTTP request
const res = http.post(url, payload, params);
// Check the response status code
check(res, {
'is status 200': (r) => r.status === 200,
});
// Add more checks as needed (e.g., response body validation)
// check(res, {
// 'verify response': (r) => r.body.includes('expected_value'),
// });
// Sleep for a short duration between requests (adjust as needed)
sleep(1);
}

View File

@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Claude Skill Configuration",
"type": "object",
"required": ["name", "description"],
"properties": {
"name": {
"type": "string",
"pattern": "^[a-z0-9-]+$",
"maxLength": 64,
"description": "Skill identifier (lowercase, hyphens only)"
},
"description": {
"type": "string",
"maxLength": 1024,
"description": "What the skill does and when to use it"
},
"allowed-tools": {
"type": "string",
"description": "Comma-separated list of allowed tools"
},
"version": {
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+$",
"description": "Semantic version (x.y.z)"
}
}
}

View File

@@ -0,0 +1,27 @@
{
"testCases": [
{
"name": "Basic activation test",
"input": "trigger phrase example",
"expected": {
"activated": true,
"toolsUsed": ["Read", "Grep"],
"success": true
}
},
{
"name": "Complex workflow test",
"input": "multi-step trigger example",
"expected": {
"activated": true,
"steps": 3,
"toolsUsed": ["Read", "Write", "Bash"],
"success": true
}
}
],
"fixtures": {
"sampleInput": "example data",
"expectedOutput": "processed result"
}
}

View File

@@ -0,0 +1,8 @@
# References
Bundled resources for api-load-tester skill
- [ ] k6_api_reference.md: API reference for k6 load testing tool.
- [ ] gatling_api_reference.md: API reference for Gatling load testing tool.
- [ ] artillery_api_reference.md: API reference for Artillery load testing tool.
- [ ] load_testing_best_practices.md: Best practices for API load testing.

View File

@@ -0,0 +1,69 @@
# Skill Best Practices
Guidelines for optimal skill usage and development.
## For Users
### Activation Best Practices
1. **Use Clear Trigger Phrases**
- Match phrases from skill description
- Be specific about intent
- Provide necessary context
2. **Provide Sufficient Context**
- Include relevant file paths
- Specify scope of analysis
- Mention any constraints
3. **Understand Tool Permissions**
- Check allowed-tools in frontmatter
- Know what the skill can/cannot do
- Request appropriate actions
### Workflow Optimization
- Start with simple requests
- Build up to complex workflows
- Verify each step before proceeding
- Use skill consistently for related tasks
## For Developers
### Skill Development Guidelines
1. **Clear Descriptions**
- Include explicit trigger phrases
- Document all capabilities
- Specify limitations
2. **Proper Tool Permissions**
- Use minimal necessary tools
- Document security implications
- Test with restricted tools
3. **Comprehensive Documentation**
- Provide usage examples
- Document common pitfalls
- Include troubleshooting guide
### Maintenance
- Keep version updated
- Test after tool updates
- Monitor user feedback
- Iterate on descriptions
## Performance Tips
- Scope skills to specific domains
- Avoid overlapping trigger phrases
- Keep descriptions under 1024 chars
- Test activation reliability
## Security Considerations
- Never include secrets in skill files
- Validate all inputs
- Use read-only tools when possible
- Document security requirements

View File

@@ -0,0 +1,70 @@
# Skill Usage Examples
This document provides practical examples of how to use this skill effectively.
## Basic Usage
### Example 1: Simple Activation
**User Request:**
```
[Describe trigger phrase here]
```
**Skill Response:**
1. Analyzes the request
2. Performs the required action
3. Returns results
### Example 2: Complex Workflow
**User Request:**
```
[Describe complex scenario]
```
**Workflow:**
1. Step 1: Initial analysis
2. Step 2: Data processing
3. Step 3: Result generation
4. Step 4: Validation
## Advanced Patterns
### Pattern 1: Chaining Operations
Combine this skill with other tools:
```
Step 1: Use this skill for [purpose]
Step 2: Chain with [other tool]
Step 3: Finalize with [action]
```
### Pattern 2: Error Handling
If issues occur:
- Check trigger phrase matches
- Verify context is available
- Review allowed-tools permissions
## Tips & Best Practices
- ✅ Be specific with trigger phrases
- ✅ Provide necessary context
- ✅ Check tool permissions match needs
- ❌ Avoid vague requests
- ❌ Don't mix unrelated tasks
## Common Issues
**Issue:** Skill doesn't activate
**Solution:** Use exact trigger phrases from description
**Issue:** Unexpected results
**Solution:** Check input format and context
## See Also
- Main SKILL.md for full documentation
- scripts/ for automation helpers
- assets/ for configuration examples

View File

@@ -0,0 +1,8 @@
# Scripts
Bundled resources for api-load-tester skill
- [ ] k6_load_test.py: Script to generate and execute k6 load tests based on user input.
- [ ] gatling_load_test.py: Script to generate and execute Gatling load tests based on user input.
- [ ] artillery_load_test.py: Script to generate and execute Artillery load tests based on user input.
- [ ] load_test_parser.py: Script to parse load test results and provide a summary.

View File

@@ -0,0 +1,42 @@
#!/bin/bash
# Helper script template for skill automation
# Customize this for your skill's specific needs
set -e
function show_usage() {
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " -v, --verbose Enable verbose output"
echo ""
}
# Parse arguments
VERBOSE=false
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_usage
exit 0
;;
-v|--verbose)
VERBOSE=true
shift
;;
*)
echo "Unknown option: $1"
show_usage
exit 1
;;
esac
done
# Your skill logic here
if [ "$VERBOSE" = true ]; then
echo "Running skill automation..."
fi
echo "✅ Complete"

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# Skill validation helper
# Validates skill activation and functionality
set -e
echo "🔍 Validating skill..."
# Check if SKILL.md exists
if [ ! -f "../SKILL.md" ]; then
echo "❌ Error: SKILL.md not found"
exit 1
fi
# Validate frontmatter
if ! grep -q "^---$" "../SKILL.md"; then
echo "❌ Error: No frontmatter found"
exit 1
fi
# Check required fields
if ! grep -q "^name:" "../SKILL.md"; then
echo "❌ Error: Missing 'name' field"
exit 1
fi
if ! grep -q "^description:" "../SKILL.md"; then
echo "❌ Error: Missing 'description' field"
exit 1
fi
echo "✅ Skill validation passed"