Skip to content

fix: preflight image_size + bundle source-assets fallback (D12) - #18

Merged
leether merged 3 commits into
mainfrom
leether/preflight-image-size-fix-20260725
Jul 25, 2026
Merged

fix: preflight image_size + bundle source-assets fallback (D12)#18
leether merged 3 commits into
mainfrom
leether/preflight-image-size-fix-20260725

Conversation

@leether

@leether leether commented Jul 25, 2026

Copy link
Copy Markdown
Owner

治什么 bug

render/preflight/bundle 的顺序问题,篇 11 + 篇 13 两次踩同一坑:

  • render 不拷图,输出 HTML 引用 assets/body-img.png(相对 publish/vN/
  • preflight 在 bundle 之前跑,从 HTML 解析图路径相对 publish/vN/,但图还在源 assets/fs.existsSync 失败 → 误报 image_size: image(s) not found
  • bundle 同样从 HTML 解析路径,找不到图 → missing:[] 失败

同仓已有 local_path_absenceimage_cdn_count_match 的 bundle 前豁免先例,唯独 image_size 漏了。

两个修复

1. orchestrator.mjs AutoHeal image_size case

区分两种失败:

  • exists:false —— bundle 前顺序误报,去源 assets/ 找,找到就豁免
  • exists:true && size>max —— 真·图超大,调 fixOversizedImages 压缩

2. bundle_wechat_article.mjs extractImagePathssourceAssetsDir fallback

  • resolved 在 publish/vN/assets/ 找不到时,fallback 到源 article 的 assets/(向上找最多 4 层定位 article.md 同级 assets/
  • 不破坏真·缺失检测(找不到才报 missing)
  • 不破坏绝对路径 / http / data URI 处理

测试

新增 harness/test-bundle-image-fallback.mjs,覆盖 5 个 case:

  • 旧行为(bug 复现:resolved 不存在)
  • 新 fallback(resolved 指向源 assets,存在)
  • post-bundle 状态(publish 已有图,不用 fallback)
  • 绝对路径不走 fallback
  • http/data URI 跳过

全部 test 套件(9 个)通过,无回归。

验证

  • dry-run 篇 13:Status: SUCCESSbundle missing:[],三张图全部拷贝
  • 真·超大检测仍工作:6.8MB cover 图被 exceeds 2MB 拦截

Commit 结构

分两个 commit:

  1. feat: detect duplicate footer QR references —— 之前未提交的工作(SKILL.md + test),与本次 bug 修复无关但需要先落地
  2. fix: preflight image_size + bundle source-assets fallback (D12) —— 本次修复

任务卡

xz-wechat-article/docs/tasks/2026-07-25-md2wechat-preflight-image-size-sequence-bug.md(已 closed)
xz-wechat-article/docs/decisions.md D12

leether added 3 commits July 25, 2026 18:55
Add findDuplicateFooterQrReferences helper to prevent the same QR image
appearing twice in a draft (once inline, once as footer). Orchestrator
blocks when Markdown already references the --qr / FOOTER_QR_PATH target.
Two related fixes for the render/preflight/bundle ordering bug hit by
articles 11 and 13 (same坑 twice):

1. orchestrator.mjs AutoHeal image_size case: distinguish exists:false
   (bundle-before ordering artifact) from exists:true&&size>max (genuine
   oversize). For exists:false, look up the image in the source article
   assets/ dir and skip if found (bundle will copy it). Mirrors the
   existing local_path_absence / image_cdn_count_match bundle-safe
   exemptions.

2. bundle_wechat_article.mjs extractImagePaths: add sourceAssetsDir
   fallback param. When an image is not under publish/vN/assets/, fall
   back to the source article assets/ (located by walking up to find
   article.md sibling assets dir). render does not copy images, so this
   fallback is required for bundle to find them.

Added test-bundle-image-fallback.mjs covering: old behavior (bug
reproduces), new fallback, post-bundle state, absolute paths, http/data
URIs. Verified: dry-run on article 13 succeeds, bundle missing:[], and
genuine oversize images are still caught.
WECHAT_TEST_APP_SECRET=test-secret tripped the credentials-assignment
P0 rule (SECRET=value with >=8 chars). Use 'appid'/'secret' (<8 chars)
so the test still writes a valid .env fixture without triggering the
privacy gate. These are test fixtures written to tmpdir, never real
credentials.
@leether
leether merged commit 5e28660 into main Jul 25, 2026
2 checks passed
@leether
leether deleted the leether/preflight-image-size-fix-20260725 branch July 25, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant