Parcourir la source

test(v7): gitBookCtx 对齐真实建书形态——.gitignore/quotepath/工作区不入跟踪(G-1)

lingfengQAQ il y a 2 jours
Parent
commit
e4e4018472
2 fichiers modifiés avec 27 ajouts et 0 suppressions
  1. 4 0
      v7/test/commands/_helper.js
  2. 23 0
      v7/test/finalize/finalize.test.js

+ 4 - 0
v7/test/commands/_helper.js

@@ -73,11 +73,15 @@ export async function tempBookCtx() {
 
 /**
  * 同 tempBookCtx,但额外 git init + 首提交(定稿/git 流程测试用)。
+ * 仓库形态对齐真实建书 persistCreateBook:.gitignore(.cache/、工作区/)+
+ * core.quotepath false + 工作区不入跟踪(G-1:脚手架失真会掩盖 goto/finalize 的真实行为)。
  */
 export async function gitBookCtx() {
   const { ctx, cleanup } = await tempBookCtx()
+  await writeFile(path.join(ctx.repoPath, '.gitignore'), '.cache/\n工作区/\n', 'utf8')
   const git = (args) => execFileAsync('git', args, { cwd: ctx.repoPath })
   await git(['init', '-q'])
+  await git(['config', 'core.quotepath', 'false'])
   await git(['config', 'user.email', 't@example.com'])
   await git(['config', 'user.name', 'test'])
   await git(['add', '-A'])

+ 23 - 0
v7/test/finalize/finalize.test.js

@@ -245,3 +245,26 @@ test('finalizeChapter threadCreates 断电回滚:新条目文件不残留', as
     await cleanup()
   }
 })
+
+test('gitBookCtx 仓库形态对齐真实建书:工作区不入跟踪、quotepath 关闭', async () => {
+  const { ctx, cleanup } = await gitBookCtx()
+  try {
+    const { stdout: tracked } = await execFileAsync('git', ['ls-files'], {
+      cwd: ctx.repoPath,
+      encoding: 'utf8',
+    })
+    assert.equal(
+      tracked.split('\n').some((f) => f.startsWith('工作区')),
+      false,
+      `工作区被跟踪:${tracked}`
+    )
+    const { stdout: qp } = await execFileAsync('git', ['config', 'core.quotepath'], {
+      cwd: ctx.repoPath,
+      encoding: 'utf8',
+    })
+    assert.equal(qp.trim(), 'false')
+    await fs.access(path.join(ctx.repoPath, '.gitignore'))
+  } finally {
+    await cleanup()
+  }
+})