---
name: pattern-master-page-mirror
description: Mechanical byte-identical mirror admin → user page khi spec deterministic + types/components đã có sẵn ở target app
metadata:
  type: feedback
---

# Pattern 16: Byte-identical mirror admin → user page (S27 Plan CA Chunk B)

**Rule:** Khi spec yêu cầu "Move N page từ fe-admin sang fe-user" + Investigator confirm fe-user CÓ types/components parity → copy NGUYÊN nội dung file (byte-identical SHA256). KHÔNG modify logic, KHÔNG adjust import path nếu `@/` alias resolve identical.

**Why:** Cognition cookie-cutter exception document — Case 2 mechanical parallel với em main BE work. Mirror identical = audit trail rõ (SHA256 verify), 0 implicit decision, regression-safe vì admin code đã UAT pass.

**How to apply:**
1. **Pre-flight verify** (mandatory before copy):
   - Investigator brief listing types/master.ts + 6 ui components (Button/Dialog/Input/Label/Select/Textarea) + DataTable + PageHeader + PermissionGuard + usePermission ở fe-user
   - Read source file để xác nhận pattern + count LOC
   - Glob `fe-user/src/pages/{target_dir}/` để check không duplicate
2. **Execute (parallel Write tools):**
   - `Write` cho mỗi file copy (nguyên nội dung từ Read source)
   - `Edit` cho menuKeys.ts extend (insert sau anchor line cụ thể)
   - `Edit × 2` cho App.tsx (1 cho import block + 1 cho route block)
3. **Verify (parallel):**
   - `npm run build` fe-user pass 0 TS err
   - `Get-FileHash ... -Algorithm SHA256` × N pairs match byte-identical
   - Read fe-user/lib/menuKeys.ts + App.tsx confirm structure
4. **Commit format Chunk X format** với "Pending Chunk Y" footer

**S27 result:** 4 page (948 LOC) + menuKeys (+5 key) + App.tsx (+9 line) = 962 LOC, 6 file, commit `06a441c`, 1916 modules build 14.14s, all 4 SHA256 match.

**Decision tree:**
- Spec nói "copy" + parity confirmed → mirror byte-identical
- Spec nói "rewrite simpler version" + drop edit → Pattern 13 read-only mirror (S24 Plan AA Chunk B)
- Spec nói "share via package" → REFUSE, em main design package boundary

**Gotcha S27:** PowerShell `$_` in `ForEach-Object` block bị Bash tool shell-escape eaten. Workaround: dùng `Get-FileHash file1, file2, file3, ...` list literal + `Format-Table` thay vì pipeline iterate.

Related: [[pattern-fe-mirror-2-app]] (Pattern 5 mirror 2 app on edit), [[pattern-readonly-admin-mirror]] (Pattern 13 read-only flavor)
