feat: Windows bootstrap script and HTTP server updates
- Add PowerShell bootstrap script for Windows runner - Update httpserver bootstrap provider, routes, and runner handlers - Add bootstrap PowerShell test case - Move old G07 task docs to archive - Update server tests
This commit is contained in:
parent
129cd29cd8
commit
ac44c85d34
13 changed files with 1126 additions and 60 deletions
|
|
@ -0,0 +1,131 @@
|
|||
<!-- task=m-cross-os-runner-bootstrap/03+01_windows_bootstrap plan=0 tag=BOOTSTRAP_WINDOWS -->
|
||||
|
||||
# CODE REVIEW: Windows PowerShell bootstrap 추가
|
||||
|
||||
## Roadmap Targets
|
||||
|
||||
- Milestone: `agent-roadmap/phase/control-plane-product-surface/milestones/cross-os-runner-bootstrap.md`
|
||||
- Epic: `[bootstrap-platforms] Cross-OS bootstrap contract`
|
||||
- Task id: `[windows-bootstrap]`
|
||||
- Completion mode: check-on-pass
|
||||
|
||||
## 사용자 리뷰 요청
|
||||
|
||||
_기본값은 `없음`이다. 구현 중 사용자 결정, 사용자 소유 외부 환경/secret/서비스 준비, 또는 계획 범위 변경 없이는 안전하게 진행할 수 없으면 아래 항목을 실제 내용으로 교체하고, 구현을 중단한 뒤 active 파일을 그대로 둔 채 리뷰를 요청한다. 구현 에이전트는 사용자에게 직접 질문하거나 선택지를 제시하거나 `request_user_input`을 호출하지 않는다. 후속 에이전트가 명령 재실행이나 산출물 수집으로 해소할 수 있는 검증 증거 공백만으로는 사용자 리뷰 요청을 작성하지 않는다._
|
||||
|
||||
- 상태: 없음
|
||||
- 사유 유형: 없음
|
||||
- 결정 필요: 없음
|
||||
- 차단 근거: 없음
|
||||
- 실행한 검증/명령: 없음
|
||||
- 자동 후속 불가 이유: 없음
|
||||
- 재개 조건: 없음
|
||||
|
||||
## 구현 에이전트 소유 섹션
|
||||
|
||||
### 계획 대비 변경 사항
|
||||
|
||||
- `runner_handlers.go`와 `server_test.go`의 Windows command 생성 로직(사례 11, 12, 13)은 `01_core_command`에서 이미 구현 완료되어 있었다. 이번 작업에서는 touch하지 않았다.
|
||||
- Dart 테스트는 PowerShell을 Linux 환경에서 실행할 수 없으므로 content assertion 전용 파일(`oto_agent_bootstrap_ps1_test.dart`)을 별도 생성했다. PLAN의 "또는 별도 runner bootstrap test" 선택지를 따랐다.
|
||||
- `oto-windows-x64.zip` / `oto-windows-arm64.zip` 리터럴이 스크립트에 존재하지 않고 `"oto-windows-$archName.zip"` 패턴으로 동적 생성되어, Dart 테스트를 패턴 검증으로 조정했다. 쉘 스크립트의 `oto-${os_name}-${arch_name}.tar.gz` 패턴과 동일한 방식이다.
|
||||
|
||||
### 수정 파일
|
||||
|
||||
| 경로 | 목적 |
|
||||
|------|------|
|
||||
| `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1` | Windows bootstrap 구현 (신규 생성) |
|
||||
| `services/core/internal/httpserver/oto_agent_bootstrap.ps1` | Core embedded Windows asset (신규 생성, 동일 내용) |
|
||||
| `services/core/internal/httpserver/bootstrap_provider.go` | `bootstrapPs1Provider` 인터페이스 및 `embeddedBootstrapPs1Provider` 추가 |
|
||||
| `services/core/internal/httpserver/runner_handlers.go` | `handleServeBootstrapPs1` handler 추가 |
|
||||
| `services/core/internal/httpserver/routes.go` | `/bootstrap/oto-agent.ps1` route 추가 |
|
||||
| `services/core/internal/httpserver/server_test.go` | `staticPs1Provider`, PS1 serve/route/drift check 테스트 추가 |
|
||||
| `apps/runner/test/oto_agent_bootstrap_ps1_test.dart` | PowerShell script content assertion 테스트 (신규 생성) |
|
||||
|
||||
### 검증 결과
|
||||
|
||||
```
|
||||
# Go 전체
|
||||
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 (cached)
|
||||
ok github.com/toki/oto/services/core/internal/httpserver ok
|
||||
ok github.com/toki/oto/services/core/internal/runnerregistry (cached)
|
||||
? github.com/toki/oto/services/core/oto [no test files]
|
||||
|
||||
# Dart shell test (기존 19개 유지)
|
||||
cd apps/runner && dart test test/oto_agent_bootstrap_script_test.dart
|
||||
+19: All tests passed!
|
||||
|
||||
# Dart PS1 content tests (신규 9개)
|
||||
cd apps/runner && dart test test/oto_agent_bootstrap_ps1_test.dart
|
||||
+9: All tests passed!
|
||||
|
||||
# Dart analyze
|
||||
cd apps/runner && dart analyze
|
||||
No issues found!
|
||||
```
|
||||
|
||||
### 구현 체크리스트
|
||||
|
||||
- [x] PowerShell bootstrap asset을 추가하고 Windows x64/arm64 zip asset 선택을 고정한다.
|
||||
- [x] Core가 `.ps1` bootstrap asset을 serve하고 Windows command에서 해당 URL을 사용한다.
|
||||
- [x] script/config 생성 시 기존 agent 설정 의미를 유지하고 enrollment token 출력 노출을 피한다.
|
||||
- [x] Windows route, content, command, quoting, zip asset 이름을 테스트한다.
|
||||
- [x] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다.
|
||||
|
||||
## 코드 리뷰 전용 섹션
|
||||
|
||||
- [x] `01_core_command` 완료 근거가 있다. (`agent-task/archive/2026/06/m-cross-os-runner-bootstrap/01_core_command/complete.log` 존재 확인)
|
||||
- [x] PowerShell quoting과 Windows path가 fixture로 검증된다. (`server_test.go` cases 11/12, Dart PS1 content tests)
|
||||
- [x] `.ps1` serving route와 command URL이 일치한다. (`/bootstrap/oto-agent.ps1` route + command의 `oto-agent.ps1` URL)
|
||||
- [x] token/credential 출력 노출이 없다. (Dart 테스트 + PS1 script에서 Write-Host가 token 변수를 출력하지 않음)
|
||||
|
||||
## 완료 판정 메모
|
||||
|
||||
| 항목 | 값 |
|
||||
|------|----|
|
||||
| Verdict | PASS |
|
||||
| Roadmap Completion | `[windows-bootstrap]` only |
|
||||
| Archive ready | yes |
|
||||
|
||||
## 코드리뷰 결과
|
||||
|
||||
### 종합 판정
|
||||
|
||||
FAIL
|
||||
|
||||
### 차원별 평가
|
||||
|
||||
| 차원 | 평가 | 근거 |
|
||||
|------|------|------|
|
||||
| correctness | Fail | Windows background 실행과 config credential 보호에 실제 동작 결함 가능성이 남아 있다. |
|
||||
| completeness | Fail | 계획의 Windows bootstrap 계약은 추가됐지만 agent 도메인 규칙의 config 보호 의미와 background 실행 계약이 완결되지 않았다. |
|
||||
| test coverage | Fail | PowerShell content assertion은 있으나 background log redirection과 config ACL/permission 보호를 고정하는 테스트가 없다. |
|
||||
| API contract | Pass | `.ps1` route와 Windows bootstrap command URL 계약은 일치한다. |
|
||||
| code quality | Pass | 관련 Go handler와 drift test는 기존 패턴을 따른다. |
|
||||
| plan deviation | Pass | 별도 PS1 content assertion 테스트 생성은 계획의 허용 범위 안이다. |
|
||||
| verification trust | Warn | 재실행한 Go/Dart 검증은 통과했지만 Linux content assertion만으로 Windows runtime 의미를 검증하지 못한다. |
|
||||
|
||||
### 발견된 문제
|
||||
|
||||
- Required: `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:100` 및 mirrored `services/core/internal/httpserver/oto_agent_bootstrap.ps1:100`에서 `Start-Process`가 `-RedirectStandardOutput`과 `-RedirectStandardError`에 같은 `$logFile`을 넘긴다. Windows PowerShell은 두 redirect 대상이 같으면 process start가 실패할 수 있어 기본 background bootstrap이 깨질 수 있다. stdout/stderr를 별도 파일로 분리하거나 PowerShell redirection wrapper로 단일 로그를 만들고, PS1 content test에 같은 경로를 동시에 쓰지 않는다는 assertion을 추가한다.
|
||||
- Required: `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:93` 및 mirrored `services/core/internal/httpserver/oto_agent_bootstrap.ps1:93`에서 enrollment token이 들어간 config를 쓴 뒤 Windows ACL/permission을 제한하지 않는다. agent 도메인 규칙은 생성 config를 `chmod 600` 의미로 보호해야 하므로, Windows equivalent ACL 적용을 추가하고 테스트가 `SetAccessRuleProtection`/`icacls` 등 permission hardening을 확인하게 한다.
|
||||
|
||||
### 다음 단계
|
||||
|
||||
- FAIL 후속: active plan/review를 로그로 아카이브하고, 위 Required 2건만 다루는 `PLAN-cloud-G07.md` 및 `CODE_REVIEW-cloud-G07.md`를 새로 작성한다.
|
||||
|
||||
## 코드리뷰 전용 체크리스트
|
||||
|
||||
- [x] `코드리뷰 결과`에 `PASS`, `WARN`, `FAIL` 중 하나의 판정을 append한다.
|
||||
- [x] 판정과 `차원별 평가`, Required/Suggested/Nit 분류가 서로 일치한다.
|
||||
- [x] active `CODE_REVIEW-cloud-G07.md`를 `code_review_cloud_G07_0.log`로 아카이브한다.
|
||||
- [x] active `PLAN-cloud-G07.md`를 `plan_cloud_G07_0.log`로 아카이브한다.
|
||||
- [x] `.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-cross-os-runner-bootstrap/03+01_windows_bootstrap/`를 `agent-task/archive/YYYY/MM/m-cross-os-runner-bootstrap/03+01_windows_bootstrap/`로 이동하고 최종 archive 경로에서 이 체크리스트를 갱신한다.
|
||||
- [ ] PASS이고 task group이 `m-<milestone-slug>`이면 런타임이 읽을 완료 이벤트 메타데이터를 보고하고, roadmap 수정이나 `update-roadmap` 직접 호출을 하지 않는다.
|
||||
- [ ] PASS split 작업이면 이동 후 빈 active parent `agent-task/m-cross-os-runner-bootstrap/`를 제거하거나, 남은 sibling/file이 있어 유지했다고 확인한다.
|
||||
- [x] WARN/FAIL이고 user-review gate가 트리거되지 않았으면 다음 active `PLAN-cloud-G07.md`와 `CODE_REVIEW-cloud-G07.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로 이동한다.
|
||||
|
|
@ -0,0 +1,226 @@
|
|||
<!-- task=m-cross-os-runner-bootstrap/03+01_windows_bootstrap plan=1 tag=REVIEW_BOOTSTRAP_WINDOWS -->
|
||||
|
||||
# Code Review Reference - REVIEW_BOOTSTRAP_WINDOWS
|
||||
|
||||
> **[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-15
|
||||
task=m-cross-os-runner-bootstrap/03+01_windows_bootstrap, plan=1, tag=REVIEW_BOOTSTRAP_WINDOWS
|
||||
|
||||
## Roadmap Targets
|
||||
|
||||
- Milestone: `agent-roadmap/phase/control-plane-product-surface/milestones/cross-os-runner-bootstrap.md`
|
||||
- Task ids:
|
||||
- `[windows-bootstrap]`: Windows PowerShell bootstrap
|
||||
- Completion mode: check-on-pass
|
||||
|
||||
## 이 파일을 읽는 리뷰 에이전트에게
|
||||
|
||||
> **[REVIEW AGENT ONLY]** 아래 종결 절차는 코드리뷰 에이전트 전용이다. 구현 에이전트는 이 섹션을 실행하지 않는다.
|
||||
|
||||
각 항목의 구현을 실제 소스 파일과 대조하고, `검증 결과` 섹션의 출력이 코드와 일치하는지 확인하세요.
|
||||
리뷰 완료는 아래 순서까지 끝난 상태를 의미합니다.
|
||||
|
||||
1. 판정을 append한다.
|
||||
2. `CODE_REVIEW-cloud-G07.md` → `code_review_cloud_G07_N.log`, `PLAN-cloud-G07.md` → `plan_cloud_G07_M.log`로 아카이브한다.
|
||||
3. PASS이면 `complete.log` 작성 후 active task 디렉터리를 `agent-task/archive/YYYY/MM/m-cross-os-runner-bootstrap/03+01_windows_bootstrap/`로 이동한다. 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` 위치에서 체크한 뒤 보고한다.
|
||||
|
||||
---
|
||||
|
||||
## 구현 항목별 완료 여부
|
||||
|
||||
| 항목 | 완료 여부 |
|
||||
|------|---------|
|
||||
| [REVIEW_BOOTSTRAP_WINDOWS-1] Background log redirection 수정 | [x] |
|
||||
| [REVIEW_BOOTSTRAP_WINDOWS-2] Config ACL hardening 추가 | [x] |
|
||||
| [REVIEW_BOOTSTRAP_WINDOWS-3] Drift 및 focused 검증 | [x] |
|
||||
|
||||
## 구현 체크리스트
|
||||
|
||||
- [x] PowerShell background 실행에서 stdout/stderr redirect target을 분리하고 content regression으로 고정한다.
|
||||
- [x] token-bearing Windows config 파일에 chmod 600 equivalent ACL hardening을 적용하고 content regression으로 고정한다.
|
||||
- [x] runner/Core PS1 asset을 byte-identical하게 동기화하고 focused 검증을 실행한다.
|
||||
- [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_G07_1.log`로 아카이브한다.
|
||||
- [x] active `PLAN-*-G??.md`를 `plan_cloud_G07_1.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-cross-os-runner-bootstrap/03+01_windows_bootstrap/`를 `agent-task/archive/YYYY/MM/m-cross-os-runner-bootstrap/03+01_windows_bootstrap/`로 이동하고 최종 archive 경로에서 이 체크리스트를 갱신한다.
|
||||
- [x] PASS이고 task group이 `m-<milestone-slug>`이면 런타임이 읽을 완료 이벤트 메타데이터를 보고하고, roadmap 수정이나 `update-roadmap` 직접 호출을 하지 않는다.
|
||||
- [x] PASS split 작업이면 이동 후 빈 active parent `agent-task/m-cross-os-runner-bootstrap/`를 제거하거나, 남은 sibling/file이 있어 유지했다고 확인한다.
|
||||
- [ ] WARN/FAIL이고 user-review gate가 트리거되지 않았으면 다음 active `PLAN-cloud-G07.md`와 `CODE_REVIEW-cloud-G07.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로 이동한다.
|
||||
|
||||
## 계획 대비 변경 사항
|
||||
|
||||
- plan=0에서 runner_handlers.go와 server_test.go의 Windows command 생성 로직(cases 11/12/13)이 이미 구현되어 있어 touch하지 않았다.
|
||||
- plan=1(이번)에서 stdout/stderr redirect 분리(`oto-agent.out.log` / `oto-agent.err.log`)와 ACL hardening(`SetAccessRuleProtection`, `FileSystemAccessRule`, `Set-Acl`)을 PS1 스크립트에 추가했다. plan=0 스크립트는 두 redirect가 동일 파일을 가리켰으며 ACL이 없었다.
|
||||
- Dart 테스트에 두 regression assertion 그룹을 추가했다.
|
||||
|
||||
## 주요 설계 결정
|
||||
|
||||
- **stdout/stderr 분리**: `Start-Process`는 `-RedirectStandardOutput`과 `-RedirectStandardError`를 각각 별도 파일로 지정해야 한다. 같은 파일을 두 매개변수에 지정하면 PowerShell이 오류를 발생시킨다. `oto-agent.out.log`와 `oto-agent.err.log`로 분리했다.
|
||||
- **ACL hardening**: `SetAccessRuleProtection($true, $false)`로 상속을 차단하고 현재 사용자만 FullControl을 갖도록 설정했다. Unix `chmod 600`과 동일한 의미다. `Get-Acl` → rule 추가 → `Set-Acl` 순서는 PowerShell ACL 수정의 표준 패턴이다.
|
||||
- **Drift 동기화**: runner asset과 Core embedded 파일은 `cp`로 동일 내용을 유지하고, Go drift test(`TestEmbeddedBootstrapPs1MatchesRunnerAsset`)가 byte-identical을 자동으로 검증한다.
|
||||
|
||||
## 사용자 리뷰 요청
|
||||
|
||||
_기본값은 `없음`이다. 구현 중 사용자 결정, 사용자 소유 외부 환경/secret/서비스 준비, 또는 계획 범위 변경 없이는 안전하게 진행할 수 없으면 아래 항목을 실제 내용으로 교체하고, 구현을 중단한 뒤 active 파일을 그대로 둔 채 리뷰를 요청한다. 구현 에이전트는 사용자에게 직접 질문하거나 선택지를 제시하거나 `request_user_input`을 호출하지 않는다. 후속 에이전트가 명령 재실행이나 산출물 수집으로 해소할 수 있는 검증 증거 공백만으로는 사용자 리뷰 요청을 작성하지 않는다._
|
||||
|
||||
- 상태: 없음
|
||||
- 사유 유형: 없음
|
||||
- 결정 필요: 없음
|
||||
- 차단 근거: 없음
|
||||
- 실행한 검증/명령: 없음
|
||||
- 자동 후속 불가 이유: 없음
|
||||
- 재개 조건: 없음
|
||||
|
||||
## 리뷰어를 위한 체크포인트
|
||||
|
||||
- `Start-Process` stdout/stderr redirect target이 서로 다른 파일인지 확인한다.
|
||||
- PowerShell config write 직후 Windows ACL/permission hardening이 적용되는지 확인한다.
|
||||
- runner/Core PS1 files가 byte-identical하고 기존 Go drift test가 통과했는지 확인한다.
|
||||
- token 값이 Write-Host/Write-Error/Write-Output으로 노출되지 않는지 기존 assertion이 유지되는지 확인한다.
|
||||
|
||||
## 검증 결과
|
||||
|
||||
_구현 에이전트가 각 중간 검증 및 최종 검증 명령 실행 후 출력을 여기에 붙여 넣는다._
|
||||
|
||||
필수 규칙:
|
||||
- 검증 명령은 고정된 계약이다. 임의로 대체하지 않는다.
|
||||
- 대체가 필요하면 `계획 대비 변경 사항`에 이유와 대체 명령을 기록한다.
|
||||
- `검증 결과`에는 실제 stdout/stderr를 붙여 넣는다.
|
||||
- 사용자 리뷰 요청으로 명령을 끝까지 실행하지 못했다면 `사용자 리뷰 요청`에 실행한 명령, 실제 출력, 미실행 명령의 사유를 기록한다.
|
||||
- mobile/UI hang, timeout, 또는 2분 무진행은 blind retry를 중단하고 focused rerun 명령과 screenshot/window/UI-tree evidence path를 남기며, 불가능하면 정확한 사유를 남긴다.
|
||||
|
||||
### REVIEW_BOOTSTRAP_WINDOWS-1 중간 검증
|
||||
```
|
||||
$ cd apps/runner && dart test test/oto_agent_bootstrap_ps1_test.dart
|
||||
+11: All tests passed!
|
||||
```
|
||||
|
||||
### REVIEW_BOOTSTRAP_WINDOWS-2 중간 검증
|
||||
```
|
||||
$ cd apps/runner && dart test test/oto_agent_bootstrap_ps1_test.dart
|
||||
+11: All tests passed!
|
||||
```
|
||||
|
||||
### REVIEW_BOOTSTRAP_WINDOWS-3 중간 검증
|
||||
```
|
||||
$ cd services/core && go test -count=1 ./...
|
||||
? 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.068s
|
||||
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 test test/oto_agent_bootstrap_ps1_test.dart
|
||||
+11: All tests passed!
|
||||
|
||||
$ cd apps/runner && dart test test/oto_agent_bootstrap_script_test.dart
|
||||
+19: All tests passed!
|
||||
|
||||
$ cd apps/runner && dart analyze
|
||||
Analyzing runner...
|
||||
No issues found!
|
||||
|
||||
$ cd services/core && go test -count=1 ./...
|
||||
? 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.068s
|
||||
ok github.com/toki/oto/services/core/internal/runnerregistry 0.003s
|
||||
? github.com/toki/oto/services/core/oto [no test files]
|
||||
|
||||
$ rg --sort path -n "RedirectStandardOutput|RedirectStandardError|SetAccessRuleProtection|FileSystemAccessRule|Set-Acl|oto-agent\.out\.log|oto-agent\.err\.log" apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1 services/core/internal/httpserver/oto_agent_bootstrap.ps1 apps/runner/test/oto_agent_bootstrap_ps1_test.dart
|
||||
apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:96: $acl.SetAccessRuleProtection($true, $false)
|
||||
apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:97: $rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||
apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:103: Set-Acl -Path $configPath -AclObject $acl
|
||||
apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:109: $outLog = Join-Path $logDir 'oto-agent.out.log'
|
||||
apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:110: $errLog = Join-Path $logDir 'oto-agent.err.log'
|
||||
apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:113: -RedirectStandardOutput $outLog `
|
||||
apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:114: -RedirectStandardError $errLog `
|
||||
services/core/internal/httpserver/oto_agent_bootstrap.ps1:96: $acl.SetAccessRuleProtection($true, $false)
|
||||
services/core/internal/httpserver/oto_agent_bootstrap.ps1:97: $rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||
services/core/internal/httpserver/oto_agent_bootstrap.ps1:103: Set-Acl -Path $configPath -AclObject $acl
|
||||
services/core/internal/httpserver/oto_agent_bootstrap.ps1:109: $outLog = Join-Path $logDir 'oto-agent.out.log'
|
||||
services/core/internal/httpserver/oto_agent_bootstrap.ps1:110: $errLog = Join-Path $logDir 'oto-agent.err.log'
|
||||
services/core/internal/httpserver/oto_agent_bootstrap.ps1:113: -RedirectStandardOutput $outLog `
|
||||
services/core/internal/httpserver/oto_agent_bootstrap.ps1:114: -RedirectStandardError $errLog `
|
||||
apps/runner/test/oto_agent_bootstrap_ps1_test.dart:82: expect(content, contains('RedirectStandardOutput'));
|
||||
apps/runner/test/oto_agent_bootstrap_ps1_test.dart:83: expect(content, contains('RedirectStandardError'));
|
||||
apps/runner/test/oto_agent_bootstrap_ps1_test.dart:84: expect(content, contains('oto-agent.out.log'));
|
||||
apps/runner/test/oto_agent_bootstrap_ps1_test.dart:85: expect(content, contains('oto-agent.err.log'));
|
||||
apps/runner/test/oto_agent_bootstrap_ps1_test.dart:89: expect(content, contains('SetAccessRuleProtection'));
|
||||
apps/runner/test/oto_agent_bootstrap_ps1_test.dart:90: expect(content, contains('FileSystemAccessRule'));
|
||||
apps/runner/test/oto_agent_bootstrap_ps1_test.dart:91: expect(content, contains('Set-Acl'));
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> **[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.
|
||||
|
||||
Sections and their ownership:
|
||||
|
||||
| Section | Owner | Note |
|
||||
|---------|-------|------|
|
||||
| Header comment, 개요, 리뷰 에이전트 지시 | Fixed at stub creation | Implementing agent must not modify or execute these |
|
||||
| Roadmap Targets | Fixed at stub creation from plan | Implementing agent must not modify; code-review copies it into `complete.log` as `Roadmap Completion` only on PASS |
|
||||
| 구현 항목별 완료 여부 (item names) | Fixed at stub creation | Implementing agent checks `[ ]` to `[x]` only |
|
||||
| 구현 체크리스트 (item text/order) | Fixed at stub creation from plan | Implementing agent checks `[ ]` to `[x]` only; final checkbox is mandatory before saving |
|
||||
| 코드리뷰 전용 체크리스트 | Review agent only | Implementing agent must not modify or check this section |
|
||||
| 계획 대비 변경 사항, 주요 설계 결정 | Implementing agent | Replace placeholder text with actual content |
|
||||
| 사용자 리뷰 요청 | Implementing agent | Keep `상태: 없음` unless user input is required to proceed |
|
||||
| 리뷰어를 위한 체크포인트 | Fixed at stub creation | Pre-filled from plan |
|
||||
| 검증 결과 (section headings + commands) | Fixed at stub creation | Implementing agent fills in command output only |
|
||||
| 코드리뷰 결과 | Review agent appends | Not included in stub |
|
||||
|
||||
## 코드리뷰 결과
|
||||
|
||||
### 종합 판정
|
||||
|
||||
PASS
|
||||
|
||||
### 차원별 평가
|
||||
|
||||
| 차원 | 평가 | 근거 |
|
||||
|------|------|------|
|
||||
| correctness | Pass | stdout/stderr redirect target이 분리됐고 config ACL hardening이 config write 직후 적용된다. |
|
||||
| completeness | Pass | plan=1의 세 구현 체크리스트와 mandatory review artifact 작성이 완료됐다. |
|
||||
| test coverage | Pass | PS1 content regression과 Go drift/route test가 변경 계약을 고정한다. |
|
||||
| API contract | Pass | `/bootstrap/oto-agent.ps1` serving, Windows command URL, 기존 shell bootstrap 계약을 유지한다. |
|
||||
| code quality | Pass | 변경은 기존 asset mirror/drift test 패턴을 따른다. |
|
||||
| plan deviation | Pass | 핵심 Required 2건은 해결됐다. stderr log path 안내는 아래 Nit로 남긴다. |
|
||||
| verification trust | Pass | reviewer가 계획의 최종 검증 명령을 재실행했고 모두 통과했다. |
|
||||
|
||||
### 발견된 문제
|
||||
|
||||
- Nit: `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:119` 및 mirrored `services/core/internal/httpserver/oto_agent_bootstrap.ps1:119`에서 background 시작 후 stdout log path만 안내한다. stderr도 별도 파일로 분리됐으므로 향후 문구를 두 경로 모두 보여주게 다듬으면 운영자가 더 찾기 쉽다. correctness를 막지는 않는다.
|
||||
|
||||
### 다음 단계
|
||||
|
||||
- PASS: active review/plan을 로그로 아카이브하고 `complete.log` 작성 후 task directory를 archive로 이동한다.
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
# Complete - m-cross-os-runner-bootstrap/03+01_windows_bootstrap
|
||||
|
||||
## 완료 일시
|
||||
|
||||
2026-06-15
|
||||
|
||||
## 요약
|
||||
|
||||
Windows PowerShell bootstrap 추가와 리뷰 후속 보강을 2회 리뷰 루프로 완료했으며 최종 판정은 PASS다.
|
||||
|
||||
## 루프 이력
|
||||
|
||||
| Plan | Review | Verdict | 메모 |
|
||||
|------|--------|---------|------|
|
||||
| `plan_cloud_G07_0.log` | `code_review_cloud_G07_0.log` | FAIL | PowerShell background log redirect와 token-bearing config ACL hardening 보강 필요 |
|
||||
| `plan_cloud_G07_1.log` | `code_review_cloud_G07_1.log` | PASS | stdout/stderr redirect 분리, Windows config ACL hardening, PS1 content regression 및 drift 검증 완료 |
|
||||
|
||||
## 구현/정리 내용
|
||||
|
||||
- Windows PowerShell bootstrap asset과 Core embedded PS1 route/provider를 추가했다.
|
||||
- Windows bootstrap command가 `/bootstrap/oto-agent.ps1` URL을 사용하고 기존 shell command 계약을 유지한다.
|
||||
- PowerShell bootstrap에서 Windows x64/arm64 zip asset 선택, HTTPS release URL 검증, config 생성, background 실행을 구현했다.
|
||||
- background 실행 로그를 `oto-agent.out.log`와 `oto-agent.err.log`로 분리했다.
|
||||
- enrollment token이 포함된 config 파일에 Windows ACL hardening을 적용했다.
|
||||
- runner PS1 asset과 Core embedded copy가 byte-identical한지 Go drift test로 고정했다.
|
||||
|
||||
## 최종 검증
|
||||
|
||||
- `git diff --check` - PASS; whitespace error 없음.
|
||||
- `cd apps/runner && dart test test/oto_agent_bootstrap_ps1_test.dart` - PASS; `+11: All tests passed!`.
|
||||
- `cd apps/runner && dart test test/oto_agent_bootstrap_script_test.dart` - PASS; `+19: All tests passed!`.
|
||||
- `cd apps/runner && dart analyze` - PASS; `No issues found!`.
|
||||
- `cd services/core && go test -count=1 ./...` - PASS; core 전체 Go package 통과.
|
||||
- `rg --sort path -n "RedirectStandardOutput|RedirectStandardError|SetAccessRuleProtection|FileSystemAccessRule|Set-Acl|oto-agent\\.out\\.log|oto-agent\\.err\\.log" apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1 services/core/internal/httpserver/oto_agent_bootstrap.ps1 apps/runner/test/oto_agent_bootstrap_ps1_test.dart` - PASS; expected PowerShell redirect/ACL/test anchors 확인.
|
||||
|
||||
## Roadmap Completion
|
||||
|
||||
- Milestone: `agent-roadmap/phase/control-plane-product-surface/milestones/cross-os-runner-bootstrap.md`
|
||||
- Completed task ids:
|
||||
- `[windows-bootstrap]`: PASS; evidence=`plan_cloud_G07_1.log`, `code_review_cloud_G07_1.log`; verification=`cd apps/runner && dart test test/oto_agent_bootstrap_ps1_test.dart`, `cd apps/runner && dart test test/oto_agent_bootstrap_script_test.dart`, `cd apps/runner && dart analyze`, `cd services/core && go test -count=1 ./...`
|
||||
- Not completed task ids: 없음
|
||||
|
||||
## 잔여 Nit
|
||||
|
||||
- PowerShell background 시작 안내가 stdout log path만 출력한다. stderr도 별도 파일로 분리됐으므로 향후 안내 문구를 두 경로 모두 보여주게 다듬으면 운영 편의가 좋아진다.
|
||||
|
||||
## 후속 작업
|
||||
|
||||
- 없음
|
||||
|
|
@ -0,0 +1,217 @@
|
|||
<!-- task=m-cross-os-runner-bootstrap/03+01_windows_bootstrap plan=1 tag=REVIEW_BOOTSTRAP_WINDOWS -->
|
||||
|
||||
# PLAN: Windows PowerShell bootstrap 리뷰 후속 수정
|
||||
|
||||
## 이 파일을 읽는 구현 에이전트에게
|
||||
|
||||
이 계획은 이전 리뷰의 Required 2건만 수정한다. 구현 후 active `CODE_REVIEW-cloud-G07.md`의 구현 에이전트 소유 섹션을 실제 변경 내용과 검증 stdout/stderr로 채우고, active 파일을 그대로 둔 채 리뷰를 요청한다. 최종 판정, 로그 아카이브, `complete.log`, task directory archive 이동은 code-review 전용이다.
|
||||
|
||||
구현 중 사용자만 결정할 수 있는 선택, 사용자 소유 외부 환경/secret/서비스 준비, 또는 계획 범위 충돌이 생기면 active review stub의 `사용자 리뷰 요청` 섹션에 정확한 근거와 재개 조건을 기록하고 중단한다. 구현 에이전트는 사용자에게 직접 질문하거나 선택지를 제시하거나 `request_user_input`을 호출하지 않는다. 후속 에이전트가 명령 재실행이나 산출물 수집으로 해소할 수 있는 증거 공백은 사용자 리뷰 요청이 아니다.
|
||||
|
||||
## 배경
|
||||
|
||||
1차 구현은 PowerShell bootstrap asset, Core `.ps1` serving route, drift test, content assertion을 추가했고 재실행한 Go/Dart 검증도 통과했다. 그러나 Windows background 실행과 token-bearing config 파일 보호에서 실제 Windows runtime 결함 가능성이 남았다. 이 후속은 기존 구현 범위를 넓히지 않고 PowerShell bootstrap script와 해당 content tests만 보강한다.
|
||||
|
||||
## 사용자 리뷰 요청 흐름
|
||||
|
||||
구현 중 blocker는 active `CODE_REVIEW-cloud-G07.md`의 `사용자 리뷰 요청` 섹션에 기록한다. 이 섹션은 `agent-ops/skills/common/_templates/implementation-user-review-request-section.md`에서 온 형식이며, 직접 사용자 프롬프트는 금지된다. `USER_REVIEW.md` 작성 여부는 다음 code-review가 판단한다.
|
||||
|
||||
## Roadmap Targets
|
||||
|
||||
- Milestone: `agent-roadmap/phase/control-plane-product-surface/milestones/cross-os-runner-bootstrap.md`
|
||||
- Task ids:
|
||||
- `[windows-bootstrap]`: Windows PowerShell bootstrap
|
||||
- Completion mode: check-on-pass
|
||||
|
||||
## 분석 결과
|
||||
|
||||
### 읽은 파일
|
||||
|
||||
- `agent-ops/rules/project/rules.md`
|
||||
- `agent-ops/rules/common/rules-roadmap.md`
|
||||
- `agent-roadmap/current.md`
|
||||
- `agent-ops/skills/common/router.md`
|
||||
- `agent-ops/skills/common/code-review/SKILL.md`
|
||||
- `agent-ops/skills/common/plan/SKILL.md`
|
||||
- `agent-ops/skills/common/_templates/implementation-user-review-request-section.md`
|
||||
- `agent-ops/rules/project/domain/cli/rules.md`
|
||||
- `agent-ops/rules/project/domain/agent/rules.md`
|
||||
- `agent-test/local/rules.md`
|
||||
- `agent-test/local/cli-smoke.md`
|
||||
- `agent-test/local/agent-smoke.md`
|
||||
- `agent-task/archive/2026/06/m-cross-os-runner-bootstrap/01_core_command/complete.log`
|
||||
- `agent-task/m-cross-os-runner-bootstrap/03+01_windows_bootstrap/plan_cloud_G07_0.log`
|
||||
- `agent-task/m-cross-os-runner-bootstrap/03+01_windows_bootstrap/code_review_cloud_G07_0.log`
|
||||
- `apps/runner/assets/script/shell/oto_agent_bootstrap.sh`
|
||||
- `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1`
|
||||
- `services/core/internal/httpserver/oto_agent_bootstrap.ps1`
|
||||
- `services/core/internal/httpserver/bootstrap_provider.go`
|
||||
- `services/core/internal/httpserver/routes.go`
|
||||
- `services/core/internal/httpserver/runner_handlers.go`
|
||||
- `services/core/internal/httpserver/server_test.go`
|
||||
- `apps/runner/test/oto_agent_bootstrap_script_test.dart`
|
||||
- `apps/runner/test/oto_agent_bootstrap_ps1_test.dart`
|
||||
- `README.md`
|
||||
|
||||
### 테스트 환경 규칙
|
||||
|
||||
- test_env: local.
|
||||
- `agent-test/local/rules.md`를 읽었고, 기본 local 검증은 원격 runner 기준이지만 현재 checkout에서 Go/Dart 명령을 재실행해 증거를 확인했다.
|
||||
- matching profiles: `agent-test/local/cli-smoke.md`, `agent-test/local/agent-smoke.md`.
|
||||
- 적용 명령: `cd services/core && go test ./...`, `cd apps/runner && dart test test/oto_agent_bootstrap_script_test.dart`, `cd apps/runner && dart test test/oto_agent_bootstrap_ps1_test.dart`, `cd apps/runner && dart analyze`.
|
||||
- 후속에서는 Go test cache를 피하기 위해 `go test -count=1 ./...`를 사용한다.
|
||||
|
||||
### 테스트 커버리지 공백
|
||||
|
||||
- Windows `.ps1` route와 embedded drift는 Go test가 커버한다.
|
||||
- Windows command URL/quoting은 기존 `server_test.go` cases 11, 12가 커버한다.
|
||||
- PowerShell script content test는 required flags, asset pattern, HTTPS, config key, token output 비노출을 커버한다.
|
||||
- 공백: background mode에서 stdout/stderr redirect 대상이 서로 달라야 한다는 계약을 테스트하지 않는다.
|
||||
- 공백: token-bearing config 파일에 Windows permission hardening을 적용한다는 계약을 테스트하지 않는다.
|
||||
|
||||
### 심볼 참조
|
||||
|
||||
- renamed/removed symbol 없음.
|
||||
- 새 provider/handler 참조는 `registerRoutes`, `handleServeBootstrapPs1`, `embeddedBootstrapPs1Provider`, `server_test.go`에서 확인했다.
|
||||
|
||||
### 분할 판단
|
||||
|
||||
- 현재 디렉터리 `03+01_windows_bootstrap`는 split subtask이며 predecessor `01_core_command`는 `agent-task/archive/2026/06/m-cross-os-runner-bootstrap/01_core_command/complete.log`로 충족됐다.
|
||||
- 후속은 같은 PowerShell bootstrap script와 content tests 안의 리뷰 수정 2건이다. stdout/stderr redirect와 config ACL은 같은 Windows bootstrap runtime 계약 안에 있어 별도 subtask로 나누면 동일 파일 동기화만 늘어난다.
|
||||
|
||||
### 범위 결정 근거
|
||||
|
||||
- 수정 범위는 `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1`, mirrored `services/core/internal/httpserver/oto_agent_bootstrap.ps1`, `apps/runner/test/oto_agent_bootstrap_ps1_test.dart`로 제한한다.
|
||||
- Go route/provider code와 Windows command generation은 1차 구현 및 선행 subtask 검증이 통과했으므로 이번 후속에서 구조 변경하지 않는다.
|
||||
- 실제 Windows integration smoke, release packaging, checksum/signature, Windows service manager 등록은 기존 계획의 범위 제외를 유지한다.
|
||||
|
||||
### 빌드 등급
|
||||
|
||||
- `cloud-G07`: PowerShell process control, stdout/stderr redirection, credential-bearing config permission 의미가 중심이고 실제 Windows runtime 검증을 deterministic content/handler evidence로 보완해야 한다.
|
||||
|
||||
## 구현 체크리스트
|
||||
|
||||
- [ ] PowerShell background 실행에서 stdout/stderr redirect target을 분리하고 content regression으로 고정한다.
|
||||
- [ ] token-bearing Windows config 파일에 chmod 600 equivalent ACL hardening을 적용하고 content regression으로 고정한다.
|
||||
- [ ] runner/Core PS1 asset을 byte-identical하게 동기화하고 focused 검증을 실행한다.
|
||||
- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다.
|
||||
|
||||
### [REVIEW_BOOTSTRAP_WINDOWS-1] Background log redirection 수정
|
||||
|
||||
문제: `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:100` 및 mirrored `services/core/internal/httpserver/oto_agent_bootstrap.ps1:100`에서 `Start-Process`가 `-RedirectStandardOutput`과 `-RedirectStandardError`에 같은 `$logFile`을 넘긴다. Windows PowerShell에서 같은 redirect target은 process start 실패로 이어질 수 있어 기본 background bootstrap이 깨질 수 있다.
|
||||
|
||||
해결 방법:
|
||||
|
||||
Before:
|
||||
|
||||
```powershell
|
||||
# apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:99
|
||||
$logFile = Join-Path $logDir 'oto-agent.log'
|
||||
$proc = Start-Process -FilePath $otoBin `
|
||||
-ArgumentList "agent run --config `"$configPath`"" `
|
||||
-RedirectStandardOutput $logFile `
|
||||
-RedirectStandardError $logFile `
|
||||
-WindowStyle Hidden `
|
||||
-PassThru
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```powershell
|
||||
$stdoutLog = Join-Path $logDir 'oto-agent.out.log'
|
||||
$stderrLog = Join-Path $logDir 'oto-agent.err.log'
|
||||
$proc = Start-Process -FilePath $otoBin `
|
||||
-ArgumentList "agent run --config `"$configPath`"" `
|
||||
-RedirectStandardOutput $stdoutLog `
|
||||
-RedirectStandardError $stderrLog `
|
||||
-WindowStyle Hidden `
|
||||
-PassThru
|
||||
```
|
||||
|
||||
`Write-Host` 안내도 단일 `$logFile` 대신 두 파일 경로를 출력하게 맞춘다. token 값은 출력하지 않는다.
|
||||
|
||||
수정 파일 및 체크리스트:
|
||||
|
||||
- `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1`
|
||||
- `services/core/internal/httpserver/oto_agent_bootstrap.ps1`
|
||||
- `apps/runner/test/oto_agent_bootstrap_ps1_test.dart`
|
||||
|
||||
테스트 작성: `oto_agent_bootstrap_ps1_test.dart`에 `-RedirectStandardOutput $stdoutLog`, `-RedirectStandardError $stderrLog`, `oto-agent.out.log`, `oto-agent.err.log`가 존재하고 `-RedirectStandardOutput $logFile` / `-RedirectStandardError $logFile` 패턴이 없음을 assertion한다.
|
||||
|
||||
중간 검증: `cd apps/runner && dart test test/oto_agent_bootstrap_ps1_test.dart`가 `All tests passed!`로 종료해야 한다.
|
||||
|
||||
### [REVIEW_BOOTSTRAP_WINDOWS-2] Config ACL hardening 추가
|
||||
|
||||
문제: `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:93` 및 mirrored `services/core/internal/httpserver/oto_agent_bootstrap.ps1:93`에서 enrollment token이 들어간 config를 쓴 뒤 Windows ACL/permission을 제한하지 않는다. agent 도메인 규칙은 생성 config 파일을 `chmod 600` 의미로 보호해야 한다.
|
||||
|
||||
해결 방법:
|
||||
|
||||
Before:
|
||||
|
||||
```powershell
|
||||
# apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1:93
|
||||
[System.IO.File]::WriteAllText($configPath, $configContent)
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```powershell
|
||||
[System.IO.File]::WriteAllText($configPath, $configContent)
|
||||
$acl = Get-Acl $configPath
|
||||
$acl.SetAccessRuleProtection($true, $false)
|
||||
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
||||
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||
$currentUser,
|
||||
'FullControl',
|
||||
'Allow'
|
||||
)
|
||||
$acl.SetAccessRule($accessRule)
|
||||
Set-Acl -Path $configPath -AclObject $acl
|
||||
```
|
||||
|
||||
필요하면 위 구조를 작은 helper 함수로 빼도 되지만, 새 의존성은 추가하지 않는다. runner asset 수정 후 Core embedded copy는 byte-identical하게 갱신한다.
|
||||
|
||||
수정 파일 및 체크리스트:
|
||||
|
||||
- `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1`
|
||||
- `services/core/internal/httpserver/oto_agent_bootstrap.ps1`
|
||||
- `apps/runner/test/oto_agent_bootstrap_ps1_test.dart`
|
||||
|
||||
테스트 작성: `oto_agent_bootstrap_ps1_test.dart`에 `SetAccessRuleProtection($true, $false)`, `WindowsIdentity`, `FileSystemAccessRule`, `Set-Acl` 중 실제 구현에 맞는 permission hardening assertion을 추가한다. token output 비노출 assertion은 유지한다.
|
||||
|
||||
중간 검증: `cd apps/runner && dart test test/oto_agent_bootstrap_ps1_test.dart`가 `All tests passed!`로 종료해야 한다.
|
||||
|
||||
### [REVIEW_BOOTSTRAP_WINDOWS-3] Drift 및 focused 검증
|
||||
|
||||
문제: runner PS1 asset과 Core embedded PS1 copy가 하나라도 빠지면 `/bootstrap/oto-agent.ps1` route가 오래된 script를 serve할 수 있다.
|
||||
|
||||
해결 방법: runner asset을 source of truth로 보고 Core embedded copy를 동일 내용으로 갱신한다. 기존 `TestEmbeddedBootstrapPs1MatchesRunnerAsset`가 byte drift를 잡는다.
|
||||
|
||||
수정 파일 및 체크리스트:
|
||||
|
||||
- `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1`
|
||||
- `services/core/internal/httpserver/oto_agent_bootstrap.ps1`
|
||||
- `services/core/internal/httpserver/server_test.go`는 drift test가 이미 있으므로 실패할 때만 수정한다.
|
||||
|
||||
테스트 작성: 기존 Go drift test를 유지한다. 별도 Go 테스트 추가는 필요하지 않다.
|
||||
|
||||
중간 검증: `cd services/core && go test -count=1 ./...`가 통과해야 한다.
|
||||
|
||||
## 수정 파일 요약
|
||||
|
||||
| 경로 | 항목 |
|
||||
|------|------|
|
||||
| `apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1` | REVIEW_BOOTSTRAP_WINDOWS-1, REVIEW_BOOTSTRAP_WINDOWS-2, REVIEW_BOOTSTRAP_WINDOWS-3 |
|
||||
| `services/core/internal/httpserver/oto_agent_bootstrap.ps1` | REVIEW_BOOTSTRAP_WINDOWS-1, REVIEW_BOOTSTRAP_WINDOWS-2, REVIEW_BOOTSTRAP_WINDOWS-3 |
|
||||
| `apps/runner/test/oto_agent_bootstrap_ps1_test.dart` | REVIEW_BOOTSTRAP_WINDOWS-1, REVIEW_BOOTSTRAP_WINDOWS-2 |
|
||||
| `services/core/internal/httpserver/server_test.go` | REVIEW_BOOTSTRAP_WINDOWS-3 only if existing drift test needs maintenance |
|
||||
|
||||
## 최종 검증
|
||||
|
||||
- `cd apps/runner && dart test test/oto_agent_bootstrap_ps1_test.dart`
|
||||
- `cd apps/runner && dart test test/oto_agent_bootstrap_script_test.dart`
|
||||
- `cd apps/runner && dart analyze`
|
||||
- `cd services/core && go test -count=1 ./...`
|
||||
- `rg --sort path -n "RedirectStandardOutput|RedirectStandardError|SetAccessRuleProtection|FileSystemAccessRule|Set-Acl|oto-agent\\.out\\.log|oto-agent\\.err\\.log" apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1 services/core/internal/httpserver/oto_agent_bootstrap.ps1 apps/runner/test/oto_agent_bootstrap_ps1_test.dart`
|
||||
|
||||
모든 코드 변경 완료 후 반드시 `CODE_REVIEW-*-G??.md`의 구현 에이전트 소유 섹션을 채운다. 이 파일 작성이 구현의 마지막 단계다.
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
<!-- task=m-cross-os-runner-bootstrap/03+01_windows_bootstrap plan=0 tag=BOOTSTRAP_WINDOWS -->
|
||||
|
||||
# CODE REVIEW: Windows PowerShell bootstrap 추가
|
||||
|
||||
## Roadmap Targets
|
||||
|
||||
- Milestone: `agent-roadmap/phase/control-plane-product-surface/milestones/cross-os-runner-bootstrap.md`
|
||||
- Epic: `[bootstrap-platforms] Cross-OS bootstrap contract`
|
||||
- Task id: `[windows-bootstrap]`
|
||||
- Completion mode: check-on-pass
|
||||
|
||||
## 사용자 리뷰 요청
|
||||
|
||||
_기본값은 `없음`이다. 구현 중 사용자 결정, 사용자 소유 외부 환경/secret/서비스 준비, 또는 계획 범위 변경 없이는 안전하게 진행할 수 없으면 아래 항목을 실제 내용으로 교체하고, 구현을 중단한 뒤 active 파일을 그대로 둔 채 리뷰를 요청한다. 구현 에이전트는 사용자에게 직접 질문하거나 선택지를 제시하거나 `request_user_input`을 호출하지 않는다. 후속 에이전트가 명령 재실행이나 산출물 수집으로 해소할 수 있는 검증 증거 공백만으로는 사용자 리뷰 요청을 작성하지 않는다._
|
||||
|
||||
- 상태: 없음
|
||||
- 사유 유형: 없음
|
||||
- 결정 필요: 없음
|
||||
- 차단 근거: 없음
|
||||
- 실행한 검증/명령: 없음
|
||||
- 자동 후속 불가 이유: 없음
|
||||
- 재개 조건: 없음
|
||||
|
||||
## 구현 에이전트 소유 섹션
|
||||
|
||||
### 계획 대비 변경 사항
|
||||
|
||||
- 미작성
|
||||
|
||||
### 수정 파일
|
||||
|
||||
- 미작성
|
||||
|
||||
### 검증 결과
|
||||
|
||||
- 미작성
|
||||
|
||||
### 구현 체크리스트
|
||||
|
||||
- [ ] PowerShell bootstrap asset을 추가하고 Windows x64/arm64 zip asset 선택을 고정한다.
|
||||
- [ ] Core가 `.ps1` bootstrap asset을 serve하고 Windows command에서 해당 URL을 사용한다.
|
||||
- [ ] script/config 생성 시 기존 agent 설정 의미를 유지하고 enrollment token 출력 노출을 피한다.
|
||||
- [ ] Windows route, content, command, quoting, zip asset 이름을 테스트한다.
|
||||
- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다.
|
||||
|
||||
## 코드 리뷰 전용 섹션
|
||||
|
||||
- [ ] `01_core_command` 완료 근거가 있다.
|
||||
- [ ] PowerShell quoting과 Windows path가 fixture로 검증된다.
|
||||
- [ ] `.ps1` serving route와 command URL이 일치한다.
|
||||
- [ ] token/credential 출력 노출이 없다.
|
||||
|
||||
## 완료 판정 메모
|
||||
|
||||
| 항목 | 값 |
|
||||
|------|----|
|
||||
| Verdict | 미작성 |
|
||||
| Roadmap Completion | `[windows-bootstrap]` only |
|
||||
| Archive ready | 미작성 |
|
||||
127
apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1
Normal file
127
apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
#Requires -Version 5.1
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$serverUrl = ''
|
||||
$agentId = ''
|
||||
$enrollmentToken = ''
|
||||
$releaseBaseUrl = ''
|
||||
$agentAlias = ''
|
||||
$installDir = Join-Path $env:LOCALAPPDATA 'oto\bin'
|
||||
$configPath = Join-Path $env:LOCALAPPDATA 'oto\agent\config.yaml'
|
||||
$workspaceRoot = Join-Path $env:LOCALAPPDATA 'oto\workspace'
|
||||
$logDir = Join-Path $env:LOCALAPPDATA 'oto\agent\log'
|
||||
$background = $true
|
||||
|
||||
$i = 0
|
||||
while ($i -lt $args.Count) {
|
||||
switch ($args[$i]) {
|
||||
'--' { $i++ }
|
||||
'--server-url' { $serverUrl = $args[$i + 1]; $i += 2 }
|
||||
'--agent-id' { $agentId = $args[$i + 1]; $i += 2 }
|
||||
'--enrollment-token' { $enrollmentToken = $args[$i + 1]; $i += 2 }
|
||||
'--release-base-url' { $releaseBaseUrl = $args[$i + 1]; $i += 2 }
|
||||
'--agent-alias' { $agentAlias = $args[$i + 1]; $i += 2 }
|
||||
'--install-dir' { $installDir = $args[$i + 1]; $i += 2 }
|
||||
'--config-path' { $configPath = $args[$i + 1]; $i += 2 }
|
||||
'--workspace-root' { $workspaceRoot = $args[$i + 1]; $i += 2 }
|
||||
'--log-dir' { $logDir = $args[$i + 1]; $i += 2 }
|
||||
'--no-background' { $background = $false; $i++ }
|
||||
default { Write-Error "Unknown option: $($args[$i])"; exit 1 }
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $serverUrl -or -not $agentId -or -not $enrollmentToken -or -not $releaseBaseUrl) {
|
||||
Write-Error 'Error: Missing required arguments: --server-url, --agent-id, --enrollment-token, --release-base-url'
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (-not $releaseBaseUrl.StartsWith('https://')) {
|
||||
Write-Error 'Error: --release-base-url must use https://'
|
||||
exit 1
|
||||
}
|
||||
|
||||
$arch = $env:PROCESSOR_ARCHITECTURE
|
||||
$archName = switch ($arch) {
|
||||
'AMD64' { 'x64' }
|
||||
'ARM64' { 'arm64' }
|
||||
default {
|
||||
Write-Error "Error: Unsupported architecture: $arch"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
$assetName = "oto-windows-$archName.zip"
|
||||
$downloadUrl = "$releaseBaseUrl/$assetName"
|
||||
|
||||
$tmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
|
||||
New-Item -ItemType Directory -Path $tmpDir | Out-Null
|
||||
|
||||
try {
|
||||
$zipPath = Join-Path $tmpDir $assetName
|
||||
|
||||
Write-Host 'Downloading OTO agent...'
|
||||
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing
|
||||
|
||||
Write-Host 'Extracting OTO agent...'
|
||||
Expand-Archive -Path $zipPath -DestinationPath $tmpDir -Force
|
||||
|
||||
$null = New-Item -ItemType Directory -Path $installDir -Force
|
||||
Copy-Item -Path (Join-Path $tmpDir 'oto.exe') -Destination (Join-Path $installDir 'oto.exe') -Force
|
||||
|
||||
$configDir = Split-Path $configPath -Parent
|
||||
$agentStateDir = Join-Path $env:LOCALAPPDATA 'oto\agent'
|
||||
$pidPath = Join-Path $agentStateDir 'oto-agent.pid'
|
||||
|
||||
$null = New-Item -ItemType Directory -Path $configDir -Force
|
||||
$null = New-Item -ItemType Directory -Path $agentStateDir -Force
|
||||
$null = New-Item -ItemType Directory -Path $workspaceRoot -Force
|
||||
$null = New-Item -ItemType Directory -Path $logDir -Force
|
||||
|
||||
$configContent = @"
|
||||
agent:
|
||||
id: "$agentId"
|
||||
alias: "$agentAlias"
|
||||
enrollment_token: "$enrollmentToken"
|
||||
server:
|
||||
url: "$serverUrl"
|
||||
runtime:
|
||||
install_dir: "$($installDir -replace '\\', '/')"
|
||||
workspace_root: "$($workspaceRoot -replace '\\', '/')"
|
||||
log_dir: "$($logDir -replace '\\', '/')"
|
||||
"@
|
||||
[System.IO.File]::WriteAllText($configPath, $configContent)
|
||||
|
||||
$acl = Get-Acl $configPath
|
||||
$acl.SetAccessRuleProtection($true, $false)
|
||||
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name,
|
||||
'FullControl',
|
||||
'Allow'
|
||||
)
|
||||
$acl.SetAccessRule($rule)
|
||||
Set-Acl -Path $configPath -AclObject $acl
|
||||
|
||||
$otoBin = Join-Path $installDir 'oto.exe'
|
||||
|
||||
if ($background) {
|
||||
Write-Host 'Starting OTO agent in the background...'
|
||||
$outLog = Join-Path $logDir 'oto-agent.out.log'
|
||||
$errLog = Join-Path $logDir 'oto-agent.err.log'
|
||||
$proc = Start-Process -FilePath $otoBin `
|
||||
-ArgumentList "agent run --config `"$configPath`"" `
|
||||
-RedirectStandardOutput $outLog `
|
||||
-RedirectStandardError $errLog `
|
||||
-WindowStyle Hidden `
|
||||
-PassThru
|
||||
[System.IO.File]::WriteAllText($pidPath, $proc.Id.ToString())
|
||||
Write-Host "OTO agent started in the background. PID: $($proc.Id)"
|
||||
Write-Host "Log path: $outLog"
|
||||
} else {
|
||||
Write-Host 'OTO agent is configured to run in the foreground.'
|
||||
Write-Host 'To run it manually, use the following command:'
|
||||
Write-Host " $otoBin agent run --config `"$configPath`""
|
||||
}
|
||||
} finally {
|
||||
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $tmpDir
|
||||
}
|
||||
116
apps/runner/test/oto_agent_bootstrap_ps1_test.dart
Normal file
116
apps/runner/test/oto_agent_bootstrap_ps1_test.dart
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
final scriptFile = File(
|
||||
'assets/script/powershell/oto_agent_bootstrap.ps1',
|
||||
);
|
||||
|
||||
group('Windows PowerShell Bootstrap Script Contract Tests', () {
|
||||
late String content;
|
||||
|
||||
setUpAll(() async {
|
||||
expect(
|
||||
await scriptFile.exists(),
|
||||
isTrue,
|
||||
reason: 'PowerShell bootstrap script file must exist',
|
||||
);
|
||||
content = await scriptFile.readAsString();
|
||||
});
|
||||
|
||||
test('should contain required flags', () {
|
||||
expect(content, contains('--server-url'));
|
||||
expect(content, contains('--agent-id'));
|
||||
expect(content, contains('--enrollment-token'));
|
||||
expect(content, contains('--release-base-url'));
|
||||
});
|
||||
|
||||
test('should contain optional flags', () {
|
||||
expect(content, contains('--agent-alias'));
|
||||
expect(content, contains('--install-dir'));
|
||||
expect(content, contains('--config-path'));
|
||||
expect(content, contains('--workspace-root'));
|
||||
expect(content, contains('--log-dir'));
|
||||
expect(content, contains('--no-background'));
|
||||
});
|
||||
|
||||
test('should support Windows x64 and arm64 zip assets via dynamic arch combination', () {
|
||||
expect(content, contains("'x64'"));
|
||||
expect(content, contains("'arm64'"));
|
||||
expect(content, contains('oto-windows-'));
|
||||
expect(content, contains('.zip'));
|
||||
expect(content, contains(r'"oto-windows-$archName.zip"'));
|
||||
});
|
||||
|
||||
test('should detect architecture via PROCESSOR_ARCHITECTURE', () {
|
||||
expect(content, contains('PROCESSOR_ARCHITECTURE'));
|
||||
expect(content, contains('AMD64'));
|
||||
expect(content, contains('ARM64'));
|
||||
expect(content, contains("'x64'"));
|
||||
expect(content, contains("'arm64'"));
|
||||
});
|
||||
|
||||
test('should fail with unsupported architecture message', () {
|
||||
expect(content, contains('Unsupported architecture:'));
|
||||
});
|
||||
|
||||
test('should validate HTTPS for release-base-url', () {
|
||||
expect(content, contains('https://'));
|
||||
expect(content, contains('--release-base-url must use https://'));
|
||||
});
|
||||
|
||||
test('should write expected keys to configuration yaml', () {
|
||||
expect(content, contains('agent:'));
|
||||
expect(content, contains('id:'));
|
||||
expect(content, contains('alias:'));
|
||||
expect(content, contains('enrollment_token:'));
|
||||
expect(content, contains('server:'));
|
||||
expect(content, contains('url:'));
|
||||
expect(content, contains('runtime:'));
|
||||
expect(content, contains('install_dir:'));
|
||||
expect(content, contains('workspace_root:'));
|
||||
expect(content, contains('log_dir:'));
|
||||
});
|
||||
|
||||
test('should contain agent runtime command and background behavior', () {
|
||||
expect(content, contains('agent run'));
|
||||
expect(content, contains('--config'));
|
||||
expect(content, contains('oto-agent.pid'));
|
||||
});
|
||||
|
||||
test('should use separate stdout and stderr log files for background process', () {
|
||||
expect(content, contains('RedirectStandardOutput'));
|
||||
expect(content, contains('RedirectStandardError'));
|
||||
expect(content, contains('oto-agent.out.log'));
|
||||
expect(content, contains('oto-agent.err.log'));
|
||||
});
|
||||
|
||||
test('should apply ACL hardening to config file after write', () {
|
||||
expect(content, contains('SetAccessRuleProtection'));
|
||||
expect(content, contains('FileSystemAccessRule'));
|
||||
expect(content, contains('Set-Acl'));
|
||||
});
|
||||
|
||||
test('should not expose enrollment token in write/output statements', () {
|
||||
final lines = content.split('\n');
|
||||
for (final line in lines) {
|
||||
final trimmed = line.trim();
|
||||
// Skip the config write block that intentionally contains the token key
|
||||
if (trimmed.contains('enrollment_token:') && trimmed.contains(r'"$enrollmentToken"')) {
|
||||
continue;
|
||||
}
|
||||
// No Write-Host / Write-Error / Write-Output line should directly print
|
||||
// the enrollment token variable outside config file construction.
|
||||
if (trimmed.startsWith('Write-Host') ||
|
||||
trimmed.startsWith('Write-Error') ||
|
||||
trimmed.startsWith('Write-Output')) {
|
||||
expect(
|
||||
trimmed,
|
||||
isNot(contains(r'$enrollmentToken')),
|
||||
reason: 'Output statement must not expose enrollment token: $trimmed',
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -8,12 +8,20 @@ import (
|
|||
//go:embed oto_agent_bootstrap.sh
|
||||
var embeddedBootstrapScript []byte
|
||||
|
||||
//go:embed oto_agent_bootstrap.ps1
|
||||
var embeddedBootstrapPs1 []byte
|
||||
|
||||
// bootstrapScriptProvider returns the content of the OTO agent bootstrap script.
|
||||
type bootstrapScriptProvider interface {
|
||||
bootstrapScript() ([]byte, error)
|
||||
}
|
||||
|
||||
// embeddedBootstrapProvider serves the script compiled into the binary via go:embed.
|
||||
// bootstrapPs1Provider returns the content of the OTO agent PowerShell bootstrap script.
|
||||
type bootstrapPs1Provider interface {
|
||||
bootstrapPs1() ([]byte, error)
|
||||
}
|
||||
|
||||
// embeddedBootstrapProvider serves the shell script compiled into the binary via go:embed.
|
||||
type embeddedBootstrapProvider struct{}
|
||||
|
||||
func (embeddedBootstrapProvider) bootstrapScript() ([]byte, error) {
|
||||
|
|
@ -22,3 +30,13 @@ func (embeddedBootstrapProvider) bootstrapScript() ([]byte, error) {
|
|||
}
|
||||
return embeddedBootstrapScript, nil
|
||||
}
|
||||
|
||||
// embeddedBootstrapPs1Provider serves the PowerShell script compiled into the binary via go:embed.
|
||||
type embeddedBootstrapPs1Provider struct{}
|
||||
|
||||
func (embeddedBootstrapPs1Provider) bootstrapPs1() ([]byte, error) {
|
||||
if len(embeddedBootstrapPs1) == 0 {
|
||||
return nil, fmt.Errorf("embedded bootstrap PS1 script is empty")
|
||||
}
|
||||
return embeddedBootstrapPs1, nil
|
||||
}
|
||||
|
|
|
|||
127
services/core/internal/httpserver/oto_agent_bootstrap.ps1
Normal file
127
services/core/internal/httpserver/oto_agent_bootstrap.ps1
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
#Requires -Version 5.1
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$serverUrl = ''
|
||||
$agentId = ''
|
||||
$enrollmentToken = ''
|
||||
$releaseBaseUrl = ''
|
||||
$agentAlias = ''
|
||||
$installDir = Join-Path $env:LOCALAPPDATA 'oto\bin'
|
||||
$configPath = Join-Path $env:LOCALAPPDATA 'oto\agent\config.yaml'
|
||||
$workspaceRoot = Join-Path $env:LOCALAPPDATA 'oto\workspace'
|
||||
$logDir = Join-Path $env:LOCALAPPDATA 'oto\agent\log'
|
||||
$background = $true
|
||||
|
||||
$i = 0
|
||||
while ($i -lt $args.Count) {
|
||||
switch ($args[$i]) {
|
||||
'--' { $i++ }
|
||||
'--server-url' { $serverUrl = $args[$i + 1]; $i += 2 }
|
||||
'--agent-id' { $agentId = $args[$i + 1]; $i += 2 }
|
||||
'--enrollment-token' { $enrollmentToken = $args[$i + 1]; $i += 2 }
|
||||
'--release-base-url' { $releaseBaseUrl = $args[$i + 1]; $i += 2 }
|
||||
'--agent-alias' { $agentAlias = $args[$i + 1]; $i += 2 }
|
||||
'--install-dir' { $installDir = $args[$i + 1]; $i += 2 }
|
||||
'--config-path' { $configPath = $args[$i + 1]; $i += 2 }
|
||||
'--workspace-root' { $workspaceRoot = $args[$i + 1]; $i += 2 }
|
||||
'--log-dir' { $logDir = $args[$i + 1]; $i += 2 }
|
||||
'--no-background' { $background = $false; $i++ }
|
||||
default { Write-Error "Unknown option: $($args[$i])"; exit 1 }
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $serverUrl -or -not $agentId -or -not $enrollmentToken -or -not $releaseBaseUrl) {
|
||||
Write-Error 'Error: Missing required arguments: --server-url, --agent-id, --enrollment-token, --release-base-url'
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (-not $releaseBaseUrl.StartsWith('https://')) {
|
||||
Write-Error 'Error: --release-base-url must use https://'
|
||||
exit 1
|
||||
}
|
||||
|
||||
$arch = $env:PROCESSOR_ARCHITECTURE
|
||||
$archName = switch ($arch) {
|
||||
'AMD64' { 'x64' }
|
||||
'ARM64' { 'arm64' }
|
||||
default {
|
||||
Write-Error "Error: Unsupported architecture: $arch"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
$assetName = "oto-windows-$archName.zip"
|
||||
$downloadUrl = "$releaseBaseUrl/$assetName"
|
||||
|
||||
$tmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
|
||||
New-Item -ItemType Directory -Path $tmpDir | Out-Null
|
||||
|
||||
try {
|
||||
$zipPath = Join-Path $tmpDir $assetName
|
||||
|
||||
Write-Host 'Downloading OTO agent...'
|
||||
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing
|
||||
|
||||
Write-Host 'Extracting OTO agent...'
|
||||
Expand-Archive -Path $zipPath -DestinationPath $tmpDir -Force
|
||||
|
||||
$null = New-Item -ItemType Directory -Path $installDir -Force
|
||||
Copy-Item -Path (Join-Path $tmpDir 'oto.exe') -Destination (Join-Path $installDir 'oto.exe') -Force
|
||||
|
||||
$configDir = Split-Path $configPath -Parent
|
||||
$agentStateDir = Join-Path $env:LOCALAPPDATA 'oto\agent'
|
||||
$pidPath = Join-Path $agentStateDir 'oto-agent.pid'
|
||||
|
||||
$null = New-Item -ItemType Directory -Path $configDir -Force
|
||||
$null = New-Item -ItemType Directory -Path $agentStateDir -Force
|
||||
$null = New-Item -ItemType Directory -Path $workspaceRoot -Force
|
||||
$null = New-Item -ItemType Directory -Path $logDir -Force
|
||||
|
||||
$configContent = @"
|
||||
agent:
|
||||
id: "$agentId"
|
||||
alias: "$agentAlias"
|
||||
enrollment_token: "$enrollmentToken"
|
||||
server:
|
||||
url: "$serverUrl"
|
||||
runtime:
|
||||
install_dir: "$($installDir -replace '\\', '/')"
|
||||
workspace_root: "$($workspaceRoot -replace '\\', '/')"
|
||||
log_dir: "$($logDir -replace '\\', '/')"
|
||||
"@
|
||||
[System.IO.File]::WriteAllText($configPath, $configContent)
|
||||
|
||||
$acl = Get-Acl $configPath
|
||||
$acl.SetAccessRuleProtection($true, $false)
|
||||
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name,
|
||||
'FullControl',
|
||||
'Allow'
|
||||
)
|
||||
$acl.SetAccessRule($rule)
|
||||
Set-Acl -Path $configPath -AclObject $acl
|
||||
|
||||
$otoBin = Join-Path $installDir 'oto.exe'
|
||||
|
||||
if ($background) {
|
||||
Write-Host 'Starting OTO agent in the background...'
|
||||
$outLog = Join-Path $logDir 'oto-agent.out.log'
|
||||
$errLog = Join-Path $logDir 'oto-agent.err.log'
|
||||
$proc = Start-Process -FilePath $otoBin `
|
||||
-ArgumentList "agent run --config `"$configPath`"" `
|
||||
-RedirectStandardOutput $outLog `
|
||||
-RedirectStandardError $errLog `
|
||||
-WindowStyle Hidden `
|
||||
-PassThru
|
||||
[System.IO.File]::WriteAllText($pidPath, $proc.Id.ToString())
|
||||
Write-Host "OTO agent started in the background. PID: $($proc.Id)"
|
||||
Write-Host "Log path: $outLog"
|
||||
} else {
|
||||
Write-Host 'OTO agent is configured to run in the foreground.'
|
||||
Write-Host 'To run it manually, use the following command:'
|
||||
Write-Host " $otoBin agent run --config `"$configPath`""
|
||||
}
|
||||
} finally {
|
||||
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $tmpDir
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ func registerRoutes(mux *http.ServeMux, registry *runnerregistry.Registry, store
|
|||
mux.HandleFunc("/api/v1/runners/{id}/disconnect", handleRunnerDisconnect(registry))
|
||||
mux.HandleFunc("/api/v1/runners/{id}", handleGetRunner(registry))
|
||||
mux.HandleFunc("/bootstrap/oto-agent.sh", handleServeBootstrapScript(embeddedBootstrapProvider{}))
|
||||
mux.HandleFunc("/bootstrap/oto-agent.ps1", handleServeBootstrapPs1(embeddedBootstrapPs1Provider{}))
|
||||
mux.HandleFunc("/api/v1/", handleRouter(store, registry))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -293,6 +293,23 @@ func handleServeBootstrapScript(provider bootstrapScriptProvider) http.HandlerFu
|
|||
}
|
||||
}
|
||||
|
||||
func handleServeBootstrapPs1(provider bootstrapPs1Provider) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
content, err := provider.bootstrapPs1()
|
||||
if err != nil {
|
||||
http.Error(w, "Bootstrap PS1 script not available: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/x-powershell")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(content)
|
||||
}
|
||||
}
|
||||
|
||||
func writeRunnerRegisterResponse(w http.ResponseWriter, status int, response *otopb.RegisterRunnerResponse) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
|
|
|
|||
|
|
@ -587,6 +587,14 @@ type staticProvider struct {
|
|||
|
||||
func (p staticProvider) bootstrapScript() ([]byte, error) { return p.content, p.err }
|
||||
|
||||
// staticPs1Provider is a test-only bootstrapPs1Provider with fixed content.
|
||||
type staticPs1Provider struct {
|
||||
content []byte
|
||||
err error
|
||||
}
|
||||
|
||||
func (p staticPs1Provider) bootstrapPs1() ([]byte, error) { return p.content, p.err }
|
||||
|
||||
func TestHandleServeBootstrapScript(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodGet, "/bootstrap/oto-agent.sh", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
|
@ -658,6 +666,94 @@ func TestEmbeddedBootstrapScriptNonEmpty(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestHandleServeBootstrapPs1(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodGet, "/bootstrap/oto-agent.ps1", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handleServeBootstrapPs1(staticPs1Provider{content: []byte("#Requires -Version 5.1\n")})(rr, req)
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Fatalf("status = %v, want %v; body = %s", rr.Code, http.StatusOK, rr.Body.String())
|
||||
}
|
||||
|
||||
if contentType := rr.Header().Get("Content-Type"); contentType != "application/x-powershell" {
|
||||
t.Fatalf("Content-Type = %q, want application/x-powershell", contentType)
|
||||
}
|
||||
|
||||
if len(rr.Body.Bytes()) == 0 {
|
||||
t.Fatal("empty PS1 bootstrap script returned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleServeBootstrapPs1_MethodNotAllowed(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodPost, "/bootstrap/oto-agent.ps1", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handleServeBootstrapPs1(staticPs1Provider{content: []byte("#Requires -Version 5.1\n")})(rr, req)
|
||||
if rr.Code != http.StatusMethodNotAllowed {
|
||||
t.Fatalf("status = %v, want %v", rr.Code, http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleServeBootstrapPs1_ProviderError(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodGet, "/bootstrap/oto-agent.ps1", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handleServeBootstrapPs1(staticPs1Provider{err: fmt.Errorf("ps1 unavailable")})(rr, req)
|
||||
if rr.Code != http.StatusInternalServerError {
|
||||
t.Fatalf("status = %v, want %v", rr.Code, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmbeddedBootstrapPs1MatchesRunnerAsset(t *testing.T) {
|
||||
// Drift check: embedded copy must be byte-identical to the runner asset.
|
||||
// On failure: cp apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1 \
|
||||
// services/core/internal/httpserver/oto_agent_bootstrap.ps1
|
||||
embedded, err := embeddedBootstrapPs1Provider{}.bootstrapPs1()
|
||||
if err != nil {
|
||||
t.Fatalf("embeddedBootstrapPs1Provider.bootstrapPs1() failed: %v", err)
|
||||
}
|
||||
|
||||
const runnerAsset = "../../../../apps/runner/assets/script/powershell/oto_agent_bootstrap.ps1"
|
||||
asset, err := os.ReadFile(runnerAsset)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read runner asset %s: %v", runnerAsset, err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(embedded, asset) {
|
||||
t.Fatalf("embedded PS1 bootstrap script differs from runner asset %s - "+
|
||||
"run: cp %s services/core/internal/httpserver/oto_agent_bootstrap.ps1",
|
||||
runnerAsset, runnerAsset)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmbeddedBootstrapPs1NonEmpty(t *testing.T) {
|
||||
provider := embeddedBootstrapPs1Provider{}
|
||||
content, err := provider.bootstrapPs1()
|
||||
if err != nil {
|
||||
t.Fatalf("bootstrapPs1() error: %v", err)
|
||||
}
|
||||
if len(content) == 0 {
|
||||
t.Fatal("embedded PS1 bootstrap script content is empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRouteBootstrapPs1(t *testing.T) {
|
||||
registry := runnerregistry.New()
|
||||
server := NewServerWithRegistry(":0", registry)
|
||||
mux := server.httpServer.Handler.(*http.ServeMux)
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/bootstrap/oto-agent.ps1", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
mux.ServeHTTP(rr, req)
|
||||
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Fatalf("mux /bootstrap/oto-agent.ps1 status = %v, want %v; body=%s", rr.Code, http.StatusOK, rr.Body.String())
|
||||
}
|
||||
if contentType := rr.Header().Get("Content-Type"); contentType != "application/x-powershell" {
|
||||
t.Fatalf("Content-Type = %q, want application/x-powershell", contentType)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleCreateJob(t *testing.T) {
|
||||
store := cicdstate.NewStore()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue