Skip to content

fixed: Replaced Scans alert() failures with toast feedback - #626

Closed
pranavv2707 wants to merge 874 commits into
utksh1:mainfrom
pranavv2707:main
Closed

fixed: Replaced Scans alert() failures with toast feedback#626
pranavv2707 wants to merge 874 commits into
utksh1:mainfrom
pranavv2707:main

Conversation

@pranavv2707

@pranavv2707 pranavv2707 commented Jun 6, 2026

Copy link
Copy Markdown

Description

Replaced alert() dialogs in the Scans page destructive-action failure paths with accessible toast notifications using the existing ToastContext. Also adds test coverage for all three failure paths:

  • Delete single task — clicking "Delete_Record" on one scan and confirming
  • Bulk delete — selecting multiple scans and clicking "Prune_Selected_Records"
  • Clear all — clicking "Purge_All_Records" which wipes everything

Related Issues

Closes issue number #469

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

Unit tests — 5 new tests in Scans.failures.test.tsx:

  • deleteTask failure shows error toast and keeps task in list
  • bulkDeleteTasks failure shows error toast and keeps tasks in list
  • clearAllTasks failure shows error toast

Checklist

  • My code follows the code style of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.

Issues Fixed

  1. The Scans page was using browser alert() dialogs for delete and clear-history failure paths, which block the page, cannot be styled, and are inaccessible to screen readers.
    • Replaced all alert() calls in handleTaskDelete, handleClearAll, and handleBulkDelete failure paths with addToast() from the existing ToastContext.
    • Error toasts use role="alert" so screen readers announce them automatically.
    • Console logging kept for diagnostics.

Tests Added

  • frontend/testing/unit/pages/Scans.failures.test.tsx — 5 new tests covering:
    • deleteTask failure shows error toast and keeps task in list
    • bulkDeleteTasks failure shows error toast and keeps tasks in list
    • clearAllTasks failure shows error toast

How to Test

  1. Run cd frontend && npm run test — all 5 new tests should pass.
  2. Run npm run build — build should complete with no errors.
  3. Optionally, run the frontend locally, open the Scans page, and trigger a delete while the backend is stopped — an error toast should appear instead of a browser alert popup.

Comments:

The npm audit failure is a pre-existing vulnerability on upstream main, not introduced by this PR.
This change only modifies frontend/src/pages/Scans.tsx and frontend/testing/unit/pages/Scans.failures.test.tsx.
I have sought assistance from LLMs and gituhub copilot to understand the codebase and guide implementation, as disclosed per the contributing guidelines.

I apologise for the large number of commits.

Screenshots for checks

Screenshot 2026-06-06 at 11 06 34

Description: The screenshot shows the passing of all 5 tests.

Screenshot 2026-06-06 at 11 07 46

Description: The screenshot shows the successful building after the running of the tests, generating no warnings.

@utksh1 utksh1 added level:beginner 20 pts difficulty label for small beginner-friendly PRs type:bug Bug fix work category bonus label type:testing Testing work category bonus label area:frontend Frontend React/UI work labels Jun 7, 2026

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toast replacement is a useful direction, but this head is behind and required checks are failing. Please rebase on latest main/current CI baseline and fix frontend-checks/backend-lint before requesting review again.

@pranavv2707
pranavv2707 force-pushed the main branch 2 times, most recently from a6a39cc to fb56811 Compare June 7, 2026 17:12

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the latest push. This still has broad Scans/Workflows/phase test churn, no-final-newline changes, and production formatting churn around the toast change. Please narrow the PR to replacing alert failures with toast feedback, remove unrelated test rewrites, and rerun frontend checks.

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecking after the latest commit: this is still blocked.

The frontend-checks job is failing on the current head. Please fix CI and keep the patch focused on replacing Scans alert failures with toast handling; unrelated Scans/Workflows churn should stay out of this PR.

@pranavv2707

Copy link
Copy Markdown
Author

Rechecking after the latest commit: this is still blocked.

The frontend-checks job is failing on the current head. Please fix CI and keep the patch focused on replacing Scans alert failures with toast handling; unrelated Scans/Workflows churn should stay out of this PR.

Hi @utksh1
The initial frontend-checks failure is because of the npm audit issue and it is present in upstream too.

The ToastContext mock additions to Scans.test.tsx, ScansPhases.test.tsx, and Scans.polling.test.tsx are necessary because adding useToast() to Scans.tsx causes those tests to fail and those are minimal 5-line additions with no other changes to those files.

Please do let know if i may remove all of them and commit just the scans alert page or any other alternative approach.

@utksh1 utksh1 closed this Jun 24, 2026
@utksh1 utksh1 added the gssoc:invalid Admin validation: invalid for GSSoC scoring label Jun 24, 2026
@utksh1 utksh1 reopened this Jun 25, 2026
@utksh1 utksh1 removed the gssoc:invalid Admin validation: invalid for GSSoC scoring label Jun 25, 2026
@utksh1 utksh1 closed this Jun 25, 2026
@utksh1 utksh1 reopened this Jun 25, 2026
opencode-bot and others added 14 commits June 25, 2026 14:19
…mit inside transactions

The execute() method was auto-committing after every query, which broke
the transaction semantics when used inside async with db.transaction()
blocks. The first execute() call would commit the BEGIN, and subsequent
operations would run outside the transaction.

- Add _in_transaction flag (initially False)
- begin() sets _in_transaction = True
- commit() and rollback() reset _in_transaction = False
- execute() only auto-commits when _in_transaction is False

This was described in the original commit message for efa59f0 but
the database.py changes were not included.
…icate anyio_backend fixture

- Revert validation.py hostname regex changes (out of PR scope)
- Revert ci.yml backend-tests condition rewrite (out of PR scope, use original)
- Remove duplicate anyio_backend fixture in conftest.py to fix event loop issues
replace_asset_services in platform_resources.py calls db.transaction(),
but _upsert_findings_and_report and _upsert_findings_and_report_from_scanner
already wrap the call in an outer transaction, causing the SQLite error
'cannot start a transaction within a transaction'.

fix: transaction()/begin()/commit()/rollback() all check _in_transaction
and become no-ops when already inside a transaction, allowing safe nesting.
…tandard_scanner

This call was added as part of the PR scope but does not exist on main.
ScannerBase._execute_command already handles this validation for modular
scanners. For standard scanners, command args are plugin-provided module
names (e.g. 'windows.pslist.PsList') that falsely trigger the hostname
regex and cause 'Hostname did not resolve' errors, breaking the
volatility integration test.
On main, _execute_standard_scanner does not accept safe_mode.
This param was added as part of the scope-creep validation call
which has now been removed. Restoring the original signature.
…ksh1#1328)

wpscan is a Ruby gem, not a standalone binary, so the availability check
  reports it unavailable without explaining the prerequisites. Expand long_description, populate dependencies.system_packages with ruby/rubygems, clarify the
  API-token help, and refresh the checksum.

Closes utksh1#842

Co-authored-by: Utkarsh Singh <[email protected]>
…ask status (utksh1#1312)

* fix(cancel_task): add status guard to prevent overwriting completed task status

Add AND status = ? WHERE clause to the cancel_task() UPDATE statement
so that only RUNNING tasks can be transitioned to CANCELLED. Without
this guard, a task that completes normally during the termination grace
period (up to 5s) would have its COMPLETED status silently overwritten
to CANCELLED, corrupting scan history.

Fixes utksh1#1272

* fix: add safe_mode argument to test_execute_standard_scanner call

* fix(ci): set asyncio_default_fixture_loop_scope to prevent Event loop is closed error

---------

Co-authored-by: opencode-bot <[email protected]>
Co-authored-by: Utkarsh Singh <[email protected]>
trivikramkalagi91-commits and others added 22 commits July 6, 2026 11:36
Closes utksh1#1623

The audit log only recorded scans that passed consent and safe-mode
validation and began executing. Attempts rejected by the consent gate
or blocked by safe-mode target validation left no entry, so an
administrator could not reconstruct misuse attempts after the fact.

Add audit log entries at the two points the issue describes:

- scan_blocked_consent: logged when a request is rejected because
  consent was not granted.
- scan_blocked_target_validation: logged when safe-mode target
  validation rejects the target (for example, a public IP or a
  domain resolving outside the allowed private ranges).

Both entries record the plugin ID and are queryable via the existing
audit_log table (event_type, plugin_id, context_json), consistent
with the report_downloaded audit entries already in this codebase.

Testing:
- Added testing/backend/integration/test_scan_block_audit_log.py
  covering: consent rejection creates an entry, safe-mode target
  rejection creates an entry with target/safe_mode/reason in context,
  and a successful scan start creates neither entry.
- Full backend unit suite: 2210 passed (6 pre-existing failures in
  test_parser_sandbox*/test_plugin_validator, confirmed present on
  main before this change, unrelated to routes.py).
- Full backend integration suite: 287 passed, 9 skipped.
- Parser contract tests (all 4 capability groups): passed.
- ruff check backend testing/backend: passed.
- scripts/check-artifacts.sh: passed.

Signed-off-by: Anshul Jain <[email protected]>
The previous run failed on backend-unit due to pre-existing test
flakiness (subprocess sandbox timing tests: test_parser_sandbox.py,
test_parser_sandbox_timeout_cleanup.py, test_plugin_validator.py),
confirmed present intermittently on main itself (3 of the last 4 main
CI runs also failed on backend-unit with the same tests, unrelated to
this PR's changes). Retriggering to get a clean run.

Signed-off-by: Anshul Jain <[email protected]>
…ocked-scans

fix: log blocked and failed scan attempts to the audit trail
…ualizer-deps-1407

fix(frontend): remove exhaustive-deps suppression from Findings virtualizer effect
…pi-client-return-types

fix: tighten API client response types
…rror-handling

test: add ApiKeySetupScreen error-handling tests
…-alerts-with-toast

fix(scans): replace error banner with toast feedback for delete and rescan failures
…out-overlap-906-refactor-v2

refactor(plugins): decompose build_command, load_plugins, and validat…
fix: deduplicate findings across tasks using finding_group_id
…ction-atomicity

fix(atomicity): wrap multi-step finding persistence in DB transactions
…-fallback

fix: replace fail-open with in-memory fallback in rate limiter
@pranavv2707

Copy link
Copy Markdown
Author

Hello @utksh1 ,
I have resolved the merge conflicts after pulling from main and the tests run successfully
Thankss

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The production toast change has already landed, and the remaining diff is useful focused frontend regression coverage with the necessary ToastContext mocks. Please rebase this test-only branch onto current so GitHub can calculate a clean merge; after that, it is ready for merge review.

@utksh1 utksh1 removed the type:bug Bug fix work category bonus label label Jul 24, 2026
@utksh1

utksh1 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Clarification: please rebase this test-only branch onto the current main branch. Once GitHub reports a clean merge state, the focused regression coverage can proceed to merge review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:frontend Frontend React/UI work level:beginner 20 pts difficulty label for small beginner-friendly PRs quality:clean Contributor score x1.2; mentor +5 pts type:testing Testing work category bonus label

Projects

None yet

Development

Successfully merging this pull request may close these issues.