{"record":{"id":"6d98df355f48a36a","repo":"flipped-aurora/gin-vue-admin","slug":"packagetype-packageinfo-template","errorCode":null,"errorMessage":"packageType 和 packageInfo.template 必须保持一致","messagePattern":"packageType 和 packageInfo\\.template 必须保持一致","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/gva_execute.go","lineNumber":298,"sourceCode":"\n\treturn &mcp.CallToolResult{\n\t\tContent: []mcp.Content{\n\t\t\tmcp.NewTextContent(fmt.Sprintf(\"执行结果：\\n\\n%s%s\", string(responseJSON), reviewMessage)),\n\t\t},\n\t}, nil\n}\n\n// validateExecutionPlan 验证执行计划的完整性\nfunc (g *GVAExecutor) validateExecutionPlan(ctx context.Context, plan *ExecutionPlan) error {\n\tif plan.PackageName == \"\" {\n\t\treturn errors.New(\"packageName 不能为空\")\n\t}\n\tif plan.PackageType != \"package\" && plan.PackageType != \"plugin\" {\n\t\treturn errors.New(\"packageType 必须是 'package' 或 'plugin'\")\n\t}\n\n\tif plan.NeedCreatedPackage && plan.PackageInfo != nil && plan.PackageType != plan.PackageInfo.Template {\n\t\treturn errors.New(\"packageType 和 packageInfo.template 必须保持一致\")\n\t}\n\n\tif plan.NeedCreatedPackage {\n\t\tif plan.PackageInfo == nil {\n\t\t\treturn errors.New(\"当 needCreatedPackage=true 时，packageInfo 不能为空\")\n\t\t}\n\t\tif plan.PackageInfo.PackageName == \"\" {\n\t\t\treturn errors.New(\"packageInfo.packageName 不能为空\")\n\t\t}\n\t\tif plan.PackageInfo.Template != \"package\" && plan.PackageInfo.Template != \"plugin\" {\n\t\t\treturn errors.New(\"packageInfo.template 必须是 'package' 或 'plugin'\")\n\t\t}\n\t\tif plan.PackageInfo.Label == \"\" {\n\t\t\treturn errors.New(\"packageInfo.label 不能为空\")\n\t\t}\n\t\tif plan.PackageInfo.Desc == \"\" {\n\t\t\treturn errors.New(\"packageInfo.desc 不能为空\")\n\t\t}","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/gva_execute.go#L280-L316","documentation":"When the plan requests package creation (NeedCreatedPackage=true) and packageInfo is present, validateExecutionPlan requires plan.PackageType to equal plan.PackageInfo.Template. This cross-field consistency check prevents a mismatch where the top-level type says one thing and the creation template another, which would make the generator produce the wrong artifact.","triggerScenarios":"executionPlan with needCreatedPackage=true, packageInfo provided, and packageType=\"plugin\" while packageInfo.template=\"package\" (or vice versa).","commonSituations":"The plan was copied from a different tool call and only one of the two fields was updated; an LLM generated the two fields independently; a UI form let the user change packageType without syncing the nested template.","solutions":["Make packageInfo.template equal the top-level packageType (or remove the redundant field and derive one from the other).","Search the call site for where packageType and template are set and update them together.","Add a client-side consistency check before invoking the tool.","If the template should follow the type, set template: packageType when building the plan."],"exampleFix":"// before\n{ packageName: \"order-center\", packageType: \"plugin\", needCreatedPackage: true,\n  packageInfo: { packageName: \"order-center\", template: \"package\", label: \"订单中心\", desc: \"...\" } }\n\n// after\n{ packageName: \"order-center\", packageType: \"plugin\", needCreatedPackage: true,\n  packageInfo: { packageName: \"order-center\", template: \"plugin\", label: \"订单中心\", desc: \"...\" } }","handlingStrategy":"validation","validationCode":"function ensureTypeConsistency(plan) {\n  if (plan.needCreatedPackage && plan.packageInfo && plan.packageInfo.template !== plan.packageType) {\n    throw new Error(`packageType (${plan.packageType}) must equal packageInfo.template (${plan.packageInfo.template})`);\n  }\n  return plan;\n}","typeGuard":"function planTypesMatch(plan) {\n  return !plan.needCreatedPackage || plan.packageInfo == null || plan.packageInfo.template === plan.packageType;\n}","tryCatchPattern":"try {\n  return await callTool('gva_execute', { executionPlan: plan });\n} catch (err) {\n  if (String(err.message).includes('必须保持一致')) {\n    plan.packageInfo.template = plan.packageType; // sync nested template to top-level type\n    return callTool('gva_execute', { executionPlan: plan });\n  }\n  throw err;\n}","preventionTips":["Derive packageInfo.template from packageType at plan-build time instead of setting both independently","Add a lint/unit test asserting the two fields agree for every generated plan","When editing a copied plan, search for both fields and update them together"],"tags":["mcp","validation","consistency","go"],"backgroundTag":"field-mismatch-validation","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}