Skip to content

Fix recent scans view button and keep scan results when refreshing or bookmarking #308 - #326

Open
ValayaDase wants to merge 4 commits into
ionfwsrijan:mainfrom
ValayaDase:recent-scan
Open

Fix recent scans view button and keep scan results when refreshing or bookmarking #308#326
ValayaDase wants to merge 4 commits into
ionfwsrijan:mainfrom
ValayaDase:recent-scan

Conversation

@ValayaDase

@ValayaDase ValayaDase commented Jul 15, 2026

Copy link
Copy Markdown

Before opening: make sure there is an issue tracking this work, and link it below. PRs without a linked issue may be closed without review.

Linked issue

Closes #308

What this PR does

Adds a SQLite persistence layer for scan findings. Previously, findings were stored only in memory and were lost after server restarts. This PR introduces SQLite integration, a findings schema, CRUD helper functions, and persistent storage keyed by job_id.

Type of change

  • Bug fix
  • New feature
  • ML model / training pipeline
  • Refactor (no behaviour change)
  • Documentation
  • Tests only

ML tier (if applicable)

  • Tier 1 — Triage
  • Tier 2 — Predictive
  • Tier 3 — Autonomous
  • Not ML-related

Stack affected

  • Backend
  • Frontend
  • Both

Changes

Backend

  • backend/app/main.py:
    • Modified the /jobs/{job_id}/findings endpoint to return the project_name key in the response payload.

Frontend

  • RecentScans.tsx:
    • Updated navigation links to pass the job_id query parameter (e.g. /findings?job_id=XYZ).
    • Disabled the "View" button and greyed out the row for failed, pending, or running scans.
  • findings.tsx:
    • Programmed the page to load scan results directly from the job_id query parameter in the web address.
    • Falls back to your browser's last scan if no scan ID is in the web address, automatically adding it to the link.
  • useRecentJobs.ts:
    • Redirects to /findings?job_id=XYZ when a scan finishes successfully.
  • verify.tsx:
    • Updated the "View All Findings" link to include the scan ID query parameter.

New dependencies

  • None

Database / schema changes

  • None

Testing

How did you test this?

  1. Ran all 108 backend Python tests to ensure no backend endpoints were broken:
    $env:OPENBLAS_NUM_THREADS="1"
    .venv\Scripts\python -m pytest tests

Copilot AI review requested due to automatic review settings July 15, 2026 19:39
@github-actions

Copy link
Copy Markdown

🎉 Thank you @ValayaDase for submitting a Pull Request!

We're excited to review your contribution.

Before Review

✅ Ensure all CI checks pass
✅ Complete the PR template
✅ Link the related issue

Want faster reviews and contributor support?

Join our Discord community:

🔗 https://discord.gg/FcXuyw2Rs

Maintainers and mentors are active there and can help resolve blockers quickly.

Happy Contributing! 🚀

@github-actions

Copy link
Copy Markdown

⚠️ Automated Check: This PR does not strictly follow the required template. Please ensure you have not deleted any checkboxes or mandatory headings, and that you have written explanations under What this PR does and How did you test this?.

Correct PR Template

Please copy and paste the raw template below into your PR description and fill it out:

> **Before opening:** make sure there is an issue tracking this work, and link it below. PRs without a linked issue may be closed without review.

## Linked issue

Closes #

## What this PR does



## Type of change

- [ ] Bug fix
- [ ] New feature
- [ ] ML model / training pipeline
- [ ] Refactor (no behaviour change)
- [ ] Documentation
- [ ] Tests only

## ML tier (if applicable)

- [ ] Tier 1 — Triage
- [ ] Tier 2 — Predictive
- [ ] Tier 3 — Autonomous
- [ ] Not ML-related

## Stack affected

- [ ] Backend
- [ ] Frontend
- [ ] Both

---

## Changes

### Backend



-

### Frontend



-

### New dependencies



-

### Database / schema changes



-

---

## Testing

**How did you test this?**



**Checklist**

- [ ] Tested locally end-to-end (upload ZIP or GitHub URL → scan → findings returned correctly)
- [ ] New ML model falls back gracefully when model file is absent
- [ ] No new `console.error` or unhandled Python exceptions introduced
- [ ] Added or updated tests where applicable
- [ ] `requirements.txt` / `package.json` updated if new dependencies added
- [ ] New model files (`.pkl`, `.pt`, etc.) are gitignored, not committed

---

## Anything reviewers should focus on



## Screenshots (if UI changed)

@github-actions github-actions Bot added backend Backend issues bug Something isn't working feature New feature frontend Frontend issues labels Jul 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a paginated GET /jobs API for listing historical scan jobs and updates the frontend to preserve scan context via job_id query parameters so findings remain accessible across refreshes/bookmarks, while also preventing “View” navigation for non-completed scans.

Changes:

  • Added GET /jobs?limit=&offset= backend endpoint (with tests) and documented it in the root API table.
  • Updated frontend navigation to include job_id in findings URLs and disabled “View” for non-completed scans in Recent Scans.
  • Hardened ML predictor imports to gracefully skip ML inference when dependencies aren’t installed; added test-time mocks for heavy ML deps.

Reviewed changes

Copilot reviewed 10 out of 22 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
README.md Documents the new GET /jobs endpoint in the API table.
frontend/src/app/pages/verify.tsx Links to findings with job_id when available.
frontend/src/app/pages/findings.tsx Loads findings based on job_id query param (and persists it via URL/local storage).
frontend/src/app/lib/api.ts Adds listJobs() and (needs) corrected typings for findings responses / type formatting.
frontend/src/app/hooks/useRecentJobs.ts Switches recents to server-backed job list (needs status normalization to avoid UI crash).
frontend/src/app/components/dashboard/RecentScans.tsx Disables row/button navigation for non-completed scans; uses job_id links for completed scans.
backend/tests/test_job_endpoints.py Adds tests for the new /jobs listing endpoint.
backend/tests/conftest.py Mocks heavy ML libraries to keep tests lightweight.
backend/app/ml/fp_predictor.py Makes torch/transformers optional and skips ML inference when unavailable.
backend/app/main.py Adds GET /jobs endpoint and includes project_name in findings response.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +47 to +59
reachability?: {
reachable?: boolean;
reason?: string;
};

features?: Record<string, unknown>;
confidence?: number;
code?: string;
suggested_fix?: string;
references?: string[];
ml_score?: number;
false_positive?: boolean | number | null;
version?: number;
Comment thread frontend/src/app/lib/api.ts Outdated
Comment on lines +104 to +108
export async function getJobFindings(jobId: string): Promise<BackendFinding[]> {
const res = await fetch(`${API_BASE}/jobs/${jobId}/findings`);
if (!res.ok) throw new Error(await res.text());
return (await res.json()) as BackendFinding[];
}
Comment on lines +29 to +52

export function useRecentJobs() {
const navigate = useNavigate();
const [recentJobs, setRecentJobs] = useState<UiJob[]>([]);

const fetchJobs = useCallback(async () => {
try {
const res = await listJobs(10, 0);
const clearedIds = getClearedJobIds();
const filtered = res.jobs
.filter((j) => !clearedIds.includes(j.job_id))
.map((j) => ({
id: j.job_id,
repoName: j.project_name,
status: j.status as UiJobStatus,
timestamp: j.created_at,
duration: "-",
findingsCount: j.finding_count ?? 0,
}));
setRecentJobs(filtered);
} catch (err) {
console.error("Failed to fetch recent jobs:", err);
}
}, []);
Comment thread README.md
| Method | Route | Description |
|---|---|---|
| `GET` | `/health` | Health check |
| `GET` | `/jobs` | List scan jobs (paginated) |

@arpit2006 arpit2006 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fix template and other issue.

@ValayaDase

ValayaDase commented Jul 18, 2026

Copy link
Copy Markdown
Author

Before opening: make sure there is an issue tracking this work, and link it below. PRs without a linked issue may be closed without review.

Linked issue

Closes #308

What this PR does

This PR adds a paginated GET /jobs API endpoint on the backend for listing historical scan jobs and updates the frontend dashboard to preserve the scan context via job_id query parameters (e.g. /findings?job_id=XYZ). This allows findings to remain accessible across page refreshes, bookmarks, and shared links.
It also prevents the "View" button from being clickable on failed/non-completed scans, maps backend statuses safely to prevent StatusPill configuration crashes,

Type of change

  • Bug fix
  • New feature
  • ML model / training pipeline
  • Refactor (no behaviour change)
  • Documentation
  • Tests only

ML tier (if applicable)

  • Tier 1 — Triage
  • Tier 2 — Predictive
  • Tier 3 — Autonomous
  • Not ML-related

Stack affected

  • Backend
  • Frontend
  • Both

Changes

Backend

  • backend/app/main.py:
    • Implemented the GET /jobs listing endpoint (paginated and ordered by created_at DESC).
    • Modified the GET /jobs/{job_id}/findings response to return the repository's project_name.
  • backend/README.md:
    • Documented all backend endpoints in a new API Reference table to satisfy SSoC requirements.
  • Code Formatting:
    • Formatted Python scripts (fp_predictor.py, conftest.py, test_job_endpoints.py, main.py) using ruff format and sorted import order via ruff check --fix to satisfy CI gate checks.

Frontend

  • api.ts (API Client):
    • Fixed incorrect indentation of properties in the BackendFinding interface type.
    • Added JobResponse wrapper interface (JobGetResponse/JobFindingsResponse) and typed the getJobFindings function correctly to resolve the type mismatch.
  • findings.tsx and fix.tsx (Findings & Fix Pages):
    • Refactored getJobFindings callers to use the type-safe findings array directly and removed redundant Array.isArray fallback checks.
  • useRecentJobs.ts (Recent Scans Hooks):
    • Added a mapBackendStatus helper to safely map backend job statuses (like scanning and aborted) to valid UiJobStatus types before passing them to the StatusPill component.
  • RecentScans.tsx (Recent Scans Panel):
    • Updated navigation links to pass the job_id query parameter (/findings?job_id=XYZ).
    • Disabled the "View" button (disabled) and greyed out rows (opacity-65, cursor-not-allowed) for failed/non-completed scans.
    • Updated formatTimestamp to parse SQLite's UTC date strings correctly (appending T and Z as needed) before converting them to the user's local timezone.
  • verify.tsx (Verification Page):
    • Updated the "View All Findings" link to include the scan ID query parameter.

New dependencies

-none

Database / schema changes

-none


Testing

How did you test this?
Ran all 113 backend Python tests to ensure no backend endpoints were broken and coverage gate is satisfied
Ran ruff checks to verify formatting passes formatting gates
Ran frontend compile build locally
Compiled successfully with no TypeScript/lint compilation errors

Checklist

  • Tested locally end-to-end (upload ZIP or GitHub URL → scan → findings returned correctly)
  • New ML model falls back gracefully when model file is absent
  • No new console.error or unhandled Python exceptions introduced
  • Added or updated tests where applicable
  • requirements.txt / package.json updated if new dependencies added
  • New model files (.pkl, .pt, etc.) are gitignored, not committed

Anything reviewers should focus on

none

Screenshots (if UI changed)

Screenshot 2026-07-19 011745

@ValayaDase

Copy link
Copy Markdown
Author

@arpit2006 completed with #308 pls let me know if you hv merged this into main or not

@arpit2006

Copy link
Copy Markdown
Collaborator

@ValayaDase , Resolve CI fail issue

@arpit2006

Copy link
Copy Markdown
Collaborator

@ValayaDase , Please resolve template issue. Until fixed i can't receive review request.

@ValayaDase

Copy link
Copy Markdown
Author

@arpit2006 check once

@arpit2006

Copy link
Copy Markdown
Collaborator

⚠️ Automated Check: This PR does not strictly follow the required template. Please ensure you have not deleted any checkboxes or mandatory headings, and that you have written explanations under What this PR does and How did you test this?.

Correct PR Template

Please copy and paste the raw template below into your PR description and fill it out:

> **Before opening:** make sure there is an issue tracking this work, and link it below. PRs without a linked issue may be closed without review.

## Linked issue

Closes #

## What this PR does



## Type of change

- [ ] Bug fix
- [ ] New feature
- [ ] ML model / training pipeline
- [ ] Refactor (no behaviour change)
- [ ] Documentation
- [ ] Tests only

## ML tier (if applicable)

- [ ] Tier 1 — Triage
- [ ] Tier 2 — Predictive
- [ ] Tier 3 — Autonomous
- [ ] Not ML-related

## Stack affected

- [ ] Backend
- [ ] Frontend
- [ ] Both

---

## Changes

### Backend



-

### Frontend



-

### New dependencies



-

### Database / schema changes



-

---

## Testing

**How did you test this?**



**Checklist**

- [ ] Tested locally end-to-end (upload ZIP or GitHub URL → scan → findings returned correctly)
- [ ] New ML model falls back gracefully when model file is absent
- [ ] No new `console.error` or unhandled Python exceptions introduced
- [ ] Added or updated tests where applicable
- [ ] `requirements.txt` / `package.json` updated if new dependencies added
- [ ] New model files (`.pkl`, `.pt`, etc.) are gitignored, not committed

---

## Anything reviewers should focus on



## Screenshots (if UI changed)

@ValayaDase , Fix this!

@ValayaDase

Copy link
Copy Markdown
Author

donee

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

Labels

backend Backend issues bug Something isn't working feature New feature frontend Frontend issues needs-work Work needed SSoC26

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add GET /jobs endpoint to list all past scans

3 participants