@kirrosh/apitool 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +27 -0
- package/.github/workflows/release.yml +97 -0
- package/.mcp.json +9 -0
- package/APITOOL.md +195 -0
- package/BACKLOG.md +62 -0
- package/CHANGELOG.md +88 -0
- package/LICENSE +21 -0
- package/README.md +105 -0
- package/bun.lock +291 -0
- package/docs/GLOSSARY.md +182 -0
- package/docs/INDEX.md +21 -0
- package/docs/agent.md +135 -0
- package/docs/archive/APITOOL-pre-M22.md +831 -0
- package/docs/archive/BACKLOG-AI-NATIVE.md +56 -0
- package/docs/archive/M1-M2-parser-runner.md +216 -0
- package/docs/archive/M4-M7-reporter-cli.md +179 -0
- package/docs/archive/M5-M7-storage-junit.md +300 -0
- package/docs/archive/M6-webui.md +339 -0
- package/docs/ci.md +274 -0
- package/docs/generation-issues.md +67 -0
- package/generated/.env.yaml +3 -0
- package/install.ps1 +80 -0
- package/install.sh +113 -0
- package/package.json +46 -0
- package/scripts/run-mocked-tests.ts +45 -0
- package/seed-demo.ts +53 -0
- package/self-tests/auth.yaml +18 -0
- package/self-tests/collections-crud.yaml +46 -0
- package/self-tests/environments-crud.yaml +48 -0
- package/self-tests/export.yaml +32 -0
- package/self-tests/runs.yaml +16 -0
- package/src/bun-types.d.ts +5 -0
- package/src/cli/commands/add-api.ts +51 -0
- package/src/cli/commands/ai-generate.ts +106 -0
- package/src/cli/commands/chat.ts +43 -0
- package/src/cli/commands/ci-init.ts +126 -0
- package/src/cli/commands/collections.ts +41 -0
- package/src/cli/commands/coverage.ts +65 -0
- package/src/cli/commands/doctor.ts +127 -0
- package/src/cli/commands/envs.ts +218 -0
- package/src/cli/commands/init.ts +84 -0
- package/src/cli/commands/mcp.ts +16 -0
- package/src/cli/commands/run.ts +137 -0
- package/src/cli/commands/runs.ts +108 -0
- package/src/cli/commands/serve.ts +22 -0
- package/src/cli/commands/update.ts +142 -0
- package/src/cli/commands/validate.ts +18 -0
- package/src/cli/index.ts +500 -0
- package/src/cli/output.ts +24 -0
- package/src/cli/runtime.ts +7 -0
- package/src/core/agent/agent-loop.ts +116 -0
- package/src/core/agent/context-manager.ts +41 -0
- package/src/core/agent/system-prompt.ts +33 -0
- package/src/core/agent/tools/diagnose-failure.ts +51 -0
- package/src/core/agent/tools/explore-api.ts +40 -0
- package/src/core/agent/tools/index.ts +48 -0
- package/src/core/agent/tools/manage-environment.ts +40 -0
- package/src/core/agent/tools/query-results.ts +40 -0
- package/src/core/agent/tools/run-tests.ts +38 -0
- package/src/core/agent/tools/send-request.ts +44 -0
- package/src/core/agent/tools/validate-tests.ts +23 -0
- package/src/core/agent/types.ts +22 -0
- package/src/core/generator/ai/ai-generator.ts +61 -0
- package/src/core/generator/ai/llm-client.ts +159 -0
- package/src/core/generator/ai/output-parser.ts +307 -0
- package/src/core/generator/ai/prompt-builder.ts +153 -0
- package/src/core/generator/ai/types.ts +56 -0
- package/src/core/generator/coverage-scanner.ts +87 -0
- package/src/core/generator/data-factory.ts +115 -0
- package/src/core/generator/index.ts +10 -0
- package/src/core/generator/openapi-reader.ts +142 -0
- package/src/core/generator/schema-utils.ts +52 -0
- package/src/core/generator/serializer.ts +189 -0
- package/src/core/generator/types.ts +47 -0
- package/src/core/parser/filter.ts +14 -0
- package/src/core/parser/index.ts +21 -0
- package/src/core/parser/schema.ts +175 -0
- package/src/core/parser/types.ts +50 -0
- package/src/core/parser/variables.ts +146 -0
- package/src/core/parser/yaml-parser.ts +85 -0
- package/src/core/reporter/console.ts +175 -0
- package/src/core/reporter/index.ts +23 -0
- package/src/core/reporter/json.ts +9 -0
- package/src/core/reporter/junit.ts +78 -0
- package/src/core/reporter/types.ts +12 -0
- package/src/core/runner/assertions.ts +172 -0
- package/src/core/runner/execute-run.ts +75 -0
- package/src/core/runner/executor.ts +150 -0
- package/src/core/runner/http-client.ts +69 -0
- package/src/core/runner/index.ts +12 -0
- package/src/core/runner/types.ts +48 -0
- package/src/core/setup-api.ts +97 -0
- package/src/core/utils.ts +9 -0
- package/src/db/queries.ts +868 -0
- package/src/db/schema.ts +215 -0
- package/src/mcp/server.ts +47 -0
- package/src/mcp/tools/ci-init.ts +57 -0
- package/src/mcp/tools/coverage-analysis.ts +58 -0
- package/src/mcp/tools/explore-api.ts +84 -0
- package/src/mcp/tools/generate-missing-tests.ts +80 -0
- package/src/mcp/tools/generate-tests-guide.ts +353 -0
- package/src/mcp/tools/manage-environment.ts +123 -0
- package/src/mcp/tools/manage-server.ts +87 -0
- package/src/mcp/tools/query-db.ts +141 -0
- package/src/mcp/tools/run-tests.ts +66 -0
- package/src/mcp/tools/save-test-suite.ts +164 -0
- package/src/mcp/tools/send-request.ts +53 -0
- package/src/mcp/tools/setup-api.ts +49 -0
- package/src/mcp/tools/validate-tests.ts +42 -0
- package/src/tui/chat-ui.ts +150 -0
- package/src/web/routes/api.ts +234 -0
- package/src/web/routes/dashboard.ts +348 -0
- package/src/web/routes/runs.ts +64 -0
- package/src/web/schemas.ts +121 -0
- package/src/web/server.ts +134 -0
- package/src/web/static/htmx.min.js +1 -0
- package/src/web/static/style.css +265 -0
- package/src/web/views/layout.ts +46 -0
- package/src/web/views/results.ts +209 -0
- package/tests/agent/agent-loop.test.ts +61 -0
- package/tests/agent/context-manager.test.ts +59 -0
- package/tests/agent/system-prompt.test.ts +42 -0
- package/tests/agent/tools/diagnose-failure.test.ts +85 -0
- package/tests/agent/tools/explore-api.test.ts +59 -0
- package/tests/agent/tools/manage-environment.test.ts +78 -0
- package/tests/agent/tools/query-results.test.ts +77 -0
- package/tests/agent/tools/run-tests.test.ts +89 -0
- package/tests/agent/tools/send-request.test.ts +78 -0
- package/tests/agent/tools/validate-tests.test.ts +59 -0
- package/tests/ai/ai-generator.integration.test.ts +131 -0
- package/tests/ai/llm-client.test.ts +145 -0
- package/tests/ai/output-parser.test.ts +132 -0
- package/tests/ai/prompt-builder.test.ts +67 -0
- package/tests/ai/types.test.ts +55 -0
- package/tests/cli/args.test.ts +63 -0
- package/tests/cli/chat.test.ts +38 -0
- package/tests/cli/ci-init.test.ts +112 -0
- package/tests/cli/commands.test.ts +316 -0
- package/tests/cli/coverage.test.ts +58 -0
- package/tests/cli/doctor.test.ts +39 -0
- package/tests/cli/envs.test.ts +181 -0
- package/tests/cli/init.test.ts +80 -0
- package/tests/cli/runs.test.ts +94 -0
- package/tests/cli/safe-run.test.ts +103 -0
- package/tests/cli/update.test.ts +32 -0
- package/tests/core/generator/schema-utils.test.ts +108 -0
- package/tests/core/parser/nested-assertions.test.ts +80 -0
- package/tests/core/runner/root-body-assertions.test.ts +70 -0
- package/tests/db/chat-queries.test.ts +88 -0
- package/tests/db/chat-schema.test.ts +37 -0
- package/tests/db/environments.test.ts +131 -0
- package/tests/db/queries.test.ts +409 -0
- package/tests/db/schema.test.ts +141 -0
- package/tests/fixtures/.env.yaml +3 -0
- package/tests/fixtures/auth-token-test.yaml +8 -0
- package/tests/fixtures/bail/suite-a.yaml +6 -0
- package/tests/fixtures/bail/suite-b.yaml +6 -0
- package/tests/fixtures/crud.yaml +35 -0
- package/tests/fixtures/invalid-missing-name.yaml +5 -0
- package/tests/fixtures/invalid-no-method.yaml +6 -0
- package/tests/fixtures/petstore-auth.json +295 -0
- package/tests/fixtures/petstore-simple.json +151 -0
- package/tests/fixtures/post-only.yaml +12 -0
- package/tests/fixtures/simple.yaml +6 -0
- package/tests/fixtures/valid/.env.yaml +1 -0
- package/tests/fixtures/valid/a.yaml +5 -0
- package/tests/fixtures/valid/b.yml +5 -0
- package/tests/generator/coverage-scanner.test.ts +129 -0
- package/tests/generator/data-factory.test.ts +133 -0
- package/tests/generator/openapi-reader.test.ts +131 -0
- package/tests/integration/auth-flow.test.ts +217 -0
- package/tests/mcp/coverage-analysis.test.ts +64 -0
- package/tests/mcp/explore-api-schemas.test.ts +105 -0
- package/tests/mcp/explore-api.test.ts +49 -0
- package/tests/mcp/generate-missing-tests.test.ts +69 -0
- package/tests/mcp/manage-environment.test.ts +89 -0
- package/tests/mcp/save-test-suite.test.ts +116 -0
- package/tests/mcp/send-request.test.ts +79 -0
- package/tests/mcp/setup-api.test.ts +106 -0
- package/tests/mcp/tools.test.ts +248 -0
- package/tests/parser/schema.test.ts +134 -0
- package/tests/parser/variables.test.ts +227 -0
- package/tests/parser/yaml-parser.test.ts +69 -0
- package/tests/reporter/console.test.ts +256 -0
- package/tests/reporter/json.test.ts +98 -0
- package/tests/reporter/junit.test.ts +284 -0
- package/tests/runner/assertions.test.ts +262 -0
- package/tests/runner/executor.test.ts +310 -0
- package/tests/runner/http-client.test.ts +138 -0
- package/tests/web/routes.test.ts +160 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, dev]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
check:
|
|
11
|
+
name: Typecheck & Test
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- uses: oven-sh/setup-bun@v2
|
|
18
|
+
with:
|
|
19
|
+
bun-version: latest
|
|
20
|
+
|
|
21
|
+
- run: bun install
|
|
22
|
+
|
|
23
|
+
- name: Typecheck
|
|
24
|
+
run: bunx tsc --noEmit
|
|
25
|
+
|
|
26
|
+
- name: Tests
|
|
27
|
+
run: bun run test
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
name: Build (${{ matrix.target }})
|
|
14
|
+
runs-on: ${{ matrix.os }}
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
include:
|
|
18
|
+
- os: ubuntu-latest
|
|
19
|
+
target: linux-x64
|
|
20
|
+
artifact: apitool
|
|
21
|
+
archive: tar.gz
|
|
22
|
+
- os: macos-latest
|
|
23
|
+
target: darwin-arm64
|
|
24
|
+
artifact: apitool
|
|
25
|
+
archive: tar.gz
|
|
26
|
+
- os: windows-latest
|
|
27
|
+
target: win-x64
|
|
28
|
+
artifact: apitool.exe
|
|
29
|
+
archive: zip
|
|
30
|
+
|
|
31
|
+
steps:
|
|
32
|
+
- uses: actions/checkout@v4
|
|
33
|
+
|
|
34
|
+
- uses: oven-sh/setup-bun@v2
|
|
35
|
+
with:
|
|
36
|
+
bun-version: latest
|
|
37
|
+
|
|
38
|
+
- run: bun install
|
|
39
|
+
|
|
40
|
+
- name: Build binary
|
|
41
|
+
run: bun build --compile src/cli/index.ts --outfile apitool
|
|
42
|
+
|
|
43
|
+
- name: Package (tar.gz)
|
|
44
|
+
if: matrix.archive == 'tar.gz'
|
|
45
|
+
run: tar -czf apitool-${{ matrix.target }}.tar.gz ${{ matrix.artifact }}
|
|
46
|
+
|
|
47
|
+
- name: Package (zip)
|
|
48
|
+
if: matrix.archive == 'zip'
|
|
49
|
+
shell: pwsh
|
|
50
|
+
run: Compress-Archive -Path ${{ matrix.artifact }} -DestinationPath apitool-${{ matrix.target }}.zip
|
|
51
|
+
|
|
52
|
+
- uses: actions/upload-artifact@v4
|
|
53
|
+
with:
|
|
54
|
+
name: apitool-${{ matrix.target }}
|
|
55
|
+
path: apitool-${{ matrix.target }}.${{ matrix.archive }}
|
|
56
|
+
|
|
57
|
+
release:
|
|
58
|
+
name: Publish Release
|
|
59
|
+
needs: build
|
|
60
|
+
runs-on: ubuntu-latest
|
|
61
|
+
|
|
62
|
+
steps:
|
|
63
|
+
- uses: actions/download-artifact@v4
|
|
64
|
+
with:
|
|
65
|
+
merge-multiple: true
|
|
66
|
+
|
|
67
|
+
- name: Create GitHub Release
|
|
68
|
+
uses: softprops/action-gh-release@v2
|
|
69
|
+
with:
|
|
70
|
+
generate_release_notes: true
|
|
71
|
+
files: |
|
|
72
|
+
apitool-linux-x64.tar.gz
|
|
73
|
+
apitool-darwin-arm64.tar.gz
|
|
74
|
+
apitool-win-x64.zip
|
|
75
|
+
|
|
76
|
+
publish:
|
|
77
|
+
name: Publish to npm
|
|
78
|
+
needs: release
|
|
79
|
+
runs-on: ubuntu-latest
|
|
80
|
+
|
|
81
|
+
steps:
|
|
82
|
+
- uses: actions/checkout@v4
|
|
83
|
+
|
|
84
|
+
- uses: actions/setup-node@v4
|
|
85
|
+
with:
|
|
86
|
+
node-version: "20"
|
|
87
|
+
registry-url: "https://registry.npmjs.org"
|
|
88
|
+
|
|
89
|
+
- uses: oven-sh/setup-bun@v2
|
|
90
|
+
with:
|
|
91
|
+
bun-version: latest
|
|
92
|
+
|
|
93
|
+
- run: bun install
|
|
94
|
+
|
|
95
|
+
- run: npm publish --access public
|
|
96
|
+
env:
|
|
97
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/.mcp.json
ADDED
package/APITOOL.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# APITOOL
|
|
2
|
+
|
|
3
|
+
**AI-native API testing tool** — OpenAPI spec → test generation → execution → diagnostics. One binary. Zero config.
|
|
4
|
+
|
|
5
|
+
- **MCP** — primary interface for AI agents (Claude Code, Cursor, Windsurf)
|
|
6
|
+
- **CLI** — for humans and CI/CD
|
|
7
|
+
- **WebUI** — dashboard for viewing results
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
apitool update # install / update
|
|
15
|
+
apitool add-api myapi --spec openapi.json # register API
|
|
16
|
+
apitool ai-generate --api myapi --prompt "test all CRUD endpoints"
|
|
17
|
+
apitool run --api myapi --env staging
|
|
18
|
+
apitool serve --port 4000 # web dashboard
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### MCP Setup
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{ "mcpServers": { "apitool": { "command": "apitool", "args": ["mcp"] } } }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then ask your AI agent: *"Test the API from openapi.json"*
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Architecture
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
src/
|
|
35
|
+
├── core/
|
|
36
|
+
│ ├── parser/ YAML → TestSuite (schema, variables, generators)
|
|
37
|
+
│ ├── runner/ HTTP execution, captures, assertions
|
|
38
|
+
│ ├── generator/ OpenAPI reader, coverage scanner, AI generation
|
|
39
|
+
│ ├── reporter/ Console, JSON, JUnit XML
|
|
40
|
+
│ └── agent/ AI Chat (AI SDK v6, tool calling)
|
|
41
|
+
├── db/ SQLite (runs, collections, environments)
|
|
42
|
+
├── mcp/ MCP Server (15 tools)
|
|
43
|
+
├── web/ Hono + HTMX dashboard
|
|
44
|
+
└── cli/ 16 CLI commands
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Stack
|
|
48
|
+
|
|
49
|
+
Bun runtime, TypeScript, SQLite (`bun:sqlite`), Hono + HTMX, `bun build --compile` → single binary.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Modules
|
|
54
|
+
|
|
55
|
+
### Parser
|
|
56
|
+
Reads YAML test files → `TestSuite[]`. Schema validation (Zod), variable interpolation (`{{base_url}}`), built-in generators (`{{$randomEmail}}`, `{{$uuid}}`, etc.), nested body assertion flattening.
|
|
57
|
+
|
|
58
|
+
### Runner
|
|
59
|
+
Executes test steps sequentially within a suite. Native `fetch`, captures (`{ capture: "token" }`), assertions (equals, type, contains, matches, gt/lt, exists), nested body paths (`category.name`), root body checks (`_body: { type: "array" }`).
|
|
60
|
+
|
|
61
|
+
### Generator
|
|
62
|
+
Reads OpenAPI specs (`@readme/openapi-parser`), compresses schemas for LLM context, scans test coverage, AI-based test generation (Ollama/OpenAI/Anthropic).
|
|
63
|
+
|
|
64
|
+
### Reporter
|
|
65
|
+
Console (colored, tags display), JSON, JUnit XML (CI-compatible).
|
|
66
|
+
|
|
67
|
+
### Agent
|
|
68
|
+
Interactive AI chat (`apitool chat`). AI SDK v6, tool calling, multi-provider (Ollama, OpenAI, Anthropic). Safe mode (GET-only).
|
|
69
|
+
|
|
70
|
+
### DB
|
|
71
|
+
SQLite auto-created. Tables: `collections`, `runs`, `results`, `environments`, `ai_generations`. Schema version 5.
|
|
72
|
+
|
|
73
|
+
### WebUI
|
|
74
|
+
Single-page dashboard: API selector → env selector → Run Tests → results + coverage + history. JUnit/JSON export. Hono + HTMX.
|
|
75
|
+
|
|
76
|
+
### MCP Server
|
|
77
|
+
15 tools for AI agent integration. Primary test generation flow:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
generate_tests_guide → [agent writes YAML] → save_test_suite → run_tests → diagnose_failure → ci_init
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### CI/CD
|
|
84
|
+
`apitool ci init` scaffolds GitHub Actions or GitLab CI workflow. Supports schedule, repository_dispatch, manual triggers. See [docs/ci.md](docs/ci.md).
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## MCP Tools
|
|
89
|
+
|
|
90
|
+
| Tool | Description |
|
|
91
|
+
|------|-------------|
|
|
92
|
+
| `generate_tests_guide` | Full API spec + generation algorithm. Use **before** writing tests |
|
|
93
|
+
| `generate_missing_tests` | Guide for only uncovered endpoints |
|
|
94
|
+
| `save_test_suite` | Validate YAML + save file. Returns coverage hint |
|
|
95
|
+
| `run_tests` | Execute tests, return summary with failures |
|
|
96
|
+
| `query_db` | List collections, runs, results, diagnose failures |
|
|
97
|
+
| `explore_api` | Browse OpenAPI spec (`includeSchemas=true` for schemas) |
|
|
98
|
+
| `coverage_analysis` | Compare spec vs existing tests |
|
|
99
|
+
| `validate_tests` | Check YAML syntax without running |
|
|
100
|
+
| `send_request` | Ad-hoc HTTP request with variable interpolation |
|
|
101
|
+
| `setup_api` | Register API (dirs + spec + env + collection) |
|
|
102
|
+
| `manage_environment` | CRUD for environments |
|
|
103
|
+
| `manage_server` | Start/stop WebUI server |
|
|
104
|
+
| `ci_init` | Generate CI/CD workflow (GitHub Actions / GitLab CI) |
|
|
105
|
+
|
|
106
|
+
## CLI Commands
|
|
107
|
+
|
|
108
|
+
| Command | Description | Key flags |
|
|
109
|
+
|---------|-------------|-----------|
|
|
110
|
+
| `add-api <name>` | Register new API | `--spec`, `--dir`, `--env key=value` |
|
|
111
|
+
| `run <path>` | Run tests | `--api`, `--env`, `--report`, `--safe`, `--tag`, `--bail` |
|
|
112
|
+
| `ai-generate` | AI test generation | `--api`, `--from`, `--prompt`, `--provider`, `--model` |
|
|
113
|
+
| `validate` | Validate YAML tests | |
|
|
114
|
+
| `envs` | Environment management | `list\|get\|set\|delete\|import\|export`, `--api` |
|
|
115
|
+
| `runs [id]` | Run history | `--limit` |
|
|
116
|
+
| `coverage` | API test coverage | `--api`, `--spec`, `--tests` |
|
|
117
|
+
| `collections` | List collections | |
|
|
118
|
+
| `serve` | Web dashboard | `--port`, `--watch` |
|
|
119
|
+
| `chat` | Interactive AI agent | `--provider`, `--model`, `--safe` |
|
|
120
|
+
| `mcp` | Start MCP server | `--db` |
|
|
121
|
+
| `ci init` | Generate CI/CD workflow | `--github`, `--gitlab`, `--dir`, `--force` |
|
|
122
|
+
| `init` | Scaffold new project | |
|
|
123
|
+
| `doctor` | Diagnostics | |
|
|
124
|
+
| `update` | Self-update | |
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## YAML Test Format
|
|
129
|
+
|
|
130
|
+
```yaml
|
|
131
|
+
name: Users CRUD
|
|
132
|
+
description: "Full lifecycle test"
|
|
133
|
+
tags: [users, crud]
|
|
134
|
+
base_url: "{{base_url}}"
|
|
135
|
+
headers:
|
|
136
|
+
Authorization: "Bearer {{auth_token}}"
|
|
137
|
+
|
|
138
|
+
tests:
|
|
139
|
+
- name: "Create user"
|
|
140
|
+
POST: /users
|
|
141
|
+
json:
|
|
142
|
+
name: "{{$randomName}}"
|
|
143
|
+
email: "{{$randomEmail}}"
|
|
144
|
+
expect:
|
|
145
|
+
status: 201
|
|
146
|
+
body:
|
|
147
|
+
id: { capture: user_id, type: integer }
|
|
148
|
+
|
|
149
|
+
- name: "Get user"
|
|
150
|
+
GET: /users/{{user_id}}
|
|
151
|
+
expect:
|
|
152
|
+
status: 200
|
|
153
|
+
body:
|
|
154
|
+
id: { equals: "{{user_id}}" }
|
|
155
|
+
|
|
156
|
+
- name: "Delete user"
|
|
157
|
+
DELETE: /users/{{user_id}}
|
|
158
|
+
expect:
|
|
159
|
+
status: 204
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Assertions
|
|
163
|
+
|
|
164
|
+
`equals`, `type`, `capture`, `contains`, `matches`, `gt`, `lt`, `exists` (boolean). Nested: `category.name: { equals: "Dogs" }`. Root body: `_body: { type: "array" }`.
|
|
165
|
+
|
|
166
|
+
### Generators
|
|
167
|
+
|
|
168
|
+
`{{$randomInt}}`, `{{$uuid}}`, `{{$timestamp}}`, `{{$randomEmail}}`, `{{$randomString}}`, `{{$randomName}}`
|
|
169
|
+
|
|
170
|
+
### Environments
|
|
171
|
+
|
|
172
|
+
```yaml
|
|
173
|
+
# .env.staging.yaml
|
|
174
|
+
base_url: https://staging.example.com/api
|
|
175
|
+
token: staging-token
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`apitool run tests/ --env staging`
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Build
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
bun run build # → apitool binary (standalone)
|
|
186
|
+
bun test # run test suite
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Principles
|
|
190
|
+
|
|
191
|
+
1. **One file** — download binary, run. No Docker, no npm.
|
|
192
|
+
2. **Tests as code** — YAML in git, code review, CI/CD.
|
|
193
|
+
3. **OpenAPI-first** — spec exists → tests generate.
|
|
194
|
+
4. **AI-native** — MCP for agents, CLI for humans, same engine.
|
|
195
|
+
5. **SQLite by default** — history works out of the box.
|
package/BACKLOG.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Backlog
|
|
2
|
+
|
|
3
|
+
## High Priority
|
|
4
|
+
|
|
5
|
+
### CI/CD Improvements
|
|
6
|
+
- **`--fail-on-coverage` flag** — fail CI if coverage below threshold: `apitool run --fail-on-coverage 80`
|
|
7
|
+
- **`--env-var` flag** — pass secrets from CI without env files: `apitool run --env-var "token=$API_TOKEN"`
|
|
8
|
+
- **GitHub Action** — `uses: kirrosh/apitool-action@v1` composite action (separate repo)
|
|
9
|
+
|
|
10
|
+
### One-shot test generation (`generate_and_save`)
|
|
11
|
+
New MCP tool that accepts spec path + optional endpoint filter and produces ready-to-save YAML test suites in one call. Eliminates the 3-step chain: `generate_tests_guide` → agent assembles YAML → `save_test_suite`.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Medium Priority
|
|
16
|
+
|
|
17
|
+
### Batch `save_test_suite`
|
|
18
|
+
Accept an array of `{filePath, content}` pairs in a single call. Reduces token usage and round-trips for bulk generation.
|
|
19
|
+
|
|
20
|
+
### Split format guide from endpoint data
|
|
21
|
+
`generate_tests_guide` returns the full YAML format reference every call. Split into static format + dynamic endpoints, or cache format after first call.
|
|
22
|
+
|
|
23
|
+
### `apitool compare` command
|
|
24
|
+
Compare two test runs — regression detection in CI.
|
|
25
|
+
|
|
26
|
+
### Timestamp capture pattern
|
|
27
|
+
When a `timestamp` field is detected in a request body schema (common in OAuth, AWS Sig, Ably tokens), add a hint in the guide: "consider GET /time before this step to capture the server timestamp".
|
|
28
|
+
|
|
29
|
+
### Per-suite env resolution
|
|
30
|
+
When running `apitool run apis/` (directory with subdirs), resolve `.env.<name>.yaml` from each suite's directory, not from `dirname(path)`.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Low Priority
|
|
35
|
+
|
|
36
|
+
### Summary after batch generation
|
|
37
|
+
After generating many suites, return a summary (created N files, total coverage %).
|
|
38
|
+
|
|
39
|
+
### Env file location in MCP output
|
|
40
|
+
`setup_api` should return the path to `.env.default.yaml` and a brief instruction for adding the API key in its response, so the agent knows exactly where to write credentials immediately after registration.
|
|
41
|
+
|
|
42
|
+
### Comment preservation
|
|
43
|
+
Parser preserves YAML comments when reading/writing (currently lost).
|
|
44
|
+
|
|
45
|
+
### `apitool docs` command
|
|
46
|
+
Generate markdown documentation from YAML tests: descriptions + examples.
|
|
47
|
+
|
|
48
|
+
### Multipart/form-data support
|
|
49
|
+
Runner support for file upload endpoints.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Not Doing
|
|
54
|
+
|
|
55
|
+
| Item | Reason |
|
|
56
|
+
|------|--------|
|
|
57
|
+
| GraphQL / gRPC / WebSocket | REST + OpenAPI = 80% of market |
|
|
58
|
+
| Load testing | Use k6 instead |
|
|
59
|
+
| WebUI polish (themes, animations) | Not a selling point |
|
|
60
|
+
| Plugins / marketplace | Requires large team |
|
|
61
|
+
| Team features / RBAC | Different product category |
|
|
62
|
+
| Docker image | Single binary is simpler |
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **MCP feedback improvements**
|
|
10
|
+
- `diagnose_failure` now includes `response_headers` in failure output (e.g. `X-Ably-ErrorMessage`)
|
|
11
|
+
- `generate_tests_guide`: annotates `any`-typed request bodies with a warning comment
|
|
12
|
+
- `generate_tests_guide`: added 204 No Content tips in Practical Tips and Common Mistakes sections
|
|
13
|
+
- `schema-utils.ts`: added `isAnySchema()` helper
|
|
14
|
+
- DB schema v6: `results.response_headers TEXT` column
|
|
15
|
+
|
|
16
|
+
- **M22: MCP-first smart test generation**
|
|
17
|
+
- `generate_tests_guide` MCP tool — returns full API spec with schemas + step-by-step generation algorithm
|
|
18
|
+
- `save_test_suite` MCP tool — validates YAML and saves test files with structured error reporting
|
|
19
|
+
- `explore_api` enhanced — new `includeSchemas` parameter for full request/response body schemas
|
|
20
|
+
- `schema-utils.ts` — extracted `compressSchema()` and `formatParam()` as shared utilities
|
|
21
|
+
- Improved MCP tool descriptions with "when to use" guidance
|
|
22
|
+
|
|
23
|
+
### Removed
|
|
24
|
+
|
|
25
|
+
- `list_environments` MCP tool — duplicated by `manage_environment(action: "list")`
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## [0.3.0] - Unreleased (post-M21)
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- **Environment management in WebUI** — full CRUD for environments (`/environments`)
|
|
34
|
+
- **Key-value editor** — add/remove variables with inline JavaScript
|
|
35
|
+
- **Environment selector** — `<select name="env">` dropdown in collection "Run Tests" form
|
|
36
|
+
- **DB queries** — `getEnvironmentById()`, `deleteEnvironment()`, `listEnvironmentRecords()`
|
|
37
|
+
- **Navigation** — "Environments" link in navbar
|
|
38
|
+
- **Improved runs filter** — environment dropdown merges defined environments + run history
|
|
39
|
+
- **Self-documented API** — routes use `@hono/zod-openapi`, `GET /api/openapi.json` serves spec
|
|
40
|
+
- **Incremental generation** — `apitool generate` skips already-covered endpoints
|
|
41
|
+
- **Dogfooding** — integration tests run against apitool's own API
|
|
42
|
+
- **Generator: `additionalProperties`** — Record types generate sample key-value pairs instead of `{}`
|
|
43
|
+
- **CI: typecheck** — `tsc --noEmit` step added to CI pipeline
|
|
44
|
+
|
|
45
|
+
### Changed
|
|
46
|
+
|
|
47
|
+
- **Auth-flow test** — rewritten with inline OpenAPI server (no external `test-server/` dependency)
|
|
48
|
+
|
|
49
|
+
### Removed
|
|
50
|
+
|
|
51
|
+
- **`test-server/`** — replaced by inline test servers in integration tests
|
|
52
|
+
- **Duplicate spec files** — `openapi-self.json`, `self-tests-spec.json` removed from project root
|
|
53
|
+
|
|
54
|
+
### Fixed
|
|
55
|
+
|
|
56
|
+
- **Type errors** — `z.coerce.number()` in schemas, `c.body()` return type in export route
|
|
57
|
+
- **Environments CRUD skeleton** — `variables` field now generates test data correctly
|
|
58
|
+
|
|
59
|
+
## [0.1.0] - 2025-02-27
|
|
60
|
+
|
|
61
|
+
Initial public release.
|
|
62
|
+
|
|
63
|
+
### Features
|
|
64
|
+
|
|
65
|
+
- **YAML test definitions** — declarative API tests with steps, assertions, variables, and captures
|
|
66
|
+
- **Test runner** — sequential HTTP execution with variable substitution, chained captures, and configurable timeouts
|
|
67
|
+
- **Assertions** — status code, JSON body (exact, contains, path), headers, response time
|
|
68
|
+
- **Environment files** — `.env.<name>.yaml` for per-environment variables (base URLs, tokens, etc.)
|
|
69
|
+
- **OpenAPI test generator** — generate skeleton YAML tests from OpenAPI 3.x specs (CRUD operations, auth-aware)
|
|
70
|
+
- **AI-powered test generation** — generate tests using LLM providers (Ollama, OpenAI, Anthropic, custom)
|
|
71
|
+
- **Reporters** — console (colored), JSON, JUnit XML output formats
|
|
72
|
+
- **SQLite storage** — persist test runs, results, and collections in `apitool.db`
|
|
73
|
+
- **WebUI dashboard** — Hono + HTMX web interface with:
|
|
74
|
+
- Run history with filters and trend charts
|
|
75
|
+
- Suite detail view with per-step results
|
|
76
|
+
- API Explorer with request builder and authorization panel
|
|
77
|
+
- Collection management with drill-down
|
|
78
|
+
- AI test generation UI
|
|
79
|
+
- Result export (JSON, JUnit)
|
|
80
|
+
- **CLI commands**:
|
|
81
|
+
- `apitool run <path>` — execute tests with env, reporter, timeout, bail options
|
|
82
|
+
- `apitool validate <path>` — validate YAML test files
|
|
83
|
+
- `apitool generate --from <spec>` — generate tests from OpenAPI
|
|
84
|
+
- `apitool ai-generate --from <spec> --prompt "..."` — AI test generation
|
|
85
|
+
- `apitool serve` — start web dashboard
|
|
86
|
+
- `apitool collections` — list test collections
|
|
87
|
+
- **Multi-auth support** — Basic, Bearer, API Key auth in CLI (`--auth-token`) and WebUI
|
|
88
|
+
- **Standalone binary** — single-file executable via `bun build --compile`
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 apitool contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @kirrosh/apitool
|
|
2
|
+
|
|
3
|
+
AI-native API testing tool. OpenAPI spec in, tests out. One binary, zero config.
|
|
4
|
+
|
|
5
|
+
[](https://cursor.com/en/install-mcp?name=apitool&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBraXJyb3NoL2FwaXRvb2wiLCJtY3AiXX0=)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Option 1: via npx (recommended — works everywhere with Node.js)
|
|
11
|
+
npx -y @kirrosh/apitool --version
|
|
12
|
+
|
|
13
|
+
# Option 2: Binary (no Node.js required)
|
|
14
|
+
# macOS / Linux
|
|
15
|
+
curl -fsSL https://raw.githubusercontent.com/kirrosh/apitool/master/install.sh | sh
|
|
16
|
+
|
|
17
|
+
# Windows
|
|
18
|
+
iwr https://raw.githubusercontent.com/kirrosh/apitool/master/install.ps1 | iex
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
[All releases](https://github.com/kirrosh/apitool/releases) (Linux x64, macOS ARM, Windows x64)
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Register API + generate + run — all in one flow via MCP or CLI
|
|
27
|
+
apitool add-api petstore --spec https://petstore.swagger.io/v2/swagger.json
|
|
28
|
+
apitool run apis/petstore/tests/ --env default
|
|
29
|
+
apitool serve # web dashboard at http://localhost:8080
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or let your AI agent do it — just say: *"Test the API from openapi.json"*
|
|
33
|
+
|
|
34
|
+
## MCP Setup (Cursor / Claude Code / Windsurf)
|
|
35
|
+
|
|
36
|
+
Click the badge above, or add manually:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"mcpServers": {
|
|
41
|
+
"apitool": {
|
|
42
|
+
"command": "npx",
|
|
43
|
+
"args": ["-y", "@kirrosh/apitool", "mcp", "--dir", "${workspaceFolder}"]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Where to put this:**
|
|
50
|
+
|
|
51
|
+
| Editor | Config file |
|
|
52
|
+
|--------|-------------|
|
|
53
|
+
| Cursor | Settings > MCP, or `.cursor/mcp.json` in project root |
|
|
54
|
+
| Claude Code | `.mcp.json` in project root |
|
|
55
|
+
| Windsurf | `.windsurfrules/mcp.json` or settings |
|
|
56
|
+
|
|
57
|
+
14 MCP tools: `setup_api`, `generate_tests_guide`, `save_test_suite`, `run_tests`, `query_db`, `explore_api`, `coverage_analysis`, `generate_missing_tests`, `validate_tests`, `send_request`, `manage_environment`, `manage_server`. Full reference in [APITOOL.md](APITOOL.md).
|
|
58
|
+
|
|
59
|
+
## YAML Test Format
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
name: Users CRUD
|
|
63
|
+
description: Full user lifecycle
|
|
64
|
+
tags: [users, crud, smoke]
|
|
65
|
+
base_url: "{{base_url}}"
|
|
66
|
+
|
|
67
|
+
tests:
|
|
68
|
+
- name: Create user
|
|
69
|
+
POST: /users
|
|
70
|
+
json:
|
|
71
|
+
name: "{{$randomName}}"
|
|
72
|
+
email: "{{$randomEmail}}"
|
|
73
|
+
expect:
|
|
74
|
+
status: 201
|
|
75
|
+
body:
|
|
76
|
+
id: { capture: user_id, type: integer }
|
|
77
|
+
|
|
78
|
+
- name: Get user
|
|
79
|
+
GET: /users/{{user_id}}
|
|
80
|
+
expect:
|
|
81
|
+
status: 200
|
|
82
|
+
|
|
83
|
+
- name: Delete user
|
|
84
|
+
DELETE: /users/{{user_id}}
|
|
85
|
+
expect:
|
|
86
|
+
status: 204
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## CLI
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
apitool run <path> Run tests (--env, --safe, --report json|junit)
|
|
93
|
+
apitool add-api <name> Register API (--spec <openapi>)
|
|
94
|
+
apitool serve Web dashboard (--port 8080)
|
|
95
|
+
apitool mcp Start MCP server
|
|
96
|
+
apitool coverage API test coverage (--spec, --tests)
|
|
97
|
+
apitool chat AI chat agent (--provider ollama|openai|anthropic)
|
|
98
|
+
apitool doctor Diagnostics
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Full docs: [APITOOL.md](APITOOL.md)
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
[MIT](LICENSE)
|