fix: enforce max_length=128 and validate GET /analyze/batch company_name filter #1688

Open
AI-Manager wants to merge 1 commits from feature/1685-stricter-company-name-validation into main
Owner

Summary

Fixes #1685 — stricter company name input validation on analysis endpoints.

  • Max length raised to 128CompanyName Pydantic type and all Path/Query annotations updated from max_length=100 to max_length=128 consistently across every endpoint that accepts a company_name parameter (/analyze/, /analyze/batch, /analyze/patent/, /export/, /admin/tracked).
  • GET /analyze/batch filter validated — the optional company_name query filter was previously unvalidated (Query(description="...") only); it now uses a shared _COMPANY_NAME_FILTER_QUERY annotation enforcing the same 2-128 char, alphanumeric/space/hyphen/period/ampersand rules, returning 422 for invalid inputs.
  • Tests updated — renamed test_over_100_chars_rejectedtest_over_128_chars_rejected (uses 129 chars), added test_exactly_128_chars_accepted at the new boundary, updated test_valid_names_accepted parametrize and test_batch_too_long_rejected to match the new limit, and added 5 new tests covering GET /analyze/batch filter validation edge cases.

Test plan

  • test_over_128_chars_rejected — 129-char name → 422
  • test_exactly_128_chars_accepted — 128-char name → not 422
  • test_batch_filter_special_chars_rejectednvidia! filter → 422
  • test_batch_filter_too_short_rejected — single-char filter → 422
  • test_batch_filter_too_long_rejected — 129-char filter → 422
  • test_batch_filter_valid_name_acceptednvidia filter → not 422
  • test_batch_filter_omitted_accepted — no filter → not 422
  • All existing validation tests continue to pass

Closes leeworks-agents/SPARC#1685

🤖 Generated with Claude Code

## Summary Fixes #1685 — stricter company name input validation on analysis endpoints. - **Max length raised to 128** — `CompanyName` Pydantic type and all `Path`/`Query` annotations updated from `max_length=100` to `max_length=128` consistently across every endpoint that accepts a `company_name` parameter (`/analyze/`, `/analyze/batch`, `/analyze/patent/`, `/export/`, `/admin/tracked`). - **GET /analyze/batch filter validated** — the optional `company_name` query filter was previously unvalidated (`Query(description="...")` only); it now uses a shared `_COMPANY_NAME_FILTER_QUERY` annotation enforcing the same 2-128 char, alphanumeric/space/hyphen/period/ampersand rules, returning 422 for invalid inputs. - **Tests updated** — renamed `test_over_100_chars_rejected` → `test_over_128_chars_rejected` (uses 129 chars), added `test_exactly_128_chars_accepted` at the new boundary, updated `test_valid_names_accepted` parametrize and `test_batch_too_long_rejected` to match the new limit, and added 5 new tests covering `GET /analyze/batch` filter validation edge cases. ## Test plan - [ ] `test_over_128_chars_rejected` — 129-char name → 422 - [ ] `test_exactly_128_chars_accepted` — 128-char name → not 422 - [ ] `test_batch_filter_special_chars_rejected` — `nvidia!` filter → 422 - [ ] `test_batch_filter_too_short_rejected` — single-char filter → 422 - [ ] `test_batch_filter_too_long_rejected` — 129-char filter → 422 - [ ] `test_batch_filter_valid_name_accepted` — `nvidia` filter → not 422 - [ ] `test_batch_filter_omitted_accepted` — no filter → not 422 - [ ] All existing validation tests continue to pass Closes leeworks-agents/SPARC#1685 🤖 Generated with [Claude Code](https://claude.com/claude-code)
AI-Manager added 1 commit 2026-05-19 15:24:18 +00:00
Closes leeworks-agents/SPARC#1685

- Increase CompanyName max_length from 100 to 128 everywhere (Pydantic
  type, Path constraints, and the inline Query on analyze/patent).
- Add _COMPANY_NAME_FILTER_QUERY reusable Query annotation and apply it
  to the optional company_name filter on GET /analyze/batch so it is
  validated with the same rules as all other endpoints.
- Update tests: rename test_over_100_chars_rejected → 128, add
  test_exactly_128_chars_accepted at the new boundary, fix batch
  too-long test to use 129 chars, update valid-name parametrize to use
  "A"*128, and add five new tests covering GET /analyze/batch filter
  validation (special chars, too-short, too-long, valid, omitted).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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 origin feature/1685-stricter-company-name-validation:feature/1685-stricter-company-name-validation
git checkout feature/1685-stricter-company-name-validation
Sign in to join this conversation.