apple_kit

Apple-native services for Radroots iOS and macOS apps
git clone https://radroots.dev/git/apple_kit.git
Log | Files | Refs | README

commit c0177dda89e33cbf18179f53558105f6ae63f693
parent 3a411118e41f4fece4d51a34328c2c6a92e9e478
Author: triesap <tyson@radroots.org>
Date:   Thu, 18 Jun 2026 13:02:13 -0700

background: fail closed on registration rejection

- map false background task registration to a scheduler failure
- preserve successful registration return values for existing callers
- add adapter coverage for registration rejection behavior
- keep background task platform APIs behind RadrootsKit

Diffstat:
MSources/RadrootsKit/RadrootsAppleBackgroundTasks.swift | 8+++++++-
MTests/RadrootsKitTests/RadrootsAppleBackgroundTaskSchedulerTests.swift | 16++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/Sources/RadrootsKit/RadrootsAppleBackgroundTasks.swift b/Sources/RadrootsKit/RadrootsAppleBackgroundTasks.swift @@ -108,7 +108,13 @@ public final class RadrootsAppleBackgroundTaskScheduler: RadrootsBackgroundTaskS @discardableResult public func register(_ registration: RadrootsAppleBackgroundTaskRegistration) async throws -> Bool { - try await adapters.register(registration) + let registered = try await adapters.register(registration) + guard registered else { + throw RadrootsBackgroundTaskError.schedulerFailure( + "background task registration was rejected" + ) + } + return registered } public func submit(_ request: RadrootsBackgroundTaskRequest) async throws -> RadrootsBackgroundTaskSnapshot { diff --git a/Tests/RadrootsKitTests/RadrootsAppleBackgroundTaskSchedulerTests.swift b/Tests/RadrootsKitTests/RadrootsAppleBackgroundTaskSchedulerTests.swift @@ -63,6 +63,22 @@ import Testing } } +@Test func appleBackgroundTaskSchedulerMapsRegistrationRejectionToTypedFailure() async throws { + let probe = RadrootsAppleBackgroundTaskSchedulerProbe(registerResult: false) + let scheduler = RadrootsAppleBackgroundTaskScheduler(adapters: probe.adapters()) + let identifier = try RadrootsBackgroundTaskIdentifier("org.radroots.field-ios.background.refresh") + let registration = RadrootsAppleBackgroundTaskRegistration( + identifier: identifier, + kind: .appRefresh, + handler: { true } + ) + + await #expect(throws: RadrootsBackgroundTaskError.schedulerFailure("background task registration was rejected")) { + _ = try await scheduler.register(registration) + } + #expect(await probe.registeredIdentifiers == [identifier]) +} + private actor RadrootsAppleBackgroundTaskSchedulerProbe { private let nowValue: Date private let registerResult: Bool