opencroc 0.1.6 → 0.1.7

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 ADDED
@@ -0,0 +1,286 @@
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/blob/main/LICENSE"><img src="https://img.shields.io/github/license/opencroc/opencroc" alt="MIT License" /></a>
14
+ <a href="https://opencroc.com"><img src="https://img.shields.io/badge/docs-opencroc.com-blue" alt="Documentation" /></a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="README.en.md">English</a> | <a href="README.zh-CN.md">简体中文</a> | <a href="README.ja.md">日本語</a>
19
+ </p>
20
+
21
+ ---
22
+
23
+ ## What is OpenCroc?
24
+
25
+ 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.
26
+
27
+ 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.
28
+
29
+ ### Key Capabilities
30
+
31
+ | Capability | Description |
32
+ |---|---|
33
+ | **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 |
34
+ | **AI-Driven Configuration** | LLM generates request body templates, seed data, parameter mappings, validated by 3-layer verification (schema -> semantic -> dry-run) |
35
+ | **Intelligent Chain Planning** | Builds API dependency DAGs, performs topological sorting, and plans test chains with greedy coverage optimization |
36
+ | **Log-Driven Completion Detection** | Goes beyond `networkidle`; verifies request completion by matching backend execution logs (`api_exec end`) |
37
+ | **Failure Chain Attribution** | Traces failures through the full call chain: network errors -> slow APIs -> backend logs -> root cause |
38
+ | **Controlled Self-Healing** | `backup -> AI patch -> dry-run -> apply -> re-run -> verify -> rollback`, with safety gates at every step |
39
+ | **Impact Analysis** | BFS traversal of foreign key relations to map blast radius and auto-generate Mermaid diagrams |
40
+
41
+ ## Quick Start
42
+
43
+ ### Prerequisites
44
+
45
+ - Node.js >= 18
46
+ - A backend project with Express/NestJS + Sequelize/TypeORM
47
+
48
+ ### Installation
49
+
50
+ ```bash
51
+ npm install opencroc --save-dev
52
+ ```
53
+
54
+ ### Initialize
55
+
56
+ ```bash
57
+ npx opencroc init
58
+ ```
59
+
60
+ This will:
61
+ 1. Scan your project structure
62
+ 2. Detect your ORM and framework
63
+ 3. Create `opencroc.config.ts` with sensible defaults
64
+ 4. Generate a sample test suite
65
+
66
+ ### Generate Tests
67
+
68
+ ```bash
69
+ # Generate tests for a single module
70
+ npx opencroc generate --module=knowledge-base
71
+
72
+ # Generate tests for all detected modules
73
+ npx opencroc generate --all
74
+
75
+ # Dry-run (preview without writing files)
76
+ npx opencroc generate --all --dry-run
77
+ ```
78
+
79
+ ### Run Tests
80
+
81
+ ```bash
82
+ # Run all generated tests
83
+ npx opencroc test
84
+
85
+ # Run specific module
86
+ npx opencroc test --module=knowledge-base
87
+
88
+ # Run with self-healing enabled
89
+ npx opencroc test --self-heal
90
+ ```
91
+
92
+ ### Validate AI Configs
93
+
94
+ ```bash
95
+ # Validate generated configurations
96
+ npx opencroc validate --all
97
+
98
+ # Compare AI-generated vs baseline results
99
+ npx opencroc compare --baseline=report-a.json --current=report-b.json
100
+ ```
101
+
102
+ ## Architecture
103
+
104
+ ```
105
+ ┌─────────────────────────────────────────────────────────────┐
106
+ │ CLI / Orchestrator │
107
+ ├──────────┬──────────┬──────────┬──────────┬─────────────────┤
108
+ │ Source │ Chain │ Test │ Execution│ Self-Healing │
109
+ │ Parser │ Planner │Generator │ Engine │ Engine │
110
+ │ │ │ │ │ │
111
+ │ ts-morph │ DAG + │ Template │Playwright│ AI Attribution │
112
+ │ Model │ Topo │ + AI │ + Log │ + Controlled │
113
+ │ Controller│ Sort + │ Config │ Driven │ Fix + Verify │
114
+ │ DTO │ Greedy │ Merge │ Assert │ + Rollback │
115
+ ├──────────┴──────────┴──────────┴──────────┴─────────────────┤
116
+ │ Observation Bus (Network + Backend Logs) │
117
+ ├──────────────────────────────────────────────────────────────┤
118
+ │ Report Engine (HTML / JSON / Markdown) │
119
+ └──────────────────────────────────────────────────────────────┘
120
+ ```
121
+
122
+ ### 6-Stage Pipeline
123
+
124
+ ```
125
+ Source Scan -> ER Diagram -> API Analysis -> Chain Planning -> Test Generation -> Failure Analysis
126
+ │ │ │ │ │ │
127
+ ts-morph Mermaid Dependency Topological Playwright + Root Cause +
128
+ parsing erDiagram DAG builder + greedy AI body/seed Impact map
129
+ ```
130
+
131
+ ## How It Works
132
+
133
+ ### 1. Source Parsing
134
+
135
+ OpenCroc uses [ts-morph](https://ts-morph.com) to statically analyze your backend:
136
+
137
+ - **Models**: Extracts table names, column types, indexes, and foreign keys from Sequelize `Model.init()` / TypeORM `@Entity()`
138
+ - **Controllers**: Extracts routes, HTTP methods, and path parameters from Express `router.get/post/put/delete`
139
+ - **DTOs**: Extracts validation rules from `@IsString()`, `@IsNumber()`, `@IsOptional()` decorators
140
+
141
+ ### 2. AI Configuration Generation
142
+
143
+ For each module, OpenCroc calls an LLM (OpenAI / ZhiPu / any OpenAI-compatible API) to generate:
144
+
145
+ - **Request body templates**: Field-accurate POST/PUT payloads
146
+ - **Seed data**: `beforeAll` setup steps with correct API sequences
147
+ - **Parameter mappings**: Path parameter aliases (`/:id` -> `categoryId`)
148
+ - **ID aliases**: Preventing ID conflicts across multi-resource chains
149
+
150
+ Each config is validated through **3 layers**:
151
+ 1. **Schema validation**: JSON structure completeness
152
+ 2. **Semantic validation**: Field values match source code metadata
153
+ 3. **Dry-run validation**: TypeScript compilation check
154
+
155
+ Failed configs are automatically fixed (up to 3 rounds) before being written.
156
+
157
+ ### 3. Log-Driven Completion
158
+
159
+ Instead of relying on fragile `networkidle` signals:
160
+
161
+ ```
162
+ Frontend Request -> Backend api_exec start log -> Backend processing -> api_exec end log
163
+
164
+ OpenCroc polls end logs to confirm completion
165
+ ```
166
+
167
+ This catches cases where the frontend appears idle but the backend is still processing.
168
+
169
+ ### 4. Self-Healing Loop
170
+
171
+ ```
172
+ Test Failure
173
+ -> AI Attribution (LLM + heuristic fallback)
174
+ -> Generate Fix Patch
175
+ -> Dry-Run Validation
176
+ -> Apply Patch (with backup)
177
+ -> Re-run Failed Tests
178
+ -> Verify Fix
179
+ -> Commit or Rollback
180
+ ```
181
+
182
+ ## Configuration
183
+
184
+ ```typescript
185
+ // opencroc.config.ts
186
+ import { defineConfig } from 'opencroc';
187
+
188
+ export default defineConfig({
189
+ // Backend source paths
190
+ backend: {
191
+ modelsDir: 'src/models',
192
+ controllersDir: 'src/controllers',
193
+ servicesDir: 'src/services',
194
+ },
195
+
196
+ // Target application
197
+ baseUrl: 'http://localhost:3000',
198
+ apiBaseUrl: 'http://localhost:3000/api',
199
+
200
+ // AI configuration
201
+ ai: {
202
+ provider: 'openai', // 'openai' | 'zhipu' | 'custom'
203
+ apiKey: process.env.AI_API_KEY,
204
+ model: 'gpt-4o-mini',
205
+ },
206
+
207
+ // Test execution
208
+ execution: {
209
+ workers: 4,
210
+ timeout: 30_000,
211
+ retries: 1,
212
+ },
213
+
214
+ // Log-driven completion (requires backend instrumentation)
215
+ logCompletion: {
216
+ enabled: true,
217
+ endpoint: '/internal/test-logs',
218
+ pollIntervalMs: 500,
219
+ timeoutMs: 10_000,
220
+ },
221
+
222
+ // Self-healing
223
+ selfHealing: {
224
+ enabled: false,
225
+ fixScope: 'config-only', // 'config-only' | 'config-and-source'
226
+ maxFixRounds: 3,
227
+ dryRunFirst: true,
228
+ },
229
+ });
230
+ ```
231
+
232
+ ## Supported Tech Stacks
233
+
234
+ | Layer | Supported | Planned |
235
+ |---|---|---|
236
+ | **ORM** | Sequelize | TypeORM, Prisma, Drizzle |
237
+ | **Framework** | Express | NestJS, Fastify, Koa |
238
+ | **Test Runner** | Playwright | — |
239
+ | **LLM** | OpenAI, ZhiPu (GLM) | Anthropic, Ollama (local) |
240
+ | **Database** | MySQL, PostgreSQL | SQLite, MongoDB |
241
+
242
+ ## Comparison
243
+
244
+ | Feature | OpenCroc | Playwright | Metersphere | auto-playwright |
245
+ |---|---|---|---|---|
246
+ | Source-aware generation | ✅ | ❌ | ❌ | ❌ |
247
+ | AI config generation + validation | ✅ | ❌ | ❌ | ❌ |
248
+ | Log-driven completion | ✅ | ❌ | ❌ | ❌ |
249
+ | Failure chain attribution | ✅ | ❌ | Partial | ❌ |
250
+ | Self-healing with rollback | ✅ | ❌ | ❌ | ❌ |
251
+ | API dependency DAG | ✅ | ❌ | ❌ | ❌ |
252
+ | Zero-config test generation | ✅ | Codegen only | Manual | NL->action |
253
+ | Impact blast radius analysis | ✅ | ❌ | ❌ | ❌ |
254
+
255
+ ## Roadmap
256
+
257
+ - [x] 6-stage source-to-test pipeline
258
+ - [x] AI configuration generation with 3-layer validation
259
+ - [x] Controlled self-healing loop
260
+ - [x] Log-driven completion detection
261
+ - [x] Failure chain attribution + impact analysis
262
+ - [ ] TypeORM / Prisma adapter
263
+ - [ ] NestJS controller parser
264
+ - [ ] Visual dashboard (opencroc.com)
265
+ - [ ] GitHub Actions integration
266
+ - [ ] VS Code extension
267
+ - [ ] Ollama local LLM support
268
+
269
+ ## Documentation
270
+
271
+ Visit **[opencroc.com](https://opencroc.com)** for full documentation, or browse:
272
+
273
+ - [Architecture Guide](docs/architecture.md)
274
+ - [Configuration Reference](docs/configuration.md)
275
+ - [Backend Instrumentation Guide](docs/backend-instrumentation.md)
276
+ - [AI Provider Setup](docs/ai-providers.md)
277
+ - [Self-Healing Guide](docs/self-healing.md)
278
+ - [Troubleshooting](docs/troubleshooting.md)
279
+
280
+ ## Contributing
281
+
282
+ We welcome contributions. See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
283
+
284
+ ## License
285
+
286
+ [MIT](LICENSE) © 2026 OpenCroc Contributors
package/README.ja.md ADDED
@@ -0,0 +1,286 @@
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/blob/main/LICENSE"><img src="https://img.shields.io/github/license/opencroc/opencroc" alt="MIT License" /></a>
14
+ <a href="https://opencroc.com"><img src="https://img.shields.io/badge/docs-opencroc.com-blue" alt="Documentation" /></a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="README.en.md">English</a> | <a href="README.zh-CN.md">简体中文</a> | <a href="README.ja.md">日本語</a>
19
+ </p>
20
+
21
+ ---
22
+
23
+ ## OpenCroc とは
24
+
25
+ OpenCroc は [Playwright](https://playwright.dev) 上に構築された **AI ネイティブ E2E テストフレームワーク** です。手作業で大量のテストスクリプトを書く代わりに、OpenCroc は**バックエンドのソースコード**(モデル、コントローラー、DTO)を解析し、API チェーン、シードデータ、リクエストボディ、アサーションを含む E2E テストスイートを自動生成します。
26
+
27
+ テストが失敗した場合、単なるエラー出力で終わりません。リクエストチェーン全体をたどって**根本原因を特定**し、**修正パッチを生成**し、**再実行で修正を検証**します。
28
+
29
+ ### 主な機能
30
+
31
+ | 機能 | 説明 |
32
+ |---|---|
33
+ | **ソースコード認識型テスト生成** | [ts-morph](https://ts-morph.com) で Sequelize/TypeORM モデル、Express/NestJS コントローラー、DTO デコレーターを解析し API 面を把握 |
34
+ | **AI 駆動の設定生成** | LLM がリクエストテンプレート、シードデータ、パラメータマッピングを生成し、3層検証(schema -> semantic -> dry-run)で確認 |
35
+ | **インテリジェントなチェーン計画** | API 依存 DAG を構築し、トポロジカルソートと貪欲最適化でテストチェーンを設計 |
36
+ | **ログ駆動の完了判定** | `networkidle` を超えて、バックエンド実行ログ(`api_exec end`)で完了を検証 |
37
+ | **失敗チェーンの原因追跡** | ネットワークエラー -> 遅延 API -> バックエンドログの順で追跡し根因特定 |
38
+ | **制御された自己修復** | `backup -> AI patch -> dry-run -> apply -> re-run -> verify -> rollback` を安全ゲート付きで実行 |
39
+ | **影響範囲分析** | 外部キー関係を BFS でたどり、影響範囲を可視化し Mermaid 図を生成 |
40
+
41
+ ## クイックスタート
42
+
43
+ ### 前提条件
44
+
45
+ - Node.js >= 18
46
+ - Express/NestJS + Sequelize/TypeORM を利用するバックエンドプロジェクト
47
+
48
+ ### インストール
49
+
50
+ ```bash
51
+ npm install opencroc --save-dev
52
+ ```
53
+
54
+ ### 初期化
55
+
56
+ ```bash
57
+ npx opencroc init
58
+ ```
59
+
60
+ このコマンドで以下を実行します:
61
+ 1. プロジェクト構成をスキャン
62
+ 2. ORM とフレームワークを検出
63
+ 3. `opencroc.config.ts` を初期生成
64
+ 4. サンプルテストを生成
65
+
66
+ ### テスト生成
67
+
68
+ ```bash
69
+ # 単一モジュールのテスト生成
70
+ npx opencroc generate --module=knowledge-base
71
+
72
+ # 全モジュールのテスト生成
73
+ npx opencroc generate --all
74
+
75
+ # ドライラン(ファイルを書き込まない)
76
+ npx opencroc generate --all --dry-run
77
+ ```
78
+
79
+ ### テスト実行
80
+
81
+ ```bash
82
+ # 生成済みテストをすべて実行
83
+ npx opencroc test
84
+
85
+ # 特定モジュールのみ実行
86
+ npx opencroc test --module=knowledge-base
87
+
88
+ # 自己修復モードで実行
89
+ npx opencroc test --self-heal
90
+ ```
91
+
92
+ ### AI 設定の検証
93
+
94
+ ```bash
95
+ # 生成設定を検証
96
+ npx opencroc validate --all
97
+
98
+ # AI 生成結果とベースラインを比較
99
+ npx opencroc compare --baseline=report-a.json --current=report-b.json
100
+ ```
101
+
102
+ ## アーキテクチャ
103
+
104
+ ```
105
+ ┌─────────────────────────────────────────────────────────────┐
106
+ │ CLI / Orchestrator │
107
+ ├──────────┬──────────┬──────────┬──────────┬─────────────────┤
108
+ │ Source │ Chain │ Test │ Execution│ Self-Healing │
109
+ │ Parser │ Planner │Generator │ Engine │ Engine │
110
+ │ │ │ │ │ │
111
+ │ ts-morph │ DAG + │ Template │Playwright│ AI Attribution │
112
+ │ Model │ Topo │ + AI │ + Log │ + Controlled │
113
+ │ Controller│ Sort + │ Config │ Driven │ Fix + Verify │
114
+ │ DTO │ Greedy │ Merge │ Assert │ + Rollback │
115
+ ├──────────┴──────────┴──────────┴──────────┴─────────────────┤
116
+ │ Observation Bus (Network + Backend Logs) │
117
+ ├──────────────────────────────────────────────────────────────┤
118
+ │ Report Engine (HTML / JSON / Markdown) │
119
+ └──────────────────────────────────────────────────────────────┘
120
+ ```
121
+
122
+ ### 6 段階パイプライン
123
+
124
+ ```
125
+ Source Scan -> ER Diagram -> API Analysis -> Chain Planning -> Test Generation -> Failure Analysis
126
+ │ │ │ │ │ │
127
+ ts-morph Mermaid Dependency Topological Playwright + Root Cause +
128
+ parsing erDiagram DAG builder + greedy AI body/seed Impact map
129
+ ```
130
+
131
+ ## 仕組み
132
+
133
+ ### 1. ソース解析
134
+
135
+ OpenCroc は [ts-morph](https://ts-morph.com) を使ってバックエンドを静的解析します。
136
+
137
+ - **Models**: Sequelize `Model.init()` / TypeORM `@Entity()` からテーブル名、列型、インデックス、外部キーを抽出
138
+ - **Controllers**: Express `router.get/post/put/delete` からルート、HTTP メソッド、パスパラメータを抽出
139
+ - **DTOs**: `@IsString()`、`@IsNumber()`、`@IsOptional()` からバリデーションルールを抽出
140
+
141
+ ### 2. AI 設定生成
142
+
143
+ 各モジュールごとに、OpenCroc は LLM(OpenAI / ZhiPu / OpenAI 互換 API)を呼び出して以下を生成します。
144
+
145
+ - **リクエストボディテンプレート**: フィールド精度の高い POST/PUT ペイロード
146
+ - **シードデータ**: 正しい API 順序を持つ `beforeAll` セットアップ
147
+ - **パラメータマッピング**: パスパラメータ別名(`/:id` -> `categoryId`)
148
+ - **ID エイリアス**: 複数リソースチェーンでの ID 衝突防止
149
+
150
+ 各設定は **3 層検証** を通過します。
151
+ 1. **Schema 検証**: JSON 構造の完全性
152
+ 2. **Semantic 検証**: フィールド値がソースメタデータに一致するか
153
+ 3. **Dry-run 検証**: TypeScript コンパイル確認
154
+
155
+ 失敗した設定は書き込み前に自動修正(最大 3 ラウンド)されます。
156
+
157
+ ### 3. ログ駆動の完了判定
158
+
159
+ 壊れやすい `networkidle` に依存せず、以下で判定します。
160
+
161
+ ```
162
+ Frontend Request -> Backend api_exec start log -> Backend processing -> api_exec end log
163
+
164
+ OpenCroc polls end logs to confirm completion
165
+ ```
166
+
167
+ フロントが待機状態でもバックエンドが継続処理中のケースを検出できます。
168
+
169
+ ### 4. 自己修復ループ
170
+
171
+ ```
172
+ Test Failure
173
+ -> AI Attribution (LLM + heuristic fallback)
174
+ -> Generate Fix Patch
175
+ -> Dry-Run Validation
176
+ -> Apply Patch (with backup)
177
+ -> Re-run Failed Tests
178
+ -> Verify Fix
179
+ -> Commit or Rollback
180
+ ```
181
+
182
+ ## 設定例
183
+
184
+ ```typescript
185
+ // opencroc.config.ts
186
+ import { defineConfig } from 'opencroc';
187
+
188
+ export default defineConfig({
189
+ // バックエンドソースのパス
190
+ backend: {
191
+ modelsDir: 'src/models',
192
+ controllersDir: 'src/controllers',
193
+ servicesDir: 'src/services',
194
+ },
195
+
196
+ // 対象アプリケーション
197
+ baseUrl: 'http://localhost:3000',
198
+ apiBaseUrl: 'http://localhost:3000/api',
199
+
200
+ // AI 設定
201
+ ai: {
202
+ provider: 'openai', // 'openai' | 'zhipu' | 'custom'
203
+ apiKey: process.env.AI_API_KEY,
204
+ model: 'gpt-4o-mini',
205
+ },
206
+
207
+ // テスト実行
208
+ execution: {
209
+ workers: 4,
210
+ timeout: 30_000,
211
+ retries: 1,
212
+ },
213
+
214
+ // ログ駆動完了判定(バックエンド側の計測が必要)
215
+ logCompletion: {
216
+ enabled: true,
217
+ endpoint: '/internal/test-logs',
218
+ pollIntervalMs: 500,
219
+ timeoutMs: 10_000,
220
+ },
221
+
222
+ // 自己修復
223
+ selfHealing: {
224
+ enabled: false,
225
+ fixScope: 'config-only', // 'config-only' | 'config-and-source'
226
+ maxFixRounds: 3,
227
+ dryRunFirst: true,
228
+ },
229
+ });
230
+ ```
231
+
232
+ ## 対応技術スタック
233
+
234
+ | レイヤー | 対応済み | 予定 |
235
+ |---|---|---|
236
+ | **ORM** | Sequelize | TypeORM, Prisma, Drizzle |
237
+ | **Framework** | Express | NestJS, Fastify, Koa |
238
+ | **Test Runner** | Playwright | — |
239
+ | **LLM** | OpenAI, ZhiPu (GLM) | Anthropic, Ollama (local) |
240
+ | **Database** | MySQL, PostgreSQL | SQLite, MongoDB |
241
+
242
+ ## 比較
243
+
244
+ | 機能 | OpenCroc | Playwright | Metersphere | auto-playwright |
245
+ |---|---|---|---|---|
246
+ | ソース認識生成 | ✅ | ❌ | ❌ | ❌ |
247
+ | AI 設定生成 + 検証 | ✅ | ❌ | ❌ | ❌ |
248
+ | ログ駆動完了判定 | ✅ | ❌ | ❌ | ❌ |
249
+ | 失敗チェーン帰属分析 | ✅ | ❌ | Partial | ❌ |
250
+ | 自己修復 + ロールバック | ✅ | ❌ | ❌ | ❌ |
251
+ | API 依存 DAG | ✅ | ❌ | ❌ | ❌ |
252
+ | ゼロ設定テスト生成 | ✅ | Codegen only | Manual | NL->action |
253
+ | 影響範囲分析 | ✅ | ❌ | ❌ | ❌ |
254
+
255
+ ## Roadmap
256
+
257
+ - [x] 6-stage source-to-test pipeline
258
+ - [x] AI configuration generation with 3-layer validation
259
+ - [x] Controlled self-healing loop
260
+ - [x] Log-driven completion detection
261
+ - [x] Failure chain attribution + impact analysis
262
+ - [ ] TypeORM / Prisma adapter
263
+ - [ ] NestJS controller parser
264
+ - [ ] Visual dashboard (opencroc.com)
265
+ - [ ] GitHub Actions integration
266
+ - [ ] VS Code extension
267
+ - [ ] Ollama local LLM support
268
+
269
+ ## ドキュメント
270
+
271
+ 詳細は **[opencroc.com](https://opencroc.com)** を参照してください。あわせて以下も確認できます。
272
+
273
+ - [Architecture Guide](docs/architecture.md)
274
+ - [Configuration Reference](docs/configuration.md)
275
+ - [Backend Instrumentation Guide](docs/backend-instrumentation.md)
276
+ - [AI Provider Setup](docs/ai-providers.md)
277
+ - [Self-Healing Guide](docs/self-healing.md)
278
+ - [Troubleshooting](docs/troubleshooting.md)
279
+
280
+ ## コントリビュート
281
+
282
+ 貢献を歓迎します。ガイドラインは [CONTRIBUTING.md](CONTRIBUTING.md) を参照してください。
283
+
284
+ ## ライセンス
285
+
286
+ [MIT](LICENSE) © 2026 OpenCroc Contributors
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="docs/assets/logo-placeholder.png" alt="OpenCroc" width="200" />
2
+ <img src="assets/banner.png" alt="OpenCroc banner" width="820" />
3
3
  </p>
4
4
 
5
5
  <h1 align="center">OpenCroc</h1>
@@ -14,6 +14,10 @@
14
14
  <a href="https://opencroc.com"><img src="https://img.shields.io/badge/docs-opencroc.com-blue" alt="Documentation" /></a>
15
15
  </p>
16
16
 
17
+ <p align="center">
18
+ <a href="README.md">English</a> | <a href="README.zh-CN.md">简体中文</a> | <a href="README.ja.md">日本語</a>
19
+ </p>
20
+
17
21
  ---
18
22
 
19
23
  ## What is OpenCroc?
@@ -0,0 +1,286 @@
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/blob/main/LICENSE"><img src="https://img.shields.io/github/license/opencroc/opencroc" alt="MIT License" /></a>
14
+ <a href="https://opencroc.com"><img src="https://img.shields.io/badge/docs-opencroc.com-blue" alt="Documentation" /></a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="README.en.md">English</a> | <a href="README.zh-CN.md">简体中文</a> | <a href="README.ja.md">日本語</a>
19
+ </p>
20
+
21
+ ---
22
+
23
+ ## OpenCroc 是什么?
24
+
25
+ OpenCroc 是一个构建在 [Playwright](https://playwright.dev) 之上的 **AI 原生端到端测试框架**。你不需要手写大量脚本,OpenCroc 会**读取后端源码**(模型、控制器、DTO),并自动生成完整 E2E 测试套件,包括 API 调用链、种子数据、请求体与断言。
26
+
27
+ 当测试失败时,OpenCroc 不只是报错,而是会沿完整请求链路**定位根因**、**生成修复补丁**,并**自动回归验证**修复结果。
28
+
29
+ ### 核心能力
30
+
31
+ | 能力 | 说明 |
32
+ |---|---|
33
+ | **源码感知测试生成** | 通过 [ts-morph](https://ts-morph.com) 解析 Sequelize/TypeORM 模型、Express/NestJS 控制器、DTO 装饰器,识别 API 面 |
34
+ | **AI 配置生成** | 使用 LLM 生成请求模板、种子数据、参数映射,并通过三层校验(schema -> semantic -> dry-run) |
35
+ | **智能调用链规划** | 构建 API 依赖 DAG,做拓扑排序并以贪心策略提升覆盖率 |
36
+ | **日志驱动完成判定** | 超越 `networkidle`,通过后端日志(`api_exec end`)确认请求真正完成 |
37
+ | **失败链路归因** | 从网络异常 -> 慢接口 -> 后端日志逐层追踪,定位根因 |
38
+ | **可控自愈机制** | `backup -> AI patch -> dry-run -> apply -> re-run -> verify -> rollback`,每步有安全闸门 |
39
+ | **影响面分析** | 基于外键关系做 BFS 传播分析,自动输出 Mermaid 图 |
40
+
41
+ ## 快速开始
42
+
43
+ ### 前置要求
44
+
45
+ - Node.js >= 18
46
+ - 使用 Express/NestJS + Sequelize/TypeORM 的后端项目
47
+
48
+ ### 安装
49
+
50
+ ```bash
51
+ npm install opencroc --save-dev
52
+ ```
53
+
54
+ ### 初始化
55
+
56
+ ```bash
57
+ npx opencroc init
58
+ ```
59
+
60
+ 该命令会:
61
+ 1. 扫描项目结构
62
+ 2. 识别 ORM 与后端框架
63
+ 3. 生成默认 `opencroc.config.ts`
64
+ 4. 生成一套示例测试
65
+
66
+ ### 生成测试
67
+
68
+ ```bash
69
+ # 为单个模块生成测试
70
+ npx opencroc generate --module=knowledge-base
71
+
72
+ # 为所有模块生成测试
73
+ npx opencroc generate --all
74
+
75
+ # 仅预览,不落盘
76
+ npx opencroc generate --all --dry-run
77
+ ```
78
+
79
+ ### 运行测试
80
+
81
+ ```bash
82
+ # 运行全部生成的测试
83
+ npx opencroc test
84
+
85
+ # 运行指定模块
86
+ npx opencroc test --module=knowledge-base
87
+
88
+ # 启用自愈运行
89
+ npx opencroc test --self-heal
90
+ ```
91
+
92
+ ### 校验 AI 配置
93
+
94
+ ```bash
95
+ # 校验所有生成配置
96
+ npx opencroc validate --all
97
+
98
+ # 比较两份报告差异
99
+ npx opencroc compare --baseline=report-a.json --current=report-b.json
100
+ ```
101
+
102
+ ## 架构
103
+
104
+ ```
105
+ ┌─────────────────────────────────────────────────────────────┐
106
+ │ CLI / Orchestrator │
107
+ ├──────────┬──────────┬──────────┬──────────┬─────────────────┤
108
+ │ Source │ Chain │ Test │ Execution│ Self-Healing │
109
+ │ Parser │ Planner │Generator │ Engine │ Engine │
110
+ │ │ │ │ │ │
111
+ │ ts-morph │ DAG + │ Template │Playwright│ AI Attribution │
112
+ │ Model │ Topo │ + AI │ + Log │ + Controlled │
113
+ │ Controller│ Sort + │ Config │ Driven │ Fix + Verify │
114
+ │ DTO │ Greedy │ Merge │ Assert │ + Rollback │
115
+ ├──────────┴──────────┴──────────┴──────────┴─────────────────┤
116
+ │ Observation Bus (Network + Backend Logs) │
117
+ ├──────────────────────────────────────────────────────────────┤
118
+ │ Report Engine (HTML / JSON / Markdown) │
119
+ └──────────────────────────────────────────────────────────────┘
120
+ ```
121
+
122
+ ### 6 阶段流水线
123
+
124
+ ```
125
+ Source Scan -> ER Diagram -> API Analysis -> Chain Planning -> Test Generation -> Failure Analysis
126
+ │ │ │ │ │ │
127
+ ts-morph Mermaid Dependency Topological Playwright + Root Cause +
128
+ parsing erDiagram DAG builder + greedy AI body/seed Impact map
129
+ ```
130
+
131
+ ## 工作原理
132
+
133
+ ### 1. 源码解析
134
+
135
+ OpenCroc 基于 [ts-morph](https://ts-morph.com) 做静态分析:
136
+
137
+ - **Models**:从 Sequelize `Model.init()` / TypeORM `@Entity()` 提取表名、字段类型、索引、外键
138
+ - **Controllers**:从 Express `router.get/post/put/delete` 提取路由、HTTP 方法、路径参数
139
+ - **DTOs**:从 `@IsString()`、`@IsNumber()`、`@IsOptional()` 装饰器提取校验规则
140
+
141
+ ### 2. AI 配置生成
142
+
143
+ 每个模块都会调用 LLM(OpenAI / 智谱 / 任意 OpenAI 兼容 API)生成:
144
+
145
+ - **请求体模板**:字段级精确的 POST/PUT payload
146
+ - **种子数据**:`beforeAll` 的初始化步骤与正确调用顺序
147
+ - **参数映射**:路径参数别名(`/:id` -> `categoryId`)
148
+ - **ID 别名**:避免多资源链路中的 ID 冲突
149
+
150
+ 每份配置都要通过 **3 层校验**:
151
+ 1. **Schema 校验**:JSON 结构完整性
152
+ 2. **语义校验**:字段值是否与源码元数据一致
153
+ 3. **Dry-run 校验**:TypeScript 编译检查
154
+
155
+ 若校验失败,会在落盘前自动修复(最多 3 轮)。
156
+
157
+ ### 3. 日志驱动完成判定
158
+
159
+ 不依赖脆弱的 `networkidle`:
160
+
161
+ ```
162
+ Frontend Request -> Backend api_exec start log -> Backend processing -> api_exec end log
163
+
164
+ OpenCroc polls end logs to confirm completion
165
+ ```
166
+
167
+ 这能覆盖“前端看起来空闲、后端仍在处理”的场景。
168
+
169
+ ### 4. 自愈闭环
170
+
171
+ ```
172
+ Test Failure
173
+ -> AI Attribution (LLM + heuristic fallback)
174
+ -> Generate Fix Patch
175
+ -> Dry-Run Validation
176
+ -> Apply Patch (with backup)
177
+ -> Re-run Failed Tests
178
+ -> Verify Fix
179
+ -> Commit or Rollback
180
+ ```
181
+
182
+ ## 配置示例
183
+
184
+ ```typescript
185
+ // opencroc.config.ts
186
+ import { defineConfig } from 'opencroc';
187
+
188
+ export default defineConfig({
189
+ // 后端源码路径
190
+ backend: {
191
+ modelsDir: 'src/models',
192
+ controllersDir: 'src/controllers',
193
+ servicesDir: 'src/services',
194
+ },
195
+
196
+ // 目标应用
197
+ baseUrl: 'http://localhost:3000',
198
+ apiBaseUrl: 'http://localhost:3000/api',
199
+
200
+ // AI 配置
201
+ ai: {
202
+ provider: 'openai', // 'openai' | 'zhipu' | 'custom'
203
+ apiKey: process.env.AI_API_KEY,
204
+ model: 'gpt-4o-mini',
205
+ },
206
+
207
+ // 测试执行
208
+ execution: {
209
+ workers: 4,
210
+ timeout: 30_000,
211
+ retries: 1,
212
+ },
213
+
214
+ // 日志驱动完成判定(需后端埋点)
215
+ logCompletion: {
216
+ enabled: true,
217
+ endpoint: '/internal/test-logs',
218
+ pollIntervalMs: 500,
219
+ timeoutMs: 10_000,
220
+ },
221
+
222
+ // 自愈
223
+ selfHealing: {
224
+ enabled: false,
225
+ fixScope: 'config-only', // 'config-only' | 'config-and-source'
226
+ maxFixRounds: 3,
227
+ dryRunFirst: true,
228
+ },
229
+ });
230
+ ```
231
+
232
+ ## 支持的技术栈
233
+
234
+ | 层级 | 已支持 | 规划中 |
235
+ |---|---|---|
236
+ | **ORM** | Sequelize | TypeORM, Prisma, Drizzle |
237
+ | **Framework** | Express | NestJS, Fastify, Koa |
238
+ | **Test Runner** | Playwright | — |
239
+ | **LLM** | OpenAI, ZhiPu (GLM) | Anthropic, Ollama (local) |
240
+ | **Database** | MySQL, PostgreSQL | SQLite, MongoDB |
241
+
242
+ ## 对比
243
+
244
+ | 功能 | OpenCroc | Playwright | Metersphere | auto-playwright |
245
+ |---|---|---|---|---|
246
+ | 源码感知生成 | ✅ | ❌ | ❌ | ❌ |
247
+ | AI 配置生成 + 校验 | ✅ | ❌ | ❌ | ❌ |
248
+ | 日志驱动完成判定 | ✅ | ❌ | ❌ | ❌ |
249
+ | 失败链路归因 | ✅ | ❌ | 部分 | ❌ |
250
+ | 自愈 + 回滚 | ✅ | ❌ | ❌ | ❌ |
251
+ | API 依赖 DAG | ✅ | ❌ | ❌ | ❌ |
252
+ | 零配置测试生成 | ✅ | 仅 codegen | 手工 | NL->action |
253
+ | 影响面分析 | ✅ | ❌ | ❌ | ❌ |
254
+
255
+ ## Roadmap
256
+
257
+ - [x] 6-stage source-to-test pipeline
258
+ - [x] AI configuration generation with 3-layer validation
259
+ - [x] Controlled self-healing loop
260
+ - [x] Log-driven completion detection
261
+ - [x] Failure chain attribution + impact analysis
262
+ - [ ] TypeORM / Prisma adapter
263
+ - [ ] NestJS controller parser
264
+ - [ ] Visual dashboard (opencroc.com)
265
+ - [ ] GitHub Actions integration
266
+ - [ ] VS Code extension
267
+ - [ ] Ollama local LLM support
268
+
269
+ ## 文档
270
+
271
+ 访问 **[opencroc.com](https://opencroc.com)** 查看完整文档,或阅读:
272
+
273
+ - [Architecture Guide](docs/architecture.md)
274
+ - [Configuration Reference](docs/configuration.md)
275
+ - [Backend Instrumentation Guide](docs/backend-instrumentation.md)
276
+ - [AI Provider Setup](docs/ai-providers.md)
277
+ - [Self-Healing Guide](docs/self-healing.md)
278
+ - [Troubleshooting](docs/troubleshooting.md)
279
+
280
+ ## 贡献
281
+
282
+ 欢迎贡献代码与文档。请查看 [CONTRIBUTING.md](CONTRIBUTING.md)。
283
+
284
+ ## License
285
+
286
+ [MIT](LICENSE) © 2026 OpenCroc Contributors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencroc",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "AI-native E2E testing framework — source-aware test generation, intelligent validation, and self-healing",
5
5
  "keywords": [
6
6
  "e2e",
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "https://github.com/opencroc/opencroc.git"
20
+ "url": "git+https://github.com/opencroc/opencroc.git"
21
21
  },
22
22
  "license": "MIT",
23
23
  "author": "OpenCroc Contributors",
@@ -25,7 +25,7 @@
25
25
  "main": "./dist/index.js",
26
26
  "types": "./dist/index.d.ts",
27
27
  "bin": {
28
- "opencroc": "./dist/cli/index.js"
28
+ "opencroc": "dist/cli/index.js"
29
29
  },
30
30
  "files": [
31
31
  "dist",