Преглед изворни кода

Merge pull request #149 from lingfengQAQ/codex/ci-portability

fix(test): normalize temporary paths across CI platforms
聆风 пре 3 недеља
родитељ
комит
2da1fc2276

+ 2 - 1
packages/bundle/tests/core-logic.spec.ts

@@ -82,7 +82,8 @@ describe('paths 当前书路径解析', () => {
   })
 
   it('绝对路径:直接放行由门禁再判', () => {
-    const r = resolveToBookPath(rootOf, 'D:/repo/书仓/甲/大纲/骨架.md')
+    const absolute = process.platform === 'win32' ? 'D:/repo/书仓/甲/大纲/骨架.md' : '/repo/书仓/甲/大纲/骨架.md'
+    const r = resolveToBookPath(rootOf, absolute)
     expect(r.ok).toBe(true)
     if (r.ok) expect(r.path).toContain('大纲/骨架.md')
   })

+ 5 - 1
packages/core/tests/canonical-path.spec.ts

@@ -39,7 +39,11 @@ describe('canonicalizePath', () => {
   })
 
   it('stripDevicePrefix:剥 \\\\?\\ 与 \\\\?\\UNC\\ 前缀', () => {
-    if (!IS_WIN) expect(stripDevicePrefix('/a/b')).toBe('/a/b')
+    if (!IS_WIN) {
+      expect(stripDevicePrefix('/a/b')).toBe('/a/b')
+      expect(stripDevicePrefix('\\\\?\\C:\\a\\b')).toBe('\\\\?\\C:\\a\\b')
+      return
+    }
     expect(stripDevicePrefix('\\\\?\\C:\\a\\b')).toBe('C:\\a\\b')
     expect(stripDevicePrefix('\\\\?\\UNC\\srv\\share\\a')).toBe('\\\\srv\\share\\a')
     expect(stripDevicePrefix('C:\\a\\b')).toBe('C:\\a\\b')

+ 4 - 2
packages/core/tests/index-sync.spec.ts

@@ -196,9 +196,11 @@ describe('程序维护的向量索引', () => {
     const script = `import { register } from 'node:module'; register(${JSON.stringify(loader)});
       const { syncFinalizedIndex } = await import(${JSON.stringify(module)});
       let calls = 0;
-      const embed = async () => { if (++calls > 1) return new Promise(() => { setInterval(() => {}, 1000) }); return [[1,0]] };
+      // Announce from inside the hanging second request: batch one is committed and no book
+      // lock or acquire guard is held, so killing here orphans only the worker lease.
+      const embed = async () => { if (++calls > 1) { process.stdout.write('CHECKPOINT\\n'); return new Promise(() => { setInterval(() => {}, 1000) }) } return [[1,0]] };
       const provider = { metadata: { provider:'fixture', model:'fixture', dimensions:2, revision:'v1', batchSize:1 }, embed, embedBatch:embed };
-      await syncFinalizedIndex(${JSON.stringify(root)}, { getProvider: () => provider, onProgress: state => { if (state.completedChunks === 1) process.stdout.write('CHECKPOINT\\n') } });`
+      await syncFinalizedIndex(${JSON.stringify(root)}, { getProvider: () => provider });`
     const child = spawn(process.execPath, ['--experimental-transform-types', '--input-type=module', '-e', script], { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] })
     const exited = new Promise<void>(resolve => child.once('exit', () => resolve()))
     try {

+ 1 - 0
packages/core/tests/reliability-fix1.spec.ts

@@ -137,6 +137,7 @@ describe('F7:提交失败后的可重试恢复', () => {
     fs.mkdirSync(hooksDir, { recursive: true })
     // sh 脚本:直接 exit 1(Windows Git for Windows 自带 sh 执行 hook)
     fs.writeFileSync(nodePath.join(hooksDir, 'pre-commit'), '#!/bin/sh\nexit 1\n', 'utf-8')
+    fs.chmodSync(nodePath.join(hooksDir, 'pre-commit'), 0o755)
   }
   function removeHook(root: string): void {
     fs.rmSync(nodePath.join(root, '.git', 'hooks', 'pre-commit'), { force: true })

+ 11 - 1
vitest.config.ts

@@ -1,10 +1,20 @@
 import { defineConfig } from 'vitest/config';
+import { realpathSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+
+// Windows runners expose an 8.3 TEMP alias; fixtures and fault-injection mocks
+// must use the same canonical path that the filesystem returns to production.
+const testTemp = realpathSync.native(tmpdir());
 
 export default defineConfig({
   test: {
     include: ['packages/*/tests/**/*.spec.ts', 'packages/*/src/**/*.spec.ts'],
     environment: 'node',
     // Many integration files spawn Git/Node processes; bound contention on CI.
-    maxWorkers: 4,
+    maxWorkers: process.env['CI'] ? 2 : 4,
+    testTimeout: 15_000,
+    // afterAll fixture removal retries on slow Windows runners can exceed the 10s default.
+    hookTimeout: 60_000,
+    env: { TEMP: testTemp, TMP: testTemp, TMPDIR: testTemp },
   },
 });