[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6CS3BJBWK71V9EJ7MJP4QXH":3,"skill-same:01M6CS3BJBWK71V9EJ7MJP4QXH":67},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":6,"ownerHtmlUrl":49,"ownerBlogUrl":50,"ownerDescription":51,"updatedAt":52,"install":53,"resources":66},"01M6CS3BJBWK71V9EJ7MJP4QXH","e2e-testing",null,"Step-based stepwise test design, implementation, and iteration for Ghost. Use this skill when creating, rewriting, reviewing, or debugging stepwise tests that chain fixtures across steps, use LiveTestEnv snapshots, run sequentially, or compare behavior across model aliases. Also covers daemon-boot e2e tests. Covers: tests\u002Fstepwise harness layout, hard-fail predecessor fixtures, transcript\u002Fmetrics artifacts, interactive scripts\u002Fe2e tooling, and the iteration workflow when tests fail.","mrtolkien\u002FGHOST","mrtolkien","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F8489650?v=4","01M6CS32Q934XBQQE8BDV5Z6W2","Tolki","01M6CS32VBCD47F5E27WF9W6FC",5,"MIT","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fe2e-testing\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"e2e testing","e2e","testing","artifacts","snapshots","tooling","use","interactive","model","ghost","metrics","harness","transcript","run","debugging","boot","e2e tests","test","workflow","design","2026-11-10 10:12:30",false,"---\nname: e2e-testing\ndescription: >-\n  Step-based stepwise test design, implementation, and iteration for Ghost. Use this\n  skill when creating, rewriting, reviewing, or debugging stepwise tests that chain\n  fixtures across steps, use LiveTestEnv snapshots, run sequentially, or compare\n  behavior across model aliases. Also covers daemon-boot e2e tests. Covers:\n  tests\u002Fstepwise harness layout, hard-fail predecessor fixtures, transcript\u002Fmetrics\n  artifacts, interactive scripts\u002Fe2e tooling, and the iteration workflow when tests\n  fail.\n---\n\n# Testing: Stepwise & E2E\n\nGhost has two kinds of live integration tests that hit real LLM providers:\n\n| Kind         | Entrypoint                              | Feature flag      | What it does                                             |\n| ------------ | --------------------------------------- | ----------------- | -------------------------------------------------------- |\n| **Stepwise** | `tests\u002Fstepwise.rs` → `tests\u002Fstepwise\u002F` | `live-tests-llms` | Snapshot-and-restore fixture chains across ordered steps |\n| **E2E**      | `tests\u002Fe2e.rs` → `tests\u002Fe2e\u002F`           | `live-tests-llms` | Boot the real daemon, send messages, assert on state     |\n\nBoth require `--features live-tests-llms`. The base `live-tests` feature covers only\nlocal-service tests (Ollama, SearXNG, crawl4ai) that don't call paid LLM APIs.\n\n## When To Read This Skill\n\nRead this skill before making changes if the task mentions any of:\n\n- stepwise tests, e2e tests, live integration tests, or scenario tests\n- splitting one flow into multiple steps\n- fixture chaining or snapshot restore between tests\n- multi-model e2e runs (`GHOST_E2E_MODEL`)\n- transcript\u002Flog rendering or fixture diffs\n- a failing stepwise or e2e test that needs debugging or iteration\n\nIf the task is only unit tests or basic integration tests that do not use either\nharness, use the `testing` skill only.\n\n## Stepwise Tests\n\n### Current System\n\nEntrypoint and modules:\n\n- `tests\u002Fstepwise.rs`\n- `tests\u002Fstepwise\u002Fmod.rs`\n- `tests\u002Fstepwise\u002Fharness.rs`\n- `tests\u002Fstepwise\u002Fscenarios\u002Fmod.rs`\n- `tests\u002Fstepwise\u002Fscenarios\u002F\u003Cscenario>\u002Fmod.rs`\n- `tests\u002Fstepwise\u002Fscenarios\u002F\u003Cscenario>\u002Fstep_XX_*.rs`\n\nScenarios currently implemented:\n\n- `printer_3d`\n  - `step_01_spawn_agent`\n  - `step_02_run_agent_completion`\n  - `step_03_reflect_agent`\n  - `step_04_finalize_chat_and_reflect`\n  - `step_05_continue_agent`\n- `project_create`\n  - `step_01_propose_project`\n  - `step_02_confirm_and_create`\n- `reference_import`\n  - `step_01_autonomous_import`\n- `ark_nova`\n  - `step_01_pdf_rules_import`\n  - `step_02_card_data_import`\n- `coding_agent`\n  - `step_01_spawn_coding_session`\n  - `step_02_coding_agent_edits`\n\n### Non-Negotiable Rules\n\n- One test per action boundary (one step = one responsibility)\n- Steps after step 01 must load predecessor snapshot\n- Missing predecessor snapshot is a hard failure\n- Sequential execution only (`--test-threads=1`)\n- Full workspace snapshot is persisted as `workspace.tar.zst`\n\n### Fixture Contract\n\nFixture path:\n\n```text\ntests\u002Ffixtures\u002Fe2e\u002F\u003Cscenario>\u002F\u003Cmodel_alias>\u002Fstep_XX_\u003Cname>\u002F\n```\n\nRequired artifacts per step:\n\n- `workspace.tar.zst`\n- `state.json`\n- `transcript.json`\n- `transcript.md`\n- `metrics.json`\n\n`state.json` must include enough linkage for next step:\n\n- `scenario`, `model_alias`, `step`, `parent_step`\n- `chat_session_id`\n- optional `agent_id` and `agent_session_id`\n- `assertion_markers` with step outputs needed later\n\n### Creating A New Stepwise Scenario\n\n1. Add `tests\u002Fstepwise\u002Fscenarios\u002F\u003Cscenario>\u002Fmod.rs` and step files.\n2. Keep each step readable: setup -> action -> assertions -> save snapshot.\n3. Use `harness::load_previous_step_or_fail(...)` for steps 02+.\n4. Build new state via `harness::fresh_step_state(...)`.\n5. Persist with `harness::save_step_snapshot(...)`.\n6. Ensure assertions are structural and robust across model variance.\n\n### Running And Refreshing\n\n#### Model Alias Resolution\n\nThe harness resolves the model alias in this order:\n\n1. `GHOST_E2E_MODEL` env var (if set)\n2. `models.default` from `~\u002F.config\u002Fghost\u002Fconfig.toml`\n3. Fallback: `\"primary\"`\n\nCheck which model aliases have fixtures: `ls tests\u002Ffixtures\u002Fe2e\u002F\u003Cscenario>\u002F`. If\n`GHOST_E2E_MODEL` doesn't match an existing fixture directory, predecessor steps will\nhard-fail. When running manually, always set the env var to match available fixtures.\n\n#### Running A Single Step\n\n```sh\nGHOST_E2E_MODEL=gpt53 cargo test --features live-tests-llms \\\n  --test stepwise printer_3d_step_01 -- --nocapture --test-threads=1\n```\n\n#### Refreshing Fixtures (Interactive Or Explicit)\n\n```sh\nuv run scripts\u002Fe2e\nuv run scripts\u002Fe2e refresh --models primary,openai\n```\n\n## E2E Tests (Daemon-Boot)\n\nThese tests boot the full Ghost daemon and exercise the real stack end-to-end.\n\nEntrypoint: `tests\u002Fe2e.rs` → `tests\u002Fe2e\u002F`\n\nModules: `ark_nova`, `helpers`, `scripting`\n\nRun with:\n\n```sh\ncargo test --features live-tests-llms --test e2e -- --nocapture\n```\n\n## Debugging Test Output (NON-NEGOTIABLE)\n\n**Never debug from cargo test stdout\u002Fstderr.** Test runs produce verbose logs (often\n1MB+) that get truncated by terminal buffers and log filters. Instead:\n\n1. **Run the test** — let it finish (pass or fail).\n2. **Find the e2e-output directory** — the test always prints the snapshot path:\n   ```\n   e2e snapshot: \u002Fpath\u002Fto\u002Fghost\u002Fe2e-output\u002F\u003Ctimestamp>_\u003Cscenario>_\u003Cstep>\u002F\n   ```\n   Or just: `ls -t e2e-output\u002F | head -1`\n3. **Inspect artifacts in the output directory**, not cargo output:\n   - `debug\u002Frequests\u002F` — raw API request JSONs, one per iteration. File names encode\n     timestamp, session ID suffix, and iteration number.\n   - `transcript.json` \u002F `transcript.md` — if the test passed and saved a snapshot.\n   - `notes\u002F`, `references\u002F`, `diary\u002F` — workspace state at time of failure.\n   - `ghost.db` — the SQLite database, queryable with `sqlite3`.\n4. **Use the analysis scripts** to inspect structured data:\n   ```sh\n   uv run scripts\u002Fe2e render-log        # Readable markdown from fixture dirs\n   uv run scripts\u002Fe2e diff              # Compare two fixture outputs\n   uv run scripts\u002Fe2e analyze-request   # Inspect raw request payloads\n   ```\n5. **For a specific debug request**, read the JSON directly or write a small `scripts\u002F`\n   Python script to extract what you need (e.g., list tool calls, find dangling function\n   calls, count tokens). Never try to grep through 1MB logs.\n\n## Iterating On Failing Tests (NON-NEGOTIABLE)\n\nWhen a stepwise or e2e test fails, follow this workflow strictly. The goal is to fix the\n_agent behavior_, never the test.\n\n### Rule 1: Never Change Test Assertions\n\nAssertions encode the RIGHT answers. They are strict on purpose. Do not weaken, relax,\nremove, or work around them. If a test fails, the agent is wrong — not the test.\n\n### Rule 2: Never Over-Fit Prompts To Tests\n\nAgent prompts, skill descriptions, and agent definitions are **generic** — they must\nstay generic. Do not add test-specific keywords, model names, or domain knowledge that\nonly exists to pass a particular assertion. A prompt change is over-fitting if it would\nnot make sense for a real user query outside the test scenario.\n\nBad: adding \"always mention the Bambu Lab P2S\" to the research agent prompt. Good:\nimproving the workflow step that tells the agent to check dedicated review sites for\nrecent models.\n\n### Rule 3: Start With Prompt Engineering\n\nWhen a test fails, the first thing to do — before touching any Rust code — is to\nunderstand what the model did wrong and why. Follow this order:\n\n1. **Read the transcript.** Use `uv run scripts\u002Fe2e render-log` to get a readable\n   markdown view of the agent's conversation. Look at what the model actually said,\n   which tools it called, and in what order.\n\n2. **Check TODO items and tool calls.** The model's internal planning (TODO lists,\n   reasoning traces) reveals how it interpreted the prompt. If it skipped a step, the\n   prompt likely did not make that step clear enough.\n\n3. **Read the failing assertion.** Understand exactly what the test expected and what\n   was missing. Map the gap back to a specific prompt instruction or workflow step.\n\n4. **Review the relevant prompts.** Read the agent prompt (`prompts\u002Fagents\u002F\u003Cagent>.md`),\n   any skills it loads, and the system prompt. Identify where the instruction was\n   ambiguous, too weak, or missing.\n\n5. **Make a targeted prompt edit.** Change one thing at a time. Re-run the failing step\n   to see if it helped. Use `uv run scripts\u002Fe2e diff` to compare before\u002Fafter\n   transcripts.\n\nCommon prompt-level fixes:\n\n- Strengthening a workflow step that the model skips\n- Reordering steps so the model does not short-circuit\n- Making a vague instruction concrete (without over-fitting)\n- Adjusting a skill's `description` field so the model reads it at the right time\n\n### Rule 4: Architectural Changes Are A Last Resort\n\nOnly consider code changes (tool loop, nudges, context management, handler logic) if\nprompt engineering alone cannot fix the failure after multiple attempts. When you do:\n\n1. **Isolate the hypothesis.** State exactly what you think the code-level problem is\n   (e.g., \"the progress gate fires too early and truncates research\").\n\n2. **Test the hypothesis.** Add logging or a small targeted change to confirm the theory\n   before making a larger refactor.\n\n3. **Keep changes minimal.** Fix the specific issue — do not refactor surrounding code,\n   add new abstractions, or \"improve\" unrelated paths.\n\n4. **Verify with a full run.** After a code change, re-run the entire scenario (all\n   steps), not just the failing step.\n\n### Iteration Quick Reference\n\n```sh\n# 1. Run the failing step\nGHOST_E2E_MODEL=primary cargo test --features live-tests-llms \\\n  --test stepwise printer_3d_step_02 -- --nocapture --test-threads=1\n\n# 2. Read the transcript\nuv run scripts\u002Fe2e render-log\n\n# 3. Compare before\u002Fafter\nuv run scripts\u002Fe2e diff\n\n# 4. Inspect raw request payloads\nuv run scripts\u002Fe2e analyze-request\n\n# 5. Re-run entire scenario after a fix\nuv run scripts\u002Fe2e refresh --models primary\n```\n\n## Debugging Methodology (Systematic)\n\nWhen an agent-driven test fails, follow this structured diagnostic process. Do NOT guess\nor make random prompt changes — diagnose first, then fix.\n\n### Step 1: Identify the Failing Assertion\n\nRead the panic message. Map it to the exact assertion in the test file. Know precisely\nwhat the test expected vs what it got (e.g., \"P2S missing from findings\", \"findings only\n49 chars\", \"web_fetch count \u003C 5\").\n\n### Step 2: Analyze the Agent Transcript\n\nUse `uv run scripts\u002Fe2e\u002Fanalyze_step02.py` (or `render-log` for fixture dirs) to get a\nstructured view of the agent's behavior. Key things to check:\n\n- **Tool call sequence**: Did the agent search, plan, fetch, then write? Or did it\n  short-circuit?\n- **TODO plan**: Was one created? How many items? Were they followed in order?\n- **Fetched URLs**: Did the agent fetch specialist review sites, or only Reddit?\n- **Token counts**: Are input tokens growing as expected, or stalling?\n- **Final text output**: How many chars? Does it contain the expected keywords?\n\n### Step 3: Check Whether the Data Exists in Context\n\nBefore blaming the prompt, verify whether the expected information actually appeared in\nthe agent's input. Use the analysis script to search for keywords (e.g., \"P2S\") across\nall tool results. If the data IS in the input but missing from the output, the problem\nis synthesis\u002Freporting, not search. If the data is NOT in the input, the problem is\nsearch\u002Ffetch.\n\n### Step 4: Inspect Nudges and System Messages\n\nCount developer\u002Fsystem messages per iteration. Known failure modes:\n\n- **TODO injection stacking**: Each `post_tool_iteration` pushes TODO state. If it\n  doesn't remove the previous one, copies accumulate (fixed Feb 2026 —\n  `history.retain()` now removes old TODO messages before pushing new).\n- **Context pressure firing too early**: The `context_pressure.threshold_chars` config\n  counts characters, not tokens. A 250K char threshold fires at ~62K tokens — way too\n  early for a 250K-token context window. Currently disabled for the deep-research agent;\n  masking handles context management.\n- **Iteration countdown stacking**: Check if countdown nudges accumulate.\n- **Nudge-to-content ratio**: If developer messages exceed 50% of the final iteration's\n  input, the agent is being drowned in noise.\n\n### Step 5: Check for Infrastructure Issues\n\n- **Provider timeouts**: Look for `timed out, retrying` in test output. Two consecutive\n  timeouts kill the agent run.\n- **Web fetch failures**: Empty or error tool results mean the page didn't load.\n- **Masking artifacts**: If `apply_masking_if_needed` fires, old tool results get\n  truncated. This is normal but can lose information the agent needs.\n\n### Analysis Scripts\n\n```sh\n# Structured agent transcript analysis (works with Codex Responses API format)\nuv run scripts\u002Fe2e\u002Fanalyze_step02.py [e2e-output-dir]\n\n# Interactive tools\nuv run scripts\u002Fe2e render-log        # Readable markdown from fixture dirs\nuv run scripts\u002Fe2e diff              # Compare two fixture outputs\nuv run scripts\u002Fe2e analyze-request   # Inspect raw request payloads\n```\n\n### Iteration Journal\n\nSave root-cause analyses and fixes to `e2e-output\u002Fiteration_journal.md`. One row per\nresolved issue, newest first. Always update the journal when closing a debugging session\nso future runs start with context.\n\n## Review Checklist\n\n- Does each step do exactly one thing?\n- Are predecessor fixtures enforced with hard-fail?\n- Is state handoff explicit and minimal?\n- Are transcript markdown and metrics produced?\n- Can the flow run sequentially for multiple model aliases?\n","# Testing: Stepwise & E2E\n\nGhost has two kinds of live integration tests that hit real LLM providers:\n\n| Kind         | Entrypoint                              | Feature flag      | What it does                                             |\n| ------------ | --------------------------------------- | ----------------- | -------------------------------------------------------- |\n| **Stepwise** | `tests\u002Fstepwise.rs` → `tests\u002Fstepwise\u002F` | `live-tests-llms` | Snapshot-and-restore fixture chains across ordered steps |\n| **E2E**      | `tests\u002Fe2e.rs` → `tests\u002Fe2e\u002F`           | `live-tests-llms` | Boot the real daemon, send messages, assert on state     |\n\nBoth require `--features live-tests-llms`. The base `live-tests` feature covers only\nlocal-service tests (Ollama, SearXNG, crawl4ai) that don't call paid LLM APIs.\n\n## When To Read This Skill\n\nRead this skill before making changes if the task mentions any of:\n\n- stepwise tests, e2e tests, live integration tests, or scenario tests\n- splitting one flow into multiple steps\n- fixture chaining or snapshot restore between tests\n- multi-model e2e runs (`GHOST_E2E_MODEL`)\n- transcript\u002Flog rendering or fixture diffs\n- a failing stepwise or e2e test that needs debugging or iteration\n\nIf the task is only unit tests or basic integration tests that do not use either\nharness, use the `testing` skill only.\n\n## Stepwise Tests\n\n### Current System\n\nEntrypoint and modules:\n\n- `tests\u002Fstepwise.rs`\n- `tests\u002Fstepwise\u002Fmod.rs`\n- `tests\u002Fstepwise\u002Fharness.rs`\n- `tests\u002Fstepwise\u002Fscenarios\u002Fmod.rs`\n- `tests\u002Fstepwise\u002Fscenarios\u002F\u003Cscenario>\u002Fmod.rs`\n- `tests\u002Fstepwise\u002Fscenarios\u002F\u003Cscenario>\u002Fstep_XX_*.rs`\n\nScenarios currently implemented:\n\n- `printer_3d`\n  - `step_01_spawn_agent`\n  - `step_02_run_agent_completion`\n  - `step_03_reflect_agent`\n  - `step_04_finalize_chat_and_reflect`\n  - `step_05_continue_agent`\n- `project_create`\n  - `step_01_propose_project`\n  - `step_02_confirm_and_create`\n- `reference_import`\n  - `step_01_autonomous_import`\n- `ark_nova`\n  - `step_01_pdf_rules_import`\n  - `step_02_card_data_import`\n- `coding_agent`\n  - `step_01_spawn_coding_session`\n  - `step_02_coding_agent_edits`\n\n### Non-Negotiable Rules\n\n- One test per action boundary (one step = one responsibility)\n- Steps after step 01 must load predecessor snapshot\n- Missing predecessor snapshot is a hard failure\n- Sequential execution only (`--test-threads=1`)\n- Full workspace snapshot is persisted as `workspace.tar.zst`\n\n### Fixture Contract\n\nFixture path:\n\n```text\ntests\u002Ffixtures\u002Fe2e\u002F\u003Cscenario>\u002F\u003Cmodel_alias>\u002Fstep_XX_\u003Cname>\u002F\n```\n\nRequired artifacts per step:\n\n- `workspace.tar.zst`\n- `state.json`\n- `transcript.json`\n- `transcript.md`\n- `metrics.json`\n\n`state.json` must include enough linkage for next step:\n\n- `scenario`, `model_alias`, `step`, `parent_step`\n- `chat_session_id`\n- optional `agent_id` and `agent_session_id`\n- `assertion_markers` with step outputs needed later\n\n### Creating A New Stepwise Scenario\n\n1. Add `tests\u002Fstepwise\u002Fscenarios\u002F\u003Cscenario>\u002Fmod.rs` and step files.\n2. Keep each step readable: setup -> action -> assertions -> save snapshot.\n3. Use `harness::load_previous_step_or_fail(...)` for steps 02+.\n4. Build new state via `harness::fresh_step_state(...)`.\n5. Persist with `harness::save_step_snapshot(...)`.\n6. Ensure assertions are structural and robust across model variance.\n\n### Running And Refreshing\n\n#### Model Alias Resolution\n\nThe harness resolves the model alias in this order:\n\n1. `GHOST_E2E_MODEL` env var (if set)\n2. `models.default` from `~\u002F.config\u002Fghost\u002Fconfig.toml`\n3. Fallback: `\"primary\"`\n\nCheck which model aliases have fixtures: `ls tests\u002Ffixtures\u002Fe2e\u002F\u003Cscenario>\u002F`. If\n`GHOST_E2E_MODEL` doesn't match an existing fixture directory, predecessor steps will\nhard-fail. When running manually, always set the env var to match available fixtures.\n\n#### Running A Single Step\n\n```sh\nGHOST_E2E_MODEL=gpt53 cargo test --features live-tests-llms \\\n  --test stepwise printer_3d_step_01 -- --nocapture --test-threads=1\n```\n\n#### Refreshing Fixtures (Interactive Or Explicit)\n\n```sh\nuv run scripts\u002Fe2e\nuv run scripts\u002Fe2e refresh --models primary,openai\n```\n\n## E2E Tests (Daemon-Boot)\n\nThese tests boot the full Ghost daemon and exercise the real stack end-to-end.\n\nEntrypoint: `tests\u002Fe2e.rs` → `tests\u002Fe2e\u002F`\n\nModules: `ark_nova`, `helpers`, `scripting`\n\nRun with:\n\n```sh\ncargo test --features live-tests-llms --test e2e -- --nocapture\n```\n\n## Debugging Test Output (NON-NEGOTIABLE)\n\n**Never debug from cargo test stdout\u002Fstderr.** Test runs produce verbose logs (often\n1MB+) that get truncated by terminal buffers and log filters. Instead:\n\n1. **Run the test** — let it finish (pass or fail).\n2. **Find the e2e-output directory** — the test always prints the snapshot path:\n   ```\n   e2e snapshot: \u002Fpath\u002Fto\u002Fghost\u002Fe2e-output\u002F\u003Ctimestamp>_\u003Cscenario>_\u003Cstep>\u002F\n   ```\n   Or just: `ls -t e2e-output\u002F | head -1`\n3. **Inspect artifacts in the output directory**, not cargo output:\n   - `debug\u002Frequests\u002F` — raw API request JSONs, one per iteration. File names encode\n     timestamp, session ID suffix, and iteration number.\n   - `transcript.json` \u002F `transcript.md` — if the test passed and saved a snapshot.\n   - `notes\u002F`, `references\u002F`, `diary\u002F` — workspace state at time of failure.\n   - `ghost.db` — the SQLite database, queryable with `sqlite3`.\n4. **Use the analysis scripts** to inspect structured data:\n   ```sh\n   uv run scripts\u002Fe2e render-log        # Readable markdown from fixture dirs\n   uv run scripts\u002Fe2e diff              # Compare two fixture outputs\n   uv run scripts\u002Fe2e analyze-request   # Inspect raw request payloads\n   ```\n5. **For a specific debug request**, read the JSON directly or write a small `scripts\u002F`\n   Python script to extract what you need (e.g., list tool calls, find dangling function\n   calls, count tokens). Never try to grep through 1MB logs.\n\n## Iterating On Failing Tests (NON-NEGOTIABLE)\n\nWhen a stepwise or e2e test fails, follow this workflow strictly. The goal is to fix the\n_agent behavior_, never the test.\n\n### Rule 1: Never Change Test Assertions\n\nAssertions encode the RIGHT answers. They are strict on purpose. Do not weaken, relax,\nremove, or work around them. If a test fails, the agent is wrong — not the test.\n\n### Rule 2: Never Over-Fit Prompts To Tests\n\nAgent prompts, skill descriptions, and agent definitions are **generic** — they must\nstay generic. Do not add test-specific keywords, model names, or domain knowledge that\nonly exists to pass a particular assertion. A prompt change is over-fitting if it would\nnot make sense for a real user query outside the test scenario.\n\nBad: adding \"always mention the Bambu Lab P2S\" to the research agent prompt. Good:\nimproving the workflow step that tells the agent to check dedicated review sites for\nrecent models.\n\n### Rule 3: Start With Prompt Engineering\n\nWhen a test fails, the first thing to do — before touching any Rust code — is to\nunderstand what the model did wrong and why. Follow this order:\n\n1. **Read the transcript.** Use `uv run scripts\u002Fe2e render-log` to get a readable\n   markdown view of the agent's conversation. Look at what the model actually said,\n   which tools it called, and in what order.\n\n2. **Check TODO items and tool calls.** The model's internal planning (TODO lists,\n   reasoning traces) reveals how it interpreted the prompt. If it skipped a step, the\n   prompt likely did not make that step clear enough.\n\n3. **Read the failing assertion.** Understand exactly what the test expected and what\n   was missing. Map the gap back to a specific prompt instruction or workflow step.\n\n4. **Review the relevant prompts.** Read the agent prompt (`prompts\u002Fagents\u002F\u003Cagent>.md`),\n   any skills it loads, and the system prompt. Identify where the instruction was\n   ambiguous, too weak, or missing.\n\n5. **Make a targeted prompt edit.** Change one thing at a time. Re-run the failing step\n   to see if it helped. Use `uv run scripts\u002Fe2e diff` to compare before\u002Fafter\n   transcripts.\n\nCommon prompt-level fixes:\n\n- Strengthening a workflow step that the model skips\n- Reordering steps so the model does not short-circuit\n- Making a vague instruction concrete (without over-fitting)\n- Adjusting a skill's `description` field so the model reads it at the right time\n\n### Rule 4: Architectural Changes Are A Last Resort\n\nOnly consider code changes (tool loop, nudges, context management, handler logic) if\nprompt engineering alone cannot fix the failure after multiple attempts. When you do:\n\n1. **Isolate the hypothesis.** State exactly what you think the code-level problem is\n   (e.g., \"the progress gate fires too early and truncates research\").\n\n2. **Test the hypothesis.** Add logging or a small targeted change to confirm the theory\n   before making a larger refactor.\n\n3. **Keep changes minimal.** Fix the specific issue — do not refactor surrounding code,\n   add new abstractions, or \"improve\" unrelated paths.\n\n4. **Verify with a full run.** After a code change, re-run the entire scenario (all\n   steps), not just the failing step.\n\n### Iteration Quick Reference\n\n```sh\n# 1. Run the failing step\nGHOST_E2E_MODEL=primary cargo test --features live-tests-llms \\\n  --test stepwise printer_3d_step_02 -- --nocapture --test-threads=1\n\n# 2. Read the transcript\nuv run scripts\u002Fe2e render-log\n\n# 3. Compare before\u002Fafter\nuv run scripts\u002Fe2e diff\n\n# 4. Inspect raw request payloads\nuv run scripts\u002Fe2e analyze-request\n\n# 5. Re-run entire scenario after a fix\nuv run scripts\u002Fe2e refresh --models primary\n```\n\n## Debugging Methodology (Systematic)\n\nWhen an agent-driven test fails, follow this structured diagnostic process. Do NOT guess\nor make random prompt changes — diagnose first, then fix.\n\n### Step 1: Identify the Failing Assertion\n\nRead the panic message. Map it to the exact assertion in the test file. Know precisely\nwhat the test expected vs what it got (e.g., \"P2S missing from findings\", \"findings only\n49 chars\", \"web_fetch count \u003C 5\").\n\n### Step 2: Analyze the Agent Transcript\n\nUse `uv run scripts\u002Fe2e\u002Fanalyze_step02.py` (or `render-log` for fixture dirs) to get a\nstructured view of the agent's behavior. Key things to check:\n\n- **Tool call sequence**: Did the agent search, plan, fetch, then write? Or did it\n  short-circuit?\n- **TODO plan**: Was one created? How many items? Were they followed in order?\n- **Fetched URLs**: Did the agent fetch specialist review sites, or only Reddit?\n- **Token counts**: Are input tokens growing as expected, or stalling?\n- **Final text output**: How many chars? Does it contain the expected keywords?\n\n### Step 3: Check Whether the Data Exists in Context\n\nBefore blaming the prompt, verify whether the expected information actually appeared in\nthe agent's input. Use the analysis script to search for keywords (e.g., \"P2S\") across\nall tool results. If the data IS in the input but missing from the output, the problem\nis synthesis\u002Freporting, not search. If the data is NOT in the input, the problem is\nsearch\u002Ffetch.\n\n### Step 4: Inspect Nudges and System Messages\n\nCount developer\u002Fsystem messages per iteration. Known failure modes:\n\n- **TODO injection stacking**: Each `post_tool_iteration` pushes TODO state. If it\n  doesn't remove the previous one, copies accumulate (fixed Feb 2026 —\n  `history.retain()` now removes old TODO messages before pushing new).\n- **Context pressure firing too early**: The `context_pressure.threshold_chars` config\n  counts characters, not tokens. A 250K char threshold fires at ~62K tokens — way too\n  early for a 250K-token context window. Currently disabled for the deep-research agent;\n  masking handles context management.\n- **Iteration countdown stacking**: Check if countdown nudges accumulate.\n- **Nudge-to-content ratio**: If developer messages exceed 50% of the final iteration's\n  input, the agent is being drowned in noise.\n\n### Step 5: Check for Infrastructure Issues\n\n- **Provider timeouts**: Look for `timed out, retrying` in test output. Two consecutive\n  timeouts kill the agent run.\n- **Web fetch failures**: Empty or error tool results mean the page didn't load.\n- **Masking artifacts**: If `apply_masking_if_needed` fires, old tool results get\n  truncated. This is normal but can lose information the agent needs.\n\n### Analysis Scripts\n\n```sh\n# Structured agent transcript analysis (works with Codex Responses API format)\nuv run scripts\u002Fe2e\u002Fanalyze_step02.py [e2e-output-dir]\n\n# Interactive tools\nuv run scripts\u002Fe2e render-log        # Readable markdown from fixture dirs\nuv run scripts\u002Fe2e diff              # Compare two fixture outputs\nuv run scripts\u002Fe2e analyze-request   # Inspect raw request payloads\n```\n\n### Iteration Journal\n\nSave root-cause analyses and fixes to `e2e-output\u002Fiteration_journal.md`. One row per\nresolved issue, newest first. Always update the journal when closing a debugging session\nso future runs start with context.\n\n## Review Checklist\n\n- Does each step do exactly one thing?\n- Are predecessor fixtures enforced with hard-fail?\n- Is state handoff explicit and minimal?\n- Are transcript markdown and metrics produced?\n- Can the flow run sequentially for multiple model aliases?\n",{"name":5,"description":7},"main","083d96429a2d05526f8a294b83c74f0336670def",".agents\u002Fskills\u002Fe2e-testing",0,"https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST","https:\u002F\u002Fgithub.com\u002Fmrtolkien","https:\u002F\u002Fblog.tolki.dev","Data Engineer \u002F Esports \u002F Keyboards","2026-04-24 15:41:08",{"source":8,"skillName":5,"commands":54,"prompt":64,"zipAvailable":65},[55,58,61],{"tool":56,"command":57},"npx","npx skills add mrtolkien\u002FGHOST --skill e2e-testing",{"tool":59,"command":60},"bunx","bunx skills add mrtolkien\u002FGHOST --skill e2e-testing",{"tool":62,"command":63},"pnpm","pnpm dlx skills add mrtolkien\u002FGHOST --skill e2e-testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fe2e-testing\u002FSKILL.md",true,[],[68,92,105,121,130,139],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":39},"01M6CS613RWD9CFJ3KFX47V1DS","system-management","Use when reading or changing GHOST configuration (providers, models, timing, compaction, services, any config.toml key), adding or switching LLM providers, answering questions about GHOST's own features or capabilities, a CLI tool is missing or \"not found\", services need starting\u002Fstopping\u002Fdebugging, updating GHOST to a newer version, managing the Nix shell environment, or troubleshooting GHOST setup.","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsystem-management\u002Fskill.md",[],[75,76,77,78,79,80,81,82,33,83,84,85,28,86,87,88,25,89,90,91],"system management","management","system","shell","cli","nix","config","setup","capabilities","services","Providers","tool","troubleshooting","environment","version","models","configuration",{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":39},"01M6CS5XTK2884R9HE15YR8YZM","writing-skills","Use when creating new skills, editing existing skills, or verifying skills work before deployment","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsuperpowers\u002Fwriting-skills\u002Fskill.md",[],[99,100,101,102,103,25,104],"writing skills","writing","coding","work","editing","deployment",{"skillNo":106,"name":107,"nameZh":6,"description":108,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":109,"categories":110,"keywords":111,"publishedAt":39},"01M6CS5V737R1DVB3TZEK0C6WT","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code. Write comprehensive implementation plans assuming the engineer has zero context for our codebase and questionable taste.","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsuperpowers\u002Fwriting-plans\u002Fskill.md",[],[112,100,113,114,115,101,116,117,25,118,119,120],"writing plans","spec","code","ZeRO","write","context","engineer","implementation","task",{"skillNo":122,"name":123,"nameZh":6,"description":124,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":125,"categories":126,"keywords":127,"publishedAt":39},"01M6CS5S5S0YY56686G5CQ0WMP","verification","Use when about to claim work is complete, fixed, or passing, before committing or creating PRs. Requires running verification commands and confirming output before making any success claims. Evidence before assertions, always.","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsuperpowers\u002Fverification\u002Fskill.md",[],[123,101,102,25,128,129],"evidence","claim",{"skillNo":131,"name":132,"nameZh":6,"description":133,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":134,"categories":135,"keywords":136,"publishedAt":39},"01M6CS5PD2ZSFWYRDZSACNTAJY","tdd","Use when implementing any feature or bugfix, before writing implementation code. Write the test first. Watch it fail. Write minimal code to pass.","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsuperpowers\u002Ftdd\u002Fskill.md",[],[132,100,114,137,101,116,25,138,119,36],"first","minimal",{"skillNo":140,"name":141,"nameZh":6,"description":142,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":143,"categories":144,"keywords":145,"publishedAt":39},"01M6CS5K5WE2SHF1YV8D9C4C77","systematic-debugging","Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes","https:\u002F\u002Fgithub.com\u002Fmrtolkien\u002FGHOST\u002Fblob\u002Fmain\u002Fassets\u002Fskills\u002Fsuperpowers\u002Fsystematic-debugging\u002Fskill.md",[],[146,33,147,25,101,36,148],"systematic debugging","behavior","bug"]