<!-- task=m-multi-provider-protocol-profile-native-messages/04+02_pi_responses_regression plan=2 tag=REVIEW_TEST -->

# Harden Pi installer regression isolation and preservation coverage

## For the Implementing Agent

Filling the implementation-owned sections of `CODE_REVIEW-*-G??.md` is the mandatory final implementation step. Make only the scoped test correction, run every verification command, paste actual output, keep the active PLAN/review files in place, and report ready for review. If blocked, record the exact blocker, attempted commands/output, and resume condition only in implementation-owned evidence. Do not ask the user, call user-input tools, create stop files, classify the next state, archive logs, or write `complete.log`; finalization belongs to the code-review skill.

## Background

The first review found that the new Pi regression passes while reading credential-bearing files from the live OS user home and while leaving important preservation/idempotency behavior unasserted. The production installer already uses the intended merge semantics, so this follow-up is limited to making the regression safe and capable of detecting default, provider-document, and rerun drift.

## Archive Evidence Snapshot

- Prior plan: `agent-task/m-multi-provider-protocol-profile-native-messages/04+02_pi_responses_regression/plan_local_G01_01.log`.
- Prior review: `agent-task/m-multi-provider-protocol-profile-native-messages/04+02_pi_responses_regression/code_review_cloud_G01_01.log`.
- Verdict: FAIL; 2 Required, 0 Suggested, 1 Nit.
- Required findings: eliminate all reads of the live user home and close the existing-default, full dev-corp document, full-document idempotency, and required-test-name gaps.
- Affected implementation file: `agent-client/pi/install_test.py`; `agent-client/pi/install.sh` and `agent-client/pi/README.md` remain unchanged.
- Verified baseline: the predecessor completion exists at `agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/complete.log`; the current four tests, shell syntax check, and `git diff --check` pass, proving the issue is assertion/isolation quality rather than an observed installer failure.
- Roadmap carryover: this child supplies Pi evidence for S08 but has no `Roadmap Targets`; PASS must not check a Milestone Task id directly.

## Analysis

### Files Read

- `agent-client/pi/install.sh`
- `agent-client/pi/install_test.py`
- `agent-client/pi/README.md`
- `agent-task/m-multi-provider-protocol-profile-native-messages/04+02_pi_responses_regression/PLAN-local-G01.md`
- `agent-task/m-multi-provider-protocol-profile-native-messages/04+02_pi_responses_regression/CODE_REVIEW-cloud-G01.md`
- `agent-roadmap/phase/operational-observability-provider-management/PHASE.md`
- `agent-roadmap/phase/operational-observability-provider-management/milestones/multi-provider-protocol-profile-native-messages.md`
- `agent-roadmap/sdd/operational-observability-provider-management/multi-provider-protocol-profile-native-messages/SDD.md`
- `agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/complete.log`
- `agent-test/local/rules.md`
- `agent-test/local/testing-smoke.md`

### SDD Criteria

- SDD: `agent-roadmap/sdd/operational-observability-provider-management/multi-provider-protocol-profile-native-messages/SDD.md`; status `[승인됨]`, lock released.
- Targeted scenario: S08 / `responses-regression`, which requires the existing Responses semantics and Pi consumption path to remain unchanged.
- Evidence Map row: S08 requires deterministic existing-Responses regression evidence. This child contributes the Pi installer consumer evidence only; the checklist therefore executes the real installer with test-owned homes and checks complete preservation/idempotency without adding a `Roadmap Targets` completion claim.

### Verification Context

- Handoff source: the prior plan/review plus repository-native local testing rules.
- Environment: current local checkout at `/config/workspace/iop-s0`; `python3` is available and the real `agent-client/pi/install.sh` is the exercised entrypoint.
- Preconditions: predecessor `02+01_messages_ingress` has the archived PASS `complete.log` cited above.
- Required commands: verbose Python unittest execution, shell syntax validation, deterministic unsafe-symbol/test-name searches, and `git diff --check`.
- Constraints: use only temporary test-owned homes and fake data; do not read the OS user's Pi files, execute a credential helper from the live home, use network, or record secrets.
- External verification: not applicable. The real changed verification entrypoint is fully exercised locally under temporary HOME isolation; no live Responses provider smoke is required by S08.
- Gap: the existing suite exits zero but its assertions do not prove the full preservation contract. Confidence is high because the gaps are directly visible in the fixtures and comparisons.

### Test Coverage Gaps

- Live-home isolation: uncovered safely; `TestNoUserHomeTouch` currently reads the actual user files and can expose their contents on assertion failure.
- Existing defaults: uncovered; fixtures omit `defaultProvider` or seed the managed defaults, so unconditional overwrite would pass.
- dev-corp preservation: partially covered; only `baseUrl` and `apiKey` are asserted.
- Idempotency: partially covered; only selected projections are compared after the second run.
- Responses API marker, timeout cleanup, legacy key migration, fake-key use, and execution of the real installer: covered.

### Symbol References

- The test method renames are local unittest discovery symbols. Repository search found no call sites outside `agent-client/pi/install_test.py`.
- Remove the unused `sys` import; it has no references.

### Split Judgment

- Keep one compact follow-up: isolation fixtures, preservation assertions, and full-document rerun comparison form one regression oracle in one test file.
- Runtime dependency `02` is satisfied by `agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/complete.log`.

### Scope Rationale

- Do not change `agent-client/pi/install.sh`; fresh review found no production failure.
- Do not change `agent-client/pi/README.md`; the follow-up findings concern test safety and coverage only.
- Do not change Edge/Node code, contracts, specs, roadmap state, or sibling task artifacts.

### Final Routing

- `evaluation_mode=isolated-reassessment`; finalizer=`finalize-task-policy.sh` pair mode.
- Build closures: scope/context/verification/evidence/ownership/decision are all true; capability gap: none.
- Build grade scores: scope_coupling=0, state_concurrency=0, blast_irreversibility=0, evidence_diagnosis=0, verification_complexity=1; grade G01.
- Build signals: `large_indivisible_context=false`, matched loop risk=`structured_interpretation`, loop risk count=1, `review_rework_count=1`, `evidence_integrity_failure=false`; route basis=`local-fit`.
- Review closures are all true; grade scores 0/0/0/0/1; route basis=`official-review`, cloud, Codex `gpt-5.6-sol`, xhigh.
- Canonical files: `PLAN-local-G01.md`, `CODE_REVIEW-cloud-G01.md`.

## Dependencies and Execution Order

1. Dependency `02` is complete at `agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/complete.log`.
2. Update only the test oracle, then run the real installer exclusively with test-created HOME roots.

## Implementation Checklist

- [ ] Replace live-user-home inspection with distinct test-owned decoy and installer homes, preserving sentinel bytes and absence state without reading any real user path.
- [ ] Assert custom existing defaults and the complete dev-corp document, compare complete settings/models documents across reruns, align the required test names, and remove the unused import.
- [ ] Run the focused verbose Python, shell syntax, deterministic search, and diff verification with no live credential, network, or user-home access.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [REVIEW_TEST-1] Make the Pi consumer regression safe and complete

#### Problem

`agent-client/pi/install_test.py:291-317` reads live `Path.home()` files and can emit their contents in an assertion failure. `agent-client/pi/install_test.py:73-77`, `176-179`, and `223-281` omit non-managed default fixtures, complete dev-corp equality, and complete-document rerun equality, so required regressions can pass undetected.

#### Solution

Before (`agent-client/pi/install_test.py:291-317`):

```python
real_home = Path.home()
real_settings = real_home / ".pi" / "agent" / "settings.json"
real_models = real_home / ".pi" / "agent" / "models.json"
settings_before = real_settings.read_text() if real_settings.exists() else None
models_before = real_models.read_text() if real_models.exists() else None
result = _run_installer(self.tmp_home)
```

After:

```python
decoy_home = self.tmp_home / "decoy-home"
installer_home = self.tmp_home / "installer-home"
# Seed only test-owned sentinel data in decoy_home.
with mock.patch.dict(os.environ, {"HOME": str(decoy_home)}):
    result = _run_installer(installer_home)
# Assert sentinel bytes and intentionally absent paths in decoy_home are unchanged.
```

Before (`agent-client/pi/install_test.py:223-281`): selected settings and model projections are compared.

After: capture the complete parsed `settings.json` and `models.json` after run one, rerun the installer, and assert the complete parsed documents are equal. Seed custom `defaultProvider`/`defaultModel` values and a nested dev-corp provider document, then assert exact equality. Add a separate missing-default assertion if needed to retain new-install behavior coverage. Rename the required methods to `test_preserves_openai_responses_consumption_and_user_settings` and `test_is_idempotent`.

#### Modified Files and Checklist

- [ ] `agent-client/pi/install_test.py`: replace live-home access, strengthen full preservation/idempotency assertions, align names, and remove the unused import.

#### Test Strategy

Modify the existing unittest file. Use only temporary roots and fake keys. The preservation test must detect custom default overwrite and any dev-corp nested-field drift; the idempotency test must detect any JSON document drift; the decoy-home test must prove the installer HOME override leaves a distinct test-owned home untouched without consulting the OS user home.

#### Verification

```bash
python3 agent-client/pi/install_test.py -v
bash -n agent-client/pi/install.sh
```

Expected: all isolated tests pass through the real installer and shell syntax is valid.

## Modified Files Summary

| File | Items |
|------|-------|
| `agent-client/pi/install_test.py` | REVIEW_TEST-1 |
| `agent-task/m-multi-provider-protocol-profile-native-messages/04+02_pi_responses_regression/CODE_REVIEW-cloud-G01.md` | evidence |

## Final Verification

```bash
test -f agent-task/archive/2026/08/m-multi-provider-protocol-profile-native-messages/02+01_messages_ingress/complete.log
command -v python3 && python3 --version
python3 agent-client/pi/install_test.py -v
bash -n agent-client/pi/install.sh
rg -n --sort path 'def test_(preserves_openai_responses_consumption_and_user_settings|is_idempotent)\(' agent-client/pi/install_test.py
if rg -n --sort path 'Path\.home\(\)' agent-client/pi/install_test.py; then echo 'unsafe live-home access remains' >&2; exit 1; fi
git diff --check
```

Expected: the predecessor exists; both required test names are found; all isolated tests and syntax checks pass; no live-home access remains; the diff is clean.

After completing all code changes, fill implementation-owned sections in `CODE_REVIEW-*-G??.md`.
