@lumeweb/sia-testing 0.0.0-stage → 0.0.1

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 (90) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +210 -2
  3. package/dist/esm/client.d.ts +8 -0
  4. package/dist/esm/client.js +6 -0
  5. package/dist/esm/http.d.ts +3 -0
  6. package/dist/esm/http.js +3 -0
  7. package/dist/esm/mock.d.ts +8 -0
  8. package/dist/esm/mock.js +7 -0
  9. package/dist/esm/model/index.js +509 -0
  10. package/dist/esm/model/state.js +188 -0
  11. package/dist/esm/msw.d.ts +2 -0
  12. package/dist/esm/msw.js +3 -0
  13. package/dist/esm/node.d.ts +4 -0
  14. package/dist/esm/node.js +4 -0
  15. package/dist/esm/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/_md.js +169 -0
  16. package/dist/esm/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/_u64.js +12 -0
  17. package/dist/esm/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/sha2.js +199 -0
  18. package/dist/esm/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/utils.js +220 -0
  19. package/dist/esm/sdk/abort.js +23 -0
  20. package/dist/esm/sdk/control.js +129 -0
  21. package/dist/esm/sdk/index.js +454 -0
  22. package/dist/esm/sdk/link.js +55 -0
  23. package/dist/esm/sdk/object.js +24 -0
  24. package/dist/esm/sdk/payload-store.d.ts +9 -0
  25. package/dist/esm/sdk/payload-store.js +67 -0
  26. package/dist/esm/sdk/state.js +74 -0
  27. package/dist/esm/testing/application-client.d.ts +8 -0
  28. package/dist/esm/testing/application-client.js +295 -0
  29. package/dist/esm/testing/application-metadata.js +17 -0
  30. package/dist/esm/testing/application-transport.js +363 -0
  31. package/dist/esm/testing/auth-client.d.ts +20 -0
  32. package/dist/esm/testing/auth-client.js +63 -0
  33. package/dist/esm/testing/authentication.js +48 -0
  34. package/dist/esm/testing/byte-view.js +28 -0
  35. package/dist/esm/testing/chunked-files.d.ts +12 -0
  36. package/dist/esm/testing/chunked-files.js +50 -0
  37. package/dist/esm/testing/client.d.ts +8 -0
  38. package/dist/esm/testing/client.js +105 -0
  39. package/dist/esm/testing/controls.d.ts +44 -0
  40. package/dist/esm/testing/controls.js +255 -0
  41. package/dist/esm/testing/diagnostics.js +55 -0
  42. package/dist/esm/testing/files.d.ts +9 -0
  43. package/dist/esm/testing/files.js +86 -0
  44. package/dist/esm/testing/http-body.js +33 -0
  45. package/dist/esm/testing/http.d.ts +14 -0
  46. package/dist/esm/testing/http.js +181 -0
  47. package/dist/esm/testing/live/agent.d.ts +1 -0
  48. package/dist/esm/testing/live/agent.js +211 -0
  49. package/dist/esm/testing/live/approval.js +42 -0
  50. package/dist/esm/testing/live/cleanup.js +74 -0
  51. package/dist/esm/testing/live/journal.js +180 -0
  52. package/dist/esm/testing/live/lease.js +56 -0
  53. package/dist/esm/testing/live/private-files.js +50 -0
  54. package/dist/esm/testing/live/process.js +208 -0
  55. package/dist/esm/testing/live/profile.js +214 -0
  56. package/dist/esm/testing/live/recovery.js +164 -0
  57. package/dist/esm/testing/live/resource-limits.js +9 -0
  58. package/dist/esm/testing/live/run.js +390 -0
  59. package/dist/esm/testing/live/session.js +93 -0
  60. package/dist/esm/testing/live/types.d.ts +8 -0
  61. package/dist/esm/testing/mock.d.ts +8 -0
  62. package/dist/esm/testing/mock.js +1364 -0
  63. package/dist/esm/testing/msw.d.ts +21 -0
  64. package/dist/esm/testing/msw.js +61 -0
  65. package/dist/esm/testing/mutations.d.ts +59 -0
  66. package/dist/esm/testing/mutations.js +58 -0
  67. package/dist/esm/testing/node-payload-store.js +353 -0
  68. package/dist/esm/testing/node.d.ts +40 -0
  69. package/dist/esm/testing/node.js +148 -0
  70. package/dist/esm/testing/owner-client.d.ts +9 -0
  71. package/dist/esm/testing/owner-client.js +101 -0
  72. package/dist/esm/testing/owner-shares.js +80 -0
  73. package/dist/esm/testing/packed.d.ts +46 -0
  74. package/dist/esm/testing/packed.js +326 -0
  75. package/dist/esm/testing/reader-lifetime.js +40 -0
  76. package/dist/esm/testing/reply-loss.js +14 -0
  77. package/dist/esm/testing/runtime.d.ts +7 -0
  78. package/dist/esm/testing/runtime.js +13 -0
  79. package/dist/esm/testing/sdk-upload.d.ts +45 -0
  80. package/dist/esm/testing/sdk-upload.js +198 -0
  81. package/dist/esm/testing/streaming-source.js +72 -0
  82. package/dist/esm/testing/transport.d.ts +22 -0
  83. package/dist/esm/testing/transport.js +238 -0
  84. package/dist/esm/testing/types.d.ts +276 -0
  85. package/dist/esm/vitest.d.ts +23 -0
  86. package/dist/esm/vitest.js +34 -0
  87. package/docs/live-auth.md +154 -0
  88. package/docs/live-runs.md +188 -0
  89. package/docs/mock-contracts.md +647 -0
  90. package/package.json +90 -3
@@ -0,0 +1,67 @@
1
+ import { sha256 } from "../node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/sha2.js";
2
+
3
+ //#region src/sdk/payload-store.ts
4
+ /** Private payload authority keeps filesystem capabilities out of object descriptors. */
5
+ /** Buffered snapshots retain their V1 encoding; only this owner can reveal buffered bytes. */
6
+ function createBufferedPayloadOwner() {
7
+ const adopted = /* @__PURE__ */ new WeakSet();
8
+ const values = /* @__PURE__ */ new WeakMap();
9
+ function bytes(token) {
10
+ const value = values.get(token);
11
+ if (!value) throw new Error("Unknown buffered payload");
12
+ return value;
13
+ }
14
+ return {
15
+ bytes,
16
+ drain() {
17
+ return Promise.resolve();
18
+ },
19
+ finish(input) {
20
+ const owned = input.slice();
21
+ const token = Object.freeze({
22
+ length: owned.byteLength,
23
+ sha256: digestHex(sha256(owned))
24
+ });
25
+ values.set(token, owned);
26
+ return token;
27
+ },
28
+ kind: "buffered",
29
+ openReader(token, offset, length) {
30
+ const value = bytes(token);
31
+ let position = Math.min(offset, value.length);
32
+ const end = Math.min(position + length, value.length);
33
+ let closed = false;
34
+ return Promise.resolve({
35
+ close() {
36
+ closed = true;
37
+ return Promise.resolve();
38
+ },
39
+ read(maxBytes = 65536) {
40
+ if (closed) return Promise.reject(/* @__PURE__ */ new Error("Payload reader closed"));
41
+ if (position === end) return Promise.resolve(null);
42
+ const next = Math.min(position + Math.min(65536, maxBytes), end);
43
+ const block = value.slice(position, next);
44
+ position = next;
45
+ return Promise.resolve(block);
46
+ }
47
+ });
48
+ },
49
+ prepareAdoption(token) {
50
+ bytes(token);
51
+ if (adopted.has(token)) throw new Error("Payload already adopted");
52
+ return () => {
53
+ adopted.add(token);
54
+ };
55
+ },
56
+ retire(token) {
57
+ values.delete(token);
58
+ return Promise.resolve();
59
+ }
60
+ };
61
+ }
62
+ function digestHex(bytes) {
63
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
64
+ }
65
+
66
+ //#endregion
67
+ export { createBufferedPayloadOwner };
@@ -0,0 +1,74 @@
1
+ import { createIndexdModel } from "../model/index.js";
2
+
3
+ //#region src/sdk/state.ts
4
+ /** Payload checkpoints pair owned bytes with a full model checkpoint; fault controls remain session-local. */
5
+ /** A reused slab ID cannot prove that cached bytes belong to the account's current pin. */
6
+ function payloadIsCurrent(model, accountId, payload) {
7
+ try {
8
+ return model.slabIdentity(accountId, payload.slabId) === payload.identity;
9
+ } catch {
10
+ return false;
11
+ }
12
+ }
13
+ function payloadSlabId(accountId, id) {
14
+ return `mock:${JSON.stringify([accountId, id])}`;
15
+ }
16
+ /** The restored model validates slab ownership before any saved payload becomes visible. */
17
+ function readNetworkState(serialized, now) {
18
+ try {
19
+ const state = JSON.parse(serialized);
20
+ if (!state || state.version !== 1 || typeof state.model !== "string" || !Array.isArray(state.payloads)) throw new Error("invalid snapshot structure");
21
+ const model = createIndexdModel({
22
+ ...now ? { now } : {},
23
+ state: state.model
24
+ });
25
+ const payloads = /* @__PURE__ */ new Map();
26
+ for (const entry of state.payloads) {
27
+ if (!entry || typeof entry.accountId !== "string" || typeof entry.id !== "string" || !entry.id || typeof entry.data !== "string") throw new Error("invalid snapshot payload");
28
+ const binary = atob(entry.data);
29
+ if (btoa(binary) !== entry.data) throw new Error("invalid snapshot encoding");
30
+ const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
31
+ const slabId = payloadSlabId(entry.accountId, entry.id);
32
+ if (model.getSlab(entry.accountId, slabId).size !== bytes.byteLength) throw new Error("snapshot payload size does not match its slab");
33
+ let owned = payloads.get(entry.accountId);
34
+ if (!owned) {
35
+ owned = /* @__PURE__ */ new Map();
36
+ payloads.set(entry.accountId, owned);
37
+ }
38
+ if (owned.has(entry.id)) throw new Error("duplicate snapshot payload");
39
+ owned.set(entry.id, {
40
+ bytes,
41
+ identity: model.slabIdentity(entry.accountId, slabId),
42
+ slabId
43
+ });
44
+ }
45
+ return {
46
+ model,
47
+ payloads
48
+ };
49
+ } catch (cause) {
50
+ throw new Error("invalid mock network snapshot", { cause });
51
+ }
52
+ }
53
+ /** Externally pruned slabs and reset accounts must not revive stale payloads on restart. */
54
+ function serializeNetworkState(model, payloads) {
55
+ const saved = {
56
+ model: model.serialize(),
57
+ payloads: [],
58
+ version: 1
59
+ };
60
+ for (const account of model.snapshot().accounts) for (const [id, payload] of payloads.get(account.id) ?? []) {
61
+ if (!payloadIsCurrent(model, account.id, payload)) continue;
62
+ let binary = "";
63
+ for (const byte of payload.bytes) binary += String.fromCharCode(byte);
64
+ saved.payloads.push({
65
+ accountId: account.id,
66
+ data: btoa(binary),
67
+ id
68
+ });
69
+ }
70
+ return JSON.stringify(saved);
71
+ }
72
+
73
+ //#endregion
74
+ export { payloadIsCurrent, payloadSlabId, readNetworkState, serializeNetworkState };
@@ -0,0 +1,8 @@
1
+ import { ApplicationPort } from "./types.js";
2
+ import { MockCredential } from "./runtime.js";
3
+ import { MockConnection } from "./transport.js";
4
+
5
+ //#region src/testing/application-client.d.ts
6
+ declare function createMockApplication(connection: MockConnection, credential: MockCredential): ApplicationPort;
7
+ //#endregion
8
+ export { createMockApplication };
@@ -0,0 +1,295 @@
1
+ import { readFixture } from "./files.js";
2
+ import { snapshotApplicationMetadata } from "./application-metadata.js";
3
+ import { domainError } from "./diagnostics.js";
4
+
5
+ //#region src/testing/application-client.ts
6
+ /** Fetch-backed ports own local refs and request lifetimes; upload sources open only after admission. */
7
+ function createMockApplication(connection, credential) {
8
+ const root = new URL(connection.url);
9
+ if (!/^https?:$/.test(root.protocol) || root.username || root.password || !/^[a-f0-9]{64}$/.test(credential.keyHex)) throw new Error("Invalid mock connection");
10
+ const lifetime = new AbortController();
11
+ const refs = /* @__PURE__ */ new WeakMap();
12
+ let shareRefs = /* @__PURE__ */ new WeakMap();
13
+ const tokenRefs = /* @__PURE__ */ new Map();
14
+ let session;
15
+ let bootstrap;
16
+ const pending = /* @__PURE__ */ new Set();
17
+ const cleanupErrors = [];
18
+ let closing;
19
+ function invalid() {
20
+ throw Object.assign(/* @__PURE__ */ new Error("Invalid application response"), { code: "unavailable" });
21
+ }
22
+ function track(action, prepare) {
23
+ let preparationError;
24
+ let preparationFailed = false;
25
+ const promise = Promise.resolve().then(() => {
26
+ if (preparationFailed) throw preparationError;
27
+ return action();
28
+ });
29
+ pending.add(promise);
30
+ try {
31
+ prepare?.();
32
+ } catch (error) {
33
+ preparationFailed = true;
34
+ preparationError = error;
35
+ }
36
+ promise.then(() => pending.delete(promise), () => {
37
+ pending.delete(promise);
38
+ });
39
+ return promise;
40
+ }
41
+ function signal(input) {
42
+ return AbortSignal.any([lifetime.signal, ...input ? [input] : []]);
43
+ }
44
+ async function call(operation, body, callSignal, token) {
45
+ const url = new URL(`${encodeURIComponent(connection.client)}/${operation}`, root);
46
+ if (token) url.searchParams.set("token", token);
47
+ const response = await fetch(url, {
48
+ body,
49
+ headers: { authorization: `Bearer ${credential.keyHex}` },
50
+ method: "POST",
51
+ redirect: "error",
52
+ ...callSignal ? { signal: callSignal } : {}
53
+ });
54
+ const value = await response.json();
55
+ if (!response.ok) throw domainError(operation, value);
56
+ return value;
57
+ }
58
+ function objectRef(object) {
59
+ const value = refs.get(object);
60
+ if (!value) throw Object.assign(/* @__PURE__ */ new Error("Unknown application object"), { code: "foreign-handle" });
61
+ return value;
62
+ }
63
+ function shareRef(ref) {
64
+ const token = shareRefs.get(ref);
65
+ if (!token) throw Object.assign(/* @__PURE__ */ new Error("Unknown application share"), { code: "foreign-handle" });
66
+ return token;
67
+ }
68
+ async function targets(s) {
69
+ const value = await call("app-share-targets", JSON.stringify({ session }), s);
70
+ if (!value || typeof value !== "object" || !("session" in value) || typeof value.session !== "string" || !/^[a-f0-9-]{36}$/.test(value.session) || session && session !== value.session || !("targets" in value) || !Array.isArray(value.targets)) invalid();
71
+ const labels = /* @__PURE__ */ new Set();
72
+ const tokens = /* @__PURE__ */ new Set();
73
+ const result = value.targets.map((target) => {
74
+ if (!target || typeof target !== "object" || !("ref" in target) || typeof target.ref !== "string" || !/^[a-f0-9-]{36}$/.test(target.ref) || tokens.has(target.ref) || !("label" in target) || typeof target.label !== "string" || !target.label.trim() || labels.has(target.label) || !("operations" in target) || !Array.isArray(target.operations) || !target.operations.length || new Set(target.operations).size !== target.operations.length || target.operations.some((op) => typeof op !== "string" || ![
75
+ "add",
76
+ "end",
77
+ "remove"
78
+ ].includes(op)) || "expiresAt" in target && (typeof target.expiresAt !== "string" || !Number.isFinite(Date.parse(target.expiresAt)) || new Date(target.expiresAt).toISOString() !== target.expiresAt)) invalid();
79
+ labels.add(target.label);
80
+ tokens.add(target.ref);
81
+ let ref = tokenRefs.get(target.ref);
82
+ if (!ref) {
83
+ ref = Object.freeze(Object.create(null));
84
+ tokenRefs.set(target.ref, ref);
85
+ shareRefs.set(ref, target.ref);
86
+ }
87
+ return {
88
+ label: target.label,
89
+ operations: [...target.operations],
90
+ ref,
91
+ ..."expiresAt" in target ? { expiresAt: target.expiresAt } : {}
92
+ };
93
+ });
94
+ s.throwIfAborted();
95
+ session = value.session;
96
+ return result;
97
+ }
98
+ function waitForTargets(current, signal) {
99
+ current.waiters++;
100
+ return new Promise((resolve, reject) => {
101
+ let waiting = true;
102
+ const detach = () => {
103
+ if (!waiting) return false;
104
+ waiting = false;
105
+ signal.removeEventListener("abort", abort);
106
+ current.waiters--;
107
+ return true;
108
+ };
109
+ const abort = () => {
110
+ if (!detach()) return;
111
+ if (!current.waiters) {
112
+ if (bootstrap === current) bootstrap = void 0;
113
+ current.abort.abort(signal.reason);
114
+ }
115
+ reject(signal.reason);
116
+ };
117
+ signal.addEventListener("abort", abort, { once: true });
118
+ current.work.then((value) => {
119
+ if (detach()) resolve(value);
120
+ }, (error) => {
121
+ if (!detach()) return;
122
+ reject(error);
123
+ });
124
+ if (signal.aborted) abort();
125
+ });
126
+ }
127
+ function shareCall(operation, ref, body, input) {
128
+ return track(async () => {
129
+ const s = signal(input);
130
+ s.throwIfAborted();
131
+ return await call(operation, JSON.stringify({
132
+ ...body,
133
+ ref: shareRef(ref),
134
+ session
135
+ }), s);
136
+ });
137
+ }
138
+ return {
139
+ close() {
140
+ lifetime.abort();
141
+ return closing ??= Promise.allSettled([...pending]).then(() => {
142
+ shareRefs = /* @__PURE__ */ new WeakMap();
143
+ tokenRefs.clear();
144
+ session = void 0;
145
+ if (cleanupErrors.length) throw new AggregateError(cleanupErrors, "Application source cleanup failed");
146
+ });
147
+ },
148
+ delete(object, options = {}) {
149
+ return track(async () => {
150
+ const s = signal(options.signal);
151
+ s.throwIfAborted();
152
+ await call("app-delete", JSON.stringify({ ref: objectRef(object) }), s);
153
+ });
154
+ },
155
+ events(input) {
156
+ return track(async () => {
157
+ const s = signal(input.signal);
158
+ s.throwIfAborted();
159
+ const value = await call("app-events", JSON.stringify({
160
+ cursor: input.cursor,
161
+ limit: input.limit
162
+ }), s);
163
+ if (!value || typeof value !== "object" || !("events" in value) || !Array.isArray(value.events) || value.events.length > input.limit || !("done" in value) || typeof value.done !== "boolean" || !("nextCursor" in value)) invalid();
164
+ let cursor = input.cursor;
165
+ for (const row of value.events) {
166
+ if (!row || typeof row !== "object" || !("id" in row) || typeof row.id !== "string" || !/^[a-f0-9]{64}$/.test(row.id) || !("deleted" in row) || typeof row.deleted !== "boolean" || !("updatedAt" in row) || typeof row.updatedAt !== "string" || !/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.000Z$/.test(row.updatedAt) || !Number.isFinite(Date.parse(row.updatedAt)) || new Date(row.updatedAt).toISOString() !== row.updatedAt || cursor && (row.updatedAt < cursor.after || row.updatedAt === cursor.after && row.id <= cursor.id)) invalid();
167
+ cursor = {
168
+ after: row.updatedAt,
169
+ id: row.id
170
+ };
171
+ }
172
+ const next = value.nextCursor;
173
+ if ((cursor === null ? next !== null : !next || typeof next !== "object" || !("after" in next) || next.after !== cursor.after || !("id" in next) || next.id !== cursor.id) || value.done !== value.events.length < input.limit) invalid();
174
+ return value;
175
+ });
176
+ },
177
+ inspect(object, options = {}) {
178
+ return track(async () => {
179
+ const s = signal(options.signal);
180
+ s.throwIfAborted();
181
+ const state = await call("app-inspect", JSON.stringify({ ref: objectRef(object) }), s);
182
+ if (state !== "uploaded" && state !== "pinned" && state !== "missing") invalid();
183
+ return state;
184
+ });
185
+ },
186
+ pin(object, options = {}) {
187
+ let metadata;
188
+ return track(async () => {
189
+ const s = signal(options.signal);
190
+ s.throwIfAborted();
191
+ await call("app-pin", JSON.stringify({
192
+ metadata: metadata === void 0 ? void 0 : [...metadata],
193
+ ref: objectRef(object)
194
+ }), s);
195
+ }, () => {
196
+ const source = options.metadata;
197
+ if (source !== void 0) metadata = snapshotApplicationMetadata(source);
198
+ });
199
+ },
200
+ shares: {
201
+ add(ref, object, options = {}) {
202
+ return track(async () => {
203
+ signal(options.signal).throwIfAborted();
204
+ await shareCall("app-share-add", ref, { object: objectRef(object) }, options.signal);
205
+ });
206
+ },
207
+ async end(ref, options = {}) {
208
+ await shareCall("app-share-end", ref, {}, options.signal);
209
+ },
210
+ inspect(ref, objectId, options = {}) {
211
+ return track(async () => {
212
+ const value = await shareCall("app-share-inspect", ref, { objectId }, options.signal);
213
+ if (!value || typeof value !== "object" || !("state" in value) || ![
214
+ "active",
215
+ "ended",
216
+ "expired"
217
+ ].includes(value.state) || !("contains" in value) || value.contains !== null && typeof value.contains !== "boolean" || (objectId === null || value.state === "ended") && value.contains !== null || objectId !== null && value.state !== "ended" && typeof value.contains !== "boolean") invalid();
218
+ return value;
219
+ });
220
+ },
221
+ async remove(ref, objectId, options = {}) {
222
+ await shareCall("app-share-remove", ref, { objectId }, options.signal);
223
+ },
224
+ targets(options = {}) {
225
+ return track(async () => {
226
+ const s = signal(options.signal);
227
+ s.throwIfAborted();
228
+ if (session) return targets(s);
229
+ if (!bootstrap) {
230
+ const abort = new AbortController();
231
+ const current = {
232
+ abort,
233
+ waiters: 0,
234
+ work: track(() => targets(AbortSignal.any([lifetime.signal, abort.signal])))
235
+ };
236
+ bootstrap = current;
237
+ const settled = () => {
238
+ if (bootstrap === current) bootstrap = void 0;
239
+ };
240
+ current.work.then(settled, settled);
241
+ }
242
+ return waitForTargets(bootstrap, s);
243
+ });
244
+ }
245
+ },
246
+ upload(input) {
247
+ return track(async () => {
248
+ const callSignal = signal(input.signal);
249
+ callSignal.throwIfAborted();
250
+ const file = {
251
+ name: input.file.name,
252
+ open: input.file.open.bind(input.file),
253
+ sha256: input.file.sha256,
254
+ sizeBytes: input.file.sizeBytes
255
+ };
256
+ const metadata = snapshotApplicationMetadata(input.metadata);
257
+ let name = input.name;
258
+ if (name === void 0) name = file.name;
259
+ if (typeof name !== "string" || !name || name.length > 1024 || new TextEncoder().encode(name).length > 1024 || !Number.isSafeInteger(file.sizeBytes) || file.sizeBytes < 0 || file.sizeBytes > 16 * 1024 * 1024 || !/^[a-f0-9]{64}$/.test(file.sha256)) throw Object.assign(/* @__PURE__ */ new Error("Invalid application upload"), { code: "invalid-input" });
260
+ const admission = await call("app-upload-admit", JSON.stringify({
261
+ metadata: [...new Uint8Array(metadata)],
262
+ name,
263
+ sha256: file.sha256,
264
+ sizeBytes: file.sizeBytes
265
+ }), callSignal);
266
+ if (!admission || typeof admission !== "object" || !("token" in admission) || typeof admission.token !== "string" || !/^[a-f0-9-]{36}$/.test(admission.token) || !("expiresAt" in admission) || typeof admission.expiresAt !== "number" || !Number.isFinite(admission.expiresAt)) invalid();
267
+ const token = admission.token;
268
+ const expiry = new AbortController();
269
+ const timer = setTimeout(() => expiry.abort(), Math.max(0, Math.min(3e4, admission.expiresAt - Date.now())));
270
+ let completed = false;
271
+ try {
272
+ const bodySignal = AbortSignal.any([callSignal, expiry.signal]);
273
+ const bytes = await readFixture(file, bodySignal, void 0, (error) => {
274
+ cleanupErrors.push(error);
275
+ });
276
+ const value = await call("app-upload-body", new Uint8Array(bytes), bodySignal, token);
277
+ if (!value || typeof value !== "object" || !("id" in value) || typeof value.id !== "string" || !/^[a-f0-9]{64}$/.test(value.id) || !("ref" in value) || typeof value.ref !== "string" || !/^[a-f0-9-]{36}$/.test(value.ref)) invalid();
278
+ const object = Object.freeze({ id: value.id });
279
+ refs.set(object, value.ref);
280
+ completed = true;
281
+ return object;
282
+ } finally {
283
+ try {
284
+ if (!completed && !lifetime.signal.aborted && !expiry.signal.aborted) await call("app-upload-cancel", "", AbortSignal.any([lifetime.signal, expiry.signal]), token).catch(() => void 0);
285
+ } finally {
286
+ clearTimeout(timer);
287
+ }
288
+ }
289
+ });
290
+ }
291
+ };
292
+ }
293
+
294
+ //#endregion
295
+ export { createMockApplication };
@@ -0,0 +1,17 @@
1
+ import { boundedByteView } from "./byte-view.js";
2
+
3
+ //#region src/testing/application-metadata.ts
4
+ /** Copies bounded application bytes without consulting subclass accessors or iterators. */
5
+ function snapshotApplicationMetadata(value) {
6
+ try {
7
+ const view = boundedByteView(value, 1024);
8
+ const result = new Uint8Array(view.byteLength);
9
+ result.set(view);
10
+ return result;
11
+ } catch {
12
+ throw Object.assign(/* @__PURE__ */ new Error("Invalid application metadata"), { code: "invalid-input" });
13
+ }
14
+ }
15
+
16
+ //#endregion
17
+ export { snapshotApplicationMetadata };