| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- """Effective run settings include saved UI choices unless a recipe overrides them.
- The workflow is held at its boundary: these tests exercise real configuration
- persistence and run snapshots without booting a simulated or physical server.
- """
- from __future__ import annotations
- import copy
- from pathlib import Path
- from unittest.mock import AsyncMock
- import uuid
- import pytest
- import pytest_asyncio
- from stl_backend.config import load_settings
- from stl_backend.engine import Bench
- ROOT = Path(__file__).resolve().parents[1]
- SAVED_FIRMWARE = {
- "uip_overrides": [
- {"id": "errhandle", "mode": "override", "value": "disable"},
- {"id": "rmt", "mode": "override", "value": "disable"},
- ],
- "mt_selection": {
- "efi_path": r"FS0:\EFI\118.efi",
- "config_path": r"FS0:\EFI\default.cfg",
- "arguments": "--pass 1",
- "command_template": "{efi_path} {config_path} {arguments}",
- },
- }
- @pytest_asyncio.fixture
- async def bench(tmp_path):
- settings = load_settings(ROOT / "config/simulated.json")
- settings["data_dir"] = str(tmp_path)
- settings["stations"] = settings["stations"][:1]
- value = Bench(settings)
- await value.initialize()
- value.workflow.run = AsyncMock()
- try:
- yield value
- finally:
- await value.close()
- async def save_station_choices(bench):
- result = await bench.controls.save_firmware_settings({
- "station_id": "S1", **copy.deepcopy(SAVED_FIRMWARE)})
- assert result["hardware_written"] is False
- return result["firmware_settings"]
- async def start_with_firmware(bench, firmware):
- recipe = await bench.store.get_recipe("DEMO-80")
- recipe["firmware_settings"] = copy.deepcopy(firmware)
- await bench.store.put_recipe(recipe, recipe["revision"])
- command = await bench.start_run({
- "command_id": "inheritance-" + uuid.uuid4().hex,
- "station_id": "S1", "operator": "test", "recipe_id": "DEMO-80",
- "work_order": "WO-test", "batch_no": "B-test",
- "dimms": [{"sn": "fixture-SN", "slot": "A1", "cpu": 0, "channel": "A"}],
- })
- run = await bench.store.get_run(command["run_id"])
- # Resolving effective run settings must not rewrite the reusable recipe.
- assert (await bench.store.get_recipe("DEMO-80"))["firmware_settings"] == firmware
- return run["recipe"]
- @pytest.mark.parametrize("firmware", [
- {},
- {"uip_overrides": [], "mt_selection": {}},
- {"uip_overrides": [{"id": "rmt", "mode": "default"}], "mt_selection": {}},
- ])
- async def test_empty_or_default_recipe_inherits_saved_uip_and_mt(bench, firmware):
- saved = await save_station_choices(bench)
- recipe = await start_with_firmware(bench, firmware)
- assert recipe["firmware_settings"] == saved
- assert recipe["stage1_commands"] == ["errhandle disable", "rmt disable"]
- assert recipe["run_rmt"] is False
- assert recipe["mt_command"] == r"FS0:\EFI\118.efi FS0:\EFI\default.cfg --pass 1"
- @pytest.mark.parametrize(("firmware", "commands", "mt_command"), [
- ({"uip_overrides": [{"id": "rmt", "mode": "override", "value": "enable"}],
- "mt_selection": {}}, ["rmt enable"], "memtest.efi {run_id}"),
- ({"uip_overrides": [], "mt_selection": {"efi_path": r"FS0:\EFI\memtest86site.efi"}},
- [], r"FS0:\EFI\memtest86site.efi"),
- ])
- async def test_explicit_recipe_settings_win_as_a_whole(bench, firmware, commands, mt_command):
- saved = await save_station_choices(bench)
- recipe = await start_with_firmware(bench, firmware)
- assert recipe["firmware_settings"] == firmware
- assert recipe["stage1_commands"] == commands
- assert recipe["run_rmt"] is True
- assert recipe["mt_command"] == mt_command
- assert bench.control_settings.load("S1")["firmware_settings"] == saved
- async def test_no_station_or_recipe_override_keeps_bios_defaults(bench):
- recipe = await start_with_firmware(bench, {"uip_overrides": [], "mt_selection": {}})
- assert recipe["firmware_settings"] == {"uip_overrides": [], "uip_raw_commands": [], "mt_selection": {}}
- assert recipe["stage1_commands"] == []
- assert recipe["mt_command"] == "memtest.efi {run_id}"
|