terp-cli 0.40.0__tar.gz → 0.41.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.
Files changed (84) hide show
  1. {terp_cli-0.40.0 → terp_cli-0.41.1}/PKG-INFO +9 -9
  2. {terp_cli-0.40.0 → terp_cli-0.41.1}/pyproject.toml +9 -9
  3. {terp_cli-0.40.0 → terp_cli-0.41.1}/signer/Dockerfile +2 -2
  4. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/__init__.py +15 -111
  5. terp_cli-0.41.1/src/terp/cli/_cors_view.py +38 -0
  6. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/access.py +48 -29
  7. terp_cli-0.41.1/src/terp/cli/authz_changes.py +321 -0
  8. terp_cli-0.41.1/src/terp/cli/authz_surface.py +325 -0
  9. terp_cli-0.41.1/src/terp/cli/dependency_audit.py +69 -0
  10. terp_cli-0.41.1/src/terp/cli/guide_capability.py +100 -0
  11. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/guide_deployment.py +44 -25
  12. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/locks.py +48 -20
  13. terp_cli-0.41.1/src/terp/cli/npm_tree.py +159 -0
  14. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/_locks.py +28 -3
  15. terp_cli-0.41.1/src/terp/cli/release/_npm_lock.py +115 -0
  16. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/_plan.py +123 -25
  17. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/manifest.py +6 -5
  18. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/promote.py +36 -7
  19. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/sign.py +6 -5
  20. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/verify.py +24 -207
  21. terp_cli-0.40.0/src/terp/cli/authz_surface.py +0 -169
  22. {terp_cli-0.40.0 → terp_cli-0.41.1}/.gitignore +0 -0
  23. {terp_cli-0.40.0 → terp_cli-0.41.1}/signer/terp-arch-releases.json +0 -0
  24. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/_appref.py +0 -0
  25. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/_engine.py +0 -0
  26. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/_output.py +0 -0
  27. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/_subjects.py +0 -0
  28. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/api_contract.py +0 -0
  29. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/api_contract_bounds.py +0 -0
  30. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/api_contract_check.py +0 -0
  31. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/api_contract_schemas.py +0 -0
  32. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/api_contract_shapes.py +0 -0
  33. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/apidocs.py +0 -0
  34. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/capabilities.py +0 -0
  35. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/deploy_safety.py +0 -0
  36. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/deployment_adopt.py +0 -0
  37. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/deployment_app.py +0 -0
  38. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/deployment_check.py +0 -0
  39. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/deployment_declare.py +0 -0
  40. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/deployment_render.py +0 -0
  41. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/dev.py +0 -0
  42. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/docker.py +0 -0
  43. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/docker_masks.py +0 -0
  44. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/envfile.py +0 -0
  45. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/envrequired.py +0 -0
  46. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/envschema.py +0 -0
  47. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/envseams.py +0 -0
  48. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/fmt.py +0 -0
  49. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/grants.py +0 -0
  50. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/guide_passwords.py +0 -0
  51. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/heartbeat.py +0 -0
  52. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/jobs.py +0 -0
  53. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/leases.py +0 -0
  54. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/module_roles.py +0 -0
  55. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/openapi.py +0 -0
  56. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/outbox.py +0 -0
  57. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/ports.py +0 -0
  58. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/profiles.py +0 -0
  59. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/py.typed +0 -0
  60. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/__init__.py +0 -0
  61. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/_common.py +0 -0
  62. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/_compare.py +0 -0
  63. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/_dockerfile.py +0 -0
  64. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/_git.py +0 -0
  65. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/_image.py +0 -0
  66. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/_registry.py +0 -0
  67. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/_render.py +0 -0
  68. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/_sandbox.py +0 -0
  69. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/build.py +0 -0
  70. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/cli.py +0 -0
  71. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/dsse.py +0 -0
  72. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/release/gate.py +0 -0
  73. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/reseal.py +0 -0
  74. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/reseal_report.py +0 -0
  75. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/routes.py +0 -0
  76. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/scaffold.py +0 -0
  77. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/schema.py +0 -0
  78. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/seed.py +0 -0
  79. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/service_accounts.py +0 -0
  80. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/smoke.py +0 -0
  81. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/users.py +0 -0
  82. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/version.py +0 -0
  83. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/workbench.py +0 -0
  84. {terp_cli-0.40.0 → terp_cli-0.41.1}/src/terp/cli/workbench_adopt.py +0 -0
@@ -1,23 +1,23 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: terp-cli
3
- Version: 0.40.0
3
+ Version: 0.41.1
4
4
  Summary: Terp command-line tool — inspect, scaffolding, migrations, checks, api-docs.
5
5
  Project-URL: Repository, https://github.com/AITT-NL/terp-framework
6
6
  Project-URL: Changelog, https://github.com/AITT-NL/terp-framework/blob/main/CHANGELOG.md
7
7
  License-Expression: Apache-2.0
8
8
  Requires-Python: >=3.13
9
9
  Requires-Dist: pyyaml>=6.0
10
- Requires-Dist: terp-arch==0.40.0
11
- Requires-Dist: terp-core==0.40.0
12
- Requires-Dist: terp-migrations==0.40.0
10
+ Requires-Dist: terp-arch==0.41.1
11
+ Requires-Dist: terp-core==0.41.1
12
+ Requires-Dist: terp-migrations==0.41.1
13
13
  Provides-Extra: jobs
14
- Requires-Dist: terp-cap-outbox==0.40.0; extra == 'jobs'
15
- Requires-Dist: terp-cap-scheduler-apscheduler==0.40.0; extra == 'jobs'
14
+ Requires-Dist: terp-cap-outbox==0.41.1; extra == 'jobs'
15
+ Requires-Dist: terp-cap-scheduler-apscheduler==0.41.1; extra == 'jobs'
16
16
  Provides-Extra: release
17
17
  Requires-Dist: cryptography>=46; extra == 'release'
18
18
  Requires-Dist: packaging>=24; extra == 'release'
19
- Requires-Dist: terp-cap-egress==0.40.0; extra == 'release'
19
+ Requires-Dist: terp-cap-egress==0.41.1; extra == 'release'
20
20
  Provides-Extra: scheduler
21
- Requires-Dist: terp-cap-scheduler-apscheduler==0.40.0; extra == 'scheduler'
21
+ Requires-Dist: terp-cap-scheduler-apscheduler==0.41.1; extra == 'scheduler'
22
22
  Provides-Extra: worker
23
- Requires-Dist: terp-cap-outbox==0.40.0; extra == 'worker'
23
+ Requires-Dist: terp-cap-outbox==0.41.1; extra == 'worker'
@@ -4,18 +4,18 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "terp-cli"
7
- version = "0.40.0"
7
+ version = "0.41.1"
8
8
  description = "Terp command-line tool — inspect, scaffolding, migrations, checks, api-docs."
9
9
  requires-python = ">=3.13"
10
10
  license = "Apache-2.0"
11
11
  dependencies = [
12
- "terp-core==0.40.0",
12
+ "terp-core==0.41.1",
13
13
  # `terp migrate` delegates to terp-migrations (lazily imported), keeping Alembic
14
14
  # off the path for `terp inspect` / `terp guide` while making migrations work.
15
- "terp-migrations==0.40.0",
15
+ "terp-migrations==0.41.1",
16
16
  # `terp guide rules` projects the live rule registry; terp-arch is imported lazily
17
17
  # (only when that topic is rendered), so it stays off the common `terp guide` path.
18
- "terp-arch==0.40.0",
18
+ "terp-arch==0.41.1",
19
19
  # `terp verify --only env-seams` and `terp smoke` read the compose profiles as data
20
20
  # (anchors and `<<:` merge keys resolved), so both answer without a Docker daemon or
21
21
  # even the `docker` binary. Declared explicitly rather than leant on: every app
@@ -29,11 +29,11 @@ dependencies = [
29
29
  # or a scheduler engine into apps that only use inspect/check/migrate. Deployments can select
30
30
  # one process role, while `jobs` is the convenient complete jobs-process bundle.
31
31
  [project.optional-dependencies]
32
- worker = ["terp-cap-outbox==0.40.0"]
33
- scheduler = ["terp-cap-scheduler-apscheduler==0.40.0"]
32
+ worker = ["terp-cap-outbox==0.41.1"]
33
+ scheduler = ["terp-cap-scheduler-apscheduler==0.41.1"]
34
34
  jobs = [
35
- "terp-cap-outbox==0.40.0",
36
- "terp-cap-scheduler-apscheduler==0.40.0",
35
+ "terp-cap-outbox==0.41.1",
36
+ "terp-cap-scheduler-apscheduler==0.41.1",
37
37
  ]
38
38
  # `terp release` and `terp promote` (ADR 0187): the DSSE signature (cryptography), the lock's
39
39
  # markers (packaging), and the one declared way to a registry, an index and the vulnerability
@@ -42,7 +42,7 @@ jobs = [
42
42
  release = [
43
43
  "cryptography>=46",
44
44
  "packaging>=24",
45
- "terp-cap-egress==0.40.0",
45
+ "terp-cap-egress==0.41.1",
46
46
  ]
47
47
 
48
48
  [project.scripts]
@@ -26,7 +26,7 @@
26
26
  # (tests/release_lane/).
27
27
 
28
28
  # python:3.14-slim, the base-image table's interpreter (terp-arch's base-images.json).
29
- FROM python@sha256:930e1abba7c4e8f96ed93e8012c35d174d7732752731bbd5e8e757d7ec6f3966 AS install
29
+ FROM python@sha256:9aaa474097d094040649f2162a627c0049b408f52138d980916788d80f04802f AS install
30
30
  COPY wheels/ /wheels/
31
31
  COPY requirements.txt /requirements.txt
32
32
  # Every distribution by its hash: the third-party ones as uv.lock pins them, the framework's as
@@ -41,7 +41,7 @@ FROM zricethezav/gitleaks@sha256:c00b6bd0aeb3071cbcb79009cb16a60dd9e0a7c60e2be9a
41
41
  # The docker client 29.9.2, by digest (docker:29.9.2-cli, read 2026-10-22).
42
42
  FROM docker@sha256:5e6baf67325a79f64ed3bed6863954d5e05d0f3d4e57cbdb14809346814bbfdb AS docker
43
43
 
44
- FROM python@sha256:930e1abba7c4e8f96ed93e8012c35d174d7732752731bbd5e8e757d7ec6f3966
44
+ FROM python@sha256:9aaa474097d094040649f2162a627c0049b408f52138d980916788d80f04802f
45
45
  RUN apt-get update \
46
46
  && apt-get install -y --no-install-recommends git \
47
47
  && rm -rf /var/lib/apt/lists/* \
@@ -11,11 +11,12 @@ import sys
11
11
  from collections.abc import Callable, Sequence
12
12
  from typing import TYPE_CHECKING
13
13
 
14
- from terp.core import ControlPlane, CorsPolicy, ModuleSpec
14
+ from terp.core import ControlPlane, ModuleSpec
15
15
 
16
16
  if TYPE_CHECKING: # terp-arch stays off the common `terp guide` / `terp inspect` path
17
17
  from terp.arch import ScanRoot
18
18
 
19
+ from terp.cli._cors_view import cors_json, cors_label
19
20
  from terp.cli._output import emit, use_utf8_output
20
21
  from terp.cli.access import (
21
22
  build_access_graph_for_app,
@@ -57,7 +58,7 @@ from terp.cli.module_roles import (
57
58
  module_role_list_command,
58
59
  module_role_revoke_command,
59
60
  )
60
- from terp.cli import guide_deployment, guide_passwords
61
+ from terp.cli import guide_capability, guide_deployment, guide_passwords
61
62
  from terp.cli.grants import (
62
63
  grant_add_command,
63
64
  grant_list_command,
@@ -668,7 +669,7 @@ The access model (three layers) — profiles + the access graph
668
669
  uv run terp inspect access --app app.main:build --app-root . --format json
669
670
  The --app form reports the WHOLE composed surface — client modules AND every
670
671
  discovered capability router (users / groups / audit / files / …) plus the kernel
671
- health routes — reconciled against app.openapi() so a mounted route can never hide
672
+ health routes — reconciled against the composed route table so a served route can never hide
672
673
  (any that is not covered is listed under omitted_routes, fail-visible). Use
673
674
  --object/--module instead to inspect a focused, hand-passed subset.
674
675
  One document: roles, permissions, every endpoint's method/path/requirement, each
@@ -1178,12 +1179,17 @@ The security declaration (SecurityConfig, refused at production boot)
1178
1179
  - FOUR of its states refuse a production boot (SecurityConfig.production_problems();
1179
1180
  create_app raises BootError "insecure production security config"). Each has exactly
1180
1181
  one declaration that answers it:
1181
- 1. CORS unset -> CorsPolicy.allow([...]) or CorsPolicy.disabled(reason=...)
1182
+ 1. CORS unset -> CorsPolicy.from_environment(), .allow([...]) or .disabled(reason=...)
1182
1183
  2. CORS allowing '*' -> name the origins; a wildcard with credentials is no origin check
1183
1184
  3. rate_limit disabled -> RateLimit(requests=..., window_seconds=...)
1184
1185
  4. an override disabled -> an override may LOWER or RAISE a limit, never remove it
1185
1186
  Declining is a full answer and must be said out loud: CorsPolicy.disabled(reason=...)
1186
1187
  is the same-origin deployment's answer, and the reason is the point of it.
1188
+ Which browser origins may call the API is a fact of an environment, not of the source:
1189
+ CorsPolicy.from_environment() takes the allowlist from BACKEND_CORS_ORIGINS when the app
1190
+ is composed (ADR 0210). An environment that names none serves no cross-origin access; an
1191
+ entry that is not an origin (a path, a trailing slash, '*') refuses the boot. Without
1192
+ that declaration the variable opens nothing, and a boot that finds it set says so.
1187
1193
  `terp verify --only production-readiness` asks these before you ship, so the refusal
1188
1194
  arrives in the gate rather than at the deploy.
1189
1195
  - rate_limit_overrides is a PER-PREFIX BUCKET, not a shared counter (ADR 0115):
@@ -1885,88 +1891,7 @@ File objects (files capability, ADR 0056/0057)
1885
1891
  add it to the profile and to the volume's "mount": {"units": [...]}. A store behind
1886
1892
  another adapter needs no volume. `terp guide deployment` has the rest.
1887
1893
  """,
1888
- "capability": """\
1889
- Using capabilities
1890
-
1891
- - Capabilities are opt-in packages (terp-cap-*). Every scaffolded app already has the
1892
- BASE PROFILE — auth, identity, users, groups, access, audit — so authentication,
1893
- accounts, group membership, permission checks and the audit trail are wired before you
1894
- write anything. Install the others you need.
1895
- - WHO IS CALLING, in words a person reads: take `caller: CallerDep` on the route.
1896
- from terp.capabilities.identity import CallerDep
1897
- def pause(name: str, caller: CallerDep, session: SessionDep) -> None:
1898
- service.pause(session, name, decided_by=caller.name)
1899
- `caller.name` is a user's email or a service account's name, read from the live row;
1900
- `caller.id` is the key to store when a record must point at who did it. Never take a
1901
- "decided by" from the request body (it is whatever the client says), and never build
1902
- an IdentityService inside a module to look the caller up.
1903
- - SEE WHAT EXISTS BEFORE YOU BUILD IT:
1904
- terp inspect capabilities
1905
- lists every maintained capability, whether this app already has it, the exact
1906
- `uv add` line and the composition-root wiring it expects. For a capability you
1907
- ALREADY have it also prints `not used here`: wiring points the package exports and
1908
- your source never mentions. That line exists because an installed capability looks
1909
- finished -- so a seam it grows in a later release is invisible from inside the
1910
- project, and at a release every day or two nobody reads the changelog delta. Most
1911
- of what it lists are alternatives you correctly did not take; it is information,
1912
- not a finding. Durable delivery, realtime
1913
- push, tenancy, files, webhooks, scheduling and shared multi-replica state are all
1914
- already solved — hand-rolling one of them is a defect, not a shortcut.
1915
- - A routed capability self-registers: create_app(specs, discover_capabilities=True)
1916
- mounts it at /api/v1/<name> via its entry point — no composition-root edit.
1917
- - A library capability (tenancy, eventbus) ships no router; you import and wire it
1918
- (a mixin/service, a dispatcher) where needed.
1919
- - Compose the app once:
1920
- create_app(specs, principal_provider=..., control_plane=...,
1921
- audit_sink=persist_audit, event_dispatcher=dispatch_in_process,
1922
- permission_enforcer=enforce_permission, discover_capabilities=True)
1923
- - You can always drop to native FastAPI/SQLModel — the same gate rules still apply.
1924
- - Outbound HTTP is a capability concern, never a module concern: importing httpx /
1925
- httpx2 / requests / urllib.request / urllib3 / aiohttp in a module is refused by the
1926
- no_raw_outbound_http rule — SSRF protection, egress allowlists and timeout policy
1927
- belong behind one declared capability, not scattered per call site. That capability
1928
- is `terp-cap-egress`, and it is a declaration rather than a client you configure at
1929
- the call site:
1930
- from terp.capabilities.egress import EgressClient, EgressPolicy
1931
- rates = EgressClient(EgressPolicy(
1932
- allowed_hosts=("api.exchange.example",), # EXACT hosts; empty permits nothing
1933
- timeout_seconds=5.0, # no per-call override, on purpose
1934
- ))
1935
- body = rates.get("https://api.exchange.example/v1/rates").content
1936
- Every resolved address is checked against the SSRF denylist and the connection is
1937
- PINNED to the one that passed (so a rebind between the check and the connect cannot
1938
- land on a private address), redirects are never followed, and every attempt —
1939
- refusals included — reaches the optional `observer=` hook, which is where metering
1940
- and egress auditing attach. A sanctioned internal target is a declared
1941
- `allow_private_addresses=True`, visible in the composition root, never a quiet
1942
- exception inside the client.
1943
- - A vendor SDK builds its own HTTP client, so neither the rule (it reads YOUR imports)
1944
- nor EgressClient sees its traffic. Hold the whole process to the declaration at the
1945
- socket, in the composition root the web process and the worker both run:
1946
- install_egress_guard(EgressGuard.for_policies(
1947
- rates_policy, # every EgressPolicy you declared
1948
- hosts=("api.vendor.example",), # what an SDK calls, by exact name
1949
- infrastructure=("db", "redis", "smtp.relay.internal"), # names, IPs or CIDRs
1950
- ))
1951
- It holds what goes through Python's socket module on IPv4/IPv6, whichever library
1952
- calls it: a lookup of an undeclared name (getaddrinfo, gethostbyname) is refused
1953
- before it is made, and a connect or datagram into a private / loopback / link-local /
1954
- metadata range is refused unless it is declared infrastructure; a peer given by name
1955
- (localhost too) is resolved and every address held. The refusal is EgressRefusedError
1956
- (502); under an async client it can arrive inside an ExceptionGroup. It cannot see
1957
- uvloop, so it refuses to install beside it and refuses `import uvloop` after it: run
1958
- uvicorn with --loop asyncio (uvicorn[standard] picks uvloop otherwise), and a worker
1959
- or scheduler with asyncio.run. Native drivers that open their own sockets (libpq,
1960
- gRPC's C core) are invisible to it and a public IP literal passes; the deployment's
1961
- network policy holds those. Built for Linux: on Windows asyncio's socketpair connects
1962
- to loopback, so a new event loop is refused unless loopback is declared.
1963
- - Credentials never live in module source: a credential-shaped assignment (password,
1964
- api_key, token, ...) to a string literal — or a recognizable secret-token literal
1965
- anywhere — is refused by the no_hardcoded_credentials rule. Wire secrets through
1966
- settings / sealed config (ADR 0055), never source.
1967
- - Sending e-mail is a capability too: `import smtplib` is refused by the same
1968
- no_raw_outbound_http rule, and terp-cap-mail is where it goes — `terp guide mail`.
1969
- """,
1894
+ "capability": guide_capability.TOPIC,
1970
1895
  "mail": """\
1971
1896
  Sending e-mail (terp-cap-mail)
1972
1897
 
@@ -3460,7 +3385,7 @@ def inspect_access(
3460
3385
 
3461
3386
  With ``app`` (a FastAPI instance or zero-arg factory, e.g. ``app.main:build``) the
3462
3387
  graph covers the WHOLE composed surface — every discovered capability router and the
3463
- kernel routes — reconciled against ``app.openapi()`` so no mounted route can hide.
3388
+ kernel routes — reconciled against the composed route table so no served route can hide.
3464
3389
  Without it, the focused form reports just the hand-passed ``modules``.
3465
3390
 
3466
3391
  The three-layer view — module policy, per-endpoint requirement, and the data
@@ -3570,7 +3495,7 @@ def _render_json(plane: ControlPlane, specs: Sequence[ModuleSpec]) -> str:
3570
3495
  "relaxed_reason": plane.passwords.relaxed_reason,
3571
3496
  },
3572
3497
  "security": {
3573
- "cors": _cors_json(plane.security.cors),
3498
+ "cors": cors_json(plane.security.cors),
3574
3499
  "rate_limit": {
3575
3500
  "enabled": plane.security.rate_limit.enabled,
3576
3501
  "requests": plane.security.rate_limit.requests,
@@ -3596,19 +3521,6 @@ def _render_json(plane: ControlPlane, specs: Sequence[ModuleSpec]) -> str:
3596
3521
  return json.dumps(payload, indent=2)
3597
3522
 
3598
3523
 
3599
- def _cors_json(cors: CorsPolicy) -> dict[str, object]:
3600
- """The CORS declaration as one of three explicit modes (never raw fields)."""
3601
- if cors.disabled_reason is not None:
3602
- return {"mode": "disabled", "reason": cors.disabled_reason}
3603
- if cors.allow_origins:
3604
- return {
3605
- "mode": "allow",
3606
- "origins": list(cors.allow_origins),
3607
- "allow_credentials": cors.allow_credentials,
3608
- }
3609
- return {"mode": "deny-all", "configured": cors.configured}
3610
-
3611
-
3612
3524
  def _module_json(spec: ModuleSpec) -> dict[str, object]:
3613
3525
  policy: dict[str, object] | None = None
3614
3526
  if spec.policy is not None:
@@ -3674,7 +3586,7 @@ def _render_text(plane: ControlPlane, specs: Sequence[ModuleSpec]) -> str:
3674
3586
  lines.append(password_line)
3675
3587
  lines.append("")
3676
3588
  lines.append("Security")
3677
- lines.append(f" cors {_cors_label(plane.security.cors)}")
3589
+ lines.append(f" cors {cors_label(plane.security.cors)}")
3678
3590
  rate_limit = plane.security.rate_limit
3679
3591
  lines.append(
3680
3592
  " rate_limit "
@@ -3700,14 +3612,6 @@ def _render_text(plane: ControlPlane, specs: Sequence[ModuleSpec]) -> str:
3700
3612
  return "\n".join(lines)
3701
3613
 
3702
3614
 
3703
- def _cors_label(cors: CorsPolicy) -> str:
3704
- if cors.disabled_reason is not None:
3705
- return f"disabled ({cors.disabled_reason})"
3706
- if cors.allow_origins:
3707
- return "allow " + ", ".join(cors.allow_origins)
3708
- return "deny-all" + ("" if cors.configured else " (unconfigured)")
3709
-
3710
-
3711
3615
  def _policy_label(spec: ModuleSpec) -> str:
3712
3616
  if spec.policy is None:
3713
3617
  return "policy=<missing>"
@@ -3842,7 +3746,7 @@ def _build_parser() -> argparse.ArgumentParser:
3842
3746
  "--app",
3843
3747
  default=None,
3844
3748
  help="Composed FastAPI app or factory (e.g. app.main:build): report the WHOLE "
3845
- "mounted surface incl. discovered capabilities, reconciled against app.openapi()",
3749
+ "mounted surface incl. discovered capabilities, reconciled against the route table",
3846
3750
  )
3847
3751
  access_parser.add_argument(
3848
3752
  "--app-root",
@@ -0,0 +1,38 @@
1
+ """The CORS declaration as ``terp inspect control-plane`` shows it: one explicit mode."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from terp.core import CorsPolicy
6
+
7
+
8
+ def cors_json(cors: CorsPolicy) -> dict[str, object]:
9
+ """The CORS declaration as one of four explicit modes (never raw fields)."""
10
+ if cors.disabled_reason is not None:
11
+ return {"mode": "disabled", "reason": cors.disabled_reason}
12
+ if cors.origins_from_environment:
13
+ # The origins are each environment's own: what is listed is what this process
14
+ # was composed with, so a plane inspected before create_app lists none.
15
+ return {
16
+ "mode": "from-environment",
17
+ "variable": "BACKEND_CORS_ORIGINS",
18
+ "origins": list(cors.allow_origins),
19
+ "allow_credentials": cors.allow_credentials,
20
+ }
21
+ if cors.allow_origins:
22
+ return {
23
+ "mode": "allow",
24
+ "origins": list(cors.allow_origins),
25
+ "allow_credentials": cors.allow_credentials,
26
+ }
27
+ return {"mode": "deny-all", "configured": cors.configured}
28
+
29
+
30
+ def cors_label(cors: CorsPolicy) -> str:
31
+ if cors.disabled_reason is not None:
32
+ return f"disabled ({cors.disabled_reason})"
33
+ if cors.origins_from_environment:
34
+ named = ", ".join(cors.allow_origins) or "none named here"
35
+ return f"from BACKEND_CORS_ORIGINS ({named})"
36
+ if cors.allow_origins:
37
+ return "allow " + ", ".join(cors.allow_origins)
38
+ return "deny-all" + ("" if cors.configured else " (unconfigured)")
@@ -30,8 +30,8 @@ import json
30
30
  from collections.abc import Sequence
31
31
 
32
32
  from fastapi import FastAPI
33
- from fastapi.routing import APIRoute
34
- from starlette.routing import Mount, Route
33
+ from fastapi.routing import APIRoute, APIWebSocketRoute, iter_route_contexts
34
+ from starlette.routing import Mount, Route, WebSocketRoute
35
35
 
36
36
  from terp.core import (
37
37
  ActorStampedMixin,
@@ -49,13 +49,6 @@ from terp.core.scoping import registered_scope_predicates
49
49
  # kernel / open route (e.g. health), not part of any module's policy surface.
50
50
  _API_PREFIX = "/api/v1/"
51
51
 
52
- # OpenAPI path-item keys that are HTTP operations (the rest are metadata such as
53
- # ``parameters`` / ``summary``) — used to read the served methods for each path.
54
- _HTTP_METHODS = frozenset(
55
- {"get", "put", "post", "delete", "options", "head", "patch", "trace"}
56
- )
57
-
58
-
59
52
  def _mro_names(model: type) -> set[str]:
60
53
  return {klass.__name__ for klass in model.__mro__}
61
54
 
@@ -201,25 +194,46 @@ def _undeclared_subscriber_alarms(specs: Sequence[ModuleSpec]) -> list[dict[str,
201
194
  ]
202
195
 
203
196
 
204
- def _served_routes(app: FastAPI) -> dict[str, frozenset[str]]:
205
- """Every path the composed app serves -> its HTTP methods, from ``app.openapi()``.
197
+ #: What a served WebSocket route is listed under: it has no HTTP method after the upgrade.
198
+ _WEBSOCKET = "WS"
199
+
206
200
 
207
- ``app.openapi()`` is the same document ``terp openapi`` exports and FastAPI serves,
208
- so it is the authoritative, full-path route table — client module routers, every
209
- discovered capability router, and the kernel health routes — the ground truth the
210
- access graph is reconciled against.
201
+ def _served_routes(app: FastAPI) -> dict[str, frozenset[str]]:
202
+ """Every path the composed app serves -> its HTTP methods, from the route table itself.
203
+
204
+ The table the router answers from, walked through every included router at the path
205
+ each route is really served under (``iter_route_contexts``, which FastAPI's own schema
206
+ generation walks). It used to be ``app.openapi()``, and a route declared with
207
+ ``include_in_schema=False`` is not in that document: one on a router included inside
208
+ a module's router was served, was in no module's endpoints, and was reconciled
209
+ against a document that did not list it, so nothing reported it. A WebSocket route,
210
+ which the document never lists, is in the table too, under :data:`_WEBSOCKET`.
211
+
212
+ Outside ``/api/v1`` only an ``APIRoute`` is listed here: the plain routes and the
213
+ mounts there are :func:`_schema_hidden_routes`'s, reported with their own note.
211
214
  """
212
- paths: dict[str, object] = app.openapi().get("paths", {})
213
- return {
214
- path: frozenset(
215
- method.upper() for method in item if method.lower() in _HTTP_METHODS
216
- )
217
- for path, item in paths.items()
218
- }
215
+ served: dict[str, set[str]] = {}
216
+ for context in iter_route_contexts(app.routes):
217
+ route = context.original_route
218
+ path = context.path or ""
219
+ if isinstance(route, APIRoute):
220
+ methods = set(context.methods or ())
221
+ elif not path.startswith(_API_PREFIX):
222
+ continue
223
+ elif isinstance(route, APIWebSocketRoute | WebSocketRoute):
224
+ methods = {_WEBSOCKET}
225
+ elif isinstance(route, Mount):
226
+ path, methods = f"{path}/*", {"*"}
227
+ else:
228
+ # A plain route, or a kind this walk does not know: served under the API
229
+ # prefix, so listed, with every method when it names none.
230
+ methods = set(getattr(route, "methods", None) or {"*"})
231
+ served.setdefault(path, set()).update(method.upper() for method in methods)
232
+ return {path: frozenset(methods) for path, methods in served.items()}
219
233
 
220
234
 
221
235
  def _schema_hidden_routes(app: FastAPI) -> list[dict[str, object]]:
222
- """Reachable top-level routes ``app.openapi()`` does NOT list — still reported.
236
+ """Reachable top-level routes that are no API route — still reported.
223
237
 
224
238
  FastAPI's own docs/schema endpoints (``/openapi.json`` / ``/docs`` / ``/redoc``,
225
239
  plain starlette ``Route``s with ``include_in_schema=False``) and any ``app.mount()``
@@ -229,7 +243,7 @@ def _schema_hidden_routes(app: FastAPI) -> list[dict[str, object]]:
229
243
  hidden: list[dict[str, object]] = []
230
244
  for route in app.routes:
231
245
  if isinstance(route, APIRoute):
232
- continue # schema-visible; reconciled via app.openapi()
246
+ continue # an API route: listed by _served_routes, in the schema or not
233
247
  if isinstance(route, Mount):
234
248
  hidden.append(
235
249
  {
@@ -256,7 +270,8 @@ def build_access_graph_for_app(app: FastAPI) -> dict[str, object]:
256
270
  ``create_app`` records the specs it mounted (client modules AND every discovered
257
271
  capability router) and its control plane on ``app.state``; this reads them back so
258
272
  the graph covers routes a hand-passed ``--module`` list would miss. It then
259
- reconciles the graph against ``app.openapi()`` (the ground truth): every served
273
+ reconciles the graph against the composed route table (the ground truth, which holds
274
+ a route the OpenAPI document was told to leave out): every served
260
275
  ``/api/v1`` method must map to a module endpoint — any that does not is reported
261
276
  under ``omitted_routes`` (fail-visible, so a mounted route can never hide) — and the
262
277
  served routes outside ``/api/v1`` (the unauthenticated kernel health routes), the
@@ -299,14 +314,18 @@ def build_access_graph_for_app(app: FastAPI) -> dict[str, object]:
299
314
  modules: list = graph["modules"] # type: ignore[assignment]
300
315
  for module in modules:
301
316
  for endpoint in module["endpoints"]:
302
- covered.setdefault(endpoint["path"], set()).update(endpoint["methods"])
317
+ # A WebSocket endpoint carries no methods; it covers the served WebSocket.
318
+ covered.setdefault(endpoint["path"], set()).update(endpoint["methods"] or [_WEBSOCKET])
303
319
  omitted: list[dict[str, object]] = []
304
320
  for path, methods in sorted(served.items()):
305
321
  if not path.startswith(_API_PREFIX):
306
322
  continue
307
- missing = sorted(methods - covered.get(path, set()))
308
- if missing:
309
- omitted.append({"path": path, "methods": missing})
323
+ missing = methods - covered.get(path, set())
324
+ if missing - {_WEBSOCKET}:
325
+ omitted.append({"path": path, "methods": sorted(missing - {_WEBSOCKET})})
326
+ if _WEBSOCKET in missing:
327
+ # No methods, as a module's own WebSocket endpoint has none.
328
+ omitted.append({"path": path, "methods": []})
310
329
  graph["omitted_routes"] = omitted
311
330
  return graph
312
331