feat(agent): runner 호환성 검증을 추가한다
Core registry와 Dart runner가 같은 protocol/capability 협상 기준을 적용해야 하므로 registration 거절 응답과 smoke 검증을 함께 보강한다.
This commit is contained in:
parent
e6e383f116
commit
dbe32b5070
9 changed files with 630 additions and 163 deletions
|
|
@ -0,0 +1,284 @@
|
|||
<!-- task=m-agent-message-protocol/02+01_core_compatibility plan=0 tag=API -->
|
||||
|
||||
# Code Review Reference - API
|
||||
|
||||
> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.**
|
||||
> The task is NOT complete until every implementation-owned section below is filled in.
|
||||
> Complete the `구현 체크리스트`; the final checklist item is mandatory before saving.
|
||||
> Fill implementation-owned sections, then stop with active files in place and report ready for review.
|
||||
> If implementation is blocked by a user-only decision, user-owned external environment prerequisite, or scope conflict, fill `사용자 리뷰 요청` with evidence and stop with active files in place; code-review decides whether to write `USER_REVIEW.md`. Evidence gaps that a follow-up agent can close by rerunning commands or collecting artifacts are normal follow-up issues, not user-review blockers by themselves.
|
||||
> Do not ask the user directly, present choices in chat, or call `request_user_input` during implementation; record the needed decision in `사용자 리뷰 요청` and stop for code-review.
|
||||
> Finalization (`코드리뷰 결과`, log rename, `complete.log`, archive moves, `코드리뷰 전용 체크리스트`) is review-agent-only, even after compaction/resume.
|
||||
> Follow the ownership table at the bottom of this file for which sections you own.
|
||||
|
||||
## 개요
|
||||
|
||||
date=2026-06-06
|
||||
task=m-agent-message-protocol/02+01_core_compatibility, plan=0, tag=API
|
||||
|
||||
## Roadmap Targets
|
||||
|
||||
- Milestone: `agent-roadmap/phase/message-based-build-agent/milestones/agent-message-protocol.md`
|
||||
- Task ids:
|
||||
- `version-capability`: 프로토콜 버전과 capability 협상 기준이 정의되어 있다.
|
||||
- Completion mode: check-on-pass
|
||||
|
||||
## 이 파일을 읽는 리뷰 에이전트에게
|
||||
|
||||
> **[REVIEW AGENT ONLY]** 아래 종결 절차는 코드리뷰 에이전트 전용이다. 구현 에이전트는 이 섹션을 실행하지 않는다.
|
||||
|
||||
각 항목의 구현을 실제 소스 파일과 대조하고, `검증 결과` 섹션의 출력이 코드와 일치하는지 확인하세요.
|
||||
리뷰 완료는 아래 순서까지 끝난 상태를 의미합니다.
|
||||
|
||||
1. 판정을 append한다.
|
||||
2. `CODE_REVIEW-cloud-G06.md` -> `code_review_cloud_G06_N.log`, `PLAN-cloud-G06.md` -> `plan_cloud_G06_M.log`로 아카이브한다.
|
||||
3. PASS이면 `complete.log` 작성 후 active task 디렉터리를 `agent-task/archive/YYYY/MM/m-agent-message-protocol/02+01_core_compatibility/`로 이동한다. WARN/FAIL이면 user-review gate를 확인한 뒤 다음 active plan/review 파일 또는 `USER_REVIEW.md`를 작성한다. `USER_REVIEW.md`가 사용자 결정으로 완료/PASS 해소되면 code-review가 `USER_REVIEW.md`를 해소 상태로 갱신하고 `complete.log` 작성 후 archive 이동한다.
|
||||
4. PASS이고 task group이 `m-<milestone-slug>`이면 완료 이벤트 메타데이터를 보고한다. roadmap 상태 체크와 `update-roadmap` 호출은 런타임 책임이다.
|
||||
5. 적용 가능한 `코드리뷰 전용 체크리스트` 항목을 최종 `.log` 위치에서 체크한 뒤 보고한다.
|
||||
|
||||
---
|
||||
|
||||
## 구현 항목별 완료 여부
|
||||
|
||||
| 항목 | 완료 여부 |
|
||||
|------|---------|
|
||||
| [API-1] Core registry compatibility policy | [x] |
|
||||
| [API-2] HTTP and Dart registration contract | [x] |
|
||||
|
||||
## 구현 체크리스트
|
||||
|
||||
- [x] `agent-task/m-agent-message-protocol/01_proto_contract/complete.log` 또는 matching archive complete.log가 있는지 확인하고, 없으면 구현하지 않고 review stub의 사용자 리뷰 요청이 아니라 dependency 대기 상태로 기록한다.
|
||||
- [x] Core registry에 supported protocol/capability 정책을 추가하고 reject reason과 structured error를 함께 채운다.
|
||||
- [x] HTTP registration handler와 tests가 새 reject response를 JSON으로 보존하는지 확인한다.
|
||||
- [x] Dart runner registration constants와 JSON payload tests를 Core policy와 맞춘다.
|
||||
- [x] 최종 검증 명령을 실행하고 실제 stdout/stderr를 review stub에 기록한다.
|
||||
- [x] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다.
|
||||
|
||||
## 코드리뷰 전용 체크리스트
|
||||
|
||||
> **[REVIEW AGENT ONLY]** 이 체크리스트는 코드리뷰 에이전트만 사용한다.
|
||||
> 구현 에이전트는 이 섹션을 수정하거나 체크하지 않는다.
|
||||
|
||||
- [x] `코드리뷰 결과`에 `PASS`, `WARN`, `FAIL` 중 하나의 판정을 append한다.
|
||||
- [x] 판정과 `차원별 평가`, Required/Suggested/Nit 분류가 서로 일치한다.
|
||||
- [x] active `CODE_REVIEW-*-G??.md`를 `code_review_cloud_G06_N.log`로 아카이브한다.
|
||||
- [x] active `PLAN-*-G??.md`를 `plan_cloud_G06_M.log`로 아카이브한다.
|
||||
- [x] `.gitignore`의 Agent-Ops 관리 block이 `agent-task/**/*.md`와 `agent-task/**/*.log`를 unignore하고 `agent-roadmap/current.md`를 ignore하는지 확인한다.
|
||||
- [x] PASS이면 `agent-ops/skills/common/code-review/templates/complete-log-template.md` 기준으로 `complete.log`를 작성하고 active `.md` 파일을 남기지 않는다.
|
||||
- [x] PASS이면 active task 디렉터리 `agent-task/m-agent-message-protocol/02+01_core_compatibility/`를 `agent-task/archive/YYYY/MM/m-agent-message-protocol/02+01_core_compatibility/`로 이동하고 최종 archive 경로에서 이 체크리스트를 갱신한다.
|
||||
- [x] PASS이고 task group이 `m-<milestone-slug>`이면 런타임이 읽을 완료 이벤트 메타데이터를 보고하고, roadmap 수정이나 `update-roadmap` 직접 호출을 하지 않는다.
|
||||
- [x] PASS split 작업이면 이동 후 빈 active parent `agent-task/m-agent-message-protocol/`를 제거하거나, 남은 sibling/file이 있어 유지했다고 확인한다.
|
||||
- [ ] WARN/FAIL이고 user-review gate가 트리거되지 않았으면 다음 active `PLAN-cloud-G06.md`와 `CODE_REVIEW-cloud-G06.md`를 작성하고 `complete.log`를 작성하지 않는다.
|
||||
- [ ] USER_REVIEW이면 `agent-ops/skills/common/code-review/templates/user-review-template.md` 기준으로 `USER_REVIEW.md`를 작성하고 active `PLAN-*.md`, `CODE_REVIEW-*.md`, `complete.log`를 남기지 않는다.
|
||||
- [ ] USER_REVIEW가 사용자 결정으로 완료/PASS 해소되면 `USER_REVIEW.md`를 해소 상태로 갱신하고 `complete.log`를 작성한 뒤 task directory를 archive로 이동한다.
|
||||
|
||||
## 계획 대비 변경 사항
|
||||
|
||||
- 없음. 계획대로 정확히 수행됨.
|
||||
|
||||
## 주요 설계 결정
|
||||
|
||||
- Go Core Registry (`services/core/internal/runnerregistry`) 내부에 `validateProtocolCompatibility` 헬퍼 함수를 구현하여, `oto.runner.v1` 프로토콜 여부, 필수 capability 이름 `oto-runner` 및 major version이 `1`로 시작하는지 (`1.x.x` 등) 여부를 stdlib을 활용해 검증하도록 설계함.
|
||||
- HTTP runner register handler (`services/core/internal/httpserver`)에서 JSON parsing 에러 시에도 동일하게 구조화된 ProtocolError를 응답하도록 예외 처리를 확장함.
|
||||
|
||||
## 사용자 리뷰 요청
|
||||
|
||||
_기본값은 `없음`이다. 구현 중 사용자 결정, 사용자 소유 외부 환경/secret/서비스 준비, 또는 계획 범위 변경 없이는 안전하게 진행할 수 없으면 아래 항목을 실제 내용으로 교체하고, 구현을 중단한 뒤 active 파일을 그대로 둔 채 리뷰를 요청한다. 구현 에이전트는 사용자에게 직접 질문하거나 선택지를 제시하거나 `request_user_input`을 호출하지 않는다. 후속 에이전트가 명령 재실행이나 산출물 수집으로 해소할 수 있는 검증 증거 공백만으로는 사용자 리뷰 요청을 작성하지 않는다._
|
||||
|
||||
- 상태: 없음
|
||||
- 사유 유형: 없음
|
||||
- 결정 필요: 없음
|
||||
- 차단 근거: 없음
|
||||
- 실행한 검증/명령: 없음
|
||||
- 자동 후속 불가 이유: 없음
|
||||
- 재개 조건: 없음
|
||||
|
||||
## 리뷰어를 위한 체크포인트
|
||||
|
||||
- `01_proto_contract`의 `complete.log`가 실제로 존재하고 predecessor로 인용되었는지 확인한다.
|
||||
- unsupported protocol/capability가 accepted=false로 거절되고 기존 accepted path가 유지되는지 확인한다.
|
||||
- Dart runner constants와 Core policy가 drift 없이 같은 값을 쓰는지 확인한다.
|
||||
- `remote-run-lifecycle` 범위인 cancel/status/self-update 동작 구현이 이 plan에 섞이지 않았는지 확인한다.
|
||||
|
||||
## 검증 결과
|
||||
|
||||
_구현 에이전트가 각 중간 검증 및 최종 검증 명령 실행 후 출력을 여기에 붙여 넣는다._
|
||||
|
||||
필수 규칙:
|
||||
- 검증 명령은 고정된 계약이다. 임의로 대체하지 않는다.
|
||||
- 대체가 필요하면 `계획 대비 변경 사항`에 이유와 대체 명령을 기록한다.
|
||||
- `검증 결과`에는 실제 stdout/stderr를 붙여 넣는다.
|
||||
- 사용자 리뷰 요청으로 명령을 끝까지 실행하지 못했다면 `사용자 리뷰 요청`에 실행한 명령, 실제 출력, 미실행 명령의 사유를 기록한다.
|
||||
- mobile/UI hang, timeout, 또는 2분 무진행은 blind retry를 중단하고 focused rerun 명령과 screenshot/window/UI-tree evidence path를 남기며, 불가능하면 정확한 사유를 남긴다.
|
||||
|
||||
### API-1 중간 검증
|
||||
```bash
|
||||
$ cd services/core && go test ./internal/runnerregistry
|
||||
ok github.com/toki/oto/services/core/internal/runnerregistry 0.003s
|
||||
```
|
||||
|
||||
### API-2 중간 검증
|
||||
```bash
|
||||
$ cd services/core && go test ./internal/httpserver ./internal/runnerregistry
|
||||
ok github.com/toki/oto/services/core/internal/httpserver 0.005s
|
||||
ok github.com/toki/oto/services/core/internal/runnerregistry 0.003s
|
||||
|
||||
$ cd apps/runner && dart test test/oto_agent_registration_test.dart
|
||||
00:00 +0: loading test/oto_agent_registration_test.dart
|
||||
00:00 +0: EdgeEndpoint EdgeEndpoint parses host and port from config edge url
|
||||
00:00 +1: EdgeEndpoint EdgeEndpoint parses host and port from config edge url
|
||||
00:00 +1: EdgeRegistrationClient.register ... result and closes the session
|
||||
00:00 +2: EdgeRegistrationClient.register ... result and closes the session
|
||||
00:00 +2: ... builds OTO Server registration request from config
|
||||
00:00 +3: OtoServerRegistrationClient ... request to OTO Server endpoint
|
||||
00:00 +4: OtoServerRegistrationClient ... request to OTO Server endpoint
|
||||
00:00 +4: ... registration client handles incompatible runner error response
|
||||
00:00 +5: ... registration client handles incompatible runner error response
|
||||
00:00 +5: OtoServerRegistrationClient ... heartbeat and disconnects on close
|
||||
00:00 +6: OtoServerRegistrationClient ... heartbeat and disconnects on close
|
||||
00:00 +6: ... does not send heartbeat or disconnect on rejected registration
|
||||
00:00 +7: ... does not send heartbeat or disconnect on rejected registration
|
||||
00:00 +7: OtoServerRegistrationClient session close cancels future heartbeats
|
||||
00:01 +7: OtoServerRegistrationClient session close cancels future heartbeats
|
||||
00:01 +8: OtoServerRegistrationClient session close cancels future heartbeats
|
||||
00:01 +8: OtoServerRegistrationClient ... claims jobs and reports build results
|
||||
00:01 +9: OtoServerRegistrationClient ... claims jobs and reports build results
|
||||
00:01 +9: ... protocol exposes run, cancel, status, self-update message fields
|
||||
00:01 +10: ... exposes run, cancel, status, self-update message fields
|
||||
00:01 +10: ... client fallback error parsing from ProtocolError map object
|
||||
00:01 +11: ... client fallback error parsing from ProtocolError map object
|
||||
00:01 +11: ... job client fallback error parsing from ProtocolError map object
|
||||
00:01 +12: ... job client fallback error parsing from ProtocolError map object
|
||||
00:01 +12: AgentRunner AgentRunner maps config token to register request
|
||||
00:01 +13: AgentRunner AgentRunner maps config token to register request
|
||||
00:01 +13: AgentRunner ... keeps session open until shutdown then closes
|
||||
00:01 +14: AgentRunner ... keeps session open until shutdown then closes
|
||||
00:01 +14: AgentRunner AgentRunner runs injected job loop after registration
|
||||
00:01 +16: All tests passed!
|
||||
```
|
||||
|
||||
### 최종 검증
|
||||
```bash
|
||||
$ test -f agent-task/m-agent-message-protocol/01_proto_contract/complete.log || find agent-task/archive -path '*/m-agent-message-protocol/01_proto_contract/complete.log' -print -quit | grep -q .
|
||||
agent-task/archive/2026/06/m-agent-message-protocol/01_proto_contract/complete.log
|
||||
|
||||
$ cd services/core && go test ./...
|
||||
? github.com/toki/oto/services/core/cmd/oto-core [no test files]
|
||||
ok github.com/toki/oto/services/core/internal/cicdstate 0.002s
|
||||
ok github.com/toki/oto/services/core/internal/httpserver 0.005s
|
||||
ok github.com/toki/oto/services/core/internal/runnerregistry 0.003s
|
||||
? github.com/toki/oto/services/core/oto [no test files]
|
||||
|
||||
$ cd apps/runner && dart analyze
|
||||
Analyzing runner...
|
||||
No issues found!
|
||||
|
||||
$ cd apps/runner && dart test test/oto_agent_migration_plan_test.dart test/oto_agent_bootstrap_script_test.dart test/oto_agent_cli_test.dart test/oto_agent_config_test.dart test/oto_agent_registration_test.dart test/oto_server_connection_smoke_test.dart
|
||||
00:00 +0: loading test/oto_agent_migration_plan_test.dart
|
||||
00:00 +0: ... plan keeps the existing iop smoke as legacy source evidence only
|
||||
00:00 +1: ... Linux Bootstrap Script Contract Tests (setUpAll)
|
||||
00:00 +2: ... Linux Bootstrap Script Contract Tests (setUpAll)
|
||||
00:00 +3: ... Linux Bootstrap Script Contract Tests (setUpAll)
|
||||
00:00 +3: ... Bootstrap Script Contract Tests should contain required flags
|
||||
00:00 +4: ... Bootstrap Script Contract Tests should contain required flags
|
||||
00:00 +6: ... Script Contract Tests should support correct architecture assets
|
||||
00:00 +6: ... Contract Tests should write expected keys to configuration yaml
|
||||
00:00 +7: ... should contain agent runtime commands and background behavior
|
||||
00:00 +8: test/oto_agent_bootstrap_script_test.dart: ... base URL is not HTTPS
|
||||
00:00 +9: test/oto_agent_bootstrap_script_test.dart: ... base URL is not HTTPS
|
||||
00:00 +9: ... standard agent state path when custom config-path is specified
|
||||
00:00 +10: ... standard agent state path when custom config-path is specified
|
||||
00:00 +11: ... standard agent state path when custom config-path is specified
|
||||
00:00 +13: ... standard agent state path when custom config-path is specified
|
||||
00:00 +14: ... standard agent state path when custom config-path is specified
|
||||
00:00 +15: ... standard agent state path when custom config-path is specified
|
||||
00:00 +16: ... standard agent state path when custom config-path is specified
|
||||
00:00 +17: ... standard agent state path when custom config-path is specified
|
||||
00:00 +18: ... standard agent state path when custom config-path is specified
|
||||
00:00 +20: ... standard agent state path when custom config-path is specified
|
||||
00:00 +21: ... standard agent state path when custom config-path is specified
|
||||
00:00 +22: ... standard agent state path when custom config-path is specified
|
||||
00:00 +23: ... standard agent state path when custom config-path is specified
|
||||
00:00 +24: ... standard agent state path when custom config-path is specified
|
||||
00:00 +25: ... standard agent state path when custom config-path is specified
|
||||
00:00 +26: ... standard agent state path when custom config-path is specified
|
||||
00:00 +27: ... standard agent state path when custom config-path is specified
|
||||
00:00 +28: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:00 +29: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:00 +30: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:00 +31: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:00 +32: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:01 +32: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:01 +33: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:01 +34: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:01 +35: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:01 +36: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:01 +37: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:01 +38: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:01 +39: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:01 +42: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:01 +43: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:02 +43: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:02 +44: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:02 +45: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:03 +45: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:04 +45: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:04 +46: test/oto_agent_cli_test.dart: actual bin agent help lists run usage
|
||||
00:04 +46: test/oto_agent_cli_test.dart: actual bin agent run help works
|
||||
00:05 +46: test/oto_agent_cli_test.dart: actual bin agent run help works
|
||||
00:06 +46: test/oto_agent_cli_test.dart: actual bin agent run help works
|
||||
00:07 +46: test/oto_agent_cli_test.dart: actual bin agent run help works
|
||||
00:07 +47: test/oto_agent_cli_test.dart: actual bin agent run help works
|
||||
00:07 +47: test/oto_agent_cli_test.dart: ... with no parameters shows root help
|
||||
00:08 +47: test/oto_agent_cli_test.dart: ... with no parameters shows root help
|
||||
00:09 +47: test/oto_agent_cli_test.dart: ... with no parameters shows root help
|
||||
00:10 +47: test/oto_agent_cli_test.dart: ... with no parameters shows root help
|
||||
00:10 +48: test/oto_agent_cli_test.dart: ... with no parameters shows root help
|
||||
00:10 +48: All tests passed!
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section: completion table, implementation checklist, changes from plan, design decisions, and verification output?**
|
||||
> If anything is blank, go back and fill it in before saving this file.
|
||||
> Leave review-agent-only sections unchanged.
|
||||
|
||||
## 섹션 소유권
|
||||
|
||||
| Section | Owner | Note |
|
||||
|---------|-------|------|
|
||||
| Header comment, 개요, 리뷰 에이전트 지시 | Fixed at stub creation | Implementing agent must not modify or execute archive/complete steps |
|
||||
| Roadmap Targets | Fixed at stub creation | Code-review copies it into `complete.log` only on PASS |
|
||||
| 구현 항목별 완료 여부 | Implementing agent | Check `[ ]` to `[x]` only |
|
||||
| 구현 체크리스트 | Implementing agent | Preserve item text and order |
|
||||
| 코드리뷰 전용 체크리스트 | Review agent only | Implementing agent must not modify |
|
||||
| 계획 대비 변경 사항, 주요 설계 결정 | Implementing agent | Replace placeholders with actual notes |
|
||||
| 사용자 리뷰 요청 | Implementing agent | Keep `상태: 없음` unless a justified blocker exists |
|
||||
| 리뷰어를 위한 체크포인트 | Fixed at stub creation | Review focus only |
|
||||
| 검증 결과 | Implementing agent | Paste actual stdout/stderr |
|
||||
|
||||
## 코드리뷰 결과
|
||||
|
||||
### 종합 판정
|
||||
|
||||
PASS
|
||||
|
||||
### 차원별 평가
|
||||
|
||||
| 차원 | 평가 | 근거 |
|
||||
|------|------|------|
|
||||
| correctness | Pass | Registry가 `oto.runner.v1`, `oto-runner`, capability major `1` 기준으로 등록을 거절/수락하고 HTTP 응답도 `accepted=false`와 structured error를 유지한다. |
|
||||
| completeness | Pass | 계획의 predecessor 확인, Core registry policy, HTTP response, Dart payload/response parsing, 최종 검증 기록이 모두 채워졌다. |
|
||||
| test coverage | Pass | Go registry/httpserver rejection tests와 Dart registration response/payload tests가 추가됐고 agent smoke baseline을 재실행했다. |
|
||||
| API contract | Pass | proto의 `RegisterRunnerRequest`/`RegisterRunnerResponse` 필드 계약과 Go/Dart JSON key 사용이 일치한다. |
|
||||
| code quality | Pass | 변경 범위가 helper와 focused tests에 한정되어 있고 디버그 출력, TODO, unrelated edit가 없다. |
|
||||
| plan deviation | Pass | 계획 범위를 벗어난 run/cancel/status/self-update 구현 변경이 없다. |
|
||||
| verification trust | Pass | 리뷰 중 동일 범위 검증을 재실행했고 `go test ./...`, `dart analyze`, agent smoke test가 통과했다. |
|
||||
|
||||
### 발견된 문제
|
||||
|
||||
없음
|
||||
|
||||
### 다음 단계
|
||||
|
||||
PASS: active `PLAN-cloud-G06.md`와 `CODE_REVIEW-cloud-G06.md`를 log로 아카이브하고 `complete.log` 작성 후 task directory를 `agent-task/archive/2026/06/m-agent-message-protocol/02+01_core_compatibility/`로 이동한다.
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
# Complete - m-agent-message-protocol/02+01_core_compatibility
|
||||
|
||||
## 완료 일시
|
||||
|
||||
2026-06-06
|
||||
|
||||
## 요약
|
||||
|
||||
프로토콜/캡빌리티 협상 기준을 Core registry와 Dart runner registration contract에 맞춘 첫 리뷰 루프를 PASS로 종료했다.
|
||||
|
||||
## 루프 이력
|
||||
|
||||
| Plan | Review | Verdict | 메모 |
|
||||
|------|--------|---------|------|
|
||||
| `plan_cloud_G06_0.log` | `code_review_cloud_G06_0.log` | PASS | Required/Suggested 없음. Core/Dart registration contract 검증 통과. |
|
||||
|
||||
## 구현/정리 내용
|
||||
|
||||
- Core runner registry가 `oto.runner.v1`, capability name `oto-runner`, capability major version `1` 기준으로 incompatible runner registration을 structured error와 함께 거절하도록 했다.
|
||||
- HTTP runner registration response가 registry reject response의 `reject_reason`과 `error` object를 JSON으로 보존하는지 테스트했다.
|
||||
- Dart runner registration payload가 Core policy와 같은 protocol/capability 값을 보내고, incompatible runner error response를 안정적으로 파싱하는지 테스트했다.
|
||||
|
||||
## 최종 검증
|
||||
|
||||
- `test -f agent-task/m-agent-message-protocol/01_proto_contract/complete.log || find agent-task/archive -path '*/m-agent-message-protocol/01_proto_contract/complete.log' -print -quit | grep -q .` - PASS; predecessor complete evidence 확인.
|
||||
- `go test ./...` in `services/core` - PASS; `cmd/oto-core`와 `oto`는 test file 없음, `internal/cicdstate`, `internal/httpserver`, `internal/runnerregistry` 통과.
|
||||
- `dart analyze` in `apps/runner` - PASS; `No issues found!`.
|
||||
- `dart test test/oto_agent_migration_plan_test.dart test/oto_agent_bootstrap_script_test.dart test/oto_agent_cli_test.dart test/oto_agent_config_test.dart test/oto_agent_registration_test.dart test/oto_server_connection_smoke_test.dart` in `apps/runner` - PASS; `All tests passed!`.
|
||||
|
||||
## Roadmap Completion
|
||||
|
||||
- Milestone: `agent-roadmap/phase/message-based-build-agent/milestones/agent-message-protocol.md`
|
||||
- Completed task ids:
|
||||
- `version-capability`: PASS; evidence=`agent-task/archive/2026/06/m-agent-message-protocol/02+01_core_compatibility/plan_cloud_G06_0.log`, `agent-task/archive/2026/06/m-agent-message-protocol/02+01_core_compatibility/code_review_cloud_G06_0.log`; verification=`go test ./...`, `dart analyze`, `dart test test/oto_agent_migration_plan_test.dart test/oto_agent_bootstrap_script_test.dart test/oto_agent_cli_test.dart test/oto_agent_config_test.dart test/oto_agent_registration_test.dart test/oto_server_connection_smoke_test.dart`
|
||||
- Not completed task ids: 없음
|
||||
|
||||
## 잔여 Nit
|
||||
|
||||
- 없음
|
||||
|
||||
## 후속 작업
|
||||
|
||||
- 없음
|
||||
|
|
@ -1,161 +0,0 @@
|
|||
<!-- task=m-agent-message-protocol/02+01_core_compatibility plan=0 tag=API -->
|
||||
|
||||
# Code Review Reference - API
|
||||
|
||||
> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.**
|
||||
> The task is NOT complete until every implementation-owned section below is filled in.
|
||||
> Complete the `구현 체크리스트`; the final checklist item is mandatory before saving.
|
||||
> Fill implementation-owned sections, then stop with active files in place and report ready for review.
|
||||
> If implementation is blocked by a user-only decision, user-owned external environment prerequisite, or scope conflict, fill `사용자 리뷰 요청` with evidence and stop with active files in place; code-review decides whether to write `USER_REVIEW.md`. Evidence gaps that a follow-up agent can close by rerunning commands or collecting artifacts are normal follow-up issues, not user-review blockers by themselves.
|
||||
> Do not ask the user directly, present choices in chat, or call `request_user_input` during implementation; record the needed decision in `사용자 리뷰 요청` and stop for code-review.
|
||||
> Finalization (`코드리뷰 결과`, log rename, `complete.log`, archive moves, `코드리뷰 전용 체크리스트`) is review-agent-only, even after compaction/resume.
|
||||
> Follow the ownership table at the bottom of this file for which sections you own.
|
||||
|
||||
## 개요
|
||||
|
||||
date=2026-06-06
|
||||
task=m-agent-message-protocol/02+01_core_compatibility, plan=0, tag=API
|
||||
|
||||
## Roadmap Targets
|
||||
|
||||
- Milestone: `agent-roadmap/phase/message-based-build-agent/milestones/agent-message-protocol.md`
|
||||
- Task ids:
|
||||
- `version-capability`: 프로토콜 버전과 capability 협상 기준이 정의되어 있다.
|
||||
- Completion mode: check-on-pass
|
||||
|
||||
## 이 파일을 읽는 리뷰 에이전트에게
|
||||
|
||||
> **[REVIEW AGENT ONLY]** 아래 종결 절차는 코드리뷰 에이전트 전용이다. 구현 에이전트는 이 섹션을 실행하지 않는다.
|
||||
|
||||
각 항목의 구현을 실제 소스 파일과 대조하고, `검증 결과` 섹션의 출력이 코드와 일치하는지 확인하세요.
|
||||
리뷰 완료는 아래 순서까지 끝난 상태를 의미합니다.
|
||||
|
||||
1. 판정을 append한다.
|
||||
2. `CODE_REVIEW-cloud-G06.md` -> `code_review_cloud_G06_N.log`, `PLAN-cloud-G06.md` -> `plan_cloud_G06_M.log`로 아카이브한다.
|
||||
3. PASS이면 `complete.log` 작성 후 active task 디렉터리를 `agent-task/archive/YYYY/MM/m-agent-message-protocol/02+01_core_compatibility/`로 이동한다. WARN/FAIL이면 user-review gate를 확인한 뒤 다음 active plan/review 파일 또는 `USER_REVIEW.md`를 작성한다. `USER_REVIEW.md`가 사용자 결정으로 완료/PASS 해소되면 code-review가 `USER_REVIEW.md`를 해소 상태로 갱신하고 `complete.log` 작성 후 archive 이동한다.
|
||||
4. PASS이고 task group이 `m-<milestone-slug>`이면 완료 이벤트 메타데이터를 보고한다. roadmap 상태 체크와 `update-roadmap` 호출은 런타임 책임이다.
|
||||
5. 적용 가능한 `코드리뷰 전용 체크리스트` 항목을 최종 `.log` 위치에서 체크한 뒤 보고한다.
|
||||
|
||||
---
|
||||
|
||||
## 구현 항목별 완료 여부
|
||||
|
||||
| 항목 | 완료 여부 |
|
||||
|------|---------|
|
||||
| [API-1] Core registry compatibility policy | [ ] |
|
||||
| [API-2] HTTP and Dart registration contract | [ ] |
|
||||
|
||||
## 구현 체크리스트
|
||||
|
||||
- [ ] `agent-task/m-agent-message-protocol/01_proto_contract/complete.log` 또는 matching archive complete.log가 있는지 확인하고, 없으면 구현하지 않고 review stub의 사용자 리뷰 요청이 아니라 dependency 대기 상태로 기록한다.
|
||||
- [ ] Core registry에 supported protocol/capability 정책을 추가하고 reject reason과 structured error를 함께 채운다.
|
||||
- [ ] HTTP registration handler와 tests가 새 reject response를 JSON으로 보존하는지 확인한다.
|
||||
- [ ] Dart runner registration constants와 JSON payload tests를 Core policy와 맞춘다.
|
||||
- [ ] 최종 검증 명령을 실행하고 실제 stdout/stderr를 review stub에 기록한다.
|
||||
- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다.
|
||||
|
||||
## 코드리뷰 전용 체크리스트
|
||||
|
||||
> **[REVIEW AGENT ONLY]** 이 체크리스트는 코드리뷰 에이전트만 사용한다.
|
||||
> 구현 에이전트는 이 섹션을 수정하거나 체크하지 않는다.
|
||||
|
||||
- [ ] `코드리뷰 결과`에 `PASS`, `WARN`, `FAIL` 중 하나의 판정을 append한다.
|
||||
- [ ] 판정과 `차원별 평가`, Required/Suggested/Nit 분류가 서로 일치한다.
|
||||
- [ ] active `CODE_REVIEW-*-G??.md`를 `code_review_cloud_G06_N.log`로 아카이브한다.
|
||||
- [ ] active `PLAN-*-G??.md`를 `plan_cloud_G06_M.log`로 아카이브한다.
|
||||
- [ ] `.gitignore`의 Agent-Ops 관리 block이 `agent-task/**/*.md`와 `agent-task/**/*.log`를 unignore하고 `agent-roadmap/current.md`를 ignore하는지 확인한다.
|
||||
- [ ] PASS이면 `agent-ops/skills/common/code-review/templates/complete-log-template.md` 기준으로 `complete.log`를 작성하고 active `.md` 파일을 남기지 않는다.
|
||||
- [ ] PASS이면 active task 디렉터리 `agent-task/m-agent-message-protocol/02+01_core_compatibility/`를 `agent-task/archive/YYYY/MM/m-agent-message-protocol/02+01_core_compatibility/`로 이동하고 최종 archive 경로에서 이 체크리스트를 갱신한다.
|
||||
- [ ] PASS이고 task group이 `m-<milestone-slug>`이면 런타임이 읽을 완료 이벤트 메타데이터를 보고하고, roadmap 수정이나 `update-roadmap` 직접 호출을 하지 않는다.
|
||||
- [ ] PASS split 작업이면 이동 후 빈 active parent `agent-task/m-agent-message-protocol/`를 제거하거나, 남은 sibling/file이 있어 유지했다고 확인한다.
|
||||
- [ ] WARN/FAIL이고 user-review gate가 트리거되지 않았으면 다음 active `PLAN-cloud-G06.md`와 `CODE_REVIEW-cloud-G06.md`를 작성하고 `complete.log`를 작성하지 않는다.
|
||||
- [ ] USER_REVIEW이면 `agent-ops/skills/common/code-review/templates/user-review-template.md` 기준으로 `USER_REVIEW.md`를 작성하고 active `PLAN-*.md`, `CODE_REVIEW-*.md`, `complete.log`를 남기지 않는다.
|
||||
- [ ] USER_REVIEW가 사용자 결정으로 완료/PASS 해소되면 `USER_REVIEW.md`를 해소 상태로 갱신하고 `complete.log`를 작성한 뒤 task directory를 archive로 이동한다.
|
||||
|
||||
## 계획 대비 변경 사항
|
||||
|
||||
_구현 에이전트가 계획과 다르게 구현한 부분을 이유와 함께 기록한다._
|
||||
|
||||
## 주요 설계 결정
|
||||
|
||||
_구현 에이전트가 주요 설계 결정 사항을 기록한다._
|
||||
|
||||
## 사용자 리뷰 요청
|
||||
|
||||
_기본값은 `없음`이다. 구현 중 사용자 결정, 사용자 소유 외부 환경/secret/서비스 준비, 또는 계획 범위 변경 없이는 안전하게 진행할 수 없으면 아래 항목을 실제 내용으로 교체하고, 구현을 중단한 뒤 active 파일을 그대로 둔 채 리뷰를 요청한다. 구현 에이전트는 사용자에게 직접 질문하거나 선택지를 제시하거나 `request_user_input`을 호출하지 않는다. 후속 에이전트가 명령 재실행이나 산출물 수집으로 해소할 수 있는 검증 증거 공백만으로는 사용자 리뷰 요청을 작성하지 않는다._
|
||||
|
||||
- 상태: 없음
|
||||
- 사유 유형: 없음
|
||||
- 결정 필요: 없음
|
||||
- 차단 근거: 없음
|
||||
- 실행한 검증/명령: 없음
|
||||
- 자동 후속 불가 이유: 없음
|
||||
- 재개 조건: 없음
|
||||
|
||||
## 리뷰어를 위한 체크포인트
|
||||
|
||||
- `01_proto_contract`의 `complete.log`가 실제로 존재하고 predecessor로 인용되었는지 확인한다.
|
||||
- unsupported protocol/capability가 accepted=false로 거절되고 기존 accepted path가 유지되는지 확인한다.
|
||||
- Dart runner constants와 Core policy가 drift 없이 같은 값을 쓰는지 확인한다.
|
||||
- `remote-run-lifecycle` 범위인 cancel/status/self-update 동작 구현이 이 plan에 섞이지 않았는지 확인한다.
|
||||
|
||||
## 검증 결과
|
||||
|
||||
_구현 에이전트가 각 중간 검증 및 최종 검증 명령 실행 후 출력을 여기에 붙여 넣는다._
|
||||
|
||||
필수 규칙:
|
||||
- 검증 명령은 고정된 계약이다. 임의로 대체하지 않는다.
|
||||
- 대체가 필요하면 `계획 대비 변경 사항`에 이유와 대체 명령을 기록한다.
|
||||
- `검증 결과`에는 실제 stdout/stderr를 붙여 넣는다.
|
||||
- 사용자 리뷰 요청으로 명령을 끝까지 실행하지 못했다면 `사용자 리뷰 요청`에 실행한 명령, 실제 출력, 미실행 명령의 사유를 기록한다.
|
||||
- mobile/UI hang, timeout, 또는 2분 무진행은 blind retry를 중단하고 focused rerun 명령과 screenshot/window/UI-tree evidence path를 남기며, 불가능하면 정확한 사유를 남긴다.
|
||||
|
||||
### API-1 중간 검증
|
||||
```bash
|
||||
$ cd services/core && go test ./internal/runnerregistry
|
||||
(output)
|
||||
```
|
||||
|
||||
### API-2 중간 검증
|
||||
```bash
|
||||
$ cd services/core && go test ./internal/httpserver ./internal/runnerregistry
|
||||
(output)
|
||||
|
||||
$ cd apps/runner && dart test test/oto_agent_registration_test.dart
|
||||
(output)
|
||||
```
|
||||
|
||||
### 최종 검증
|
||||
```bash
|
||||
$ test -f agent-task/m-agent-message-protocol/01_proto_contract/complete.log || find agent-task/archive -path '*/m-agent-message-protocol/01_proto_contract/complete.log' -print -quit | grep -q .
|
||||
(output)
|
||||
|
||||
$ cd services/core && go test ./...
|
||||
(output)
|
||||
|
||||
$ cd apps/runner && dart analyze
|
||||
(output)
|
||||
|
||||
$ cd apps/runner && dart test test/oto_agent_migration_plan_test.dart test/oto_agent_bootstrap_script_test.dart test/oto_agent_cli_test.dart test/oto_agent_config_test.dart test/oto_agent_registration_test.dart test/oto_server_connection_smoke_test.dart
|
||||
(output)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section: completion table, implementation checklist, changes from plan, design decisions, and verification output?**
|
||||
> If anything is blank, go back and fill it in before saving this file.
|
||||
> Leave review-agent-only sections unchanged.
|
||||
|
||||
## 섹션 소유권
|
||||
|
||||
| Section | Owner | Note |
|
||||
|---------|-------|------|
|
||||
| Header comment, 개요, 리뷰 에이전트 지시 | Fixed at stub creation | Implementing agent must not modify or execute archive/complete steps |
|
||||
| Roadmap Targets | Fixed at stub creation | Code-review copies it into `complete.log` only on PASS |
|
||||
| 구현 항목별 완료 여부 | Implementing agent | Check `[ ]` to `[x]` only |
|
||||
| 구현 체크리스트 | Implementing agent | Preserve item text and order |
|
||||
| 코드리뷰 전용 체크리스트 | Review agent only | Implementing agent must not modify |
|
||||
| 계획 대비 변경 사항, 주요 설계 결정 | Implementing agent | Replace placeholders with actual notes |
|
||||
| 사용자 리뷰 요청 | Implementing agent | Keep `상태: 없음` unless a justified blocker exists |
|
||||
| 리뷰어를 위한 체크포인트 | Fixed at stub creation | Review focus only |
|
||||
| 검증 결과 | Implementing agent | Paste actual stdout/stderr |
|
||||
|
|
@ -158,6 +158,7 @@ runtime:
|
|||
expect(payload['alias'], 'my-agent');
|
||||
expect(payload['protocol_version'], otoRunnerProtocolVersion);
|
||||
expect(payload['capability'], containsPair('name', 'oto-runner'));
|
||||
expect(payload['capability'], containsPair('version', otoRunnerCapabilityVersion));
|
||||
expect(
|
||||
payload['command_catalog'],
|
||||
containsPair('command_types', ['Shell', 'Git']),
|
||||
|
|
@ -168,6 +169,45 @@ runtime:
|
|||
}
|
||||
});
|
||||
|
||||
test('registration client handles incompatible runner error response', () async {
|
||||
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
|
||||
final serverSub = server.listen((request) async {
|
||||
request.response
|
||||
..headers.contentType = ContentType.json
|
||||
..write(
|
||||
jsonEncode({
|
||||
'accepted': false,
|
||||
'reject_reason': 'unsupported protocol version: "oto.runner.v2"',
|
||||
'error': {
|
||||
'code': 'incompatible_runner',
|
||||
'message': 'unsupported protocol version: "oto.runner.v2"',
|
||||
}
|
||||
}),
|
||||
);
|
||||
await request.response.close();
|
||||
});
|
||||
|
||||
try {
|
||||
final config = AgentConfig(
|
||||
agent: validConfig.agent,
|
||||
server: ServerConnectionConfig(
|
||||
url: 'http://${server.address.host}:${server.port}',
|
||||
),
|
||||
runtime: validConfig.runtime,
|
||||
);
|
||||
final client = OtoServerRegistrationClient(
|
||||
commandTypes: ['Shell', 'Git'],
|
||||
);
|
||||
|
||||
final result = await client.register(config);
|
||||
expect(result.accepted, isFalse);
|
||||
expect(result.rejectReason, 'unsupported protocol version: "oto.runner.v2"');
|
||||
} finally {
|
||||
await serverSub.cancel();
|
||||
await server.close(force: true);
|
||||
}
|
||||
});
|
||||
|
||||
test('sends first heartbeat and disconnects on close', () async {
|
||||
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
|
||||
final registerReceived = Completer<void>();
|
||||
|
|
|
|||
|
|
@ -100,6 +100,10 @@ func handleRunnerRegister(registry *runnerregistry.Registry) http.HandlerFunc {
|
|||
writeRunnerRegisterResponse(w, http.StatusBadRequest, &otopb.RegisterRunnerResponse{
|
||||
Accepted: false,
|
||||
RejectReason: "invalid registration request",
|
||||
Error: &otopb.ProtocolError{
|
||||
Code: "invalid_registration_request",
|
||||
Message: "invalid registration request",
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,6 +157,12 @@ func TestHandleRunnerRegisterRejectsMissingToken(t *testing.T) {
|
|||
if response.GetRejectReason() != "missing enrollment token" {
|
||||
t.Fatalf("reject reason = %q, want missing enrollment token", response.GetRejectReason())
|
||||
}
|
||||
if response.GetError() == nil {
|
||||
t.Fatal("missing structured error")
|
||||
}
|
||||
if response.GetError().GetCode() != "registration_rejected" {
|
||||
t.Fatalf("error code = %q, want registration_rejected", response.GetError().GetCode())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleRunnerRegisterMethodNotAllowed(t *testing.T) {
|
||||
|
|
@ -188,6 +194,10 @@ func TestHandleRunnerHeartbeat(t *testing.T) {
|
|||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
|
||||
// 3. Valid Heartbeat on registered runner should succeed
|
||||
|
|
@ -232,6 +242,10 @@ func TestHandleRunnerDisconnect(t *testing.T) {
|
|||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
|
||||
// 3. Disconnect registered runner should succeed
|
||||
|
|
@ -277,6 +291,10 @@ func TestHandleGetRunner(t *testing.T) {
|
|||
RunnerId: "runner-123",
|
||||
Alias: "build-linux",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
|
||||
// 3. Get registered runner should succeed (200) and return JSON record status
|
||||
|
|
@ -308,12 +326,20 @@ func TestHandleRunnerHeartbeatMismatch(t *testing.T) {
|
|||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-a",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
// Register runner-b
|
||||
registry.Register(&otopb.RegisterRunnerRequest{
|
||||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-b",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
|
||||
// Heartbeat with mismatched runner ID in body vs path
|
||||
|
|
@ -731,6 +757,10 @@ func TestHandleRunnerCicdClaimReportLogsAndArtifacts(t *testing.T) {
|
|||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
if _, err := store.CreateJob("job-1", "build"); err != nil {
|
||||
t.Fatalf("CreateJob failed: %v", err)
|
||||
|
|
@ -852,3 +882,71 @@ func TestHandleRunnerCicdRejectsUnknownRunner(t *testing.T) {
|
|||
t.Fatalf("status = %v, want %v; body=%s", rr.Code, http.StatusNotFound, rr.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleRunnerRegisterRejectsIncompatibleProtocol(t *testing.T) {
|
||||
registry := runnerregistry.New()
|
||||
body := bytes.NewBufferString(`{
|
||||
"enrollment_token":"token-123",
|
||||
"runner_id":"runner-123",
|
||||
"protocol_version":"oto.runner.v2",
|
||||
"capability":{"name":"oto-runner","version":"1.0.0"}
|
||||
}`)
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/runners/register", body)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handleRunnerRegister(registry)(rr, req)
|
||||
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Fatalf("status = %v, want %v", rr.Code, http.StatusOK)
|
||||
}
|
||||
var response otopb.RegisterRunnerResponse
|
||||
if err := json.Unmarshal(rr.Body.Bytes(), &response); err != nil {
|
||||
t.Fatalf("decode response: %v", err)
|
||||
}
|
||||
if response.GetAccepted() {
|
||||
t.Fatal("incompatible protocol registration was accepted")
|
||||
}
|
||||
if response.GetRejectReason() != `unsupported protocol version: "oto.runner.v2"` {
|
||||
t.Fatalf("reject reason = %q", response.GetRejectReason())
|
||||
}
|
||||
if response.GetError() == nil {
|
||||
t.Fatal("missing structured error")
|
||||
}
|
||||
if response.GetError().GetCode() != "incompatible_runner" {
|
||||
t.Fatalf("error code = %q, want incompatible_runner", response.GetError().GetCode())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleRunnerRegisterRejectsIncompatibleCapability(t *testing.T) {
|
||||
registry := runnerregistry.New()
|
||||
body := bytes.NewBufferString(`{
|
||||
"enrollment_token":"token-123",
|
||||
"runner_id":"runner-123",
|
||||
"protocol_version":"oto.runner.v1",
|
||||
"capability":{"name":"oto-runner","version":"2.0.0"}
|
||||
}`)
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/runners/register", body)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handleRunnerRegister(registry)(rr, req)
|
||||
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Fatalf("status = %v, want %v", rr.Code, http.StatusOK)
|
||||
}
|
||||
var response otopb.RegisterRunnerResponse
|
||||
if err := json.Unmarshal(rr.Body.Bytes(), &response); err != nil {
|
||||
t.Fatalf("decode response: %v", err)
|
||||
}
|
||||
if response.GetAccepted() {
|
||||
t.Fatal("incompatible capability version registration was accepted")
|
||||
}
|
||||
if response.GetRejectReason() != `incompatible capability major version: "2.0.0", want major version 1` {
|
||||
t.Fatalf("reject reason = %q", response.GetRejectReason())
|
||||
}
|
||||
if response.GetError() == nil {
|
||||
t.Fatal("missing structured error")
|
||||
}
|
||||
if response.GetError().GetCode() != "incompatible_runner" {
|
||||
t.Fatalf("error code = %q, want incompatible_runner", response.GetError().GetCode())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package runnerregistry
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -71,6 +72,10 @@ func (r *Registry) Register(req *otopb.RegisterRunnerRequest) *otopb.RegisterRun
|
|||
return rejected("missing protocol version")
|
||||
}
|
||||
|
||||
if err := validateProtocolCompatibility(protocolVersion, req.GetCapability()); err != nil {
|
||||
return rejectedWithCode("incompatible_runner", err.Error())
|
||||
}
|
||||
|
||||
record := RunnerRecord{
|
||||
RunnerID: runnerID,
|
||||
Alias: strings.TrimSpace(req.GetAlias()),
|
||||
|
|
@ -172,9 +177,38 @@ func (r *Registry) Snapshot(runnerID string) (RunnerRecord, bool) {
|
|||
return record, true
|
||||
}
|
||||
|
||||
func rejected(reason string) *otopb.RegisterRunnerResponse {
|
||||
func validateProtocolCompatibility(protocolVersion string, capability *otopb.RunnerCapability) error {
|
||||
if protocolVersion != "oto.runner.v1" {
|
||||
return fmt.Errorf("unsupported protocol version: %q", protocolVersion)
|
||||
}
|
||||
if capability == nil {
|
||||
return fmt.Errorf("missing runner capability")
|
||||
}
|
||||
if strings.TrimSpace(capability.GetName()) != "oto-runner" {
|
||||
return fmt.Errorf("unsupported capability name: %q", capability.GetName())
|
||||
}
|
||||
version := strings.TrimSpace(capability.GetVersion())
|
||||
if version == "" {
|
||||
return fmt.Errorf("missing capability version")
|
||||
}
|
||||
parts := strings.Split(version, ".")
|
||||
if parts[0] != "1" {
|
||||
return fmt.Errorf("incompatible capability major version: %q, want major version 1", version)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func rejectedWithCode(code, message string) *otopb.RegisterRunnerResponse {
|
||||
return &otopb.RegisterRunnerResponse{
|
||||
Accepted: false,
|
||||
RejectReason: reason,
|
||||
RejectReason: message,
|
||||
Error: &otopb.ProtocolError{
|
||||
Code: code,
|
||||
Message: message,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func rejected(reason string) *otopb.RegisterRunnerResponse {
|
||||
return rejectedWithCode("registration_rejected", reason)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,6 +117,10 @@ func TestRegistryHeartbeatTransitionsStatus(t *testing.T) {
|
|||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
|
||||
record, _ := registry.Snapshot("runner-123")
|
||||
|
|
@ -167,6 +171,10 @@ func TestRegistryDisconnect(t *testing.T) {
|
|||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
|
||||
if ok := registry.Disconnect("unknown-runner"); ok {
|
||||
|
|
@ -195,11 +203,19 @@ func TestRegistryCheckTimeouts(t *testing.T) {
|
|||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-accepted",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
registry.Register(&otopb.RegisterRunnerRequest{
|
||||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-online",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
|
||||
// transition runner-online to online
|
||||
|
|
@ -241,6 +257,10 @@ func TestRegistryHeartbeatTerminalStateDefense(t *testing.T) {
|
|||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
|
||||
// Move to Online
|
||||
|
|
@ -268,6 +288,10 @@ func TestRegistryHeartbeatTerminalStateDefense(t *testing.T) {
|
|||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
rec, _ = registry.Snapshot("runner-123")
|
||||
if rec.Status != StatusAccepted {
|
||||
|
|
@ -285,6 +309,10 @@ func TestRegistryHeartbeatTerminalStateDefense(t *testing.T) {
|
|||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
})
|
||||
mockTime = mockTime.Add(1 * time.Second)
|
||||
registry.Heartbeat("runner-123", otopb.HeartbeatStatus_HEARTBEAT_STATUS_HEALTHY)
|
||||
|
|
@ -307,3 +335,100 @@ func TestRegistryHeartbeatTerminalStateDefense(t *testing.T) {
|
|||
t.Fatalf("expected status to remain heartbeat_timeout, got %s", rec.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistryRejectsIncompatibleRunnerContract(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
req *otopb.RegisterRunnerRequest
|
||||
wantMsg string
|
||||
wantCode string
|
||||
}{
|
||||
{
|
||||
name: "unsupported protocol version",
|
||||
req: &otopb.RegisterRunnerRequest{
|
||||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v2",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
},
|
||||
wantMsg: `unsupported protocol version: "oto.runner.v2"`,
|
||||
wantCode: "incompatible_runner",
|
||||
},
|
||||
{
|
||||
name: "missing capability",
|
||||
req: &otopb.RegisterRunnerRequest{
|
||||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
},
|
||||
wantMsg: "missing runner capability",
|
||||
wantCode: "incompatible_runner",
|
||||
},
|
||||
{
|
||||
name: "unsupported capability name",
|
||||
req: &otopb.RegisterRunnerRequest{
|
||||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "other-runner",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
},
|
||||
wantMsg: `unsupported capability name: "other-runner"`,
|
||||
wantCode: "incompatible_runner",
|
||||
},
|
||||
{
|
||||
name: "missing capability version",
|
||||
req: &otopb.RegisterRunnerRequest{
|
||||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "",
|
||||
},
|
||||
},
|
||||
wantMsg: "missing capability version",
|
||||
wantCode: "incompatible_runner",
|
||||
},
|
||||
{
|
||||
name: "incompatible capability major version",
|
||||
req: &otopb.RegisterRunnerRequest{
|
||||
EnrollmentToken: "token-123",
|
||||
RunnerId: "runner-123",
|
||||
ProtocolVersion: "oto.runner.v1",
|
||||
Capability: &otopb.RunnerCapability{
|
||||
Name: "oto-runner",
|
||||
Version: "2.0.0",
|
||||
},
|
||||
},
|
||||
wantMsg: `incompatible capability major version: "2.0.0", want major version 1`,
|
||||
wantCode: "incompatible_runner",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
response := New().Register(tt.req)
|
||||
if response.GetAccepted() {
|
||||
t.Fatal("Register accepted incompatible contract")
|
||||
}
|
||||
if response.GetRejectReason() != tt.wantMsg {
|
||||
t.Fatalf("reject reason = %q, want %q", response.GetRejectReason(), tt.wantMsg)
|
||||
}
|
||||
if response.GetError() == nil {
|
||||
t.Fatal("missing structured error")
|
||||
}
|
||||
if response.GetError().GetCode() != tt.wantCode {
|
||||
t.Fatalf("error code = %q, want %q", response.GetError().GetCode(), tt.wantCode)
|
||||
}
|
||||
if response.GetError().GetMessage() != tt.wantMsg {
|
||||
t.Fatalf("error message = %q, want %q", response.GetError().GetMessage(), tt.wantMsg)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue