Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

- **AI step on by default** (docs/GUIDE.md §5b): `generate` uses a console AI tool when one is found (`API_AI` / `--ai-runner`, else `claude`, else `codex`); none found, a failing tool or `--no-ai` → generated without it.
- new: read-only sources of path values: the AI says which list operation and field hold existing ids (`brandId ← GET /brands #/0/id`); after the spec check (safe list operation, a pointer through a list element, a fitting identifier type) a positive test reads the list and then the record, skipped with the reason when there is no record or the list is refused; marked `ai-proposed` (pytest `ai_proposed`), listed in the report section "AI participation";
- answers cached in the suite (`_support/ai-sources.json`): regeneration, `maintain` (which never calls the AI) and runs without AI reproduce the same tests; a reviewed form in the deps file: `"sources": [...]`;
- unconfirmed write dependencies stay proposals (`ai-deps.proposed.json`); `--ai-max-calls` default 25.
- On Toolshop: 8 sources found (brands, category tree, related / specs of a product, invoices, users): 8 more tests passed, 8 skipped with the reason (no invoices on a fresh account, `GET /users` needs an admin), `MISSING_RESOURCE_SOURCE` 22 → 15.
- **Query parameters and GET collections** (docs/SUPPORT_MATRIX.md):
- confirmed: a decimal case for integer parameters (inside the documented bounds, so only the type is broken); every query case checks that the value really went over HTTP; accepted values also check the response contract; values over the limits are `CASE_LIMIT_REACHED` gaps instead of being dropped silently; Python sends query booleans as `true` / `false`;
- exploratory probes for scalar query parameters of GET / HEAD operations (empty, text, decimal, zero, negative, large, special characters, another spelling of a boolean or enum value, a missing required parameter): deduplicated against confirmed cases and the documented range, never failing on the API's behavior, recorded in the report (`exploratory.jsonl`, "Exploratory query probes");
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ OpenAPI spec ──► lint + catalogue ──► safe probe ──► Schemathe

## Principles

- **Deterministic first, no AI in this version.** Parsing, lint, catalogue, payloads, templates, CI: all rule-based. AI is planned only for ambiguous dependencies, with a token budget.
- **Deterministic first, AI where rules cannot decide.** Parsing, lint, catalogue, payloads, templates, CI: rule-based. When a console AI tool is found, `generate` also asks it where an existing id can be read (read-only tests, marked AI-proposed, cached for reproducibility) and proposes unconfirmed dependencies for review; without a tool it runs exactly as before.
- **The spec is the requirement.** An observed response that differs from the spec is a `CONTRACT_MISMATCH` for a human to decide on. The tool never treats the implementation as the source of truth.
- **Stop with a precise blocker instead of inventing.** No example for a required parameter, a pattern it cannot satisfy, a dependency that is only implied by path names: each becomes `BLOCKED` with the exact question to answer.
- **Never make a test green by editing it.** Generated tests run once; assertions are not touched.
Expand Down Expand Up @@ -49,7 +49,7 @@ npx @testomut/api-test-agent diff --head openapi.yaml # what changed in the sp

**Test language:** TypeScript (Playwright Test) or Python (pytest + requests), chosen in `init` or with `API_TESTS_LANG` / `generate --lang`. Same layout, cases and safety rules in both.

**Optional AI (`--ai`):** runs through a console tool you are logged in to (Claude Code `claude -p`, Codex `codex exec`, or your own orchestrator command): no API keys. It proposes answers for unconfirmed dependencies from a minimal spec excerpt; every answer is schema-validated, checked against the spec and written as a proposal you review, never applied automatically. Without `--ai` the tool is fully deterministic.
**AI step (on by default, `--no-ai` to switch off):** runs through a console tool you are logged in to (Claude Code `claude -p`, Codex `codex exec`, or your own orchestrator command), no API keys; none found → generated without it. From a minimal spec excerpt it finds where existing ids can be read, which unblocks read-only tests of `GET /x/{id}` (marked `ai-proposed`; copy them into the deps file `sources` to keep them reviewed), and proposes unconfirmed dependencies, which are never applied without your review. Every answer is schema-validated and checked against the spec.

**Full guide: [docs/GUIDE.md](docs/GUIDE.md)** (configuration, every check, what each command changes). Legacy projects to try it on: [Playwright](examples/legacy-project), [pytest](examples/legacy-pytest-project).

Expand Down
22 changes: 15 additions & 7 deletions docs/GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,16 @@ Not yet: three-way `registry merge`, `--id-aliases` / `--apply-registry`, `plan`
- Assertions: the statuses from `pm.test`; if the request had none and the operation is in the spec, the documented success status (marked as such in the test). Other `pm.test` lines are copied as comments for review.
- Output in the configured language: `<resource>/<method>/positive.postman.spec.ts` or `test_positive_postman.py`.

## 5b. Optional AI (`--ai`), through console tools
## 5b. AI step (on by default), through console tools

Everything above is deterministic. `--ai` adds an AI step in **one** place where rules cannot decide: **unconfirmed dependencies** (`POST /x` + `/x/{param}` with no OpenAPI `links` and no deps file, normally BLOCKED with a question).
`generate` asks an AI where rules cannot decide, **when a console tool is found** (`API_AI` / `--ai-runner`, else `claude`, else `codex` on PATH). No tool, or not logged in: the run says so and goes on without AI, exactly as before. `--no-ai` switches it off.

1. **Read-only sources of path values (used right away, marked AI-proposed).** A safe operation such as `GET /brands/{brandId}` is normally blocked (`MISSING_RESOURCE_SOURCE`): no real id to call it with. The AI picks the list operation and field that hold existing ids (`brandId ← GET /brands #/0/id`). After the spec check (below) the test reads the list, takes an existing value and reads that record; no record, or the list refused (e.g. another role needed) → skipped with the reason. These tests only read, carry the `ai-proposed` annotation (pytest marker `ai_proposed`) and are listed in the report section "AI participation". To make one reviewed, copy it into the deps file:
```json
"sources": [{ "operationId": "getBrand", "param": "brandId", "from": "getBrands", "pointer": "/0/id" }]
```
The answers are cached in the suite (`_support/ai-sources.json`, in the generation manifest): a regeneration, `maintain` and a run without AI reuse them, so the suite stays reproducible.
2. **Unconfirmed dependencies (proposals, never applied).** `POST /x` + `/x/{param}` with no OpenAPI `links` and no deps file: these would create and delete data, so the answer is only a proposal (`ai-deps.proposed.json`) until you pass it with `--deps`.

The AI runs through a **console tool you are already logged in to**: no API keys, usage counts against your subscription.

Expand All @@ -222,11 +229,12 @@ npx @testomut/api-test-agent generate --deps reports/api-agent/generate/ai-deps.

**Contract for `command` (orchestrators):** the request is written to stdin as JSON `{"system": "...", "prompt": "...", "schema": {JSON Schema}}`; the tool prints the answer object (matching the schema) as JSON on stdout and exits 0. The tool runs in an empty temporary folder.

- **Opt-in only.** Without `--ai` no tool is called.
- **Minimal context.** For each candidate: operation keys and ids, the create response's property names and types, the path parameter's type. Never example values, request data, test results or `.env` contents.
- **Validated twice.** The answer must match the JSON Schema (checked here, not only by the tool), then the spec: the identifier pointer must exist in the create response and its type/format must match the path parameter; low confidence is rejected.
- **On by default, never required.** No tool found, a tool that fails, or `--no-ai`: generated without AI; `maintain` never calls the AI (cached answers and reviewed sources only).
- **Minimal context.** Operation keys, ids and summaries, response field names and types, the path parameter's type. Never example values, request data, test results or `.env` contents.
- **Validated twice.** The answer must match the JSON Schema (checked here, not only by the tool), then the spec. A source: a safe list operation of the spec callable as is, a pointer through a list element of its response, a field type that fits the parameter (an integer id may fill a string parameter, a decimal never). A dependency: the identifier pointer must exist in the create response and its type/format must match. Low confidence is rejected.
- **Writes only after review.** AI answers never create or delete data: sources only read, dependencies stay proposals.
- **Proposals, never applied.** Accepted answers go to `ai-deps.proposed.json` (deps-file format); every answer with its reason to `ai-proposals.json`. Tests use them only after you pass the file with `--deps`, and running the tests then confirms the link against the real API.
- **Budget:** `--ai-max-calls` (default 10). The run ends with answers, failures, time and, for `claude`, the cost Claude Code reports (only billed per call when you use an API key instead of a subscription).
- **Budget:** `--ai-max-calls` (default 25). The run ends with answers, failures, time and, for `claude`, the cost Claude Code reports (only billed per call when you use an API key instead of a subscription).
- **Tool missing or not logged in:** the AI step is skipped with a message; the rest of the run is unaffected.

## 6. Checks catalogue
Expand Down Expand Up @@ -368,7 +376,7 @@ Python folders use underscores and contain `__init__.py`, so `test_functional.py

**Postman cloud or file?** Both. A path ending in `.json` is read from disk; anything else is treated as a cloud collection id and needs `POSTMAN_API_KEY`.

**Does it use AI?** Only with `--ai`, through a console tool you are logged in to (Claude Code, Codex, or your own orchestrator), and only to propose answers for unconfirmed dependencies, which you review (§5b). No API keys. Everything else (spec analysis, cases, payloads, test analysis, generation) is rule-based and reproducible.
**Does it use AI?** By default `generate` does, when a console tool you are logged in to is found (Claude Code, Codex, or your own orchestrator), and only where rules cannot decide (§5b): read-only sources of path values (used, marked AI-proposed, cached for reproducibility) and unconfirmed dependencies (proposals you review). No API keys. Without a tool, or with `--no-ai`, everything is rule-based.

**Which languages can tests be generated in?** TypeScript (Playwright Test) and Python (pytest + requests), chosen in `init` or with `API_TESTS_LANG` / `--lang`. The analysis, cases and safety rules are shared; only the output templates differ, so more languages can be added.

Expand Down
8 changes: 8 additions & 0 deletions docs/SUPPORT_MATRIX.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ Inputs a real client sends by mistake, for scalar query parameters of GET / HEAD

Write operations are never probed (`UNSAFE_LIVE_CHECK`); an operation with an unknown path value is not probed (`MISSING_RESOURCE_SOURCE`); more than 24 probes per operation → `CASE_LIMIT_REACHED`.

### Path values from existing data (`src/ai/sources.ts`)

| Source | State | How / limits |
|---|---|---|
| deps `sources` (reviewed) | ✅ | `{ operationId, param, from, pointer }`, checked against the spec; a mismatch → `INVALID_REVIEWED_CONFIG` |
| AI step (on by default) | ✅ | for safe operations blocked by one unknown path value; spec check: a safe list operation callable as is, a pointer through a list element, a fitting identifier type; low confidence rejected; tests only read, marked `ai-proposed`; answers cached in `_support/ai-sources.json` |
| no record / the list refused | ✅ | the test is skipped with the reason, never failed |

## Functional (`functional.spec.ts`)

| Check | State | Limits | Stage |
Expand Down
Loading
Loading