Core Implementation (BAT-010):
- Add daemon registry schema and CRUD operations (req-023)
- Implement single-daemon asset assignment constraint (one asset per daemon)
- Add daemon_id field to service_token for daemon identification
- Add daemon.py CLI module for daemon management commands
- Add 20260513_0016_daemon_model.py migration for daemon tables
API Changes:
- GET /v1/assets: include daemon_id in AssetResponse
- POST /v1/assets/{asset_id}/ledger/trades: require daemon token binding
- GET /v1/user_info: include daemon metadata
- Enhanced service-token rotate to preserve daemon bindings
CLI Commands:
- pfhub daemon register --name <name> --runtime-id <runtime-id>
- pfhub daemon list
- pfhub daemon get <daemon-id>
- pfhub daemon revoke <daemon-id>
Requirements (REQ-023, REQ-028):
- REQ-023: Daemon Registry and Service Token Daemon Binding (Interface, Approved)
* AC-1: daemon CRUD operations
* AC-2: service token daemon binding for POST /v1/assets/{asset_id}/ledger/trades
* AC-3: single daemon per asset (exact-one assignment model)
- REQ-028: README.md Daemon Provisioning Runbook update (Documentation, Approved)
Documentation:
- Add dcy-006 Discovery for daemon-id and single-daemon asset assignment
- Update README.md with Daemon Provisioning Runbook section
- Add BAT-010 batch documentation with planning, implementation, verification
- Update rel-006 release document (daemon model implementation)
- Update data-model.md with daemon and daemon_asset_assignment tables
- Update interface-contract.md with daemon registry APIs
- Update runtime-flows.md with daemon lifecycle flows
Breaking Changes:
- REQ-005~009, REQ-011~012 status reverted to Approved due to revised contract
* daemon_id field addition and exact-one asset assignment requirement
* Existing Implemented evidence invalidated by contract revision
* BAT-001/002/008 re-verification required
Testing:
- Add test_daemon_registry.py for daemon CRUD operations
- Add test_daemon_assignment.py for single-asset assignment constraints
- Update test_auth.py, test_cli.py, test_v1.py for daemon support
- Verify daemon token binding in trade endpoint authorization
Impact:
- Database: 2 new tables (daemons, daemon_asset_assignments)
- Migration: 20260513_0016 creates daemon model schema
- CLI: 4 new daemon subcommands
- API: daemon_id propagation through v1 endpoints
- Verification: BAT-001/002/008 re-verification gates next release
261 lines
12 KiB
Markdown
261 lines
12 KiB
Markdown
# req-006: GET /v1/assets 엔드포인트 구현
|
|
|
|
- Status: Approved
|
|
- Type: Interface
|
|
- Priority: High
|
|
- Owner: repository-maintainers
|
|
|
|
## Intent
|
|
- trex-basic 데몬이 자신에게 배정된 자산 목록과 전략 파라미터만 조회할 수 있도록 portfolio 데이터를 daemon-scoped asset 뷰로 제공한다.
|
|
- 동일 owner user 아래 여러 daemon이 존재해도, 다른 daemon에 배정된 asset은 응답에 섞이면 안 된다.
|
|
|
|
## Requirement
|
|
- GET /v1/assets는 service-token bearer 인증으로 토큰 소유 user 범위 안에서, 인증된 token의 `daemon_id`에 배정된 portfolio 목록만 `asset_id`, `symbol`, `market`, `status`, `cash`, `quantity`, `broker_type`, `strategy_id`, `strategy_type`, `strategy_params`, `updated_at` 필드로 반환해야 한다. 다른 사용자 소유 portfolio와 다른 daemon에 배정된 portfolio는 응답에 포함되면 안 된다.
|
|
- `status=active` 쿼리 파라미터는 daemon-scoped 결과 집합 위에서 필터링되어야 한다.
|
|
- strategy_params는 해당 portfolio의 active_strategy_id로 조회한 StrategySet.config에서 파생한다. strategy_id는 허용값 검증 없이 그대로 반환한다(OQ-1 Answered).
|
|
- strategy_type은 해당 portfolio의 active_strategy_id로 조회한 StrategySet.name을 반환한다. active_strategy_id가 없거나 StrategySet 조회 실패 시 null을 반환한다.
|
|
- `daemon_id`가 없는 legacy service-token은 transition 구간 동안 `GET /v1/assets`에서 fail-closed(`403 Forbidden`)로 처리되어야 한다.
|
|
|
|
## Acceptance Criteria
|
|
1. Given 유효한 daemon-bound service-token bearer 인증으로 `GET /v1/assets` 요청 시, When 토큰이 유효하면, Then HTTP 200과 해당 daemon에 배정된 portfolio 목록만 반환되어야 하며 다른 사용자 소유 portfolio나 다른 daemon에 배정된 portfolio는 포함되면 안 된다.
|
|
2. Given `GET /v1/assets?status=active` 요청 시, Then status가 active인 항목만 daemon-scoped 결과 안에서 반환되어야 한다.
|
|
3. Given 응답의 각 항목을 확인하면, Then asset_id, symbol, market, status, cash, quantity, broker_type, strategy_id, strategy_type, strategy_params, updated_at 필드가 모두 포함되어야 한다.
|
|
4. Given portfolio에 연결된 StrategySet이 있을 때, When strategy_params를 확인하면, Then StrategySet.config 값에서 파생된 JSON 객체여야 한다.
|
|
5. Given StrategySet config가 없거나 파싱 실패 시, Then strategy_params는 빈 객체({})를 반환하고 에러가 전파되지 않아야 한다.
|
|
6. Given portfolios.market이 NULL인 경우, Then 응답의 market 필드도 null로 반환되어야 한다(DECIDE_MARKET_DEFAULT Answered).
|
|
7. Given 인증 없이 GET /v1/assets 요청 시, Then HTTP 401이 반환되어야 한다.
|
|
8. Given portfolio에 active_strategy_id로 연결된 StrategySet이 있을 때, Then strategy_type은 해당 StrategySet.name 값을 반환해야 한다.
|
|
9. Given portfolio에 active_strategy_id가 없거나 StrategySet 조회 실패 시, Then strategy_type은 null을 반환해야 한다.
|
|
10. Given `daemon_id`가 없는 legacy service-token으로 `GET /v1/assets` 요청 시, Then HTTP 403이 반환되어야 하고 daemon-scoped asset 목록은 비노출이어야 한다.
|
|
|
|
## Impacted Area
|
|
- Docs: docs/interface-contract.md (REQ-011에서 갱신 예정), docs/project-structure.md (신규 라우터 파일 반영 필요)
|
|
- Modules: app/api/v1_assets.py, app/schemas/v1.py, app/repositories/portfolio_repository.py, app/repositories/postgres.py, app/core/auth.py, app/main.py
|
|
- Tests: tests/test_v1.py, tests/test_portfolio_ownership.py 또는 신규 daemon assignment 회귀 테스트
|
|
|
|
## Notes
|
|
- broker_type은 portfolios.broker 컬럼을 그대로 매핑한다(m-2 finding 반영).
|
|
- strategy_id는 portfolios.active_strategy_id를 그대로 반환한다.
|
|
- `GET /v1/assets`의 최종 authorization 스코프는 service-token 소유자 범위 위에 `managed_by_daemon_id = auth.daemon_id` 조건을 추가한 daemon scope다.
|
|
- exact-one asset assignment는 `portfolios.managed_by_daemon_id`를 통해 표현되며 스키마 제약은 REQ-009 change-req에서 다룬다.
|
|
- Source Discovery: dcy-002 (FR-3, A-3, OQ-1), dcy-006 (FR-2, FR-3, NFR-2)
|
|
|
|
## Change Log
|
|
|
|
### CHG-20260513-01
|
|
- Date: 2026-05-13
|
|
- Author: repository-maintainers
|
|
|
|
#### Change Summary
|
|
- owner-user scope 기반 `/v1/assets` 요구사항을 daemon-scoped asset visibility와 fail-closed legacy token 규칙으로 갱신하고, Implemented 상태를 Approved로 되돌림
|
|
|
|
#### Intent
|
|
- dcy-006에서 각 asset은 정확히 1개 daemon에 배정되고, `GET /v1/assets`는 owner user 전체가 아니라 인증 daemon 범위만 반환해야 한다. 현재 구현은 `owner_user_id=auth.user_id`만 사용하므로 revised authorization model과 맞지 않는다.
|
|
|
|
#### Acceptance Criteria Delta
|
|
- Added:
|
|
- AC-10: daemon-less legacy token fail-closed(403)
|
|
- Updated:
|
|
- AC-1, AC-2: owner scope를 daemon scope 기준으로 재정의
|
|
- Removed:
|
|
- none
|
|
|
|
#### Impacted Area Delta
|
|
- Docs:
|
|
- `docs/interface-contract.md`, `docs/runtime-flows.md` — daemon-scoped asset list contract 반영 필요
|
|
- Modules:
|
|
- `app/api/v1_assets.py`, `app/schemas/v1.py`, `app/repositories/portfolio_repository.py`, `app/repositories/postgres.py`, `app/core/auth.py`
|
|
- Tests:
|
|
- `tests/test_v1.py`, daemon assignment 관련 신규 회귀 테스트
|
|
|
|
#### Delivery Trace Delta
|
|
- Batches:
|
|
- BAT-001 (release-candidate; REL-001 released input) — owner-user scope verification evidence는 daemon-scoped visibility 기준으로 전면 재검증 필요
|
|
- Releases:
|
|
- REL-001 (released) — released contract는 owner-user scope 기준이라 revised REQ와 불일치
|
|
|
|
#### Revalidation Impact
|
|
- Reverification Needed: yes
|
|
- Existing Implementation Invalidated: yes
|
|
- Status Recommendation: rollback-to-approved
|
|
- Follow-up Action: dcy-006 후속 batch에서 daemon assignment query, 403 fail-closed path, daemon-scoped regression test를 구현한다.
|
|
|
|
#### Validation Plan
|
|
- `app/api/v1_assets.py`가 현재 `owner_user_id=auth.user_id`만 적용하는지 확인하고, daemon-aware query 설계를 REQ-009와 함께 정리한다.
|
|
- 구현 후 daemon A/B 분리 시나리오와 daemon-less token 403 시나리오를 targeted pytest로 검증한다.
|
|
|
|
### CHG-20260511-02
|
|
- Date: 2026-05-11
|
|
- Author: repository-maintainers
|
|
|
|
#### Change Summary
|
|
- owner scope 회귀 수정 반영 — GET /v1/assets는 service-token 소유자의 portfolio만 반환함을 REQ와 verification evidence에 명시
|
|
|
|
#### Intent
|
|
- CONFLICT-1 분석 결과와 2026-05-11 사용자 결정에 따라 trex-basic은 전체 사용자의 portfolio를 조회하면 안 되며, 서비스 토큰 소유자 범위로만 조회되어야 한다는 설계를 REQ 본문과 검증 기준에 명확히 남긴다.
|
|
|
|
#### Acceptance Criteria Delta
|
|
- Added:
|
|
- none
|
|
- Updated:
|
|
- AC1: 반환 범위를 "해당 사용자 소유 portfolio 목록만"으로 명확화하고, 다른 사용자 소유 portfolio 비포함 조건을 추가
|
|
- Removed:
|
|
- none
|
|
|
|
#### Impacted Area Delta
|
|
- Docs:
|
|
- docs/batches/bat-001_20260502_trex-basic-v1-api-contract/verification.md: REQ-006 AC1 evidence를 owner scope 기준으로 재정렬
|
|
- Modules:
|
|
- app/api/v1_assets.py: `owner_user_id=auth.user_id` 적용으로 owner scope 강제
|
|
- Tests:
|
|
- tests/test_v1.py: `test_v1_assets_returns_asset_list`에 `owner_user_id="user-1"` 전달 assert 추가
|
|
|
|
#### Delivery Trace Delta
|
|
- Batches:
|
|
- BAT-001 (release-candidate) — REQ-006 targeted re-verification 필요 및 evidence 갱신
|
|
- Releases:
|
|
- REL-001 (draft) — release 입력 전 owner scope 기준 반영 여부 재확인 필요
|
|
|
|
#### Revalidation Impact
|
|
- Reverification Needed: yes
|
|
- Existing Implementation Invalidated: yes
|
|
- Status Recommendation: keep-current
|
|
- Follow-up Action: owner scope 수정 코드와 targeted pytest 재실행 결과를 BAT-001 verification에 반영하고 Implemented 상태 유지
|
|
|
|
#### Validation Plan
|
|
- `app/api/v1_assets.py`에서 `owner_user_id=auth.user_id` 적용 여부 확인
|
|
- `tests/test_v1.py -k 'v1_assets'` 재실행으로 GET /v1/assets 회귀 테스트 PASS 확인
|
|
- BAT-001 verification.md의 REQ-006 AC1 evidence를 최신 테스트와 맞춤
|
|
|
|
### CHG-20260511-01
|
|
- Date: 2026-05-11
|
|
- Author: repository-maintainers
|
|
|
|
#### Change Summary
|
|
- Implemented 전환 — BAT-001 re-verified verification passed, confirm-req-implemented 게이트 통과
|
|
|
|
#### Intent
|
|
- BAT-001 verification.md (re-verified, 2026-05-03, CHG-20260503-01 strategy_type 재검증 포함) AC-1~9 모두 PASS. Blocking Issues 없음.
|
|
|
|
#### Acceptance Criteria Delta
|
|
- none
|
|
|
|
#### Impacted Area Delta
|
|
- none
|
|
|
|
#### Delivery Trace Delta
|
|
- Batches: BAT-001 (release-candidate)
|
|
- Releases: none
|
|
|
|
#### Revalidation Impact
|
|
- Reverification Needed: no
|
|
- Existing Implementation Invalidated: no
|
|
- Status Recommendation: implemented
|
|
- Follow-up Action: draft-release (BAT-001)
|
|
|
|
#### Validation Plan
|
|
- BAT-001 verification.md (re-verified) AC-1~9 evidence 연결 확인 완료 (strategy_type 필드 재검증 포함)
|
|
|
|
### CHG-20260503-01
|
|
- Date: 2026-05-03
|
|
- Author: repository-maintainers
|
|
|
|
#### Change Summary
|
|
- GET /v1/assets 응답 필드에 `strategy_type` 추가 — StrategySet.name 값을 반환
|
|
|
|
#### Intent
|
|
- trex-basic 데몬이 asset 뷰에서 전략 이름(StrategySet.name)을 직접 확인할 수 있도록 `strategy_type` 필드를 응답에 추가한다.
|
|
- DB 변경 없이 기존 StrategySet.name 컬럼을 활용하는 순수 응답 스키마 확장이다.
|
|
|
|
#### Acceptance Criteria Delta
|
|
- Added:
|
|
- AC-8: Given portfolio에 active_strategy_id로 연결된 StrategySet이 있을 때, Then strategy_type은 StrategySet.name 값을 반환해야 한다.
|
|
- AC-9: Given portfolio에 active_strategy_id가 없거나 StrategySet 조회 실패 시, Then strategy_type은 null을 반환해야 한다.
|
|
- Modified:
|
|
- AC-3: `strategy_type` 필드를 필수 응답 필드 목록에 추가
|
|
|
|
#### Impacted Area Delta
|
|
- Modules:
|
|
- app/schemas/v1.py: AssetItem에 strategy_type 필드 추가
|
|
- app/api/v1_assets.py: strategy_type 매핑 로직 추가 (StrategySet.name 조회)
|
|
|
|
#### Delivery Trace Delta
|
|
- Batches:
|
|
- BAT-001 (release-candidate) — REQ-006 포함, strategy_type 추가로 재검증 필요
|
|
- Releases:
|
|
- 없음 (아직 draft-release 미수행)
|
|
|
|
#### Revalidation Impact
|
|
- Reverification Needed: yes
|
|
- Existing Implementation Invalidated: yes (BAT-001 verification은 strategy_type 없이 수행됨)
|
|
- Status Recommendation: keep-current (Approved 유지 — 구현 전 단계이므로 상태 되돌림 불필요)
|
|
- Follow-up Action: 구현 후 BAT-001 verification 재수행 또는 BAT-006 신규 생성 결정 필요
|
|
|
|
#### Validation Plan
|
|
- app/schemas/v1.py AssetItem에 strategy_type 필드 추가
|
|
- app/api/v1_assets.py에서 portfolio.active_strategy_id로 StrategySet.name 조회 후 매핑
|
|
- tests/test_v1_assets.py 또는 test_app.py에서 strategy_type 필드 존재 및 null 케이스 검증
|
|
|
|
### CHG-20260502-02
|
|
- Date: 2026-05-02
|
|
- Author: repository-maintainers
|
|
|
|
#### Change Summary
|
|
- REQ-006 confirm-req 승인 전환 (Status: Proposed → Approved)
|
|
|
|
#### Intent
|
|
- 필수 필드(Status, Type, Priority, Owner, Intent, Requirement, Acceptance Criteria 7개, Impacted Area, Change Log) 모두 충족 확인 후 승인
|
|
|
|
#### Acceptance Criteria Delta
|
|
- No change
|
|
|
|
#### Impacted Area Delta
|
|
- No change
|
|
|
|
#### Delivery Trace Delta
|
|
- Batches:
|
|
- none
|
|
- Releases:
|
|
- none
|
|
|
|
#### Revalidation Impact
|
|
- Reverification Needed: no
|
|
- Existing Implementation Invalidated: no
|
|
- Status Recommendation: keep-current
|
|
- Follow-up Action: suggest-batch-reqs → draft-batch
|
|
|
|
### CHG-20260502-01
|
|
- Date: 2026-05-02
|
|
- Author: repository-maintainers
|
|
|
|
#### Change Summary
|
|
- REQ-006 최초 생성 (source Discovery: dcy-002 FR-3)
|
|
|
|
#### Intent
|
|
- trex-basic Consumer-Driven Contract의 GET /v1/assets 요구사항을 REQ backlog로 정규화
|
|
|
|
#### Acceptance Criteria Delta
|
|
- Added:
|
|
- 전체 Acceptance Criteria 신규 작성
|
|
|
|
#### Impacted Area Delta
|
|
- Docs:
|
|
- docs/interface-contract.md (REQ-011에서 갱신 예정)
|
|
- Modules:
|
|
- app/api/v1_assets.py 신규
|
|
- app/main.py (/v1 라우터 등록)
|
|
- Tests:
|
|
- tests/test_v1_assets.py 신규
|
|
|
|
#### Delivery Trace Delta
|
|
- Batches:
|
|
- none
|
|
- Releases:
|
|
- none
|
|
|
|
#### Revalidation Impact
|
|
- Reverification Needed: no
|
|
- Existing Implementation Invalidated: no
|
|
- Status Recommendation: keep-current
|
|
- Follow-up Action: confirm-req 후 batch 배정. REQ-009 migration(market 컬럼 추가)과 함께 delivery 단위 구성 권장.
|