compose-plugins 0.2.0__tar.gz → 0.3.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 (77) hide show
  1. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/PKG-INFO +24 -8
  2. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/README.md +23 -7
  3. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/__init__.py +10 -5
  4. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/conformance.py +152 -2
  5. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/consent.py +161 -11
  6. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/derive.py +18 -0
  7. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/errors.py +42 -0
  8. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/host.py +58 -2
  9. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/lifecycle.py +415 -56
  10. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/manifest.py +247 -10
  11. compose_plugins-0.3.0/compose_plugins/schema/manifest-0.3.schema.json +265 -0
  12. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/store.py +64 -7
  13. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/version.py +1 -1
  14. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/web.py +155 -19
  15. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins.egg-info/PKG-INFO +24 -8
  16. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins.egg-info/SOURCES.txt +9 -0
  17. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/pyproject.toml +1 -1
  18. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_schema_file.py +6 -1
  19. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_v02_install_log.py +21 -6
  20. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_v02_license_eula.py +11 -6
  21. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_v02_schema_by_contract.py +4 -3
  22. compose_plugins-0.3.0/tests/test_v03_lifecycle.py +695 -0
  23. compose_plugins-0.3.0/tests/test_v03_manifest.py +458 -0
  24. compose_plugins-0.3.0/tests/test_v03_r27.py +514 -0
  25. compose_plugins-0.3.0/tests/test_v03_r27_round3.py +234 -0
  26. compose_plugins-0.3.0/tests/test_v03_reads_0_2.py +217 -0
  27. compose_plugins-0.3.0/tests/test_v03_uninstall_data.py +274 -0
  28. compose_plugins-0.3.0/tests/test_v03_warnings.py +385 -0
  29. compose_plugins-0.3.0/tests/test_v03_web.py +254 -0
  30. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_version.py +6 -6
  31. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_wave2_lifecycle.py +3 -1
  32. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/LICENSE +0 -0
  33. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/_child.py +0 -0
  34. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/_probe.py +0 -0
  35. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/config.py +0 -0
  36. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/__init__.py +0 -0
  37. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_eula/EULA.txt +0 -0
  38. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_eula/__init__.py +0 -0
  39. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_eula/hello_world/__init__.py +0 -0
  40. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_eula/hello_world/plugin.py +0 -0
  41. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_eula/manifest.json +0 -0
  42. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_v1/__init__.py +0 -0
  43. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_v1/hello_world/__init__.py +0 -0
  44. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_v1/hello_world/plugin.py +0 -0
  45. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_v1/manifest.json +0 -0
  46. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_v2/__init__.py +0 -0
  47. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_v2/hello_world/__init__.py +0 -0
  48. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_v2/hello_world/plugin.py +0 -0
  49. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/fixtures/hello_world_v2/manifest.json +0 -0
  50. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/package.py +0 -0
  51. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/probe_client.py +0 -0
  52. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/runner.py +0 -0
  53. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/schema/__init__.py +0 -0
  54. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/schema/manifest-0.1.schema.json +0 -0
  55. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins/schema/manifest-0.2.schema.json +0 -0
  56. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins.egg-info/dependency_links.txt +0 -0
  57. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins.egg-info/entry_points.txt +0 -0
  58. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins.egg-info/requires.txt +0 -0
  59. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/compose_plugins.egg-info/top_level.txt +0 -0
  60. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/setup.cfg +0 -0
  61. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_consent.py +0 -0
  62. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_consent_record_r9.py +0 -0
  63. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_host_name_r10.py +0 -0
  64. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_manifest.py +0 -0
  65. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_package.py +0 -0
  66. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_qa_wave1_rulings.py +0 -0
  67. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_r21_permissions.py +0 -0
  68. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_r24_conformance_hooks.py +0 -0
  69. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_v02_record_decline.py +0 -0
  70. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_v02_uninstall_confirm.py +0 -0
  71. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_validator_readings.py +0 -0
  72. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_wave2_build.py +0 -0
  73. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_wave2_conformance.py +0 -0
  74. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_wave2_r18.py +0 -0
  75. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_wave2_r19.py +0 -0
  76. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_wave2_runner.py +0 -0
  77. {compose_plugins-0.2.0 → compose_plugins-0.3.0}/tests/test_wave2_web.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: compose-plugins
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: The shared plug-in contract library (manifest, consent, version rule) for ComposeIO and Gnomon hosts
5
5
  License: MIT
6
6
  Requires-Python: >=3.10
@@ -12,9 +12,23 @@ Dynamic: license-file
12
12
  # compose-plugins
13
13
 
14
14
  The shared plug-in contract library for ComposeIO's ComposeServer and for
15
- Gnomon, implementing the Shared Plug-in Contract v0.2 (ComposeIO spec 95,
16
- `[SPEC:CXC-PLUGIN-CONTRACT]`, revision r24 plus its v0.2 delta). It is the layer
17
- a plug-in is INSTALLED and CONSENTED to, plus the shared manager that drives it.
15
+ Gnomon, implementing the Shared Plug-in Contract v0.3 (ComposeIO spec 95,
16
+ `[SPEC:CXC-PLUGIN-CONTRACT]`, revision r24 plus its v0.2 delta plus the v0.3 delta,
17
+ section 18). It is the layer a plug-in is INSTALLED and CONSENTED to, plus the shared
18
+ manager that drives it. See `CHANGELOG.md` for what 0.3.0 changes and what was measured.
19
+
20
+ Contract 0.3 is an additive MINOR over 0.2 that FREEZES the manifest schema: optional
21
+ `capabilities` (`agent-messaging` is defined) and `warnings` (`{id, title, text}`, each
22
+ acknowledged on its own, its sha256 stored in the consent record); an optional
23
+ `Host.policy` hook (host-required warnings, refusal by policy) and `Host.data_dir`;
24
+ consent only at install and at an upgrade that widens or changes the EULA, a capability
25
+ or a warning; a refuse that always stops (an upgrade with no gate and `accepted=False`
26
+ raises `OperatorDeclined`); an operator-attributed lifecycle record in `installs.jsonl`
27
+ (`operator`, `result`, `consent_id`, new events `configure` and `decline`); an advisory
28
+ for grant-bearing `config_schema` fields; and a keep-or-delete choice for the plug-in's
29
+ data folder at uninstall. A host that mounts the web manager MUST keep every
30
+ state-changing route out of agents' reach (`[CXC-PC-V03-HOST-AGENT-BLOCK]`): the
31
+ library cannot tell a person from an agent.
18
32
 
19
33
  Contract 0.2 is an additive MINOR over 0.1: optional manifest fields `license`
20
34
  (an SPDX expression, informational) and `eula` (a package-relative UTF-8 text
@@ -33,7 +47,7 @@ that is not ComposeIO can use the library on its own.
33
47
 
34
48
  | module | what |
35
49
  |---|---|
36
- | `compose_plugins.manifest` | the v0.1 manifest validator (authoritative) and the shipped JSON Schemas, one per contract (`schema/manifest-0.1.schema.json`, unchanged from 0.1.0, and `schema/manifest-0.2.schema.json`; `schema_for(manifest)` picks by the manifest's `contract`), generated from the validator's own patterns |
50
+ | `compose_plugins.manifest` | the v0.1 manifest validator (authoritative) and the shipped JSON Schemas, one per contract (`schema/manifest-0.1.schema.json` and `schema/manifest-0.2.schema.json`, both byte-identical to the compose-plugins 0.2.0 files, and `schema/manifest-0.3.schema.json`, frozen at the tag; `schema_for(manifest)` picks by the manifest's `contract`), generated from the validator's own patterns |
37
51
  | `compose_plugins.package` | reading `manifest.json` from a directory or a wheel WITHOUT executing anything, and the `manifest_sha256` rule (exact bytes, no canonicalization) |
38
52
  | `compose_plugins.version` | the contract version rule: a host accepts the same MAJOR and a MINOR at or below its own, and refuses anything newer, naming both versions |
39
53
  | `compose_plugins.consent` | consent content rendered from the manifest alone, the granted set, the widening rule, and the append-only consent-record store |
@@ -45,7 +59,7 @@ that is not ComposeIO can use the library on its own.
45
59
  | `compose_plugins.store` | the install records (the registry), stored config, and the append-only install event log `InstallLog` with its findings |
46
60
  | `compose_plugins.web` | the plain Plugin Manager: server-rendered HTML, a mountable WSGI app that is correct under any URL prefix, with the host's auth hook and CSRF defence |
47
61
  | `compose_plugins.conformance` | the conformance script (below) |
48
- | `compose_plugins.fixtures` | the hello-world v1 and v2 conformance plug-ins, and `hello-world-eula` (contract 0.2, declares a EULA) |
62
+ | `compose_plugins.fixtures` | the hello-world v1 and v2 conformance plug-ins, and `hello-world-eula` (contract 0.2, declares a EULA); unmodified since 0.2 |
49
63
 
50
64
  ```python
51
65
  from compose_plugins.package import read_manifest
@@ -64,7 +78,9 @@ non-conformant. It runs the hello-world lifecycle in nine steps (install with
64
78
  consent, configure, start, health, a publish/subscribe round trip, an upgrade
65
79
  to v2 with re-consent and config migration, disable, re-enable, and uninstall
66
80
  with the retained topic tombstoned and the consent record kept). It then runs
67
- negative controls NC1 to NC8, each of which must fail loudly. This happens once
81
+ negative controls NC1 to NC10 (NC9: a non-widening upgrade with `accepted=False`
82
+ stops and writes one `decline` entry; NC10: a grant-bearing config property draws a
83
+ named advisory and is not refused), each of which must fail loudly. This happens once
68
84
  per host and per isolation level the host supports. At the subprocess level it
69
85
  also checks that the child holds no network socket and that a child crash is
70
86
  reported as `failed(<reason>)`.
@@ -85,7 +101,7 @@ plus the two members added in spec 95 r24:
85
101
  installed.
86
102
  - `host_section(fixture: str) -> dict` (optional): this host's own valid
87
103
  section for a fixture id: `hello-world-v1`, `hello-world-v2`, or a
88
- negative-control id `NC1` to `NC8`. Before every install it hands to the
104
+ negative-control id `NC1` to `NC10`. Before every install it hands to the
89
105
  host, the runner writes that value at `hosts.<target.host.name>`, so the
90
106
  consented `manifest_sha256` covers it. A target without the hook gets `{}`
91
107
  there. The shared fixtures never decide a host's section: each host owns its
@@ -1,9 +1,23 @@
1
1
  # compose-plugins
2
2
 
3
3
  The shared plug-in contract library for ComposeIO's ComposeServer and for
4
- Gnomon, implementing the Shared Plug-in Contract v0.2 (ComposeIO spec 95,
5
- `[SPEC:CXC-PLUGIN-CONTRACT]`, revision r24 plus its v0.2 delta). It is the layer
6
- a plug-in is INSTALLED and CONSENTED to, plus the shared manager that drives it.
4
+ Gnomon, implementing the Shared Plug-in Contract v0.3 (ComposeIO spec 95,
5
+ `[SPEC:CXC-PLUGIN-CONTRACT]`, revision r24 plus its v0.2 delta plus the v0.3 delta,
6
+ section 18). It is the layer a plug-in is INSTALLED and CONSENTED to, plus the shared
7
+ manager that drives it. See `CHANGELOG.md` for what 0.3.0 changes and what was measured.
8
+
9
+ Contract 0.3 is an additive MINOR over 0.2 that FREEZES the manifest schema: optional
10
+ `capabilities` (`agent-messaging` is defined) and `warnings` (`{id, title, text}`, each
11
+ acknowledged on its own, its sha256 stored in the consent record); an optional
12
+ `Host.policy` hook (host-required warnings, refusal by policy) and `Host.data_dir`;
13
+ consent only at install and at an upgrade that widens or changes the EULA, a capability
14
+ or a warning; a refuse that always stops (an upgrade with no gate and `accepted=False`
15
+ raises `OperatorDeclined`); an operator-attributed lifecycle record in `installs.jsonl`
16
+ (`operator`, `result`, `consent_id`, new events `configure` and `decline`); an advisory
17
+ for grant-bearing `config_schema` fields; and a keep-or-delete choice for the plug-in's
18
+ data folder at uninstall. A host that mounts the web manager MUST keep every
19
+ state-changing route out of agents' reach (`[CXC-PC-V03-HOST-AGENT-BLOCK]`): the
20
+ library cannot tell a person from an agent.
7
21
 
8
22
  Contract 0.2 is an additive MINOR over 0.1: optional manifest fields `license`
9
23
  (an SPDX expression, informational) and `eula` (a package-relative UTF-8 text
@@ -22,7 +36,7 @@ that is not ComposeIO can use the library on its own.
22
36
 
23
37
  | module | what |
24
38
  |---|---|
25
- | `compose_plugins.manifest` | the v0.1 manifest validator (authoritative) and the shipped JSON Schemas, one per contract (`schema/manifest-0.1.schema.json`, unchanged from 0.1.0, and `schema/manifest-0.2.schema.json`; `schema_for(manifest)` picks by the manifest's `contract`), generated from the validator's own patterns |
39
+ | `compose_plugins.manifest` | the v0.1 manifest validator (authoritative) and the shipped JSON Schemas, one per contract (`schema/manifest-0.1.schema.json` and `schema/manifest-0.2.schema.json`, both byte-identical to the compose-plugins 0.2.0 files, and `schema/manifest-0.3.schema.json`, frozen at the tag; `schema_for(manifest)` picks by the manifest's `contract`), generated from the validator's own patterns |
26
40
  | `compose_plugins.package` | reading `manifest.json` from a directory or a wheel WITHOUT executing anything, and the `manifest_sha256` rule (exact bytes, no canonicalization) |
27
41
  | `compose_plugins.version` | the contract version rule: a host accepts the same MAJOR and a MINOR at or below its own, and refuses anything newer, naming both versions |
28
42
  | `compose_plugins.consent` | consent content rendered from the manifest alone, the granted set, the widening rule, and the append-only consent-record store |
@@ -34,7 +48,7 @@ that is not ComposeIO can use the library on its own.
34
48
  | `compose_plugins.store` | the install records (the registry), stored config, and the append-only install event log `InstallLog` with its findings |
35
49
  | `compose_plugins.web` | the plain Plugin Manager: server-rendered HTML, a mountable WSGI app that is correct under any URL prefix, with the host's auth hook and CSRF defence |
36
50
  | `compose_plugins.conformance` | the conformance script (below) |
37
- | `compose_plugins.fixtures` | the hello-world v1 and v2 conformance plug-ins, and `hello-world-eula` (contract 0.2, declares a EULA) |
51
+ | `compose_plugins.fixtures` | the hello-world v1 and v2 conformance plug-ins, and `hello-world-eula` (contract 0.2, declares a EULA); unmodified since 0.2 |
38
52
 
39
53
  ```python
40
54
  from compose_plugins.package import read_manifest
@@ -53,7 +67,9 @@ non-conformant. It runs the hello-world lifecycle in nine steps (install with
53
67
  consent, configure, start, health, a publish/subscribe round trip, an upgrade
54
68
  to v2 with re-consent and config migration, disable, re-enable, and uninstall
55
69
  with the retained topic tombstoned and the consent record kept). It then runs
56
- negative controls NC1 to NC8, each of which must fail loudly. This happens once
70
+ negative controls NC1 to NC10 (NC9: a non-widening upgrade with `accepted=False`
71
+ stops and writes one `decline` entry; NC10: a grant-bearing config property draws a
72
+ named advisory and is not refused), each of which must fail loudly. This happens once
57
73
  per host and per isolation level the host supports. At the subprocess level it
58
74
  also checks that the child holds no network socket and that a child crash is
59
75
  reported as `failed(<reason>)`.
@@ -74,7 +90,7 @@ plus the two members added in spec 95 r24:
74
90
  installed.
75
91
  - `host_section(fixture: str) -> dict` (optional): this host's own valid
76
92
  section for a fixture id: `hello-world-v1`, `hello-world-v2`, or a
77
- negative-control id `NC1` to `NC8`. Before every install it hands to the
93
+ negative-control id `NC1` to `NC10`. Before every install it hands to the
78
94
  host, the runner writes that value at `hosts.<target.host.name>`, so the
79
95
  consented `manifest_sha256` covers it. A target without the hook gets `{}`
80
96
  there. The shared fixtures never decide a host's section: each host owns its
@@ -1,5 +1,6 @@
1
1
  """compose_plugins — the shared plug-in contract library ([SPEC:CXC-PLUGIN-CONTRACT],
2
- contract 0.2: spec 95 r24 plus its v0.2 delta, [DELTA:CXC-PLUGIN-CONTRACT-V0-2-DELTA]).
2
+ contract 0.3: spec 95 r24 plus its v0.2 delta, [DELTA:CXC-PLUGIN-CONTRACT-V0-2-DELTA],
3
+ plus the v0.3 delta, section 18 of spec 95 ([CXC-PC-V03-BASIS])).
3
4
 
4
5
  The manifest validator and JSON Schema (``manifest``), the no-execution manifest
5
6
  and EULA reader and the manifest_sha256 rule (``package``), the version rule
@@ -11,16 +12,20 @@ subprocess runner (``runner``), the registry, config and install-event-log
11
12
  stores (``store``), the plain web Plugin Manager (``web``), and the conformance
12
13
  script (``conformance``) with its hello-world fixtures. See README.md.
13
14
 
14
- Contract 0.2 adds these exports ([CXC-PC-V02-STORES-COMPAT] manager-signatures).
15
+ Contract 0.2 adds these exports ([CXC-PC-V02-STORES-COMPAT] manager-signatures);
16
+ contract 0.3 adds ``OperatorDeclined``, ``PolicyRefused`` and ``WarningAckRefused``
17
+ ([CXC-PC-V03-STORES-COMPAT] manager-signatures).
15
18
  """
16
19
 
17
- __version__ = "0.2.0"
20
+ __version__ = "0.3.0"
18
21
 
19
22
  from .consent import eula_text_shown # noqa: E402
20
23
  from .errors import ( # noqa: E402
21
- EulaShaMismatch, InstallLogRefused, PromptNotPrepared, PromptStale,
24
+ EulaShaMismatch, InstallLogRefused, OperatorDeclined, PolicyRefused, PromptNotPrepared,
25
+ PromptStale, WarningAckRefused,
22
26
  )
23
27
  from .store import InstallLog, InstallLogFinding # noqa: E402
24
28
 
25
29
  __all__ = ["EulaShaMismatch", "InstallLog", "InstallLogFinding", "InstallLogRefused",
26
- "PromptNotPrepared", "PromptStale", "__version__", "eula_text_shown"]
30
+ "OperatorDeclined", "PolicyRefused", "PromptNotPrepared", "PromptStale",
31
+ "WarningAckRefused", "__version__", "eula_text_shown"]
@@ -42,7 +42,7 @@ from dataclasses import dataclass
42
42
  from pathlib import Path
43
43
  from typing import Any, Callable
44
44
 
45
- from .errors import HostNameRefused, ManifestRefused, ManifestShaMismatch
45
+ from .errors import HostNameRefused, ManifestRefused, ManifestShaMismatch, OperatorDeclined
46
46
  from .fixtures import package_dir
47
47
  from .lifecycle import ConsentDenied
48
48
  from .manifest import check_host_name
@@ -71,7 +71,7 @@ class Fail(AssertionError):
71
71
  #: the script's own fixture ids, the only values ``host_section`` is called with
72
72
  #: ([CXC-PC-CONFORMANCE-SCRIPT] ``host-section-hook``, spec 95 r24)
73
73
  FIXTURE_IDS = ("hello-world-v1", "hello-world-v2",
74
- "NC1", "NC2", "NC3", "NC4", "NC5", "NC6", "NC7", "NC8")
74
+ "NC1", "NC2", "NC3", "NC4", "NC5", "NC6", "NC7", "NC8", "NC9", "NC10")
75
75
 
76
76
 
77
77
  class ConformanceRefused(Exception):
@@ -601,6 +601,154 @@ def nc8(r: Run, t) -> None:
601
601
  check(t.manager.state(DOMAIN) == "installed", "hello-world's own manifest did not install")
602
602
 
603
603
 
604
+ def _web_decide(t, path: str, form: dict, decision: str) -> "tuple[str, str]":
605
+ """POST ``form`` plus ``decision`` to the library's web manager mounted on the target's
606
+ manager under an empty prefix, as a same-origin request with a valid CSRF token and a
607
+ script-only identity (the target's own auth hook is replaced on the instance for the
608
+ call and put back). Returns (status, Location)."""
609
+ import io
610
+ from urllib.parse import urlencode
611
+ from .web import PluginManagerApp
612
+ host = t.host
613
+ had = "auth_hook" in vars(host)
614
+ old = vars(host).get("auth_hook")
615
+ host.auth_hook = lambda environ: environ.get("_conformance_operator")
616
+ try:
617
+ app = PluginManagerApp(t.manager)
618
+ ident = "conformance-operator"
619
+ body = urlencode({**form, "decision": decision, "csrf": app.csrf_token(ident)}).encode()
620
+ environ = {"REQUEST_METHOD": "POST", "SCRIPT_NAME": "", "PATH_INFO": path,
621
+ "CONTENT_LENGTH": str(len(body)), "wsgi.input": io.BytesIO(body),
622
+ "wsgi.url_scheme": "http", "HTTP_HOST": "127.0.0.1:8080",
623
+ "REMOTE_ADDR": "127.0.0.1", "_conformance_operator": ident}
624
+ out: dict = {}
625
+ app(environ, lambda status, headers: out.update(status=status, headers=dict(headers)))
626
+ return out["status"], out["headers"].get("Location", "")
627
+ finally:
628
+ if had:
629
+ host.auth_hook = old
630
+ else:
631
+ del host.auth_hook
632
+
633
+
634
+ @_fresh
635
+ def nc9(r: Run, t) -> None:
636
+ """[CXC-PC-V03-NC-UPGRADE-DECLINED]: a non-widening upgrade with
637
+ ``accepted=False`` aborts with no change and writes one ``decline`` entry."""
638
+ m = t.manager
639
+ r.install(t, r.fixture(t, "v1", "NC9"))
640
+ m.configure(DOMAIN, {"greeting": "nc9"})
641
+ m.enable(DOMAIN)
642
+ check(settle(t, lambda s: s == "running") == "running", "v1 did not reach running")
643
+ root = Path(t.host.state_root)
644
+ cfg = root / "config" / f"{DOMAIN}.json"
645
+ snap = lambda: ((root / "installs.json").read_bytes(), # noqa: E731
646
+ sorted(str(p.relative_to(t.host.install_root))
647
+ for p in t.host.install_root.rglob("*") if p.is_file()))
648
+ v1b = r.fixture(t, "v1", "NC9", lambda d: d.update(version="1.0.1"))
649
+ p = m.prepare_upgrade(v1b)
650
+ check(p.gate is False, "a version-only upgrade claims it needs the consent gate")
651
+ before, n_consent, n_log = snap(), len(m.consent.records()), len(m.install_log.events())
652
+ cfg_before = cfg.read_bytes()
653
+ log_before = [(e["seq"], e["consent_basis"], e["consent_id"]) for e in m.install_log.events()]
654
+ try:
655
+ m.upgrade(v1b, consented_sha256=p.manifest_sha256, operator=t.operator,
656
+ accepted=False)
657
+ except OperatorDeclined as exc:
658
+ r.observe("refusal", exc)
659
+ check("DECLINED by the operator" in str(exc), "the refusal does not say declined")
660
+ else:
661
+ raise Fail("a declined upgrade went ahead")
662
+ check(snap() == before, "installs.json or the install root changed")
663
+ check(len(m.consent.records()) == n_consent, "a consent record was written")
664
+ new = m.install_log.events()[n_log:]
665
+ r.observe("log entries added", [(e["event"], e.get("result")) for e in new])
666
+ check(len(new) == 1 and new[0]["event"] == "decline" and new[0]["result"] == "declined"
667
+ and new[0]["consent"] is None, "not exactly one decline entry")
668
+ check(m.record(DOMAIN)["version"] == "1.0.0" and m.state(DOMAIN) == "enabled",
669
+ "v1 is not still enabled")
670
+ # [CXC-PC-V03-RULING-CONFORMANCE-NC9]: the spec's full `expected` list
671
+ check(cfg.read_bytes() == cfg_before, "the stored config changed")
672
+ check(m.status(DOMAIN) == "running", f"v1 is not running ({m.status(DOMAIN)})")
673
+ check(new[0]["consent_basis"] == "none" and new[0]["consent_id"] is None,
674
+ "the decline entry carries a consent_basis or consent_id")
675
+ check([(e["seq"], e["consent_basis"], e["consent_id"])
676
+ for e in m.install_log.events()[:n_log]] == log_before,
677
+ "an earlier entry's consent_basis or consent_id changed")
678
+ # [CXC-PC-V03-RULING-CONFORMANCE-NC9] the web half: the web manager's no-gate upgrade
679
+ # screen, answered with Cancel and with Refuse, redirects to the plug-in's detail page
680
+ # and changes nothing; each writes one `decline` entry (the library's own half above)
681
+ for decision in ("cancel", "refuse"):
682
+ n_before = len(m.install_log.events())
683
+ st, location = _web_decide(t, f"/plugin/{DOMAIN}/upgrade/decide",
684
+ {"source": str(v1b), "sha256": p.manifest_sha256}, decision)
685
+ r.observe(f"web decision={decision}", f"{st} -> {location}")
686
+ check(st.startswith("303") and location == f"/plugin/{DOMAIN}",
687
+ f"web {decision}: not a 303 to the detail page ({st} {location})")
688
+ check(snap() == before and cfg.read_bytes() == cfg_before,
689
+ f"web {decision}: installs.json, the code tree or the config changed")
690
+ check(len(m.consent.records()) == n_consent, f"web {decision}: a consent record was written")
691
+ added = m.install_log.events()[n_before:]
692
+ check(len(added) == 1 and added[0]["event"] == "decline"
693
+ and added[0]["consent"] is None and added[0]["consent_id"] is None,
694
+ f"web {decision}: not exactly one decline entry")
695
+ check(m.record(DOMAIN)["version"] == "1.0.0" and m.status(DOMAIN) == "running",
696
+ f"web {decision}: v1 is not still running")
697
+ m.upgrade(v1b, consented_sha256=p.manifest_sha256, operator=t.operator, accepted=True)
698
+ check(m.record(DOMAIN)["version"] == "1.0.1", "the accepted upgrade did not upgrade")
699
+ check(len(m.consent.records()) == n_consent, "a no-gate upgrade wrote a consent record")
700
+
701
+
702
+ @_fresh
703
+ def nc10(r: Run, t) -> None:
704
+ """[CXC-PC-V03-NC-GRANT-BEARING-CONFIG]: a 0.3 manifest whose config_schema
705
+ names a grant-bearing property draws one named advisory and is NOT refused;
706
+ the same manifest stating 0.2 draws none."""
707
+ cases = {
708
+ "target_host": ({"target_host": {"type": "string"}},
709
+ "config_schema/properties/target_host"),
710
+ "site": ({"site": {"type": "string", "format": "uri"}},
711
+ "config_schema/properties/site"),
712
+ "$defs": (None, "config_schema/$defs/endpoint/properties/data_path"),
713
+ }
714
+
715
+ def edit_for(name: str, contract: str):
716
+ def edit(d: dict) -> None:
717
+ d["contract"] = contract
718
+ props, _ = cases[name]
719
+ if props is not None:
720
+ d["config_schema"]["properties"].update(props)
721
+ else:
722
+ d["config_schema"]["$defs"] = {"endpoint": {"type": "object", "properties": {
723
+ "data_path": {"type": "string"}}}}
724
+ return edit
725
+ for name, (_, pointer) in cases.items():
726
+ for contract, want in (("0.3", [pointer]), ("0.2", [])):
727
+ tt = r.new_target()
728
+ try:
729
+ p = tt.manager.prepare_install(
730
+ r.fixture(tt, "v1", "NC10", edit_for(name, contract)))
731
+ got = [a.field for a in p.manifest.advisories]
732
+ r.observe(f"{name} stating {contract}: advisories", got)
733
+ check(got == want, f"{name} {contract}: advisories {got} != {want}")
734
+ line = f"config field {pointer} looks grant-bearing (structural check; not verified)"
735
+ check((line in p.content.text()) == bool(want), "consent line wrong")
736
+ tt.manager.install(p.source, consented_sha256=p.manifest_sha256,
737
+ operator=tt.operator, accepted=True)
738
+ check(tt.manager.state(DOMAIN) == "installed", f"{name} {contract} not installed")
739
+ finally:
740
+ tt.close()
741
+ tt = r.new_target()
742
+ try:
743
+ def plain(d: dict) -> None:
744
+ d["contract"] = "0.3"
745
+ d["config_schema"]["properties"]["repeat"] = {"type": "integer"}
746
+ p = tt.manager.prepare_install(r.fixture(tt, "v1", "NC10", plain))
747
+ check(list(p.manifest.advisories) == [], "greeting and repeat drew an advisory")
748
+ finally:
749
+ tt.close()
750
+
751
+
604
752
  @_fresh
605
753
  def nc_r15(r: Run, t) -> None:
606
754
  _refused_at_install(r, t, "hello-world-v1",
@@ -650,6 +798,8 @@ STEPS: "tuple[Step, ...]" = (
650
798
  Step("NC6", "widening-refused", "CXC-PC-NC-WIDENING-REFUSED", nc6),
651
799
  Step("NC7", "host-provided-requirement", "CXC-PC-NC-HOST-PROVIDED-REQUIREMENT", nc7),
652
800
  Step("NC8", "malformed-permission", "CXC-PC-NC-MALFORMED-PERMISSION", nc8),
801
+ Step("NC9", "upgrade-declined", "CXC-PC-V03-NC-UPGRADE-DECLINED", nc9),
802
+ Step("NC10", "grant-bearing-config", "CXC-PC-V03-NC-GRANT-BEARING-CONFIG", nc10),
653
803
  Step("R15", "requirements-refused-in-v0.1", "CXC-PC-LIFECYCLE-INSTALL (r15)", nc_r15),
654
804
  Step("H1", "degraded-empty-greeting", "CXC-PC-HELLO-V1 / LIFECYCLE-HEALTH", h1_degraded),
655
805
  Step("L1", "runner-refuses-non-AF_UNIX", "CXC-PC-RUNNER-LOCAL-ONLY", l1_refuses_non_unix,
@@ -18,6 +18,7 @@ their grant strings; that is all it does with them.
18
18
  """
19
19
  from __future__ import annotations
20
20
 
21
+ import hashlib
21
22
  import html
22
23
  import json
23
24
  import os
@@ -150,6 +151,21 @@ def upgrade_widens(old_granted: Iterable[str], new_granted: Iterable[str],
150
151
  return widens(old_granted, new_granted) or level_drops(old_runs_as, new_runs_as)
151
152
 
152
153
 
154
+ def declarations_change(old: "dict | None", new: "dict | None") -> bool:
155
+ """[CXC-PC-V03-DECLARATION-CHANGE-PREDICATE]: True iff an upgrade ADDS or
156
+ CHANGES a capability token or a warning. ``old`` and ``new`` are mappings
157
+ with the two keys ``capabilities`` (tokens) and ``warning_digests`` (a map
158
+ from acknowledgement key to the sha256 of that warning's text); an absent
159
+ key or a None side reads as empty. A removed token or warning, and a changed
160
+ ``title`` alone, never make it true."""
161
+ o, n = old or {}, new or {}
162
+ old_caps = set(o.get("capabilities") or ())
163
+ old_digests = dict(o.get("warning_digests") or {})
164
+ if any(tok not in old_caps for tok in (n.get("capabilities") or ())):
165
+ return True
166
+ return any(old_digests.get(k) != d for k, d in (n.get("warning_digests") or {}).items())
167
+
168
+
153
169
  def added_grants(old_granted: Iterable[str], new_granted: Iterable[str]) -> "list[str]":
154
170
  """What the new set adds over the old one, sorted (the same covering
155
171
  reading as :func:`widens`, so what is marked added is what widens)."""
@@ -187,8 +203,9 @@ class ConsentLine:
187
203
  grant: "str | None" = None
188
204
  added: bool = False
189
205
  #: "field" (``label: value``), "heading" (the permissions heading, shown
190
- #: as its value alone) or "permission" (one declared permission, shown as
191
- #: its value alone, in the permission-lines format)
206
+ #: as its value alone), "permission" (one declared permission, shown as
207
+ #: its value alone, in the permission-lines format) or (0.3) "advisory"
208
+ #: (one grant-bearing config advisory, shown as its value alone)
192
209
  kind: str = "field"
193
210
 
194
211
  def text(self) -> str:
@@ -216,6 +233,48 @@ class ConsentEula:
216
233
  sha256: str
217
234
 
218
235
 
236
+ #: [CXC-PC-V03-CAPABILITIES] rule (5): the capabilities line's suffix
237
+ CAPABILITIES_SUFFIX = " (declared by the plug-in; not verified)"
238
+ #: [CXC-PC-V03-WARNINGS] rule (6) and [CXC-PC-V03-HOST-POLICY-HOOK] rule (3)
239
+ WARNING_LABEL_PLUGIN = "declared by the plug-in; not verified"
240
+ WARNING_LABEL_HOST = "required by this host"
241
+ #: [CXC-PC-V03-GRANT-FREE-CONFIG] rule (3): the advisory line, "<pointer>" filled in
242
+ ADVISORY_LINE = "config field {pointer} looks grant-bearing (structural check; not verified)"
243
+ WARNING_SOURCES = ("plugin", "host")
244
+
245
+
246
+ def warning_sha256(text: str) -> str:
247
+ """The lowercase hex sha256 of a warning's ``text`` as UTF-8, exactly as
248
+ declared ([CXC-PC-V03-WARNING-ACK] rule (3))."""
249
+ return hashlib.sha256(text.encode("utf-8")).hexdigest()
250
+
251
+
252
+ @dataclass(frozen=True)
253
+ class ConsentWarning:
254
+ """One warning on the consent page. ``source`` is ``plugin`` or ``host``;
255
+ its acknowledgement key is ``<source>:<id>`` ([CXC-PC-V03-WARNING-ACK])."""
256
+
257
+ source: str
258
+ id: str
259
+ title: str
260
+ text: str
261
+
262
+ @property
263
+ def key(self) -> str:
264
+ return f"{self.source}:{self.id}"
265
+
266
+ @property
267
+ def sha256(self) -> str:
268
+ return warning_sha256(self.text)
269
+
270
+ @property
271
+ def label(self) -> str:
272
+ return WARNING_LABEL_HOST if self.source == "host" else WARNING_LABEL_PLUGIN
273
+
274
+ def heading(self) -> str:
275
+ return f"Warning: {self.title} ({self.label})"
276
+
277
+
219
278
  @dataclass(frozen=True)
220
279
  class ConsentContent:
221
280
  domain: str
@@ -235,16 +294,25 @@ class ConsentContent:
235
294
  #: (0.2) True iff this upgrade's EULA differs from the consented one
236
295
  #: ([CXC-PC-V02-EULA-RECONSENT] screen)
237
296
  eula_changed: bool = False
297
+ #: (0.3) the declared capability tokens ([CXC-PC-V03-CAPABILITIES]); also
298
+ #: shown as one line in ``lines``
299
+ capabilities: "tuple[str, ...]" = field(default=())
300
+ #: (0.3) every warning shown, the plug-in's first (in declared order) and
301
+ #: then the host's ([CXC-PC-V03-WARNING-ACK]); empty for a 0.2 manifest
302
+ warnings: "tuple[ConsentWarning, ...]" = field(default=())
238
303
 
239
304
  def text(self) -> str:
240
305
  """The title, then the manifest summary below it, one line each; then,
241
306
  when a EULA is declared, its block: the heading, the text exactly as in
242
- the file, and the hash line ([CXC-PC-V02-EULA-DISPLAY])."""
307
+ the file, and the hash line ([CXC-PC-V02-EULA-DISPLAY]); then (0.3)
308
+ each warning, the plug-in's then the host's, in order."""
243
309
  out = "\n".join([self.title] + [line.text() for line in self.lines])
244
310
  if self.eula is not None:
245
311
  changed = f"[ADDED] {EULA_CHANGED}\n" if self.eula_changed else ""
246
312
  out += (f"\n{changed}{EULA_HEADING}:\n{self.eula.text}"
247
313
  f"\nEULA sha256: {self.eula.sha256}")
314
+ for w in self.warnings:
315
+ out += f"\n{w.heading()}\n{w.text}"
248
316
  return out
249
317
 
250
318
 
@@ -268,7 +336,8 @@ def render_consent(manifest: Manifest, *, host: str, runs_as: str,
268
336
  previous_granted: "Iterable[str] | None" = None,
269
337
  previous_runs_as: "str | None" = None,
270
338
  eula: "ConsentEula | None" = None,
271
- eula_changed: bool = False) -> ConsentContent:
339
+ eula_changed: bool = False,
340
+ host_warnings: "Iterable[dict] | None" = None) -> ConsentContent:
272
341
  """Render the consent content from the manifest ALONE.
273
342
 
274
343
  ``runs_as`` is the ACTUAL isolation level the host will use; it may not be
@@ -348,6 +417,18 @@ def render_consent(manifest: Manifest, *, host: str, runs_as: str,
348
417
  if not perms:
349
418
  out.append(line(label, NONE_DECLARED))
350
419
  out.extend(line(label, p.text, p.grant) for p in perms)
420
+ # (0.3) the capabilities line, then one advisory line each, after the
421
+ # permission lines and before the EULA block; nothing at all for a manifest
422
+ # that declares none, so a 0.2 manifest renders as under 0.2
423
+ caps = manifest.capabilities
424
+ if caps:
425
+ out.append(ConsentLine("capabilities", ", ".join(caps) + CAPABILITIES_SUFFIX))
426
+ out.extend(ConsentLine("advisory", ADVISORY_LINE.format(pointer=a.field), kind="advisory")
427
+ for a in manifest.advisories)
428
+ warnings = tuple(ConsentWarning("plugin", w["id"], w["title"], w["text"])
429
+ for w in manifest.warnings)
430
+ warnings += tuple(ConsentWarning("host", w["id"], w["title"], w["text"])
431
+ for w in (host_warnings or ()))
351
432
 
352
433
  granted = sorted({ln.grant for ln in out if ln.grant})
353
434
  added = tuple(added_grants(prev, granted)) if prev is not None else ()
@@ -355,7 +436,8 @@ def render_consent(manifest: Manifest, *, host: str, runs_as: str,
355
436
  domain=manifest.domain, version=manifest.version, host=host,
356
437
  runs_as=runs_as, lines=tuple(out), granted=tuple(granted), added=added,
357
438
  widens=prev is not None and upgrade_widens(prev, granted, previous_runs_as, runs_as),
358
- title=dialog_title(manifest), eula=eula, eula_changed=bool(eula and eula_changed))
439
+ title=dialog_title(manifest), eula=eula, eula_changed=bool(eula and eula_changed),
440
+ capabilities=caps, warnings=warnings)
359
441
 
360
442
 
361
443
  # --------------------------------------------------------------------------- #
@@ -366,7 +448,34 @@ RECORD_KEYS = ("domain", "version", "manifest_sha256", "granted", "decided_by",
366
448
  "decided_at", "host", "decision")
367
449
  #: (0.2) [CXC-PC-CONSENT-RECORD] optional-keys: present only for a manifest that
368
450
  #: declares ``eula``, never null
369
- OPTIONAL_RECORD_KEYS = ("eula_sha256",)
451
+ OPTIONAL_RECORD_KEYS = ("eula_sha256", "acknowledged_warnings")
452
+ #: (0.3) [CXC-PC-V03-WARNING-ACK] rule (4): an acknowledged warning's key
453
+ #: ``<source>:<id>`` and its keys inside the record's list
454
+ _ACK_KEY_RE = re.compile(r"(?:plugin|host):[a-z][a-z0-9_-]{0,63}")
455
+ ACK_ENTRY_KEYS = ("id", "sha256")
456
+
457
+
458
+ def acknowledged_problem(value: object) -> "str | None":
459
+ """The problem with an ``acknowledged_warnings`` value as it appears in a
460
+ record line (a list of ``{id, sha256}`` objects sorted by ``id``), or None."""
461
+ if not isinstance(value, list) or not value:
462
+ return f"acknowledged_warnings must be a non-empty list, never null (got {value!r})"
463
+ ids = []
464
+ for i, e in enumerate(value):
465
+ if not isinstance(e, dict) or set(e) != set(ACK_ENTRY_KEYS):
466
+ return (f"acknowledged_warnings[{i}] must be an object with exactly the keys "
467
+ f"{list(ACK_ENTRY_KEYS)} (got {e!r})")
468
+ if not isinstance(e["id"], str) or _ACK_KEY_RE.fullmatch(e["id"]) is None:
469
+ return (f"acknowledged_warnings[{i}].id {e['id']!r} must be '<source>:<id>' "
470
+ "with source plugin or host")
471
+ if not isinstance(e["sha256"], str) or _SHA_RE.fullmatch(e["sha256"]) is None:
472
+ return (f"acknowledged_warnings[{i}].sha256 for {e['id']} must be 64 lowercase "
473
+ f"hex characters (got {e['sha256']!r})")
474
+ ids.append(e["id"])
475
+ if ids != sorted(set(ids)):
476
+ return "acknowledged_warnings must be sorted by id, with no id repeated"
477
+ return None
478
+
370
479
  _SHA_RE = re.compile(r"[0-9a-f]{64}")
371
480
 
372
481
 
@@ -439,9 +548,24 @@ class ConsentRecord:
439
548
  #: (0.2) the sha256 of the EULA the operator was shown; None = no EULA
440
549
  #: declared (the key is then OMITTED from the JSON, never null)
441
550
  eula_sha256: "str | None" = None
551
+ #: (0.3) the warnings the operator acknowledged, as (key, sha256) pairs
552
+ #: sorted by key ([CXC-PC-V03-WARNING-ACK] rule (4)); None = none (the key
553
+ #: is then OMITTED from the JSON, never null or empty)
554
+ acknowledged_warnings: "tuple[tuple[str, str], ...] | None" = None
442
555
 
443
556
  def __post_init__(self) -> None:
444
557
  problems = []
558
+ if self.acknowledged_warnings is not None:
559
+ p = acknowledged_problem([{"id": k, "sha256": s} for k, s in
560
+ self.acknowledged_warnings]
561
+ if isinstance(self.acknowledged_warnings, tuple)
562
+ and all(isinstance(x, tuple) and len(x) == 2
563
+ for x in self.acknowledged_warnings)
564
+ else self.acknowledged_warnings)
565
+ if p is not None:
566
+ problems.append(p)
567
+ elif self.decision != "granted":
568
+ problems.append("acknowledged_warnings is only on a granted record")
445
569
  if self.eula_sha256 is not None and (not isinstance(self.eula_sha256, str)
446
570
  or _SHA_RE.fullmatch(self.eula_sha256) is None):
447
571
  problems.append(f"eula_sha256 must be 64 lowercase hex characters "
@@ -479,6 +603,9 @@ class ConsentRecord:
479
603
  d["granted"] = list(self.granted)
480
604
  if self.eula_sha256 is not None:
481
605
  d["eula_sha256"] = self.eula_sha256
606
+ if self.acknowledged_warnings is not None:
607
+ d["acknowledged_warnings"] = [{"id": k, "sha256": s}
608
+ for k, s in self.acknowledged_warnings]
482
609
  return d
483
610
 
484
611
  @classmethod
@@ -497,14 +624,23 @@ class ConsentRecord:
497
624
  raise ConsentRefused(f"consent record REFUSED: eula_sha256 must be 64 lowercase "
498
625
  f"hex characters when present, never null "
499
626
  f"(got {d['eula_sha256']!r})")
627
+ extra = {}
628
+ if "acknowledged_warnings" in d:
629
+ p = acknowledged_problem(d["acknowledged_warnings"])
630
+ if p is not None:
631
+ raise ConsentRefused(f"consent record REFUSED: {p}")
632
+ extra["acknowledged_warnings"] = tuple(
633
+ (e["id"], e["sha256"]) for e in d["acknowledged_warnings"])
500
634
  g = d["granted"]
501
- return cls(**{**d, "granted": tuple(g) if isinstance(g, list) else g})
635
+ return cls(**{**d, "granted": tuple(g) if isinstance(g, list) else g, **extra})
502
636
 
503
637
 
504
638
  def make_record(*, manifest: Manifest, manifest_sha256: str, granted: Iterable[str],
505
639
  decided_by: str, host: str, decision: str,
506
640
  clock: Callable[[], datetime] = utc_now,
507
- eula_sha256: "str | None" = None) -> ConsentRecord:
641
+ eula_sha256: "str | None" = None,
642
+ acknowledged_warnings: "Iterable[tuple[str, str]] | None" = None
643
+ ) -> ConsentRecord:
508
644
  """Build a record; ``decided_at`` is taken from ``clock`` (UTC, ISO 8601)."""
509
645
  now = clock()
510
646
  if now.tzinfo is None:
@@ -515,7 +651,20 @@ def make_record(*, manifest: Manifest, manifest_sha256: str, granted: Iterable[s
515
651
  domain=manifest.domain, version=manifest.version,
516
652
  manifest_sha256=manifest_sha256, granted=tuple(sorted(set(granted))),
517
653
  decided_by=decided_by, decided_at=decided_at, host=host, decision=decision,
518
- eula_sha256=eula_sha256)
654
+ eula_sha256=eula_sha256,
655
+ acknowledged_warnings=(tuple(sorted(acknowledged_warnings))
656
+ if acknowledged_warnings else None))
657
+
658
+
659
+ def consent_line(record: ConsentRecord) -> str:
660
+ """The record as ``consent.jsonl`` writes it, without the line feed."""
661
+ return json.dumps(record.to_json(), sort_keys=True, ensure_ascii=False)
662
+
663
+
664
+ def consent_id(record: ConsentRecord) -> str:
665
+ """[CXC-PC-V03-RULING-CONSENT-ID]: the lowercase hex sha256 of the record's
666
+ line as written to ``consent.jsonl`` (UTF-8, no trailing line feed)."""
667
+ return hashlib.sha256(consent_line(record).encode("utf-8")).hexdigest()
519
668
 
520
669
 
521
670
  class ConsentStore:
@@ -530,8 +679,7 @@ class ConsentStore:
530
679
  def append(self, record: ConsentRecord) -> None:
531
680
  if not isinstance(record, ConsentRecord):
532
681
  raise TypeError("ConsentStore.append takes a ConsentRecord")
533
- line = (json.dumps(record.to_json(), sort_keys=True, ensure_ascii=False)
534
- + "\n").encode("utf-8")
682
+ line = (consent_line(record) + "\n").encode("utf-8")
535
683
  fd = os.open(self.path, os.O_WRONLY | os.O_APPEND | os.O_CREAT, 0o600)
536
684
  try:
537
685
  import fcntl
@@ -566,6 +714,8 @@ __all__ = [
566
714
  "DIALOG_TITLE_SUFFIX", "FILESYSTEM_GRANT_PREFIX", "NETWORK_GRANT_PREFIX",
567
715
  "PERMISSIONS_HEADING", "dialog_title", "filesystem_grant", "network_grant",
568
716
  "ConsentEula", "EULA_CHANGED", "EULA_HEADING", "LICENSE_SUFFIX", "OPTIONAL_RECORD_KEYS",
717
+ "ConsentWarning", "WARNING_SOURCES", "acknowledged_problem", "consent_id", "consent_line",
718
+ "declarations_change", "warning_sha256", "ADVISORY_LINE", "CAPABILITIES_SUFFIX",
569
719
  "eula_text_shown",
570
720
  "ABSENT", "ConsentContent", "ConsentLine", "ConsentRecord", "ConsentStore",
571
721
  "DECISIONS", "HostPermission", "HostSectionRenderer", "NONE_DECLARED",