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

Merge remote-tracking branch 'origin/master' into feat/gui-full-access-confirmation

ZiyaZhang пре 1 месец
родитељ
комит
b6dd855a7c

+ 4 - 5
.github/workflows/ci.yml

@@ -50,7 +50,7 @@ jobs:
       ${{ vars.DSH_CI_FAILOVER == 'selfhosted'
           && github.event.pull_request.user.login != 'dependabot[bot]'
           && fromJSON('["self-hosted", "linux", "x64", "vm-backup"]')
-          || 'dsh-enterprise-ubuntu-latest-32core-test' }}
+          || 'dsh-ubuntu-24-04-16core' }}
     name: node 24 / static
     env:
       DSH_GATE_CONCURRENCY: '8'
@@ -102,7 +102,7 @@ jobs:
       ${{ vars.DSH_CI_FAILOVER == 'selfhosted'
           && github.event.pull_request.user.login != 'dependabot[bot]'
           && fromJSON('["self-hosted", "linux", "x64", "vm-backup"]')
-          || 'dsh-enterprise-ubuntu-24-04-32core-test' }}
+          || 'dsh-ubuntu-24-04-16core' }}
     name: node 24 / coverage
     env:
       # Failover shrinks the worker bound: the hosted 32-core runner is
@@ -110,9 +110,8 @@ jobs:
       # across six always-on runner instances, and the timing-sensitive
       # process suites have documented aggregate-contention failures.
       # 8 × 6 instances = 48 workers worst case on 64 cores.
-      DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '8' }}
+      DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '6' }}
       DSH_GATE_CONCURRENCY: '3'
-      NODE_OPTIONS: '--max-old-space-size=8192'
     steps:
       - uses: actions/checkout@v6
         with:
@@ -167,7 +166,7 @@ jobs:
       ${{ vars.DSH_CI_FAILOVER == 'selfhosted'
           && github.event.pull_request.user.login != 'dependabot[bot]'
           && fromJSON('["self-hosted", "linux", "x64", "vm-backup"]')
-          || 'dsh-enterprise-ubuntu-latest-32core-test' }}
+          || 'dsh-ubuntu-24-04-16core' }}
     name: node 24 / snapshots and artifacts
     env:
       DSH_GATE_CONCURRENCY: '8'

+ 27 - 0
packages/typert/generator/src/analyzer.ts

@@ -131,6 +131,26 @@ interface FaceProgramHost {
   readonly files: Map<string, ts.SourceFile | undefined>
 }
 
+/**
+ * Process-wide parse cache for the bundled TypeScript default libraries.
+ * `typescript/lib/lib.*.d.ts` content is immutable for the process lifetime,
+ * so parses are shared across every {@link WorkspaceCaches} instance; the key
+ * carries the parse-affecting settings, keeping reuse exact.
+ */
+const defaultLibraryParses = new Map<string, ts.SourceFile | undefined>()
+
+function defaultLibraryKey(fileName: string, languageVersionOrOptions: ts.ScriptTarget | ts.CreateSourceFileOptions): string {
+  const options = typeof languageVersionOrOptions === 'object'
+    ? languageVersionOrOptions
+    : { languageVersion: languageVersionOrOptions }
+  return [
+    fileName,
+    String(options.languageVersion),
+    String(options.impliedNodeFormat ?? ''),
+    String(options.jsDocParsingMode ?? ''),
+  ].join('\0')
+}
+
 /**
  * Shared memo over one immutable workspace snapshot. Passing one instance to
  * several analyzers (the batched and write-mode children reuse their parent's
@@ -185,6 +205,13 @@ export class WorkspaceCaches {
       // only fires under oldProgram reuse, which these fresh programs never
       // request, and invalidate() is the one supported re-read path.
       host.getSourceFile = (fileName, languageVersionOrOptions, onError) => {
+        if (isStandardLibraryFile(fileName)) {
+          const key = defaultLibraryKey(fileName, languageVersionOrOptions)
+          if (!defaultLibraryParses.has(key)) {
+            defaultLibraryParses.set(key, base(fileName, languageVersionOrOptions, onError))
+          }
+          return defaultLibraryParses.get(key)
+        }
         if (!files.has(fileName)) files.set(fileName, base(fileName, languageVersionOrOptions, onError))
         return files.get(fileName)
       }

+ 2 - 1
scripts/test-invariants.spec.ts

@@ -61,7 +61,8 @@ describe('global test invariant host', () => {
       return () => {}
     })
     const fakeContext = { invariants: { register } } as unknown as Context
-    for (const [rawPath, companion] of Object.entries(testInvariantCompanions)) {
+    for (const [rawPath, load] of Object.entries(testInvariantCompanions)) {
+      const companion = await load()
       const path = rawPath.replace(/^\.\.\//, '')
       expect(companion.default, path).toBeUndefined()
       const unwrapped = loader.unwrapExports(companion) as typeof companion

+ 36 - 30
scripts/test-invariants.ts

@@ -12,8 +12,8 @@ import InvariantService from '@deepseek-ai/dsh-invariants'
 
 declare global {
   interface ImportMeta {
-    /** Eager Vite module-glob expansion used by the Vitest setup file. */
-    glob<TModule>(pattern: string, options: { eager: true }): Record<string, TModule>
+    /** Lazy Vite module-glob expansion used by the Vitest setup file. */
+    glob<TModule>(pattern: string): Record<string, () => Promise<TModule>>
   }
 }
 
@@ -25,9 +25,15 @@ export interface TestInvariantCompanion {
   apply(ctx: Context): Promise<() => void>
 }
 
-/** Every package companion, discovered eagerly so coverage observes each registration. */
-export const testInvariantCompanions: Readonly<Record<string, TestInvariantCompanion>> =
-  import.meta.glob<TestInvariantCompanion>('../packages/*/*/src/invariant.ts', { eager: true })
+/**
+ * Every package companion as a lazy loader keyed by glob path. Ordinary tests
+ * load only their owner's module; the exhaustive topology test loads and
+ * executes all of them, so aggregated coverage still observes every
+ * registration while per-file setup stops importing 168 companions and their
+ * transitive package sources.
+ */
+export const testInvariantCompanions: Readonly<Record<string, () => Promise<TestInvariantCompanion>>> =
+  import.meta.glob<TestInvariantCompanion>('../packages/*/*/src/invariant.ts')
 
 /** Manual-topology suites whose names cannot follow the focused invariant convention. */
 const MANUAL_INVARIANT_TEST_EXCEPTIONS = [
@@ -36,7 +42,6 @@ const MANUAL_INVARIANT_TEST_EXCEPTIONS = [
 ] as const
 
 interface InvariantHost {
-  readonly fibers: readonly PluginFiber[]
   readonly byCallback: ReadonlyMap<unknown, PluginFiber>
   readonly ready: Promise<void>
 }
@@ -102,39 +107,40 @@ export function testInvariantCompanionPaths(testPath: string): string[] {
 }
 
 function startInvariantHost(root: Context): InvariantHost {
-  const fibers: PluginFiber[] = []
   const byCallback = new Map<unknown, PluginFiber>()
-  const mount = (plugin: Plugin, config?: unknown): void => {
+  const mount = (plugin: Plugin, config?: unknown): PluginFiber => {
     const fiber = originalPlugin.call(root.registry, plugin, config)
     const callback = root.registry.resolve(plugin)
     if (callback === undefined) throw new Error('test invariants: companion is not a valid Cordis plugin')
-    fibers.push(fiber)
     byCallback.set(callback, fiber)
+    return fiber
   }
 
-  mount(InvariantService, { enabled: true })
+  // The service mounts synchronously so the intercepted registration that
+  // started this host immediately finds its own fiber in byCallback.
+  // Companions load and mount inside the ready chain (after the service is
+  // active, so their startup is directly joinable); every joined root plugin
+  // awaits ready, so none starts ahead of its package checks. Tests plugging
+  // a companion directly must await an earlier root plugin first — the
+  // duplicate-mount failure otherwise is loud (owner name already reserved).
+  const serviceFiber = mount(InvariantService, { enabled: true })
   const testPath = expect.getState().testPath ?? ''
   const companionPaths = testInvariantCompanionPaths(testPath)
-  for (const path of companionPaths) {
-    const companion = testInvariantCompanions[path]
-    if (companion === undefined) {
-      throw new Error(`test invariants: selected companion vanished at ${path}`)
-    }
-    if (!companion.inject.includes('invariants')) {
-      throw new Error(`test invariants: ${path} must inject the invariant service`)
-    }
-    mount(companion)
-  }
-
-  const [serviceFiber, ...companionFibers] = fibers
-  if (serviceFiber === undefined) throw new Error('test invariants: service fiber was not mounted')
-  // A companion is initially PENDING on the invariant service, and Cordis
-  // Fiber.await() only joins work already in flight. Wait for the service to
-  // activate its dependants before joining their startup and failures.
-  const ready = serviceFiber.await()
-    .then(() => Promise.all(companionFibers.map(fiber => fiber.await())))
-    .then(() => undefined)
-  const host = { fibers, byCallback, ready }
+  const ready = serviceFiber.await().then(async () => {
+    const companionFibers = await Promise.all(companionPaths.map(async (path) => {
+      const load = testInvariantCompanions[path]
+      if (load === undefined) {
+        throw new Error(`test invariants: selected companion vanished at ${path}`)
+      }
+      const companion = await load()
+      if (!companion.inject.includes('invariants')) {
+        throw new Error(`test invariants: ${path} must inject the invariant service`)
+      }
+      return mount(companion)
+    }))
+    await Promise.all(companionFibers.map(fiber => fiber.await()))
+  })
+  const host = { byCallback, ready }
   hosts.set(root, host)
   return host
 }

+ 11 - 7
vitest.config.ts

@@ -62,10 +62,12 @@ export default defineConfig({
         plugins: [pathsPlugin()],
         test: {
           name: 'thread-safe',
-          // Node 24 has aborted in its CJS lexer from a macOS arm64 worker
-          // thread. A fork contains that external runtime failure to the test
-          // process; other hosts retain the lower-overhead thread pool.
-          pool: process.platform === 'darwin' ? 'forks' : 'threads',
+          // Node 24 has aborted in its CJS lexer (v8::ToLocalChecked Empty
+          // MaybeLocal in cjs_lexer::Parse) from worker threads on macOS
+          // arm64 and later on Linux. A fork contains that external runtime
+          // failure to the test process; Windows keeps the thread pool, where
+          // the abort has not reproduced and process spawn is costlier.
+          pool: process.platform === 'win32' ? 'threads' : 'forks',
           setupFiles: ['./scripts/test-invariants.ts'],
           include: testIncludes,
           exclude: [
@@ -155,9 +157,11 @@ export default defineConfig({
         'packages/client/ui-sidebar/src/client/index.ts',
         'packages/client/ui-skill/src/client/index.ts',
         'packages/client/ui-workspace/src/client/index.ts',
-        'packages/typert/generator/src/analyzer.ts',
-        'packages/typert/generator/src/renderer.ts',
-        'packages/typert/generator/src/cordis-catalog.ts',
+        // Typert generator: correctness is pinned by its fixture suites and
+        // the byte-for-byte catalog reproduction test; per-file coverage
+        // would put whole-workspace compiler analysis under v8
+        // instrumentation — the coverage lane's longest tail.
+        'packages/typert/generator/src/*.ts',
         'packages/host/apiproxy/src/index.ts',
         'packages/host/apiproxy/src/invariant.ts',
         'packages/host/apiproxy/src/api-proxy.ts',