Skip to content

UN-3636 [DEV] Hermetic LLM mock hook for execute-path critical tests#2170

Draft
chandrasekharan-zipstack wants to merge 2 commits into
mainfrom
feat/un-3636-execute-path-llm-mock
Draft

UN-3636 [DEV] Hermetic LLM mock hook for execute-path critical tests#2170
chandrasekharan-zipstack wants to merge 2 commits into
mainfrom
feat/un-3636-execute-path-llm-mock

Conversation

@chandrasekharan-zipstack

Copy link
Copy Markdown
Contributor

Stacked on #2164. Adds the deterministic-LLM capability the execute-path critical-path gaps need, without dragging real provider secrets into CI.

What

  • sdk1 hook (llm.py): one module-level _inject_mock_response + a one-line call at all four litellm.completion/acompletion sites. When UNSTRACT_LLM_MOCK_RESPONSE is set, litellm returns that string as the completion with fixed usage (10/20/30), tunable via DEFAULT_MOCK_RESPONSE_*; error sentinels like litellm.RateLimitError force error paths. Unset in production → no-op.
  • compose overlay: pass the env through worker-executor-v2 / worker-file-processing-v2 (the processes that run the LLM). Empty unless the rig/CI sets it.
  • unit tests: pin both our injector and the litellm mock contract (string + deterministic usage + error sentinel), so a litellm bump can't silently break hermetic execute-path coverage.

Why this shape

  • Single-place change, no cross-codebase adapter churn (unlike the retired NoOp adapter).
  • Hermetic + secret-free by construction — a cache-miss can't fall through to a real paid call (contrast: a record/replay proxy needs real keys to warm + as miss fallback).
  • Execute path tolerates a plain string (TEXT prompts stored verbatim; JSON prompts use tolerant repair) and never calls test_connection(), so a fixed mock runs every execute path to completion.

Not in this PR

The actual execute-path e2e tests (workflow-create-execute, usage-token-tracking, …) that consume this hook — those need the full compose stack booted to author the API flow correctly and will land next. Critical-path mappings are intentionally left unflipped until a real passing test exists (no false greens).

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c9eee07c-ba44-48c6-8872-f4dc536a2ee5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/un-3636-execute-path-llm-mock

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.

Base automatically changed from feat/un-3636-critical-path-integration-tests to main July 14, 2026 10:31
Execute-path critical paths (workflow-create-execute, usage-token-tracking,
etc.) need a deterministic LLM without real provider secrets. Add a single
sdk1 escape hatch: when UNSTRACT_LLM_MOCK_RESPONSE is set, inject litellm's
mock_response so completions return that string with fixed usage (10/20/30),
tunable via DEFAULT_MOCK_RESPONSE_* and error sentinels like
"litellm.RateLimitError". No-op in production (env unset).

Wire the env through worker-executor-v2 / worker-file-processing-v2 in the e2e
compose overlay so the mock reaches the process that runs the LLM.

Covered by unit tests pinning both our injector and the litellm mock contract
(string + deterministic usage + error sentinel) so a litellm bump can't
silently break hermetic execute-path coverage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017UVfw7aAocC3KCJaEyZ5GU
@chandrasekharan-zipstack chandrasekharan-zipstack force-pushed the feat/un-3636-execute-path-llm-mock branch from f26d44c to fc0d056 Compare July 14, 2026 12:06
Add e2e tests that exercise the full execute path hermetically using the
UNSTRACT_LLM_MOCK_RESPONSE hook (no real LLM/secret):

- api-deployment-run + usage-token-tracking: deploy a workflow as an API,
  POST a doc synchronously, assert the mocked answer and fixed 10/20/30
  usage come back as structured JSON.
- workflow-create-execute: two-step /workflow/execute/ then poll to
  COMPLETED; COMPLETED + a successful file is the hermetic proof (without
  the mock the completion would fail).

A shared provisioned_workflow fixture stands up a Prompt Studio-backed API
workflow (NoOp x2text/vectordb, chunk_size=0 so embedding/vectordb are
skipped). The rig seeds a canonical mock string in ComposeRuntime so both
the workers and pytest see the same value; tests skip if it is unset.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017UVfw7aAocC3KCJaEyZ5GU
@sonarqubecloud

Copy link
Copy Markdown

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