Heuristic:4thfever Cultivation world simulator Test Mode Fallback Registration
| Knowledge Sources | |
|---|---|
| Domains | Testing, LLM |
| Last Updated | 2026-10-22 16:00 GMT |
Overview
Every new LLM task must register a deterministic fallback in `test_mode_fallbacks.py` or explicitly fail-closed; unknown tasks must never fall back to a real LLM provider in test mode.
Description
When `RunConfig.test_mode=True`, all LLM calls are intercepted by `resolve_test_mode_task()` in `test_mode_fallbacks.py`. This function returns deterministic, parser-safe results without any network calls. If a task name is not registered, it raises `TestModeUnsupportedLLMTask` — a fail-closed design that prevents accidental real LLM calls during tests. Some tasks (like `world_lore_rewrite`) are explicitly marked unavailable via `TestModeLLMUnavailable` because they cannot be meaningfully simulated with rules.
Usage
Use this heuristic whenever adding a new LLM task to the codebase. You must add a branch in `resolve_test_mode_task()` returning a valid, parser-safe result. If the task genuinely cannot be simulated (e.g., it requires creative text generation), raise `TestModeLLMUnavailable` with the feature name.
The Insight (Rule of Thumb)
- Action: Add a branch in `resolve_test_mode_task()` for every new LLM task name.
- Value: Return the minimal valid JSON structure that the parser accepts (e.g., `{"story": ""}` for `story_teller`).
- Trade-off: Test-mode results are not semantically meaningful, but they exercise the full pipeline without network or cost.
- Fail-closed: Unknown task names raise `TestModeUnsupportedLLMTask`, never silently call the real provider.
Reasoning
Test mode exists to run the simulation deterministically without LLM API costs or network dependencies. If a new task is added without a fallback, the test will fail loudly — which is better than silently calling a real API and incurring cost or nondeterminism. The `registered_test_mode_tasks()` function provides a frozenset for validation tests to check coverage.
Code Evidence
Task resolution from `src/utils/llm/test_mode_fallbacks.py:41-68`:
def resolve_test_mode_task(task_name: str, infos: Mapping[str, Any]) -> dict[str, Any]:
if task_name == "action_decision":
return _action_decision(infos)
if task_name == "backstory":
return {"backstory": ""}
if task_name == "story_teller":
return {"story": ""}
# ...
if task_name.startswith("world_lore_"):
raise TestModeLLMUnavailable("world_lore_rewrite")
raise TestModeUnsupportedLLMTask(task_name)
Test mode short-circuit from `src/utils/llm/client.py:491-492`:
if is_test_mode_enabled():
return resolve_test_mode_task(task_name, infos)