Buckets:
localhost1978/localhost / LOCALHOST1978 /Modules /SSK_Providers /Tests /SSK_ProvidersTests /DaemonModelDocGenSetupTests.swift
| #if os(macOS) | |
| import Foundation | |
| import SSK_Foundation | |
| import XCTest | |
| @testable import SSK_Providers | |
| final class DaemonModelDocGenSetupTests: XCTestCase { | |
| func testVaultLeaseStartsStorageHostAtVerifiedMountURL() async throws { | |
| let probe = StorageHostLifecycleProbe() | |
| let state = StorageHostRunState() | |
| let hooks = DaemonModel.makeVaultBackgroundServiceHooks( | |
| state: state, | |
| startStorageHost: { mountURL in | |
| await probe.record(.start(mountURL)) | |
| }, | |
| stopStorageHost: { | |
| await probe.record(.stop) | |
| } | |
| ) | |
| let vaultID = VaultID() | |
| let mountURL = URL(fileURLWithPath: "/private/tmp/VaultMounts/\(vaultID)") | |
| try await hooks.start(vaultID, mountURL) | |
| XCTAssertTrue(state.isRunning) | |
| let events = await probe.events() | |
| XCTAssertEqual(events, [.start(mountURL)]) | |
| } | |
| func testStorageHostStartFailureFailsLeaseHookAndDoesNotMarkItRunning() async { | |
| let probe = StorageHostLifecycleProbe() | |
| let state = StorageHostRunState() | |
| let hooks = DaemonModel.makeVaultBackgroundServiceHooks( | |
| state: state, | |
| startStorageHost: { mountURL in | |
| await probe.record(.start(mountURL)) | |
| throw StorageHostLifecycleTestError.startFailed | |
| }, | |
| stopStorageHost: { | |
| await probe.record(.stop) | |
| } | |
| ) | |
| let vaultID = VaultID() | |
| let mountURL = URL(fileURLWithPath: "/private/tmp/VaultMounts/\(vaultID)") | |
| do { | |
| try await hooks.start(vaultID, mountURL) | |
| XCTFail("Expected storage start to fail.") | |
| } catch { | |
| XCTAssertEqual(error as? StorageHostLifecycleTestError, .startFailed) | |
| } | |
| XCTAssertFalse(state.isRunning) | |
| let events = await probe.events() | |
| XCTAssertEqual(events, [.start(mountURL)]) | |
| } | |
| func testLeaseStopWaitsForStorageHostStopAndClearsState() async throws { | |
| let probe = StorageHostLifecycleProbe() | |
| let state = StorageHostRunState() | |
| let hooks = DaemonModel.makeVaultBackgroundServiceHooks( | |
| state: state, | |
| startStorageHost: { mountURL in | |
| await probe.record(.start(mountURL)) | |
| }, | |
| stopStorageHost: { | |
| await probe.record(.stop) | |
| } | |
| ) | |
| let vaultID = VaultID() | |
| let mountURL = URL(fileURLWithPath: "/private/tmp/VaultMounts/\(vaultID)") | |
| try await hooks.start(vaultID, mountURL) | |
| try await hooks.stop(vaultID) | |
| XCTAssertFalse(state.isRunning) | |
| let events = await probe.events() | |
| XCTAssertEqual(events, [.start(mountURL), .stop]) | |
| } | |
| func testMissingVaultLaunchKeyFailsClosed() async { | |
| let resolver = DaemonModel.makeDocGenExecutorResolver( | |
| environment: ["SSK_DOCGEN_WORKSPACE": "/private/tmp"], | |
| executableURL: URL(fileURLWithPath: "/bin/sh") | |
| ) | |
| do { | |
| _ = try await resolver() | |
| XCTFail("Expected the missing vault key to fail.") | |
| } catch { | |
| XCTAssertEqual(error as? DocGenExecutorResolutionError, .vaultUnavailable) | |
| } | |
| } | |
| func testRelativeLaunchPathsFailClosed() async { | |
| let resolver = DaemonModel.makeDocGenExecutorResolver( | |
| environment: [ | |
| "SSK_DOCGEN_WORKSPACE": "relative/workspace", | |
| "SSK_DOCGEN_VAULT": "relative/vault", | |
| ], | |
| executableURL: URL(fileURLWithPath: "/bin/sh") | |
| ) | |
| do { | |
| _ = try await resolver() | |
| XCTFail("Expected relative paths to fail.") | |
| } catch { | |
| XCTAssertEqual(error as? DocGenExecutorResolutionError, .vaultUnavailable) | |
| } | |
| } | |
| func testUnknownEnvironmentKeysDoNotConfigureDocGen() async { | |
| let resolver = DaemonModel.makeDocGenExecutorResolver( | |
| environment: [ | |
| "WORKSPACE": "/private/tmp", | |
| "VAULT": "/private/tmp", | |
| ], | |
| executableURL: URL(fileURLWithPath: "/bin/sh") | |
| ) | |
| do { | |
| _ = try await resolver() | |
| XCTFail("Expected unknown launch keys to be ignored.") | |
| } catch { | |
| XCTAssertEqual(error as? DocGenExecutorResolutionError, .vaultUnavailable) | |
| } | |
| } | |
| func testStoredConfigurationIsUsedWhenDevelopmentOverridesAreAbsent() async throws { | |
| let configuration = DocGenHostConfiguration( | |
| workspaceURL: URL(fileURLWithPath: "/private/tmp"), | |
| vaultURL: URL(fileURLWithPath: "/private/tmp") | |
| ) | |
| let resolver = DaemonModel.makeDocGenExecutorResolver( | |
| environment: [:], | |
| executableURL: URL(fileURLWithPath: "/bin/sh"), | |
| storedConfiguration: configuration | |
| ) | |
| _ = try await resolver() | |
| } | |
| func testIncompleteDevelopmentOverrideDoesNotMixWithStoredConfiguration() async { | |
| let configuration = DocGenHostConfiguration( | |
| workspaceURL: URL(fileURLWithPath: "/private/tmp"), | |
| vaultURL: URL(fileURLWithPath: "/private/tmp") | |
| ) | |
| let resolver = DaemonModel.makeDocGenExecutorResolver( | |
| environment: ["SSK_DOCGEN_WORKSPACE": "/private/tmp"], | |
| executableURL: URL(fileURLWithPath: "/bin/sh"), | |
| storedConfiguration: configuration | |
| ) | |
| do { | |
| _ = try await resolver() | |
| XCTFail("Expected the incomplete environment override to fail closed.") | |
| } catch { | |
| XCTAssertEqual(error as? DocGenExecutorResolutionError, .vaultUnavailable) | |
| } | |
| } | |
| func testCompleteDevelopmentOverrideTakesPriorityOverStoredConfiguration() async throws { | |
| let configuration = DocGenHostConfiguration( | |
| workspaceURL: URL(fileURLWithPath: "/path/that/does/not/exist"), | |
| vaultURL: URL(fileURLWithPath: "/path/that/does/not/exist") | |
| ) | |
| let resolver = DaemonModel.makeDocGenExecutorResolver( | |
| environment: [ | |
| "SSK_DOCGEN_WORKSPACE": "/private/tmp", | |
| "SSK_DOCGEN_VAULT": "/private/tmp", | |
| ], | |
| executableURL: URL(fileURLWithPath: "/bin/sh"), | |
| storedConfiguration: configuration | |
| ) | |
| _ = try await resolver() | |
| } | |
| } | |
| private enum StorageHostLifecycleTestError: Error, Equatable, Sendable { | |
| case startFailed | |
| } | |
| private actor StorageHostLifecycleProbe { | |
| enum Event: Equatable, Sendable { | |
| case start(URL) | |
| case stop | |
| } | |
| private var recordedEvents: [Event] = [] | |
| func record(_ event: Event) { | |
| recordedEvents.append(event) | |
| } | |
| func events() -> [Event] { | |
| recordedEvents | |
| } | |
| } | |
| #endif | |
Xet Storage Details
- Size:
- 6.8 kB
- Xet hash:
- 893f01d52d872ddd059334df06b71671fefb92ac6302508407476daaa628de84
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.