Skip to content

Conversation

@mfleader
Copy link
Contributor

@mfleader mfleader commented Dec 10, 2025

What does this PR do?

Consolidates provider data context handling into middleware, eliminating
duplication between FastAPI router routes and legacy @webmethod routes.

Closes #4366

Test Plan

Added unit test suite test_test_context_middleware, specifically test_middleware_extracts_test_id_from_header to validate the expected behavior.

❯ ./scripts/unit-tests.sh tests/unit/

Integration of the middleware test context with the files FastAPI router migration from pull/4339.

❯ git switch migrate-files-api
Switched to branch 'migrate-files-api'
❯ git rebase fix-test-ctx-middleware
Successfully rebased and updated refs/heads/migrate-files-api.
❯ ./scripts/integration-tests.sh --inference-mode replay --suite base --setup ollama --stack-config server:starter --subdirs files

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 10, 2025
@mfleader mfleader force-pushed the fix-test-ctx-middleware branch from d8f747d to dd814f2 Compare December 10, 2025 21:46
@mfleader mfleader force-pushed the fix-test-ctx-middleware branch 2 times, most recently from 3507982 to 3218597 Compare December 11, 2025 19:43
@mfleader mfleader force-pushed the fix-test-ctx-middleware branch from 3218597 to 05ec343 Compare December 12, 2025 12:56
@mfleader mfleader requested a review from ashwinb December 12, 2025 12:57
@mfleader mfleader requested a review from ashwinb December 12, 2025 17:59
@mfleader mfleader force-pushed the fix-test-ctx-middleware branch 6 times, most recently from 0610806 to 806b2b5 Compare December 16, 2025 13:08
@mfleader mfleader changed the title fix(server): add TestContextMiddleware for integration test replay fix(server): add middleware for provider data and test context Dec 16, 2025
@mfleader mfleader force-pushed the fix-test-ctx-middleware branch from 806b2b5 to bb9e3e6 Compare December 16, 2025 16:03
Copy link
Collaborator

@leseb leseb left a comment

Choose a reason for hiding this comment

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

one nit otherwise LGTM, thanks for catching this!

Ensures provider data and test context from X-LlamaStack-Provider-Data
header is available to all routes, enabling deterministic ID generation
in replay mode. Remove duplicate context setup from create_dynamic_typed_route().

Signed-off-by: Matthew F Leader <mleader@redhat.com>
@mfleader mfleader force-pushed the fix-test-ctx-middleware branch from bb9e3e6 to 3463505 Compare December 16, 2025 17:33
@cdoern cdoern merged commit 722d9c5 into llamastack:main Dec 16, 2025
34 checks passed
@mfleader mfleader deleted the fix-test-ctx-middleware branch December 16, 2025 22:02
r-bit-rry pushed a commit to r-bit-rry/llama-stack that referenced this pull request Dec 23, 2025
…stack#4367)

# What does this PR do?
Consolidates provider data context handling into middleware, eliminating
duplication between FastAPI router routes and legacy @webmethod routes.

Closes llamastack#4366 

## Test Plan

Added unit test suite `test_test_context_middleware`, specifically
`test_middleware_extracts_test_id_from_header` to validate the expected
behavior.
```
❯ ./scripts/unit-tests.sh tests/unit/
```

Integration of the middleware test context with the `files` FastAPI
router migration from
[pull/4339](llamastack#4339).
```
❯ git switch migrate-files-api
Switched to branch 'migrate-files-api'
❯ git rebase fix-test-ctx-middleware
Successfully rebased and updated refs/heads/migrate-files-api.
❯ ./scripts/integration-tests.sh --inference-mode replay --suite base --setup ollama --stack-config server:starter --subdirs files
```

Signed-off-by: Matthew F Leader <mleader@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FastAPI router routes don't propagate test context for replay mode

4 participants