@waffle-os/runtime 0.0.155 → 0.0.157

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 (77) hide show
  1. package/browser/filesystem-backend.ts +11 -1
  2. package/browser/preview-protocol.ts +2 -0
  3. package/browser/preview.ts +128 -18
  4. package/browser/runtime-terminals.ts +65 -24
  5. package/browser/shared-fs.ts +141 -14
  6. package/browser/worker.ts +73 -6
  7. package/core/descriptors.ts +19 -2
  8. package/core/devices.ts +237 -2
  9. package/core/fd-reopen.ts +105 -20
  10. package/core/filesystem.ts +79 -0
  11. package/core/index.ts +4 -0
  12. package/core/open-file.ts +212 -18
  13. package/core/wasi.ts +449 -47
  14. package/dist/browser/filesystem-backend.js +4 -2
  15. package/dist/browser/preview.js +120 -17
  16. package/dist/browser/runtime-terminals.js +53 -10
  17. package/dist/browser/shared-fs.js +124 -11
  18. package/dist/browser/worker.js +59 -6
  19. package/dist/core/descriptors.js +9 -1
  20. package/dist/core/devices.js +211 -1
  21. package/dist/core/fd-reopen.js +79 -18
  22. package/dist/core/filesystem.js +14 -0
  23. package/dist/core/open-file.js +166 -13
  24. package/dist/core/wasi.js +402 -29
  25. package/dist/fs/backend.js +51 -3
  26. package/dist/fs/client.js +204 -7
  27. package/dist/fs/cold-read-cache.js +23 -0
  28. package/dist/fs/index.js +21 -1
  29. package/dist/fs/indexeddb.js +30 -2
  30. package/dist/fs/locks.js +1112 -0
  31. package/dist/fs/memory.js +126 -2
  32. package/dist/fs/multitab-backend.js +317 -196
  33. package/dist/fs/multitab-protocol.js +2 -0
  34. package/dist/fs/persistent.js +32 -7
  35. package/dist/fs/protocol.js +9 -3
  36. package/dist/fs/service.js +387 -22
  37. package/dist/fs/shared.js +54 -1
  38. package/dist/fs/storage-geometry.js +2 -0
  39. package/dist/interrupt/rewriter-internal.js +4 -1
  40. package/dist/proc/abi.js +80 -6
  41. package/dist/proc/errors.js +1 -0
  42. package/dist/proc/filesystem-codec.js +40 -9
  43. package/dist/proc/index.js +10 -1
  44. package/dist/proc/pty.js +193 -0
  45. package/dist/proc/worker-client.js +11 -2
  46. package/dist/proc/worker-pipes.js +51 -0
  47. package/dist/runtime.js +11 -2
  48. package/dist/search/engine.js +53 -0
  49. package/dist/tooling/program/program-transformer.json +1 -1
  50. package/fs/backend.ts +54 -2
  51. package/fs/client.ts +230 -6
  52. package/fs/cold-read-cache.ts +38 -0
  53. package/fs/index.ts +22 -1
  54. package/fs/indexeddb.ts +36 -2
  55. package/fs/locks.ts +1406 -0
  56. package/fs/memory.ts +132 -1
  57. package/fs/multitab-backend.ts +563 -304
  58. package/fs/multitab-protocol.ts +2 -0
  59. package/fs/persistent.ts +46 -4
  60. package/fs/protocol.ts +17 -5
  61. package/fs/service.ts +469 -23
  62. package/fs/shared.ts +60 -2
  63. package/fs/storage-geometry.ts +3 -0
  64. package/index.ts +2 -0
  65. package/interrupt/rewriter-internal.ts +4 -1
  66. package/package.json +2 -2
  67. package/proc/abi.ts +79 -6
  68. package/proc/errors.ts +1 -0
  69. package/proc/filesystem-codec.ts +39 -9
  70. package/proc/index.ts +11 -0
  71. package/proc/pty.ts +227 -0
  72. package/proc/worker-client.ts +28 -6
  73. package/proc/worker-pipes.ts +57 -0
  74. package/runtime.ts +12 -2
  75. package/search/engine.ts +49 -0
  76. package/testing/indexeddb-storage-browser.ts +173 -2
  77. package/tooling/program/program-transformer.json +1 -1
@@ -300,14 +300,23 @@ export interface WorkerProcessClientOptions {
300
300
  postMessage(message: WorkerProcessMessage): void;
301
301
  codec: WorkerDescriptorCodec;
302
302
  beginSpawnTransfer?(): () => void;
303
- prepareSpawn?(pid: number, cleanupFailed?: (error: unknown) => void): WorkerSpawnTransfer;
304
- prepareExec?(pid: number, cleanupFailed?: (error: unknown) => void): WorkerSpawnTransfer;
303
+ prepareSpawn?(
304
+ pid: number,
305
+ cleanupFailed?: (error: unknown) => void,
306
+ processKind?: ProcessKind,
307
+ ): WorkerSpawnTransfer;
308
+ prepareExec?(
309
+ pid: number,
310
+ cleanupFailed?: (error: unknown) => void,
311
+ keptFds?: readonly number[],
312
+ ): WorkerSpawnTransfer;
305
313
  registerRevocation?(hook: () => void): () => void;
306
314
  /** Synchronously freeze shared endpoint cursors after default signal death is selected.
307
315
  * A shared pipe publication registry supplies this hook without entering the guest worker.
308
316
  */
309
317
  revokeProcess?(pid: number, transport: WorkerProcessTransport): void;
310
318
  createPipe?(): readonly [Stream, Stream];
319
+ createPty?(cols: number, rows: number): readonly [Stream, Stream];
311
320
  onError?(error: unknown): void;
312
321
  }
313
322
  function snapshotSpawnRequest(
@@ -400,9 +409,16 @@ export class WorkerProcessClient {
400
409
  };
401
410
  const handoff = commandExecTransfer(staged);
402
411
  let published = false;
412
+ const keptFds: number[] = [];
413
+ for (let index = 0; index < snapshot.fds.length; index++) {
414
+ arrayAppend(keptFds, snapshot.fds[index]!.parent);
415
+ }
403
416
  try {
404
- transfer = this.options.prepareExec(pid, (error) =>
405
- recordCommandTransferFailure(this.options.transport, "exec", staged.generation, error),
417
+ transfer = this.options.prepareExec(
418
+ pid,
419
+ (error) =>
420
+ recordCommandTransferFailure(this.options.transport, "exec", staged.generation, error),
421
+ keptFds,
406
422
  );
407
423
  codec = transfer.codec ?? codec;
408
424
  staged.data = transfer.data;
@@ -643,8 +659,10 @@ export class WorkerProcessClient {
643
659
  try {
644
660
  // Acquire the host admission fence before touching shared membership. Fatal
645
661
  // teardown must not stop this worker with an anonymous outstanding reservation.
646
- transfer = this.options.prepareSpawn?.(pid, (error) =>
647
- recordCommandTransferFailure(this.options.transport, "spawn", pid, error),
662
+ transfer = this.options.prepareSpawn?.(
663
+ pid,
664
+ (error) => recordCommandTransferFailure(this.options.transport, "spawn", pid, error),
665
+ processKind,
648
666
  );
649
667
  codec = transfer?.codec ?? codec;
650
668
  child = reserveRecord(
@@ -1086,6 +1104,10 @@ export class WorkerProcessClient {
1086
1104
  if (!this.options.createPipe) throw new ProcessError(58, "worker pipe factory is unavailable");
1087
1105
  return this.options.createPipe();
1088
1106
  }
1107
+ createPty(cols: number, rows: number): readonly [Stream, Stream] {
1108
+ if (!this.options.createPty) throw new ProcessError(58, "worker pty factory is unavailable");
1109
+ return this.options.createPty(cols, rows);
1110
+ }
1089
1111
  private report(error: unknown): void {
1090
1112
  try {
1091
1113
  this.options.onError?.(error);
@@ -11,6 +11,12 @@ import {
11
11
  type PipeOptions,
12
12
  type PipePublicationRegistryHandle,
13
13
  } from "./pipes.js";
14
+ import {
15
+ PtyEndpoint,
16
+ allocatePtyGeometry,
17
+ attachPtyEndpoint,
18
+ type PtyEndpointHandle,
19
+ } from "./pty.js";
14
20
  import {
15
21
  workerProcessState,
16
22
  type WorkerDescriptorCodec,
@@ -22,9 +28,15 @@ export interface WorkerPipeDescriptorToken {
22
28
  kind: "pipe";
23
29
  endpoint: PipeEndpointHandle;
24
30
  }
31
+ export interface WorkerPtyDescriptorToken extends PtyEndpointHandle {
32
+ kind: "pty";
33
+ }
25
34
  export function isWorkerPipeDescriptorToken(token: unknown): token is WorkerPipeDescriptorToken {
26
35
  return typeof token === "object" && token !== null && "kind" in token && token.kind === "pipe";
27
36
  }
37
+ export function isWorkerPtyDescriptorToken(token: unknown): token is WorkerPtyDescriptorToken {
38
+ return typeof token === "object" && token !== null && "kind" in token && token.kind === "pty";
39
+ }
28
40
  export interface WorkerPipeCodecOptions extends Pick<PipeOptions, "allocateShared"> {
29
41
  /** Exec retains an independent lifetime while keeping the existing process lane. */
30
42
  successor?: boolean;
@@ -40,6 +52,12 @@ export interface WorkerPipeCodecOptions extends Pick<PipeOptions, "allocateShare
40
52
  export function createWorkerPipeCodec(options: WorkerPipeCodecOptions = {}): WorkerDescriptorCodec {
41
53
  return {
42
54
  export(descriptor, pid): unknown {
55
+ if (isInstance(descriptor.resource, PtyEndpoint)) {
56
+ const endpoint = options.successor
57
+ ? descriptor.resource.retainSuccessor()
58
+ : descriptor.resource.forProcess(pid);
59
+ return { kind: "pty", ...endpoint.handle() } satisfies WorkerPtyDescriptorToken;
60
+ }
43
61
  if (!isInstance(descriptor.resource, PipeEndpoint)) {
44
62
  if (options.fallback) return options.fallback.export(descriptor, pid);
45
63
  throw new TypeError(`unsupported worker descriptor: ${descriptor.resource.kind}`);
@@ -50,6 +68,14 @@ export function createWorkerPipeCodec(options: WorkerPipeCodecOptions = {}): Wor
50
68
  return { kind: "pipe", endpoint: endpoint.handle() } satisfies WorkerPipeDescriptorToken;
51
69
  },
52
70
  import(token, pid): OpenDescription {
71
+ if (isWorkerPtyDescriptorToken(token)) {
72
+ if (token.read.pid !== pid || token.write.pid !== pid)
73
+ throw new TypeError("pty descriptor belongs to another process");
74
+ options.onPipe?.(token.read);
75
+ options.onPipe?.(token.write);
76
+ const endpoint = attachPtyEndpoint(token, options);
77
+ return new OpenDescription(endpoint, () => endpoint.close());
78
+ }
53
79
  if (!isWorkerPipeDescriptorToken(token)) {
54
80
  if (options.fallback) return options.fallback.import(token, pid);
55
81
  throw new TypeError("unsupported worker descriptor token");
@@ -61,6 +87,14 @@ export function createWorkerPipeCodec(options: WorkerPipeCodecOptions = {}): Wor
61
87
  return new OpenDescription(endpoint, () => endpoint.close());
62
88
  },
63
89
  discard(token): void {
90
+ if (isWorkerPtyDescriptorToken(token)) {
91
+ try {
92
+ attachPipeEndpoint(token.read, options).close();
93
+ } finally {
94
+ attachPipeEndpoint(token.write, options).close();
95
+ }
96
+ return;
97
+ }
64
98
  if (isWorkerPipeDescriptorToken(token)) attachPipeEndpoint(token.endpoint, options).close();
65
99
  else if (options.fallback) options.fallback.discard(token);
66
100
  else throw new TypeError("unsupported worker descriptor token");
@@ -139,6 +173,29 @@ export class WorkerPipeHost {
139
173
  throw error;
140
174
  }
141
175
  }
176
+ createPty(cols: number, rows: number): readonly [PtyEndpoint, PtyEndpoint] {
177
+ const geometry = allocatePtyGeometry(cols, rows, this.options.allocateShared);
178
+ const input = this.createPipe();
179
+ const slaveIn = input[0];
180
+ const masterOut = input[1];
181
+ let masterIn: PipeEndpoint | undefined;
182
+ let slaveOut: PipeEndpoint | undefined;
183
+ try {
184
+ const output = this.createPipe();
185
+ masterIn = output[0];
186
+ slaveOut = output[1];
187
+ return [
188
+ new PtyEndpoint("master", masterIn, masterOut, geometry),
189
+ new PtyEndpoint("slave", slaveIn, slaveOut, geometry),
190
+ ];
191
+ } catch (error) {
192
+ slaveIn.close();
193
+ masterOut.close();
194
+ masterIn?.close();
195
+ slaveOut?.close();
196
+ throw error;
197
+ }
198
+ }
142
199
  /** Host capability, not a guest ABI: call only after process/job authority and default action
143
200
  * selection. It freezes even cursors on descendant-created pipes the page has not seen yet.
144
201
  */
package/runtime.ts CHANGED
@@ -86,6 +86,8 @@ export type {
86
86
  SharedFilesystemStatus,
87
87
  SharedFilesystemStateObserver,
88
88
  RemoveCondition,
89
+ StatOptions,
90
+ PathStat,
89
91
  } from "./browser/shared-fs.js";
90
92
  export { getVfsDescriptor, VfsError } from "./fs/vfs.js";
91
93
  export type { VfsMode, VfsDescriptor, VfsSelection, VfsWhenBusy, VfsErrorCode } from "./fs/vfs.js";
@@ -259,6 +261,7 @@ const filesystemCapabilities = {
259
261
  drain: "async",
260
262
  flush: "async",
261
263
  resolvePath: "async",
264
+ stat: "async",
262
265
  lookup: "async",
263
266
  readFile: "async",
264
267
  listFiles: "async",
@@ -268,6 +271,7 @@ const filesystemCapabilities = {
268
271
  move: "async",
269
272
  workspace: "readonly",
270
273
  state: "readonly",
274
+ machineId: "readonly",
271
275
  vfs: "readonly",
272
276
  ownershipLost: "readonly",
273
277
  onOwnershipLost: "callback",
@@ -954,9 +958,15 @@ export function createRuntime(options: RuntimeOptions = {}): Runtime {
954
958
  // A controller may be awaiting an adapter's launch handle when suspension wins.
955
959
  // Its late handle and asynchronous stop still belong to this page, not the next owner.
956
960
  while (launching.size) await Promise.allSettled(Array.from(launching));
957
- if (!pendingStartup) {
961
+ if (!pendingStartup && !filesystem.ownershipLost) {
958
962
  filesystem.beginRuntimeDispose();
959
- await attempt(() => filesystem.drain());
963
+ await attempt(async () => {
964
+ try {
965
+ await filesystem.drain();
966
+ } catch (error) {
967
+ if (!filesystem.ownershipLost) throw error;
968
+ }
969
+ });
960
970
  }
961
971
  // Keep the backend and relays alive while every admitted filesystem request fences.
962
972
  const failuresBeforeFences = failures.length;
package/search/engine.ts CHANGED
@@ -58,6 +58,42 @@ function displayPath(root: string, relative: string, tool: SearchPlan["tool"]):
58
58
  return prefix.endsWith("/") ? `${prefix}${relative}` : `${prefix}/${relative}`;
59
59
  }
60
60
 
61
+ /** Matches a literal-plus-`*` glob with fnmatch(pat, text, 0) semantics (`*` crosses `/`). */
62
+ function matchStarGlob(glob: string, text: string): boolean {
63
+ let g = 0;
64
+ let t = 0;
65
+ let star = -1;
66
+ let match = 0;
67
+ while (t < text.length) {
68
+ if (g < glob.length && glob[g] === "*") {
69
+ star = g++;
70
+ match = t;
71
+ } else if (g < glob.length && glob[g] === text[t]) {
72
+ g++;
73
+ t++;
74
+ } else if (star !== -1) {
75
+ g = star + 1;
76
+ t = ++match;
77
+ } else {
78
+ return false;
79
+ }
80
+ }
81
+ while (g < glob.length && glob[g] === "*") g++;
82
+ return g === glob.length;
83
+ }
84
+
85
+ function matchPathSuffix(glob: string, path: string): boolean {
86
+ let offset = 0;
87
+ for (;;) {
88
+ if (matchStarGlob(glob, path.slice(offset))) return true;
89
+ let slash = path.indexOf("/", offset);
90
+ if (slash === -1) return false;
91
+ while (slash < path.length && path[slash] === "/") slash++;
92
+ if (slash >= path.length) return false;
93
+ offset = slash;
94
+ }
95
+ }
96
+
61
97
  /** One source belongs to one SearchRun. Its entry sequence is SearchRun's candidate index. */
62
98
  export class WalkSource implements CandidateSource {
63
99
  private readonly leases = new Map<number, Lease>();
@@ -120,6 +156,10 @@ export class WalkSource implements CandidateSource {
120
156
  return;
121
157
  }
122
158
  if (opened.kind === "file") {
159
+ if (!this.matchesExplicitFile(path)) {
160
+ this.context.fs.release(opened.handle);
161
+ return;
162
+ }
123
163
  this.add(
124
164
  entries,
125
165
  { kind: "file", path, handle: opened.handle, size: opened.size },
@@ -134,6 +174,15 @@ export class WalkSource implements CandidateSource {
134
174
  }
135
175
  }
136
176
 
177
+ private matchesExplicitFile(path: string): boolean {
178
+ if (this.context.request.plan.tool !== "grep") return true;
179
+ const { include, exclude } = this.context.request.plan.walk;
180
+ if (include.length === 0 && exclude.length === 0) return true;
181
+ const matches = (pattern: { readonly glob: string }) => matchPathSuffix(pattern.glob, path);
182
+ if (include.length > 0 && !include.some(matches)) return false;
183
+ return !exclude.some(matches);
184
+ }
185
+
137
186
  private openWalk(path: string, handle: number): void {
138
187
  try {
139
188
  const original = this.context.fs.walkOpen(handle, this.context.request.plan.walk);
@@ -24,16 +24,27 @@ import { rootedSymlinkStorageCase } from "./fixtures/rooted-symlinks-storage.js"
24
24
  import { fileTimesStorageCase } from "./fixtures/file-times-storage.js";
25
25
  import { withVfsImplementation, type VfsImplementation } from "../fs/vfs-internal.js";
26
26
  /** Real browser storage tests. Shared contract cases run unchanged against both backends. */
27
- import { createRuntime, VfsError, type RuntimeStartupStage } from "../index.js";
27
+ import {
28
+ createRuntime,
29
+ deleteWorkspace,
30
+ openIdleWorkspace,
31
+ VfsError,
32
+ type RuntimeStartupStage,
33
+ } from "../index.js";
28
34
  import {
29
35
  FilesystemClient,
30
36
  FilesystemService,
31
37
  PersistentBackend,
32
38
  createFilesystemConnection,
33
39
  } from "../fs/index.js";
40
+ import { existingDatabase } from "../fs/idle-database.js";
34
41
  import { INDEXEDDB_FORMAT } from "../fs/vfs-format.js";
35
42
  import { CHUNK_SIZE } from "../fs/indexeddb-chunks.js";
36
- import { IndexedDBStorage } from "../fs/indexeddb.js";
43
+ import {
44
+ IndexedDBStorage,
45
+ IndexedDBStorageBusyError,
46
+ IndexedDBStorageMissingError,
47
+ } from "../fs/indexeddb.js";
37
48
  import { FilesystemError, PAGE } from "../fs/protocol.js";
38
49
  import { gatedIndexedDB } from "./gated-indexeddb.js";
39
50
  import { assertRuntimeStartupTrace } from "./runtime-startup-proof.js";
@@ -1918,6 +1929,166 @@ function indexedDBCases(
1918
1929
  );
1919
1930
  });
1920
1931
 
1932
+ test("open with createIfMissing false rejects absent database without creating it", async (name) => {
1933
+ const assertAbsent = async (phase: string) => {
1934
+ const existing = await existingDatabase(name);
1935
+ existing?.close();
1936
+ assert(existing === undefined, `${phase}: database must remain absent`);
1937
+ if (typeof indexedDB.databases === "function") {
1938
+ const names = (await indexedDB.databases()).map((entry) => entry.name);
1939
+ assert(!names.includes(name), `${phase}: indexedDB.databases() must not list ${name}`);
1940
+ }
1941
+ };
1942
+ await assertAbsent("initial");
1943
+ let openError: unknown;
1944
+ try {
1945
+ await IndexedDBStorage.open(name, { createIfMissing: false });
1946
+ } catch (error) {
1947
+ openError = error;
1948
+ }
1949
+ assert(
1950
+ openError instanceof IndexedDBStorageMissingError &&
1951
+ openError.name === "IndexedDBStorageMissingError",
1952
+ `expected IndexedDBStorageMissingError from open, got ${String(openError)}`,
1953
+ );
1954
+ await assertAbsent("after open");
1955
+
1956
+ let committedError: unknown;
1957
+ try {
1958
+ await IndexedDBStorage.openCommitted(name, { createIfMissing: false });
1959
+ } catch (error) {
1960
+ committedError = error;
1961
+ }
1962
+ assert(
1963
+ committedError instanceof IndexedDBStorageMissingError,
1964
+ `expected IndexedDBStorageMissingError from openCommitted, got ${String(committedError)}`,
1965
+ );
1966
+ await assertAbsent("after openCommitted");
1967
+ assert(
1968
+ (await deleteWorkspace({ mode: "fast", name })) === "missing",
1969
+ "maintenance lock must already be released after missing rejection",
1970
+ );
1971
+ });
1972
+
1973
+ test("open with createIfMissing false opens existing workspace for writes and respects busy locks", async (name, open) => {
1974
+ const initial = await open();
1975
+ await initial.persist(batch(1));
1976
+ await initial.close();
1977
+
1978
+ const writable = await IndexedDBStorage.open(name, { createIfMissing: false });
1979
+ try {
1980
+ assert((await writable.load())?.generation === 1, "existing generation 1 loaded");
1981
+ let busyError: unknown;
1982
+ try {
1983
+ await IndexedDBStorage.open(name, { createIfMissing: false, whenBusy: "ifAvailable" });
1984
+ } catch (error) {
1985
+ busyError = error;
1986
+ }
1987
+ assert(
1988
+ busyError instanceof IndexedDBStorageBusyError,
1989
+ `expected IndexedDBStorageBusyError while writer holds lock, got ${String(busyError)}`,
1990
+ );
1991
+ await writable.persist(batch(2));
1992
+ } finally {
1993
+ await writable.close();
1994
+ }
1995
+
1996
+ const reopened = await IndexedDBStorage.open(name, { createIfMissing: false });
1997
+ try {
1998
+ assert((await reopened.load())?.generation === 2, "persisted generation 2 recovered");
1999
+ } finally {
2000
+ await reopened.close();
2001
+ }
2002
+
2003
+ const committedName = `${name}-committed`;
2004
+ await allocation?.allocate({ kind: "indexeddb", name: committedName });
2005
+ try {
2006
+ const seeded = await IndexedDBStorage.openCommitted(committedName);
2007
+ await seeded.close();
2008
+ const committed = await IndexedDBStorage.openCommitted(committedName, {
2009
+ createIfMissing: false,
2010
+ });
2011
+ try {
2012
+ assert(
2013
+ (await committed.recoverCommitted()).index === undefined,
2014
+ "existing committed database opens cleanly",
2015
+ );
2016
+ } finally {
2017
+ await committed.close();
2018
+ }
2019
+ } finally {
2020
+ await request(indexedDB.deleteDatabase(committedName));
2021
+ }
2022
+ });
2023
+
2024
+ test("delete-vs-open race with createIfMissing false never recreates an absent database", async (name, open) => {
2025
+ const seed = await open();
2026
+ await seed.persist(batch(1));
2027
+ await seed.close();
2028
+
2029
+ const idle = await openIdleWorkspace({ mode: "fast", name });
2030
+ assert(typeof idle !== "string", `expected idle handle, got ${String(idle)}`);
2031
+ const waiting = Promise.withResolvers<void>();
2032
+ const queuedOpen = IndexedDBStorage.open(name, {
2033
+ createIfMissing: false,
2034
+ onWaiting: () => waiting.resolve(),
2035
+ });
2036
+ await waiting.promise;
2037
+ await idle.delete();
2038
+ let queuedError: unknown;
2039
+ try {
2040
+ const storage = await queuedOpen;
2041
+ await storage.close();
2042
+ } catch (error) {
2043
+ queuedError = error;
2044
+ }
2045
+ assert(
2046
+ queuedError instanceof IndexedDBStorageMissingError,
2047
+ `queued existing-only open after idle.delete() must throw IndexedDBStorageMissingError, got ${String(queuedError)}`,
2048
+ );
2049
+ const afterIdleDelete = await existingDatabase(name);
2050
+ afterIdleDelete?.close();
2051
+ assert(afterIdleDelete === undefined, "idle.delete() race must not recreate database");
2052
+
2053
+ for (let round = 0; round < 10; round++) {
2054
+ const target = `${name}-race-${round}`;
2055
+ await allocation?.allocate({ kind: "indexeddb", name: target });
2056
+ const writer = await IndexedDBStorage.open(target, { compactEvery: 2 });
2057
+ await writer.persist(batch(1));
2058
+ await writer.close();
2059
+ const [deleteOutcome, openOutcome] = await Promise.allSettled([
2060
+ deleteWorkspace({ mode: "fast", name: target }),
2061
+ IndexedDBStorage.open(target, { createIfMissing: false }),
2062
+ ]);
2063
+ assert(deleteOutcome.status === "fulfilled", `round ${round}: deleteWorkspace must fulfill`);
2064
+ if (deleteOutcome.value === "deleted") {
2065
+ assert(
2066
+ openOutcome.status === "rejected" &&
2067
+ openOutcome.reason instanceof IndexedDBStorageMissingError,
2068
+ `round ${round}: open after delete must reject with IndexedDBStorageMissingError`,
2069
+ );
2070
+ const probe = await existingDatabase(target);
2071
+ probe?.close();
2072
+ assert(probe === undefined, `round ${round}: deleted database must never be recreated`);
2073
+ continue;
2074
+ }
2075
+ assert(deleteOutcome.value === "busy", `round ${round}: unexpected delete outcome`);
2076
+ assert(openOutcome.status === "fulfilled", `round ${round}: winning open must fulfill`);
2077
+ try {
2078
+ assert(
2079
+ (await openOutcome.value.load())?.generation === 1,
2080
+ `round ${round}: winning open reads existing workspace`,
2081
+ );
2082
+ } finally {
2083
+ await openOutcome.value.close();
2084
+ }
2085
+ assert(
2086
+ (await deleteWorkspace({ mode: "fast", name: target })) === "deleted",
2087
+ `round ${round}: cleanup delete`,
2088
+ );
2089
+ }
2090
+ });
2091
+
1921
2092
  return cases;
1922
2093
  }
1923
2094
 
@@ -1 +1 @@
1
- {"commit":"b2cbaa1b6b80ccf3d082d6cb6af8075e2b607006","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
1
+ {"commit":"009023cdfec2eef3e9e0502ad18609021dc86dd3","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}