From c3402921cee1a1fa903324f318204032c789ad2a Mon Sep 17 00:00:00 2001 From: suleman-uzair Date: Thu, 12 Nov 2026 18:16:43 +0500 Subject: [PATCH] Build against the final unitsml-rs delivery and replay the register scope vectors The native pin moves from unitsml-rs fd3b3cb to 14c1707, which includes 87c97eb: a caller registration applies only to the unit the request names. unitsml-rs now takes unitsdb-rs 969a131 (UnitsDB b210137, merged as b0b4315) as a locked Cargo git dependency, so the sibling unitsdb-rs checkout is dropped. native-source.json records the new commit, Cargo.lock, UnitsDB data and library hashes; CI still validates the binary it builds through the build receipt. The asciiunits and F40 corpus pins are unchanged. tests/register-scope-vectors.json records two vectors from unitsml-ruby 2ec9583 on UnitsDB b0b4315: with the pound (NISTu201) registered, 2 lb converts to 45359237/50000000 kg, and cwt (US) (NISTu230) is refused because the pound has no UnitsDB conversion. tests/test_register_scope.py replays them against the installed wheel; the F40 vectors are unchanged. --- ci/native-source.json | 9 +++-- native-source.json | 10 ++--- tests/register-scope-vectors.json | 64 +++++++++++++++++++++++++++++++ tests/test_register_scope.py | 42 ++++++++++++++++++++ 4 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 tests/register-scope-vectors.json create mode 100644 tests/test_register_scope.py diff --git a/ci/native-source.json b/ci/native-source.json index 7f3bc99..3870baf 100644 --- a/ci/native-source.json +++ b/ci/native-source.json @@ -7,14 +7,14 @@ "kind": "prebuilt-library", "repository": "unitsml/unitsml-rs", "local": "workspace/units-native/unitsml-rs", - "revision": "fd3b3cbdd3bb91f732e5c8f2d76ff86a8168ec49", + "revision": "14c17076b7199940acaf9ce1f0272f3808b389bd", "public": true, "deps": { "unitsdb_rs": { "repository": "unitsml/unitsdb-rs", - "revision": "c631488e03f58c5cfd0ada369948b946a23a4f42", + "revision": "969a131b8992930a6ff6f869291f1f0d7cb68d33", "public": true, - "checkout_as": "unitsdb-rs" + "note": "Cargo git dependency of unitsml-rs, locked in its Cargo.lock; bundles the UnitsDB b210137 projection (merged in unitsml/unitsdb as b0b4315)" }, "asciiunits_python": { "repository": "unitsml/asciiunits-python", @@ -34,7 +34,8 @@ }, "data": null, "tests": [ - "tests/test_installed.py" + "tests/test_installed.py", + "tests/test_register_scope.py" ], "python_runtime": { "repository": "parsanol/parsanol-python", diff --git a/native-source.json b/native-source.json index 307066d..696a63c 100644 --- a/native-source.json +++ b/native-source.json @@ -1,9 +1,9 @@ { - "native_source_commit": "fd3b3cbdd3bb91f732e5c8f2d76ff86a8168ec49", - "library_sha256": "b27039135260c41d801f49064f0d066bb8e4ba7636c6af8cac2d75b63b4baa9a", - "cargo_lock_sha256": "26c4f9e73ce68a99d08dc2bfb69b8f268cc0fb8aa3b3928d7cc03ecaccdd33d1", - "unitsdb_commit": "c631488e03f58c5cfd0ada369948b946a23a4f42", - "unitsdb_data_sha256": "660b471fd895d99a74849adaf1cfb0ec4570cd5dbcd9ebf695970af0dc0b3c97", + "native_source_commit": "14c17076b7199940acaf9ce1f0272f3808b389bd", + "library_sha256": "b09f4f7c61cec01af521ae5bb714cd8bedd5216852ea27b103c86dc16782019e", + "cargo_lock_sha256": "949a6198b0462cc6096a18fc85e0e3a220bea0ae66b0d2c6e2979c0bb7a80946", + "unitsdb_commit": "969a131b8992930a6ff6f869291f1f0d7cb68d33", + "unitsdb_data_sha256": "595e987112aed69d06ac2e68fda4b12e58266d5577ccd8cd8aa2cdc56eb765d4", "asciiunits_python_commit": "5c185e271220604648da2a036b4dc94c729fa952", "asciiunits_wheel_sha256": "0f83d4cb6c9a9897a9ce317f5442c961ccc0d8bb781d4caa893d0eab48471de9", "f40_corpus_commit": "877530fd9a04ed8c9026dafc2ee5127215e2bd00", diff --git a/tests/register-scope-vectors.json b/tests/register-scope-vectors.json new file mode 100644 index 0000000..76a9711 --- /dev/null +++ b/tests/register-scope-vectors.json @@ -0,0 +1,64 @@ +{ + "profile": "unitsml-register-scope/v1", + "reference": { + "repository": "unitsml/unitsml-ruby", + "commit": "2ec9583a1902a2c13fd508f3bec558a2adde5de7", + "api": "Unitsml::Conversion.with_register(register) { Unitsml::Quantity.new(value:, unit:).convert_to(target) }", + "unitsdb": { + "repository": "unitsml/unitsdb", + "commit": "b0b4315fc5b53f6caa0a1edb94707b4f13223b38", + "tree": "c57eb0ae330b051e6ea7909aeabe0a89b77707ed", + "units_yaml_sha256": "aac53ed54cb38632d6bdc942022261bf8a369d8e3630d39ecce2567aadb745bd" + } + }, + "native": { + "repository": "unitsml/unitsml-rs", + "commit": "14c17076b7199940acaf9ce1f0272f3808b389bd", + "change": "87c97eb2971df85fb568ec354ac15c809594ab97" + }, + "cases": [ + { + "id": "register-direct-lb", + "register": [ + { + "unit": "NISTu201", + "dimensions": { + "Mass": "1" + }, + "factor": "0.45359237" + } + ], + "value": "2", + "unit": "NISTu201", + "ruby_unit": "lb", + "target": "kg", + "ruby": { + "outcome": "ok", + "converted_value": "45359237/50000000", + "converted_unit": "kg" + } + }, + { + "id": "register-chained-cwt-us-refused", + "register": [ + { + "unit": "NISTu201", + "dimensions": { + "Mass": "1" + }, + "factor": "0.45359237" + } + ], + "value": "2", + "unit": "NISTu230", + "ruby_unit": "cwt (US)", + "target": "kg", + "ruby": { + "outcome": "error", + "error_class": "Unitsml::Errors::ConversionError", + "message": "no canonical conversion path for \"lb\"" + }, + "native_code": "missing_conversion" + } + ] +} diff --git a/tests/test_register_scope.py b/tests/test_register_scope.py new file mode 100644 index 0000000..0c08f0b --- /dev/null +++ b/tests/test_register_scope.py @@ -0,0 +1,42 @@ +import json +from pathlib import Path +import unittest + +import unitsml + +VECTORS = json.loads(Path(__file__).with_name("register-scope-vectors.json").read_bytes()) + + +def convert(case): + return unitsml.evaluate({ + "op": "convert", + "register": case["register"], + "left": {"value": case["value"], "terms": [{"unit": case["unit"]}]}, + "right": {"expression": case["target"]}, + }) + + +class InstalledRegisterScopeTests(unittest.TestCase): + """Caller registrations reach only the unit the request names, as in unitsml-ruby.""" + + def test_vectors_follow_the_ruby_reference(self): + self.assertEqual(VECTORS["profile"], "unitsml-register-scope/v1") + self.assertEqual([case["id"] for case in VECTORS["cases"]], + ["register-direct-lb", "register-chained-cwt-us-refused"]) + for case in VECTORS["cases"]: + with self.subTest(case=case["id"]): + expected = case["ruby"] + if expected["outcome"] == "ok": + result = convert(case) + self.assertEqual(result["magnitude"], expected["converted_value"]) + target = unitsml.evaluate({"op": "resolve", "left": {"value": "1", "expression": case["target"]}}) + self.assertEqual(result["terms"], target["terms"]) + else: + self.assertEqual(expected["error_class"], "Unitsml::Errors::ConversionError") + with self.assertRaises(unitsml.EvaluationError) as refusal: + convert(case) + self.assertEqual(refusal.exception.code, case["native_code"]) + + +if __name__ == "__main__": + unittest.main()