-
Notifications
You must be signed in to change notification settings - Fork 727
fix: skip onboarding when insights project was soft-deleted (CM-1138) #4568
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
Open
ulemons
wants to merge
3
commits into
main
Choose a base branch
from
fix/CM-1138-skip-onboarding-soft-deleted-insights-projects
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions
2
backend/src/database/migrations/V1788516039__skip-reason-to-project-catalog.sql
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,2 @@ | ||
| ALTER TABLE "projectCatalog" | ||
| ADD COLUMN IF NOT EXISTS "skipReason" TEXT; |
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
16 changes: 16 additions & 0 deletions
16
services/apps/automatic_onboarding_worker/src/activities/insightsProjectSkip.test.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,16 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { buildInsightsProjectSkipReason } from './insightsProjectSkip' | ||
|
|
||
| describe('buildInsightsProjectSkipReason', () => { | ||
| it('normalizes the project slug and includes the deletion date', () => { | ||
| const reason = buildInsightsProjectSkipReason( | ||
| 'nonlf_gerritcodereview-gerrit', | ||
| '2026-04-10T00:00:00.000Z', | ||
| ) | ||
|
|
||
| expect(reason).toBe( | ||
| "Insights project 'nonlf-gerritcodereview-gerrit' was deleted on 2026-04-10T00:00:00.000Z; onboarding skipped for manual review", | ||
| ) | ||
| }) | ||
| }) |
8 changes: 8 additions & 0 deletions
8
services/apps/automatic_onboarding_worker/src/activities/insightsProjectSkip.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,8 @@ | ||
| import { deriveProjectSlug } from '../onboarder/onboarder' | ||
|
|
||
| // A soft-deleted insightsProjects row still owns its slug (the unique index can't be made | ||
| // partial on deletedAt: three FKs reference it), so segment creation would 500 on it. | ||
| export function buildInsightsProjectSkipReason(projectSlug: string, deletedAt: string): string { | ||
| const slug = deriveProjectSlug(projectSlug) | ||
| return `Insights project '${slug}' was deleted on ${deletedAt}; onboarding skipped for manual review` | ||
| } |
27 changes: 27 additions & 0 deletions
27
services/apps/automatic_onboarding_worker/src/onboarder/onboarder.test.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,27 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { readErrorBody } from './onboarder' | ||
|
|
||
| describe('readErrorBody', () => { | ||
| it('returns the response body text', async () => { | ||
| const response = new Response('{"error":"insightsProjects slug already exists"}') | ||
|
|
||
| expect(await readErrorBody(response)).toBe('{"error":"insightsProjects slug already exists"}') | ||
| }) | ||
|
|
||
| it('truncates a body longer than 500 characters', async () => { | ||
| const response = new Response('a'.repeat(600)) | ||
|
|
||
| const body = await readErrorBody(response) | ||
|
|
||
| expect(body).toBe(`${'a'.repeat(500)}…`) | ||
| }) | ||
|
|
||
| it('returns an empty string when the body cannot be read', async () => { | ||
| const response = new Response(null) | ||
| // Consuming the body once locks the stream, so a second read fails. | ||
| await response.text() | ||
|
|
||
| expect(await readErrorBody(response)).toBe('') | ||
| }) | ||
| }) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| export interface IOnboardProjectsInput { | ||
| batchSize?: number | ||
| } | ||
|
|
||
| export type OnboardAndUpdateProjectOutcome = | ||
| | 'onboarded' | ||
| | 'skipped' | ||
| | 'already-onboarded' | ||
| | 'catalog-changed' |
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
55 changes: 55 additions & 0 deletions
55
services/libs/data-access-layer/src/collections/index.test.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,55 @@ | ||
| import { test as base, describe, expect } from 'vitest' | ||
|
|
||
| import { withQx } from '@crowd/test-kit/db' | ||
|
|
||
| import { | ||
| InsightsProjectField, | ||
| createInsightsProject, | ||
| deleteInsightsProject, | ||
| findInsightsProjectBySlugIncludingDeleted, | ||
| } from './index' | ||
|
|
||
| const test = withQx(base) | ||
|
|
||
| describe('findInsightsProjectBySlugIncludingDeleted', () => { | ||
| test('finds a soft-deleted row by slug, with deletedAt set', async ({ qx }) => { | ||
| const created = await createInsightsProject(qx, { | ||
| name: 'Gerrit', | ||
| slug: 'gerritcodereview-gerrit', | ||
| isLF: false, | ||
| }) | ||
| await deleteInsightsProject(qx, created.id) | ||
|
|
||
| const found = await findInsightsProjectBySlugIncludingDeleted(qx, 'gerritcodereview-gerrit', [ | ||
| InsightsProjectField.ID, | ||
| InsightsProjectField.DELETED_AT, | ||
| ]) | ||
|
|
||
| expect(found?.id).toBe(created.id) | ||
| expect(found?.deletedAt).not.toBeNull() | ||
| }) | ||
|
|
||
| test('finds a live row by slug, with deletedAt null', async ({ qx }) => { | ||
| const created = await createInsightsProject(qx, { | ||
| name: 'Kubernetes', | ||
| slug: 'kubernetes-kubernetes', | ||
| isLF: true, | ||
| }) | ||
|
|
||
| const found = await findInsightsProjectBySlugIncludingDeleted(qx, 'kubernetes-kubernetes', [ | ||
| InsightsProjectField.ID, | ||
| InsightsProjectField.DELETED_AT, | ||
| ]) | ||
|
|
||
| expect(found?.id).toBe(created.id) | ||
| expect(found?.deletedAt).toBeNull() | ||
| }) | ||
|
|
||
| test('returns null when no row has the slug', async ({ qx }) => { | ||
| const found = await findInsightsProjectBySlugIncludingDeleted(qx, 'does-not-exist', [ | ||
| InsightsProjectField.ID, | ||
| ]) | ||
|
|
||
| expect(found).toBeNull() | ||
| }) | ||
| }) |
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
73 changes: 73 additions & 0 deletions
73
services/libs/data-access-layer/src/project-catalog/projectCatalog.test.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,73 @@ | ||
| import { test as base, describe, expect } from 'vitest' | ||
|
|
||
| import { withQx } from '@crowd/test-kit/db' | ||
|
|
||
| import { | ||
| findProjectCatalogById, | ||
| insertProjectCatalog, | ||
| markProjectCatalogOnboardingSkipped, | ||
| updateProjectCatalog, | ||
| } from './projectCatalog' | ||
|
|
||
| const test = withQx(base) | ||
|
|
||
| function catalogRow(overrides: Partial<Parameters<typeof insertProjectCatalog>[1]> = {}) { | ||
| return { | ||
| projectSlug: 'gerritcodereview-gerrit', | ||
| repoName: 'gerrit', | ||
| repoUrl: 'https://github.com/gerritcodereview/gerrit', | ||
| action: 'onboard' as const, | ||
| ...overrides, | ||
| } | ||
| } | ||
|
|
||
| describe('markProjectCatalogOnboardingSkipped', () => { | ||
| test('transitions a pending row to skip with the reason, and clears a prior onboarding error', async ({ | ||
| qx, | ||
| }) => { | ||
| const inserted = await insertProjectCatalog(qx, catalogRow()) | ||
| await updateProjectCatalog(qx, inserted.id, { | ||
| onboardingError: 'Segment creation returned HTTP 500: Internal Server Error', | ||
| }) | ||
|
|
||
| const updatedRows = await markProjectCatalogOnboardingSkipped( | ||
| qx, | ||
| inserted.id, | ||
| "Insights project 'gerritcodereview-gerrit' was deleted on 2026-04-10; onboarding skipped for manual review", | ||
| ) | ||
|
|
||
| const row = await findProjectCatalogById(qx, inserted.id) | ||
| expect(updatedRows).toBe(1) | ||
| expect(row?.action).toBe('skip') | ||
| expect(row?.skipReason).toBe( | ||
| "Insights project 'gerritcodereview-gerrit' was deleted on 2026-04-10; onboarding skipped for manual review", | ||
| ) | ||
| expect(row?.onboardingError).toBeNull() | ||
| }) | ||
|
|
||
| test('does not touch a row whose action is no longer onboard', async ({ qx }) => { | ||
| const inserted = await insertProjectCatalog(qx, catalogRow({ action: 'error' })) | ||
|
|
||
| const updatedRows = await markProjectCatalogOnboardingSkipped(qx, inserted.id, 'some reason') | ||
|
|
||
| const row = await findProjectCatalogById(qx, inserted.id) | ||
| expect(updatedRows).toBe(0) | ||
| expect(row?.action).toBe('error') | ||
| expect(row?.skipReason).toBeNull() | ||
| }) | ||
|
|
||
| test('does not touch a row already onboarded', async ({ qx }) => { | ||
| const inserted = await insertProjectCatalog(qx, catalogRow()) | ||
| await updateProjectCatalog(qx, inserted.id, { | ||
| action: 'onboarded', | ||
| onboardedAt: new Date().toISOString(), | ||
| }) | ||
|
|
||
| const updatedRows = await markProjectCatalogOnboardingSkipped(qx, inserted.id, 'some reason') | ||
|
|
||
| const row = await findProjectCatalogById(qx, inserted.id) | ||
| expect(updatedRows).toBe(0) | ||
| expect(row?.action).toBe('onboarded') | ||
| expect(row?.skipReason).toBeNull() | ||
| }) | ||
| }) |
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.