@voltro/testing 0.32.0 → 0.34.0

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # @voltro/testing
4
4
 
5
- **Test utilities for Voltro apps — deterministic clock, captured emails, queued LLM responses, scoped subject/tenant runners, and a cross-dialect parity harness.**
5
+ **Test utilities for Voltro apps — deterministic clock, subject and row factories, a handler-level invoke and a request-level app harness, queued LLM responses, scoped subject/tenant runners, and a cross-dialect parity harness.**
6
6
 
7
7
  [📖 Documentation](https://docs.voltro.dev/docs/testing/overview) · [voltro.dev](https://voltro.dev) · [Voltro Cloud](https://voltro.cloud)
8
8
 
@@ -5,7 +5,7 @@ property of its respective copyright holders and is used under the terms of
5
5
  its license. This file is provided for attribution; it grants no rights in
6
6
  @voltro/testing itself, which is proprietary (see LICENSE).
7
7
 
8
- Generated from the resolved runtime dependency closure (52 packages).
8
+ Generated from the resolved runtime dependency closure (51 packages).
9
9
 
10
10
  ---
11
11
 
@@ -37,34 +37,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
37
  SOFTWARE.
38
38
  ```
39
39
 
40
- ## @effect/opentelemetry@0.64.0
41
-
42
- License: MIT
43
-
44
- ```
45
- MIT License
46
-
47
- Copyright (c) 2020-present The Contributors
48
-
49
- Permission is hereby granted, free of charge, to any person obtaining a copy
50
- of this software and associated documentation files (the "Software"), to deal
51
- in the Software without restriction, including without limitation the rights
52
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
- copies of the Software, and to permit persons to whom the Software is
54
- furnished to do so, subject to the following conditions:
55
-
56
- The above copyright notice and this permission notice shall be included in all
57
- copies or substantial portions of the Software.
58
-
59
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
- SOFTWARE.
66
- ```
67
-
68
40
  ## @effect/platform-node@0.108.0
69
41
 
70
42
  License: MIT
package/dist/client.d.ts CHANGED
@@ -1,9 +1,40 @@
1
+ import { Effect } from 'effect';
2
+ import { Exit } from 'effect/Exit';
1
3
  import { ReactElement } from 'react';
2
4
  import { ReactNode } from 'react';
5
+ import { RunForkOptions } from 'effect/Runtime';
6
+ import { RuntimeFiber } from 'effect/Fiber';
7
+
8
+ /**
9
+ * The runtime the hooks get. EXPORTED so it can be guarded.
10
+ *
11
+ * `runPromiseExit` is required, not optional: every write hook goes through
12
+ * `runRpcPromise`, which reads the exit and re-throws `Cause.squash(...)` so a
13
+ * rejection carries its `_tag` — and it calls `runtime.runPromiseExit`, not
14
+ * `runPromise`. A fake missing the method makes `mutate()` throw
15
+ * `runtime.runPromiseExit is not a function` into a `void`ed promise: no handler
16
+ * runs, nothing is recorded, and the component renders perfectly. This harness
17
+ * kept a two-method runtime for a release after the write path moved, and the
18
+ * failure read as "the click did not register".
19
+ *
20
+ * It is a module constant rather than a per-instance literal for one reason:
21
+ * `fakeRuntimeParity.test.ts` derives the required method set from the client's
22
+ * own source and checks it against THIS object, so the next method the client
23
+ * starts calling goes red here instead of in whichever hook reaches it first.
24
+ */
25
+ export declare const FAKE_RUNTIME: {
26
+ runPromise: <A, E>(effect: Effect.Effect<A, E, never>, options?: {
27
+ readonly signal?: AbortSignal | undefined;
28
+ } | undefined) => Promise<A>;
29
+ runPromiseExit: <A, E>(effect: Effect.Effect<A, E, never>, options?: {
30
+ readonly signal?: AbortSignal;
31
+ } | undefined) => Promise< Exit<A, E>>;
32
+ runFork: <A, E>(effect: Effect.Effect<A, E>, options?: RunForkOptions) => RuntimeFiber<A, E>;
33
+ dispose: () => Effect.Effect<void, never, never>;
34
+ };
3
35
 
4
36
  declare type Handler = (input: never) => unknown;
5
37
 
6
- /** Build a fake api context for tests. See the module comment. */
7
38
  export declare const makeVoltroTestClient: (config?: VoltroTestClientConfig) => VoltroTestClient;
8
39
 
9
40
  /** One recorded write, so a test can assert WHAT was called with WHICH input. */
@@ -13,13 +44,29 @@ export declare interface RecordedCall {
13
44
  readonly input: unknown;
14
45
  }
15
46
 
47
+ /**
48
+ * The parts of a snapshot that are NOT the data.
49
+ *
50
+ * They exist because real pages render them: the notes template greys out rows
51
+ * while `pendingPatches > 0` and prints the time of the last delta from
52
+ * `emittedAt`. The harness hardcoded both, so a page that renders either had a
53
+ * state no test could reach — the gap you only find by pointing the harness at
54
+ * an app that was written before it.
55
+ */
56
+ export declare interface SnapshotMeta {
57
+ /** Optimistic patches awaiting confirmation. Drives "n pending" affordances. */
58
+ readonly pendingPatches?: number;
59
+ /** When the server emitted this delta, in ms. */
60
+ readonly emittedAt?: number;
61
+ }
62
+
16
63
  export declare interface VoltroTestClient {
17
64
  /** Wrap the component under test. */
18
65
  readonly Provider: (props: {
19
66
  readonly children: ReactNode;
20
67
  }) => ReactElement;
21
68
  /** Push new data for a tag — components re-render, like a server delta. */
22
- readonly setSubscription: (tag: string, data: unknown) => void;
69
+ readonly setSubscription: (tag: string, data: unknown, meta?: SnapshotMeta) => void;
23
70
  /** Put a tag into the COLD-START error state (no snapshot + an error). */
24
71
  readonly failSubscription: (tag: string, error: unknown) => void;
25
72
  /** Return a tag to the loading state (no snapshot yet). */
package/dist/client.js CHANGED
@@ -2,36 +2,45 @@ import { Effect as e } from "effect";
2
2
  import { createElement as t } from "react";
3
3
  import { FrameworkRuntimesContext as n, RpcErrorBus as r } from "@voltro/client";
4
4
  //#region src/client.tsx
5
- var i = (i = {}) => {
6
- let a = i.apiName ?? "app", o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), l = [];
7
- for (let [e, t] of Object.entries(i.subscriptions ?? {})) o.set(e, {
5
+ var i = {
6
+ runPromise: e.runPromise,
7
+ runPromiseExit: e.runPromiseExit,
8
+ runFork: e.runFork,
9
+ dispose: () => e.void
10
+ }, a = (a = {}) => {
11
+ let o = a.apiName ?? "app", s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), u = [];
12
+ for (let [e, t] of Object.entries(a.subscriptions ?? {})) s.set(e, {
8
13
  data: t,
9
14
  error: void 0,
10
- revision: 0
15
+ revision: 0,
16
+ pendingPatches: 0,
17
+ emittedAt: void 0
11
18
  });
12
- let u = (e) => o.get(e) ?? {
19
+ let d = (e) => s.get(e) ?? {
13
20
  data: void 0,
14
21
  error: void 0,
15
- revision: -1
16
- }, d = (e) => {
17
- c.delete(e);
18
- for (let t of s.get(e) ?? []) t();
19
- }, f = (e) => String(e[0] ?? ""), p = {
22
+ revision: -1,
23
+ pendingPatches: 0,
24
+ emittedAt: void 0
25
+ }, f = (e) => {
26
+ l.delete(e);
27
+ for (let t of c.get(e) ?? []) t();
28
+ }, p = (e) => String(e[0] ?? ""), m = {
20
29
  peek: (e) => {
21
- let t = f(e), n = c.get(t);
30
+ let t = p(e), n = l.get(t);
22
31
  if (n) return n;
23
- let r = u(t), i = {
32
+ let r = d(t), i = {
24
33
  data: r.data,
25
34
  revision: r.revision,
26
- emittedAt: void 0,
35
+ emittedAt: r.emittedAt,
27
36
  error: r.error,
28
- pendingPatches: 0
37
+ pendingPatches: r.pendingPatches
29
38
  };
30
- return c.set(t, i), i;
39
+ return l.set(t, i), i;
31
40
  },
32
41
  subscribe: (e, t, n, r) => {
33
- let i = f(e), a = s.get(i) ?? /* @__PURE__ */ new Set();
34
- return a.add(r), s.set(i, a), { unsubscribe: () => {
42
+ let i = p(e), a = c.get(i) ?? /* @__PURE__ */ new Set();
43
+ return a.add(r), c.set(i, a), { unsubscribe: () => {
35
44
  a.delete(r);
36
45
  } };
37
46
  },
@@ -41,11 +50,11 @@ var i = (i = {}) => {
41
50
  update: () => {},
42
51
  forTag: () => ({ patchedCount: 0 }),
43
52
  refreshAll: () => {}
44
- }, m = {}, h = (t, n, r) => {
45
- let i = t.split("."), a = m;
53
+ }, h = {}, g = (t, n, r) => {
54
+ let i = t.split("."), a = h;
46
55
  for (let e of i.slice(0, -1)) a[e] = a[e] ?? {}, a = a[e];
47
56
  a[i[i.length - 1]] = (i) => e.tryPromise({
48
- try: async () => (l.push({
57
+ try: async () => (u.push({
49
58
  kind: n,
50
59
  tag: t,
51
60
  input: i
@@ -53,47 +62,48 @@ var i = (i = {}) => {
53
62
  catch: (e) => e
54
63
  });
55
64
  };
56
- for (let [e, t] of Object.entries(i.mutations ?? {})) h(e, "mutation", t);
57
- for (let [e, t] of Object.entries(i.actions ?? {})) h(e, "action", t);
58
- let g = {
59
- runtime: {
60
- runPromise: e.runPromise,
61
- runFork: e.runFork
62
- },
63
- cache: p,
64
- client: m,
65
+ for (let [e, t] of Object.entries(a.mutations ?? {})) g(e, "mutation", t);
66
+ for (let [e, t] of Object.entries(a.actions ?? {})) g(e, "action", t);
67
+ let _ = {
68
+ runtime: i,
69
+ cache: m,
70
+ client: h,
65
71
  descriptors: {},
66
72
  inspectBaseUrl: "http://test.local",
67
73
  errorBus: new r()
68
- }, _ = {
74
+ }, v = {
69
75
  get: (e) => {
70
- if (e !== a) throw Error(`makeVoltroTestClient: component asked for api '${e}' but the harness was built for '${a}'. Pass { apiName: '${e}' }.`);
71
- return g;
76
+ if (e !== o) throw Error(`makeVoltroTestClient: component asked for api '${e}' but the harness was built for '${o}'. Pass { apiName: '${e}' }.`);
77
+ return _;
72
78
  },
73
- names: [a]
79
+ names: [o]
74
80
  };
75
81
  return {
76
- Provider: ({ children: e }) => t(n.Provider, { value: _ }, e),
77
- setSubscription: (e, t) => {
78
- let n = u(e);
79
- o.set(e, {
82
+ Provider: ({ children: e }) => t(n.Provider, { value: v }, e),
83
+ setSubscription: (e, t, n) => {
84
+ let r = d(e);
85
+ s.set(e, {
80
86
  data: t,
81
87
  error: void 0,
82
- revision: n.revision + 1
83
- }), d(e);
88
+ revision: r.revision + 1,
89
+ pendingPatches: n?.pendingPatches ?? 0,
90
+ emittedAt: n?.emittedAt
91
+ }), f(e);
84
92
  },
85
93
  failSubscription: (e, t) => {
86
- o.set(e, {
94
+ s.set(e, {
87
95
  data: void 0,
88
96
  error: t,
89
- revision: -1
90
- }), d(e);
97
+ revision: -1,
98
+ pendingPatches: 0,
99
+ emittedAt: void 0
100
+ }), f(e);
91
101
  },
92
102
  resetSubscription: (e) => {
93
- o.delete(e), d(e);
103
+ s.delete(e), f(e);
94
104
  },
95
- calls: l
105
+ calls: u
96
106
  };
97
107
  };
98
108
  //#endregion
99
- export { i as makeVoltroTestClient };
109
+ export { i as FAKE_RUNTIME, a as makeVoltroTestClient };