@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.
Files changed (178) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/lib/bs/.compiler.log +2 -2
  3. package/lib/bs/.sourcedirs.json +1 -0
  4. package/lib/bs/ReventlessSeed.cmi +0 -0
  5. package/lib/bs/ReventlessSeed.cmt +0 -0
  6. package/lib/bs/ReventlessSeed.mlmap +6 -0
  7. package/lib/bs/compiler-info.json +2 -2
  8. package/lib/bs/src/Seed-ReventlessSeed.cmi +0 -0
  9. package/lib/bs/src/Seed-ReventlessSeed.cmt +0 -0
  10. package/lib/bs/src/Seed.ast +0 -0
  11. package/lib/bs/src/Seed.res +12 -3
  12. package/lib/bs/src/Seed.res.mjs +3 -0
  13. package/lib/bs/src/Seed_Client-ReventlessSeed.cmi +0 -0
  14. package/lib/bs/src/Seed_Client-ReventlessSeed.cmj +0 -0
  15. package/lib/bs/src/Seed_Client-ReventlessSeed.cmt +0 -0
  16. package/lib/bs/src/Seed_Client.ast +0 -0
  17. package/lib/bs/src/Seed_Client.res +382 -21
  18. package/lib/bs/src/Seed_Client.res.mjs +332 -24
  19. package/lib/bs/src/Seed_Connect-ReventlessSeed.cmi +0 -0
  20. package/lib/bs/src/Seed_Connect-ReventlessSeed.cmj +0 -0
  21. package/lib/bs/src/Seed_Connect-ReventlessSeed.cmt +0 -0
  22. package/lib/bs/src/Seed_Connect.ast +0 -0
  23. package/lib/bs/src/Seed_Connect.res +281 -33
  24. package/lib/bs/src/Seed_Connect.res.mjs +162 -8
  25. package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmi +0 -0
  26. package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmj +0 -0
  27. package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmt +0 -0
  28. package/lib/bs/src/Seed_Prompt.ast +0 -0
  29. package/lib/bs/src/Seed_Prompt.res +140 -41
  30. package/lib/bs/src/Seed_Prompt.res.mjs +88 -13
  31. package/lib/bs/src/Seed_Random-ReventlessSeed.cmi +0 -0
  32. package/lib/bs/src/Seed_Random-ReventlessSeed.cmt +0 -0
  33. package/lib/bs/src/Seed_Random.ast +0 -0
  34. package/lib/bs/src/Seed_Random.res +4 -2
  35. package/lib/bs/src/Seed_Runner-ReventlessSeed.cmi +0 -0
  36. package/lib/bs/src/Seed_Runner-ReventlessSeed.cmj +0 -0
  37. package/lib/bs/src/Seed_Runner-ReventlessSeed.cmt +0 -0
  38. package/lib/bs/src/Seed_Runner.ast +0 -0
  39. package/lib/bs/src/Seed_Runner.res +45 -19
  40. package/lib/bs/src/Seed_Runner.res.mjs +19 -1
  41. package/lib/bs/src/Seed_Types-ReventlessSeed.cmt +0 -0
  42. package/lib/bs/src/Seed_Upload-ReventlessSeed.cmi +0 -0
  43. package/lib/bs/src/Seed_Upload-ReventlessSeed.cmj +0 -0
  44. package/lib/bs/src/Seed_Upload-ReventlessSeed.cmt +0 -0
  45. package/lib/bs/src/Seed_Upload.ast +0 -0
  46. package/lib/bs/src/Seed_Upload.res +43 -43
  47. package/lib/bs/src/Seed_Upload.res.mjs +65 -69
  48. package/lib/bs/src/Seed_Users-ReventlessSeed.cmi +0 -0
  49. package/lib/bs/src/Seed_Users-ReventlessSeed.cmj +0 -0
  50. package/lib/bs/src/Seed_Users-ReventlessSeed.cmt +0 -0
  51. package/lib/bs/src/Seed_Users.ast +0 -0
  52. package/lib/bs/src/Seed_Users.res +92 -0
  53. package/lib/bs/src/Seed_Users.res.mjs +91 -0
  54. package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmi +0 -0
  55. package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmj +0 -0
  56. package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmt +0 -0
  57. package/lib/bs/tests/Seed_ClientTest.ast +0 -0
  58. package/lib/bs/tests/Seed_ClientTest.res +287 -0
  59. package/lib/bs/tests/Seed_ClientTest.res.mjs +268 -0
  60. package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmi +0 -0
  61. package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmj +0 -0
  62. package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmt +0 -0
  63. package/lib/bs/tests/Seed_ConnectTest.ast +0 -0
  64. package/lib/bs/tests/Seed_ConnectTest.res +64 -0
  65. package/lib/bs/tests/Seed_ConnectTest.res.mjs +56 -0
  66. package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmi +0 -0
  67. package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmj +0 -0
  68. package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmt +0 -0
  69. package/lib/bs/tests/Seed_PromptTest.ast +0 -0
  70. package/lib/bs/tests/Seed_PromptTest.res +55 -0
  71. package/lib/bs/tests/Seed_PromptTest.res.mjs +63 -0
  72. package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmi +0 -0
  73. package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmj +0 -0
  74. package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmt +0 -0
  75. package/lib/bs/tests/Seed_RandomTest.ast +0 -0
  76. package/lib/bs/tests/Seed_RandomTest.res +200 -0
  77. package/lib/bs/tests/Seed_RandomTest.res.mjs +208 -0
  78. package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmi +0 -0
  79. package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmj +0 -0
  80. package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmt +0 -0
  81. package/lib/bs/tests/Seed_UsersTest.ast +0 -0
  82. package/lib/bs/tests/Seed_UsersTest.res +129 -0
  83. package/lib/bs/tests/Seed_UsersTest.res.mjs +113 -0
  84. package/lib/ocaml/.compiler.log +2 -2
  85. package/lib/ocaml/ReventlessSeed.cmi +0 -0
  86. package/lib/ocaml/ReventlessSeed.cmt +0 -0
  87. package/lib/ocaml/ReventlessSeed.mlmap +6 -0
  88. package/lib/ocaml/Seed-ReventlessSeed.cmi +0 -0
  89. package/lib/ocaml/Seed-ReventlessSeed.cmt +0 -0
  90. package/lib/ocaml/Seed.ast +0 -0
  91. package/lib/ocaml/Seed.res +12 -3
  92. package/lib/ocaml/Seed_Client-ReventlessSeed.cmi +0 -0
  93. package/lib/ocaml/Seed_Client-ReventlessSeed.cmj +0 -0
  94. package/lib/ocaml/Seed_Client-ReventlessSeed.cmt +0 -0
  95. package/lib/ocaml/Seed_Client.ast +0 -0
  96. package/lib/ocaml/Seed_Client.res +382 -21
  97. package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmi +0 -0
  98. package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmj +0 -0
  99. package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmt +0 -0
  100. package/lib/ocaml/Seed_ClientTest.ast +0 -0
  101. package/lib/ocaml/Seed_ClientTest.res +287 -0
  102. package/lib/ocaml/Seed_Connect-ReventlessSeed.cmi +0 -0
  103. package/lib/ocaml/Seed_Connect-ReventlessSeed.cmj +0 -0
  104. package/lib/ocaml/Seed_Connect-ReventlessSeed.cmt +0 -0
  105. package/lib/ocaml/Seed_Connect.ast +0 -0
  106. package/lib/ocaml/Seed_Connect.res +281 -33
  107. package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmi +0 -0
  108. package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmj +0 -0
  109. package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmt +0 -0
  110. package/lib/ocaml/Seed_ConnectTest.ast +0 -0
  111. package/lib/ocaml/Seed_ConnectTest.res +64 -0
  112. package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmi +0 -0
  113. package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmj +0 -0
  114. package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmt +0 -0
  115. package/lib/ocaml/Seed_Prompt.ast +0 -0
  116. package/lib/ocaml/Seed_Prompt.res +140 -41
  117. package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmi +0 -0
  118. package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmj +0 -0
  119. package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmt +0 -0
  120. package/lib/ocaml/Seed_PromptTest.ast +0 -0
  121. package/lib/ocaml/Seed_PromptTest.res +55 -0
  122. package/lib/ocaml/Seed_Random-ReventlessSeed.cmi +0 -0
  123. package/lib/ocaml/Seed_Random-ReventlessSeed.cmt +0 -0
  124. package/lib/ocaml/Seed_Random.ast +0 -0
  125. package/lib/ocaml/Seed_Random.res +4 -2
  126. package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmi +0 -0
  127. package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmj +0 -0
  128. package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmt +0 -0
  129. package/lib/ocaml/Seed_RandomTest.ast +0 -0
  130. package/lib/ocaml/Seed_RandomTest.res +200 -0
  131. package/lib/ocaml/Seed_Runner-ReventlessSeed.cmi +0 -0
  132. package/lib/ocaml/Seed_Runner-ReventlessSeed.cmj +0 -0
  133. package/lib/ocaml/Seed_Runner-ReventlessSeed.cmt +0 -0
  134. package/lib/ocaml/Seed_Runner.ast +0 -0
  135. package/lib/ocaml/Seed_Runner.res +45 -19
  136. package/lib/ocaml/Seed_Types-ReventlessSeed.cmt +0 -0
  137. package/lib/ocaml/Seed_Upload-ReventlessSeed.cmi +0 -0
  138. package/lib/ocaml/Seed_Upload-ReventlessSeed.cmj +0 -0
  139. package/lib/ocaml/Seed_Upload-ReventlessSeed.cmt +0 -0
  140. package/lib/ocaml/Seed_Upload.ast +0 -0
  141. package/lib/ocaml/Seed_Upload.res +43 -43
  142. package/lib/ocaml/Seed_Users-ReventlessSeed.cmi +0 -0
  143. package/lib/ocaml/Seed_Users-ReventlessSeed.cmj +0 -0
  144. package/lib/ocaml/Seed_Users-ReventlessSeed.cmt +0 -0
  145. package/lib/ocaml/Seed_Users.ast +0 -0
  146. package/lib/ocaml/Seed_Users.res +92 -0
  147. package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmi +0 -0
  148. package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmj +0 -0
  149. package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmt +0 -0
  150. package/lib/ocaml/Seed_UsersTest.ast +0 -0
  151. package/lib/ocaml/Seed_UsersTest.res +129 -0
  152. package/package.json +7 -2
  153. package/rescript.json +9 -1
  154. package/src/Seed.res +12 -3
  155. package/src/Seed.res.mjs +3 -0
  156. package/src/Seed_Client.res +382 -21
  157. package/src/Seed_Client.res.mjs +332 -24
  158. package/src/Seed_Connect.res +281 -33
  159. package/src/Seed_Connect.res.mjs +162 -8
  160. package/src/Seed_Prompt.res +140 -41
  161. package/src/Seed_Prompt.res.mjs +88 -13
  162. package/src/Seed_Random.res +4 -2
  163. package/src/Seed_Runner.res +45 -19
  164. package/src/Seed_Runner.res.mjs +19 -1
  165. package/src/Seed_Upload.res +43 -43
  166. package/src/Seed_Upload.res.mjs +65 -69
  167. package/src/Seed_Users.res +92 -0
  168. package/src/Seed_Users.res.mjs +91 -0
  169. package/tests/Seed_ClientTest.res +287 -0
  170. package/tests/Seed_ClientTest.res.mjs +268 -0
  171. package/tests/Seed_ConnectTest.res +64 -0
  172. package/tests/Seed_ConnectTest.res.mjs +56 -0
  173. package/tests/Seed_PromptTest.res +55 -0
  174. package/tests/Seed_PromptTest.res.mjs +63 -0
  175. package/tests/Seed_RandomTest.res +200 -0
  176. package/tests/Seed_RandomTest.res.mjs +208 -0
  177. package/tests/Seed_UsersTest.res +129 -0
  178. package/tests/Seed_UsersTest.res.mjs +113 -0
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
+ })
@@ -0,0 +1,63 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Seed_Prompt$ReventlessSeed from "../src/Seed_Prompt.res.mjs";
4
+
5
+ globalThis.describe("Seed_Prompt.isAffirmative:", () => {
6
+ globalThis.test("takes the three spellings of yes", () => {
7
+ [
8
+ "y",
9
+ "yes",
10
+ "1"
11
+ ].forEach(v => {
12
+ globalThis.expect(Seed_Prompt$ReventlessSeed.isAffirmative(v)).toBe(true);
13
+ });
14
+ });
15
+ globalThis.test("ignores case, so Y and YES answer as y does", () => {
16
+ [
17
+ "Y",
18
+ "Yes",
19
+ "YES"
20
+ ].forEach(v => {
21
+ globalThis.expect(Seed_Prompt$ReventlessSeed.isAffirmative(v)).toBe(true);
22
+ });
23
+ });
24
+ globalThis.test("ignores surrounding space", () => {
25
+ [
26
+ " y",
27
+ "y ",
28
+ " yes "
29
+ ].forEach(v => {
30
+ globalThis.expect(Seed_Prompt$ReventlessSeed.isAffirmative(v)).toBe(true);
31
+ });
32
+ });
33
+ globalThis.test("declines every spelling of no, capital N included", () => {
34
+ [
35
+ "n",
36
+ "N",
37
+ "no",
38
+ "No",
39
+ "NO"
40
+ ].forEach(v => {
41
+ globalThis.expect(Seed_Prompt$ReventlessSeed.isAffirmative(v)).toBe(false);
42
+ });
43
+ });
44
+ globalThis.test("declines anything it does not recognise", () => {
45
+ [
46
+ "",
47
+ " ",
48
+ "0",
49
+ "true",
50
+ "yep",
51
+ "y.",
52
+ "yesplease",
53
+ "affirmative"
54
+ ].forEach(v => {
55
+ globalThis.expect(Seed_Prompt$ReventlessSeed.isAffirmative(v)).toBe(false);
56
+ });
57
+ });
58
+ globalThis.test("does not quietly grow a fourth spelling", () => {
59
+ globalThis.expect(Seed_Prompt$ReventlessSeed.isAffirmative("true")).toBe(false);
60
+ });
61
+ });
62
+
63
+ /* Not a pure module */
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
+ })
@@ -0,0 +1,208 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
4
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
5
+ import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
6
+ import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
7
+ import * as Seed_Random$ReventlessSeed from "../src/Seed_Random.res.mjs";
8
+
9
+ globalThis.describe("Seed_Random:", () => {
10
+ let take = (seed, n) => {
11
+ let r = Seed_Random$ReventlessSeed.make(seed);
12
+ return Stdlib_Array.make(n, 0.0).map(param => Seed_Random$ReventlessSeed.float(r));
13
+ };
14
+ globalThis.describe("reproducibility — the reason this module exists:", () => {
15
+ globalThis.test("the same seed replays the same sequence", () => {
16
+ globalThis.expect(take(42, 25)).toEqual(take(42, 25));
17
+ });
18
+ globalThis.test("different seeds diverge", () => {
19
+ globalThis.expect(Primitive_object.equal(take(42, 25), take(43, 25))).toBe(false);
20
+ });
21
+ globalThis.test("a fresh generator does not continue the previous one", () => {
22
+ let r = Seed_Random$ReventlessSeed.make(7);
23
+ let first = Seed_Random$ReventlessSeed.float(r);
24
+ Seed_Random$ReventlessSeed.float(r);
25
+ globalThis.expect(Seed_Random$ReventlessSeed.float(Seed_Random$ReventlessSeed.make(7))).toEqual(first);
26
+ });
27
+ });
28
+ globalThis.describe("float stays a unit interval:", () => {
29
+ globalThis.test("every draw is in [0, 1)", () => {
30
+ globalThis.expect(take(99, 500).every(f => {
31
+ if (f >= 0.0) {
32
+ return f < 1.0;
33
+ } else {
34
+ return false;
35
+ }
36
+ })).toBe(true);
37
+ });
38
+ globalThis.test("and the draws are not all the same value", () => {
39
+ let draws = take(99, 100);
40
+ globalThis.expect(draws.some(f => f !== draws[0])).toBe(true);
41
+ });
42
+ });
43
+ globalThis.describe("int is inclusive on both ends, as documented:", () => {
44
+ let draws = (min, max, n) => {
45
+ let r = Seed_Random$ReventlessSeed.make(5);
46
+ return Stdlib_Array.make(n, 0).map(param => Seed_Random$ReventlessSeed.int(r, min, max));
47
+ };
48
+ globalThis.test("never escapes the range", () => {
49
+ globalThis.expect(draws(3, 7, 500).every(i => {
50
+ if (i >= 3) {
51
+ return i <= 7;
52
+ } else {
53
+ return false;
54
+ }
55
+ })).toBe(true);
56
+ });
57
+ globalThis.test("reaches both bounds", () => {
58
+ let d = draws(3, 7, 500);
59
+ globalThis.expect([
60
+ d.includes(3),
61
+ d.includes(7)
62
+ ]).toEqual([
63
+ true,
64
+ true
65
+ ]);
66
+ });
67
+ globalThis.test("a single-value range is that value", () => {
68
+ globalThis.expect(draws(4, 4, 10).every(i => i === 4)).toBe(true);
69
+ });
70
+ });
71
+ globalThis.describe("pick:", () => {
72
+ globalThis.test("returns None for an empty array", () => {
73
+ globalThis.expect(Seed_Random$ReventlessSeed.pick(Seed_Random$ReventlessSeed.make(1), [])).toEqual(undefined);
74
+ });
75
+ globalThis.test("always lands on a member", () => {
76
+ let r = Seed_Random$ReventlessSeed.make(2);
77
+ let xs = [
78
+ "a",
79
+ "b",
80
+ "c",
81
+ "d"
82
+ ];
83
+ let hits = Stdlib_Array.make(200, "").map(param => Seed_Random$ReventlessSeed.pickOr(r, "MISS", xs));
84
+ globalThis.expect(hits.every(h => xs.includes(h))).toBe(true);
85
+ });
86
+ globalThis.test("pickOr falls back only when there is nothing to pick", () => {
87
+ globalThis.expect(Seed_Random$ReventlessSeed.pickOr(Seed_Random$ReventlessSeed.make(3), "fallback", [])).toBe("fallback");
88
+ });
89
+ });
90
+ globalThis.describe("sampleWeighted is without replacement:", () => {
91
+ let equal = xs => xs.map(x => [
92
+ x,
93
+ 1.0
94
+ ]);
95
+ globalThis.test("count = length yields a permutation, not a multiset", () => {
96
+ let xs = [
97
+ "a",
98
+ "b",
99
+ "c",
100
+ "d",
101
+ "e"
102
+ ];
103
+ let out = Seed_Random$ReventlessSeed.sampleWeighted(Seed_Random$ReventlessSeed.make(11), equal(xs), 5);
104
+ let sorted = out.toSorted(Primitive_string.compare);
105
+ globalThis.expect([
106
+ out.length,
107
+ sorted
108
+ ]).toEqual([
109
+ 5,
110
+ [
111
+ "a",
112
+ "b",
113
+ "c",
114
+ "d",
115
+ "e"
116
+ ]
117
+ ]);
118
+ });
119
+ globalThis.test("count < length returns exactly count distinct items", () => {
120
+ let xs = [
121
+ "a",
122
+ "b",
123
+ "c",
124
+ "d",
125
+ "e"
126
+ ];
127
+ let out = Seed_Random$ReventlessSeed.sampleWeighted(Seed_Random$ReventlessSeed.make(12), equal(xs), 3);
128
+ let distinct = new Set(out).size;
129
+ globalThis.expect([
130
+ out.length,
131
+ distinct
132
+ ]).toEqual([
133
+ 3,
134
+ 3
135
+ ]);
136
+ });
137
+ globalThis.test("count > length clamps to the pool", () => {
138
+ globalThis.expect(Seed_Random$ReventlessSeed.sampleWeighted(Seed_Random$ReventlessSeed.make(13), equal([
139
+ "a",
140
+ "b"
141
+ ]), 99).length).toBe(2);
142
+ });
143
+ globalThis.test("a zero-weight entry is never chosen while others remain", () => {
144
+ let out = Seed_Random$ReventlessSeed.sampleWeighted(Seed_Random$ReventlessSeed.make(14), [
145
+ [
146
+ "never",
147
+ 0.0
148
+ ],
149
+ [
150
+ "a",
151
+ 1.0
152
+ ],
153
+ [
154
+ "b",
155
+ 1.0
156
+ ]
157
+ ], 2);
158
+ globalThis.expect(out.includes("never")).toBe(false);
159
+ });
160
+ globalThis.test("is reproducible for a given seed", () => {
161
+ let run = () => Seed_Random$ReventlessSeed.sampleWeighted(Seed_Random$ReventlessSeed.make(15), equal([
162
+ "a",
163
+ "b",
164
+ "c",
165
+ "d",
166
+ "e",
167
+ "f"
168
+ ]), 4);
169
+ globalThis.expect(run()).toEqual(run());
170
+ });
171
+ });
172
+ globalThis.describe("zipfWeights skews toward the head:", () => {
173
+ let weights = Seed_Random$ReventlessSeed.zipfWeights([
174
+ "a",
175
+ "b",
176
+ "c",
177
+ "d",
178
+ "e"
179
+ ], 1.1);
180
+ globalThis.test("keeps every item, in order", () => {
181
+ globalThis.expect(weights.map(param => param[0])).toEqual([
182
+ "a",
183
+ "b",
184
+ "c",
185
+ "d",
186
+ "e"
187
+ ]);
188
+ });
189
+ globalThis.test("weight decreases monotonically with rank", () => {
190
+ let ws = weights.map(param => param[1]);
191
+ let decreasing = ws.every((w, i) => {
192
+ if (i === 0) {
193
+ return true;
194
+ } else {
195
+ return w < ws[i - 1 | 0];
196
+ }
197
+ });
198
+ globalThis.expect(decreasing).toBe(true);
199
+ });
200
+ globalThis.test("the leader is clear — first outweighs last several times over", () => {
201
+ let first = Stdlib_Option.mapOr(weights[0], 0.0, param => param[1]);
202
+ let last = Stdlib_Option.mapOr(weights[4], 0.0, param => param[1]);
203
+ globalThis.expect(first > last * 3.0).toBe(true);
204
+ });
205
+ });
206
+ });
207
+
208
+ /* Not a pure module */
Binary file
@@ -0,0 +1,129 @@
1
+ open JestGlobals
2
+
3
+ // `.reventless/users.yaml` is hand-maintained and shared with the auth adapter,
4
+ // so the seed reads it defensively: it must survive the comment blocks both
5
+ // copies carry, must not reorder the accounts (the first one is the prompt's
6
+ // default, so order IS the contract), and must never throw — a broken file costs
7
+ // the menu, not the run.
8
+
9
+ let document = `
10
+ # Local dev users — a comment block like the real file carries.
11
+
12
+ - username: admin
13
+ password: admin
14
+ groups: [Admin, Shopper]
15
+ userId: local-admin
16
+
17
+ - username: shopper
18
+ password: Shopper-2026!
19
+ groups: [Shopper]
20
+
21
+ - username: noGroups
22
+ password: pw
23
+ `
24
+
25
+ describe("Seed_Users.parseString:", () => {
26
+ testSync("reads every account, in the order the file defines them", () => {
27
+ let users = Seed_Users.parseString(document)
28
+ expect(users->Array.map(u => u.Seed_Users.username))->Expect.toEqual([
29
+ "admin",
30
+ "shopper",
31
+ "noGroups",
32
+ ])
33
+ })
34
+
35
+ testSync("carries the password beside the username", () => {
36
+ let users = Seed_Users.parseString(document)
37
+ expect(users->Array.map(u => u.Seed_Users.password))->Expect.toEqual([
38
+ "admin",
39
+ "Shopper-2026!",
40
+ "pw",
41
+ ])
42
+ })
43
+
44
+ testSync("keeps the groups, and reads a missing groups key as none", () => {
45
+ let users = Seed_Users.parseString(document)
46
+ expect(users->Array.map(u => u.Seed_Users.groups))->Expect.toEqual([
47
+ ["Admin", "Shopper"],
48
+ ["Shopper"],
49
+ [],
50
+ ])
51
+ })
52
+
53
+ // The half that was dropped, and the reason owner-scoped demo rows were keyed
54
+ // to ids nobody on a Cognito deployment holds: the file records the id the
55
+ // platform stamps, and reading it only for a password threw that away.
56
+ //
57
+ // Absent stays absent rather than defaulting to the username — a local file
58
+ // may omit it and let the auth adapter default it, and an AWS file records a
59
+ // sub no default could invent. Guessing here would look like an answer.
60
+ testSync("keeps the userId an entry declares, and reads a missing one as absent", () => {
61
+ let users = Seed_Users.parseString(document)
62
+ expect(users->Array.map(u => u.Seed_Users.userId))->Expect.toEqual([
63
+ Some("local-admin"),
64
+ None,
65
+ None,
66
+ ])
67
+ })
68
+
69
+ // An entry half-written by hand is the likely flaw in this file. Dropping it
70
+ // keeps the other accounts selectable; failing the parse would not.
71
+ testSync("skips an entry that names no password", () => {
72
+ let users = Seed_Users.parseString(`
73
+ - username: admin
74
+ password: admin
75
+ - username: halfWritten
76
+ groups: [Shopper]
77
+ `)
78
+ expect(users->Array.map(u => u.Seed_Users.username))->Expect.toEqual(["admin"])
79
+ })
80
+
81
+ testSync("yields no accounts for a document that is not a list", () => {
82
+ expect(Seed_Users.parseString("users: {}")->Array.length)->Expect.toBe(0)
83
+ })
84
+
85
+ // The whole point of returning accounts rather than raising: the caller falls
86
+ // back to prompting, and it can only do that if nothing here escapes.
87
+ testSync("yields no accounts for malformed YAML instead of throwing", () => {
88
+ expect(Seed_Users.parseString("- username: [unclosed")->Array.length)->Expect.toBe(0)
89
+ })
90
+ })
91
+
92
+ describe("Seed_Users.load:", () => {
93
+ testSync("is silent about a file that is not there", () => {
94
+ expect(Seed_Users.load(~path="/nonexistent/.reventless/users.yaml"))->Expect.toBe(None)
95
+ })
96
+ })
97
+
98
+ describe("Seed_Users.label:", () => {
99
+ testSync("names the groups an account carries", () => {
100
+ expect(
101
+ Seed_Users.label({
102
+ username: "admin",
103
+ password: "x",
104
+ groups: ["Admin", "Shopper"],
105
+ userId: None,
106
+ }),
107
+ )->Expect.toBe("admin [Admin, Shopper]")
108
+ })
109
+
110
+ testSync("is the bare username when the file records no groups", () => {
111
+ expect(
112
+ Seed_Users.label({username: "admin", password: "x", groups: [], userId: None}),
113
+ )->Expect.toBe("admin")
114
+ })
115
+
116
+ // The menu is unchanged by the id: an operator picks an account by name and
117
+ // membership, and a Cognito sub in the list would be noise at the one moment
118
+ // they are choosing a login.
119
+ testSync("says nothing about the userId", () => {
120
+ expect(
121
+ Seed_Users.label({
122
+ username: "admin",
123
+ password: "x",
124
+ groups: ["Admin"],
125
+ userId: Some("4275e4a4-00c1-70e1-1cb5-363b06b992b5"),
126
+ }),
127
+ )->Expect.toBe("admin [Admin]")
128
+ })
129
+ })