Metadata-Version: 2.4
Name: juntai-platform-swp-stream
Version: 1.0.0
Summary: Fail-closed QueueTransport executor for Juntai Platform synthetic-workload processing
Author: Juntai contributors
License: Apache License
        Version 2.0, January 2004
        http://www.apache.org/licenses/
        
        Copyright 2026 Juntai contributors
        
        Licensed under the Apache License, Version 2.0 (the "License");
        you may not use this file except in compliance with the License.
        You may obtain a copy of the License at
        
            http://www.apache.org/licenses/LICENSE-2.0
        
        Unless required by applicable law or agreed to in writing, software
        distributed under the License is distributed on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        See the License for the specific language governing permissions and
        limitations under the License.
        
License-File: LICENSE
License-File: NOTICE
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.12
Requires-Dist: grpcio<2,>=1.74.0
Requires-Dist: juntai-iam==2.0.0
Requires-Dist: meridian-storage-core==1.0.0
Requires-Dist: meridian-storage-evidence==1.0.0
Requires-Dist: meridian-storage-semantics==1.0.0
Requires-Dist: meridian-storage-streaming==1.0.0
Provides-Extra: test
Requires-Dist: build==1.3.0; extra == 'test'
Requires-Dist: mypy==1.17.1; extra == 'test'
Requires-Dist: pytest-cov==6.2.1; extra == 'test'
Requires-Dist: pytest==8.4.2; extra == 'test'
Requires-Dist: ruff==0.12.11; extra == 'test'
Description-Content-Type: text/markdown

# Juntai Platform SWP Executor

`juntai-platform-swp-stream` is the fail-closed QueueTransport boundary between the
synthetic relay, Platform's SWP executor, and isolated worker Pods. It owns request
validation, trusted-context enforcement, deterministic ledger transitions, Meridian
streaming, audit evidence, recovery, and the executor-only worker attach client.

It deliberately does **not** own or expose storage Engines, adapters, provisioning,
physical locators, IAM policy sources, relay credentials, Kubernetes credentials, or a
worker-to-broker path.

## Trust and data flow

1. The relay terminates mTLS on QueueTransport port `7444`; its durable service identity is
   derived from the verified certificate, never from envelope fields.
2. `QueueTransportExecutor` validates the exact relay principal, application,
   authenticator reference, audience, resource indicator, and self-authority mode, then
   calls the injected Juntai IAM 2.0 authorization hook.
3. A separate Platform SWP executor identity is authorized for each Meridian operation.
   Relay authority is never installed in Meridian and is recorded only as the audit actor.
4. The injected Meridian Core runtime resolves six opaque logical resources: four
   QueueTransport streams, one structured ledger, and one audit-evidence resource.
5. Pending ledger transitions precede publication. Exact retries use the same
   idempotency keys; mismatched generation, message, or payload fingerprints fail closed.
6. External responses contain only QueueTransport fields. Meridian receipts, delivery
   tokens, cursors, runtime Bindings, and physical topology never cross the boundary.

## Installation

```bash
python -m pip install juntai-platform-swp-stream==1.0.0
```

Python 3.12 or newer is required, matching the released Meridian 1.0 contracts.

The release pins and verifies these immutable foundations:

| Package | Version |
| --- | --- |
| `juntai-iam` | `2.0.0` |
| `meridian-storage-core` | `1.0.0` |
| `meridian-storage-semantics` | `1.0.0` |
| `meridian-storage-streaming` | `1.0.0` |
| `meridian-storage-evidence` | `1.0.0` |

## Executor integration

Platform creates and starts `meridian_storage.Meridian` from the executor-only
`MERIDIAN_CONFIG`, validates its startup report, and injects it into `MeridianGateway`.
The package never parses that configuration and cannot resolve an adapter or physical
resource itself.

Platform also renders `JUNTAI_SWP_LOGICAL_RESOURCES` as one exact JSON object:

```json
{
  "audit": "<opaque evidence resource ref>",
  "cancellation": "<opaque streaming resource ref>",
  "intake": "<opaque streaming resource ref>",
  "ledger": "<opaque structured resource ref>",
  "outcome": "<opaque streaming resource ref>",
  "recovery": "<opaque streaming resource ref>"
}
```

Unknown, missing, duplicate, URI-like, broker-, Engine-, topic-, partition-, credential-,
or secret-bearing values are rejected. The four stream roles are stable; their values are
private deployment projections.

```python
from juntai_platform_swp_stream import LogicalResources, MeridianGateway

resources = LogicalResources.from_environment()
gateway = MeridianGateway(started_meridian_runtime, resources)
```

The host supplies `QueueTrustPolicy`, the IAM authorization hook, and the verified
executor `IdentityContext`. A QueueTransport handler supplies the relay's verified
`IdentityContext`, the endpoint's `LogicalChannel`, and `QueueRequest.from_mapping(...)`.
Authenticate the transport before decoding an application envelope.

## Deterministic states

| Operation | Durable transition | Retry behavior |
| --- | --- | --- |
| Submit | absent → `pending` → publish intake → `accepted` | exact pending resumes; exact accepted returns `duplicate` |
| Cancel | active → `cancellation_pending` → publish cancellation → `cancelled` | exact pending resumes; terminal cancellation is denied |
| Recover | exact `pending` → publish recovery → `accepted` | only the original message/generation/digest is accepted |
| Outcome | exact generation → publish digest-only outcome → `succeeded`/`failed` | Meridian idempotency key is stable |

Authentication and authorization failures, invalid physical fields, replay, and stale
cancellation are non-retryable. Only keepalive timeout, deadline exceeded, and dependency
unavailability are retryable. Audit append is part of successful submit/cancel/recovery;
an unavailable evidence catalog fails the request closed.

## Worker contract

Workers receive only these values from Platform:

```text
JUNTAI_SWP_TRANSPORT_FACTORY=juntai_platform_swp_stream:create_worker_client
address=grpcs://[literal Service ClusterIP]:7443?serverName=swp-executor.juntai-platform.svc.cluster.local
ca_file=/var/run/secrets/juntai/swp/ca.crt
token_file=/var/run/secrets/juntai/swp/token
claim_id=<1-200 printable ASCII characters>
claim_generation=<canonical integer 1..5>
pod_uid=<canonical UUID>
contract_manifest_file=<absolute file path>
contract_manifest_sha256=sha256:<64 lowercase hexadecimal characters>
```

`open()` verifies the manifest digest, creates an executor-only TLS channel, reads the
audience-bound token, sends `Auth` first, and requires an exact `Accepted` echo of claim,
generation, and Pod UID. A hostname address, wrong SAN, symlinked credential file, altered
manifest, or unexpected first frame fails closed. Workers receive no QueueTransport,
Meridian, broker, Kubernetes API, or physical storage configuration.

## Verification and release

```bash
python -m pip install '.[test]'
ruff check .
mypy src
pytest
python -m build
python scripts/verify_release.py dist
```

CI runs lint, type checking, tests, source-boundary checks, wheel installation, package
metadata verification, and deterministic release-evidence validation. Tags matching
`v*` build once, attest checksums/SBOM/provenance, publish through GitHub's trusted
PyPI environment, and attach the artifacts to the GitHub release.

## Security

See [SECURITY.md](SECURITY.md). Do not report credentials, tokens, physical topology, or
policy contents in public issues.
