"""Integration tests for (REMEDIATE): tree → write_emit_ctx → emit_result. The defect: parse_wave.py writes `_partial_reason` and `_pending_fetches` into the tree on disk. emit_result.py reads `ctx["partial_reason"]` and `ctx["pending_fetches_count"]` from the emit ctx. But write_emit_ctx.py NEVER populated those ctx keys from the tree — they silently defaulted to empty / 0 on every run. Depth-cap truncation was invisible downstream. These tests exercise both halves of the wiring: test_write_emit_ctx_reads_tree_partial_signals fake tree JSON → write_emit_ctx → assert ctx keys populated. test_end_to_end_tree_surfaces_partial_reason_in_result_block tree → write_emit_ctx → emit_result → assert RESULT block carries PARTIAL_REASON + PENDING_FETCHES_COUNT. End-to-end — this is the test both reviewers called for. Missing-tree behavior is also covered so early-abort paths still work. """ from __future__ import annotations import json import os import pathlib import subprocess import sys import tempfile import unittest from . import _bootstrap # noqa: F401 def _tools_dir() -> pathlib.Path: """Absolute path to the skill's scripts/ dir — where the emit helpers live.""" here = pathlib.Path(__file__).resolve() return here.parent.parent def _run_script(script_name: str, env: dict) -> subprocess.CompletedProcess: """Invoke `python3 /