nukadoko 0.2.0 → 0.4.0

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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +153 -0
  3. data/README.ja.md +6 -3
  4. data/README.md +6 -3
  5. data/lib/nukadoko/aria_snapshot.rb +4 -4
  6. data/lib/nukadoko/base.rb +49 -29
  7. data/lib/nukadoko/check.rb +62 -5
  8. data/lib/nukadoko/claim_check.rb +2 -2
  9. data/lib/nukadoko/claim_rules.rb +1 -1
  10. data/lib/nukadoko/claim_sides.rb +481 -0
  11. data/lib/nukadoko/claims.rb +182 -20
  12. data/lib/nukadoko/cli.rb +24 -7
  13. data/lib/nukadoko/codes.json +20 -15
  14. data/lib/nukadoko/criteria.rb +1 -1
  15. data/lib/nukadoko/env_check.rb +1 -3
  16. data/lib/nukadoko/fixtures.rb +53 -21
  17. data/lib/nukadoko/init.rb +0 -1
  18. data/lib/nukadoko/js_json.rb +274 -0
  19. data/lib/nukadoko/js_pattern.rb +531 -0
  20. data/lib/nukadoko/parameter_types.rb +54 -0
  21. data/lib/nukadoko/parts.rb +1 -1
  22. data/lib/nukadoko/pattern.rb +112 -2
  23. data/lib/nukadoko/poll.rb +5 -3
  24. data/lib/nukadoko/program.rb +5 -5
  25. data/lib/nukadoko/project_files.rb +17 -0
  26. data/lib/nukadoko/project_program.rb +119 -0
  27. data/lib/nukadoko/run.rb +62 -17
  28. data/lib/nukadoko/run_record.rb +25 -22
  29. data/lib/nukadoko/scaffold.rb +2 -2
  30. data/lib/nukadoko/schema.rb +60 -18
  31. data/lib/nukadoko/secrets.rb +20 -4
  32. data/lib/nukadoko/spaces.rb +28 -0
  33. data/lib/nukadoko/step.rb +7 -1
  34. data/lib/nukadoko/text_fit.rb +1 -1
  35. data/lib/nukadoko/trace_actions.rb +4 -2
  36. data/lib/nukadoko/tree_passes.rb +6 -3
  37. data/lib/nukadoko/version.rb +1 -1
  38. data/lib/nukadoko.rb +26 -2
  39. data/llms.txt +20 -18
  40. data/sig/generated/nukadoko/aria_snapshot.rbs +2 -2
  41. data/sig/generated/nukadoko/base.rbs +24 -18
  42. data/sig/generated/nukadoko/check.rbs +11 -1
  43. data/sig/generated/nukadoko/claim_sides.rbs +216 -0
  44. data/sig/generated/nukadoko/claims.rbs +46 -3
  45. data/sig/generated/nukadoko/cli.rbs +1 -1
  46. data/sig/generated/nukadoko/env_check.rbs +0 -4
  47. data/sig/generated/nukadoko/fixtures.rbs +25 -2
  48. data/sig/generated/nukadoko/init.rbs +0 -2
  49. data/sig/generated/nukadoko/js_json.rbs +109 -0
  50. data/sig/generated/nukadoko/js_pattern.rbs +194 -0
  51. data/sig/generated/nukadoko/parameter_types.rbs +27 -0
  52. data/sig/generated/nukadoko/pattern.rbs +59 -1
  53. data/sig/generated/nukadoko/poll.rbs +3 -2
  54. data/sig/generated/nukadoko/program.rbs +1 -1
  55. data/sig/generated/nukadoko/project_files.rbs +19 -0
  56. data/sig/generated/nukadoko/project_program.rbs +55 -0
  57. data/sig/generated/nukadoko/run.rbs +17 -3
  58. data/sig/generated/nukadoko/run_record.rbs +5 -4
  59. data/sig/generated/nukadoko/schema.rbs +22 -4
  60. data/sig/generated/nukadoko/secrets.rbs +17 -2
  61. data/sig/generated/nukadoko/spaces.rbs +31 -0
  62. data/sig/generated/nukadoko/trace_actions.rbs +3 -1
  63. data/sig/generated/nukadoko/tree_passes.rbs +2 -2
  64. data/sig/generated/nukadoko.rbs +11 -0
  65. data/skills/nukadoko/SKILL.md +2 -2
  66. data/skills/nukadoko/references/diagnosing.md +1 -1
  67. data/skills/nukadoko/references/examples/http-api.md +19 -16
  68. data/skills/nukadoko/references/fixtures.md +1 -1
  69. data/skills/nukadoko/references/perturbed-worlds.md +8 -6
  70. data/skills/nukadoko/references/program.md +20 -20
  71. data/skills/nukadoko/references/running.md +2 -2
  72. data/skills/nukadoko/references/scenario-rules.md +2 -2
  73. data/skills/nukadoko/references/verdicts.md +3 -3
  74. data/skills/nukadoko/references/writing-steps.md +1 -1
  75. data/skills/nukadoko-verification/SKILL.md +6 -6
  76. metadata +19 -5
@@ -68,18 +68,27 @@ module Nukadoko
68
68
  data_class.new(**fields.to_h { [_1.name, hash.fetch(_1.name.to_s)] })
69
69
  end
70
70
 
71
- # Every way `value` departs from the schema, as `path: problem` lines.
71
+ # Every way `value` departs from the schema, as `path: problem` lines in
72
+ # zod's words, so a step fails with the text the TypeScript engine gives.
72
73
  # A key the schema does not declare is no problem: as a zod object does,
73
- # the schema drops it (`strip`), and `dropped` names where.
74
- #: (untyped, ?String?) -> Array[String]
75
- def problems(value, path = nil)
76
- return ["#{path || "value"} must be an object, got #{value.inspect}"] unless value.is_a?(Hash)
74
+ # the schema drops it (`strip`), and `dropped` names where. `strict`
75
+ # refuses one at the root instead, as the TypeScript engine's args do.
76
+ #: (untyped, ?String?, ?strict: bool) -> Array[String]
77
+ def problems(value, path = nil, strict: false)
78
+ return ["#{path || "(root)"}: #{Schema.invalid("object", value)}"] unless value.is_a?(Hash)
77
79
 
78
80
  hash = value.transform_keys(&:to_s)
79
- fields.flat_map do |field|
81
+ found = fields.flat_map do |field|
80
82
  key = join(path, field.name)
81
- hash.key?(field.name.to_s) ? Schema.type_problems(field.type, hash[field.name.to_s], key) : ["#{key} is missing"]
83
+ if hash.key?(field.name.to_s) then Schema.type_problems(field.type, hash[field.name.to_s], key)
84
+ elsif field.type == :unknown then []
85
+ else Schema.type_problems(field.type, MISSING, key)
86
+ end
82
87
  end
88
+ extra = hash.keys - fields.map { _1.name.to_s }
89
+ return found unless strict && extra.any?
90
+
91
+ found + ["#{path || "(root)"}: Unrecognized key#{"s" if extra.size > 1}: #{extra.map { JSON.generate(_1) }.join(", ")}"]
83
92
  end
84
93
 
85
94
  # The value with every key the schema does not declare left out, at any
@@ -142,24 +151,57 @@ module Nukadoko
142
151
  end
143
152
  end
144
153
 
154
+ # A key the value does not hold, which zod reads as undefined.
155
+ MISSING = Object.new.freeze
156
+ SAFE = 2**53 - 1
157
+
158
+ # What zod calls a value's type in "received ...".
159
+ #: (untyped) -> String
160
+ def self.received(value)
161
+ case value
162
+ when MISSING then "undefined"
163
+ when nil then "null"
164
+ when String then "string"
165
+ when true, false then "boolean"
166
+ when Float then value.nan? ? "NaN" : "number"
167
+ when Numeric then "number"
168
+ when Array then "array"
169
+ else "object"
170
+ end
171
+ end
172
+
173
+ #: (String, untyped) -> String
174
+ def self.invalid(expected, value) = "Invalid input: expected #{expected}, received #{received(value)}"
175
+
145
176
  #: (untyped, untyped, String) -> Array[String]
146
177
  def self.type_problems(type, value, path)
147
- ok =
178
+ problem =
148
179
  case type
149
- in :string then value.is_a?(String)
150
- in :boolean then [true, false].include?(value)
151
- in :integer then value.is_a?(Integer)
152
- in :number then value.is_a?(Numeric)
153
- in :unknown then true
180
+ in :string then invalid("string", value) unless value.is_a?(String)
181
+ in :boolean then invalid("boolean", value) unless [true, false].include?(value)
182
+ in :number then invalid("number", value) unless value.is_a?(Numeric) && value.finite?
183
+ in :integer then integer_problem(value)
184
+ in :unknown then nil
154
185
  in [:nullable, inner] then return value.nil? ? [] : type_problems(inner, value, path)
155
- in [:enum, values] then values.include?(value.is_a?(Symbol) ? value.to_s : value)
186
+ in [:enum, values]
187
+ "Invalid option: expected one of #{values.map { JSON.generate(_1) }.join("|")}" unless values.include?(value.is_a?(Symbol) ? value.to_s : value)
156
188
  in [:array, item]
157
- return ["#{path} must be an array, got #{value.inspect}"] unless value.is_a?(Array)
189
+ return ["#{path}: #{invalid("array", value)}"] unless value.is_a?(Array)
158
190
 
159
- return value.each_with_index.flat_map { |v, i| type_problems(item, v, "#{path}[#{i}]") }
160
- in Schema then return type.problems(value, path)
191
+ return value.each_with_index.flat_map { |v, i| type_problems(item, v, "#{path}.#{i}") }
192
+ in Schema then return value.is_a?(Hash) ? type.problems(value, path) : ["#{path}: #{invalid("object", value)}"]
161
193
  end
162
- ok ? [] : ["#{path} must be #{type}, got #{value.inspect}"]
194
+ problem ? ["#{path}: #{problem}"] : []
195
+ end
196
+
197
+ # zod's int: a finite whole number within Number.MAX_SAFE_INTEGER.
198
+ #: (untyped) -> String?
199
+ def self.integer_problem(value)
200
+ return invalid("number", value) unless value.is_a?(Numeric) && value.finite?
201
+ return "Invalid input: expected int, received number" unless value == value.floor
202
+ return "Too big: expected int to be <=#{SAFE}" if value > SAFE
203
+
204
+ "Too small: expected int to be >=-#{SAFE}" if value < -SAFE
163
205
  end
164
206
 
165
207
  # The JSON Schema `nuka describe` prints, as zod's own conversion gives it:
@@ -213,15 +213,31 @@ module Nukadoko
213
213
  #: Hash[String, String]
214
214
  attr_reader :values
215
215
 
216
- #: (?Hash[String, String]) -> void
216
+ # Each name with its value, a name twice when two sets held it with
217
+ # different values (`with`), so neither value goes unredacted.
218
+ #: Array[[String, String]]
219
+ attr_reader :pairs
220
+
221
+ #: (?Hash[String, String] | Array[[String, String]]) -> void
217
222
  def initialize(values = {})
218
- @values = values
223
+ @pairs = values.to_a.uniq
224
+ @values = @pairs.to_h
219
225
  @replacements = replacements
220
226
  @pattern = @replacements.empty? ? nil : Regexp.union((@replacements.keys + @replacements.values.uniq).sort_by { -_1.length })
221
227
  end
222
228
 
223
229
  #: () -> bool
224
- def empty? = @values.empty?
230
+ def empty? = @pairs.empty?
231
+
232
+ # Both sets: a tree's pass redacts with head's secrets as well as its
233
+ # own, since the tree's config must not decide which of head's values
234
+ # may print.
235
+ #: (Secrets) -> Secrets
236
+ def with(other) = Secrets.new(@pairs + other.pairs)
237
+
238
+ # Every loaded value, each once.
239
+ #: () -> Array[String]
240
+ def shown_values = @pairs.map(&:last).uniq
225
241
 
226
242
  # A copy of `value` with every secret spelling in its strings and
227
243
  # keys written as its token. Two keys that redact to one would lose
@@ -265,7 +281,7 @@ module Nukadoko
265
281
  # among equals the alphabetically first name wins.
266
282
  #: () -> Hash[String, String]
267
283
  def replacements
268
- named = @values.select { |_, value| value.length >= MIN_LENGTH }.sort_by(&:first)
284
+ named = @pairs.select { |_, value| value.length >= MIN_LENGTH }.sort_by(&:first)
269
285
  tokens = {} #: Hash[String, String]
270
286
  named.each { |name, value| tokens[value] ||= "{{secret.#{name}}}" }
271
287
  named.each do |name, value|
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ # rbs_inline: enabled
3
+
4
+ # Responsibility: the spaces JavaScript's trim, trimEnd, and \s take, so a
5
+ # text the Ruby engine trims ends where the TypeScript engine's does.
6
+ # Ruby's strip takes a NUL and no Unicode space, and [[:space:]] takes
7
+ # U+0085, which JavaScript keeps; a page's text often ends in a no-break
8
+ # space, so either would judge a claim the other way.
9
+ module Nukadoko
10
+ module Engine
11
+ module Spaces
12
+ CLASS = "\\s\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff"
13
+ SPACE = /[#{CLASS}]/
14
+ LEADING = /\A[#{CLASS}]+/
15
+ TRAILING = /[#{CLASS}]+\z/
16
+ BLANK = /\A[#{CLASS}]*\z/
17
+
18
+ #: (String) -> String
19
+ def self.trim(text) = text.sub(LEADING, "").sub(TRAILING, "")
20
+
21
+ #: (String) -> String
22
+ def self.trim_end(text) = text.sub(TRAILING, "")
23
+
24
+ #: (String) -> bool
25
+ def self.blank?(text) = text.match?(BLANK)
26
+ end
27
+ end
28
+ end
data/lib/nukadoko/step.rb CHANGED
@@ -96,7 +96,13 @@ module Nukadoko
96
96
  #: (untyped) -> [untyped, Array[String]]
97
97
  def returned(value)
98
98
  schema = returns
99
- return [value, schema.problems(value)] if schema
99
+ # nil is a body that gave back nothing, which zod's "(root): expected
100
+ # object" would leave without its cause or either fix.
101
+ if schema
102
+ nothing = "this step declares returns, but run returned nothing; return a value that matches returns, " \
103
+ "or delete returns if no later step reads from this one"
104
+ return [value, value.nil? ? [nothing] : schema.problems(value)]
105
+ end
100
106
  return [{}, []] unless value.is_a?(Hash)
101
107
  return [value, []] if value.empty?
102
108
 
@@ -172,7 +172,7 @@ module Nukadoko
172
172
  # Whether an expected text states nothing beyond its stand-ins.
173
173
  #: (String) -> bool
174
174
  def only_stand_ins?(expected)
175
- lines(expected).all? { _1 == ANY_LINES || fixed_line(_1).parts.join.strip.empty? }
175
+ lines(expected).all? { _1 == ANY_LINES || Spaces.blank?(fixed_line(_1).parts.join) }
176
176
  end
177
177
  end
178
178
  end
@@ -16,10 +16,12 @@ require "zlib"
16
16
  module Nukadoko
17
17
  module Engine
18
18
  module TraceActions
19
- # Version 8 as the TypeScript engine measured it, and version 10 as
19
+ # Version 8 as the TypeScript engine measured it, version 9 as
20
+ # Playwright 1.63.0 writes it (the same fields and the same actions as
21
+ # version 8), and version 10 as
20
22
  # Playwright 1.65.1 writes it for the Ruby client: the same `before`
21
23
  # and `after` fields, with a number for `callId`.
22
- KNOWN_VERSIONS = [8, 10].freeze
24
+ KNOWN_VERSIONS = [8, 9, 10].freeze
23
25
  MAX_ACTIONS = 100
24
26
  INTERNAL_WAIT = "__waitInfo__"
25
27
  JUDGED_VIEW_GROUP = "nukadoko: view of the judged reading"
@@ -21,8 +21,9 @@ module Nukadoko
21
21
 
22
22
  # `judged_by` says why head's passing executions of a row judged no
23
23
  # claim in Then position (Run.then_judged_by).
24
- #: (Base, Array[Scenario], Hash[Scenario, Array[Hash[Symbol, untyped]]], Array[Environment], String, IO, ?^(Scenario) -> untyped) -> void
25
- def initialize(base, scenarios, head_cells, environments, dir, out, judged_by = ->(_) {})
24
+ #: (Base, Array[Scenario], Hash[Scenario, Array[Hash[Symbol, untyped]]], Array[Environment], String, IO, ?^(Scenario) -> untyped, ?head_root: String) -> void
25
+ def initialize(base, scenarios, head_cells, environments, dir, out, judged_by = ->(_) {}, head_root: Dir.pwd)
26
+ @head_root = head_root
26
27
  @judged_by = judged_by
27
28
  @base = base
28
29
  @scenarios = scenarios
@@ -105,7 +106,9 @@ module Nukadoko
105
106
  plan = File.join(@dir, "trees", "#{world}-#{environment.name}.plan.json")
106
107
  result = File.join(@dir, "trees", "#{world}-#{environment.name}.result.json")
107
108
  targets = rows.map { |scenario| place(world, scenario).then { { feature: _1, line: _2 } } }
108
- File.write(plan, JSON.generate(world: world, environment: environment.name, targets: targets, dir: @dir, result: result))
109
+ config = Nukadoko.config_options.fetch(:secrets, {}) #: Hash[Symbol, untyped]
110
+ head = { root: File.expand_path(@head_root), env_files: environment.env_files, public: (config[:public] || []).map(&:to_s), redact: (config[:redact] || []).map(&:to_s) }
111
+ File.write(plan, JSON.generate(world: world, environment: environment.name, targets: targets, dir: @dir, result: result, head: head))
109
112
  output, status = Open3.capture2e(RbConfig.ruby, "-I", LIB, EXE, "__tree", plan, chdir: root)
110
113
  @out.write(output.gsub(@dir, File.join(".nukadoko", "runs", File.basename(@dir))))
111
114
  return JSON.parse(File.read(result), symbolize_names: true) if File.exist?(result)
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Nukadoko
5
- VERSION = "0.2.0"
5
+ VERSION = "0.4.0"
6
6
  end
data/lib/nukadoko.rb CHANGED
@@ -3,13 +3,18 @@
3
3
 
4
4
  require "json"
5
5
  require_relative "nukadoko/version"
6
+ require_relative "nukadoko/project_files"
7
+ require_relative "nukadoko/spaces"
8
+ require_relative "nukadoko/js_pattern"
6
9
  require_relative "nukadoko/schema"
7
10
  require_relative "nukadoko/step"
8
11
  require_relative "nukadoko/pattern"
9
12
  require_relative "nukadoko/features"
10
13
  require_relative "nukadoko/codes"
11
14
  require_relative "nukadoko/selection"
15
+ require_relative "nukadoko/js_json"
12
16
  require_relative "nukadoko/claims"
17
+ require_relative "nukadoko/claim_sides"
13
18
  require_relative "nukadoko/aria_snapshot"
14
19
  require_relative "nukadoko/judgments"
15
20
  require_relative "nukadoko/judgment_file"
@@ -36,6 +41,8 @@ require_relative "nukadoko/claim_rules"
36
41
  require_relative "nukadoko/definition"
37
42
  require_relative "nukadoko/vocabulary"
38
43
  require_relative "nukadoko/program"
44
+ require_relative "nukadoko/project_program"
45
+ require_relative "nukadoko/parameter_types"
39
46
  require_relative "nukadoko/table"
40
47
  require_relative "nukadoko/order"
41
48
  require_relative "nukadoko/run_record"
@@ -53,10 +60,27 @@ require_relative "nukadoko/init"
53
60
  require_relative "nukadoko/skill"
54
61
 
55
62
  module Nukadoko
63
+ # What a program file of a release before the program moved into the
64
+ # config calls. Only a `--base` ref still holds one, and the run reads it
65
+ # in a process of its own (Engine::ProjectProgram.elsewhere).
56
66
  #: (**untyped) -> Hash[Symbol, untyped]
57
- def self.program(**options) = (@program = options)
67
+ def self.program(**options) = (@legacy_program = options)
68
+ #: () -> Hash[Symbol, untyped]?
69
+ def self.legacy_program = @legacy_program
70
+ # The program under test of the project whose config load_project read.
58
71
  #: () -> Hash[Symbol, untyped]
59
- def self.program_options = @program || {}
72
+ def self.program_options = @program_options || {}
73
+
74
+ # Loads the config of the project at `root`, and reads its program.
75
+ #: (String) -> void
76
+ def self.load_project(root)
77
+ config = File.join(root, Engine::CONFIG)
78
+ @legacy_program = nil
79
+ load config if File.exist?(config)
80
+ Engine::ParameterTypes.read(config_options[:parameterTypes])
81
+ @program_options = Engine::ProjectProgram.read(root)
82
+ end
83
+
60
84
  #: (**untyped) -> Hash[Symbol, untyped]
61
85
  def self.config(**options) = (@config = options)
62
86
  #: () -> Hash[Symbol, untyped]