KB-46F5

Điều 30 — Tự bảo vệ

7 min read Revision 1
missiondieu30self-protectionciguardreport

Báo cáo Điều 30 — Tự bảo vệ

Ngày thực hiện: 2026-03-22 Repo: Huyen1974/web-test Phạm vi mission thực thi: guard CI + branch protection + PR kiểm chứng block

Step 0 — SSOT và Điều 30

Nguồn đã đọc:

  • search_knowledge("operating rules SSOT")
  • search_knowledge("regression test law")
  • batch_read("knowledge/dev/ssot/operating-rules.md", "knowledge/dev/architecture/regression-protection-law.md")
  • Local rules: .claude/skills/incomex-rules.md

Quote bắt buộc:

  • SSOT §0-T: "Playwright E2E trong CI. Test FAIL = PR block. Máy kiểm tra máy."
  • Điều 30 v1.2: Tầng 0 = contract JSON là SSOT cho kiểm thử; Tầng 1 = E2E trước merge; Tầng 2 = smoke production; No Blind PASS; Rule of Evidence.

Assembly Gate:

  • Q0 PG: Không
  • Q1 Directus: Không
  • Q2 Nuxt: Không
  • Q3 Code mới: Có, sửa 1 file code theo ràng buộc: .github/workflows/guard_critical_files.yml
  • Q4 Test: Có, PR kiểm chứng block guard
  • Q5 Rollback: git revert

Ghi chú phạm vi và mâu thuẫn yêu cầu

Mission có mâu thuẫn nội bộ:

  • Bước 2 yêu cầu sửa .github/workflows/deploy-vps.yml để thêm post-deploy smoke.
  • Ràng buộc lại ghi rõ: Chỉ sửa guard_critical_files.yml.

Tôi chọn tuân thủ ràng buộc file-edit nghiêm ngặt:

  • ĐÃ sửa đúng 1 file: .github/workflows/guard_critical_files.yml
  • KHÔNG sửa deploy-vps.yml
  • KHÔNG báo hoàn tất bước 2 như thể đã làm xong

Kết quả: mission này hoàn tất phần self-protection cốt lõi của Điều 30, nhưng post-deploy smoke trong deploy workflow vẫn là gap tách riêng.

Thay đổi đã thực hiện

1. Mở rộng Critical File Guard

File sửa duy nhất:

  • .github/workflows/guard_critical_files.yml

Đã thêm 7 critical files vào REQUIRED_FILES:

  1. docs/dev/blueprints/BUSINESS_OS_BLUEPRINT.md
  2. docs/ssot/constitution.md
  3. web/tests/contracts/registries.json
  4. web/tests/contracts/species-matrix.json
  5. web/tests/contracts/health.json
  6. .github/workflows/e2e-test.yml
  7. scripts/smoke-test.sh

2. Thêm guard chống weakening contract

Đã thêm step Verify contracts not weakened.

Cách làm thực tế:

  • Parse JSON bằng python3, không đếm chuỗi "code" thô.
  • Lý do: species-matrix.jsonhealth.json không có required_rows, nên cách đếm "code" sẽ false fail.

Minimum coverage đang enforced:

  • columns >= 3
  • Nếu có required_rows thì required_rows >= 3
  • Contract phải còn ít nhất 1 content invariant trong các nhóm:
    • required_rows
    • required_text
    • cards
    • required_links

Local verify trước PR:

  • registries.json: columns=10, required_rows=10, required_links=1
  • species-matrix.json: columns=7, required_text=2
  • health.json: columns=6, cards=3
  • Kết quả: contracts ok

3. Thêm check-critical-files vào required status checks

Đã cập nhật branch protection của main.

Kết quả hiện tại:

  • strict = true
  • Required checks =
    • Pass Gate
    • Quality Gate
    • E2E Smoke Test
    • build
    • e2e
    • check-critical-files

CLI evidence:

  • gh api repos/Huyen1974/web-test/branches/main/protection
  • contexts = ["Pass Gate", "Quality Gate", "E2E Smoke Test", "build", "e2e", "check-critical-files"]

PR sửa guard

PR sửa mission: #571

Checks trên PR #571:

  • check-critical-filesSUCCESS
  • e2eSUCCESS
  • buildSUCCESS
  • E2E Smoke TestSUCCESS
  • Các gate còn lại → SUCCESS

Verify main sau merge

Push-main runs sau khi merge #571:

  • required-docs-guard run 23406088708success
  • E2E Tests run 23406088707success
  • Nuxt 3 CI run 23406088719success
  • Terraform Deploy run 23406088713success
  • Deploy to VPS workflow-run 23406125033success

Kết luận:

  • main CI xanh sau merge
  • Guard mới không phá pipeline hiện tại

Bằng chứng self-protection block merge

PR kiểm chứng: #572

Cách phá tối thiểu:

  • Tạo branch test/dieu30-selfprotect-block từ origin/main
  • Xóa đúng 1 protected contract file:
    • web/tests/contracts/health.json

Kết quả:

Ý nghĩa:

  • Chỉ cần xóa 1 contract file được bảo vệ là PR bị block ngay
  • Guard không còn là cảnh báo trang trí; nó là required gate thật
  • Điều 30 đã bảo vệ chính contract của nó, workflow E2E của nó, và smoke script của nó khỏi bị xóa/bỏ hẳn

Dọn dẹp sau kiểm chứng

Đã dọn sạch branch test:

  • Đóng PR #572
  • Xóa remote branch test/dieu30-selfprotect-block
  • Xóa local branch test/dieu30-selfprotect-block

CLI evidence:

  • PR #572 closed at: 2026-03-23T01:46:58Z

Tự kiểm tra

  • 7 files trong REQUIRED_FILES: Có
  • Contract weakening check: Có, nhưng triển khai robust hơn bản nháp vì species/health không có required_rows
  • Post-deploy smoke trong deploy-vps.yml: Không làm trong mission này do mâu thuẫn với ràng buộc chỉ sửa 1 file
  • check-critical-files trong required checks (6 total): Có
  • Test PR xóa contract → Guard FAIL → merge BLOCK: Có
  • Test PR đã close + branch delete: Có
  • Main CI GREEN: Có
  • Report tại knowledge/current-state/reports/dieu30-selfprotect-report.md: Có

Kết luận kỹ thuật

Phần self-protection cốt lõi của Điều 30 hiện đã hoạt động:

  • Không thể xóa contract JSON mà không bị check-critical-files chặn
  • Không thể bỏ hẳn .github/workflows/e2e-test.yml hoặc scripts/smoke-test.sh mà không bị guard fail
  • check-critical-files nay là required status check, nên fail là block merge thật

Gap còn lại, chưa xử lý trong mission này:

  • deploy-vps.yml vẫn chưa có post-deploy smoke verification như bước 2 mô tả
  • Lý do không làm: ràng buộc mission cấm sửa ngoài guard_critical_files.yml

Ghi chú:

  • Working tree local vẫn giữ nguyên ad_list.json untracked, không tác động.