<!-- task=m-plane-origin-authoring-roundtrip-sync/10+09_plane_todo plan=0 tag=TEST -->

# Plan - TEST

## 이 파일을 읽는 구현 에이전트에게

`CODE_REVIEW-cloud-G07.md`의 구현 에이전트 소유 섹션을 채우는 것까지가 구현이다. Plane API/UI, DB ledger, Core log 증거를 secret 없이 기록하고 active 파일을 그대로 둔 채 리뷰 준비를 보고한다. SDD/Milestone lock 결정 외에는 직접 사용자에게 묻지 않는다.

## 배경

`plane-todo`는 reconcile job이 Plane 원문 댓글을 보존하고, Milestone 본문/제목을 projection하며, Plane work item을 `Todo`로 이동했음을 확인하는 작업이다. SDD S15는 Plane UI/API와 `roadmap_sync_steps` 증거를 함께 요구한다.

## 사용자 리뷰 요청 흐름

선택된 SDD 결정 또는 Milestone lock 결정만 review stub의 `사용자 리뷰 요청`에 기록한다. Plane credential, server state, live evidence gap은 검증 결과와 follow-up으로 처리한다.

## Archive Evidence Snapshot

- Prior dependency: `agent-task/archive/2026/06/m-plane-origin-authoring-roundtrip-sync/07+05,06_slug_reconcile/complete.log`
- Immediate predecessor required by directory name: `09+08_scan_enqueue/complete.log`
- Carryover: sync identity and slug retry behavior are ready for provider projection evidence.

## Roadmap Targets

- Milestone: `agent-roadmap/phase/agent-ops-mcp-control-plane/milestones/plane-origin-authoring-roundtrip-sync.md`
- Task ids:
  - `plane-todo`: preserve original comment, project Milestone body/title, and move Plane work item to Todo
- Completion mode: check-on-pass

## Spec Targets

- SDD: `agent-roadmap/sdd/agent-ops-mcp-control-plane/plane-origin-authoring-roundtrip-sync/SDD.md`
- Acceptance scenarios:
  - `S15`: task=`plane-todo`; evidence=`original comment, body update, title update, Todo move recorded`
- Completion mode: spec-check-on-pass

## 분석 결과

### 읽은 파일

- `agent-test/local/rules.md`
- `agent-test/local/core-smoke.md`
- `agent-test/live-cycle-smoke.md`
- `agent-roadmap/phase/agent-ops-mcp-control-plane/milestones/plane-origin-authoring-roundtrip-sync.md`
- `agent-roadmap/sdd/agent-ops-mcp-control-plane/plane-origin-authoring-roundtrip-sync/SDD.md`
- `services/core/internal/roadmapsync/plane_projection.go`
- `services/core/internal/roadmapsync/plane_projection_test.go`
- `services/core/internal/roadmapsync/plane_format.go`
- `services/core/internal/roadmapsync/plane_format_test.go`
- `services/core/internal/roadmapsyncpipeline/service.go`
- `services/core/internal/roadmapsyncpipeline/service_test.go`
- `services/core/internal/adapters/plane/client.go`
- `services/core/internal/adapters/plane/client_test.go`
- `services/core/migrations/00007_create_roadmap_sync_steps.sql`
- `services/core/queries/roadmap_sync_steps.sql`
- `services/core/internal/storage/roadmap_sync_steps.go`

### 테스트 환경 규칙

- test_env: `local`
- Env rules read: `agent-test/local/rules.md`
- Profiles read: `agent-test/local/core-smoke.md`, `agent-test/live-cycle-smoke.md`
- Current precheck passed: `cd services/core && go test -count=1 ./cmd/server ./internal/http ./internal/gitosync ./internal/roadmapsync ./internal/roadmapsyncpipeline ./internal/scheduler ./internal/adapters/plane ./internal/authoring`
- Final evidence must come from remote runner plus Plane UI/API and DB ledger.

### 테스트 커버리지 공백

- Unit tests cover provider call order, original comment preservation, body/status projection, Plane adapter PATCH/POST payloads, and ledger step marking.
- Missing live evidence: actual Plane item has `[milestone-id]` title/body, original comment, Todo state, and DB has `develop_matched`, `original_comment_preserved`, `plane_body_updated`, `plane_todo_moved`.

### 심볼 참조

- none

### 분할 판단

- Split policy evaluated before choosing files.
- This task depends on `09+08_scan_enqueue`, because projection evidence requires a reconcile job to be enqueued.
- It is separate from `slot-finalize` because Plane projection can succeed while task/slot finalization can still fail.

### 범위 결정 근거

- Scope includes Plane provider projection and `roadmap_sync_steps` ledger evidence.
- Excludes workspace slot terminal mapping except where needed to locate the task.
- Excludes creating new roadmap tasks or Plane child tickets.

### 빌드 등급

- `cloud-G07`: live Plane API/UI state and DB ledger must be reconciled with Core logs; unit tests alone are insufficient.

## 구현 체크리스트

- [ ] Predecessor `09+08_scan_enqueue` complete log이 있는지 확인하고, 없으면 구현을 시작하지 않고 review stub에 dependency blocker로 기록한다.
- [ ] Plane projection unit tests와 adapter tests를 remote runner에서 실행하고 출력 기록한다.
- [ ] Plane UI/API에서 original comment, `[milestone-id]` title, projected body, Todo state를 secret 없이 기록한다.
- [ ] DB `roadmap_sync_steps`에서 `milestone_id_matched`, `original_comment_preserved`, `plane_body_updated`, `plane_todo_moved`에 해당하는 ledger evidence를 기록한다.
- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다.

### [TEST-1] Plane Projection And Ledger Evidence

#### 문제

- Milestone line 78 requires original comment preservation, Milestone body projection, `[milestone-id]` title update, and Todo move.
- `SyncCreation` validates projection input and builds provider calls at `services/core/internal/roadmapsyncpipeline/service.go:259`.
- `runRemainingSteps` records step ledger marks after provider calls at `services/core/internal/roadmapsyncpipeline/service.go:429`.
- DB allowed steps are defined in `services/core/internal/storage/roadmap_sync_steps.go` and migration `00007_create_roadmap_sync_steps.sql`.
- SDD S15 requires Plane UI/API plus ledger evidence at `agent-roadmap/sdd/agent-ops-mcp-control-plane/plane-origin-authoring-roundtrip-sync/SDD.md:131`.

#### 해결 방법

- Use remote runner tests to verify local contracts.
- Use the live work item produced by predecessor tasks to inspect Plane state and DB ledger.
- If ledger or Plane mutation is missing, patch only the projection/service/adapter layer and add a focused regression test.

#### 수정 파일 및 체크리스트

- [ ] `services/core/internal/roadmapsyncpipeline/service.go`: optional defect fix only if step execution/ledger evidence fails.
- [ ] `services/core/internal/roadmapsync/plane_projection.go`: optional defect fix only if projection ordering/input guard fails.
- [ ] `services/core/internal/adapters/plane/client.go`: optional defect fix only if live Plane API payload mapping is wrong.
- [ ] `CODE_REVIEW-cloud-G07.md`: record Plane/DB/Core evidence with secret redaction.

#### 테스트 작성

- Skip new tests if live evidence matches existing unit coverage.
- If a defect is found, add a regression test to `service_test.go`, `plane_projection_test.go`, or `client_test.go` depending on the failing layer.

#### 중간 검증

```sh
ssh toki@toki-labs.com 'zsh -lc '\''cd "$HOME/agent-work/nomadcode/services/core" && go test -count=1 ./internal/roadmapsync ./internal/roadmapsyncpipeline ./internal/adapters/plane'\'''
```

Expected: packages pass.

## 의존 관계 및 구현 순서

- Wait for predecessor `09+08_scan_enqueue` complete log.
- Run focused tests.
- Collect Plane API/UI state and DB ledger evidence from the same live work item/reconcile cycle.
- Dependent task `11+10_slot_finalize` waits for this task's `complete.log`.

## 수정 파일 요약

| 파일 | 항목 |
|------|------|
| `services/core/internal/roadmapsyncpipeline/service.go` | TEST-1 optional defect fix |
| `services/core/internal/roadmapsync/plane_projection.go` | TEST-1 optional defect fix |
| `services/core/internal/adapters/plane/client.go` | TEST-1 optional defect fix |
| `CODE_REVIEW-cloud-G07.md` | TEST-1 evidence |

## 최종 검증

```sh
ssh toki@toki-labs.com 'zsh -lc '\''cd "$HOME/agent-work/nomadcode/services/core" && go test -count=1 ./internal/roadmapsync ./internal/roadmapsyncpipeline ./internal/adapters/plane'\'''
```

Expected: all listed packages pass.

```sh
ssh toki@toki-labs.com 'zsh -lc '\''cd "$HOME/agent-work/nomadcode/services/core" && docker compose logs --no-color --since=30m nomadcode-core | rg "roadmap creation sync completed|plane_todo_moved|plane work item created|plane body"'\'''
```

Expected: output links the reconcile action to projected/complete state without secrets.

```sh
ssh toki@toki-labs.com 'zsh -lc '\''docker exec code-server-postgres psql -U nomadcode -d nomad-core-dev -c "select i.roadmap_item_id, i.work_item_id, s.step, s.completed_at from roadmap_sync_identities i join roadmap_sync_steps s on s.roadmap_sync_identity_id = i.id where s.step in ('\''develop_matched'\'','\''original_comment_preserved'\'','\''plane_body_updated'\'','\''plane_todo_moved'\'') order by s.completed_at desc limit 20;"'\'''
```

Expected: the live target milestone/work item has the four expected steps. Do not paste secret values.

모든 코드 변경 완료 후 반드시 `CODE_REVIEW-*-G??.md`의 구현 에이전트 소유 섹션을 채운다. 이 파일 작성이 구현의 마지막 단계다.
