feat: 发布 v1 智能框架 0.1.0 版本

🚀 新增功能:
- wwjcloud-nest-v1: 完整的 NestJS 智能框架
- AI 自愈机制: @wwjcloud/auto-healing 模块
- 智能代码生成: tools-v1/php-tools 迁移工具链
- AI 能力规划: v1/docs/AI-CAPABILITY-ROADMAP.md

📦 核心模块:
- libs/wwjcloud-ai: AI 策略和恢复服务
- libs/wwjcloud-boot: 启动和配置管理
- libs/wwjcloud-core: 核心基础设施
- libs/wwjcloud-addon: 插件系统

🏗️ 架构特性:
- 分层渐进式 AI 策略
- 微服务导向的模块化设计
- 与 PHP 项目 100% 业务一致性
- Docker 容器化部署支持

📋 版本信息:
- 版本: v0.1.0
- 发布日期: 2025-01-25
- 分支: v1
This commit is contained in:
wanwujie
2025-10-19 19:55:52 +08:00
parent e7a1d6b4d6
commit b5826ee469
1103 changed files with 179805 additions and 1672 deletions

View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail
# tools-v1/apps-api 开发快速启动脚本
# 用法bash tools-v1/scripts/dev-start.sh [ENV_FILE]
# 默认为 tools-v1/env/apps-api.development.example
ENV_FILE=${1:-tools-v1/env/apps-api.development.example}
if [ ! -f "$ENV_FILE" ]; then
echo "[ERROR] ENV file not found: $ENV_FILE" >&2
exit 1
fi
# shellcheck disable=SC1090
set -a
source "$ENV_FILE"
set +a
echo "[INFO] Starting apps/api with ENV: $ENV_FILE"
# 注意:在 wwjcloud-nest-v1 目录下启动 apps/api
bash -lc 'NODE_ENV=${NODE_ENV:-development} JWT_SECRET=${JWT_SECRET:-dev-secret} AI_ENABLED=${AI_ENABLED:-true} AUTH_ENABLED=${AUTH_ENABLED:-true} RBAC_ENABLED=${RBAC_ENABLED:-false} GLOBAL_PREFIX=${GLOBAL_PREFIX:-api} QUEUE_ENABLED=${QUEUE_ENABLED:-false} PORT=${PORT:-3001} npm run start -- api'

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,595 @@
/**
* 质量保证系统
* 为AI自动生成打下基石
*/
class QualityAssurance {
constructor() {
this.validators = {
syntax: this.validateSyntax.bind(this),
types: this.validateTypes.bind(this),
imports: this.validateImports.bind(this),
business: this.validateBusinessLogic.bind(this),
performance: this.validatePerformance.bind(this),
security: this.validateSecurity.bind(this)
};
this.fixers = {
syntax: this.fixSyntaxErrors.bind(this),
types: this.fixTypeErrors.bind(this),
imports: this.fixImportErrors.bind(this),
business: this.fixBusinessLogicErrors.bind(this)
};
this.metrics = {
complexity: this.calculateComplexity.bind(this),
maintainability: this.calculateMaintainability.bind(this),
testability: this.calculateTestability.bind(this),
performance: this.calculatePerformance.bind(this)
};
}
/**
* 执行完整的质量检查
*/
async performQualityCheck(code, context = {}) {
const results = {
overall: 'pass',
validations: {},
fixes: {},
metrics: {},
recommendations: [],
errors: [],
warnings: []
};
console.log('🛡️ 开始质量检查...');
// 执行所有验证
for (const [type, validator] of Object.entries(this.validators)) {
try {
console.log(` 🔍 执行${type}验证...`);
const validation = await validator(code, context);
results.validations[type] = validation;
if (validation.errors.length > 0) {
results.errors.push(...validation.errors);
results.overall = 'fail';
}
if (validation.warnings.length > 0) {
results.warnings.push(...validation.warnings);
}
console.log(`${type}验证完成: ${validation.errors.length}个错误, ${validation.warnings.length}个警告`);
} catch (error) {
console.error(`${type}验证失败:`, error.message);
results.errors.push({
type,
message: error.message,
stack: error.stack
});
results.overall = 'fail';
}
}
// 计算质量指标
for (const [type, calculator] of Object.entries(this.metrics)) {
try {
results.metrics[type] = calculator(code, context);
} catch (error) {
console.error(`${type}指标计算失败:`, error.message);
}
}
// 生成建议
results.recommendations = this.generateRecommendations(results);
console.log(`🎯 质量检查完成: ${results.overall.toUpperCase()}`);
return results;
}
/**
* 自动修复代码问题
*/
async autoFix(code, qualityResults) {
let fixedCode = code;
const fixes = [];
console.log('🔧 开始自动修复...');
// 修复语法错误
if (qualityResults.validations.syntax?.errors.length > 0) {
const syntaxFixes = await this.fixers.syntax(fixedCode, qualityResults.validations.syntax);
fixedCode = syntaxFixes.code;
fixes.push(...syntaxFixes.fixes);
}
// 修复类型错误
if (qualityResults.validations.types?.errors.length > 0) {
const typeFixes = await this.fixers.types(fixedCode, qualityResults.validations.types);
fixedCode = typeFixes.code;
fixes.push(...typeFixes.fixes);
}
// 修复导入错误
if (qualityResults.validations.imports?.errors.length > 0) {
const importFixes = await this.fixers.imports(fixedCode, qualityResults.validations.imports);
fixedCode = importFixes.code;
fixes.push(...importFixes.fixes);
}
// 修复业务逻辑错误
if (qualityResults.validations.business?.errors.length > 0) {
const businessFixes = await this.fixers.business(fixedCode, qualityResults.validations.business);
fixedCode = businessFixes.code;
fixes.push(...businessFixes.fixes);
}
console.log(`✅ 自动修复完成: ${fixes.length}个修复`);
return {
code: fixedCode,
fixes,
summary: {
totalFixes: fixes.length,
fixedTypes: [...new Set(fixes.map(f => f.type))]
}
};
}
/**
* 验证语法
*/
async validateSyntax(code, context) {
const errors = [];
const warnings = [];
// 检查方括号错误
const bracketErrors = this.findBracketErrors(code);
errors.push(...bracketErrors);
// 检查重复前缀
const prefixErrors = this.findPrefixErrors(code);
errors.push(...prefixErrors);
// 检查语法错误
const syntaxErrors = this.findSyntaxErrors(code);
errors.push(...syntaxErrors);
// 检查代码风格
const styleWarnings = this.findStyleWarnings(code);
warnings.push(...styleWarnings);
return { errors, warnings };
}
/**
* 验证类型
*/
async validateTypes(code, context) {
const errors = [];
const warnings = [];
// 检查类型声明
const typeErrors = this.findTypeErrors(code);
errors.push(...typeErrors);
// 检查类型使用
const usageWarnings = this.findTypeUsageWarnings(code);
warnings.push(...usageWarnings);
return { errors, warnings };
}
/**
* 验证导入
*/
async validateImports(code, context) {
const errors = [];
const warnings = [];
// 检查缺失的导入
const missingImports = this.findMissingImports(code);
errors.push(...missingImports);
// 检查未使用的导入
const unusedImports = this.findUnusedImports(code);
warnings.push(...unusedImports);
return { errors, warnings };
}
/**
* 验证业务逻辑
*/
async validateBusinessLogic(code, context) {
const errors = [];
const warnings = [];
// 检查业务逻辑完整性
const businessErrors = this.findBusinessLogicErrors(code);
errors.push(...businessErrors);
// 检查业务规则
const ruleWarnings = this.findBusinessRuleWarnings(code);
warnings.push(...ruleWarnings);
return { errors, warnings };
}
/**
* 验证性能
*/
async validatePerformance(code, context) {
const errors = [];
const warnings = [];
// 检查性能问题
const performanceIssues = this.findPerformanceIssues(code);
warnings.push(...performanceIssues);
return { errors, warnings };
}
/**
* 验证安全性
*/
async validateSecurity(code, context) {
const errors = [];
const warnings = [];
// 检查安全问题
const securityIssues = this.findSecurityIssues(code);
errors.push(...securityIssues);
return { errors, warnings };
}
// 错误检测方法
findBracketErrors(code) {
const errors = [];
const lines = code.split('\n');
lines.forEach((line, index) => {
if (line.includes(']') && !line.includes('[')) {
// 检查是否是函数调用中的方括号错误
if (line.match(/\w+\]/)) {
errors.push({
type: 'syntax',
message: '方括号错误: 应该是圆括号',
line: index + 1,
code: line.trim(),
severity: 'error'
});
}
}
});
return errors;
}
findPrefixErrors(code) {
const errors = [];
const lines = code.split('\n');
lines.forEach((line, index) => {
if (line.includes('BusinessBusinessException')) {
errors.push({
type: 'syntax',
message: '重复的Business前缀',
line: index + 1,
code: line.trim(),
severity: 'error'
});
}
});
return errors;
}
findSyntaxErrors(code) {
const errors = [];
const lines = code.split('\n');
lines.forEach((line, index) => {
// 检查等号错误
if (line.includes('====')) {
errors.push({
type: 'syntax',
message: '重复的等号',
line: index + 1,
code: line.trim(),
severity: 'error'
});
}
// 检查括号不匹配
const openParens = (line.match(/\(/g) || []).length;
const closeParens = (line.match(/\)/g) || []).length;
const openBrackets = (line.match(/\[/g) || []).length;
const closeBrackets = (line.match(/\]/g) || []).length;
if (openParens !== closeParens) {
errors.push({
type: 'syntax',
message: '括号不匹配',
line: index + 1,
code: line.trim(),
severity: 'error'
});
}
if (openBrackets !== closeBrackets) {
errors.push({
type: 'syntax',
message: '方括号不匹配',
line: index + 1,
code: line.trim(),
severity: 'error'
});
}
});
return errors;
}
findStyleWarnings(code) {
const warnings = [];
const lines = code.split('\n');
lines.forEach((line, index) => {
// 检查行长度
if (line.length > 120) {
warnings.push({
type: 'style',
message: '行长度超过120字符',
line: index + 1,
code: line.trim(),
severity: 'warning'
});
}
// 检查尾随空格
if (line.endsWith(' ')) {
warnings.push({
type: 'style',
message: '尾随空格',
line: index + 1,
code: line.trim(),
severity: 'warning'
});
}
});
return warnings;
}
findTypeErrors(code) {
const errors = [];
// 类型错误检测逻辑
return errors;
}
findTypeUsageWarnings(code) {
const warnings = [];
// 类型使用警告检测逻辑
return warnings;
}
findMissingImports(code) {
const errors = [];
const lines = code.split('\n');
// 检查使用的类是否已导入
const usedClasses = this.extractUsedClasses(code);
const importedClasses = this.extractImportedClasses(code);
usedClasses.forEach(className => {
if (!importedClasses.includes(className)) {
errors.push({
type: 'import',
message: `缺失导入: ${className}`,
line: -1,
code: '',
severity: 'error'
});
}
});
return errors;
}
findUnusedImports(code) {
const warnings = [];
// 未使用导入检测逻辑
return warnings;
}
findBusinessLogicErrors(code) {
const errors = [];
// 业务逻辑错误检测逻辑
return errors;
}
findBusinessRuleWarnings(code) {
const warnings = [];
// 业务规则警告检测逻辑
return warnings;
}
findPerformanceIssues(code) {
const warnings = [];
// 性能问题检测逻辑
return warnings;
}
findSecurityIssues(code) {
const errors = [];
// 安全问题检测逻辑
return errors;
}
// 修复方法
async fixSyntaxErrors(code, validation) {
let fixedCode = code;
const fixes = [];
validation.errors.forEach(error => {
if (error.message.includes('方括号错误')) {
fixedCode = fixedCode.replace(/(\w+)\]/g, '$1)');
fixes.push({
type: 'syntax',
description: '修复方括号错误',
line: error.line
});
}
if (error.message.includes('重复的Business前缀')) {
fixedCode = fixedCode.replace(/BusinessBusinessException/g, 'BusinessException');
fixes.push({
type: 'syntax',
description: '修复重复的Business前缀',
line: error.line
});
}
if (error.message.includes('重复的等号')) {
fixedCode = fixedCode.replace(/====/g, '===');
fixes.push({
type: 'syntax',
description: '修复重复的等号',
line: error.line
});
}
});
return { code: fixedCode, fixes };
}
async fixTypeErrors(code, validation) {
let fixedCode = code;
const fixes = [];
// 类型错误修复逻辑
return { code: fixedCode, fixes };
}
async fixImportErrors(code, validation) {
let fixedCode = code;
const fixes = [];
// 导入错误修复逻辑
return { code: fixedCode, fixes };
}
async fixBusinessLogicErrors(code, validation) {
let fixedCode = code;
const fixes = [];
// 业务逻辑错误修复逻辑
return { code: fixedCode, fixes };
}
// 指标计算方法
calculateComplexity(code, context) {
const lines = code.split('\n');
const methods = (code.match(/function\s+\w+/g) || []).length;
const conditions = (code.match(/if\s*\(|else\s*if\s*\(|switch\s*\(/g) || []).length;
const loops = (code.match(/for\s*\(|while\s*\(|foreach\s*\(/g) || []).length;
return {
lines: lines.length,
methods,
conditions,
loops,
cyclomatic: methods + conditions + loops + 1
};
}
calculateMaintainability(code, context) {
const complexity = this.calculateComplexity(code, context);
const maintainabilityIndex = Math.max(0, 171 - 5.2 * Math.log(complexity.lines) - 0.23 * complexity.cyclomatic);
return {
index: maintainabilityIndex,
rating: maintainabilityIndex > 80 ? 'A' : maintainabilityIndex > 60 ? 'B' : maintainabilityIndex > 40 ? 'C' : 'D'
};
}
calculateTestability(code, context) {
const methods = (code.match(/function\s+\w+/g) || []).length;
const dependencies = (code.match(/this\.\w+Service/g) || []).length;
return {
methods,
dependencies,
testabilityScore: Math.max(0, 100 - dependencies * 10)
};
}
calculatePerformance(code, context) {
const loops = (code.match(/for\s*\(|while\s*\(|foreach\s*\(/g) || []).length;
const asyncCalls = (code.match(/await\s+/g) || []).length;
return {
loops,
asyncCalls,
performanceScore: Math.max(0, 100 - loops * 5 - asyncCalls * 2)
};
}
// 辅助方法
extractUsedClasses(code) {
const classes = [];
const matches = code.match(/([A-Z][a-zA-Z0-9_]*)/g);
if (matches) {
classes.push(...matches);
}
return [...new Set(classes)];
}
extractImportedClasses(code) {
const imports = [];
const matches = code.match(/import\s*\{\s*([^}]+)\s*\}\s*from/g);
if (matches) {
matches.forEach(match => {
const importMatch = match.match(/import\s*\{\s*([^}]+)\s*\}\s*from/);
if (importMatch) {
const classNames = importMatch[1].split(',').map(name => name.trim());
imports.push(...classNames);
}
});
}
return imports;
}
generateRecommendations(results) {
const recommendations = [];
if (results.errors.length > 0) {
recommendations.push({
type: 'error',
message: '修复所有语法错误以提高代码质量',
priority: 'high'
});
}
if (results.warnings.length > 10) {
recommendations.push({
type: 'warning',
message: '减少警告数量以提高代码质量',
priority: 'medium'
});
}
if (results.metrics.complexity?.cyclomatic > 10) {
recommendations.push({
type: 'complexity',
message: '降低代码复杂度以提高可维护性',
priority: 'medium'
});
}
return recommendations;
}
}
module.exports = QualityAssurance;

View File

@@ -0,0 +1,175 @@
#!/usr/bin/env node
/**
* 测试 dict-generator 修复
* 验证文件命名和重叠名问题
*/
const DictGenerator = require('./generators/dict-generator');
class DictFixTester {
constructor() {
this.errors = [];
this.passed = [];
}
async run() {
console.log('🧪 测试 dict-generator 修复...\n');
// 测试1: 继承 BaseGenerator
this.testInheritance();
// 测试2: 文件命名规范
this.testFileNaming();
// 测试3: 避免重叠名
this.testNoOverlappingNames();
// 输出结果
this.printResults();
}
testInheritance() {
console.log('📝 测试1: 继承 BaseGenerator');
const generator = new DictGenerator();
if (typeof generator.writeFile === 'function') {
this.passed.push('DictGenerator 继承了 BaseGenerator.writeFile');
console.log(' ✅ 继承了 BaseGenerator.writeFile');
} else {
this.errors.push('DictGenerator 未继承 BaseGenerator.writeFile');
console.log(' ❌ 未继承 BaseGenerator.writeFile');
}
if (typeof generator.printStats === 'function') {
this.passed.push('DictGenerator 继承了 BaseGenerator.printStats');
console.log(' ✅ 继承了 BaseGenerator.printStats');
} else {
this.errors.push('DictGenerator 未继承 BaseGenerator.printStats');
console.log(' ❌ 未继承 BaseGenerator.printStats');
}
if (generator.dryRun !== undefined) {
this.passed.push('DictGenerator 支持 dry-run 模式');
console.log(' ✅ 支持 dry-run 模式');
} else {
this.errors.push('DictGenerator 不支持 dry-run 模式');
console.log(' ❌ 不支持 dry-run 模式');
}
}
testFileNaming() {
console.log('\n📝 测试2: 文件命名规范kebab-case');
const generator = new DictGenerator();
// 模拟生成内容并检查
const testCases = [
{ input: 'Dict', expected: 'dict.enum.ts' },
{ input: 'MemberLevel', expected: 'member-level.enum.ts' },
{ input: 'PayChannel', expected: 'pay-channel.enum.ts' },
{ input: 'dict_service', expected: 'dict-service.enum.ts' }
];
for (const testCase of testCases) {
const kebabName = generator.toKebabCase(testCase.input);
const fileName = `${kebabName}.enum.ts`;
if (fileName === testCase.expected) {
this.passed.push(`文件命名正确: ${testCase.input}${fileName}`);
console.log(`${testCase.input}${fileName}`);
} else {
this.errors.push(`文件命名错误: ${testCase.input} 应为 ${testCase.expected},实际为 ${fileName}`);
console.log(`${testCase.input} 应为 ${testCase.expected},实际为 ${fileName}`);
}
}
}
testNoOverlappingNames() {
console.log('\n📝 测试3: 避免重叠名问题');
const generator = new DictGenerator();
const content = generator.generateDictContent('test', 'Dict');
// 检查1: 应该生成 DictEnum 而不是 DictDict
if (content.includes('export enum DictEnum')) {
this.passed.push('使用 DictEnum 而不是 DictDict');
console.log(' ✅ 使用 DictEnum避免重叠名');
} else if (content.includes('export enum DictDict')) {
this.errors.push('错误使用了 DictDict重叠名');
console.log(' ❌ 错误使用了 DictDict重叠名');
} else {
this.errors.push('未找到枚举定义');
console.log(' ❌ 未找到枚举定义');
}
// 检查2: dictDict 变量名是合理的
if (content.includes('export const dictDict')) {
this.passed.push('dictDict 变量名符合预期');
console.log(' ✅ dictDict 变量名符合预期');
} else {
this.errors.push('dictDict 变量名不正确');
console.log(' ❌ dictDict 变量名不正确');
}
// 检查3: 工具类命名
if (content.includes('export class DictEnumUtil')) {
this.passed.push('工具类使用 DictEnumUtil');
console.log(' ✅ 工具类使用 DictEnumUtil');
} else {
this.errors.push('工具类命名不正确');
console.log(' ❌ 工具类命名不正确');
}
// 检查4: 文件名建议
console.log('\n 💡 推荐文件名模式:');
console.log(' - dict.enum.ts (kebab-case + .enum.ts 后缀)');
console.log(' - member-level.enum.ts');
console.log(' - pay-channel.enum.ts');
console.log('\n ❌ 禁止的文件名:');
console.log(' - DictDict.ts (PascalCase + 重叠名)');
console.log(' - Dict.ts (无后缀)');
}
printResults() {
console.log('\n\n📊 测试结果汇总');
console.log('='.repeat(60));
console.log(`\n✅ 通过项 (${this.passed.length}):`);
this.passed.forEach(item => console.log(` - ${item}`));
if (this.errors.length > 0) {
console.log(`\n❌ 错误项 (${this.errors.length}):`);
this.errors.forEach(item => console.log(` - ${item}`));
}
console.log('\n' + '='.repeat(60));
const totalChecks = this.passed.length + this.errors.length;
const successRate = totalChecks > 0
? ((this.passed.length / totalChecks) * 100).toFixed(2)
: '0.00';
console.log(`📈 成功率: ${successRate}% (${this.passed.length}/${totalChecks})`);
if (this.errors.length === 0) {
console.log('\n🎉 dict-generator 修复验证通过!');
return true;
} else {
console.log(`\n💔 发现 ${this.errors.length} 个错误,需要修复`);
return false;
}
}
}
// 运行测试
if (require.main === module) {
const tester = new DictFixTester();
tester.run().then(passed => {
process.exit(passed ? 0 : 1);
});
}
module.exports = DictFixTester;

View File

@@ -0,0 +1,319 @@
#!/usr/bin/env node
/**
* 测试修复脚本
* 验证所有修复是否正确
*/
const fs = require('fs');
const path = require('path');
class FixValidator {
constructor() {
this.errors = [];
this.warnings = [];
this.passed = [];
}
/**
* 运行所有验证
*/
async run() {
console.log('🧪 开始验证修复...\n');
// 验证1: command-generator.js 导入路径
console.log('📝 验证1: command-generator.js 导入路径修复');
this.validateCommandGeneratorImport();
// 验证2: BaseGenerator 存在性
console.log('\n📝 验证2: BaseGenerator 基类存在性');
this.validateBaseGenerator();
// 验证3: entity-generator.js 继承 BaseGenerator
console.log('\n📝 验证3: entity-generator.js 继承 BaseGenerator');
this.validateEntityGeneratorInheritance();
// 验证4: command-generator.js 继承 BaseGenerator
console.log('\n📝 验证4: command-generator.js 继承 BaseGenerator');
this.validateCommandGeneratorInheritance();
// 验证5: Quality Gate 工具存在
console.log('\n📝 验证5: Quality Gate 工具存在');
this.validateQualityGate();
// 验证6: migration-coordinator.js 集成 Quality Gate
console.log('\n📝 验证6: migration-coordinator.js 集成 Quality Gate');
this.validateCoordinatorQualityGate();
// 验证7: README.md 文档更新
console.log('\n📝 验证7: README.md 文档更新');
this.validateReadmeUpdate();
// 输出验证结果
this.printResults();
}
/**
* 验证 command-generator.js 导入路径
*/
validateCommandGeneratorImport() {
const filePath = path.join(__dirname, 'generators/command-generator.js');
const content = fs.readFileSync(filePath, 'utf8');
// 检查错误的导入
if (content.includes("@wwjCore/exceptions/Customexceptions")) {
this.errors.push('command-generator.js 仍使用错误的导入路径 @wwjCore/exceptions/Customexceptions');
console.log(' ❌ 仍使用错误的导入路径');
} else if (content.includes("@wwjCommon/exceptions/business.exception")) {
this.passed.push('command-generator.js 使用正确的导入路径');
console.log(' ✅ 使用正确的导入路径 @wwjCommon/exceptions/business.exception');
} else {
this.warnings.push('command-generator.js 未找到 BusinessException 导入');
console.log(' ⚠️ 未找到 BusinessException 导入');
}
}
/**
* 验证 BaseGenerator 存在
*/
validateBaseGenerator() {
const filePath = path.join(__dirname, 'generators/base-generator.js');
if (!fs.existsSync(filePath)) {
this.errors.push('base-generator.js 不存在');
console.log(' ❌ base-generator.js 不存在');
return;
}
const content = fs.readFileSync(filePath, 'utf8');
// 检查关键方法
const requiredMethods = ['writeFile', 'ensureDir', 'readFile', 'printStats'];
let allMethodsPresent = true;
for (const method of requiredMethods) {
if (!content.includes(`${method}(`)) {
this.errors.push(`base-generator.js 缺少方法: ${method}`);
allMethodsPresent = false;
}
}
if (allMethodsPresent) {
this.passed.push('BaseGenerator 包含所有必需方法');
console.log(' ✅ 包含所有必需方法');
} else {
console.log(' ❌ 缺少部分方法');
}
// 检查 dry-run 支持
if (content.includes('this.dryRun')) {
this.passed.push('BaseGenerator 支持 dry-run 模式');
console.log(' ✅ 支持 dry-run 模式');
} else {
this.errors.push('BaseGenerator 不支持 dry-run 模式');
console.log(' ❌ 不支持 dry-run 模式');
}
}
/**
* 验证 entity-generator.js 继承
*/
validateEntityGeneratorInheritance() {
const filePath = path.join(__dirname, 'generators/entity-generator.js');
const content = fs.readFileSync(filePath, 'utf8');
if (content.includes("extends BaseGenerator")) {
this.passed.push('entity-generator.js 继承 BaseGenerator');
console.log(' ✅ 继承 BaseGenerator');
} else {
this.errors.push('entity-generator.js 未继承 BaseGenerator');
console.log(' ❌ 未继承 BaseGenerator');
}
if (content.includes("require('./base-generator')")) {
this.passed.push('entity-generator.js 导入 BaseGenerator');
console.log(' ✅ 导入 BaseGenerator');
} else {
this.errors.push('entity-generator.js 未导入 BaseGenerator');
console.log(' ❌ 未导入 BaseGenerator');
}
if (content.includes("this.writeFile(")) {
this.passed.push('entity-generator.js 使用 BaseGenerator.writeFile');
console.log(' ✅ 使用 BaseGenerator.writeFile');
} else {
this.warnings.push('entity-generator.js 可能未使用 BaseGenerator.writeFile');
console.log(' ⚠️ 可能未使用 BaseGenerator.writeFile');
}
}
/**
* 验证 command-generator.js 继承
*/
validateCommandGeneratorInheritance() {
const filePath = path.join(__dirname, 'generators/command-generator.js');
const content = fs.readFileSync(filePath, 'utf8');
if (content.includes("extends BaseGenerator")) {
this.passed.push('command-generator.js 继承 BaseGenerator');
console.log(' ✅ 继承 BaseGenerator');
} else {
this.errors.push('command-generator.js 未继承 BaseGenerator');
console.log(' ❌ 未继承 BaseGenerator');
}
if (content.includes("this.writeFile(")) {
this.passed.push('command-generator.js 使用 BaseGenerator.writeFile');
console.log(' ✅ 使用 BaseGenerator.writeFile');
} else {
this.warnings.push('command-generator.js 可能未使用 BaseGenerator.writeFile');
console.log(' ⚠️ 可能未使用 BaseGenerator.writeFile');
}
}
/**
* 验证 Quality Gate 工具
*/
validateQualityGate() {
const filePath = path.join(__dirname, 'generators/quality-gate.js');
if (!fs.existsSync(filePath)) {
this.errors.push('quality-gate.js 不存在');
console.log(' ❌ quality-gate.js 不存在');
return;
}
const content = fs.readFileSync(filePath, 'utf8');
// 检查关键方法
const requiredMethods = ['checkTypeScript', 'checkESLint', 'run', 'printStats'];
let allMethodsPresent = true;
for (const method of requiredMethods) {
if (!content.includes(`${method}(`)) {
this.errors.push(`quality-gate.js 缺少方法: ${method}`);
allMethodsPresent = false;
}
}
if (allMethodsPresent) {
this.passed.push('Quality Gate 包含所有必需方法');
console.log(' ✅ 包含所有必需方法');
} else {
console.log(' ❌ 缺少部分方法');
}
}
/**
* 验证 migration-coordinator.js 集成
*/
validateCoordinatorQualityGate() {
const filePath = path.join(__dirname, 'migration-coordinator.js');
const content = fs.readFileSync(filePath, 'utf8');
if (content.includes("require('./generators/quality-gate')")) {
this.passed.push('migration-coordinator.js 导入 QualityGate');
console.log(' ✅ 导入 QualityGate');
} else {
this.errors.push('migration-coordinator.js 未导入 QualityGate');
console.log(' ❌ 未导入 QualityGate');
}
if (content.includes("runQualityGate")) {
this.passed.push('migration-coordinator.js 包含 runQualityGate 方法');
console.log(' ✅ 包含 runQualityGate 方法');
} else {
this.errors.push('migration-coordinator.js 未包含 runQualityGate 方法');
console.log(' ❌ 未包含 runQualityGate 方法');
}
if (content.includes("await this.runQualityGate()")) {
this.passed.push('migration-coordinator.js 调用 runQualityGate');
console.log(' ✅ 在流程中调用 runQualityGate');
} else {
this.errors.push('migration-coordinator.js 未在流程中调用 runQualityGate');
console.log(' ❌ 未在流程中调用 runQualityGate');
}
}
/**
* 验证 README.md 更新
*/
validateReadmeUpdate() {
const filePath = path.join(__dirname, 'README.md');
const content = fs.readFileSync(filePath, 'utf8');
if (content.includes('dry-run') || content.includes('DRY_RUN')) {
this.passed.push('README.md 包含 dry-run 使用说明');
console.log(' ✅ 包含 dry-run 使用说明');
} else {
this.warnings.push('README.md 缺少 dry-run 使用说明');
console.log(' ⚠️ 缺少 dry-run 使用说明');
}
if (content.includes('quality-gate') || content.includes('Quality Gate')) {
this.passed.push('README.md 包含 Quality Gate 说明');
console.log(' ✅ 包含 Quality Gate 说明');
} else {
this.warnings.push('README.md 缺少 Quality Gate 说明');
console.log(' ⚠️ 缺少 Quality Gate 说明');
}
if (content.includes('base-generator')) {
this.passed.push('README.md 包含 BaseGenerator 说明');
console.log(' ✅ 包含 BaseGenerator 说明');
} else {
this.warnings.push('README.md 缺少 BaseGenerator 说明');
console.log(' ⚠️ 缺少 BaseGenerator 说明');
}
}
/**
* 输出验证结果
*/
printResults() {
console.log('\n\n📊 验证结果汇总');
console.log('='.repeat(60));
console.log(`\n✅ 通过项 (${this.passed.length}):`);
this.passed.forEach(item => console.log(` - ${item}`));
if (this.warnings.length > 0) {
console.log(`\n⚠️ 警告项 (${this.warnings.length}):`);
this.warnings.forEach(item => console.log(` - ${item}`));
}
if (this.errors.length > 0) {
console.log(`\n❌ 错误项 (${this.errors.length}):`);
this.errors.forEach(item => console.log(` - ${item}`));
}
console.log('\n' + '='.repeat(60));
const totalChecks = this.passed.length + this.warnings.length + this.errors.length;
const successRate = totalChecks > 0
? ((this.passed.length / totalChecks) * 100).toFixed(2)
: '0.00';
console.log(`📈 成功率: ${successRate}% (${this.passed.length}/${totalChecks})`);
if (this.errors.length === 0) {
console.log('\n🎉 所有必需检查已通过!');
return true;
} else {
console.log(`\n💔 发现 ${this.errors.length} 个错误,需要修复`);
return false;
}
}
}
// 运行验证
if (require.main === module) {
const validator = new FixValidator();
validator.run().then(passed => {
process.exit(passed ? 0 : 1);
});
}
module.exports = FixValidator;

View File

@@ -0,0 +1,62 @@
#!/usr/bin/env node
const IncrementalUpdater = require('./incremental-updater');
/**
* 🧪 增量更新功能测试
*/
async function testIncrementalUpdate() {
console.log('🧪 开始测试增量更新功能...\n');
try {
// 设置测试环境
process.env.DRY_RUN = 'true';
console.log('📋 测试配置:');
console.log('- 干运行模式: 启用');
console.log('- 详细输出: 启用');
console.log('- 测试环境: 开发环境\n');
// 创建增量更新器实例
const updater = new IncrementalUpdater();
console.log('🔧 增量更新器配置:');
console.log(`- PHP项目路径: ${updater.config.phpBasePath}`);
console.log(`- NestJS项目路径: ${updater.config.nestjsBasePath}`);
console.log(`- 状态文件路径: ${updater.config.stateFilePath}`);
console.log(`- 备份路径: ${updater.config.backupPath}`);
console.log(`- 干运行模式: ${updater.config.dryRun}\n`);
// 执行增量更新
console.log('🚀 执行增量更新...');
const result = await updater.run();
if (result !== false) {
console.log('\n✅ 增量更新测试成功完成!');
console.log('📊 测试结果: 所有功能正常工作');
} else {
console.log('\n❌ 增量更新测试失败');
console.log('📊 测试结果: 存在功能问题');
}
} catch (error) {
console.error('\n💥 测试过程中发生错误:');
console.error('错误信息:', error.message);
console.error('错误堆栈:', error.stack);
console.log('\n🔧 可能的原因:');
console.log('1. PHP项目路径不存在或无法访问');
console.log('2. NestJS项目路径不存在或无法访问');
console.log('3. 文件权限不足');
console.log('4. 依赖模块缺失');
process.exit(1);
}
}
// 运行测试
if (require.main === module) {
testIncrementalUpdate();
}
module.exports = { testIncrementalUpdate };