terp-cli 0.42.0__tar.gz → 0.43.0__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 (103) hide show
  1. {terp_cli-0.42.0 → terp_cli-0.43.0}/PKG-INFO +9 -9
  2. {terp_cli-0.42.0 → terp_cli-0.43.0}/pyproject.toml +9 -9
  3. {terp_cli-0.42.0 → terp_cli-0.43.0}/signer/Dockerfile +3 -3
  4. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/__init__.py +24 -298
  5. terp_cli-0.43.0/src/terp/cli/audit_findings.py +142 -0
  6. terp_cli-0.43.0/src/terp/cli/dependency_risk.py +167 -0
  7. terp_cli-0.43.0/src/terp/cli/dependency_scan.py +110 -0
  8. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/envschema.py +2 -0
  9. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/guide_deployment.py +20 -12
  10. terp_cli-0.43.0/src/terp/cli/guide_files.py +102 -0
  11. terp_cli-0.43.0/src/terp/cli/guide_maintenance.py +134 -0
  12. terp_cli-0.43.0/src/terp/cli/guide_migrations.py +216 -0
  13. terp_cli-0.43.0/src/terp/cli/maintenance/__init__.py +203 -0
  14. terp_cli-0.43.0/src/terp/cli/maintenance/_images.py +156 -0
  15. terp_cli-0.43.0/src/terp/cli/maintenance/_packages.py +270 -0
  16. terp_cli-0.43.0/src/terp/cli/maintenance/_platform.py +330 -0
  17. terp_cli-0.43.0/src/terp/cli/maintenance/_report.py +210 -0
  18. terp_cli-0.43.0/src/terp/cli/maintenance/_vulnerabilities.py +357 -0
  19. terp_cli-0.43.0/src/terp/cli/python_audit.py +62 -0
  20. terp_cli-0.43.0/src/terp/cli/release/_archives.py +67 -0
  21. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/_common.py +70 -9
  22. terp_cli-0.43.0/src/terp/cli/release/_history.py +203 -0
  23. terp_cli-0.43.0/src/terp/cli/release/_image.py +448 -0
  24. terp_cli-0.43.0/src/terp/cli/release/_migrations.py +378 -0
  25. terp_cli-0.43.0/src/terp/cli/release/_osv.py +126 -0
  26. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/_plan.py +20 -10
  27. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/_render.py +102 -16
  28. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/_sandbox.py +38 -43
  29. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/cli.py +13 -3
  30. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/dsse.py +9 -9
  31. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/gate.py +75 -17
  32. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/manifest.py +31 -9
  33. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/promote.py +104 -21
  34. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/sign.py +148 -10
  35. terp_cli-0.43.0/src/terp/cli/risk_authority.py +97 -0
  36. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/scaffold.py +50 -123
  37. terp_cli-0.43.0/src/terp/cli/scaffold_frontend.py +101 -0
  38. terp_cli-0.43.0/src/terp/cli/upgrade_recipes.py +157 -0
  39. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/verify.py +18 -39
  40. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/version.py +9 -123
  41. terp_cli-0.42.0/src/terp/cli/release/_image.py +0 -199
  42. {terp_cli-0.42.0 → terp_cli-0.43.0}/.gitignore +0 -0
  43. {terp_cli-0.42.0 → terp_cli-0.43.0}/signer/terp-arch-releases.json +0 -0
  44. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/_appref.py +0 -0
  45. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/_cors_view.py +0 -0
  46. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/_engine.py +0 -0
  47. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/_output.py +0 -0
  48. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/_subjects.py +0 -0
  49. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/access.py +0 -0
  50. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/api_contract.py +0 -0
  51. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/api_contract_bounds.py +0 -0
  52. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/api_contract_check.py +0 -0
  53. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/api_contract_schemas.py +0 -0
  54. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/api_contract_shapes.py +0 -0
  55. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/apidocs.py +0 -0
  56. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/authz_surface.py +0 -0
  57. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/capabilities.py +0 -0
  58. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/dependency_audit.py +0 -0
  59. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/deploy_safety.py +0 -0
  60. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/deployment_adopt.py +0 -0
  61. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/deployment_app.py +0 -0
  62. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/deployment_check.py +0 -0
  63. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/deployment_declare.py +0 -0
  64. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/deployment_render.py +0 -0
  65. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/dev.py +0 -0
  66. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/docker.py +0 -0
  67. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/docker_masks.py +0 -0
  68. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/envfile.py +0 -0
  69. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/envrequired.py +0 -0
  70. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/envseams.py +0 -0
  71. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/fmt.py +0 -0
  72. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/grants.py +0 -0
  73. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/guide_capability.py +0 -0
  74. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/guide_passwords.py +0 -0
  75. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/heartbeat.py +0 -0
  76. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/jobs.py +0 -0
  77. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/leases.py +0 -0
  78. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/locks.py +0 -0
  79. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/module_roles.py +0 -0
  80. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/npm_tree.py +0 -0
  81. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/openapi.py +0 -0
  82. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/outbox.py +0 -0
  83. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/ports.py +0 -0
  84. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/profiles.py +0 -0
  85. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/py.typed +0 -0
  86. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/__init__.py +0 -0
  87. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/_compare.py +0 -0
  88. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/_dockerfile.py +0 -0
  89. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/_git.py +0 -0
  90. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/_locks.py +0 -0
  91. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/_npm_lock.py +0 -0
  92. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/_registry.py +0 -0
  93. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/release/build.py +0 -0
  94. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/reseal.py +0 -0
  95. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/reseal_report.py +0 -0
  96. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/routes.py +0 -0
  97. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/schema.py +0 -0
  98. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/seed.py +0 -0
  99. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/service_accounts.py +0 -0
  100. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/smoke.py +0 -0
  101. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/users.py +0 -0
  102. {terp_cli-0.42.0 → terp_cli-0.43.0}/src/terp/cli/workbench.py +0 -0
  103. {terp_cli-0.42.0 → terp_cli-0.43.0}/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.42.0
3
+ Version: 0.43.0
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.42.0
11
- Requires-Dist: terp-core==0.42.0
12
- Requires-Dist: terp-migrations==0.42.0
10
+ Requires-Dist: terp-arch==0.43.0
11
+ Requires-Dist: terp-core==0.43.0
12
+ Requires-Dist: terp-migrations==0.43.0
13
13
  Provides-Extra: jobs
14
- Requires-Dist: terp-cap-outbox==0.42.0; extra == 'jobs'
15
- Requires-Dist: terp-cap-scheduler-apscheduler==0.42.0; extra == 'jobs'
14
+ Requires-Dist: terp-cap-outbox==0.43.0; extra == 'jobs'
15
+ Requires-Dist: terp-cap-scheduler-apscheduler==0.43.0; 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.42.0; extra == 'release'
19
+ Requires-Dist: terp-cap-egress==0.43.0; extra == 'release'
20
20
  Provides-Extra: scheduler
21
- Requires-Dist: terp-cap-scheduler-apscheduler==0.42.0; extra == 'scheduler'
21
+ Requires-Dist: terp-cap-scheduler-apscheduler==0.43.0; extra == 'scheduler'
22
22
  Provides-Extra: worker
23
- Requires-Dist: terp-cap-outbox==0.42.0; extra == 'worker'
23
+ Requires-Dist: terp-cap-outbox==0.43.0; extra == 'worker'
@@ -4,18 +4,18 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "terp-cli"
7
- version = "0.42.0"
7
+ version = "0.43.0"
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.42.0",
12
+ "terp-core==0.43.0",
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.42.0",
15
+ "terp-migrations==0.43.0",
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.42.0",
18
+ "terp-arch==0.43.0",
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.42.0"]
33
- scheduler = ["terp-cap-scheduler-apscheduler==0.42.0"]
32
+ worker = ["terp-cap-outbox==0.43.0"]
33
+ scheduler = ["terp-cap-scheduler-apscheduler==0.43.0"]
34
34
  jobs = [
35
- "terp-cap-outbox==0.42.0",
36
- "terp-cap-scheduler-apscheduler==0.42.0",
35
+ "terp-cap-outbox==0.43.0",
36
+ "terp-cap-scheduler-apscheduler==0.43.0",
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.42.0",
45
+ "terp-cap-egress==0.43.0",
46
46
  ]
47
47
 
48
48
  [project.scripts]
@@ -25,8 +25,8 @@
25
25
  # release lane's, is reached with `--network host`. The release lane runs it exactly so
26
26
  # (tests/release_lane/).
27
27
 
28
- # python:3.14-slim, the base-image table's interpreter (terp-arch's base-images.json).
29
- FROM python@sha256:9aaa474097d094040649f2162a627c0049b408f52138d980916788d80f04802f AS install
28
+ # python:3.15-slim, the base-image table's interpreter (terp-arch's base-images.json).
29
+ FROM python@sha256:65a65fc7b30b06cb6df4930fd4650697cb23f4c2698ab81fc87e4b031bc36928 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:9aaa474097d094040649f2162a627c0049b408f52138d980916788d80f04802f
44
+ FROM python@sha256:65a65fc7b30b06cb6df4930fd4650697cb23f4c2698ab81fc87e4b031bc36928
45
45
  RUN apt-get update \
46
46
  && apt-get install -y --no-install-recommends git \
47
47
  && rm -rf /var/lib/apt/lists/* \
@@ -58,7 +58,14 @@ from terp.cli.module_roles import (
58
58
  module_role_list_command,
59
59
  module_role_revoke_command,
60
60
  )
61
- from terp.cli import guide_capability, guide_deployment, guide_passwords
61
+ from terp.cli import (
62
+ guide_capability,
63
+ guide_deployment,
64
+ guide_files,
65
+ guide_maintenance,
66
+ guide_migrations,
67
+ guide_passwords,
68
+ )
62
69
  from terp.cli.grants import (
63
70
  grant_add_command,
64
71
  grant_list_command,
@@ -1818,79 +1825,7 @@ Realtime push (realtime capability)
1818
1825
  carries 3s and takes --shutdown-timeout. Yours must be under whatever stops your
1819
1826
  container, or the bound never takes effect. ADR 0108.
1820
1827
  """,
1821
- "files": """\
1822
- File objects (files capability, ADR 0056/0057)
1823
-
1824
- - Upload/download/list/rename/delete ride the admin-only discovered router at
1825
- /api/v1/files; File composes OwnedMixin, so rename/delete are owner-gated centrally.
1826
- - Bytes live behind the StorageBackend port (put/open/delete, streamed via file-like
1827
- objects, and open_range for a Range request: its default reads forward to the offset, so an
1828
- adapter whose store reads a range overrides it) in a NAMED-PROFILE registry;
1829
- metadata (name, type, size, sha256, storage_key, storage_profile) lives in the platform
1830
- DB. FileRead omits storage_key and storage_profile, and the API's routes never show them;
1831
- a store's signed link carries the key as its URL path, which opens nothing on a private
1832
- store without the signature.
1833
- - Any provider is an adapter subclass (local ships; a NAS mount is the local adapter on
1834
- another root). Two object-store adapters ship behind extras (ADR 0201): S3Storage
1835
- (terp-cap-files[s3]) takes the SDK's own client and a bucket; AzureBlobStorage
1836
- (terp-cap-files[azure]) takes the SDK's ContainerClient and, for user-delegation SAS
1837
- links, a BlobServiceClient under an Entra credential. Register each store once at the
1838
- composition root:
1839
- register_storage_backend("s3-media", S3Storage(boto3.client("s3"), bucket="app-media"))
1840
- register_storage_backend("azure-invoices", AzureBlobStorage(invoices_container))
1841
- register_storage_backend("azure-hr", AzureBlobStorage(hr_container, delegation=service))
1842
- Keep credentials in settings / sealed config — never in module code. Building the Azure
1843
- adapter without its extra fails at boot with the install line (StorageSdkMissingError);
1844
- the S3 adapter takes the SDK's client, so a missing extra fails where that is built.
1845
- - A client that cannot send a bearer (an <audio>/<video> element, a PDF viewer, a native
1846
- client's media stack) gets a short-lived LINK to one file's bytes instead (ADR 0201):
1847
- GET /api/v1/files/{id}/link?ttl_seconds=600&inline=true -> {url, expires_at}
1848
- The link is minted where a download is authorized (row scope, then quarantine), by the
1849
- store the ROW names: an S3 presigned GET or an Azure SAS where the store can sign, else
1850
- an app-signed token the capability serves itself at GET /api/v1/files/link/{token} —
1851
- its one public route, rate-limited, answering 404 to an expired, altered or foreign
1852
- token. The default lifetime is an hour, the longest 24 hours; a link is not single-use
1853
- (a player makes many range requests), its expiry is the control. inline is honoured only
1854
- for a type a browser renders without running it (image, audio, video, PDF — not an XML
1855
- image such as SVG, which is a document with script in it). From a module, mint through
1856
- your own authorized row and a declared FileRef:
1857
- link = FileService().link_for(session, invoice, "attachment_file_id", ttl=timedelta(minutes=10))
1858
- Both content routes honour one bytes= Range (206 / 416); the local adapter seeks, an
1859
- object store's stream is read forward. A link from a store that signs never streams
1860
- through the API; the authenticated content route still serves any store's bytes to a
1861
- caller who asks it to.
1862
- - Pick the store per module (subclass default) or per call — never from a client:
1863
- class InvoiceFileService(FileService):
1864
- storage_profile = "azure-invoices"
1865
- service.store(session, filename=..., content_type=..., source=..., profile="azure-hr")
1866
- Resolution is FAIL-CLOSED: an unknown profile raises (UnknownStorageProfileError)
1867
- before any byte lands; load/remove always resolve the store the ROW itself names.
1868
- - Uploads stream (never fully buffered) under a 25 MiB default cap; the files spec
1869
- declares its own request-body allowance so the kernel's global max_request_bytes
1870
- (1 MiB default) is lifted for /api/v1/files ONLY (ADR 0067). Retune per deployment
1871
- with two composition-root lines (the request allowance must exceed the stored cap
1872
- by multipart framing headroom):
1873
- configure_upload_limit(100 * 1024 * 1024)
1874
- create_app(..., request_size_overrides={"files": 100 * 1024 * 1024 + 65536})
1875
- - Content types are allowed by default (descriptive metadata); a deployment narrows
1876
- uploads to an allowlist with one composition-root line — enforced in the service
1877
- chokepoint (typed 415, before any byte lands), so no upload path can bypass it:
1878
- configure_allowed_content_types(["application/pdf", "image/*"])
1879
- - Referencing a file from your own model? Declare it — never a bare uuid column (the
1880
- no_raw_file_references rule enforces this on table models):
1881
- class Invoice(BaseTable, table=True):
1882
- attachment_file_id: uuid.UUID | None = FileRef()
1883
- Serve it THROUGH your own already-authorized row (serve-through delegation): load the
1884
- invoice via your own service (its policy + row scope decide visibility), then
1885
- row, data = FileService().load_for(session, invoice, "attachment_file_id")
1886
- load_for fail-closes on an undeclared reference; /api/v1/files itself stays ADMIN-only.
1887
- - The local profile's bytes need a volume in production, or they live in the container and
1888
- go with it. The template's production profile (use_files) mounts the files-data volume at
1889
- var/files on api, and deployment.json declares it with its backup policy, so a deploy tool
1890
- backs it up. A unit of your own that reads stored bytes (a worker) mounts the same volume:
1891
- add it to the profile and to the volume's "mount": {"units": [...]}. A store behind
1892
- another adapter needs no volume. `terp guide deployment` has the rest.
1893
- """,
1828
+ "files": guide_files.TOPIC,
1894
1829
  "capability": guide_capability.TOPIC,
1895
1830
  "mail": """\
1896
1831
  Sending e-mail (terp-cap-mail)
@@ -1999,193 +1934,7 @@ Sending e-mail (terp-cap-mail)
1999
1934
  same place: configure_mail(settings, transport=<a callable built on
2000
1935
  terp.capabilities.egress>). Call sites stay send_mail either way.
2001
1936
  """,
2002
- "migrations": """\
2003
- Database migrations (terp migrate)
2004
-
2005
- - Each table-owning package (capability or app module) owns an INDEPENDENT, linear
2006
- Alembic history with its own alembic_version_<label> table - no shared graph and no
2007
- CROSS-package merges. Terp discovers them; you never hand-write env.py.
2008
- - Author a revision after changing a model (autogenerated, scoped to that package so
2009
- it never proposes another package's tables):
2010
- terp migrate make <label> -m "add invoice.status" # <label> e.g. invoices
2011
- Autogenerate DIFFS A LIVE DATABASE AT HEAD, so it needs two things the default
2012
- environment does not give you: a database that outlives the process (the settings
2013
- default is in-memory SQLite) and one that is already at head (a fresh file database
2014
- is behind). Both, in one paste, with a throwaway file you delete afterwards:
2015
- DATABASE_URL="sqlite:///./.migrate-scratch.db" terp migrate upgrade
2016
- DATABASE_URL="sqlite:///./.migrate-scratch.db" terp migrate make <label>
2017
- (PowerShell: $env:DATABASE_URL='sqlite:///./.migrate-scratch.db')
2018
- Point it at your real Postgres URL instead when the revision must diff against real
2019
- schema, or pass --no-autogenerate to author an empty revision by hand.
2020
- Cross-module / cross-package foreign keys just work: every package's models are
2021
- imported so an FK target (a sibling module, or identity_user) resolves at make time,
2022
- and upgrade is ordered by FK dependencies so a referenced table is always created
2023
- before the table that references it - regardless of label ordering. (A cross-package
2024
- FK *cycle* cannot be ordered and fails closed; break it with a nullable FK populated
2025
- in a later migration.)
2026
- - Apply / inspect / walk back across every package:
2027
- terp migrate upgrade # each package to head (run on deploy)
2028
- terp migrate upgrade --sql > release.sql # render DBA-reviewable offline SQL
2029
- # instead (nothing connects; flat layout)
2030
- terp migrate status # current-vs-head per package
2031
- terp migrate check # exit 0 only at head or inside the window
2032
- terp migrate downgrade # every package back to base (or -N)
2033
- terp migrate downgrade --label notes --revision <rev> # one package only
2034
- A concrete revision is package-specific, so the all-package downgrade takes only
2035
- base or a relative -N; pass --label to roll one package to any of its own revisions.
2036
- A downgrade is for walking a history back while developing. A production rollback
2037
- never migrates (next point).
2038
- - ROLLING BACK A RELEASE (ADR 0185). Each revision says whether it is expand-only:
2039
- expand_only = True # the previous release still runs on the schema this leaves
2040
- `terp migrate make` always writes `expand_only = False` (a contract revision), and adds
2041
- a comment where every operation it generated is on the expand list. Raise the mark
2042
- yourself, once the previous release may run without what the revision adds: a NOT NULL
2043
- scan state with a default, or a token epoch, is on the list and still carries a
2044
- restriction a rollback would drop. The expand list is closed: create_table (a key from
2045
- it only with CASCADE or SET NULL, never onto a soft-deleted table) and bulk_insert into
2046
- it; add_column that is nullable, has a server_default or is Computed, with no unique, no
2047
- check and at most a SET NULL key on a nullable column; create_index that is not unique;
2048
- a batch block of those, never recreate="always". Anything else (a drop, a rename,
2049
- tightening, execute(), a statement through op.get_bind(), a back-fill of an existing
2050
- table) is refused by `terp check` (expand_revisions_only_expand, no opt-out) and again
2051
- by the migration run, before its DDL. A back-fill runs as a job: the expand release
2052
- already handles rows it has not filled.
2053
- When every revision release N applied is expand-only, release N-1 starts again on N's
2054
- database: its boot guard admits a database one migration run ahead (it logs which
2055
- revisions it runs behind), and its `migrate` finds nothing to apply and runs no DDL. The
2056
- rollback check is the target's own `terp migrate check`, run from the target's image
2057
- against the live database: exit 0 is restore-free, anything else is a restore. Two
2058
- expanding releases in a row are one too many, a contract revision or another Terp
2059
- version is never crossed, and a migration applied from an offline script is not in
2060
- the record, so each of those rolls back by restore.
2061
- Until the contract release, N keeps writing the old shape N-1 reads, treats it as the
2062
- truth for what N-1 writes (compute a derived value on read, or make it a generated
2063
- column), and handles NULL in its new columns.
2064
- Every release after a rollback keeps N's revision files and the model fields and tables
2065
- they create, and reverts behaviour only; removing them is a later contract release. A
2066
- release cut from N-1 that adds a revision of its own is refused by `migrate`.
2067
- - CONTRACT STEPS GO INTO A LATER RELEASE than the one that expanded: drop, rename or
2068
- tighten once nothing in the release before still needs the old shape. A release that
2069
- mixes expand and contract revisions is legal and rolls back by restore.
2070
- - Removing a module or capability from the app RETIRES it, in the same release: list its
2071
- label in <app root>/modules/__init__.py, read without importing the app,
2072
- RETIRED_MIGRATIONS = ("invoices",)
2073
- a literal tuple of strings (anything else refuses). Its tables stay yours. A package
2074
- that comes back takes a new label.
2075
- - Two developers branched the same package? Resolve the within-package divergence:
2076
- terp migrate heads # more than one head = diverged
2077
- terp migrate merge <label> -m "merge"
2078
- Before a release, re-parent one unreleased revision onto the other instead: a merge
2079
- revision is a contract revision.
2080
- - Locks: `migrate` runs before `api` is recreated, so the previous release still serves
2081
- while it runs. A create_index without postgresql_concurrently (inside
2082
- op.get_context().autocommit_block()), a volatile default and a generated column (stored,
2083
- so the table is rewritten) hold a lock that long; on a large table compute a derived
2084
- value on read. A new child table of a soft-deleted parent is a contract revision:
2085
- neither CASCADE nor SET NULL can fire onto it.
2086
- - A STEP THAT IS SAFE ONLY AGAINST AN EMPTY DATABASE is refused by `terp check`
2087
- (`no_destructive_migrations`). A deploy migrates while the previous release still
2088
- serves, and a rollback runs that release on the migrated schema, so a revision has two
2089
- audiences your scratch database never shows: the rows production holds, and the
2090
- release still running. Five kinds of step fail one of them:
2091
- drop drop_table / drop_column / TRUNCATE / DELETE FROM / DROP SCHEMA
2092
- rename rename_table / alter_column(new_column_name=...) / ALTER TABLE .. RENAME
2093
- type change alter_column(type_=...) / ALTER COLUMN .. TYPE
2094
- NOT NULL alter_column(nullable=False) on an existing table / SET NOT NULL
2095
- constraint create_unique_constraint / create_check_constraint /
2096
- create_foreign_key / create_primary_key / create_index(unique=True) /
2097
- ADD CONSTRAINT / CREATE UNIQUE INDEX / VALIDATE CONSTRAINT
2098
- on `op`, a batch block or any alias, imported by name (from alembic.op import
2099
- drop_column) or looked up by a literal getattr, in upgrade() and in every function of
2100
- the revision it calls, and through execute(...) whenever the statement is readable in
2101
- the source, one statement at a time. Do this instead, and every finding says which:
2102
- EXPAND (add the new column, nullable, or the new table beside the old one), BACKFILL
2103
- (copy or clean the rows with a job, not a statement in the revision, and write both),
2104
- then CONTRACT in a LATER release (drop the old name, tighten, add the constraint). The
2105
- contract step is the destructive one, so it carries
2106
- `# arch-allow-no-destructive-migrations: <reason>` on (or immediately above) its line,
2107
- after review, budgeted by the escape-hatch ratchet. Not refused: anything on a table
2108
- this upgrade() creates (it holds no rows yet), and a unique, foreign-key or
2109
- unique-index constraint on columns this upgrade() adds nullable with no server_default
2110
- (every existing row holds NULL, which those accept) - the shape autogenerate writes for
2111
- a new reference column. Not refused is not the same as an expand step: a constraint on
2112
- an existing table, or any execute(), is never one. A type WIDENING is still reported,
2113
- because nothing in the revision says what the old type was: justify it with the marker.
2114
- - ADDING A NOT NULL COLUMN is the revision that passes everything you can run and then
2115
- fails in production. For a new non-nullable field autogenerate writes
2116
- `add_column(sa.Column('rank', sa.Integer(), nullable=False))`, and that statement
2117
- succeeds against an empty database and fails against one that holds rows - the rows
2118
- already there need a value it never supplies. Nothing local catches it, because a
2119
- migration test upgrades a FRESH scratch database, where the statement is correct.
2120
- Give the column a server_default and the database back-fills the existing rows as it
2121
- adds it; new rows still take the model-side default:
2122
- op.add_column('note', sa.Column('rank', sa.Integer(), nullable=False,
2123
- server_default='0'))
2124
- Where no literal default is right, expand/contract instead - add the column nullable,
2125
- back-fill it with a job in the same release, tighten it in a LATER release (that
2126
- tightening is a contract step: it takes the destructive-migration marker above). `terp check`
2127
- refuses the unbackfilled form (`not_null_columns_are_backfilled`); a table that
2128
- genuinely holds no rows yet opts out with
2129
- `# arch-allow-not-null-columns-are-backfilled: <reason>`.
2130
- - MOVING A MODEL TO ANOTHER MODULE is the one edit that looks free and is not. Just
2131
- moving the class emits NO ddl at all - the losing package stops owning the table so
2132
- its scoped autogenerate cannot propose a drop, and the gaining package diffs against
2133
- a database where the table already exists so it proposes no create. Your database
2134
- keeps upgrading; CI and staging stay green. Then the NEXT ordinary change to that
2135
- model (an added column) is authored into the gaining package's INDEPENDENT history,
2136
- which - with no foreign key between the two packages - a fresh install may run
2137
- BEFORE the history that creates the table: "no such table", months later, in a new
2138
- environment, blamed on an innocent add_column. Terp refuses the split at `terp
2139
- migrate make` and in the build-time guard. Move a table properly, expand/contract:
2140
- 1. Give the new module its own model with its own __tablename__;
2141
- `terp migrate make <new>` creates it.
2142
- 2. Copy the rows in that same release (a data migration, or a backfill job),
2143
- and write to both tables while the old one still has readers.
2144
- 3. In a LATER release, once nothing reads the old table, drop it - with
2145
- `# arch-allow-no-destructive-migrations: <reason>` and a human reviewer.
2146
- Step 3 stays human-reviewed on purpose: dropping a populated table is a genuine,
2147
- irreversible risk, and the one place where a second pair of eyes is worth the
2148
- friction. If the model is simply in the wrong module and holds no data you care
2149
- about, the cheap fix is to move the class BACK and rename the module instead.
2150
- Already shipped the move and planning the expand/contract for a later release? The
2151
- owning package's models.py may carry `# arch-allow-table-ownership-is-not-split:
2152
- <reason>`, counted by the escape-hatch budget like any other opt-out.
2153
- - Adopt Terp on an EXISTING database (built by create_all or by hand) without dropping
2154
- data - baseline each history at head, then only genuinely new migrations apply:
2155
- terp migrate stamp # records head, runs no DDL
2156
- - Want physical per-module separation on PostgreSQL (each package's tables in its own
2157
- schema, the groundwork for per-schema GRANTs)? Set DB_SCHEMA_LAYOUT=per-module for a
2158
- fresh database, or move an existing flat one in place (idempotent, data moves with
2159
- the tables, version tables stay put):
2160
- terp migrate adopt-schemas # one-time; ADR 0070
2161
- - Least-privilege runtime (ADR 0071): migrate as the owning role, run the app as a
2162
- separate login that holds ONLY DML - the database itself then refuses DDL and
2163
- (per-module) any tampering with migration state. Provision the login yourself, then:
2164
- terp migrate grant-runtime <role> # idempotent; run after upgrade/adopt
2165
- Run it as the role that runs `terp migrate` - or pass --owner-role <role> so the
2166
- ALTER DEFAULT PRIVILEGES it emits covers tables that future upgrades create.
2167
- Module-to-module DML is deliberately NOT database-blocked (one runtime role spans
2168
- every write schema; audit/outbox ride the business write's single session).
2169
- - Operate safely: run `terp migrate upgrade` ONCE per deploy (e.g. a release job), not
2170
- on every replica - it takes no lock, so concurrent runs race. The boot guard below is
2171
- read-only and safe on every replica. The migration engine is built from DATABASE_URL,
2172
- so put URL-expressible options (e.g. sslmode) there.
2173
- - Run from your app root so app/ is importable (app modules ship their history in
2174
- app/modules/<name>/migrations/; a capability declares a terp.migrations entry point).
2175
- - Make upgrading non-optional: wire the fail-closed boot guard so the app refuses to
2176
- start against a stale schema (a deploy that skipped the upgrade fails loudly). Pass an
2177
- app_root so it guards your app modules too, not only capabilities:
2178
- from functools import partial
2179
- from pathlib import Path
2180
- from terp.migrations import assert_migrations_current
2181
- create_app(specs, ..., migration_check=partial(
2182
- assert_migrations_current, app_root=Path(__file__).parent))
2183
- Gate it on production if local dev builds the schema with create_all / SQLite.
2184
- - Test the REAL migration path (not only create_all) so a model change with no
2185
- migration fails CI, not production:
2186
- from terp.migrations import upgrade, assert_migrations_match_models
2187
- upgrade(db_url, app_root); assert_migrations_match_models(db_url, app_root)
2188
- """,
1937
+ "migrations": guide_migrations.TOPIC,
2189
1938
  "frontend": """\
2190
1939
  Frontend module screens (@terpjs/react-core)
2191
1940
 
@@ -2756,7 +2505,7 @@ else. A `"format": "secret"` declaration must appear with an EMPTY value: this f
2756
2505
  committed, .app.env is not.
2757
2506
 
2758
2507
  Never write a secret value into the manifest, .env.example, .app.env.example, source,
2759
- tests, prompts or logs. Platform-owned names (SECRET_KEY, POSTGRES_PASSWORD, DATABASE_URL,
2508
+ tests, prompts or logs. Platform-owned names (SECRET_KEY, POSTGRES_PASSWORD, TERP_RUNTIME_DB_PASSWORD, TERP_MIGRATION_DATABASE_URL, DATABASE_URL,
2760
2509
  ENVIRONMENT, WEB_PORT, BACKEND_CORS_ORIGINS) are refused in the manifest: they already
2761
2510
  have an owner.
2762
2511
 
@@ -2775,6 +2524,7 @@ scoped app uses `terp env init` rather than `cp`; and a service that adds its ow
2775
2524
  not concatenate sequences), so both files have to be listed.
2776
2525
  """,
2777
2526
  "deployment": guide_deployment.TOPIC,
2527
+ "maintenance": guide_maintenance.TOPIC,
2778
2528
  }
2779
2529
 
2780
2530
  # Topics whose body is generated from a live registry (not a static recipe above).
@@ -2916,6 +2666,7 @@ More: terp guide <topic> (topics: {_TOPIC_NAMES})
2916
2666
  terp guide theming (palettes, design tokens, the brand mark)
2917
2667
  terp guide changelog (what changed — read this before and after a bump)
2918
2668
  terp upgrade --check (is there a newer release for the whole set?)
2669
+ terp maintenance (what to maintain: platform, advisories, bases; a report)
2919
2670
  terp inspect capabilities (what the platform offers: installed vs adoptable)
2920
2671
  terp inspect control-plane (your roles / permissions / module authority map)
2921
2672
  terp inspect access (the full access graph: modules, endpoints, data traits)
@@ -3834,23 +3585,9 @@ def _build_parser() -> argparse.ArgumentParser:
3834
3585
  "led by its Security and Upgrade notes. Pass the version this app is on",
3835
3586
  )
3836
3587
 
3837
- upgrade_parser = subcommands.add_parser(
3838
- "upgrade",
3839
- help="Check whether a newer Terp release is available for the whole set",
3840
- )
3841
- upgrade_parser.add_argument(
3842
- "--check",
3843
- action="store_true",
3844
- help="Report the available release and the bump recipe (the only mode: "
3845
- "Terp reports, it does not edit your manifests)",
3846
- )
3847
- upgrade_parser.add_argument(
3848
- "--format",
3849
- choices=("text", "json"),
3850
- default="text",
3851
- help="Output format: text (the recipe) or json (the same facts as data — "
3852
- "installed, current, target, covers_whole_set, stragglers, rerender_blocker)",
3853
- )
3588
+ from terp.cli.maintenance import add_parsers as add_maintenance_parsers
3589
+
3590
+ add_maintenance_parsers(subcommands)
3854
3591
 
3855
3592
  migrate_parser = subcommands.add_parser(
3856
3593
  "migrate",
@@ -4257,7 +3994,7 @@ def _build_parser() -> argparse.ArgumentParser:
4257
3994
  )
4258
3995
  module_parser.add_argument("name", help="Module name (lowercase identifier, e.g. invoices)")
4259
3996
  module_parser.add_argument("--root", default=".", help="App root to scaffold into (default: .)")
4260
- module_parser.add_argument("--package", default="app", help="Module package root (default: app)")
3997
+ module_parser.add_argument("--package", default="app", help="Top-level Python package (default: app)")
4261
3998
  module_parser.add_argument(
4262
3999
  "--no-frontend",
4263
4000
  action="store_true",
@@ -4741,17 +4478,11 @@ def main(argv: Sequence[str] | None = None) -> None:
4741
4478
  )
4742
4479
  emit(guide(args.topic, since=args.since))
4743
4480
  return
4744
- if args.command == "upgrade":
4745
- from terp.cli.version import render_upgrade_check
4481
+ if args.command in ("upgrade", "maintenance"):
4482
+ from terp.cli.maintenance import run as run_maintenance
4746
4483
 
4747
- if not args.check:
4748
- raise SystemExit(
4749
- "terp upgrade: run `terp upgrade --check`. Terp reports what is "
4750
- "available and how to bump; it does not edit your manifests, because "
4751
- "a lockstep bump spans pyproject.toml and frontend/package.json and "
4752
- "must be reviewed as one change."
4753
- )
4754
- emit(render_upgrade_check(fmt=args.format))
4484
+ if code := run_maintenance(args):
4485
+ raise SystemExit(code)
4755
4486
  return
4756
4487
  if args.command == "migrate":
4757
4488
  from terp.migrations import migrate_main
@@ -4882,14 +4613,9 @@ def main(argv: Sequence[str] | None = None) -> None:
4882
4613
  raise SystemExit(status)
4883
4614
  return
4884
4615
  if args.command == "new" and args.new_command == "module":
4885
- paths = new_module(
4886
- args.name,
4887
- root=args.root,
4888
- package=args.package,
4889
- frontend=not args.no_frontend,
4890
- profile=args.profile,
4891
- )
4892
- emit(new_module_message(args.name, paths, profile=args.profile))
4616
+ options = {"root": args.root, "package": args.package, "profile": args.profile}
4617
+ paths = new_module(args.name, frontend=not args.no_frontend, **options)
4618
+ emit(new_module_message(args.name, paths, **options))
4893
4619
  return
4894
4620
  if args.command == "api-docs":
4895
4621
  for path in api_docs(args.out):
@@ -0,0 +1,142 @@
1
+ """Normalize scanner evidence without interpreting a scanner error as a clean audit.
2
+
3
+ Dependency metadata describes installation scope, never exploitability. Findings keep
4
+ every installed occurrence; accepting one occurrence cannot cover another lock or version.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import hashlib
10
+ import json
11
+ import re
12
+ from typing import Any
13
+
14
+
15
+ class AuditUnreadable(ValueError):
16
+ """The scanner or lock did not provide complete evidence."""
17
+
18
+
19
+ def digest(value: object) -> str:
20
+ return "sha256:" + hashlib.sha256(
21
+ json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=True).encode()
22
+ ).hexdigest()
23
+
24
+
25
+ def _object(value: object) -> dict:
26
+ if not isinstance(value, dict):
27
+ raise AuditUnreadable("expected an object in the dependency audit")
28
+ return value
29
+
30
+
31
+ def _strings(value: object) -> list[str]:
32
+ if not isinstance(value, list) or not all(isinstance(v, str) and v for v in value):
33
+ raise AuditUnreadable("expected a list of nonempty strings in the dependency audit")
34
+ return sorted(set(value))
35
+
36
+
37
+ def finding(*, advisory: str, aliases: list[str], ecosystem: str, package: str,
38
+ version: str, lockfile: str, paths: list[str], severity: str,
39
+ fixed: list[str], scope: str) -> dict[str, Any]:
40
+ identity = {
41
+ "advisories": sorted(set([advisory, *aliases])), "ecosystem": ecosystem,
42
+ "package": package, "version": version, "lockfile": lockfile,
43
+ "dependency_paths": sorted(set(paths)),
44
+ }
45
+ if not all(isinstance(v, str) and v for v in (advisory, package, version, lockfile)):
46
+ raise AuditUnreadable("a dependency finding has no identity")
47
+ return {**identity, "fingerprint": digest(identity), "severity": severity,
48
+ "fixed_versions": sorted(set(fixed)), "dependency_scope": scope}
49
+
50
+
51
+ def npm_findings(report: object, lock: object, lockfile: str) -> list[dict]:
52
+ report, lock = _object(report), _object(lock)
53
+ if "error" in report or report.get("auditReportVersion") != 2:
54
+ raise AuditUnreadable("npm audit did not complete with a version 2 report")
55
+ vulnerabilities = _object(report.get("vulnerabilities"))
56
+ packages = _object(lock.get("packages"))
57
+ counts = _object(_object(report.get("metadata")).get("vulnerabilities"))
58
+ if type(counts.get("total")) is not int or counts["total"] != len(vulnerabilities):
59
+ raise AuditUnreadable("npm audit vulnerability counts contradict its findings")
60
+ found: dict[str, dict] = {}
61
+
62
+ def advisories(name: str, visiting: frozenset[str] = frozenset()) -> list[dict]:
63
+ if name in visiting:
64
+ raise AuditUnreadable("npm audit contains cyclic vulnerability references")
65
+ entry = _object(vulnerabilities.get(name))
66
+ via = entry.get("via")
67
+ if not isinstance(via, list) or not via:
68
+ raise AuditUnreadable("npm audit contains a vulnerability with no advisory")
69
+ result = []
70
+ for source in via:
71
+ if isinstance(source, str):
72
+ result.extend(advisories(source, visiting | {name}))
73
+ else:
74
+ result.append(_object(source))
75
+ return result
76
+
77
+ for name, value in vulnerabilities.items():
78
+ entry = _object(value)
79
+ nodes = _strings(entry.get("nodes"))
80
+ if not nodes:
81
+ raise AuditUnreadable("npm audit contains a vulnerability with no installed path")
82
+ for advisory in advisories(name):
83
+ url = advisory.get("url", "")
84
+ match = re.fullmatch(r"https://github.com/advisories/(GHSA-[a-z0-9-]+)", str(url))
85
+ if match is None or advisory.get("severity") not in {"info", "low", "moderate", "high", "critical"}:
86
+ raise AuditUnreadable("npm audit contains an unrecognized advisory identity or severity")
87
+ for node in nodes:
88
+ installed = _object(packages.get(node))
89
+ item = finding(
90
+ advisory=match[1], aliases=[], ecosystem="npm", package=name,
91
+ version=installed.get("version", ""), lockfile=lockfile, paths=[node],
92
+ severity=advisory["severity"], fixed=[],
93
+ scope="development" if installed.get("dev") is True else "runtime",
94
+ )
95
+ if item["fingerprint"] in found and found[item["fingerprint"]] != item:
96
+ raise AuditUnreadable("npm audit contradicts itself about an advisory")
97
+ found[item["fingerprint"]] = item
98
+ return sorted(found.values(), key=lambda item: item["fingerprint"])
99
+
100
+
101
+ def python_findings(report: object, lockfile: str = "uv.lock", *, project_names: frozenset[str] = frozenset()) -> list[dict]:
102
+ report = _object(report)
103
+ if report.get("fixes"):
104
+ raise AuditUnreadable("an audit must not modify dependencies")
105
+ dependencies = report.get("dependencies")
106
+ if not isinstance(dependencies, list):
107
+ raise AuditUnreadable("pip-audit did not return dependencies")
108
+ result = []
109
+ for dependency in dependencies:
110
+ dependency = _object(dependency)
111
+ if "skip_reason" in dependency:
112
+ # The application's own code has no registry advisory identity. Its lock
113
+ # explicitly marks it as the root; skipping any third-party package fails.
114
+ name = dependency.get("name", "")
115
+ if isinstance(name, str) and re.sub(r"[-_.]+", "-", name).lower() in project_names:
116
+ continue
117
+ raise AuditUnreadable("pip-audit skipped a dependency")
118
+ if not all(isinstance(dependency.get(key), str) and dependency[key] for key in ("name", "version")):
119
+ raise AuditUnreadable("pip-audit omitted a dependency's identity")
120
+ vulns = dependency.get("vulns")
121
+ if not isinstance(vulns, list):
122
+ raise AuditUnreadable("pip-audit omitted a dependency's findings")
123
+ for vuln in vulns:
124
+ vuln = _object(vuln)
125
+ aliases = _strings(vuln.get("aliases", []))
126
+ result.append(finding(
127
+ advisory=vuln.get("id", ""), aliases=aliases, ecosystem="pypi",
128
+ package=dependency.get("name", ""), version=dependency.get("version", ""),
129
+ lockfile=lockfile, paths=[dependency.get("name", "")], severity="unknown",
130
+ fixed=_strings(vuln.get("fix_versions", [])), scope="unknown",
131
+ ))
132
+ found = {}
133
+ for item in result:
134
+ if item["fingerprint"] in found and found[item["fingerprint"]] != item:
135
+ raise AuditUnreadable("pip-audit contradicts itself about an advisory")
136
+ found[item["fingerprint"]] = item
137
+ return sorted(found.values(), key=lambda item: item["fingerprint"])
138
+
139
+
140
+ def blocking(item: dict) -> bool:
141
+ """npm retains its high threshold; pip-audit retains its all-findings threshold."""
142
+ return item["ecosystem"] == "pypi" or item["severity"] in {"high", "critical"}