Skip to content

fix: harden initialization races and manuscript splitting - #2

Merged
ACBBZ merged 9 commits into
mainfrom
fix/runtime-regressions-20260729
Jul 29, 2026
Merged

ACBBZ merged 9 commits into
mainfrom
fix/runtime-regressions-20260729

Conversation

@ACBBZ

@ACBBZ ACBBZ commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • tolerate directories created between preflight and mkdir only when they are real directories
  • keep raced parent directories out of rollback ownership
  • reject concurrently claimed content/runtime roots before writing into them
  • preserve arbitrary Markdown level-one headings inside chapter bodies
  • continue isolating explicit preface/note/appendix-style headings as pending fragments
  • align invalid entity schema tests with their matching entity types
  • add regression tests for directory races and manuscript heading preservation
  • add GitHub Actions CI for npm run check

Risk controls

  • symlinks and non-directory EEXIST targets remain rejected
  • content/runtime roots must be created by the current initialization attempt
  • no existing book root is recursively removed unless this attempt created it
  • chapter boundaries still recognize 第N章 headings and explicit non-chapter metadata headings

Validation

  • CI runs npm ci and npm run check on pull requests
  • new focused tests cover raced parent directories, conflicting files, arbitrary H1 headings, tail notes, and interstitial author notes

Copilot AI review requested due to automatic review settings July 29, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 主要增强“初始化书籍(init-book)”在并发/竞态场景下的安全性与可回滚性,并改进“导入稿件分章(chapter-splitter)”对 Markdown 一级标题的边界识别,从而避免把正文中的普通 H1 误当作结构分隔符。

Changes:

  • init-bookmkdir 竞态下仅在目标确为目录时容忍 EEXIST,并确保 content/runtime 根目录必须由本次初始化创建,否则拒绝继续写入;回滚时避免把并发产生的父目录纳入“本次创建”的所有权集合。
  • chapter-splitter:将“任意 Markdown H1”改为“仅特定非章节说明类 H1”作为分隔标记,保留章节正文中的任意 H1,同时继续隔离明确的尾注/作者的话等片段。
  • 测试与 CI:新增竞态与标题保留回归测试;新增 GitHub Actions 在 PR/主分支运行 npm ci + npm run check

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/unit/schema-boundaries.test.ts 修正无效实体用例的 id/type 组合,使测试与实体类型匹配
tests/unit/init-book-race.test.ts 新增目录并发创建/同名文件占用的回归测试,覆盖 EEXIST 竞态分支
tests/unit/chapter-splitter.test.ts 新增“正文 H1 保留 + 明确尾注隔离/章间说明隔离”的分章回归测试
src/project/init-book.ts 加固目录创建竞态处理与根目录并发占用拒绝逻辑,并调整回滚所有权记录
src/project/chapter-splitter.ts 将结构标记从“任意 H1”收敛为“特定非章节说明 H1”,避免误切分正文
.github/workflows/ci.yml 新增 CI 工作流,运行 npm run check

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ACBBZ ACBBZ left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已完成逐文件审查,未发现阻塞性问题。

重点核对:

  • EEXIST 仅在目标是非符号链接真实目录时被接受,且并发创建的父目录不会被纳入本次回滚所有权;最终内容根和运行时根必须由本次初始化创建。
  • 任意一级 Markdown 标题会保留在章节正文中,只有明确的前言、作者说明、尾注、附录等标题仍作为待确认片段切分。
  • 新增回归测试覆盖目录竞争、同名普通文件、正文 H1、尾注和章节间作者说明。
  • Schema 边界测试已按 ID 类型对齐。
  • CI 在仓库实际依赖 /usr/bin/lockf 的 macOS 运行环境中通过 npm ci、TypeScript 检查和完整测试。

当前登录账号与 PR 作者相同,GitHub 不允许自我 APPROVE,因此以 COMMENT 形式记录审查结论;结论为可合并。

@ACBBZ
ACBBZ merged commit 8a7e615 into main Jul 29, 2026
1 check passed
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.

2 participants