@reventlessdev/reventless-seed 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +149 -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 +6 -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 +12 -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 +382 -21
- package/lib/bs/src/Seed_Client.res.mjs +332 -24
- 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 +281 -33
- package/lib/bs/src/Seed_Connect.res.mjs +162 -8
- 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 +140 -41
- package/lib/bs/src/Seed_Prompt.res.mjs +88 -13
- package/lib/bs/src/Seed_Random-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Random-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Random.ast +0 -0
- package/lib/bs/src/Seed_Random.res +4 -2
- 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 +45 -19
- 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 +43 -43
- 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 +92 -0
- package/lib/bs/src/Seed_Users.res.mjs +91 -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 +287 -0
- package/lib/bs/tests/Seed_ClientTest.res.mjs +268 -0
- package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_ConnectTest.ast +0 -0
- package/lib/bs/tests/Seed_ConnectTest.res +64 -0
- package/lib/bs/tests/Seed_ConnectTest.res.mjs +56 -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 +55 -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 +200 -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 +129 -0
- package/lib/bs/tests/Seed_UsersTest.res.mjs +113 -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 +6 -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 +12 -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 +382 -21
- 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 +287 -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 +281 -33
- package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_ConnectTest.ast +0 -0
- package/lib/ocaml/Seed_ConnectTest.res +64 -0
- 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 +140 -41
- 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 +55 -0
- package/lib/ocaml/Seed_Random-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Random-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Random.ast +0 -0
- package/lib/ocaml/Seed_Random.res +4 -2
- 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 +200 -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 +45 -19
- 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 +43 -43
- 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 +92 -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 +129 -0
- package/package.json +7 -2
- package/rescript.json +9 -1
- package/src/Seed.res +12 -3
- package/src/Seed.res.mjs +3 -0
- package/src/Seed_Client.res +382 -21
- package/src/Seed_Client.res.mjs +332 -24
- package/src/Seed_Connect.res +281 -33
- package/src/Seed_Connect.res.mjs +162 -8
- package/src/Seed_Prompt.res +140 -41
- package/src/Seed_Prompt.res.mjs +88 -13
- package/src/Seed_Random.res +4 -2
- package/src/Seed_Runner.res +45 -19
- package/src/Seed_Runner.res.mjs +19 -1
- package/src/Seed_Upload.res +43 -43
- package/src/Seed_Upload.res.mjs +65 -69
- package/src/Seed_Users.res +92 -0
- package/src/Seed_Users.res.mjs +91 -0
- package/tests/Seed_ClientTest.res +287 -0
- package/tests/Seed_ClientTest.res.mjs +268 -0
- package/tests/Seed_ConnectTest.res +64 -0
- package/tests/Seed_ConnectTest.res.mjs +56 -0
- package/tests/Seed_PromptTest.res +55 -0
- package/tests/Seed_PromptTest.res.mjs +63 -0
- package/tests/Seed_RandomTest.res +200 -0
- package/tests/Seed_RandomTest.res.mjs +208 -0
- package/tests/Seed_UsersTest.res +129 -0
- package/tests/Seed_UsersTest.res.mjs +113 -0
|
Binary file
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
open JestGlobals
|
|
2
|
+
|
|
3
|
+
// `SEED_ROLE` is how a run says what to act as when nobody can answer a prompt —
|
|
4
|
+
// a CI run wedged by a stored narrowing, or a deliberate restricted run.
|
|
5
|
+
//
|
|
6
|
+
// It carries two different intentions in one variable, which is why the parsing
|
|
7
|
+
// is worth pinning: naming a role narrows to it, and the "give me everything"
|
|
8
|
+
// answer has several spellings because an operator setting it by hand will write
|
|
9
|
+
// whichever one comes to mind. Getting that wrong is not a typo — `SEED_ROLE=full`
|
|
10
|
+
// read as a role named "full" would ask the platform to act as a group nobody
|
|
11
|
+
// holds, and be refused.
|
|
12
|
+
|
|
13
|
+
let withEnv = (value: option<string>, f: unit => unit) => {
|
|
14
|
+
let key = "SEED_ROLE"
|
|
15
|
+
let previous = NodeProcess.env->Dict.get(key)
|
|
16
|
+
switch value {
|
|
17
|
+
| Some(v) => NodeProcess.env->Dict.set(key, v)
|
|
18
|
+
| None => NodeProcess.env->Dict.delete(key)
|
|
19
|
+
}
|
|
20
|
+
f()
|
|
21
|
+
switch previous {
|
|
22
|
+
| Some(v) => NodeProcess.env->Dict.set(key, v)
|
|
23
|
+
| None => NodeProcess.env->Dict.delete(key)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("Seed_Connect.roleFromEnv:", () => {
|
|
28
|
+
testSync("is absent when nothing asked for a role", () =>
|
|
29
|
+
withEnv(None, () => expect(Seed_Connect.roleFromEnv())->Expect.toEqual(None))
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
testSync("reads a named role as a narrowing to it", () =>
|
|
33
|
+
withEnv(
|
|
34
|
+
Some("Shopper"),
|
|
35
|
+
() =>
|
|
36
|
+
expect(Seed_Connect.roleFromEnv())->Expect.toEqual(Some(Seed_Connect.Narrowed("Shopper"))),
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
// Every spelling of "everything" an operator might reach for. They all mean
|
|
41
|
+
// clear the stored choice, which is what seeding wants.
|
|
42
|
+
testSync("takes each spelling of full membership as a clear", () =>
|
|
43
|
+
["full", "all", "none", "clear", "FULL", "All"]->Array.forEach(
|
|
44
|
+
v =>
|
|
45
|
+
withEnv(
|
|
46
|
+
Some(v),
|
|
47
|
+
() => expect(Seed_Connect.roleFromEnv())->Expect.toEqual(Some(Seed_Connect.Full)),
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
// Role names are case-sensitive to the platform (`mayActAs` compares exactly),
|
|
53
|
+
// so a named role is passed through untouched — only the clear vocabulary is
|
|
54
|
+
// case-folded.
|
|
55
|
+
testSync("passes a role name through with its case intact", () =>
|
|
56
|
+
withEnv(
|
|
57
|
+
Some("Merchandiser"),
|
|
58
|
+
() =>
|
|
59
|
+
expect(Seed_Connect.roleFromEnv())->Expect.toEqual(
|
|
60
|
+
Some(Seed_Connect.Narrowed("Merchandiser")),
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
})
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -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,27 +48,31 @@ 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
|
|
|
66
|
+
/** Whether an interactive prompt is possible at all. Callers that can carry on
|
|
67
|
+
without an answer ask this first; a prompt nobody can answer is worse than a
|
|
68
|
+
default, because it turns a workable run into a hang or a throw. */
|
|
69
|
+
let hasTty = (): bool => NodeProcess.stdin->NodeProcess.isTTY->Option.getOr(false)
|
|
70
|
+
|
|
76
71
|
let requireTty = (): unit =>
|
|
77
|
-
if !(
|
|
72
|
+
if !hasTty() {
|
|
78
73
|
throw(
|
|
79
74
|
Failed(
|
|
80
|
-
"no TTY for an interactive prompt — set the documented SEED_* / REVENTLESS_DEMO_* " ++
|
|
81
|
-
"env vars to run non-interactively.",
|
|
75
|
+
"no TTY for an interactive prompt — set the documented SEED_* / REVENTLESS_DEMO_* " ++ "env vars to run non-interactively.",
|
|
82
76
|
),
|
|
83
77
|
)
|
|
84
78
|
}
|
|
@@ -101,24 +95,41 @@ let askHidden = (query: string): promise<string> =>
|
|
|
101
95
|
let rl = iface()
|
|
102
96
|
rl->question(query, answer => {
|
|
103
97
|
muted := false
|
|
104
|
-
stdout->
|
|
98
|
+
NodeProcess.stdout->NodeProcess.write("\n")
|
|
105
99
|
resolve(answer)
|
|
106
100
|
})
|
|
107
101
|
muted := true
|
|
108
102
|
})
|
|
109
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Whether an answer means yes — the one vocabulary, for the typed reply and the
|
|
106
|
+
* env var that stands in for it alike.
|
|
107
|
+
*
|
|
108
|
+
* It exists because those two drifted: a `[y/N]` prompt took `y`, and the env
|
|
109
|
+
* var beside it took only `1` or `yes`, so the obvious `SEED_RESET_CONFIRM=y`
|
|
110
|
+
* silently fell through to the interactive branch — which, on the CI runs the
|
|
111
|
+
* variable exists for, has no TTY and throws. Two spellings of one question are
|
|
112
|
+
* one spelling too many; callers ask this instead of comparing strings.
|
|
113
|
+
*
|
|
114
|
+
* Trimmed and case-folded, so `Yes`/` y ` answer the same as `y`.
|
|
115
|
+
*/
|
|
116
|
+
let isAffirmative = (answer: string): bool =>
|
|
117
|
+
switch answer->String.trim->String.toLowerCase {
|
|
118
|
+
| "y" | "yes" | "1" => true
|
|
119
|
+
| _ => false
|
|
120
|
+
}
|
|
121
|
+
|
|
110
122
|
/**
|
|
111
123
|
* Chooses one of `options` (a label paired with the value it selects).
|
|
112
124
|
*
|
|
113
125
|
* Auto-returns when there is a single option, so a lone data set or stack needs
|
|
114
126
|
* no keypress. `env` (e.g. `SEED_SET`) preselects by matching label or 1-based
|
|
115
127
|
* index, so CI runs without a TTY. Otherwise it prints a numbered menu.
|
|
128
|
+
*
|
|
129
|
+
* `defaultIndex` makes Enter a valid answer, selecting that 0-based option;
|
|
130
|
+
* without one every reply must name a choice.
|
|
116
131
|
*/
|
|
117
|
-
let select = async (
|
|
118
|
-
~title: string,
|
|
119
|
-
~options: array<(string, 'a)>,
|
|
120
|
-
~env=?,
|
|
121
|
-
): 'a =>
|
|
132
|
+
let select = async (~title: string, ~options: array<(string, 'a)>, ~env=?, ~defaultIndex=?): 'a =>
|
|
122
133
|
switch options {
|
|
123
134
|
| [(_, only)] => only
|
|
124
135
|
| _ =>
|
|
@@ -145,15 +156,24 @@ let select = async (
|
|
|
145
156
|
options->Array.forEachWithIndex(((label, _), i) =>
|
|
146
157
|
Console.log(` ${(i + 1)->Int.toString}) ${label}`)
|
|
147
158
|
)
|
|
159
|
+
let fallback = defaultIndex->Option.flatMap(i => options->Array.get(i))
|
|
160
|
+
let hint = switch (defaultIndex, fallback) {
|
|
161
|
+
| (Some(i), Some(_)) => ` (default ${(i + 1)->Int.toString})`
|
|
162
|
+
| _ => ""
|
|
163
|
+
}
|
|
148
164
|
let rec pick = async (): 'a => {
|
|
149
|
-
let answer = await ask(`\nSelect [1-${
|
|
150
|
-
switch
|
|
151
|
-
| Some(
|
|
152
|
-
let (_, value) = options->Array.getUnsafe(n - 1)
|
|
153
|
-
value
|
|
165
|
+
let answer = await ask(`\nSelect [1-${options->Array.length->Int.toString}]${hint}: `)
|
|
166
|
+
switch (answer, fallback) {
|
|
167
|
+
| ("", Some((_, value))) => value
|
|
154
168
|
| _ =>
|
|
155
|
-
|
|
156
|
-
|
|
169
|
+
switch Int.fromString(answer) {
|
|
170
|
+
| Some(n) if n >= 1 && n <= options->Array.length =>
|
|
171
|
+
let (_, value) = options->Array.getUnsafe(n - 1)
|
|
172
|
+
value
|
|
173
|
+
| _ =>
|
|
174
|
+
Console.log(" Not a valid choice.")
|
|
175
|
+
await pick()
|
|
176
|
+
}
|
|
157
177
|
}
|
|
158
178
|
}
|
|
159
179
|
await pick()
|
|
@@ -161,13 +181,30 @@ let select = async (
|
|
|
161
181
|
}
|
|
162
182
|
|
|
163
183
|
/**
|
|
164
|
-
*
|
|
184
|
+
* The account a run authenticated as, alongside every account the platform's
|
|
185
|
+
* accounts file declares.
|
|
165
186
|
*
|
|
166
|
-
* `
|
|
167
|
-
* `
|
|
187
|
+
* `accounts` is `[]` whenever no file was read — the
|
|
188
|
+
* `REVENTLESS_DEMO_USER`/`REVENTLESS_DEMO_PASSWORD` path bypasses it entirely,
|
|
189
|
+
* and so does typing both halves — so a consumer must handle empty rather than
|
|
190
|
+
* assume the file was there. `caller` is always populated, but carries no
|
|
191
|
+
* `groups` and no `userId` on those paths: nothing read them off a file.
|
|
168
192
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
193
|
+
type resolved = {caller: Seed_Users.user, accounts: array<Seed_Users.user>}
|
|
194
|
+
|
|
195
|
+
let typedUser = (~username: string, ~password: string): Seed_Users.user => {
|
|
196
|
+
username,
|
|
197
|
+
password,
|
|
198
|
+
groups: [],
|
|
199
|
+
userId: None,
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Typing both halves is the fallback, not the first offer: it is what happens
|
|
203
|
+
// when the platform keeps no accounts file. `envUser` is threaded in so a
|
|
204
|
+
// `REVENTLESS_DEMO_USER` that named nobody in the file still skips the username
|
|
205
|
+
// prompt rather than asking for a name that was already given.
|
|
206
|
+
let askCredentials = async (~localDefaults: bool, ~envUser: option<string>): Seed_Users.user => {
|
|
207
|
+
let username = switch envUser {
|
|
171
208
|
| Some(u) => u
|
|
172
209
|
| None =>
|
|
173
210
|
requireTty()
|
|
@@ -181,8 +218,70 @@ let credentials = async (~localDefaults: bool=false): (string, string) => {
|
|
|
181
218
|
let entered = await askHidden(localDefaults ? "Password [admin]: " : "Password: ")
|
|
182
219
|
entered == "" && localDefaults ? "admin" : entered
|
|
183
220
|
}
|
|
184
|
-
|
|
221
|
+
typedUser(~username, ~password)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// The accounts file the platform already keeps (`.reventless/users.yaml`, or
|
|
225
|
+
// `SEED_USERS_FILE`). It records the password beside the username, so choosing
|
|
226
|
+
// an account is the whole credential step — nothing is typed.
|
|
227
|
+
//
|
|
228
|
+
// A named `REVENTLESS_DEMO_USER` picks its entry directly; otherwise the file's
|
|
229
|
+
// accounts are offered in the order it defines them, first as the default.
|
|
230
|
+
// `None` means the file has nothing to offer and the caller should ask.
|
|
231
|
+
//
|
|
232
|
+
// The whole list travels back with the chosen account, not just the credentials
|
|
233
|
+
// it supplied: the file is also the only place a demo owner's id can be looked
|
|
234
|
+
// up, and reading it once to pick a login and never again is what let a data set
|
|
235
|
+
// seed rows under ids nobody on the platform holds.
|
|
236
|
+
let fromUsersFile = async (~envUser: option<string>): option<resolved> =>
|
|
237
|
+
switch Seed_Users.load(~path=?envValue("SEED_USERS_FILE")) {
|
|
238
|
+
| None => None
|
|
239
|
+
| Some((path, users)) =>
|
|
240
|
+
let chosen = switch envUser {
|
|
241
|
+
| Some(name) => users->Array.find(u => u.username == name)
|
|
242
|
+
| None =>
|
|
243
|
+
Some(
|
|
244
|
+
await select(
|
|
245
|
+
~title=`User (${path}):`,
|
|
246
|
+
~options=users->Array.map(u => (Seed_Users.label(u), u)),
|
|
247
|
+
~env="SEED_USER",
|
|
248
|
+
~defaultIndex=0,
|
|
249
|
+
),
|
|
250
|
+
)
|
|
251
|
+
}
|
|
252
|
+
// Logged for every arm, including the single-account file that selects
|
|
253
|
+
// itself without a keypress: which identity seeded the data is the thing an
|
|
254
|
+
// operator checks when owner-scoped rows turn up under the wrong account.
|
|
255
|
+
chosen->Option.map(u => {
|
|
256
|
+
Console.log(`Logging in as ${u.username} (from ${path})`)
|
|
257
|
+
{caller: u, accounts: users}
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Resolves the credentials a seed run logs in with.
|
|
263
|
+
*
|
|
264
|
+
* `REVENTLESS_DEMO_USER` + `REVENTLESS_DEMO_PASSWORD` together are the
|
|
265
|
+
* non-interactive path and skip everything below. Otherwise the platform's
|
|
266
|
+
* `.reventless/users.yaml` supplies the accounts to choose from, and only a
|
|
267
|
+
* platform without one falls back to typing both halves — where, with
|
|
268
|
+
* `localDefaults`, empty input means `admin`/`admin`.
|
|
269
|
+
*
|
|
270
|
+
* Returns the resolved account rather than a pair, and the accounts file
|
|
271
|
+
* alongside it when there was one — see `resolved`.
|
|
272
|
+
*/
|
|
273
|
+
let credentials = async (~localDefaults: bool=false): resolved => {
|
|
274
|
+
let envUser = envValue("REVENTLESS_DEMO_USER")
|
|
275
|
+
let resolved = switch (envUser, envValue("REVENTLESS_DEMO_PASSWORD")) {
|
|
276
|
+
| (Some(username), Some(password)) => {caller: typedUser(~username, ~password), accounts: []}
|
|
277
|
+
| _ =>
|
|
278
|
+
switch await fromUsersFile(~envUser) {
|
|
279
|
+
| Some(resolved) => resolved
|
|
280
|
+
| None => {caller: await askCredentials(~localDefaults, ~envUser), accounts: []}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if resolved.caller.username == "" || resolved.caller.password == "" {
|
|
185
284
|
throw(Failed("username and password are required."))
|
|
186
285
|
}
|
|
187
|
-
|
|
286
|
+
resolved
|
|
188
287
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,55 @@
|
|
|
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 => expect(Seed_Prompt.isAffirmative(v))->Expect.toBe(true))
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// A prompt that prints `[y/N]` invites a capital as readily as a lowercase
|
|
22
|
+
// one, and an env var set by hand is written however the hand felt.
|
|
23
|
+
testSync("ignores case, so Y and YES answer as y does", () => {
|
|
24
|
+
["Y", "Yes", "YES"]->Array.forEach(v => expect(Seed_Prompt.isAffirmative(v))->Expect.toBe(true))
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
testSync("ignores surrounding space", () => {
|
|
28
|
+
[" y", "y ", " yes "]->Array.forEach(
|
|
29
|
+
v => expect(Seed_Prompt.isAffirmative(v))->Expect.toBe(true),
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// The half that matters most: every one of these is an ANSWER, and the caller
|
|
34
|
+
// reads it as "no". None may be mistaken for "nothing was said", which is what
|
|
35
|
+
// sent the old code to a prompt it could not open.
|
|
36
|
+
testSync("declines every spelling of no, capital N included", () => {
|
|
37
|
+
["n", "N", "no", "No", "NO"]->Array.forEach(
|
|
38
|
+
v => expect(Seed_Prompt.isAffirmative(v))->Expect.toBe(false),
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
testSync("declines anything it does not recognise", () => {
|
|
43
|
+
["", " ", "0", "true", "yep", "y.", "yesplease", "affirmative"]->Array.forEach(
|
|
44
|
+
v => expect(Seed_Prompt.isAffirmative(v))->Expect.toBe(false),
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
// `true` is deliberately absent from the vocabulary above. Named here so that
|
|
49
|
+
// adding it is a decision someone takes against a failing test rather than a
|
|
50
|
+
// kindness someone slips in: the prompt this stands in for asks `[y/N]`, and a
|
|
51
|
+
// reply nobody would type at that prompt should not work around it either.
|
|
52
|
+
testSync("does not quietly grow a fourth spelling", () => {
|
|
53
|
+
expect(Seed_Prompt.isAffirmative("true"))->Expect.toBe(false)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -10,13 +10,15 @@ type t = {mutable state: int}
|
|
|
10
10
|
|
|
11
11
|
let make = (~seed: int): t => {state: seed}
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
/** mulberry32 — small, fast, and stable across JS engines and Node versions. */
|
|
15
14
|
let float = (r: t): float => {
|
|
16
15
|
r.state = (r.state + 0x6d2b79f5)->Int.bitwiseOr(0)
|
|
17
16
|
let a = r.state
|
|
18
17
|
let b = imul(a->Int.bitwiseXor(a->Int.shiftRightUnsigned(15)), a->Int.bitwiseOr(1))
|
|
19
|
-
let c =
|
|
18
|
+
let c =
|
|
19
|
+
b->Int.bitwiseXor(
|
|
20
|
+
b + imul(b->Int.bitwiseXor(b->Int.shiftRightUnsigned(7)), b->Int.bitwiseOr(61)),
|
|
21
|
+
)
|
|
20
22
|
let bits = c->Int.bitwiseXor(c->Int.shiftRightUnsigned(14))
|
|
21
23
|
// `bits` is a signed 32-bit result; fold the sign bit back in to get the
|
|
22
24
|
// unsigned value a `>>> 0` would produce.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,200 @@
|
|
|
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(
|
|
20
|
+
"the same seed replays the same sequence",
|
|
21
|
+
() => expect(take(~seed=42, ~n=25))->toEqual(take(~seed=42, ~n=25)),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
// Without this, a generator that returned a constant would satisfy the
|
|
25
|
+
// case above and nothing else in the suite would catch it.
|
|
26
|
+
testSync(
|
|
27
|
+
"different seeds diverge",
|
|
28
|
+
() => expect(take(~seed=42, ~n=25) == take(~seed=43, ~n=25))->toBe(false),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
testSync(
|
|
32
|
+
"a fresh generator does not continue the previous one",
|
|
33
|
+
() => {
|
|
34
|
+
let r = Seed_Random.make(~seed=7)
|
|
35
|
+
let first = Seed_Random.float(r)
|
|
36
|
+
let _ = Seed_Random.float(r)
|
|
37
|
+
expect(Seed_Random.float(Seed_Random.make(~seed=7)))->toEqual(first)
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe("float stays a unit interval:", () => {
|
|
43
|
+
// mulberry32's last step is a signed 32-bit value folded back to unsigned.
|
|
44
|
+
// Get that fold wrong and roughly half the draws come out negative, which
|
|
45
|
+
// every consumer below (int, pick, sampleWeighted) silently mis-scales.
|
|
46
|
+
testSync(
|
|
47
|
+
"every draw is in [0, 1)",
|
|
48
|
+
() => expect(take(~seed=99, ~n=500)->Array.every(f => f >= 0.0 && f < 1.0))->toBe(true),
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
testSync(
|
|
52
|
+
"and the draws are not all the same value",
|
|
53
|
+
() => {
|
|
54
|
+
let draws = take(~seed=99, ~n=100)
|
|
55
|
+
expect(draws->Array.some(f => f != draws->Array.getUnsafe(0)))->toBe(true)
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
describe("int is inclusive on both ends, as documented:", () => {
|
|
61
|
+
let draws = (~min, ~max, ~n) => {
|
|
62
|
+
let r = Seed_Random.make(~seed=5)
|
|
63
|
+
Array.make(~length=n, 0)->Array.map(_ => Seed_Random.int(r, ~min, ~max))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
testSync(
|
|
67
|
+
"never escapes the range",
|
|
68
|
+
() => expect(draws(~min=3, ~max=7, ~n=500)->Array.every(i => i >= 3 && i <= 7))->toBe(true),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
// The documented contract is "inclusive on both ends"; an off-by-one in the
|
|
72
|
+
// `max - min + 1` scaling shows up as a bound that is never drawn.
|
|
73
|
+
testSync(
|
|
74
|
+
"reaches both bounds",
|
|
75
|
+
() => {
|
|
76
|
+
let d = draws(~min=3, ~max=7, ~n=500)
|
|
77
|
+
expect((d->Array.includes(3), d->Array.includes(7)))->toEqual((true, true))
|
|
78
|
+
},
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
testSync(
|
|
82
|
+
"a single-value range is that value",
|
|
83
|
+
() => expect(draws(~min=4, ~max=4, ~n=10)->Array.every(i => i == 4))->toBe(true),
|
|
84
|
+
)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe("pick:", () => {
|
|
88
|
+
testSync(
|
|
89
|
+
"returns None for an empty array",
|
|
90
|
+
() => expect(Seed_Random.make(~seed=1)->Seed_Random.pick([]))->toEqual(None),
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
testSync(
|
|
94
|
+
"always lands on a member",
|
|
95
|
+
() => {
|
|
96
|
+
let r = Seed_Random.make(~seed=2)
|
|
97
|
+
let xs = ["a", "b", "c", "d"]
|
|
98
|
+
let hits =
|
|
99
|
+
Array.make(~length=200, "")->Array.map(_ => r->Seed_Random.pickOr(~fallback="MISS", xs))
|
|
100
|
+
expect(hits->Array.every(h => xs->Array.includes(h)))->toBe(true)
|
|
101
|
+
},
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
testSync(
|
|
105
|
+
"pickOr falls back only when there is nothing to pick",
|
|
106
|
+
() =>
|
|
107
|
+
expect(Seed_Random.make(~seed=3)->Seed_Random.pickOr(~fallback="fallback", []))->toBe(
|
|
108
|
+
"fallback",
|
|
109
|
+
),
|
|
110
|
+
)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
describe("sampleWeighted is without replacement:", () => {
|
|
114
|
+
let equal = xs => xs->Array.map(x => (x, 1.0))
|
|
115
|
+
|
|
116
|
+
// The documented shuffle use: equal weights, count = length. If sampling
|
|
117
|
+
// ever replaced instead of removing, duplicates would appear here.
|
|
118
|
+
testSync(
|
|
119
|
+
"count = length yields a permutation, not a multiset",
|
|
120
|
+
() => {
|
|
121
|
+
let xs = ["a", "b", "c", "d", "e"]
|
|
122
|
+
let out = Seed_Random.make(~seed=11)->Seed_Random.sampleWeighted(equal(xs), ~count=5)
|
|
123
|
+
let sorted = out->Array.toSorted(String.compare)
|
|
124
|
+
expect((out->Array.length, sorted))->toEqual((5, ["a", "b", "c", "d", "e"]))
|
|
125
|
+
},
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
testSync(
|
|
129
|
+
"count < length returns exactly count distinct items",
|
|
130
|
+
() => {
|
|
131
|
+
let xs = ["a", "b", "c", "d", "e"]
|
|
132
|
+
let out = Seed_Random.make(~seed=12)->Seed_Random.sampleWeighted(equal(xs), ~count=3)
|
|
133
|
+
let distinct = Set.fromArray(out)->Set.size
|
|
134
|
+
expect((out->Array.length, distinct))->toEqual((3, 3))
|
|
135
|
+
},
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
testSync(
|
|
139
|
+
"count > length clamps to the pool",
|
|
140
|
+
() =>
|
|
141
|
+
expect(
|
|
142
|
+
Seed_Random.make(~seed=13)
|
|
143
|
+
->Seed_Random.sampleWeighted(equal(["a", "b"]), ~count=99)
|
|
144
|
+
->Array.length,
|
|
145
|
+
)->toBe(2),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
testSync(
|
|
149
|
+
"a zero-weight entry is never chosen while others remain",
|
|
150
|
+
() => {
|
|
151
|
+
let out =
|
|
152
|
+
Seed_Random.make(~seed=14)->Seed_Random.sampleWeighted(
|
|
153
|
+
[("never", 0.0), ("a", 1.0), ("b", 1.0)],
|
|
154
|
+
~count=2,
|
|
155
|
+
)
|
|
156
|
+
expect(out->Array.includes("never"))->toBe(false)
|
|
157
|
+
},
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
testSync(
|
|
161
|
+
"is reproducible for a given seed",
|
|
162
|
+
() => {
|
|
163
|
+
let run = () =>
|
|
164
|
+
Seed_Random.make(~seed=15)->Seed_Random.sampleWeighted(
|
|
165
|
+
equal(["a", "b", "c", "d", "e", "f"]),
|
|
166
|
+
~count=4,
|
|
167
|
+
)
|
|
168
|
+
expect(run())->toEqual(run())
|
|
169
|
+
},
|
|
170
|
+
)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
describe("zipfWeights skews toward the head:", () => {
|
|
174
|
+
let weights = Seed_Random.zipfWeights(["a", "b", "c", "d", "e"], ~exponent=1.1)
|
|
175
|
+
|
|
176
|
+
testSync(
|
|
177
|
+
"keeps every item, in order",
|
|
178
|
+
() => expect(weights->Array.map(((item, _)) => item))->toEqual(["a", "b", "c", "d", "e"]),
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
testSync(
|
|
182
|
+
"weight decreases monotonically with rank",
|
|
183
|
+
() => {
|
|
184
|
+
let ws = weights->Array.map(((_, w)) => w)
|
|
185
|
+
let decreasing =
|
|
186
|
+
ws->Array.everyWithIndex((w, i) => i == 0 || w < ws->Array.getUnsafe(i - 1))
|
|
187
|
+
expect(decreasing)->toBe(true)
|
|
188
|
+
},
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
testSync(
|
|
192
|
+
"the leader is clear — first outweighs last several times over",
|
|
193
|
+
() => {
|
|
194
|
+
let first = weights->Array.get(0)->Option.mapOr(0.0, ((_, w)) => w)
|
|
195
|
+
let last = weights->Array.get(4)->Option.mapOr(0.0, ((_, w)) => w)
|
|
196
|
+
expect(first > last *. 3.0)->toBe(true)
|
|
197
|
+
},
|
|
198
|
+
)
|
|
199
|
+
})
|
|
200
|
+
})
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|