test(grpc-data-rig): #1115 scale profile (seed --scale N) and the #1026 scale gate

- device: read-only scale block (holding registers 1000..5095) + scale_set control action
- seed: GRPC_DATA_SCALE=N adds SOURCE driver modscale/dev with N UInt16 tags in TagGroups
  small (first 160) / large (rest), one RawTagGroup export + CONSUMER mapping each
  (map-scale-small|large); fixture.json records the counts
- rig.py: seed --scale N; deploy trigger gets a 60 s socket timeout (the AdminUI's
  StartDeployment ask waits up to 45 s; a 2048-tag snapshot read took ~25 s, so the
  general 15 s cap aborted the POST)
- scale_gate.py: opens a >128 and a >1024-item mapping via Client CLI recursive
  subscribes on CONSUMER, requires all Good, churns the block, restarts the SOURCE pair,
  requires all Good with a post-restart value, checks the consumer ResetHistory counter
  and the container logs for 'history expired'; PASS/FAIL + evidence/S1026-results.json

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-12-05 03:34:02 -05:00
parent 961ca2897c
commit 8ddae2f43d
7 changed files with 570 additions and 9 deletions
@@ -80,6 +80,21 @@ class ModbusFixtureTests(unittest.TestCase):
apply_control(self.state, command)
self.assertEqual(self.state.snapshot()["effect_total"], 0)
def test_scale_block_is_read_only_and_set_as_one_value(self):
# #1115: 4096 contiguous read-only registers from 1000; one control action sets them all.
self.assertEqual(words(handle_modbus_pdu(self.state, 1, request(3, 1000, 125))), (1,) * 125)
self.assertEqual(words(handle_modbus_pdu(self.state, 1, request(3, 5095 - 124, 125))), (1,) * 125)
self.assertEqual(handle_modbus_pdu(self.state, 1, request(3, 5096, 1)), b"\x83\x02")
self.assertEqual(handle_modbus_pdu(self.state, 1, request(3, 999, 2)), b"\x83\x02")
self.assertEqual(handle_modbus_pdu(self.state, 1, request(6, 1000, 5)), b"\x86\x02")
apply_control(self.state, {"action": "scale_set", "value": 4242})
self.assertEqual(words(handle_modbus_pdu(self.state, 1, request(3, 2047, 3))), (4242,) * 3)
self.assertEqual(self.state.snapshot()["scale"], {"base": 1000, "count": 4096, "value": 4242, "sets": 1})
for invalid in (-1, 65536, "1", None):
with self.assertRaises(ValueError):
apply_control(self.state, {"action": "scale_set", "value": invalid})
self.assertEqual(self.state.snapshot()["effect_total"], 0)
if __name__ == "__main__":
unittest.main()
@@ -680,3 +680,37 @@ class PinnedSourceRevisionTests(unittest.TestCase):
instance.compose.side_effect = stamp
with patch.object(rig, "pinned_tree_hash", return_value="edited-export"), self.assertRaises(rig.RigError):
instance.verify_candidate()
class ScaleSeedTests(unittest.TestCase):
"""#1115: `seed --scale N` reaches only the seeder, bounded by the device fixture's scale block."""
def instance(self):
instance = object.__new__(rig.LocalRig)
instance.load = Mock(return_value={})
instance.compose = Mock(side_effect=StopIteration("seeder invoked"))
return instance
def test_out_of_range_or_non_integer_scale_is_refused_before_the_seeder_runs(self):
for scale in (0, -1, rig.SCALE_MAX_TAGS + 1, 2.5, "2048", True):
instance = self.instance()
with self.subTest(scale=scale), self.assertRaisesRegex(rig.RigError, "--scale"):
instance.seed(scale=scale)
instance.compose.assert_not_called()
def test_scale_is_passed_to_the_seeder_as_its_environment(self):
instance = self.instance()
with self.assertRaises(StopIteration):
instance.seed(scale=2048)
arguments = instance.compose.call_args.args
self.assertEqual(arguments[:7], ("run", "--rm", "--no-deps", "--env", "GRPC_DATA_SCALE=2048", "seeder", "seed"))
def test_scale_flag_is_seed_only(self):
with patch.object(rig, "LocalRig") as local, patch("sys.stderr"):
self.assertEqual(rig.main(["up", "--run-id", RUN, "--scale", "10"]), 2)
local.return_value.up.assert_not_called()
def test_device_scale_block_covers_the_seed_bound(self):
sys.path.insert(0, str(Path(rig.__file__).resolve().parent / "device"))
import server
self.assertEqual(server.SCALE_COUNT, rig.SCALE_MAX_TAGS)