{"id":"bf8ba6a46952004a","repo":"vitest-dev/vitest","slug":"failed-to-update-coverage-thresholds-configuratio","errorCode":null,"errorMessage":"Failed to update coverage thresholds. Configuration file is too complex.","messagePattern":"Failed to update coverage thresholds\\. Configuration file is too complex\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/coverage.ts","lineNumber":903,"sourceCode":"    let config = resolveDefineConfig(mod)\n    if (config) {\n      return config\n    }\n\n    // \"export default mergeConfig(..., defineConfig(...))\"\n    if (mod.$type === 'function-call' && mod.$callee === 'mergeConfig') {\n      config = resolveMergeConfig(mod)\n      if (config) {\n        return config\n      }\n    }\n  }\n  catch (error) {\n    // Reduce magicast's verbose errors to readable ones\n    throw new Error(error instanceof Error ? error.message : String(error))\n  }\n\n  throw new Error(\n    'Failed to update coverage thresholds. Configuration file is too complex.',\n  )\n}\n\nfunction resolveDefineConfig(mod: any) {\n  if (mod.$type === 'function-call' && mod.$callee === 'defineConfig') {\n    // \"export default defineConfig({ test: {...} })\"\n    if (mod.$args[0].$type === 'object') {\n      return mod.$args[0]\n    }\n\n    if (mod.$args[0].$type === 'arrow-function-expression') {\n      if (mod.$args[0].$body.$type === 'object') {\n        // \"export default defineConfig(() => ({ test: {...} }))\"\n        return mod.$args[0].$body\n      }\n\n      // \"export default defineConfig(() => mergeConfig({...}, ...))\"","sourceCodeStart":885,"sourceCodeEnd":921,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/coverage.ts#L885-L921","documentation":"resolveConfig (coverage.ts:903) final fallback: vitest tried inline object, defineConfig(...), and mergeConfig(...) shapes and none matched, so it cannot safely rewrite thresholds. The config is too complex for static rewriting.","triggerScenarios":"Config uses a pattern vitest doesn't recognize — custom wrapper around defineConfig, factory functions, re-exports, or third-party compose helpers — so the AST walker can't find the thresholds node.","commonSituations":"Shared monorepo config helpers, configs that call defineConfig through indirection, configs built by plugins.","solutions":["Use the standard form: export default defineConfig({ test: { coverage: { thresholds: {...} } } }).","Disable coverage.thresholds.autoUpdate and update the numbers manually.","Inline any wrapper so the thresholds object is statically visible to magicast."],"exampleFix":"// before\nexport default wrapConfig(defineConfig({ test: { coverage: { thresholds: {...} } } }))\n\n// after\nexport default defineConfig({ test: { coverage: { thresholds: { lines: 80 } } } })","handlingStrategy":"validation","validationCode":"const mod = await parseModule(await fs.readFile(cfgPath, 'utf-8'))\nconst def = mod.exports.default\nconst ok = def?.$type === 'object'\n  || def?.$callee === 'defineConfig'\n  || def?.$callee === 'mergeConfig'\nif (!ok) throw new Error('Config shape not supported for autoUpdate')","typeGuard":"function isRecognizedConfigShape(def: any): boolean {\n  return def?.$type === 'object'\n    || (def?.$type === 'function-call' && ['defineConfig', 'mergeConfig'].includes(def.$callee))\n}","tryCatchPattern":null,"preventionTips":["Use export default defineConfig({ test: { coverage: { thresholds: {...} } } }) verbatim.","Don't wrap the config in custom factories when using autoUpdate.","Disable autoUpdate for configs that must use wrappers."],"tags":["coverage","config","thresholds","autoupdate","magicast"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}