# Gate Policy — Track별 필수 게이트 정책
#
# 산출물 ③ — Phase A. 조건부 PASS 수정 반영 v1.1.
# 작성: 2026-05-07 anu-direct 2차 수정안

version: v1.1
updated: '2026-05-07'
status: phase_a_propose_only_corrected
gates:
  smoke:
    description: L1 스모크 테스트 — 서버 재시작 + API 200 / curl evidence
    cost_minutes: 1
    enforcer: finish-task.sh
  L1_smoketest:
    description: Playwright 또는 Chrome devtools 실 브라우저 테스트
    cost_minutes: 5
    enforcer: tests/regression/L1/*
  gemini_evidence:
    description: Gemini PR 자동 리뷰 + High 0건
    cost_minutes: 5
    enforcer: .github/workflows/gemini-review.yml
    external_dependency: BOT_GITHUB_TOKEN (graphql)
  redteam:
    description: 로키 redteam (composite-team) — 디자인/논리 비평
    cost_minutes: 30
    enforcer: composite-team dispatch
  3docs:
    description: Lv.3+ 시스템 설계 시 plan/context/checklist 3문서
    cost_minutes: 60
    enforcer: /3docs-create skill
  brainstorming:
    description: UX 사전 브레인스토밍 (Lv.3-4 + UX 영향 시)
    cost_minutes: 30
    enforcer: /brainstorming skill
  ci_required_checks:
    description: GitHub required status checks (8 of 8 etc.)
    cost_minutes: 10
    enforcer: GitHub branch protection ruleset
    external_dependency: ruleset configuration
  surface_contract:
    description: Expected Change Surface 계약 검증 (Track C 도입 예정)
    cost_minutes: 1
    enforcer: finish-task.sh (TBD)
    status: planned_track_c
  qc_self_check:
    description: QC 8항목 self-check
    cost_minutes: 1
    enforcer: QC-RULES.md
matrix:
  dev_workspace:
    Lv0:
      required:
      - qc_self_check
      optional:
      - smoke
    Lv1:
      required:
      - qc_self_check
      - smoke
      optional: []
    Lv2:
      required:
      - qc_self_check
      - smoke
      - gemini_evidence
      optional:
      - L1_smoketest
    Lv3:
      required:
      - qc_self_check
      - smoke
      - gemini_evidence
      - L1_smoketest
      - 3docs
      optional:
      - redteam
    Lv4:
      required:
      - qc_self_check
      - smoke
      - gemini_evidence
      - L1_smoketest
      - 3docs
      - brainstorming
      - redteam
      optional: []
  user_service:
    Lv0:
      required:
      - qc_self_check
      - smoke
    Lv1:
      required:
      - qc_self_check
      - smoke
      - L1_smoketest
    Lv2:
      required:
      - qc_self_check
      - smoke
      - L1_smoketest
      - gemini_evidence
    Lv3:
      required:
      - qc_self_check
      - smoke
      - L1_smoketest
      - gemini_evidence
      - 3docs
      - redteam
      optional:
      - brainstorming
    Lv4:
      required:
      - qc_self_check
      - smoke
      - L1_smoketest
      - gemini_evidence
      - 3docs
      - brainstorming
      - redteam
      - ci_required_checks
  internal_doc:
    Lv0:
      required: []
    Lv1:
      required:
      - qc_self_check
    Lv2:
      required:
      - qc_self_check
    Lv3:
      required:
      - qc_self_check
      - 3docs
    Lv4:
      required:
      - qc_self_check
      - 3docs
      - brainstorming
merge_policy:
  auto_merge_allowed: true
  merge_queue_allowed_if_all:
  - gemini_status == "success"
  - required_evidence_present == true
  - smoke_or_e2e_passed == true
  - no_blocker_known_issues == true
  - branch_protection_passed == true
  forbidden:
  - bypass_failed_gate
  - bypass_gemini_failure
  - merge_without_evidence
  - force_push_to_main
  - direct_push_to_main
  - admin_override_in_auto_chain
excluded_from_auto_chain:
- production_deploy
- security_change
- credential_change
- external_api_write
- gate_bypass
- force_merge
failure_handling:
  gate_external_dependency_failed:
    action: blocking_issues에 'external_dependency_failed' 추가
    not_treated_as: 본질 실패
    classification_hint: DOGFOODING_PENDING 또는 RETRY_AFTER_INFRA_FIX 후보
  gate_intrinsic_failed:
    action: ESCALATED 분류
    not_treated_as: 외부 의존
  policy_lookup_failed:
    action: fail-closed. blocking_issues에 'gate_policy_undefined_for_track' 추가, risk_level=4
      fallback
  ci_required_checks_infra_failed:
    action: classify as DOGFOODING_PENDING or EXTERNAL_DEPENDENCY_FAILED
    not_treated_as: task intrinsic failure
    classification_hint: ruleset/config/token/check registration failure; merge eligibility
      blocked until infra fix
  validation_failed:
    action: manual_only; dispatch.py 실행 금지; audit validation_failed 기록
    not_treated_as: success
    classification_hint: Subagent JSON parse/schema/policy mismatch failure
precedence:
- 1. 회장 명시 단발 결정 (events/<task>.chairman-decision)
- 2. excluded_from_auto_chain + merge_policy.forbidden
- 3. security / credential / production deploy guard
- 4. forbidden_routings (route_policy)
- 5. gate_policy matrix[track][lv].required
- 6. limited_approval.scope
- 7. auto_chain allow_auto_dispatch_for
- 8. Subagent recommendation (항상 최하위)
- 충돌 시 manual_only + dispatch 금지
chairman_review_required:
- matrix[user_service][Lv4]의 ci_required_checks는 merge eligibility gate로 유지하되, ruleset/infra
  결함은 DOGFOODING_PENDING/EXTERNAL_DEPENDENCY_FAILED로 분리
- surface_contract는 Phase B sample/check only, Phase C dev_workspace P0부터 적용
- DOGFOODING_PENDING 상태는 PASS/FAIL과 별도 분류로 통합 완료. 세부 문구 최종 확인 필요
gate_result_statuses:
  PASS: All intrinsic and required gates passed.
  FAIL_INTRINSIC: Task-owned behavior failed (smoke/e2e/redteam high).
  DOGFOODING_PENDING: Automation/infra/gate system issue blocks verification; not
    task intrinsic failure.
  EXTERNAL_DEPENDENCY_FAILED: Provider/token/network/ruleset dependency failed.
  BLOCKED_BY_ACTIVE_SURFACE: Active task owns overlapping P0/P1 surface.
  MANUAL_ONLY: Policy conflict or schema validation failure; manual chairman/Anu decision
    required.
redteam_policy:
  user_service_lv3_new_feature: required
  user_service_lv3_simple_bugfix: optional
  user_service_lv4: required
  dev_workspace_lv3_plus: optional_unless_gate_security_daemon_state_machine
  dev_workspace_gate_security_daemon_state_machine: required
surface_contract_rollout:
  phase_b: sample_check_only
  phase_c: dev_workspace_p0_required
  user_service: after_beta_gate_stabilized
