Skip to content
43 changes: 43 additions & 0 deletions .dump/_relation_browser_check_v13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
"""V13 关系索引真实 Chrome 冒烟:关系页只加载 relation core,不预取 metadata。"""
from __future__ import annotations
import os,re,shutil,subprocess,sys,tempfile
from pathlib import Path

TARGET=(Path(sys.argv[1]) if len(sys.argv)>1 else Path('dist/full/index.html')).resolve()


def find_chrome():
env=os.environ.get('CHROME_BIN')
if env and Path(env).exists():return env
for name in ('google-chrome','chrome','chromium','chromium-browser'):
found=shutil.which(name)
if found:return found
for cand in ('/usr/bin/google-chrome','/usr/bin/chromium'):
if Path(cand).exists():return cand
return None


def chrome_dump(hash_:str,budget:int=10000)->str:
chrome=find_chrome()
if not chrome:raise SystemExit('未找到 Chrome / Chromium')
with tempfile.TemporaryDirectory() as prof:
cmd=[chrome,'--headless=new','--disable-gpu','--no-first-run','--no-default-browser-check','--disable-extensions','--allow-file-access-from-files','--user-data-dir='+prof,'--virtual-time-budget=%d'%budget,'--dump-dom',TARGET.as_uri()+hash_]
if hasattr(os,'geteuid') and os.geteuid()==0:cmd.insert(1,'--no-sandbox')
r=subprocess.run(cmd,capture_output=True,text=True,encoding='utf-8',errors='replace')
if not r.stdout:raise AssertionError('Chrome 未返回 DOM:%s'%((r.stderr or '').strip()[-500:]))
return r.stdout


def check_relation_core_only():
dom=chrome_dump('#view=relations')
for pattern in (r'data-ming-chunks="relations"',r'data-ming-data-chunk="relations"',r'id="relations" class="view active"',r'关系索引',r'<table class="data-table">'):
if not re.search(pattern,dom,re.S):raise AssertionError('缺少关系页渲染结果:%s'%pattern)
if 'data-ming-data-chunk="relation-meta"' in dom:
raise AssertionError('关系索引不应预取 relation-meta')
print('ok V13 关系索引仅 relation core,不预取 metadata')


if __name__=='__main__':
if not TARGET.exists():raise SystemExit('目标文件不存在:%s'%TARGET)
check_relation_core_only()
19 changes: 14 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:

jobs:
check:
name: 语法 · 不变量 · 构建 · V12 浏览器
name: 语法 · 不变量 · 构建 · V13 浏览器
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
Expand All @@ -35,7 +35,7 @@ jobs:
echo "未发现原书全文文件 ✓"

- name: Python 语法检查
run: python -m compileall -q src tests .dump/_web_browser_check.py
run: python -m compileall -q src tests .dump/_web_browser_check.py .dump/_relation_browser_check_v13.py

- name: 前端动态统计口径规范化
run: |
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
python src/sync_theme.py
git diff --check -- web/template/index.html

- name: V3 / V12 产品体验镜像同步冒烟
- name: V3 / V13 产品体验镜像同步冒烟
run: |
python src/sync_experience.py
python src/sync_experience.py --check
Expand All @@ -83,7 +83,8 @@ jobs:
python src/sync_readme.py
python src/sync_readme_v11.py
python src/sync_readme_v12.py
python src/sync_readme_v12.py --check
python src/sync_readme_v13.py
python src/sync_readme_v13.py --check
git diff --check -- README.md

- name: 构建冒烟(standalone,不落盘)
Expand All @@ -101,13 +102,15 @@ jobs:
- name: 离线版体积预算
run: python src/check_budget.py .ci/standalone.html

- name: 构建在线 V12 分层产物
- name: 构建在线 V13 分层产物
run: |
python src/build.py --scope full --target web --out .ci/site --quiet
python src/split_time_asset_v11.py .ci/site
python src/split_time_asset_v11.py .ci/site --check
python src/split_event_asset_v12.py .ci/site
python src/split_event_asset_v12.py .ci/site --check
python src/split_relation_asset_v13.py .ci/site
python src/split_relation_asset_v13.py .ci/site --check

- name: 在线实体/空间基础结构与体积预算
run: python src/check_delivery.py .ci/site
Expand All @@ -118,6 +121,9 @@ jobs:
- name: V12 事件摘要/详情分层与组合入口预算
run: python src/check_event_layers_v12.py .ci/site

- name: V13 关系 core / metadata 分层预算
run: python src/check_relation_layers_v13.py .ci/site

- name: 单文件无头浏览器自检
run: python .dump/_browser_check.py .ci/standalone.html

Expand All @@ -126,3 +132,6 @@ jobs:

- name: V12 在线分层浏览器自检
run: python .dump/_web_browser_check.py .ci/site/index.html

- name: V13 关系索引在线浏览器自检
run: python .dump/_relation_browser_check_v13.py .ci/site/index.html
18 changes: 11 additions & 7 deletions .github/workflows/refresh-index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ concurrency:
jobs:
refresh:
if: github.actor != 'github-actions[bot]'
name: 重建在线 V12 分层版、离线版与 README 统计
name: 重建在线 V13 分层版、离线版与 README 统计
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
Expand All @@ -48,17 +48,18 @@ jobs:
- name: 同步视觉主题镜像
run: python src/sync_theme.py

- name: 同步 V3 / V12 产品体验镜像
- name: 同步 V3 / V13 产品体验镜像
run: python src/sync_experience.py

- name: 同步 README 最终模型与 V12 交付说明
- name: 同步 README 最终模型与 V13 交付说明
run: |
python src/sync_readme.py
python src/sync_readme_v11.py
python src/sync_readme_v12.py
python src/sync_readme_v12.py --check
python src/sync_readme_v13.py
python src/sync_readme_v13.py --check

- name: 构建 V12 双交付产物
- name: 构建 V13 双交付产物
shell: bash
run: |
rm -rf .ci/publish
Expand All @@ -67,6 +68,8 @@ jobs:
python src/split_time_asset_v11.py .ci/publish --check
python src/split_event_asset_v12.py .ci/publish
python src/split_event_asset_v12.py .ci/publish --check
python src/split_relation_asset_v13.py .ci/publish
python src/split_relation_asset_v13.py .ci/publish --check
python src/build.py --scope full --target standalone --out standalone.html --quiet
rm -rf assets
cp .ci/publish/index.html index.html
Expand All @@ -75,6 +78,7 @@ jobs:
python src/check_delivery.py .ci/publish
python src/check_time_layers_v11.py .ci/publish
python src/check_event_layers_v12.py .ci/publish
python src/check_relation_layers_v13.py .ci/publish
python src/check_budget.py standalone.html

- name: 仅在公开产物变化时回写 main
Expand All @@ -86,11 +90,11 @@ jobs:
exit 0
fi
if git diff --quiet -- web/js/app.js web/js/experience.js web/css/app.css web/template/index.html README.md index.html standalone.html assets; then
echo "源码镜像、README、在线 V12 分层版与离线版均已一致,无需提交。"
echo "源码镜像、README、在线 V13 分层版与离线版均已一致,无需提交。"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add web/js/app.js web/js/experience.js web/css/app.css web/template/index.html README.md index.html standalone.html assets
git commit -m "chore: publish layered event, time and space web data"
git commit -m "chore: publish layered relation, event, time and space web data"
git push origin HEAD:main
67 changes: 67 additions & 0 deletions src/check_relation_layers_v13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
"""V13 关系 core / metadata 分层交付门禁。"""
from __future__ import annotations

import sys
from pathlib import Path

import split_relation_asset_v13 as V13

KIB = 1024
CORE_WARN = 340 * KIB
CORE_HARD = 448 * KIB
META_HARD = 640 * KIB


def human(n: int) -> str:
return "%.1f KiB" % (n / KIB)


def main(argv=None) -> int:
argv = list(sys.argv[1:] if argv is None else argv)
root = Path(argv[0] if argv else ".ci/site")
try:
stats = V13.check_site(root)
except (RuntimeError, ValueError) as exc:
print("[FAIL] %s" % exc)
return 2

loader_path = root / "assets" / "data-loader.js"
if not loader_path.exists():
print("[FAIL] 缺少 data-loader.js")
return 2
loader = loader_path.read_text(encoding="utf-8")
errors = []
for token in (
"'relations','relation-meta','time'",
"relations:['relations']",
"__MING_APPLY_RELATION_META__",
):
if token not in loader:
errors.append("loader 缺少 V13 关系分层契约:%s" % token)
if "relations:['relations','relation-meta']" in loader:
errors.append("关系索引仍预取 relation-meta")

core = stats["relations_bytes"]
meta = stats["meta_bytes"]
print("V13 relation core:%s · %d relations" % (human(core), stats["relation_count"]))
print("V13 deferred relation metadata:%s" % human(meta))
print("V13 关系索引零缓存数据:%s" % human(core))

if core > CORE_HARD:
errors.append("data-relations.js 超过 hard %s" % human(CORE_HARD))
elif core > CORE_WARN:
print("[WARN] relation core %s > warn %s" % (human(core), human(CORE_WARN)))
if meta > META_HARD:
errors.append("data-relation-meta.js 超过 hard %s" % human(META_HARD))

if errors:
for error in errors:
print("[FAIL] %s" % error)
return 1
print("V13 关系 core / metadata 分层预算通过。")
return 0


if __name__ == "__main__":
raise SystemExit(main())
Loading