@reventlessdev/reventless-core 3.0.0-alpha.338 → 3.0.0-alpha.340

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 (51) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/package.json +7 -7
  3. package/src/ComponentType.res +38 -62
  4. package/src/ComponentType.res.mjs +34 -115
  5. package/src/ResourceAttribution.res +7 -33
  6. package/src/ResourceAttribution.res.mjs +2 -51
  7. package/src/ViewChange.res.mjs +2 -2
  8. package/src/admin/Platform_Admin.res +66 -58
  9. package/src/admin/Platform_Admin.res.mjs +4 -2
  10. package/src/admin/Platform_ComponentDefinitionsApi.res +10 -11
  11. package/src/admin/Platform_ComponentDefinitionsApi.res.mjs +9 -8
  12. package/src/admin/Platform_PluginStructuresApi.res +1 -1
  13. package/src/admin/Platform_SelfRegistration.res.mjs +3 -3
  14. package/src/components/Dcb/Dcb_Builder.res +1 -0
  15. package/src/components/Dcb/Dcb_Builder.res.mjs +1 -1
  16. package/src/components/QueryDb/QueryDb.res.mjs +1 -1
  17. package/src/plugin/component/Plugin_Builder.res +13 -8
  18. package/src/plugin/component/Plugin_Builder.res.mjs +6 -4
  19. package/src/plugin/component/Plugin_BuiltHook.res +7 -2
  20. package/src/plugin/component/Plugin_Helpers.res +4 -0
  21. package/src/plugin/component/Plugin_Structure.res +8 -14
  22. package/src/plugin/component/Plugin_Structure.res.mjs +9 -18
  23. package/src/plugin/component/SchemaWalker.res +4 -4
  24. package/src/plugin/component/SchemaWalker.res.mjs +4 -4
  25. package/src/plugin/connect/PluginExtensionPoint_Builder.res +4 -1
  26. package/src/plugin/connect/PluginExtensionPoint_Plugin.res +7 -3
  27. package/src/plugin/connect/PluginExtensionPoint_Plugin.res.mjs +2 -2
  28. package/src/util/EffectLogger.res.mjs +8 -8
  29. package/src/util/Logger.res +21 -7
  30. package/src/util/Logger.res.mjs +44 -30
  31. package/tests/ClosedSetWordsTest.res +105 -0
  32. package/tests/ClosedSetWordsTest.res.mjs +145 -0
  33. package/tests/ResourceAttributionTest.res.mjs +4 -7
  34. package/tests/admin/AdminApiSchemaDriftTest.res +1 -1
  35. package/tests/admin/Platform_BakedManifestTest.res +1 -1
  36. package/tests/admin/Platform_ComponentDefinitionsApiTest.res +1 -1
  37. package/tests/admin/Platform_PluginStructuresApiTest.res +3 -3
  38. package/tests/admin/Platform_SelfRegistrationTest.res +2 -2
  39. package/tests/commandgenerator/OwnerStampingTest.res.mjs +1 -1
  40. package/tests/dcb/DcbScopeInferenceTest.res +66 -0
  41. package/tests/dcb/DcbScopeInferenceTest.res.mjs +166 -0
  42. package/tests/dcb/DcbValidationTest.res +21 -0
  43. package/tests/dcb/DcbValidationTest.res.mjs +26 -9
  44. package/tests/logger/LogFormatTest.res.mjs +2 -2
  45. package/tests/logger/LoggerLazyTest.res.mjs +2 -2
  46. package/tests/logger/LoggerSinkTest.res.mjs +26 -26
  47. package/tests/plugin/ManifestVisibilityTest.res +4 -2
  48. package/tests/plugin/ManifestVisibilityTest.res.mjs +5 -1
  49. package/tests/plugin/SchemaWalkerTest.res +3 -3
  50. package/tests/plugin/SchemaWalkerTest.res.mjs +3 -3
  51. package/tests/projection/ViewChangeTest.res.mjs +1 -1
@@ -22,29 +22,40 @@ let s = process.env.REVENTLESS_LOG_MAX_DETAIL_BYTES;
22
22
 
23
23
  let maxDetailBytes = s !== undefined ? Stdlib_Option.getOr(Stdlib_Int.fromString(s, undefined), 32768) : 32768;
24
24
 
25
+ let levels = [
26
+ "DEBUG",
27
+ "INFO",
28
+ "WARN",
29
+ "ERROR"
30
+ ];
31
+
25
32
  function levelToInt(l) {
26
33
  switch (l) {
27
- case "Debug" :
34
+ case "DEBUG" :
28
35
  return 0;
29
- case "Info" :
36
+ case "INFO" :
30
37
  return 1;
31
- case "Warn" :
38
+ case "WARN" :
32
39
  return 2;
33
- case "Error" :
40
+ case "ERROR" :
34
41
  return 3;
35
42
  }
36
43
  }
37
44
 
38
45
  function levelLabel(l) {
39
- switch (l) {
40
- case "Debug" :
41
- return "DEBUG";
42
- case "Info" :
43
- return "INFO";
44
- case "Warn" :
45
- return "WARN";
46
- case "Error" :
47
- return "ERROR";
46
+ return l;
47
+ }
48
+
49
+ function levelOfLabel(label) {
50
+ return levels.find(l => l === label);
51
+ }
52
+
53
+ function levelOfWord(word) {
54
+ let lower = word.toLowerCase();
55
+ if (lower === "warning") {
56
+ return "WARN";
57
+ } else {
58
+ return levels.find(l => l.toLowerCase() === lower);
48
59
  }
49
60
  }
50
61
 
@@ -100,7 +111,7 @@ function recordFields(r) {
100
111
  ],
101
112
  [
102
113
  "level",
103
- levelLabel(r.level)
114
+ r.level
104
115
  ],
105
116
  [
106
117
  "message",
@@ -197,23 +208,23 @@ function emit(level, comp, plugin, detail, annotations, msg) {
197
208
  let t = hms();
198
209
  let c = LogPrefix$Reventless.fmtComp(comp, undefined);
199
210
  switch (level) {
200
- case "Debug" :
211
+ case "DEBUG" :
201
212
  console.log(t + ` ` + dim + `D` + reset + ` ` + c + msg);
202
213
  return;
203
- case "Info" :
214
+ case "INFO" :
204
215
  console.log(t + ` ` + cyan + `I` + reset + ` ` + c + msg);
205
216
  return;
206
- case "Warn" :
217
+ case "WARN" :
207
218
  console.warn(t + ` ` + yellow + `W` + reset + ` ` + c + msg);
208
219
  return;
209
- case "Error" :
220
+ case "ERROR" :
210
221
  console.error(t + ` ` + red + `E` + reset + ` ` + c + msg);
211
222
  return;
212
223
  }
213
224
  }
214
225
 
215
226
  let defaultMinLevel = {
216
- contents: "Info"
227
+ contents: "INFO"
217
228
  };
218
229
 
219
230
  function setDefaultMinLevel(l) {
@@ -229,20 +240,20 @@ function makeLoggerWith(shouldLog) {
229
240
  emit(level, comp, undefined, undefined, undefined, msg + dataStr);
230
241
  };
231
242
  return {
232
- debug: (comp, data, msg) => log("Debug", comp, data, msg),
233
- info: (comp, data, msg) => log("Info", comp, data, msg),
234
- warn: (comp, data, msg) => log("Warn", comp, data, msg),
235
- error: (comp, data, msg) => log("Error", comp, data, msg),
243
+ debug: (comp, data, msg) => log("DEBUG", comp, data, msg),
244
+ info: (comp, data, msg) => log("INFO", comp, data, msg),
245
+ warn: (comp, data, msg) => log("WARN", comp, data, msg),
246
+ error: (comp, data, msg) => log("ERROR", comp, data, msg),
236
247
  debugLazy: (comp, makeMsg) => {
237
- if (shouldLog("Debug", comp)) {
238
- return emit("Debug", comp, undefined, undefined, undefined, makeMsg());
248
+ if (shouldLog("DEBUG", comp)) {
249
+ return emit("DEBUG", comp, undefined, undefined, undefined, makeMsg());
239
250
  }
240
251
  }
241
252
  };
242
253
  }
243
254
 
244
255
  function makeLogger(minLevelOpt) {
245
- let minLevel = minLevelOpt !== undefined ? minLevelOpt : "Info";
256
+ let minLevel = minLevelOpt !== undefined ? minLevelOpt : "INFO";
246
257
  return makeLoggerWith((l, param) => levelToInt(l) >= levelToInt(minLevel));
247
258
  }
248
259
 
@@ -281,15 +292,15 @@ function effectiveMin() {
281
292
  }
282
293
  switch (match) {
283
294
  case "debug" :
284
- return "Debug";
295
+ return "DEBUG";
285
296
  case "error" :
286
- return "Error";
297
+ return "ERROR";
287
298
  case "silent" :
288
299
  return;
289
300
  case "warn" :
290
- return "Warn";
301
+ return "WARN";
291
302
  default:
292
- return "Info";
303
+ return "INFO";
293
304
  }
294
305
  }
295
306
 
@@ -453,8 +464,11 @@ let resolvePlugin = LogPrefix$Reventless.resolvePlugin;
453
464
  export {
454
465
  serviceName,
455
466
  maxDetailBytes,
467
+ levels,
456
468
  levelToInt,
457
469
  levelLabel,
470
+ levelOfLabel,
471
+ levelOfWord,
458
472
  red,
459
473
  yellow,
460
474
  cyan,
@@ -0,0 +1,105 @@
1
+ open JestGlobals
2
+
3
+ // Each closed set below is held as a variant and turned into text only where a
4
+ // deployment, a published structure or a log line carries it. These pin that
5
+ // text: every word reads back as its case and prints as the same word.
6
+
7
+ describe("ComponentType", () => {
8
+ let words = [
9
+ "Aggregate",
10
+ "Counter",
11
+ "Plugin",
12
+ "Platform",
13
+ "CommandGenerator",
14
+ "CommandTopic",
15
+ "EventCollector",
16
+ "EventLog",
17
+ "EventMapper",
18
+ "EventTopic",
19
+ "ExtensionPoint",
20
+ "Extension",
21
+ "QueryDB",
22
+ "ReadModel",
23
+ "Scheduler",
24
+ "Service",
25
+ "SideEffectHandler",
26
+ "Task",
27
+ "Vpc",
28
+ "Heartbeat",
29
+ "Cloner",
30
+ "DcbEventLog",
31
+ "StateChangeSlice",
32
+ "StateViewSlice",
33
+ "AutomationSlice",
34
+ "OutboundTranslationSlice",
35
+ "InboundTranslationSlice",
36
+ ]
37
+
38
+ testSync("prints each kind as the word a deployment carries", () =>
39
+ expect(ComponentType.all->Array.map(ComponentType.toString))->toEqual(words)
40
+ )
41
+
42
+ testSync("reads each word back, and no other", () =>
43
+ expect(
44
+ Array.concat(words, ["QueryDb", "Runtime"])->Array.map(
45
+ w => ComponentType.ofString(w)->Option.map(ComponentType.toString),
46
+ ),
47
+ )->toEqual(Array.concat(words->Array.map(w => Some(w)), [None, None]))
48
+ )
49
+
50
+ // The short name every physical resource is named with: a second spelling of
51
+ // the query store that is not the kind's word.
52
+ testSync("the query store's short name stays QueryDb", () =>
53
+ expect(ComponentType.QueryDb->ComponentType.toName)->toBe("QueryDb")
54
+ )
55
+ })
56
+
57
+ describe("ResourceAttribution", () => {
58
+ testSync("a role's text is its name, and an other role is its own word", () =>
59
+ expect(
60
+ [
61
+ ResourceAttribution.Role.QueryDb,
62
+ Runtime,
63
+ EventSourceMapping,
64
+ Other("ChangeFeed"),
65
+ ]->Array.map(ResourceAttribution.Role.toString),
66
+ )->toEqual(["QueryDb", "Runtime", "EventSourceMapping", "ChangeFeed"])
67
+ )
68
+ })
69
+
70
+ describe("Plugin_Structure.labelFieldSource", () => {
71
+ testSync("prints each source in lower case", () =>
72
+ expect(
73
+ [Plugin_Structure.Annotation, Convention, Position, Fallback]->Array.map(
74
+ Plugin_Structure.labelFieldSourceToString,
75
+ ),
76
+ )->toEqual(["annotation", "convention", "position", "fallback"])
77
+ )
78
+ })
79
+
80
+ describe("Plugin_BuiltHook.schemaKind", () => {
81
+ testSync("prints each kind as a published schema carries it", () =>
82
+ expect(
83
+ [Plugin_BuiltHook.RecordSchema, VariantSchema, UnknownSchema]->Array.map(k => (k :> string)),
84
+ )->toEqual(["RecordSchema", "VariantSchema", "UnknownSchema"])
85
+ )
86
+ })
87
+
88
+ describe("Logger levels", () => {
89
+ testSync("a level's label is its upper-case word, and reads back exactly", () => {
90
+ expect(Logger.levels->Array.map(Logger.levelLabel))->toEqual(["DEBUG", "INFO", "WARN", "ERROR"])
91
+ expect(
92
+ ["DEBUG", "INFO", "WARN", "ERROR", "warn", "WARNING"]->Array.map(
93
+ w => Logger.levelOfLabel(w)->Option.map(Logger.levelLabel),
94
+ ),
95
+ )->toEqual([Some("DEBUG"), Some("INFO"), Some("WARN"), Some("ERROR"), None, None])
96
+ })
97
+
98
+ testSync("a word reads in any case, warning included", () =>
99
+ expect(
100
+ ["debug", "Info", "WARN", "warning", "Error", "trace"]->Array.map(
101
+ w => Logger.levelOfWord(w)->Option.map(Logger.levelLabel),
102
+ ),
103
+ )->toEqual([Some("DEBUG"), Some("INFO"), Some("WARN"), Some("WARN"), Some("ERROR"), None])
104
+ )
105
+ })
@@ -0,0 +1,145 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
4
+ import * as Logger$ReventlessCore from "../src/util/Logger.res.mjs";
5
+ import * as ComponentType$ReventlessCore from "../src/ComponentType.res.mjs";
6
+ import * as Plugin_Structure$ReventlessCore from "../src/plugin/component/Plugin_Structure.res.mjs";
7
+ import * as ResourceAttribution$ReventlessCore from "../src/ResourceAttribution.res.mjs";
8
+
9
+ globalThis.describe("ComponentType", () => {
10
+ let words = [
11
+ "Aggregate",
12
+ "Counter",
13
+ "Plugin",
14
+ "Platform",
15
+ "CommandGenerator",
16
+ "CommandTopic",
17
+ "EventCollector",
18
+ "EventLog",
19
+ "EventMapper",
20
+ "EventTopic",
21
+ "ExtensionPoint",
22
+ "Extension",
23
+ "QueryDB",
24
+ "ReadModel",
25
+ "Scheduler",
26
+ "Service",
27
+ "SideEffectHandler",
28
+ "Task",
29
+ "Vpc",
30
+ "Heartbeat",
31
+ "Cloner",
32
+ "DcbEventLog",
33
+ "StateChangeSlice",
34
+ "StateViewSlice",
35
+ "AutomationSlice",
36
+ "OutboundTranslationSlice",
37
+ "InboundTranslationSlice"
38
+ ];
39
+ globalThis.test("prints each kind as the word a deployment carries", () => {
40
+ globalThis.expect(ComponentType$ReventlessCore.all.map(ComponentType$ReventlessCore.toString)).toEqual(words);
41
+ });
42
+ globalThis.test("reads each word back, and no other", () => {
43
+ globalThis.expect(words.concat([
44
+ "QueryDb",
45
+ "Runtime"
46
+ ]).map(w => Stdlib_Option.map(ComponentType$ReventlessCore.ofString(w), ComponentType$ReventlessCore.toString))).toEqual(words.map(w => w).concat([
47
+ undefined,
48
+ undefined
49
+ ]));
50
+ });
51
+ globalThis.test("the query store's short name stays QueryDb", () => {
52
+ globalThis.expect(ComponentType$ReventlessCore.toName("QueryDB")).toBe("QueryDb");
53
+ });
54
+ });
55
+
56
+ globalThis.describe("ResourceAttribution", () => {
57
+ globalThis.test("a role's text is its name, and an other role is its own word", () => {
58
+ globalThis.expect([
59
+ "QueryDb",
60
+ "Runtime",
61
+ "EventSourceMapping",
62
+ "ChangeFeed"
63
+ ].map(ResourceAttribution$ReventlessCore.Role.toString)).toEqual([
64
+ "QueryDb",
65
+ "Runtime",
66
+ "EventSourceMapping",
67
+ "ChangeFeed"
68
+ ]);
69
+ });
70
+ });
71
+
72
+ globalThis.describe("Plugin_Structure.labelFieldSource", () => {
73
+ globalThis.test("prints each source in lower case", () => {
74
+ globalThis.expect([
75
+ "annotation",
76
+ "convention",
77
+ "position",
78
+ "fallback"
79
+ ].map(Plugin_Structure$ReventlessCore.labelFieldSourceToString)).toEqual([
80
+ "annotation",
81
+ "convention",
82
+ "position",
83
+ "fallback"
84
+ ]);
85
+ });
86
+ });
87
+
88
+ globalThis.describe("Plugin_BuiltHook.schemaKind", () => {
89
+ globalThis.test("prints each kind as a published schema carries it", () => {
90
+ globalThis.expect([
91
+ "RecordSchema",
92
+ "VariantSchema",
93
+ "UnknownSchema"
94
+ ].map(k => k)).toEqual([
95
+ "RecordSchema",
96
+ "VariantSchema",
97
+ "UnknownSchema"
98
+ ]);
99
+ });
100
+ });
101
+
102
+ globalThis.describe("Logger levels", () => {
103
+ globalThis.test("a level's label is its upper-case word, and reads back exactly", () => {
104
+ globalThis.expect(Logger$ReventlessCore.levels.map(Logger$ReventlessCore.levelLabel)).toEqual([
105
+ "DEBUG",
106
+ "INFO",
107
+ "WARN",
108
+ "ERROR"
109
+ ]);
110
+ globalThis.expect([
111
+ "DEBUG",
112
+ "INFO",
113
+ "WARN",
114
+ "ERROR",
115
+ "warn",
116
+ "WARNING"
117
+ ].map(w => Stdlib_Option.map(Logger$ReventlessCore.levelOfLabel(w), Logger$ReventlessCore.levelLabel))).toEqual([
118
+ "DEBUG",
119
+ "INFO",
120
+ "WARN",
121
+ "ERROR",
122
+ undefined,
123
+ undefined
124
+ ]);
125
+ });
126
+ globalThis.test("a word reads in any case, warning included", () => {
127
+ globalThis.expect([
128
+ "debug",
129
+ "Info",
130
+ "WARN",
131
+ "warning",
132
+ "Error",
133
+ "trace"
134
+ ].map(w => Stdlib_Option.map(Logger$ReventlessCore.levelOfWord(w), Logger$ReventlessCore.levelLabel))).toEqual([
135
+ "DEBUG",
136
+ "INFO",
137
+ "WARN",
138
+ "WARN",
139
+ "ERROR",
140
+ undefined
141
+ ]);
142
+ });
143
+ });
144
+
145
+ /* Not a pure module */
@@ -9,9 +9,9 @@ import * as ResourceAttribution$ReventlessCore from "../src/ResourceAttribution.
9
9
  globalThis.describe("ResourceAttribution.Scope — wire spellings", () => {
10
10
  globalThis.test("scopes render lower-case", () => {
11
11
  globalThis.expect([
12
- "Component",
13
- "Plugin",
14
- "Platform"
12
+ "component",
13
+ "plugin",
14
+ "platform"
15
15
  ].map(ResourceAttribution$ReventlessCore.Scope.toString)).toEqual([
16
16
  "component",
17
17
  "plugin",
@@ -35,10 +35,7 @@ globalThis.describe("ResourceAttribution.Role — wire spellings", () => {
35
35
  ]);
36
36
  });
37
37
  globalThis.test("Other carries the caller's name verbatim", () => {
38
- globalThis.expect(ResourceAttribution$ReventlessCore.Role.toString({
39
- TAG: "Other",
40
- _0: "ChangeFeed"
41
- })).toBe("ChangeFeed");
38
+ globalThis.expect(ResourceAttribution$ReventlessCore.Role.toString("ChangeFeed")).toBe("ChangeFeed");
42
39
  });
43
40
  globalThis.test("platform-level things are Platform, not Core", () => {
44
41
  globalThis.expect(ComponentType$ReventlessCore.toString("Platform")).toBe("Platform");
@@ -174,7 +174,7 @@ let capabilityDecl: requiredCapabilityDeclaration = {
174
174
 
175
175
  let admissionDef: Reventless.Admission.def = {
176
176
  role: "Clerk",
177
- strategy: "Invitation",
177
+ strategy: InvitationWord,
178
178
  invitedBy: ["Admin"],
179
179
  }
180
180
 
@@ -48,7 +48,7 @@ let structure: pluginStructure = {
48
48
  readModels: [readSide(~name="Customers", ())],
49
49
  stateViewSlices: [
50
50
  readSide(~name="Orders", ~ownerField="customerId", ()),
51
- readSide(~name="AvailableProducts", ~visibility="Internal", ()),
51
+ readSide(~name="AvailableProducts", ~visibility=Internal, ()),
52
52
  ],
53
53
  stateChangeSlices: [
54
54
  writeSide(
@@ -232,7 +232,7 @@ describe("visibility filtering (deployed AutoUI hides Internal)", () => {
232
232
  labelField: "name",
233
233
  searchableFields: ["name"],
234
234
  labelFieldSource: "convention",
235
- visibility: "Internal",
235
+ visibility: Internal,
236
236
  singleQueryField: "Ordering_AvailableProduct",
237
237
  idField: "productId",
238
238
  idFieldSource: "sole",
@@ -27,7 +27,7 @@ let internalRm: readSideDef = {
27
27
  ...publicRm,
28
28
  name: "ProductAudit",
29
29
  queryField: "Catalog_ProductAudit",
30
- visibility: "Internal",
30
+ visibility: Internal,
31
31
  }
32
32
 
33
33
  let structure: pluginStructure = {
@@ -61,8 +61,8 @@ let structure: pluginStructure = {
61
61
  ],
62
62
  requiredCapabilities: [{capability: "Geocoding", component: "GeocodeAddress"}],
63
63
  admission: [
64
- {role: "Shopper", strategy: "SelfService"},
65
- {role: "Clerk", strategy: "Invitation", invitedBy: ["Admin"]},
64
+ {role: "Shopper", strategy: SelfServiceWord},
65
+ {role: "Clerk", strategy: InvitationWord, invitedBy: ["Admin"]},
66
66
  ],
67
67
  admissionDoors: [{component: "SignUp", part: "start"}],
68
68
  }
@@ -17,8 +17,8 @@ let empty: Reventless.Plugin.pluginStructure = {
17
17
  let registration: Reventless.Plugin.pluginStructure = {
18
18
  ...empty,
19
19
  admission: [
20
- {Reventless.Admission.role: "Shopper", strategy: "SelfService"},
21
- {Reventless.Admission.role: "Admin", strategy: "Provisioned"},
20
+ {Reventless.Admission.role: "Shopper", strategy: SelfServiceWord},
21
+ {Reventless.Admission.role: "Admin", strategy: ProvisionedWord},
22
22
  ],
23
23
  admissionDoors: [
24
24
  {Reventless.Admission.component: "SignUp", part: "start"},
@@ -333,7 +333,7 @@ globalThis.describe("the command's entry names the command on its lines", () =>
333
333
  });
334
334
  remove();
335
335
  let line = Stdlib_Option.getOrThrow(lines.find(r => r.message.startsWith("refused before its handler")), undefined);
336
- globalThis.expect(line.level).toEqual("Warn");
336
+ globalThis.expect(line.level).toEqual("WARN");
337
337
  globalThis.expect(Stdlib_Option.isSome(line.annotations["msgId"])).toBe(true);
338
338
  globalThis.expect(heard.map(r => [
339
339
  r.component,
@@ -602,6 +602,72 @@ describe("DcbScopeInference:", () => {
602
602
  expect(issues.contradictions->names)->toEqual(["ShipOrder"])
603
603
  },
604
604
  )
605
+
606
+ // A question's answer is kept per message. `AnswerMarked` names the reply, but
607
+ // `QuestionReopened` does not, so the reply cannot be the partition — though
608
+ // `ReplyPosted` comes from a slice partitioned by it, which once gave it back.
609
+ let postMessage = slice(
610
+ "PostMessage",
611
+ ~chapter="Messages",
612
+ ~produced=[ev("MessagePosted", [scal("messageId"), scal("channelId")])],
613
+ ~partitionHint="messageId",
614
+ )
615
+ let postReply = slice(
616
+ "PostReply",
617
+ ~chapter="Messages",
618
+ ~consumed=[ev("MessagePosted", [scal("messageId"), scal("channelId")])],
619
+ ~produced=[ev("ReplyPosted", [scal("replyId"), scal("messageId"), scal("channelId")])],
620
+ )
621
+ let questionState = slice(
622
+ "QuestionState",
623
+ ~chapter="Questions",
624
+ ~partitionHint="messageId",
625
+ ~consumed=[
626
+ ev("AnswerMarked", [scal("messageId"), scal("replyId"), scal("channelId")]),
627
+ ev("QuestionReopened", [scal("messageId"), scal("channelId")]),
628
+ ev("MessagePosted", [scal("messageId"), scal("channelId")]),
629
+ ev("ReplyPosted", [scal("replyId"), scal("messageId"), scal("channelId")]),
630
+ ],
631
+ ~produced=[
632
+ ev("AnswerMarked", [scal("messageId"), scal("replyId"), scal("channelId")]),
633
+ ev("QuestionReopened", [scal("messageId"), scal("channelId")]),
634
+ ],
635
+ )
636
+ let questions = [postMessage, postReply, questionState]
637
+
638
+ testSync(
639
+ "inference never picks a key one of the slice's own events lacks",
640
+ () => {
641
+ let unhinted = {...questionState, partitionHint: None}
642
+ let r = DSI.resolvePartitions([postMessage, postReply, unhinted])
643
+ expect(r.partitionBySlice->Dict.get("QuestionState"))->toEqual(None)
644
+ expect(r.candidatesBySlice->Dict.get("QuestionState"))->toEqual(Some([]))
645
+ },
646
+ )
647
+
648
+ testSync(
649
+ "a hint deciding a slice inference leaves unresolved is accepted",
650
+ () => {
651
+ let issues = check(questions)
652
+ expect(issues.contradictions)->toEqual([])
653
+ expect(issues.redundancies)->toEqual([])
654
+ expect(
655
+ DSI.resolvePartitions(questions).partitionBySlice->Dict.get("QuestionState"),
656
+ )->toEqual(Some("messageId"))
657
+ },
658
+ )
659
+
660
+ testSync(
661
+ "a hint naming a key one of the slice's events lacks is still a contradiction",
662
+ () => {
663
+ let issues = check([
664
+ postMessage,
665
+ postReply,
666
+ {...questionState, partitionHint: Some("replyId")},
667
+ ])
668
+ expect(issues.contradictions->names)->toEqual(["QuestionState"])
669
+ },
670
+ )
605
671
  })
606
672
 
607
673
  describe("ambiguity surfacing", () => {