@@ -6,8 +6,6 @@ import { beforeEach, describe, expect, test, vi } from "vitest";
66const mocks = vi . hoisted ( ( ) => ( {
77 connectionFindUniqueOrThrow : vi . fn ( ) ,
88 connectionUpdate : vi . fn ( ) ,
9- connectionSyncJobUpsert : vi . fn ( ) ,
10- connectionSyncJobUpdate : vi . fn ( ) ,
119 compileGithubConfig : vi . fn ( ) ,
1210 loadConfig : vi . fn ( ) ,
1311 syncSearchContexts : vi . fn ( ) ,
@@ -99,36 +97,18 @@ import {
9997import { reportRepositoryDiscoveryIssue } from "./repositoryDiscoveryIssueContext.js" ;
10098import { REPO_PERMISSION_SYNC_WHERE } from "./ee/permissionSyncEligibility.js" ;
10199
102- const transactionClient = {
103- connection : {
104- update : mocks . connectionUpdate ,
105- } ,
106- connectionSyncJob : {
107- upsert : mocks . connectionSyncJobUpsert ,
108- } ,
109- } ;
110- const transaction = vi . fn (
111- ( callback : ( tx : typeof transactionClient ) => Promise < unknown > ) =>
112- callback ( transactionClient ) ,
113- ) ;
114-
115100const db = {
116101 connection : {
117102 findUniqueOrThrow : mocks . connectionFindUniqueOrThrow ,
118103 update : mocks . connectionUpdate ,
119104 } ,
120- connectionSyncJob : {
121- upsert : mocks . connectionSyncJobUpsert ,
122- update : mocks . connectionSyncJobUpdate ,
123- } ,
124105 repo : {
125106 findMany : mocks . repoFindMany ,
126107 upsert : mocks . repoUpsert ,
127108 } ,
128109 repoToConnection : {
129110 deleteMany : mocks . repoToConnectionDeleteMany ,
130111 } ,
131- $transaction : transaction ,
132112} as unknown as PrismaClient ;
133113
134114const jobManager = {
@@ -172,10 +152,10 @@ describe("connectionWorkload", () => {
172152 mocks . syncSearchContexts . mockResolvedValue ( undefined ) ;
173153 } ) ;
174154
175- test ( "declares database-backed lifecycle hooks " , ( ) => {
155+ test ( "only records the latest job when the workload starts " , ( ) => {
176156 expect ( connectionWorkload . onStarted ) . toBeTypeOf ( "function" ) ;
177- expect ( connectionWorkload . onCompleted ) . toBeTypeOf ( "function" ) ;
178- expect ( connectionWorkload . onTerminalFailure ) . toBeTypeOf ( "function" ) ;
157+ expect ( connectionWorkload . onCompleted ) . toBeUndefined ( ) ;
158+ expect ( connectionWorkload . onTerminalFailure ) . toBeUndefined ( ) ;
179159 } ) ;
180160
181161 test ( "uses a distinct execution lock for each connection" , ( ) => {
@@ -204,26 +184,9 @@ describe("connectionWorkload", () => {
204184 expect ( mocks . connectionFindUniqueOrThrow ) . not . toHaveBeenCalled ( ) ;
205185 } ) ;
206186
207- test ( "marks the connection sync job as in progress when started" , async ( ) => {
187+ test ( "records the latest connection sync job ID when started" , async ( ) => {
208188 await connectionWorkload . onStarted ?.( lifecycleContext ) ;
209189
210- expect ( mocks . connectionSyncJobUpsert ) . toHaveBeenCalledWith ( {
211- where : {
212- id : "job-1" ,
213- } ,
214- update : {
215- status : "IN_PROGRESS" ,
216- completedAt : null ,
217- errorMessage : null ,
218- warningMessages : [ ] ,
219- } ,
220- create : {
221- id : "job-1" ,
222- connectionId : 42 ,
223- status : "IN_PROGRESS" ,
224- warningMessages : [ ] ,
225- } ,
226- } ) ;
227190 expect ( mocks . connectionUpdate ) . toHaveBeenCalledWith ( {
228191 where : {
229192 id : 42 ,
@@ -232,42 +195,6 @@ describe("connectionWorkload", () => {
232195 latestSyncJobId : "job-1" ,
233196 } ,
234197 } ) ;
235- expect ( transaction ) . toHaveBeenCalledOnce ( ) ;
236- } ) ;
237-
238- test ( "marks the connection sync job as completed" , async ( ) => {
239- await connectionWorkload . onCompleted ?.( lifecycleContext , {
240- outcome : "SUCCESS" ,
241- } ) ;
242-
243- expect ( mocks . connectionSyncJobUpdate ) . toHaveBeenCalledWith ( {
244- where : {
245- id : "job-1" ,
246- } ,
247- data : {
248- status : "COMPLETED" ,
249- completedAt : expect . any ( Date ) ,
250- errorMessage : null ,
251- } ,
252- } ) ;
253- } ) ;
254-
255- test ( "marks the connection sync job as failed after terminal failure" , async ( ) => {
256- await connectionWorkload . onTerminalFailure ?.(
257- lifecycleContext ,
258- new Error ( "Connection credentials expired" ) ,
259- ) ;
260-
261- expect ( mocks . connectionSyncJobUpdate ) . toHaveBeenCalledWith ( {
262- where : {
263- id : "job-1" ,
264- } ,
265- data : {
266- status : "FAILED" ,
267- completedAt : expect . any ( Date ) ,
268- errorMessage : "Connection credentials expired" ,
269- } ,
270- } ) ;
271198 } ) ;
272199
273200 test ( "orchestrates discovery, persistence, and repo work reconciliation" , async ( ) => {
0 commit comments