@@ -314,6 +314,7 @@ class AnalyzerTests: AppTestCase {
314314 // Ensure a package that fails analysis goes back to ingesting and isn't stuck in an analysis loop
315315 try await withDependencies {
316316 $0. date. now = . now
317+ $0. fileManager. fileExists = { @Sendable _ in true }
317318 } operation: {
318319 // setup
319320 do {
@@ -333,9 +334,7 @@ class AnalyzerTests: AppTestCase {
333334 try await XCTAssertEqualAsync ( try await Package . fetchCandidates ( app. db, for: . analysis, limit: 10 ) . count, 1 )
334335
335336 // MUT
336- try await Analyze . analyze ( client: app. client,
337- database: app. db,
338- mode: . limit( 10 ) )
337+ try await Analyze . analyze ( client: app. client, database: app. db, mode: . limit( 10 ) )
339338
340339 // Ensure candidate selection is now zero for analysis
341340 // (and also for ingestion, as we're immediately after analysis)
@@ -360,6 +359,7 @@ class AnalyzerTests: AppTestCase {
360359 $0. date. now = . now
361360 $0. environment. allowSocialPosts = { true }
362361 $0. environment. loadSPIManifest = { _ in nil }
362+ $0. fileManager. fileExists = { @Sendable _ in true }
363363 } operation: {
364364 // setup
365365 let urls = [ " https://github.com/foo/1 " , " https://github.com/foo/2 " ]
@@ -395,9 +395,7 @@ class AnalyzerTests: AppTestCase {
395395 }
396396
397397 // MUT
398- try await Analyze . analyze ( client: app. client,
399- database: app. db,
400- mode: . limit( 10 ) )
398+ try await Analyze . analyze ( client: app. client, database: app. db, mode: . limit( 10 ) )
401399
402400 // assert packages have been updated
403401 let packages = try await Package . query ( on: app. db) . sort ( \. $createdAt) . all ( )
@@ -521,39 +519,43 @@ class AnalyzerTests: AppTestCase {
521519 }
522520
523521 func test_updateRepository( ) async throws {
524- // setup
525- Current . git. commitCount = { @Sendable _ in 12 }
526- Current . git. firstCommitDate = { @Sendable _ in . t0 }
527- Current . git. lastCommitDate = { @Sendable _ in . t1 }
528- Current . git. shortlog = { @Sendable _ in
522+ try await withDependencies {
523+ $0. fileManager. fileExists = { @Sendable _ in true }
524+ } operation: {
525+ // setup
526+ Current . git. commitCount = { @Sendable _ in 12 }
527+ Current . git. firstCommitDate = { @Sendable _ in . t0 }
528+ Current . git. lastCommitDate = { @Sendable _ in . t1 }
529+ Current . git. shortlog = { @Sendable _ in
529530 """
530531 10 \t Person 1
531532 2 \t Person 2
532533 """
533- }
534- Current . shell. run = { @Sendable cmd, _ in throw TestError . unknownCommand }
535- let pkg = Package ( id: . id0, url: " 1 " . asGithubUrl. url)
536- try await pkg. save ( on: app. db)
537- try await Repository ( id: . id1, package : pkg, defaultBranch: " main " ) . save ( on: app. db)
538- let jpr = try await Package . fetchCandidate ( app. db, id: pkg. id!)
534+ }
535+ Current . shell. run = { @Sendable cmd, _ in throw TestError . unknownCommand }
536+ let pkg = Package ( id: . id0, url: " 1 " . asGithubUrl. url)
537+ try await pkg. save ( on: app. db)
538+ try await Repository ( id: . id1, package : pkg, defaultBranch: " main " ) . save ( on: app. db)
539+ let jpr = try await Package . fetchCandidate ( app. db, id: pkg. id!)
539540
540- // MUT
541- try await Analyze . updateRepository ( on: app. db, package : jpr)
541+ // MUT
542+ try await Analyze . updateRepository ( on: app. db, package : jpr)
542543
543- // validate
544- do { // ensure JPR relation is updated
545- XCTAssertEqual ( jpr. repository? . commitCount, 12 )
546- XCTAssertEqual ( jpr. repository? . firstCommitDate, . t0)
547- XCTAssertEqual ( jpr. repository? . lastCommitDate, . t1)
548- XCTAssertEqual ( jpr. repository? . authors, PackageAuthors ( authors: [ Author ( name: " Person 1 " ) ] ,
549- numberOfContributors: 1 ) )
550- }
551- do { // ensure changes are persisted
552- let repo = try await Repository . find ( . id1, on: app. db)
553- XCTAssertEqual ( repo? . commitCount, 12 )
554- XCTAssertEqual ( repo? . firstCommitDate, . t0)
555- XCTAssertEqual ( repo? . lastCommitDate, . t1)
556- XCTAssertEqual ( repo? . authors, PackageAuthors ( authors: [ Author ( name: " Person 1 " ) ] , numberOfContributors: 1 ) )
544+ // validate
545+ do { // ensure JPR relation is updated
546+ XCTAssertEqual ( jpr. repository? . commitCount, 12 )
547+ XCTAssertEqual ( jpr. repository? . firstCommitDate, . t0)
548+ XCTAssertEqual ( jpr. repository? . lastCommitDate, . t1)
549+ XCTAssertEqual ( jpr. repository? . authors, PackageAuthors ( authors: [ Author ( name: " Person 1 " ) ] ,
550+ numberOfContributors: 1 ) )
551+ }
552+ do { // ensure changes are persisted
553+ let repo = try await Repository . find ( . id1, on: app. db)
554+ XCTAssertEqual ( repo? . commitCount, 12 )
555+ XCTAssertEqual ( repo? . firstCommitDate, . t0)
556+ XCTAssertEqual ( repo? . lastCommitDate, . t1)
557+ XCTAssertEqual ( repo? . authors, PackageAuthors ( authors: [ Author ( name: " Person 1 " ) ] , numberOfContributors: 1 ) )
558+ }
557559 }
558560 }
559561
@@ -751,6 +753,7 @@ class AnalyzerTests: AppTestCase {
751753 // Tests getPackageInfo(package:version:)
752754 try await withDependencies {
753755 $0. environment. loadSPIManifest = { _ in nil }
756+ $0. fileManager. fileExists = { @Sendable _ in true }
754757 } operation: {
755758 // setup
756759 let commands = QueueIsolated < [ String ] > ( [ ] )
@@ -890,6 +893,7 @@ class AnalyzerTests: AppTestCase {
890893 $0. date. now = . now
891894 $0. environment. allowSocialPosts = { true }
892895 $0. environment. loadSPIManifest = { _ in nil }
896+ $0. fileManager. fileExists = { @Sendable _ in true }
893897 } operation: {
894898 // setup
895899 Current . git. commitCount = { @Sendable _ in 12 }
@@ -1021,16 +1025,20 @@ class AnalyzerTests: AppTestCase {
10211025 // Test parsing a Package.swift that requires a 5.4 toolchain
10221026 // NB: If this test fails on macOS make sure xcode-select -p
10231027 // points to the correct version of Xcode!
1024- // setup
1025- Current . fileManager = . live
1026- Current . shell = . live
1027- try await withTempDir { tempDir in
1028- let fixture = fixturesDirectory ( )
1029- . appendingPathComponent ( " 5.4-Package-swift " ) . path
1030- let fname = tempDir. appending ( " /Package.swift " )
1031- try await ShellOut . shellOut ( to: . copyFile( from: fixture, to: fname) )
1032- let m = try await Analyze . dumpPackage ( at: tempDir)
1033- XCTAssertEqual ( m. name, " VisualEffects " )
1028+ try await withDependencies {
1029+ $0. fileManager. fileExists = FileManagerClient . liveValue. fileExists ( atPath: )
1030+ } operation: {
1031+ // setup
1032+ Current . fileManager = . live
1033+ Current . shell = . live
1034+ try await withTempDir { tempDir in
1035+ let fixture = fixturesDirectory ( )
1036+ . appendingPathComponent ( " 5.4-Package-swift " ) . path
1037+ let fname = tempDir. appending ( " /Package.swift " )
1038+ try await ShellOut . shellOut ( to: . copyFile( from: fixture, to: fname) )
1039+ let m = try await Analyze . dumpPackage ( at: tempDir)
1040+ XCTAssertEqual ( m. name, " VisualEffects " )
1041+ }
10341042 }
10351043 }
10361044
@@ -1039,33 +1047,41 @@ class AnalyzerTests: AppTestCase {
10391047 // NB: If this test fails on macOS make sure xcode-select -p
10401048 // points to the correct version of Xcode!
10411049 // See also https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/1441
1042- // setup
1043- Current . fileManager = . live
1044- Current . shell = . live
1045- try await withTempDir { tempDir in
1046- let fixture = fixturesDirectory ( )
1047- . appendingPathComponent ( " 5.5-Package-swift " ) . path
1048- let fname = tempDir. appending ( " /Package.swift " )
1049- try await ShellOut . shellOut ( to: . copyFile( from: fixture, to: fname) )
1050- let m = try await Analyze . dumpPackage ( at: tempDir)
1051- XCTAssertEqual ( m. name, " Firestarter " )
1050+ try await withDependencies {
1051+ $0. fileManager. fileExists = FileManagerClient . liveValue. fileExists ( atPath: )
1052+ } operation: {
1053+ // setup
1054+ Current . fileManager = . live
1055+ Current . shell = . live
1056+ try await withTempDir { tempDir in
1057+ let fixture = fixturesDirectory ( )
1058+ . appendingPathComponent ( " 5.5-Package-swift " ) . path
1059+ let fname = tempDir. appending ( " /Package.swift " )
1060+ try await ShellOut . shellOut ( to: . copyFile( from: fixture, to: fname) )
1061+ let m = try await Analyze . dumpPackage ( at: tempDir)
1062+ XCTAssertEqual ( m. name, " Firestarter " )
1063+ }
10521064 }
10531065 }
10541066
10551067 func test_dumpPackage_5_9_macro_target( ) async throws {
10561068 // Test parsing a 5.9 Package.swift with a macro target
10571069 // NB: If this test fails on macOS make sure xcode-select -p
10581070 // points to the correct version of Xcode!
1059- // setup
1060- Current . fileManager = . live
1061- Current . shell = . live
1062- try await withTempDir { tempDir in
1063- let fixture = fixturesDirectory ( )
1064- . appendingPathComponent ( " 5.9-Package-swift " ) . path
1065- let fname = tempDir. appending ( " /Package.swift " )
1066- try await ShellOut . shellOut ( to: . copyFile( from: fixture, to: fname) )
1067- let m = try await Analyze . dumpPackage ( at: tempDir)
1068- XCTAssertEqual ( m. name, " StaticMemberIterable " )
1071+ try await withDependencies {
1072+ $0. fileManager. fileExists = FileManagerClient . liveValue. fileExists ( atPath: )
1073+ } operation: {
1074+ // setup
1075+ Current . fileManager = . live
1076+ Current . shell = . live
1077+ try await withTempDir { tempDir in
1078+ let fixture = fixturesDirectory ( )
1079+ . appendingPathComponent ( " 5.9-Package-swift " ) . path
1080+ let fname = tempDir. appending ( " /Package.swift " )
1081+ try await ShellOut . shellOut ( to: . copyFile( from: fixture, to: fname) )
1082+ let m = try await Analyze . dumpPackage ( at: tempDir)
1083+ XCTAssertEqual ( m. name, " StaticMemberIterable " )
1084+ }
10691085 }
10701086 }
10711087
@@ -1506,6 +1522,7 @@ class AnalyzerTests: AppTestCase {
15061522 try await withDependencies {
15071523 $0. date. now = . now
15081524 $0. environment. loadSPIManifest = { _ in nil }
1525+ $0. fileManager. fileExists = { @Sendable _ in true }
15091526 } operation: {
15101527 // setup
15111528 let pkg = try await savePackage ( on: app. db, id: . id0, " https://github.com/foo/1 " . url, processingStage: . ingestion)
0 commit comments