codeant-ai-for-open-source[bot] commented on code in PR #41550: URL: https://github.com/apache/superset/pull/41550#discussion_r3691338538
########## superset-frontend/playwright/tests/recently-archived/recently-archived.spec.ts: ########## @@ -0,0 +1,223 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * End-to-end coverage for the Archive (Recently-Archived) view. + * + * Requires the running instance to have the SOFT_DELETE feature flag enabled. + * The flag is off by default everywhere โ including the docker dev stack โ so + * these specs skip unless the instance opts in; in CI that is the dedicated + * "Soft-delete Tests" step in superset-e2e.yml, which boots its server with + * SUPERSET_FEATURE_SOFT_DELETE=true. Each test creates a disposable object via + * the authenticated REST API, soft-deletes it, then drives the real UI to + * restore it and asserts โ via the API โ that it is live again. + */ +import { test, expect, Page } from '@playwright/test'; +import { apiGet, apiPost } from '../../helpers/api/requests'; +import { extractIdFromResponse } from '../../helpers/api/assertions'; +import { + apiPostChart, + apiGetChart, + apiDeleteChart, +} from '../../helpers/api/chart'; +import { + apiPostDashboard, + apiGetDashboard, + apiDeleteDashboard, +} from '../../helpers/api/dashboard'; +import { + createTestVirtualDataset, + apiGetDataset, + apiDeleteDataset, +} from '../../helpers/api/dataset'; +import { skipUnlessFeatureEnabled } from '../../helpers/featureFlags'; + +test.beforeEach(async ({ page }) => { + await skipUnlessFeatureEnabled(page, 'SOFT_DELETE'); +}); + +interface TypeConfig { + key: string; + label: string; + create: (page: Page, name: string) => Promise<number>; + softDelete: (page: Page, id: number) => Promise<{ ok: () => boolean }>; + status: (page: Page, id: number) => Promise<number>; +} + +async function anyDatasetId(page: Page): Promise<number> { + const res = await apiGet(page, 'api/v1/dataset/?q=(page_size:1)'); + const body = await res.json(); + return body.result[0].id; +} + +const TYPES: TypeConfig[] = [ + { + key: 'dashboard', + label: 'Dashboard', + create: async (page, name) => + extractIdFromResponse( + await apiPostDashboard(page, { dashboard_title: name }), + ), + softDelete: (page, id) => apiDeleteDashboard(page, id), + status: async (page, id) => (await apiGetDashboard(page, id)).status(), + }, + { + key: 'chart', + label: 'Chart', + create: async (page, name) => { + const datasourceId = await anyDatasetId(page); + const res = await apiPostChart(page, { + slice_name: name, + datasource_id: datasourceId, + datasource_type: 'table', + viz_type: 'table', + }); + return extractIdFromResponse(res); + }, + softDelete: (page, id) => apiDeleteChart(page, id), + status: async (page, id) => (await apiGetChart(page, id)).status(), + }, + { + key: 'dataset', + label: 'Dataset', + create: async (page, name) => { + const id = await createTestVirtualDataset(page, name); + if (!id) throw new Error('failed to create virtual dataset'); + return id; + }, + softDelete: (page, id) => apiDeleteDataset(page, id), + status: async (page, id) => (await apiGetDataset(page, id)).status(), + }, +]; + +async function openArchive(page: Page, typeLabel: string, name: string) { + await page.goto('archived/'); + await expect(page.getByTestId('archived-list-view')).toBeVisible(); + // Select the object type, then narrow to the unique name. The antd Select's + // value chip overlays the combobox input, so force the click to open it, then + // pick the option from the portal listbox. + await page.getByRole('combobox', { name: 'Type' }).click({ force: true }); + await page.getByRole('option', { name: typeLabel, exact: true }).click(); + const search = page.getByPlaceholder(/type a value/i); + await search.click(); + await search.fill(name); + await search.press('Enter'); +} + +for (const cfg of TYPES) { + test(`restores a soft-deleted ${cfg.key} from the archive`, async ({ + page, + }) => { + const name = `e2e_archive_${cfg.key}_${Date.now()}`; + const id = await cfg.create(page, name); + expect(id, 'created id').toBeTruthy(); + + const del = await cfg.softDelete(page, id); + expect(del.ok(), 'soft-delete should succeed').toBeTruthy(); + + await openArchive(page, cfg.label, name); + + // The archived row is listed; restore it (scope to the named row so any + // unrelated archived residue on the instance can't make the action ambiguous). + const row = page.getByRole('row').filter({ hasText: name }); + await expect(row).toBeVisible(); + await row.getByTestId('archived-row-restore').click(); + + // Success toast, and the object is live again per the API. + await expect( + page.getByText(`${name} restored successfully`, { exact: false }), + ).toBeVisible({ timeout: 15000 }); + await expect.poll(() => cfg.status(page, id)).toBe(200); + + // Cleanup: re-archive so it leaves the normal lists. + await cfg.softDelete(page, id); + }); Review Comment: **Suggestion:** The test only re-archives the created object after all assertions succeed. If the UI navigation, restore request, toast assertion, or API status poll fails, the test exits before this line and leaves the object archived in the shared E2E instance; the purge and stale-row tests have the same cleanup pattern. Wrap creation and assertions in a try/finally and perform best-effort cleanup there so failed tests do not accumulate archived fixtures or affect later runs. [resource leak] <details> <summary><b>Severity Level:</b> Minor ๐งน</summary> ```mdx - โ ๏ธ Failed E2E tests accumulate archived fixtures. - โ ๏ธ Later archive runs query a polluted shared instance. - โ ๏ธ Stale tests can also leave restored dashboards live. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3681da2bbafd4949b8a97611d7bf4add&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=3681da2bbafd4949b8a97611d7bf4add&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent ๐ค </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/playwright/tests/recently-archived/recently-archived.spec.ts **Line:** 149:150 **Comment:** *Resource Leak: The test only re-archives the created object after all assertions succeed. If the UI navigation, restore request, toast assertion, or API status poll fails, the test exits before this line and leaves the object archived in the shared E2E instance; the purge and stale-row tests have the same cleanup pattern. Wrap creation and assertions in a try/finally and perform best-effort cleanup there so failed tests do not accumulate archived fixtures or affect later runs. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41550&comment_hash=0644f3eb8670ff86ea415fcdca1075d9a5d822dec61c2cc754d5bcf4b211b6cf&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41550&comment_hash=0644f3eb8670ff86ea415fcdca1075d9a5d822dec61c2cc754d5bcf4b211b6cf&reaction=dislike'>๐</a> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
