Skip to content

RHIDP-14308: add saved prompts GET/POST/DELETE endpoints#2214

Open
Jdubrick wants to merge 12 commits into
lightspeed-core:mainfrom
Jdubrick:add-saved-prompts-get
Open

RHIDP-14308: add saved prompts GET/POST/DELETE endpoints#2214
Jdubrick wants to merge 12 commits into
lightspeed-core:mainfrom
Jdubrick:add-saved-prompts-get

Conversation

@Jdubrick

@Jdubrick Jdubrick commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

Adds authenticated CRUD-style saved prompts APIs for the current user:

  • GET /v1/saved-prompts — list saved prompts (newest first)
  • POST /v1/saved-prompts — create a saved prompt (name + content)
  • DELETE /v1/saved-prompts/{prompt_id} — delete an owned saved prompt (204; missing or non-owned → 404 to avoid probing)
  • Shared MANAGE_SAVED_PROMPTS authorization for list/create/delete
  • Config limits via existing GET /v1/saved-prompts/config / saved_prompts YAML section
  • OpenAPI regression matrix coverage for list/create/delete

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement

Tools used to create PR

  • Assisted-by: Grok 4.5
  • Generated by: Grok 4.5

Related Tickets & Documents

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Unit tests in tests/unit/app/endpoints/test_saved_prompts.py for list/create/delete (authz, validation, ownership scoping, error mapping).
  • Integration OpenAPI path/response matrix updated for GET/POST/DELETE saved-prompts.
  • Manual: POST create → copy id → DELETE → 204; non-owner/user_id mismatch → 404; saved_prompts.max_prompts_per_user enforced after config reload.

Jdubrick added 7 commits July 22, 2026 13:28
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Jdubrick, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4c273537-d158-45d0-9f9e-0c87b788099e

📥 Commits

Reviewing files that changed from the base of the PR and between c4959a8 and 1ece125.

📒 Files selected for processing (10)
  • docs/devel_doc/openapi.json
  • src/app/endpoints/saved_prompts.py
  • src/models/api/requests/README.md
  • src/models/api/responses/error/bad_request.py
  • src/models/api/responses/error/conflict.py
  • src/models/api/responses/error/not_found.py
  • src/models/api/responses/error/unprocessable_entity.py
  • tests/unit/app/endpoints/test_saved_prompts.py
  • tests/unit/models/responses/test_error_responses.py
  • tests/unit/utils/test_models_dumper.py

Walkthrough

Adds an authenticated GET /v1/saved-prompts endpoint, the MANAGE_SAVED_PROMPTS authorization action, saved-prompt request and response models, configuration constraints, OpenAPI documentation, and tests for isolation, authorization, serialization, and errors.

Changes

Saved prompts listing

Layer / File(s) Summary
Authorization and configuration contract
src/models/config.py, docs/auth/authorization.md, docs/devel_doc/ARCHITECTURE.md
Adds MANAGE_SAVED_PROMPTS, documents its endpoints, and applies non-nullable constrained saved-prompt limits.
Saved-prompt data contracts
src/models/api/requests/..., src/models/api/responses/successful/..., docs/devel_doc/openapi.json
Defines strict creation, single-item, and list models, exports them, and documents their schemas and examples.
Authenticated listing endpoint
src/app/endpoints/saved_prompts.py
Implements user-scoped listing, response mapping, OpenAPI response definitions, and database error handling.
API validation and isolation coverage
tests/unit/app/endpoints/*, tests/unit/models/*, tests/unit/utils/test_saved_prompts.py, tests/integration/test_openapi_json.py
Tests ordering, empty results, exact user isolation, authorization, authentication, configuration failures, serialization, and documented response codes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  actor Client
  participant AuthDependency
  participant list_saved_prompts_handler
  participant list_saved_prompts_by_user
  Client->>AuthDependency: GET /v1/saved-prompts
  AuthDependency->>list_saved_prompts_handler: AuthTuple
  list_saved_prompts_handler->>list_saved_prompts_by_user: user_id
  list_saved_prompts_by_user-->>list_saved_prompts_handler: saved prompt rows
  list_saved_prompts_handler-->>Client: SavedPromptsListResponse
Loading

Possibly related PRs

Suggested reviewers: tisnik

🚥 Pre-merge checks | ✅ 7
✅ Passed checks (7 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Performance And Algorithmic Complexity ✅ Passed src/utils/saved_prompts.py:178-197 uses one query with ORDER BY + LIMIT 200; endpoint maps rows in-memory only, so no N+1 or unbounded list.
Security And Secret Handling ✅ Passed PASS: endpoints use authz, responses omit user_id, prompt_id is SUID-validated, and SQLAlchemy filters are parameterized; no real secrets found.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding saved prompts GET/POST/DELETE endpoints.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/endpoints/saved_prompts.py`:
- Around line 137-156: Update the logging in the saved-prompts retrieval flow to
remove user_id from both the initial retrieval message and the SQLAlchemyError
message, while retaining operation context and exception details. Keep the
completion log’s result count, but do not include any authenticated user
identifier in these log entries.
- Line 140: Update the async route around list_saved_prompts_by_user so its
synchronous database work does not execute on the event loop; either convert the
DAL helper and its SQLAlchemy query to async, or offload the existing helper
invocation to the framework’s thread pool, preserving its event-loop-independent
Session handling.

In `@tests/unit/app/endpoints/test_saved_prompts.py`:
- Around line 267-276: Complete the _prompt_row docstring with Google-style
Parameters and Returns sections, documenting each argument and the
SimpleNamespace return value. Keep the helper implementation unchanged and use
the repository’s Parameters heading rather than Args.
- Line 23: Update the MOCK_LIST_AUTH module constant annotation to use
Final[AuthTuple], preserving its existing tuple value and type.

In `@tests/unit/models/README.md`:
- Around line 12-13: Add a blank line between the
test_saved_prompts_list_response.py heading and its descriptive text in the
README, preserving the existing heading and content.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b89866aa-ad60-4ea1-b6c7-3ac856a7e8ba

📥 Commits

Reviewing files that changed from the base of the PR and between 287072e and 5c409ce.

📒 Files selected for processing (13)
  • docs/auth/authorization.md
  • docs/devel_doc/ARCHITECTURE.md
  • docs/devel_doc/openapi.json
  • src/app/endpoints/saved_prompts.py
  • src/models/api/responses/successful/README.md
  • src/models/api/responses/successful/__init__.py
  • src/models/api/responses/successful/saved_prompts.py
  • src/models/config.py
  • tests/unit/app/endpoints/README.md
  • tests/unit/app/endpoints/test_saved_prompts.py
  • tests/unit/models/README.md
  • tests/unit/models/test_saved_prompts_list_response.py
  • tests/unit/utils/test_saved_prompts.py
📜 Review details
⏰ Context from checks skipped due to timeout. (14)
  • GitHub Check: build-pr
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: Pylinter
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-0-7-on-pull-request
🧰 Additional context used
📓 Path-based instructions (5)
**/*

📄 CodeRabbit inference engine (Custom checks)

**/*: Flag meaningful O(n^2)+ algorithms on non-trivial inputs, including handlers and Kubernetes list operations.
Flag N+1 patterns that list items and then query once per item, including Kubernetes API and database access.
Flag expensive work inside loops, including API calls, JSON parsing, and regex compilation.
Flag unbounded growth in caches, watchers, or buffers when eviction or limits are missing.
Flag missing pagination or limits on list operations and API endpoints.
Flag secrets or tokens logged in plaintext or hardcoded in source.
Flag API endpoints missing authentication or authorization.
Flag injection vulnerabilities, including SQL injection, command injection, and path traversal.
Flag sensitive data leaked in API responses, WebSocket messages, or logs.
Flag Kubernetes Secrets and Red Hat secrets missing OwnerReferences.

Never commit secrets or keys; use environment variables for sensitive data.

Files:

  • docs/devel_doc/ARCHITECTURE.md
  • tests/unit/models/README.md
  • tests/unit/app/endpoints/README.md
  • docs/auth/authorization.md
  • src/models/api/responses/successful/__init__.py
  • tests/unit/utils/test_saved_prompts.py
  • src/models/api/responses/successful/README.md
  • src/models/config.py
  • tests/unit/models/test_saved_prompts_list_response.py
  • docs/devel_doc/openapi.json
  • src/models/api/responses/successful/saved_prompts.py
  • src/app/endpoints/saved_prompts.py
  • tests/unit/app/endpoints/test_saved_prompts.py
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Use absolute imports for internal Python modules.
All modules must begin with descriptive docstrings; package __init__.py files must contain brief package descriptions.
Use logger = get_logger(__name__) from log.py for module logging.
Use Final[type] type hints for constants and keep shared constants in the central constants.py module with descriptive comments.
Functions must have complete parameter and return type annotations, descriptive snake_case action-oriented names, and docstrings.
Use modern union syntax such as str | int, Optional[Type] for optional values, and typing_extensions.Self for model validators.
Avoid modifying input parameters in place; return a new data structure instead.
Use async def for I/O operations and external API calls.
Handle APIConnectionError from Llama Stack integrations.
All classes must have descriptive docstrings, PascalCase descriptive names, complete attribute annotations, and specific types instead of Any.
Use ConfigurationBase for configuration Pydantic models and BaseModel for other data models.
Use ABC interfaces with @abstractmethod decorators for abstract classes.
Use @model_validator and @field_validator for custom Pydantic model validation.
Follow Google Python docstring conventions, including Parameters, Returns, Raises, and Attributes sections when applicable.
Use uv run for project commands, including formatting, verification, and tests.

Files:

  • src/models/api/responses/successful/__init__.py
  • tests/unit/utils/test_saved_prompts.py
  • src/models/config.py
  • tests/unit/models/test_saved_prompts_list_response.py
  • src/models/api/responses/successful/saved_prompts.py
  • src/app/endpoints/saved_prompts.py
  • tests/unit/app/endpoints/test_saved_prompts.py
src/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Configuration models must extend ConfigurationBase, whose extra setting must be "forbid" to reject unknown fields; use types such as Optional[FilePath], PositiveInt, and SecretStr.

Files:

  • src/models/api/responses/successful/__init__.py
  • src/models/config.py
  • src/models/api/responses/successful/saved_prompts.py
  • src/app/endpoints/saved_prompts.py
tests/unit/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

tests/unit/**/*.py: Use pytest for unit tests; do not use unittest. Put shared fixtures in conftest.py, use pytest-mock for mocking, and mark asynchronous tests with pytest.mark.asyncio.
Unit tests must provide at least 60% coverage.

Files:

  • tests/unit/utils/test_saved_prompts.py
  • tests/unit/models/test_saved_prompts_list_response.py
  • tests/unit/app/endpoints/test_saved_prompts.py
src/app/endpoints/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Use FastAPI HTTPException with appropriate status codes for API endpoint errors.

Files:

  • src/app/endpoints/saved_prompts.py
🧠 Learnings (7)
📚 Learning: 2026-01-12T10:58:40.230Z
Learnt from: blublinsky
Repo: lightspeed-core/lightspeed-stack PR: 972
File: src/models/config.py:459-513
Timestamp: 2026-01-12T10:58:40.230Z
Learning: In lightspeed-core/lightspeed-stack, for Python files under src/models, when a user claims a fix is done but the issue persists, verify the current code state before accepting the fix. Steps: review the diff, fetch the latest changes, run relevant tests, reproduce the issue, search the codebase for lingering references to the original problem, confirm the fix is applied and not undone by subsequent commits, and validate with local checks to ensure the issue is resolved.

Applied to files:

  • src/models/api/responses/successful/__init__.py
  • src/models/config.py
  • src/models/api/responses/successful/saved_prompts.py
📚 Learning: 2026-02-25T07:46:33.545Z
Learnt from: asimurka
Repo: lightspeed-core/lightspeed-stack PR: 1211
File: src/models/responses.py:8-16
Timestamp: 2026-02-25T07:46:33.545Z
Learning: In the Python codebase, requests.py should use OpenAIResponseInputTool as Tool while responses.py uses OpenAIResponseTool as Tool. This difference is intentional due to differing schemas for input vs output tools in llama-stack-api. Apply this distinction consistently to other models under src/models (e.g., ensure request-related tools use the InputTool variant and response-related tools use the ResponseTool variant). If adding new tools, choose the corresponding InputTool or Tool class based on whether the tool represents input or output, and document the rationale in code comments.

Applied to files:

  • src/models/api/responses/successful/__init__.py
  • src/models/config.py
  • src/models/api/responses/successful/saved_prompts.py
📚 Learning: 2026-06-24T13:45:37.249Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 1971
File: src/utils/markdown_repair.py:31-36
Timestamp: 2026-06-24T13:45:37.249Z
Learning: In the lightspeed-stack repository, docstrings must use the section header name "Parameters:" (not "Args:") for function arguments, even if the project references Google Python docstring conventions. Ensure docstrings follow the project’s established "Parameters:" header format for any documented function parameters.

Applied to files:

  • src/models/api/responses/successful/__init__.py
  • tests/unit/utils/test_saved_prompts.py
  • src/models/config.py
  • tests/unit/models/test_saved_prompts_list_response.py
  • src/models/api/responses/successful/saved_prompts.py
  • src/app/endpoints/saved_prompts.py
  • tests/unit/app/endpoints/test_saved_prompts.py
📚 Learning: 2026-07-06T15:26:18.398Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2071
File: src/models/config.py:2416-2422
Timestamp: 2026-07-06T15:26:18.398Z
Learning: In this repo’s Python code under src/**, don’t treat differences in string concatenation style as a style inconsistency when Black has effectively forced (or made clearer) use of explicit `+` string concatenation in multi-line logger/string expressions. If adjacent-literal implicit concatenation is avoided/changed specifically to accommodate Black’s formatting in these call sites, accept the `+` usage and don’t recommend converting it solely for consistency with nearby blocks that use implicit concatenation.

Applied to files:

  • src/models/api/responses/successful/__init__.py
  • src/models/config.py
  • src/models/api/responses/successful/saved_prompts.py
  • src/app/endpoints/saved_prompts.py
📚 Learning: 2026-07-17T19:25:05.325Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2166
File: src/utils/saved_prompts.py:129-157
Timestamp: 2026-07-17T19:25:05.325Z
Learning: For any endpoint that handles saved prompts and calls `src/utils/saved_prompts.py::create_saved_prompt`, treat the endpoint as the validation boundary. Before calling `create_saved_prompt`, validate the incoming saved-prompt name and content, specifically using `validate_saved_prompt_name` and then persist (store) the normalized value it returns. Do not call `create_saved_prompt` with unvalidated/raw name/content.

Applied to files:

  • src/models/api/responses/successful/__init__.py
  • src/models/config.py
  • src/models/api/responses/successful/saved_prompts.py
  • src/app/endpoints/saved_prompts.py
📚 Learning: 2026-07-21T11:10:05.060Z
Learnt from: are-ces
Repo: lightspeed-core/lightspeed-stack PR: 2162
File: src/a2a_client/__init__.py:3-9
Timestamp: 2026-07-21T11:10:05.060Z
Learning: In this repository, it is acceptable for Python package `__init__.py` files to contain functional code (not only docstrings/metadata) and to perform package-level re-exports. Do not flag `__init__.py` solely for containing imports or other logic used to re-export symbols; this is allowed when it’s implemented via imports and `__all__` (or otherwise clearly intended to define the package’s public API).

Applied to files:

  • src/models/api/responses/successful/__init__.py
📚 Learning: 2026-04-06T20:18:07.852Z
Learnt from: major
Repo: lightspeed-core/lightspeed-stack PR: 1463
File: src/app/endpoints/rlsapi_v1.py:266-271
Timestamp: 2026-04-06T20:18:07.852Z
Learning: In the lightspeed-stack codebase, within `src/app/endpoints/` inference/MCP endpoints, treat `tools: Optional[list[Any]]` in MCP tool definitions as an intentional, consistent typing pattern (used across `query`, `responses`, `streaming_query`, `rlsapi_v1`). Do not raise or suggest this as a typing issue during code review; changing it in isolation could break endpoint typing consistency across the codebase.

Applied to files:

  • src/app/endpoints/saved_prompts.py
🪛 markdownlint-cli2 (0.23.0)
tests/unit/models/README.md

[warning] 12-12: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)

🔇 Additional comments (13)
src/models/config.py (1)

1310-1312: LGTM!

tests/unit/app/endpoints/README.md (1)

70-70: LGTM!

tests/unit/utils/test_saved_prompts.py (1)

320-320: LGTM!

Also applies to: 339-356

docs/auth/authorization.md (1)

114-114: LGTM!

docs/devel_doc/ARCHITECTURE.md (1)

203-205: LGTM!

src/models/api/responses/successful/saved_prompts.py (1)

1-3: LGTM!

Also applies to: 49-99, 102-132

src/models/api/responses/successful/__init__.py (1)

52-56: LGTM!

Also applies to: 97-99

src/models/api/responses/successful/README.md (1)

40-40: LGTM!

docs/devel_doc/openapi.json (4)

7097-7253: LGTM!


11186-11187: LGTM!


19603-19668: LGTM!


19760-19794: LGTM!

tests/unit/models/test_saved_prompts_list_response.py (1)

1-75: LGTM!

Comment thread src/app/endpoints/saved_prompts.py Outdated
Comment thread src/app/endpoints/saved_prompts.py Outdated
Comment thread tests/unit/app/endpoints/test_saved_prompts.py Outdated
Comment thread tests/unit/app/endpoints/test_saved_prompts.py Outdated
Comment thread tests/unit/models/README.md
Jdubrick added 4 commits July 22, 2026 14:46
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
@Jdubrick Jdubrick changed the title RHIDP-14308: add get endpoint for saved prompts RHIDP-14308: add saved prompts GET/POST/DELETE endpoints Jul 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
tests/unit/app/endpoints/test_saved_prompts.py (2)

485-504: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Cover the list handler’s database-error branch.

Add a test that makes list_saved_prompts_by_user raise SQLAlchemyError and asserts the handler returns HTTP 500 with the database-error response, matching the explicit error path in src/app/endpoints/saved_prompts.py.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/app/endpoints/test_saved_prompts.py` around lines 485 - 504, Add
an async test alongside test_list_saved_prompts_configuration_not_loaded that
patches list_saved_prompts_by_user to raise SQLAlchemyError, invokes
list_saved_prompts_handler with the existing authorization and request fixtures,
and asserts HTTP 500 plus the expected database-error response details from the
handler’s explicit exception branch.

399-451: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Exercise authorization through FastAPI’s dependency wiring.

Direct handler calls invoke assertions without FastAPI dependency dispatch, so these “action used/forbidden” tests do not exercise the actual route authorization path. Use TestClient/ASGI requests, or invoke the authorization dependency/wrapping behavior directly rather than the inner handlers at lines 399-451, 595-629, 764-789, 958-984, and 1036-1060.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/app/endpoints/test_saved_prompts.py` around lines 399 - 451,
Update the saved-prompts authorization tests, including
test_list_saved_prompts_uses_manage_saved_prompts_action and
test_list_saved_prompts_forbidden_without_action, to exercise FastAPI dependency
wiring through TestClient/ASGI requests or the authorization wrapper/dependency
itself instead of calling list_saved_prompts_handler directly. Apply the same
approach to the corresponding tests at the referenced ranges, preserving
assertions for the required action and 403 response.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/devel_doc/openapi.json`:
- Around line 7384-7455: The saved-prompts OpenAPI responses use shared error
examples and include an invalid DELETE validation response. In the saved-prompts
endpoint definitions in src/app/endpoints/saved_prompts.py, add
endpoint-specific examples for the 409/422 responses and DELETE 400/404
responses, remove DELETE’s saved-prompt 422 HTTPValidationError response, then
regenerate docs/devel_doc/openapi.json; update both affected generated sections
at docs/devel_doc/openapi.json lines 7384-7455 and 7510-7717.

In `@src/models/api/requests/README.md`:
- Around line 30-31: Insert a blank line between the saved_prompts.py heading
and its descriptive text to satisfy the Markdown heading-spacing rule.

---

Outside diff comments:
In `@tests/unit/app/endpoints/test_saved_prompts.py`:
- Around line 485-504: Add an async test alongside
test_list_saved_prompts_configuration_not_loaded that patches
list_saved_prompts_by_user to raise SQLAlchemyError, invokes
list_saved_prompts_handler with the existing authorization and request fixtures,
and asserts HTTP 500 plus the expected database-error response details from the
handler’s explicit exception branch.
- Around line 399-451: Update the saved-prompts authorization tests, including
test_list_saved_prompts_uses_manage_saved_prompts_action and
test_list_saved_prompts_forbidden_without_action, to exercise FastAPI dependency
wiring through TestClient/ASGI requests or the authorization wrapper/dependency
itself instead of calling list_saved_prompts_handler directly. Apply the same
approach to the corresponding tests at the referenced ranges, preserving
assertions for the required action and 403 response.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e55830af-bf73-4b5c-a1b8-1b119ce7d49f

📥 Commits

Reviewing files that changed from the base of the PR and between 5c409ce and c4959a8.

📒 Files selected for processing (11)
  • docs/auth/authorization.md
  • docs/devel_doc/ARCHITECTURE.md
  • docs/devel_doc/openapi.json
  • src/app/endpoints/saved_prompts.py
  • src/models/api/requests/README.md
  • src/models/api/requests/__init__.py
  • src/models/api/requests/saved_prompts.py
  • src/models/config.py
  • tests/integration/test_openapi_json.py
  • tests/unit/app/endpoints/test_saved_prompts.py
  • tests/unit/models/README.md
📜 Review details
⏰ Context from checks skipped due to timeout. (14)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: build-pr
  • GitHub Check: Pylinter
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-0-7-on-pull-request
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
🧰 Additional context used
📓 Path-based instructions (7)
**/*

📄 CodeRabbit inference engine (Custom checks)

**/*: Flag meaningful O(n^2)+ algorithms on non-trivial inputs, including handlers and Kubernetes list operations.
Flag N+1 patterns that list items and then query once per item, including Kubernetes API and database access.
Flag expensive work inside loops, including API calls, JSON parsing, and regex compilation.
Flag unbounded growth in caches, watchers, or buffers when eviction or limits are missing.
Flag missing pagination or limits on list operations and API endpoints.
Flag secrets or tokens logged in plaintext or hardcoded in source.
Flag API endpoints missing authentication or authorization.
Flag injection vulnerabilities, including SQL injection, command injection, and path traversal.
Flag sensitive data leaked in API responses, WebSocket messages, or logs.
Flag Kubernetes Secrets and Red Hat secrets missing OwnerReferences.

Files:

  • src/models/api/requests/__init__.py
  • src/models/api/requests/README.md
  • tests/unit/models/README.md
  • src/models/api/requests/saved_prompts.py
  • docs/devel_doc/ARCHITECTURE.md
  • docs/auth/authorization.md
  • tests/integration/test_openapi_json.py
  • src/models/config.py
  • docs/devel_doc/openapi.json
  • src/app/endpoints/saved_prompts.py
  • tests/unit/app/endpoints/test_saved_prompts.py
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Use absolute imports for internal Python modules.
All modules must begin with descriptive docstrings explaining their purpose.
Use logger = get_logger(__name__) from log.py for module logging.
Use complete type annotations for function parameters and return types.
Use modern union syntax such as str | int; use Optional[Type] for optional values.
Use typing_extensions.Self for model validators.
Functions must use descriptive, action-oriented snake_case names such as get_, validate_, and check_.
Avoid modifying mutable parameters in place; return a new data structure instead.
Use async def for I/O operations and external API calls.
Handle APIConnectionError from Llama Stack.
All classes must have descriptive docstrings and complete type annotations for class attributes; use specific types instead of Any.
Use PascalCase for classes and descriptive standard suffixes such as Configuration, Error/Exception, Resolver, and Interface.
Use ABC and @abstractmethod for abstract interfaces.
Follow Google Python docstring conventions; document all modules, classes, and functions, including Parameters, Returns, Raises, and Attributes sections as applicable.
Never commit secrets or keys; use environment variables for sensitive data.

Files:

  • src/models/api/requests/__init__.py
  • src/models/api/requests/saved_prompts.py
  • tests/integration/test_openapi_json.py
  • src/models/config.py
  • src/app/endpoints/saved_prompts.py
  • tests/unit/app/endpoints/test_saved_prompts.py
**/__init__.py

📄 CodeRabbit inference engine (AGENTS.md)

Package __init__.py files must contain brief package descriptions.

Files:

  • src/models/api/requests/__init__.py
src/models/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/models/**/*.py: Extend ConfigurationBase for configuration models and BaseModel for data models.
Use @model_validator and @field_validator for Pydantic model validation.

Files:

  • src/models/api/requests/__init__.py
  • src/models/api/requests/saved_prompts.py
  • src/models/config.py
tests/integration/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Use pytest for all integration tests; do not use unittest.

Files:

  • tests/integration/test_openapi_json.py
src/app/endpoints/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Use FastAPI HTTPException with appropriate status codes for API endpoints.

Files:

  • src/app/endpoints/saved_prompts.py
tests/unit/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

tests/unit/**/*.py: Use pytest for all unit tests; do not use unittest.
Use conftest.py for shared fixtures, pytest-mock for AsyncMock objects, and pytest.mark.asyncio for asynchronous tests.

Files:

  • tests/unit/app/endpoints/test_saved_prompts.py
🧠 Learnings (7)
📚 Learning: 2026-01-12T10:58:40.230Z
Learnt from: blublinsky
Repo: lightspeed-core/lightspeed-stack PR: 972
File: src/models/config.py:459-513
Timestamp: 2026-01-12T10:58:40.230Z
Learning: In lightspeed-core/lightspeed-stack, for Python files under src/models, when a user claims a fix is done but the issue persists, verify the current code state before accepting the fix. Steps: review the diff, fetch the latest changes, run relevant tests, reproduce the issue, search the codebase for lingering references to the original problem, confirm the fix is applied and not undone by subsequent commits, and validate with local checks to ensure the issue is resolved.

Applied to files:

  • src/models/api/requests/__init__.py
  • src/models/api/requests/saved_prompts.py
  • src/models/config.py
📚 Learning: 2026-02-25T07:46:33.545Z
Learnt from: asimurka
Repo: lightspeed-core/lightspeed-stack PR: 1211
File: src/models/responses.py:8-16
Timestamp: 2026-02-25T07:46:33.545Z
Learning: In the Python codebase, requests.py should use OpenAIResponseInputTool as Tool while responses.py uses OpenAIResponseTool as Tool. This difference is intentional due to differing schemas for input vs output tools in llama-stack-api. Apply this distinction consistently to other models under src/models (e.g., ensure request-related tools use the InputTool variant and response-related tools use the ResponseTool variant). If adding new tools, choose the corresponding InputTool or Tool class based on whether the tool represents input or output, and document the rationale in code comments.

Applied to files:

  • src/models/api/requests/__init__.py
  • src/models/api/requests/saved_prompts.py
  • src/models/config.py
📚 Learning: 2026-06-24T13:45:37.249Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 1971
File: src/utils/markdown_repair.py:31-36
Timestamp: 2026-06-24T13:45:37.249Z
Learning: In the lightspeed-stack repository, docstrings must use the section header name "Parameters:" (not "Args:") for function arguments, even if the project references Google Python docstring conventions. Ensure docstrings follow the project’s established "Parameters:" header format for any documented function parameters.

Applied to files:

  • src/models/api/requests/__init__.py
  • src/models/api/requests/saved_prompts.py
  • tests/integration/test_openapi_json.py
  • src/models/config.py
  • src/app/endpoints/saved_prompts.py
  • tests/unit/app/endpoints/test_saved_prompts.py
📚 Learning: 2026-07-06T15:26:18.398Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2071
File: src/models/config.py:2416-2422
Timestamp: 2026-07-06T15:26:18.398Z
Learning: In this repo’s Python code under src/**, don’t treat differences in string concatenation style as a style inconsistency when Black has effectively forced (or made clearer) use of explicit `+` string concatenation in multi-line logger/string expressions. If adjacent-literal implicit concatenation is avoided/changed specifically to accommodate Black’s formatting in these call sites, accept the `+` usage and don’t recommend converting it solely for consistency with nearby blocks that use implicit concatenation.

Applied to files:

  • src/models/api/requests/__init__.py
  • src/models/api/requests/saved_prompts.py
  • src/models/config.py
  • src/app/endpoints/saved_prompts.py
📚 Learning: 2026-07-17T19:25:05.325Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2166
File: src/utils/saved_prompts.py:129-157
Timestamp: 2026-07-17T19:25:05.325Z
Learning: For any endpoint that handles saved prompts and calls `src/utils/saved_prompts.py::create_saved_prompt`, treat the endpoint as the validation boundary. Before calling `create_saved_prompt`, validate the incoming saved-prompt name and content, specifically using `validate_saved_prompt_name` and then persist (store) the normalized value it returns. Do not call `create_saved_prompt` with unvalidated/raw name/content.

Applied to files:

  • src/models/api/requests/__init__.py
  • src/models/api/requests/saved_prompts.py
  • src/models/config.py
  • src/app/endpoints/saved_prompts.py
📚 Learning: 2026-07-21T11:10:05.060Z
Learnt from: are-ces
Repo: lightspeed-core/lightspeed-stack PR: 2162
File: src/a2a_client/__init__.py:3-9
Timestamp: 2026-07-21T11:10:05.060Z
Learning: In this repository, it is acceptable for Python package `__init__.py` files to contain functional code (not only docstrings/metadata) and to perform package-level re-exports. Do not flag `__init__.py` solely for containing imports or other logic used to re-export symbols; this is allowed when it’s implemented via imports and `__all__` (or otherwise clearly intended to define the package’s public API).

Applied to files:

  • src/models/api/requests/__init__.py
📚 Learning: 2026-04-06T20:18:07.852Z
Learnt from: major
Repo: lightspeed-core/lightspeed-stack PR: 1463
File: src/app/endpoints/rlsapi_v1.py:266-271
Timestamp: 2026-04-06T20:18:07.852Z
Learning: In the lightspeed-stack codebase, within `src/app/endpoints/` inference/MCP endpoints, treat `tools: Optional[list[Any]]` in MCP tool definitions as an intentional, consistent typing pattern (used across `query`, `responses`, `streaming_query`, `rlsapi_v1`). Do not raise or suggest this as a typing issue during code review; changing it in isolation could break endpoint typing consistency across the codebase.

Applied to files:

  • src/app/endpoints/saved_prompts.py
🪛 markdownlint-cli2 (0.23.0)
src/models/api/requests/README.md

[warning] 30-30: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)

🔇 Additional comments (20)
tests/integration/test_openapi_json.py (1)

260-270: LGTM!

Also applies to: 376-386

tests/unit/app/endpoints/test_saved_prompts.py (1)

3-45: LGTM!

Also applies to: 155-156, 257-396, 454-483, 505-594, 632-763, 792-955, 987-1035, 1063-1091

tests/unit/models/README.md (1)

12-14: LGTM!

src/models/config.py (2)

1310-1311: LGTM!


2385-2418: LGTM!

docs/auth/authorization.md (1)

103-114: LGTM!

docs/devel_doc/ARCHITECTURE.md (1)

203-205: LGTM!

src/models/api/requests/saved_prompts.py (1)

1-38: LGTM!

src/models/api/requests/__init__.py (1)

18-18: LGTM!

Also applies to: 41-41

docs/devel_doc/openapi.json (5)

6940-6940: LGTM!


7098-7251: LGTM!


11692-11692: LGTM!


20108-20207: LGTM!


20255-20317: LGTM!

src/app/endpoints/saved_prompts.py (6)

5-67: LGTM!


87-108: LGTM!


133-150: LGTM!


153-195: LGTM!


289-357: LGTM!


246-266: 🗄️ Data Integrity & Integration

No change needed for content persistence.

validate_saved_prompt_content validates in place and returns None; it does not normalize persisted content.

			> Likely an incorrect or invalid review comment.

Comment thread docs/devel_doc/openapi.json
Comment thread src/models/api/requests/README.md
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant