From b5dc61f24d15c06e2c2e62726b6c8634e6e601fb Mon Sep 17 00:00:00 2001 From: chojuninengu Date: Tue, 28 Apr 2026 19:11:22 +0100 Subject: [PATCH 1/2] fix: resolve scan_results FK violation by inserting scans record before findings - For both run_scan and run_workspace_scan, the 'scans' table row is now inserted BEFORE the background task starts emitting findings into 'scan_results'. This eliminates the foreign key constraint violation. - Completion logic now uses UPDATE instead of INSERT ... ON CONFLICT, keeping the logic clean and atomic. - Added usage store (apps/web/src/lib/stores/usage.ts) for reactive sidebar scan count that refreshes after each completed scan. - Removed stale code paths and unused mut warnings. --- README.md | 54 ++-- apps/web/src/lib/api.ts | 1 + apps/web/src/lib/stores/usage.ts | 13 + apps/web/src/routes/+layout.svelte | 12 +- apps/web/src/routes/history/[id]/+page.svelte | 4 +- apps/web/src/routes/scan/+page.svelte | 54 +++- crates/scanner/src/engines/ai_code.rs | 22 +- crates/scanner/src/engines/sca.rs | 42 ++- crates/scanner/tests/integration.rs | 18 +- crates/server/src/cve_sync/mod.rs | 6 +- crates/server/src/main.rs | 270 ++++++++++-------- 11 files changed, 316 insertions(+), 180 deletions(-) create mode 100644 apps/web/src/lib/stores/usage.ts diff --git a/README.md b/README.md index 775cfe0..1056e03 100644 --- a/README.md +++ b/README.md @@ -153,28 +153,40 @@ zenvra/ ### Setup -```bash -# Clone -git clone https://github.com/Cameroon-Developer-Network/zenvra.git -cd zenvra - -# Start infrastructure -docker compose up -d - -# Configure environment -cp .env.example .env -# Add your ANTHROPIC_API_KEY and DATABASE_URL - -# Build Rust workspace -cargo build +1. **Clone the repository:** + ```bash + git clone https://github.com/Cameroon-Developer-Network/zenvra.git + cd zenvra + ``` + +2. **Start infrastructure (Postgres & Redis):** + ```bash + # Starts only the necessary databases + docker compose up -d postgres redis + ``` + +3. **Configure environment:** + ```bash + cp .env.example .env + # Open .env and add your AI provider keys (Anthropic, OpenAI, or Google) + # The default DATABASE_URL in .env.example works with the docker setup + ``` + +4. **Start the Backend API:** + ```bash + cargo run -p zenvra-server + ``` + +5. **Start the Dashboard (Frontend):** + ```bash + cd apps/web + npm install # or pnpm install + npm run dev + ``` + +### Quick Scan via CLI -# Run all tests -cargo test --all - -# Frontend -cd apps/web && pnpm install && pnpm dev - -# Try the CLI +```bash cargo run -p zenvra-cli -- scan ./path/to/code ``` diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts index 76f559e..fba5e5e 100644 --- a/apps/web/src/lib/api.ts +++ b/apps/web/src/lib/api.ts @@ -16,6 +16,7 @@ export interface ScanRequest { language?: string; engines?: string[]; ai_config?: AiConfig; + min_severity?: 'critical' | 'high' | 'medium' | 'low' | 'info'; } export interface Finding { diff --git a/apps/web/src/lib/stores/usage.ts b/apps/web/src/lib/stores/usage.ts new file mode 100644 index 0000000..3869b07 --- /dev/null +++ b/apps/web/src/lib/stores/usage.ts @@ -0,0 +1,13 @@ +import { writable } from 'svelte/store'; +import { getHistory } from '$lib/api'; + +export const scanCount = writable(0); + +export async function refreshScanCount() { + try { + const history = await getHistory(); + scanCount.set(history.length); + } catch (e) { + console.error('Failed to refresh scan count:', e); + } +} diff --git a/apps/web/src/routes/+layout.svelte b/apps/web/src/routes/+layout.svelte index e33f4b8..d8f9b33 100644 --- a/apps/web/src/routes/+layout.svelte +++ b/apps/web/src/routes/+layout.svelte @@ -1,8 +1,16 @@