Fix recent scans view button and keep scan results when refreshing or bookmarking #308 - #326
Fix recent scans view button and keep scan results when refreshing or bookmarking #308#326ValayaDase wants to merge 4 commits into
Conversation
|
🎉 Thank you @ValayaDase for submitting a Pull Request! We're excited to review your contribution. Before Review✅ Ensure all CI checks pass ⚡ 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! 🚀 |
|
Correct PR TemplatePlease 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)
|
There was a problem hiding this comment.
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_idin 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.
| 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; |
| 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[]; | ||
| } |
|
|
||
| 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); | ||
| } | ||
| }, []); |
| | Method | Route | Description | | ||
| |---|---|---| | ||
| | `GET` | `/health` | Health check | | ||
| | `GET` | `/jobs` | List scan jobs (paginated) | |
arpit2006
left a comment
There was a problem hiding this comment.
Fix template and other issue.
Linked issueCloses #308 What this PR doesThis PR adds a paginated Type of change
ML tier (if applicable)
Stack affected
ChangesBackend
Frontend
New dependencies-none Database / schema changes-none TestingHow did you test this? Checklist
Anything reviewers should focus onnone Screenshots (if UI changed)
|
|
@arpit2006 completed with #308 pls let me know if you hv merged this into main or not |
|
@ValayaDase , Resolve CI fail issue |
|
@ValayaDase , Please resolve template issue. Until fixed i can't receive review request. |
|
@arpit2006 check once |
@ValayaDase , Fix this! |
|
donee |

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
ML tier (if applicable)
Stack affected
Changes
Backend
backend/app/main.py:/jobs/{job_id}/findingsendpoint to return theproject_namekey in the response payload.Frontend
RecentScans.tsx:job_idquery parameter (e.g./findings?job_id=XYZ).findings.tsx:job_idquery parameter in the web address.useRecentJobs.ts:/findings?job_id=XYZwhen a scan finishes successfully.verify.tsx:New dependencies
Database / schema changes
Testing
How did you test this?