tng 0.4.7 โ 0.4.9
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.
- checksums.yaml +4 -4
- data/README.md +291 -321
- data/Rakefile +8 -0
- data/bin/tng +292 -17
- data/binaries/go-ui-darwin-amd64 +0 -0
- data/binaries/go-ui-darwin-arm64 +0 -0
- data/binaries/go-ui-linux-amd64 +0 -0
- data/binaries/go-ui-linux-arm64 +0 -0
- data/binaries/tng-darwin-arm64.bundle +0 -0
- data/binaries/tng-darwin-x86_64.bundle +0 -0
- data/binaries/tng-linux-arm64.so +0 -0
- data/binaries/tng-linux-x86_64.so +0 -0
- data/binaries/tng.bundle +0 -0
- data/lib/generators/tng/install_generator.rb +1 -0
- data/lib/tng/services/direct_generation.rb +31 -2
- data/lib/tng/services/test_generator.rb +72 -8
- data/lib/tng/ui/go_ui_session.rb +78 -4
- data/lib/tng/ui/json_session.rb +18 -0
- data/lib/tng/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
# TNG - AI-Powered Test Generation for Rails
|
|
1
|
+
# TNG - AI-Powered Test Generation & Code Analysis for Rails
|
|
2
2
|
|
|
3
|
-
TNG is
|
|
3
|
+
TNG is a comprehensive AI-powered tool for Rails applications that combines intelligent test generation with advanced static analysis. Analyze your code structure, detect issues, find duplicates, and generate high-quality tests that follow your project's conventions.
|
|
4
4
|
|
|
5
5
|
**Owner:** Binary Dreams LLC
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **๐งช AI Test Generation** - Generate comprehensive tests for controllers, models, services, and 20+ file types
|
|
10
|
+
- **๐ Code Audit** - Deep security, performance, and best-practice analysis
|
|
11
|
+
- **๐ฌ Symbolic Trace** - Visualize execution paths and logic flow with Mermaid diagrams
|
|
12
|
+
- **๐ Clone Detection** - Find duplicate code with 3 detection levels (Token, Structural, Fuzzy)
|
|
13
|
+
- **๐ Dead Code Detection** - Identify unreachable code, unused variables, and unused private methods
|
|
14
|
+
- **โก Blazing Fast** - Powered by Rust for near-instant analysis
|
|
8
15
|
|
|
9
|
-
|
|
16
|
+
## Installation
|
|
10
17
|
|
|
11
18
|
Add this line to your application's Gemfile:
|
|
12
19
|
|
|
@@ -20,415 +27,378 @@ And then execute:
|
|
|
20
27
|
bundle install
|
|
21
28
|
```
|
|
22
29
|
|
|
23
|
-
##
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### 1. Initialize Configuration
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
Generate the configuration file:
|
|
26
35
|
|
|
27
36
|
```bash
|
|
28
37
|
rails generate tng:install
|
|
29
38
|
```
|
|
30
39
|
|
|
31
|
-
This creates `config/initializers/tng.rb
|
|
32
|
-
|
|
33
|
-
### Configuration Options Explained
|
|
34
|
-
|
|
35
|
-
#### API Configuration
|
|
36
|
-
- **`api_key`**: Your TNG API key from https://app.tng.sh/
|
|
37
|
-
- **`base_url`**: TNG service endpoint (automatically configured, do not modify)
|
|
38
|
-
|
|
39
|
-
#### Code Reading
|
|
40
|
-
- **`read_source_code`**: Analyzes the specific code file for which tests are being generated
|
|
41
|
-
- **`read_test_code`**: Reads existing tests for the specific file to match your testing patterns
|
|
42
|
-
|
|
43
|
-
#### Testing Framework Settings
|
|
44
|
-
- **`testing_framework`**: Automatically detected. Possible values: `minitest` or `rspec`
|
|
45
|
-
|
|
46
|
-
*Note: The following settings depend on your testing framework.*
|
|
47
|
-
|
|
48
|
-
**For Minitest:**
|
|
49
|
-
- **`test_style`**: Test organization style. Possible options:
|
|
50
|
-
- `test_block` - `test "does something" do ... end`
|
|
51
|
-
- `spec` - `it "does something" do ... end`
|
|
52
|
-
- `unit` - `def test_does_something ... end`
|
|
53
|
-
- **`assertion_style`**: Assertion syntax preference. Possible values:
|
|
54
|
-
- `assert/refute` - Uses syntax like `assert`, `assert_equal`, `assert_nil`, `refute`, `refute_nil`
|
|
55
|
-
- `assert/assert_not` - Uses syntax like `assert`, `assert_equal`, `assert_nil`, `assert_not`, `assert_not_equl`, `assert_not_nil`
|
|
56
|
-
- `must/wont` - `value.must_equal`, `value.must_be_instance_of`, `value.must_raise`, `value.wont_equal`, `value.wont_be_instance_of`, `value.wont_raise`
|
|
57
|
-
|
|
58
|
-
**For RSpec:**
|
|
59
|
-
- **`describe_style`**: Include describe blocks. Possible values: `true`, `false`
|
|
60
|
-
- **`context_style`**: Context block style. Possible values: `context`, `describe`
|
|
61
|
-
- **`it_style`**: Example block style. Possible values: `it`, `specify`
|
|
62
|
-
- **`before_style`**: Setup block style. Possible values: `before`, `setup`
|
|
63
|
-
- **`after_style`**: Teardown block style. Possible values: `after`, `teardown`
|
|
64
|
-
- **`let_style`**: Use let helpers. Possible values: `true`, `false`
|
|
65
|
-
- **`subject_style`**: Use subject helpers. Possible values: `true`, `false`
|
|
66
|
-
|
|
67
|
-
#### Authentication Methods
|
|
68
|
-
Supported authentication types:
|
|
69
|
-
- **`session`**: Session-based authentication
|
|
70
|
-
- **`devise`**: Devise gem integration
|
|
71
|
-
- **`jwt`**: JSON Web Token authentication
|
|
72
|
-
- **`token_auth`**: Token-based authentication
|
|
73
|
-
- **`basic_auth`**: HTTP Basic Authentication
|
|
74
|
-
- **`oauth`**: OAuth authentication
|
|
75
|
-
- **`headers`**: Custom header authentication
|
|
76
|
-
- **`custom`**: Custom authentication logic
|
|
77
|
-
|
|
78
|
-
#### Mock and Factory Libraries
|
|
79
|
-
- **`mock_library`**: Mock library preference
|
|
80
|
-
- **For Minitest**: `minitest/mock`, `mocha`, `nil`
|
|
81
|
-
- **For RSpec**: `rspec-mocks`, `mocha`, `flexmock`, `nil`
|
|
82
|
-
- **`http_mock_library`**: HTTP mocking library. Possible values: `webmock`, `vcr`, `httparty`, `nil`
|
|
83
|
-
- **`factory_library`**: Factory library preference. Possible values: `factory_bot`, `factory_girl`, `fabrication`, `fabricator`, `fixtures`, `active_record`
|
|
84
|
-
|
|
85
|
-
## Configuration Examples
|
|
86
|
-
|
|
87
|
-
### Minitest with FactoryBot Setup
|
|
40
|
+
This creates `config/initializers/tng.rb`:
|
|
88
41
|
|
|
89
42
|
```ruby
|
|
90
|
-
# config/initializers/tng.rb
|
|
91
43
|
Tng.configure do |config|
|
|
44
|
+
# Get your API key from https://app.tng.sh/
|
|
92
45
|
config.api_key = ENV["TNG_API_KEY"]
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
config.
|
|
96
|
-
config.read_test_code = true
|
|
97
|
-
|
|
98
|
-
config.testing_framework = "minitest"
|
|
99
|
-
config.test_style = "test_block"
|
|
100
|
-
config.assertion_style = "assert/refute"
|
|
101
|
-
config.setup_style = true
|
|
102
|
-
config.teardown_style = false
|
|
103
|
-
|
|
104
|
-
config.mock_library = "minitest/mock"
|
|
105
|
-
config.http_mock_library = "webmock"
|
|
106
|
-
config.factory_library = "factory_bot"
|
|
107
|
-
|
|
108
|
-
config.authentication_enabled = true
|
|
109
|
-
config.authentication_methods = [
|
|
110
|
-
{
|
|
111
|
-
method: "authenticate_user!",
|
|
112
|
-
file_location: "app/controllers/application_controller.rb",
|
|
113
|
-
auth_type: "session"
|
|
114
|
-
}
|
|
115
|
-
]
|
|
46
|
+
|
|
47
|
+
# API endpoint (do not modify unless instructed)
|
|
48
|
+
config.base_url = ENV["API_BASE_URI"] || "https://app.tng.sh/"
|
|
116
49
|
end
|
|
117
50
|
```
|
|
118
51
|
|
|
119
|
-
###
|
|
52
|
+
### 2. Set Your API Key
|
|
120
53
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
config.base_url = "https://app.tng.sh/"
|
|
126
|
-
|
|
127
|
-
config.testing_framework = "rspec"
|
|
128
|
-
config.assertion_style = "expect"
|
|
129
|
-
config.describe_style = true
|
|
130
|
-
config.context_style = "context"
|
|
131
|
-
config.it_style = "it"
|
|
132
|
-
config.before_style = "before"
|
|
133
|
-
config.after_style = "after"
|
|
134
|
-
config.let_style = true
|
|
135
|
-
config.subject_style = true
|
|
136
|
-
|
|
137
|
-
config.mock_library = "rspec-mocks"
|
|
138
|
-
config.http_mock_library = "webmock"
|
|
139
|
-
config.factory_library = "factory_bot"
|
|
140
|
-
|
|
141
|
-
config.authentication_enabled = true
|
|
142
|
-
config.authentication_methods = [
|
|
143
|
-
{
|
|
144
|
-
method: "authenticate_user!",
|
|
145
|
-
file_location: "app/controllers/application_controller.rb",
|
|
146
|
-
auth_type: "devise"
|
|
147
|
-
}
|
|
148
|
-
]
|
|
149
|
-
end
|
|
54
|
+
Add to your `.env` file or export:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
export TNG_API_KEY=your_api_key_here
|
|
150
58
|
```
|
|
151
59
|
|
|
152
|
-
|
|
60
|
+
Get your API key from [https://app.tng.sh/](https://app.tng.sh/)
|
|
153
61
|
|
|
154
|
-
|
|
155
|
-
# config/initializers/tng.rb
|
|
156
|
-
Tng.configure do |config|
|
|
157
|
-
config.api_key = ENV["TNG_API_KEY"]
|
|
158
|
-
config.base_url = "https://app.tng.sh/"
|
|
159
|
-
|
|
160
|
-
config.read_source_code = true
|
|
161
|
-
config.read_test_code = true
|
|
162
|
-
|
|
163
|
-
config.testing_framework = "minitest"
|
|
164
|
-
config.test_style = "test_block"
|
|
165
|
-
config.assertion_style = "assert/refute"
|
|
166
|
-
|
|
167
|
-
config.mock_library = "minitest/mock"
|
|
168
|
-
config.http_mock_library = "webmock"
|
|
169
|
-
config.factory_library = "fixtures"
|
|
170
|
-
|
|
171
|
-
config.authentication_enabled = true
|
|
172
|
-
config.authentication_methods = [
|
|
173
|
-
{
|
|
174
|
-
method: "authenticate_via_token!",
|
|
175
|
-
file_location: "app/controllers/application_controller.rb",
|
|
176
|
-
auth_type: "headers"
|
|
177
|
-
}
|
|
178
|
-
]
|
|
179
|
-
end
|
|
180
|
-
```
|
|
62
|
+
### 3. Start Using TNG
|
|
181
63
|
|
|
182
|
-
|
|
64
|
+
```bash
|
|
65
|
+
# Interactive mode (recommended)
|
|
66
|
+
bundle exec tng
|
|
183
67
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
Tng.configure do |config|
|
|
187
|
-
config.api_key = ENV["TNG_API_KEY"]
|
|
188
|
-
config.base_url = "https://app.tng.sh/"
|
|
189
|
-
config.testing_framework = "rspec"
|
|
190
|
-
config.assertion_style = "expect"
|
|
191
|
-
config.let_style = true
|
|
192
|
-
|
|
193
|
-
config.mock_library = "rspec-mocks"
|
|
194
|
-
config.http_mock_library = "webmock"
|
|
195
|
-
config.factory_library = "factory_bot"
|
|
196
|
-
|
|
197
|
-
config.authentication_enabled = true
|
|
198
|
-
config.authentication_methods = [
|
|
199
|
-
{
|
|
200
|
-
method: "authenticate_user!",
|
|
201
|
-
file_location: "app/controllers/application_controller.rb",
|
|
202
|
-
auth_type: "session"
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
method: "authenticate_api_user!",
|
|
206
|
-
file_location: "app/controllers/api/base_controller.rb",
|
|
207
|
-
auth_type: "token_auth"
|
|
208
|
-
}
|
|
209
|
-
]
|
|
210
|
-
|
|
211
|
-
config.authorization_library = "pundit"
|
|
212
|
-
end
|
|
68
|
+
# Or use direct commands
|
|
69
|
+
bundle exec tng --file app/models/user.rb --clones
|
|
213
70
|
```
|
|
214
71
|
|
|
215
|
-
##
|
|
72
|
+
## Usage
|
|
216
73
|
|
|
217
|
-
###
|
|
74
|
+
### Interactive Mode (TUI)
|
|
218
75
|
|
|
219
|
-
|
|
76
|
+
The most powerful way to use TNG:
|
|
220
77
|
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
{
|
|
224
|
-
method: "verify_custom_auth!",
|
|
225
|
-
file_location: "app/controllers/concerns/custom_auth.rb",
|
|
226
|
-
auth_type: "custom"
|
|
227
|
-
}
|
|
228
|
-
]
|
|
78
|
+
```bash
|
|
79
|
+
bundle exec tng
|
|
229
80
|
```
|
|
230
81
|
|
|
231
|
-
|
|
82
|
+
**Interactive Features:**
|
|
83
|
+
- ๐ **Browse** your application structure
|
|
84
|
+
- ๐งช **Generate Tests** for specific methods
|
|
85
|
+
- ๐ **Audit** methods for issues and improvements
|
|
86
|
+
- ๐ฌ **Trace** symbolic execution paths
|
|
87
|
+
- ๐ **Check Duplicates** across your codebase
|
|
88
|
+
- ๐ **Find Dead Code** in files
|
|
89
|
+
- ๐ **View Stats** and usage metrics
|
|
232
90
|
|
|
233
|
-
|
|
234
|
-
config.authentication_enabled = true
|
|
235
|
-
config.authentication_methods = [
|
|
236
|
-
{
|
|
237
|
-
method: "authenticate_with_token",
|
|
238
|
-
file_location: "app/controllers/application_controller.rb",
|
|
239
|
-
auth_type: "jwt"
|
|
240
|
-
}
|
|
241
|
-
]
|
|
242
|
-
config.factory_library = "fixtures" # Often simpler for API apps
|
|
243
|
-
```
|
|
91
|
+
### Command Line Interface
|
|
244
92
|
|
|
245
|
-
####
|
|
93
|
+
#### Test Generation
|
|
246
94
|
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
file_location: "app/controllers/application_controller.rb",
|
|
257
|
-
auth_type: "devise"
|
|
258
|
-
}
|
|
259
|
-
]
|
|
95
|
+
```bash
|
|
96
|
+
# Generate test for a specific method
|
|
97
|
+
bundle exec tng --file app/controllers/users_controller.rb --method index
|
|
98
|
+
|
|
99
|
+
# Short form
|
|
100
|
+
bundle exec tng -f users_controller.rb -m show
|
|
101
|
+
|
|
102
|
+
# Works from subdirectories (auto-detection)
|
|
103
|
+
bundle exec tng users_controller.rb index
|
|
260
104
|
```
|
|
261
105
|
|
|
262
|
-
|
|
106
|
+
**Supported File Types:**
|
|
107
|
+
Controllers, Models, Services, Jobs, Helpers, Lib, Policies, Presenters, Mailers, Serializers, Decorators, Forms, Queries, Channels, GraphQL (Resolvers, Types, Mutations, Loaders, Schemas), and more.
|
|
263
108
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
auth_type: "session"
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
method: "authenticate_api_key!",
|
|
278
|
-
file_location: "app/controllers/api/v1/base_controller.rb",
|
|
279
|
-
auth_type: "headers"
|
|
280
|
-
}
|
|
281
|
-
]
|
|
109
|
+
#### Code Audit
|
|
110
|
+
|
|
111
|
+
Analyze code for security, performance, and best practices:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# Audit a specific method
|
|
115
|
+
bundle exec tng --file app/services/payment_service.rb --method process_payment --audit
|
|
116
|
+
|
|
117
|
+
# Interactive audit mode
|
|
118
|
+
bundle exec tng -f payment_service.rb -m process_payment -a
|
|
282
119
|
```
|
|
283
120
|
|
|
284
|
-
|
|
121
|
+
**Audit Checks:**
|
|
122
|
+
- Security vulnerabilities
|
|
123
|
+
- Performance bottlenecks
|
|
124
|
+
- Code smells
|
|
125
|
+
- Best practice violations
|
|
126
|
+
- Rails-specific patterns
|
|
285
127
|
|
|
286
|
-
|
|
128
|
+
#### Symbolic Trace
|
|
287
129
|
|
|
288
|
-
|
|
130
|
+
Visualize execution paths and generate Mermaid diagrams:
|
|
289
131
|
|
|
290
132
|
```bash
|
|
291
|
-
|
|
133
|
+
# Trace a method's execution flow
|
|
134
|
+
bundle exec tng --file app/models/order.rb --method calculate_total --trace
|
|
135
|
+
|
|
136
|
+
# Short form
|
|
137
|
+
bundle exec tng -f order.rb -m calculate_total -t
|
|
292
138
|
```
|
|
293
139
|
|
|
294
|
-
|
|
295
|
-
-
|
|
296
|
-
-
|
|
297
|
-
-
|
|
298
|
-
-
|
|
140
|
+
**Trace Features:**
|
|
141
|
+
- Control flow visualization
|
|
142
|
+
- Conditional path analysis
|
|
143
|
+
- Loop detection
|
|
144
|
+
- Method call chains
|
|
145
|
+
- Mermaid diagram generation
|
|
146
|
+
|
|
147
|
+
#### Clone Detection
|
|
299
148
|
|
|
300
|
-
|
|
149
|
+
Find duplicate code with 3 levels of detection:
|
|
301
150
|
|
|
302
|
-
|
|
151
|
+
```bash
|
|
152
|
+
# Check for all types of clones
|
|
153
|
+
bundle exec tng --file app/services/pricing_service.rb --clones
|
|
303
154
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
155
|
+
# Specific detection level
|
|
156
|
+
bundle exec tng --file app/services/pricing_service.rb --clones --level=1
|
|
157
|
+
bundle exec tng --file app/services/pricing_service.rb --clones --level=2
|
|
158
|
+
bundle exec tng --file app/services/pricing_service.rb --clones --level=3
|
|
308
159
|
|
|
309
|
-
|
|
160
|
+
# Short form
|
|
161
|
+
bundle exec tng -f pricing_service.rb -c
|
|
162
|
+
```
|
|
310
163
|
|
|
311
|
-
|
|
164
|
+
**Detection Levels:**
|
|
165
|
+
- **Level 1 (Token)** - Exact or near-exact duplicates (copy-paste detection)
|
|
166
|
+
- **Level 2 (Structural)** - Same AST structure with different names
|
|
167
|
+
- **Level 3 (Fuzzy)** - Similar logic with variations (up to 20% difference)
|
|
312
168
|
|
|
313
|
-
|
|
169
|
+
#### Dead Code Detection
|
|
170
|
+
|
|
171
|
+
Identify unreachable code and unused elements:
|
|
314
172
|
|
|
315
173
|
```bash
|
|
316
|
-
#
|
|
317
|
-
bundle exec tng app/
|
|
174
|
+
# Detect dead code in a file
|
|
175
|
+
bundle exec tng --file app/models/user.rb --deadcode
|
|
318
176
|
|
|
319
|
-
# Short form
|
|
320
|
-
bundle exec tng f
|
|
177
|
+
# Short form
|
|
178
|
+
bundle exec tng -f user.rb -d
|
|
321
179
|
|
|
322
|
-
#
|
|
323
|
-
bundle exec tng
|
|
180
|
+
# JSON output for CI/CD
|
|
181
|
+
bundle exec tng -f user.rb --deadcode --json
|
|
182
|
+
```
|
|
324
183
|
|
|
325
|
-
|
|
326
|
-
|
|
184
|
+
**Dead Code Types:**
|
|
185
|
+
- **Unreachable Code** - Code after `return`, `raise`, `exit`, etc.
|
|
186
|
+
- **Unused Variables** - Local variables assigned but never used
|
|
187
|
+
- **Unused Private Methods** - Private methods never called
|
|
188
|
+
- **Unused Parameters** - Method parameters never referenced
|
|
189
|
+
|
|
190
|
+
### JSON Output Mode
|
|
191
|
+
|
|
192
|
+
Get machine-readable output for CI/CD integration:
|
|
327
193
|
|
|
328
|
-
|
|
329
|
-
|
|
194
|
+
```bash
|
|
195
|
+
# Any command with --json flag
|
|
196
|
+
bundle exec tng --file app/models/user.rb --clones --json
|
|
197
|
+
bundle exec tng --file app/services/payment.rb --deadcode --json
|
|
198
|
+
bundle exec tng --file app/controllers/api_controller.rb --trace --json
|
|
330
199
|
```
|
|
331
200
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
201
|
+
## Advanced Features
|
|
202
|
+
|
|
203
|
+
### Method-Specific Analysis
|
|
204
|
+
|
|
205
|
+
TNG focuses on precise, method-level analysis:
|
|
206
|
+
|
|
207
|
+
- **Select specific methods** from any file type
|
|
208
|
+
- **Interactive browsing** with search and filter
|
|
209
|
+
- **Focused generation** for individual methods
|
|
210
|
+
- **No bulk generation** - designed for precision
|
|
211
|
+
|
|
212
|
+
### File Type Auto-Detection
|
|
213
|
+
|
|
214
|
+
No need to specify file types - TNG automatically detects:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# All of these work automatically
|
|
218
|
+
bundle exec tng users_controller.rb index
|
|
219
|
+
bundle exec tng user.rb validate_email
|
|
220
|
+
bundle exec tng payment_service.rb process
|
|
221
|
+
bundle exec tng user_mailer.rb welcome_email
|
|
222
|
+
bundle exec tng user_resolver.rb find_user
|
|
223
|
+
```
|
|
337
224
|
|
|
338
225
|
### Debug Mode
|
|
339
226
|
|
|
340
|
-
|
|
227
|
+
Enable detailed logging for troubleshooting:
|
|
341
228
|
|
|
342
229
|
```bash
|
|
343
|
-
# Interactive mode with debug on
|
|
344
230
|
DEBUG=1 bundle exec tng
|
|
231
|
+
DEBUG=1 bundle exec tng -f users_controller.rb -m index
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Examples
|
|
235
|
+
|
|
236
|
+
### Example 1: Find Duplicate Code
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
$ bundle exec tng --file app/services/pricing_service.rb --clones
|
|
240
|
+
|
|
241
|
+
๐ Clone Detection Results
|
|
345
242
|
|
|
346
|
-
|
|
347
|
-
|
|
243
|
+
Level 1 (Token): 2 matches found
|
|
244
|
+
โโ Lines 45-52 โ Lines 78-85 (8 lines, exact match)
|
|
245
|
+
โโ Lines 120-127 โ Lines 156-163 (8 lines, exact match)
|
|
246
|
+
|
|
247
|
+
Level 2 (Structural): 1 match found
|
|
248
|
+
โโ Lines 200-215 โ Lines 240-255 (16 nodes, complexity: 85)
|
|
249
|
+
|
|
250
|
+
Level 3 (Fuzzy): 1 match found
|
|
251
|
+
โโ Lines 300-320 โ Lines 350-370 (similar logic, 15% variation)
|
|
348
252
|
```
|
|
349
253
|
|
|
350
|
-
###
|
|
254
|
+
### Example 2: Detect Dead Code
|
|
351
255
|
|
|
352
256
|
```bash
|
|
353
|
-
bundle exec tng --
|
|
354
|
-
|
|
257
|
+
$ bundle exec tng --file app/models/user.rb --deadcode
|
|
258
|
+
|
|
259
|
+
๐ Dead Code Detection Results
|
|
260
|
+
|
|
261
|
+
[Unreachable Code] Line 42: Code follows terminal statement
|
|
262
|
+
42: puts "This will never execute"
|
|
263
|
+
|
|
264
|
+
[Unused Variable] Line 67: Variable 'temp' is assigned but never used
|
|
265
|
+
67: temp = calculate_something
|
|
266
|
+
|
|
267
|
+
[Unused Method] Line 120: Private method 'unused_helper' is never used
|
|
268
|
+
120: def unused_helper
|
|
269
|
+
|
|
270
|
+
[Unused Parameter] Line 85: Parameter 'options' is never used
|
|
271
|
+
85: def process(data, options)
|
|
355
272
|
```
|
|
356
273
|
|
|
357
|
-
|
|
274
|
+
### Example 3: Trace Execution Flow
|
|
358
275
|
|
|
359
|
-
|
|
276
|
+
```bash
|
|
277
|
+
$ bundle exec tng --file app/models/order.rb --method calculate_total --trace
|
|
278
|
+
|
|
279
|
+
๐ฌ Symbolic Trace Results
|
|
280
|
+
|
|
281
|
+
Execution Paths: 3
|
|
282
|
+
Complexity Score: 12
|
|
283
|
+
|
|
284
|
+
Path 1: items.empty? โ return 0
|
|
285
|
+
Path 2: discount_code.present? โ apply_discount โ calculate_tax โ total
|
|
286
|
+
Path 3: !discount_code.present? โ calculate_tax โ total
|
|
360
287
|
|
|
361
|
-
|
|
288
|
+
[Mermaid diagram saved to: trace_order_calculate_total.md]
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## CLI Reference
|
|
292
|
+
|
|
293
|
+
### Flags
|
|
294
|
+
|
|
295
|
+
| Flag | Short | Description |
|
|
296
|
+
|------|-------|-------------|
|
|
297
|
+
| `--file` | `-f` | Target file path |
|
|
298
|
+
| `--method` | `-m` | Method name to analyze |
|
|
299
|
+
| `--audit` | `-a` | Run audit mode |
|
|
300
|
+
| `--trace` | `-t` | Run symbolic trace mode |
|
|
301
|
+
| `--clones` | `-c` | Run clone detection |
|
|
302
|
+
| `--deadcode` | `-d` | Run dead code detection |
|
|
303
|
+
| `--level` | `-l` | Clone detection level (1, 2, 3, or all) |
|
|
304
|
+
| `--json` | | Output as JSON |
|
|
305
|
+
| `--help` | `-h` | Show help message |
|
|
306
|
+
|
|
307
|
+
### Examples
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
# Test generation
|
|
311
|
+
bundle exec tng -f users_controller.rb -m index
|
|
312
|
+
|
|
313
|
+
# Code audit
|
|
314
|
+
bundle exec tng -f payment_service.rb -m process -a
|
|
315
|
+
|
|
316
|
+
# Symbolic trace
|
|
317
|
+
bundle exec tng -f order.rb -m calculate_total -t
|
|
318
|
+
|
|
319
|
+
# Clone detection (all levels)
|
|
320
|
+
bundle exec tng -f pricing_service.rb -c
|
|
321
|
+
|
|
322
|
+
# Clone detection (specific level)
|
|
323
|
+
bundle exec tng -f pricing_service.rb -c -l 2
|
|
324
|
+
|
|
325
|
+
# Dead code detection
|
|
326
|
+
bundle exec tng -f user.rb -d
|
|
327
|
+
|
|
328
|
+
# JSON output
|
|
329
|
+
bundle exec tng -f user.rb -c --json
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Troubleshooting
|
|
333
|
+
|
|
334
|
+
### API Key Issues
|
|
362
335
|
|
|
363
336
|
**Error: "Invalid API key"**
|
|
364
337
|
- Verify your API key from https://app.tng.sh/
|
|
365
|
-
- Check
|
|
366
|
-
- Ensure no extra spaces in `.env
|
|
338
|
+
- Check: `echo $TNG_API_KEY`
|
|
339
|
+
- Ensure no extra spaces in `.env`: `TNG_API_KEY=your_key_here`
|
|
367
340
|
|
|
368
341
|
**Error: "API key not found"**
|
|
369
342
|
- Set environment variable: `export TNG_API_KEY=your_key`
|
|
370
343
|
- Or add to `.env` file: `TNG_API_KEY=your_key`
|
|
371
|
-
- Restart Rails server after
|
|
344
|
+
- Restart Rails server after changes
|
|
372
345
|
|
|
373
|
-
|
|
346
|
+
### Configuration Issues
|
|
374
347
|
|
|
375
348
|
**Error: "Invalid configuration"**
|
|
376
|
-
- Run
|
|
377
|
-
- Verify
|
|
349
|
+
- Run: `rails console` then `Tng.configuration`
|
|
350
|
+
- Verify `config/initializers/tng.rb` exists
|
|
378
351
|
- Check for typos in configuration file
|
|
379
352
|
|
|
380
|
-
**Poor Test Quality**
|
|
381
|
-
- Verify authentication methods are correctly configured
|
|
382
|
-
- Check factory library setting matches your setup
|
|
383
|
-
- Ensure `read_source_code` and `read_test_code` are enabled
|
|
384
|
-
- Review testing framework settings match your project
|
|
385
|
-
|
|
386
|
-
#### Authentication Configuration Issues
|
|
387
|
-
|
|
388
|
-
**Tests don't include authentication**
|
|
389
|
-
- Verify `authentication_enabled = true`
|
|
390
|
-
- Check authentication methods are correctly specified
|
|
391
|
-
- Ensure file paths exist: `ls app/controllers/application_controller.rb`
|
|
392
|
-
- Verify method names exist in specified files
|
|
393
|
-
|
|
394
|
-
**Authentication tests fail**
|
|
395
|
-
- Check auth method names match your application
|
|
396
|
-
- Verify file locations are correct
|
|
397
|
-
- Ensure auth_type matches your authentication pattern
|
|
398
|
-
|
|
399
353
|
### Generation Issues
|
|
400
354
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
3. Configuration is valid
|
|
407
|
-
4. API key is working
|
|
408
|
-
5. Internet connection is available
|
|
355
|
+
**No tests generated:**
|
|
356
|
+
1. Verify file path: `ls app/controllers/users_controller.rb`
|
|
357
|
+
2. Check file contains valid Ruby code
|
|
358
|
+
3. Verify API key is working
|
|
359
|
+
4. Check internet connection
|
|
409
360
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
-
|
|
414
|
-
- Factory library setting doesn't match your setup
|
|
415
|
-
- `read_source_code` or `read_test_code` disabled
|
|
416
|
-
- File analysis failed (check DEBUG mode)
|
|
361
|
+
**Poor test quality:**
|
|
362
|
+
- Ensure you're using the latest version
|
|
363
|
+
- Try audit mode for better insights
|
|
364
|
+
- Check file is properly formatted
|
|
417
365
|
|
|
418
366
|
### Debug Mode
|
|
419
367
|
|
|
420
|
-
Enable debug
|
|
368
|
+
Enable debug output for detailed information:
|
|
421
369
|
|
|
422
370
|
```bash
|
|
423
|
-
DEBUG=1 bundle exec tng
|
|
371
|
+
DEBUG=1 bundle exec tng -f users_controller.rb -m index
|
|
424
372
|
```
|
|
425
373
|
|
|
426
374
|
Debug output includes:
|
|
427
|
-
- API request/response
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
375
|
+
- API request/response details
|
|
376
|
+
- File analysis results
|
|
377
|
+
- Configuration validation
|
|
378
|
+
- Error stack traces
|
|
379
|
+
|
|
380
|
+
## What's New in v0.4.8
|
|
381
|
+
|
|
382
|
+
### New Features
|
|
383
|
+
- โจ **Level 3 Fuzzy Clone Detection** - Find similar code with variations
|
|
384
|
+
- โจ **Dead Code Detection** - Identify unreachable code and unused elements
|
|
385
|
+
- โจ **Simplified Configuration** - Only API key required to get started
|
|
386
|
+
- โจ **Enhanced Clone Detection** - 3 levels of duplicate detection
|
|
387
|
+
- โจ **Improved UI** - Better visualization of results
|
|
388
|
+
|
|
389
|
+
### Improvements
|
|
390
|
+
- โก Faster file analysis with optimized Rust parsers
|
|
391
|
+
- ๐จ Better error messages and user feedback
|
|
392
|
+
- ๐ Enhanced reporting for all analysis modes
|
|
393
|
+
- ๐ง Auto-detection of file types and test frameworks
|
|
394
|
+
|
|
395
|
+
## Getting Help
|
|
396
|
+
|
|
397
|
+
If you're experiencing issues:
|
|
398
|
+
- Check the troubleshooting section above
|
|
399
|
+
- Enable debug mode: `DEBUG=1 bundle exec tng`
|
|
400
|
+
- Contact support at https://app.tng.sh/
|
|
401
|
+
- Open a GitHub issue for bug reports
|
|
432
402
|
|
|
433
403
|
## License
|
|
434
404
|
|