deploy: rate limit stats, cursor pagination, validation, tests, CI, and refactors #5

Open
AI-Manager wants to merge 30 commits from leeworks-agents/SPARC:main into main
Contributor

Deployment PR

This PR brings the fork (leeworks-agents/SPARC:main) up to date with upstream (0xWheatyz/SPARC:main). The fork is 28+ commits ahead.

Changes Included

Features

  • Add rate limit stats to admin panel
  • Add cursor-based pagination to /analyze/batch and /jobs endpoints
  • Add stricter input validation for company names

Refactoring

  • Refactor scheduler.py to use pooled DatabaseClient
  • Fix remaining dark mode issue in Analysis page

Tests

  • Add tests for tracked company admin endpoints and scheduler
  • Add API tests for export endpoints (CSV and PDF)
  • Add webhook integration tests for retry logic and payloads
  • Add S3/MinIO storage backend tests
  • Add test coverage for analyze_single_patent auto-download path
  • Expand JWT auth integration tests to 33 cases

CI / Docs

  • Enable ruff linting and pytest in CI pipeline
  • Update ROADMAP.md: mark completed P1 and P2 items as done

Notes

  • 8 open PRs exist on the fork but none are approved yet; they are NOT included in this deployment.
  • Do NOT merge this PR yourself — human operator review required.
  • Updated by ship cycle on 2026-05-19.
## Deployment PR This PR brings the fork (`leeworks-agents/SPARC:main`) up to date with upstream (`0xWheatyz/SPARC:main`). The fork is 28+ commits ahead. ## Changes Included ### Features - Add rate limit stats to admin panel - Add cursor-based pagination to `/analyze/batch` and `/jobs` endpoints - Add stricter input validation for company names ### Refactoring - Refactor `scheduler.py` to use pooled `DatabaseClient` - Fix remaining dark mode issue in Analysis page ### Tests - Add tests for tracked company admin endpoints and scheduler - Add API tests for export endpoints (CSV and PDF) - Add webhook integration tests for retry logic and payloads - Add S3/MinIO storage backend tests - Add test coverage for `analyze_single_patent` auto-download path - Expand JWT auth integration tests to 33 cases ### CI / Docs - Enable ruff linting and pytest in CI pipeline - Update ROADMAP.md: mark completed P1 and P2 items as done ## Notes - 8 open PRs exist on the fork but none are approved yet; they are NOT included in this deployment. - Do NOT merge this PR yourself — human operator review required. - Updated by ship cycle on 2026-05-19.
AI-Manager added 2 commits 2026-04-19 23:41:59 +00:00
Uncomment the ruff check and pytest steps in the Gitea Actions build
workflow so that linting violations and test failures block image builds.
Fix all pre-existing ruff violations (E402 import ordering in analyzer.py,
F821 undefined name in api.py, I001 unsorted imports in test files, F401
unused import in test_rate_limit.py).

Closes leeworks-agents/SPARC#1559
Closes leeworks-agents/SPARC#1560

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge PR #1568: ci: enable ruff linting and pytest in CI pipeline

Closes #1559
Closes #1560
AI-Manager added 2 commits 2026-04-20 06:41:51 +00:00
Add comprehensive edge-case coverage for issue #1624:

- Admin delete user endpoint (5 tests): successful delete, self-delete
  prevention, nonexistent user 404, non-admin 403, missing token rejection
- Admin role change gaps (2 tests): nonexistent user 404, non-admin 403
- Input validation (3 tests): invalid email 422, short password 422,
  missing fields 422 for both register and login
- Token edge cases (4 tests): malformed token, wrong-secret token,
  deleted user token, deleted user refresh
- Token claim verification (1 test): login tokens contain correct claims

All tests use mocked DB fixtures and require no live database.

Closes leeworks-agents/SPARC#1624

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Expand JWT auth integration tests to 33 cases (#1627)
AI-Manager added 2 commits 2026-04-20 06:42:05 +00:00
The prose-invert class was applied unconditionally, causing inverted
(light) text in light mode within the AI analysis results section.
Changed to dark:prose-invert so it only activates when dark mode is
enabled.

Note: The broader dark mode feature (issue #1605) is already fully
implemented -- ThemeContext, toggle button, CSS variables, dark:
variants across all pages. This fix addresses the only remaining
unstyled element.

Closes leeworks-agents/SPARC#1605

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fix remaining dark mode issue in Analysis page prose block (#1628)
AI-Manager changed title from deploy: enable ruff linting and pytest in CI pipeline to deploy: CI pipeline, JWT auth test expansion, and dark mode fix 2026-04-20 07:48:14 +00:00
AI-Manager added 2 commits 2026-04-20 23:03:48 +00:00
Replace the per-invocation DatabaseClient creation in
run_scheduled_analysis() with the shared pooled client from
SPARC.auth.get_db_client(). This avoids creating a new database
connection on every scheduler tick, which could exhaust the connection
pool under load.

Key changes:
- Import get_db_client from SPARC.auth instead of DatabaseClient
- Remove manual connect/initialize_schema/close calls
- Remove unused SPARC.config import

Closes leeworks-agents/SPARC#1658

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge: Refactor scheduler.py to use pooled DatabaseClient

Closes #1658
AI-Manager added 2 commits 2026-04-20 23:04:01 +00:00
Move all completed items (security hardening, structured logging, dark mode,
export, webhooks, scheduled analysis, multi-model, trend charts, CI, etc.)
into a new Completed section. Reorganize remaining P1/P2/P3 items to reflect
current priorities. Add new next-horizon items: historical diffing, patent
classification tagging, user API keys, batch export, and multi-tenant support.

Closes leeworks-agents/SPARC#1659

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge: Update ROADMAP.md to reflect completed work and add next-horizon items

Closes #1659
AI-Manager added 2 commits 2026-04-20 23:04:05 +00:00
7 test cases covering:
- PDF on disk analyzed directly (no download)
- Auto-download from cached metadata link when PDF missing
- FileNotFoundError when no cached link available
- Cached patent without pdf_link raises FileNotFoundError
- Analysis pipeline failure returns error string gracefully
- Model override parameter forwarded to LLM
- FileNotFoundError during parsing re-raised (not swallowed)

Closes leeworks-agents/SPARC#1661

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge: Add test coverage for analyze_single_patent auto-download path

Closes #1661
AI-Manager added 2 commits 2026-04-20 23:04:11 +00:00
21 test cases covering:
- S3StorageBackend: read, write, exists, path_for with mocked boto3
- Error handling: NoSuchKey exception, generic 404, non-404 re-raise
- Bucket auto-creation on init and graceful handling of creation failure
- Constructor credential/endpoint passthrough
- LocalStorageBackend: round-trip read/write, missing file, empty file
- get_storage_backend() factory: local/s3 selection, case-insensitivity

Closes leeworks-agents/SPARC#1660

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge: Add S3/MinIO storage backend tests for storage.py

Closes #1660
AI-Manager added 2 commits 2026-04-20 23:04:25 +00:00
22 test cases covering:
- Slack/Discord URL detection
- Generic vs Slack payload formatting
- Exponential backoff retry logic with network/timeout error handling
- Multi-URL dispatch with format auto-detection
- notify_job_completed() and notify_alert() helpers

Closes leeworks-agents/SPARC#1657

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge: Add webhook integration tests for retry logic and payloads

Closes #1657
AI-Manager added 2 commits 2026-04-20 23:04:29 +00:00
Covers GET /export/{company_name} and /export/{company_name}/pdf with
13 test cases: successful export, 404 on missing data, auth enforcement,
filename sanitization, XML-special character handling in PDF, and
multi-row output validation.

Closes leeworks-agents/SPARC#1655

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge: Add API tests for export endpoints (CSV and PDF)

Closes #1655
AI-Manager added 4 commits 2026-04-20 23:06:01 +00:00
20 test cases covering:
- GET/POST/DELETE /admin/tracked endpoints with admin auth enforcement
- GET /admin/alerts with limit parameter and auth
- scheduler.run_scheduled_analysis() for multi-company analysis, alert
  triggering on significant patent count changes, graceful failure handling

Closes leeworks-agents/SPARC#1656

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The scheduler was refactored (PR #1665) to use the pooled
get_db_client() from SPARC.auth instead of creating its own
DatabaseClient. Update test mocks accordingly and remove the
db.close() assertion since the pooled client is no longer closed
by the scheduler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge: Add tests for tracked company admin endpoints and scheduler integration

Closes #1656
AI-Manager changed title from deploy: CI pipeline, JWT auth test expansion, and dark mode fix to deploy: test suite expansion, scheduler refactor, CI pipeline, and dark mode fix 2026-04-21 01:42:01 +00:00
AI-Manager added 2 commits 2026-05-19 00:12:36 +00:00
Move seven completed items from the P1 and P2 sections into the
Completed section: in-memory jobs persistence, export endpoint tests,
tracked company admin tests, webhook integration tests, S3 storage
tests, auto-download path tests, and scheduler DatabaseClient refactor.

The P2 section now only lists the two genuinely open items: cursor-based
pagination (Issue #1669) and request validation (Issue #1670).

Closes leeworks-agents/SPARC#1678

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge PR #1679
AI-Manager added 2 commits 2026-05-19 00:12:43 +00:00
Add a CompanyName validated type enforcing 2-100 character length and
allowing only alphanumeric characters, spaces, hyphens, ampersands, and
periods. Applied to all endpoints accepting company names: /analyze,
/analyze/patent, /analyze/batch, /admin/tracked, and /export.

Includes unit tests covering too-short, too-long, special character,
leading-character, and valid edge cases for both single and batch
endpoints.

Closes leeworks-agents/SPARC#1670

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge PR #1680
AI-Manager added 2 commits 2026-05-19 00:12:51 +00:00
Add a new GET /analyze/batch endpoint that returns stored analysis results
with cursor-based pagination (default limit 50, max 200). Also update the
existing /jobs endpoint defaults from limit=10/max=100 to limit=50/max=200
for consistency.

The database layer gains a list_analyses() method with cursor support using
(timestamp, id) ordering, matching the existing list_jobs() pattern.

Includes tests for pagination behavior, boundary limits, cursor forwarding,
company name filtering, and empty result sets.

Closes leeworks-agents/SPARC#1669

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge PR #1681
AI-Manager added 2 commits 2026-05-19 00:12:58 +00:00
Add GET /admin/rate-limits endpoint (admin-only) that returns current
rate limit configuration and request statistics for all rate-limited
endpoints (/auth/register and /auth/login). Tracks total requests and
rejection counts via in-memory counters.

Includes tests for admin access, non-admin rejection, empty state,
request tracking, and configuration display.

Closes leeworks-agents/SPARC#1675

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge PR #1682
AI-Manager changed title from deploy: test suite expansion, scheduler refactor, CI pipeline, and dark mode fix to deploy: rate limit stats, cursor pagination, input validation, test suite, scheduler refactor, CI, dark mode fix 2026-05-19 00:56:09 +00:00
AI-Manager changed title from deploy: rate limit stats, cursor pagination, input validation, test suite, scheduler refactor, CI, dark mode fix to deploy: rate limit stats, cursor pagination, validation, tests, CI, and refactors 2026-05-19 15:55:31 +00:00
Some checks are pending
1 workflow awaiting approval

The workflow will only run after approval from the repository maintainer.

Test and Lint / test (pull_request) Has been cancelled
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u https://gitea.leeworks.devleeworks-agents/SPARC main:leeworks-agents-main
git checkout leeworks-agents-main
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: 0xWheatyz/SPARC#5