kiosk-test-support 0.5.20

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 (38) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +149 -0
  3. data/LICENSE.txt +202 -0
  4. data/README.md +146 -0
  5. data/lib/kiosk/story_spec.rb +6 -0
  6. data/lib/kiosk/story_test.rb +16 -0
  7. data/lib/kiosk/test_helpers/assistant/events.rb +135 -0
  8. data/lib/kiosk/test_helpers/assistant.rb +151 -0
  9. data/lib/kiosk/test_helpers/conformance/checks/declared_shape.rb +91 -0
  10. data/lib/kiosk/test_helpers/conformance/checks/executes.rb +57 -0
  11. data/lib/kiosk/test_helpers/conformance/checks/helpers.rb +112 -0
  12. data/lib/kiosk/test_helpers/conformance/checks/principal_scope.rb +104 -0
  13. data/lib/kiosk/test_helpers/conformance/checks/routes.rb +94 -0
  14. data/lib/kiosk/test_helpers/conformance/checks.rb +45 -0
  15. data/lib/kiosk/test_helpers/conformance/in_process_origin.rb +121 -0
  16. data/lib/kiosk/test_helpers/conformance/minitest.rb +57 -0
  17. data/lib/kiosk/test_helpers/conformance/null_origin.rb +55 -0
  18. data/lib/kiosk/test_helpers/conformance/outcome.rb +25 -0
  19. data/lib/kiosk/test_helpers/conformance/rspec.rb +100 -0
  20. data/lib/kiosk/test_helpers/conformance/verb.rb +36 -0
  21. data/lib/kiosk/test_helpers/conformance.rb +46 -0
  22. data/lib/kiosk/test_helpers/customer.rb +154 -0
  23. data/lib/kiosk/test_helpers/descriptor_examples.rb +46 -0
  24. data/lib/kiosk/test_helpers/errors.rb +55 -0
  25. data/lib/kiosk/test_helpers/in_process_executor.rb +198 -0
  26. data/lib/kiosk/test_helpers/in_process_wire.rb +90 -0
  27. data/lib/kiosk/test_helpers/journey.rb +98 -0
  28. data/lib/kiosk/test_helpers/kyc.rb +98 -0
  29. data/lib/kiosk/test_helpers/live_server.rb +56 -0
  30. data/lib/kiosk/test_helpers/null_executor.rb +95 -0
  31. data/lib/kiosk/test_helpers/person.rb +52 -0
  32. data/lib/kiosk/test_helpers/small_equihash.rb +18 -0
  33. data/lib/kiosk/test_helpers/story.rb +36 -0
  34. data/lib/kiosk/test_helpers/stripe_mock.rb +146 -0
  35. data/lib/kiosk/test_helpers/version.rb +7 -0
  36. data/lib/kiosk/test_helpers/wire.rb +124 -0
  37. data/lib/kiosk/test_helpers.rb +28 -0
  38. metadata +205 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 82f1f47c2715da7a7ef6897038c156d7033991f159d7dea50446ee3af8933d01
4
+ data.tar.gz: 0b06db9324f1ea8d0e7e11036f756db6e4eef3fffc9899961506e95f0f999183
5
+ SHA512:
6
+ metadata.gz: 4b1c2beec651bb6bb2836c28cb5440903d113867d91f33bce3bdd42625c5d34336b0916332e39b3d92b60d5633668074decb3c5c2169597fd6c036c7b274595f
7
+ data.tar.gz: 66c9376f8e27a37bd455f503fa34f1617d8e7e790eb348fc44075494cc81e386f9e1ec23593a86f011781ec537909ec5a14a2feba01f7cb4fa4cee1684ccbbc9
data/CHANGELOG.md ADDED
@@ -0,0 +1,149 @@
1
+ # Changelog
2
+
3
+ All notable changes follow [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/).
4
+
5
+ How to write an entry, and what a release section means: `CHANGELOG-RULE.md` at
6
+ the root of this repository —
7
+ <https://github.com/kiosk-hq/kiosk/blob/main/CHANGELOG-RULE.md>. In short: under
8
+ 200 characters, one or two sentences, the essence rather than the content; write it
9
+ under `## [Unreleased]`; a cut renames that heading to
10
+ `## [MAJOR.MINOR.PATCH] — <date>` and opens a fresh empty one above it; nothing
11
+ already written is edited.
12
+
13
+ ## [Unreleased]
14
+
15
+ ## [0.5.20] — 2026-10-20
16
+
17
+ - 2026-10-20: `InProcessOrigin` and `InProcessExecutor` call a verb through its route with a linked assistant's token; `InProcessWire` does the call.
18
+ - 2026-10-20: The conformance checks hold an action's arguments to its `input_schema` with no exemption for `limit` or `cursor`, as the wire does.
19
+
20
+ ## [0.5.19] — 2026-10-20
21
+
22
+ - 2026-10-19: `Wire` and `Assistant::Events` connect to a base URL that names an IPv6 literal, such as `http://[::1]:3001`.
23
+
24
+ ## [0.5.18] — 2026-10-18
25
+
26
+ - 2026-10-18: Version 0.5.18, the tree cut that matches skill 0.5.18.
27
+
28
+ ## [0.5.17] — 2026-10-18
29
+
30
+ - 2026-10-18: `StripeMock` runs one stripe-mock per process on free ports unless `STRIPE_MOCK_URL` names one; `StripeMock.url` replaces `URL`.
31
+
32
+ ## [0.5.16] — 2026-10-18
33
+
34
+ - 2026-10-18: The Stripe test front answers a refund that names no charge with a 400, as Stripe does.
35
+
36
+ ## [0.5.15] — 2026-10-18
37
+
38
+ - 2026-10-18: `Kiosk::TestHelpers::Customer#pays_cart(cart, scope:)` signs the `cart` an action answered with and pays.
39
+
40
+ - 2026-10-18: `Kiosk::StoryTest#assert_refused(answer, code)` asserts a wire refusal and prints the answer when it fails.
41
+
42
+ - 2026-10-18: Declares `puma`, which the live server helper requires; a RubyGems install no longer fails to load it.
43
+
44
+ ## [0.5.14] — 2026-10-18
45
+
46
+ - 2026-10-18: Version 0.5.14, the tree cut that matches skill 0.5.14.
47
+
48
+ - 2026-10-17: New `kiosk/test_helpers/small_equihash`: required from test setup, it makes the Equihash default n=96 k=5 so test registrations stay fast.
49
+
50
+ - 2026-10-17: Adds InProcessExecutor and Conformance::InProcessOrigin, moved from kiosk-server. Require them explicitly; they run against the host's kiosk-server.
51
+
52
+ - 2026-10-17: `Assistant#pay` calls `payment_setup` when `pay` answers `payment_setup_required`, then pays once more.
53
+
54
+ - 2026-10-17: `Customer#leaves` is removed; nothing called it.
55
+ - 2026-10-17: `Person#links_a_newcomer` links a newly keyed assistant to the signed-in person, for scripts that need a bound principal.
56
+
57
+ ## [0.5.13] — 2026-10-11
58
+
59
+ - 2026-10-11: Version 0.5.13, the tree cut that matches skill 0.5.13.
60
+
61
+ - 2026-10-09: **A story's `Person` links, approves and unlinks assistants**, and a `Customer` pays a quote, signs back in, follows news checked against its schema; `kiosk/story_spec` is RSpec's form.
62
+
63
+ - 2026-10-09: **`Kiosk::StoryTest` and `Kiosk::TestHelpers::Story`** let a test tell an operator's business story through a `Customer` who asks, does, pays and hears.
64
+
65
+ - 2026-10-09: **`Assistant` drives an origin as an assistant does; `Kyc` stands in for the KYC provider** so a test decides how a check ends. `Wire` and `StripeMock` move here.
66
+
67
+ - 2026-10-09: **`LiveServer` and `SeededDatabase`** serve the app over HTTP from the test process on committed, seeded data; **`DescriptorExamples`** checks each published example against its schema.
68
+
69
+ ## [0.5.12] — 2026-10-08
70
+
71
+ - 2026-10-08: Version 0.5.12, the tree cut that matches skill 0.5.12; this gem's surface is unchanged.
72
+
73
+ ## [0.5.11] — 2026-10-08
74
+
75
+ - 2026-10-08: Version 0.5.11, the tree cut that matches skill 0.5.11; this gem's surface is unchanged.
76
+
77
+ ## [0.5.10] — 2026-10-08
78
+
79
+ - 2026-10-08: Version 0.5.10, the tree cut that matches skill 0.5.10; this gem's surface is unchanged.
80
+
81
+ ## [0.5.9] — 2026-10-08
82
+
83
+ - 2026-10-08: Version 0.5.9, the tree cut that matches skill 0.5.9; this gem's surface is unchanged.
84
+
85
+ ## [0.5.8] — 2026-10-07
86
+
87
+ - 2026-10-07: Version 0.5.8, the tree cut that matches skill 0.5.8; this gem's surface is unchanged.
88
+
89
+ ## [0.5.7] — 2026-10-07
90
+
91
+ - 2026-10-07: Version 0.5.7, the tree cut that matches skill 0.5.7; this gem's surface is unchanged.
92
+
93
+ ## [0.5.6] — 2026-10-07
94
+
95
+ - 2026-10-07: Version 0.5.6, the tree cut that matches skill 0.5.6; this gem's surface is unchanged.
96
+
97
+ ## [0.5.5] — 2026-10-07
98
+
99
+ - 2026-10-07: Version 0.5.5, the tree cut that matches skill 0.5.5; this gem's surface is unchanged.
100
+
101
+ ## [0.5.4] — 2026-10-07
102
+
103
+ - 2026-10-07: Version 0.5.4, the tree cut that matches skill 0.5.4; this gem's surface is unchanged.
104
+
105
+ ## [0.5.3] — 2026-10-06
106
+
107
+ - 2026-10-06: Version 0.5.3, the tree cut that matches skill 0.5.3; this gem's surface is unchanged.
108
+
109
+ ## [0.5.2] — 2026-10-06
110
+
111
+ - 2026-10-06: Version 0.5.2, the tree cut that matches skill 0.5.2; this gem's surface is unchanged.
112
+
113
+ ## [0.5.0] — 2026-09-26
114
+
115
+ ### Removed
116
+
117
+ - **`NullExecutor#identity_stack` is no longer public, and `enqueue_action` is now `enqueue_run_action` (K-1708).** Ask `current_identity`; every rig helper is named for the kind it queues.
118
+
119
+ - **`Conformance::Verb#action?` and `Conformance::Outcome#to_s`, neither of which had a caller anywhere (K-1703).** `kind` and `message` are public and say the same.
120
+
121
+ ### Changed
122
+
123
+ - **`have_a_route_for_every_verb` took no block parameter, so `origin:` was accepted and discarded (K-1702).** It now honours the keyword its Minitest twin honours.
124
+
125
+ - **The published journey-helper roll-call was short by `run_query` (K-1696).** The lists name it now, and the two «helpers are available» tests are held to the module rather than to themselves.
126
+
127
+ - The route conformance check no longer special-cases the engine's refusal controller, which no longer exists: a declared verb whose route is missing is reported as declared-and-never-routed, which is what every caller now meets as an ordinary 404.
128
+ - README: every `gem` line in the install section now carries `github: "kiosk-hq/kiosk"`, so a copied line resolves before publication; the banner above them states what the block does rather than asking the reader to add it.
129
+ - Dropped the `kiosk-rls` dependency (RLS is opt-in now). This gem never
130
+ used `Kiosk::RLS` constants — `Errors::RLSDenied` is its own class and
131
+ stays.
132
+
133
+ ### Added
134
+
135
+ - `Kiosk::TestHelpers::Conformance` — four checks an origin runs against itself for the four properties the protocol makes normative of it: that its routes resolve, that a verb executes, that a query answers the shape it declared, and that data access is scoped to the authenticated principal. Inert until an origin is wired (`Conformance.origin=`); `kiosk-server` ships the real one.
136
+ - Two adapters, loaded by explicit require so this gem still depends on no test framework: `kiosk/test_helpers/conformance/minitest` (`assert_kiosk_verbs_routed`, `assert_kiosk_verb_executes`, `assert_kiosk_answer_matches_declared_schema`, `assert_kiosk_scoped_to_principal`) and `kiosk/test_helpers/conformance/rspec` (`have_a_route_for_every_verb`, `execute_as_a_kiosk_verb`, `answer_its_declared_schema`, `be_scoped_to_principal`). Both render the same failure sentence.
137
+ - `Kiosk::TestHelpers::Conformance::NullOrigin` — the zero-dependency reference implementation of the origin contract, for unit-shaped tests with no Rails and no database.
138
+ - `Journey#run_query(name, **args)` and a matching `run_query` on the executor contract. `query` takes SQL; without this, a declared `kind :query` verb was reachable through nothing.
139
+ - `Errors::OriginNotConfigured` and `Errors::SchemaValidatorMissing`, both carrying wiring instructions.
140
+
141
+ - Initial skeleton.
142
+ - `Kiosk::TestHelpers::Journey` module — the journey-test DSL: `as_agent_of`, `as_user`, `as_agent`, `as_anonymous`, `query`, `run_action`, `pay_action`, `kiosk_seed`.
143
+ - Pluggable executor contract — `Kiosk::TestHelpers.executor=` accepts any object responding to `with_identity(identity, &block)`, `query(sql)`, `run_action(name, args)`, `pay_action(name, args)`, `seed(table, attrs, count:)`. Default is unset; raises `Kiosk::TestHelpers::Errors::ExecutorNotConfigured` until wired.
144
+ - `Kiosk::TestHelpers::NullExecutor` — records calls into an inspectable array; queues seeded results. Used by this gem's own specs and by `kiosk-rls-rspec` / `kiosk-rls-minitest` self-tests; `kiosk-server` ships the real `Kiosk::Server::TestExecutor` for production-shaped tests.
145
+ - `Kiosk::TestHelpers::Errors` — `RLSDenied`, `QuotaExceeded`, `ExecutorNotConfigured`. Used by the framework-specific matchers / assertions.
146
+
147
+ ### Notes on the three-gem split
148
+
149
+ The journey-test DSL was originally scoped to live inside `kiosk-rls-rspec` and `kiosk-rls-minitest`. We split the shared module out into this third gem so both harness gems can `include Kiosk::TestHelpers::Journey` without duplication or one harness depending on the other. The two harness gems remain ≤200 LOC each (framework wiring only); the shared DSL fits in ≤400 LOC here.
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # kiosk-test-support
2
+
3
+ Test helpers for [Kiosk](https://kiosk.tech) origins, and the journey-test DSL of the Kiosk test harnesses.
4
+
5
+ ## What it does
6
+
7
+ - `Kiosk::TestHelpers::Assistant` — registers, pays tolls, queries, runs actions, pays and listens for events against an origin, as an AI assistant does.
8
+ - `Kiosk::TestHelpers::Wire` — the same transport without a principal: any method, any path, any headers.
9
+ - `Kiosk::StoryTest` / `Kiosk::TestHelpers::Story` — a test told as a business story by customers' assistants and the people on the operator's site.
10
+ - `Kiosk::TestHelpers::Kyc` — stands in for the operator's KYC provider, so a test decides how an identity check ends.
11
+ - `Kiosk::TestHelpers::StripeMock` — starts a local stripe-mock that answers a confirmed charge as paid.
12
+ - `Kiosk::TestHelpers::LiveServer` — serves the app over HTTP from the test process and gives the test an assistant for it.
13
+ - `Kiosk::TestHelpers::SeededDatabase` — each test starts from the seeds and leaves the database empty.
14
+ - `Kiosk::TestHelpers::DescriptorExamples` — the examples a served `/kiosk/schema` publishes, each checked against its schema.
15
+
16
+ Carries the shared pieces of the Kiosk journey-test DSL: the `Journey` module mixed into RSpec / Minitest tests, the pluggable `executor` contract, a `NullExecutor` for self-tests, and the structured error classes that the framework-specific matchers and assertions look for.
17
+
18
+ The journey DSL comes with one of the harnesses:
19
+
20
+ > **Not on RubyGems yet** — so every `gem` line below carries `github: "kiosk-hq/kiosk"`, which is what makes it copy-pasteable today. Publication status and the canonical install are stated once, in the monorepo README's [Install](https://github.com/kiosk-hq/kiosk#install) section.
21
+
22
+ ```ruby
23
+ group :test do
24
+ gem "kiosk-rls-rspec", github: "kiosk-hq/kiosk" # RSpec
25
+ # or
26
+ gem "kiosk-rls-minitest", github: "kiosk-hq/kiosk" # Minitest
27
+ end
28
+ ```
29
+
30
+ Both harnesses pull `kiosk-test-support` as a transitive dependency.
31
+
32
+ ## DSL
33
+
34
+ ```ruby
35
+ as_agent_of(alice) do
36
+ run_action :create_order, items: ["bread"]
37
+ end
38
+
39
+ as_user(alice) do
40
+ expect(query("select item from orders")).to contain_exactly({ item: "bread" })
41
+ end
42
+
43
+ as_anonymous do
44
+ expect { query("select * from orders") }.to be_rls_denied
45
+ end
46
+ ```
47
+
48
+ Helpers: `as_agent_of(user, role:)`, `as_user(user, role:)`, `as_agent(name)`, `as_anonymous`, `query(sql)`, `run_query(name, **args)`, `run_action(name, **args)`, `pay_action(name, **args)`, `kiosk_seed(table, count:, owner:, **attrs)`. See the `Kiosk::TestHelpers::Journey` docstrings for full semantics.
49
+
50
+ ## Wiring an executor
51
+
52
+ The DSL is inert until you wire an executor. In production-shaped tests you wire `Kiosk::TestHelpers::InProcessExecutor`, which runs against `kiosk-server` in your Rails app:
53
+
54
+ ```ruby
55
+ # spec/spec_helper.rb (RSpec) or test/test_helper.rb (Minitest)
56
+ require "kiosk/test_helpers/in_process_executor"
57
+ Kiosk::TestHelpers.executor = Kiosk::TestHelpers::InProcessExecutor.new
58
+ ```
59
+
60
+ For unit-shaped tests where you only care about call ordering, use the bundled `NullExecutor`:
61
+
62
+ ```ruby
63
+ Kiosk::TestHelpers.executor = Kiosk::TestHelpers::NullExecutor.new.tap do |e|
64
+ e.enqueue_query [{ item: "bread" }]
65
+ end
66
+ ```
67
+
68
+ The `NullExecutor` is the zero-dependency fallback for unit-shaped tests; production-shaped tests wire `Kiosk::TestHelpers::InProcessExecutor` (above).
69
+
70
+ ## Driving the wire as an assistant
71
+
72
+ `Kiosk::TestHelpers::Assistant` registers, pays proof-of-work tolls, queries, runs, pays with signed mandates and listens on `<endpoint>/events`, against any origin — a test's own live server or a deployment:
73
+
74
+ ```ruby
75
+ require "kiosk/test_helpers/assistant"
76
+
77
+ assistant = Kiosk::TestHelpers::Assistant.new(base_url: live_url)
78
+ rider = assistant.register!
79
+ events = assistant.events(rider)
80
+ events.subscribe("kyc_verification")
81
+ assistant.run(rider, name: "reserve", scooter_code: "SK-001")
82
+ ```
83
+
84
+ Every answer carries its status, parsed body and headers. `Kiosk::TestHelpers::Wire` is the same transport without a principal: any method, any path, any headers.
85
+
86
+ ## Telling a business story
87
+
88
+ `Kiosk::StoryTest` (Minitest), or `require "kiosk/story_spec"` and `type: :story` (RSpec), serves the app from the test process and tells a story through `Customer`s, which a demo subclasses with its own business actions:
89
+
90
+ ```ruby
91
+ class Shopper < Kiosk::TestHelpers::Customer
92
+ def orders(*skus) = does(:create_order, items: skus.map { { sku: _1, qty: 1 } })
93
+ def pays_for(order) = pays(total: order["total_cents"], scope: "grocery", line_items: [{ order_id: order["order_id"] }])
94
+ end
95
+
96
+ class ShopStory < Kiosk::StoryTest
97
+ test "a shopper orders and pays" do
98
+ shopper = a_customer(as: Shopper)
99
+ assert shopper.pays_for(shopper.orders("banana")).ok?
100
+ end
101
+ end
102
+ ```
103
+
104
+ - `a_customer(as:)` registers an assistant; `a_newcomer(as:)` holds a key and no account yet; `published(path)` reads what the origin shows anyone.
105
+ - `Customer#asks` and `#does` answer an `Answer` (`ok?`, `refused?(code)`, `detail`, `hint`, `rows`, `header`, `tolls_paid`, `solved_toll`, `next_page`); `asks(…, unpaid: true)` or `asks(…, proofs: […])` leaves the toll to the story.
106
+ - `Kiosk::StoryTest#assert_refused(answer, code)` asserts the wire refused the `Answer` with `code`.
107
+ - `Customer#sets_up_payment` and `#requests_verification` run the engine's `payment_setup` and `request_kyc`, and `#hears_verification_passed` waits for the outcome of the check it asked for last; `#pays(total:, scope:, line_items:, currency:)` signs the intent, cart and payment mandates for a quote and pays; on `payment_setup_required` it calls `payment_setup` and pays once more.
108
+ - `Customer#account`, `#role` and `#claims` read its credential; `#signs_back_in`, `#with_a_fresh_credential`, `#redeems(link_code)`, `#asks_to_be_linked`, `#polls` and `#collects` are the sign-in and linking ceremonies.
109
+ - `Customer#listens_for`, `#follows(*topics, subject:, since:)` and `#hears(topic, about:, on:, **data)` read the event stream, holding each heard payload to the schema the origin publishes for its topic.
110
+ - `a_person(email:, password:)` signs a person in on the operator's site through `kiosk-user-idp-devise`'s `DeviseSession`: `links(customer)`, `link_code`, `approves(user_code)`, `unlinks(customer)`, `visits(path)`.
111
+
112
+ ## Identity checks in tests
113
+
114
+ A real identity check is a human showing documents to a provider; a test cannot do that, so `Kiosk::TestHelpers::Kyc` stands in for the operator's KYC provider for the length of each test and the test says how the check ends. The engine receives the provider's callback and runs the operator's code exactly as it would in production:
115
+
116
+ ```ruby
117
+ require "kiosk/test_helpers/kyc"
118
+
119
+ class LicenceStory < Kiosk::StoryTest # or an RSpec group including Kiosk::TestHelpers::Story
120
+ include Kiosk::TestHelpers::Kyc
121
+
122
+ test "a motorcycle opens once the licence check passes" do
123
+ rider = a_customer
124
+ rider.requests_verification
125
+ the_verification_service_confirms(rider, age_over_18: true, licence_a: true)
126
+ assert rider.hears_verification_passed
127
+ end
128
+ end
129
+ ```
130
+
131
+ `kyc_attestation(principal, **attributes)` signs an attestation an assistant submits to `POST <endpoint>/agents/kyc`. A check the human refuses sends nothing, so there is no helper for it.
132
+
133
+ `Kiosk::TestHelpers::StripeMock.start` fronts a local [stripe-mock](https://github.com/stripe/stripe-mock) that answers a confirmed charge as paid. stripe-mock lists a saved card for every Customer, so once `payment_setup` has mapped one, `pay` settles.
134
+
135
+ ## Status
136
+
137
+ Pre-v1.0 alpha. The Journey DSL surface is stable across pre-v1.0 minor bumps; the executor contract may still evolve pre-v1.0 (`Kiosk::TestHelpers::InProcessExecutor` implements it today).
138
+
139
+ ## License
140
+
141
+ Apache-2.0 — see `LICENSE.txt`.
142
+
143
+ ## Links
144
+
145
+ - [kiosk.tech](https://kiosk.tech)
146
+ - [Issue tracker](https://github.com/kiosk-hq/kiosk/issues)
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kiosk/test_helpers/story'
4
+
5
+ # RSpec's form of Kiosk::StoryTest: every `type: :story` group tells a story.
6
+ RSpec.configure { it.include Kiosk::TestHelpers::Story, type: :story }
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/test_case'
4
+ require 'kiosk/test_helpers/story'
5
+
6
+ module Kiosk
7
+ # Minitest's form of Kiosk::TestHelpers::Story; RSpec includes the module.
8
+ class StoryTest < ActiveSupport::TestCase
9
+ include TestHelpers::Story
10
+
11
+ # Asserts the wire refused `response` with `code`.
12
+ def assert_refused(response, code)
13
+ assert response.refused?(code), "expected a #{code} refusal, got #{response}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'json_schemer'
5
+ require 'openssl'
6
+ require 'socket'
7
+ require 'uri'
8
+ require 'websocket/driver'
9
+
10
+ module Kiosk
11
+ module TestHelpers
12
+ class Assistant
13
+ # The assistant's side of `<endpoint>/events`: one WebSocket, subscribed
14
+ # to topics, read until an event arrives.
15
+ #
16
+ # events = assistant.events(rider)
17
+ # events.subscribe("kyc_verification")
18
+ # event = events.await { _1["topic"] == "kyc_verification" }
19
+ # events.close
20
+ class Events
21
+ class Error < StandardError; end
22
+
23
+ # Every way an event's `data` breaks the `payload_schema` the origin serves
24
+ # for its topic, as "topic: error".
25
+ def self.payload_errors(schema_document, events)
26
+ schemas = Array(schema_document['events']).to_h { [it['name'], it['payload_schema']] }
27
+ events.flat_map do |event|
28
+ topic = event['topic']
29
+ schema = schemas[topic] or next ["#{topic}: this origin serves no such topic"]
30
+ JSONSchemer.schema(schema, meta_schema: 'https://json-schema.org/draft/2020-12/schema')
31
+ .validate(JSON.parse(JSON.generate(event['data'])))
32
+ .map { "#{topic}: #{it['error']}" }
33
+ end
34
+ end
35
+
36
+ attr_reader :url
37
+
38
+ def initialize(base_url:, token:, path: '/kiosk/events', timeout: 10)
39
+ uri = URI(base_url)
40
+ tls = uri.scheme == 'https'
41
+ @url = "#{tls ? 'wss' : 'ws'}://#{uri.host}:#{uri.port}#{path}"
42
+ @io = open_socket(uri.hostname, uri.port, tls)
43
+ @frames = []
44
+ @closed = false
45
+ @driver = start_driver(token)
46
+ pump(timeout) { @frames.any? { it['type'] == 'welcome' } } || raise(Error, "#{@url} did not welcome the connection")
47
+ end
48
+
49
+ # For the driver.
50
+ def write(data) = @io.write(data)
51
+
52
+ def subscribe(topic, timeout: 10, **params)
53
+ identifier = { 'channel' => 'KioskEvents', 'topic' => topic }.merge(params.transform_keys(&:to_s))
54
+ @driver.text(JSON.generate('command' => 'subscribe', 'identifier' => JSON.generate(identifier)))
55
+ frame = nil
56
+ pump(timeout) { frame = messages.find { it['type'] == 'subscribed' && it['topic'] == topic } }
57
+ frame || raise(Error, "subscribe to #{topic} was not confirmed")
58
+ end
59
+
60
+ def events = messages.select { it.key?('id') && it.key?('topic') }
61
+
62
+ def await(timeout: 30, &match) = await_in(:events, timeout, &match)
63
+
64
+ # Any message, including frames such as `{"type" => "unsubscribed", "reason" => "reach_revoked"}`.
65
+ def await_message(timeout: 30, &match) = await_in(:messages, timeout, &match)
66
+
67
+ # Reads for a fixed time, for asserting what did not arrive.
68
+ def listen(seconds)
69
+ pump(seconds) { false }
70
+ events
71
+ end
72
+
73
+ def close
74
+ @io.close
75
+ rescue IOError
76
+ nil
77
+ end
78
+
79
+ private
80
+
81
+ # A `ping` frame's message is a bare timestamp.
82
+ def messages = @frames.filter_map { it['message'] if it['message'].is_a?(Hash) }
83
+
84
+ def await_in(source, timeout, &)
85
+ found = nil
86
+ pump(timeout) { found = send(source).find(&) }
87
+ found || raise(Error, "nothing matching arrived within #{timeout}s")
88
+ end
89
+
90
+ def open_socket(host, port, tls)
91
+ tcp = TCPSocket.new(host, port)
92
+ return tcp unless tls
93
+
94
+ ssl = OpenSSL::SSL::SSLSocket.new(tcp, OpenSSL::SSL::SSLContext.new.tap(&:set_params))
95
+ ssl.hostname = host
96
+ ssl.sync_close = true
97
+ ssl.connect
98
+ ssl
99
+ end
100
+
101
+ def start_driver(token)
102
+ driver = WebSocket::Driver.client(self)
103
+ driver.set_header('Authorization', "Bearer #{token}")
104
+ driver.on(:message) { @frames << JSON.parse(it.data) }
105
+ driver.on(:close) { @closed = true }
106
+ driver.on(:error) { @closed = true }
107
+ driver.start
108
+ driver
109
+ end
110
+
111
+ def pump(seconds)
112
+ deadline = Time.now + seconds
113
+ until Time.now > deadline
114
+ return true if yield
115
+ break if @closed
116
+
117
+ read_frames if buffered? || @io.wait_readable(0.1)
118
+ end
119
+ yield
120
+ end
121
+
122
+ def read_frames
123
+ @driver.parse(@io.read_nonblock(8192))
124
+ rescue IO::WaitReadable
125
+ nil
126
+ rescue IOError, Errno::ECONNRESET
127
+ @closed = true
128
+ end
129
+
130
+ # TLS decrypts ahead of the socket.
131
+ def buffered? = @io.is_a?(OpenSSL::SSL::SSLSocket) && @io.pending.positive?
132
+ end
133
+ end
134
+ end
135
+ end