From 39574c8bb26f5eb8b533a55f0a406863dffe9b09 Mon Sep 17 00:00:00 2001 From: Gale W Date: Sun, 31 May 2026 12:19:30 -0400 Subject: [PATCH] tests: clean up persistent temp directories --- Tests/RAGKitTests/CoreDataVectorIndexTests.swift | 11 +++++++++++ .../SwiftlyFetchLibraryTests.swift | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Tests/RAGKitTests/CoreDataVectorIndexTests.swift b/Tests/RAGKitTests/CoreDataVectorIndexTests.swift index 89d4ce7..d664a85 100644 --- a/Tests/RAGKitTests/CoreDataVectorIndexTests.swift +++ b/Tests/RAGKitTests/CoreDataVectorIndexTests.swift @@ -318,6 +318,17 @@ final class CoreDataVectorIndexTests: XCTestCase { at: directory, withIntermediateDirectories: true ) + addTeardownBlock { + do { + try FileManager.default.removeItem(at: directory) + } catch { + XCTFail( + "RAGKit could not remove a temporary Core Data vector index test directory at \(directory.path). \(error.localizedDescription)", + file: file, + line: line + ) + } + } } catch { XCTFail( "RAGKit could not create a temporary Core Data vector index test directory. \(error.localizedDescription)", diff --git a/Tests/SwiftlyFetchTests/SwiftlyFetchLibraryTests.swift b/Tests/SwiftlyFetchTests/SwiftlyFetchLibraryTests.swift index 8e47568..b6f1aa5 100644 --- a/Tests/SwiftlyFetchTests/SwiftlyFetchLibraryTests.swift +++ b/Tests/SwiftlyFetchTests/SwiftlyFetchLibraryTests.swift @@ -308,6 +308,9 @@ struct SwiftlyFetchLibraryTests { @Test("Persistent facade reopens conventional and semantic state") func persistentFacadeReopensConventionalAndSemanticState() async throws { let directory = try temporaryDirectory() + defer { + cleanupTemporaryDirectory(directory) + } do { let firstLibrary = try await SwiftlyFetchLibrary.macOSPersistentLibrary(at: directory) @@ -332,6 +335,9 @@ struct SwiftlyFetchLibraryTests { @Test("Core Data semantic retry store reopens pending retries") func coreDataSemanticRetryStoreReopensPendingRetries() async throws { let directory = try temporaryDirectory() + defer { + cleanupTemporaryDirectory(directory) + } let storeURL = directory.appendingPathComponent("SemanticRetries.sqlite") let olderDate = try #require(Calendar.current.date(from: DateComponents(year: 2026, month: 1, day: 1))) let newerDate = try #require(Calendar.current.date(from: DateComponents(year: 2026, month: 1, day: 2))) @@ -493,4 +499,14 @@ private func temporaryDirectory() throws -> URL { return directory } + +private func cleanupTemporaryDirectory(_ directory: URL) { + do { + try FileManager.default.removeItem(at: directory) + } catch { + Issue.record( + "SwiftlyFetch could not remove a temporary test directory at \(directory.path). \(error.localizedDescription)" + ) + } +} #endif