Skip to content

refactor: clean up SessionPhase after code review#27

Merged
gwillish merged 1 commit into
mainfrom
simplify/session-phase-cleanup
May 10, 2026
Merged

refactor: clean up SessionPhase after code review#27
gwillish merged 1 commit into
mainfrom
simplify/session-phase-cleanup

Conversation

@gwillish
Copy link
Copy Markdown
Owner

@gwillish gwillish commented May 10, 2026

Summary

  • SessionPhase.Codable: moved the forward-compatibility fallback (unknown raw value → .running) into a custom init(from:) on SessionPhase itself, so EncounterSession's decoder can use decodeIfPresent(SessionPhase.self, …) instead of a stringly-typed String → rawValue detour
  • pause() / resume(): guard on current value before writing to avoid spurious @Observable notifications when the phase is already in the target state (consistent with other mutating methods in the file)
  • Duplicate MARK removed: // MARK: Lifecycle (no-dash property marker) was redundant alongside // MARK: - Lifecycle for the methods section
  • Force-unwrap in tests: replaced json.data(using: .utf8)! with try #require(…) in the two Codable edge-case tests per project convention

Test plan

  • swift test --filter DHKitTests passes (101 tests, 14 suites)
  • SessionPhaseTests — all phase transition, idempotency, and Codable round-trip cases green
  • missingPhaseKeyDecodesAsRunning and unknownFuturePhaseValueDecodesAsRunning still green with the new SessionPhase.init(from:) implementation

- Move forward-compat fallback into SessionPhase.init(from:) so callers
  use typed decodeIfPresent instead of a String→rawValue detour
- Guard pause()/resume() before writing to avoid spurious @observable
  notifications when phase is already in the target state
- Remove duplicate // MARK: Lifecycle property marker (methods section
  already carries the canonical MARK)
- Replace force-unwrap in tests with try #require per project convention
@gwillish gwillish merged commit 0b7d284 into main May 10, 2026
2 checks passed
@gwillish gwillish deleted the simplify/session-phase-cleanup branch May 10, 2026 16:53
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