-
Notifications
You must be signed in to change notification settings - Fork 322
[comp] Production Deploy #2994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
[comp] Production Deploy #2994
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
732f262
fix(api): include a default justification on SoA
chasprowebdev 13f468a
fix(app): show default justification at all times on SoA
chasprowebdev 2939178
fix(app): able to edit the justification
chasprowebdev 17d899f
Merge branch 'main' into chas/soa-justification
chasprowebdev 6682be1
fix(app): return a generic default when no family match on SoA
chasprowebdev 4253d45
Merge branch 'chas/soa-justification' of https://github.com/trycompai…
chasprowebdev 090e7bc
Merge branch 'main' into chas/soa-justification
tofikwest 09da0ef
Merge branch 'main' of https://github.com/trycompai/comp into chas/so…
chasprowebdev 35eb9e7
Merge branch 'main' into chas/soa-justification
chasprowebdev b9fd71b
Merge branch 'main' into chas/soa-justification
chasprowebdev 2c33ecc
Merge branch 'main' of https://github.com/trycompai/comp into chas/so…
chasprowebdev 67b4ab9
chore: merge release v3.66.2 back to main [skip ci]
github-actions[bot] 3bec256
Merge branch 'main' of https://github.com/trycompai/comp into chas/so…
chasprowebdev 43fa889
fix(app): fix empty justification issue on SoA
chasprowebdev a5621cb
fix(app): keep SoA justification dialog open when save fails
chasprowebdev 7f564df
fix(api): guarantee non-null SoA justification on YES defaults
chasprowebdev 9d01005
Merge pull request #2921 from trycompai/chas/soa-justification
tofikwest 4e7d57d
fix(people): stop tracking background checks for auditor-only members…
Marfuen 51c3b3d
feat(background-checks): admin cancel/delete/retry (CS-475) (#2993)
Marfuen 3d6e609
feat(background-checks): hourly reconciliation for stuck checks (CS-4…
Marfuen c381397
feat(admin): add Finding Templates management to admin panel
tofikwest d7e2caf
Merge branch 'main' into tofik/finding-templates-admin
tofikwest 612489f
Merge pull request #2997 from trycompai/tofik/finding-templates-admin
tofikwest dcd4b4d
fix(background-checks): move admin actions into the status card foote…
Marfuen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
apps/api/src/background-checks/background-check-identity.client.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { BackgroundCheckIdentityClient } from './background-check-identity.client'; | ||
|
|
||
| describe('BackgroundCheckIdentityClient idempotency key', () => { | ||
| const originalEnv = { ...process.env }; | ||
| const originalFetch = global.fetch; | ||
|
|
||
| beforeEach(() => { | ||
| process.env = { | ||
| ...originalEnv, | ||
| BACKGROUND_CHECK_API_KEY: 'bc_test', | ||
| BACKGROUND_CHECK_API_BASE_URL: 'https://identity.test', | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.env = originalEnv; | ||
| global.fetch = originalFetch; | ||
| }); | ||
|
|
||
| function mockFetchOk() { | ||
| const fetchMock = jest.fn().mockResolvedValue({ | ||
| ok: true, | ||
| text: async () => JSON.stringify({ id: 'check_1', status: 'invited' }), | ||
| }); | ||
| global.fetch = fetchMock as unknown as typeof fetch; | ||
| return fetchMock; | ||
| } | ||
|
|
||
| function keyFrom(fetchMock: jest.Mock): string { | ||
| const init = fetchMock.mock.calls[0][1] as { | ||
| headers: Record<string, string>; | ||
| }; | ||
| return init.headers['Idempotency-Key']; | ||
| } | ||
|
|
||
| const params = { | ||
| organizationId: 'org_1', | ||
| memberId: 'mem_1', | ||
| employeeName: 'Ada', | ||
| employeeEmail: 'ada@example.com', | ||
| requesterEmail: 'admin@example.com', | ||
| }; | ||
|
|
||
| it('forwards the provided idempotency key as the Idempotency-Key header', async () => { | ||
| const fetchMock = mockFetchOk(); | ||
| await new BackgroundCheckIdentityClient().createBackgroundCheck({ | ||
| ...params, | ||
| idempotencyKey: 'comp-background-check:bcr_1', | ||
| }); | ||
| expect(keyFrom(fetchMock)).toBe('comp-background-check:bcr_1'); | ||
| }); | ||
|
|
||
| it('forwards a per-attempt retry idempotency key unchanged', async () => { | ||
| const fetchMock = mockFetchOk(); | ||
| await new BackgroundCheckIdentityClient().createBackgroundCheck({ | ||
| ...params, | ||
| idempotencyKey: 'comp-background-check:bcr_1:2', | ||
| }); | ||
| expect(keyFrom(fetchMock)).toBe('comp-background-check:bcr_1:2'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
apps/api/src/background-checks/background-check-retry.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| import { BadRequestException, NotFoundException } from '@nestjs/common'; | ||
| import { BackgroundCheckStatus, db, Prisma } from '@db'; | ||
| import type { BackgroundCheckIdentityClient } from './background-check-identity.client'; | ||
|
|
||
| type GetForMemberFn = (params: { | ||
| organizationId: string; | ||
| memberId: string; | ||
| }) => Promise<{ | ||
| id: string; | ||
| rerunCount: number; | ||
| employeeName: string; | ||
| employeeEmail: string; | ||
| status: BackgroundCheckStatus; | ||
| } | null>; | ||
|
|
||
| export function assertTransitionAllowed( | ||
| action: 'cancel' | 'retry', | ||
| status: BackgroundCheckStatus, | ||
| ): void { | ||
| const allowed: Record<'cancel' | 'retry', BackgroundCheckStatus[]> = { | ||
| cancel: [ | ||
| BackgroundCheckStatus.invited, | ||
| BackgroundCheckStatus.in_progress, | ||
| BackgroundCheckStatus.in_review, | ||
| ], | ||
| retry: [BackgroundCheckStatus.failed, BackgroundCheckStatus.cancelled], | ||
| }; | ||
| if (!allowed[action].includes(status)) { | ||
| throw new BadRequestException( | ||
| `Cannot ${action} a background check in '${status}' status.`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export async function cancelForMember({ | ||
| organizationId, | ||
| memberId, | ||
| getForMember, | ||
| }: { | ||
| organizationId: string; | ||
| memberId: string; | ||
| getForMember: GetForMemberFn; | ||
| }) { | ||
| const existing = await getForMember({ organizationId, memberId }); | ||
| if (!existing) { | ||
| throw new NotFoundException('Background check not found.'); | ||
| } | ||
| assertTransitionAllowed('cancel', existing.status); | ||
|
|
||
| return db.backgroundCheckRequest.update({ | ||
| where: { organizationId_memberId: { organizationId, memberId } }, | ||
| data: { | ||
| status: BackgroundCheckStatus.cancelled, | ||
| lastSyncedAt: new Date(), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export async function deleteForMember({ | ||
| organizationId, | ||
| memberId, | ||
| getForMember, | ||
| }: { | ||
| organizationId: string; | ||
| memberId: string; | ||
| getForMember: GetForMemberFn; | ||
| }): Promise<{ ok: true }> { | ||
| const existing = await getForMember({ organizationId, memberId }); | ||
| if (!existing) { | ||
| throw new NotFoundException('Background check not found.'); | ||
| } | ||
| // Hard delete; webhookEvents cascade via the FK. Frees the | ||
| // @@unique([organizationId, memberId]) constraint for a fresh request. | ||
| await db.backgroundCheckRequest.delete({ | ||
| where: { organizationId_memberId: { organizationId, memberId } }, | ||
| }); | ||
| return { ok: true }; | ||
| } | ||
|
|
||
| export async function retryForMember({ | ||
| organizationId, | ||
| memberId, | ||
| requesterEmail, | ||
| identityClient, | ||
| getForMember, | ||
| }: { | ||
| organizationId: string; | ||
| memberId: string; | ||
| requesterEmail: string; | ||
| identityClient: BackgroundCheckIdentityClient; | ||
| getForMember: GetForMemberFn; | ||
| }) { | ||
| const existing = await getForMember({ organizationId, memberId }); | ||
| if (!existing) { | ||
| throw new NotFoundException('Background check not found.'); | ||
| } | ||
| assertTransitionAllowed('retry', existing.status); | ||
|
|
||
| const attempt = existing.rerunCount + 1; | ||
| const where = { organizationId_memberId: { organizationId, memberId } }; | ||
|
|
||
| // Free retry: no charge. Create a fresh Identity check first (varied | ||
| // idempotency key) so a late webhook from the prior check cannot match | ||
| // the row after we swap in the new id. | ||
| let identityResult; | ||
| try { | ||
| identityResult = await identityClient.createBackgroundCheck({ | ||
| organizationId, | ||
| memberId, | ||
| employeeName: existing.employeeName, | ||
| employeeEmail: existing.employeeEmail, | ||
| requesterEmail, | ||
| // Per-record, per-attempt key so each retry creates a fresh vendor | ||
| // check rather than colliding with a prior attempt's idempotency key. | ||
| idempotencyKey: `comp-background-check:${existing.id}:${attempt}`, | ||
| }); | ||
| } catch (error) { | ||
| // Restore the prior status (retry is only allowed from 'failed' or | ||
| // 'cancelled'). Forcing 'failed' here would strip a cancelled check of the | ||
| // webhook terminal-guard and let a late vendor webhook resurrect it. | ||
| await db.backgroundCheckRequest.update({ | ||
| where, | ||
| data: { status: existing.status, lastSyncedAt: new Date() }, | ||
| }); | ||
| throw error; | ||
| } | ||
|
|
||
| return db.backgroundCheckRequest.update({ | ||
| where, | ||
| data: { | ||
| identityBackgroundCheckId: identityResult.id, | ||
| candidateUrl: identityResult.candidateUrl ?? null, | ||
| status: identityResult.status, | ||
| rerunCount: attempt, | ||
| identityStatus: null, | ||
| employmentStatus: null, | ||
| referenceStatus: null, | ||
| rightToWorkStatus: null, | ||
| adjudicationStatus: null, | ||
| reportSnapshot: Prisma.JsonNull, | ||
| reportSyncedAt: null, | ||
| lastSyncedAt: new Date(), | ||
| }, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The retry error handler performs a stale status write that can clobber a successful concurrent retry.
Prompt for AI agents