@@ -158,17 +158,17 @@ class PipelineTests: AppTestCase {
158158 }
159159
160160 func test_processing_pipeline( ) async throws {
161+ let urls = [ " 1 " , " 2 " , " 3 " ] . asGithubUrls
161162 try await withDependencies {
162163 $0. date. now = . now
164+ $0. packageListRepository. fetchPackageList = { @Sendable _ in urls. asURLs }
165+ $0. packageListRepository. fetchPackageDenyList = { @Sendable _ in [ ] }
163166 $0. packageListRepository. fetchCustomCollections = { @Sendable _ in [ ] }
164167 $0. packageListRepository. fetchCustomCollection = { @Sendable _, _ in [ ] }
165168 } operation: {
166169 // Test pipeline pick-up end to end
167170 // setup
168- let urls = [ " 1 " , " 2 " , " 3 " ] . asGithubUrls
169171 Current . fetchMetadata = { _, owner, repository in . mock( owner: owner, repository: repository) }
170- Current . fetchPackageList = { _ in urls. asURLs }
171-
172172 Current . git. commitCount = { @Sendable _ in 12 }
173173 Current . git. firstCommitDate = { @Sendable _ in . t0 }
174174 Current . git. lastCommitDate = { @Sendable _ in . t1 }
@@ -224,76 +224,78 @@ class PipelineTests: AppTestCase {
224224 XCTAssertEqual ( packages. map ( \. isNew) , [ false , false , false ] )
225225 }
226226
227- // Now we've got a new package and a deletion
228- Current . fetchPackageList = { _ in [ " 1 " , " 3 " , " 4 " ] . asGithubUrls. asURLs }
229-
230- // MUT - reconcile again
231- try await reconcile ( client: app. client, database: app. db)
232-
233- do { // validate - only new package moves to .reconciliation stage
234- let packages = try await Package . query ( on: app. db) . sort ( \. $url) . all ( )
235- XCTAssertEqual ( packages. map ( \. url) , [ " 1 " , " 3 " , " 4 " ] . asGithubUrls)
236- XCTAssertEqual ( packages. map ( \. status) , [ . ok, . ok, . new] )
237- XCTAssertEqual ( packages. map ( \. processingStage) , [ . analysis, . analysis, . reconciliation] )
238- XCTAssertEqual ( packages. map ( \. isNew) , [ false , false , true ] )
239- }
240-
241- // MUT - ingest again
242- try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
243-
244- do { // validate - only new package moves to .ingestion stage
245- let packages = try await Package . query ( on: app. db) . sort ( \. $url) . all ( )
246- XCTAssertEqual ( packages. map ( \. url) , [ " 1 " , " 3 " , " 4 " ] . asGithubUrls)
247- XCTAssertEqual ( packages. map ( \. status) , [ . ok, . ok, . new] )
248- XCTAssertEqual ( packages. map ( \. processingStage) , [ . analysis, . analysis, . ingestion] )
249- XCTAssertEqual ( packages. map ( \. isNew) , [ false , false , true ] )
250- }
251-
252- // MUT - analyze again
253- let lastAnalysis = Date . now
254- try await Analyze . analyze ( client: app. client,
255- database: app. db,
256- mode: . limit( 10 ) )
257-
258- do { // validate - only new package moves to .ingestion stage
259- let packages = try await Package . query ( on: app. db) . sort ( \. $url) . all ( )
260- XCTAssertEqual ( packages. map ( \. url) , [ " 1 " , " 3 " , " 4 " ] . asGithubUrls)
261- XCTAssertEqual ( packages. map ( \. status) , [ . ok, . ok, . ok] )
262- XCTAssertEqual ( packages. map ( \. processingStage) , [ . analysis, . analysis, . analysis] )
263- XCTAssertEqual ( packages. map { $0. updatedAt! > lastAnalysis } , [ false , false , true ] )
264- XCTAssertEqual ( packages. map ( \. isNew) , [ false , false , false ] )
265- }
266-
267227 try await withDependencies {
268- // fast forward our clock by the deadtime interval
269- $0. date . now = . now . addingTimeInterval ( Constants . reIngestionDeadtime )
228+ // Now we've got a new package and a deletion
229+ $0. packageListRepository . fetchPackageList = { @ Sendable _ in [ " 1 " , " 3 " , " 4 " ] . asGithubUrls . asURLs }
270230 } operation: {
271- // MUT - ingest yet again
231+ // MUT - reconcile again
232+ try await reconcile ( client: app. client, database: app. db)
233+
234+ do { // validate - only new package moves to .reconciliation stage
235+ let packages = try await Package . query ( on: app. db) . sort ( \. $url) . all ( )
236+ XCTAssertEqual ( packages. map ( \. url) , [ " 1 " , " 3 " , " 4 " ] . asGithubUrls)
237+ XCTAssertEqual ( packages. map ( \. status) , [ . ok, . ok, . new] )
238+ XCTAssertEqual ( packages. map ( \. processingStage) , [ . analysis, . analysis, . reconciliation] )
239+ XCTAssertEqual ( packages. map ( \. isNew) , [ false , false , true ] )
240+ }
241+
242+ // MUT - ingest again
272243 try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
273-
274- do { // validate - now all three packages should have been updated
244+
245+ do { // validate - only new package moves to .ingestion stage
275246 let packages = try await Package . query ( on: app. db) . sort ( \. $url) . all ( )
276247 XCTAssertEqual ( packages. map ( \. url) , [ " 1 " , " 3 " , " 4 " ] . asGithubUrls)
277- XCTAssertEqual ( packages. map ( \. status) , [ . ok, . ok, . ok ] )
278- XCTAssertEqual ( packages. map ( \. processingStage) , [ . ingestion , . ingestion , . ingestion] )
279- XCTAssertEqual ( packages. map ( \. isNew) , [ false , false , false ] )
248+ XCTAssertEqual ( packages. map ( \. status) , [ . ok, . ok, . new ] )
249+ XCTAssertEqual ( packages. map ( \. processingStage) , [ . analysis , . analysis , . ingestion] )
250+ XCTAssertEqual ( packages. map ( \. isNew) , [ false , false , true ] )
280251 }
281-
282- // MUT - re-run analysis to complete the sequence
252+
253+ // MUT - analyze again
254+ let lastAnalysis = Date . now
283255 try await Analyze . analyze ( client: app. client,
284256 database: app. db,
285257 mode: . limit( 10 ) )
286-
258+
287259 do { // validate - only new package moves to .ingestion stage
288260 let packages = try await Package . query ( on: app. db) . sort ( \. $url) . all ( )
289261 XCTAssertEqual ( packages. map ( \. url) , [ " 1 " , " 3 " , " 4 " ] . asGithubUrls)
290262 XCTAssertEqual ( packages. map ( \. status) , [ . ok, . ok, . ok] )
291263 XCTAssertEqual ( packages. map ( \. processingStage) , [ . analysis, . analysis, . analysis] )
264+ XCTAssertEqual ( packages. map { $0. updatedAt! > lastAnalysis } , [ false , false , true ] )
292265 XCTAssertEqual ( packages. map ( \. isNew) , [ false , false , false ] )
293266 }
294-
295- // at this point we've ensured that retriggering ingestion after the deadtime will
296- // refresh analysis as expected
267+
268+ try await withDependencies {
269+ // fast forward our clock by the deadtime interval
270+ $0. date. now = . now. addingTimeInterval ( Constants . reIngestionDeadtime)
271+ } operation: {
272+ // MUT - ingest yet again
273+ try await ingest ( client: app. client, database: app. db, mode: . limit( 10 ) )
274+
275+ do { // validate - now all three packages should have been updated
276+ let packages = try await Package . query ( on: app. db) . sort ( \. $url) . all ( )
277+ XCTAssertEqual ( packages. map ( \. url) , [ " 1 " , " 3 " , " 4 " ] . asGithubUrls)
278+ XCTAssertEqual ( packages. map ( \. status) , [ . ok, . ok, . ok] )
279+ XCTAssertEqual ( packages. map ( \. processingStage) , [ . ingestion, . ingestion, . ingestion] )
280+ XCTAssertEqual ( packages. map ( \. isNew) , [ false , false , false ] )
281+ }
282+
283+ // MUT - re-run analysis to complete the sequence
284+ try await Analyze . analyze ( client: app. client,
285+ database: app. db,
286+ mode: . limit( 10 ) )
287+
288+ do { // validate - only new package moves to .ingestion stage
289+ let packages = try await Package . query ( on: app. db) . sort ( \. $url) . all ( )
290+ XCTAssertEqual ( packages. map ( \. url) , [ " 1 " , " 3 " , " 4 " ] . asGithubUrls)
291+ XCTAssertEqual ( packages. map ( \. status) , [ . ok, . ok, . ok] )
292+ XCTAssertEqual ( packages. map ( \. processingStage) , [ . analysis, . analysis, . analysis] )
293+ XCTAssertEqual ( packages. map ( \. isNew) , [ false , false , false ] )
294+ }
295+
296+ // at this point we've ensured that retriggering ingestion after the deadtime will
297+ // refresh analysis as expected
298+ }
297299 }
298300 }
299301 }
0 commit comments