@@ -363,9 +363,10 @@ class IngestorTests: AppTestCase {
363363 // - don't update package
364364 // - don't create repository records
365365 // setup
366- for url in [ " https://github.com/foo/1 " , " https://github.com/foo/2 " ] . asURLs {
367- try await Package ( url: url, processingStage: . reconciliation) . save ( on: app. db)
368- }
366+ try await Package ( id: . id0, url: " https://github.com/foo/0 " , status: . ok, processingStage: . reconciliation)
367+ . save ( on: app. db)
368+ try await Package ( id: . id1, url: " https://github.com/foo/1 " , status: . ok, processingStage: . reconciliation)
369+ . save ( on: app. db)
369370 // Return identical metadata for both packages, same as a for instance a redirected
370371 // package would after a rename / ownership change
371372 Current . fetchMetadata = { _, _, _ in
@@ -385,7 +386,6 @@ class IngestorTests: AppTestCase {
385386 stars: 0 ,
386387 summary: " desc " )
387388 }
388- let lastUpdate = Date ( )
389389
390390 try await withDependencies {
391391 $0. date. now = . now
@@ -396,31 +396,48 @@ class IngestorTests: AppTestCase {
396396
397397 // validate repositories (single element pointing to the ingested package)
398398 let repos = try await Repository . query ( on: app. db) . all ( )
399- let ingested = try await Package . query ( on: app. db)
400- . filter ( \. $processingStage == . ingestion)
399+ XCTAssertEqual ( repos. count, 1 )
400+
401+ // validate packages - one should have succeeded, one should have failed
402+ let succeeded = try await Package . query ( on: app. db)
403+ . filter ( \. $status == . ok)
401404 . first ( )
402405 . unwrap ( )
403- XCTAssertEqual ( repos. map ( \. $package. id) , [ try ingested. requireID ( ) ] )
404-
405- // validate packages
406- let reconciled = try await Package . query ( on: app. db)
407- . filter ( \. $processingStage == . reconciliation)
406+ let failed = try await Package . query ( on: app. db)
407+ . filter ( \. $status == . ingestionFailed)
408408 . first ( )
409409 . unwrap ( )
410- // the ingested package has the update ...
411- XCTAssertEqual ( ingested. status, . new)
412- XCTAssertEqual ( ingested. processingStage, . ingestion)
413- XCTAssert ( ingested. updatedAt! > lastUpdate)
414- // ... while the reconciled package remains unchanged ...
415- XCTAssertEqual ( reconciled. status, . new)
416- XCTAssertEqual ( reconciled. processingStage, . reconciliation)
417- XCTAssert ( reconciled. updatedAt! < lastUpdate)
418- // ... and an error has been logged
410+ XCTAssertEqual ( succeeded. processingStage, . ingestion)
411+ XCTAssertEqual ( failed. processingStage, . ingestion)
412+ // an error must have been logged
419413 try logger. logs. withValue { logs in
420414 XCTAssertEqual ( logs. count, 1 )
421415 let log = try XCTUnwrap ( logs. first)
422416 XCTAssertEqual ( log. level, . critical)
423- XCTAssertEqual ( log. message, #"Ingestion.Error( \#( try reconciled. requireID ( ) ) , repositorySaveUniqueViolation(duplicate key value violates unique constraint "idx_repositories_owner_name"))"# )
417+ XCTAssertEqual ( log. message, #"Ingestion.Error( \#( try failed. requireID ( ) ) , repositorySaveUniqueViolation(duplicate key value violates unique constraint "idx_repositories_owner_name"))"# )
418+ }
419+
420+ // ensure analysis can process these packages
421+ try await withDependencies {
422+ $0. date. now = . now
423+ $0. environment. allowSocialPosts = { false }
424+ } operation: {
425+ Current . fileManager. fileExists = { @Sendable _ in true }
426+ Current . git. commitCount = { @Sendable _ in 1 }
427+ Current . git. firstCommitDate = { @Sendable _ in . t0 }
428+ Current . git. lastCommitDate = { @Sendable _ in . t0 }
429+ Current . git. getTags = { @Sendable _ in [ ] }
430+ Current . git. hasBranch = { @Sendable _, _ in true }
431+ Current . git. revisionInfo = { @Sendable _, _ in . init( commit: " sha0 " , date: . t0) }
432+ Current . git. shortlog = { @Sendable _ in " " }
433+ Current . shell. run = { @Sendable cmd, _ in
434+ if cmd. description. hasSuffix ( " package dump-package " ) {
435+ return . packageDump( name: " foo " )
436+ }
437+ return " "
438+ }
439+
440+ try await Analyze . analyze ( client: app. client, database: app. db, mode: . limit( 10 ) )
424441 }
425442 }
426443
@@ -665,3 +682,24 @@ class IngestorTests: AppTestCase {
665682 XCTAssertEqual ( fork5, nil )
666683 }
667684}
685+
686+
687+ private extension String {
688+ static func packageDump( name: String ) -> Self {
689+ #"""
690+ {
691+ "name": " \#( name) ",
692+ "products": [
693+ {
694+ "name": "p1",
695+ "targets": [],
696+ "type": {
697+ "executable": null
698+ }
699+ }
700+ ],
701+ "targets": []
702+ }
703+ """#
704+ }
705+ }
0 commit comments