Skip to content

refactor: extract pure AD-fallback helpers and fold overview's double-pass - #9

Merged
zerox80 merged 1 commit into
mainfrom
refactor/ad-users-overview-fold
Jul 1, 2026
Merged

refactor: extract pure AD-fallback helpers and fold overview's double-pass#9
zerox80 merged 1 commit into
mainfrom
refactor/ad-users-overview-fold

Conversation

@zerox80

@zerox80 zerox80 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extract the CSV/inventory fallback-user builder and the search-filter+truncate step out of get_ad_users into small, pure, independently testable functions in a new ad_users module. The stateful AD cache/TTL/fetch/lock-ordering logic (ad_fetch-before-inner) is untouched.
  • Fold build_overview's separate second .filter(needs_upgrade).count() pass into the existing single tallying loop via one more accumulator, removing a redundant full-slice scan while preserving both status.upgrade (status=="upgrade" only) and upgrade_needed (upgrade OR stale-with-reasons) as distinct values.
  • Add Default derive to DeviceFull to enable terse test fixtures for the above.

Why

Readability/maintainability follow-ups from a full code review — no behavior changes, no new dependencies, no speculative abstractions. Both extractions follow the existing pattern in this codebase (see store/facts.rs, upgrade.rs) of keeping pure decision logic in small plain functions that are easy to unit test, separate from the stateful orchestration layer.

Changes

  • New app/src-tauri/src/ad_users.rs: fallback_users_from_devices, filter_and_truncate (pure, unit-tested).
  • New app/src-tauri/src/ad_users_tests.rs: unit tests for the above.
  • app/src-tauri/src/commands.rs: get_ad_users now calls into the two extracted helpers instead of inlining the logic; lock ordering / TTL / cache orchestration unchanged.
  • app/src-tauri/src/store/overview.rs: build_overview computes upgrade_needed inside the existing single accumulation loop instead of a separate pass; status.upgrade computation unchanged.
  • app/src-tauri/src/store/overview_tests.rs: new focused unit test asserting status.upgrade and upgrade_needed diverge correctly for a stale-with-reasons device.
  • app/src-tauri/src/model.rs: DeviceFull derives Default (all field types already support it) to keep test fixtures terse.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test --all (32 tests pass; overview_aggregates assertions unchanged: status.upgrade == 4, upgrade_needed == 5)
  • npm run check
  • Confirmed all touched/new files remain ≤ 300 lines (Source-Line-Limits CI job)

…-pass

get_ad_users mixed cache/TTL/fetch orchestration with two untested pure
steps (fallback-user building, filter+truncate); extract those into a
new ad_users module with unit tests, so the pure logic is testable
independent of the tauri::State-based command.

build_overview scanned devices twice to compute upgrade_needed (once in
the main tally loop, once via a separate .filter().count()); fold the
second pass into the existing loop. status.upgrade and upgrade_needed
remain distinct counters as before (guarded by a new regression test).

No behavior change; both refactors are pure code-quality follow-ups
from a full repo review.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@zerox80
zerox80 merged commit e292c9a into main Jul 1, 2026
9 checks passed
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