compose-plugins 0.0.0__tar.gz → 0.2.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 (74) hide show
  1. compose_plugins-0.2.0/PKG-INFO +102 -0
  2. compose_plugins-0.2.0/README.md +91 -0
  3. compose_plugins-0.2.0/compose_plugins/__init__.py +26 -0
  4. compose_plugins-0.2.0/compose_plugins/_child.py +117 -0
  5. compose_plugins-0.2.0/compose_plugins/_probe.py +51 -0
  6. compose_plugins-0.2.0/compose_plugins/config.py +27 -0
  7. compose_plugins-0.2.0/compose_plugins/conformance.py +713 -0
  8. compose_plugins-0.2.0/compose_plugins/consent.py +575 -0
  9. compose_plugins-0.2.0/compose_plugins/derive.py +206 -0
  10. compose_plugins-0.2.0/compose_plugins/errors.py +167 -0
  11. compose_plugins-0.2.0/compose_plugins/fixtures/__init__.py +24 -0
  12. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_eula/EULA.txt +14 -0
  13. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_eula/__init__.py +0 -0
  14. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_eula/hello_world/__init__.py +1 -0
  15. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_eula/hello_world/plugin.py +54 -0
  16. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_eula/manifest.json +52 -0
  17. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v1/__init__.py +0 -0
  18. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v1/hello_world/__init__.py +1 -0
  19. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v1/hello_world/plugin.py +54 -0
  20. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v1/manifest.json +51 -0
  21. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v2/__init__.py +0 -0
  22. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v2/hello_world/__init__.py +1 -0
  23. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v2/hello_world/plugin.py +59 -0
  24. compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v2/manifest.json +60 -0
  25. compose_plugins-0.2.0/compose_plugins/host.py +119 -0
  26. compose_plugins-0.2.0/compose_plugins/lifecycle.py +834 -0
  27. compose_plugins-0.2.0/compose_plugins/manifest.py +1169 -0
  28. compose_plugins-0.2.0/compose_plugins/package.py +504 -0
  29. compose_plugins-0.2.0/compose_plugins/probe_client.py +76 -0
  30. compose_plugins-0.2.0/compose_plugins/runner.py +391 -0
  31. compose_plugins-0.2.0/compose_plugins/schema/__init__.py +8 -0
  32. compose_plugins-0.2.0/compose_plugins/schema/manifest-0.1.schema.json +216 -0
  33. compose_plugins-0.2.0/compose_plugins/schema/manifest-0.2.schema.json +226 -0
  34. compose_plugins-0.2.0/compose_plugins/store.py +307 -0
  35. compose_plugins-0.2.0/compose_plugins/version.py +60 -0
  36. compose_plugins-0.2.0/compose_plugins/web.py +376 -0
  37. compose_plugins-0.2.0/compose_plugins.egg-info/PKG-INFO +102 -0
  38. compose_plugins-0.2.0/compose_plugins.egg-info/SOURCES.txt +66 -0
  39. compose_plugins-0.2.0/compose_plugins.egg-info/entry_points.txt +2 -0
  40. compose_plugins-0.2.0/compose_plugins.egg-info/requires.txt +1 -0
  41. compose_plugins-0.2.0/pyproject.toml +37 -0
  42. compose_plugins-0.2.0/tests/test_consent.py +302 -0
  43. compose_plugins-0.2.0/tests/test_consent_record_r9.py +187 -0
  44. compose_plugins-0.2.0/tests/test_host_name_r10.py +156 -0
  45. compose_plugins-0.2.0/tests/test_manifest.py +513 -0
  46. compose_plugins-0.2.0/tests/test_package.py +300 -0
  47. compose_plugins-0.2.0/tests/test_qa_wave1_rulings.py +558 -0
  48. compose_plugins-0.2.0/tests/test_r21_permissions.py +720 -0
  49. compose_plugins-0.2.0/tests/test_r24_conformance_hooks.py +240 -0
  50. compose_plugins-0.2.0/tests/test_schema_file.py +111 -0
  51. compose_plugins-0.2.0/tests/test_v02_install_log.py +782 -0
  52. compose_plugins-0.2.0/tests/test_v02_license_eula.py +616 -0
  53. compose_plugins-0.2.0/tests/test_v02_record_decline.py +338 -0
  54. compose_plugins-0.2.0/tests/test_v02_schema_by_contract.py +98 -0
  55. compose_plugins-0.2.0/tests/test_v02_uninstall_confirm.py +218 -0
  56. compose_plugins-0.2.0/tests/test_validator_readings.py +289 -0
  57. compose_plugins-0.2.0/tests/test_version.py +85 -0
  58. compose_plugins-0.2.0/tests/test_wave2_build.py +109 -0
  59. compose_plugins-0.2.0/tests/test_wave2_conformance.py +120 -0
  60. compose_plugins-0.2.0/tests/test_wave2_lifecycle.py +335 -0
  61. compose_plugins-0.2.0/tests/test_wave2_r18.py +255 -0
  62. compose_plugins-0.2.0/tests/test_wave2_r19.py +209 -0
  63. compose_plugins-0.2.0/tests/test_wave2_runner.py +276 -0
  64. compose_plugins-0.2.0/tests/test_wave2_web.py +321 -0
  65. compose_plugins-0.0.0/PKG-INFO +0 -16
  66. compose_plugins-0.0.0/README.md +0 -5
  67. compose_plugins-0.0.0/compose_plugins/__init__.py +0 -2
  68. compose_plugins-0.0.0/compose_plugins.egg-info/PKG-INFO +0 -16
  69. compose_plugins-0.0.0/compose_plugins.egg-info/SOURCES.txt +0 -8
  70. compose_plugins-0.0.0/pyproject.toml +0 -18
  71. {compose_plugins-0.0.0 → compose_plugins-0.2.0}/LICENSE +0 -0
  72. {compose_plugins-0.0.0 → compose_plugins-0.2.0}/compose_plugins.egg-info/dependency_links.txt +0 -0
  73. {compose_plugins-0.0.0 → compose_plugins-0.2.0}/compose_plugins.egg-info/top_level.txt +0 -0
  74. {compose_plugins-0.0.0 → compose_plugins-0.2.0}/setup.cfg +0 -0
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: compose-plugins
3
+ Version: 0.2.0
4
+ Summary: The shared plug-in contract library (manifest, consent, version rule) for ComposeIO and Gnomon hosts
5
+ License: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: composebus==0.1.2
10
+ Dynamic: license-file
11
+
12
+ # compose-plugins
13
+
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.
18
+
19
+ Contract 0.2 is an additive MINOR over 0.1: optional manifest fields `license`
20
+ (an SPDX expression, informational) and `eula` (a package-relative UTF-8 text
21
+ file, shown verbatim at consent, its sha256 stored in the consent record);
22
+ `PluginManager.record_decline(prompt, *, decided_by)`; the append-only install
23
+ event log `installs.jsonl` and `PluginManager.install_log_findings()`; and a
24
+ confirm step in front of uninstall in the web manager. The one non-additive
25
+ change: the web manager's `POST .../uninstall` no longer uninstalls, it shows
26
+ the confirm screen.
27
+
28
+ One runtime dependency: `composebus==0.1.2` (the runtime `ComposePlugin` and
29
+ its `MessageType` names). No ComposeIO distribution is required, so a host
30
+ that is not ComposeIO can use the library on its own.
31
+
32
+ ## What is in the package
33
+
34
+ | module | what |
35
+ |---|---|
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 |
37
+ | `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
+ | `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
+ | `compose_plugins.consent` | consent content rendered from the manifest alone, the granted set, the widening rule, and the append-only consent-record store |
40
+ | `compose_plugins.host` | the `Host` protocol each host implements: consent gate, install root, own host-section validator and renderer, auth hook, `extra_panels`, supported isolation levels |
41
+ | `compose_plugins.lifecycle` | `PluginManager`: install, configure, enable, disable, upgrade and uninstall, with the state machine of the contract |
42
+ | `compose_plugins.config` | config validated against `config_schema` before the plug-in is instantiated; invalid config parks loudly |
43
+ | `compose_plugins.derive` | `compose-plugin build` (writes `config_schema` and `bus` into `manifest.json` from the class) and the enable-time class/manifest drift check |
44
+ | `compose_plugins.runner` | running a plug-in in-process, or in a child process over an inherited `AF_UNIX` socketpair (never a network listener) |
45
+ | `compose_plugins.store` | the install records (the registry), stored config, and the append-only install event log `InstallLog` with its findings |
46
+ | `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
+ | `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) |
49
+
50
+ ```python
51
+ from compose_plugins.package import read_manifest
52
+ from compose_plugins.manifest import validate_manifest
53
+
54
+ mf = read_manifest("path/to/plugin_dir_or.whl") # executes nothing
55
+ m = validate_manifest(mf.data, host="myhost",
56
+ section_validator=my_section_validator, package=mf.package)
57
+ ```
58
+
59
+ ## The conformance script
60
+
61
+ The contract is authoritative, and the conformance script is the arbiter
62
+ between hosts: a host that fails any step or negative control is
63
+ non-conformant. It runs the hello-world lifecycle in nine steps (install with
64
+ consent, configure, start, health, a publish/subscribe round trip, an upgrade
65
+ to v2 with re-consent and config migration, disable, re-enable, and uninstall
66
+ 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
68
+ per host and per isolation level the host supports. At the subprocess level it
69
+ also checks that the child holds no network socket and that a child crash is
70
+ reported as `failed(<reason>)`.
71
+
72
+ python -m compose_plugins.conformance --target <module>:<factory> --isolation inprocess|subprocess
73
+
74
+ The factory is called as `factory(isolation, workdir)` and returns a TARGET
75
+ with `.manager`, `.bus`, `.host`, `.isolation`, `.operator` and `.close()`,
76
+ plus the two members added in spec 95 r24:
77
+
78
+ - `foreign_host: str` (REQUIRED): the name of another host. NC4's paired
79
+ positive control puts an unknown key inside `hosts.<foreign_host>` and
80
+ expects this host to ignore it and install the plug-in. The key is never put
81
+ in this host's own section, so the control runs unchanged on every host. The
82
+ runner refuses to run before step 1 if `foreign_host` is absent
83
+ ("foreign_host missing"), equals `target.host.name`, or breaks the host-name
84
+ rule; the refusal names the value, the exit status is 2, and nothing is
85
+ installed.
86
+ - `host_section(fixture: str) -> dict` (optional): this host's own valid
87
+ 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
89
+ host, the runner writes that value at `hosts.<target.host.name>`, so the
90
+ consented `manifest_sha256` covers it. A target without the hook gets `{}`
91
+ there. The shared fixtures never decide a host's section: each host owns its
92
+ own.
93
+
94
+ The script prints the observed value for every step, and exits 0 only when
95
+ every step and control passes.
96
+
97
+ ## Tests
98
+
99
+ From a checkout of the ComposeIO repository:
100
+
101
+ pip install ./python/composebus ./python/compose_plugins -r python/compose_plugins/tests/requirements.txt
102
+ pytest python/compose_plugins/tests
@@ -0,0 +1,91 @@
1
+ # compose-plugins
2
+
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.
7
+
8
+ Contract 0.2 is an additive MINOR over 0.1: optional manifest fields `license`
9
+ (an SPDX expression, informational) and `eula` (a package-relative UTF-8 text
10
+ file, shown verbatim at consent, its sha256 stored in the consent record);
11
+ `PluginManager.record_decline(prompt, *, decided_by)`; the append-only install
12
+ event log `installs.jsonl` and `PluginManager.install_log_findings()`; and a
13
+ confirm step in front of uninstall in the web manager. The one non-additive
14
+ change: the web manager's `POST .../uninstall` no longer uninstalls, it shows
15
+ the confirm screen.
16
+
17
+ One runtime dependency: `composebus==0.1.2` (the runtime `ComposePlugin` and
18
+ its `MessageType` names). No ComposeIO distribution is required, so a host
19
+ that is not ComposeIO can use the library on its own.
20
+
21
+ ## What is in the package
22
+
23
+ | module | what |
24
+ |---|---|
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 |
26
+ | `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
+ | `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
+ | `compose_plugins.consent` | consent content rendered from the manifest alone, the granted set, the widening rule, and the append-only consent-record store |
29
+ | `compose_plugins.host` | the `Host` protocol each host implements: consent gate, install root, own host-section validator and renderer, auth hook, `extra_panels`, supported isolation levels |
30
+ | `compose_plugins.lifecycle` | `PluginManager`: install, configure, enable, disable, upgrade and uninstall, with the state machine of the contract |
31
+ | `compose_plugins.config` | config validated against `config_schema` before the plug-in is instantiated; invalid config parks loudly |
32
+ | `compose_plugins.derive` | `compose-plugin build` (writes `config_schema` and `bus` into `manifest.json` from the class) and the enable-time class/manifest drift check |
33
+ | `compose_plugins.runner` | running a plug-in in-process, or in a child process over an inherited `AF_UNIX` socketpair (never a network listener) |
34
+ | `compose_plugins.store` | the install records (the registry), stored config, and the append-only install event log `InstallLog` with its findings |
35
+ | `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
+ | `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) |
38
+
39
+ ```python
40
+ from compose_plugins.package import read_manifest
41
+ from compose_plugins.manifest import validate_manifest
42
+
43
+ mf = read_manifest("path/to/plugin_dir_or.whl") # executes nothing
44
+ m = validate_manifest(mf.data, host="myhost",
45
+ section_validator=my_section_validator, package=mf.package)
46
+ ```
47
+
48
+ ## The conformance script
49
+
50
+ The contract is authoritative, and the conformance script is the arbiter
51
+ between hosts: a host that fails any step or negative control is
52
+ non-conformant. It runs the hello-world lifecycle in nine steps (install with
53
+ consent, configure, start, health, a publish/subscribe round trip, an upgrade
54
+ to v2 with re-consent and config migration, disable, re-enable, and uninstall
55
+ 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
57
+ per host and per isolation level the host supports. At the subprocess level it
58
+ also checks that the child holds no network socket and that a child crash is
59
+ reported as `failed(<reason>)`.
60
+
61
+ python -m compose_plugins.conformance --target <module>:<factory> --isolation inprocess|subprocess
62
+
63
+ The factory is called as `factory(isolation, workdir)` and returns a TARGET
64
+ with `.manager`, `.bus`, `.host`, `.isolation`, `.operator` and `.close()`,
65
+ plus the two members added in spec 95 r24:
66
+
67
+ - `foreign_host: str` (REQUIRED): the name of another host. NC4's paired
68
+ positive control puts an unknown key inside `hosts.<foreign_host>` and
69
+ expects this host to ignore it and install the plug-in. The key is never put
70
+ in this host's own section, so the control runs unchanged on every host. The
71
+ runner refuses to run before step 1 if `foreign_host` is absent
72
+ ("foreign_host missing"), equals `target.host.name`, or breaks the host-name
73
+ rule; the refusal names the value, the exit status is 2, and nothing is
74
+ installed.
75
+ - `host_section(fixture: str) -> dict` (optional): this host's own valid
76
+ 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
78
+ host, the runner writes that value at `hosts.<target.host.name>`, so the
79
+ consented `manifest_sha256` covers it. A target without the hook gets `{}`
80
+ there. The shared fixtures never decide a host's section: each host owns its
81
+ own.
82
+
83
+ The script prints the observed value for every step, and exits 0 only when
84
+ every step and control passes.
85
+
86
+ ## Tests
87
+
88
+ From a checkout of the ComposeIO repository:
89
+
90
+ pip install ./python/composebus ./python/compose_plugins -r python/compose_plugins/tests/requirements.txt
91
+ pytest python/compose_plugins/tests
@@ -0,0 +1,26 @@
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]).
3
+
4
+ The manifest validator and JSON Schema (``manifest``), the no-execution manifest
5
+ and EULA reader and the manifest_sha256 rule (``package``), the version rule
6
+ (``version``), consent content, granted sets, widening and the consent-record
7
+ store (``consent``), the ``Host`` protocol (``host``), the lifecycle operations
8
+ and ``record_decline`` (``lifecycle``), config validation (``config``),
9
+ ``compose-plugin build`` and the drift check (``derive``), the in-process and
10
+ subprocess runner (``runner``), the registry, config and install-event-log
11
+ stores (``store``), the plain web Plugin Manager (``web``), and the conformance
12
+ script (``conformance``) with its hello-world fixtures. See README.md.
13
+
14
+ Contract 0.2 adds these exports ([CXC-PC-V02-STORES-COMPAT] manager-signatures).
15
+ """
16
+
17
+ __version__ = "0.2.0"
18
+
19
+ from .consent import eula_text_shown # noqa: E402
20
+ from .errors import ( # noqa: E402
21
+ EulaShaMismatch, InstallLogRefused, PromptNotPrepared, PromptStale,
22
+ )
23
+ from .store import InstallLog, InstallLogFinding # noqa: E402
24
+
25
+ __all__ = ["EulaShaMismatch", "InstallLog", "InstallLogFinding", "InstallLogRefused",
26
+ "PromptNotPrepared", "PromptStale", "__version__", "eula_text_shown"]
@@ -0,0 +1,117 @@
1
+ """The CHILD side of the subprocess runner. Run as
2
+ ``python -m compose_plugins._child --fd N`` by the runner only.
3
+
4
+ It reads ``configure`` then ``start``, builds a PRIVATE in-process ComposeBus
5
+ (never started: no clock, no heartbeat, no connector), starts the plug-in on
6
+ it, and bridges: every message the plug-in emits on a declared publish becomes
7
+ a bus frame to the host; every bus frame from the host is replayed with source
8
+ ``_host`` (never echoed back). It polls ``health_reason()`` and reports
9
+ ``_ctl: health`` / ``_ctl: degraded`` on change. ``stop`` stops the plug-in and
10
+ exits 0. An exception in the plug-in exits non-zero with the reason on stderr.
11
+ """
12
+ from __future__ import annotations
13
+
14
+ import argparse
15
+ import json
16
+ import socket
17
+ import sys
18
+ import threading
19
+ import traceback
20
+
21
+ from composebus.transport import BusMessage
22
+
23
+ from .derive import resolve_entry
24
+ from .runner import CTL_TO_CHILD, HOST_SOURCE, apply_to_bus, ctl_frame, frame_from_message
25
+
26
+ HEALTH_POLL_S = 0.2
27
+
28
+
29
+ def main(argv: "list[str] | None" = None) -> int:
30
+ ap = argparse.ArgumentParser()
31
+ ap.add_argument("--fd", type=int, required=True)
32
+ args = ap.parse_args(argv)
33
+ sock = socket.socket(fileno=args.fd)
34
+ rfile = sock.makefile("rb")
35
+ wlock = threading.Lock()
36
+
37
+ def send(data: bytes) -> None:
38
+ with wlock:
39
+ sock.sendall(data)
40
+
41
+ def read_obj() -> dict:
42
+ raw = rfile.readline()
43
+ if not raw:
44
+ raise SystemExit(0) # host closed the link
45
+ obj = json.loads(raw)
46
+ if not isinstance(obj, dict):
47
+ raise ValueError("frame is not a JSON object")
48
+ if "_ctl" in obj and obj["_ctl"] not in CTL_TO_CHILD:
49
+ print(f"protocol: _ctl {obj['_ctl']!r} refused", file=sys.stderr)
50
+ raise SystemExit(4)
51
+ return obj
52
+
53
+ cfg = read_obj()
54
+ if cfg.get("_ctl") != "configure":
55
+ print("protocol: first frame must be _ctl=configure", file=sys.stderr)
56
+ return 4
57
+ if read_obj().get("_ctl") != "start":
58
+ print("protocol: second frame must be _ctl=start", file=sys.stderr)
59
+ return 4
60
+ for p in reversed(cfg["sys_path"]):
61
+ sys.path.insert(0, p)
62
+ publishes = {tuple(x) for x in cfg["publishes"]}
63
+
64
+ from composebus.bus import ComposeIOBus
65
+ bus = ComposeIOBus(bus_id=f"child-{cfg['domain']}")
66
+
67
+ def forward(msg: BusMessage) -> None:
68
+ if msg.source == HOST_SOURCE:
69
+ return
70
+ if (msg.namespace, msg.type.name) in publishes:
71
+ send(frame_from_message(msg))
72
+
73
+ bus.on_message(forward)
74
+ try:
75
+ cls = resolve_entry(cfg["entry"])
76
+ plugin = cls(config=cfg["config"])
77
+ plugin.start(bus)
78
+ except Exception as exc:
79
+ traceback.print_exc(file=sys.stderr)
80
+ print(f"start raised {type(exc).__name__}: {exc}", file=sys.stderr)
81
+ return 3
82
+
83
+ stop = threading.Event()
84
+ last: "list[object]" = [object()]
85
+
86
+ def report() -> None:
87
+ probe = getattr(plugin, "health_reason", None)
88
+ reason = probe() if callable(probe) else None
89
+ if reason != last[0]:
90
+ last[0] = reason
91
+ send(ctl_frame("health", state="running") if reason is None
92
+ else ctl_frame("degraded", reason=reason))
93
+
94
+ report()
95
+
96
+ def poll() -> None:
97
+ while not stop.wait(HEALTH_POLL_S):
98
+ try:
99
+ report()
100
+ except Exception:
101
+ traceback.print_exc(file=sys.stderr)
102
+ stop.set()
103
+
104
+ threading.Thread(target=poll, daemon=True).start()
105
+ while True:
106
+ obj = read_obj()
107
+ if obj.get("_ctl") == "stop":
108
+ stop.set()
109
+ plugin.stop()
110
+ return 0
111
+ if "_ctl" in obj:
112
+ continue # configure/start again: ignored
113
+ apply_to_bus(bus, BusMessage.from_json(obj), HOST_SOURCE)
114
+
115
+
116
+ if __name__ == "__main__":
117
+ sys.exit(main())
@@ -0,0 +1,51 @@
1
+ """One-shot probe, run in a FRESH CHILD by ``compose_plugins.probe_client``.
2
+
3
+ python -m compose_plugins._probe --fd N
4
+ stdin: {"entry", "sys_path", "config", "nonce"} (read BEFORE plug-in code)
5
+ fd N: ONE line {"nonce", "resolve_error", "config_schema", "bus", "bus_error",
6
+ "config_errors"}, then fd N is closed.
7
+
8
+ stdout and stderr belong to the plug-in and are never read as the verdict.
9
+ """
10
+ from __future__ import annotations
11
+
12
+ import argparse
13
+ import json
14
+ import os
15
+ import sys
16
+
17
+
18
+ def main() -> int:
19
+ ap = argparse.ArgumentParser()
20
+ ap.add_argument("--fd", type=int, required=True)
21
+ args = ap.parse_args()
22
+ req = json.loads(sys.stdin.read()) # before ANY plug-in code runs
23
+ fd, nonce = args.fd, req["nonce"]
24
+ for p in reversed(req["sys_path"]):
25
+ sys.path.insert(0, p)
26
+ from .config import config_errors
27
+ from .derive import BuildRefused, derive_bus, derive_config_schema, resolve_entry
28
+ out: dict = {"nonce": nonce, "resolve_error": None, "config_schema": None, "bus": None,
29
+ "bus_error": None, "config_errors": []}
30
+ try:
31
+ cls = resolve_entry(req["entry"])
32
+ except Exception as exc:
33
+ out["resolve_error"] = f"{type(exc).__name__}: {exc}"
34
+ else:
35
+ out["config_schema"] = derive_config_schema(cls)
36
+ try:
37
+ out["bus"] = derive_bus(cls)
38
+ except BuildRefused as exc:
39
+ out["bus_error"] = str(exc)
40
+ out["config_errors"] = config_errors(cls.Config, req["config"])
41
+ data = (json.dumps(out) + "\n").encode("utf-8")
42
+ view = memoryview(data)
43
+ while view:
44
+ n = os.write(fd, view)
45
+ view = view[n:]
46
+ os.close(fd) # nothing written later can reach the host
47
+ return 0
48
+
49
+
50
+ if __name__ == "__main__":
51
+ sys.exit(main())
@@ -0,0 +1,27 @@
1
+ """Config validated BEFORE instantiation ([CXC-PC-LIFECYCLE-CONFIG]).
2
+
3
+ The same call and the same ``config:<field>: <message>`` park taxonomy as spec
4
+ 87's ``validate_config`` ([CXC-CSL-CONFIG-VALIDATION]): construct
5
+ ``Config(**payload)`` directly. Kept here because compose_plugins must not
6
+ depend on composeio; ``tests/test_wave2_*`` checks the two produce identical
7
+ reasons.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ from typing import Any
12
+
13
+ from pydantic import ValidationError
14
+
15
+
16
+ def config_errors(config_model, payload: Any) -> "list[str]":
17
+ if not isinstance(payload, dict):
18
+ return [f"config:<root>: expected an object, got {type(payload).__name__}"]
19
+ try:
20
+ config_model(**payload)
21
+ return []
22
+ except ValidationError as exc:
23
+ out = []
24
+ for err in exc.errors():
25
+ loc = ".".join(str(p) for p in err.get("loc", ())) or "<root>"
26
+ out.append(f"config:{loc}: {err.get('msg', 'invalid')}")
27
+ return out