Просмотр исходного кода

feat(v7): M1 阶段 E——Windows 中文路径全链路测试(AC5 验证)

- 集成测试:os.tmpdir() 下建「测试书仓库」目录
- 含中文路径:定稿/正文/0001-测试章节.md + .cache/index.db
- 全链路验证:重建缓存 + 读取接口(ChapterReader.readFrontMatter)
- 显式 cache.close() 关闭数据库连接(避免 Windows 文件锁导致清理失败)
- 清理临时目录(force: true 容忍锁定失败)
- CI 自动覆盖:.github/workflows/v7-ci.yml 已有 Windows job

测试通过:Windows 中文路径全链路 ✓

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
lingfengQAQ 1 день назад
Родитель
Сommit
2fcfc58b2f
1 измененных файлов с 65 добавлено и 0 удалено
  1. 65 0
      v7/test/integration/chinese-path.test.js

+ 65 - 0
v7/test/integration/chinese-path.test.js

@@ -0,0 +1,65 @@
+import { test } from 'node:test'
+import assert from 'node:assert/strict'
+import { promises as fs } from 'node:fs'
+import path from 'node:path'
+import os from 'node:os'
+import { CacheManager } from '../../src/cache/index.js'
+import { ChapterReader } from '../../src/storage/adapters/ChapterReader.js'
+
+test('Windows 中文路径全链路', async (t) => {
+  if (process.platform !== 'win32') {
+    t.skip('Windows 专用测试')
+    return
+  }
+
+  const tmpDir = path.join(os.tmpdir(), '测试书仓库', `test-${Date.now()}`)
+
+  try {
+    // 构建含中文目录/文件的 fixture
+    await fs.mkdir(path.join(tmpDir, '定稿', '正文'), { recursive: true })
+    await fs.mkdir(path.join(tmpDir, '.cache'), { recursive: true })
+
+    const testChapter = `---
+章号: 1
+标题: 测试章节
+卷: 1
+字数: 100
+章定位: 推进
+---
+这是测试正文。`
+
+    await fs.writeFile(
+      path.join(tmpDir, '定稿', '正文', '0001-测试章节.md'),
+      testChapter,
+      'utf8'
+    )
+
+    await fs.writeFile(
+      path.join(tmpDir, 'book.yaml'),
+      'spec_version: "7.0"\n书名: 测试\n类型: 玄幻\n每章目标字数: 3000\n卷规模: 40',
+      'utf8'
+    )
+
+    // 重建缓存
+    const cache = new CacheManager(path.join(tmpDir, '.cache', 'index.db'))
+    await cache.ensureReady(tmpDir)
+
+    // 读取接口
+    const reader = new ChapterReader(tmpDir, cache)
+    const result = await reader.readFrontMatter(1)
+
+    assert.equal(result.ok, true, `读取失败:${result.error}`)
+    // 缓存返回英文字段名(title),源文件解析返回中文字段名(标题)
+    assert.equal(result.data.title || result.data.标题, '测试章节')
+
+    // 显式关闭数据库连接(避免 Windows 文件锁导致清理失败)
+    await cache.close()
+  } finally {
+    // 清理
+    try {
+      await fs.rm(tmpDir, { recursive: true, force: true })
+    } catch (err) {
+      // Windows 文件锁可能导致删除失败,忽略
+    }
+  }
+})