Files
alro65 deb04c9315 sprint-0: fundaciones VMS-Sailor
Sprint 0 completo del producto VMS-Sailor (Vessel Management System
integrado para buques 30-40m). Brief de referencia en
VMS_Sailor_v2_Parte_*.md (intacto).

Core (vmssailor.core, 95.17% coverage, 99 tests verde):
- ShipCoord: sistema naval x_pp/y_cl/z_bl frozen
- Vessel, Deck, Bulkhead
- Equipment, EquipmentModel, Sensor, EquipmentSpec
- Tag, AlarmConfig, TagBinding, Scaling
- CardInstance, Bus, Topology con validacion 21 puntos I/O AR-NMEA-IO-v1.0
- Alarm, PermissiveRule, Condition
- Project agregado raiz con validacion cross-entity
- Persistencia portable .vmsproj (SQLite) con roundtrip verificable

Biblioteca curada seed (vmssailor.library):
- systems_catalog.json completo (catalogo maestro Parte 1 sec 7)
- 2 vessels: Sunseeker 76, Ferretti 850
- 2 motores: MTU 12V 2000 M96, Volvo D13-900
- 1 genset: Northern Lights M65C13
- yacht_motor_planeo.yaml (reglas heuristicas)
- TODO marcado data_source=seed_estimate - requiere validacion datasheets

Tools:
- vms-validate-library: CLI valida biblioteca completa
- vms-generate-test-project: CLI demo + verificacion roundtrip persistencia

Design System + 8 mockups HTML estaticos:
- docs/design_system.md (paleta Deep Ocean, gradientes, typography, motion)
- docs/brand/ (logo + variantes SVG)
- docs/mockups/splash, studio_main, runtime_overview,
  runtime_mimic_fuel (P&ID animado), runtime_alarms, runtime_trim (panel
  estrella con horizonte artificial), mobile_overview, mobile_trim
- docs/mockups/index.html (galeria)

Firmware (Sprint 12+ implementacion):
- firmware/ar_nmea_io_v1/src/config/pinout.h con macros GPIO

Decisiones autonomas documentadas en docs/decisions_sprint0.md.

Stack: Python 3.11 + uv + Pydantic v2 + SQLite stdlib + hatchling +
pytest 9 + ruff + mypy. Sin PySide6, FastAPI, Flutter ni firmware
funcional (entran en sprints siguientes).

Criterio de aceptacion Sprint 0: cumplido.
- uv sync: OK
- pytest: 99/99 verde
- cov vmssailor.core: 95.17% (objetivo >=80%)
- ruff: clean
- vms-validate-library: OK
- vms-generate-test-project: INTEGRIDAD OK

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 07:26:06 -04:00

195 lines
5.6 KiB
Python

"""Tests del agregado raíz Project."""
from __future__ import annotations
import pytest
from pydantic import ValidationError
from vmssailor.core import (
Bus,
BusRole,
CardInstance,
Equipment,
PermissiveRule,
Project,
Protocol,
ShipCoord,
SystemId,
Tag,
Topology,
UnitSI,
Vessel,
)
from vmssailor.core.permissive import Condition
def test_project_stats(sample_project: Project) -> None:
stats = sample_project.stats()
assert stats["systems"] == 1
assert stats["equipment"] == 1
assert stats["tags"] == 1
assert stats["tags_with_alarms"] == 1
assert stats["buses"] == 1
assert stats["cards"] == 1
def test_project_equipment_requires_enabled_system(
minimal_vessel: Vessel, sample_topology: Topology
) -> None:
eq = Equipment(
id="eq",
model_ref="m",
tag_prefix="X",
display_name="x",
location=ShipCoord(x_pp=5.0, y_cl=0.0, z_bl=1.0),
system_id=SystemId.WATERMAKER, # NO en systems_enabled
)
with pytest.raises(ValidationError):
Project(
id="p",
name="p",
vessel=minimal_vessel,
systems_enabled=[SystemId.MAIN_ENGINE],
equipment=[eq],
topology=sample_topology,
)
def test_project_tag_equipment_id_must_exist(
minimal_vessel: Vessel, sample_topology: Topology, sample_equipment: Equipment
) -> None:
with pytest.raises(ValidationError):
Project(
id="p",
name="p",
vessel=minimal_vessel,
systems_enabled=[SystemId.MAIN_ENGINE],
equipment=[sample_equipment],
tags=[
Tag(
id="GHOST.X",
equipment_id="ghost_eq", # no existe
unit_si=UnitSI.BAR,
protocol=Protocol.MODBUS_RTU,
address=1,
)
],
topology=sample_topology,
)
def test_project_tag_binding_must_reference_existing_card(
minimal_vessel: Vessel,
) -> None:
from vmssailor.core import ChannelType, SignalType, TagBinding
b = Bus(id="bm", name="bm", protocol=Protocol.MODBUS_RTU, physical_port="COM3")
c = CardInstance(
id="card_001", slot_number=1, bus_id="bm",
bus_role=BusRole.MODBUS_SLAVE, modbus_address=1,
)
topo = Topology(buses=[b], cards=[c])
eq = Equipment(
id="eq",
model_ref="m",
tag_prefix="X",
display_name="x",
location=ShipCoord(x_pp=5.0, y_cl=0.0, z_bl=1.0),
system_id=SystemId.MAIN_ENGINE,
)
bad_tag = Tag(
id="X.PRESS",
equipment_id="eq",
unit_si=UnitSI.BAR,
protocol=Protocol.MODBUS_RTU,
physical_binding=TagBinding(
card_id="ghost_card",
channel_type=ChannelType.AI,
channel_number=1,
signal_type=SignalType.SIG_4_20_MA,
),
)
with pytest.raises(ValidationError):
Project(
id="p",
name="p",
vessel=minimal_vessel,
systems_enabled=[SystemId.MAIN_ENGINE],
equipment=[eq],
tags=[bad_tag],
topology=topo,
)
def test_project_permissive_condition_must_reference_existing_tag(
sample_project: Project,
) -> None:
bad_rule = PermissiveRule(
id="bad",
action_id="DO_X",
conditions=[Condition(tag_ref="GHOST.TAG", operator=">", threshold=1.0)],
)
with pytest.raises(ValidationError):
Project(
id=sample_project.id,
name=sample_project.name,
vessel=sample_project.vessel,
systems_enabled=sample_project.systems_enabled,
equipment=sample_project.equipment,
tags=sample_project.tags,
topology=sample_project.topology,
permissive_rules=[bad_rule],
)
def test_project_helpers(sample_project: Project) -> None:
eq = sample_project.equipment_by_id("eq_me_port")
assert eq is not None
assert eq.tag_prefix == "ME_PORT"
tag = sample_project.tag_by_id("ME_PORT.OIL_PRESS")
assert tag is not None
tags_eq = sample_project.tags_for_equipment("eq_me_port")
assert len(tags_eq) == 1
tags_sys = sample_project.tags_for_system(SystemId.MAIN_ENGINE)
assert len(tags_sys) == 1
def test_project_touch_updates_timestamp(sample_project: Project) -> None:
original = sample_project.updated_at
sample_project.touch()
assert sample_project.updated_at >= original
def test_project_equipment_unique_tag_prefix(minimal_vessel: Vessel) -> None:
e1 = Equipment(
id="e1", model_ref="m", tag_prefix="ME",
display_name="A", location=ShipCoord(x_pp=1, y_cl=0, z_bl=0),
system_id=SystemId.MAIN_ENGINE,
)
e2 = Equipment(
id="e2", model_ref="m", tag_prefix="ME", # mismo prefix
display_name="B", location=ShipCoord(x_pp=2, y_cl=0, z_bl=0),
system_id=SystemId.MAIN_ENGINE,
)
with pytest.raises(ValidationError):
Project(
id="p", name="p", vessel=minimal_vessel,
systems_enabled=[SystemId.MAIN_ENGINE],
equipment=[e1, e2],
)
def test_project_equipment_deck_must_exist(minimal_vessel: Vessel) -> None:
eq = Equipment(
id="eq", model_ref="m", tag_prefix="X",
display_name="x", location=ShipCoord(x_pp=1, y_cl=0, z_bl=0),
deck_id="non_existent_deck",
system_id=SystemId.MAIN_ENGINE,
)
with pytest.raises(ValidationError):
Project(
id="p", name="p", vessel=minimal_vessel,
systems_enabled=[SystemId.MAIN_ENGINE],
equipment=[eq],
)