Skip to content

Commit 5332c58

Browse files
authored
Merge pull request #394 from shreyansh-chandel/mismatch-threshold-fix
added fix for mismatch threshold
2 parents 6312523 + 0c9b202 commit 5332c58

File tree

2 files changed

+45
-29
lines changed

2 files changed

+45
-29
lines changed

src/lib/httpClient.ts

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -375,51 +375,66 @@ export default class httpClient {
375375
}, ctx.log)
376376
}
377377

378-
processSnapshotCaps(ctx: Context, snapshot: ProcessedSnapshot, snapshotUuid: string, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false) {
378+
processSnapshotCaps(ctx: Context, snapshot: ProcessedSnapshot, snapshotUuid: string, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false, approvalThreshold: number| undefined, rejectionThreshold: number| undefined) {
379+
const requestData: any = {
380+
name: snapshot.name,
381+
url: snapshot.url,
382+
snapshotUuid: snapshotUuid,
383+
variantCount: variantCount,
384+
test: {
385+
type: ctx.testType,
386+
source: 'cli'
387+
},
388+
doRemoteDiscovery: snapshot.options.doRemoteDiscovery,
389+
discoveryErrors: discoveryErrors,
390+
sync: sync
391+
}
392+
if (approvalThreshold !== undefined) {
393+
requestData.approvalThreshold = approvalThreshold;
394+
}
395+
if (rejectionThreshold !== undefined) {
396+
requestData.rejectionThreshold = rejectionThreshold;
397+
}
379398
return this.request({
380399
url: `/build/${capsBuildId}/snapshot`,
381400
method: 'POST',
382401
headers: {
383402
'Content-Type': 'application/json',
384403
projectToken: capsProjectToken !== '' ? capsProjectToken : this.projectToken
385404
},
386-
data: {
387-
name: snapshot.name,
388-
url: snapshot.url,
389-
snapshotUuid: snapshotUuid,
390-
variantCount: variantCount,
391-
test: {
392-
type: ctx.testType,
393-
source: 'cli'
394-
},
395-
doRemoteDiscovery: snapshot.options.doRemoteDiscovery,
396-
discoveryErrors: discoveryErrors,
397-
sync: sync
398-
}
405+
data: requestData
399406
}, ctx.log)
400407
}
401408

402-
uploadSnapshotForCaps(ctx: Context, snapshot: ProcessedSnapshot, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false) {
409+
uploadSnapshotForCaps(ctx: Context, snapshot: ProcessedSnapshot, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false, approvalThreshold: number| undefined, rejectionThreshold: number| undefined) {
403410
// Use capsBuildId if provided, otherwise fallback to ctx.build.id
404411
const buildId = capsBuildId !== '' ? capsBuildId : ctx.build.id;
405-
412+
413+
const requestData: any = {
414+
snapshot,
415+
test: {
416+
type: ctx.testType,
417+
source: 'cli'
418+
},
419+
discoveryErrors: discoveryErrors,
420+
variantCount: variantCount,
421+
sync: sync
422+
}
423+
if (approvalThreshold !== undefined) {
424+
requestData.approvalThreshold = approvalThreshold;
425+
}
426+
if (rejectionThreshold !== undefined) {
427+
requestData.rejectionThreshold = rejectionThreshold;
428+
}
429+
406430
return this.request({
407431
url: `/builds/${buildId}/snapshot`,
408432
method: 'POST',
409433
headers: {
410434
'Content-Type': 'application/json',
411435
projectToken: capsProjectToken !== '' ? capsProjectToken : this.projectToken // Use capsProjectToken dynamically
412436
},
413-
data: {
414-
snapshot,
415-
test: {
416-
type: ctx.testType,
417-
source: 'cli'
418-
},
419-
discoveryErrors: discoveryErrors,
420-
variantCount: variantCount,
421-
sync: sync
422-
}
437+
data: requestData
423438
}, ctx.log);
424439
}
425440

src/lib/snapshotQueue.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,10 @@ export default class Queue {
360360
}
361361

362362

363-
364363
if (useCapsBuildId) {
365364
this.ctx.log.info(`Using cached buildId: ${capsBuildId}`);
365+
let approvalThreshold = snapshot?.options?.approvalThreshold || this.ctx.config.approvalThreshold;
366+
let rejectionThreshold = snapshot?.options?.rejectionThreshold || this.ctx.config.rejectionThreshold;
366367
if (useKafkaFlowCaps) {
367368
let snapshotUuid = uuidv4();
368369
if (snapshot?.options?.contextId && this.ctx.contextToSnapshotMap?.has(snapshot.options.contextId)) {
@@ -378,9 +379,9 @@ export default class Queue {
378379
this.ctx.log.debug(`Uploading dom to S3 for snapshot using LSRS`);
379380
await this.ctx.client.sendDomToLSRSForCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken);
380381
}
381-
await this.ctx.client.processSnapshotCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync);
382+
await this.ctx.client.processSnapshotCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync, approvalThreshold, rejectionThreshold);
382383
} else {
383-
await this.ctx.client.uploadSnapshotForCaps(this.ctx, processedSnapshot, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync);
384+
await this.ctx.client.uploadSnapshotForCaps(this.ctx, processedSnapshot, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync, approvalThreshold, rejectionThreshold);
384385
}
385386

386387
// Increment snapshot count for the specific buildId

0 commit comments

Comments
 (0)