ask-ruby-harness 0.3.0 → 0.3.2
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/CHANGELOG.md +13 -0
- data/lib/ask/ruby/harness/tools/run_tests.rb +47 -2
- data/lib/ask/ruby/harness/version.rb +1 -1
- data/lib/ask/ruby/harness.rb +27 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bc926a8ba86f90bbc682d1361f4b436decfb071f543303a4f1055b7d8e986b59
|
|
4
|
+
data.tar.gz: b49641a4b3d21015363f0744ea28a5a146dd42eec21859120faee3977adfcba1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe9cef5ac7bab9ae6742e988b0e46359d95809aedc91995918dd49d1481e770819d1e08388b90e60a3d1db0b4344dd32309ff317808283bf9ef4031104cd1713
|
|
7
|
+
data.tar.gz: b29401a3227880eb954e684b14fe4b197da492da840d1ab068f594f10007e6309deeeae95ca6bc5afcd6108fbadb1e119589bba5c478eb4ff959d9dbefba809e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## [0.3.2] — 2026-08-12
|
|
2
|
+
|
|
3
|
+
### Fixed
|
|
4
|
+
|
|
5
|
+
- **ERB-safe `config/database.yml` parsing** — `database_yaml` now renders
|
|
6
|
+
ERB (Rails-style) before YAML loading. Raw `YAML.safe_load` choked on the
|
|
7
|
+
ERB most real database.yml files embed (ENV/credentials), so the named
|
|
8
|
+
database fallback reported "not found" for those apps.
|
|
9
|
+
- **Env-name lookup for named databases** — `database: "production"` from a
|
|
10
|
+
development-booted server now resolves that environment's own section in
|
|
11
|
+
`config/database.yml`: its flat single-DB config, or its `primary` pool
|
|
12
|
+
for multi-DB apps.
|
|
13
|
+
|
|
1
14
|
## [0.3.0] — 2026-08-10
|
|
2
15
|
|
|
3
16
|
### Added
|
|
@@ -30,6 +30,14 @@ module Ask
|
|
|
30
30
|
files = files.map { |f| rel_to_run_root(f, run_root) }
|
|
31
31
|
runner = detect_runner(run_root)
|
|
32
32
|
|
|
33
|
+
# rake test only takes files (TEST env); expand directory args to
|
|
34
|
+
# their *_test.rb files. Rails and rspec expand dirs natively.
|
|
35
|
+
if runner == :minitest
|
|
36
|
+
expanded = expand_minitest_directories(files, run_root)
|
|
37
|
+
return expanded unless expanded.is_a?(Array)
|
|
38
|
+
files = expanded
|
|
39
|
+
end
|
|
40
|
+
|
|
33
41
|
failed_tests = failed_only ? load_failed_tests(run_root) : nil
|
|
34
42
|
if failed_only && failed_tests.empty?
|
|
35
43
|
return Ask::Result.failure("No failed tests from the previous run to rerun.")
|
|
@@ -40,6 +48,10 @@ module Ask
|
|
|
40
48
|
json_path = artifact_dir.join("last-test.json")
|
|
41
49
|
status_path = artifact_dir.join("last-failures.json")
|
|
42
50
|
|
|
51
|
+
# A child that produces no JSON must not be masked by a previous
|
|
52
|
+
# run's stale file — parse_results only looks at this path.
|
|
53
|
+
json_path.delete if json_path.exist?
|
|
54
|
+
|
|
43
55
|
command, env = build_command(runner, files, name, failed_tests, json_path)
|
|
44
56
|
outcome = run(command, env, log_path, timeout, run_root)
|
|
45
57
|
|
|
@@ -101,6 +113,25 @@ module Ask
|
|
|
101
113
|
Pathname.new(File.expand_path(file, app_root)).relative_path_from(run_root).to_s
|
|
102
114
|
end
|
|
103
115
|
|
|
116
|
+
# rake_test_loader requires each arg as a file — a directory arg
|
|
117
|
+
# explodes ("cannot load such file -- .../test"). Replace directory
|
|
118
|
+
# args with the *_test.rb files under them (relative to run_root),
|
|
119
|
+
# mirroring the standard Rake::TestTask pattern.
|
|
120
|
+
def expand_minitest_directories(files, run_root)
|
|
121
|
+
files.flat_map do |f|
|
|
122
|
+
dir = File.join(run_root.to_s, f)
|
|
123
|
+
next f unless File.directory?(dir)
|
|
124
|
+
|
|
125
|
+
matches = Dir.glob(File.join(dir, "**", "*_test.rb"))
|
|
126
|
+
.map { |m| Pathname.new(m).relative_path_from(run_root).to_s }
|
|
127
|
+
.uniq
|
|
128
|
+
if matches.empty?
|
|
129
|
+
return Ask::Result.failure("No *_test.rb files found under '#{f}'.")
|
|
130
|
+
end
|
|
131
|
+
matches
|
|
132
|
+
end.uniq
|
|
133
|
+
end
|
|
134
|
+
|
|
104
135
|
def build_command(runner, files, name, failed_tests, json_path)
|
|
105
136
|
case runner
|
|
106
137
|
when :rspec
|
|
@@ -125,11 +156,25 @@ module Ask
|
|
|
125
156
|
# arrives via RUBYOPT like everywhere else.
|
|
126
157
|
args = ["bundle", "exec", "rake", "test"]
|
|
127
158
|
env = injection_env(json_path)
|
|
128
|
-
|
|
159
|
+
# Rake::TestTask reads TEST/TESTOPTS from the environment, so
|
|
160
|
+
# the child inherits whatever the parent run carried (nested
|
|
161
|
+
# runs!) unless it's overwritten or cleared here — a stray TEST
|
|
162
|
+
# pointing at the outer project's files would abort the inner
|
|
163
|
+
# run before any test loads.
|
|
164
|
+
env["TEST"] = files.any? ? files.join(",") : nil
|
|
129
165
|
testopts = []
|
|
130
166
|
testopts << "--name=#{name}" if name
|
|
131
167
|
testopts << "--name=#{name_pattern(failed_tests)}" if failed_tests
|
|
132
|
-
|
|
168
|
+
if testopts.empty?
|
|
169
|
+
env["TESTOPTS"] = nil
|
|
170
|
+
else
|
|
171
|
+
# rake's test task runs ruby through the shell, so unquoted
|
|
172
|
+
# TESTOPTS with `|` (failed_only alternations) or spaces gets
|
|
173
|
+
# split into bogus commands. Quote each option so it survives
|
|
174
|
+
# as one ARGV entry in rake_test_loader.
|
|
175
|
+
env["TESTOPTS"] = testopts.map { |o| "\"#{o}\"" }.join(" ")
|
|
176
|
+
end
|
|
177
|
+
%w[TESTOPT TEST_OPTS TEST_OPT].each { |k| env[k] = nil }
|
|
133
178
|
[args, env]
|
|
134
179
|
end
|
|
135
180
|
end
|
data/lib/ask/ruby/harness.rb
CHANGED
|
@@ -97,7 +97,11 @@ module Ask
|
|
|
97
97
|
# Config for a NAMED database. Resolution order:
|
|
98
98
|
# 1. the host app's own configurations registry (Rails multi-DB —
|
|
99
99
|
# resolves credentials/ENV for us),
|
|
100
|
-
# 2. config/database.yml, the environment section's key
|
|
100
|
+
# 2. config/database.yml, the current environment section's key,
|
|
101
|
+
# 3. config/database.yml, the named environment section itself —
|
|
102
|
+
# "database: production" from a development-booted server
|
|
103
|
+
# resolves production's config (its "primary" pool for
|
|
104
|
+
# multi-DB apps).
|
|
101
105
|
def database_config_for(name)
|
|
102
106
|
name = name.to_s
|
|
103
107
|
if ActiveRecord::Base.respond_to?(:configurations)
|
|
@@ -107,6 +111,15 @@ module Ask
|
|
|
107
111
|
|
|
108
112
|
section = database_yaml_section
|
|
109
113
|
config = section[name] if section.is_a?(Hash) && section[name].is_a?(Hash)
|
|
114
|
+
return sanitize_database_config(config) if config
|
|
115
|
+
|
|
116
|
+
yaml = database_yaml
|
|
117
|
+
env_section = yaml[name] if yaml.is_a?(Hash)
|
|
118
|
+
return nil unless env_section.is_a?(Hash)
|
|
119
|
+
|
|
120
|
+
# Multi-DB apps nest pools under the env key; single-DB apps keep
|
|
121
|
+
# the connection config flat under it.
|
|
122
|
+
config = env_section["primary"].is_a?(Hash) ? env_section["primary"] : env_section
|
|
110
123
|
sanitize_database_config(config)
|
|
111
124
|
end
|
|
112
125
|
|
|
@@ -205,12 +218,22 @@ module Ask
|
|
|
205
218
|
private
|
|
206
219
|
|
|
207
220
|
def database_yaml_section
|
|
221
|
+
yaml = database_yaml || {}
|
|
222
|
+
yaml[env] || yaml["development"] || {}
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Parses config/database.yml with ERB preprocessing (Rails-style) —
|
|
226
|
+
# most real database.yml files embed ENV/credentials ERB, which raw
|
|
227
|
+
# YAML.safe_load cannot parse. Returns nil when unreadable; the
|
|
228
|
+
# callers fall back to the Rails configurations registry.
|
|
229
|
+
def database_yaml
|
|
208
230
|
path = app_root.join("config", "database.yml")
|
|
209
231
|
return nil unless path.exist?
|
|
210
232
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
233
|
+
require "erb"
|
|
234
|
+
rendered = ERB.new(path.read).result
|
|
235
|
+
YAML.safe_load(rendered, aliases: true) || {}
|
|
236
|
+
rescue Psych::Exception, NameError, SyntaxError
|
|
214
237
|
nil
|
|
215
238
|
end
|
|
216
239
|
|