@shivaedev/test-story 0.47.2 → 0.47.3

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.47.3 - 2026-11-18
4
+
5
+ ### Changed
6
+
7
+ - Update `@shivaedev/contract` from 0.45.0 to 0.46.0.
8
+ - Update `@shivaedev/test-sql` from 0.25.1 to 0.25.2.
9
+
3
10
  ## 0.47.2 - 2026-11-18
4
11
 
5
12
  ### Changed
package/README.md CHANGED
@@ -1076,12 +1076,15 @@ yield* screen.settle();
1076
1076
  expect(screen.text("output")).toBe("Saved title");
1077
1077
  ```
1078
1078
 
1079
- `settle()` waits until every supplied source is settled together, then flushes the renderer before returning. A source that becomes busy while another finishes keeps the wait open. `pending` and `transport` each accept the same sampler, boolean stream or `ScreenSignal` shape; `activity` accepts a `ScreenSignal`; contract owns the projection from native `ClientActivity`. It observes changes from all three without sleeps, quiet windows or polling. With `activityScreenSignal(clientActivity(client))`, the default is commands in flight and each mounted query's first result. A live query that has already delivered, including one awaiting a later refresh, is normal screen state and keeps no wait open. Contract uses its query/command declarations, so kits list no queries as settling exceptions. `find()` waits for settled activity and a matching target, including a target rendered by a later DOM mutation. To wait for a particular changed value, use `findText()` or `withLiveAnswer`.
1079
+ `settle()` waits until every supplied source is settled together, then flushes the renderer before returning. A source that becomes busy while another finishes keeps the wait open. `pending` and `transport` each accept the same sampler, boolean stream or `ScreenSignal` shape; `activity` accepts a `ScreenSignal`; contract owns the projection from native `ClientActivity`. It observes changes from all three without sleeps, quiet windows or polling. With `activityScreenSignal(clientActivity(client))`, the default is commands until they are reflected and each mounted query's first result. A command is reflected when every live query open on the screen shows the server's state after it, so `settle()` after a save returns with the saved value on the screen, and a command that changes nothing settles without an update. A live query that has already delivered, including one awaiting a refresh another viewer caused, is normal screen state and keeps no wait open. Contract uses its query/command declarations, so kits list no queries as settling exceptions. `find()` waits for settled activity and a matching target, including a target rendered by a later DOM mutation. To wait for a particular changed value, use `findText()`.
1080
1080
 
1081
- `withLiveAnswer(answers, action, { timeoutMs }?)` runs an action and returns its result once the live query named by `answers` has delivered a settled answer after the action began. It is the one wait for a live change, whether the story's own command or another viewer's write causes it: a contract command settles on its receipt, and the server's rerun reaches a live query later as a push that `settle()` does not wait for. Build `answers` with `liveAnswers(view.registry, "the notes list", api.list.query())` from `@shivaedev/contract/liveAnswers.ts`, or supply any `LiveAnswerSignal` from `server/LiveAnswerSignal.ts`. Any answer to that query counts, including one caused by another change or an unchanged rerun. A held server rerun leaves the current value visible and keeps the wait open. If no answer arrives within the driver's `timeoutMs`, or the answers end, the verb fails with `SignalNotReceived`, naming the query. Settle the screen after it; `activityScreenSignal(activity, isClientIdle)` from `@shivaedev/contract/clientActivity.ts` also waits for finite calls and pending query atoms. To assert which kind of update arrived, read the transport with `browserReads` below; the driver only waits.
1081
+ `sync({ timeoutMs }?)` waits for a write the screen's client did not make, such as another viewer's save or a finished job. Supply the driver's `sync` option, an Effect that completes once the screen's live queries show every change committed before it; `screenSync(client, registry)` from `@shivaedev/contract/screenSync.ts` builds it from a `makeClient` client and the view's registry. The verb runs that Effect inside the renderer's `act`, then settles the screen. A held server rerun keeps the current value visible and the wait open. If the sync does not complete within the driver's `timeoutMs` the verb dies with the screen's text, and without the `sync` option it fails with `MissingScreenSync`. `settle()` and `sync()` rely on a host that confirms commands, which the application host does; against a host that confirms nothing, a command counts as reflected at its reply. To assert which kind of update arrived, read the transport with `browserReads` below; the driver only waits.
1082
1082
 
1083
1083
  ```ts
1084
- submitNote: () => screen.withLiveAnswer(liveAnswers(view.registry, "the notes list", client.api.list.query()), screen.submit()),
1084
+ const screen = screenDriver({ act, activity: activityScreenSignal(clientActivity(client)), root, sync: screenSync(client, view.registry), tell });
1085
+ yield* anotherViewerSaves("Shared title");
1086
+ yield* screen.sync();
1087
+ expect(screen.text("output")).toBe("Shared title");
1085
1088
  ```
1086
1089
 
1087
1090
  For screens with runtime timers, acquire `const clock = yield* watchedClock` from `server/watchedClock.ts` during kit creation and pass `clock` to `screenDriver({ act, clock, pending, root, tell })`. Supply that same Clock to the application's atom runtime. While the supplied completion sources are busy, screen waits advance to the next registered sleep inside the supplied renderer `act`, then check completion again. Canceled sleeps are removed. A debounced search can therefore use `enter` followed by `settle` without a real wait or its debounce duration in a kit verb. Clock advancement is opt-in; the driver leaves time alone without `clock`. It advances the shared clock, including other scheduled work, so use explicit `clock.adjust(duration)` inside `act` when a story needs to observe a time boundary, such as holding a diary row for a long press.
@@ -1154,8 +1157,7 @@ Import each module with the prefix `@shivaedev/test-story/`; there is no root en
1154
1157
  | `server/domPage.ts` | `domPage(url)` with a scoped global fetch and a `pending` stream |
1155
1158
  | `server/adapters/seedCookies.ts` | `seedCookies(cookies, target?)`, `DomCookie` |
1156
1159
  | `server/routeOutbound.ts` | `routeOutbound(routes)` |
1157
- | `server/screenDriver.ts` | `screenDriver(options)`, `ScreenDriverOptions`, `ScreenDriver`, `ScreenTarget`, `MissingScreenPending` |
1158
- | `server/LiveAnswerSignal.ts` | `LiveAnswerSignal`, the answers of one query that `withLiveAnswer` waits for |
1160
+ | `server/screenDriver.ts` | `screenDriver(options)`, `ScreenDriverOptions`, `ScreenDriver`, `ScreenTarget`, `MissingScreenPending`, `MissingScreenSync` |
1159
1161
  | `server/adapters/memberScreens.ts` | `memberScreens(options)`, `MemberScreen` |
1160
1162
  | `server/adapters/domNavigate.ts` | `domNavigate(url?)` |
1161
1163
  | `server/genreTags.ts` | `genreTags(...kitNames)`, `GenreTag` |
@@ -1,7 +1,6 @@
1
1
  import * as Effect from "effect/Effect";
2
2
  import type * as Stream from "effect/Stream";
3
3
  import { type ScreenAct } from "#server/adapters/screenAct.ts";
4
- import type { LiveAnswerSignal } from "#server/LiveAnswerSignal.ts";
5
4
  import type { ScreenSignal } from "#server/screenSignal.ts";
6
5
  import type { ScreenClock } from "#server/watchedClock.ts";
7
6
  export type ScreenTarget = string | {
@@ -15,6 +14,7 @@ export interface ScreenDriverOptions {
15
14
  readonly loadingTimeoutMs?: number;
16
15
  readonly pending?: (() => boolean) | Stream.Stream<boolean> | ScreenSignal;
17
16
  readonly root: HTMLElement | (() => HTMLElement);
17
+ readonly sync?: Effect.Effect<unknown, unknown>;
18
18
  readonly tell: (line: string) => void;
19
19
  readonly timeoutMs?: number;
20
20
  readonly transport?: ScreenDriverOptions["pending"];
@@ -25,10 +25,19 @@ declare const MissingScreenPending_base: new <A extends Record<string, any> = {}
25
25
  export declare class MissingScreenPending extends MissingScreenPending_base {
26
26
  readonly message = "Cannot settle the screen without a completion signal.\nhelp: Supply pending, activity or transport that stays busy until the resulting screen work is ready to render.";
27
27
  }
28
- export type ScreenDriver<E = never> = Omit<ReturnType<typeof makeScreenActions>, "settle"> & {
28
+ declare const MissingScreenSync_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
29
+ readonly _tag: "MissingScreenSync";
30
+ } & Readonly<A>;
31
+ export declare class MissingScreenSync extends MissingScreenSync_base {
32
+ readonly message = "Cannot sync the screen without a sync Effect.\nhelp: Supply sync, an Effect that completes once the screen's live queries show every change committed before it, such as screenSync(client, registry) from @shivaedev/contract/screenSync.ts.";
33
+ }
34
+ export type ScreenDriver<E = never> = Omit<ReturnType<typeof makeScreenActions>, "settle" | "sync"> & {
29
35
  settle: (options?: {
30
36
  readonly timeoutMs?: number;
31
37
  }) => Effect.Effect<void, E>;
38
+ sync: (options?: {
39
+ readonly timeoutMs?: number;
40
+ }) => Effect.Effect<void, E | MissingScreenSync>;
32
41
  dialog: (target: ScreenTarget) => ScreenDriver<E>;
33
42
  within: (container: ScreenTarget | HTMLElement) => ScreenDriver<E>;
34
43
  };
@@ -79,9 +88,9 @@ declare function makeScreenActions(options: ScreenDriverOptions, dialogs: boolea
79
88
  readonly timeoutMs?: number;
80
89
  }) => Effect.Effect<void, never, never> | Effect.Effect<never, MissingScreenPending, never>;
81
90
  submit: (selector?: ScreenTarget) => Effect.Effect<void, never, never>;
82
- withLiveAnswer: <A, E, R>(answers: LiveAnswerSignal, action: Effect.Effect<A, E, R>, settings?: {
91
+ sync: (settings?: {
83
92
  readonly timeoutMs?: number;
84
- }) => Effect.Effect<A, E | import("./until.ts").SignalNotReceived, R>;
93
+ } | undefined) => Effect.Effect<undefined, MissingScreenPending | MissingScreenSync, never>;
85
94
  };
86
95
  export {};
87
96
  //# sourceMappingURL=screenDriver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"screenDriver.d.ts","sourceRoot":"","sources":["../../src/server/screenDriver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAmB,KAAK,SAAS,EAA4B,MAAM,+BAA+B,CAAC;AAE1G,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAE9F,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,GAAG,MAAM,CA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AC,CAAC;CACnE,CAAC;AAEF,wBAAgB,YAAY,CAC3B,OAAO,EAAE,mBAAmB,GAC3B,CACG;IAAE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAA;CAAE,GACjE;IAAE,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,GACnC;IAAE,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAA;CAAE,CACvE,GACA,YAAY,CAAC;AAChB,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAAC,oBAAoB,CAAC,CAAC;AAoC/F,iBAAS,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAerD,YAAY;sBAOZ,YAAY,SAAS,MAAM;uBAC1B,YAAY,SAAS,MAAM;wBAhBpB;QAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;wBAmBtC,YAAY;;6BACsC,MAAM;;EAe5E"}
@@ -3,7 +3,6 @@ import * as Effect from "effect/Effect";
3
3
  import { withLive } from "@shivaedev/test/withLive.ts";
4
4
  import { directScreenAct, screenAct, screenPerform } from "#server/adapters/screenAct.ts";
5
5
  import { screenElements } from "#server/adapters/screenElements.ts";
6
- import { nextLiveAnswer } from "#server/nextLiveAnswer.ts";
7
6
  import { screenInteractions } from "#server/screenInteractions.ts";
8
7
  import { screenReadouts } from "#server/screenReadouts.ts";
9
8
  import { screenWaits } from "#server/screenWaits.ts";
@@ -11,6 +10,9 @@ import { targetName } from "#server/targetName.ts";
11
10
  export class MissingScreenPending extends Data.TaggedError("MissingScreenPending") {
12
11
  message = "Cannot settle the screen without a completion signal.\nhelp: Supply pending, activity or transport that stays busy until the resulting screen work is ready to render.";
13
12
  }
13
+ export class MissingScreenSync extends Data.TaggedError("MissingScreenSync") {
14
+ message = "Cannot sync the screen without a sync Effect.\nhelp: Supply sync, an Effect that completes once the screen's live queries show every change committed before it, such as screenSync(client, registry) from @shivaedev/contract/screenSync.ts.";
15
+ }
14
16
  export function screenDriver(options) {
15
17
  return makeDriver(options, true);
16
18
  }
@@ -38,12 +40,19 @@ function makeDriver(options, dialogs, dialogOwner) {
38
40
  },
39
41
  };
40
42
  }
43
+ function unsynced(limit, screen) {
44
+ return new Error(`The screen did not sync within ${limit}ms.\nhelp: Release held server work and check that the host serves the client's sync command.\nScreen: ${screen}`);
45
+ }
41
46
  function makeScreenActions(options, dialogs) {
42
47
  const { root, pending, activity, transport, tell, act = directScreenAct, timeoutMs = 3000, loadingTimeoutMs = 10_000 } = options;
48
+ const supplied = pending !== undefined || activity !== undefined || transport !== undefined;
43
49
  const currentRoot = typeof root === "function" ? root : () => root;
44
50
  const elements = screenElements(currentRoot, dialogs);
45
51
  const waits = screenWaits({ ...options, act, loadingTimeoutMs, pending, root: currentRoot, timeoutMs }, elements, dialogs);
46
52
  const perform = screenPerform(act, tell);
53
+ function settle(settings) {
54
+ return supplied ? waits.settle(settings) : Effect.fail(new MissingScreenPending());
55
+ }
47
56
  return {
48
57
  ...screenReadouts(currentRoot, tell, dialogs),
49
58
  ...screenInteractions(elements, perform),
@@ -56,14 +65,16 @@ function makeScreenActions(options, dialogs) {
56
65
  }),
57
66
  enter: (selector, value) => perform(`enter a value in ${targetName(selector)}`, () => elements.enter(selector, value)),
58
67
  select: (selector, value) => perform(`select ${JSON.stringify(value)} in ${targetName(selector)}`, () => elements.select(selector, value)),
59
- settle: (settings) => pending === undefined && activity === undefined && transport === undefined ? Effect.fail(new MissingScreenPending()) : waits.settle(settings),
68
+ settle,
60
69
  submit: (selector = "form") => perform(`submit ${targetName(selector)}`, () => elements.form(selector).requestSubmit()),
61
- withLiveAnswer: (answers, action, settings = {}) => Effect.gen(function* () {
62
- const before = yield* answers.current;
63
- const result = yield* action;
64
- tell(`wait for a live answer to ${answers.name}`);
65
- yield* withLive(screenAct(act, nextLiveAnswer(answers, before, settings.timeoutMs ?? timeoutMs)));
66
- return result;
70
+ sync: Effect.fnUntraced(function* (settings) {
71
+ if (options.sync === undefined) {
72
+ return yield* new MissingScreenSync();
73
+ }
74
+ const limit = settings?.timeoutMs ?? timeoutMs;
75
+ tell("wait for the screen to show every change committed so far");
76
+ yield* withLive(screenAct(act, Effect.timeoutOrElse(Effect.orDie(options.sync), { duration: limit, orElse: () => Effect.die(unsynced(limit, currentRoot().textContent)) })));
77
+ yield* settle(settings);
67
78
  }),
68
79
  };
69
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"screenDriver.js","sourceRoot":"","sources":["../../src/server/screenDriver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAkB,SAAS,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC1G,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAiBnD,MAAM,OAAO,oBAAqB,SAAQ,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC;IAC/D,OAAO,GACxB,wKAAwK,CAAC;CAC1K;AAiBD,MAAM,UAAU,YAAY,CAAC,OAA4B;IACxD,OAAO,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,UAAU,CAAC,OAA4B,EAAE,OA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- "version": "0.47.2",
3
+ "version": "0.47.3",
4
4
  "description": "Tests that read like stories over the real engine: a story kit per engine with its own it, traits per feature, and a failure that prints the story, where it stopped and the engine's state",
5
5
  "homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/test-story#readme",
6
6
  "bugs": {
@@ -42,9 +42,9 @@
42
42
  "README.md"
43
43
  ],
44
44
  "dependencies": {
45
- "@shivaedev/contract": "0.45.0",
45
+ "@shivaedev/contract": "0.46.0",
46
46
  "@shivaedev/test": "0.17.2",
47
- "@shivaedev/test-sql": "0.25.1",
47
+ "@shivaedev/test-sql": "0.25.2",
48
48
  "dom-accessibility-api": "0.7.1"
49
49
  },
50
50
  "devDependencies": {
@@ -52,9 +52,9 @@
52
52
  "@effect/platform-node": "4.1.2",
53
53
  "@effect/sql-pg": "4.1.2",
54
54
  "@effect/vitest": "4.1.2",
55
- "@shivaedev/quality": "0.78.1",
56
- "@shivaedev/react": "0.48.0",
57
- "@shivaedev/server": "0.34.2",
55
+ "@shivaedev/quality": "0.78.2",
56
+ "@shivaedev/react": "0.48.1",
57
+ "@shivaedev/server": "0.35.0",
58
58
  "@types/node": "24.19.2",
59
59
  "@types/react": "19.3.0",
60
60
  "@types/react-dom": "19.3.0",
@@ -4,8 +4,6 @@ import type * as Stream from "effect/Stream";
4
4
  import { withLive } from "@shivaedev/test/withLive.ts";
5
5
  import { directScreenAct, type ScreenAct, screenAct, screenPerform } from "#server/adapters/screenAct.ts";
6
6
  import { screenElements } from "#server/adapters/screenElements.ts";
7
- import type { LiveAnswerSignal } from "#server/LiveAnswerSignal.ts";
8
- import { nextLiveAnswer } from "#server/nextLiveAnswer.ts";
9
7
  import { screenInteractions } from "#server/screenInteractions.ts";
10
8
  import { screenReadouts } from "#server/screenReadouts.ts";
11
9
  import type { ScreenSignal } from "#server/screenSignal.ts";
@@ -22,6 +20,7 @@ export interface ScreenDriverOptions {
22
20
  readonly loadingTimeoutMs?: number;
23
21
  readonly pending?: (() => boolean) | Stream.Stream<boolean> | ScreenSignal;
24
22
  readonly root: HTMLElement | (() => HTMLElement);
23
+ readonly sync?: Effect.Effect<unknown, unknown>;
25
24
  readonly tell: (line: string) => void;
26
25
  readonly timeoutMs?: number;
27
26
  readonly transport?: ScreenDriverOptions["pending"];
@@ -32,8 +31,14 @@ export class MissingScreenPending extends Data.TaggedError("MissingScreenPending
32
31
  "Cannot settle the screen without a completion signal.\nhelp: Supply pending, activity or transport that stays busy until the resulting screen work is ready to render.";
33
32
  }
34
33
 
35
- export type ScreenDriver<E = never> = Omit<ReturnType<typeof makeScreenActions>, "settle"> & {
34
+ export class MissingScreenSync extends Data.TaggedError("MissingScreenSync") {
35
+ override readonly message =
36
+ "Cannot sync the screen without a sync Effect.\nhelp: Supply sync, an Effect that completes once the screen's live queries show every change committed before it, such as screenSync(client, registry) from @shivaedev/contract/screenSync.ts.";
37
+ }
38
+
39
+ export type ScreenDriver<E = never> = Omit<ReturnType<typeof makeScreenActions>, "settle" | "sync"> & {
36
40
  settle: (options?: { readonly timeoutMs?: number }) => Effect.Effect<void, E>;
41
+ sync: (options?: { readonly timeoutMs?: number }) => Effect.Effect<void, E | MissingScreenSync>;
37
42
  dialog: (target: ScreenTarget) => ScreenDriver<E>;
38
43
  within: (container: ScreenTarget | HTMLElement) => ScreenDriver<E>;
39
44
  };
@@ -76,12 +81,22 @@ function makeDriver(options: ScreenDriverOptions, dialogs: boolean, dialogOwner?
76
81
  };
77
82
  }
78
83
 
84
+ function unsynced(limit: number, screen: string | null) {
85
+ return new Error(
86
+ `The screen did not sync within ${limit}ms.\nhelp: Release held server work and check that the host serves the client's sync command.\nScreen: ${screen}`,
87
+ );
88
+ }
89
+
79
90
  function makeScreenActions(options: ScreenDriverOptions, dialogs: boolean) {
80
91
  const { root, pending, activity, transport, tell, act = directScreenAct, timeoutMs = 3000, loadingTimeoutMs = 10_000 } = options;
92
+ const supplied = pending !== undefined || activity !== undefined || transport !== undefined;
81
93
  const currentRoot = typeof root === "function" ? root : () => root;
82
94
  const elements = screenElements(currentRoot, dialogs);
83
95
  const waits = screenWaits({ ...options, act, loadingTimeoutMs, pending, root: currentRoot, timeoutMs }, elements, dialogs);
84
96
  const perform = screenPerform(act, tell);
97
+ function settle(settings?: { readonly timeoutMs?: number }) {
98
+ return supplied ? waits.settle(settings) : Effect.fail(new MissingScreenPending());
99
+ }
85
100
 
86
101
  return {
87
102
  ...screenReadouts(currentRoot, tell, dialogs),
@@ -97,16 +112,21 @@ function makeScreenActions(options: ScreenDriverOptions, dialogs: boolean) {
97
112
  enter: (selector: ScreenTarget, value: string) => perform(`enter a value in ${targetName(selector)}`, () => elements.enter(selector, value)),
98
113
  select: (selector: ScreenTarget, value: string) =>
99
114
  perform(`select ${JSON.stringify(value)} in ${targetName(selector)}`, () => elements.select(selector, value)),
100
- settle: (settings?: { readonly timeoutMs?: number }) =>
101
- pending === undefined && activity === undefined && transport === undefined ? Effect.fail(new MissingScreenPending()) : waits.settle(settings),
115
+ settle,
102
116
  submit: (selector: ScreenTarget = "form") => perform(`submit ${targetName(selector)}`, () => elements.form(selector).requestSubmit()),
103
- withLiveAnswer: <A, E, R>(answers: LiveAnswerSignal, action: Effect.Effect<A, E, R>, settings: { readonly timeoutMs?: number } = {}) =>
104
- Effect.gen(function* () {
105
- const before = yield* answers.current;
106
- const result = yield* action;
107
- tell(`wait for a live answer to ${answers.name}`);
108
- yield* withLive(screenAct(act, nextLiveAnswer(answers, before, settings.timeoutMs ?? timeoutMs)));
109
- return result;
110
- }),
117
+ sync: Effect.fnUntraced(function* (settings?: { readonly timeoutMs?: number }) {
118
+ if (options.sync === undefined) {
119
+ return yield* new MissingScreenSync();
120
+ }
121
+ const limit = settings?.timeoutMs ?? timeoutMs;
122
+ tell("wait for the screen to show every change committed so far");
123
+ yield* withLive(
124
+ screenAct(
125
+ act,
126
+ Effect.timeoutOrElse(Effect.orDie(options.sync), { duration: limit, orElse: () => Effect.die(unsynced(limit, currentRoot().textContent)) }),
127
+ ),
128
+ );
129
+ yield* settle(settings);
130
+ }),
111
131
  };
112
132
  }
@@ -1,8 +0,0 @@
1
- import type * as Effect from "effect/Effect";
2
- import type * as Stream from "effect/Stream";
3
- export interface LiveAnswerSignal {
4
- readonly answered: Stream.Stream<number>;
5
- readonly current: Effect.Effect<number>;
6
- readonly name: string;
7
- }
8
- //# sourceMappingURL=LiveAnswerSignal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiveAnswerSignal.d.ts","sourceRoot":"","sources":["../../src/server/LiveAnswerSignal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAE7C,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=LiveAnswerSignal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiveAnswerSignal.js","sourceRoot":"","sources":["../../src/server/LiveAnswerSignal.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
- import * as Effect from "effect/Effect";
2
- import type { LiveAnswerSignal } from "#server/LiveAnswerSignal.ts";
3
- import { SignalNotReceived } from "#server/until.ts";
4
- export declare const nextLiveAnswer: (answers: LiveAnswerSignal, before: number, timeoutMs: number) => Effect.Effect<void, SignalNotReceived, never>;
5
- //# sourceMappingURL=nextLiveAnswer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nextLiveAnswer.d.ts","sourceRoot":"","sources":["../../src/server/nextLiveAnswer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,eAAO,MAAM,cAAc,iHAiBzB,CAAC"}
@@ -1,19 +0,0 @@
1
- import * as Effect from "effect/Effect";
2
- import * as Option from "effect/Option";
3
- import * as Stream from "effect/Stream";
4
- import { SignalNotReceived } from "#server/until.ts";
5
- export const nextLiveAnswer = Effect.fnUntraced(function* (answers, before, timeoutMs) {
6
- function missing(reason) {
7
- return new SignalNotReceived({
8
- message: [
9
- `Waited for a live answer to ${answers.name} after the action above, none arrived: ${reason}.`,
10
- "help: the server pushed no result for this query after the action. Check that the action changes what the query",
11
- " reads, or settle without this wait when the command's own reply updates the screen.",
12
- ].join("\n"),
13
- });
14
- }
15
- const answer = answers.answered.pipe(Stream.filter((completed) => completed > before), Stream.runHead, Effect.flatMap((found) => (Option.isSome(found) ? Effect.void : Effect.fail(missing("the query's answers ended")))));
16
- const deadline = Effect.sleep(timeoutMs).pipe(Effect.andThen(Effect.fail(missing(`nothing came within ${timeoutMs}ms`))));
17
- return yield* Effect.raceFirst(answer, deadline);
18
- });
19
- //# sourceMappingURL=nextLiveAnswer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nextLiveAnswer.js","sourceRoot":"","sources":["../../src/server/nextLiveAnswer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,OAAyB,EAAE,MAAc,EAAE,SAAiB;IACtH,SAAS,OAAO,CAAC,MAAc;QAC9B,OAAO,IAAI,iBAAiB,CAAC;YAC5B,OAAO,EAAE;gBACR,+BAA+B,OAAO,CAAC,IAAI,0CAA0C,MAAM,GAAG;gBAC9F,iHAAiH;gBACjH,2FAA2F;aAC3F,CAAC,IAAI,CAAC,IAAI,CAAC;SACZ,CAAC,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CACnC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,GAAG,MAAM,CAAC,EAChD,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,CACnH,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,uBAAuB,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1H,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAClD,CAAC,CAAC,CAAC"}
@@ -1,8 +0,0 @@
1
- import type * as Effect from "effect/Effect";
2
- import type * as Stream from "effect/Stream";
3
-
4
- export interface LiveAnswerSignal {
5
- readonly answered: Stream.Stream<number>;
6
- readonly current: Effect.Effect<number>;
7
- readonly name: string;
8
- }
@@ -1,24 +0,0 @@
1
- import * as Effect from "effect/Effect";
2
- import * as Option from "effect/Option";
3
- import * as Stream from "effect/Stream";
4
- import type { LiveAnswerSignal } from "#server/LiveAnswerSignal.ts";
5
- import { SignalNotReceived } from "#server/until.ts";
6
-
7
- export const nextLiveAnswer = Effect.fnUntraced(function* (answers: LiveAnswerSignal, before: number, timeoutMs: number) {
8
- function missing(reason: string) {
9
- return new SignalNotReceived({
10
- message: [
11
- `Waited for a live answer to ${answers.name} after the action above, none arrived: ${reason}.`,
12
- "help: the server pushed no result for this query after the action. Check that the action changes what the query",
13
- " reads, or settle without this wait when the command's own reply updates the screen.",
14
- ].join("\n"),
15
- });
16
- }
17
- const answer = answers.answered.pipe(
18
- Stream.filter((completed) => completed > before),
19
- Stream.runHead,
20
- Effect.flatMap((found) => (Option.isSome(found) ? Effect.void : Effect.fail(missing("the query's answers ended")))),
21
- );
22
- const deadline = Effect.sleep(timeoutMs).pipe(Effect.andThen(Effect.fail(missing(`nothing came within ${timeoutMs}ms`))));
23
- return yield* Effect.raceFirst(answer, deadline);
24
- });