@reventlessdev/reventless-seed 1.0.0-alpha.2 → 1.0.0-alpha.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.
- package/CHANGELOG.md +137 -0
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/.sourcedirs.json +1 -0
- package/lib/bs/ReventlessSeed.cmi +0 -0
- package/lib/bs/ReventlessSeed.cmt +0 -0
- package/lib/bs/ReventlessSeed.mlmap +5 -0
- package/lib/bs/compiler-info.json +2 -2
- package/lib/bs/src/Seed-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed.ast +0 -0
- package/lib/bs/src/Seed.res +6 -3
- package/lib/bs/src/Seed.res.mjs +3 -0
- package/lib/bs/src/Seed_Client-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Client-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Client-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Client.ast +0 -0
- package/lib/bs/src/Seed_Client.res +228 -15
- package/lib/bs/src/Seed_Client.res.mjs +196 -23
- package/lib/bs/src/Seed_Connect-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Connect-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Connect-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Connect.ast +0 -0
- package/lib/bs/src/Seed_Connect.res +27 -18
- package/lib/bs/src/Seed_Connect.res.mjs +10 -6
- package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Prompt.ast +0 -0
- package/lib/bs/src/Seed_Prompt.res +110 -35
- package/lib/bs/src/Seed_Prompt.res.mjs +73 -8
- package/lib/bs/src/Seed_Random-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Runner-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Runner-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Runner-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Runner.ast +0 -0
- package/lib/bs/src/Seed_Runner.res +38 -7
- package/lib/bs/src/Seed_Runner.res.mjs +19 -1
- package/lib/bs/src/Seed_Types-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Upload-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Upload-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Upload-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Upload.ast +0 -0
- package/lib/bs/src/Seed_Upload.res +40 -42
- package/lib/bs/src/Seed_Upload.res.mjs +65 -69
- package/lib/bs/src/Seed_Users-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Users-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Users-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Users.ast +0 -0
- package/lib/bs/src/Seed_Users.res +80 -0
- package/lib/bs/src/Seed_Users.res.mjs +90 -0
- package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_ClientTest.ast +0 -0
- package/lib/bs/tests/Seed_ClientTest.res +157 -0
- package/lib/bs/tests/Seed_ClientTest.res.mjs +167 -0
- package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_PromptTest.ast +0 -0
- package/lib/bs/tests/Seed_PromptTest.res +59 -0
- package/lib/bs/tests/Seed_PromptTest.res.mjs +63 -0
- package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_RandomTest.ast +0 -0
- package/lib/bs/tests/Seed_RandomTest.res +160 -0
- package/lib/bs/tests/Seed_RandomTest.res.mjs +208 -0
- package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_UsersTest.ast +0 -0
- package/lib/bs/tests/Seed_UsersTest.res +92 -0
- package/lib/bs/tests/Seed_UsersTest.res.mjs +95 -0
- package/lib/ocaml/.compiler.log +2 -2
- package/lib/ocaml/ReventlessSeed.cmi +0 -0
- package/lib/ocaml/ReventlessSeed.cmt +0 -0
- package/lib/ocaml/ReventlessSeed.mlmap +5 -0
- package/lib/ocaml/Seed-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed.ast +0 -0
- package/lib/ocaml/Seed.res +6 -3
- package/lib/ocaml/Seed_Client-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Client-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Client-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Client.ast +0 -0
- package/lib/ocaml/Seed_Client.res +228 -15
- package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_ClientTest.ast +0 -0
- package/lib/ocaml/Seed_ClientTest.res +157 -0
- package/lib/ocaml/Seed_Connect-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Connect-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Connect-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Connect.ast +0 -0
- package/lib/ocaml/Seed_Connect.res +27 -18
- package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Prompt.ast +0 -0
- package/lib/ocaml/Seed_Prompt.res +110 -35
- package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_PromptTest.ast +0 -0
- package/lib/ocaml/Seed_PromptTest.res +59 -0
- package/lib/ocaml/Seed_Random-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_RandomTest.ast +0 -0
- package/lib/ocaml/Seed_RandomTest.res +160 -0
- package/lib/ocaml/Seed_Runner-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Runner-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Runner-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Runner.ast +0 -0
- package/lib/ocaml/Seed_Runner.res +38 -7
- package/lib/ocaml/Seed_Types-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Upload-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Upload-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Upload-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Upload.ast +0 -0
- package/lib/ocaml/Seed_Upload.res +40 -42
- package/lib/ocaml/Seed_Users-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Users-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Users-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Users.ast +0 -0
- package/lib/ocaml/Seed_Users.res +80 -0
- package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_UsersTest.ast +0 -0
- package/lib/ocaml/Seed_UsersTest.res +92 -0
- package/package.json +7 -2
- package/rescript.json +9 -1
- package/src/Seed.res +6 -3
- package/src/Seed.res.mjs +3 -0
- package/src/Seed_Client.res +228 -15
- package/src/Seed_Client.res.mjs +196 -23
- package/src/Seed_Connect.res +27 -18
- package/src/Seed_Connect.res.mjs +10 -6
- package/src/Seed_Prompt.res +110 -35
- package/src/Seed_Prompt.res.mjs +73 -8
- package/src/Seed_Runner.res +38 -7
- package/src/Seed_Runner.res.mjs +19 -1
- package/src/Seed_Upload.res +40 -42
- package/src/Seed_Upload.res.mjs +65 -69
- package/src/Seed_Users.res +80 -0
- package/src/Seed_Users.res.mjs +90 -0
- package/tests/Seed_ClientTest.res +157 -0
- package/tests/Seed_ClientTest.res.mjs +167 -0
- package/tests/Seed_PromptTest.res +59 -0
- package/tests/Seed_PromptTest.res.mjs +63 -0
- package/tests/Seed_RandomTest.res +160 -0
- package/tests/Seed_RandomTest.res.mjs +208 -0
- package/tests/Seed_UsersTest.res +92 -0
- package/tests/Seed_UsersTest.res.mjs +95 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// One shared readline interface for every interactive prompt in a seed run.
|
|
2
2
|
//
|
|
3
3
|
// The reason this module exists: creating and closing a fresh `readline`
|
|
4
|
-
// interface per prompt leaves stdin paused after the first `close`, so the
|
|
4
|
+
// interface per prompt leaves NodeProcess.stdin paused after the first `close`, so the
|
|
5
5
|
// second prompt (password after username) never fires and the run hangs. A
|
|
6
6
|
// single interface, created lazily and closed exactly once, avoids that — and a
|
|
7
7
|
// `muted` gate on its output lets password entry reuse the same interface
|
|
@@ -14,18 +14,8 @@ open Seed_Types
|
|
|
14
14
|
|
|
15
15
|
// ── Node bindings ─────────────────────────────────────────────────────────────
|
|
16
16
|
|
|
17
|
-
type stream
|
|
18
|
-
@val @scope("process") external stdin: stream = "stdin"
|
|
19
|
-
@val @scope("process") external stdout: stream = "stdout"
|
|
20
|
-
@send external writeStream: (stream, string) => unit = "write"
|
|
21
|
-
@get external isTTY: stream => bool = "isTTY"
|
|
22
|
-
@send external pauseStream: stream => unit = "pause"
|
|
23
|
-
@send external unrefStream: stream => unit = "unref"
|
|
24
|
-
|
|
25
|
-
@scope("process") @val external processEnv: dict<string> = "env"
|
|
26
|
-
|
|
27
17
|
type rl
|
|
28
|
-
type rlOptions = {input: stream, output: stream, terminal?: bool}
|
|
18
|
+
type rlOptions = {input: NodeProcess.stream, output: NodeProcess.stream, terminal?: bool}
|
|
29
19
|
@module("node:readline") external createInterface: rlOptions => rl = "createInterface"
|
|
30
20
|
@send external question: (rl, string, string => unit) => unit = "question"
|
|
31
21
|
@send external closeRl: rl => unit = "close"
|
|
@@ -42,10 +32,10 @@ let iface = (): rl =>
|
|
|
42
32
|
switch rlRef.contents {
|
|
43
33
|
| Some(rl) => rl
|
|
44
34
|
| None =>
|
|
45
|
-
let rl = createInterface({input: stdin, output: stdout, terminal: true})
|
|
35
|
+
let rl = createInterface({input: NodeProcess.stdin, output: NodeProcess.stdout, terminal: true})
|
|
46
36
|
rl->setWriteToOutput(s =>
|
|
47
37
|
if !muted.contents {
|
|
48
|
-
stdout->
|
|
38
|
+
NodeProcess.stdout->NodeProcess.write(s)
|
|
49
39
|
}
|
|
50
40
|
)
|
|
51
41
|
rlRef := Some(rl)
|
|
@@ -58,23 +48,23 @@ let close = (): unit =>
|
|
|
58
48
|
rl->closeRl
|
|
59
49
|
rlRef := None
|
|
60
50
|
// Closing the interface is not enough: a terminal-mode readline leaves
|
|
61
|
-
// stdin resumed and reffed, which keeps the event loop alive so the CLI
|
|
51
|
+
// NodeProcess.stdin resumed and reffed, which keeps the event loop alive so the CLI
|
|
62
52
|
// never exits after seeding. Release it explicitly.
|
|
63
|
-
stdin->
|
|
64
|
-
stdin->
|
|
53
|
+
NodeProcess.stdin->NodeProcess.pause
|
|
54
|
+
NodeProcess.stdin->NodeProcess.unref
|
|
65
55
|
| None => ()
|
|
66
56
|
}
|
|
67
57
|
|
|
68
58
|
// ── Env + TTY ─────────────────────────────────────────────────────────────────
|
|
69
59
|
|
|
70
60
|
let envValue = (key: string): option<string> =>
|
|
71
|
-
switch
|
|
61
|
+
switch NodeProcess.env->Dict.get(key) {
|
|
72
62
|
| Some(v) if v->String.trim != "" => Some(v->String.trim)
|
|
73
63
|
| _ => None
|
|
74
64
|
}
|
|
75
65
|
|
|
76
66
|
let requireTty = (): unit =>
|
|
77
|
-
if !(stdin->isTTY) {
|
|
67
|
+
if !(NodeProcess.stdin->NodeProcess.isTTY->Option.getOr(false)) {
|
|
78
68
|
throw(
|
|
79
69
|
Failed(
|
|
80
70
|
"no TTY for an interactive prompt — set the documented SEED_* / REVENTLESS_DEMO_* " ++
|
|
@@ -101,23 +91,45 @@ let askHidden = (query: string): promise<string> =>
|
|
|
101
91
|
let rl = iface()
|
|
102
92
|
rl->question(query, answer => {
|
|
103
93
|
muted := false
|
|
104
|
-
stdout->
|
|
94
|
+
NodeProcess.stdout->NodeProcess.write("\n")
|
|
105
95
|
resolve(answer)
|
|
106
96
|
})
|
|
107
97
|
muted := true
|
|
108
98
|
})
|
|
109
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Whether an answer means yes — the one vocabulary, for the typed reply and the
|
|
102
|
+
* env var that stands in for it alike.
|
|
103
|
+
*
|
|
104
|
+
* It exists because those two drifted: a `[y/N]` prompt took `y`, and the env
|
|
105
|
+
* var beside it took only `1` or `yes`, so the obvious `SEED_RESET_CONFIRM=y`
|
|
106
|
+
* silently fell through to the interactive branch — which, on the CI runs the
|
|
107
|
+
* variable exists for, has no TTY and throws. Two spellings of one question are
|
|
108
|
+
* one spelling too many; callers ask this instead of comparing strings.
|
|
109
|
+
*
|
|
110
|
+
* Trimmed and case-folded, so `Yes`/` y ` answer the same as `y`.
|
|
111
|
+
*/
|
|
112
|
+
let isAffirmative = (answer: string): bool =>
|
|
113
|
+
switch answer->String.trim->String.toLowerCase {
|
|
114
|
+
| "y" | "yes" | "1" => true
|
|
115
|
+
| _ => false
|
|
116
|
+
}
|
|
117
|
+
|
|
110
118
|
/**
|
|
111
119
|
* Chooses one of `options` (a label paired with the value it selects).
|
|
112
120
|
*
|
|
113
121
|
* Auto-returns when there is a single option, so a lone data set or stack needs
|
|
114
122
|
* no keypress. `env` (e.g. `SEED_SET`) preselects by matching label or 1-based
|
|
115
123
|
* index, so CI runs without a TTY. Otherwise it prints a numbered menu.
|
|
124
|
+
*
|
|
125
|
+
* `defaultIndex` makes Enter a valid answer, selecting that 0-based option;
|
|
126
|
+
* without one every reply must name a choice.
|
|
116
127
|
*/
|
|
117
128
|
let select = async (
|
|
118
129
|
~title: string,
|
|
119
130
|
~options: array<(string, 'a)>,
|
|
120
131
|
~env=?,
|
|
132
|
+
~defaultIndex=?,
|
|
121
133
|
): 'a =>
|
|
122
134
|
switch options {
|
|
123
135
|
| [(_, only)] => only
|
|
@@ -145,29 +157,38 @@ let select = async (
|
|
|
145
157
|
options->Array.forEachWithIndex(((label, _), i) =>
|
|
146
158
|
Console.log(` ${(i + 1)->Int.toString}) ${label}`)
|
|
147
159
|
)
|
|
160
|
+
let fallback = defaultIndex->Option.flatMap(i => options->Array.get(i))
|
|
161
|
+
let hint = switch (defaultIndex, fallback) {
|
|
162
|
+
| (Some(i), Some(_)) => ` (default ${(i + 1)->Int.toString})`
|
|
163
|
+
| _ => ""
|
|
164
|
+
}
|
|
148
165
|
let rec pick = async (): 'a => {
|
|
149
|
-
let answer = await ask(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
166
|
+
let answer = await ask(
|
|
167
|
+
`\nSelect [1-${(options->Array.length)->Int.toString}]${hint}: `,
|
|
168
|
+
)
|
|
169
|
+
switch (answer, fallback) {
|
|
170
|
+
| ("", Some((_, value))) => value
|
|
154
171
|
| _ =>
|
|
155
|
-
|
|
156
|
-
|
|
172
|
+
switch Int.fromString(answer) {
|
|
173
|
+
| Some(n) if n >= 1 && n <= options->Array.length =>
|
|
174
|
+
let (_, value) = options->Array.getUnsafe(n - 1)
|
|
175
|
+
value
|
|
176
|
+
| _ =>
|
|
177
|
+
Console.log(" Not a valid choice.")
|
|
178
|
+
await pick()
|
|
179
|
+
}
|
|
157
180
|
}
|
|
158
181
|
}
|
|
159
182
|
await pick()
|
|
160
183
|
}
|
|
161
184
|
}
|
|
162
185
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
let credentials = async (~localDefaults: bool=false): (string, string) => {
|
|
170
|
-
let username = switch envValue("REVENTLESS_DEMO_USER") {
|
|
186
|
+
// Typing both halves is the fallback, not the first offer: it is what happens
|
|
187
|
+
// when the platform keeps no accounts file. `envUser` is threaded in so a
|
|
188
|
+
// `REVENTLESS_DEMO_USER` that named nobody in the file still skips the username
|
|
189
|
+
// prompt rather than asking for a name that was already given.
|
|
190
|
+
let askCredentials = async (~localDefaults: bool, ~envUser: option<string>): (string, string) => {
|
|
191
|
+
let username = switch envUser {
|
|
171
192
|
| Some(u) => u
|
|
172
193
|
| None =>
|
|
173
194
|
requireTty()
|
|
@@ -181,6 +202,60 @@ let credentials = async (~localDefaults: bool=false): (string, string) => {
|
|
|
181
202
|
let entered = await askHidden(localDefaults ? "Password [admin]: " : "Password: ")
|
|
182
203
|
entered == "" && localDefaults ? "admin" : entered
|
|
183
204
|
}
|
|
205
|
+
(username, password)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// The accounts file the platform already keeps (`.reventless/users.yaml`, or
|
|
209
|
+
// `SEED_USERS_FILE`). It records the password beside the username, so choosing
|
|
210
|
+
// an account is the whole credential step — nothing is typed.
|
|
211
|
+
//
|
|
212
|
+
// A named `REVENTLESS_DEMO_USER` picks its entry directly; otherwise the file's
|
|
213
|
+
// accounts are offered in the order it defines them, first as the default.
|
|
214
|
+
// `None` means the file has nothing to offer and the caller should ask.
|
|
215
|
+
let fromUsersFile = async (~envUser: option<string>): option<(string, string)> =>
|
|
216
|
+
switch Seed_Users.load(~path=?envValue("SEED_USERS_FILE")) {
|
|
217
|
+
| None => None
|
|
218
|
+
| Some((path, users)) =>
|
|
219
|
+
let chosen = switch envUser {
|
|
220
|
+
| Some(name) => users->Array.find(u => u.username == name)
|
|
221
|
+
| None =>
|
|
222
|
+
Some(
|
|
223
|
+
await select(
|
|
224
|
+
~title=`User (${path}):`,
|
|
225
|
+
~options=users->Array.map(u => (Seed_Users.label(u), u)),
|
|
226
|
+
~env="SEED_USER",
|
|
227
|
+
~defaultIndex=0,
|
|
228
|
+
),
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
// Logged for every arm, including the single-account file that selects
|
|
232
|
+
// itself without a keypress: which identity seeded the data is the thing an
|
|
233
|
+
// operator checks when owner-scoped rows turn up under the wrong account.
|
|
234
|
+
chosen->Option.map(u => {
|
|
235
|
+
Console.log(`Logging in as ${u.username} (from ${path})`)
|
|
236
|
+
(u.username, u.password)
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Resolves the credentials a seed run logs in with.
|
|
242
|
+
*
|
|
243
|
+
* `REVENTLESS_DEMO_USER` + `REVENTLESS_DEMO_PASSWORD` together are the
|
|
244
|
+
* non-interactive path and skip everything below. Otherwise the platform's
|
|
245
|
+
* `.reventless/users.yaml` supplies the accounts to choose from, and only a
|
|
246
|
+
* platform without one falls back to typing both halves — where, with
|
|
247
|
+
* `localDefaults`, empty input means `admin`/`admin`.
|
|
248
|
+
*/
|
|
249
|
+
let credentials = async (~localDefaults: bool=false): (string, string) => {
|
|
250
|
+
let envUser = envValue("REVENTLESS_DEMO_USER")
|
|
251
|
+
let (username, password) = switch (envUser, envValue("REVENTLESS_DEMO_PASSWORD")) {
|
|
252
|
+
| (Some(u), Some(p)) => (u, p)
|
|
253
|
+
| _ =>
|
|
254
|
+
switch await fromUsersFile(~envUser) {
|
|
255
|
+
| Some(pair) => pair
|
|
256
|
+
| None => await askCredentials(~localDefaults, ~envUser)
|
|
257
|
+
}
|
|
258
|
+
}
|
|
184
259
|
if username == "" || password == "" {
|
|
185
260
|
throw(Failed("username and password are required."))
|
|
186
261
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
open JestGlobals
|
|
2
|
+
|
|
3
|
+
// `isAffirmative` is the one vocabulary for "yes", shared by a typed `[y/N]`
|
|
4
|
+
// reply and by the env var that stands in for it on a run with no terminal.
|
|
5
|
+
//
|
|
6
|
+
// It exists because those two drifted: the prompt took `y`, the env var took
|
|
7
|
+
// only the literals `1` and `yes`, and every other value — `y` included, and an
|
|
8
|
+
// explicit `no` with it — fell through to the interactive branch, which throws
|
|
9
|
+
// when there is no TTY. So the variable that exists to make the tool
|
|
10
|
+
// non-interactive had two spellings that worked and a crash for the rest.
|
|
11
|
+
//
|
|
12
|
+
// The suite is written around the shape of that bug rather than around the
|
|
13
|
+
// function: what must confirm, what must decline, and — the case that actually
|
|
14
|
+
// broke CI — that declining is a normal answer and not a fall-through.
|
|
15
|
+
|
|
16
|
+
describe("Seed_Prompt.isAffirmative:", () => {
|
|
17
|
+
testSync("takes the three spellings of yes", () => {
|
|
18
|
+
["y", "yes", "1"]->Array.forEach(v =>
|
|
19
|
+
expect(Seed_Prompt.isAffirmative(v))->Expect.toBe(true)
|
|
20
|
+
)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
// A prompt that prints `[y/N]` invites a capital as readily as a lowercase
|
|
24
|
+
// one, and an env var set by hand is written however the hand felt.
|
|
25
|
+
testSync("ignores case, so Y and YES answer as y does", () => {
|
|
26
|
+
["Y", "Yes", "YES"]->Array.forEach(v =>
|
|
27
|
+
expect(Seed_Prompt.isAffirmative(v))->Expect.toBe(true)
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
testSync("ignores surrounding space", () => {
|
|
32
|
+
[" y", "y ", " yes "]->Array.forEach(v =>
|
|
33
|
+
expect(Seed_Prompt.isAffirmative(v))->Expect.toBe(true)
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// The half that matters most: every one of these is an ANSWER, and the caller
|
|
38
|
+
// reads it as "no". None may be mistaken for "nothing was said", which is what
|
|
39
|
+
// sent the old code to a prompt it could not open.
|
|
40
|
+
testSync("declines every spelling of no, capital N included", () => {
|
|
41
|
+
["n", "N", "no", "No", "NO"]->Array.forEach(v =>
|
|
42
|
+
expect(Seed_Prompt.isAffirmative(v))->Expect.toBe(false)
|
|
43
|
+
)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
testSync("declines anything it does not recognise", () => {
|
|
47
|
+
["", " ", "0", "true", "yep", "y.", "yesplease", "affirmative"]->Array.forEach(v =>
|
|
48
|
+
expect(Seed_Prompt.isAffirmative(v))->Expect.toBe(false)
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
// `true` is deliberately absent from the vocabulary above. Named here so that
|
|
53
|
+
// adding it is a decision someone takes against a failing test rather than a
|
|
54
|
+
// kindness someone slips in: the prompt this stands in for asks `[y/N]`, and a
|
|
55
|
+
// reply nobody would type at that prompt should not work around it either.
|
|
56
|
+
testSync("does not quietly grow a fourth spelling", () => {
|
|
57
|
+
expect(Seed_Prompt.isAffirmative("true"))->Expect.toBe(false)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
open JestGlobals
|
|
2
|
+
|
|
3
|
+
// `Seed_Random` exists so that two seed runs against a fresh store produce the
|
|
4
|
+
// same data — that is what makes a seeded store usable as a screenshot baseline
|
|
5
|
+
// or a comparison target. Its correctness is therefore not "looks random" but
|
|
6
|
+
// "repeats exactly, and stays inside the bounds it advertises".
|
|
7
|
+
//
|
|
8
|
+
// The suite is written around that: every case below fails for a generator that
|
|
9
|
+
// is subtly non-reproducible or that walks out of its range, and none of them
|
|
10
|
+
// would notice a change of algorithm that kept both properties.
|
|
11
|
+
|
|
12
|
+
describe("Seed_Random:", () => {
|
|
13
|
+
let take = (~seed, ~n) => {
|
|
14
|
+
let r = Seed_Random.make(~seed)
|
|
15
|
+
Array.make(~length=n, 0.0)->Array.map(_ => Seed_Random.float(r))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("reproducibility — the reason this module exists:", () => {
|
|
19
|
+
testSync("the same seed replays the same sequence", () =>
|
|
20
|
+
expect(take(~seed=42, ~n=25))->toEqual(take(~seed=42, ~n=25))
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
// Without this, a generator that returned a constant would satisfy the
|
|
24
|
+
// case above and nothing else in the suite would catch it.
|
|
25
|
+
testSync("different seeds diverge", () =>
|
|
26
|
+
expect(take(~seed=42, ~n=25) == take(~seed=43, ~n=25))->toBe(false)
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
testSync("a fresh generator does not continue the previous one", () => {
|
|
30
|
+
let r = Seed_Random.make(~seed=7)
|
|
31
|
+
let first = Seed_Random.float(r)
|
|
32
|
+
let _ = Seed_Random.float(r)
|
|
33
|
+
expect(Seed_Random.float(Seed_Random.make(~seed=7)))->toEqual(first)
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe("float stays a unit interval:", () => {
|
|
38
|
+
// mulberry32's last step is a signed 32-bit value folded back to unsigned.
|
|
39
|
+
// Get that fold wrong and roughly half the draws come out negative, which
|
|
40
|
+
// every consumer below (int, pick, sampleWeighted) silently mis-scales.
|
|
41
|
+
testSync("every draw is in [0, 1)", () =>
|
|
42
|
+
expect(take(~seed=99, ~n=500)->Array.every(f => f >= 0.0 && f < 1.0))->toBe(true)
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
testSync("and the draws are not all the same value", () => {
|
|
46
|
+
let draws = take(~seed=99, ~n=100)
|
|
47
|
+
expect(draws->Array.some(f => f != draws->Array.getUnsafe(0)))->toBe(true)
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
describe("int is inclusive on both ends, as documented:", () => {
|
|
52
|
+
let draws = (~min, ~max, ~n) => {
|
|
53
|
+
let r = Seed_Random.make(~seed=5)
|
|
54
|
+
Array.make(~length=n, 0)->Array.map(_ => Seed_Random.int(r, ~min, ~max))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
testSync("never escapes the range", () =>
|
|
58
|
+
expect(draws(~min=3, ~max=7, ~n=500)->Array.every(i => i >= 3 && i <= 7))->toBe(true)
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
// The documented contract is "inclusive on both ends"; an off-by-one in the
|
|
62
|
+
// `max - min + 1` scaling shows up as a bound that is never drawn.
|
|
63
|
+
testSync("reaches both bounds", () => {
|
|
64
|
+
let d = draws(~min=3, ~max=7, ~n=500)
|
|
65
|
+
expect((d->Array.includes(3), d->Array.includes(7)))->toEqual((true, true))
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
testSync("a single-value range is that value", () =>
|
|
69
|
+
expect(draws(~min=4, ~max=4, ~n=10)->Array.every(i => i == 4))->toBe(true)
|
|
70
|
+
)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe("pick:", () => {
|
|
74
|
+
testSync("returns None for an empty array", () =>
|
|
75
|
+
expect(Seed_Random.make(~seed=1)->Seed_Random.pick([]))->toEqual(None)
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
testSync("always lands on a member", () => {
|
|
79
|
+
let r = Seed_Random.make(~seed=2)
|
|
80
|
+
let xs = ["a", "b", "c", "d"]
|
|
81
|
+
let hits = Array.make(~length=200, "")->Array.map(_ =>
|
|
82
|
+
r->Seed_Random.pickOr(~fallback="MISS", xs)
|
|
83
|
+
)
|
|
84
|
+
expect(hits->Array.every(h => xs->Array.includes(h)))->toBe(true)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
testSync("pickOr falls back only when there is nothing to pick", () =>
|
|
88
|
+
expect(Seed_Random.make(~seed=3)->Seed_Random.pickOr(~fallback="fallback", []))->toBe(
|
|
89
|
+
"fallback",
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
describe("sampleWeighted is without replacement:", () => {
|
|
95
|
+
let equal = xs => xs->Array.map(x => (x, 1.0))
|
|
96
|
+
|
|
97
|
+
// The documented shuffle use: equal weights, count = length. If sampling
|
|
98
|
+
// ever replaced instead of removing, duplicates would appear here.
|
|
99
|
+
testSync("count = length yields a permutation, not a multiset", () => {
|
|
100
|
+
let xs = ["a", "b", "c", "d", "e"]
|
|
101
|
+
let out = Seed_Random.make(~seed=11)->Seed_Random.sampleWeighted(equal(xs), ~count=5)
|
|
102
|
+
let sorted = out->Array.toSorted(String.compare)
|
|
103
|
+
expect((out->Array.length, sorted))->toEqual((5, ["a", "b", "c", "d", "e"]))
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
testSync("count < length returns exactly count distinct items", () => {
|
|
107
|
+
let xs = ["a", "b", "c", "d", "e"]
|
|
108
|
+
let out = Seed_Random.make(~seed=12)->Seed_Random.sampleWeighted(equal(xs), ~count=3)
|
|
109
|
+
let distinct = Set.fromArray(out)->Set.size
|
|
110
|
+
expect((out->Array.length, distinct))->toEqual((3, 3))
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
testSync("count > length clamps to the pool", () =>
|
|
114
|
+
expect(
|
|
115
|
+
Seed_Random.make(~seed=13)
|
|
116
|
+
->Seed_Random.sampleWeighted(equal(["a", "b"]), ~count=99)
|
|
117
|
+
->Array.length,
|
|
118
|
+
)->toBe(2)
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
testSync("a zero-weight entry is never chosen while others remain", () => {
|
|
122
|
+
let out =
|
|
123
|
+
Seed_Random.make(~seed=14)->Seed_Random.sampleWeighted(
|
|
124
|
+
[("never", 0.0), ("a", 1.0), ("b", 1.0)],
|
|
125
|
+
~count=2,
|
|
126
|
+
)
|
|
127
|
+
expect(out->Array.includes("never"))->toBe(false)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
testSync("is reproducible for a given seed", () => {
|
|
131
|
+
let run = () =>
|
|
132
|
+
Seed_Random.make(~seed=15)->Seed_Random.sampleWeighted(
|
|
133
|
+
equal(["a", "b", "c", "d", "e", "f"]),
|
|
134
|
+
~count=4,
|
|
135
|
+
)
|
|
136
|
+
expect(run())->toEqual(run())
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
describe("zipfWeights skews toward the head:", () => {
|
|
141
|
+
let weights = Seed_Random.zipfWeights(["a", "b", "c", "d", "e"], ~exponent=1.1)
|
|
142
|
+
|
|
143
|
+
testSync("keeps every item, in order", () =>
|
|
144
|
+
expect(weights->Array.map(((item, _)) => item))->toEqual(["a", "b", "c", "d", "e"])
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
testSync("weight decreases monotonically with rank", () => {
|
|
148
|
+
let ws = weights->Array.map(((_, w)) => w)
|
|
149
|
+
let decreasing =
|
|
150
|
+
ws->Array.everyWithIndex((w, i) => i == 0 || w < ws->Array.getUnsafe(i - 1))
|
|
151
|
+
expect(decreasing)->toBe(true)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
testSync("the leader is clear — first outweighs last several times over", () => {
|
|
155
|
+
let first = weights->Array.get(0)->Option.mapOr(0.0, ((_, w)) => w)
|
|
156
|
+
let last = weights->Array.get(4)->Option.mapOr(0.0, ((_, w)) => w)
|
|
157
|
+
expect(first > last *. 3.0)->toBe(true)
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
})
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
open Seed_Types
|
|
4
4
|
|
|
5
|
-
@scope("process") @val external exit: int => unit = "exit"
|
|
6
|
-
@scope("process") @val external env: dict<string> = "env"
|
|
7
5
|
|
|
8
6
|
let envOr = (key: string, fallback: string): string =>
|
|
9
|
-
env->Dict.get(key)->Option.getOr(fallback)
|
|
7
|
+
NodeProcess.env->Dict.get(key)->Option.getOr(fallback)
|
|
10
8
|
|
|
11
9
|
/** One line of progress per phase, so a slow run never looks hung. */
|
|
12
10
|
let report = (line: string): unit => Console.log(` ${line}`)
|
|
@@ -90,6 +88,33 @@ let warn = (warnings: array<string>): unit =>
|
|
|
90
88
|
warnings->Array.forEach(w => Console.log(` - ${w}`))
|
|
91
89
|
}
|
|
92
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Pre-flight: refuse to seed onto a store that already holds data.
|
|
93
|
+
*
|
|
94
|
+
* The harness is a one-shot against a fresh store — a re-run would hit the
|
|
95
|
+
* domain's own duplicate rejections (`CategoryAlreadyExists`, …) and abort
|
|
96
|
+
* mid-phase. Catching it here, before any command is sent, turns that into an
|
|
97
|
+
* honest "nothing was written" startup abort instead of a misleading
|
|
98
|
+
* half-seeded one. It is the inverse of `verifyViews`: seeding refuses to start
|
|
99
|
+
* unless the store reads empty. Stops at the first non-empty probe view, so a
|
|
100
|
+
* populated store aborts after a single query.
|
|
101
|
+
*/
|
|
102
|
+
let assertStoreEmpty = async (client: Seed_Client.t, ~probeViews: array<string>): unit =>
|
|
103
|
+
for i in 0 to probeViews->Array.length - 1 {
|
|
104
|
+
switch probeViews->Array.get(i) {
|
|
105
|
+
| Some(name) =>
|
|
106
|
+
let count = await Seed_Client.countNodes(client, ~field=name)
|
|
107
|
+
if count > 0 {
|
|
108
|
+
throw(
|
|
109
|
+
Failed(
|
|
110
|
+
`the target store is not empty — "${name}" already holds ${count->Int.toString} row(s). Seeding is a one-shot against a fresh store; reset the store before re-running.`,
|
|
111
|
+
),
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
| None => ()
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
93
118
|
/**
|
|
94
119
|
* Wraps a seed run. On failure it prints the cause and exits non-zero, saying
|
|
95
120
|
* plainly that the store is now half-seeded — recovery is a reset, not a re-run.
|
|
@@ -100,7 +125,7 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
100
125
|
// Exit cleanly: HTTP keep-alive sockets (and, on the interactive path, the
|
|
101
126
|
// readline/stdin handle) can otherwise keep the event loop alive so the CLI
|
|
102
127
|
// appears to hang after a successful run.
|
|
103
|
-
exit(0)
|
|
128
|
+
NodeProcess.exit(0)
|
|
104
129
|
} catch {
|
|
105
130
|
| Failed(message) =>
|
|
106
131
|
Console.error("")
|
|
@@ -108,7 +133,7 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
108
133
|
Console.error("fresh store once the cause below is fixed.")
|
|
109
134
|
Console.error("")
|
|
110
135
|
Console.error(message)
|
|
111
|
-
exit(1)
|
|
136
|
+
NodeProcess.exit(1)
|
|
112
137
|
| exn =>
|
|
113
138
|
Console.error("")
|
|
114
139
|
Console.error("Seeding aborted with an unexpected error:")
|
|
@@ -116,7 +141,7 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
116
141
|
Console.error(
|
|
117
142
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown"),
|
|
118
143
|
)
|
|
119
|
-
exit(1)
|
|
144
|
+
NodeProcess.exit(1)
|
|
120
145
|
}
|
|
121
146
|
|
|
122
147
|
/**
|
|
@@ -128,6 +153,9 @@ type dataSet = {
|
|
|
128
153
|
name: string,
|
|
129
154
|
label: string,
|
|
130
155
|
seed: Seed_Connect.connection => promise<unit>,
|
|
156
|
+
// View names probed by the fresh-store guard before any command is sent; a
|
|
157
|
+
// non-empty one aborts the run at startup. Omit to skip the guard.
|
|
158
|
+
probeViews?: array<string>,
|
|
131
159
|
}
|
|
132
160
|
|
|
133
161
|
/**
|
|
@@ -142,7 +170,7 @@ let abortStartup = (message: string): unit => {
|
|
|
142
170
|
Console.error("Seeding did not start — nothing was written. Fix the cause below and re-run.")
|
|
143
171
|
Console.error("")
|
|
144
172
|
Console.error(message)
|
|
145
|
-
exit(1)
|
|
173
|
+
NodeProcess.exit(1)
|
|
146
174
|
}
|
|
147
175
|
|
|
148
176
|
/**
|
|
@@ -179,6 +207,9 @@ let seed = (~sets: array<dataSet>, ~connect: unit => promise<Seed_Connect.connec
|
|
|
179
207
|
}
|
|
180
208
|
let connection = await connect()
|
|
181
209
|
Seed_Prompt.close()
|
|
210
|
+
// Runs inside this pre-seed `try`, so refusing a non-empty store (or a
|
|
211
|
+
// failed probe query) is reported as "did not start", not "half-seeded".
|
|
212
|
+
await assertStoreEmpty(connection.client, ~probeViews=chosen.probeViews->Option.getOr([]))
|
|
182
213
|
Some((chosen, connection))
|
|
183
214
|
} catch {
|
|
184
215
|
| Failed(message) =>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|