Commit Graph
5 Commits
Author SHA1 Message Date
David Santos 989a92ba07 BIT-15744: add unit tests and coverage config for api, ingest-api, collector-worker
Add 68 new unit tests covering:
- api/src/types/auth.ts: can() RBAC function and ROLE_PERMISSIONS matrix (10 tests)
- ingest-api/src/lib/hash.ts: sha256Hex() and stableJsonHash() pure functions (12 tests)
- ingest-api/src/config/env.ts: loadEnv() with defaults, validation, clamping (8 tests)
- collector-worker/src/config/loadEnv.ts: loadEnv() with all opts (11 tests)
- collector-worker/src/log/structuredLog.ts: logInfo/logWarn/logError output (11 tests)
- collector-worker/src/poll/fetchHttpEvents.ts: full validation/error path coverage (16 tests)

Also add coverage reporting to vitest.config.ts (v8 provider, text/json/html reporters)
and @vitest/coverage-v8 to devDependencies + test:coverage script in each service.

All 68 tests pass. Run npm install && npm run test:coverage in each service directory.

Paperclip-Issue: BIT-15744
Paperclip-Run: 2ff0b69d-853a-46fe-add7-43aa07012016
2026-04-29 04:44:48 +00:00
David Santos 14df06dca3 Align api Fastify range with ingest-api (BIT-2517).
Set fastify to ^4.28.1 in api/package.json and sync the lockfile
metadata. npm run build && npm test passed for api and ingest-api.

Made-with: Cursor
2026-04-12 08:37:08 +00:00
Peter Spark c6e4305c79 feat(observability): stats endpoint, Prometheus metrics, SLO tracking, Grafana dashboard (BIT-734)
- GET /api/error-monitoring/stats: 24h ingestion volume, severity
  distribution, per-project metrics with resolution rates, hourly trend
- Prometheus /metrics on both api (port 3200) and ingest-api (port 3041)
  with HTTP request duration histograms, ingest SLO latency (p50/p95/p99),
  event throughput counters, domain gauges
- Grafana dashboard JSON (deploy/grafana/) with SLO panels, error volume,
  severity/state distribution, per-project charts, Node.js process metrics
- SLO runbook (docs/RUNBOOK_SLO.md): alert rules, scrape config,
  triage procedures for latency, error rate, and availability breaches

Paperclip-Agent: Peter Spark (urlKey peter-spark; id 49ce66f8-6be6-4644-afd3-eb6d8d0d4b3e)
Paperclip-Issue: BIT-734
Paperclip-Run: f45bcdc4-4757-4829-8e75-b60a8f9a7be4
2026-04-02 18:26:24 +00:00
1sonhadorandPaperclip 4604606033 feat(errors): migrate error-reporting stack from PostgreSQL to MariaDB (BIT-255)
Replace Postgres with MariaDB 11 in docker-compose; convert all
database/error_reporting and db/migrations SQL to InnoDB-friendly syntax
(DATETIME(6), AUTO_INCREMENT, ON DUPLICATE KEY). Run admin portal DDL in the
same migrate one-shot as error_reporting.

Switch ingest-api, collector-worker, and api from pg to mysql2 (pools,
parameterized queries, transactions). Align ingest writes with
er_incident_occurrences and include project_id on idempotency inserts.

Add scripts/run-mysql-migrations.sh for host-side applies; update LXC
run-migrate/verify, deployment docs, and .env.example (mysql://, ER_MYSQL_*).

Verified: npm run build + npm test in ingest-api and collector-worker;
npm run build in api. Full docker compose not run here (no local daemon).

Co-Authored-By: Paperclip <[email protected]>
2026-03-22 19:29:11 +00:00
1sonhadorandPaperclip eeb5039a3c feat(BIT-183): admin auth, RBAC, audit logging, rate limiting
Implements BIT-154.7 — Auth administrativa, RBAC e quotas:

- api/src/types/auth.ts: 3 roles (superadmin/admin/viewer), 18 permissions,
  ROLE_PERMISSIONS map as single source of truth
- api/src/plugins/auth.ts: JWT via HTTP-only __Host- cookies (15min access /
  7d refresh), token rotation, timing-safe login
- api/src/plugins/rbac.ts: requirePermission() + requireRole() Fastify
  decorators for route-level enforcement
- api/src/plugins/audit.ts: auditLog() helper + Fastify plugin; writes to
  audit_logs table; failure never aborts main operation
- api/src/plugins/rate-limit.ts: per-route limits (login: 10/5min IP,
  ingest: 1000/min token, global: 500/min) + payload size enforcement
- api/src/routes/admin/auth.ts: POST login, POST refresh, POST logout,
  GET /me — with audit events on all operations
- db/migrations/001–004: admin_users, refresh_tokens, audit_logs tables +
  dev seed (bcrypt superadmin)
- web/src/app/(admin)/login: Velzon Bootstrap 5 login page (Next.js client
  component, credentials:include, HTTP-only cookie flow)
- docs/permission-matrix.md: full permission matrix + audit event catalogue
  + rate/payload limit table (BIT-183 acceptance criterion)

Co-Authored-By: Paperclip <[email protected]>
2026-03-22 04:22:57 +00:00