---
phase: 01-topic-start-hardening
plan: 03
type: execute
wave: 2
depends_on:
  - "01-01"
  - "01-02"
files_modified:
  - research/knowledge-hub/tests/test_aitp_service.py
  - research/knowledge-hub/tests/test_topic_start_regressions.py
autonomous: true
requirements:
  - START-03
  - STAT-03
user_setup: []
must_haves:
  truths:
    - Phase 1 behavior is verified by a deterministic test suite that does not depend on the operator's real home-directory state.
    - Topic-start and status-explainability regressions can be exercised together from the repo test suite.
    - Full `research/knowledge-hub/tests` regression passes after the Phase 1 changes land.
  artifacts:
    - path: research/knowledge-hub/tests/test_aitp_service.py
      provides: Environment-isolated migration/install regression coverage
      contains: "_claude_legacy_command_paths"
    - path: research/knowledge-hub/tests/test_topic_start_regressions.py
      provides: Combined Phase 1 regression coverage for topic-start hardening
      contains: "test_"
  key_links:
    - from: research/knowledge-hub/tests/test_topic_start_regressions.py
      to: research/knowledge-hub/knowledge_hub/aitp_service.py
      via: topic-start regression coverage
      pattern: "idea_packet|distill"
    - from: research/knowledge-hub/tests/test_topic_start_regressions.py
      to: research/knowledge-hub/runtime/scripts/sync_topic_state.py
      via: explainability regression coverage
      pattern: "status_explainability|why_this_topic_is_here"
---

<objective>
Lock Phase 1 into a deterministic regression surface and prove the repo test
suite stays green after the topic-start hardening changes.

Purpose: Turn the current working-tree improvements into repeatable and
trustworthy engineering progress.
Output: Isolated migration/install regression coverage, combined Phase 1
regression tests, and a passing full runtime test suite.
</objective>

<execution_context>
@D:/BaiduSyncdisk/Theoretical-Physics/.codex-home/get-shit-done/workflows/execute-plan.md
@D:/BaiduSyncdisk/Theoretical-Physics/.codex-home/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/01-topic-start-hardening/01-CONTEXT.md
@.planning/phases/01-topic-start-hardening/01-01-PLAN.md
@.planning/phases/01-topic-start-hardening/01-02-PLAN.md
@research/knowledge-hub/tests/test_aitp_service.py
</context>

<tasks>

<task type="auto">
  <name>Task 1: Isolate environment-dependent migration coverage</name>
  <files>research/knowledge-hub/tests/test_aitp_service.py</files>
  <read_first>research/knowledge-hub/tests/test_aitp_service.py, research/knowledge-hub/knowledge_hub/aitp_service.py</read_first>
  <action>Patch the local-install migration regression so it does not read the operator's real `~/.claude/commands` state. Use a test-local patch such as `patch.object(self.service, "_claude_legacy_command_paths", return_value=[])` around the `migrate_local_install()` call so the assertion only measures the workspace-root fixtures created inside the test temp root.</action>
  <verify>python -m pytest research/knowledge-hub/tests/test_aitp_service.py::AITPServiceTests::test_migrate_local_install_moves_workspace_legacy_and_records_pip_actions -q</verify>
  <acceptance_criteria>
    - research/knowledge-hub/tests/test_aitp_service.py contains `_claude_legacy_command_paths`
    - `python -m pytest research/knowledge-hub/tests/test_aitp_service.py::AITPServiceTests::test_migrate_local_install_moves_workspace_legacy_and_records_pip_actions -q` exits 0
  </acceptance_criteria>
  <done>The migration/install regression no longer depends on real user-home state.</done>
</task>

<task type="auto">
  <name>Task 2: Add a focused Phase 1 regression module and run the full suite</name>
  <files>research/knowledge-hub/tests/test_topic_start_regressions.py</files>
  <read_first>research/knowledge-hub/knowledge_hub/aitp_service.py, research/knowledge-hub/runtime/scripts/sync_topic_state.py, research/knowledge-hub/tests/test_aitp_service.py, research/knowledge-hub/tests/test_runtime_scripts.py</read_first>
  <action>Create `research/knowledge-hub/tests/test_topic_start_regressions.py` with focused regressions that exercise Phase 1 behavior end-to-end enough to catch future drift: source-driven idea-packet shaping, honest fallback when source evidence is weak, and the presence of the core explainability fields. Keep the module lightweight and deterministic, then run the full `research/knowledge-hub/tests` suite to confirm Phase 1 remains green.</action>
  <verify>python -m pytest research/knowledge-hub/tests -q</verify>
  <acceptance_criteria>
    - research/knowledge-hub/tests/test_topic_start_regressions.py exists
    - research/knowledge-hub/tests/test_topic_start_regressions.py contains `test_`
    - `python -m pytest research/knowledge-hub/tests -q` exits 0
  </acceptance_criteria>
  <done>Phase 1 has deterministic regression coverage and the full runtime test suite passes.</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] `python -m pytest research/knowledge-hub/tests/test_aitp_service.py::AITPServiceTests::test_migrate_local_install_moves_workspace_legacy_and_records_pip_actions -q`
- [ ] `python -m pytest research/knowledge-hub/tests -q`
- [ ] Added regressions are deterministic and do not depend on real home-directory state.
</verification>

<success_criteria>

- All tasks completed
- All verification checks pass
- No errors or warnings introduced
- Phase 1 behavior is covered by deterministic regressions and the full suite stays green

  </success_criteria>

<output>
After completion, create `.planning/phases/01-topic-start-hardening/01-03-SUMMARY.md`
</output>
