@@ -2935,6 +2935,93 @@ struct PackageCommandTests {
29352935 }
29362936 }
29372937
2938+ @Test (
2939+ . tags( . Feature. Command. Package. PurgeCache) ,
2940+ arguments: getBuildData ( for: SupportedBuildSystemOnAllPlatforms) ,
2941+ )
2942+ func purgeCacheWithoutPackage(
2943+ data: BuildData ,
2944+ ) async throws {
2945+ // Create a temporary directory without Package.swift
2946+ try await fixture ( name: " Miscellaneous " ) { fixturePath in
2947+ let tempDir = fixturePath. appending ( " empty-dir-for-purge-test " )
2948+ try localFileSystem. createDirectory ( tempDir, recursive: true )
2949+
2950+ // Use a unique temporary cache directory to avoid conflicts with parallel tests
2951+ try await withTemporaryDirectory ( removeTreeOnDeinit: true ) { cacheDir in
2952+ let result = try await executeSwiftPackage (
2953+ tempDir,
2954+ configuration: data. config,
2955+ extraArgs: [ " purge-cache " , " --cache-path " , cacheDir. pathString] ,
2956+ buildSystem: data. buildSystem
2957+ )
2958+
2959+ #expect( !result. stderr. contains ( " Could not find Package.swift " ) )
2960+ }
2961+ }
2962+ }
2963+
2964+ @Test (
2965+ . tags( . Feature. Command. Package. PurgeCache) ,
2966+ arguments: getBuildData ( for: SupportedBuildSystemOnAllPlatforms) ,
2967+ )
2968+ func purgeCacheInPackageDirectory(
2969+ data: BuildData ,
2970+ ) async throws {
2971+ // Test that purge-cache works in a package directory and successfully purges caches
2972+ try await fixture ( name: " DependencyResolution/External/Simple " ) { fixturePath in
2973+ let packageRoot = fixturePath. appending ( " Bar " )
2974+
2975+ // Use a unique temporary cache directory for this test
2976+ try await withTemporaryDirectory ( removeTreeOnDeinit: true ) { tempDir in
2977+ let cacheDir = tempDir. appending ( " test-cache " )
2978+ let cacheArgs = [ " --cache-path " , cacheDir. pathString]
2979+
2980+ // Resolve dependencies to populate cache
2981+ // Note: This fixture uses local dependencies, so only manifest cache will be populated
2982+ try await executeSwiftPackage (
2983+ packageRoot,
2984+ configuration: data. config,
2985+ extraArgs: [ " resolve " ] + cacheArgs,
2986+ buildSystem: data. buildSystem
2987+ )
2988+
2989+ // Verify manifest cache was populated
2990+ let manifestsCache = cacheDir. appending ( components: " manifests " )
2991+ expectDirectoryExists ( at: manifestsCache)
2992+
2993+ // Check for manifest.db file (main database file)
2994+ let manifestDB = manifestsCache. appending ( " manifest.db " )
2995+ let hasManifestDB = localFileSystem. exists ( manifestDB)
2996+
2997+ // Check for SQLite auxiliary files that might exist
2998+ let manifestDBWAL = manifestsCache. appending ( " manifest.db-wal " )
2999+ let manifestDBSHM = manifestsCache. appending ( " manifest.db-shm " )
3000+ let hasAuxFiles = localFileSystem. exists ( manifestDBWAL) || localFileSystem. exists ( manifestDBSHM)
3001+
3002+ // At least one manifest database file should exist
3003+ #expect( hasManifestDB || hasAuxFiles, " Manifest cache should be populated after resolve " )
3004+
3005+ // Run purge-cache
3006+ let result = try await executeSwiftPackage (
3007+ packageRoot,
3008+ configuration: data. config,
3009+ extraArgs: [ " purge-cache " ] + cacheArgs,
3010+ buildSystem: data. buildSystem
3011+ )
3012+
3013+ // Verify command succeeded
3014+ #expect( !result. stderr. contains ( " Could not find Package.swift " ) )
3015+
3016+ // Verify manifest.db was removed (the purge implementation removes this file)
3017+ expectFileDoesNotExists ( at: manifestDB, " manifest.db should be removed after purge " )
3018+
3019+ // Note: SQLite auxiliary files (WAL/SHM) may or may not be removed depending on SQLite state
3020+ // The important check is that the main database file is removed
3021+ }
3022+ }
3023+ }
3024+
29383025 @Test (
29393026 . tags(
29403027 . Feature. Command. Package. Resolve,
0 commit comments