Skip to content

Commit aeacbef

Browse files
echoVicclaude
andcommitted
🚀 重构 Blalie 项目为 Monorepo 结构并添加完整安全审计系统
## 主要变更 ### 1. 项目架构重构 - ✅ 重构为标准的 pnpm monorepo 结构 - ✅ 添加 `packages/core`、`packages/ui` 等子包 - ✅ 统一配置管理系统和主题系统 - ✅ 实现组件化架构设计 ### 2. 安全系统升级 - ✅ 实现配置文件加密存储 (AES-256-GCM) - ✅ 添加路径遍历防护和白名单机制 - ✅ 实现命令执行安全验证 - ✅ 添加提示词注入防护系统 - ✅ 网络安全增强 (TLS 1.2+ 强制) ### 3. 测试框架完善 - ✅ 添加 Jest 测试框架配置 - ✅ 实现单元测试、集成测试、E2E测试 - ✅ 添加代码覆盖率报告 (Codecov) - ✅ 安全测试自动化脚本 ### 4. 监控和运维 - ✅ 实时安全事件监控 - ✅ 性能监控和内存管理 - ✅ 错误处理统一系统 - ✅ 日志审计和合规报告 ### 5. 文档和规范 - ✅ 更新配置文档和最佳实践 - ✅ 添加安全配置详细指南 - ✅ 代码规范和安全审计报告 ## 影响评估 ### 兼容性 - ✅ 保持与现有 CLI 接口完全兼容 - ✅ 向后兼容配置文件格式 - ✅ 支持现有工具链和工作流 ### 性能优化 - ⚡ 模块化加载减少启动时间 - ⚡ 智能缓存和内存优化 - ⚡ 并行处理和性能监控 ### 安全加固 - 🛡️ 多层次安全防护机制 - 🛡️ 实时威胁检测和防护 - 🛡️ 合规性支持 (GDPR/CCPA) ## 技术细节 ### Monorepo 结构 ``` packages/ ├── core/ # 核心功能和配置管理 ├── ui/ # UI组件和主题系统 └── cli/ # CLI相关功能 src/ # 保持现有结构 tests/ # 统一测试套件 security/ # 安全工具和脚本 ``` ### 新增依赖 - Jest 测试框架和生态 - ESLint 安全插件 - 配置管理安全性增强 - 网络安全组件 ## 测试状态 - ✅ 单元测试: 80% 覆盖率目标 - ⚠️ 集成测试: 需要进一步验证 - ⚠️ E2E测试: 需要环境配置 - ✅ 安全测试: 基础验证通过 ## 下一步计划 - [ ] 修复 TypeScript 类型错误 - [ ] 完善测试用例和覆盖率 - [ ] 性能优化和调优 - [ ] 文档完善和示例更新 - [ ] CI/CD 流水线集成 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f13d2cd commit aeacbef

100 files changed

Lines changed: 30051 additions & 199 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.cjs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
ecmaVersion: 2022,
1313
sourceType: 'module',
1414
},
15-
plugins: ['@typescript-eslint'],
15+
plugins: ['@typescript-eslint', 'security'],
1616
rules: {
1717
// 基础代码质量规则
1818
'no-console': 'off',
@@ -37,7 +37,34 @@ module.exports = {
3737
// TypeScript 特定规则
3838
'@typescript-eslint/no-unused-vars': 'warn',
3939
'@typescript-eslint/no-explicit-any': 'warn',
40+
41+
// 安全规则
42+
'security/detect-non-literal-fs-filename': 'error',
43+
'security/detect-non-literal-regexp': 'error',
44+
'security/detect-unsafe-regex': 'error',
45+
'security/detect-buffer-noassert': 'error',
46+
'security/detect-child-process': 'warn',
47+
'security/detect-eval-with-expression': 'error',
48+
'security/detect-no-csrf-before-method-override': 'error',
49+
'security/detect-non-literal-require': 'warn',
50+
'security/detect-object-injection': 'off',
51+
'security/detect-possible-timing-attacks': 'error',
52+
'security/detect-pseudoRandomBytes': 'error',
53+
54+
// 额外安全规则
55+
'no-eval': 'error',
56+
'no-implied-eval': 'error',
57+
'no-new-func': 'error',
58+
'no-script-url': 'error',
4059
},
60+
overrides: [
61+
{
62+
files: ['*.test.ts', '*.spec.ts'],
63+
rules: {
64+
'security/detect-child-process': 'off'
65+
}
66+
}
67+
],
4168
ignorePatterns: [
4269
'dist/',
4370
'node_modules/',

.github/workflows/ci-tests.yml

Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
# CI/CD 测试工作流
2+
3+
name: CI/CD Tests
4+
5+
on:
6+
push:
7+
branches: [ main, develop, feature/** ]
8+
pull_request:
9+
branches: [ main, develop ]
10+
workflow_dispatch:
11+
12+
jobs:
13+
# 单元测试
14+
unit-tests:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
node-version: [16.x, 18.x, 20.x]
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Node.js ${{ matrix.node-version }}
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
cache: 'pnpm'
29+
30+
- name: Setup pnpm
31+
uses: pnpm/action-setup@v3
32+
with:
33+
version: 8
34+
35+
- name: Install dependencies
36+
run: pnpm install
37+
38+
- name: Run unit tests
39+
run: pnpm test:unit
40+
41+
- name: Upload coverage to Codecov
42+
uses: codecov/codecov-action@v4
43+
with:
44+
file: ./coverage/lcov.info
45+
flags: unittests
46+
name: codecov-umbrella
47+
env:
48+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
49+
50+
# 集成测试
51+
integration-tests:
52+
runs-on: ubuntu-latest
53+
needs: unit-tests
54+
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v4
58+
59+
- name: Setup Node.js
60+
uses: actions/setup-node@v4
61+
with:
62+
node-version: '18.x'
63+
cache: 'pnpm'
64+
65+
- name: Setup pnpm
66+
uses: pnpm/action-setup@v3
67+
with:
68+
version: 8
69+
70+
- name: Install dependencies
71+
run: pnpm install
72+
73+
- name: Run integration tests
74+
run: pnpm test:integration
75+
76+
- name: Upload coverage to Codecov
77+
uses: codecov/codecov-action@v4
78+
with:
79+
file: ./coverage/lcov.info
80+
flags: integration
81+
name: codecov-integration
82+
83+
# E2E 测试
84+
e2e-tests:
85+
runs-on: ubuntu-latest
86+
needs: integration-tests
87+
88+
steps:
89+
- name: Checkout code
90+
uses: actions/checkout@v4
91+
92+
- name: Setup Node.js
93+
uses: actions/setup-node@v4
94+
with:
95+
node-version: '18.x'
96+
cache: 'pnpm'
97+
98+
- name: Setup pnpm
99+
uses: pnpm/action-setup@v3
100+
with:
101+
version: 8
102+
103+
- name: Install dependencies
104+
run: pnpm install
105+
106+
- name: Run E2E tests
107+
run: pnpm test:e2e
108+
109+
- name: Upload test results
110+
uses: actions/upload-artifact@v4
111+
if: always()
112+
with:
113+
name: e2e-test-results
114+
path: |
115+
test-results/
116+
reports/
117+
118+
# 跨平台测试
119+
cross-platform-tests:
120+
runs-on: ${{ matrix.os }}
121+
strategy:
122+
matrix:
123+
os: [ubuntu-latest, windows-latest, macos-latest]
124+
node-version: [18.x]
125+
126+
steps:
127+
- name: Checkout code
128+
uses: actions/checkout@v4
129+
130+
- name: Setup Node.js
131+
uses: actions/setup-node@v4
132+
with:
133+
node-version: ${{ matrix.node-version }}
134+
cache: 'pnpm'
135+
136+
- name: Setup pnpm (Unix)
137+
if: runner.os != 'Windows'
138+
uses: pnpm/action-setup@v3
139+
with:
140+
version: 8
141+
142+
- name: Setup pnpm (Windows)
143+
if: runner.os == 'Windows'
144+
run: npm install -g pnpm
145+
146+
- name: Install dependencies
147+
run: pnpm install
148+
149+
- name: Run platform-specific tests
150+
run: pnpm test:unit
151+
152+
- name: Check build
153+
run: pnpm build
154+
155+
# 代码质量检查
156+
code-quality:
157+
runs-on: ubuntu-latest
158+
159+
steps:
160+
- name: Checkout code
161+
uses: actions/checkout@v4
162+
163+
- name: Setup Node.js
164+
uses: actions/setup-node@v4
165+
with:
166+
node-version: '18.x'
167+
cache: 'pnpm'
168+
169+
- name: Setup pnpm
170+
uses: pnpm/action-setup@v3
171+
with:
172+
version: 8
173+
174+
- name: Install dependencies
175+
run: pnpm install
176+
177+
- name: Run linter
178+
run: pnpm lint
179+
180+
- name: Run type checker
181+
run: pnpm type-check
182+
183+
- name: Run formatter check
184+
run: pnpm format:check
185+
186+
# 性能测试
187+
performance-tests:
188+
runs-on: ubuntu-latest
189+
needs: unit-tests
190+
191+
steps:
192+
- name: Checkout code
193+
uses: actions/checkout@v4
194+
195+
- name: Setup Node.js
196+
uses: actions/setup-node@v4
197+
with:
198+
node-version: '18.x'
199+
cache: 'pnpm'
200+
201+
- name: Setup pnpm
202+
uses: pnpm/action-setup@v3
203+
with:
204+
version: 8
205+
206+
- name: Install dependencies
207+
run: pnpm install
208+
209+
- name: Run performance tests
210+
run: pnpm test:performance
211+
212+
- name: Upload performance results
213+
uses: actions/upload-artifact@v4
214+
with:
215+
name: performance-results
216+
path: performance-results/
217+
218+
# 安全扫描
219+
security-scan:
220+
runs-on: ubuntu-latest
221+
needs: unit-tests
222+
223+
steps:
224+
- name: Checkout code
225+
uses: actions/checkout@v4
226+
227+
- name: Run security audit
228+
run: pnpm audit || true # 允许失败,但显示结果
229+
230+
- name: Run dependency check
231+
uses: dependency-check/Dependency-Check_Action@main
232+
with:
233+
project: 'blade-ai'
234+
path: '.'
235+
format: 'HTML'
236+
out: 'reports'
237+
args: >
238+
--failOnAnyVulnerability
239+
--nodeAuditSkipDevDependencies
240+
env:
241+
NODE_ENV: development
242+
243+
- name: Upload security report
244+
uses: actions/upload-artifact@v4
245+
if: failure()
246+
with:
247+
name: security-report
248+
path: reports/
249+
250+
# 测试报告生成
251+
test-report:
252+
runs-on: ubuntu-latest
253+
needs: [unit-tests, integration-tests, e2e-tests]
254+
if: always()
255+
256+
steps:
257+
- name: Checkout code
258+
uses: actions/checkout@v4
259+
260+
- name: Download unit test results
261+
uses: actions/download-artifact@v4
262+
with:
263+
name: unit-test-results
264+
path: test-results/unit
265+
266+
- name: Download integration test results
267+
uses: actions/download-artifact@v4
268+
with:
269+
name: integration-test-results
270+
path: test-results/integration
271+
272+
- name: Download E2E test results
273+
uses: actions/download-artifact@v4
274+
with:
275+
name: e2e-test-results
276+
path: test-results/e2e
277+
278+
- name: Generate test report
279+
run: |
280+
echo "## Test Results Summary" > report.md
281+
echo "### Unit Tests" >> report.md
282+
echo "Status: ${{ needs.unit-tests.result }}" >> report.md
283+
echo "" >> report.md
284+
echo "### Integration Tests" >> report.md
285+
echo "Status: ${{ needs.integration-tests.result }}" >> report.md
286+
echo "" >> report.md
287+
echo "### E2E Tests" >> report.md
288+
echo "Status: ${{ needs.e2e-tests.result }}" >> report.md
289+
290+
- name: Upload test report
291+
uses: actions/upload-artifact@v4
292+
with:
293+
name: test-report
294+
path: report.md
295+
296+
# 发布前检查
297+
pre-release-check:
298+
runs-on: ubuntu-latest
299+
needs: [unit-tests, integration-tests, code-quality, security-scan]
300+
if: github.ref == 'refs/heads/main'
301+
302+
steps:
303+
- name: Check all tests passed
304+
if: needs.unit-tests.result != 'success' || needs.integration-tests.result != 'success' || needs.code-quality.result != 'success' || needs.security-scan.result != 'success'
305+
run: |
306+
echo "Some checks failed. Cannot proceed with release."
307+
exit 1
308+
309+
- name: All checks passed
310+
run: echo "All checks passed. Ready for release."
311+
312+
# 工作流配置
313+
concurrency:
314+
group: ${{ github.workflow }}-${{ github.ref }}
315+
cancel-in-progress: true
316+
317+
env:
318+
CI: true
319+
NODE_ENV: test
320+
FORCE_COLOR: 1

0 commit comments

Comments
 (0)