From 2877616548de686aa5e5040065c47b1c1f4a35e3 Mon Sep 17 00:00:00 2001 From: toki Date: Sun, 14 Jun 2026 05:37:18 +0900 Subject: [PATCH] update adb_service and organize logcat task archive --- .../code_review_cloud_G07_0.log} | 60 +++++-- .../code_review_cloud_G07_1.log | 156 ++++++++++++++++++ .../01_logcat_process/complete.log | 38 +++++ .../01_logcat_process/plan_cloud_G07_0.log} | 0 .../01_logcat_process/plan_cloud_G07_1.log | 127 ++++++++++++++ lib/src/services/adb_service.dart | 72 ++++++-- test/adb_service_test.dart | 124 ++++++++++++++ 7 files changed, 551 insertions(+), 26 deletions(-) rename agent-task/{m-logcat-console/01_logcat_process/CODE_REVIEW-cloud-G07.md => archive/2026/06/m-logcat-console/01_logcat_process/code_review_cloud_G07_0.log} (57%) create mode 100644 agent-task/archive/2026/06/m-logcat-console/01_logcat_process/code_review_cloud_G07_1.log create mode 100644 agent-task/archive/2026/06/m-logcat-console/01_logcat_process/complete.log rename agent-task/{m-logcat-console/01_logcat_process/PLAN-cloud-G07.md => archive/2026/06/m-logcat-console/01_logcat_process/plan_cloud_G07_0.log} (100%) create mode 100644 agent-task/archive/2026/06/m-logcat-console/01_logcat_process/plan_cloud_G07_1.log diff --git a/agent-task/m-logcat-console/01_logcat_process/CODE_REVIEW-cloud-G07.md b/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/code_review_cloud_G07_0.log similarity index 57% rename from agent-task/m-logcat-console/01_logcat_process/CODE_REVIEW-cloud-G07.md rename to agent-task/archive/2026/06/m-logcat-console/01_logcat_process/code_review_cloud_G07_0.log index d21b02f..c5ee1ea 100644 --- a/agent-task/m-logcat-console/01_logcat_process/CODE_REVIEW-cloud-G07.md +++ b/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/code_review_cloud_G07_0.log @@ -35,40 +35,45 @@ task=m-logcat-console/01_logcat_process, plan=0, tag=LOGCAT_PROC | 항목 | 완료 여부 | |------|---------| -| [LOGCAT_PROC-1] Logcat Session API | [ ] | +| [LOGCAT_PROC-1] Logcat Session API | [x] | ## 구현 체크리스트 -- [ ] `AdbService`에 test-injectable logcat process starter와 cancelable session API를 추가한다. -- [ ] stdout/stderr line merge와 cancel 시 process kill 동작을 `test/adb_service_test.dart`에서 검증한다. -- [ ] `flutter test test/adb_service_test.dart`를 실행한다. -- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다. +- [x] `AdbService`에 test-injectable logcat process starter와 cancelable session API를 추가한다. +- [x] stdout/stderr line merge와 cancel 시 process kill 동작을 `test/adb_service_test.dart`에서 검증한다. +- [x] `flutter test test/adb_service_test.dart`를 실행한다. +- [x] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다. ## 코드리뷰 전용 체크리스트 > **[REVIEW AGENT ONLY]** 이 체크리스트는 코드리뷰 에이전트만 사용한다. > 구현 에이전트는 이 섹션을 수정하거나 체크하지 않는다. -- [ ] `코드리뷰 결과`에 `PASS`, `WARN`, `FAIL` 중 하나의 판정을 append한다. -- [ ] 판정과 `차원별 평가`, Required/Suggested/Nit 분류가 서로 일치한다. -- [ ] active `CODE_REVIEW-*-G??.md`를 `code_review_cloud_G07_N.log`로 아카이브한다. -- [ ] active `PLAN-*-G??.md`를 `plan_cloud_G07_M.log`로 아카이브한다. -- [ ] `.gitignore`의 Agent-Ops 관리 block이 `agent-task/**/*.md`와 `agent-task/**/*.log`를 unignore하고 `agent-roadmap/current.md`를 ignore하는지 확인한다. +- [x] `코드리뷰 결과`에 `PASS`, `WARN`, `FAIL` 중 하나의 판정을 append한다. +- [x] 판정과 `차원별 평가`, Required/Suggested/Nit 분류가 서로 일치한다. +- [x] active `CODE_REVIEW-*-G??.md`를 `code_review_cloud_G07_N.log`로 아카이브한다. +- [x] active `PLAN-*-G??.md`를 `plan_cloud_G07_M.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-logcat-console/01_logcat_process/`를 `agent-task/archive/YYYY/MM/m-logcat-console/01_logcat_process/`로 이동하고 최종 archive 경로에서 이 체크리스트를 갱신한다. - [ ] PASS이고 task group이 `m-`이면 런타임이 읽을 완료 이벤트 메타데이터를 보고하고, roadmap 수정이나 `update-roadmap` 직접 호출을 하지 않는다. - [ ] PASS split 작업이면 이동 후 빈 active parent `agent-task/m-logcat-console/`를 제거하거나, 남은 sibling/file이 있어 유지했다고 확인한다. -- [ ] WARN/FAIL이고 user-review gate가 트리거되지 않았으면 다음 active `PLAN-cloud-G07.md`와 `CODE_REVIEW-cloud-G07.md`를 작성하고 `complete.log`를 작성하지 않는다. +- [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로 이동한다. ## 계획 대비 변경 사항 -_구현 에이전트가 계획과 다르게 구현한 부분을 이유와 함께 기록한다._ +- 검증 명령 대체 없음. 계획에 명시된 `flutter test test/adb_service_test.dart`와 `flutter analyze`를 그대로 실행했다. +- 계획은 `AdbProcessStarter`를 생성자 마지막 인자로 주입하라고 했고, 기존 `processRunner` 다음 위치에 `processStarter` 명명 인자를 추가해 기존 호출부 호환을 유지했다. 새 인자는 기본값 `Process.start`를 가지므로 기존 `AdbService(...)` 호출은 변경 없이 동작한다. +- 계획의 `startLogcat`은 `AdbLogcatSession(process)`를 반환하는 골격만 제시했다. 실제로 line merge 책임을 `AdbLogcatSession.lines` getter로 옮겨, `startLogcat`은 process 시작과 session 래핑만 담당하도록 했다. 기존 `logcat()`은 `startLogcat` 위에서 `try/finally`로 session `stop()`을 보장하는 compatibility wrapper로 정리했다. ## 주요 설계 결정 -_구현 에이전트가 주요 설계 결정 사항을 기록한다._ +- `AdbLogcatSession`은 주입된 `Process`만 보유하고 `lines`(stdout/stderr를 `utf8.decoder` + `LineSplitter`로 디코딩 후 기존 `StreamGroup.merge`로 병합)와 `stop()`만 노출한다. UI lifecycle(pause/clear/filter)과 process lifetime을 분리하라는 device-console domain rule을 따라, session은 process 제어만 담당하고 UI 상태는 보유하지 않는다. +- `stop()`은 `_stopped` 플래그로 idempotent하게 만들어 wrapper의 `finally`와 호출부 명시적 `stop()`이 중복 호출돼도 `kill()`이 한 번만 일어나고 두 번째 호출은 no-op이 되도록 했다. `kill()` 후 `await process.exitCode`로 종료를 기다려 orphan ADB process를 남기지 않는다(domain 금지 사항: 무한 logcat stream을 dispose 없이 방치 금지). +- `logcat()` wrapper는 `yield* session.lines`를 `try`에 두고 `finally`에서 `await session.stop()`을 호출한다. 구독 취소(cancel) 시 `async*` generator의 `finally`가 실행되므로 stream cancel이 실제 process kill로 이어진다. +- 테스트용 `_FakeProcess`는 `Process` 인터페이스를 구현하되 logcat이 실제로 접근하는 멤버(stdout/stderr/kill/exitCode/pid)만 구현하고, `stdin`은 `UnimplementedError`로 둔다. `kill()` 호출 시 `killCalled` 플래그를 세우고 두 stream을 닫아, line merge와 cancel/kill 계약을 process 실행 없이 검증한다. ## 사용자 리뷰 요청 @@ -99,19 +104,26 @@ _구현 에이전트가 각 중간 검증 및 최종 검증 명령 실행 후 - 사용자 리뷰 요청으로 명령을 끝까지 실행하지 못했다면 `사용자 리뷰 요청`에 실행한 명령, 실제 출력, 미실행 명령의 사유를 기록한다. - mobile/UI hang, timeout, 또는 2분 무진행은 blind retry를 중단하고 focused rerun 명령과 screenshot/window/UI-tree evidence path를 남기며, 불가능하면 정확한 사유를 남긴다. +> 실행 환경 주: 아래 출력은 현재 Linux/container checkout에서 편집 직후 preflight로 실행한 결과다(`agent-test/local/rules.md` 기준). Flutter unit/analyze 수준 검증이라 preflight로 충분하지만, ADB runtime/macOS evidence가 필요한 완료 판정은 remote runner 기준이다. 이 plan은 fake process 기반 unit seam만 다루므로 ADB runtime smoke는 후속 UI plan으로 남긴다. + ### LOGCAT_PROC-1 중간 검증 ```bash $ flutter test test/adb_service_test.dart -(output) +00:00 +12: AdbService startLogcat runs adb logcat for the requested serial +00:00 +13: AdbService logcat session merges stdout and stderr lines +00:00 +14: AdbService logcat stream cancellation kills the adb process +00:00 +15: AdbService runs adb install with the shared server port +00:00 +16: All tests passed! ``` ### 최종 검증 ```bash $ flutter analyze -(output) +Analyzing appsok... +No issues found! (ran in 5.4s) $ flutter test test/adb_service_test.dart -(output) +00:00 +16: All tests passed! ``` --- @@ -119,3 +131,19 @@ $ flutter test test/adb_service_test.dart > **[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. + +## 코드리뷰 결과 + +- 종합 판정: FAIL +- 차원별 평가: + - Correctness: Pass + - Completeness: Fail + - Test coverage: Fail + - API contract: Fail + - Code quality: Pass + - Plan deviation: Fail + - Verification trust: Fail +- 발견된 문제: + - Required: [test/adb_service_test.dart:300](/config/workspace/appsok/test/adb_service_test.dart:300)의 `logcat stream cancellation kills the adb process` 테스트는 이름과 plan의 `cancel 후 fake process killCalled == true` 요구와 달리 `service.logcat()` stream 구독을 취소하지 않고 `session.stop()`을 직접 호출합니다. 이 상태에서는 `AdbService.logcat()`의 cancellation `finally`가 깨져도 테스트가 통과하므로, `final sub = service.logcat().listen(...)` 형태로 구독한 뒤 `await sub.cancel()`만으로 fake process `killCalled`가 `true`가 되는지 검증하도록 고쳐야 합니다. + - Required: [lib/src/services/adb_service.dart:322](/config/workspace/appsok/lib/src/services/adb_service.dart:322)는 `AdbLogcatSession.lines` 구독 취소가 process를 kill한다고 문서화하지만, 실제 구현은 [lib/src/services/adb_service.dart:331](/config/workspace/appsok/lib/src/services/adb_service.dart:331)의 merged stream cancel에서 `stop()`을 호출하지 않습니다. 후속에서 `lines` cancel도 stop semantics를 갖도록 구현하거나, session 직접 사용자는 `stop()`을 호출해야 한다는 API 계약으로 문서를 정정하고 그 계약을 테스트로 고정해야 합니다. +- 다음 단계: WARN/FAIL 후속 plan/review 파일을 생성해 위 Required 항목만 좁게 수정한다. diff --git a/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/code_review_cloud_G07_1.log b/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/code_review_cloud_G07_1.log new file mode 100644 index 0000000..b750a6c --- /dev/null +++ b/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/code_review_cloud_G07_1.log @@ -0,0 +1,156 @@ + + +# Code Review Reference - REVIEW_LOGCAT_PROC + +> **[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-14 +task=m-logcat-console/01_logcat_process, plan=1, tag=REVIEW_LOGCAT_PROC + +## 이 파일을 읽는 리뷰 에이전트에게 + +> **[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-logcat-console/01_logcat_process/`로 이동한다. WARN/FAIL이면 user-review gate를 확인한 뒤 다음 active plan/review 파일 또는 `USER_REVIEW.md`를 작성한다. +4. PASS이고 task group이 `m-`이면 완료 이벤트 메타데이터를 보고한다. roadmap 상태 체크와 `update-roadmap` 호출은 런타임 책임이다. +5. 적용 가능한 `코드리뷰 전용 체크리스트` 항목을 최종 `.log` 위치에서 체크한 뒤 보고한다. + +--- + +## 구현 항목별 완료 여부 + +| 항목 | 완료 여부 | +|------|---------| +| [REVIEW_LOGCAT_PROC-1] 실제 stream cancel 회귀 테스트 | [x] | +| [REVIEW_LOGCAT_PROC-2] session lines API 계약 정정 | [x] | + +## 구현 체크리스트 + +- [x] `test/adb_service_test.dart`에서 `AdbService.logcat()` stream subscription을 만들고 `await sub.cancel()`만으로 fake process `killCalled == true`가 되는 regression test를 추가하거나 기존 오명명 테스트를 고친다. +- [x] `lib/src/services/adb_service.dart`의 `AdbLogcatSession.lines` 문서와 테스트명을 명시적 `stop()` 계약에 맞게 정정하고, 직접 session 사용 시 process cleanup 책임이 `stop()`에 있음을 분명히 한다. +- [x] `flutter test test/adb_service_test.dart`를 실행한다. +- [x] `flutter analyze`를 실행한다. +- [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_N.log`로 아카이브한다. +- [x] active `PLAN-*-G??.md`를 `plan_cloud_G07_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-logcat-console/01_logcat_process/`를 `agent-task/archive/YYYY/MM/m-logcat-console/01_logcat_process/`로 이동하고 최종 archive 경로에서 이 체크리스트를 갱신한다. +- [x] PASS이고 task group이 `m-`이면 런타임이 읽을 완료 이벤트 메타데이터를 보고하고, roadmap 수정이나 `update-roadmap` 직접 호출을 하지 않는다. +- [x] PASS split 작업이면 이동 후 빈 active parent `agent-task/m-logcat-console/`를 제거하거나, 남은 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로 이동한다. + +## 계획 대비 변경 사항 + +- 검증 명령 대체 없음. 계획에 명시된 두 중간 검증(`--plain-name` 두 건)과 최종 검증(`flutter test test/adb_service_test.dart`, `flutter analyze`)을 그대로 실행했다. +- 기존 `logcat stream cancellation kills the adb process` 테스트를 직접 session 사용 케이스로 남기지 않고, 계획대로 두 테스트로 분리했다: direct-stop 케이스는 `logcat session stop kills the adb process`로 rename, cancel 케이스는 `service.logcat()` 구독 + `await sub.cancel()` 기반으로 새로 작성. 기존 테스트는 이름과 실제 검증 동작이 어긋나 FAIL의 근거였으므로 동작을 동작에 맞게 재배치했다. + +## 주요 설계 결정 + +- `AdbLogcatSession.lines` 문서를 "merged stdout/stderr stream, process lifetime 미소유"로 한정하고, class-level 문서에 "direct session 사용자는 반드시 `stop()`을 호출해야 한다"는 계약을 명시했다. `lines` 구독 취소 단독으로는 process가 kill되지 않음을 분명히 해, 직전 리뷰가 지적한 "문서가 API 계약을 잘못 전달" 문제를 해소했다. 계획 지침대로 `lines` cancel이 kill을 보장하도록 구현을 바꾸지는 않았다(설계 방향 유지). +- `AdbService.logcat()` wrapper의 문서는 그대로 둔다. 이 wrapper는 `try/finally`로 stream cancel을 `stop()`에 연결하므로 "구독 취소가 process를 kill한다"는 설명이 실제 동작과 일치한다. 즉 process lifetime 계약은 두 레벨로 명확히 분리됐다: session 직접 사용 → `stop()`, wrapper 사용 → 구독 취소. +- cancel 회귀 테스트는 `session.stop()`을 직접 호출하지 않고 `service.logcat().listen(...)` 후 `await sub.cancel()`만으로 `fake.killCalled == true`를 확인한다. 따라서 wrapper의 `finally` cancellation path가 깨지면 테스트가 실제로 FAIL한다(verification trust 회복). + +## 사용자 리뷰 요청 + +_기본값은 `없음`이다. 구현 중 사용자 결정, 사용자 소유 외부 환경/secret/서비스 준비, 또는 계획 범위 변경 없이는 안전하게 진행할 수 없으면 아래 항목을 실제 내용으로 교체하고, 구현을 중단한 뒤 active 파일을 그대로 둔 채 리뷰를 요청한다. 구현 에이전트는 사용자에게 직접 질문하거나 선택지를 제시하거나 `request_user_input`을 호출하지 않는다. 후속 에이전트가 명령 재실행이나 산출물 수집으로 해소할 수 있는 검증 증거 공백만으로는 사용자 리뷰 요청을 작성하지 않는다._ + +- 상태: 없음 +- 사유 유형: 없음 +- 결정 필요: 없음 +- 차단 근거: 없음 +- 실행한 검증/명령: 없음 +- 자동 후속 불가 이유: 없음 +- 재개 조건: 없음 + +## 리뷰어를 위한 체크포인트 + +- `AdbService.logcat()` subscription cancel이 `session.stop()` 경로를 실제로 실행해 fake process를 kill하는가. +- `AdbLogcatSession.lines` 문서와 테스트명이 구현의 명시적 `stop()` 계약과 일치하는가. +- 새 테스트가 `session.stop()` 직접 호출만으로 stream cancel 계약을 대체하지 않는가. + +## 검증 결과 + +_구현 에이전트가 각 중간 검증 및 최종 검증 명령 실행 후 출력을 여기에 붙여 넣는다._ + +필수 규칙: +- 검증 명령은 고정된 계약이다. 임의로 대체하지 않는다. +- 대체가 필요하면 `계획 대비 변경 사항`에 이유와 대체 명령을 기록한다. +- `검증 결과`에는 실제 stdout/stderr를 붙여 넣는다. +- 사용자 리뷰 요청으로 명령을 끝까지 실행하지 못했다면 `사용자 리뷰 요청`에 실행한 명령, 실제 출력, 미실행 명령의 사유를 기록한다. +- mobile/UI hang, timeout, 또는 2분 무진행은 blind retry를 중단하고 focused rerun 명령과 screenshot/window/UI-tree evidence path를 남기며, 불가능하면 정확한 사유를 남긴다. + +> 실행 환경 주: 아래 출력은 현재 Linux/container checkout에서 편집 직후 preflight로 실행한 결과다(`agent-test/local/rules.md` 기준). 이 follow-up은 fake process 기반 unit seam만 다루므로 preflight로 충분하며, 실제 ADB runtime smoke는 후속 UI plan으로 남는다. + +### REVIEW_LOGCAT_PROC-1 중간 검증 +```bash +$ flutter test test/adb_service_test.dart --plain-name "logcat stream cancellation kills the adb process" +00:00 +0: loading /config/workspace/appsok/test/adb_service_test.dart +00:00 +0: AdbService logcat stream cancellation kills the adb process +00:00 +1: All tests passed! +``` + +### REVIEW_LOGCAT_PROC-2 중간 검증 +```bash +$ flutter test test/adb_service_test.dart --plain-name "logcat session stop kills the adb process" +00:00 +0: loading /config/workspace/appsok/test/adb_service_test.dart +00:00 +0: AdbService logcat session stop kills the adb process +00:00 +1: All tests passed! +``` + +### 최종 검증 +```bash +$ flutter test test/adb_service_test.dart +00:00 +14: AdbService logcat session stop kills the adb process +00:00 +15: AdbService logcat stream cancellation kills the adb process +00:00 +16: AdbService runs adb install with the shared server port +00:00 +17: All tests passed! + +$ flutter analyze +Analyzing appsok... +No issues found! (ran in 6.8s) +``` + +--- + +> **[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. + +## 코드리뷰 결과 + +- 종합 판정: PASS +- 차원별 평가: + - Correctness: Pass + - Completeness: Pass + - Test coverage: Pass + - API contract: Pass + - Code quality: Pass + - Plan deviation: Pass + - Verification trust: Pass +- 발견된 문제: 없음 +- 다음 단계: PASS이므로 active plan/review를 archive log로 이동하고 `complete.log` 작성 후 task directory를 월별 archive로 이동한다. diff --git a/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/complete.log b/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/complete.log new file mode 100644 index 0000000..04f2fae --- /dev/null +++ b/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/complete.log @@ -0,0 +1,38 @@ +# Complete - m-logcat-console/01_logcat_process + +## 완료 일시 + +2026-06-13 + +## 요약 + +ADB logcat process/session foundation follow-up을 2회 리뷰 루프 끝에 PASS로 종료했다. + +## 루프 이력 + +| Plan | Review | Verdict | 메모 | +|------|--------|---------|------| +| `plan_cloud_G07_0.log` | `code_review_cloud_G07_0.log` | FAIL | stream cancel regression test가 실제 구독 취소를 검증하지 않았고 `AdbLogcatSession.lines` 문서가 stop 계약과 어긋나 follow-up 필요 | +| `plan_cloud_G07_1.log` | `code_review_cloud_G07_1.log` | PASS | `AdbService.logcat()` 구독 취소 회귀 테스트와 session direct `stop()` 계약 정정을 확인 | + +## 구현/정리 내용 + +- `AdbService.logcat()` wrapper의 구독 취소가 `AdbLogcatSession.stop()`을 통해 fake process를 kill하는 회귀 테스트를 추가했다. +- `AdbLogcatSession.lines` 문서를 output stream 책임으로 한정하고, 직접 session 사용자는 `stop()`으로 process lifetime을 정리한다는 계약을 명확히 했다. +- direct session stop 테스트명을 실제 계약과 맞게 정리했다. + +## 최종 검증 + +- `flutter test test/adb_service_test.dart --plain-name "logcat stream cancellation kills the adb process"` - PASS; `All tests passed!` +- `flutter test test/adb_service_test.dart --plain-name "logcat session stop kills the adb process"` - PASS; `All tests passed!` +- `flutter test test/adb_service_test.dart` - PASS; `17: All tests passed!` +- `flutter analyze` - PASS; `No issues found! (ran in 5.2s)` +- `git diff --check` - PASS; 출력 없음 + +## 잔여 Nit + +- 없음 + +## 후속 작업 + +- 없음 diff --git a/agent-task/m-logcat-console/01_logcat_process/PLAN-cloud-G07.md b/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/plan_cloud_G07_0.log similarity index 100% rename from agent-task/m-logcat-console/01_logcat_process/PLAN-cloud-G07.md rename to agent-task/archive/2026/06/m-logcat-console/01_logcat_process/plan_cloud_G07_0.log diff --git a/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/plan_cloud_G07_1.log b/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/plan_cloud_G07_1.log new file mode 100644 index 0000000..23a77c8 --- /dev/null +++ b/agent-task/archive/2026/06/m-logcat-console/01_logcat_process/plan_cloud_G07_1.log @@ -0,0 +1,127 @@ + + +# REVIEW_LOGCAT_PROC 계획 + +## 이 파일을 읽는 구현 에이전트에게 + +이 plan은 직전 코드리뷰 FAIL의 Required 항목만 닫는다. `CODE_REVIEW-*-G??.md`의 구현 에이전트 소유 섹션을 채우는 것은 필수이며, 구현 후 검증을 실행하고 실제 내용과 출력을 기록한 뒤 active 파일을 그대로 두고 리뷰 준비를 보고한다. 최종 판정, log rename, `complete.log`, archive 이동은 code-review-skill 전용이다. 구현이 사용자 결정, 사용자 소유 외부 환경, 범위 충돌로 막히면 review stub의 `사용자 리뷰 요청` 섹션에 근거를 기록하고 중단한다. 직접 질문, 채팅 선택지, `request_user_input`, `USER_REVIEW.md` 작성, archive, `complete.log` 작성은 금지다. 후속 에이전트가 재실행이나 산출물 수집으로 닫을 수 있는 증거 공백은 사용자 리뷰 요청이 아니다. + +## 배경 + +직전 구현은 `AdbService.startLogcat()`와 `AdbLogcatSession`을 추가했고 targeted test/analyze는 통과했다. 그러나 핵심 회귀 테스트인 `logcat stream cancellation kills the adb process`가 실제 stream subscription cancel을 실행하지 않고 `session.stop()`만 직접 호출한다. 또한 `AdbLogcatSession.lines` 문서는 직접 구독 취소가 process를 kill한다고 말하지만 구현은 명시적 `stop()`만 process lifetime을 제어한다. + +## 범위 결정 근거 + +- 이번 follow-up은 직전 리뷰의 Required 2건만 수정한다. +- `ConsolePage` live stream UI, device selection, auto-scroll, filter UI는 이 subtask 범위가 아니다. +- 기존 설계대로 session 직접 사용자는 `stop()`으로 lifetime을 정리하고, compatibility wrapper인 `AdbService.logcat()`은 stream cancel 시 `stop()`을 보장하는 계약으로 둔다. +- Roadmap Targets는 직전 plan에 없었고, 이번 follow-up도 roadmap Task 완료를 직접 주장하지 않는다. + +## 빌드 등급 + +- build/review: `cloud-G07`. +- 사유: ADB process lifecycle, stream cancellation, verification trust 회복이 핵심이다. 직전 route가 적절했으므로 동일 route를 유지한다. + +## 구현 체크리스트 + +- [ ] `test/adb_service_test.dart`에서 `AdbService.logcat()` stream subscription을 만들고 `await sub.cancel()`만으로 fake process `killCalled == true`가 되는 regression test를 추가하거나 기존 오명명 테스트를 고친다. +- [ ] `lib/src/services/adb_service.dart`의 `AdbLogcatSession.lines` 문서와 테스트명을 명시적 `stop()` 계약에 맞게 정정하고, 직접 session 사용 시 process cleanup 책임이 `stop()`에 있음을 분명히 한다. +- [ ] `flutter test test/adb_service_test.dart`를 실행한다. +- [ ] `flutter analyze`를 실행한다. +- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다. + +## REVIEW_LOGCAT_PROC-1 실제 stream cancel 회귀 테스트 + +### 문제 + +[test/adb_service_test.dart](/config/workspace/appsok/test/adb_service_test.dart:300)의 `logcat stream cancellation kills the adb process`는 stream cancel을 검증하지 않는다. `final session = await service.startLogcat()` 뒤 `await session.stop()`만 호출하므로 [lib/src/services/adb_service.dart](/config/workspace/appsok/lib/src/services/adb_service.dart:92)의 `async*` wrapper cancellation path가 깨져도 테스트는 계속 통과한다. + +### 해결 방법 + +테스트가 `service.logcat()`을 직접 구독하고, 구독 취소가 wrapper의 `finally`를 통해 fake process kill로 이어지는지 확인하게 고친다. + +예시 흐름: + +```dart +final fake = _FakeProcess(); +final service = AdbService( + runtimeConfig: const AdbRuntimeConfig(customAdbPath: '/opt/appsok/adb'), + processStarter: (_, args, {environment}) async => fake, +); + +final sub = service.logcat().listen((_) {}); +await Future.delayed(Duration.zero); +expect(fake.killCalled, isFalse); + +await sub.cancel(); + +expect(fake.killCalled, isTrue); +``` + +필요하면 fake process가 `kill()`에서 stream을 닫고 `exitCode`를 완료하는 현재 구조를 재사용한다. 이 테스트는 `session.stop()`을 직접 호출하지 않아야 한다. + +### 수정 파일 및 체크리스트 + +- [ ] `test/adb_service_test.dart`: `service.logcat()` subscription cancel 기반 regression test 작성. +- [ ] `test/adb_service_test.dart`: 테스트명이 실제 검증 동작과 일치하도록 정리. + +### 테스트 작성 + +- 작성: `test/adb_service_test.dart` +- 테스트 이름 후보: `logcat stream cancellation kills the adb process` +- assertion: cancel 전 `killCalled == false`, `await sub.cancel()` 후 `killCalled == true`. + +### 중간 검증 + +```bash +flutter test test/adb_service_test.dart --plain-name "logcat stream cancellation kills the adb process" +``` + +예상: 해당 테스트 통과. + +## REVIEW_LOGCAT_PROC-2 session lines API 계약 정정 + +### 문제 + +[lib/src/services/adb_service.dart](/config/workspace/appsok/lib/src/services/adb_service.dart:322)는 `AdbLogcatSession.lines` 구독 취소가 process를 kill한다고 문서화하지만, 구현은 `stop()`에서만 kill한다. 직전 구현의 설계 결정도 session이 process 제어만 담당하고 UI lifecycle은 명시적 stop으로 분리한다고 설명하므로 문서가 API 계약을 잘못 전달한다. + +### 해결 방법 + +`AdbLogcatSession.lines` 문서를 "stdout/stderr line merge stream"으로 한정하고, session 직접 사용자는 `stop()`을 호출해야 한다는 계약을 명확히 한다. 기존 direct stop 테스트는 이름을 `logcat session stop kills the adb process`처럼 고쳐 실제 동작과 일치시킨다. 직접 `lines` cancellation이 process kill을 보장해야 한다는 방향으로 바꾸지 않는다. + +### 수정 파일 및 체크리스트 + +- [ ] `lib/src/services/adb_service.dart`: `AdbLogcatSession.lines` 문서에서 직접 cancel kill 보장을 제거하고 `stop()` 책임을 명확히 한다. +- [ ] `test/adb_service_test.dart`: direct session stop 테스트 이름과 assertion을 API 계약에 맞게 정리한다. + +### 테스트 작성 + +- 작성: `test/adb_service_test.dart` +- 테스트 이름 후보: `logcat session stop kills the adb process` +- assertion: `session.stop()` 호출 후 fake process `killCalled == true`. + +### 중간 검증 + +```bash +flutter test test/adb_service_test.dart --plain-name "logcat session stop kills the adb process" +``` + +예상: 해당 테스트 통과. + +## 수정 파일 요약 + +| 파일 | 항목 | +|------|------| +| `lib/src/services/adb_service.dart` | REVIEW_LOGCAT_PROC-2 | +| `test/adb_service_test.dart` | REVIEW_LOGCAT_PROC-1, REVIEW_LOGCAT_PROC-2 | + +## 최종 검증 + +```bash +flutter test test/adb_service_test.dart +flutter analyze +``` + +예상: targeted test 통과, analyzer issue 없음. + +모든 코드 변경 완료 후 반드시 `CODE_REVIEW-*-G??.md`의 구현 에이전트 소유 섹션을 채운다. 이 파일 작성이 구현의 마지막 단계다. diff --git a/lib/src/services/adb_service.dart b/lib/src/services/adb_service.dart index d50d618..1db527a 100644 --- a/lib/src/services/adb_service.dart +++ b/lib/src/services/adb_service.dart @@ -13,18 +13,28 @@ typedef AdbProcessRunner = Map? environment, }); +typedef AdbProcessStarter = + Future Function( + String executable, + List arguments, { + Map? environment, + }); + class AdbService { AdbService({ String? adbPath, AdbRuntimeConfig runtimeConfig = const AdbRuntimeConfig(), AdbProcessRunner processRunner = Process.run, + AdbProcessStarter processStarter = Process.start, }) : runtimeConfig = adbPath == null ? runtimeConfig : runtimeConfig.copyWith(customAdbPath: adbPath), - _processRunner = processRunner; + _processRunner = processRunner, + _processStarter = processStarter; final AdbRuntimeConfig runtimeConfig; final AdbProcessRunner _processRunner; + final AdbProcessStarter _processStarter; AdbRuntime get runtime => runtimeConfig.resolve(); String get adbPath => runtime.executablePath; @@ -62,25 +72,30 @@ class AdbService { ); } - Stream logcat({String? serial}) async* { + Future startLogcat({String? serial}) async { final args = [ if (serial != null) ...['-s', serial], 'logcat', ]; final runtime = this.runtime; - final process = await Process.start( + final process = await _processStarter( runtime.executablePath, args, environment: runtime.environment, ); - final stdout = process.stdout - .transform(utf8.decoder) - .transform(const LineSplitter()); - final stderr = process.stderr - .transform(utf8.decoder) - .transform(const LineSplitter()); + return AdbLogcatSession(process); + } - yield* StreamGroup.merge([stdout, stderr]); + /// Compatibility wrapper over [startLogcat]. Cancelling the returned + /// subscription stops the underlying logcat session and kills the process, + /// so no orphan ADB process is left running. + Stream logcat({String? serial}) async* { + final session = await startLogcat(serial: serial); + try { + yield* session.lines; + } finally { + await session.stop(); + } } Future collectDiagnostics() async { @@ -302,6 +317,43 @@ class AdbRuntime { }; } +/// A running `adb logcat` session. +/// +/// Process lifetime is controlled only by [stop]: a direct session user MUST +/// call [stop] to kill the underlying process and avoid leaving an orphan ADB +/// process. Cancelling a [lines] subscription on its own does not stop the +/// process. ([AdbService.logcat] is a convenience wrapper that ties stream +/// cancellation to [stop] for callers that don't manage the session directly.) +class AdbLogcatSession { + AdbLogcatSession(this._process); + + final Process _process; + var _stopped = false; + + /// Merged stdout/stderr of the logcat process, decoded as text lines. + /// + /// This getter only exposes output; it does not own process lifetime. + /// Call [stop] to terminate the process. + Stream get lines { + final stdout = _process.stdout + .transform(utf8.decoder) + .transform(const LineSplitter()); + final stderr = _process.stderr + .transform(utf8.decoder) + .transform(const LineSplitter()); + + return StreamGroup.merge([stdout, stderr]); + } + + /// Kills the logcat process. Safe to call more than once. + Future stop() async { + if (_stopped) return; + _stopped = true; + _process.kill(); + await _process.exitCode; + } +} + class AdbInstallResult { const AdbInstallResult({ required this.exitCode, diff --git a/test/adb_service_test.dart b/test/adb_service_test.dart index 00854d2..175751c 100644 --- a/test/adb_service_test.dart +++ b/test/adb_service_test.dart @@ -1,3 +1,5 @@ +import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; @@ -241,6 +243,91 @@ void main() { }, ); + test('startLogcat runs adb logcat for the requested serial', () async { + final calls = + <({String executable, List args, String? port})>[]; + final fake = _FakeProcess(); + final service = AdbService( + runtimeConfig: const AdbRuntimeConfig( + customAdbPath: '/opt/appsok/adb', + serverPort: 15037, + ), + processStarter: (executable, args, {environment}) async { + calls.add(( + executable: executable, + args: args, + port: environment?['ADB_SERVER_PORT'], + )); + return fake; + }, + ); + + final session = await service.startLogcat(serial: 'R5CT90A1B2C'); + addTearDown(session.stop); + + expect(calls, hasLength(1)); + expect(calls.single.executable, '/opt/appsok/adb'); + expect(calls.single.args, ['-s', 'R5CT90A1B2C', 'logcat']); + expect(calls.single.port, '15037'); + }); + + test('logcat session merges stdout and stderr lines', () async { + final fake = _FakeProcess(); + final service = AdbService( + runtimeConfig: const AdbRuntimeConfig(customAdbPath: '/opt/appsok/adb'), + processStarter: (_, args, {environment}) async => fake, + ); + + final session = await service.startLogcat(); + final received = []; + final sub = session.lines.listen(received.add); + + fake.emitStdout('I/out: first\n'); + fake.emitStderr('E/err: oops\n'); + fake.emitStdout('I/out: second\n'); + await Future.delayed(Duration.zero); + + expect(received, [ + 'I/out: first', + 'E/err: oops', + 'I/out: second', + ]); + + await sub.cancel(); + await session.stop(); + }); + + test('logcat session stop kills the adb process', () async { + final fake = _FakeProcess(); + final service = AdbService( + runtimeConfig: const AdbRuntimeConfig(customAdbPath: '/opt/appsok/adb'), + processStarter: (_, args, {environment}) async => fake, + ); + + final session = await service.startLogcat(); + expect(fake.killCalled, isFalse); + + await session.stop(); + + expect(fake.killCalled, isTrue); + }); + + test('logcat stream cancellation kills the adb process', () async { + final fake = _FakeProcess(); + final service = AdbService( + runtimeConfig: const AdbRuntimeConfig(customAdbPath: '/opt/appsok/adb'), + processStarter: (_, args, {environment}) async => fake, + ); + + final sub = service.logcat().listen((_) {}); + await Future.delayed(Duration.zero); + expect(fake.killCalled, isFalse); + + await sub.cancel(); + + expect(fake.killCalled, isTrue); + }); + test('runs adb install with the shared server port', () async { final calls = <({List args, String? port})>[]; final service = AdbService( @@ -271,3 +358,40 @@ void main() { }); }); } + +/// Minimal in-memory [Process] stand-in for logcat tests. Only the members the +/// logcat session touches (stdout, stderr, kill, exitCode) are implemented. +class _FakeProcess implements Process { + final _stdout = StreamController>(); + final _stderr = StreamController>(); + final _exitCode = Completer(); + + bool killCalled = false; + + void emitStdout(String text) => _stdout.add(utf8.encode(text)); + void emitStderr(String text) => _stderr.add(utf8.encode(text)); + + @override + Stream> get stdout => _stdout.stream; + + @override + Stream> get stderr => _stderr.stream; + + @override + Future get exitCode => _exitCode.future; + + @override + bool kill([ProcessSignal signal = ProcessSignal.sigterm]) { + killCalled = true; + if (!_exitCode.isCompleted) _exitCode.complete(-15); + _stdout.close(); + _stderr.close(); + return true; + } + + @override + int get pid => 4242; + + @override + IOSink get stdin => throw UnimplementedError(); +}