nukadoko 0.5.0 → 0.7.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 (203) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +553 -3
  3. data/README.ja.md +22 -6
  4. data/README.md +13 -7
  5. data/docs/ci.ja.md +542 -0
  6. data/docs/ci.md +635 -0
  7. data/docs/commands.ja.md +1524 -0
  8. data/docs/commands.md +1281 -0
  9. data/docs/engines.json +19 -0
  10. data/docs/execution-events.ja.md +336 -0
  11. data/docs/execution-events.md +423 -0
  12. data/docs/glossary.json +1348 -0
  13. data/docs/guide.ja.md +733 -0
  14. data/docs/guide.md +815 -0
  15. data/docs/intent.ja.md +133 -0
  16. data/docs/intent.md +156 -0
  17. data/docs/layout.ja.md +442 -0
  18. data/docs/layout.md +399 -0
  19. data/docs/releasing.ja.md +186 -0
  20. data/docs/releasing.md +237 -0
  21. data/docs/ruby/reference.ja.md +302 -0
  22. data/docs/ruby/reference.md +368 -0
  23. data/docs/spec.ja.md +8916 -0
  24. data/docs/spec.md +11250 -0
  25. data/docs/tutorial.ja.md +451 -0
  26. data/docs/tutorial.md +458 -0
  27. data/docs/typescript/adopting.ja.md +231 -0
  28. data/docs/typescript/adopting.md +251 -0
  29. data/docs/typescript/doors.ja.md +301 -0
  30. data/docs/typescript/doors.md +329 -0
  31. data/docs/typescript/migration-playwright-test.ja.md +189 -0
  32. data/docs/typescript/migration-playwright-test.md +212 -0
  33. data/docs/typescript/migration.ja.md +391 -0
  34. data/docs/typescript/migration.md +505 -0
  35. data/docs/typescript/reference.ja.md +176 -0
  36. data/docs/typescript/reference.md +197 -0
  37. data/docs/typescript/upgrading.ja.md +1774 -0
  38. data/docs/typescript/upgrading.md +2224 -0
  39. data/docs/web-app.ja.md +627 -0
  40. data/docs/web-app.md +659 -0
  41. data/docs/writing-scenarios.ja.md +544 -0
  42. data/docs/writing-scenarios.md +563 -0
  43. data/lib/nukadoko/base.rb +12 -5
  44. data/lib/nukadoko/changed_files.rb +95 -0
  45. data/lib/nukadoko/check.rb +459 -51
  46. data/lib/nukadoko/claim_drops.rb +271 -0
  47. data/lib/nukadoko/claim_line.rb +24 -4
  48. data/lib/nukadoko/claim_rules.rb +143 -1
  49. data/lib/nukadoko/claim_sides.rb +157 -9
  50. data/lib/nukadoko/cli.rb +403 -50
  51. data/lib/nukadoko/codes.json +246 -21
  52. data/lib/nukadoko/codes.rb +21 -4
  53. data/lib/nukadoko/command.rb +120 -13
  54. data/lib/nukadoko/command_help.rb +128 -0
  55. data/lib/nukadoko/compat.rb +469 -0
  56. data/lib/nukadoko/criteria.rb +1 -1
  57. data/lib/nukadoko/definition.rb +157 -7
  58. data/lib/nukadoko/error_frames.rb +6 -3
  59. data/lib/nukadoko/events/count.rb +146 -0
  60. data/lib/nukadoko/events/counted.rb +114 -0
  61. data/lib/nukadoko/events/format.rb +257 -0
  62. data/lib/nukadoko/events/lists.rb +154 -0
  63. data/lib/nukadoko/events/path.rb +285 -0
  64. data/lib/nukadoko/events/read.rb +284 -0
  65. data/lib/nukadoko/events/reader.rb +490 -0
  66. data/lib/nukadoko/events/selection.rb +252 -0
  67. data/lib/nukadoko/events/tally.rb +438 -0
  68. data/lib/nukadoko/features.rb +2 -2
  69. data/lib/nukadoko/fixtures.rb +160 -35
  70. data/lib/nukadoko/http_recording.rb +6 -2
  71. data/lib/nukadoko/intent.rb +364 -0
  72. data/lib/nukadoko/intent_file.rb +81 -0
  73. data/lib/nukadoko/intent_view.rb +190 -0
  74. data/lib/nukadoko/js_json.rb +2 -1
  75. data/lib/nukadoko/judge.rb +2 -2
  76. data/lib/nukadoko/judgment_file.rb +22 -1
  77. data/lib/nukadoko/judgments.rb +33 -3
  78. data/lib/nukadoko/measure_mcp.rb +202 -0
  79. data/lib/nukadoko/parts.rb +8 -2
  80. data/lib/nukadoko/path_view.rb +252 -0
  81. data/lib/nukadoko/place_rows.rb +161 -0
  82. data/lib/nukadoko/program.rb +1265 -51
  83. data/lib/nukadoko/program_log.rb +122 -0
  84. data/lib/nukadoko/program_shape.rb +385 -0
  85. data/lib/nukadoko/project_fixtures.rb +43 -10
  86. data/lib/nukadoko/project_program.rb +5 -4
  87. data/lib/nukadoko/repeated_prefix.rb +310 -0
  88. data/lib/nukadoko/report_run.rb +3 -3
  89. data/lib/nukadoko/run.rb +1156 -159
  90. data/lib/nukadoko/run_record.rb +70 -46
  91. data/lib/nukadoko/scaffold.rb +24 -6
  92. data/lib/nukadoko/schema.rb +15 -2
  93. data/lib/nukadoko/secrets.rb +55 -5
  94. data/lib/nukadoko/states.rb +478 -0
  95. data/lib/nukadoko/step.rb +71 -2
  96. data/lib/nukadoko/step_fixtures.rb +52 -3
  97. data/lib/nukadoko/summary.rb +803 -30
  98. data/lib/nukadoko/table.rb +4 -2
  99. data/lib/nukadoko/text_fit.rb +20 -7
  100. data/lib/nukadoko/trace.rb +152 -45
  101. data/lib/nukadoko/tree_passes.rb +95 -33
  102. data/lib/nukadoko/underneath.rb +311 -0
  103. data/lib/nukadoko/verdict.rb +18 -1
  104. data/lib/nukadoko/version.rb +1 -1
  105. data/lib/nukadoko/vocabulary.rb +166 -23
  106. data/lib/nukadoko/walk.rb +2 -2
  107. data/lib/nukadoko/walk_step.rb +1 -1
  108. data/lib/nukadoko.rb +23 -0
  109. data/llms.txt +42 -35
  110. data/sig/generated/nukadoko/base.rbs +4 -4
  111. data/sig/generated/nukadoko/changed_files.rbs +42 -0
  112. data/sig/generated/nukadoko/check.rbs +147 -10
  113. data/sig/generated/nukadoko/claim_drops.rbs +135 -0
  114. data/sig/generated/nukadoko/claim_line.rbs +11 -0
  115. data/sig/generated/nukadoko/claim_rules.rbs +49 -4
  116. data/sig/generated/nukadoko/claim_sides.rbs +63 -12
  117. data/sig/generated/nukadoko/cli.rbs +80 -7
  118. data/sig/generated/nukadoko/codes.rbs +19 -4
  119. data/sig/generated/nukadoko/command.rbs +68 -1
  120. data/sig/generated/nukadoko/command_help.rbs +18 -0
  121. data/sig/generated/nukadoko/compat.rbs +392 -0
  122. data/sig/generated/nukadoko/criteria.rbs +1 -1
  123. data/sig/generated/nukadoko/definition.rbs +50 -0
  124. data/sig/generated/nukadoko/error_frames.rbs +1 -1
  125. data/sig/generated/nukadoko/events/count.rbs +69 -0
  126. data/sig/generated/nukadoko/events/counted.rbs +70 -0
  127. data/sig/generated/nukadoko/events/format.rbs +163 -0
  128. data/sig/generated/nukadoko/events/lists.rbs +47 -0
  129. data/sig/generated/nukadoko/events/path.rbs +161 -0
  130. data/sig/generated/nukadoko/events/read.rbs +109 -0
  131. data/sig/generated/nukadoko/events/reader.rbs +226 -0
  132. data/sig/generated/nukadoko/events/selection.rbs +100 -0
  133. data/sig/generated/nukadoko/events/tally.rbs +227 -0
  134. data/sig/generated/nukadoko/features.rbs +6 -4
  135. data/sig/generated/nukadoko/fixtures.rbs +67 -11
  136. data/sig/generated/nukadoko/http_recording.rbs +1 -1
  137. data/sig/generated/nukadoko/intent.rbs +132 -0
  138. data/sig/generated/nukadoko/intent_file.rbs +46 -0
  139. data/sig/generated/nukadoko/intent_view.rbs +69 -0
  140. data/sig/generated/nukadoko/judgment_file.rbs +7 -1
  141. data/sig/generated/nukadoko/judgments.rbs +10 -0
  142. data/sig/generated/nukadoko/measure_mcp.rbs +104 -0
  143. data/sig/generated/nukadoko/parts.rbs +2 -2
  144. data/sig/generated/nukadoko/path_view.rbs +105 -0
  145. data/sig/generated/nukadoko/place_rows.rbs +43 -0
  146. data/sig/generated/nukadoko/program.rbs +627 -23
  147. data/sig/generated/nukadoko/program_log.rbs +67 -0
  148. data/sig/generated/nukadoko/program_shape.rbs +147 -0
  149. data/sig/generated/nukadoko/project_fixtures.rbs +16 -3
  150. data/sig/generated/nukadoko/project_program.rbs +2 -1
  151. data/sig/generated/nukadoko/repeated_prefix.rbs +172 -0
  152. data/sig/generated/nukadoko/report_run.rbs +1 -1
  153. data/sig/generated/nukadoko/run.rbs +286 -41
  154. data/sig/generated/nukadoko/run_record.rbs +20 -12
  155. data/sig/generated/nukadoko/scaffold.rbs +3 -0
  156. data/sig/generated/nukadoko/schema.rbs +5 -0
  157. data/sig/generated/nukadoko/secrets.rbs +26 -3
  158. data/sig/generated/nukadoko/states.rbs +214 -0
  159. data/sig/generated/nukadoko/step.rbs +58 -1
  160. data/sig/generated/nukadoko/step_fixtures.rbs +39 -0
  161. data/sig/generated/nukadoko/summary.rbs +256 -2
  162. data/sig/generated/nukadoko/table.rbs +3 -2
  163. data/sig/generated/nukadoko/trace.rbs +108 -33
  164. data/sig/generated/nukadoko/tree_passes.rbs +36 -8
  165. data/sig/generated/nukadoko/underneath.rbs +141 -0
  166. data/sig/generated/nukadoko/verdict.rbs +8 -0
  167. data/sig/generated/nukadoko/vocabulary.rbs +45 -6
  168. data/skills/nukadoko/SKILL.md +18 -18
  169. data/skills/nukadoko/references/checking-steps.md +16 -83
  170. data/skills/nukadoko/references/diagnosing.md +6 -6
  171. data/skills/nukadoko/references/done.md +22 -0
  172. data/skills/nukadoko/references/evidence.md +19 -6
  173. data/skills/nukadoko/references/exploring.md +22 -7
  174. data/skills/nukadoko/references/fixtures.md +12 -32
  175. data/skills/nukadoko/references/judgments.md +18 -0
  176. data/skills/nukadoko/references/maintenance.md +1 -1
  177. data/skills/nukadoko/references/merge-risk.md +1 -1
  178. data/skills/nukadoko/references/parts.md +46 -23
  179. data/skills/nukadoko/references/{perturbed-worlds.md → perturbed-systems.md} +30 -12
  180. data/skills/nukadoko/references/program.md +168 -169
  181. data/skills/nukadoko/references/reviewing.md +20 -20
  182. data/skills/nukadoko/references/ruby/checking-steps.md +106 -0
  183. data/skills/nukadoko/references/ruby/examples/cli.md +212 -0
  184. data/skills/nukadoko/references/ruby/fixtures.md +34 -0
  185. data/skills/nukadoko/references/ruby/program.md +112 -0
  186. data/skills/nukadoko/references/ruby/step-files.md +115 -0
  187. data/skills/nukadoko/references/running.md +34 -34
  188. data/skills/nukadoko/references/scenario-rules.md +7 -6
  189. data/skills/nukadoko/references/states.md +7 -1
  190. data/skills/nukadoko/references/step-files.md +41 -120
  191. data/skills/nukadoko/references/typescript/checking-steps.md +129 -0
  192. data/skills/nukadoko/references/{examples → typescript/examples}/cli.md +1 -1
  193. data/skills/nukadoko/references/{examples → typescript/examples}/http-api.md +6 -6
  194. data/skills/nukadoko/references/{examples → typescript/examples}/workflow.md +1 -1
  195. data/skills/nukadoko/references/typescript/fixtures.md +56 -0
  196. data/skills/nukadoko/references/typescript/program.md +111 -0
  197. data/skills/nukadoko/references/typescript/step-files.md +104 -0
  198. data/skills/nukadoko/references/verdicts.md +10 -10
  199. data/skills/nukadoko/references/writing-steps.md +67 -67
  200. data/skills/nukadoko/references/writing-the-feature.md +1 -1
  201. data/skills/nukadoko-verification/SKILL.md +13 -8
  202. metadata +103 -7
  203. data/skills/nukadoko/references/ruby.md +0 -80
@@ -0,0 +1,271 @@
1
+ # frozen_string_literal: true
2
+ # rbs_inline: enabled
3
+
4
+ # Responsibility: why a comparison that came out one way on the values a
5
+ # step's `returns` parsed may have come out otherwise on the values the
6
+ # step returned. A `returns` schema keeps the keys it declares and drops
7
+ # the rest, so a claim that reads such a value judges a copy with keys
8
+ # missing, and a comparison that turns on one of them measures the schema
9
+ # rather than the behaviour. The step record names those keys
10
+ # (`returns_dropped`), and a claim whose answer turns on one is left
11
+ # unjudged with the keys named. The same as the TypeScript engine.
12
+ #
13
+ # Boundary: it reads what a record says and compares the two values it is
14
+ # handed. It takes no value from a step, and it never turns an unjudged
15
+ # claim into a judged one.
16
+ module Nukadoko
17
+ module Engine
18
+ module ClaimDrops
19
+ # One side of a comparison: where its value sits, the args path it
20
+ # sits at, or none (`nil`) for a value the line states, `observe`
21
+ # returned, or a view or a count made, and what the producers of this
22
+ # step's `from` values had their returns drop (`filled`).
23
+ Side = Data.define(
24
+ :place, #: ClaimSides::Place
25
+ :path, #: Array[String]?
26
+ :filled, #: Hash[String, Hash[Symbol, untyped]]
27
+ )
28
+
29
+ # A Data block's methods are its own, but rbs-inline reads only a
30
+ # class body, so they are written in one.
31
+ class Side
32
+ # What was dropped from the object at `rel` inside this side's value.
33
+ #: (Array[String]) -> Hash[Symbol, untyped]?
34
+ def drops(rel)
35
+ at = path
36
+ at && ClaimDrops.dropped_keys_at(filled, [*at, *rel])
37
+ end
38
+ end
39
+
40
+ #: (ClaimSides::Place, Array[String]?, Hash[String, Hash[Symbol, untyped]]) -> Side
41
+ def self.side(place, path, filled) = Side.new(place: place, path: path, filled: filled)
42
+
43
+ # What the producer of a `from` value had its returns drop from the
44
+ # object at the args path `segments`: the entry of its
45
+ # `returns_dropped` at the place, or nil for a key no earlier step
46
+ # filled and for a place where nothing was dropped. A Ruby returns
47
+ # schema is a declaration this engine walks itself, so there is no
48
+ # place it could not see which keys were dropped.
49
+ #: (Hash[String, Hash[Symbol, untyped]], Array[String]) -> Hash[Symbol, untyped]?
50
+ def self.dropped_keys_at(filled, segments)
51
+ key, *path = segments
52
+ found = key && filled[key]
53
+ return nil unless found
54
+
55
+ at = [found[:key].to_s, *path]
56
+ entry = (found[:dropped] || []).find { _1[:at].map(&:to_s) == at }
57
+ entry && { step: found[:step].to_s, keys: entry[:keys].map(&:to_s) }
58
+ end
59
+
60
+ # What was dropped from one object, and where the object sits:
61
+ # `place` and `dropped`.
62
+ #: (Side, Array[String], Hash[Symbol, untyped]) -> Hash[Symbol, untyped]
63
+ def self.found_at(side, rel, dropped)
64
+ { place: ClaimSides.place_at(side.place, rel.join(".")), dropped: dropped }
65
+ end
66
+
67
+ # Whether `key` is one of the keys `dropped` names.
68
+ #: (Hash[Symbol, untyped], String) -> bool
69
+ def self.dropped?(dropped, key) = dropped[:keys].include?(key)
70
+
71
+ # The first object inside `value`, itself included, that had a key
72
+ # dropped, with where it sits.
73
+ #: (untyped, Side, ?Array[String]) -> Hash[Symbol, untyped]?
74
+ def self.first_drop(value, side, rel = [])
75
+ return nil unless value.is_a?(Hash) || value.is_a?(Array)
76
+
77
+ if value.is_a?(Hash)
78
+ dropped = side.drops(rel)
79
+ return found_at(side, rel, dropped) if dropped
80
+ end
81
+ pairs(value).each do |key, item|
82
+ found = first_drop(item, side, [*rel, key])
83
+ return found if found
84
+ end
85
+ nil
86
+ end
87
+
88
+ # An object's keys, or an array's indexes, with their values.
89
+ #: (untyped) -> Array[[String, untyped]]
90
+ def self.pairs(value)
91
+ return value.each_with_index.map { [_2.to_s, _1] } if value.is_a?(Array)
92
+
93
+ value.map { [_1.to_s, _2] }
94
+ end
95
+
96
+ EQUAL = { answer: "equal", via: nil }.freeze #: Hash[Symbol, untyped]
97
+ UNEQUAL = { answer: "unequal", via: nil }.freeze #: Hash[Symbol, untyped]
98
+
99
+ # Whether two values were equal as the steps returned them, before any
100
+ # key was dropped: `equal` or `unequal` for certain, or `unknown`,
101
+ # with the drop the answer turns on (`via`, nil when none does). A
102
+ # dropped key never changes a value's JSON type or an array's length,
103
+ # and a dropped key's value is not known, so two objects can be equal
104
+ # as returned only where each key one of them holds or dropped is a
105
+ # key the other holds or dropped too.
106
+ #: (untyped, untyped, Side, Side, ?Array[String], ?Array[String]) -> Hash[Symbol, untyped]
107
+ def self.raw_equality(a, b, side_a, side_b, rel_a = [], rel_b = [])
108
+ type = Claims.json_type(a)
109
+ return UNEQUAL if type != Claims.json_type(b)
110
+ return array_equality(a, b, side_a, side_b, rel_a, rel_b) if type == "array"
111
+ return a == b ? EQUAL : UNEQUAL if type != "object"
112
+
113
+ object_equality(a, b, side_a, side_b, rel_a, rel_b)
114
+ end
115
+
116
+ #: (Array[untyped], Array[untyped], Side, Side, Array[String], Array[String]) -> Hash[Symbol, untyped]
117
+ def self.array_equality(a, b, side_a, side_b, rel_a, rel_b)
118
+ return UNEQUAL if a.size != b.size
119
+
120
+ open = nil #: Hash[Symbol, untyped]?
121
+ a.each_with_index do |item, index|
122
+ found = raw_equality(item, b[index], side_a, side_b, [*rel_a, index.to_s], [*rel_b, index.to_s])
123
+ return found if found[:answer] == "unequal"
124
+
125
+ open ||= found[:via] if found[:answer] == "unknown"
126
+ end
127
+ open.nil? ? EQUAL : { answer: "unknown", via: open }
128
+ end
129
+
130
+ #: (Hash[String, untyped], Hash[String, untyped], Side, Side, Array[String], Array[String]) -> Hash[Symbol, untyped]
131
+ def self.object_equality(a, b, side_a, side_b, rel_a, rel_b)
132
+ dropped_a = side_a.drops(rel_a)
133
+ dropped_b = side_b.drops(rel_b)
134
+ open = nil #: Hash[Symbol, untyped]?
135
+ (a.keys | b.keys).each do |key|
136
+ if a.key?(key) && b.key?(key)
137
+ found = raw_equality(a[key], b[key], side_a, side_b, [*rel_a, key], [*rel_b, key])
138
+ return found if found[:answer] == "unequal"
139
+
140
+ open ||= found[:via] if found[:answer] == "unknown"
141
+ next
142
+ end
143
+
144
+ # A key one side holds was in the other side's value only if that
145
+ # side's object dropped it.
146
+ side, rel, dropped = a.key?(key) ? [side_b, rel_b, dropped_b] : [side_a, rel_a, dropped_a]
147
+ return UNEQUAL if dropped.nil? || !dropped?(dropped, key)
148
+
149
+ open ||= found_at(side, rel, dropped)
150
+ end
151
+ # Each key an object is known to have dropped was in its value, so
152
+ # the other side's value held it too, or the two differ.
153
+ answer, found = known_drops(dropped_a, b, dropped_b, side_a, rel_a)
154
+ return { answer: "unequal", via: found } if answer
155
+
156
+ open ||= found
157
+ answer, found = known_drops(dropped_b, a, dropped_a, side_b, rel_b)
158
+ return { answer: "unequal", via: found } if answer
159
+
160
+ open ||= found
161
+ open.nil? ? EQUAL : { answer: "unknown", via: open }
162
+ end
163
+
164
+ # Whether the keys one object dropped make the two differ for
165
+ # certain: "unequal" with the drop, or nil with the drop the answer
166
+ # turns on, if any.
167
+ #: (Hash[Symbol, untyped]?, Hash[String, untyped], Hash[Symbol, untyped]?, Side, Array[String]) -> [String?, Hash[Symbol, untyped]?]
168
+ def self.known_drops(dropped, other, other_dropped, side, rel)
169
+ return [nil, nil] if dropped.nil?
170
+
171
+ via = nil #: Hash[Symbol, untyped]?
172
+ dropped[:keys].each do |key|
173
+ return ["unequal", found_at(side, rel, dropped)] if !other.key?(key) && (other_dropped.nil? || !dropped?(other_dropped, key))
174
+
175
+ via ||= found_at(side, rel, dropped)
176
+ end
177
+ [nil, via]
178
+ end
179
+
180
+ # Why a comparison that came out `holds` on the values the steps'
181
+ # returns parsed may come out otherwise on the values the steps
182
+ # returned, or nil. A dropped key never changes a text, a number, a
183
+ # kind, or an array's length, so only these compares turn on one:
184
+ # `lacks-field` on a field the object dropped, `equal`, `not-equal`,
185
+ # `has-item`, and `has-same-items` where the values as returned may
186
+ # differ in such a key, and `has-fields`, which holds on an actual
187
+ # object with more keys, where the expected object had a key dropped.
188
+ # A broken comparison stays broken, except in a `where` clause, where
189
+ # it decides which items an `each` selects.
190
+ #: (String, bool, Hash[Symbol, untyped], Hash[Symbol, untyped], bool) -> String?
191
+ def self.change(compare, holds, actual, expected, where)
192
+ return nil if !holds && !where
193
+
194
+ case compare
195
+ when "lacks-field" then lacks_field_change(holds, actual, expected)
196
+ when "equal", "not-equal" then equality_change(compare, holds, actual, expected)
197
+ when "has-item" then has_item_change(holds, actual, expected)
198
+ when "has-same-items" then same_items_change(holds, actual, expected)
199
+ when "has-fields" then has_fields_change(holds, actual, expected)
200
+ end
201
+ end
202
+
203
+ #: (bool, Hash[Symbol, untyped], Hash[Symbol, untyped]) -> String?
204
+ def self.lacks_field_change(holds, actual, expected)
205
+ # A key the parsed object holds is no key its returns dropped.
206
+ return nil unless holds
207
+
208
+ field = expected[:value].to_s
209
+ dropped = actual[:side].drops([])
210
+ return nil if dropped.nil? || !dropped?(dropped, field)
211
+
212
+ reason(found_at(actual[:side], [], dropped), "the #{field} field was there")
213
+ end
214
+
215
+ #: (String, bool, Hash[Symbol, untyped], Hash[Symbol, untyped]) -> String?
216
+ def self.equality_change(compare, holds, actual, expected)
217
+ parsed_equal = compare == "equal" ? holds : !holds
218
+ equality = raw_equality(actual[:value], expected[:value], actual[:side], expected[:side])
219
+ return nil if equality[:answer] == (parsed_equal ? "equal" : "unequal") || equality[:via].nil?
220
+
221
+ consequence = if !parsed_equal then "the two values may have been equal as returned"
222
+ elsif equality[:answer] == "unequal" then "the two values differed as returned"
223
+ else "the two values may have differed as returned"
224
+ end
225
+ reason(equality[:via], consequence)
226
+ end
227
+
228
+ #: (bool, Hash[Symbol, untyped], Hash[Symbol, untyped]) -> String?
229
+ def self.has_item_change(holds, actual, expected)
230
+ via = nil #: Hash[Symbol, untyped]?
231
+ actual[:value].each_with_index do |item, index|
232
+ next if holds && item != expected[:value]
233
+
234
+ equality = raw_equality(item, expected[:value], actual[:side], expected[:side], [index.to_s], [])
235
+ return nil if holds && equality[:answer] == "equal"
236
+
237
+ unless holds || equality[:answer] == "unequal"
238
+ return equality[:via].nil? ? nil : reason(equality[:via], "an item may have equaled the expected value as returned")
239
+ end
240
+
241
+ via ||= equality[:via]
242
+ end
243
+ holds && via ? reason(via, "no item is known to have equaled the expected value as returned") : nil
244
+ end
245
+
246
+ #: (bool, Hash[Symbol, untyped], Hash[Symbol, untyped]) -> String?
247
+ def self.same_items_change(holds, actual, expected)
248
+ return nil if !holds && actual[:value].size != expected[:value].size
249
+
250
+ via = first_drop(actual[:value], actual[:side]) || first_drop(expected[:value], expected[:side])
251
+ via && reason(via, holds ? "the items may have differed as returned" : "the items may have been the same as returned")
252
+ end
253
+
254
+ #: (bool, Hash[Symbol, untyped], Hash[Symbol, untyped]) -> String?
255
+ def self.has_fields_change(holds, actual, expected)
256
+ via = holds ? first_drop(expected[:value], expected[:side]) : first_drop(actual[:value], actual[:side])
257
+ via && reason(via, holds ? "the expected value may have held a field the actual value lacks" : "the actual value may have held the expected fields as returned")
258
+ end
259
+
260
+ # The reason a claim is not judged, naming the step, the place, and
261
+ # what it dropped there, then `consequence`.
262
+ #: (Hash[Symbol, untyped], String) -> String
263
+ def self.reason(found, consequence)
264
+ place = found[:place]
265
+ dropped = found[:dropped]
266
+ what = %(step "#{dropped[:step]}" returned #{dropped[:keys].join(", ")} at #{place.label}, and its returns dropped #{dropped[:keys].size == 1 ? "it" : "them"})
267
+ "#{what}, so #{consequence}, and the claim was not judged"
268
+ end
269
+ end
270
+ end
271
+ end
@@ -19,9 +19,13 @@ module Nukadoko
19
19
 
20
20
  module_function
21
21
 
22
+ # JavaScript has one number type, so a line of the TypeScript engine
23
+ # reads a whole number as digits alone. A Ruby step that writes a
24
+ # literal 2.0 states the same number as one that writes 2, and a line
25
+ # that showed `2.0` would read as another value.
22
26
  #: (untyped) -> String
23
27
  def value_text(value)
24
- text = JSON.generate(value)
28
+ text = JsJson.generate(value)
25
29
  text.size > VALUE_TEXT_LIMIT ? "#{text[0, VALUE_TEXT_LIMIT]}..." : text
26
30
  end
27
31
 
@@ -30,7 +34,10 @@ module Nukadoko
30
34
 
31
35
  #: (Hash[Symbol, untyped]) -> String
32
36
  def comparison_text(record)
33
- actual = record.key?(:actual) ? snapshot_excerpt_text(record) || "#{value_text(record[:actual])} (#{record[:actual_from]})" : record[:actual_from]
37
+ actual = if record.key?(:actual) then snapshot_excerpt_text(record) || "#{value_text(record[:actual])} (#{record[:actual_from]})"
38
+ elsif record[:actual_range] then "#{Events::Count.describe_range(record[:actual_range])} (#{record[:actual_from]})"
39
+ else record[:actual_from]
40
+ end
34
41
  "#{actual} #{record[:compare]} #{expected_text(record)}"
35
42
  end
36
43
 
@@ -332,6 +339,19 @@ module Nukadoko
332
339
  difference ? "; #{difference}" : ""
333
340
  end
334
341
 
342
+ # What a count of execution events counted, after its outcome and its
343
+ # reason, under every outcome: a count that held on the wrong table
344
+ # reads as plainly as one that broke on it. Then what it left out,
345
+ # since the program marks their table.
346
+ #: (Hash[Symbol, untyped]) -> String
347
+ def counted_text(record)
348
+ return "" if each?(record)
349
+
350
+ counted = record[:counted] ? Events::Counted.describe(record[:counted]) : ""
351
+ left_out = record[:left_out] ? Events::Counted.describe_left_out(record[:left_out]) : ""
352
+ "#{"; counted #{counted}" unless counted.empty?}#{"; left out #{left_out}" unless left_out.empty?}"
353
+ end
354
+
335
355
  #: (Hash[Symbol, untyped]) -> String
336
356
  def reason_text(record) = record[:reason] ? ": #{record[:reason]}" : difference_text(record)
337
357
 
@@ -354,7 +374,7 @@ module Nukadoko
354
374
  # first broken item and that item's first broken comparison.
355
375
  #: (Hash[Symbol, untyped]) -> String
356
376
  def line(record)
357
- text = "#{claim_text(record)} #{record[:outcome]}#{reason_text(record)}"
377
+ text = "#{claim_text(record)} #{record[:outcome]}#{reason_text(record)}#{counted_text(record)}"
358
378
  return text unless each?(record)
359
379
 
360
380
  item = named_item(record)
@@ -373,7 +393,7 @@ module Nukadoko
373
393
  #: (Array[Hash[Symbol, untyped]]) -> String
374
394
  def broken_claims_message(records)
375
395
  records.select { %w[broken unjudged].include?(_1[:outcome]) }.flat_map do |record|
376
- ["claim #{record[:outcome]}: #{claim_text(record)}#{reason_text(record)}", *(each?(record) ? named_item_lines(record) : [])]
396
+ ["claim #{record[:outcome]}: #{claim_text(record)}#{reason_text(record)}#{counted_text(record)}", *(each?(record) ? named_item_lines(record) : [])]
377
397
  end.join("\n")
378
398
  end
379
399
  end
@@ -22,8 +22,22 @@ module Nukadoko
22
22
  :from_keys, #: Array[String]
23
23
  :capture_keys, #: Array[String]
24
24
  :observe, #: bool
25
+ # The keys of the step's files, each a list a claim reads by its key alone.
26
+ :files, #: Array[String]
27
+ # The keys of the step's events, each a count a claim reads by its key alone.
28
+ :events, #: Array[String]
29
+ # Each value a selection takes from the sentence: the events key,
30
+ # the field, and the args key that holds the value.
31
+ :events_sentence, #: Array[Hash[Symbol, String]]
25
32
  )
26
33
 
34
+ # A Data block's methods are its own, but rbs-inline reads only a class
35
+ # body, so they are written in one.
36
+ class Shape
37
+ #: (?files: Array[String], ?events: Array[String], ?events_sentence: Array[Hash[Symbol, String]], **untyped) -> void
38
+ def initialize(files: [], events: [], events_sentence: [], **rest) = super
39
+ end
40
+
27
41
  VIEWS = %w[text lines json comma-list].freeze
28
42
  COMPARISON_KEYS = %w[actual view at count compare expected expected_view].freeze
29
43
  EACH_CLAIM_KEYS = %w[actual view at each].freeze
@@ -365,7 +379,19 @@ module Nukadoko
365
379
  refuse("#{label} must be an object with actual, compare, and expected, or actual and each") unless claim.is_a?(Hash)
366
380
 
367
381
  check_path("#{label}.actual", claim[:actual], false)
382
+ if shape.files.include?(claim[:actual])
383
+ check_files_claim(label, claim, claim[:actual], shape)
384
+ next
385
+ end
368
386
  head = claim[:actual].split(".").first.to_s
387
+ refuse(%(#{label}.actual reads inside files.#{head}, a list of paths with nothing to walk into. Name the key alone: actual "#{head}")) if shape.files.include?(head)
388
+ if shape.events.include?(claim[:actual])
389
+ check_events_claim(label, claim, claim[:actual], shape)
390
+ next
391
+ end
392
+ if shape.events.include?(head)
393
+ refuse(%(#{label}.actual reads inside events.#{head}, a count of execution events, which is one number with nothing inside it. Name the key alone: actual "#{head}"))
394
+ end
369
395
  from_observe = !shape.from_keys.include?(head)
370
396
  refuse(%(#{label}.actual starts with "#{head}", which is not a key of this step's from, and the step has no observe to read it)) if from_observe && !shape.observe
371
397
  if !from_observe && shape.capture_keys.include?(head)
@@ -384,10 +410,125 @@ module Nukadoko
384
410
  check_common(label, claim)
385
411
  check_each(label, claim[:each], shape, from_observe)
386
412
  end
413
+ check_events(claims, shape)
414
+ check_files(claims, shape)
387
415
  check_observe_read(claims, shape)
388
416
  check_captures_read(claims, shape)
389
417
  end
390
418
 
419
+ # The compares a list of paths can take: a text or order compare
420
+ # breaks on an array on every line, and is-a list holds on every one.
421
+ FILES_COMPARES = %w[equal not-equal has-item has-same-items].freeze
422
+ FILES_CLAIM_KEYS = %w[actual count compare expected expected_view].freeze
423
+
424
+ # A claim on a files key reads the list nukadoko made from an earlier
425
+ # step's record, so it takes no path, view, or at, and compares the
426
+ # whole list or its count. Its expected value is the sentence's: a
427
+ # list from { from } or { observe } would be one step code chose.
428
+ #: (String, Hash[Symbol, untyped], String, Shape) -> void
429
+ def check_files_claim(label, claim, key, shape)
430
+ reads = "#{label} reads files.#{key}, the list of paths an earlier step's commands changed"
431
+ refuse("#{reads}, and a claim on it compares the whole list or counts it. Compare it with #{FILES_COMPARES.join(", ")}, or count it") unless claim[:each].nil?
432
+ check_keys(label, claim, FILES_CLAIM_KEYS, "a claim on files")
433
+ expected = claim[:expected]
434
+ if expected.is_a?(Hash) && (expected.key?(:from) || expected.key?(:observe))
435
+ source = expected.key?(:from) ? "from" : "observe"
436
+ refuse("#{reads}, and its expected value is { #{source} }, a value step code #{source == "from" ? "returned" : "read"}, so step code would choose the list the measured one is compared with. " \
437
+ "State the expected paths in the sentence: a capture, the docstring, or the pattern's words")
438
+ end
439
+ if claim[:count].nil? && !FILES_COMPARES.include?(claim[:compare])
440
+ refuse("#{reads}, which is an array of paths, and #{describe(claim[:compare])} does not compare it, so the claim would break on every line or hold on every line. " \
441
+ "Compare it with #{FILES_COMPARES.join(", ")}, or count it")
442
+ end
443
+ check_expected(label, expected, claim[:compare], shape, false)
444
+ check_expected_view(label, claim, shape)
445
+ check_count(label, claim)
446
+ return unless claim[:count].nil?
447
+
448
+ # has-item compares with one path, and the other compares with a
449
+ # list: an expected value of the other kind breaks the claim on
450
+ # every line, or, under not-equal, holds on every one.
451
+ one = claim[:compare] == "has-item"
452
+ wanted = one ? "a text" : "an array"
453
+ fix = one ? "State the path in the pattern's fixed words, or capture it" : "State the list with a word such as nothing or no, or read the docstring with expected_view lines"
454
+ literal = literal_of(expected)
455
+ if literal && (one ? !literal[:literal].is_a?(String) : !literal[:literal].is_a?(Array))
456
+ refuse("#{reads}, and its expected value is the literal #{describe(literal[:literal])}, which is never #{wanted}, so #{claim[:compare]} judges it the same way on every line. #{fix}")
457
+ end
458
+ return unless expected.is_a?(String) && shape.string_args.include?(expected)
459
+
460
+ view = claim[:expected_view]
461
+ makes = view.nil? ? "string" : VIEW_MAKES[view]
462
+ return if makes.nil? || makes == (one ? "string" : "array")
463
+
464
+ how = view.nil? ? "a plain z.string()" : "a plain z.string() read through expected_view #{view}"
465
+ refuse("#{reads}, and its expected value is args.#{expected}, #{how}, which is never #{wanted}, so #{claim[:compare]} judges it the same way on every line. #{fix}")
466
+ end
467
+
468
+ EVENTS_CLAIM_KEYS = %w[actual compare expected].freeze
469
+
470
+ # A claim on an events key reads the count nukadoko measured, one
471
+ # number, so it takes no path, view, at, or count, and compares the
472
+ # count with a number the line states.
473
+ #: (String, Hash[Symbol, untyped], String, Shape) -> void
474
+ def check_events_claim(label, claim, key, shape)
475
+ reads = "#{label} reads events.#{key}, a count of execution events"
476
+ refuse("#{reads}, which is one number, and each reads the items of an array. Compare the count with #{COUNT_COMPARES.join(", ")}") unless claim[:each].nil?
477
+ check_keys(label, claim, EVENTS_CLAIM_KEYS, "a claim on a count of execution events")
478
+ unless COUNT_COMPARES.include?(claim[:compare])
479
+ refuse("#{reads}, which is a number, and #{describe(claim[:compare])} does not compare two numbers, so the claim would break on every line or hold on every line. " \
480
+ "Compare the count with #{COUNT_COMPARES.join(", ")}")
481
+ end
482
+ check_expected(label, claim[:expected], claim[:compare], shape, false)
483
+ literal = literal_of(claim[:expected])
484
+ if literal && !literal[:literal].is_a?(Numeric)
485
+ refuse("#{reads}, which is a number, and its expected value is the literal #{describe(literal[:literal])}, which is never a number, so the claim always breaks. " \
486
+ "State the number in the pattern, as digits, a number word, once, twice, or a word such as nothing or never, and write it as a number literal")
487
+ end
488
+ return unless claim[:expected].is_a?(String) && shape.string_args.include?(claim[:expected])
489
+
490
+ refuse("#{reads}, which is a number, and its expected value is args.#{claim[:expected]}, a plain z.string(), which is never a number, so the claim always breaks. Capture the number with {int}")
491
+ end
492
+
493
+ # An events key that collides with another source of a claim's
494
+ # actual, takes a sentence value an expected sentence key could not
495
+ # be, or names a count no claim reads.
496
+ #: (Array[Hash[Symbol, untyped]], Shape) -> void
497
+ def check_events(claims, shape)
498
+ shape.events.each do |key|
499
+ other = if shape.from_keys.include?(key) then "a key of from"
500
+ elsif shape.args_keys.include?(key) || shape.capture_keys.include?(key) then "an args key"
501
+ end
502
+ refuse(%(events.#{key} has the name of #{other}, so a claim's actual "#{key}" would have two sources. Rename one of them)) if other
503
+ next if claims.any? { _1[:actual] == key }
504
+
505
+ refuse(%(events.#{key} is read by no claim, so the count it names changes no verdict. Compare a claim with actual "#{key}", or take the key out of events))
506
+ end
507
+ shape.events_sentence.each do |value|
508
+ label = "events.#{value[:key]}.count.#{value[:field]}"
509
+ if shape.from_keys.include?(value[:name])
510
+ refuse(%(#{label} takes { sentence: "#{value[:name]}" }, which from fills from an earlier step, and a selection takes a value the line states))
511
+ end
512
+ refuse(%(#{label} takes { sentence: "#{value[:name]}" }, which is not a key of args)) unless shape.args_keys.include?(value[:name])
513
+ end
514
+ end
515
+
516
+ # A files key that collides with another source of a claim's actual,
517
+ # or that no claim reads.
518
+ #: (Array[Hash[Symbol, untyped]], Shape) -> void
519
+ def check_files(claims, shape)
520
+ shape.files.each do |key|
521
+ other = if shape.from_keys.include?(key) then "a key of from"
522
+ elsif shape.args_keys.include?(key) || shape.capture_keys.include?(key) then "an args key"
523
+ elsif shape.events.include?(key) then "a key of events"
524
+ end
525
+ refuse(%(files.#{key} has the name of #{other}, so a claim's actual "#{key}" would have two sources. Rename one of them)) if other
526
+ next if claims.any? { _1[:actual] == key }
527
+
528
+ refuse(%(files.#{key} is read by no claim, so the list it names changes no verdict. Compare a claim with actual "#{key}", or take the key out of files))
529
+ end
530
+ end
531
+
391
532
  #: (String, untyped, Shape, bool) -> void
392
533
  def check_each(label, each, shape, from_observe)
393
534
  refuse("#{label}.each.claims must be a non-empty array of claims on one item") if !each.is_a?(Hash) || !each[:claims].is_a?(Array) || each[:claims].empty?
@@ -471,6 +612,7 @@ module Nukadoko
471
612
  return unless shape.observe
472
613
 
473
614
  read = claims.any? do |claim|
615
+ next false if shape.files.include?(claim[:actual]) || shape.events.include?(claim[:actual])
474
616
  next true unless shape.from_keys.include?(claim[:actual].to_s.split(".").first.to_s)
475
617
 
476
618
  entries = claim[:each] ? [*(claim[:each][:where] || []), *claim[:each][:claims]] : [claim]
@@ -489,7 +631,7 @@ module Nukadoko
489
631
  def check_captures_read(claims, shape)
490
632
  return if shape.observe
491
633
 
492
- read = keys_read(claims)
634
+ read = keys_read(claims) + shape.events_sentence.map { _1[:name] }
493
635
  unread = shape.capture_keys.find { !read.include?(_1) }
494
636
  return unless unread
495
637