Files
Termind/FrameworkTests/SSHAgentForwardingPersistenceTests.swift
T
Kaede Akino 8e3f1128da feat(sessions): add tmux persistence and terminal context tracking
Add extensible remote session backends, safe ownership and restore handling, and pane-scoped shell integration over the existing SSH connection.

Keep iOS workspaces in memory and rebuild expired Activity targets on demand. Integrate session selection into Connection Journey with consistent controls, cancellation behavior, and localized counts.
2026-10-16 01:04:12 +08:00

53 lines
2.5 KiB
Swift

import Foundation
import SwiftData
import TermindDomain
import TermindPersistence
import Testing
@Suite @MainActor
struct SSHAgentForwardingPersistenceTests {
@Test func version43HostMigratesDisabledAndNewSettingSurvivesReopen() throws {
let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: root) }
let url = root.appendingPathComponent("Migration.store")
let host = TermindDomain.Host(name: "Existing", host: "localhost", startupSnippetID: UUID())
do {
let schema = Schema(versionedSchema: TermindSchemaV43.self)
let container = try ModelContainer(
for: schema,
configurations: [
ModelConfiguration("Termind", schema: schema, url: url, cloudKitDatabase: .none)
])
container.mainContext.insert(TermindSchemaV32HostModels.PersistentHost(host))
try container.mainContext.save()
}
do {
let container = try TermindPersistence.makeContainer(url: url)
let record = try #require(container.mainContext.fetch(FetchDescriptor<PersistentHost>()).first)
#expect(!record.agentForwardingEnabled)
#expect(record.value.startupSnippetID == host.startupSnippetID)
record.agentForwardingEnabled = true
try container.mainContext.save()
}
let reopened = try TermindPersistence.makeContainer(url: url)
#expect(
try reopened.mainContext.fetch(FetchDescriptor<PersistentHost>()).first?.value.agentForwardingEnabled
== true)
}
@Test func hostVersionTwoRoundTripsAndCannotBeWrittenAsVersionOne() throws {
let host = TermindDomain.Host(
name: "Forwarded", host: "localhost", agentForwardingEnabled: true,
sessionPersistence: .init(enabled: false))
let payload = VaultRecordPayload.host(host)
var envelope = VaultEnvelope(key: payload.key, version: .baseline(writerID: UUID()), payload: payload)
envelope.formatVersion = 2
#expect(try VaultSyncCodec.decode(VaultSyncCodec.encode(envelope)) == envelope)
envelope.formatVersion = 1
#expect(throws: (any Error).self) { try VaultSyncCodec.encode(envelope) }
#expect(SyncRecordFormats.vault.writingVersion(for: "sshKey") == 3)
#expect(SyncRecordFormats.vault.supports(kind: "host", version: 1))
}
}