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"
}
}