<!-- task=m-plane-origin-authoring-roundtrip-sync/08+07_gito_delivery plan=1 tag=REVIEW_TEST -->

# Plan - REVIEW_TEST

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

`CODE_REVIEW-cloud-G07.md`의 구현 에이전트 소유 섹션을 채우는 것까지가 구현이다. 검증을 실행하고 실제 출력과 증거 경로를 붙여 넣은 뒤 active 파일을 그대로 두고 리뷰 준비를 보고한다. SDD 결정 또는 Milestone `구현 잠금 > 결정 필요` 항목이 실구현을 막을 때만 review stub의 `사용자 리뷰 요청`을 채우고 멈춘다. 직접 사용자에게 묻거나 `USER_REVIEW.md`, `complete.log`, archive 로그를 만들지 않는다. secret/service 준비, 증거 공백, 범위 조정은 일반 follow-up으로 기록한다.

## 배경

이 후속 계획은 이전 루프의 소스 구현을 다시 넓히지 않고, `gito-delivery` SDD S13 완료에 필요한 non-secret duplicate result 증거만 보강한다. 이전 루프의 Core webhook 202 로그와 unit test는 유효하지만, duplicate 결과는 raw response/body 또는 동등한 명시 로그로 남지 않았다.

## 사용자 리뷰 요청 흐름

사용자 리뷰 요청은 선택된 SDD 결정 또는 Milestone lock 결정이 있을 때만 active review stub의 `사용자 리뷰 요청` 섹션에 기록한다. 구현 중 직접 질문하거나 선택지를 제시하지 않으며, code-review가 검증 후 실제 `USER_REVIEW.md` 작성 여부를 판단한다.

## Archive Evidence Snapshot

- Current archived plan: `agent-task/m-plane-origin-authoring-roundtrip-sync/08+07_gito_delivery/plan_cloud_G07_0.log`
- Current archived review: `agent-task/m-plane-origin-authoring-roundtrip-sync/08+07_gito_delivery/code_review_cloud_G07_0.log`
- Verdict: FAIL
- Required summary: S13 duplicate handling was labeled in comments, but the raw evidence only showed generic Core `http request` 202 lines. It did not include `{"status":"duplicate"}`, reused delivery id/hash, or equivalent non-secret duplicate result.
- Affected files: `CODE_REVIEW-cloud-G07.md` evidence only; no source file change is planned unless the live duplicate check exposes a concrete defect.
- Reviewer rerun evidence: `ssh toki@toki-labs.com 'zsh -lc '\''cd "$HOME/agent-work/nomadcode/services/core" && docker compose logs --no-color --since=48h nomadcode-core | grep -E "gito http webhook consumer enabled|gito creation sync enqueued|gito missing-create sync enqueued|gito webhook handler failed|/api/integrations/gito/webhook|duplicate"'\'''` showed consumer enabled and generic 202 request logs, but no explicit duplicate result.
- Reviewer rerun evidence: `ssh toki@toki-labs.com 'zsh -lc '\''cd "$HOME/agent-work/nomadcode/services/core" && go test -count=1 ./cmd/server ./internal/http ./internal/gitosync'\'''` passed.
- Narrow reread allowed: the next implementer may read only `agent-task/m-plane-origin-authoring-roundtrip-sync/08+07_gito_delivery/plan_cloud_G07_0.log` and `agent-task/m-plane-origin-authoring-roundtrip-sync/08+07_gito_delivery/code_review_cloud_G07_0.log` from prior loop artifacts.

## Roadmap Targets

- Milestone: `agent-roadmap/phase/agent-ops-mcp-control-plane/milestones/plane-origin-authoring-roundtrip-sync.md`
- Task ids:
  - `gito-delivery`: Forgejo push -> Gito -> Core signed HTTP webhook delivery and duplicate handling
- 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:
  - `S13`: task=`gito-delivery`; evidence=`signed delivery 202, Core log, duplicate result recorded without secret`
- Completion mode: spec-check-on-pass

## 분석 결과

### 읽은 파일

- `agent-task/m-plane-origin-authoring-roundtrip-sync/08+07_gito_delivery/plan_cloud_G07_0.log`
- `agent-task/m-plane-origin-authoring-roundtrip-sync/08+07_gito_delivery/code_review_cloud_G07_0.log`
- `agent-roadmap/sdd/agent-ops-mcp-control-plane/plane-origin-authoring-roundtrip-sync/SDD.md`
- `services/core/internal/http/gito_webhook.go`
- `services/core/internal/http/gito_webhook_test.go`
- `services/core/cmd/server/main.go`
- `services/core/cmd/server/main_test.go`
- `services/core/internal/gitosync/bridge.go`

### 테스트 환경 규칙

- test_env: `local`
- Env rules: `agent-test/local/rules.md`; standard remote runner is the baseline.
- Matched profiles: `agent-test/local/core-smoke.md`, live delivery evidence from `agent-test/live-cycle-smoke.md`.

### 범위 결정 근거

- Scope is evidence-only for S13 duplicate result.
- Do not broaden into `scan-enqueue`, `plane-todo`, or `slot-finalize`; those remain dependent sibling tasks.
- Do not print raw `GITO_WEBHOOK_SECRET`, signatures, Plane tokens, or private payload secrets.
- If the duplicate check exposes a concrete source defect, patch only the directly affected file and rerun the targeted tests.

### 빌드 등급

- `cloud-G07`: live external delivery and duplicate evidence are central and cannot be fully proven by local unit tests.

## 구현 체크리스트

- [ ] Accepted signed Core Gito delivery and duplicate handling are recorded with non-secret target repo/branch/revision, delivery id hash or redacted id, first 202 result, and explicit duplicate 202 result.
- [ ] `gito-delivery` S13 evidence is recorded in `CODE_REVIEW-cloud-G07.md` as actual commands/stdout/stderr, including secret redaction notes and any live side effect note.
- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다.

### [REVIEW_TEST-1] Record Explicit Duplicate Result Evidence

#### 문제

- Previous review evidence at `code_review_cloud_G07_0.log` shows generic Core 202 request logs but no explicit duplicate result.
- `services/core/internal/http/gito_webhook.go` returns `{"status":"duplicate"}` only when the same delivery id or revision key has already been accepted; the previous log does not show that body.
- SDD S13 requires secret-redacted live evidence for signed delivery and duplicate handling.

#### 해결 방법

- Prefer a redelivery/replay of an already accepted Gito delivery, so the request reaches the HTTP duplicate branch before the bridge can enqueue new work.
- If the prior accepted delivery id/body is inaccessible, run a controlled same-delivery-id signed request twice against the Core webhook. Keep the secret only in shell variables, never echo it, and record only the delivery id hash or a redacted id. If the first request is not already duplicate and causes live enqueue side effects, record that explicitly and keep the follow-up evidence scoped to S13.
- The recorded evidence must include the raw second response body or an equivalent explicit result showing `duplicate`, plus HTTP 202.

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

- [ ] `CODE_REVIEW-cloud-G07.md`: record the duplicate evidence command output and redaction notes.
- [ ] `services/core/internal/http/gito_webhook.go`: no planned change; patch only if duplicate evidence exposes a handler defect.
- [ ] `services/core/internal/http/gito_webhook_test.go`: no planned change; patch only if source behavior changes.

#### 테스트 작성

- No new unit tests are required for evidence-only completion. Existing tests already cover signed delivery acceptance and duplicate delivery handling.
- If source behavior changes, add or update the smallest targeted test in `services/core/internal/http/gito_webhook_test.go`.

#### 중간 검증

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

Expected: command exits 0 and all listed packages report `ok`.

## 의존 관계 및 구현 순서

- `08+07_gito_delivery` must remain in this same task directory.
- Dependent task `09+08_scan_enqueue` must wait for this task's `complete.log`.

## 수정 파일 요약

| 파일 | 항목 |
|------|------|
| `CODE_REVIEW-cloud-G07.md` | REVIEW_TEST-1 duplicate evidence 기록 |
| `services/core/internal/http/gito_webhook.go` | 계획 없음; live defect 발견 시에만 최소 수정 |
| `services/core/internal/http/gito_webhook_test.go` | 계획 없음; source 수정 시에만 최소 테스트 수정 |

## 최종 검증

```sh
ssh toki@toki-labs.com 'zsh -lc '\''cd "$HOME/agent-work/nomadcode/services/core" && docker compose logs --no-color --since=48h nomadcode-core | grep -E "gito http webhook consumer enabled|/api/integrations/gito/webhook|gito webhook handler failed|duplicate"'\'''
```

Expected: output shows the enabled consumer and relevant Core webhook request logs with no secret values.

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

Expected: all listed packages pass from remote runner checkout.

Final evidence requirement: `CODE_REVIEW-cloud-G07.md` must include the actual duplicate evidence command/output. The output must show HTTP 202 and an explicit duplicate result such as `{"status":"duplicate"}` or an equivalent non-secret source of truth, plus delivery id hash/redaction and target repo/branch/revision.

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