codapact 0.5.1__tar.gz → 0.5.2__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.
Files changed (164) hide show
  1. codapact-0.5.2/.release-please-manifest.json +1 -0
  2. {codapact-0.5.1 → codapact-0.5.2}/CHANGELOG.md +7 -0
  3. {codapact-0.5.1 → codapact-0.5.2}/PKG-INFO +1 -1
  4. {codapact-0.5.1 → codapact-0.5.2}/docs/configuration.md +1 -1
  5. {codapact-0.5.1 → codapact-0.5.2}/pyproject.toml +1 -1
  6. {codapact-0.5.1 → codapact-0.5.2}/pyproject.toml.orig +1 -1
  7. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/__init__.py +1 -1
  8. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/cli.py +41 -12
  9. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_live_ynab_findings.py +61 -1
  10. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_usability.py +1 -1
  11. {codapact-0.5.1 → codapact-0.5.2}/uv.lock +1 -1
  12. codapact-0.5.1/.release-please-manifest.json +0 -1
  13. {codapact-0.5.1 → codapact-0.5.2}/.github/workflows/ci.yml +0 -0
  14. {codapact-0.5.1 → codapact-0.5.2}/.github/workflows/codeql.yml +0 -0
  15. {codapact-0.5.1 → codapact-0.5.2}/.github/workflows/mutation.yml +0 -0
  16. {codapact-0.5.1 → codapact-0.5.2}/.github/workflows/nightly.yml +0 -0
  17. {codapact-0.5.1 → codapact-0.5.2}/.github/workflows/release.yml +0 -0
  18. {codapact-0.5.1 → codapact-0.5.2}/LICENSE +0 -0
  19. {codapact-0.5.1 → codapact-0.5.2}/README.md +0 -0
  20. {codapact-0.5.1 → codapact-0.5.2}/docs/architecture.md +0 -0
  21. {codapact-0.5.1 → codapact-0.5.2}/docs/branding/README.md +0 -0
  22. {codapact-0.5.1 → codapact-0.5.2}/docs/branding/mark.svg +0 -0
  23. {codapact-0.5.1 → codapact-0.5.2}/docs/branding/wordmark.svg +0 -0
  24. {codapact-0.5.1 → codapact-0.5.2}/docs/testing.md +0 -0
  25. {codapact-0.5.1 → codapact-0.5.2}/examples/library/codapact.yaml +0 -0
  26. {codapact-0.5.1 → codapact-0.5.2}/examples/library/operations.graphql +0 -0
  27. {codapact-0.5.1 → codapact-0.5.2}/examples/library/schema.graphql +0 -0
  28. {codapact-0.5.1 → codapact-0.5.2}/examples/petstore/codapact.yaml +0 -0
  29. {codapact-0.5.1 → codapact-0.5.2}/examples/petstore/openapi.yaml +0 -0
  30. {codapact-0.5.1 → codapact-0.5.2}/release-please-config.json +0 -0
  31. {codapact-0.5.1 → codapact-0.5.2}/scripts/extract_openapi_subset.py +0 -0
  32. {codapact-0.5.1 → codapact-0.5.2}/scripts/mutation_score.py +0 -0
  33. {codapact-0.5.1 → codapact-0.5.2}/scripts/verify_dist.py +0 -0
  34. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/__main__.py +0 -0
  35. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/commands/__init__.py +0 -0
  36. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/commands/derive.py +0 -0
  37. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/commands/model.py +0 -0
  38. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/core/__init__.py +0 -0
  39. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/core/diagnostics.py +0 -0
  40. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/core/errors.py +0 -0
  41. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/core/naming.py +0 -0
  42. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/core/net.py +0 -0
  43. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/model/__init__.py +0 -0
  44. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/model/api.py +0 -0
  45. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/model/authspec.py +0 -0
  46. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/model/migrations.py +0 -0
  47. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/model/rewrite.py +0 -0
  48. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/model/serialize.py +0 -0
  49. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/model/types.py +0 -0
  50. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/model/validate.py +0 -0
  51. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/model/values.py +0 -0
  52. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/pipeline/__init__.py +0 -0
  53. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/pipeline/cli.py +0 -0
  54. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/pipeline/config.py +0 -0
  55. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/pipeline/defaults.py +0 -0
  56. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/pipeline/pipeline.py +0 -0
  57. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/pipeline/writer.py +0 -0
  58. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/plugins/__init__.py +0 -0
  59. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/plugins/external.py +0 -0
  60. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/plugins/protocol.py +0 -0
  61. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/plugins/registry.py +0 -0
  62. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/py.typed +0 -0
  63. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/__init__.py +0 -0
  64. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/abstractions.py +0 -0
  65. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/arguments.py +0 -0
  66. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/auth.py +0 -0
  67. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/cli_auth.py +0 -0
  68. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/cli_tools.py +0 -0
  69. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/client.py +0 -0
  70. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/codec.py +0 -0
  71. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/credentials.py +0 -0
  72. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/errors.py +0 -0
  73. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/middleware.py +0 -0
  74. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/oauth.py +0 -0
  75. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/protocols/__init__.py +0 -0
  76. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/protocols/base.py +0 -0
  77. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/protocols/graphql.py +0 -0
  78. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/protocols/http.py +0 -0
  79. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/runtime/selftest.py +0 -0
  80. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/shaping/__init__.py +0 -0
  81. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/shaping/base.py +0 -0
  82. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/shaping/engine.py +0 -0
  83. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/shaping/transforms.py +0 -0
  84. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/sources/__init__.py +0 -0
  85. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/sources/base.py +0 -0
  86. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/sources/graphql/__init__.py +0 -0
  87. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/sources/graphql/translator.py +0 -0
  88. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/sources/loader.py +0 -0
  89. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/sources/openapi/__init__.py +0 -0
  90. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/sources/openapi/translator.py +0 -0
  91. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/surface/__init__.py +0 -0
  92. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/surface/derive.py +0 -0
  93. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/surface/model.py +0 -0
  94. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/targets/__init__.py +0 -0
  95. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/targets/python/__init__.py +0 -0
  96. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/targets/python/cli.py +0 -0
  97. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/targets/python/e2e.py +0 -0
  98. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/targets/python/library.py +0 -0
  99. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/targets/python/naming.py +0 -0
  100. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/targets/typescript/__init__.py +0 -0
  101. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/targets/typescript/library.py +0 -0
  102. {codapact-0.5.1 → codapact-0.5.2}/src/codapact/targets/typescript/runtime.ts +0 -0
  103. {codapact-0.5.1 → codapact-0.5.2}/tests/authlab.py +0 -0
  104. {codapact-0.5.1 → codapact-0.5.2}/tests/conftest.py +0 -0
  105. {codapact-0.5.1 → codapact-0.5.2}/tests/e2e/test_auth_e2e.py +0 -0
  106. {codapact-0.5.1 → codapact-0.5.2}/tests/e2e/test_cli_e2e.py +0 -0
  107. {codapact-0.5.1 → codapact-0.5.2}/tests/e2e/test_public_apis.py +0 -0
  108. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/authlab/authlab_plugin.py +0 -0
  109. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/authlab/codapact.yaml +0 -0
  110. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/authlab/fake_browser.py +0 -0
  111. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/authlab/openapi.yaml +0 -0
  112. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/authlab_smoke.ts +0 -0
  113. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/contracts/wire.yaml +0 -0
  114. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/README.md +0 -0
  115. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/countries/codapact.yaml +0 -0
  116. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/countries/operations.graphql +0 -0
  117. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/countries/schema.graphql +0 -0
  118. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/github/codapact.yaml +0 -0
  119. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/github/openapi.json +0 -0
  120. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/pokeapi/codapact.yaml +0 -0
  121. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/pokeapi/openapi.yml +0 -0
  122. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/ynab/README.md +0 -0
  123. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/ynab/codapact.yaml +0 -0
  124. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/corpus/ynab/openapi.yaml +0 -0
  125. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/library_smoke.ts +0 -0
  126. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/outline_plugin.py +0 -0
  127. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/petstore_smoke.ts +0 -0
  128. {codapact-0.5.1 → codapact-0.5.2}/tests/fixtures/wire_parity.ts +0 -0
  129. {codapact-0.5.1 → codapact-0.5.2}/tests/integration/test_cli_conformance.py +0 -0
  130. {codapact-0.5.1 → codapact-0.5.2}/tests/integration/test_cli_conventions.py +0 -0
  131. {codapact-0.5.1 → codapact-0.5.2}/tests/integration/test_contract_properties.py +0 -0
  132. {codapact-0.5.1 → codapact-0.5.2}/tests/integration/test_corpus.py +0 -0
  133. {codapact-0.5.1 → codapact-0.5.2}/tests/integration/test_generated_code_properties.py +0 -0
  134. {codapact-0.5.1 → codapact-0.5.2}/tests/integration/test_generation.py +0 -0
  135. {codapact-0.5.1 → codapact-0.5.2}/tests/integration/test_public_api_cli.py +0 -0
  136. {codapact-0.5.1 → codapact-0.5.2}/tests/integration/test_wire_parity.py +0 -0
  137. {codapact-0.5.1 → codapact-0.5.2}/tests/integration/test_ynab_contract.py +0 -0
  138. {codapact-0.5.1 → codapact-0.5.2}/tests/perf/test_scaling.py +0 -0
  139. {codapact-0.5.1 → codapact-0.5.2}/tests/public_api_contract.py +0 -0
  140. {codapact-0.5.1 → codapact-0.5.2}/tests/strategies.py +0 -0
  141. {codapact-0.5.1 → codapact-0.5.2}/tests/support.py +0 -0
  142. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_architecture.py +0 -0
  143. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_auth_and_graphql_sources.py +0 -0
  144. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_auth_sources.py +0 -0
  145. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_bundle_e2e.py +0 -0
  146. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_cli_auth.py +0 -0
  147. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_cli_builtins.py +0 -0
  148. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_cli_options.py +0 -0
  149. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_codec_serialize.py +0 -0
  150. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_core.py +0 -0
  151. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_guards.py +0 -0
  152. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_model.py +0 -0
  153. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_mutation_score.py +0 -0
  154. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_oauth.py +0 -0
  155. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_openapi_edges.py +0 -0
  156. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_openapi_translator_units.py +0 -0
  157. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_plugins_pipeline.py +0 -0
  158. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_public_api_findings.py +0 -0
  159. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_runtime.py +0 -0
  160. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_runtime_edges.py +0 -0
  161. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_runtime_pagination.py +0 -0
  162. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_shaping_surface_commands.py +0 -0
  163. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_sources.py +0 -0
  164. {codapact-0.5.1 → codapact-0.5.2}/tests/unit/test_target_rendering.py +0 -0
@@ -0,0 +1 @@
1
+ {".":"0.5.2"}
@@ -2,6 +2,13 @@
2
2
 
3
3
  <!-- markdownlint-configure-file { "MD024": { "siblings_only": true } } -->
4
4
 
5
+ ## [0.5.2](https://github.com/mikejhill/codapact/compare/v0.5.1...v0.5.2) (2026-11-14)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **cli:** fail when --query matches nothing ([#39](https://github.com/mikejhill/codapact/issues/39)) ([08bd3aa](https://github.com/mikejhill/codapact/commit/08bd3aa5a3e45192461633c084feb7d9438cb193))
11
+
5
12
  ## [0.5.1](https://github.com/mikejhill/codapact/compare/v0.5.0...v0.5.1) (2026-11-14)
6
13
 
7
14
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codapact
3
- Version: 0.5.1
3
+ Version: 0.5.2
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
@@ -116,7 +116,7 @@ credential variables for the contract's auth schemes.
116
116
 
117
117
  Global options work before or after the command: `--base-url`, `--timeout`, `--config`,
118
118
  `-o/--output`, `--query PATH` (`data.items[].name`, `data.items[0]`; with `--all` the
119
- result is the item list, so `[].name`), `--dry-run`, `-v/--verbose`, `--error-format`,
119
+ result is the item list, so `[].name`; a path that matches nothing fails with exit 2 and lists the keys that exist), `--dry-run`, `-v/--verbose`, `--error-format`,
120
120
  `--allow-private`, and `--response-validation`. Command help lists them in one line;
121
121
  `<program> --help` describes each.
122
122
  `table` renders a list of objects, unwrapping single-list envelopes such as `{"data": {"items": [...]}}`.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codapact"
3
- version = "0.5.1"
3
+ version = "0.5.2"
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"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codapact"
3
- version = "0.5.1"
3
+ version = "0.5.2"
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"
@@ -5,4 +5,4 @@ from importlib.metadata import PackageNotFoundError, version
5
5
  try:
6
6
  __version__ = version("codapact")
7
7
  except PackageNotFoundError: # pragma: no cover - running from an unbuilt tree
8
- __version__ = "0.5.1"
8
+ __version__ = "0.5.2"
@@ -1038,7 +1038,7 @@ class CliRuntime:
1038
1038
  if streamed:
1039
1039
  return EXIT_OK
1040
1040
  if query:
1041
- result = select(result, query)
1041
+ result = select(result, query, strict=True)
1042
1042
  elif fields:
1043
1043
  result = _pick_target(result, fields)
1044
1044
  result = pick(result, fields)
@@ -1244,36 +1244,65 @@ def describe_invalid(error: ValidationError, flags: dict[str, str]) -> str:
1244
1244
 
1245
1245
 
1246
1246
  _STEP = re.compile(r"(?P<key>[^.\[\]]*)(?P<index>\[(?:-?\d+)?\])?")
1247
+ _QUERY_SYNTAX = "--query takes a dotted path: a.b, a[0], a[-1], a[] (not JMESPath)"
1248
+ _MISSING = object()
1247
1249
 
1248
1250
 
1249
- def select(value: Any, query: str) -> Any:
1251
+ def select(value: Any, query: str, *, strict: bool = False) -> Any:
1250
1252
  """Return the part of ``value`` at a dotted path.
1251
1253
 
1252
1254
  ``a.b`` reads keys, ``a[0]`` / ``a[-1]`` index a list, and ``a[]`` maps the
1253
- rest of the path over every element (the result is then a list).
1255
+ rest of the path over every element (the result is then a list). A part that
1256
+ is absent reads as ``None``; with ``strict``, a path that matches nothing at
1257
+ all raises instead, naming the step that failed.
1254
1258
  """
1255
1259
  current: list[Any] = [value]
1256
1260
  spread = False
1257
- for raw in query.split("."):
1261
+ miss: tuple[str, Any] | None = None # first step that found nothing, and what it looked in
1262
+ for number, raw in enumerate(query.split(".")):
1258
1263
  step = _STEP.fullmatch(raw)
1259
1264
  if step is None:
1260
- raise CodapactError(f"invalid --query step {raw!r}")
1265
+ raise CodapactError(f"invalid --query step {raw!r}; {_QUERY_SYNTAX}")
1261
1266
  key, index = step.group("key"), step.group("index")
1262
1267
  nxt: list[Any] = []
1263
1268
  for item in current:
1264
- if key:
1265
- item = item.get(key) if isinstance(item, dict) else None
1269
+ parent = item
1270
+ if key and item is not _MISSING:
1271
+ item = item.get(key, _MISSING) if isinstance(item, dict) else _MISSING
1272
+ parent = parent if item is _MISSING else item
1266
1273
  if index == "[]":
1267
- nxt.extend(item if isinstance(item, list) else [])
1268
- elif index:
1274
+ if isinstance(item, list):
1275
+ nxt.extend(item)
1276
+ continue
1277
+ item = _MISSING
1278
+ elif index and item is not _MISSING:
1269
1279
  position = int(index[1:-1])
1270
1280
  ok = isinstance(item, list) and -len(item) <= position < len(item)
1271
- nxt.append(item[position] if ok else None)
1272
- else:
1281
+ item = item[position] if ok else _MISSING
1282
+ if item is _MISSING and parent is not _MISSING and miss is None:
1283
+ miss = (".".join(query.split(".")[: number + 1]), parent)
1284
+ if item is not _MISSING or index != "[]":
1273
1285
  nxt.append(item)
1274
1286
  current = nxt
1275
1287
  spread = spread or index == "[]"
1276
- return current if spread else current[0]
1288
+ if strict and miss is not None and all(item is _MISSING for item in current):
1289
+ raise CodapactError(_no_match(query, *miss))
1290
+ found = [None if item is _MISSING else item for item in current]
1291
+ return found if spread else found[0]
1292
+
1293
+
1294
+ def _no_match(query: str, path: str, parent: Any) -> str:
1295
+ """Explain a ``--query`` that matched nothing."""
1296
+ message = f"--query {query!r} matched nothing at {path!r}"
1297
+ if isinstance(parent, dict) and parent:
1298
+ keys = list(parent)
1299
+ more = f", ... ({len(keys)} keys)" if len(keys) > 12 else ""
1300
+ message += f"; available keys: {', '.join(map(str, keys[:12]))}{more}"
1301
+ elif isinstance(parent, list):
1302
+ message += f"; that is a list of {len(parent)}, index it with [N] or []"
1303
+ if re.search(r"[()@|*?=!&\s'\"`]", query):
1304
+ message += f"; {_QUERY_SYNTAX}"
1305
+ return message
1277
1306
 
1278
1307
 
1279
1308
  def render(value: Any, fmt: str, out: TextIO) -> None:
@@ -13,7 +13,7 @@ import pytest
13
13
  from codapact.core.errors import CodapactError, ResponseTooLargeError, TransportError
14
14
  from codapact.core.net import HttpRequest, SafeHttpClient
15
15
  from codapact.runtime import RuntimeClient, StaticAuth
16
- from codapact.runtime.cli import CliRuntime, _utf8, render
16
+ from codapact.runtime.cli import CliRuntime, _utf8, render, select
17
17
  from codapact.runtime.client import DEFAULT_MAX_RESPONSE_BYTES
18
18
  from codapact.runtime.selftest import Suite
19
19
  from tests.support import Petstore, petstore_api, serve
@@ -155,3 +155,63 @@ def test_bundle_suite_decodes_cli_output_as_utf8(tmp_path: Path) -> None:
155
155
  result = suite.invoke([], {"PYTHONPATH": str(tmp_path)})
156
156
  assert result.code == 0
157
157
  assert result.stdout.startswith('{"n": "café ”q”"}') and result.stdout.endswith("\ufffd")
158
+
159
+
160
+ # ---------------------------------------------------------------- --query that matches nothing
161
+
162
+ _VALUE = {"data": {"items": [{"id": 1, "tags": ["a"]}, {"id": 2}], "plan": {"note": None}}}
163
+
164
+
165
+ @pytest.mark.parametrize(
166
+ ("query", "expected"),
167
+ [
168
+ ("data.items[].id", [1, 2]),
169
+ ("data.items[].tags", [["a"], None]), # some elements lack it: still a match
170
+ ("data.items[].tags[]", ["a"]),
171
+ ("data.plan.note", None), # present but null is a match
172
+ ("data.items[-1].id", 2),
173
+ ],
174
+ )
175
+ def test_strict_query_keeps_real_matches(query: str, expected: Any) -> None:
176
+ assert select(_VALUE, query, strict=True) == expected
177
+
178
+
179
+ @pytest.mark.parametrize(
180
+ ("query", "message"),
181
+ [
182
+ ("data.nonexistent", "at 'data.nonexistent'; available keys: items, plan"),
183
+ ("data.missing.x", "at 'data.missing'; available keys"),
184
+ ("data.items.id", "that is a list of 2, index it with [N] or []"),
185
+ ("data.items[5].id", "at 'data.items[5]'; that is a list of 2"),
186
+ ("data.items[].nokey", "available keys: id, tags"),
187
+ ("data.plan[]", "at 'data.plan[]'; available keys: note"),
188
+ ("length(data.items)", "not JMESPath"),
189
+ ("7.x", "matched nothing at '7'"),
190
+ ("data.items[0].id.x", "at 'data.items[0].id.x'"), # a scalar has no keys
191
+ ],
192
+ )
193
+ def test_strict_query_explains_a_path_that_matches_nothing(query: str, message: str) -> None:
194
+ with pytest.raises(CodapactError, match="matched nothing") as caught:
195
+ select(_VALUE, query, strict=True)
196
+ assert message in str(caught.value)
197
+ lenient = select(_VALUE, query) # --fields stays lenient
198
+ assert lenient is None or not any(lenient)
199
+
200
+
201
+ def test_many_keys_are_truncated() -> None:
202
+ wide = {f"k{n}": n for n in range(20)}
203
+ with pytest.raises(CodapactError, match=r"k11, \.\.\. \(20 keys\)"):
204
+ select(wide, "nope", strict=True)
205
+
206
+
207
+ def test_cli_query_that_matches_nothing_fails_with_a_usage_error(tmp_path: Path) -> None:
208
+ runtime = CliRuntime("hub", "HUB", environ={"XDG_CONFIG_HOME": str(tmp_path)})
209
+ out, err = io.StringIO(), io.StringIO()
210
+ args = _parse(runtime, "--query", "data.nonexistent")
211
+ code = runtime.run(args, lambda _o: None, lambda _c, _a: _VALUE, stdout=out, stderr=err)
212
+ assert code == 2 and out.getvalue() == ""
213
+ assert "matched nothing at 'data.nonexistent'" in err.getvalue()
214
+ out = io.StringIO()
215
+ args = _parse(runtime, "--query", "data.items[].id", "-o", "json")
216
+ assert runtime.run(args, lambda _o: None, lambda _c, _a: _VALUE, stdout=out, stderr=err) == 0
217
+ assert out.getvalue().split() == ["[", "1,", "2", "]"]
@@ -188,7 +188,7 @@ def test_select_paths() -> None:
188
188
  assert select(value, "data.items[].tags[]") == ["a"]
189
189
  assert select(value, "data.missing.x") is None
190
190
  assert select(value, "data") == value["data"]
191
- with pytest.raises(CodapactError, match="invalid --query"):
191
+ with pytest.raises(CodapactError, match=r"invalid --query.*dotted path"):
192
192
  select(value, "data.items[x]")
193
193
 
194
194
 
@@ -247,7 +247,7 @@ wheels = [
247
247
 
248
248
  [[package]]
249
249
  name = "codapact"
250
- version = "0.5.1"
250
+ version = "0.5.2"
251
251
  source = { editable = "." }
252
252
  dependencies = [
253
253
  { name = "graphql-core" },
@@ -1 +0,0 @@
1
- {".":"0.5.1"}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes