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

# Plan - TEST

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

`CODE_REVIEW-cloud-G06.md`의 구현 에이전트 소유 섹션을 채우는 것까지가 구현이다. 검증을 실행하고 실제 출력과 증거 경로를 기록한 뒤 active 파일을 그대로 두고 리뷰 준비를 보고한다. 선택된 SDD/Milestone lock 결정이 막을 때만 review stub의 `사용자 리뷰 요청`을 채우며, 직접 사용자에게 묻거나 `USER_REVIEW.md`, `complete.log`, archive 로그를 만들지 않는다.

## 배경

`scan-enqueue`는 Gito wakeup이 단순 changed file hint가 아니라 local develop checkout fetch, active Milestone 전체 index scan, slug 단위 `roadmap_creation_sync` enqueue로 이어지는지 닫는 작업이다. SDD S14는 unit 또는 smoke evidence를 요구하고, milestone line 77은 archive Milestone 제외까지 요구한다.

## 사용자 리뷰 요청 흐름

사용자 리뷰 요청은 선택된 SDD 결정 또는 Milestone lock 결정이 있을 때만 active review stub의 `사용자 리뷰 요청` 섹션에 기록한다. 환경/secret/service 문제는 검증 결과와 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: `08+07_gito_delivery/complete.log`
- Carryover from 07: same-slug retry and safe attribute update are complete.

## Roadmap Targets

- Milestone: `agent-roadmap/phase/agent-ops-mcp-control-plane/milestones/plane-origin-authoring-roundtrip-sync.md`
- Task ids:
  - `scan-enqueue`: Gito wakeup fetches local develop, scans active Milestone index, and enqueues slug reconcile jobs
- 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:
  - `S14`: task=`scan-enqueue`; evidence=`active reconcile enqueue evidence 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/gitosync/scanner.go`
- `services/core/internal/gitosync/scanner_test.go`
- `services/core/internal/gitosync/bridge.go`
- `services/core/internal/gitosync/bridge_test.go`
- `services/core/internal/scheduler/river.go`
- `services/core/internal/scheduler/roadmap_sync_jobs.go`
- `services/core/cmd/server/main.go`
- `services/core/cmd/server/main_test.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 commands use standard remote runner and focused package tests.

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

- `scanner.go` unit tests cover fetch/rev-parse/`git ls-tree` active index and archive candidate exclusion.
- `bridge.go` tests cover one job per scanned doc and missing-create job shape.
- Remaining gap: live Core log or queue evidence that a real Gito delivery from task 08 enqueued `roadmap_creation_sync` jobs for active Milestones, regardless of changed file hints.

### 심볼 참조

- none

### 분할 판단

- Split policy evaluated before choosing files.
- This task depends on `08+07_gito_delivery`, because live scan/enqueue evidence must start from an accepted Gito delivery.
- Directory predecessor `08` is not yet satisfied until `agent-task/m-plane-origin-authoring-roundtrip-sync/08+07_gito_delivery/complete.log` or matching archive complete log exists.
- It remains separate from `plane-todo` because queue creation can be proven before provider projection runs.

### 범위 결정 근거

- Scope includes active index scan, archive exclusion, and enqueue evidence.
- Excludes Plane comment/body/status mutation and slot terminal state.
- Do not broaden into roadmap Task completion updates.

### 빌드 등급

- `cloud-G06`: code tests are bounded, but accepted live delivery and queue/log evidence cross runtime service boundaries.

## 구현 체크리스트

- [ ] Predecessor `08+07_gito_delivery` complete log이 있는지 확인하고, 없으면 구현을 시작하지 않고 review stub에 dependency blocker로 기록한다.
- [ ] Gito wakeup 후 scanner가 active Milestone 전체를 후보로 만들고 archive Milestone은 제외하는 unit/focused test output을 기록한다.
- [ ] Remote Core log 또는 queue/DB evidence로 `roadmap_creation_sync` enqueue가 slug 단위로 발생했음을 기록한다.
- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다.

### [TEST-1] Active Index Scan To Enqueue Evidence

#### 문제

- Milestone line 77 requires Gito wakeup -> local develop fetch -> active Milestone index scan -> slug reconcile enqueue.
- `BranchRevisionScanner.Scan` fetches and verifies remote revision at `services/core/internal/gitosync/scanner.go:113`, then indexes `agent-roadmap/phase` and `agent-roadmap/archive` via `git ls-tree` at `services/core/internal/gitosync/scanner.go:133`.
- `Bridge.Handle` scans and enqueues each doc at `services/core/internal/gitosync/bridge.go:101`.
- Missing identity docs become missing-create jobs at `services/core/internal/gitosync/bridge.go:136`.

#### 해결 방법

- Use focused unit tests to prove scanner and bridge behavior.
- After task 08 delivery, collect Core log or queue evidence showing `EnqueueRoadmapCreationSync` was reached for the accepted delivery.
- If the live queue does not reflect active Milestone scan, patch only the scanner/bridge/wiring path and add a focused regression test in the relevant package.

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

- [ ] `services/core/internal/gitosync/scanner.go`: inspect or patch active index behavior only if live/unit evidence fails.
- [ ] `services/core/internal/gitosync/bridge.go`: inspect or patch enqueue args only if queue evidence is wrong.
- [ ] `services/core/cmd/server/main.go`: inspect or patch bridge wiring only if handler reaches HTTP but not bridge.
- [ ] `CODE_REVIEW-cloud-G06.md`: record unit output and live enqueue/log evidence.

#### 테스트 작성

- Default skip: existing tests cover active index and bridge enqueue.
- If a defect is found, add a regression test to `services/core/internal/gitosync/scanner_test.go`, `services/core/internal/gitosync/bridge_test.go`, or `services/core/cmd/server/main_test.go` matching the defect.

#### 중간 검증

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

Expected: packages pass.

## 의존 관계 및 구현 순서

- Wait for predecessor `08+07_gito_delivery` complete log.
- Then run focused tests, collect queue/log evidence, and only patch if evidence fails.
- Dependent task `10+09_plane_todo` waits for this task's `complete.log`.

## 수정 파일 요약

| 파일 | 항목 |
|------|------|
| `services/core/internal/gitosync/scanner.go` | TEST-1 optional defect fix |
| `services/core/internal/gitosync/bridge.go` | TEST-1 optional defect fix |
| `services/core/cmd/server/main.go` | TEST-1 optional wiring fix |
| `CODE_REVIEW-cloud-G06.md` | TEST-1 evidence |

## 최종 검증

```sh
ssh toki@toki-labs.com 'zsh -lc '\''cd "$HOME/agent-work/nomadcode/services/core" && go test -count=1 ./internal/gitosync ./cmd/server ./internal/scheduler'\'''
```

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 "gito creation sync enqueued|gito missing-create sync enqueued|roadmap_creation_sync|active milestone"'\'''
```

Expected: output shows slug-level creation sync enqueue after the accepted Gito delivery, with archive Milestones not listed as sync targets.

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