Skip to content

test: baseline pure-logic tests across manager + agent#15

Merged
kleopasevan merged 2 commits intomainfrom
baseline-tests
Apr 29, 2026
Merged

test: baseline pure-logic tests across manager + agent#15
kleopasevan merged 2 commits intomainfrom
baseline-tests

Conversation

@kleopasevan
Copy link
Copy Markdown
Contributor

Summary

Adds 70 pure-logic tests across modules the upcoming pluggable-VMM
backend refactor will touch. Captures current behavior so refactors
can detect regressions.

Test count: 25 → 95 across the workspace (no integration tests; all
pure logic, no DB, no HTTP, no real VMM).

Per-module breakdown

Module Tests Notes
manager/vms/service.rs 14 network selection, rate-limiter normalization, VmPaths, tap-name format, snapshot payloads, URL query encoding
manager/snapshots/{routes,repo}.rs 18 URL building, payload shapes, name resolution, mem-path handling. 7 pure helpers extracted from inlined async handlers for testability
manager/templates/{routes,repo}.rs 7 TemplateSpec round-trip, TemplateRow JSON decoding
manager/hosts/routes.rs 8 status thresholds, metrics extraction, row mapping. 3 helpers + 2 threshold constants extracted
manager/networks/{service,routes}.rs 8 gateway derivation, DHCP range, host-IP parsing, list-item mapping
agent/vm/spawn.rs 5 unit-name format, SpawnReq serde, socket connectability
agent/vm/{stop,serial,balloon,entropy,system}.rs 8 request serde round-trips, config-path layouts

Production code refactors (in scope, byte-for-byte equivalent)

  • snapshots/routes.rs — extracted 7 pure helpers (build_agent_snapshot_urls, resolve_snapshot_name, resolve_snapshot_type, build_create_snapshot_payload, combined_snapshot_size_i64, resolve_storage_mem_path, resolve_instantiate_name) and a AgentSnapshotUrls struct. Original behavior preserved including Some("") override semantics and None mem path serializing as JSON null.
  • hosts/routes.rs — extracted compute_host_status, extract_host_metrics, host_row_to_list_item plus HEALTHY_THRESHOLD_SECONDS = 30 and DEGRADED_THRESHOLD_SECONDS = 300 constants. Call sites in heartbeat/list/get rewired to call helpers.

No other production code modified. No new dependencies.

Verification

  • cargo test --workspace --no-fail-fast → 72 manager + 23 agent passing, 11 ignored (pre-existing)
  • cargo clippy --all-targets --all-features -- -D warnings → clean
  • cargo fmt -- --check → clean

What this enables

The companion VMM-backend spec (docs/superpowers/specs/2026-04-28-pluggable-vmm-backend.md, separate PR) refactors apps/agent/src/features/vm/spawn.rs, snapshot routes, and the manager's spawn_firecracker flow into a VmmDriver trait. With this baseline in place, that refactor can be verified to preserve current behavior — without it, "no regression" is vacuous (only 25 tests existed beforehand, mostly leaf helpers).

Test plan

  • cargo test --workspace
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo fmt -- --check
  • Reviewer spot-check: extracted helpers in snapshots/routes.rs and hosts/routes.rs preserve original semantics

🤖 Generated with Claude Code

kleopasevan and others added 2 commits April 29, 2026 20:12
Plan 2 (iSCSI): generic + TrueNAS REST control-plane backends, agent
IscsiHostBackend with iscsiadm shell-out, agent kind() handshake,
slow-path rootfs allocator (provision + agent populate + caller-side
resize2fs). 14 tasks.

Plan 3 (UI): TypeScript types, useStorageBackends hook, BackendSelector
component, VM-create + volume-create form integration. 7 tasks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds 70 pure-logic tests covering modules the upcoming pluggable-VMM
refactor will touch: vms, snapshots, templates, hosts, networks (manager)
and vm/{spawn,stop,serial,balloon,entropy,system} (agent). Captures
current behavior so refactors can detect regressions.

Per-module breakdown:
- manager/vms/service.rs: 14 tests (network selection, rate-limiter
  normalization, VmPaths, tap-name format, snapshot payloads, query strings)
- manager/snapshots/{routes,repo}.rs: 18 tests (URL building, payload
  shapes, name resolution, mem-path handling) + 7 helpers extracted
  for testability
- manager/templates/{routes,repo}.rs: 7 tests (TemplateSpec round-trip,
  TemplateRow JSON decoding)
- manager/hosts/routes.rs: 8 tests (status thresholds, metrics extraction,
  row mapping) + 3 helpers + 2 threshold constants extracted
- manager/networks/{service,routes}.rs: 8 tests (gateway derivation,
  DHCP range, host-IP parsing, list-item mapping)
- agent/vm/spawn.rs: 5 tests (unit-name format, SpawnReq serde,
  socket connectability)
- agent/vm/{stop,serial,balloon,entropy,system}.rs: 8 tests (request
  serde round-trips, config-path layouts)

Test count: 25 → 95 across the workspace. All clippy-clean, fmt-clean,
no new dependencies. Production code changes are limited to extracting
pure helpers from inlined async handlers (snapshots/routes.rs,
hosts/routes.rs); behavior is byte-for-byte identical.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kleopasevan kleopasevan merged commit 3bc4917 into main Apr 29, 2026
8 checks passed
@kleopasevan kleopasevan deleted the baseline-tests branch April 29, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant