armnet-core 0.3.2__tar.gz → 0.3.3__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 (29) hide show
  1. {armnet_core-0.3.2 → armnet_core-0.3.3}/PKG-INFO +1 -1
  2. {armnet_core-0.3.2 → armnet_core-0.3.3}/pyproject.toml +1 -1
  3. {armnet_core-0.3.2 → armnet_core-0.3.3}/src/armnet_core/__init__.py +17 -2
  4. {armnet_core-0.3.2 → armnet_core-0.3.3}/src/armnet_core/enums.py +4 -0
  5. armnet_core-0.3.3/src/armnet_core/image_refs.py +154 -0
  6. {armnet_core-0.3.2 → armnet_core-0.3.3}/src/armnet_core/models.py +323 -22
  7. armnet_core-0.3.3/tests/test_cell_device_config.py +414 -0
  8. armnet_core-0.3.3/tests/test_image_refs.py +91 -0
  9. {armnet_core-0.3.2 → armnet_core-0.3.3}/tests/test_robot_cell_config.py +77 -2
  10. {armnet_core-0.3.2 → armnet_core-0.3.3}/tests/test_yam_cell_config.py +30 -3
  11. armnet_core-0.3.2/tests/test_cell_device_config.py +0 -138
  12. {armnet_core-0.3.2 → armnet_core-0.3.3}/.gitignore +0 -0
  13. {armnet_core-0.3.2 → armnet_core-0.3.3}/LICENSE +0 -0
  14. {armnet_core-0.3.2 → armnet_core-0.3.3}/README.md +0 -0
  15. {armnet_core-0.3.2 → armnet_core-0.3.3}/src/armnet_core/auth.py +0 -0
  16. {armnet_core-0.3.2 → armnet_core-0.3.3}/src/armnet_core/env.py +0 -0
  17. {armnet_core-0.3.2 → armnet_core-0.3.3}/src/armnet_core/environment.py +0 -0
  18. {armnet_core-0.3.2 → armnet_core-0.3.3}/src/armnet_core/manual_reset.py +0 -0
  19. {armnet_core-0.3.2 → armnet_core-0.3.3}/src/armnet_core/markers.py +0 -0
  20. {armnet_core-0.3.2 → armnet_core-0.3.3}/src/armnet_core/scene_calibration.py +0 -0
  21. {armnet_core-0.3.2 → armnet_core-0.3.3}/src/armnet_core/volume_sync.py +0 -0
  22. {armnet_core-0.3.2 → armnet_core-0.3.3}/tests/test_job_ids.py +0 -0
  23. {armnet_core-0.3.2 → armnet_core-0.3.3}/tests/test_job_spec.py +0 -0
  24. {armnet_core-0.3.2 → armnet_core-0.3.3}/tests/test_manual_reset.py +0 -0
  25. {armnet_core-0.3.2 → armnet_core-0.3.3}/tests/test_manual_reset_size_guide.py +0 -0
  26. {armnet_core-0.3.2 → armnet_core-0.3.3}/tests/test_package_version.py +0 -0
  27. {armnet_core-0.3.2 → armnet_core-0.3.3}/tests/test_scene_calibration.py +0 -0
  28. {armnet_core-0.3.2 → armnet_core-0.3.3}/tests/test_volume_sync.py +0 -0
  29. {armnet_core-0.3.2 → armnet_core-0.3.3}/tests/yam_fixtures.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: armnet-core
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Shared wire types for the armnet platform: Embodiment, Task, JobSpec, JobResult, Job, JobStatus.
5
5
  Project-URL: Homepage, https://armnet.dev
6
6
  Project-URL: Documentation, https://docs.armnet.dev/packages/core/
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
  name = "armnet-core"
7
7
  # 0.2.0 is a wire break: a cell reports the `environment` it is set up for in
8
8
  # place of a single `task`, so 0.1.x cannot read a cell-status response.
9
- version = "0.3.2"
9
+ version = "0.3.3"
10
10
  description = "Shared wire types for the armnet platform: Embodiment, Task, JobSpec, JobResult, Job, JobStatus."
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.12,<3.13"
@@ -9,8 +9,8 @@ from importlib.metadata import PackageNotFoundError as _PackageNotFound
9
9
  from importlib.metadata import version as _package_version
10
10
 
11
11
  from armnet_core.auth import API_KEY_ENV, API_KEY_HEADER
12
- from armnet_core.enums import (DEFAULT_EMBODIMENT, DEFAULT_ENVIRONMENT,
13
- DEFAULT_TASK, Embodiment)
12
+ from armnet_core.enums import (CELL_ID_PATTERN, DEFAULT_EMBODIMENT,
13
+ DEFAULT_ENVIRONMENT, DEFAULT_TASK, Embodiment)
14
14
  from armnet_core.enums import Environment as EnvironmentName
15
15
  from armnet_core.enums import Task
16
16
  from armnet_core.environment import (CompletionStatus, Environment,
@@ -37,6 +37,14 @@ from armnet_core.manual_reset import (
37
37
  ShirtSize,
38
38
  sample_manual_reset_layout,
39
39
  )
40
+ from armnet_core.image_refs import (
41
+ ImageReferenceError,
42
+ canonical_customer_image,
43
+ customer_image_selector,
44
+ customer_registry_slug,
45
+ require_owned_customer_image,
46
+ validate_image_selector,
47
+ )
40
48
  from armnet_core.models import (BIMANUAL_YAM_EMBODIMENT, TELEOP_EVENT_NEXT_EPISODE,
41
49
  TELEOP_EVENT_RERECORD_EPISODE,
42
50
  TELEOP_EVENT_STOP_RECORDING, TELEOP_EVENTS,
@@ -76,6 +84,7 @@ __all__ = [
76
84
  "API_KEY_HEADER",
77
85
  "BIMANUAL_YAM_EMBODIMENT",
78
86
  "BOX_LENGTH_SCALES",
87
+ "CELL_ID_PATTERN",
79
88
  "DEFAULT_LAYOUT_ATTEMPTS",
80
89
  "DEFAULT_EMBODIMENT",
81
90
  "DEFAULT_ENVIRONMENT",
@@ -96,10 +105,14 @@ __all__ = [
96
105
  "EnvironmentNotFound",
97
106
  "FULL_FRAME_VERTICES",
98
107
  "InstrumentedCell",
108
+ "ImageReferenceError",
99
109
  "Reading",
100
110
  "TaskSpec",
101
111
  "available_environments",
102
112
  "canonical_job_id",
113
+ "canonical_customer_image",
114
+ "customer_image_selector",
115
+ "customer_registry_slug",
103
116
  "environment_for",
104
117
  "task_environment",
105
118
  "Job",
@@ -127,6 +140,7 @@ __all__ = [
127
140
  "RailVariation",
128
141
  "RegistryCredentials",
129
142
  "RemoteExecutionError",
143
+ "require_owned_customer_image",
130
144
  "RobotArmConfig",
131
145
  "RobotCellConfig",
132
146
  "SceneCalibration",
@@ -165,6 +179,7 @@ __all__ = [
165
179
  "sample_scene_target",
166
180
  "sample_manual_reset_layout",
167
181
  "validate_normalized_polygon",
182
+ "validate_image_selector",
168
183
  ]
169
184
 
170
185
  # Read from installed metadata so the version lives in pyproject.toml only; a
@@ -30,6 +30,10 @@ Embodiment = str
30
30
  Environment = str
31
31
  Task = str
32
32
 
33
+ # A cell id is also a NATS subject token and a JetStream consumer name (a job
34
+ # can be routed to one cell), so it is limited to characters valid in both.
35
+ CELL_ID_PATTERN = r"^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$"
36
+
33
37
  # Convenience defaults for local dev and SDK call sites, not an authoritative
34
38
  # list. Keep in sync with the seed rows in db/data_core/data_core.sql.
35
39
  DEFAULT_EMBODIMENT: Embodiment = "lerobot/so-101"
@@ -0,0 +1,154 @@
1
+ """Canonical customer-container image references.
2
+
3
+ The authenticated username, registry host, and repository prefix are trusted
4
+ platform state. Customers choose only the image selector beneath their own
5
+ namespace (for example ``policy:sha-abc``). A fully-qualified SDK-produced ref
6
+ is accepted for compatibility, but its supplied username is discarded and the
7
+ canonical prefix is rebuilt server-side.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import re
13
+
14
+ _NAME_COMPONENT = re.compile(r"^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$")
15
+ _TAG = re.compile(r"^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$")
16
+ _SHA256 = re.compile(r"^sha256:[0-9a-f]{64}$")
17
+ _CUSTOMER_SLUG = re.compile(r"^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$")
18
+
19
+
20
+ class ImageReferenceError(ValueError):
21
+ """An image ref cannot be safely canonicalized for one customer."""
22
+
23
+
24
+ def customer_registry_slug(username: str) -> str:
25
+ """Current username→registry mapping, validated as one path component.
26
+
27
+ Existing production namespaces use lowercase usernames, so preserve that
28
+ mapping. Account provisioning must prevent case-fold collisions (e.g.
29
+ ``Alice`` and ``alice``); this function rejects path separators and other
30
+ characters rather than silently sanitizing them into collisions.
31
+ """
32
+
33
+ slug = username.strip().lower()
34
+ if not slug or not _CUSTOMER_SLUG.fullmatch(slug):
35
+ raise ImageReferenceError(
36
+ f"username {username!r} cannot be represented as a registry namespace"
37
+ )
38
+ return slug
39
+
40
+
41
+ def validate_image_selector(selector: str) -> str:
42
+ """Validate a repository path plus explicit tag or sha256 digest."""
43
+
44
+ if not selector or selector != selector.strip():
45
+ raise ImageReferenceError("image selector must be nonempty with no surrounding whitespace")
46
+ if any(ch.isspace() for ch in selector) or "\\" in selector:
47
+ raise ImageReferenceError("image selector must not contain whitespace or backslashes")
48
+ if selector.startswith(("-", "/", ".")) or "//" in selector:
49
+ raise ImageReferenceError("invalid image selector path")
50
+
51
+ name_and_tag, at, digest = selector.partition("@")
52
+ if at:
53
+ if not _SHA256.fullmatch(digest):
54
+ raise ImageReferenceError("image digest must be lowercase sha256:<64 hex>")
55
+ elif "@" in digest:
56
+ raise ImageReferenceError("invalid image digest")
57
+
58
+ last_slash = name_and_tag.rfind("/")
59
+ last_colon = name_and_tag.rfind(":")
60
+ tag = None
61
+ name = name_and_tag
62
+ if last_colon > last_slash:
63
+ name, tag = name_and_tag[:last_colon], name_and_tag[last_colon + 1 :]
64
+ if not _TAG.fullmatch(tag):
65
+ raise ImageReferenceError("invalid image tag")
66
+
67
+ if tag is None and not at:
68
+ raise ImageReferenceError("image selector must include an explicit tag or digest")
69
+ components = name.split("/")
70
+ if not components or any(not _NAME_COMPONENT.fullmatch(part) for part in components):
71
+ raise ImageReferenceError(
72
+ "image name must use lowercase path components containing letters, "
73
+ "digits, '.', '_', or '-'"
74
+ )
75
+ return selector
76
+
77
+
78
+ def customer_image_selector(
79
+ requested: str,
80
+ *,
81
+ registry: str,
82
+ namespace_prefix: str,
83
+ ) -> str:
84
+ """Return the customer-controlled suffix from a relative or platform ref.
85
+
86
+ For a full ref, the shape must be
87
+ ``<registry>/<namespace-prefix>/<supplied-user>/<selector>``. The supplied
88
+ user component is deliberately ignored; callers reconstruct it from the
89
+ authenticated identity.
90
+ """
91
+
92
+ registry = registry.strip().rstrip("/")
93
+ prefix = namespace_prefix.strip().strip("/")
94
+ if not registry or "/" in registry or not prefix:
95
+ raise ImageReferenceError("platform image registry configuration is invalid")
96
+
97
+ first = requested.split("/", 1)[0]
98
+ explicit_registry = "/" in requested and (
99
+ "." in first or ":" in first or first == "localhost"
100
+ )
101
+ if not explicit_registry:
102
+ return validate_image_selector(requested)
103
+
104
+ platform_base = f"{registry}/{prefix}/"
105
+ if not requested.startswith(platform_base):
106
+ raise ImageReferenceError(
107
+ f"image must come from the platform registry {registry}/{prefix}"
108
+ )
109
+ remainder = requested[len(platform_base) :]
110
+ supplied_user, separator, selector = remainder.partition("/")
111
+ if not separator or not _CUSTOMER_SLUG.fullmatch(supplied_user):
112
+ raise ImageReferenceError(
113
+ "fully-qualified customer image must include a user namespace and image selector"
114
+ )
115
+ return validate_image_selector(selector)
116
+
117
+
118
+ def canonical_customer_image(
119
+ requested: str,
120
+ *,
121
+ registry: str,
122
+ namespace_prefix: str,
123
+ username: str,
124
+ ) -> str:
125
+ """Build the only image ref an authenticated customer may execute."""
126
+
127
+ selector = customer_image_selector(
128
+ requested,
129
+ registry=registry,
130
+ namespace_prefix=namespace_prefix,
131
+ )
132
+ slug = customer_registry_slug(username)
133
+ return f"{registry.rstrip('/')}/{namespace_prefix.strip('/')}/{slug}/{selector}"
134
+
135
+
136
+ def require_owned_customer_image(
137
+ image: str,
138
+ *,
139
+ registry: str,
140
+ namespace_prefix: str,
141
+ username: str,
142
+ ) -> None:
143
+ """Reject a persisted/dispatch image unless it is already canonical."""
144
+
145
+ canonical = canonical_customer_image(
146
+ image,
147
+ registry=registry,
148
+ namespace_prefix=namespace_prefix,
149
+ username=username,
150
+ )
151
+ if image != canonical:
152
+ raise ImageReferenceError(
153
+ f"image is not owned by authenticated user {username!r}; expected {canonical!r}"
154
+ )