Files
uconsole_asw_game/tests/test_sonar_track_publication.py
T
db9979andClaude Opus 5.5 1a13d5ce5e Real-time only, measured threat cues, status ticker, text fitting, web NATO symbols
Previously uncommitted work: the game always runs in real time (no pause
or time acceleration), web client fixes (plot smoothing, spectrum peak
labels shared with the uConsole), regenerated contact-analysis images,
docs and manual updates.

UI/realism review, phase 1 (no truth leaks):
- Sonar CIC domain follows only the operator classification; new TORPEDO class.
- Torpedo alarm from intercepts only (launch transient, HF seeker pulses),
  used by Bridge, Autocrew and the web Bridge threat block.
- ASM cue from measured speed/altitude or a jamming strobe; CIWS/ESSM/ECM
  resolve missiles through their own M- tracks.
- HFDF fixes publish no domain; lookout domain needs recognition.
- No "hostile ping"/"submarine sunk" reports: breaking-up noises on a
  bearing; score only in the debrief.
- Helicopter layer shown only after the dome passed it; web Bridge gets
  published rows only.

Phase 2 (uConsole screen and text):
- Status ticker (default) frees 158 px; F11 event log/telemetry overlay
  (display only); docked band selectable in the options.
- Layout helpers fall back to catalog abbreviations (<key>.short) before
  any ellipsis; feed wraps, ticker scrolls; zero truncations EN/DE.
- Localised telemetry and OPZ affiliation/domain codes, bounded map labels.

Web: role map and chart draw NATO affiliation frames with domain glyphs.
Tests: truth boundary, text fit, session-wide preferences isolation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 06:52:32 +02:00

71 lines
2.3 KiB
Python

from unittest.mock import Mock
from src.core.game import Game
from src.sonar.sonar import Contact
from src.ui.nato_symbols import domain_for_kind
def _publish(game, monkeypatch, contact):
contact.last_seen = game.sim_t
contact.confidence = contact.quality = 1.0
contact.passive_bearing = 90.0
monkeypatch.setattr(game.sonar, "update", Mock())
monkeypatch.setattr(game.sonar, "active_contacts", lambda: [contact])
game._update_sensors(0.25)
return game.air_picture._tracks[f"U-{contact.target_id}"]
def test_generic_underwater_contact_publishes_unknown_domain(monkeypatch):
game = Game(seed=901, audio_enabled=False)
contact = Contact(7, 700, "passiv", "sub")
track = _publish(game, monkeypatch, contact)
assert track.kind == "UNKNOWN"
assert track.label == "K7"
assert track.hostile is False
def test_torpedo_domain_comes_only_from_operator_classification(monkeypatch):
game = Game(seed=902, audio_enabled=False)
contact = Contact(8, 800, "passiv", "torpedo")
# The weapon itself publishes no domain until the operator classifies it.
assert _publish(game, monkeypatch, contact).kind == "UNKNOWN"
contact.player_class = "TORPEDO"
game.sim_t += 1.0 # next measurement epoch
track = _publish(game, monkeypatch, contact)
assert track.kind == "TORP"
assert domain_for_kind(track.kind) == "UNDERWATER_WEAPON"
assert track.label == "K8"
assert track.hostile is False
def test_biological_contact_publishes_no_domain_hint(monkeypatch):
game = Game(seed=903, audio_enabled=False)
contact = Contact(9, 900, "passiv", "animal")
track = _publish(game, monkeypatch, contact)
# A whale once published SUBSURFACE while real boats stayed UNKNOWN.
assert track.kind == "UNKNOWN"
assert domain_for_kind(track.kind) == "UNKNOWN"
assert track.label == "K9"
assert track.hostile is False
def test_manual_reclassification_does_not_rewrite_sensor_domain(monkeypatch):
game = Game(seed=904, audio_enabled=False)
contact = Contact(10, 1000, "passiv", "sub")
track = _publish(game, monkeypatch, contact)
assert track.kind == "UNKNOWN"
contact.player_class = "U_BOOT"
assert contact.display_label == "U-Boot"
track = _publish(game, monkeypatch, contact)
assert track.kind == "UNKNOWN"
assert track.label == "K10"
assert track.hostile is False