Refactor providers - Topology, Instant Privacy, and Polling - #544
Conversation
- Add 3 new ServiceError types for topology operations: - TopologyTimeoutError: timeout waiting for nodes offline - NodeOfflineError: target node unreachable - NodeOperationFailedError: reboot/reset/blink failures - Create InstantTopologyService with JNAP communication logic: - rebootNodes(): single/multi-node reboot with reverse order - factoryResetNodes(): single/multi-node factory reset - startBlinkNodeLED() / stopBlinkNodeLED(): LED control - waitForNodesOffline(): polling with timeout error handling - Update InstantTopologyNotifier to delegate to service: - Remove direct JNAP imports (actions, commands, results) - Remove RouterRepository dependency - Delegate all operations to InstantTopologyService - Add comprehensive test coverage: - 16 service tests covering all methods and error scenarios - 15 provider tests for delegation and error handling - InstantTopologyTestData builder for mock responses - Add spec documentation (analysis.md, checklists, tasks.md)
- Create InstantPrivacyService with 4 methods: - fetchMacFilterSettings() - fetches and transforms MAC filter settings - saveMacFilterSettings() - transforms and saves settings to JNAP - fetchStaBssids() - fetches STA BSSIDs if supported - fetchMyMacAddress() - fetches current device MAC address - Refactor InstantPrivacyNotifier to delegate to InstantPrivacyService - Remove JNAP imports from provider (architecture compliance) - Add error handling with JNAPError to ServiceError mapping - Add InstantPrivacyTestData builder for test data creation - Add MockServiceHelper.isSupportGetSTABSSID() mock method - Add 63 unit tests: - 22 service tests (JNAP communication, error handling) - 5 provider tests (delegation verification) - 36 state tests (enum, data class serialization) - Include spec documentation (spec.md, plan.md, tasks.md, contracts/)
- Create PollingService to handle JNAP communication for polling operations - Move checkDeviceMode (formerly checkSmartMode) to PollingService - Move buildCoreTransactions (formerly _buildCoreTransaction) to PollingService - Move executeTransaction logic to PollingService - Move parseCacheData logic to PollingService - Move updateFernetKeyFromResult (Fernet key update) to PollingService - PollingNotifier now delegates to PollingService while retaining state management and Timer control - All public APIs (pollingProvider, CoreTransactionData) remain unchanged - Add comprehensive unit tests for PollingService (22 tests) - Add unit tests for PollingNotifier state management (11 tests) - Add PollingTestData builder for test data generation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||||||||||||||
| ) | ||
| .then((result) => MACFilterSettings.fromMap(result.output)); | ||
|
|
||
| final mode = MacFilterMode.reslove(settings.macFilterMode); |
There was a problem hiding this comment.
Suggestion: Correct typo in method name
| final mode = MacFilterMode.reslove(settings.macFilterMode); | |
| final mode = MacFilterMode.resolve(settings.macFilterMode); |
User description
- fetchMacFilterSettings() - fetches and transforms MAC filter settings
- saveMacFilterSettings() - transforms and saves settings to JNAP
- fetchStaBssids() - fetches STA BSSIDs if supported
- fetchMyMacAddress() - fetches current device MAC address
- fetchMacFilterSettings() - fetches and transforms MAC filter settings
- saveMacFilterSettings() - transforms and saves settings to JNAP
- fetchStaBssids() - fetches STA BSSIDs if supported
- fetchMyMacAddress() - fetches current device MAC address
PR Type
Enhancement, Tests, Documentation
Description
Create PollingService to encapsulate JNAP polling operations with methods for device mode checking, transaction building, execution, cache parsing, and Fernet key updates
Create InstantPrivacyService with 4 methods for MAC filter settings management, STA BSSID fetching, and device MAC address retrieval with comprehensive error handling
Create InstantTopologyService with methods for node reboot, factory reset, and LED blink operations including offline node polling with timeout detection
Refactor PollingNotifier, InstantPrivacyNotifier, and InstantTopologyNotifier to delegate JNAP operations to respective service layers while maintaining public APIs and state management
Remove JNAP imports from providers to enforce three-layer architecture compliance (provider → service → JNAP)
Add 80+ comprehensive unit tests covering service operations, error handling, state serialization, and provider delegation
Add ServiceError subtypes (
TopologyTimeoutError,NodeOfflineError,NodeOperationFailedError) for topology-specific error scenariosCreate test data builders (
PollingTestData,InstantPrivacyTestData,InstantTopologyTestData) for improved test readability and maintainabilityAdd mock helper methods for service capability detection (
isSupportGetSTABSSID(),isSupportSetup())Create comprehensive specification documents including feature specs, API contracts, data models, research, plans, and quickstart guides for both InstantPrivacy and InstantTopology services
Diagram Walkthrough
File Walkthrough
11 files
instant_privacy_service_test.dart
InstantPrivacyService unit tests with error handlingtest/page/instant_privacy/services/instant_privacy_service_test.dart
InstantPrivacyServicecoveringJNAP communication
splitting (allow/deny)
deduplication
authorization and validation failures
instant_privacy_state_test.dart
InstantPrivacy state classes serialization and equality teststest/page/instant_privacy/providers/instant_privacy_state_test.dart
MacFilterMode,InstantPrivacyStatus,InstantPrivacySettings, andInstantPrivacyStatefunctionality
toJson/fromJson) round-trips
instant_topology_service_test.dart
InstantTopologyService unit tests for node operationstest/page/instant_topology/services/instant_topology_service_test.dart
InstantTopologyServicecovering reboot,factory reset, and LED blink operations
with reverse ordering
state handling
ServiceErrorsubtypespolling_service_test.dart
PollingService unit tests for polling operationstest/core/jnap/services/polling_service_test.dart
PollingServicecovering device mode checkingand core transaction building
device mode and feature support
handling
handling
polling_test_data.dart
PollingTestData builder for test data generationtest/mocks/test_data/polling_test_data.dart
PollingTestDatabuilder class with factory methods for creatingJNAP mock responses
network connections, and system stats
responses
maintainability
instant_topology_provider_test.dart
InstantTopologyNotifier provider delegation teststest/page/instant_topology/providers/instant_topology_provider_test.dart
InstantTopologyNotifierdelegation toInstantTopologyServiceblink operations
NodeOperationFailedError,TopologyTimeoutError, andUnauthorizedErrorare preserved
instant_privacy_provider_test.dart
InstantPrivacyNotifier provider delegation teststest/page/instant_privacy/providers/instant_privacy_provider_test.dart
InstantPrivacyNotifierdelegation toInstantPrivacyServiceperformFetch()with forceRemote and updateStatusOnlyparameters
performSave()delegates to service with node MACaddresses
getMyMACAddress()delegation and proper parameter passingpolling_provider_test.dart
Add unit tests for polling provider and data classestest/core/jnap/providers/polling_provider_test.dart
CoreTransactionDataclasscovering construction, copyWith updates, equality, and props
PollingNotifier.build()to verify initial statePollingNotifier.init()to verify state resetPollingNotifier.pausedgetter and setterPollingNotifier.stopPolling()methodPollingServicefor provider-level testinginstant_topology_test_data.dart
Create test data builder for InstantTopology service teststest/mocks/test_data/instant_topology_test_data.dart
InstantTopologyTestDatabuilder class for test data generationresponses
createGetDevicesResponse()with configurableonline/offline device lists
blink failures
_createDeviceMap()for consistent devicestructure in test data
instant_privacy_test_data.dart
Create test data builder for InstantPrivacy service teststest/mocks/test_data/instant_privacy_test_data.dart
InstantPrivacyTestDatabuilder class for MAC filtering testdata
createMacFilterSettingsSuccess()with configurable filtermode and MAC addresses
createStaBssidsSuccess()for STA BSSID response generationcreateLocalDeviceSuccess()for local device responsegeneration
createLinksysDevice()factory method for creating testdevice objects with connections
jnap_service_supported_mocks.dart
Add mock methods for service capability detectiontest/mocks/jnap_service_supported_mocks.dart
isSupportGetSTABSSID()mock method toMockServiceHelperfortesting STA BSSID support detection
isSupportSetup()mock method toMockServiceHelperfor testingsetup capability detection
7 files
polling_provider.dart
PollingNotifier refactored to use PollingServicelib/core/jnap/providers/polling_provider.dart
PollingNotifierto delegate polling operations to newPollingService_buildCoreTransaction, cache parsing, Fernet key updates)
_servicegetter to accessPollingServicevia Riverpod providerRouterRepositoryparametersinstant_topology_service.dart
InstantTopologyService for node operationslib/page/instant_topology/services/instant_topology_service.dart
InstantTopologyServicewith four public methods:rebootNodes(),factoryResetNodes(),startBlinkNodeLED(),stopBlinkNodeLED()waitForNodesOffline()helper for polling device statuswith configurable retry and timeout
ServiceErrorsubtypes (NodeOperationFailedError, TopologyTimeoutError)
instant_privacy_provider.dart
InstantPrivacyNotifier refactored to use service layerlib/page/instant_privacy/providers/instant_privacy_provider.dart
InstantPrivacyNotifierto delegate JNAP operations to newInstantPrivacyServicesettings, STA BSSIDs, local device fetching)
performFetch()andperformSave()by delegating to servicemethods
RouterRepositoryusage in favor of service layerinstant_topology_provider.dart
Refactor InstantTopology provider to delegate to service layerlib/page/instant_topology/providers/instant_topology_provider.dart
better_action,jnap_transaction,base_command,jnap_result,router_repository)reboot(),startBlinkNodeLED(),stopBlinkNodeLED(),factoryReset()methods to delegate toInstantTopologyService_waitForNodesOffline()method (moved to servicelayer)
toggleBlinkNode()to use service delegation while keepingSharedPreferences state management in provider
polling_service.dart
Create PollingService for JNAP polling operationslib/core/jnap/services/polling_service.dart
PollingServiceclass to encapsulate JNAP pollingoperations
checkDeviceMode()to fetch current device modebuildCoreTransactions()to construct list of pollingcommands based on device capabilities
executeTransaction()to execute JNAP transactions withoptional cache bypass
parseCacheData()to validate and convert cached data toJNAP result map
updateFernetKeyFromResult()to extract and update Fernetencryption key from device info
pollingServiceProviderfor Riverpod dependency injectioninstant_privacy_service.dart
Create InstantPrivacyService for MAC filtering operationslib/page/instant_privacy/services/instant_privacy_service.dart
InstantPrivacyServiceclass for MAC filtering operationsfetchMacFilterSettings()to fetch and transform MAC filtersettings with optional status-only mode
saveMacFilterSettings()to transform and save settings toJNAP with node MAC address merging
fetchStaBssids()to fetch STA BSSIDs with gracefulfallback for unsupported devices
fetchMyMacAddress()to fetch current device MAC addressfrom device list
_mapJnapError()to convertJNAPErrortoServiceErrorinstantPrivacyServiceProviderfor Riverpod dependency injectionservice_error.dart
Add topology operation error types to ServiceErrorlib/core/errors/service_error.dart
TopologyTimeoutErrorfor timeout scenarios when nodes don't gooffline within configured timeout
NodeOfflineErrorfor operations on offline nodes that cannot bereached
NodeOperationFailedErrorfor failed node operations (reboot,factory reset, LED blink) with device ID and operation type
17 files
tasks.md
Add detailed task breakdown for InstantTopology service extractionspecs/001-instant-topology-service/tasks.md
extraction with 49 tasks
Provider Tests, and Polish
tasks.md
Add detailed task breakdown for InstantPrivacy service extractionspecs/001-instant-privacy-service/tasks.md
extraction with 43 tasks
Verification, and Polish
strategies
analysis.md
Add specification analysis report for InstantTopology servicespecs/001-instant-topology-service/analysis.md
and constitution compliance
corresponding tasks
VII, IX, XIII
instant_topology_service_contract.md
Add API contract for InstantTopology servicespecs/001-instant-topology-service/contracts/instant_topology_service_contract.md
InstantTopologyServiceclass structureand provider definition
rebootNodes(),factoryResetNodes(),startBlinkNodeLED(),stopBlinkNodeLED(),waitForNodesOffline()documentation
spec.md
Add feature specification for InstantPrivacy service extractionspecs/001-instant-privacy-service/spec.md
criteria
enforcement
quickstart.md
Add quickstart guide for InstantPrivacy service extractionspecs/001-instant-privacy-service/quickstart.md
extraction
provider refactoring
spec.md
Add feature specification for InstantTopology service extractionspecs/001-instant-topology-service/spec.md
acceptance scenarios
handling, and architecture compliance
research.md
Add research document for InstantTopology service extractionspecs/001-instant-topology-service/research.md
design decisions
RouterPasswordServicepattern asreference implementation
ServiceErrorsubtypes with implementation patternshandling, and test data patterns
requirements.md
Add specification quality checklist for InstantPrivacy servicespecs/001-instant-privacy-service/checklists/requirements.md
readiness
measurable
instant_privacy_service_contract.md
InstantPrivacyService API contract and JNAP communicationspecificationspecs/001-instant-privacy-service/contracts/instant_privacy_service_contract.md
InstantPrivacyServicewith 4 publicmethods:
fetchMacFilterSettings(),saveMacFilterSettings(),fetchStaBssids(), andfetchMyMacAddress()models and UI models, and error handling strategy
InstantPrivacyNotifierand dependency injection patternRouterRepository,JNAPAction, andServiceErrorquickstart.md
InstantTopologyService extraction developer quickstart guidespecs/001-instant-topology-service/quickstart.md
InstantTopologyServicefromInstantTopologyNotifierServiceErrortypes, creatingservice class, updating provider, and writing tests
architecture compliance
implementation
data-model.md
InstantPrivacyService data model and transformation specificationsspecs/001-instant-privacy-service/data-model.md
application layer UI models
JNAP) operations
MacFilterMode,InstantPrivacySettings,InstantPrivacyStatus) that require no changesmodes
data-model.md
InstantTopologyService error types and data flow architecturespecs/001-instant-topology-service/data-model.md
ServiceErrorsubtypes:TopologyTimeoutError,NodeOfflineError, andNodeOperationFailedErrorwith detailed fielddescriptions
architecture
sequence diagrams
operation names
plan.md
InstantTopologyService implementation plan and architecture compliancespecs/001-instant-topology-service/plan.md
InstantTopologyNotifierintoInstantTopologyServiceArticles I, III, V, VI, IX, and XIII
organization
contract, and quickstart documents
research.md
InstantPrivacyService design decisions and research findingsspecs/001-instant-privacy-service/research.md
mapping strategy, capability checks, device manager access patterns,
and test data builders
rejected
RouterPasswordServiceas implementation pattern to followplan.md
InstantPrivacyService implementation plan and constitution compliancespecs/001-instant-privacy-service/plan.md
InstantPrivacyServicefromInstantPrivacyNotifierto enforce three-layer architectureVI, VIII, and XIII
and test data builder locations
patterns
requirements.md
InstantTopologyService specification quality validation checklistspecs/001-instant-topology-service/checklists/requirements.md
quality, requirement completeness, and feature readiness
remain
technology-agnostic
architectural compliance