Commit Graph

266 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] c7423834d5 fix(ocr): rewrite MistralOCRProvider to use native Mistral OCR API
- PDFs are now uploaded to Mistral Files API (POST /v1/files) and
  processed via a signed document_url, resolving the 422 error caused
  by passing data:application/pdf;base64,... to an image endpoint
- Images (JPEG/PNG/GIF/WEBP/BMP/TIFF) use base64 image_url directly
- Unsupported MIME types raise a clear ValueError
- Magic-byte fallback detects PDFs with no file extension
- Switches from openai chat completions to requests HTTP calls
- Adds helper method _upload_pdf_and_get_document()
- Adds TestMistralOCRProvider with 9 unit tests covering all paths

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-24 12:13:38 +00:00
Christian Krakau-Louis e3cff12f93 Merge pull request #385 from christianlouis/copilot/increase-codecov-coverage
feat(tests): Increase CodeCov test coverage above 90%
2026-02-24 12:53:30 +01:00
copilot-swe-agent[bot] 1f080a8a43 style(tests): rename _SESSION_SECRET to TEST_SESSION_SECRET; tighten non-admin redirect assertions to == 302
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-24 00:04:42 +00:00
copilot-swe-agent[bot] a1b9ac1db6 feat(tests): increase code coverage from 89.28% to 92.15%
- Add comprehensive tests for app/views/filemanager.py (14% → 97%)
- Add tests for app/views/settings.py credentials_page and audit_log_page (53% → 100%)
- Add tests for base.py kwargs context CSRF injection (66% → 100%)
- Add tests for general.py DB error, favicon 404, license fallback (89% → 100%)
- Add tests for status.py Docker exception branches (89% → 96%)
- Add tests for config_validator/providers.py alternative AI providers (45% → 90%+)
- Add tests for settings_sync.py reload failure and signal handler (80% → 100%)

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 23:59:50 +00:00
github-actions[bot] 0827b6eaa9 style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-23 23:24:27 +00:00
copilot-swe-agent[bot] f9d849f7eb feat(api): remove redundant /env and /api/diagnostic/settings endpoints
- Remove `/api/diagnostic/settings` endpoint (superseded by `/api/settings/`)
- Remove `/env` view route (superseded by `/settings` admin page)
- Delete `env_debug.html` template
- Remove `/env` nav links from base.html (desktop + mobile)
- Update status_dashboard.html to link to /settings instead of /env
- Remove corresponding tests for deleted endpoints
- Update RateLimitingStrategy.md docs

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 23:23:28 +00:00
copilot-swe-agent[bot] 7fdd8a4d3f fix(tests): update process_with_azure patch target in test_storage_reorganization
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 23:09:55 +00:00
copilot-swe-agent[bot] 8828b71031 fix(tests): update process_document test patches to use process_with_ocr
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 23:00:45 +00:00
copilot-swe-agent[bot] a94b52ee14 feat(ai): handle temperature incompatibility for gpt-5 and o-series models, add model picker UI
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 22:12:08 +00:00
copilot-swe-agent[bot] 3262d65bfe test(api): add comprehensive tests for AI extraction endpoint reaching 100% coverage
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 21:14:08 +00:00
copilot-swe-agent[bot] ce73f23a89 feat(api): add POST /api/ai/test-extraction endpoint and Test Extraction UI button
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 21:09:27 +00:00
github-actions[bot] 724d7d870f style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-23 20:23:06 +00:00
copilot-swe-agent[bot] 044da0ff47 feat: update all OpenAI/ChatGPT refs + settings dropdown for fixed-value fields
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 20:06:57 +00:00
copilot-swe-agent[bot] dcdef44303 feat: add Portkey provider support and null-content guard to AI abstraction layer
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 19:42:03 +00:00
copilot-swe-agent[bot] d4c7fb26ac feat: add AI provider abstraction layer with OpenAI, Azure, Anthropic, Gemini, Ollama, OpenRouter, LiteLLM support
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 19:26:45 +00:00
copilot-swe-agent[bot] d885b63d38 fix(api): pass base_url to OpenAI client in test endpoint to prevent UnsupportedProtocol error
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 18:54:14 +00:00
copilot-swe-agent[bot] b9b9456310 feat(api): improve verbose error logging for OpenAI connection errors
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 18:28:49 +00:00
copilot-swe-agent[bot] efb3fa7d6c fix(config): decrypt sensitive settings when loading from database
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 12:54:34 +00:00
github-actions[bot] c37a2878d6 style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-23 12:28:59 +00:00
copilot-swe-agent[bot] 862ba99802 fix(settings): rollback restores old_value instead of new_value and supports deletion fallback
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 12:15:44 +00:00
copilot-swe-agent[bot] 0188575c27 fix: isolate token_hex mock to wizard module and fix mypy annotation
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 10:01:07 +00:00
github-actions[bot] 540541eec6 style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-23 09:33:48 +00:00
copilot-swe-agent[bot] 7fe25474bb feat(settings): wizard DB persistence, worker sync, ENV exporter, and setup wizard improvements
E) Wizard DB persistence + worker sync
- app/api/dropbox.py: save-settings persists to DB (primary); .env write
  is now best-effort (no 500 on missing file); notify_settings_updated()
  called; update-settings already done in previous commit
- app/api/google_drive.py: update-settings + save-settings both persist
  to DB and call notify_settings_updated(); .env write remains best-effort
- app/api/onedrive.py: save-settings + update-settings persist to DB +
  notify; test-token auto-refresh path persists rotated token via
  SessionLocal + notifies; .env write is best-effort throughout
- app/views/wizard.py: setup-wizard POST calls notify_settings_updated()
  when settings are saved; GET pre-fills fields from DB > ENV > default
  with a source badge; new GET /setup/undo-skip route removes skip marker

F) ENV Exporter
- app/utils/settings_service.py: get_settings_for_export(db, source)
  supports source=db (DB-only) and source=effective (full runtime config)
- app/api/settings.py: GET /api/settings/export-env admin-only endpoint
  returns downloadable .env file; source= query param selects scope
- frontend/templates/settings.html: Export .env dropdown (DB / effective)
  + Setup Wizard button added alongside existing Audit Log button

G) Setup Wizard improvements
- frontend/templates/setup_wizard.html: inputs pre-filled with
  current_value; DB/ENV/DEFAULT source badges; undo-skip messaging
- app/views/wizard.py: passes setup_skipped flag to template

Tests
- tests/test_wizard_db_persist.py: 28 tests across 7 classes covering
  wizard DB persistence, undo-skip, ENV exporter service + endpoint
- tests/test_api_dropbox.py: updated two tests to match new best-effort
  .env behavior (was: assert 500; now: assert 200)
- tests/test_api_onedrive_comprehensive.py: same for two OneDrive tests;
  fixed settings singleton pollution by adding @patch("app.api.*.settings")
  to all new wizard tests that call save/update endpoints

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 03:06:00 +00:00
copilot-swe-agent[bot] 22ab9255e2 fix(test): simplify always-false conditional in patch decorator
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-23 02:49:45 +00:00
copilot-swe-agent[bot] c2e60d3d71 test: add comprehensive tests for wizard DB persistence and settings export
- TestSetupWizardDbPersist: verify save_setting_to_db and notify_settings_updated called
- TestSetupWizardUndoSkip: verify skip marker removed and redirect
- TestDropboxSaveSettingsDbPersist: verify DB written even without .env
- TestGoogleDriveUpdateSettingsDbPersist: verify per-field DB persistence
- TestOneDriveSaveSettingsDbPersist: verify DB written without .env file
- TestGetSettingsForExport: unit tests for source=db and source=effective
- TestExportEnvEndpoint: admin-only, text/plain, content-disposition, 400 on invalid source

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-23 02:48:18 +00:00
copilot-swe-agent[bot] 90e5e0037c feat(settings): per-option save, live worker sync, audit log, and rollback
A) Per-option Save Button
- Add per-setting Save button in settings.html (visible only when value changed)
- Button calls POST /api/settings/{key} directly; existing bulk Save retained
- Add Audit Log link in settings page header

B) Immediate Worker Sync
- New app/utils/settings_sync.py with notify_settings_updated() (Redis version key)
  and register_settings_reload_signal() (Celery task_prerun handler)
- Register signal in celery_worker.py at startup
- All API write paths call notify_settings_updated() after successful saves

C) Audit Log
- Add SettingsAuditLog model (key, old_value, new_value, changed_by, changed_at, action)
- save_setting_to_db / delete_setting_from_db accept changed_by and write audit entries
- New get_audit_log() service function (masks sensitive values)
- New GET /api/settings/audit-log endpoint (admin-only)
- New GET /admin/settings/audit-log view + audit_log.html template
- Visible to all admins (per clarified requirement)

D) Config Rollback / History
- New get_setting_history() and rollback_setting() service functions
- New GET /api/settings/{key}/history endpoint
- New POST /api/settings/{key}/rollback/{history_id} endpoint
- Rollback buttons in audit_log.html with confirmation dialog
- Tests: 25 new tests covering audit log, rollback, worker sync helpers, and API endpoints

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 02:28:08 +00:00
copilot-swe-agent[bot] 9f4b162811 fix(tests): resolve CI test failures from asyncio event loop and settings reload side-effects
Two root causes identified and fixed:

1. tests/test_api_settings.py (TestListCredentials):
   asyncio.get_event_loop().run_until_complete() raised RuntimeError in
   Python 3.12 because test_api_auth_enabled.py's asyncio.run() sets the
   current event loop to None on completion. Replace all 7 occurrences
   with asyncio.run() which creates its own event loop each time.

2. tests/test_cors.py:
   reload(app.config) replaced the app.config.settings singleton with a
   new instance, so app modules holding the original reference no longer
   saw patches applied to app.config.settings.X. This caused the
   notification, OpenAI, and file-upload tests to behave as if unpatched.
   Remove the redundant reload() calls — the tests only need a fresh
   Settings(...) instance constructed with the env var already set.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 20:56:58 +00:00
Christian Krakau-Louis d870dd9fa7 Merge pull request #350 from christianlouis/copilot/implement-api-key-rotation
feat: API key rotation mechanisms — audit endpoint, rotation guide, and admin UI
2026-02-22 20:44:01 +01:00
github-actions[bot] 6cea3a370c style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-22 19:43:15 +00:00
github-actions[bot] 969b2d3d2f style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-22 19:29:32 +00:00
copilot-swe-agent[bot] 1648d8c745 feat(api): configure CORS middleware for API endpoints
- Add CORSMiddleware (disabled by default, enabled via CORS_ENABLED=true)
- Add cors_enabled, cors_allowed_origins, cors_allow_credentials,
  cors_allowed_methods, cors_allowed_headers settings to config.py
- Add parse_comma_separated_list validator for CORS list env vars
- Insert CORS middleware between SessionMiddleware and ProxyHeaders
  so preflight runs before CSRF/auth but after proxy-header processing
- Document CORS env vars in .env.demo with rationale for proxy-first approach
- Mark CORS TODO as completed in SECURITY_AUDIT.md
- Add tests/test_cors.py with 12 unit and integration tests

Closes #175

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 19:26:39 +00:00
copilot-swe-agent[bot] a46cd6634b feat(api): implement API key rotation mechanisms (#168)
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 19:24:38 +00:00
copilot-swe-agent[bot] c54cbcbdd6 feat(auth): implement CSRF token protection for state-changing operations
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 16:27:37 +00:00
github-actions[bot] 8f1abf8cdd style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-22 16:12:58 +00:00
copilot-swe-agent[bot] 3035802c16 feat(security): add comprehensive input validation and sanitization (#172)
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 16:02:00 +00:00
github-actions[bot] 77e777418c style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-22 15:25:48 +00:00
copilot-swe-agent[bot] ca27a0b687 feat(security): add request size limits to API endpoints
- Add RequestSizeLimitMiddleware that checks Content-Length header
  before request body is read: non-multipart requests capped at
  MAX_REQUEST_BODY_SIZE (default 1 MB), multipart uploads capped at
  MAX_UPLOAD_SIZE (default 1 GB). Returns HTTP 413 on violation.
- Register middleware in app/main.py
- Add max_request_body_size setting to app/config.py
- Fix ui_upload in files.py to check Content-Length early and read
  in 64 KB chunks (bounded memory usage), removing the post-write
  os.path.getsize check
- Document MAX_REQUEST_BODY_SIZE in .env.demo and ConfigurationGuide.md
- Mark SECURITY_AUDIT.md item #4 as resolved
- Add 9 tests in test_request_size_limit.py
- Update test_upload_file_too_large to use patch.object instead of
  the now-unused os.path.getsize mock

Closes #173

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 14:41:04 +00:00
github-actions[bot] bdf0afd9bf style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-22 14:24:27 +00:00
copilot-swe-agent[bot] ca6a3beb3f feat(security): add request/audit logging with sensitive data masking (#170)
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-21 21:21:29 +00:00
copilot-swe-agent[bot] 895585c1e8 fix(ci): lint errors, remove webhook deploy, add ArgoCD GitOps k8s manifest update
- Fix ruff format: add blank line before nested function in app/views/filemanager.py
- Fix ruff format: use double-quote escaping in tests/test_config.py
- Remove deploy job (Portainer webhook) from ci.yml
- Add update-k8s-manifest job: after main-branch build, updates
  apps/docuelevate/preprod/docuelevate-stack.yaml in christianlouis/k8s-cluster-state
  with the new GHCR image tag (ghcr.io/christianlouis/docuelevate:main-<short-sha>)
  using mikefarah/yq@v4.44.6 and GH_PAT secret for cross-repo write access

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-21 09:40:52 +00:00
copilot-swe-agent[bot] 48443dc30a fix(config): strip outer quotes from env var string values (Kubernetes compatibility)
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-21 09:23:39 +00:00
copilot-swe-agent[bot] e3cc489975 fix(test): fix test_get_lgpl_license_not_found JSONDecodeError
The test had two issues:
1. Too-broad mock: patching pathlib.Path.exists globally broke
   Starlette/FastAPI internals. Now targets the specific module.
2. Wrong assertion: response.json() failed because the custom
   HTTPException handler returns HTML for non-API routes, not JSON.
   Updated to only assert on status code.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-17 12:01:40 +00:00
copilot-swe-agent[bot] 13a3c41482 fix: make log_task_progress resilient to DB errors and fix test assertions
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-17 11:40:34 +00:00
copilot-swe-agent[bot] 3d3d68f7a7 fix(tests): mock log_task_progress in S3 upload tests
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-17 04:35:00 +00:00
copilot-swe-agent[bot] 9b548cc500 fix: Apply ruff format to test_send_to_all.py
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-16 20:40:44 +00:00
copilot-swe-agent[bot] 671b6885e4 fix: add missing mocks to test_send_to_all.py tests to avoid Redis connection issues
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-16 18:08:02 +00:00
copilot-swe-agent[bot] ae8a75489a Fix ruff W293 error - remove whitespace from blank line
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-16 17:23:28 +00:00
copilot-swe-agent[bot] f2eff3e2fb fix: return boolean values from _should_upload functions and fix test expectations
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-16 16:59:17 +00:00
copilot-swe-agent[bot] 44a757200b fix: correct notification test to handle keyword args and actual file size formatting
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-16 15:56:19 +00:00
copilot-swe-agent[bot] 939c456f2f fix: provide required fields when creating FileRecord in test
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-16 15:54:13 +00:00