commit 9288634d7348740710d4fac64e90bf699a9ed0d8
parent dcd76a615d0aaa75ced6062718853a43faa7cea8
Author: triesap <tyson@radroots.org>
Date: Wed, 8 Apr 2026 22:07:07 +0000
core: make hyf build identity artifact-backed
Diffstat:
3 files changed, 68 insertions(+), 65 deletions(-)
diff --git a/src/hyf_core/metadata.mojo b/src/hyf_core/metadata.mojo
@@ -1,5 +1,6 @@
from std.os import getenv
-from std.pathlib import Path, _dir_of_current_file
+
+from hyf_core.package_surface import hyf_package_name, hyf_package_version
def hyf_protocol_version() -> Int:
@@ -24,74 +25,19 @@ struct HyfBuildIdentity(Copyable, Movable):
var deterministic_execution_available: Bool
var assisted_execution_available: Bool
-
-def _package_surface_manifest_path() raises -> Path:
- return _dir_of_current_file() / ".." / ".." / "pixi.toml"
-
-
-def _package_surface_manifest_text() raises -> String:
+def current_package_surface() raises -> HyfPackageSurface:
if (
getenv("HYF_TEST_FAULT_CURRENT_PACKAGE_SURFACE", "")
== "invalid_unquoted_version"
):
- return '[workspace]\nname = "hyf"\nversion = 0.1.0\n'
- return _package_surface_manifest_path().read_text()
+ raise Error("simulated invalid package surface")
-
-def _parse_quoted_assignment_value(value: String) raises -> String:
- var trimmed_value = value.strip()
- if (
- trimmed_value.byte_length() < 2
- or not trimmed_value.startswith("\"")
- or not trimmed_value.endswith("\"")
- ):
- raise Error("manifest assignment value must be a quoted string")
-
- return String(
- trimmed_value[byte=1 : trimmed_value.byte_length() - 1]
+ return HyfPackageSurface(
+ package_name=hyf_package_name(),
+ package_version=hyf_package_version(),
)
-def current_package_surface() raises -> HyfPackageSurface:
- var in_workspace = False
- var package_name = String("")
- var package_version = String("")
-
- for raw_line in _package_surface_manifest_text().splitlines():
- var line = String(raw_line).strip()
- if line == "" or line.startswith("#"):
- continue
-
- if line.startswith("["):
- in_workspace = line == "[workspace]"
- continue
-
- if not in_workspace:
- continue
-
- var equals_index = line.find("=")
- if equals_index < 0:
- continue
-
- var key = String(line[byte=0:equals_index]).strip()
- var value = _parse_quoted_assignment_value(
- String(line[byte=equals_index + 1 :])
- )
-
- if key == "name":
- package_name = value^
- elif key == "version":
- package_version = value^
-
- if package_name != "" and package_version != "":
- return HyfPackageSurface(
- package_name=package_name^,
- package_version=package_version^,
- )
-
- raise Error("unable to derive hyf package surface from pixi.toml")
-
-
def current_build_identity() raises -> HyfBuildIdentity:
var package_surface = current_package_surface()
return HyfBuildIdentity(
diff --git a/src/hyf_core/package_surface.mojo b/src/hyf_core/package_surface.mojo
@@ -0,0 +1,9 @@
+# generated from the checked-in workspace package surface for runtime identity
+
+
+def hyf_package_name() -> String:
+ return "hyf"
+
+
+def hyf_package_version() -> String:
+ return "0.1.0"
diff --git a/tests/test_hyf.mojo b/tests/test_hyf.mojo
@@ -1,4 +1,5 @@
from std.os import getenv, setenv, unsetenv
+from std.pathlib import Path, _dir_of_current_file
from std.testing import (
TestSuite,
assert_equal,
@@ -33,6 +34,51 @@ def _dispatch(line: String) raises -> Value:
return loads(handle_request_line(line))
+def _test_manifest_path() raises -> Path:
+ return _dir_of_current_file() / ".." / "pixi.toml"
+
+
+def _parse_manifest_quoted_value(value: String) raises -> String:
+ var trimmed = value.strip()
+ if (
+ trimmed.byte_length() < 2
+ or not trimmed.startswith("\"")
+ or not trimmed.endswith("\"")
+ ):
+ raise Error("manifest assignment value must be quoted")
+ return String(trimmed[byte=1 : trimmed.byte_length() - 1])
+
+
+def _manifest_workspace_value(target_key: String) raises -> String:
+ var in_workspace = False
+
+ for raw_line in _test_manifest_path().read_text().splitlines():
+ var line = String(raw_line).strip()
+ if line == "" or line.startswith("#"):
+ continue
+
+ if line.startswith("["):
+ in_workspace = line == "[workspace]"
+ continue
+
+ if not in_workspace:
+ continue
+
+ var equals_index = line.find("=")
+ if equals_index < 0:
+ continue
+
+ var key = String(line[byte=0:equals_index]).strip()
+ if key != target_key:
+ continue
+
+ return _parse_manifest_quoted_value(
+ String(line[byte=equals_index + 1 :])
+ )
+
+ raise Error("missing workspace manifest key '" + target_key + "'")
+
+
def _has_key(value: Value, key: String) -> Bool:
for candidate in value.object_keys():
if candidate == key:
@@ -151,12 +197,14 @@ def test_handle_request_line_returns_invalid_request_for_bad_line() raises:
def test_current_build_identity_matches_manifest_package_surface() raises:
var package_surface = current_package_surface()
var build_identity = current_build_identity()
+ var manifest_package_name = _manifest_workspace_value("name")
+ var manifest_package_version = _manifest_workspace_value("version")
- assert_equal(package_surface.package_name, "hyf")
- assert_equal(package_surface.package_version, "0.1.0")
- assert_equal(build_identity.package_name, package_surface.package_name)
+ assert_equal(package_surface.package_name, manifest_package_name)
+ assert_equal(package_surface.package_version, manifest_package_version)
+ assert_equal(build_identity.package_name, manifest_package_name)
assert_equal(
- build_identity.package_version, package_surface.package_version
+ build_identity.package_version, manifest_package_version
)