diff --git a/.gitignore b/.gitignore index 5a3fe6d..563f6a4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,6 @@ dist/ test-results/ playwright-report/ blob-report/ -.harness/gradle-cache/ -.harness/local/ *.log .DS_Store diff --git a/.harness/commands.yaml b/.harness/commands.yaml deleted file mode 100644 index 1356c0f..0000000 --- a/.harness/commands.yaml +++ /dev/null @@ -1,16 +0,0 @@ -schema_version: 1 -workspace_id: workspace.ui -commands: - - id: command.test-suite - kind: test - argv: [pnpm, test, --run] - timeout_seconds: 600 - - id: command.pr-checks - kind: review - argv: [gh, pr, checks] - timeout_seconds: 120 - environment: [APPDATA, LOCALAPPDATA] - - id: command.develop-integration - kind: integration - argv: [git, merge-base, --is-ancestor, HEAD, origin/develop] - timeout_seconds: 30 diff --git a/README.md b/README.md index 5ae89a5..6adbf01 100644 --- a/README.md +++ b/README.md @@ -16,35 +16,61 @@ pnpm test -- --run pnpm build ``` -### 실제 계정 API 여정 +### 실제 backend API 여정 -선택 실행하는 Playwright 여정은 네트워크 fixture를 사용하지 않습니다. 임시 PostgreSQL에 -backend의 canonical Flyway migration을 적용하고 production `backend-api`를 기동한 뒤, -Chromium에서 가입·인증·로그인·환경설정·사용자 케이스를 실행합니다. Docker와 Chromium이 -필요합니다. Backend는 정확히 `65e6426b`, root Flyway bundle은 정확히 `e259a83`인 -깨끗한 worktree만 허용합니다. 환경 변수를 생략하면 UI worktree와 나란히 있는 -`a23-real-backend-develop`, `a23-real-root-develop`을 검사합니다. +선택 실행하는 Playwright 여정은 네트워크 fixture 없이 production `backend-api`를 대상으로 +합니다. 기본 실행 범위는 다음 두 파일입니다. + +- `e2e/real-account-api.e2e.ts`: 가입, 잘못된 비밀번호와 정상 로그인, 계정 환경설정 조회, + 사용자 케이스 제출 +- `e2e/competition-room-create-real.e2e.ts`: 대회 방 생성·취소, 비공개 방 초대 제어 + +Docker, Playwright Chromium, 그리고 Windows가 아니면 `pwsh`가 필요합니다. UI를 root +저장소의 `ui` submodule로 checkout했다면 환경 변수 없이 실행할 수 있습니다. ```powershell -$env:A23_BACKEND_DIR='C:\path\to\Idea2Strategy-backend' -$env:A23_ROOT_DIR='C:\path\to\Idea2Strategy-root' +pnpm e2e:install pnpm e2e:real-api ``` -Pinned root bundle은 root 검증 스크립트의 resource-free manifest/SHA-256/source-revision -정책을 그대로 실행한 뒤, harness가 label을 붙인 PostgreSQL/Flyway에서 migrate와 validate를 -수행합니다. -DB 비밀번호와 네 가지 용도별 HMAC/암호화 키는 실행마다 별도로 생성하고 파일에 쓰지 +`pnpm e2e:real-api`는 앱과 backend용 빈 포트를 하나씩 할당해 `A23_APP_PORT`, +`A23_BACKEND_PORT`로 넘깁니다. `playwright.real-api.config.ts`를 직접 실행하면 포트가 없어 +즉시 실패합니다. Global setup(`e2e/realApiGlobalSetup.ts`)은 다음 순서로 동작합니다. + +1. UI checkout의 상위 디렉터리를 root 저장소로, `../backend`를 backend 저장소로 사용합니다. + 다른 위치는 `A23_ROOT_DIR`, `A23_BACKEND_DIR`로 지정합니다. Backend `HEAD`는 root가 + 고정한 `backend` gitlink와 같아야 하며 `A23_BACKEND_REVISION`으로 바꿀 수 있습니다. Root + revision은 `A23_ROOT_REVISION`을 지정했을 때만 검사합니다. 두 저장소 모두 깨끗해야 하고, + root에서는 `A23_ROOT_ALLOWED_DIRTY_GITLINKS`(쉼표 구분)에 적은 submodule gitlink 변경만 + 허용합니다. +2. Root `scripts/test-flyway-ci-bundle.ps1`의 resource-free 검증 부분으로 + `db/flyway-ci-bundle`의 manifest, SHA-256, source revision을 확인합니다. +3. 전용 Docker network에 PostgreSQL 16을 띄우고 Flyway 11로 migrate와 validate를 실행한 뒤 + 전략 instrument(AAPL, MSFT, SPY), `config/development/runtime-policy/policy-seed.sql`, + `config/development/scoring/scoring-template-seed.sql`을 넣습니다. +4. Gradle 8.14.3/JDK 21 컨테이너에서 backend checkout을 mount해 + `:apps:backend-api:bootRun`을 실행하고 `/actuator/health`가 응답할 때까지 기다립니다. + 대기 시간은 기본 600초이며 `A23_BACKEND_READY_TIMEOUT_SECONDS`로 60-1200초 사이에서 + 바꿀 수 있습니다. +5. Vite dev server는 `VITE_REAL_API_TARGET`으로 `/api`와 `/actuator` 요청을 이 backend에 + proxy합니다. + +DB 비밀번호와 identity 암호화·HMAC·JWT 서명 키는 실행마다 새로 생성하고 파일에 쓰지 않습니다. 실행 중에는 Docker inspect 권한이 있는 로컬 사용자가 컨테이너 환경을 볼 수 -있으므로 harness는 project/run label을 붙입니다. 다른 active run은 건드리지 않고 1시간 넘게 -중지된 resource만 회수합니다. 같은 backend checkout의 Gradle output을 공유하므로 project별 -active-run lock으로 실행을 직렬화하며, 두 번째 실행은 첫 실행을 삭제하지 않고 즉시 실패합니다. 정상 종료·process -exit·SIGINT·SIGTERM에서는 자기 컨테이너와 network만 제거합니다. 정상 teardown의 inspect나 -삭제 실패는 테스트 실패로 보고합니다. -Gradle cache는 host UID나 bind mount에 의존하지 않는 Docker named volume에만 저장합니다. -이 cache volume은 실행 간 재사용하도록 의도적으로 유지하며, 비밀번호·암호화 키 등 실행 secret은 저장하지 않습니다. -신뢰된 servlet principal과 MFA를 수립하는 gateway가 준비되기 전까지 operator 경로는 -의도적으로 제외합니다. +있습니다. 모든 resource에는 project/run label이 붙습니다. 같은 backend checkout의 Gradle +output을 공유하므로 lock 컨테이너로 실행을 직렬화하며, 두 번째 실행은 첫 실행을 건드리지 +않고 즉시 실패합니다. 1시간 넘게 중지된 resource만 회수하고, 정상 종료·process exit·SIGINT· +SIGTERM에서는 자기 컨테이너와 network만 제거합니다. 정상 teardown의 inspect나 삭제 실패는 +테스트 실패로 보고합니다. + +Gradle cache는 기본적으로 Docker named volume `a23-real-api-gradle-cache`에 두고 실행 간 +재사용합니다. CI처럼 `A23_GRADLE_CACHE_DIR`를 지정하면 그 디렉터리를 bind mount합니다. +Cache에는 비밀번호나 키 같은 실행 secret을 저장하지 않습니다. + +`A23_EXTERNAL_BASE_URL`을 지정하면 global setup과 dev server 없이 이미 떠 있는 stack을 +대상으로 실행하고, `A23_FULL_STACK_E2E=1`이면 `e2e/basic-strategy-real.e2e.ts`만 실행합니다. +Root `scripts/test-basic-strategy-real-e2e.ps1`이 이 방식을 사용합니다. Operator cookie +session 화면은 mock API를 쓰는 `pnpm e2e:operator-session`에서 검증합니다. ## 현재 제품 구성 diff --git a/docs/OPERATOR_OIDC_DEPLOYMENT.md b/docs/OPERATOR_OIDC_DEPLOYMENT.md deleted file mode 100644 index 5b3928f..0000000 --- a/docs/OPERATOR_OIDC_DEPLOYMENT.md +++ /dev/null @@ -1,46 +0,0 @@ -# Production operator OIDC inputs - -The production UI uses a dedicated OAuth 2.0 Authorization Code flow with PKCE for -operator access. It does not reuse the customer session. Tokens are held in browser -memory; `sessionStorage` contains only a one-time, five-minute redirect transaction -and is cleared after callback or failure. - -Set these values when building the production frontend: - -| Variable | Required value | -| --- | --- | -| `VITE_OPERATOR_OIDC_ENABLED` | `true` | -| `VITE_OPERATOR_OIDC_ISSUER` | Exact HTTPS issuer accepted by the backend/gateway | -| `VITE_OPERATOR_OIDC_AUTHORIZATION_ENDPOINT` | Provider HTTPS authorization endpoint | -| `VITE_OPERATOR_OIDC_TOKEN_ENDPOINT` | Provider HTTPS token endpoint with browser CORS enabled for the UI origin | -| `VITE_OPERATOR_OIDC_END_SESSION_ENDPOINT` | Optional provider HTTPS logout endpoint | -| `VITE_OPERATOR_OIDC_CLIENT_ID` | Public browser client ID (no client secret) | -| `VITE_OPERATOR_OIDC_AUDIENCE` | Exact operator API audience accepted by the backend/gateway | -| `VITE_OPERATOR_OIDC_REDIRECT_URI` | Same-origin absolute URL ending in `/operations/callback` | -| `VITE_OPERATOR_OIDC_POST_LOGOUT_REDIRECT_URI` | Same-origin absolute URL ending in `/operations/login` | -| `VITE_OPERATOR_OIDC_LOGOUT_REDIRECT_PARAMETER` | `post_logout_redirect_uri` by default; use `logout_uri` for Amazon Cognito managed login | -| `VITE_OPERATOR_OIDC_SCOPES` | Space-delimited scopes including `openid`; include the provider's refresh scope if refresh tokens are enabled | -| `VITE_OPERATOR_OIDC_SIGNING_ALGORITHM` | Exact expected JWT algorithm, normally `RS256` | - -Register both redirect URIs on the identity provider. Configure it as a public client: -no client secret is embedded in the frontend, authorization code and PKCE S256 are -required, implicit flow is disabled, and redirect URI matching is exact. - -The browser validates token shape, algorithm and time/issuer/audience/nonce claims to -fail closed before use. Cryptographic JWT signature, current MFA and operator RBAC are -authoritatively validated by the backend or trusted gateway on every operator request. -All operator API calls use `Authorization: Bearer` with `credentials: omit`. - -`VITE_*` values are public build-time configuration, not secrets. Provider client -secrets, private keys and backend credentials belong in the runtime secret store and -must never be supplied to the UI build. - -Run the production-mode browser contract locally with: - -```powershell -pnpm e2e:operator-oidc -``` - -This starts a disposable mock IdP, checks the real PKCE redirect and token exchange in -Chromium, verifies the isolated bearer request, confirms tokens are not persisted, and -exercises provider logout. diff --git a/docs/RUNTIME_DATA_READINESS.md b/docs/RUNTIME_DATA_READINESS.md index 17db98f..a200f26 100644 --- a/docs/RUNTIME_DATA_READINESS.md +++ b/docs/RUNTIME_DATA_READINESS.md @@ -43,7 +43,7 @@ records the exact blocker so the UI does not invent a contract. ## External runtime prerequisite After that contract is approved and implemented, activation still requires a -deployed provider, a real authenticated browser session, and the configured -operator OIDC/AWS trust path. Browser mocks are not acceptable release +deployed provider, a real authenticated browser session, and the internal +operator cookie-session sign-in. Browser mocks are not acceptable release evidence. These external prerequisites are separate from the UI's loading, error, and empty-state implementation. diff --git a/e2e/ports.ts b/e2e/ports.ts index ed9c3ff..a1e949f 100644 --- a/e2e/ports.ts +++ b/e2e/ports.ts @@ -8,8 +8,6 @@ */ export const APP_PORT = 4318; export const MOCK_API_PORT = 4319; -export const MOCK_IDP_PORT = 4320; export const APP_URL = `http://127.0.0.1:${APP_PORT}`; export const MOCK_API_URL = `http://127.0.0.1:${MOCK_API_PORT}`; -export const MOCK_IDP_URL = `http://127.0.0.1:${MOCK_IDP_PORT}`; diff --git a/playwright.config.ts b/playwright.config.ts index 52f561e..831fd7c 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -26,7 +26,6 @@ export default defineConfig({ /real-account-api\.e2e\.ts/, /basic-strategy-real\.e2e\.ts/, /competition-room-create-real\.e2e\.ts/, - /operator-oidc\.e2e\.ts/, /operator-session\.e2e\.ts/, ], fullyParallel: true, @@ -57,9 +56,6 @@ export default defineConfig({ // single line of application code for the test. env: { VITE_API_BASE_URL: MOCK_API_URL, - // Enables only the explicit development bridge. The token itself is injected - // at browser runtime and is never compiled into the Vite bundle. - VITE_ENABLE_LOCAL_OPERATOR_HARNESS: 'true', }, }, }); diff --git a/src/api/accountOperations.test.ts b/src/api/accountOperations.test.ts index 8a78ff8..8258436 100644 --- a/src/api/accountOperations.test.ts +++ b/src/api/accountOperations.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import { AccountOperationsApiError, createAccountOperationsClient, createAdminMcpClient } from './accountOperations'; +import { AccountOperationsApiError, createAccountOperationsClient } from './accountOperations'; const caseView = { id: 'case-1', accountId: 'account-1', type: 'APPEAL', status: 'OPEN', version: 1, @@ -133,23 +133,3 @@ describe('account operations API client', () => { expect(fetchImpl).toHaveBeenCalledTimes(1); }); }); - -describe('admin MCP client', () => { - it('invokes only an explicitly named versioned tool with idempotency and correlation', async () => { - const fetchImpl = vi.fn().mockResolvedValue(new Response(JSON.stringify({ status: 'EXECUTED', code: 'OK', result: { accepted: true }, correlationId: 'corr-mcp' }), { status: 200 })); - const client = createAdminMcpClient({ baseUrl: 'https://admin.example/', fetchImpl, createCorrelationId: () => 'corr-mcp', getOperatorCsrfToken: () => 'operator-token' }); - await expect(client.invoke('corporate_action_candidate.query', { registryVersion: 'mcp-v1', requestSchemaVersion: 'schema-v1', targetId: 'candidate-1', input: { candidateId: 'candidate-1' } }, 'idem-mcp')) - .resolves.toEqual({ status: 'EXECUTED', code: 'OK', result: { accepted: true }, correlationId: 'corr-mcp' }); - expect(fetchImpl).toHaveBeenCalledWith('https://admin.example/mcp/v1/tools/corporate_action_candidate.query:invoke', expect.objectContaining({ - headers: expect.objectContaining({ 'X-Operator-CSRF': 'operator-token', 'Idempotency-Key': 'idem-mcp', 'X-Correlation-Id': 'corr-mcp' }), - })); - }); - - it('fails closed without an independently established operator credential', async () => { - const fetchImpl = vi.fn().mockResolvedValue(new Response(JSON.stringify({ code: 'OPERATOR_AUTHENTICATION_REQUIRED' }), { status: 401 })); - const client = createAdminMcpClient({ fetchImpl, createCorrelationId: () => 'corr-mcp-guard', getAccessToken: () => 'ordinary-session-token' }); - await expect(client.invoke('tool', { registryVersion: 'v1', requestSchemaVersion: 'v1', targetId: 'target', input: {} }, 'idem')) - .rejects.toEqual(expect.objectContaining({ status: 401, code: 'OPERATOR_AUTHENTICATION_REQUIRED' })); - expect(fetchImpl).toHaveBeenCalledTimes(1); - }); -}); diff --git a/src/api/accountOperations.ts b/src/api/accountOperations.ts index c629619..f77cc79 100644 --- a/src/api/accountOperations.ts +++ b/src/api/accountOperations.ts @@ -251,38 +251,6 @@ export function createAccountOperationsClient({ }; } -export interface AdminMcpClient { - invoke(toolName: string, input: { registryVersion: string; requestSchemaVersion: string; targetId: string; targetVersion?: number | null; input: Record }, idempotencyKey: string, signal?: AbortSignal): Promise<{ status: string; code: string; result: Record; correlationId: string }>; -} - -export function createAdminMcpClient(options: ClientOptions = {}): AdminMcpClient { - const root = (options.baseUrl ?? '').replace(/\/$/, ''); - const fetchImpl = options.fetchImpl ?? fetch; - const correlation = options.createCorrelationId ?? (() => crypto.randomUUID()); - return { - async invoke(toolName, input, idempotencyKey, signal) { - const correlationId = correlation(); - const csrf = options.getOperatorCsrfToken?.(); - let response: Response; - try { - response = await fetchImpl(`${root}/mcp/v1/tools/${encodeURIComponent(toolName)}:invoke`, { - method: 'POST', signal, credentials: 'include', - headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'Idempotency-Key': idempotencyKey, 'X-Correlation-Id': correlationId, ...(csrf ? { 'X-Operator-CSRF': csrf } : {}) }, - body: JSON.stringify({ ...input, targetVersion: input.targetVersion ?? null }), - }); - } catch { - throw new AccountOperationsApiError(0, 'NETWORK_ERROR', correlationId); - } - if (!response.ok) throw await readError(response, correlationId); - const value = object(await json(response)); - return { - status: text(value.status, 'status'), code: text(value.code, 'code'), - result: object(value.result), correlationId: text(value.correlationId, 'correlationId'), - }; - }, - }; -} - async function readError(response: Response, fallbackCorrelationId: string) { let body: Record = {}; try { body = object(await response.json()); } catch { /* keep protocol fallback */ } @@ -410,4 +378,3 @@ async function sha256(value: string): Promise { } export const defaultAccountOperationsClient = createAccountOperationsClient({ baseUrl: import.meta.env.VITE_API_BASE_URL ?? '', getAccessToken: getSessionAccessToken }); -export const defaultAdminMcpClient = createAdminMcpClient({ baseUrl: import.meta.env.VITE_ADMIN_MCP_BASE_URL ?? '' }); diff --git a/src/lib/operatorLocalHarness.test.ts b/src/lib/operatorLocalHarness.test.ts deleted file mode 100644 index d1a903c..0000000 --- a/src/lib/operatorLocalHarness.test.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { describe, expect, it } from 'vitest'; -import { createLocalOperatorHarness, LOCAL_OPERATOR_TOKEN_KEY } from './operatorLocalHarness'; - -const storage = (token: string | null): Pick => ({ - getItem: (key) => key === LOCAL_OPERATOR_TOKEN_KEY ? token : null, -}); - -describe('local operator browser harness', () => { - it('is dormant unless an explicit development-only flag is present', () => { - expect(createLocalOperatorHarness({ enabled: false, mode: 'development', storage: storage('token') })).toBeNull(); - expect(createLocalOperatorHarness({ enabled: true, mode: 'production', storage: storage('token') })).toBeNull(); - }); - - it('reads a runtime session token without embedding it in the bundle', () => { - const harness = createLocalOperatorHarness({ enabled: true, mode: 'development', storage: storage('operator-token') }); - expect(harness).not.toBeNull(); - expect(harness?.getOperatorAccessToken()).toBe('operator-token'); - }); - - it('stays fail closed when the local browser has no token', () => { - const harness = createLocalOperatorHarness({ enabled: true, mode: 'development', storage: storage(null) }); - expect(harness?.getOperatorAccessToken()).toBeNull(); - }); -}); diff --git a/src/lib/operatorLocalHarness.ts b/src/lib/operatorLocalHarness.ts deleted file mode 100644 index 0390f0e..0000000 --- a/src/lib/operatorLocalHarness.ts +++ /dev/null @@ -1,26 +0,0 @@ -export const LOCAL_OPERATOR_TOKEN_KEY = 'idea2strategy.local.operatorAccessToken'; - -interface LocalOperatorHarnessOptions { - enabled: boolean; - mode: string; - storage: Pick; -} - -export interface LocalOperatorHarness { - getOperatorAccessToken(): string | null; -} - -/** - * Development-only bridge for the offline Chromium journey. Production operator - * credentials still come from the deployed OIDC integration; this bridge cannot be - * activated in a production build and never contains a credential of its own. - */ -export function createLocalOperatorHarness({ enabled, mode, storage }: LocalOperatorHarnessOptions): LocalOperatorHarness | null { - if (!enabled || mode !== 'development') return null; - return { - getOperatorAccessToken() { - const token = storage.getItem(LOCAL_OPERATOR_TOKEN_KEY)?.trim(); - return token || null; - }, - }; -} diff --git a/start.cmd b/start.cmd deleted file mode 100644 index 4ce0a36..0000000 --- a/start.cmd +++ /dev/null @@ -1,22 +0,0 @@ -@echo off -setlocal - -set "NODE_EXE=%USERPROFILE%\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe" -set "VITE_ENTRY=%~dp0node_modules\vite\bin\vite.js" - -if not exist "%NODE_EXE%" ( - echo [ERROR] Node.js runtime was not found. - echo Install Node.js LTS, then run: corepack enable - exit /b 1 -) - -if not exist "%VITE_ENTRY%" ( - echo [ERROR] Project dependencies were not found. - echo Run pnpm install after installing Node.js and enabling Corepack. - exit /b 1 -) - -echo Starting I2S UI/UX sample... -echo Open http://localhost:5173 in your browser. -"%NODE_EXE%" "%VITE_ENTRY%" --host 127.0.0.1 %* -