@softistx/s3 0.0.0-stage → 0.13.2

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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +609 -2
  3. package/dist/bucket/bind-bucket.d.ts +42 -0
  4. package/dist/bucket/bind-bucket.d.ts.map +1 -0
  5. package/dist/bucket/bound-bucket.d.ts +119 -0
  6. package/dist/bucket/bound-bucket.d.ts.map +1 -0
  7. package/dist/bucket/context.d.ts +55 -0
  8. package/dist/bucket/context.d.ts.map +1 -0
  9. package/dist/bucket/define-bucket.d.ts +16 -0
  10. package/dist/bucket/define-bucket.d.ts.map +1 -0
  11. package/dist/bucket/disposition.d.ts +9 -0
  12. package/dist/bucket/disposition.d.ts.map +1 -0
  13. package/dist/bucket/guards.d.ts +38 -0
  14. package/dist/bucket/guards.d.ts.map +1 -0
  15. package/dist/bucket/operations/counted-stream.d.ts +26 -0
  16. package/dist/bucket/operations/counted-stream.d.ts.map +1 -0
  17. package/dist/bucket/operations/deadline.d.ts +21 -0
  18. package/dist/bucket/operations/deadline.d.ts.map +1 -0
  19. package/dist/bucket/operations/fetch-object.d.ts +68 -0
  20. package/dist/bucket/operations/fetch-object.d.ts.map +1 -0
  21. package/dist/bucket/operations/list-xml.d.ts +18 -0
  22. package/dist/bucket/operations/list-xml.d.ts.map +1 -0
  23. package/dist/bucket/operations/list.d.ts +12 -0
  24. package/dist/bucket/operations/list.d.ts.map +1 -0
  25. package/dist/bucket/operations/open-answer.d.ts +5 -0
  26. package/dist/bucket/operations/open-answer.d.ts.map +1 -0
  27. package/dist/bucket/operations/open-range.d.ts +10 -0
  28. package/dist/bucket/operations/open-range.d.ts.map +1 -0
  29. package/dist/bucket/operations/open-relay.d.ts +8 -0
  30. package/dist/bucket/operations/open-relay.d.ts.map +1 -0
  31. package/dist/bucket/operations/open.d.ts +4 -0
  32. package/dist/bucket/operations/open.d.ts.map +1 -0
  33. package/dist/bucket/operations/post-policy.d.ts +77 -0
  34. package/dist/bucket/operations/post-policy.d.ts.map +1 -0
  35. package/dist/bucket/operations/post-signer.d.ts +21 -0
  36. package/dist/bucket/operations/post-signer.d.ts.map +1 -0
  37. package/dist/bucket/operations/presign-post.d.ts +44 -0
  38. package/dist/bucket/operations/presign-post.d.ts.map +1 -0
  39. package/dist/bucket/operations/presign.d.ts +34 -0
  40. package/dist/bucket/operations/presign.d.ts.map +1 -0
  41. package/dist/bucket/operations/put-body.d.ts +13 -0
  42. package/dist/bucket/operations/put-body.d.ts.map +1 -0
  43. package/dist/bucket/operations/query-sign.d.ts +15 -0
  44. package/dist/bucket/operations/query-sign.d.ts.map +1 -0
  45. package/dist/bucket/operations/reads.d.ts +8 -0
  46. package/dist/bucket/operations/reads.d.ts.map +1 -0
  47. package/dist/bucket/operations/sized-body.d.ts +24 -0
  48. package/dist/bucket/operations/sized-body.d.ts.map +1 -0
  49. package/dist/bucket/operations/slice.d.ts +4 -0
  50. package/dist/bucket/operations/slice.d.ts.map +1 -0
  51. package/dist/bucket/operations/writes.d.ts +10 -0
  52. package/dist/bucket/operations/writes.d.ts.map +1 -0
  53. package/dist/bucket/shape.d.ts +6 -0
  54. package/dist/bucket/shape.d.ts.map +1 -0
  55. package/dist/bucket/types.d.ts +164 -0
  56. package/dist/bucket/types.d.ts.map +1 -0
  57. package/dist/chunks/index-jgjey570.js +118 -0
  58. package/dist/chunks/index-jgjey570.js.map +13 -0
  59. package/dist/errors/is-bucket-unavailable.d.ts +18 -0
  60. package/dist/errors/is-bucket-unavailable.d.ts.map +1 -0
  61. package/dist/errors/s3-error.d.ts +80 -0
  62. package/dist/errors/s3-error.d.ts.map +1 -0
  63. package/dist/index.d.ts +8 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +1288 -0
  66. package/dist/index.js.map +32 -0
  67. package/dist/testing/fetch-archive.d.ts +8 -0
  68. package/dist/testing/fetch-archive.d.ts.map +1 -0
  69. package/dist/testing/index.d.ts +6 -0
  70. package/dist/testing/index.d.ts.map +1 -0
  71. package/dist/testing/index.js +416 -0
  72. package/dist/testing/index.js.map +16 -0
  73. package/dist/testing/ports.d.ts +15 -0
  74. package/dist/testing/ports.d.ts.map +1 -0
  75. package/dist/testing/ready.d.ts +49 -0
  76. package/dist/testing/ready.d.ts.map +1 -0
  77. package/dist/testing/reaper.d.ts +4 -0
  78. package/dist/testing/reaper.d.ts.map +1 -0
  79. package/dist/testing/seaweedfs.d.ts +64 -0
  80. package/dist/testing/seaweedfs.d.ts.map +1 -0
  81. package/dist/testing/test-s3.d.ts +35 -0
  82. package/dist/testing/test-s3.d.ts.map +1 -0
  83. package/dist/testing/weed.d.ts +17 -0
  84. package/dist/testing/weed.d.ts.map +1 -0
  85. package/docs/README.md +17 -0
  86. package/docs/guide/buckets.md +220 -0
  87. package/docs/guide/presigned-urls.md +403 -0
  88. package/docs/guide/reads.md +417 -0
  89. package/docs/guide/testing.md +151 -0
  90. package/docs/guide/writes.md +374 -0
  91. package/docs/roadmap.md +116 -0
  92. package/docs/troubleshooting.md +982 -0
  93. package/package.json +61 -5
@@ -0,0 +1,416 @@
1
+ import {
2
+ S3Error2,
3
+ checkTimeout
4
+ } from "../chunks/index-jgjey570.js";
5
+
6
+ // src/testing/seaweedfs.ts
7
+ import { chmod, mkdir, rename, rm } from "node:fs/promises";
8
+ import { homedir } from "node:os";
9
+ import { dirname, isAbsolute, join } from "node:path";
10
+ import { $, CryptoHasher } from "bun";
11
+
12
+ // src/testing/fetch-archive.ts
13
+ class TransientDownloadError extends Error {
14
+ }
15
+ async function fetchArchive(url, fetcher) {
16
+ let response;
17
+ let bytes;
18
+ try {
19
+ response = await fetcher(url);
20
+ if (response.ok)
21
+ bytes = new Uint8Array(await response.arrayBuffer());
22
+ } catch (cause) {
23
+ throw new TransientDownloadError(`GET ${url} failed: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
24
+ }
25
+ if (!response.ok || !bytes) {
26
+ const message = `GET ${url} answered ${response.status}`;
27
+ if (response.status >= 500 || response.status === 429) {
28
+ throw new TransientDownloadError(message);
29
+ }
30
+ throw new Error(message);
31
+ }
32
+ return bytes;
33
+ }
34
+ async function fetchWithRetry(url, deps) {
35
+ const attempts = Math.max(1, Math.floor(deps.attempts ?? 4) || 1);
36
+ const delay = deps.delay ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
37
+ for (let attempt = 1;; attempt++) {
38
+ try {
39
+ return await fetchArchive(url, deps.fetch ?? fetch);
40
+ } catch (error) {
41
+ if (!(error instanceof TransientDownloadError) || attempt >= attempts) {
42
+ throw error;
43
+ }
44
+ await delay(500 * 2 ** (attempt - 1));
45
+ }
46
+ }
47
+ }
48
+
49
+ // src/testing/seaweedfs.ts
50
+ var TEST_SEAWEEDFS_VERSION = "4.47";
51
+ var TEST_SEAWEEDFS_SHA256 = {
52
+ "darwin_amd64.tar.gz": "45475223d51b78efb413cb7a29c005c7e9e0cc3f0dfe13d10413e7f85c479b6a",
53
+ "darwin_arm64.tar.gz": "3ad466db33e83d0b103f90a06997feeb1cc42fd536e6cbdcdded975778f64fda",
54
+ "freebsd_amd64.tar.gz": "5a8595de1ccf6f459457b46334ddd4d4acb0d9b09d6bcea1e4b6e3d0c3e05053",
55
+ "freebsd_arm.tar.gz": "5aa419209657396380102e8d11f2d66aadb40a1aeb1f224f908b4c4aea3685d1",
56
+ "freebsd_arm64.tar.gz": "08ddd46893384d9805c3a7ade74ce89a32d3c07104c717a73e456284e3511130",
57
+ "linux_amd64.tar.gz": "31fb804858885f9e7f18b6d3b1da09e824baac3e6a55b5a62c3c4c77e6ed6d7d",
58
+ "linux_arm.tar.gz": "ac302e29ea7d6f23b4ccd74462d49161970d3205a5af58caab9d023a854b3357",
59
+ "linux_arm64.tar.gz": "ba5c9def9ff98f78becdf309a50a9f906922f6383a7c4c772d01ede3cc012e16",
60
+ "openbsd_amd64.tar.gz": "8414bedaf0d3868e7901906751b91170956fea15d0e1667fb542fc05f3d59ec4",
61
+ "openbsd_arm.tar.gz": "83e5bc7a861846d35d8ac9045e7fcbc82160c804689965a295e819e8cf66e7bf",
62
+ "openbsd_arm64.tar.gz": "607333bf22c5b6945300fcea5d985ec32f5349f936eb3221b963fb72df13e9d1"
63
+ };
64
+ function assetFor(platform, arch) {
65
+ const platforms = {
66
+ linux: "linux",
67
+ darwin: "darwin",
68
+ freebsd: "freebsd",
69
+ openbsd: "openbsd"
70
+ };
71
+ const arches = {
72
+ x64: "amd64",
73
+ arm64: "arm64",
74
+ arm: "arm"
75
+ };
76
+ const os = platforms[platform];
77
+ const cpu = arches[arch];
78
+ if (!os || !cpu || cpu === "arm" && os === "darwin") {
79
+ throw new Error(`No SeaweedFS binary for ${platform}/${arch}: install one and set ` + "WEED_BIN to its path.");
80
+ }
81
+ return `${os}_${cpu}.tar.gz`;
82
+ }
83
+ function verifyArchive(asset, bytes, expected = TEST_SEAWEEDFS_SHA256[asset]) {
84
+ if (!expected) {
85
+ throw new Error(`No pinned SHA-256 for SeaweedFS ${TEST_SEAWEEDFS_VERSION} ${asset}: ` + "refusing to run an unchecked download.");
86
+ }
87
+ const actual = new CryptoHasher("sha256").update(bytes).digest("hex");
88
+ if (actual !== expected) {
89
+ throw new Error(`SeaweedFS ${TEST_SEAWEEDFS_VERSION} ${asset} has SHA-256 ${actual}, ` + `expected ${expected}: refusing to run it.`);
90
+ }
91
+ }
92
+ function defaultCacheDir(env = process.env, home = homedir()) {
93
+ const xdg = env["XDG_CACHE_HOME"];
94
+ const base = xdg && isAbsolute(xdg) ? xdg : join(home, ".cache");
95
+ return join(base, "nxgt", "seaweedfs");
96
+ }
97
+ async function download(asset, target, deps = {}) {
98
+ const url = `https://github.com/seaweedfs/seaweedfs/releases/download/${TEST_SEAWEEDFS_VERSION}/${asset}`;
99
+ process.emitWarning(`Downloading SeaweedFS ${TEST_SEAWEEDFS_VERSION} (${asset}) into ${dirname(target)}`, { code: "NxgtS3Download" });
100
+ const bytes = await fetchWithRetry(url, deps);
101
+ verifyArchive(asset, bytes, deps.sha256 ?? TEST_SEAWEEDFS_SHA256[asset]);
102
+ await mkdir(dirname(target), { recursive: true });
103
+ const staging = `${target}.${process.pid}.part`;
104
+ const archive = `${staging}.tar.gz`;
105
+ try {
106
+ await Bun.write(archive, bytes);
107
+ await mkdir(staging, { recursive: true });
108
+ const untar = await $`tar xzf ${archive} -C ${staging}`.quiet().nothrow();
109
+ if (untar.exitCode !== 0) {
110
+ throw new Error(`unpacking ${asset} failed: ${untar.stderr.toString().trim()}`);
111
+ }
112
+ const unpacked = join(staging, "weed");
113
+ await chmod(unpacked, 493);
114
+ const ran = await $`${unpacked} version`.quiet().nothrow();
115
+ if (ran.exitCode !== 0) {
116
+ throw new Error(`the downloaded ${asset} does not run: ${ran.stderr.toString().trim()}`);
117
+ }
118
+ await rename(unpacked, target);
119
+ } finally {
120
+ await rm(archive, { force: true });
121
+ await rm(staging, { recursive: true, force: true });
122
+ }
123
+ }
124
+ async function seaweedfsBinary(options = {}) {
125
+ if (options.binary) {
126
+ if (!await Bun.file(options.binary).exists()) {
127
+ throw new Error(`binary is ${options.binary}, which does not exist`);
128
+ }
129
+ return options.binary;
130
+ }
131
+ const override = process.env["WEED_BIN"];
132
+ if (override) {
133
+ if (!await Bun.file(override).exists()) {
134
+ throw new Error(`WEED_BIN is ${override}, which does not exist`);
135
+ }
136
+ return override;
137
+ }
138
+ const cacheDir = options.cacheDir ?? defaultCacheDir();
139
+ const target = join(cacheDir, TEST_SEAWEEDFS_VERSION, "weed");
140
+ if (await Bun.file(target).exists())
141
+ return target;
142
+ await download(assetFor(process.platform, process.arch), target);
143
+ return target;
144
+ }
145
+ // src/testing/test-s3.ts
146
+ import { mkdir as mkdir2, mkdtemp, rm as rm2 } from "node:fs/promises";
147
+ import { tmpdir as tmpdir2 } from "node:os";
148
+ import { join as join3 } from "node:path";
149
+
150
+ // src/testing/ports.ts
151
+ import { createServer } from "node:net";
152
+ async function isFree(port) {
153
+ return new Promise((resolve) => {
154
+ const server = createServer();
155
+ server.unref();
156
+ server.on("error", () => resolve(false));
157
+ server.listen(port, "127.0.0.1", () => {
158
+ server.close(() => resolve(true));
159
+ });
160
+ });
161
+ }
162
+ var PORTS = 8;
163
+ var claimed = new Set;
164
+ function releasePorts(ports) {
165
+ for (const port of ports)
166
+ claimed.delete(port);
167
+ }
168
+ async function freePorts() {
169
+ for (let attempt = 0;attempt < 50; attempt++) {
170
+ const base = 20000 + Math.floor(Math.random() * 1e4);
171
+ const wanted = Array.from({ length: PORTS }, (_, i) => base + i);
172
+ if (wanted.some((port) => claimed.has(port)))
173
+ continue;
174
+ for (const port of wanted)
175
+ claimed.add(port);
176
+ const free = await Promise.all(wanted.map(isFree));
177
+ if (free.every(Boolean))
178
+ return wanted;
179
+ releasePorts(wanted);
180
+ }
181
+ throw new Error(`no free block of ${PORTS} consecutive ports`);
182
+ }
183
+
184
+ // src/testing/ready.ts
185
+ import { S3Client } from "bun";
186
+ async function within(timeoutMs, bucket, call, run) {
187
+ if (timeoutMs === undefined)
188
+ return run();
189
+ let timer;
190
+ const late = new Promise((_, reject) => {
191
+ timer = setTimeout(() => reject(new S3Error2("TIMEOUT", bucket, `${call} on "${bucket}": the test S3 server gave no answer in ${timeoutMs}ms; it is stuck`)), timeoutMs);
192
+ });
193
+ const work = run();
194
+ work.catch(() => {
195
+ return;
196
+ });
197
+ try {
198
+ return await Promise.race([work, late]);
199
+ } finally {
200
+ clearTimeout(timer);
201
+ }
202
+ }
203
+ function checkBucketName(name) {
204
+ if (!/^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/.test(name)) {
205
+ throw new TypeError(`createBucket: "${name.slice(0, 80)}" is not a bucket name S3 accepts: ` + "3 to 63 characters, lowercase letters, digits, dots and hyphens, " + "starting and ending with a letter or digit");
206
+ }
207
+ }
208
+ async function logTail(logPath) {
209
+ const said = await Bun.file(logPath).text().catch(() => "");
210
+ const interesting = said.split(`
211
+ `).filter((line) => /error|fatal|^F\d|refus|denied/i.test(line));
212
+ return (interesting.length > 0 ? interesting : said.split(`
213
+ `)).slice(-8).join(`
214
+ `);
215
+ }
216
+ async function createBucketOn(address, bucket, server, options = {}) {
217
+ checkBucketName(bucket);
218
+ const own = checkTimeout(bucket, options.timeoutMs, "createBucket");
219
+ const timeoutMs = own ?? 90000;
220
+ const scoped = new S3Client({ ...address, bucket });
221
+ const deadline = Date.now() + timeoutMs;
222
+ let dead = false;
223
+ server.exited.then(() => {
224
+ dead = true;
225
+ });
226
+ for (;; ) {
227
+ const ok = await within(own === undefined ? undefined : Math.max(1, deadline - Date.now()), bucket, "createBucket", () => scoped.write(".nxgt-ready", "ok").then(() => true).catch(() => false));
228
+ if (ok)
229
+ break;
230
+ if (own !== undefined && !dead && Date.now() > deadline) {
231
+ throw new S3Error2("TIMEOUT", bucket, `createBucket on "${bucket}": the test S3 server did not take a write in ${own}ms. Its log, ${server.logPath}, says:
232
+ ` + await logTail(server.logPath));
233
+ }
234
+ const failed = dead ? "SeaweedFS exited before it served S3" : Date.now() > deadline ? `SeaweedFS did not serve S3 on ${address.endpoint} in ${Math.round(timeoutMs / 1000)}s` : undefined;
235
+ if (failed) {
236
+ throw new Error(`${failed} (bucket "${bucket}"). Its log, ${server.logPath}, says:
237
+ ` + await logTail(server.logPath));
238
+ }
239
+ await Bun.sleep(250);
240
+ }
241
+ await scoped.delete(".nxgt-ready").catch(() => {
242
+ return;
243
+ });
244
+ }
245
+ async function emptyBucket(address, bucket, options = {}) {
246
+ const own = checkTimeout(bucket, options.timeoutMs, "reset");
247
+ const scoped = new S3Client({ ...address, bucket });
248
+ for (let page = 0;page < 1000; page++) {
249
+ const listed = await within(own, bucket, "reset (list)", () => scoped.list({ maxKeys: 1000 }));
250
+ const keys = (listed.contents ?? []).flatMap((found) => found.key ? [found.key] : []);
251
+ await within(own, bucket, "reset (delete)", () => Promise.all(keys.map((key) => scoped.delete(key))));
252
+ if (keys.length === 0 || !listed.isTruncated)
253
+ return;
254
+ }
255
+ }
256
+
257
+ // src/testing/reaper.ts
258
+ import { rmSync } from "node:fs";
259
+ var live = new Map;
260
+ var SIGNALS = { SIGINT: 2, SIGTERM: 15 };
261
+ function killAll() {
262
+ for (const [child, paths] of live) {
263
+ child.kill("SIGKILL");
264
+ for (const path of paths) {
265
+ try {
266
+ rmSync(path, { recursive: true, force: true });
267
+ } catch {}
268
+ }
269
+ }
270
+ }
271
+ var handlers = Object.fromEntries(Object.entries(SIGNALS).map(([name, number]) => [
272
+ name,
273
+ () => {
274
+ killAll();
275
+ if (process.listenerCount(name) === 1)
276
+ process.exit(128 + number);
277
+ }
278
+ ]));
279
+ function reapOnExit(child, paths) {
280
+ if (live.size === 0) {
281
+ process.on("exit", killAll);
282
+ for (const name of Object.keys(SIGNALS)) {
283
+ process.on(name, handlers[name]);
284
+ }
285
+ }
286
+ live.set(child, paths);
287
+ return () => {
288
+ live.delete(child);
289
+ if (live.size > 0)
290
+ return;
291
+ process.off("exit", killAll);
292
+ for (const name of Object.keys(SIGNALS)) {
293
+ process.off(name, handlers[name]);
294
+ }
295
+ };
296
+ }
297
+
298
+ // src/testing/weed.ts
299
+ import { tmpdir } from "node:os";
300
+ import { join as join2 } from "node:path";
301
+ var ACCESS_KEY_ID = "nxgt-test-key";
302
+ var SECRET_ACCESS_KEY = "nxgt-test-secret";
303
+ function identities() {
304
+ return JSON.stringify({
305
+ identities: [
306
+ {
307
+ name: "test",
308
+ credentials: [
309
+ { accessKey: ACCESS_KEY_ID, secretKey: SECRET_ACCESS_KEY }
310
+ ],
311
+ actions: ["Admin", "Read", "Write", "List", "Tagging"]
312
+ }
313
+ ]
314
+ });
315
+ }
316
+ function spawnWeed(binary, data, logDir, config, ports, log) {
317
+ const [s3Port, master, volume, filer] = ports;
318
+ const [s3Grpc, masterGrpc, volumeGrpc, filerGrpc] = ports.slice(4);
319
+ const child = Bun.spawn([
320
+ binary,
321
+ `-logdir=${logDir}`,
322
+ "server",
323
+ `-dir=${data}`,
324
+ "-s3",
325
+ `-s3.port=${s3Port}`,
326
+ `-s3.config=${config}`,
327
+ "-s3.port.iceberg=0",
328
+ "-s3.port.lance=0",
329
+ "-master.volumeSizeLimitMB=64",
330
+ "-volume.max=100",
331
+ `-master.port=${master}`,
332
+ `-volume.port=${volume}`,
333
+ `-filer.port=${filer}`,
334
+ `-s3.port.grpc=${s3Grpc}`,
335
+ `-master.port.grpc=${masterGrpc}`,
336
+ `-volume.port.grpc=${volumeGrpc}`,
337
+ `-filer.port.grpc=${filerGrpc}`,
338
+ "-ip=127.0.0.1"
339
+ ], { stdout: "ignore", stderr: log });
340
+ child.unref();
341
+ return child;
342
+ }
343
+ function socketsOf(ports) {
344
+ const folders = [...new Set(["/tmp", tmpdir()])];
345
+ return folders.flatMap((folder) => ["s3", "master", "volume", "filer"].flatMap((service, index) => [
346
+ join2(folder, `seaweedfs-${service}-${ports[index]}.sock`),
347
+ join2(folder, `seaweedfs-${service}-grpc-${ports[index + 4]}.sock`)
348
+ ]));
349
+ }
350
+
351
+ // src/testing/test-s3.ts
352
+ async function startTestS3(options = {}) {
353
+ const binary = await seaweedfsBinary(options);
354
+ const dir = await mkdtemp(join3(tmpdir2(), "nxgt-s3-"));
355
+ const ports = await freePorts();
356
+ const logPath = join3(dir, "weed.log");
357
+ let child;
358
+ try {
359
+ const data = join3(dir, "data");
360
+ await mkdir2(data, { recursive: true });
361
+ const config = join3(dir, "s3.json");
362
+ await Bun.write(config, identities());
363
+ child = spawnWeed(binary, data, dir, config, ports, Bun.file(logPath));
364
+ } catch (error) {
365
+ releasePorts(ports);
366
+ await rm2(dir, { recursive: true, force: true });
367
+ throw error;
368
+ }
369
+ const stop = makeStop(child, dir, ports);
370
+ const address = {
371
+ endpoint: `http://127.0.0.1:${ports[0]}`,
372
+ accessKeyId: ACCESS_KEY_ID,
373
+ secretAccessKey: SECRET_ACCESS_KEY,
374
+ region: "us-east-1",
375
+ virtualHostedStyle: false
376
+ };
377
+ const server = { logPath, exited: child.exited };
378
+ try {
379
+ await createBucketOn(address, "health", server);
380
+ } catch (error) {
381
+ await stop();
382
+ throw error;
383
+ }
384
+ return {
385
+ endpoint: address.endpoint,
386
+ accessKeyId: ACCESS_KEY_ID,
387
+ secretAccessKey: SECRET_ACCESS_KEY,
388
+ region: address.region,
389
+ options: address,
390
+ createBucket: (name, options) => createBucketOn(address, name, server, options),
391
+ reset: (bucket, options) => emptyBucket(address, bucket, options),
392
+ stop
393
+ };
394
+ }
395
+ function makeStop(child, dir, ports) {
396
+ const unreap = reapOnExit(child, [dir, ...socketsOf(ports)]);
397
+ let stopped;
398
+ return () => {
399
+ stopped ??= (async () => {
400
+ unreap();
401
+ child.kill("SIGKILL");
402
+ await child.exited;
403
+ await rm2(dir, { recursive: true, force: true });
404
+ await Promise.all(socketsOf(ports).map((socket) => rm2(socket, { force: true })));
405
+ })().finally(() => releasePorts(ports));
406
+ return stopped;
407
+ };
408
+ }
409
+ export {
410
+ TEST_SEAWEEDFS_VERSION,
411
+ seaweedfsBinary,
412
+ startTestS3
413
+ };
414
+
415
+ //# debugId=6F61AF16CC89427164756E2164756E21
416
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,16 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/testing/seaweedfs.ts", "../src/testing/fetch-archive.ts", "../src/testing/test-s3.ts", "../src/testing/ports.ts", "../src/testing/ready.ts", "../src/testing/reaper.ts", "../src/testing/weed.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The SeaweedFS `weed` binary `@softistx/s3/testing` starts: where it comes from,\n * and how it is checked.\n *\n * SeaweedFS is the server because **MinIO no longer is** — measured on\n * 2026-09-18, `dl.min.io` answers `410 Gone` and the latest GitHub release\n * carries no binary at all. SeaweedFS publishes one per platform, and\n * `weed server -s3` serves the S3 API that `Bun.S3Client` talks to.\n *\n * The binary is, in order: the `binary` option, `$WEED_BIN`, the cached one,\n * or one downloaded now into the cache and checked against the SHA-256 pinned\n * below. A download that does not match is refused and never cached.\n */\n\nimport { chmod, mkdir, rename, rm } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, isAbsolute, join } from 'node:path';\nimport { $, CryptoHasher } from 'bun';\nimport { fetchWithRetry } from './fetch-archive';\n\n/** The SeaweedFS release the test server runs: the one place it is pinned. */\nexport const TEST_SEAWEEDFS_VERSION = '4.47';\n\n/**\n * The SHA-256 of each release asset of `TEST_SEAWEEDFS_VERSION`, computed from\n * the downloaded assets (and equal to the digest GitHub shows for them).\n * Raise the version and this table together.\n */\nexport const TEST_SEAWEEDFS_SHA256: Readonly<Record<string, string>> = {\n\t'darwin_amd64.tar.gz':\n\t\t'45475223d51b78efb413cb7a29c005c7e9e0cc3f0dfe13d10413e7f85c479b6a',\n\t'darwin_arm64.tar.gz':\n\t\t'3ad466db33e83d0b103f90a06997feeb1cc42fd536e6cbdcdded975778f64fda',\n\t'freebsd_amd64.tar.gz':\n\t\t'5a8595de1ccf6f459457b46334ddd4d4acb0d9b09d6bcea1e4b6e3d0c3e05053',\n\t'freebsd_arm.tar.gz':\n\t\t'5aa419209657396380102e8d11f2d66aadb40a1aeb1f224f908b4c4aea3685d1',\n\t'freebsd_arm64.tar.gz':\n\t\t'08ddd46893384d9805c3a7ade74ce89a32d3c07104c717a73e456284e3511130',\n\t'linux_amd64.tar.gz':\n\t\t'31fb804858885f9e7f18b6d3b1da09e824baac3e6a55b5a62c3c4c77e6ed6d7d',\n\t'linux_arm.tar.gz':\n\t\t'ac302e29ea7d6f23b4ccd74462d49161970d3205a5af58caab9d023a854b3357',\n\t'linux_arm64.tar.gz':\n\t\t'ba5c9def9ff98f78becdf309a50a9f906922f6383a7c4c772d01ede3cc012e16',\n\t'openbsd_amd64.tar.gz':\n\t\t'8414bedaf0d3868e7901906751b91170956fea15d0e1667fb542fc05f3d59ec4',\n\t'openbsd_arm.tar.gz':\n\t\t'83e5bc7a861846d35d8ac9045e7fcbc82160c804689965a295e819e8cf66e7bf',\n\t'openbsd_arm64.tar.gz':\n\t\t'607333bf22c5b6945300fcea5d985ec32f5349f936eb3221b963fb72df13e9d1',\n};\n\nexport interface SeaweedfsOptions {\n\t/** A `weed` binary to use. Wins over `$WEED_BIN` and the cache. */\n\tbinary?: string;\n\t/**\n\t * Where the download is cached; the binary lives in `<cacheDir>/<version>/weed`.\n\t * Defaults to `$XDG_CACHE_HOME/nxgt/seaweedfs`, else `~/.cache/nxgt/seaweedfs`.\n\t */\n\tcacheDir?: string;\n}\n\n/**\n * The release asset for a platform and an architecture, as `process.platform`\n * and `process.arch` name them. Throws for one the release does not ship.\n */\nexport function assetFor(platform: string, arch: string): string {\n\tconst platforms: Record<string, string> = {\n\t\tlinux: 'linux',\n\t\tdarwin: 'darwin',\n\t\tfreebsd: 'freebsd',\n\t\topenbsd: 'openbsd',\n\t};\n\tconst arches: Record<string, string> = {\n\t\tx64: 'amd64',\n\t\tarm64: 'arm64',\n\t\tarm: 'arm',\n\t};\n\tconst os = platforms[platform];\n\tconst cpu = arches[arch];\n\t// The release ships no darwin/arm and no `arm` outside linux and the BSDs.\n\tif (!os || !cpu || (cpu === 'arm' && os === 'darwin')) {\n\t\tthrow new Error(\n\t\t\t`No SeaweedFS binary for ${platform}/${arch}: install one and set ` +\n\t\t\t\t'WEED_BIN to its path.',\n\t\t);\n\t}\n\treturn `${os}_${cpu}.tar.gz`;\n}\n\n/**\n * Refuses an archive whose SHA-256 is not the pinned one. The message names\n * both, so a tampered download and a stale table read differently.\n */\nexport function verifyArchive(\n\tasset: string,\n\tbytes: Uint8Array,\n\texpected = TEST_SEAWEEDFS_SHA256[asset],\n): void {\n\tif (!expected) {\n\t\tthrow new Error(\n\t\t\t`No pinned SHA-256 for SeaweedFS ${TEST_SEAWEEDFS_VERSION} ${asset}: ` +\n\t\t\t\t'refusing to run an unchecked download.',\n\t\t);\n\t}\n\tconst actual = new CryptoHasher('sha256').update(bytes).digest('hex');\n\tif (actual !== expected) {\n\t\tthrow new Error(\n\t\t\t`SeaweedFS ${TEST_SEAWEEDFS_VERSION} ${asset} has SHA-256 ${actual}, ` +\n\t\t\t\t`expected ${expected}: refusing to run it.`,\n\t\t);\n\t}\n}\n\n/**\n * `$XDG_CACHE_HOME/nxgt/seaweedfs`, else `~/.cache/nxgt/seaweedfs`: a per-user\n * folder outside `node_modules`, so a clean install keeps the binary and every\n * repository on the machine shares one copy. A relative `$XDG_CACHE_HOME` is\n * ignored, as the XDG specification says.\n */\nexport function defaultCacheDir(\n\tenv: Record<string, string | undefined> = process.env,\n\thome: string = homedir(),\n): string {\n\tconst xdg = env['XDG_CACHE_HOME'];\n\tconst base = xdg && isAbsolute(xdg) ? xdg : join(home, '.cache');\n\treturn join(base, 'nxgt', 'seaweedfs');\n}\n\n/** What `download` takes from outside; the specs replace both. */\nexport interface DownloadDeps {\n\tfetch?: typeof fetch;\n\t/** The SHA-256 the archive must have. Defaults to the pinned one. */\n\tsha256?: string;\n\t/** Tries at fetching and reading the archive, the first included. Defaults to 4. */\n\tattempts?: number;\n\t/** Waits `ms` between two tries. Defaults to a timer; the specs pass a no-op. */\n\tdelay?: (ms: number) => Promise<void>;\n}\n\nexport async function download(\n\tasset: string,\n\ttarget: string,\n\tdeps: DownloadDeps = {},\n): Promise<void> {\n\tconst url = `https://github.com/seaweedfs/seaweedfs/releases/download/${TEST_SEAWEEDFS_VERSION}/${asset}`;\n\tprocess.emitWarning(\n\t\t`Downloading SeaweedFS ${TEST_SEAWEEDFS_VERSION} (${asset}) into ${dirname(target)}`,\n\t\t{ code: 'NxgtS3Download' },\n\t);\n\tconst bytes = await fetchWithRetry(url, deps);\n\tverifyArchive(asset, bytes, deps.sha256 ?? TEST_SEAWEEDFS_SHA256[asset]);\n\n\t// Unpacked into a directory of this process's own, then renamed: two runs\n\t// starting at once never see half a binary. The archive holds one file.\n\tawait mkdir(dirname(target), { recursive: true });\n\tconst staging = `${target}.${process.pid}.part`;\n\tconst archive = `${staging}.tar.gz`;\n\ttry {\n\t\tawait Bun.write(archive, bytes);\n\t\tawait mkdir(staging, { recursive: true });\n\t\tconst untar = await $`tar xzf ${archive} -C ${staging}`.quiet().nothrow();\n\t\tif (untar.exitCode !== 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`unpacking ${asset} failed: ${untar.stderr.toString().trim()}`,\n\t\t\t);\n\t\t}\n\t\tconst unpacked = join(staging, 'weed');\n\t\tawait chmod(unpacked, 0o755);\n\t\tconst ran = await $`${unpacked} version`.quiet().nothrow();\n\t\tif (ran.exitCode !== 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`the downloaded ${asset} does not run: ${ran.stderr.toString().trim()}`,\n\t\t\t);\n\t\t}\n\t\tawait rename(unpacked, target);\n\t} finally {\n\t\tawait rm(archive, { force: true });\n\t\tawait rm(staging, { recursive: true, force: true });\n\t}\n}\n\n/**\n * The path of a `weed` binary that runs: the `binary` option, `$WEED_BIN`, the\n * cached one, or one downloaded now and checked against its pinned SHA-256.\n */\nexport async function seaweedfsBinary(\n\toptions: SeaweedfsOptions = {},\n): Promise<string> {\n\tif (options.binary) {\n\t\tif (!(await Bun.file(options.binary).exists())) {\n\t\t\tthrow new Error(`binary is ${options.binary}, which does not exist`);\n\t\t}\n\t\treturn options.binary;\n\t}\n\tconst override = process.env['WEED_BIN'];\n\tif (override) {\n\t\tif (!(await Bun.file(override).exists())) {\n\t\t\tthrow new Error(`WEED_BIN is ${override}, which does not exist`);\n\t\t}\n\t\treturn override;\n\t}\n\n\tconst cacheDir = options.cacheDir ?? defaultCacheDir();\n\tconst target = join(cacheDir, TEST_SEAWEEDFS_VERSION, 'weed');\n\tif (await Bun.file(target).exists()) return target;\n\tawait download(assetFor(process.platform, process.arch), target);\n\treturn target;\n}\n",
6
+ "export interface FetchRetryOptions {\n\tfetch?: typeof fetch;\n\tattempts?: number;\n\tdelay?: (ms: number) => Promise<void>;\n}\n\n/** A failure worth another try: a network or body-read failure, a 5xx or a 429. */\nclass TransientDownloadError extends Error {}\n\nasync function fetchArchive(\n\turl: string,\n\tfetcher: typeof fetch,\n): Promise<Uint8Array> {\n\tlet response: Response;\n\tlet bytes: Uint8Array | undefined;\n\ttry {\n\t\tresponse = await fetcher(url);\n\t\tif (response.ok) bytes = new Uint8Array(await response.arrayBuffer());\n\t} catch (cause) {\n\t\tthrow new TransientDownloadError(\n\t\t\t`GET ${url} failed: ${cause instanceof Error ? cause.message : String(cause)}`,\n\t\t\t{ cause },\n\t\t);\n\t}\n\tif (!response.ok || !bytes) {\n\t\tconst message = `GET ${url} answered ${response.status}`;\n\t\tif (response.status >= 500 || response.status === 429) {\n\t\t\tthrow new TransientDownloadError(message);\n\t\t}\n\t\tthrow new Error(message);\n\t}\n\treturn bytes;\n}\n\n/** Fetches and reads the whole archive, retrying transient failures with a growing pause. */\nexport async function fetchWithRetry(\n\turl: string,\n\tdeps: FetchRetryOptions,\n): Promise<Uint8Array> {\n\tconst attempts = Math.max(1, Math.floor(deps.attempts ?? 4) || 1);\n\tconst delay =\n\t\tdeps.delay ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));\n\tfor (let attempt = 1; ; attempt++) {\n\t\ttry {\n\t\t\treturn await fetchArchive(url, deps.fetch ?? fetch);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof TransientDownloadError) || attempt >= attempts) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tawait delay(500 * 2 ** (attempt - 1));\n\t\t}\n\t}\n}\n",
7
+ "import { mkdir, mkdtemp, rm } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport type { Subprocess } from 'bun';\nimport { freePorts, releasePorts } from './ports';\nimport {\n\tcreateBucketOn,\n\ttype DeadlineOptions,\n\temptyBucket,\n\ttype ServerAddress,\n} from './ready';\nimport { reapOnExit } from './reaper';\nimport { type SeaweedfsOptions, seaweedfsBinary } from './seaweedfs';\nimport {\n\tACCESS_KEY_ID,\n\tidentities,\n\tSECRET_ACCESS_KEY,\n\tsocketsOf,\n\tspawnWeed,\n} from './weed';\n\nexport type TestS3Options = SeaweedfsOptions;\n\nexport interface TestS3 {\n\tendpoint: string;\n\taccessKeyId: string;\n\tsecretAccessKey: string;\n\tregion: string;\n\t/** Options ready for `bindBucket`, pointing at this server. */\n\toptions: ServerAddress;\n\t/**\n\t * Creates `name` and resolves once it takes writes. With `timeoutMs` a\n\t * server that is not ready in time fails with `S3Error` `TIMEOUT`; without\n\t * it the wait is 90 s.\n\t */\n\tcreateBucket(name: string, options?: DeadlineOptions): Promise<void>;\n\t/**\n\t * Empties a bucket, so each test starts from nothing. With `timeoutMs`, a\n\t * list or delete round that gets no answer in time fails with `S3Error`\n\t * `TIMEOUT`, instead of hanging until the test runner's hook timeout.\n\t */\n\treset(bucket: string, options?: DeadlineOptions): Promise<void>;\n\t/** Kills the server and removes its files. Calling it again does nothing. */\n\tstop(): Promise<void>;\n}\n\n/**\n * A real S3 API for a suite: SeaweedFS's own gateway, started by\n * `weed server -s3` on free ports, with no Docker. The first run downloads\n * the binary into the cache.\n *\n * A server nobody stops does not keep the process alive, and is killed when\n * the process exits or receives SIGINT or SIGTERM.\n */\nexport async function startTestS3(\n\toptions: TestS3Options = {},\n): Promise<TestS3> {\n\tconst binary = await seaweedfsBinary(options);\n\tconst dir = await mkdtemp(join(tmpdir(), 'nxgt-s3-'));\n\tconst ports = await freePorts();\n\n\tconst logPath = join(dir, 'weed.log');\n\tlet child: Subprocess;\n\ttry {\n\t\t// `weed` refuses to start when `-dir` is not there — it does not create\n\t\t// it, and says so only on stderr, which is why that is captured below.\n\t\tconst data = join(dir, 'data');\n\t\tawait mkdir(data, { recursive: true });\n\t\tconst config = join(dir, 's3.json');\n\t\tawait Bun.write(config, identities());\n\n\t\t// Its log goes to a file, not a pipe: SeaweedFS is chatty enough to fill\n\t\t// the 64 KB pipe buffer in well under a minute, and a pipe nobody drains\n\t\t// blocks the process that writes to it — measured, that is a server that\n\t\t// starts, serves briefly and then hangs.\n\t\tchild = spawnWeed(binary, data, dir, config, ports, Bun.file(logPath));\n\t} catch (error) {\n\t\treleasePorts(ports);\n\t\tawait rm(dir, { recursive: true, force: true });\n\t\tthrow error;\n\t}\n\tconst stop = makeStop(child, dir, ports);\n\n\tconst address: ServerAddress = {\n\t\tendpoint: `http://127.0.0.1:${ports[0]}`,\n\t\taccessKeyId: ACCESS_KEY_ID,\n\t\tsecretAccessKey: SECRET_ACCESS_KEY,\n\t\tregion: 'us-east-1',\n\t\tvirtualHostedStyle: false,\n\t};\n\tconst server = { logPath, exited: child.exited };\n\n\ttry {\n\t\tawait createBucketOn(address, 'health', server);\n\t} catch (error) {\n\t\tawait stop();\n\t\tthrow error;\n\t}\n\n\treturn {\n\t\tendpoint: address.endpoint,\n\t\taccessKeyId: ACCESS_KEY_ID,\n\t\tsecretAccessKey: SECRET_ACCESS_KEY,\n\t\tregion: address.region,\n\t\toptions: address,\n\t\tcreateBucket: (name, options) =>\n\t\t\tcreateBucketOn(address, name, server, options),\n\t\treset: (bucket, options) => emptyBucket(address, bucket, options),\n\t\tstop,\n\t};\n}\n\n/** `stop()`: kills the server, removes its files, and is safe to repeat. */\nfunction makeStop(\n\tchild: Subprocess,\n\tdir: string,\n\tports: number[],\n): () => Promise<void> {\n\tconst unreap = reapOnExit(child, [dir, ...socketsOf(ports)]);\n\tlet stopped: Promise<void> | undefined;\n\treturn () => {\n\t\tstopped ??= (async () => {\n\t\t\tunreap();\n\t\t\t// `SIGKILL`, not the default `SIGTERM`. Measured on SeaweedFS 4.47:\n\t\t\t// `weed server` takes **20 s** to exit on either SIGTERM or SIGINT —\n\t\t\t// 20078 / 20024 ms and 20015 / 20102 ms over two runs each — and\n\t\t\t// **11 ms** on SIGKILL. That is a fixed shutdown grace period, not a\n\t\t\t// flush: the directory it writes into is removed on the next line.\n\t\t\tchild.kill('SIGKILL');\n\t\t\tawait child.exited;\n\t\t\tawait rm(dir, { recursive: true, force: true });\n\t\t\t// `weed` leaves a unix socket per port it bound; a long-lived CI\n\t\t\t// runner would otherwise collect them.\n\t\t\tawait Promise.all(\n\t\t\t\tsocketsOf(ports).map((socket) => rm(socket, { force: true })),\n\t\t\t);\n\t\t})().finally(() => releasePorts(ports));\n\t\treturn stopped;\n\t};\n}\n",
8
+ "import { createServer } from 'node:net';\n\n/** Whether nothing listens on `port`, and nothing can be bound there. */\nasync function isFree(port: number): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst server = createServer();\n\t\tserver.unref();\n\t\tserver.on('error', () => resolve(false));\n\t\tserver.listen(port, '127.0.0.1', () => {\n\t\t\tserver.close(() => resolve(true));\n\t\t});\n\t});\n}\n\n/**\n * Eight consecutive free ports: one per service, plus one gRPC port each.\n *\n * Each SeaweedFS service listens twice, and left alone it derives the gRPC\n * port by adding 10000 — the filer even names a unix socket after it,\n * `/tmp/seaweedfs-filer-grpc-<port>.sock`. Measured, a run whose filer landed\n * on 42937 died with its gRPC socket missing, because something already held\n * 52937. `weed server` takes `-master.port.grpc` and the three others, so\n * every port it binds is named and verified rather than hoped for.\n */\nexport const PORTS = 8;\n\n/**\n * Blocks handed out by this process and not yet released. Probing alone is a\n * check-then-use race: two servers started together both probe before either\n * binds, so both can be told the same, or an overlapping, block (#277: the\n * second master died with `bind: address already in use` on a gRPC port).\n */\nconst claimed = new Set<number>();\n\n/** Gives a block back once its server is stopped. */\nexport function releasePorts(ports: number[]): void {\n\tfor (const port of ports) claimed.delete(port);\n}\n\nexport async function freePorts(): Promise<number[]> {\n\tfor (let attempt = 0; attempt < 50; attempt++) {\n\t\t// Below the ephemeral range the kernel hands out, so nothing is taken\n\t\t// from under the server mid-run.\n\t\tconst base = 20_000 + Math.floor(Math.random() * 10_000);\n\t\tconst wanted = Array.from({ length: PORTS }, (_, i) => base + i);\n\t\tif (wanted.some((port) => claimed.has(port))) continue;\n\t\t// Claimed before the first await, so a concurrent call sees it.\n\t\tfor (const port of wanted) claimed.add(port);\n\t\tconst free = await Promise.all(wanted.map(isFree));\n\t\tif (free.every(Boolean)) return wanted;\n\t\treleasePorts(wanted);\n\t}\n\tthrow new Error(`no free block of ${PORTS} consecutive ports`);\n}\n",
9
+ "import { S3Client } from 'bun';\nimport { checkTimeout } from '../bucket/operations/deadline';\nimport { S3Error } from '../errors/s3-error';\n\n/** The option both `createBucket` and `reset` take. */\nexport interface DeadlineOptions {\n\t/**\n\t * A deadline in whole milliseconds, 1 or more. A call that gets no answer\n\t * in time rejects with `S3Error` `TIMEOUT`. Without it, `reset` waits as\n\t * long as the server does and `createBucket` keeps its 90 s readiness wait.\n\t */\n\ttimeoutMs?: number | undefined;\n}\n\n/**\n * Settles with `run`, or rejects with `S3Error` `TIMEOUT` once `timeoutMs`\n * has passed. The timer is cleared whichever way it ends.\n */\nasync function within<T>(\n\ttimeoutMs: number | undefined,\n\tbucket: string,\n\tcall: string,\n\trun: () => Promise<T>,\n): Promise<T> {\n\tif (timeoutMs === undefined) return run();\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst late = new Promise<never>((_, reject) => {\n\t\ttimer = setTimeout(\n\t\t\t() =>\n\t\t\t\treject(\n\t\t\t\t\tnew S3Error(\n\t\t\t\t\t\t'TIMEOUT',\n\t\t\t\t\t\tbucket,\n\t\t\t\t\t\t`${call} on \"${bucket}\": the test S3 server gave no answer in ${timeoutMs}ms; it is stuck`,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\ttimeoutMs,\n\t\t);\n\t});\n\tconst work = run();\n\twork.catch(() => undefined);\n\ttry {\n\t\treturn await Promise.race([work, late]);\n\t} finally {\n\t\tclearTimeout(timer);\n\t}\n}\n\nexport interface ServerAddress {\n\tendpoint: string;\n\taccessKeyId: string;\n\tsecretAccessKey: string;\n\tregion: string;\n\tvirtualHostedStyle: false;\n}\n\n/**\n * S3's rules for a bucket name, which SeaweedFS enforces by refusing every\n * write: without this check `createBucket` would retry for the whole timeout.\n */\nexport function checkBucketName(name: string): void {\n\tif (!/^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/.test(name)) {\n\t\tthrow new TypeError(\n\t\t\t`createBucket: \"${name.slice(0, 80)}\" is not a bucket name S3 accepts: ` +\n\t\t\t\t'3 to 63 characters, lowercase letters, digits, dots and hyphens, ' +\n\t\t\t\t'starting and ending with a letter or digit',\n\t\t);\n\t}\n}\n\nexport interface ServerHandle {\n\tlogPath: string;\n\t/** Settles when the server process ends. */\n\texited: Promise<unknown>;\n}\n\n/** The interesting lines of the server's own log, or its last ones. */\nasync function logTail(logPath: string): Promise<string> {\n\t// Its own words, or the failure is unreadable: `weed` reports a bad\n\t// `-dir`, a taken port and a refused config all on stderr.\n\tconst said = await Bun.file(logPath)\n\t\t.text()\n\t\t.catch(() => '');\n\tconst interesting = said\n\t\t.split('\\n')\n\t\t.filter((line) => /error|fatal|^F\\d|refus|denied/i.test(line));\n\treturn (interesting.length > 0 ? interesting : said.split('\\n'))\n\t\t.slice(-8)\n\t\t.join('\\n');\n}\n\n/**\n * Creates `bucket` and waits until it takes writes.\n *\n * The gateway answers well before the filer behind it has registered, and a\n * write that lands in between fails with `InternalError`. Writing is the only\n * thing that proves it is ready — and it has to be **every** bucket, because\n * the readiness is per bucket: measured, a write to the first bucket succeeds\n * while a write to the second still fails for a moment. SeaweedFS creates a\n * bucket on that first write; `Bun.S3Client` has no `createBucket`, and\n * `presign('')` is refused (`ERR_S3_INVALID_PATH`), so there is nothing more\n * direct to call.\n *\n * A server that dies while this waits is reported at once, with its log.\n */\nexport async function createBucketOn(\n\taddress: ServerAddress,\n\tbucket: string,\n\tserver: ServerHandle,\n\toptions: DeadlineOptions = {},\n): Promise<void> {\n\tcheckBucketName(bucket);\n\tconst own = checkTimeout(bucket, options.timeoutMs, 'createBucket');\n\tconst timeoutMs = own ?? 90_000;\n\tconst scoped = new S3Client({ ...address, bucket });\n\tconst deadline = Date.now() + timeoutMs;\n\tlet dead = false;\n\tvoid server.exited.then(() => {\n\t\tdead = true;\n\t});\n\tfor (;;) {\n\t\tconst ok = await within(\n\t\t\town === undefined ? undefined : Math.max(1, deadline - Date.now()),\n\t\t\tbucket,\n\t\t\t'createBucket',\n\t\t\t() =>\n\t\t\t\tscoped\n\t\t\t\t\t.write('.nxgt-ready', 'ok')\n\t\t\t\t\t.then(() => true)\n\t\t\t\t\t.catch(() => false),\n\t\t);\n\t\tif (ok) break;\n\t\tif (own !== undefined && !dead && Date.now() > deadline) {\n\t\t\tthrow new S3Error(\n\t\t\t\t'TIMEOUT',\n\t\t\t\tbucket,\n\t\t\t\t`createBucket on \"${bucket}\": the test S3 server did not take a write in ${own}ms. Its log, ${server.logPath}, says:\\n` +\n\t\t\t\t\t(await logTail(server.logPath)),\n\t\t\t);\n\t\t}\n\t\tconst failed = dead\n\t\t\t? 'SeaweedFS exited before it served S3'\n\t\t\t: Date.now() > deadline\n\t\t\t\t? `SeaweedFS did not serve S3 on ${address.endpoint} in ${Math.round(timeoutMs / 1000)}s`\n\t\t\t\t: undefined;\n\t\tif (failed) {\n\t\t\tthrow new Error(\n\t\t\t\t`${failed} (bucket \"${bucket}\"). Its log, ${server.logPath}, says:\\n` +\n\t\t\t\t\t(await logTail(server.logPath)),\n\t\t\t);\n\t\t}\n\t\tawait Bun.sleep(250);\n\t}\n\tawait scoped.delete('.nxgt-ready').catch(() => undefined);\n}\n\n/**\n * Deletes every object of `bucket`, so a test starts from nothing. A failure\n * of the listing or of a delete (a bucket that was never created included) is\n * thrown, not hidden: a test must not run on objects a reset missed. With\n * `timeoutMs`, each list and delete round has that deadline (`TIMEOUT`).\n */\nexport async function emptyBucket(\n\taddress: ServerAddress,\n\tbucket: string,\n\toptions: DeadlineOptions = {},\n): Promise<void> {\n\tconst own = checkTimeout(bucket, options.timeoutMs, 'reset');\n\tconst scoped = new S3Client({ ...address, bucket });\n\tfor (let page = 0; page < 1000; page++) {\n\t\tconst listed = await within(own, bucket, 'reset (list)', () =>\n\t\t\tscoped.list({ maxKeys: 1000 }),\n\t\t);\n\t\tconst keys = (listed.contents ?? []).flatMap((found) =>\n\t\t\tfound.key ? [found.key] : [],\n\t\t);\n\t\tawait within(own, bucket, 'reset (delete)', () =>\n\t\t\tPromise.all(keys.map((key) => scoped.delete(key))),\n\t\t);\n\t\tif (keys.length === 0 || !listed.isTruncated) return;\n\t}\n}\n",
10
+ "import { rmSync } from 'node:fs';\nimport type { Subprocess } from 'bun';\n\n/**\n * Kills the servers a process forgot to stop.\n *\n * The child is unref'd, so a script that never calls `stop()` still ends on\n * its own; its `exit` event then kills the server. A signal is the other way\n * out: with the child's parent gone, `weed` would be orphaned. The handlers\n * kill every live server, and when this module is the only listener for the\n * signal they end the process the way the default would (`128 + n`), so\n * nothing is swallowed. A process with its own handler keeps its own policy.\n *\n * One set of handlers serves every server; the last `stop()` removes them.\n */\n/** Each live server, with the paths to remove once it is killed. */\nconst live = new Map<Subprocess, string[]>();\nconst SIGNALS = { SIGINT: 2, SIGTERM: 15 } as const;\n\nfunction killAll(): void {\n\t// Best effort, and synchronous: this runs in `exit`, where nothing async\n\t// does. The directory and the sockets go with the server.\n\tfor (const [child, paths] of live) {\n\t\tchild.kill('SIGKILL');\n\t\tfor (const path of paths) {\n\t\t\ttry {\n\t\t\t\trmSync(path, { recursive: true, force: true });\n\t\t\t} catch {\n\t\t\t\t// Leaving a temp file behind must not hide the original exit.\n\t\t\t}\n\t\t}\n\t}\n}\n\nconst handlers = Object.fromEntries(\n\tObject.entries(SIGNALS).map(([name, number]) => [\n\t\tname,\n\t\t() => {\n\t\t\tkillAll();\n\t\t\tif (process.listenerCount(name) === 1) process.exit(128 + number);\n\t\t},\n\t]),\n) as Record<keyof typeof SIGNALS, () => void>;\n\n/** Watches `child`; the function it returns stops watching. */\nexport function reapOnExit(child: Subprocess, paths: string[]): () => void {\n\tif (live.size === 0) {\n\t\tprocess.on('exit', killAll);\n\t\tfor (const name of Object.keys(SIGNALS) as (keyof typeof SIGNALS)[]) {\n\t\t\tprocess.on(name, handlers[name]);\n\t\t}\n\t}\n\tlive.set(child, paths);\n\treturn () => {\n\t\tlive.delete(child);\n\t\tif (live.size > 0) return;\n\t\tprocess.off('exit', killAll);\n\t\tfor (const name of Object.keys(SIGNALS) as (keyof typeof SIGNALS)[]) {\n\t\t\tprocess.off(name, handlers[name]);\n\t\t}\n\t};\n}\n",
11
+ "import { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport type { Subprocess } from 'bun';\n\n/** The credentials the server signs with. Local only, and never a real key. */\nexport const ACCESS_KEY_ID = 'nxgt-test-key';\nexport const SECRET_ACCESS_KEY = 'nxgt-test-secret';\n\n/**\n * Without an identities file there are no credentials, and every signed\n * request is refused.\n */\nexport function identities(): string {\n\treturn JSON.stringify({\n\t\tidentities: [\n\t\t\t{\n\t\t\t\tname: 'test',\n\t\t\t\tcredentials: [\n\t\t\t\t\t{ accessKey: ACCESS_KEY_ID, secretKey: SECRET_ACCESS_KEY },\n\t\t\t\t],\n\t\t\t\tactions: ['Admin', 'Read', 'Write', 'List', 'Tagging'],\n\t\t\t},\n\t\t],\n\t});\n}\n\n/**\n * `weed server -s3` on free ports. Each flag is a measured trap; see\n * AGENTS.md, Tests.\n */\nexport function spawnWeed(\n\tbinary: string,\n\tdata: string,\n\tlogDir: string,\n\tconfig: string,\n\tports: number[],\n\tlog: ReturnType<typeof Bun.file>,\n): Subprocess {\n\tconst [s3Port, master, volume, filer] = ports as [\n\t\tnumber,\n\t\tnumber,\n\t\tnumber,\n\t\tnumber,\n\t];\n\tconst [s3Grpc, masterGrpc, volumeGrpc, filerGrpc] = ports.slice(4) as [\n\t\tnumber,\n\t\tnumber,\n\t\tnumber,\n\t\tnumber,\n\t];\n\tconst child = Bun.spawn(\n\t\t[\n\t\t\tbinary,\n\t\t\t// A global flag, so it comes before the subcommand. Without it glog\n\t\t\t// writes `weed.<host>.<user>.log.*` and `weed.INFO` links into\n\t\t\t// `$TMPDIR`, outside the server's own directory, and `stop()` would\n\t\t\t// leave them there.\n\t\t\t`-logdir=${logDir}`,\n\t\t\t'server',\n\t\t\t`-dir=${data}`,\n\t\t\t'-s3',\n\t\t\t`-s3.port=${s3Port}`,\n\t\t\t`-s3.config=${config}`,\n\t\t\t// 4.47 starts two more listeners beside the S3 one, each on a\n\t\t\t// **fixed** port: an Iceberg REST Catalog on 8181 and a Lance\n\t\t\t// Namespace on 9101. Either one collides with a second server or a\n\t\t\t// leftover one and kills the whole process — `bind: address already\n\t\t\t// in use`, fatal, whatever the ports above were. Nothing uses them.\n\t\t\t'-s3.port.iceberg=0',\n\t\t\t'-s3.port.lance=0',\n\t\t\t// Each bucket is a *collection*, and a collection needs a volume of\n\t\t\t// its own. The defaults are a production shape — 8 volumes of 30 GB —\n\t\t\t// and on a normal disk the master then finds nothing it can\n\t\t\t// allocate: `No writable volumes and no free volumes left`. Small\n\t\t\t// volumes, and enough of them for a suite's buckets.\n\t\t\t'-master.volumeSizeLimitMB=64',\n\t\t\t'-volume.max=100',\n\t\t\t`-master.port=${master}`,\n\t\t\t`-volume.port=${volume}`,\n\t\t\t`-filer.port=${filer}`,\n\t\t\t`-s3.port.grpc=${s3Grpc}`,\n\t\t\t`-master.port.grpc=${masterGrpc}`,\n\t\t\t`-volume.port.grpc=${volumeGrpc}`,\n\t\t\t`-filer.port.grpc=${filerGrpc}`,\n\t\t\t'-ip=127.0.0.1',\n\t\t],\n\t\t{ stdout: 'ignore', stderr: log },\n\t);\n\t// A server nobody stopped must not keep the process alive: `reaper.ts`\n\t// kills it when the process ends.\n\tchild.unref();\n\treturn child;\n}\n\n/** The unix sockets `weed` leaves in the temp directory, one per port. */\nexport function socketsOf(ports: number[]): string[] {\n\t// Measured on macOS: `weed` names its sockets in a literal `/tmp`, whatever\n\t// `$TMPDIR` is, so both places are cleaned.\n\tconst folders = [...new Set(['/tmp', tmpdir()])];\n\treturn folders.flatMap((folder) =>\n\t\t['s3', 'master', 'volume', 'filer'].flatMap((service, index) => [\n\t\t\tjoin(folder, `seaweedfs-${service}-${ports[index]}.sock`),\n\t\t\tjoin(folder, `seaweedfs-${service}-grpc-${ports[index + 4]}.sock`),\n\t\t]),\n\t);\n}\n"
12
+ ],
13
+ "mappings": ";;;;;;AAcA;AACA;AACA;AACA;;;ACVA,MAAM,+BAA+B,MAAM;AAAC;AAE5C,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K,EAAE,IAAI,CAAC,WAAW,IAAG,QAAQ,EAAE,OAAO,KAAK,CAAC,CAAC,CAC7D;AAAA,OACE,EAAE,QAAQ,MAAM,aAAa,KAAK,CAAC;AAAA,IACtC,OAAO;AAAA;AAAA;",
14
+ "debugId": "6F61AF16CC89427164756E2164756E21",
15
+ "names": []
16
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Eight consecutive free ports: one per service, plus one gRPC port each.
3
+ *
4
+ * Each SeaweedFS service listens twice, and left alone it derives the gRPC
5
+ * port by adding 10000 — the filer even names a unix socket after it,
6
+ * `/tmp/seaweedfs-filer-grpc-<port>.sock`. Measured, a run whose filer landed
7
+ * on 42937 died with its gRPC socket missing, because something already held
8
+ * 52937. `weed server` takes `-master.port.grpc` and the three others, so
9
+ * every port it binds is named and verified rather than hoped for.
10
+ */
11
+ export declare const PORTS = 8;
12
+ /** Gives a block back once its server is stopped. */
13
+ export declare function releasePorts(ports: number[]): void;
14
+ export declare function freePorts(): Promise<number[]>;
15
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/testing/ports.ts"],"names":[],"mappings":"AAcA;;;;;;;;;GASG;AACH,eAAO,MAAM,KAAK,IAAI,CAAC;AAUvB,qDAAqD;AACrD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAElD;AAED,wBAAsB,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAcnD"}
@@ -0,0 +1,49 @@
1
+ /** The option both `createBucket` and `reset` take. */
2
+ export interface DeadlineOptions {
3
+ /**
4
+ * A deadline in whole milliseconds, 1 or more. A call that gets no answer
5
+ * in time rejects with `S3Error` `TIMEOUT`. Without it, `reset` waits as
6
+ * long as the server does and `createBucket` keeps its 90 s readiness wait.
7
+ */
8
+ timeoutMs?: number | undefined;
9
+ }
10
+ export interface ServerAddress {
11
+ endpoint: string;
12
+ accessKeyId: string;
13
+ secretAccessKey: string;
14
+ region: string;
15
+ virtualHostedStyle: false;
16
+ }
17
+ /**
18
+ * S3's rules for a bucket name, which SeaweedFS enforces by refusing every
19
+ * write: without this check `createBucket` would retry for the whole timeout.
20
+ */
21
+ export declare function checkBucketName(name: string): void;
22
+ export interface ServerHandle {
23
+ logPath: string;
24
+ /** Settles when the server process ends. */
25
+ exited: Promise<unknown>;
26
+ }
27
+ /**
28
+ * Creates `bucket` and waits until it takes writes.
29
+ *
30
+ * The gateway answers well before the filer behind it has registered, and a
31
+ * write that lands in between fails with `InternalError`. Writing is the only
32
+ * thing that proves it is ready — and it has to be **every** bucket, because
33
+ * the readiness is per bucket: measured, a write to the first bucket succeeds
34
+ * while a write to the second still fails for a moment. SeaweedFS creates a
35
+ * bucket on that first write; `Bun.S3Client` has no `createBucket`, and
36
+ * `presign('')` is refused (`ERR_S3_INVALID_PATH`), so there is nothing more
37
+ * direct to call.
38
+ *
39
+ * A server that dies while this waits is reported at once, with its log.
40
+ */
41
+ export declare function createBucketOn(address: ServerAddress, bucket: string, server: ServerHandle, options?: DeadlineOptions): Promise<void>;
42
+ /**
43
+ * Deletes every object of `bucket`, so a test starts from nothing. A failure
44
+ * of the listing or of a delete (a bucket that was never created included) is
45
+ * thrown, not hidden: a test must not run on objects a reset missed. With
46
+ * `timeoutMs`, each list and delete round has that deadline (`TIMEOUT`).
47
+ */
48
+ export declare function emptyBucket(address: ServerAddress, bucket: string, options?: DeadlineOptions): Promise<void>;
49
+ //# sourceMappingURL=ready.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ready.d.ts","sourceRoot":"","sources":["../../src/testing/ready.ts"],"names":[],"mappings":"AAIA,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC/B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B;AAoCD,MAAM,WAAW,aAAa;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,KAAK,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAQlD;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CACzB;AAiBD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CACnC,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,eAAoB,GAC3B,OAAO,CAAC,IAAI,CAAC,CA4Cf;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAChC,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,eAAoB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAef"}
@@ -0,0 +1,4 @@
1
+ import type { Subprocess } from 'bun';
2
+ /** Watches `child`; the function it returns stops watching. */
3
+ export declare function reapOnExit(child: Subprocess, paths: string[]): () => void;
4
+ //# sourceMappingURL=reaper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reaper.d.ts","sourceRoot":"","sources":["../../src/testing/reaper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AA2CtC,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAgBzE"}