@reventlessdev/reventless-seed 1.0.0-alpha.5 → 1.0.0-alpha.7

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 (111) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/lib/bs/.compiler.log +2 -2
  3. package/lib/bs/.sourcedirs.json +1 -1
  4. package/lib/bs/ReventlessSeed.cmi +0 -0
  5. package/lib/bs/ReventlessSeed.cmt +0 -0
  6. package/lib/bs/ReventlessSeed.mlmap +1 -1
  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 +4 -5
  12. package/lib/bs/src/Seed_Client-ReventlessSeed.cmi +0 -0
  13. package/lib/bs/src/Seed_Client-ReventlessSeed.cmj +0 -0
  14. package/lib/bs/src/Seed_Client-ReventlessSeed.cmt +0 -0
  15. package/lib/bs/src/Seed_Client.ast +0 -0
  16. package/lib/bs/src/Seed_Client.res +4 -0
  17. package/lib/bs/src/Seed_Client.res.mjs +5 -0
  18. package/lib/bs/src/Seed_Connect-ReventlessSeed.cmi +0 -0
  19. package/lib/bs/src/Seed_Connect-ReventlessSeed.cmj +0 -0
  20. package/lib/bs/src/Seed_Connect-ReventlessSeed.cmt +0 -0
  21. package/lib/bs/src/Seed_Connect.ast +0 -0
  22. package/lib/bs/src/Seed_Connect.res +13 -49
  23. package/lib/bs/src/Seed_Connect.res.mjs +5 -26
  24. package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmi +0 -0
  25. package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmt +0 -0
  26. package/lib/bs/src/Seed_Prompt.ast +0 -0
  27. package/lib/bs/src/Seed_Prompt.res +10 -20
  28. package/lib/bs/src/Seed_Prompt.res.mjs +1 -1
  29. package/lib/bs/src/Seed_Random-ReventlessSeed.cmt +0 -0
  30. package/lib/bs/src/Seed_Runner-ReventlessSeed.cmi +0 -0
  31. package/lib/bs/src/Seed_Runner-ReventlessSeed.cmt +0 -0
  32. package/lib/bs/src/Seed_Runner.ast +0 -0
  33. package/lib/bs/src/Seed_Runner.res +5 -7
  34. package/lib/bs/src/Seed_Types-ReventlessSeed.cmt +0 -0
  35. package/lib/bs/src/Seed_Upload-ReventlessSeed.cmi +0 -0
  36. package/lib/bs/src/Seed_Upload-ReventlessSeed.cmj +0 -0
  37. package/lib/bs/src/Seed_Upload-ReventlessSeed.cmt +0 -0
  38. package/lib/bs/src/Seed_Upload.ast +0 -0
  39. package/lib/bs/src/Seed_Upload.res +39 -100
  40. package/lib/bs/src/Seed_Upload.res.mjs +61 -93
  41. package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmi +0 -0
  42. package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmj +0 -0
  43. package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmt +0 -0
  44. package/lib/bs/tests/Seed_RandomTest.ast +0 -0
  45. package/lib/bs/tests/Seed_RandomTest.res +160 -0
  46. package/lib/bs/tests/Seed_RandomTest.res.mjs +208 -0
  47. package/lib/ocaml/.compiler.log +2 -2
  48. package/lib/ocaml/ReventlessSeed.cmi +0 -0
  49. package/lib/ocaml/ReventlessSeed.cmt +0 -0
  50. package/lib/ocaml/ReventlessSeed.mlmap +1 -1
  51. package/lib/ocaml/Seed-ReventlessSeed.cmi +0 -0
  52. package/lib/ocaml/Seed-ReventlessSeed.cmt +0 -0
  53. package/lib/ocaml/Seed.ast +0 -0
  54. package/lib/ocaml/Seed.res +4 -5
  55. package/lib/ocaml/Seed_Client-ReventlessSeed.cmi +0 -0
  56. package/lib/ocaml/Seed_Client-ReventlessSeed.cmj +0 -0
  57. package/lib/ocaml/Seed_Client-ReventlessSeed.cmt +0 -0
  58. package/lib/ocaml/Seed_Client.ast +0 -0
  59. package/lib/ocaml/Seed_Client.res +4 -0
  60. package/lib/ocaml/Seed_Connect-ReventlessSeed.cmi +0 -0
  61. package/lib/ocaml/Seed_Connect-ReventlessSeed.cmj +0 -0
  62. package/lib/ocaml/Seed_Connect-ReventlessSeed.cmt +0 -0
  63. package/lib/ocaml/Seed_Connect.ast +0 -0
  64. package/lib/ocaml/Seed_Connect.res +13 -49
  65. package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmi +0 -0
  66. package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmt +0 -0
  67. package/lib/ocaml/Seed_Prompt.ast +0 -0
  68. package/lib/ocaml/Seed_Prompt.res +10 -20
  69. package/lib/ocaml/Seed_Random-ReventlessSeed.cmt +0 -0
  70. package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmi +0 -0
  71. package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmj +0 -0
  72. package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmt +0 -0
  73. package/lib/ocaml/Seed_RandomTest.ast +0 -0
  74. package/lib/ocaml/Seed_RandomTest.res +160 -0
  75. package/lib/ocaml/Seed_Runner-ReventlessSeed.cmi +0 -0
  76. package/lib/ocaml/Seed_Runner-ReventlessSeed.cmt +0 -0
  77. package/lib/ocaml/Seed_Runner.ast +0 -0
  78. package/lib/ocaml/Seed_Runner.res +5 -7
  79. package/lib/ocaml/Seed_Types-ReventlessSeed.cmt +0 -0
  80. package/lib/ocaml/Seed_Upload-ReventlessSeed.cmi +0 -0
  81. package/lib/ocaml/Seed_Upload-ReventlessSeed.cmj +0 -0
  82. package/lib/ocaml/Seed_Upload-ReventlessSeed.cmt +0 -0
  83. package/lib/ocaml/Seed_Upload.ast +0 -0
  84. package/lib/ocaml/Seed_Upload.res +39 -100
  85. package/package.json +5 -2
  86. package/rescript.json +1 -0
  87. package/src/Seed.res +4 -5
  88. package/src/Seed_Client.res +4 -0
  89. package/src/Seed_Client.res.mjs +5 -0
  90. package/src/Seed_Connect.res +13 -49
  91. package/src/Seed_Connect.res.mjs +5 -26
  92. package/src/Seed_Prompt.res +10 -20
  93. package/src/Seed_Prompt.res.mjs +1 -1
  94. package/src/Seed_Runner.res +5 -7
  95. package/src/Seed_Upload.res +39 -100
  96. package/src/Seed_Upload.res.mjs +61 -93
  97. package/tests/Seed_RandomTest.res +160 -0
  98. package/tests/Seed_RandomTest.res.mjs +208 -0
  99. package/lib/bs/tests/UploadEndpointResolutionTest-ReventlessSeed.cmi +0 -0
  100. package/lib/bs/tests/UploadEndpointResolutionTest-ReventlessSeed.cmj +0 -0
  101. package/lib/bs/tests/UploadEndpointResolutionTest-ReventlessSeed.cmt +0 -0
  102. package/lib/bs/tests/UploadEndpointResolutionTest.ast +0 -0
  103. package/lib/bs/tests/UploadEndpointResolutionTest.res +0 -101
  104. package/lib/bs/tests/UploadEndpointResolutionTest.res.mjs +0 -59
  105. package/lib/ocaml/UploadEndpointResolutionTest-ReventlessSeed.cmi +0 -0
  106. package/lib/ocaml/UploadEndpointResolutionTest-ReventlessSeed.cmj +0 -0
  107. package/lib/ocaml/UploadEndpointResolutionTest-ReventlessSeed.cmt +0 -0
  108. package/lib/ocaml/UploadEndpointResolutionTest.ast +0 -0
  109. package/lib/ocaml/UploadEndpointResolutionTest.res +0 -101
  110. package/tests/UploadEndpointResolutionTest.res +0 -101
  111. package/tests/UploadEndpointResolutionTest.res.mjs +0 -59
@@ -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 */
@@ -1,2 +1,2 @@
1
- #Start(1785495045271)
2
- #Done(1785495045300)
1
+ #Start(1785603404546)
2
+ #Done(1785603404581)
Binary file
Binary file
@@ -4,7 +4,7 @@ Seed_Client
4
4
  Seed_Connect
5
5
  Seed_Prompt
6
6
  Seed_Random
7
+ Seed_RandomTest
7
8
  Seed_Runner
8
9
  Seed_Types
9
10
  Seed_Upload
10
- UploadEndpointResolutionTest
Binary file
Binary file
Binary file
@@ -14,13 +14,12 @@ module Connect = Seed_Connect
14
14
 
15
15
  exception Failed = Seed_Types.Failed
16
16
 
17
- // A live target a data set seeds against: an authenticated client, the
18
- // deployment's upload endpoints (the legacy single service and the per-store
19
- // map, either of which may be empty), and a label.
17
+ // A live target a data set seeds against: an authenticated client, whether uploads
18
+ // are skipped this run, and a label. Uploads mint through the domain API's
19
+ // `Upload_Presign` mutation on the client (route B), so no upload endpoint is carried.
20
20
  type connection = Seed_Connect.connection = {
21
21
  client: Seed_Client.t,
22
- uploadEndpoint: string,
23
- uploadEndpoints: dict<string>,
22
+ uploadsSkipped: bool,
24
23
  label: string,
25
24
  }
26
25
 
Binary file
@@ -43,6 +43,10 @@ let make = (~config: config): t => {config, token: None}
43
43
  Seed.Upload) can authenticate side-channel requests with the same identity. */
44
44
  let currentToken = (t: t): option<string> => t.token
45
45
 
46
+ /** The GraphQL endpoint this client targets — so `Seed.Upload` can resolve a
47
+ relative presigned `uploadUrl` against the same origin. */
48
+ let endpoint = (t: t): string => t.config.endpoint
49
+
46
50
  /** Injects a bearer obtained out-of-band (e.g. a Cognito id token), instead of
47
51
  minting one via `login`. Provider-agnostic: the harness only cares that the
48
52
  token is a valid bearer for `endpoint`. */
Binary file
@@ -9,15 +9,13 @@
9
9
 
10
10
  open Seed_Types
11
11
 
12
- // `uploadEndpoint` is the legacy single presign service (and the local dev
13
- // server's one upload route); `uploadEndpoints` maps the qualified
14
- // `{plugin}.{store}` of each declared store to its own presign endpoint. Both,
15
- // because a deployment may publish either or both — see `Seed_Upload.endpointFor`
16
- // for the resolution between them.
12
+ // Under route B the client mints uploads through the domain API's `Upload_Presign`
13
+ // mutation (authenticated by the same bearer as commands), so a connection needs no
14
+ // upload endpoint — just the authenticated client and whether uploads are skipped this
15
+ // run (`SEED_SKIP_UPLOADS`). Which store an asset uploads into is the caller's `~store`.
17
16
  type connection = {
18
17
  client: Seed_Client.t,
19
- uploadEndpoint: string,
20
- uploadEndpoints: dict<string>,
18
+ uploadsSkipped: bool,
21
19
  label: string,
22
20
  }
23
21
 
@@ -29,48 +27,20 @@ type connection = {
29
27
  let make = async (
30
28
  ~label: string,
31
29
  ~endpoint: string,
32
- ~uploadEndpoint: string,
33
- ~uploadEndpoints: dict<string>=Dict.make(),
34
30
  ~login: (~username: string, ~password: string) => promise<string>,
35
31
  ~localDefaults: bool=false,
36
32
  ): connection => {
37
- // `SEED_SKIP_UPLOADS` forces the connection to carry no upload endpoint at
38
- // all, so a data set's upload phase no-ops the same way it does when a
39
- // deployment serves none. Use it to seed domain data fast, or to skip a
40
- // broken/absent upload path without editing the data set. It is the single
41
- // knob: an empty `REVENTLESS_UPLOAD_ENDPOINT` env reads as "unset" (falls back
42
- // to discovery), so this is the reliable way to disable uploads — which means
43
- // it has to clear the per-store map too, or a declared store keeps uploading
44
- // through it.
45
- let skip = Seed_Prompt.envValue("SEED_SKIP_UPLOADS")->Option.isSome
46
- let uploadEndpoint = skip ? "" : uploadEndpoint
47
- let uploadEndpoints = skip ? Dict.make() : uploadEndpoints
33
+ // `SEED_SKIP_UPLOADS` forces the upload phase to no-op — seed domain data fast, or
34
+ // skip a broken/absent upload path without editing the data set. The data set reads
35
+ // `connection.uploadsSkipped` and reports the skip.
36
+ let uploadsSkipped = Seed_Upload.uploadsSkipped()
48
37
  let (username, password) = await Seed_Prompt.credentials(~localDefaults)
49
38
  let token = await login(~username, ~password)
50
39
  let client = Seed_Client.make(~config={endpoint: endpoint})
51
40
  client->Seed_Client.useToken(token)
52
- {client, uploadEndpoint, uploadEndpoints, label}
41
+ {client, uploadsSkipped, label}
53
42
  }
54
43
 
55
- /**
56
- * The endpoint an asset destined for `store` uploads through, or the reason
57
- * there is none — the message to report when the upload phase skips.
58
- *
59
- * `store` is the qualified `{plugin}.{store}` the asset's field declares, e.g.
60
- * `"Catalog.productImages"`. Resolution is `Seed_Upload.endpointFor`; naming a
61
- * store the deployment does not serve falls back to the legacy single service
62
- * rather than to another store's endpoint.
63
- */
64
- let uploadEndpointFor = (c: connection, ~store: string): result<string, string> =>
65
- switch Seed_Upload.endpointFor(
66
- ~store,
67
- ~uploadEndpoint=c.uploadEndpoint,
68
- ~uploadEndpoints=c.uploadEndpoints,
69
- ) {
70
- | Some(endpoint) => Ok(endpoint)
71
- | None => Error(Seed_Upload.unresolvedReason(~store, ~uploadEndpoints=c.uploadEndpoints))
72
- }
73
-
74
44
  /**
75
45
  * A login function backed by an HTTP login endpoint (the local dev
76
46
  * `/__inmemory/login` shape: POST `{username, password}` → `{token}`). Reuses
@@ -98,24 +68,18 @@ let envOr = (key: string, fallback: string): string =>
98
68
  * defaults baked in and overridable per endpoint (arg, then env var, then
99
69
  * default). Empty input at the credential prompt falls back to `admin`/`admin`.
100
70
  *
101
- * No per-store map: the local dev server serves every store through its one
102
- * upload route, so a data set naming a store resolves to that route by the
103
- * "declares a store with no matching endpoint" row.
71
+ * No upload endpoint: uploads mint through the domain API's `Upload_Presign` mutation
72
+ * on the same `graphql` endpoint, with the store passed per asset.
104
73
  */
105
- let local = (~graphql=?, ~upload=?, ~login=?, ()): (unit => promise<connection>) => {
74
+ let local = (~graphql=?, ~login=?, ()): (unit => promise<connection>) => {
106
75
  let endpoint =
107
76
  graphql->Option.getOr(envOr("REVENTLESS_GRAPHQL_ENDPOINT", "http://localhost:4000/graphql"))
108
- let uploadEndpoint =
109
- upload->Option.getOr(
110
- envOr("REVENTLESS_UPLOAD_ENDPOINT", "http://localhost:4000/__inmemory/upload"),
111
- )
112
77
  let loginEndpoint =
113
78
  login->Option.getOr(envOr("REVENTLESS_LOGIN_ENDPOINT", "http://localhost:4000/__inmemory/login"))
114
79
  () =>
115
80
  make(
116
81
  ~label="local",
117
82
  ~endpoint,
118
- ~uploadEndpoint,
119
83
  ~login=viaLoginEndpoint(~loginEndpoint),
120
84
  ~localDefaults=true,
121
85
  )
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->writeStream(s)
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->pauseStream
64
- stdin->unrefStream
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 processEnv->Dict.get(key) {
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,7 +91,7 @@ let askHidden = (query: string): promise<string> =>
101
91
  let rl = iface()
102
92
  rl->question(query, answer => {
103
93
  muted := false
104
- stdout->writeStream("\n")
94
+ NodeProcess.stdout->NodeProcess.write("\n")
105
95
  resolve(answer)
106
96
  })
107
97
  muted := true
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