89 lines
3.8 KiB
Python
89 lines
3.8 KiB
Python
from pathlib import Path
|
|
import importlib.util
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
SCRIPT_PATH = ROOT / "scripts" / "lab_003_battery_disconnect_packet.py"
|
|
DOC_PATH = ROOT / "docs" / "LAB_003_BATTERY_DISCONNECT_PACKET.md"
|
|
|
|
|
|
def load_module(path: Path, name: str):
|
|
assert path.exists(), f"missing {path.relative_to(ROOT)}"
|
|
spec = importlib.util.spec_from_file_location(name, path)
|
|
assert spec and spec.loader
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
class TestLab003BatteryDisconnectPacket(unittest.TestCase):
|
|
def test_packet_defaults_to_parts_run_and_tracks_issue_specific_requirements(self):
|
|
mod = load_module(SCRIPT_PATH, "lab_003_battery_disconnect_packet")
|
|
packet = mod.build_packet({})
|
|
|
|
self.assertEqual(packet["status"], "pending_parts_run")
|
|
self.assertEqual(packet["install_target"], "negative battery terminal")
|
|
self.assertIn("battery terminal disconnect switch", packet["required_items"])
|
|
self.assertIn("terminal shim/post riser if needed", packet["required_items"])
|
|
self.assertIn("AutoZone", packet["candidate_stores"][0])
|
|
self.assertIn("no special tools required to operate", packet["selection_criteria"])
|
|
self.assertIn("overnight_test_hours", packet["missing_fields"])
|
|
self.assertIn("receipt_or_photo_path", packet["missing_fields"])
|
|
|
|
def test_packet_marks_verified_after_successful_24h_validation_with_proof(self):
|
|
mod = load_module(SCRIPT_PATH, "lab_003_battery_disconnect_packet")
|
|
packet = mod.build_packet(
|
|
{
|
|
"store_selected": "AutoZone - Newport",
|
|
"part_name": "Knob-style battery disconnect switch",
|
|
"part_cost_usd": 24.99,
|
|
"install_completed": True,
|
|
"physically_secure": True,
|
|
"overnight_test_hours": 26,
|
|
"truck_started_after_disconnect": True,
|
|
"receipt_or_photo_path": "evidence/lab-003-installed-switch.jpg",
|
|
}
|
|
)
|
|
|
|
self.assertEqual(packet["status"], "verified")
|
|
self.assertEqual(packet["missing_fields"], [])
|
|
self.assertTrue(packet["ready_to_operate_without_tools"])
|
|
|
|
def test_packet_flags_battery_replace_candidate_when_overnight_test_fails(self):
|
|
mod = load_module(SCRIPT_PATH, "lab_003_battery_disconnect_packet")
|
|
packet = mod.build_packet(
|
|
{
|
|
"store_selected": "O'Reilly - Claremont",
|
|
"part_name": "Knob-style battery disconnect switch",
|
|
"install_completed": True,
|
|
"physically_secure": True,
|
|
"overnight_test_hours": 24,
|
|
"truck_started_after_disconnect": False,
|
|
}
|
|
)
|
|
|
|
self.assertEqual(packet["status"], "battery_replace_candidate")
|
|
self.assertIn("battery_replacement_followup", packet)
|
|
self.assertIn("replace battery", packet["battery_replacement_followup"].lower())
|
|
|
|
def test_repo_contains_grounded_lab_003_packet_doc(self):
|
|
self.assertTrue(DOC_PATH.exists(), "missing committed LAB-003 packet doc")
|
|
text = DOC_PATH.read_text(encoding="utf-8")
|
|
for snippet in (
|
|
"# LAB-003 — Truck Battery Disconnect Install Packet",
|
|
"No battery disconnect switch has been purchased or installed yet.",
|
|
"negative battery terminal",
|
|
"AutoZone",
|
|
"Advance",
|
|
"O'Reilly",
|
|
"terminal shim/post riser if needed",
|
|
"Truck starts reliably after sitting 24+ hours with switch disconnected",
|
|
"Receipt or photo of installed switch uploaded to this issue",
|
|
):
|
|
self.assertIn(snippet, text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|