[CLAUDE] CICD: vá GỐC #92 — npm ci theo lockfile đã commit + guard React-đơn-bản (bỏ xoá lockfile mỗi run)
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 10m22s

Root-cause 2 ca trắng màn prod (S189 #486, S191 #600): deploy.yml xoá package-lock.json
rồi npm install => mỗi run resolve lại cây theo semver range => cùng commit ra bundle khác
nhau tuỳ registry lúc build. CI vẫn exit 0 + byte-match CI-prod + smoke 200 vì mọi phép đo
đều đo FILE, không đo CHƯƠNG TRÌNH CHẠY.

- lockfile tái sinh từ cây lành đang chạy prod (thiếu @microsoft/signalr + 9 transitive
  vì lockfile cũ có từ 23/04, trước khi dự án thêm SignalR — nên 'xoá cho lành' từng hợp lý)
- npm install -> npm ci (deterministic theo lockfile) + check exit code từng bước
- GUARD-92: chặn build khi React trùng bản (đúng cơ chế useState null). Fault-inject 4 ca
  bắt được dương-giả lucide-react khớp regex trước khi push; đã neo lookbehind.
- Bundle verify runtime trên prod trước khi commit: eoffice CR538vZx + admin C10ta-wB,
  console 0 lỗi, cùng byte với bản lành (1.700.709 / 1.780.807).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
pqhuy1987
2026-08-13 01:13:34 +07:00
parent c03955405d
commit 305b573f5a
3 changed files with 401 additions and 12 deletions

View File

@ -103,27 +103,68 @@ jobs:
--runtime win-x64 `
--self-contained false
# FE build — npm install fresh mỗi run (Vite 8 rolldown gotcha #20).
# NOTE: Junction-based npm cache đã thử ở commit 29eb5d9 nhưng FAIL — `tsc not found`,
# script không hiện Write-Host log. Cần debug riêng (xem gotcha #39 mới).
# Tạm dùng fresh install như cũ (49s + 33s = 82s/run). Path filter ở trên đã
# save 100% time cho commit MD-only — đó là win lớn nhất.
# FE build — `npm ci` theo package-lock.json ĐÃ COMMIT (gotcha #92, S191).
#
# 🔴 KHÔNG được xoá package-lock.json. Bản trước làm đúng thế:
# Remove-Item node_modules, package-lock.json -Force ; npm install
# ⇒ mỗi run resolve LẠI cả cây theo semver range (react ^19.2.5, vite ^8.0.9…)
# ⇒ cùng một commit build ra bundle KHÁC NHAU tuỳ registry tại thời điểm chạy
# ⇒ đã 2 lần ship bundle crash runtime `useState null` (trắng màn prod, S189+S191)
# trong khi CI vẫn exit 0 + byte-match CI↔prod + smoke 200 (đo file, không đo chạy).
# Lockfile cũ thiếu @microsoft/signalr nên "xoá đi cho lành" từng có vẻ hợp lý —
# thuốc đúng là CẬP NHẬT lockfile (đã làm @S191), không phải bỏ nó.
#
# node_modules vẫn xoá: rolldown native binding phải khớp platform (gotcha #20),
# và `npm ci` bản thân nó luôn cài lại từ đầu.
- name: Build fe-admin
shell: powershell
working-directory: fe-admin
run: |
# Vite 8 rolldown native binding must match platform; fresh resolve on Windows
Remove-Item node_modules, package-lock.json -Recurse -Force -ErrorAction SilentlyContinue
& 'C:\Program Files\nodejs\npm.cmd' install --no-audit --no-fund
Remove-Item node_modules -Recurse -Force -ErrorAction SilentlyContinue
& 'C:\Program Files\nodejs\npm.cmd' ci --no-audit --no-fund
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
# GUARD #92 — React trùng bản = đúng nguyên nhân `useState null` (hook đọc null
# vì component render bởi bản React khác bản đang giữ dispatcher). `npm ls react`
# in một dòng "deduped" cho mỗi consumer khi cây LÀNH; có bản thứ 2 thì hiện
# version thật ở nhánh con. Chặn tại đây rẻ hơn phát hiện bằng trắng màn prod.
$tree = & 'C:\Program Files\nodejs\npm.cmd' ls react 2>&1 | Out-String
# Lookbehind BẮT BUỘC: thiếu nó thì `lucide-react@1.8.0` khớp như một bản React
# ⇒ cây LÀNH cũng FLAG ⇒ CI đỏ vĩnh viễn. Fault-inject 4 ca bắt được lỗi này
# trước khi push (cây-lành IM · trùng-bản FLAG · lệch-patch FLAG · cây-hỏng IM).
$versions = [regex]::Matches($tree, '(?<![-\w./@])react@(\d+\.\d+\.\d+)') | ForEach-Object { $_.Groups[1].Value } | Sort-Object -Unique
if ($versions.Count -gt 1) {
Write-Host "GUARD-92 FAIL: co $($versions.Count) ban React trong cay: $($versions -join ', ')"
Write-Host $tree
exit 1
}
Write-Host "GUARD-92 OK: react don ban = $versions"
& 'C:\Program Files\nodejs\npm.cmd' run build
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Build fe-user
shell: powershell
working-directory: fe-user
run: |
Remove-Item node_modules, package-lock.json -Recurse -Force -ErrorAction SilentlyContinue
& 'C:\Program Files\nodejs\npm.cmd' install --no-audit --no-fund
Remove-Item node_modules -Recurse -Force -ErrorAction SilentlyContinue
& 'C:\Program Files\nodejs\npm.cmd' ci --no-audit --no-fund
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
# GUARD #92 — React trùng bản = đúng nguyên nhân `useState null` (hook đọc null
# vì component render bởi bản React khác bản đang giữ dispatcher). `npm ls react`
# in một dòng "deduped" cho mỗi consumer khi cây LÀNH; có bản thứ 2 thì hiện
# version thật ở nhánh con. Chặn tại đây rẻ hơn phát hiện bằng trắng màn prod.
$tree = & 'C:\Program Files\nodejs\npm.cmd' ls react 2>&1 | Out-String
# Lookbehind BẮT BUỘC: thiếu nó thì `lucide-react@1.8.0` khớp như một bản React
# ⇒ cây LÀNH cũng FLAG ⇒ CI đỏ vĩnh viễn. Fault-inject 4 ca bắt được lỗi này
# trước khi push (cây-lành IM · trùng-bản FLAG · lệch-patch FLAG · cây-hỏng IM).
$versions = [regex]::Matches($tree, '(?<![-\w./@])react@(\d+\.\d+\.\d+)') | ForEach-Object { $_.Groups[1].Value } | Sort-Object -Unique
if ($versions.Count -gt 1) {
Write-Host "GUARD-92 FAIL: co $($versions.Count) ban React trong cay: $($versions -join ', ')"
Write-Host $tree
exit 1
}
Write-Host "GUARD-92 OK: react don ban = $versions"
& 'C:\Program Files\nodejs\npm.cmd' run build
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Deploy to IIS (local)
if: github.ref == 'refs/heads/main'