opencroc 0.1.6 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +317 -0
- package/README.ja.md +317 -0
- package/README.md +42 -7
- package/README.zh-CN.md +317 -0
- package/dist/cli/index.js +1936 -42
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +335 -26
- package/dist/index.js +2621 -45
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
package/README.en.md
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/banner.png" alt="OpenCroc banner" width="820" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">OpenCroc</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>AI-native E2E testing framework that reads your source code, generates tests, and self-heals failures.</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/opencroc"><img src="https://img.shields.io/npm/v/opencroc?color=green" alt="npm version" /></a>
|
|
13
|
+
<a href="https://github.com/opencroc/opencroc/actions/workflows/ci.yml"><img src="https://github.com/opencroc/opencroc/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI" /></a>
|
|
14
|
+
<a href="https://github.com/opencroc/opencroc/blob/main/LICENSE"><img src="https://img.shields.io/github/license/opencroc/opencroc" alt="MIT License" /></a>
|
|
15
|
+
<a href="https://opencroc.com"><img src="https://img.shields.io/badge/docs-opencroc.com-blue" alt="Documentation" /></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="README.en.md">English</a> | <a href="README.zh-CN.md">简体中文</a> | <a href="README.ja.md">日本語</a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## What is OpenCroc?
|
|
25
|
+
|
|
26
|
+
OpenCroc is an **AI-native end-to-end testing framework** built on top of [Playwright](https://playwright.dev). Instead of writing test scripts by hand, OpenCroc **reads your backend source code** (models, controllers, DTOs) and automatically generates complete E2E test suites, including API chains, seed data, request bodies, and assertions.
|
|
27
|
+
|
|
28
|
+
When tests fail, OpenCroc does not just report errors. It **traces the root cause** through the full request chain, **generates fix patches**, and **re-runs tests to verify the fix** autonomously.
|
|
29
|
+
|
|
30
|
+
### Key Capabilities
|
|
31
|
+
|
|
32
|
+
| Capability | Description |
|
|
33
|
+
|---|---|
|
|
34
|
+
| **Source-Aware Test Generation** | Parses Sequelize/TypeORM models, Express/NestJS controllers, and DTO decorators via [ts-morph](https://ts-morph.com) to understand your API surface |
|
|
35
|
+
| **AI-Driven Configuration** | LLM generates request body templates, seed data, parameter mappings, validated by 3-layer verification (schema -> semantic -> dry-run) |
|
|
36
|
+
| **Intelligent Chain Planning** | Builds API dependency DAGs, performs topological sorting, and plans test chains with greedy coverage optimization |
|
|
37
|
+
| **Log-Driven Completion Detection** | Goes beyond `networkidle`; verifies request completion by matching backend execution logs (`api_exec end`) |
|
|
38
|
+
| **Failure Chain Attribution** | Traces failures through the full call chain: network errors -> slow APIs -> backend logs -> root cause |
|
|
39
|
+
| **Controlled Self-Healing** | `backup -> AI patch -> dry-run -> apply -> re-run -> verify -> rollback`, with safety gates at every step |
|
|
40
|
+
| **Impact Analysis** | BFS traversal of foreign key relations to map blast radius and auto-generate Mermaid diagrams |
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
### Prerequisites
|
|
45
|
+
|
|
46
|
+
- Node.js >= 18
|
|
47
|
+
- A backend project with Express/NestJS + Sequelize/TypeORM
|
|
48
|
+
|
|
49
|
+
### Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install opencroc --save-dev
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Initialize
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx opencroc init
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This will:
|
|
62
|
+
1. Scan your project structure
|
|
63
|
+
2. Detect your ORM and framework
|
|
64
|
+
3. Create `opencroc.config.ts` with sensible defaults
|
|
65
|
+
4. Generate a sample test suite
|
|
66
|
+
|
|
67
|
+
### Generate Tests
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Generate tests for a single module
|
|
71
|
+
npx opencroc generate --module=knowledge-base
|
|
72
|
+
|
|
73
|
+
# Generate tests for all detected modules
|
|
74
|
+
npx opencroc generate --all
|
|
75
|
+
|
|
76
|
+
# Dry-run (preview without writing files)
|
|
77
|
+
npx opencroc generate --all --dry-run
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Run Tests
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Run all generated tests
|
|
84
|
+
npx opencroc test
|
|
85
|
+
|
|
86
|
+
# Run specific module
|
|
87
|
+
npx opencroc test --module=knowledge-base
|
|
88
|
+
|
|
89
|
+
# Run with self-healing enabled
|
|
90
|
+
npx opencroc test --self-heal
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Validate AI Configs
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Validate generated configurations
|
|
97
|
+
npx opencroc validate --all
|
|
98
|
+
|
|
99
|
+
# Compare AI-generated vs baseline results
|
|
100
|
+
npx opencroc compare --baseline=report-a.json --current=report-b.json
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Architecture
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
107
|
+
│ CLI / Orchestrator │
|
|
108
|
+
├──────────┬──────────┬──────────┬──────────┬─────────────────┤
|
|
109
|
+
│ Source │ Chain │ Test │ Execution│ Self-Healing │
|
|
110
|
+
│ Parser │ Planner │Generator │ Engine │ Engine │
|
|
111
|
+
│ │ │ │ │ │
|
|
112
|
+
│ ts-morph │ DAG + │ Template │Playwright│ AI Attribution │
|
|
113
|
+
│ Model │ Topo │ + AI │ + Log │ + Controlled │
|
|
114
|
+
│ Controller│ Sort + │ Config │ Driven │ Fix + Verify │
|
|
115
|
+
│ DTO │ Greedy │ Merge │ Assert │ + Rollback │
|
|
116
|
+
├──────────┴──────────┴──────────┴──────────┴─────────────────┤
|
|
117
|
+
│ Observation Bus (Network + Backend Logs) │
|
|
118
|
+
├──────────────────────────────────────────────────────────────┤
|
|
119
|
+
│ Report Engine (HTML / JSON / Markdown) │
|
|
120
|
+
└──────────────────────────────────────────────────────────────┘
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 6-Stage Pipeline
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
Source Scan -> ER Diagram -> API Analysis -> Chain Planning -> Test Generation -> Failure Analysis
|
|
127
|
+
│ │ │ │ │ │
|
|
128
|
+
ts-morph Mermaid Dependency Topological Playwright + Root Cause +
|
|
129
|
+
parsing erDiagram DAG builder + greedy AI body/seed Impact map
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## How It Works
|
|
133
|
+
|
|
134
|
+
### 1. Source Parsing
|
|
135
|
+
|
|
136
|
+
OpenCroc uses [ts-morph](https://ts-morph.com) to statically analyze your backend:
|
|
137
|
+
|
|
138
|
+
- **Models**: Extracts table names, column types, indexes, and foreign keys from Sequelize `Model.init()` / TypeORM `@Entity()`
|
|
139
|
+
- **Controllers**: Extracts routes, HTTP methods, and path parameters from Express `router.get/post/put/delete`
|
|
140
|
+
- **DTOs**: Extracts validation rules from `@IsString()`, `@IsNumber()`, `@IsOptional()` decorators
|
|
141
|
+
|
|
142
|
+
### 2. AI Configuration Generation
|
|
143
|
+
|
|
144
|
+
For each module, OpenCroc calls an LLM (OpenAI / ZhiPu / any OpenAI-compatible API) to generate:
|
|
145
|
+
|
|
146
|
+
- **Request body templates**: Field-accurate POST/PUT payloads
|
|
147
|
+
- **Seed data**: `beforeAll` setup steps with correct API sequences
|
|
148
|
+
- **Parameter mappings**: Path parameter aliases (`/:id` -> `categoryId`)
|
|
149
|
+
- **ID aliases**: Preventing ID conflicts across multi-resource chains
|
|
150
|
+
|
|
151
|
+
Each config is validated through **3 layers**:
|
|
152
|
+
1. **Schema validation**: JSON structure completeness
|
|
153
|
+
2. **Semantic validation**: Field values match source code metadata
|
|
154
|
+
3. **Dry-run validation**: TypeScript compilation check
|
|
155
|
+
|
|
156
|
+
Failed configs are automatically fixed (up to 3 rounds) before being written.
|
|
157
|
+
|
|
158
|
+
### 3. Log-Driven Completion
|
|
159
|
+
|
|
160
|
+
Instead of relying on fragile `networkidle` signals:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
Frontend Request -> Backend api_exec start log -> Backend processing -> api_exec end log
|
|
164
|
+
↓
|
|
165
|
+
OpenCroc polls end logs to confirm completion
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
This catches cases where the frontend appears idle but the backend is still processing.
|
|
169
|
+
|
|
170
|
+
### 4. Self-Healing Loop
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
Test Failure
|
|
174
|
+
-> AI Attribution (LLM + heuristic fallback)
|
|
175
|
+
-> Generate Fix Patch
|
|
176
|
+
-> Dry-Run Validation
|
|
177
|
+
-> Apply Patch (with backup)
|
|
178
|
+
-> Re-run Failed Tests
|
|
179
|
+
-> Verify Fix
|
|
180
|
+
-> Commit or Rollback
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Real-World Validation
|
|
184
|
+
|
|
185
|
+
OpenCroc has been validated against a **production-scale RBAC system** (multi-tenant enterprise permission management) with 100+ Sequelize models, 75+ Express controllers, and embedded associations:
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
$ npx tsx examples/rbac-system/smoke-test.ts
|
|
189
|
+
|
|
190
|
+
Modules : 5 (default, aigc, data-platform, integration, workflow)
|
|
191
|
+
ER Diagrams : 5
|
|
192
|
+
[default] 102 tables, 65 relations
|
|
193
|
+
[aigc] 6 tables, 0 relations
|
|
194
|
+
[data-platform] 4 tables, 0 relations
|
|
195
|
+
[integration] 14 tables, 0 relations
|
|
196
|
+
[workflow] 2 tables, 0 relations
|
|
197
|
+
Chain Plans : 5
|
|
198
|
+
[aigc] 78 chains, 150 steps
|
|
199
|
+
Generated Files: 78
|
|
200
|
+
Duration : 1153ms
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Key findings:
|
|
204
|
+
- **102 tables** and **65 foreign key relations** correctly extracted from flat model layout
|
|
205
|
+
- **Embedded associations** (`.belongsTo()` / `.hasMany()` inside model files) detected without dedicated association files
|
|
206
|
+
- **78 test files** generated across 5 modules in just over 1 second
|
|
207
|
+
- Handles both flat (`models/*.ts`) and nested (`models/module/*.ts`) directory structures
|
|
208
|
+
|
|
209
|
+
## Configuration
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
// opencroc.config.ts
|
|
213
|
+
import { defineConfig } from 'opencroc';
|
|
214
|
+
|
|
215
|
+
export default defineConfig({
|
|
216
|
+
// Backend source paths
|
|
217
|
+
backend: {
|
|
218
|
+
modelsDir: 'src/models',
|
|
219
|
+
controllersDir: 'src/controllers',
|
|
220
|
+
servicesDir: 'src/services',
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
// Target application
|
|
224
|
+
baseUrl: 'http://localhost:3000',
|
|
225
|
+
apiBaseUrl: 'http://localhost:3000/api',
|
|
226
|
+
|
|
227
|
+
// AI configuration
|
|
228
|
+
ai: {
|
|
229
|
+
provider: 'openai', // 'openai' | 'zhipu' | 'custom'
|
|
230
|
+
apiKey: process.env.AI_API_KEY,
|
|
231
|
+
model: 'gpt-4o-mini',
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
// Test execution
|
|
235
|
+
execution: {
|
|
236
|
+
workers: 4,
|
|
237
|
+
timeout: 30_000,
|
|
238
|
+
retries: 1,
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
// Log-driven completion (requires backend instrumentation)
|
|
242
|
+
logCompletion: {
|
|
243
|
+
enabled: true,
|
|
244
|
+
endpoint: '/internal/test-logs',
|
|
245
|
+
pollIntervalMs: 500,
|
|
246
|
+
timeoutMs: 10_000,
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
// Self-healing
|
|
250
|
+
selfHealing: {
|
|
251
|
+
enabled: false,
|
|
252
|
+
fixScope: 'config-only', // 'config-only' | 'config-and-source'
|
|
253
|
+
maxFixRounds: 3,
|
|
254
|
+
dryRunFirst: true,
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Supported Tech Stacks
|
|
260
|
+
|
|
261
|
+
| Layer | Supported | Planned |
|
|
262
|
+
|---|---|---|
|
|
263
|
+
| **ORM** | Sequelize, TypeORM, Prisma | Drizzle |
|
|
264
|
+
| **Framework** | Express | NestJS, Fastify, Koa |
|
|
265
|
+
| **Test Runner** | Playwright | — |
|
|
266
|
+
| **LLM** | OpenAI, ZhiPu (GLM), Ollama (local) | Anthropic |
|
|
267
|
+
| **Database** | MySQL, PostgreSQL | SQLite, MongoDB |
|
|
268
|
+
|
|
269
|
+
## Comparison
|
|
270
|
+
|
|
271
|
+
| Feature | OpenCroc | Playwright | Metersphere | auto-playwright |
|
|
272
|
+
|---|---|---|---|---|
|
|
273
|
+
| Source-aware generation | ✅ | ❌ | ❌ | ❌ |
|
|
274
|
+
| AI config generation + validation | ✅ | ❌ | ❌ | ❌ |
|
|
275
|
+
| Log-driven completion | ✅ | ❌ | ❌ | ❌ |
|
|
276
|
+
| Failure chain attribution | ✅ | ❌ | Partial | ❌ |
|
|
277
|
+
| Self-healing with rollback | ✅ | ❌ | ❌ | ❌ |
|
|
278
|
+
| API dependency DAG | ✅ | ❌ | ❌ | ❌ |
|
|
279
|
+
| Zero-config test generation | ✅ | Codegen only | Manual | NL->action |
|
|
280
|
+
| Impact blast radius analysis | ✅ | ❌ | ❌ | ❌ |
|
|
281
|
+
|
|
282
|
+
## Roadmap
|
|
283
|
+
|
|
284
|
+
- [x] 6-stage source-to-test pipeline
|
|
285
|
+
- [x] AI configuration generation with 3-layer validation
|
|
286
|
+
- [x] Controlled self-healing loop
|
|
287
|
+
- [x] Log-driven completion detection
|
|
288
|
+
- [x] Failure chain attribution + impact analysis
|
|
289
|
+
- [x] TypeORM / Prisma adapter
|
|
290
|
+
- [x] Ollama local LLM support
|
|
291
|
+
- [x] Real-world validation (102 tables, 65 relations, 78 generated tests)
|
|
292
|
+
- [x] GitHub Actions / GitLab CI integration
|
|
293
|
+
- [x] VS Code extension scaffold
|
|
294
|
+
- [x] Plugin system
|
|
295
|
+
- [x] HTML / JSON / Markdown report generation
|
|
296
|
+
- [ ] NestJS controller parser
|
|
297
|
+
- [ ] Visual dashboard (opencroc.com)
|
|
298
|
+
- [ ] Drizzle ORM adapter
|
|
299
|
+
|
|
300
|
+
## Documentation
|
|
301
|
+
|
|
302
|
+
Visit **[opencroc.com](https://opencroc.com)** for full documentation, or browse:
|
|
303
|
+
|
|
304
|
+
- [Architecture Guide](docs/architecture.md)
|
|
305
|
+
- [Configuration Reference](docs/configuration.md)
|
|
306
|
+
- [Backend Instrumentation Guide](docs/backend-instrumentation.md)
|
|
307
|
+
- [AI Provider Setup](docs/ai-providers.md)
|
|
308
|
+
- [Self-Healing Guide](docs/self-healing.md)
|
|
309
|
+
- [Troubleshooting](docs/troubleshooting.md)
|
|
310
|
+
|
|
311
|
+
## Contributing
|
|
312
|
+
|
|
313
|
+
We welcome contributions. See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
314
|
+
|
|
315
|
+
## License
|
|
316
|
+
|
|
317
|
+
[MIT](LICENSE) © 2026 OpenCroc Contributors
|
package/README.ja.md
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/banner.png" alt="OpenCroc バナー" width="820" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">OpenCroc</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>ソースコードを読み取り、テストを自動生成し、失敗を自己修復する AI ネイティブ E2E テストフレームワーク。</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/opencroc"><img src="https://img.shields.io/npm/v/opencroc?color=green" alt="npm version" /></a>
|
|
13
|
+
<a href="https://github.com/opencroc/opencroc/actions/workflows/ci.yml"><img src="https://github.com/opencroc/opencroc/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI" /></a>
|
|
14
|
+
<a href="https://github.com/opencroc/opencroc/blob/main/LICENSE"><img src="https://img.shields.io/github/license/opencroc/opencroc" alt="MIT License" /></a>
|
|
15
|
+
<a href="https://opencroc.com"><img src="https://img.shields.io/badge/docs-opencroc.com-blue" alt="Documentation" /></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="README.en.md">English</a> | <a href="README.zh-CN.md">简体中文</a> | <a href="README.ja.md">日本語</a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## OpenCroc とは
|
|
25
|
+
|
|
26
|
+
OpenCroc は [Playwright](https://playwright.dev) 上に構築された **AI ネイティブ E2E テストフレームワーク** です。手作業で大量のテストスクリプトを書く代わりに、OpenCroc は**バックエンドのソースコード**(モデル、コントローラー、DTO)を解析し、API チェーン、シードデータ、リクエストボディ、アサーションを含む E2E テストスイートを自動生成します。
|
|
27
|
+
|
|
28
|
+
テストが失敗した場合、単なるエラー出力で終わりません。リクエストチェーン全体をたどって**根本原因を特定**し、**修正パッチを生成**し、**再実行で修正を検証**します。
|
|
29
|
+
|
|
30
|
+
### 主な機能
|
|
31
|
+
|
|
32
|
+
| 機能 | 説明 |
|
|
33
|
+
|---|---|
|
|
34
|
+
| **ソースコード認識型テスト生成** | [ts-morph](https://ts-morph.com) で Sequelize/TypeORM モデル、Express/NestJS コントローラー、DTO デコレーターを解析し API 面を把握 |
|
|
35
|
+
| **AI 駆動の設定生成** | LLM がリクエストテンプレート、シードデータ、パラメータマッピングを生成し、3層検証(schema -> semantic -> dry-run)で確認 |
|
|
36
|
+
| **インテリジェントなチェーン計画** | API 依存 DAG を構築し、トポロジカルソートと貪欲最適化でテストチェーンを設計 |
|
|
37
|
+
| **ログ駆動の完了判定** | `networkidle` を超えて、バックエンド実行ログ(`api_exec end`)で完了を検証 |
|
|
38
|
+
| **失敗チェーンの原因追跡** | ネットワークエラー -> 遅延 API -> バックエンドログの順で追跡し根因特定 |
|
|
39
|
+
| **制御された自己修復** | `backup -> AI patch -> dry-run -> apply -> re-run -> verify -> rollback` を安全ゲート付きで実行 |
|
|
40
|
+
| **影響範囲分析** | 外部キー関係を BFS でたどり、影響範囲を可視化し Mermaid 図を生成 |
|
|
41
|
+
|
|
42
|
+
## クイックスタート
|
|
43
|
+
|
|
44
|
+
### 前提条件
|
|
45
|
+
|
|
46
|
+
- Node.js >= 18
|
|
47
|
+
- Express/NestJS + Sequelize/TypeORM を利用するバックエンドプロジェクト
|
|
48
|
+
|
|
49
|
+
### インストール
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install opencroc --save-dev
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 初期化
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx opencroc init
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
このコマンドで以下を実行します:
|
|
62
|
+
1. プロジェクト構成をスキャン
|
|
63
|
+
2. ORM とフレームワークを検出
|
|
64
|
+
3. `opencroc.config.ts` を初期生成
|
|
65
|
+
4. サンプルテストを生成
|
|
66
|
+
|
|
67
|
+
### テスト生成
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# 単一モジュールのテスト生成
|
|
71
|
+
npx opencroc generate --module=knowledge-base
|
|
72
|
+
|
|
73
|
+
# 全モジュールのテスト生成
|
|
74
|
+
npx opencroc generate --all
|
|
75
|
+
|
|
76
|
+
# ドライラン(ファイルを書き込まない)
|
|
77
|
+
npx opencroc generate --all --dry-run
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### テスト実行
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# 生成済みテストをすべて実行
|
|
84
|
+
npx opencroc test
|
|
85
|
+
|
|
86
|
+
# 特定モジュールのみ実行
|
|
87
|
+
npx opencroc test --module=knowledge-base
|
|
88
|
+
|
|
89
|
+
# 自己修復モードで実行
|
|
90
|
+
npx opencroc test --self-heal
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### AI 設定の検証
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# 生成設定を検証
|
|
97
|
+
npx opencroc validate --all
|
|
98
|
+
|
|
99
|
+
# AI 生成結果とベースラインを比較
|
|
100
|
+
npx opencroc compare --baseline=report-a.json --current=report-b.json
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## アーキテクチャ
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
107
|
+
│ CLI / Orchestrator │
|
|
108
|
+
├──────────┬──────────┬──────────┬──────────┬─────────────────┤
|
|
109
|
+
│ Source │ Chain │ Test │ Execution│ Self-Healing │
|
|
110
|
+
│ Parser │ Planner │Generator │ Engine │ Engine │
|
|
111
|
+
│ │ │ │ │ │
|
|
112
|
+
│ ts-morph │ DAG + │ Template │Playwright│ AI Attribution │
|
|
113
|
+
│ Model │ Topo │ + AI │ + Log │ + Controlled │
|
|
114
|
+
│ Controller│ Sort + │ Config │ Driven │ Fix + Verify │
|
|
115
|
+
│ DTO │ Greedy │ Merge │ Assert │ + Rollback │
|
|
116
|
+
├──────────┴──────────┴──────────┴──────────┴─────────────────┤
|
|
117
|
+
│ Observation Bus (Network + Backend Logs) │
|
|
118
|
+
├──────────────────────────────────────────────────────────────┤
|
|
119
|
+
│ Report Engine (HTML / JSON / Markdown) │
|
|
120
|
+
└──────────────────────────────────────────────────────────────┘
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 6 段階パイプライン
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
Source Scan -> ER Diagram -> API Analysis -> Chain Planning -> Test Generation -> Failure Analysis
|
|
127
|
+
│ │ │ │ │ │
|
|
128
|
+
ts-morph Mermaid Dependency Topological Playwright + Root Cause +
|
|
129
|
+
parsing erDiagram DAG builder + greedy AI body/seed Impact map
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## 仕組み
|
|
133
|
+
|
|
134
|
+
### 1. ソース解析
|
|
135
|
+
|
|
136
|
+
OpenCroc は [ts-morph](https://ts-morph.com) を使ってバックエンドを静的解析します。
|
|
137
|
+
|
|
138
|
+
- **Models**: Sequelize `Model.init()` / TypeORM `@Entity()` からテーブル名、列型、インデックス、外部キーを抽出
|
|
139
|
+
- **Controllers**: Express `router.get/post/put/delete` からルート、HTTP メソッド、パスパラメータを抽出
|
|
140
|
+
- **DTOs**: `@IsString()`、`@IsNumber()`、`@IsOptional()` からバリデーションルールを抽出
|
|
141
|
+
|
|
142
|
+
### 2. AI 設定生成
|
|
143
|
+
|
|
144
|
+
各モジュールごとに、OpenCroc は LLM(OpenAI / ZhiPu / OpenAI 互換 API)を呼び出して以下を生成します。
|
|
145
|
+
|
|
146
|
+
- **リクエストボディテンプレート**: フィールド精度の高い POST/PUT ペイロード
|
|
147
|
+
- **シードデータ**: 正しい API 順序を持つ `beforeAll` セットアップ
|
|
148
|
+
- **パラメータマッピング**: パスパラメータ別名(`/:id` -> `categoryId`)
|
|
149
|
+
- **ID エイリアス**: 複数リソースチェーンでの ID 衝突防止
|
|
150
|
+
|
|
151
|
+
各設定は **3 層検証** を通過します。
|
|
152
|
+
1. **Schema 検証**: JSON 構造の完全性
|
|
153
|
+
2. **Semantic 検証**: フィールド値がソースメタデータに一致するか
|
|
154
|
+
3. **Dry-run 検証**: TypeScript コンパイル確認
|
|
155
|
+
|
|
156
|
+
失敗した設定は書き込み前に自動修正(最大 3 ラウンド)されます。
|
|
157
|
+
|
|
158
|
+
### 3. ログ駆動の完了判定
|
|
159
|
+
|
|
160
|
+
壊れやすい `networkidle` に依存せず、以下で判定します。
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
Frontend Request -> Backend api_exec start log -> Backend processing -> api_exec end log
|
|
164
|
+
↓
|
|
165
|
+
OpenCroc polls end logs to confirm completion
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
フロントが待機状態でもバックエンドが継続処理中のケースを検出できます。
|
|
169
|
+
|
|
170
|
+
### 4. 自己修復ループ
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
Test Failure
|
|
174
|
+
-> AI Attribution (LLM + heuristic fallback)
|
|
175
|
+
-> Generate Fix Patch
|
|
176
|
+
-> Dry-Run Validation
|
|
177
|
+
-> Apply Patch (with backup)
|
|
178
|
+
-> Re-run Failed Tests
|
|
179
|
+
-> Verify Fix
|
|
180
|
+
-> Commit or Rollback
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## 実プロジェクト検証
|
|
184
|
+
|
|
185
|
+
OpenCroc は**本番規模の RBAC システム**(マルチテナント企業権限管理)で検証済みです。100+ の Sequelize モデル、75+ の Express コントローラー、モデルファイル内埋め込みアソシエーションを含みます:
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
$ npx tsx examples/rbac-system/smoke-test.ts
|
|
189
|
+
|
|
190
|
+
Modules : 5 (default, aigc, data-platform, integration, workflow)
|
|
191
|
+
ER Diagrams : 5
|
|
192
|
+
[default] 102 tables, 65 relations
|
|
193
|
+
[aigc] 6 tables, 0 relations
|
|
194
|
+
[data-platform] 4 tables, 0 relations
|
|
195
|
+
[integration] 14 tables, 0 relations
|
|
196
|
+
[workflow] 2 tables, 0 relations
|
|
197
|
+
Chain Plans : 5
|
|
198
|
+
[aigc] 78 chains, 150 steps
|
|
199
|
+
Generated Files: 78
|
|
200
|
+
Duration : 1153ms
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
主な結果:
|
|
204
|
+
- フラットモデルレイアウトから **102 テーブル** と **65 の外部キー関係** を正確に抽出
|
|
205
|
+
- 専用の association ファイル不要 — モデルファイル内の**埋め込みアソシエーション**(`.belongsTo()` / `.hasMany()`)を検出
|
|
206
|
+
- 5 モジュールで **78 テストファイル** を約1秒で生成
|
|
207
|
+
- フラット(`models/*.ts`)とネスト(`models/module/*.ts`)の両ディレクトリ構造に対応
|
|
208
|
+
|
|
209
|
+
## 設定例
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
// opencroc.config.ts
|
|
213
|
+
import { defineConfig } from 'opencroc';
|
|
214
|
+
|
|
215
|
+
export default defineConfig({
|
|
216
|
+
// バックエンドソースのパス
|
|
217
|
+
backend: {
|
|
218
|
+
modelsDir: 'src/models',
|
|
219
|
+
controllersDir: 'src/controllers',
|
|
220
|
+
servicesDir: 'src/services',
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
// 対象アプリケーション
|
|
224
|
+
baseUrl: 'http://localhost:3000',
|
|
225
|
+
apiBaseUrl: 'http://localhost:3000/api',
|
|
226
|
+
|
|
227
|
+
// AI 設定
|
|
228
|
+
ai: {
|
|
229
|
+
provider: 'openai', // 'openai' | 'zhipu' | 'custom'
|
|
230
|
+
apiKey: process.env.AI_API_KEY,
|
|
231
|
+
model: 'gpt-4o-mini',
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
// テスト実行
|
|
235
|
+
execution: {
|
|
236
|
+
workers: 4,
|
|
237
|
+
timeout: 30_000,
|
|
238
|
+
retries: 1,
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
// ログ駆動完了判定(バックエンド側の計測が必要)
|
|
242
|
+
logCompletion: {
|
|
243
|
+
enabled: true,
|
|
244
|
+
endpoint: '/internal/test-logs',
|
|
245
|
+
pollIntervalMs: 500,
|
|
246
|
+
timeoutMs: 10_000,
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
// 自己修復
|
|
250
|
+
selfHealing: {
|
|
251
|
+
enabled: false,
|
|
252
|
+
fixScope: 'config-only', // 'config-only' | 'config-and-source'
|
|
253
|
+
maxFixRounds: 3,
|
|
254
|
+
dryRunFirst: true,
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## 対応技術スタック
|
|
260
|
+
|
|
261
|
+
| レイヤー | 対応済み | 予定 |
|
|
262
|
+
|---|---|---|
|
|
263
|
+
| **ORM** | Sequelize, TypeORM, Prisma | Drizzle |
|
|
264
|
+
| **Framework** | Express | NestJS, Fastify, Koa |
|
|
265
|
+
| **Test Runner** | Playwright | — |
|
|
266
|
+
| **LLM** | OpenAI, ZhiPu (GLM), Ollama (local) | Anthropic |
|
|
267
|
+
| **Database** | MySQL, PostgreSQL | SQLite, MongoDB |
|
|
268
|
+
|
|
269
|
+
## 比較
|
|
270
|
+
|
|
271
|
+
| 機能 | OpenCroc | Playwright | Metersphere | auto-playwright |
|
|
272
|
+
|---|---|---|---|---|
|
|
273
|
+
| ソース認識生成 | ✅ | ❌ | ❌ | ❌ |
|
|
274
|
+
| AI 設定生成 + 検証 | ✅ | ❌ | ❌ | ❌ |
|
|
275
|
+
| ログ駆動完了判定 | ✅ | ❌ | ❌ | ❌ |
|
|
276
|
+
| 失敗チェーン帰属分析 | ✅ | ❌ | Partial | ❌ |
|
|
277
|
+
| 自己修復 + ロールバック | ✅ | ❌ | ❌ | ❌ |
|
|
278
|
+
| API 依存 DAG | ✅ | ❌ | ❌ | ❌ |
|
|
279
|
+
| ゼロ設定テスト生成 | ✅ | Codegen only | Manual | NL->action |
|
|
280
|
+
| 影響範囲分析 | ✅ | ❌ | ❌ | ❌ |
|
|
281
|
+
|
|
282
|
+
## Roadmap
|
|
283
|
+
|
|
284
|
+
- [x] 6-stage source-to-test pipeline
|
|
285
|
+
- [x] AI configuration generation with 3-layer validation
|
|
286
|
+
- [x] Controlled self-healing loop
|
|
287
|
+
- [x] Log-driven completion detection
|
|
288
|
+
- [x] Failure chain attribution + impact analysis
|
|
289
|
+
- [x] TypeORM / Prisma adapter
|
|
290
|
+
- [x] Ollama local LLM support
|
|
291
|
+
- [x] Real-world validation (102 tables, 65 relations, 78 generated tests)
|
|
292
|
+
- [x] GitHub Actions / GitLab CI integration
|
|
293
|
+
- [x] VS Code extension scaffold
|
|
294
|
+
- [x] Plugin system
|
|
295
|
+
- [x] HTML / JSON / Markdown report generation
|
|
296
|
+
- [ ] NestJS controller parser
|
|
297
|
+
- [ ] Visual dashboard (opencroc.com)
|
|
298
|
+
- [ ] Drizzle ORM adapter
|
|
299
|
+
|
|
300
|
+
## ドキュメント
|
|
301
|
+
|
|
302
|
+
詳細は **[opencroc.com](https://opencroc.com)** を参照してください。あわせて以下も確認できます。
|
|
303
|
+
|
|
304
|
+
- [Architecture Guide](docs/architecture.md)
|
|
305
|
+
- [Configuration Reference](docs/configuration.md)
|
|
306
|
+
- [Backend Instrumentation Guide](docs/backend-instrumentation.md)
|
|
307
|
+
- [AI Provider Setup](docs/ai-providers.md)
|
|
308
|
+
- [Self-Healing Guide](docs/self-healing.md)
|
|
309
|
+
- [Troubleshooting](docs/troubleshooting.md)
|
|
310
|
+
|
|
311
|
+
## コントリビュート
|
|
312
|
+
|
|
313
|
+
貢献を歓迎します。ガイドラインは [CONTRIBUTING.md](CONTRIBUTING.md) を参照してください。
|
|
314
|
+
|
|
315
|
+
## ライセンス
|
|
316
|
+
|
|
317
|
+
[MIT](LICENSE) © 2026 OpenCroc Contributors
|