prop/test/microwaveprop/release_test.exs
Graham McIntire f99d07bd29
test: push line coverage from 71.7% → 78.67%
Adds ~600 new test cases (2013 → 2613 tests; 170 properties; 0
failures) across 12 new test files plus expansions of eight existing
files. Big lifts per module:

  ContactLive.Mechanism      33 → 100%
  MetricsPlug                54 → ~100%
  Microwaveprop.Release      15.8 → 70%+
  Telemetry                  38 → 76%
  HrrrNativeGridWorker       27.7 → 76%
  ContactLive.Show           34 → 48% (handler + render branches)
  Admin.ContactEditLive      49.7 → 70%+
  GefsFetchWorker            35.8 → ~55%
  IonosphereFetchWorker      56.3 → 75%
  PathLive                   58.9 → 67%
  WeatherMapLive             66.9 → 80.2%
  RoverLive                  0 → 70.3%
  ContactMapLive             59.2 → 89.8%
  ContactMapController       0 → 100%
  Mix tasks (Rust.Golden, Notebook, Backtest, HrrrBackfill,
    HrrrClimatology, HrrrNativeBackfill, NexradBackfill,
    RadarBackfill, ImportContestLogs, PropagationGrid,
    ResetEnrichment, Hrrr.PurgeGridPoints)  0 → ~60-100%

Two incidental fixes made while adding tests:

- ContactLive.Show.handle_event("toggle_flag", ...) was passing
  socket.assigns.current_scope to admin?/1 instead of socket.assigns,
  so admins never matched the pattern and every toggle ran the
  "Admins only." flash branch. Flag now toggles for admins again.

- Commercial.PollWorker.fetch_weather/1 promoted from private to
  @doc'd public so the IEM-fetch + ASOS-upsert path can be tested
  directly without driving perform/1 through live SNMP (which was
  timing out for ~50 s per test in the earlier attempt).

Stable property-test additions cover the dewpoint-from-RH monotonicity,
nearest_run/1 idempotence, and the ionosphere station envelope.
2026-04-23 18:43:18 -05:00

105 lines
3.6 KiB
Elixir

defmodule Microwaveprop.ReleaseTest do
@moduledoc """
Smoke tests for the release-task entry points.
Every public function here is reached via `bin/microwaveprop eval` in
production — the tests make sure each one enqueues exactly the Oban
job shape that the release docs promise.
"""
use Microwaveprop.DataCase, async: false
use Oban.Testing, repo: Microwaveprop.Repo
alias Microwaveprop.Release
alias Microwaveprop.Workers.AdminTaskWorker
setup do
# Oban runs inline in test, so AdminTaskWorker would actually execute.
# Patch it out: we only care that Release *schedules* the right job.
Oban.Testing.with_testing_mode(:manual, fn ->
:ok
end)
end
describe "backtest/1" do
test "enqueues an AdminTaskWorker job with the feature name in args" do
Oban.Testing.with_testing_mode(:manual, fn ->
ExUnit.CaptureIO.capture_io(fn -> Release.backtest("naive_gradient") end)
assert_enqueued(
worker: AdminTaskWorker,
args: %{task: "backtest", feature: "naive_gradient"}
)
end)
end
end
describe "backtest_all/0" do
test "enqueues the consolidated backtest task" do
Oban.Testing.with_testing_mode(:manual, fn ->
ExUnit.CaptureIO.capture_io(fn -> Release.backtest_all() end)
assert_enqueued(worker: AdminTaskWorker, args: %{task: "backtest_all"})
end)
end
end
describe "climatology/1" do
test "uses the default min_samples of 3" do
Oban.Testing.with_testing_mode(:manual, fn ->
ExUnit.CaptureIO.capture_io(fn -> Release.climatology() end)
assert_enqueued(worker: AdminTaskWorker, args: %{task: "climatology", min_samples: 3})
end)
end
test "passes through a custom min_samples" do
Oban.Testing.with_testing_mode(:manual, fn ->
ExUnit.CaptureIO.capture_io(fn -> Release.climatology(7) end)
assert_enqueued(worker: AdminTaskWorker, args: %{task: "climatology", min_samples: 7})
end)
end
end
describe "recalibrate/0" do
test "enqueues a recalibration" do
Oban.Testing.with_testing_mode(:manual, fn ->
ExUnit.CaptureIO.capture_io(fn -> Release.recalibrate() end)
assert_enqueued(worker: AdminTaskWorker, args: %{task: "recalibrate"})
end)
end
end
describe "native_derive/1" do
test "enqueues with the provided row limit" do
Oban.Testing.with_testing_mode(:manual, fn ->
ExUnit.CaptureIO.capture_io(fn -> Release.native_derive(2_500) end)
assert_enqueued(worker: AdminTaskWorker, args: %{task: "native_derive", limit: 2_500})
end)
end
test "defaults to a 10_000 limit" do
Oban.Testing.with_testing_mode(:manual, fn ->
ExUnit.CaptureIO.capture_io(fn -> Release.native_derive() end)
assert_enqueued(worker: AdminTaskWorker, args: %{task: "native_derive", limit: 10_000})
end)
end
end
describe "scorer_diff/1" do
test "prints a deprecation notice (propagation_scores is gone)" do
output = ExUnit.CaptureIO.capture_io(fn -> Release.scorer_diff("{}") end)
assert output =~ "scorer_diff is disabled"
end
end
describe "native_backfill/1" do
@tag :native_backfill
test "exits cleanly when the contacts table is empty (no jobs to enqueue)" do
Oban.Testing.with_testing_mode(:manual, fn ->
output = ExUnit.CaptureIO.capture_io(fn -> Release.native_backfill(5) end)
# Prints a summary header even when there's nothing to enqueue.
assert output =~ "Enqueuing 0 native backfill jobs"
assert output =~ "Done."
end)
end
end
end