codapact 0.4.0__tar.gz → 0.5.1__tar.gz
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.
- {codapact-0.4.0 → codapact-0.5.1}/.github/workflows/mutation.yml +16 -3
- codapact-0.5.1/.release-please-manifest.json +1 -0
- {codapact-0.4.0 → codapact-0.5.1}/CHANGELOG.md +19 -0
- {codapact-0.4.0 → codapact-0.5.1}/PKG-INFO +3 -1
- {codapact-0.4.0 → codapact-0.5.1}/docs/configuration.md +3 -1
- {codapact-0.4.0 → codapact-0.5.1}/docs/testing.md +1 -1
- {codapact-0.4.0 → codapact-0.5.1}/pyproject.toml +4 -1
- {codapact-0.4.0 → codapact-0.5.1}/pyproject.toml.orig +5 -1
- {codapact-0.4.0 → codapact-0.5.1}/scripts/mutation_score.py +25 -7
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/__init__.py +1 -1
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/core/errors.py +9 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/core/net.py +2 -2
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/__init__.py +2 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/cli.py +75 -4
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/cli_tools.py +4 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/client.py +10 -1
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/errors.py +2 -1
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/selftest.py +3 -1
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/targets/python/e2e.py +10 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/targets/python/library.py +17 -3
- {codapact-0.4.0 → codapact-0.5.1}/tests/integration/test_generation.py +1 -1
- {codapact-0.4.0 → codapact-0.5.1}/tests/integration/test_ynab_contract.py +2 -1
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_bundle_e2e.py +33 -0
- codapact-0.5.1/tests/unit/test_cli_auth.py +331 -0
- codapact-0.5.1/tests/unit/test_cli_options.py +316 -0
- codapact-0.5.1/tests/unit/test_live_ynab_findings.py +157 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_mutation_score.py +22 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_public_api_findings.py +2 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_target_rendering.py +21 -7
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_usability.py +13 -0
- {codapact-0.4.0 → codapact-0.5.1}/uv.lock +26 -1
- codapact-0.4.0/.release-please-manifest.json +0 -1
- {codapact-0.4.0 → codapact-0.5.1}/.github/workflows/ci.yml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/.github/workflows/codeql.yml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/.github/workflows/nightly.yml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/.github/workflows/release.yml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/LICENSE +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/README.md +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/docs/architecture.md +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/docs/branding/README.md +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/docs/branding/mark.svg +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/docs/branding/wordmark.svg +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/examples/library/codapact.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/examples/library/operations.graphql +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/examples/library/schema.graphql +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/examples/petstore/codapact.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/examples/petstore/openapi.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/release-please-config.json +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/scripts/extract_openapi_subset.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/scripts/verify_dist.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/__main__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/commands/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/commands/derive.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/commands/model.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/core/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/core/diagnostics.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/core/naming.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/model/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/model/api.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/model/authspec.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/model/migrations.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/model/rewrite.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/model/serialize.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/model/types.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/model/validate.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/model/values.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/pipeline/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/pipeline/cli.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/pipeline/config.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/pipeline/defaults.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/pipeline/pipeline.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/pipeline/writer.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/plugins/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/plugins/external.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/plugins/protocol.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/plugins/registry.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/py.typed +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/abstractions.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/arguments.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/auth.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/cli_auth.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/codec.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/credentials.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/middleware.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/oauth.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/protocols/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/protocols/base.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/protocols/graphql.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/runtime/protocols/http.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/shaping/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/shaping/base.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/shaping/engine.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/shaping/transforms.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/sources/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/sources/base.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/sources/graphql/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/sources/graphql/translator.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/sources/loader.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/sources/openapi/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/sources/openapi/translator.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/surface/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/surface/derive.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/surface/model.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/targets/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/targets/python/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/targets/python/cli.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/targets/python/naming.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/targets/typescript/__init__.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/targets/typescript/library.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/src/codapact/targets/typescript/runtime.ts +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/authlab.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/conftest.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/e2e/test_auth_e2e.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/e2e/test_cli_e2e.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/e2e/test_public_apis.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/authlab/authlab_plugin.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/authlab/codapact.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/authlab/fake_browser.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/authlab/openapi.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/authlab_smoke.ts +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/contracts/wire.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/README.md +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/countries/codapact.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/countries/operations.graphql +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/countries/schema.graphql +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/github/codapact.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/github/openapi.json +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/pokeapi/codapact.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/pokeapi/openapi.yml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/ynab/README.md +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/ynab/codapact.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/corpus/ynab/openapi.yaml +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/library_smoke.ts +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/outline_plugin.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/petstore_smoke.ts +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/fixtures/wire_parity.ts +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/integration/test_cli_conformance.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/integration/test_cli_conventions.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/integration/test_contract_properties.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/integration/test_corpus.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/integration/test_generated_code_properties.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/integration/test_public_api_cli.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/integration/test_wire_parity.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/perf/test_scaling.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/public_api_contract.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/strategies.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/support.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_architecture.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_auth_and_graphql_sources.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_auth_sources.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_cli_builtins.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_codec_serialize.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_core.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_guards.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_model.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_oauth.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_openapi_edges.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_openapi_translator_units.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_plugins_pipeline.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_runtime.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_runtime_edges.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_runtime_pagination.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_shaping_surface_commands.py +0 -0
- {codapact-0.4.0 → codapact-0.5.1}/tests/unit/test_sources.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
name: Mutation
|
|
2
2
|
# Mutation testing measures whether the tests notice behavior changes. It is slow
|
|
3
|
-
# (~
|
|
3
|
+
# (~18k mutants), so it runs in parallel shards after merges to main, weekly, and on
|
|
4
4
|
# demand; it never gates a PR. Each shard must finish and meet the score floor.
|
|
5
5
|
on:
|
|
6
6
|
push:
|
|
@@ -25,7 +25,19 @@ jobs:
|
|
|
25
25
|
- {name: openapi, patterns: 'codapact.sources.openapi.*'}
|
|
26
26
|
- {name: sources, patterns: 'codapact.sources.graphql.* codapact.sources.loader.* codapact.sources.base.*'}
|
|
27
27
|
- {name: targets, patterns: 'codapact.targets.*'}
|
|
28
|
-
|
|
28
|
+
# runtime is split seven ways: as one shard it outgrew the 65-minute cap, and
|
|
29
|
+
# the CLI modules (~3.8k slow mutants) did too, cli.py alone included. cli.py is
|
|
30
|
+
# split by mutant name: module functions and small classes, CliRuntime's private
|
|
31
|
+
# methods, and its public ones.
|
|
32
|
+
# A new codapact.runtime module, or a cli.py class starting with C, must be added
|
|
33
|
+
# to one of these patterns.
|
|
34
|
+
- {name: runtime-cli, patterns: 'codapact.runtime.cli.x_* codapact.runtime.cli.xǁ[!C]* codapact.runtime.cli.xǁCliParserǁ*'}
|
|
35
|
+
- {name: runtime-cli-run, patterns: 'codapact.runtime.cli.xǁCliRuntimeǁ_*'}
|
|
36
|
+
- {name: runtime-cli-runtime, patterns: 'codapact.runtime.cli.xǁCliRuntimeǁ[!_]*'}
|
|
37
|
+
- {name: runtime-cli-auth, patterns: 'codapact.runtime.cli_auth.*'}
|
|
38
|
+
- {name: runtime-cli-tools, patterns: 'codapact.runtime.cli_tools.*'}
|
|
39
|
+
- {name: runtime-auth, patterns: 'codapact.runtime.oauth.* codapact.runtime.auth.* codapact.runtime.credentials.*'}
|
|
40
|
+
- {name: runtime-core, patterns: 'codapact.runtime.arguments.* codapact.runtime.middleware.* codapact.runtime.errors.* codapact.runtime.abstractions.* codapact.runtime.protocols.* codapact.runtime.client.* codapact.runtime.codec.* codapact.runtime.selftest.*'}
|
|
29
41
|
- {name: pipeline, patterns: 'codapact.pipeline.* codapact.plugins.* codapact.commands.*'}
|
|
30
42
|
- {name: model, patterns: 'codapact.model.* codapact.shaping.* codapact.surface.* codapact.core.*'}
|
|
31
43
|
env:
|
|
@@ -55,8 +67,9 @@ jobs:
|
|
|
55
67
|
PATTERNS: ${{ matrix.shard.patterns }}
|
|
56
68
|
run: |
|
|
57
69
|
test "$run_exit" = 0 || { echo "mutmut did not finish (exit $run_exit)"; exit 1; }
|
|
70
|
+
read -ra patterns <<< "$PATTERNS"
|
|
58
71
|
args=()
|
|
59
|
-
for pattern in $
|
|
72
|
+
for pattern in "${patterns[@]}"; do args+=(--pattern "$pattern"); done
|
|
60
73
|
uv run python scripts/mutation_score.py --results mutation-report/results.txt "${args[@]}"
|
|
61
74
|
- if: always()
|
|
62
75
|
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{".":"0.5.1"}
|
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- markdownlint-configure-file { "MD024": { "siblings_only": true } } -->
|
|
4
4
|
|
|
5
|
+
## [0.5.1](https://github.com/mikejhill/codapact/compare/v0.5.0...v0.5.1) (2026-11-14)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **cli:** configurable response limit, UTF-8 pipes, jsonl records ([#37](https://github.com/mikejhill/codapact/issues/37)) ([f8a3b72](https://github.com/mikejhill/codapact/commit/f8a3b72ac2d95f2d873cfa65db2104a4750b029a))
|
|
11
|
+
|
|
12
|
+
## [0.5.0](https://github.com/mikejhill/codapact/compare/v0.4.0...v0.5.0) (2026-11-12)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **cli:** pick unwraps envelopes; keyring for generated CLIs ([#32](https://github.com/mikejhill/codapact/issues/32)) ([f1c5104](https://github.com/mikejhill/codapact/commit/f1c51040a9bd5c21aa3e634955f2b5c0b7a4a6a1))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **e2e:** fill a required body whose fields are all optional in dry-run cases ([#31](https://github.com/mikejhill/codapact/issues/31)) ([c9a4ebb](https://github.com/mikejhill/codapact/commit/c9a4ebbad4338443689c0bf732c4b1e4cb266826))
|
|
23
|
+
|
|
5
24
|
## [0.4.0](https://github.com/mikejhill/codapact/compare/v0.3.0...v0.4.0) (2026-11-12)
|
|
6
25
|
|
|
7
26
|
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codapact
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: Contracts into callable tools: generate libraries, then CLIs, from OpenAPI, GraphQL, and other API contracts.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
7
7
|
Requires-Dist: pyyaml>=6.0.3,<7
|
|
8
8
|
Requires-Dist: graphql-core>=3.2.6,<4
|
|
9
|
+
Requires-Dist: keyring>=25,<26 ; extra == 'keyring'
|
|
9
10
|
Requires-Python: >=3.13
|
|
10
11
|
Project-URL: Homepage, https://github.com/mikejhill/codapact
|
|
11
12
|
Project-URL: Documentation, https://github.com/mikejhill/codapact#readme
|
|
12
13
|
Project-URL: Changelog, https://github.com/mikejhill/codapact/blob/main/CHANGELOG.md
|
|
13
14
|
Project-URL: Issues, https://github.com/mikejhill/codapact/issues
|
|
15
|
+
Provides-Extra: keyring
|
|
14
16
|
Description-Content-Type: text/markdown
|
|
15
17
|
|
|
16
18
|
---
|
|
@@ -104,6 +104,7 @@ Precedence: flag, then environment, then settings file.
|
|
|
104
104
|
| Timeout | `--timeout` | `<PREFIX>_TIMEOUT` | `timeout` |
|
|
105
105
|
| Private network | `--allow-private` | `<PREFIX>_ALLOW_PRIVATE` | `allow_private` |
|
|
106
106
|
| Response validation | `--response-validation strict\|warn\|off` | `<PREFIX>_RESPONSE_VALIDATION` | `response_validation` |
|
|
107
|
+
| Response size limit | none | `<PREFIX>_MAX_RESPONSE_BYTES` | `max_response_bytes` (default 100 MB) |
|
|
107
108
|
| Output format | `-o`/`--output json\|jsonl\|yaml\|table\|raw` | `<PREFIX>_OUTPUT` | `output` |
|
|
108
109
|
| Error format | `--error-format text\|json` | `<PREFIX>_ERROR_FORMAT` | `error_format` |
|
|
109
110
|
| Credentials | none | `<PREFIX>_<SCHEME>`; basic uses `_USERNAME`/`_PASSWORD`; full chain under [Authentication](#authentication) | `auth_plugin`; secrets are never read from the file |
|
|
@@ -119,7 +120,8 @@ result is the item list, so `[].name`), `--dry-run`, `-v/--verbose`, `--error-fo
|
|
|
119
120
|
`--allow-private`, and `--response-validation`. Command help lists them in one line;
|
|
120
121
|
`<program> --help` describes each.
|
|
121
122
|
`table` renders a list of objects, unwrapping single-list envelopes such as `{"data": {"items": [...]}}`.
|
|
122
|
-
`jsonl` prints one JSON value per line
|
|
123
|
+
`jsonl` prints one JSON value per line, unwrapping the same envelopes as `table`, and streams
|
|
124
|
+
`--all` results page by page. Output to a pipe or file is UTF-8 on every platform.
|
|
123
125
|
|
|
124
126
|
### Conventions every generated CLI follows
|
|
125
127
|
|
|
@@ -28,7 +28,7 @@ make sure they keep running.
|
|
|
28
28
|
| Auth | `e2e/test_auth_e2e.py` | Generated CLIs, bundle suites, and TypeScript clients authenticate against AuthLab (`tests/authlab.py`), a loopback server that answers 401 unless the scheme is satisfied: API keys (header, query, cookie), basic, bearer, OAuth 2.0 client credentials, device code, authorization code + PKCE, refresh, and an HMAC-signing plugin | every PR |
|
|
29
29
|
| Live | marker `live`, `CODAPACT_LIVE=1` | PokeAPI and Countries GraphQL respond as the generated CLI expects; the GitHub corpus bundle runs its own live suite with `GITHUB_TOKEN` (authenticated quota, invalid token rejected) | nightly |
|
|
30
30
|
| Performance | `tests/perf`, `perf` | Translation, generation, and decoding scale linearly; throughput floors | every PR |
|
|
31
|
-
| Mutation | `mutmut`,
|
|
31
|
+
| Mutation | `mutmut`, 12 parallel shards | Tests notice behavior changes in `src/codapact` | after merge to main, weekly |
|
|
32
32
|
|
|
33
33
|
Suite markers come from the directory (`tests/conftest.py`); a new file needs no marker.
|
|
34
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "codapact"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.1"
|
|
4
4
|
description = "Contracts into callable tools: generate libraries, then CLIs, from OpenAPI, GraphQL, and other API contracts."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -11,6 +11,9 @@ dependencies = [
|
|
|
11
11
|
"graphql-core>=3.2.6,<4",
|
|
12
12
|
]
|
|
13
13
|
|
|
14
|
+
[project.optional-dependencies]
|
|
15
|
+
keyring = ["keyring>=25,<26"]
|
|
16
|
+
|
|
14
17
|
[project.scripts]
|
|
15
18
|
codapact = "codapact.pipeline.cli:main"
|
|
16
19
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "codapact"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.1"
|
|
4
4
|
description = "Contracts into callable tools: generate libraries, then CLIs, from OpenAPI, GraphQL, and other API contracts."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -8,6 +8,10 @@ license-files = ["LICENSE"]
|
|
|
8
8
|
requires-python = ">=3.13"
|
|
9
9
|
dependencies = ["PyYAML>=6.0.3,<7", "graphql-core>=3.2.6,<4"]
|
|
10
10
|
|
|
11
|
+
[project.optional-dependencies]
|
|
12
|
+
# Generated CLIs depend on this extra so `auth login` saves to the OS keyring.
|
|
13
|
+
keyring = ["keyring>=25,<26"]
|
|
14
|
+
|
|
11
15
|
[project.scripts]
|
|
12
16
|
codapact = "codapact.pipeline.cli:main"
|
|
13
17
|
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
Usage::
|
|
4
4
|
|
|
5
5
|
mutmut results --all true > results.txt
|
|
6
|
-
python scripts/mutation_score.py --results results.txt [--
|
|
6
|
+
python scripts/mutation_score.py --results results.txt [--pattern 'codapact.runtime.*']
|
|
7
7
|
|
|
8
8
|
The score is killed / (killed + survived + timeout + suspicious + no tests). Within
|
|
9
|
-
``--
|
|
9
|
+
``--pattern`` (one CI shard, matched like ``mutmut run`` arguments) or ``--prefix``,
|
|
10
|
+
mutants left unchecked make the result incomplete,
|
|
10
11
|
which fails too: a run that did not finish is not evidence of a good suite. Writes
|
|
11
12
|
a Markdown summary to ``$GITHUB_STEP_SUMMARY`` when set.
|
|
12
13
|
"""
|
|
@@ -14,6 +15,7 @@ a Markdown summary to ``$GITHUB_STEP_SUMMARY`` when set.
|
|
|
14
15
|
from __future__ import annotations
|
|
15
16
|
|
|
16
17
|
import argparse
|
|
18
|
+
import fnmatch
|
|
17
19
|
import os
|
|
18
20
|
import sys
|
|
19
21
|
from pathlib import Path
|
|
@@ -21,12 +23,20 @@ from pathlib import Path
|
|
|
21
23
|
DEFAULT_FLOOR = 80.0
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
def count(
|
|
25
|
-
|
|
26
|
+
def count(
|
|
27
|
+
results: str, prefix: str | tuple[str, ...] = "", patterns: tuple[str, ...] = ()
|
|
28
|
+
) -> dict[str, int]:
|
|
29
|
+
"""Tally ``mutmut results --all true`` lines (``name: status``) under ``prefix``.
|
|
30
|
+
|
|
31
|
+
``patterns``, when given, also keeps only names matching one of them (fnmatch,
|
|
32
|
+
as ``mutmut run`` selects mutants).
|
|
33
|
+
"""
|
|
26
34
|
stats: dict[str, int] = {}
|
|
27
35
|
for line in results.splitlines():
|
|
28
36
|
name, sep, status = line.strip().rpartition(": ")
|
|
29
|
-
if sep and name.startswith(prefix):
|
|
37
|
+
if not (sep and name.startswith(prefix)):
|
|
38
|
+
continue
|
|
39
|
+
if not patterns or any(fnmatch.fnmatch(name, pattern) for pattern in patterns):
|
|
30
40
|
key = status.strip().replace(" ", "_")
|
|
31
41
|
stats[key] = stats.get(key, 0) + 1
|
|
32
42
|
return stats
|
|
@@ -63,12 +73,20 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
63
73
|
parser.add_argument(
|
|
64
74
|
"--prefix", action="append", default=[], help="only mutants under this name (repeatable)"
|
|
65
75
|
)
|
|
76
|
+
parser.add_argument(
|
|
77
|
+
"--pattern",
|
|
78
|
+
action="append",
|
|
79
|
+
default=[],
|
|
80
|
+
help="only mutants matching this mutmut name pattern (repeatable)",
|
|
81
|
+
)
|
|
66
82
|
parser.add_argument(
|
|
67
83
|
"--floor", type=float, default=float(os.environ.get("MUTATION_FLOOR", DEFAULT_FLOOR))
|
|
68
84
|
)
|
|
69
85
|
args = parser.parse_args(argv)
|
|
70
86
|
try:
|
|
71
|
-
stats = count(
|
|
87
|
+
stats = count(
|
|
88
|
+
args.results.read_text("utf-8"), tuple(args.prefix) or "", tuple(args.pattern)
|
|
89
|
+
)
|
|
72
90
|
except OSError as error:
|
|
73
91
|
print(f"cannot read mutation results: {error}", file=sys.stderr)
|
|
74
92
|
return 1
|
|
@@ -77,7 +95,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
77
95
|
target = os.environ.get("GITHUB_STEP_SUMMARY")
|
|
78
96
|
if target:
|
|
79
97
|
with Path(target).open("a", encoding="utf-8") as handle:
|
|
80
|
-
title = f"Mutation score: {', '.join(args.prefix) or 'codapact'}"
|
|
98
|
+
title = f"Mutation score: {', '.join(args.pattern + args.prefix) or 'codapact'}"
|
|
81
99
|
handle.write(f"## {title}\n\n{summary}\n")
|
|
82
100
|
return 0 if passed else 1
|
|
83
101
|
|
|
@@ -41,6 +41,15 @@ class TransportError(CodapactError):
|
|
|
41
41
|
"""A request could not be sent or the response was rejected before decoding."""
|
|
42
42
|
|
|
43
43
|
|
|
44
|
+
class ResponseTooLargeError(TransportError):
|
|
45
|
+
"""The response body is larger than the client's ``max_bytes`` limit."""
|
|
46
|
+
|
|
47
|
+
def __init__(self, limit: int) -> None:
|
|
48
|
+
"""Record the limit that was exceeded."""
|
|
49
|
+
super().__init__(f"response exceeds {limit} bytes")
|
|
50
|
+
self.limit = limit
|
|
51
|
+
|
|
52
|
+
|
|
44
53
|
def expect[T](value: T | None, what: str) -> T:
|
|
45
54
|
"""Return ``value`` or raise when an internal invariant is broken."""
|
|
46
55
|
if value is None:
|
|
@@ -22,7 +22,7 @@ import urllib.request
|
|
|
22
22
|
from dataclasses import dataclass, field
|
|
23
23
|
from urllib.parse import SplitResult, urlsplit
|
|
24
24
|
|
|
25
|
-
from codapact.core.errors import ConfigError, TransportError
|
|
25
|
+
from codapact.core.errors import ConfigError, ResponseTooLargeError, TransportError
|
|
26
26
|
|
|
27
27
|
DEFAULT_MAX_BYTES = 10_000_000
|
|
28
28
|
|
|
@@ -153,7 +153,7 @@ class SafeHttpClient:
|
|
|
153
153
|
finally:
|
|
154
154
|
connection.close()
|
|
155
155
|
if len(body) > self.max_bytes:
|
|
156
|
-
raise
|
|
156
|
+
raise ResponseTooLargeError(self.max_bytes)
|
|
157
157
|
if 300 <= response.status < 400:
|
|
158
158
|
raise TransportError("redirects are not followed")
|
|
159
159
|
return HttpResponse(response.status, dict(response.getheaders()), body)
|
|
@@ -28,6 +28,7 @@ from codapact.runtime.errors import (
|
|
|
28
28
|
AuthError,
|
|
29
29
|
ClientError,
|
|
30
30
|
GraphQLResponseError,
|
|
31
|
+
ResponseTooLargeError,
|
|
31
32
|
TransportError,
|
|
32
33
|
ValidationError,
|
|
33
34
|
)
|
|
@@ -64,6 +65,7 @@ __all__ = [
|
|
|
64
65
|
"HttpRequest",
|
|
65
66
|
"HttpResponse",
|
|
66
67
|
"Middleware",
|
|
68
|
+
"ResponseTooLargeError",
|
|
67
69
|
"Retry",
|
|
68
70
|
"RuntimeClient",
|
|
69
71
|
"StaticAuth",
|
|
@@ -26,12 +26,13 @@ from urllib.parse import quote, quote_plus
|
|
|
26
26
|
import yaml
|
|
27
27
|
|
|
28
28
|
from codapact import __version__
|
|
29
|
-
from codapact.core.errors import CodapactError, TransportError
|
|
29
|
+
from codapact.core.errors import CodapactError, ResponseTooLargeError, TransportError
|
|
30
30
|
from codapact.core.net import HttpRequest, HttpResponse, SafeHttpClient
|
|
31
31
|
from codapact.model.api import Api, AuthKind, AuthScheme
|
|
32
32
|
from codapact.runtime import cli_auth, cli_tools
|
|
33
33
|
from codapact.runtime.abstractions import CallContext, Credential, Next, Secret
|
|
34
34
|
from codapact.runtime.auth import ChainAuth, EnvAuth, FunctionAuthenticator
|
|
35
|
+
from codapact.runtime.client import DEFAULT_MAX_RESPONSE_BYTES
|
|
35
36
|
from codapact.runtime.credentials import cli_auth as build_cli_auth
|
|
36
37
|
from codapact.runtime.errors import (
|
|
37
38
|
ApiError,
|
|
@@ -69,6 +70,7 @@ SETTINGS_KEYS = frozenset(
|
|
|
69
70
|
"base_url",
|
|
70
71
|
"timeout",
|
|
71
72
|
"allow_private",
|
|
73
|
+
"max_response_bytes",
|
|
72
74
|
"response_validation",
|
|
73
75
|
"output",
|
|
74
76
|
"error_format",
|
|
@@ -101,6 +103,32 @@ def json_value(text: str) -> Any:
|
|
|
101
103
|
raise argparse.ArgumentTypeError("expected JSON or @file") from None
|
|
102
104
|
|
|
103
105
|
|
|
106
|
+
def _utf8(stream: TextIO) -> TextIO:
|
|
107
|
+
"""Write UTF-8 to pipes and files, whatever the locale (cp1252 on Windows).
|
|
108
|
+
|
|
109
|
+
Consoles keep their own encoding; JSON output with non-ASCII text must not depend
|
|
110
|
+
on the code page of whoever redirects it.
|
|
111
|
+
"""
|
|
112
|
+
encoding = (getattr(stream, "encoding", None) or "").lower().replace("-", "")
|
|
113
|
+
reconfigure = getattr(stream, "reconfigure", None)
|
|
114
|
+
if encoding != "utf8" and reconfigure is not None and not stream.isatty():
|
|
115
|
+
reconfigure(encoding="utf-8", errors="backslashreplace")
|
|
116
|
+
return stream
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _positive_int(value: Any, name: str) -> int:
|
|
120
|
+
"""Parse a byte limit from a flag, environment variable, or settings file."""
|
|
121
|
+
if value is None or value == "":
|
|
122
|
+
return DEFAULT_MAX_RESPONSE_BYTES
|
|
123
|
+
try:
|
|
124
|
+
number = int(value)
|
|
125
|
+
except (TypeError, ValueError):
|
|
126
|
+
raise CodapactError(f"{name} must be a whole number of bytes, not {value!r}") from None
|
|
127
|
+
if number <= 0 or isinstance(value, bool):
|
|
128
|
+
raise CodapactError(f"{name} must be a positive number of bytes")
|
|
129
|
+
return number
|
|
130
|
+
|
|
131
|
+
|
|
104
132
|
def integer(text: str) -> int:
|
|
105
133
|
"""Parse an integer argument."""
|
|
106
134
|
try:
|
|
@@ -546,6 +574,10 @@ class CliRuntime:
|
|
|
546
574
|
)
|
|
547
575
|
if allow_private in (True, "1", "true", "yes"):
|
|
548
576
|
options["allow_private"] = True
|
|
577
|
+
limit, sources["max_response_bytes"] = self._setting(
|
|
578
|
+
args, file_settings, "max_response_bytes"
|
|
579
|
+
)
|
|
580
|
+
options["max_response_bytes"] = _positive_int(limit, "max_response_bytes")
|
|
549
581
|
mode, sources["response_validation"] = self._setting(
|
|
550
582
|
args, file_settings, "response_validation"
|
|
551
583
|
)
|
|
@@ -755,8 +787,8 @@ class CliRuntime:
|
|
|
755
787
|
) -> int:
|
|
756
788
|
"""Parse ``argv`` and run one generated or built-in command; return the exit code."""
|
|
757
789
|
words = list(sys.argv[1:] if argv is None else argv)
|
|
758
|
-
out = stdout or sys.stdout
|
|
759
|
-
err = stderr or sys.stderr
|
|
790
|
+
out = stdout or _utf8(sys.stdout)
|
|
791
|
+
err = stderr or _utf8(sys.stderr)
|
|
760
792
|
token = _error_format.set(self._error_mode(self._pre_scan(words).error_format))
|
|
761
793
|
try:
|
|
762
794
|
parser = build_parser()
|
|
@@ -902,6 +934,13 @@ class CliRuntime:
|
|
|
902
934
|
|
|
903
935
|
def _client_options(self, args: argparse.Namespace, err: TextIO) -> dict[str, Any]:
|
|
904
936
|
options = self.settings(args)
|
|
937
|
+
# The CLI builds the transport so the response cap also applies to clients
|
|
938
|
+
# generated before ``max_response_bytes`` existed.
|
|
939
|
+
options["transport"] = SafeHttpClient(
|
|
940
|
+
allow_private=bool(options.get("allow_private")),
|
|
941
|
+
timeout=float(options.get("timeout") or 30.0),
|
|
942
|
+
max_bytes=options.pop("max_response_bytes"),
|
|
943
|
+
)
|
|
905
944
|
if getattr(args, "dry_run", False):
|
|
906
945
|
options["transport"] = DryRunTransport()
|
|
907
946
|
options["auth"] = PlaceholderAuth(
|
|
@@ -1000,6 +1039,8 @@ class CliRuntime:
|
|
|
1000
1039
|
return EXIT_OK
|
|
1001
1040
|
if query:
|
|
1002
1041
|
result = select(result, query)
|
|
1042
|
+
elif fields:
|
|
1043
|
+
result = _pick_target(result, fields)
|
|
1003
1044
|
result = pick(result, fields)
|
|
1004
1045
|
except DryRun as dry:
|
|
1005
1046
|
render(dry.describe(), fmt if fmt != "table" else "json", out)
|
|
@@ -1019,6 +1060,12 @@ class CliRuntime:
|
|
|
1019
1060
|
args.placeholders = True # show where the missing credential would go
|
|
1020
1061
|
return self._run(args, make_client, handler, stdout, stderr)
|
|
1021
1062
|
return emit_error(p, "auth", str(error), EXIT_AUTH, err, hint=f"run {p} doctor")
|
|
1063
|
+
except ResponseTooLargeError as error:
|
|
1064
|
+
hint = (
|
|
1065
|
+
f"raise the limit with {self.env_prefix}_MAX_RESPONSE_BYTES or "
|
|
1066
|
+
"max_response_bytes in the settings file"
|
|
1067
|
+
)
|
|
1068
|
+
return emit_error(p, "transport", str(error), EXIT_TRANSPORT, err, hint=hint)
|
|
1022
1069
|
except TransportError as error:
|
|
1023
1070
|
hint = f"run {p} doctor to check the base URL, proxy, and connectivity"
|
|
1024
1071
|
return emit_error(p, "transport", str(error), EXIT_TRANSPORT, err, hint=hint)
|
|
@@ -1243,7 +1290,7 @@ def render(value: Any, fmt: str, out: TextIO) -> None:
|
|
|
1243
1290
|
if isinstance(value, bytes):
|
|
1244
1291
|
value = value.decode("utf-8", errors="replace")
|
|
1245
1292
|
if fmt == "jsonl":
|
|
1246
|
-
items = value if isinstance(value, list) else [value]
|
|
1293
|
+
items = value if isinstance(value, list) else (_rows(value) or [value])
|
|
1247
1294
|
for item in items:
|
|
1248
1295
|
out.write(json.dumps(item, ensure_ascii=False, default=str) + "\n")
|
|
1249
1296
|
return
|
|
@@ -1309,6 +1356,30 @@ def _cell(value: Any) -> str:
|
|
|
1309
1356
|
return text if len(text) <= MAX_CELL else text[: MAX_CELL - 1] + "…"
|
|
1310
1357
|
|
|
1311
1358
|
|
|
1359
|
+
def _pick_target(value: Any, fields: str) -> Any:
|
|
1360
|
+
"""Return what ``--pick`` applies to when no ``--query`` is given.
|
|
1361
|
+
|
|
1362
|
+
A response envelope such as ``{"data": {"items": [...], "cursor": 3}}`` is
|
|
1363
|
+
unwrapped to its single list (the rows ``--output table`` shows), unless a
|
|
1364
|
+
picked key names a top-level field of the envelope itself.
|
|
1365
|
+
"""
|
|
1366
|
+
if not isinstance(value, dict):
|
|
1367
|
+
return value
|
|
1368
|
+
heads = {name.strip().split(".", 1)[0] for name in fields.split(",") if name.strip()}
|
|
1369
|
+
if heads & set(value):
|
|
1370
|
+
return value
|
|
1371
|
+
current: dict[str, Any] = value
|
|
1372
|
+
for _ in range(3):
|
|
1373
|
+
lists = [v for v in current.values() if isinstance(v, list)]
|
|
1374
|
+
if len(lists) == 1:
|
|
1375
|
+
return lists[0]
|
|
1376
|
+
nested = [v for v in current.values() if isinstance(v, dict)]
|
|
1377
|
+
if len(current) != 1 or not nested:
|
|
1378
|
+
return value
|
|
1379
|
+
current = nested[0]
|
|
1380
|
+
return value
|
|
1381
|
+
|
|
1382
|
+
|
|
1312
1383
|
def pick(value: Any, fields: str | None) -> Any:
|
|
1313
1384
|
"""Keep only ``fields`` (comma-separated dotted paths) of an object or list of objects."""
|
|
1314
1385
|
if not fields:
|
|
@@ -503,6 +503,10 @@ class Doctor:
|
|
|
503
503
|
mode = options.get("response_validation", "warn")
|
|
504
504
|
source = sources.get("response_validation", "default")
|
|
505
505
|
checks.append(Check("response validation", "info", f"{mode} (from {source})"))
|
|
506
|
+
limit = options.get("max_response_bytes")
|
|
507
|
+
if limit:
|
|
508
|
+
source = sources.get("max_response_bytes", "default")
|
|
509
|
+
checks.append(Check("response limit", "info", f"{limit} bytes (from {source})"))
|
|
506
510
|
if offline:
|
|
507
511
|
checks.append(Check("connectivity", "skip", "skipped (--offline)"))
|
|
508
512
|
elif base_ok:
|
|
@@ -28,6 +28,8 @@ from codapact.runtime.protocols.http import HttpAdapter
|
|
|
28
28
|
AdapterFactory = Callable[[Exchange], ProtocolAdapter]
|
|
29
29
|
DEFAULT_ADAPTERS: tuple[AdapterFactory, ...] = (HttpAdapter, GraphQLAdapter)
|
|
30
30
|
MAX_PAGES = 10_000
|
|
31
|
+
DEFAULT_MAX_RESPONSE_BYTES = 100_000_000
|
|
32
|
+
"""Largest response body the default transport accepts (100 MB)."""
|
|
31
33
|
|
|
32
34
|
|
|
33
35
|
def load_model(resource: Traversable) -> Api:
|
|
@@ -53,12 +55,14 @@ class RuntimeClient:
|
|
|
53
55
|
user_agent: str | None = None,
|
|
54
56
|
response_validation: str = "strict",
|
|
55
57
|
proxy: str | None = None,
|
|
58
|
+
max_response_bytes: int = DEFAULT_MAX_RESPONSE_BYTES,
|
|
56
59
|
) -> None:
|
|
57
60
|
"""Configure the client; ``base_url`` defaults to the model's first server.
|
|
58
61
|
|
|
59
62
|
``response_validation`` is ``strict`` (mismatching responses raise
|
|
60
63
|
``ResponseValidationError``), ``warn`` (emit ``ResponseValidationWarning`` and
|
|
61
64
|
return the data), or ``off``. ``proxy`` overrides the ``HTTPS_PROXY`` environment.
|
|
65
|
+
``max_response_bytes`` caps each response body of the default transport.
|
|
62
66
|
"""
|
|
63
67
|
if response_validation not in RESPONSE_VALIDATION_MODES:
|
|
64
68
|
raise ConfigError(
|
|
@@ -78,7 +82,12 @@ class RuntimeClient:
|
|
|
78
82
|
codec=self._codec,
|
|
79
83
|
base_url=self.base_url,
|
|
80
84
|
transport=transport
|
|
81
|
-
or SafeHttpClient(
|
|
85
|
+
or SafeHttpClient(
|
|
86
|
+
allow_private=allow_private,
|
|
87
|
+
timeout=timeout,
|
|
88
|
+
proxy=proxy,
|
|
89
|
+
max_bytes=max_response_bytes,
|
|
90
|
+
),
|
|
82
91
|
auth=auth,
|
|
83
92
|
middleware=tuple(middleware) if middleware is not None else (Retry(),),
|
|
84
93
|
validate=validate,
|
|
@@ -4,13 +4,14 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import Any
|
|
6
6
|
|
|
7
|
-
from codapact.core.errors import CodapactError, TransportError
|
|
7
|
+
from codapact.core.errors import CodapactError, ResponseTooLargeError, TransportError
|
|
8
8
|
|
|
9
9
|
__all__ = [
|
|
10
10
|
"ApiError",
|
|
11
11
|
"AuthError",
|
|
12
12
|
"ClientError",
|
|
13
13
|
"GraphQLResponseError",
|
|
14
|
+
"ResponseTooLargeError",
|
|
14
15
|
"ResponseValidationError",
|
|
15
16
|
"ResponseValidationWarning",
|
|
16
17
|
"TransportError",
|
|
@@ -151,11 +151,13 @@ class Suite:
|
|
|
151
151
|
input=stdin,
|
|
152
152
|
capture_output=True,
|
|
153
153
|
text=True,
|
|
154
|
+
encoding="utf-8", # generated CLIs write UTF-8 to pipes on every platform
|
|
155
|
+
errors="replace",
|
|
154
156
|
timeout=TIMEOUT,
|
|
155
157
|
check=False,
|
|
156
158
|
)
|
|
157
159
|
shown = (str(self.data["program"]), *argv)
|
|
158
|
-
return Result(shown, completed.returncode, completed.stdout, completed.stderr)
|
|
160
|
+
return Result(shown, completed.returncode, completed.stdout or "", completed.stderr or "")
|
|
159
161
|
|
|
160
162
|
def credential_variables(self) -> list[str]:
|
|
161
163
|
"""Every environment variable that can carry a credential for this CLI."""
|
|
@@ -230,6 +230,16 @@ def _dry_run(api: Api, operation: Operation, command: Command, words: list[str])
|
|
|
230
230
|
argv.append(value)
|
|
231
231
|
else:
|
|
232
232
|
argv += [f"--{arg.flag.kebab}", value]
|
|
233
|
+
by_flag = {"--" + a.flag.kebab: a for a in command.args}
|
|
234
|
+
for group in command.requires_one_of: # members are optional, so none is in argv yet
|
|
235
|
+
for flag in group:
|
|
236
|
+
value = _arg_sample(api, by_flag[flag])
|
|
237
|
+
if value is not None:
|
|
238
|
+
argv += [flag, value]
|
|
239
|
+
break
|
|
240
|
+
else:
|
|
241
|
+
case["skip"] = f"no sample satisfies any of {' or '.join(group)}"
|
|
242
|
+
return case
|
|
233
243
|
if command.destructive:
|
|
234
244
|
argv.append("--yes")
|
|
235
245
|
case["run"] = [*words, *argv]
|
|
@@ -320,10 +320,12 @@ def _pyproject(options: PythonOptions, generator_version: str) -> str:
|
|
|
320
320
|
# The floor is the generating version: generated code may use runtime helpers
|
|
321
321
|
# that older releases of the same minor line do not have.
|
|
322
322
|
floor = re.sub(r"[^0-9.].*$", "", version).rstrip(".") or f"{major}.{minor}"
|
|
323
|
+
# CLIs take the keyring extra so `auth login` uses the OS credential store.
|
|
324
|
+
package = "codapact[keyring]" if options.command else "codapact"
|
|
323
325
|
runtime = (
|
|
324
|
-
f"
|
|
326
|
+
f"{package}>={floor},<{int(major) + 1}"
|
|
325
327
|
if major != "0"
|
|
326
|
-
else f"
|
|
328
|
+
else f"{package}>={floor},<0.{int(minor) + 1}"
|
|
327
329
|
)
|
|
328
330
|
scripts = (
|
|
329
331
|
f'\n[project.scripts]\n{options.command} = "{options.package}.cli:main"\n'
|
|
@@ -361,7 +363,19 @@ def _readme(api: Api, options: PythonOptions) -> str:
|
|
|
361
363
|
"Anywhere, without a project:\n\n"
|
|
362
364
|
f"```console\nuvx --from PATH/TO/THIS/DIR {program} --help\n"
|
|
363
365
|
f"uv tool install PATH/TO/THIS/DIR # then just: {program} --help\n```\n"
|
|
364
|
-
+ (
|
|
366
|
+
+ (
|
|
367
|
+
"\n## Credentials\n\n"
|
|
368
|
+
f"Save once (OS keyring): `uv run {program} auth login`, then check with "
|
|
369
|
+
f"`uv run {program} auth status` or `uv run {program} doctor`.\n\n"
|
|
370
|
+
f"Or set per shell:\n\n{credentials}\n"
|
|
371
|
+
f"`<VAR>_COMMAND` runs a command that prints the secret "
|
|
372
|
+
"(e.g. a password manager).\n"
|
|
373
|
+
if credentials
|
|
374
|
+
else ""
|
|
375
|
+
)
|
|
376
|
+
+ "\n## Tests\n\n"
|
|
377
|
+
"```console\nuv run pytest # offline: help, dry runs, scenarios\n"
|
|
378
|
+
f"{prefix}_E2E_LIVE=1 uv run pytest -k live # read-only calls to the real API\n```\n"
|
|
365
379
|
)
|
|
366
380
|
return (
|
|
367
381
|
f"# {_one_line(api.name)}\n\n"
|
|
@@ -103,7 +103,7 @@ def test_python_package_layout(petstore) -> None:
|
|
|
103
103
|
python = root / "python"
|
|
104
104
|
pyproject = (python / "pyproject.toml").read_text("utf-8")
|
|
105
105
|
assert 'petstore = "petstore.cli:main"' in pyproject
|
|
106
|
-
assert "codapact>=" in pyproject
|
|
106
|
+
assert "codapact[keyring]>=" in pyproject
|
|
107
107
|
types = (python / "src/petstore/types.py").read_text("utf-8")
|
|
108
108
|
assert (
|
|
109
109
|
"Pet = TypedDict(" in types
|
|
@@ -270,6 +270,7 @@ def test_generated_package_runs_with_a_short_command(ynab) -> None:
|
|
|
270
270
|
package = root / "python"
|
|
271
271
|
pyproject = (package / "pyproject.toml").read_text()
|
|
272
272
|
assert 'ynab = "ynab_api.cli:main"' in pyproject
|
|
273
|
-
assert re.search(r'"codapact>=\d+\.\d+\.\d+,<', pyproject)
|
|
273
|
+
assert re.search(r'"codapact\[keyring\]>=\d+\.\d+\.\d+,<', pyproject)
|
|
274
274
|
readme = (package / "README.md").read_text()
|
|
275
275
|
assert "uv run ynab --help" in readme and "`YNAB_BEARER`" in readme
|
|
276
|
+
assert "uv run ynab auth login" in readme and "YNAB_E2E_LIVE=1" in readme
|
|
@@ -218,6 +218,39 @@ def test_render_suite_derives_cases() -> None:
|
|
|
218
218
|
assert len(suite_for(api, {"smoke": {"limit": 1}})["smoke"]) == 1
|
|
219
219
|
|
|
220
220
|
|
|
221
|
+
def _wrapper_body(properties: dict[str, Any]) -> dict[str, Any]:
|
|
222
|
+
return {
|
|
223
|
+
"post": {
|
|
224
|
+
"operationId": "post_" + "_".join(properties),
|
|
225
|
+
"requestBody": {
|
|
226
|
+
"required": True,
|
|
227
|
+
"content": {
|
|
228
|
+
"application/json": {"schema": {"type": "object", "properties": properties}}
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
"responses": {"200": {"description": "ok"}},
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def test_dry_run_fills_a_required_body_whose_fields_are_all_optional() -> None:
|
|
237
|
+
never = {"type": "string", "maxLength": 0}
|
|
238
|
+
contract = {
|
|
239
|
+
"openapi": "3.1.0",
|
|
240
|
+
"info": {"title": "Zoo", "version": "1"},
|
|
241
|
+
"servers": [{"url": "https://zoo.example.com"}],
|
|
242
|
+
"paths": {
|
|
243
|
+
"/one": _wrapper_body({"first": never, "second": {"type": "string"}}),
|
|
244
|
+
"/none": _wrapper_body({"bad": never, "worse": never}),
|
|
245
|
+
},
|
|
246
|
+
}
|
|
247
|
+
api = openapi(contract).api
|
|
248
|
+
assert api is not None
|
|
249
|
+
runs = {c["name"]: c for c in suite_for(api)["dry_runs"]}
|
|
250
|
+
assert runs["post-first-second"]["run"] == ["post-first-second", "--second", "sample"]
|
|
251
|
+
assert runs["post-bad-worse"]["skip"] == "no sample satisfies any of --bad or --worse"
|
|
252
|
+
|
|
253
|
+
|
|
221
254
|
def test_render_suite_for_graphql() -> None:
|
|
222
255
|
suite = suite_for(library_api())
|
|
223
256
|
case = suite["dry_runs"][0]
|