# .github/workflows/verify-phase-3.yml
# Source: Phase 3 SDOC-01..06 composite verify gate.
# Triggered on changes to Phase 3 artifacts; runs `pnpm verify:phase-3`.
#
# Canonical gate runs on ubuntu-latest — that is the determinism reference
# platform. Per Phase 3 plan 03-09 SUMMARY: Windows local execution surfaces
# spurious drift due to `core.autocrlf=true` interaction with verify gates;
# CI on Linux is the source of truth for "green".

name: verify-phase-3

on:
  push:
    branches: [main]
    paths:
      - 'docs/extracted-server/**'
      - 'docs/adr/000[23]-*.md'
      - 'tools/protocol-doc/**'
      - 'tools/save-format-doc/**'
      - 'tools/asset-catalog/scripts/lint-*.mjs'
      - 'tools/asset-catalog/src/autogen.ts'
      - 'tools/db-schema/**'
      - 'decomp/wiki/16-*.md'
      - '.planning/research/PITFALLS.md'
      - 'scripts/verify-phase-3.mjs'
      - '.github/workflows/verify-phase-3.yml'
  pull_request:
    paths:
      - 'docs/extracted-server/**'
      - 'docs/adr/000[23]-*.md'
      - 'tools/protocol-doc/**'
      - 'tools/save-format-doc/**'
      - 'tools/asset-catalog/scripts/lint-*.mjs'
      - 'tools/asset-catalog/src/autogen.ts'
      - 'tools/db-schema/**'
      - 'decomp/wiki/16-*.md'
      - '.planning/research/PITFALLS.md'
      - 'scripts/verify-phase-3.mjs'

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v4
        with:
          version: 10
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: 'pnpm'

      # Install per-tool deps (no root workspace until Phase 4)
      - name: Install tools/protocol-doc
        run: cd tools/protocol-doc && pnpm install --frozen-lockfile
      - name: Install tools/save-format-doc
        run: cd tools/save-format-doc && pnpm install --frozen-lockfile
      - name: Install tools/asset-catalog
        run: cd tools/asset-catalog && pnpm install --frozen-lockfile
      - name: Install tools/db-schema
        run: pnpm -C tools/db-schema install --frozen-lockfile

      # Composite verify gate
      - name: pnpm verify:phase-3
        run: pnpm verify:phase-3

      # Post-condition: zero git diff (deterministic regen)
      - name: Confirm no drift after verify
        run: |
          git diff --exit-code docs/extracted-server/ tools/db-schema/migrations/
