tng 0.1.4

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.

Potentially problematic release.


This version of tng might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 58907277090e7b363bd0907be694ee5023ec4b18b0d24a4ab0956ba2e29fd648
4
+ data.tar.gz: 055abaa322144382a523118edbef976b6ded86425b18d5c6b0308c5e282d3d89
5
+ SHA512:
6
+ metadata.gz: e321fee31b6b91e63c54a318b30f28b66cf05e4e342a2cca2fbc67d1fa76e86ee9102fd788ede777bd6d8f80f32bc7d46bfa985db7b82d4e1b91efe2e32addc3
7
+ data.tar.gz: eca7b0234cf41ef0466f4016229a9236c577e4b0488a227ffa96cfb2baac4587309e70dc95ef6460bad0b4225f98582f00e1c2a50c310e7259a39e3d97f0c3ea
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in tng.gemspec
6
+ gemspec
7
+
8
+ gem "irb"
9
+ gem "rake", "~> 13.0"
10
+
11
+ gem "rake-compiler"
12
+
13
+ gem "minitest", "~> 5.16"
14
+
15
+ gem "rubocop", "~> 1.21"
data/LICENSE.md ADDED
@@ -0,0 +1,32 @@
1
+ # Commercial License
2
+
3
+ Copyright (c) 2025 TNG. All rights reserved.
4
+
5
+ ## License Grant
6
+
7
+ This software is available under a commercial license. You may use this software if you have obtained a valid license from the copyright holder.
8
+
9
+ ## Restrictions
10
+
11
+ Without a valid commercial license, you may NOT:
12
+ - Use this software in any commercial or production environment
13
+ - Fork, copy, modify, or create derivative works
14
+ - Distribute, redistribute, sublicense, or sell copies
15
+ - Reverse engineer or decompile the software
16
+ - Remove or alter any copyright notices
17
+
18
+ ## Commercial Use
19
+
20
+ To obtain a commercial license for production use, contact: [claudiu@tng.sh]
21
+
22
+ ## Evaluation Use
23
+
24
+ You may evaluate this software for a period of 30 days for non-commercial purposes only.
25
+
26
+ ## Termination
27
+
28
+ Any unauthorized use will result in immediate termination of rights and may result in legal action.
29
+
30
+ ## Disclaimer
31
+
32
+ THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
data/README.md ADDED
@@ -0,0 +1,427 @@
1
+ # TNG - AI-Powered Test Generation for Rails
2
+
3
+ TNG is an AI-powered test generation tool that automatically creates comprehensive tests for your Rails applications. It analyzes your code structure, authentication patterns, and configuration to generate high-quality, contextual tests that follow your project's conventions.
4
+
5
+ ## Installation
6
+
7
+ ### Standard Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tng'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ bundle install
19
+ ```
20
+
21
+ ## Configuration
22
+
23
+ TNG requires proper configuration to generate high-quality tests. Generate the configuration file by running:
24
+
25
+ ```bash
26
+ rails generate tng:install
27
+ ```
28
+
29
+ This creates `config/initializers/tng.rb` with a configuration template that you'll need to customize for your application. The generator will attempt to detect your existing setup and pre-configure common settings.
30
+
31
+ ### Configuration Options Explained
32
+
33
+ #### API Configuration
34
+ - **`api_key`**: Your TNG API key from https://app.tng.sh/
35
+ - **`base_url`**: TNG service endpoint (automatically configured, do not modify)
36
+
37
+ #### Code Reading
38
+ - **`read_source_code`**: Analyzes the specific code file for which tests are being generated
39
+ - **`read_test_code`**: Reads existing tests for the specific file to match your testing patterns
40
+
41
+ #### Testing Framework Settings
42
+ - **`testing_framework`**: Automatically detected. Possible values: `minitest` or `rspec`
43
+
44
+ *Note: The following settings depend on your testing framework.*
45
+
46
+ **For Minitest:**
47
+ - **`test_style`**: Test organization style. Possible options:
48
+ - `test_block` - `test "does something" do ... end`
49
+ - `spec` - `it "does something" do ... end`
50
+ - `unit` - `def test_does_something ... end`
51
+ - **`assertion_style`**: Assertion syntax preference. Possible values:
52
+ - `assert/refute` - Uses syntax like `assert`, `assert_equal`, `assert_nil`, `refute`, `refute_nil`
53
+ - `assert/assert_not` - Uses syntax like `assert`, `assert_equal`, `assert_nil`, `assert_not`, `assert_not_equl`, `assert_not_nil`
54
+ - `must/wont` - `value.must_equal`, `value.must_be_instance_of`, `value.must_raise`, `value.wont_equal`, `value.wont_be_instance_of`, `value.wont_raise`
55
+
56
+ **For RSpec:**
57
+ - **`describe_style`**: Include describe blocks. Possible values: `true`, `false`
58
+ - **`context_style`**: Context block style. Possible values: `context`, `describe`
59
+ - **`it_style`**: Example block style. Possible values: `it`, `specify`
60
+ - **`before_style`**: Setup block style. Possible values: `before`, `setup`
61
+ - **`after_style`**: Teardown block style. Possible values: `after`, `teardown`
62
+ - **`let_style`**: Use let helpers. Possible values: `true`, `false`
63
+ - **`subject_style`**: Use subject helpers. Possible values: `true`, `false`
64
+
65
+ #### Authentication Methods
66
+ Supported authentication types:
67
+ - **`session`**: Session-based authentication
68
+ - **`devise`**: Devise gem integration
69
+ - **`jwt`**: JSON Web Token authentication
70
+ - **`token_auth`**: Token-based authentication
71
+ - **`basic_auth`**: HTTP Basic Authentication
72
+ - **`oauth`**: OAuth authentication
73
+ - **`headers`**: Custom header authentication
74
+ - **`custom`**: Custom authentication logic
75
+
76
+ #### Mock and Factory Libraries
77
+ - **`mock_library`**: Mock library preference
78
+ - **For Minitest**: `minitest/mock`, `mocha`, `nil`
79
+ - **For RSpec**: `rspec-mocks`, `mocha`, `flexmock`, `nil`
80
+ - **`http_mock_library`**: HTTP mocking library. Possible values: `webmock`, `vcr`, `httparty`, `nil`
81
+ - **`factory_library`**: Factory library preference. Possible values: `factory_bot`, `factory_girl`, `fabrication`, `fabricator`, `fixtures`, `active_record`
82
+
83
+ ## Configuration Examples
84
+
85
+ ### Minitest with FactoryBot Setup
86
+
87
+ ```ruby
88
+ # config/initializers/tng.rb
89
+ Tng.configure do |config|
90
+ config.api_key = ENV["TNG_API_KEY"]
91
+ config.base_url = "https://app.tng.sh/"
92
+
93
+ config.read_source_code = true
94
+ config.read_test_code = true
95
+
96
+ config.testing_framework = "minitest"
97
+ config.test_style = "test_block"
98
+ config.assertion_style = "assert/refute"
99
+ config.setup_style = true
100
+ config.teardown_style = false
101
+
102
+ config.mock_library = "minitest/mock"
103
+ config.http_mock_library = "webmock"
104
+ config.factory_library = "factory_bot"
105
+
106
+ config.authentication_enabled = true
107
+ config.authentication_methods = [
108
+ {
109
+ method: "authenticate_user!",
110
+ file_location: "app/controllers/application_controller.rb",
111
+ auth_type: "session"
112
+ }
113
+ ]
114
+ end
115
+ ```
116
+
117
+ ### RSpec with FactoryBot Setup
118
+
119
+ ```ruby
120
+ # config/initializers/tng.rb
121
+ Tng.configure do |config|
122
+ config.api_key = ENV["TNG_API_KEY"]
123
+ config.base_url = "https://app.tng.sh/"
124
+
125
+ config.read_source_code = true
126
+ config.read_test_code = true
127
+
128
+ config.testing_framework = "rspec"
129
+ config.assertion_style = "expect"
130
+ config.describe_style = true
131
+ config.context_style = "context"
132
+ config.it_style = "it"
133
+ config.before_style = "before"
134
+ config.after_style = "after"
135
+ config.let_style = true
136
+ config.subject_style = true
137
+
138
+ config.mock_library = "rspec-mocks"
139
+ config.http_mock_library = "webmock"
140
+ config.factory_library = "factory_bot"
141
+
142
+ config.authentication_enabled = true
143
+ config.authentication_methods = [
144
+ {
145
+ method: "authenticate_user!",
146
+ file_location: "app/controllers/application_controller.rb",
147
+ auth_type: "devise"
148
+ }
149
+ ]
150
+ end
151
+ ```
152
+
153
+ ### API-Only Application with Token Authentication
154
+
155
+ ```ruby
156
+ # config/initializers/tng.rb
157
+ Tng.configure do |config|
158
+ config.api_key = ENV["TNG_API_KEY"]
159
+ config.base_url = "https://app.tng.sh/"
160
+
161
+ config.read_source_code = true
162
+ config.read_test_code = true
163
+
164
+ config.testing_framework = "minitest"
165
+ config.test_style = "test_block"
166
+ config.assertion_style = "assert/refute"
167
+
168
+ config.mock_library = "minitest/mock"
169
+ config.http_mock_library = "webmock"
170
+ config.factory_library = "fixtures"
171
+
172
+ config.authentication_enabled = true
173
+ config.authentication_methods = [
174
+ {
175
+ method: "authenticate_via_token!",
176
+ file_location: "app/controllers/application_controller.rb",
177
+ auth_type: "headers"
178
+ }
179
+ ]
180
+ end
181
+ ```
182
+
183
+ ### Multiple Authentication Methods
184
+
185
+ ```ruby
186
+ # config/initializers/tng.rb
187
+ Tng.configure do |config|
188
+ config.api_key = ENV["TNG_API_KEY"]
189
+ config.base_url = "https://app.tng.sh/"
190
+
191
+ config.read_source_code = true
192
+ config.read_test_code = true
193
+
194
+ config.testing_framework = "rspec"
195
+ config.assertion_style = "expect"
196
+ config.let_style = true
197
+
198
+ config.mock_library = "rspec-mocks"
199
+ config.http_mock_library = "webmock"
200
+ config.factory_library = "factory_bot"
201
+
202
+ config.authentication_enabled = true
203
+ config.authentication_methods = [
204
+ {
205
+ method: "authenticate_user!",
206
+ file_location: "app/controllers/application_controller.rb",
207
+ auth_type: "session"
208
+ },
209
+ {
210
+ method: "authenticate_api_user!",
211
+ file_location: "app/controllers/api/base_controller.rb",
212
+ auth_type: "token_auth"
213
+ }
214
+ ]
215
+
216
+ config.authorization_library = "pundit"
217
+ end
218
+ ```
219
+
220
+ ## Advanced Configuration
221
+
222
+ ### Custom Authentication Setup
223
+
224
+ For applications with custom authentication logic that doesn't fit standard patterns:
225
+
226
+ ```ruby
227
+ config.authentication_methods = [
228
+ {
229
+ method: "verify_custom_auth!",
230
+ file_location: "app/controllers/concerns/custom_auth.rb",
231
+ auth_type: "custom"
232
+ }
233
+ ]
234
+ ```
235
+
236
+ #### Rails API Application
237
+
238
+ ```ruby
239
+ config.authentication_enabled = true
240
+ config.authentication_methods = [
241
+ {
242
+ method: "authenticate_with_token",
243
+ file_location: "app/controllers/application_controller.rb",
244
+ auth_type: "jwt"
245
+ }
246
+ ]
247
+ config.factory_library = "fixtures" # Often simpler for API apps
248
+ ```
249
+
250
+ #### Multi-Tenant Application
251
+
252
+ ```ruby
253
+ config.authentication_methods = [
254
+ {
255
+ method: "authenticate_tenant!",
256
+ file_location: "app/controllers/application_controller.rb",
257
+ auth_type: "custom"
258
+ },
259
+ {
260
+ method: "authenticate_user!",
261
+ file_location: "app/controllers/application_controller.rb",
262
+ auth_type: "devise"
263
+ }
264
+ ]
265
+ ```
266
+
267
+ #### Legacy Application with Mixed Authentication
268
+
269
+ ```ruby
270
+ config.authentication_methods = [
271
+ {
272
+ method: "authenticate_admin!",
273
+ file_location: "app/controllers/admin/base_controller.rb",
274
+ auth_type: "basic_auth"
275
+ },
276
+ {
277
+ method: "authenticate_user!",
278
+ file_location: "app/controllers/application_controller.rb",
279
+ auth_type: "session"
280
+ },
281
+ {
282
+ method: "authenticate_api_key!",
283
+ file_location: "app/controllers/api/v1/base_controller.rb",
284
+ auth_type: "headers"
285
+ }
286
+ ]
287
+ ```
288
+
289
+ ## Usage Patterns
290
+
291
+ ### Interactive Mode
292
+
293
+ The recommended way to use TNG for beginners and exploratory testing:
294
+
295
+ ```bash
296
+ bundle exec tng
297
+ ```
298
+
299
+ This launches an interactive session where you can:
300
+ - Browse your application structure
301
+ - Select files to generate tests for
302
+ - Preview generated tests before saving
303
+ - Adjust configuration on the fly
304
+
305
+ ### Direct Mode
306
+
307
+ Generate tests directly from the command line without interactive prompts:
308
+
309
+ #### Standard Format
310
+ ```bash
311
+ bundle exec tng --type=controller --file=users_controller
312
+ bundle exec tng --type=controller --file="admin/users_controller"
313
+ bundle exec tng --type=model --file=user
314
+ bundle exec tng --type=model --file="blog/post"
315
+ ```
316
+
317
+ #### Short Aliases
318
+ ```bash
319
+ # Super concise - perfect for quick generation
320
+ bundle exec tng -t c -f ping
321
+ bundle exec tng -t m -f user
322
+
323
+ # Mixed format also works
324
+ bundle exec tng --type=c --file=ping
325
+ bundle exec tng -t controller -f users_controller
326
+ ```
327
+
328
+ Use `bundle exec tng --help` for more options.
329
+
330
+ ### Debug Mode
331
+
332
+ For troubleshooting configuration or generation issues:
333
+
334
+ ```bash
335
+ # Interactive mode with debug on
336
+ DEBUG=1 bundle exec tng
337
+
338
+ # Direct mode with debug
339
+ DEBUG=1 bundle exec tng -t c -f ping
340
+ ```
341
+
342
+ ### Help and Options
343
+
344
+ ```bash
345
+ bundle exec tng --help # Show help message
346
+ bundle exec tng -h # Short help
347
+ ```
348
+
349
+ ## Troubleshooting
350
+
351
+ ### Configuration Issues
352
+
353
+ #### API Key Problems
354
+
355
+ **Error: "Invalid API key"**
356
+ - Verify your API key from https://app.tng.sh/
357
+ - Check environment variable: `echo $TNG_API_KEY`
358
+ - Ensure no extra spaces in `.env` file: `TNG_API_KEY=your_key_here`
359
+
360
+ **Error: "API key not found"**
361
+ - Set environment variable: `export TNG_API_KEY=your_key`
362
+ - Or add to `.env` file: `TNG_API_KEY=your_key`
363
+ - Restart Rails server after changing environment variables
364
+
365
+ #### Configuration Validation
366
+
367
+ **Error: "Invalid configuration"**
368
+ - Run configuration check: `rails console` then `Tng.configuration`
369
+ - Verify all required settings are present
370
+ - Check for typos in configuration file
371
+
372
+ **Poor Test Quality**
373
+ - Verify authentication methods are correctly configured
374
+ - Check factory library setting matches your setup
375
+ - Ensure `read_source_code` and `read_test_code` are enabled
376
+ - Review testing framework settings match your project
377
+
378
+ #### Authentication Configuration Issues
379
+
380
+ **Tests don't include authentication**
381
+ - Verify `authentication_enabled = true`
382
+ - Check authentication methods are correctly specified
383
+ - Ensure file paths exist: `ls app/controllers/application_controller.rb`
384
+ - Verify method names exist in specified files
385
+
386
+ **Authentication tests fail**
387
+ - Check auth method names match your application
388
+ - Verify file locations are correct
389
+ - Ensure auth_type matches your authentication pattern
390
+
391
+ ### Generation Issues
392
+
393
+ #### No Tests Generated
394
+
395
+ **Check these common issues:**
396
+ 1. File path is correct: `ls app/controllers/users_controller.rb`
397
+ 2. File contains valid Ruby code
398
+ 3. Configuration is valid
399
+ 4. API key is working
400
+ 5. Internet connection is available
401
+
402
+ #### Generated Tests Are Generic
403
+
404
+ **Common causes:**
405
+ - Authentication not properly configured
406
+ - Factory library setting doesn't match your setup
407
+ - `read_source_code` or `read_test_code` disabled
408
+ - File analysis failed (check DEBUG mode)
409
+
410
+ ### Debug Mode
411
+
412
+ Enable debug mode to get detailed information:
413
+
414
+ ```bash
415
+ DEBUG=1 bundle exec tng -t c -f your_controller
416
+ ```
417
+
418
+ Debug output includes:
419
+ - API request/response information
420
+
421
+ ### Getting Help
422
+
423
+ If you're still experiencing issues: Contact the gem maintainers or open a GitHub issue for support
424
+
425
+ ## License
426
+
427
+ See [LICENSE.md](LICENSE.md) for details.
data/Rakefile ADDED
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ require "rb_sys/extensiontask"
13
+
14
+ task build: :compile
15
+
16
+ GEMSPEC = Gem::Specification.load("tng.gemspec")
17
+
18
+ RbSys::ExtensionTask.new("tng", GEMSPEC) do |ext|
19
+ ext.lib_dir = "lib/tng"
20
+ end
21
+
22
+ task default: %i[compile test rubocop]
23
+
24
+ desc "Recompile Rust code and copy the binary for packaging"
25
+ task redo: :compile do
26
+ puts "Copying compiled binary to binaries/ directory..."
27
+ binary_name = RUBY_PLATFORM.include?("darwin") ? "tng.bundle" : "tng.so"
28
+ source_file = File.join("lib", "tng", binary_name)
29
+ destination_dir = "binaries"
30
+
31
+ if File.exist?(source_file)
32
+ FileUtils.mkdir_p(destination_dir)
33
+ FileUtils.cp(source_file, File.join(destination_dir, binary_name))
34
+ puts "✅ Copied #{binary_name} to #{destination_dir}/"
35
+ else
36
+ puts "❌ Error: Compiled binary not found at #{source_file}"
37
+ puts "Make sure 'rake compile' ran successfully."
38
+ end
39
+ end
40
+
41
+ desc "Build binaries for both Mac and Linux platforms"
42
+ task :build_both do
43
+ puts "Building tng native extensions for both platforms..."
44
+
45
+ # Clean up and create binaries directory
46
+ puts "Cleaning up old binaries..."
47
+ FileUtils.rm_rf("binaries")
48
+ puts "Creating binaries directory..."
49
+ FileUtils.mkdir_p("binaries")
50
+ puts "Binaries directory created: #{Dir.pwd}/binaries/"
51
+
52
+ # Build Mac version
53
+ puts "Building Mac version..."
54
+ system("bundle exec rake compile") || (puts "❌ Mac build failed"
55
+ exit 1)
56
+
57
+ # Copy Mac binary
58
+ mac_binary = "lib/tng/tng.bundle"
59
+ if File.exist?(mac_binary)
60
+ FileUtils.cp(mac_binary, "binaries/tng.bundle")
61
+ puts "Mac binary copied to binaries/ for packaging"
62
+ else
63
+ puts "❌ Mac binary not found"
64
+ exit 1
65
+ end
66
+
67
+ # Ensure it's in lib/tng/ for gem loading
68
+ if File.exist?("lib/tng/tng.bundle")
69
+ puts "Mac binary confirmed in lib/tng/ for gem loading"
70
+ else
71
+ puts "Warning: Mac binary not found in lib/tng/ - copying from binaries/"
72
+ FileUtils.cp("binaries/tng.bundle", "lib/tng/tng.bundle")
73
+ end
74
+
75
+ # Build Linux version
76
+ puts "Building Linux version..."
77
+ system("./build_linux_binaries.sh") || (puts "❌ Linux build failed"
78
+ exit 1)
79
+
80
+ puts "Build complete!"
81
+ puts "Binaries for packaging:"
82
+ system("ls -la binaries/")
83
+ puts "Binaries for gem loading:"
84
+ system("ls -la lib/tng/*.bundle lib/tng/*.so 2>/dev/null || echo 'No binaries found in lib/tng/'")
85
+ end
86
+
87
+ desc "Development build: compile for current OS and build gem"
88
+ task dev: :redo do
89
+ puts "Building gem..."
90
+ system("gem build tng.gemspec") || (puts "❌ Gem build failed"
91
+ exit 1)
92
+ puts "✅ Development build complete!"
93
+ end
94
+
95
+ # Add this task to suppress the native artifact warning
96
+ task release: :build_both do
97
+ # Temporarily rename the binary to avoid the warning during gem build
98
+ puts "📦 Building gem with pre-compiled binaries..." if File.exist?("binaries/tng.bundle")
99
+ end
100
+
101
+ desc "Clean release: build binaries and release gem"
102
+ task :clean_release do
103
+ puts "🔨 Running build_both to ensure fresh binaries..."
104
+ Rake::Task[:build_both].invoke
105
+
106
+ puts "🧹 Cleaning development artifacts (keeping binaries/)..."
107
+ # Clean ext/ compiled files (development artifacts)
108
+ Dir.glob("ext/**/*.{bundle,so,dylib}").each do |file|
109
+ File.delete(file)
110
+ puts "Removed development artifact: #{file}"
111
+ end
112
+
113
+ # Clean lib/tng/ compiled files (development artifacts)
114
+ Dir.glob("lib/tng/*.{bundle,so,dylib}").each do |file|
115
+ File.delete(file)
116
+ puts "Removed development artifact: #{file}"
117
+ end
118
+
119
+ puts "📦 Binaries for distribution:"
120
+ system("ls -la binaries/")
121
+
122
+ puts "🚀 Releasing gem..."
123
+ Rake::Task["release"].invoke
124
+ end
data/bin/load_dev ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Development loader for TNG gem
5
+ # This script loads the local development version of the gem
6
+ # Usage: bin/load_dev
7
+
8
+ puts "🔧 Loading TNG development environment..."
9
+
10
+ # Add the lib directory to the load path
11
+ lib_path = File.expand_path("../lib", __dir__)
12
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
13
+
14
+ # Load the development version
15
+ require_relative "../lib/tng"
16
+
17
+ puts "✅ TNG development version loaded!"
18
+ puts "📍 Loaded from: #{lib_path}"
19
+
20
+ # Start IRB with the gem loaded
21
+ require "irb"
22
+ IRB.start