unitysvc-core 0.3.4__tar.gz → 0.3.6__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 (55) hide show
  1. {unitysvc_core-0.3.4/src/unitysvc_core.egg-info → unitysvc_core-0.3.6}/PKG-INFO +24 -3
  2. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/README.md +23 -2
  3. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/pyproject.toml +1 -1
  4. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/grants.py +12 -4
  5. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/channel.py +4 -2
  6. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/offering_v1.py +21 -6
  7. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/validators.py +71 -5
  8. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/schema/offering_v1.json +10 -15
  9. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/validator.py +32 -4
  10. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6/src/unitysvc_core.egg-info}/PKG-INFO +24 -3
  11. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core.egg-info/SOURCES.txt +1 -0
  12. unitysvc_core-0.3.6/tests/test_external_apps.py +159 -0
  13. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_grants.py +25 -0
  14. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_validators.py +9 -0
  15. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/LICENSE +0 -0
  16. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/setup.cfg +0 -0
  17. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/__init__.py +0 -0
  18. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/__init__.py +0 -0
  19. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/base.py +0 -0
  20. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/documents.py +0 -0
  21. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/listing_data.py +0 -0
  22. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/listing_v1.py +0 -0
  23. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/offering_data.py +0 -0
  24. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/pricing.py +0 -0
  25. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/promotion_data.py +0 -0
  26. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/provider_data.py +0 -0
  27. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/provider_v1.py +0 -0
  28. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/service.py +0 -0
  29. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/models/service_group_data.py +0 -0
  30. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/parameter_usage.py +0 -0
  31. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/py.typed +0 -0
  32. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/schema/base.json +0 -0
  33. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/schema/listing_v1.json +0 -0
  34. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/schema/promotion_v1.json +0 -0
  35. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/schema/provider_v1.json +0 -0
  36. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/schema/service_group_v1.json +0 -0
  37. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core/utils.py +0 -0
  38. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core.egg-info/dependency_links.txt +0 -0
  39. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core.egg-info/requires.txt +0 -0
  40. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/src/unitysvc_core.egg-info/top_level.txt +0 -0
  41. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_access_interface_routing.py +0 -0
  42. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_canonical_interfaces.py +0 -0
  43. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_channel.py +0 -0
  44. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_effective_price.py +0 -0
  45. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_hidden_path_skip.py +0 -0
  46. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_listing_audience.py +0 -0
  47. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_offering_data.py +0 -0
  48. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_parameter_usage.py +0 -0
  49. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_pricing.py +0 -0
  50. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_provider_account_rate_limits.py +0 -0
  51. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_service_group.py +0 -0
  52. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_service_status.py +0 -0
  53. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_utils.py +0 -0
  54. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_validate_service.py +0 -0
  55. {unitysvc_core-0.3.4 → unitysvc_core-0.3.6}/tests/test_validator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitysvc-core
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Summary: Shared data models and validation helpers for UnitySVC packages
5
5
  Author-email: Bo Peng <bo.peng@unitysvc.com>
6
6
  Maintainer-email: Bo Peng <bo.peng@unitysvc.com>
@@ -214,7 +214,7 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
214
214
  - **A request's `options` are fixed.** Every option it declares is in the policy of an approved request, with the declared value; the customer may repeat it but not change or drop it. An option the request does not declare is the customer's to set at enrollment (a form rendered from the target's `options` schema). So `{"object": "service:ai", ...}` lets the customer pick the AI service, and `"options": "service=labs/llm-balanced"` pins it.
215
215
  - Several requests may name one object (two kinds of room) only if each fixes some option to a different value (`kind=chat`, `kind=feed`), so an approval says which one it is.
216
216
  - `limits` (`validate_limits`): `count_per_hour` / `count_per_day` / `count_per_month` / `count_total` (positive integer) and the same for `amount_` (finite positive decimal, as a number or a string). Limits are universal: the platform meters every call, so any service can be limited without exporting anything. The seller's limits only pre-fill the form; the customer sets them at enrollment, and an enrollment's own limits (unitysvc/unitysvc#2687) use the same shape. They are counted per policy entry (the enrollment's calls to that service) from the usage stream (counters keyed by scope, metric and window bucket), and the gateway refuses calls once one is exceeded.
217
- - **A room the platform provisions** (unitysvc/unitysvc#2830) is asked for with `resource:room`: `{"object": "resource:room", "permissions": ["create"], "required": true, "justification": "Creates your chat room", "options": "kind=chat&max_members=100"}`. Core knows the resource, so no catalog is consulted. The request must fix `kind`, the room's identity; each kind bounds the permissions (`chat`: `create`, a room the customer owns; `support`: `join`, `read`, `post`, the seller's private room with the customer; `announcement`: `join`, `read`; `discussion`: `join`, `read`, `post`). `max_members` (a positive integer) caps only a room the customer creates. A channel requests each kind at most once, and a resource takes no limits.
217
+ - **A room the platform provisions** (unitysvc/unitysvc#2830) is asked for with `resource:room`: `{"object": "resource:room", "permissions": ["create"], "required": true, "justification": "Creates your chat room", "options": "kind=chat&max_members=100"}`. Core knows the resource, so no catalog is consulted. The request must fix `kind`, the room's identity; each kind bounds the permissions (`chat`: `create`, a room the customer owns; `support`: `join`, `read`, `post`, the seller's private room with the customer; `announcement`: `join`, `read`; `discussion`: `join`, `read`, `post`). `max_members` (a positive integer) caps only a room the customer creates; `max_retention` (seconds, 0 or more) caps how long any provisioned room keeps messages, within the platform's own ceiling for the kind, and the room's owner may keep less. A channel requests each kind at most once, and a resource takes no limits.
218
218
  - **A longer-lived leased key** is asked for with one `apikey` entry: `{"object": "apikey", "required": false, "limits": {"api_key_lifespan": 14400}, "justification": "Batch runs take up to four hours"}`. It names the key itself, so it takes only `limits` (exactly `api_key_lifespan`, whole seconds from 1 to 86400), `required` and a `justification`, needs no catalog lookup, and grants nothing. Without it, a key the seller leases for the enrollment lives `DEFAULT_API_KEY_LIFESPAN` (3600 s). `api_key_lifespan` is valid only on this entry.
219
219
 
220
220
  **3. How options reach the service.** Not through the upstream URL: the gateway never changes a target's `base_url` or query to carry policy. How an option is applied is up to the service's implementation:
@@ -260,7 +260,7 @@ A policy has three kinds of entry (unitysvc/unitysvc#2770):
260
260
  | Channel key | What it is |
261
261
  | --- | --- |
262
262
  | `access_method` | `http` (default), `smtp`, `s3` or `mcp`; selects the server type |
263
- | `type` | normally derived by the platform; declare `external` (or `enrollable`) to state it |
263
+ | `type` | normally derived by the platform; declare `enrollable` to state it |
264
264
  | `description`, `is_active`, `sort_order` | display text; inactive channels are skipped; rank, lowest first |
265
265
  | `request_formats`, `applicable_interfaces` | the formats the channel serves; the interfaces that reach it (display only) |
266
266
  | `rate_limit_refs` | the provider rate limits it consumes |
@@ -272,6 +272,27 @@ The common one-server case writes the connection fields directly on the channel;
272
272
 
273
273
  Unknown keys are refused. Retired keys are refused with what to do instead (`RETIRED_CHANNEL_KEYS`): `raw`, `is_primary`, the listing-style parameter trio, `grants`, `rate_limits` (nothing reads it; use `rate_limit_refs`), `storage_type` (use `access_method: s3`), `response_rules`, `timeout_ms`, `transport`, and the platform-derived `customer_secrets_required` / `customer_secrets_optional`.
274
274
 
275
+ ### External apps and product links
276
+
277
+ An offering that declares no channel (`upstream_access_config` omitted or `{}`) is an **external app**: customers reach it at its own site, not through the gateway (unitysvc/unitysvc#2873). `external` is not a channel type. An external app:
278
+
279
+ - gives its homepage in `details.links.homepage` (required; the provider's homepage is not substituted);
280
+ - has no `user_access_interfaces` and no `list_price` (signup and payment happen at its site);
281
+ - needs no connectivity-test document.
282
+
283
+ `details.links` holds an offering's product links, for any service: up to 10 free display labels (at most 40 characters each) mapped to `https://` URLs without embedded credentials. When present it must include `homepage`, the primary product link. The rest of `details` stays free-form. `validate_details_links` checks it on every `offering_v1`.
284
+
285
+ ```json
286
+ {
287
+ "details": {
288
+ "links": {
289
+ "homepage": "https://app.example",
290
+ "documentation": "https://app.example/docs"
291
+ }
292
+ }
293
+ }
294
+ ```
295
+
275
296
  ### Enrollment parameters on channels
276
297
 
277
298
  A channel declares the enrollment parameters it reads, so each plan of a service asks for what it needs (unitysvc/unitysvc#2726). A listing declares none: `user_parameters_schema`, `user_parameters_ui_schema` and `service_options.ops_testing_parameters` are refused.
@@ -179,7 +179,7 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
179
179
  - **A request's `options` are fixed.** Every option it declares is in the policy of an approved request, with the declared value; the customer may repeat it but not change or drop it. An option the request does not declare is the customer's to set at enrollment (a form rendered from the target's `options` schema). So `{"object": "service:ai", ...}` lets the customer pick the AI service, and `"options": "service=labs/llm-balanced"` pins it.
180
180
  - Several requests may name one object (two kinds of room) only if each fixes some option to a different value (`kind=chat`, `kind=feed`), so an approval says which one it is.
181
181
  - `limits` (`validate_limits`): `count_per_hour` / `count_per_day` / `count_per_month` / `count_total` (positive integer) and the same for `amount_` (finite positive decimal, as a number or a string). Limits are universal: the platform meters every call, so any service can be limited without exporting anything. The seller's limits only pre-fill the form; the customer sets them at enrollment, and an enrollment's own limits (unitysvc/unitysvc#2687) use the same shape. They are counted per policy entry (the enrollment's calls to that service) from the usage stream (counters keyed by scope, metric and window bucket), and the gateway refuses calls once one is exceeded.
182
- - **A room the platform provisions** (unitysvc/unitysvc#2830) is asked for with `resource:room`: `{"object": "resource:room", "permissions": ["create"], "required": true, "justification": "Creates your chat room", "options": "kind=chat&max_members=100"}`. Core knows the resource, so no catalog is consulted. The request must fix `kind`, the room's identity; each kind bounds the permissions (`chat`: `create`, a room the customer owns; `support`: `join`, `read`, `post`, the seller's private room with the customer; `announcement`: `join`, `read`; `discussion`: `join`, `read`, `post`). `max_members` (a positive integer) caps only a room the customer creates. A channel requests each kind at most once, and a resource takes no limits.
182
+ - **A room the platform provisions** (unitysvc/unitysvc#2830) is asked for with `resource:room`: `{"object": "resource:room", "permissions": ["create"], "required": true, "justification": "Creates your chat room", "options": "kind=chat&max_members=100"}`. Core knows the resource, so no catalog is consulted. The request must fix `kind`, the room's identity; each kind bounds the permissions (`chat`: `create`, a room the customer owns; `support`: `join`, `read`, `post`, the seller's private room with the customer; `announcement`: `join`, `read`; `discussion`: `join`, `read`, `post`). `max_members` (a positive integer) caps only a room the customer creates; `max_retention` (seconds, 0 or more) caps how long any provisioned room keeps messages, within the platform's own ceiling for the kind, and the room's owner may keep less. A channel requests each kind at most once, and a resource takes no limits.
183
183
  - **A longer-lived leased key** is asked for with one `apikey` entry: `{"object": "apikey", "required": false, "limits": {"api_key_lifespan": 14400}, "justification": "Batch runs take up to four hours"}`. It names the key itself, so it takes only `limits` (exactly `api_key_lifespan`, whole seconds from 1 to 86400), `required` and a `justification`, needs no catalog lookup, and grants nothing. Without it, a key the seller leases for the enrollment lives `DEFAULT_API_KEY_LIFESPAN` (3600 s). `api_key_lifespan` is valid only on this entry.
184
184
 
185
185
  **3. How options reach the service.** Not through the upstream URL: the gateway never changes a target's `base_url` or query to carry policy. How an option is applied is up to the service's implementation:
@@ -225,7 +225,7 @@ A policy has three kinds of entry (unitysvc/unitysvc#2770):
225
225
  | Channel key | What it is |
226
226
  | --- | --- |
227
227
  | `access_method` | `http` (default), `smtp`, `s3` or `mcp`; selects the server type |
228
- | `type` | normally derived by the platform; declare `external` (or `enrollable`) to state it |
228
+ | `type` | normally derived by the platform; declare `enrollable` to state it |
229
229
  | `description`, `is_active`, `sort_order` | display text; inactive channels are skipped; rank, lowest first |
230
230
  | `request_formats`, `applicable_interfaces` | the formats the channel serves; the interfaces that reach it (display only) |
231
231
  | `rate_limit_refs` | the provider rate limits it consumes |
@@ -237,6 +237,27 @@ The common one-server case writes the connection fields directly on the channel;
237
237
 
238
238
  Unknown keys are refused. Retired keys are refused with what to do instead (`RETIRED_CHANNEL_KEYS`): `raw`, `is_primary`, the listing-style parameter trio, `grants`, `rate_limits` (nothing reads it; use `rate_limit_refs`), `storage_type` (use `access_method: s3`), `response_rules`, `timeout_ms`, `transport`, and the platform-derived `customer_secrets_required` / `customer_secrets_optional`.
239
239
 
240
+ ### External apps and product links
241
+
242
+ An offering that declares no channel (`upstream_access_config` omitted or `{}`) is an **external app**: customers reach it at its own site, not through the gateway (unitysvc/unitysvc#2873). `external` is not a channel type. An external app:
243
+
244
+ - gives its homepage in `details.links.homepage` (required; the provider's homepage is not substituted);
245
+ - has no `user_access_interfaces` and no `list_price` (signup and payment happen at its site);
246
+ - needs no connectivity-test document.
247
+
248
+ `details.links` holds an offering's product links, for any service: up to 10 free display labels (at most 40 characters each) mapped to `https://` URLs without embedded credentials. When present it must include `homepage`, the primary product link. The rest of `details` stays free-form. `validate_details_links` checks it on every `offering_v1`.
249
+
250
+ ```json
251
+ {
252
+ "details": {
253
+ "links": {
254
+ "homepage": "https://app.example",
255
+ "documentation": "https://app.example/docs"
256
+ }
257
+ }
258
+ }
259
+ ```
260
+
240
261
  ### Enrollment parameters on channels
241
262
 
242
263
  A channel declares the enrollment parameters it reads, so each plan of a service asks for what it needs (unitysvc/unitysvc#2726). A listing declares none: `user_parameters_schema`, `user_parameters_ui_schema` and `service_options.ops_testing_parameters` are refused.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "unitysvc-core"
7
- version = "0.3.4"
7
+ version = "0.3.6"
8
8
  description = "Shared data models and validation helpers for UnitySVC packages"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Bo Peng", email = "bo.peng@unitysvc.com" }]
@@ -81,7 +81,9 @@ customer consent and key issuance establish its *authority*.
81
81
  A request's ``object`` is ``service:<name>``; or ``resource:room``, a room the
82
82
  platform provisions for the enrollment (unitysvc/unitysvc#2830), whose
83
83
  ``kind`` (``chat``, ``support``, ``announcement``, ``discussion``) the
84
- request fixes and whose permissions the kind bounds (:data:`ROOM_KINDS`); or
84
+ request fixes and whose permissions the kind bounds (:data:`ROOM_KINDS`),
85
+ with optional caps on its members (``max_members``) and on how long it keeps
86
+ messages (``max_retention``, seconds); or
85
87
  ``apikey``: how long a key leased for the enrollment lives
86
88
  (``limits.api_key_lifespan``, up to a day, with a justification), which grants
87
89
  nothing. :func:`build_policy` turns a customer's approvals into the policy an
@@ -199,6 +201,10 @@ ROOM_KINDS: dict[str, frozenset[str]] = {
199
201
  }
200
202
  ROOM_KIND = "kind"
201
203
  ROOM_MAX_MEMBERS = "max_members"
204
+ # The longest the provisioned room keeps messages, in seconds (0: never
205
+ # stored); the platform's own ceiling for the kind still applies, and the
206
+ # room's owner may keep less (unitysvc/unitysvc#2907).
207
+ ROOM_MAX_RETENTION = "max_retention"
202
208
  RESOURCES: dict[str, Exports] = {
203
209
  "room": Exports(
204
210
  {name: () for name in ("create", "join", "read", "post")},
@@ -208,6 +214,7 @@ RESOURCES: dict[str, Exports] = {
208
214
  "properties": {
209
215
  ROOM_KIND: {"type": "string", "enum": list(ROOM_KINDS)},
210
216
  ROOM_MAX_MEMBERS: {"type": "integer", "minimum": 1},
217
+ ROOM_MAX_RETENTION: {"type": "integer", "minimum": 0},
211
218
  },
212
219
  },
213
220
  ),
@@ -617,9 +624,10 @@ def check_resource(where: str, obj: str, permissions: list[str], options: dict[s
617
624
  not allow, for a request and for a policy entry alike.
618
625
 
619
626
  A room claim names its ``kind`` in its options; its permissions are some
620
- of those the kind allows, and ``max_members`` (a positive integer) only
621
- caps a room the customer creates. A resource is provisioned, not called,
622
- so it takes no limits.
627
+ of those the kind allows, ``max_members`` (a positive integer) only caps
628
+ a room the customer creates, and ``max_retention`` (seconds, 0 or more)
629
+ caps how long any provisioned room keeps messages. A resource is
630
+ provisioned, not called, so it takes no limits.
623
631
  """
624
632
  check_claim(where, obj, permissions, options, RESOURCES[obj.removeprefix(RESOURCE_PREFIX)])
625
633
  if limits:
@@ -165,7 +165,9 @@ class McpServer(_Server):
165
165
  allowed_hosts: list[str] | None = None
166
166
 
167
167
 
168
- ChannelType = Literal["unbound", "secret_bound", "enrollable", "me_bound", "external"]
168
+ # Derived by the platform. An app with no channel at all (an external app,
169
+ # unitysvc/unitysvc#2873) is not a channel type: it declares no channel.
170
+ ChannelType = Literal["unbound", "secret_bound", "enrollable", "me_bound"]
169
171
 
170
172
  # Keys a channel no longer takes, with what to do instead.
171
173
  RETIRED_CHANNEL_KEYS: dict[str, str] = {
@@ -193,7 +195,7 @@ class _ChannelBase(BaseModel):
193
195
 
194
196
  type: ChannelType | None = Field(
195
197
  default=None,
196
- description="Normally derived by the platform; declare 'external' (or 'enrollable') to state it",
198
+ description="Normally derived by the platform; declare 'enrollable' to state it",
197
199
  )
198
200
  description: str | None = None
199
201
  is_active: bool = True
@@ -1,13 +1,13 @@
1
1
  from datetime import datetime
2
2
  from typing import Any
3
3
 
4
- from pydantic import ConfigDict, Field, HttpUrl, field_validator
4
+ from pydantic import ConfigDict, Field, HttpUrl, field_validator, model_validator
5
5
 
6
6
  from .channel import UpstreamAccessConfig
7
7
  from .documents import DocumentData
8
8
  from .offering_data import ServiceOfferingData
9
9
  from .pricing import Pricing
10
- from .validators import validate_service_identifier
10
+ from .validators import validate_details_links, validate_service_identifier
11
11
 
12
12
 
13
13
  class OfferingV1(ServiceOfferingData):
@@ -33,16 +33,22 @@ class OfferingV1(ServiceOfferingData):
33
33
  # Static information (optional — not all service types have meaningful details)
34
34
  details: dict[str, Any] = Field( # type: ignore[assignment]
35
35
  default_factory=dict,
36
- description="Dictionary of static features and information",
36
+ description=(
37
+ "Dictionary of static features and information. Its 'links' key holds the product "
38
+ "links (label -> https:// URL, including 'homepage'), required when the offering "
39
+ "declares no channel"
40
+ ),
37
41
  )
38
42
 
39
43
  # Convenience field for logo (converted to documents during import)
40
44
  logo: str | HttpUrl | None = None
41
45
 
42
- # Required in file validation (the base allows None and keeps channels as
43
- # plain dicts, for stored data the platform has annotated).
46
+ # The base allows None and keeps channels as plain dicts, for stored data
47
+ # the platform has annotated. Omitted and empty are the same: an offering
48
+ # with no channel, an external app reached at its own site (#2873).
44
49
  upstream_access_config: UpstreamAccessConfig = Field( # type: ignore[assignment]
45
- description="Upstream access channels, keyed by channel name",
50
+ default_factory=lambda: UpstreamAccessConfig({}),
51
+ description="Upstream access channels, keyed by channel name; omit for an external app",
46
52
  )
47
53
 
48
54
  documents: dict[str, DocumentData] | None = Field( # type: ignore[assignment]
@@ -55,6 +61,15 @@ class OfferingV1(ServiceOfferingData):
55
61
  description="Payout pricing: How to calculate seller payout",
56
62
  )
57
63
 
64
+ @model_validator(mode="after")
65
+ def _validate_links(self) -> "OfferingV1":
66
+ """Product links are well formed, and an offering with no channel has
67
+ its homepage (unitysvc/unitysvc#2873)."""
68
+ channel_less = not self.upstream_access_config.root
69
+ if errors := validate_details_links(self.details, channel_less=channel_less):
70
+ raise ValueError("; ".join(errors))
71
+ return self
72
+
58
73
  @field_validator("name")
59
74
  @classmethod
60
75
  def validate_name_format(cls, v: str) -> str:
@@ -915,11 +915,11 @@ def validate_mcp_offering(data: dict[str, Any] | None) -> list[str]:
915
915
  if mcp_channels:
916
916
  declarations.append("MCP upstream channel(s) " + ", ".join(repr(name) for name in mcp_channels))
917
917
  if declarations:
918
- return [
919
- f"service_type {service_type!r} may not declare "
920
- + "; ".join(declarations)
921
- + "; use service_type 'mcp' instead"
922
- ]
918
+ # service_type is optional (unitysvc/unitysvc#2833): name what is there.
919
+ declared = (
920
+ f"service_type {service_type!r}" if service_type is not None else "an offering without service_type"
921
+ )
922
+ return [f"{declared} may not declare " + "; ".join(declarations) + "; use service_type 'mcp' instead"]
923
923
  return []
924
924
 
925
925
  if not channels or not isinstance(channels, dict):
@@ -1297,3 +1297,69 @@ def validate_listing_jinja_var_references(data: dict[str, Any] | None) -> list[s
1297
1297
  errors.append(f"{field_path}: Jinja syntax error in '{value}' — {exc.message}.")
1298
1298
 
1299
1299
  return errors
1300
+
1301
+
1302
+ HOMEPAGE_LINK = "homepage"
1303
+ MAX_LINKS = 10
1304
+ MAX_LINK_LABEL_LENGTH = 40
1305
+
1306
+
1307
+ def validate_details_links(details: dict[str, Any] | None, *, channel_less: bool) -> list[str]:
1308
+ """Check an offering's product links, ``details.links`` (unitysvc/unitysvc#2873).
1309
+
1310
+ Product links (homepage, documentation, support, …) describe the product,
1311
+ whether or not it is delivered through the gateway, and are kept apart from
1312
+ the operational ``upstream_access_config``. When present, ``details.links``
1313
+ maps up to ``MAX_LINKS`` nonempty display labels (at most
1314
+ ``MAX_LINK_LABEL_LENGTH`` characters) to ``https://`` URLs without embedded
1315
+ credentials, and includes ``homepage``, the primary product link; the rest
1316
+ of ``details`` stays free-form. An offering with no channel (an app reached
1317
+ at its own site) must provide it: its homepage is how customers reach it.
1318
+ """
1319
+ from pydantic import HttpUrl, TypeAdapter, ValidationError
1320
+
1321
+ url_adapter = TypeAdapter(HttpUrl)
1322
+ links = (details or {}).get("links")
1323
+ if links is None:
1324
+ if channel_less:
1325
+ return [
1326
+ "An offering with no upstream_access_config channel is an external app: "
1327
+ f"details.links.{HOMEPAGE_LINK} must give its https:// homepage"
1328
+ ]
1329
+ return []
1330
+ if not isinstance(links, dict):
1331
+ return ["details.links must be an object of link label -> https:// URL"]
1332
+ errors: list[str] = []
1333
+ if len(links) > MAX_LINKS:
1334
+ errors.append(f"details.links may hold at most {MAX_LINKS} links, got {len(links)}")
1335
+ for label, url in links.items():
1336
+ where = f"details.links.{label}"
1337
+ if not isinstance(label, str) or not label.strip():
1338
+ errors.append("details.links: a link label must be a nonempty string")
1339
+ continue
1340
+ if len(label) > MAX_LINK_LABEL_LENGTH:
1341
+ errors.append(f"details.links: the label {label!r} is longer than {MAX_LINK_LABEL_LENGTH} characters")
1342
+ if not isinstance(url, str) or not url.strip():
1343
+ errors.append(f"{where} must be a nonempty https:// URL")
1344
+ continue
1345
+ # HttpUrl repairs some malformed input (``https:app.example`` becomes
1346
+ # ``https://app.example/``), but the original string is what is stored
1347
+ # and rendered as an href, where it would resolve relative to the
1348
+ # page. So the string itself must be an absolute ``https://`` URL with
1349
+ # an authority; HttpUrl then checks the host, port and the rest.
1350
+ authority = url[len("https://") :]
1351
+ if url != url.strip() or not url.lower().startswith("https://") or authority[:1] in ("", "/", "\\"):
1352
+ errors.append(f"{where} must be an https:// URL, got {url!r}")
1353
+ continue
1354
+ try:
1355
+ parsed = url_adapter.validate_python(url)
1356
+ except (ValidationError, ValueError):
1357
+ errors.append(f"{where} must be an https:// URL, got {url!r}")
1358
+ continue
1359
+ if parsed.scheme != "https" or not parsed.host:
1360
+ errors.append(f"{where} must be an https:// URL, got {url!r}")
1361
+ elif parsed.username is not None or parsed.password is not None:
1362
+ errors.append(f"{where} must not embed credentials")
1363
+ if HOMEPAGE_LINK not in links:
1364
+ errors.append(f"details.links must include '{HOMEPAGE_LINK}', the primary product link")
1365
+ return errors
@@ -1242,8 +1242,7 @@
1242
1242
  "unbound",
1243
1243
  "secret_bound",
1244
1244
  "enrollable",
1245
- "me_bound",
1246
- "external"
1245
+ "me_bound"
1247
1246
  ],
1248
1247
  "type": "string"
1249
1248
  },
@@ -1252,7 +1251,7 @@
1252
1251
  }
1253
1252
  ],
1254
1253
  "default": null,
1255
- "description": "Normally derived by the platform; declare 'external' (or 'enrollable') to state it",
1254
+ "description": "Normally derived by the platform; declare 'enrollable' to state it",
1256
1255
  "title": "Type"
1257
1256
  },
1258
1257
  "upstream_format": {
@@ -1993,8 +1992,7 @@
1993
1992
  "unbound",
1994
1993
  "secret_bound",
1995
1994
  "enrollable",
1996
- "me_bound",
1997
- "external"
1995
+ "me_bound"
1998
1996
  ],
1999
1997
  "type": "string"
2000
1998
  },
@@ -2003,7 +2001,7 @@
2003
2001
  }
2004
2002
  ],
2005
2003
  "default": null,
2006
- "description": "Normally derived by the platform; declare 'external' (or 'enrollable') to state it",
2004
+ "description": "Normally derived by the platform; declare 'enrollable' to state it",
2007
2005
  "title": "Type"
2008
2006
  },
2009
2007
  "weight": {
@@ -2750,8 +2748,7 @@
2750
2748
  "unbound",
2751
2749
  "secret_bound",
2752
2750
  "enrollable",
2753
- "me_bound",
2754
- "external"
2751
+ "me_bound"
2755
2752
  ],
2756
2753
  "type": "string"
2757
2754
  },
@@ -2760,7 +2757,7 @@
2760
2757
  }
2761
2758
  ],
2762
2759
  "default": null,
2763
- "description": "Normally derived by the platform; declare 'external' (or 'enrollable') to state it",
2760
+ "description": "Normally derived by the platform; declare 'enrollable' to state it",
2764
2761
  "title": "Type"
2765
2762
  },
2766
2763
  "weight": {
@@ -3184,8 +3181,7 @@
3184
3181
  "unbound",
3185
3182
  "secret_bound",
3186
3183
  "enrollable",
3187
- "me_bound",
3188
- "external"
3184
+ "me_bound"
3189
3185
  ],
3190
3186
  "type": "string"
3191
3187
  },
@@ -3194,7 +3190,7 @@
3194
3190
  }
3195
3191
  ],
3196
3192
  "default": null,
3197
- "description": "Normally derived by the platform; declare 'external' (or 'enrollable') to state it",
3193
+ "description": "Normally derived by the platform; declare 'enrollable' to state it",
3198
3194
  "title": "Type"
3199
3195
  },
3200
3196
  "username": {
@@ -3667,7 +3663,7 @@
3667
3663
  },
3668
3664
  "details": {
3669
3665
  "additionalProperties": true,
3670
- "description": "Dictionary of static features and information",
3666
+ "description": "Dictionary of static features and information. Its 'links' key holds the product links (label -> https:// URL, including 'homepage'), required when the offering declares no channel",
3671
3667
  "title": "Details",
3672
3668
  "type": "object"
3673
3669
  },
@@ -3888,14 +3884,13 @@
3888
3884
  },
3889
3885
  "upstream_access_config": {
3890
3886
  "$ref": "#/$defs/UpstreamAccessConfig",
3891
- "description": "Upstream access channels, keyed by channel name"
3887
+ "description": "Upstream access channels, keyed by channel name; omit for an external app"
3892
3888
  }
3893
3889
  },
3894
3890
  "required": [
3895
3891
  "name",
3896
3892
  "summary",
3897
3893
  "description",
3898
- "upstream_access_config",
3899
3894
  "time_created"
3900
3895
  ],
3901
3896
  "title": "OfferingV1",
@@ -670,12 +670,39 @@ class DataValidator:
670
670
  f"digits and '.', '_', ':', '-', with no 'org/' prefix (e.g. 'glm-5.2'), got {value!r}."
671
671
  ]
672
672
 
673
- def validate_connectivity_test_exists(self, data: dict[str, Any], schema_name: str) -> list[str]:
673
+ @staticmethod
674
+ def _is_channel_less(offering: dict[str, Any] | None) -> bool:
675
+ """Whether an offering declares no channel: an external app (#2873)."""
676
+ return isinstance(offering, dict) and not offering.get("upstream_access_config")
677
+
678
+ def validate_external_app_listing(self, data: dict[str, Any], offering: dict[str, Any] | None) -> list[str]:
679
+ """A listing whose offering declares no channel is an external app
680
+ (unitysvc/unitysvc#2873): reached at its homepage, so it has nothing to
681
+ route to and no price (signup and payment happen at the seller's site)."""
682
+ if not self._is_channel_less(offering):
683
+ return []
684
+ errors: list[str] = []
685
+ if data.get("user_access_interfaces"):
686
+ errors.append(
687
+ "An external app (its offering declares no channel) has nothing to route to: "
688
+ "remove user_access_interfaces"
689
+ )
690
+ if data.get("list_price"):
691
+ errors.append(
692
+ "An external app (its offering declares no channel) is paid for at the seller's site: remove list_price"
693
+ )
694
+ return errors
695
+
696
+ def validate_connectivity_test_exists(
697
+ self, data: dict[str, Any], schema_name: str, *, offering: dict[str, Any] | None = None
698
+ ) -> list[str]:
674
699
  """Validate that at least one connectivity_test document exists.
675
700
 
676
701
  For listing_v1 data, the documents section must contain at least one
677
702
  document with category "connectivity_test". This is required for
678
- automated service testing during the publish workflow.
703
+ automated service testing during the publish workflow. An external
704
+ app (its offering declares no channel) needs none: the platform checks
705
+ its product links instead (unitysvc/unitysvc#2873).
679
706
 
680
707
  Args:
681
708
  data: The data to validate
@@ -687,7 +714,7 @@ class DataValidator:
687
714
  errors: list[str] = []
688
715
 
689
716
  # Only validate listing_v1 schema
690
- if schema_name != "listing_v1":
717
+ if schema_name != "listing_v1" or self._is_channel_less(offering):
691
718
  return errors
692
719
 
693
720
  documents = data.get("documents")
@@ -1041,7 +1068,7 @@ class DataValidator:
1041
1068
  errors.extend(service_options_errors)
1042
1069
 
1043
1070
  # Validate at least one connectivity_test document exists (listing_v1 only)
1044
- connectivity_errors = self.validate_connectivity_test_exists(data, schema_name)
1071
+ connectivity_errors = self.validate_connectivity_test_exists(data, schema_name, offering=offering)
1045
1072
  errors.extend(connectivity_errors)
1046
1073
 
1047
1074
  # Validate S3, SMTP, MCP, and API-gateway interfaces (listing_v1 only)
@@ -1064,6 +1091,7 @@ class DataValidator:
1064
1091
  errors.extend(validate_listing_mcp_base_urls(uai))
1065
1092
  errors.extend(validate_listing_jinja_var_references(data))
1066
1093
  errors.extend(validate_listing_interfaces_are_canonical(uai))
1094
+ errors.extend(self.validate_external_app_listing(data, offering))
1067
1095
  if offering is not None:
1068
1096
  errors.extend(
1069
1097
  validate_required_parameter_usage(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitysvc-core
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Summary: Shared data models and validation helpers for UnitySVC packages
5
5
  Author-email: Bo Peng <bo.peng@unitysvc.com>
6
6
  Maintainer-email: Bo Peng <bo.peng@unitysvc.com>
@@ -214,7 +214,7 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
214
214
  - **A request's `options` are fixed.** Every option it declares is in the policy of an approved request, with the declared value; the customer may repeat it but not change or drop it. An option the request does not declare is the customer's to set at enrollment (a form rendered from the target's `options` schema). So `{"object": "service:ai", ...}` lets the customer pick the AI service, and `"options": "service=labs/llm-balanced"` pins it.
215
215
  - Several requests may name one object (two kinds of room) only if each fixes some option to a different value (`kind=chat`, `kind=feed`), so an approval says which one it is.
216
216
  - `limits` (`validate_limits`): `count_per_hour` / `count_per_day` / `count_per_month` / `count_total` (positive integer) and the same for `amount_` (finite positive decimal, as a number or a string). Limits are universal: the platform meters every call, so any service can be limited without exporting anything. The seller's limits only pre-fill the form; the customer sets them at enrollment, and an enrollment's own limits (unitysvc/unitysvc#2687) use the same shape. They are counted per policy entry (the enrollment's calls to that service) from the usage stream (counters keyed by scope, metric and window bucket), and the gateway refuses calls once one is exceeded.
217
- - **A room the platform provisions** (unitysvc/unitysvc#2830) is asked for with `resource:room`: `{"object": "resource:room", "permissions": ["create"], "required": true, "justification": "Creates your chat room", "options": "kind=chat&max_members=100"}`. Core knows the resource, so no catalog is consulted. The request must fix `kind`, the room's identity; each kind bounds the permissions (`chat`: `create`, a room the customer owns; `support`: `join`, `read`, `post`, the seller's private room with the customer; `announcement`: `join`, `read`; `discussion`: `join`, `read`, `post`). `max_members` (a positive integer) caps only a room the customer creates. A channel requests each kind at most once, and a resource takes no limits.
217
+ - **A room the platform provisions** (unitysvc/unitysvc#2830) is asked for with `resource:room`: `{"object": "resource:room", "permissions": ["create"], "required": true, "justification": "Creates your chat room", "options": "kind=chat&max_members=100"}`. Core knows the resource, so no catalog is consulted. The request must fix `kind`, the room's identity; each kind bounds the permissions (`chat`: `create`, a room the customer owns; `support`: `join`, `read`, `post`, the seller's private room with the customer; `announcement`: `join`, `read`; `discussion`: `join`, `read`, `post`). `max_members` (a positive integer) caps only a room the customer creates; `max_retention` (seconds, 0 or more) caps how long any provisioned room keeps messages, within the platform's own ceiling for the kind, and the room's owner may keep less. A channel requests each kind at most once, and a resource takes no limits.
218
218
  - **A longer-lived leased key** is asked for with one `apikey` entry: `{"object": "apikey", "required": false, "limits": {"api_key_lifespan": 14400}, "justification": "Batch runs take up to four hours"}`. It names the key itself, so it takes only `limits` (exactly `api_key_lifespan`, whole seconds from 1 to 86400), `required` and a `justification`, needs no catalog lookup, and grants nothing. Without it, a key the seller leases for the enrollment lives `DEFAULT_API_KEY_LIFESPAN` (3600 s). `api_key_lifespan` is valid only on this entry.
219
219
 
220
220
  **3. How options reach the service.** Not through the upstream URL: the gateway never changes a target's `base_url` or query to carry policy. How an option is applied is up to the service's implementation:
@@ -260,7 +260,7 @@ A policy has three kinds of entry (unitysvc/unitysvc#2770):
260
260
  | Channel key | What it is |
261
261
  | --- | --- |
262
262
  | `access_method` | `http` (default), `smtp`, `s3` or `mcp`; selects the server type |
263
- | `type` | normally derived by the platform; declare `external` (or `enrollable`) to state it |
263
+ | `type` | normally derived by the platform; declare `enrollable` to state it |
264
264
  | `description`, `is_active`, `sort_order` | display text; inactive channels are skipped; rank, lowest first |
265
265
  | `request_formats`, `applicable_interfaces` | the formats the channel serves; the interfaces that reach it (display only) |
266
266
  | `rate_limit_refs` | the provider rate limits it consumes |
@@ -272,6 +272,27 @@ The common one-server case writes the connection fields directly on the channel;
272
272
 
273
273
  Unknown keys are refused. Retired keys are refused with what to do instead (`RETIRED_CHANNEL_KEYS`): `raw`, `is_primary`, the listing-style parameter trio, `grants`, `rate_limits` (nothing reads it; use `rate_limit_refs`), `storage_type` (use `access_method: s3`), `response_rules`, `timeout_ms`, `transport`, and the platform-derived `customer_secrets_required` / `customer_secrets_optional`.
274
274
 
275
+ ### External apps and product links
276
+
277
+ An offering that declares no channel (`upstream_access_config` omitted or `{}`) is an **external app**: customers reach it at its own site, not through the gateway (unitysvc/unitysvc#2873). `external` is not a channel type. An external app:
278
+
279
+ - gives its homepage in `details.links.homepage` (required; the provider's homepage is not substituted);
280
+ - has no `user_access_interfaces` and no `list_price` (signup and payment happen at its site);
281
+ - needs no connectivity-test document.
282
+
283
+ `details.links` holds an offering's product links, for any service: up to 10 free display labels (at most 40 characters each) mapped to `https://` URLs without embedded credentials. When present it must include `homepage`, the primary product link. The rest of `details` stays free-form. `validate_details_links` checks it on every `offering_v1`.
284
+
285
+ ```json
286
+ {
287
+ "details": {
288
+ "links": {
289
+ "homepage": "https://app.example",
290
+ "documentation": "https://app.example/docs"
291
+ }
292
+ }
293
+ }
294
+ ```
295
+
275
296
  ### Enrollment parameters on channels
276
297
 
277
298
  A channel declares the enrollment parameters it reads, so each plan of a service asks for what it needs (unitysvc/unitysvc#2726). A listing declares none: `user_parameters_schema`, `user_parameters_ui_schema` and `service_options.ops_testing_parameters` are refused.
@@ -37,6 +37,7 @@ tests/test_access_interface_routing.py
37
37
  tests/test_canonical_interfaces.py
38
38
  tests/test_channel.py
39
39
  tests/test_effective_price.py
40
+ tests/test_external_apps.py
40
41
  tests/test_grants.py
41
42
  tests/test_hidden_path_skip.py
42
43
  tests/test_listing_audience.py
@@ -0,0 +1,159 @@
1
+ """External apps and product links (unitysvc/unitysvc#2873).
2
+
3
+ An offering may declare no channel: it is then an external app, reached at its
4
+ own homepage, which ``details.links.homepage`` must give. ``details.links`` is
5
+ validated for every offering that declares it, and ``external`` is no longer a
6
+ channel type.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import copy
12
+ from pathlib import Path
13
+ from typing import Any
14
+
15
+ import pytest
16
+
17
+ from unitysvc_core.models.channel import UpstreamAccessConfig
18
+ from unitysvc_core.models.offering_v1 import OfferingV1
19
+ from unitysvc_core.models.validators import validate_details_links
20
+ from unitysvc_core.utils import load_data_file
21
+ from unitysvc_core.validator import DataValidator
22
+
23
+ SCHEMA_DIR = Path(__file__).parents[1] / "src" / "unitysvc_core" / "schema"
24
+ EXAMPLES = Path(__file__).parent / "example_data"
25
+ SERVICE1 = EXAMPLES / "provider1" / "services" / "service1"
26
+ HOMEPAGE = {"homepage": "https://app.example"}
27
+
28
+
29
+ def _offering(**changes: Any) -> dict[str, Any]:
30
+ data, _ = load_data_file(next(SERVICE1.glob("offering.*")))
31
+ assert data is not None
32
+ data = copy.deepcopy(data)
33
+ data.update(changes)
34
+ return data
35
+
36
+
37
+ def _external(**changes: Any) -> dict[str, Any]:
38
+ data = _offering(details={"links": dict(HOMEPAGE)}, **changes)
39
+ data.pop("upstream_access_config", None)
40
+ data.pop("service_type", None)
41
+ return data
42
+
43
+
44
+ @pytest.fixture
45
+ def validator() -> DataValidator:
46
+ return DataValidator(EXAMPLES, SCHEMA_DIR)
47
+
48
+
49
+ class TestLinks:
50
+ def test_links_are_optional_with_a_channel(self) -> None:
51
+ assert validate_details_links({}, channel_less=False) == []
52
+
53
+ def test_labels_are_free_and_homepage_is_required_when_links_exist(self) -> None:
54
+ links = {"homepage": "https://a.example", "Status page": "https://status.a.example"}
55
+ assert validate_details_links({"links": links}, channel_less=False) == []
56
+
57
+ errors = validate_details_links({"links": {"docs": "https://a.example/docs"}}, channel_less=False)
58
+ assert any("must include 'homepage'" in e for e in errors)
59
+
60
+ @pytest.mark.parametrize(
61
+ ("url", "message"),
62
+ [
63
+ ("http://a.example", "https:// URL"),
64
+ ("mailto:help@a.example", "https:// URL"),
65
+ ("https://", "https:// URL"),
66
+ ("https://app.example:abc", "https:// URL"),
67
+ ("https://app.example:99999", "https:// URL"),
68
+ ("https://bad host.example", "https:// URL"),
69
+ ("https://[broken", "https:// URL"),
70
+ ("https://[::1", "https:// URL"),
71
+ ("https:app.example", "https:// URL"),
72
+ ("https:/app.example", "https:// URL"),
73
+ ("https:///app.example", "https:// URL"),
74
+ ("https:\\\\app.example", "https:// URL"),
75
+ (" https://app.example", "https:// URL"),
76
+ ("https://user:pw@a.example", "embed credentials"),
77
+ ("", "nonempty"),
78
+ ],
79
+ )
80
+ def test_a_malformed_link_is_rejected(self, url: str, message: str) -> None:
81
+ errors = validate_details_links({"links": {"homepage": url}}, channel_less=False)
82
+ assert any(message in e for e in errors), errors
83
+
84
+ def test_labels_are_short_and_links_few(self) -> None:
85
+ long_label = {**HOMEPAGE, "x" * 41: "https://a.example/x"}
86
+ assert any("longer than 40" in e for e in validate_details_links({"links": long_label}, channel_less=False))
87
+
88
+ many = {**HOMEPAGE, **{f"page {i}": f"https://a.example/{i}" for i in range(10)}}
89
+ assert any("at most 10 links" in e for e in validate_details_links({"links": many}, channel_less=False))
90
+
91
+ def test_an_empty_label_is_rejected(self) -> None:
92
+ errors = validate_details_links({"links": {**HOMEPAGE, " ": "https://a.example/x"}}, channel_less=False)
93
+ assert any("nonempty string" in e for e in errors)
94
+
95
+ def test_other_details_stay_free_form(self) -> None:
96
+ details = {"links": dict(HOMEPAGE), "context_length": 8192, "anything": {"goes": True}}
97
+ assert validate_details_links(details, channel_less=True) == []
98
+
99
+
100
+ class TestOffering:
101
+ def test_an_omitted_or_empty_config_is_an_external_app(self) -> None:
102
+ omitted = OfferingV1.model_validate(_external())
103
+ empty = OfferingV1.model_validate(_external(upstream_access_config={}))
104
+
105
+ assert omitted.upstream_access_config.root == {}
106
+ assert empty.upstream_access_config.root == {}
107
+
108
+ def test_an_external_app_needs_its_homepage(self) -> None:
109
+ data = _external()
110
+ data["details"] = {}
111
+ with pytest.raises(ValueError, match="external app"):
112
+ OfferingV1.model_validate(data)
113
+
114
+ def test_a_service_with_a_channel_rejects_malformed_links(self) -> None:
115
+ with pytest.raises(ValueError, match="https:// URL"):
116
+ OfferingV1.model_validate(_offering(details={"links": {"homepage": "http://a.example"}}))
117
+
118
+ def test_external_is_no_longer_a_channel_type(self) -> None:
119
+ with pytest.raises(ValueError):
120
+ UpstreamAccessConfig.model_validate({"site": {"type": "external", "base_url": "https://a.example"}})
121
+
122
+
123
+ class TestValidator:
124
+ def test_an_external_app_validates_without_a_connectivity_test(self, validator: DataValidator) -> None:
125
+ listing, _ = load_data_file(next(SERVICE1.glob("listing.*")))
126
+ assert listing is not None
127
+ listing = copy.deepcopy(listing)
128
+ listing.pop("user_access_interfaces", None)
129
+ listing.pop("list_price", None)
130
+ listing.pop("documents", None)
131
+
132
+ result = validator.validate_service(offering=_external(), listing=listing, service_dir=SERVICE1)
133
+
134
+ assert result["offering"] == []
135
+ assert not any("connectivity_test" in e for e in result["listing"]), result["listing"]
136
+
137
+ def test_an_external_app_has_no_interfaces_and_no_price(self, validator: DataValidator) -> None:
138
+ listing, _ = load_data_file(next(SERVICE1.glob("listing.*")))
139
+ assert listing is not None
140
+ listing = copy.deepcopy(listing)
141
+ listing["user_access_interfaces"] = {
142
+ "canonical": {"access_method": "http", "base_url": "${API_GATEWAY_BASE_URL}/x"}
143
+ }
144
+ listing["list_price"] = {"type": "constant", "price": "1"}
145
+
146
+ errors = validator.validate_service(offering=_external(), listing=listing, service_dir=SERVICE1)["listing"]
147
+
148
+ assert any("remove user_access_interfaces" in e for e in errors)
149
+ assert any("remove list_price" in e for e in errors)
150
+
151
+ def test_a_service_with_a_channel_still_needs_a_connectivity_test(self, validator: DataValidator) -> None:
152
+ listing, _ = load_data_file(next(SERVICE1.glob("listing.*")))
153
+ assert listing is not None
154
+ listing = copy.deepcopy(listing)
155
+ listing.pop("documents", None)
156
+
157
+ errors = validator.validate_service(offering=_offering(), listing=listing, service_dir=SERVICE1)["listing"]
158
+
159
+ assert any("connectivity_test" in e for e in errors)
@@ -831,8 +831,11 @@ def _resource(kind: str = "chat", permissions: list[str] | None = None, **fields
831
831
  "entry",
832
832
  [
833
833
  _resource(options="kind=chat&max_members=100"),
834
+ _resource(options="kind=chat&max_retention=3600"),
835
+ _resource(options="kind=chat&max_retention=0"),
834
836
  _resource(),
835
837
  _resource("support", ["join", "read", "post"]),
838
+ _resource("support", ["join", "read", "post"], options="kind=support&max_retention=86400"),
836
839
  _resource("announcement", ["join", "read"]),
837
840
  _resource("discussion", ["join", "read", "post"]),
838
841
  _resource("support", ["read"]),
@@ -874,6 +877,8 @@ def test_one_channel_may_request_several_kinds_of_room() -> None:
874
877
  ([_resource(options="kind=chat&max_members=0")], "max_members 0 is less than the minimum of 1"),
875
878
  ([_resource(options="kind=chat&max_members=many")], "max_members 'many' is not of type 'integer'"),
876
879
  ([_resource("support", ["join"], options="kind=support&max_members=5")], "only a room the customer creates"),
880
+ ([_resource(options="kind=chat&max_retention=-1")], "max_retention -1 is less than the minimum of 0"),
881
+ ([_resource(options="kind=chat&max_retention=soon")], "max_retention 'soon' is not of type 'integer'"),
877
882
  ([_resource(options="kind=chat&topic=x")], "accepts no option 'topic'"),
878
883
  ([_resource(limits={"count_per_day": 1})], "provisioned, not called; it takes no limits"),
879
884
  ([_resource(), _resource(options="kind=chat&max_members=5")], "kind=chat is listed twice"),
@@ -948,3 +953,23 @@ def test_a_customer_may_cap_their_own_room_when_the_request_leaves_it_open() ->
948
953
  [_resource()], [{"object": "resource:room", "permissions": ["create"], "options": "max_members=8"}]
949
954
  )
950
955
  assert policy == [{"object": "resource:room", "permissions": ["create"], "options": "kind=chat&max_members=8"}]
956
+
957
+
958
+ def test_a_room_approval_keeps_the_requested_retention_cap() -> None:
959
+ """The seller's ``max_retention`` (seconds) is the room's cap; an approval
960
+ carries it, and may not raise it (unitysvc/unitysvc#2907)."""
961
+ requested = [_resource(options="kind=chat&max_retention=3600")]
962
+ policy = build_policy(requested, [{"object": "resource:room", "permissions": ["create"], "options": "kind=chat"}])
963
+ assert policy == [{"object": "resource:room", "permissions": ["create"], "options": "kind=chat&max_retention=3600"}]
964
+ with pytest.raises(ValueError, match="max_retention: the service fixes it to '3600'"):
965
+ build_policy(
966
+ requested,
967
+ [{"object": "resource:room", "permissions": ["create"], "options": "kind=chat&max_retention=86400"}],
968
+ )
969
+
970
+
971
+ def test_a_customer_may_cap_their_own_rooms_retention_when_the_request_leaves_it_open() -> None:
972
+ policy = build_policy(
973
+ [_resource()], [{"object": "resource:room", "permissions": ["create"], "options": "max_retention=600"}]
974
+ )
975
+ assert policy == [{"object": "resource:room", "permissions": ["create"], "options": "kind=chat&max_retention=600"}]
@@ -593,6 +593,15 @@ class TestValidateMcpOffering:
593
593
  assert "mcp-delegation" in errors[0]
594
594
  assert "service_type 'mcp'" in errors[0]
595
595
 
596
+ def test_an_offering_without_service_type_cannot_declare_an_mcp_channel(self) -> None:
597
+ errors = validate_mcp_offering(
598
+ {"upstream_access_config": {"upstream": {"access_method": "mcp", "base_url": "https://mcp.example.test"}}}
599
+ )
600
+ assert errors == [
601
+ "an offering without service_type may not declare MCP upstream channel(s) 'upstream'; "
602
+ "use service_type 'mcp' instead"
603
+ ]
604
+
596
605
  def test_non_mcp_offering_cannot_declare_an_mcp_channel(self) -> None:
597
606
  errors = validate_mcp_offering(
598
607
  {
File without changes
File without changes