@specific.dev/spectest 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ import type { ServiceSetupContext } from "../index.js";
2
+ export interface AwsOptions {
3
+ /**
4
+ * Lambda functions to deploy from the project's own source, keyed by
5
+ * function name — the name the app (or a state machine) invokes.
6
+ *
7
+ * ```ts
8
+ * lambdas: {
9
+ * add: { source: "lambda/add" },
10
+ * resize: { source: "lambda/resize", runtime: "python3.12", timeoutSecs: 60 },
11
+ * }
12
+ * ```
13
+ *
14
+ * Each is packaged and deployed during environment bring-up, so it is part
15
+ * of the warm-template snapshot: a warm start restores the deployed
16
+ * function instead of deploying it again.
17
+ */
18
+ lambdas?: Record<string, LambdaOptions>;
19
+ }
20
+ export interface LambdaOptions {
21
+ /**
22
+ * The function's code, as a path in your repository — either a directory
23
+ * (packaged whole, recursively, with its contents at the root of the
24
+ * package) or a single file. Relative paths resolve against the project
25
+ * root, so `"lambda/add"` is the repo's own `lambda/add/`.
26
+ *
27
+ * The code is taken from the repository on purpose: the function you test
28
+ * is the function you ship. Anything the handler imports at runtime —
29
+ * including its dependencies — must be inside this path, exactly as a real
30
+ * deployment package requires.
31
+ */
32
+ source: string;
33
+ /** Entry point, as AWS spells it: `<file>.<exported function>`. Default
34
+ * `"index.handler"`. */
35
+ handler?: string;
36
+ /** Lambda runtime identifier. Default `"nodejs20.x"`. */
37
+ runtime?: string;
38
+ /** Environment variables for the function. */
39
+ env?: Record<string, string>;
40
+ /** Function timeout in seconds. Default `30`. */
41
+ timeoutSecs?: number;
42
+ /** Execution-role ARN. Defaults to a fixed placeholder — the emulator does
43
+ * not enforce IAM. Set it only when the code reads the ARN itself. */
44
+ role?: string;
45
+ }
46
+ /**
47
+ * The AWS cloud APIs, emulated in the environment and answering at their real
48
+ * endpoints. Drop into `environment.services`:
49
+ *
50
+ * ```ts
51
+ * import { aws } from "@specific.dev/spectest/components";
52
+ *
53
+ * services: {
54
+ * aws: aws({
55
+ * lambdas: {
56
+ * add: { source: "lambda/add" },
57
+ * subtract: { source: "lambda/subtract" },
58
+ * },
59
+ * }),
60
+ * app: {
61
+ * image: { type: "dockerfile", content: appDockerfile },
62
+ * // Whatever the app already reads in production. An AWS SDK needs a
63
+ * // region and credentials; the emulator accepts any credential value.
64
+ * env: {
65
+ * AWS_REGION: "us-east-1",
66
+ * AWS_ACCESS_KEY_ID: "test",
67
+ * AWS_SECRET_ACCESS_KEY: "test",
68
+ * },
69
+ * dependsOn: ["aws"],
70
+ * },
71
+ * }
72
+ * ```
73
+ *
74
+ * The app keeps its production configuration — `new SFNClient({})`, no
75
+ * endpoint — because the component owns DNS and TLS for the AWS domains. It
76
+ * answers for **every region**, so an app that talks to two of them, or that
77
+ * reads its region from configuration, needs nothing declared here.
78
+ *
79
+ * Tests reach the same cloud with the AWS CLI, which the emulator's image
80
+ * ships as `awslocal` (the CLI, already pointed at it):
81
+ *
82
+ * ```ts
83
+ * const listed = await ctx.exec("aws", "awslocal stepfunctions list-state-machines");
84
+ * expect(listed.exitCode).toBe(0);
85
+ * const machines = listed.stdout.transform("machines", (out) =>
86
+ * (JSON.parse(out) as { stateMachines: unknown[] }).stateMachines,
87
+ * );
88
+ * expect(machines).toHaveLength(1);
89
+ * ```
90
+ *
91
+ * For S3, prefer the `s3()` component and give it the endpoint your app uses
92
+ * (`s3({ hosts: ["s3.us-east-1.amazonaws.com"] })`). An exact hostname always
93
+ * beats this component's wildcard, so the two compose without further
94
+ * configuration.
95
+ */
96
+ export declare function aws(opts?: AwsOptions): {
97
+ setup?: (({ name, projectRoot }: ServiceSetupContext) => Promise<void>) | undefined;
98
+ image: {
99
+ type: "registry";
100
+ reference: string;
101
+ };
102
+ env: {
103
+ AWS_DEFAULT_REGION: string;
104
+ };
105
+ ports: number[];
106
+ readyCheck: {
107
+ type: "http";
108
+ port: number;
109
+ path: string;
110
+ timeoutSecs: number;
111
+ };
112
+ };
@@ -0,0 +1,397 @@
1
+ // `aws()` — the AWS cloud APIs, emulated inside the environment, answering
2
+ // at their **real** endpoints.
3
+ //
4
+ // The component runs one emulator container and claims the AWS domains for
5
+ // it: DNS, a leaf certificate minted from the in-VM root CA, and a
6
+ // TLS-terminating reverse proxy. An AWS SDK in the app under test therefore
7
+ // resolves `https://states.us-east-1.amazonaws.com` the way it does in
8
+ // production and reaches the emulator — the app needs no endpoint override,
9
+ // no test-only branch, and no knowledge that it is under test.
10
+ //
11
+ // Lambda functions are declared next to the services and deployed from the
12
+ // project's own source. Deployment happens in the service `setup` hook, which
13
+ // runs before the warm-template snapshot, so a warm start restores functions
14
+ // that are already deployed, already active, and already warm.
15
+ //
16
+ // ── Internal notes (deliberately not in the user-facing docs) ──────────────
17
+ //
18
+ // The backing image is MiniStack (MIT, github.com/ministackorg/ministack),
19
+ // pinned rather than floated. It replaced LocalStack, which folded its
20
+ // Apache-2.0 Community edition into one paid product in March 2026 (current
21
+ // images demand a LOCALSTACK_AUTH_TOKEN). MiniStack also suits fork-per-test
22
+ // far better: ~270 MB against ~1 GB, a ~2 s boot, and Lambda on an in-process
23
+ // warm worker pool instead of sibling containers — so no docker socket is
24
+ // bind-mounted and there is no host-architecture workaround on Graviton.
25
+ //
26
+ // Like `email()`'s mail server, the product name stays out of every
27
+ // user-facing surface (docs, examples, error messages). Users get "the AWS
28
+ // emulator"; `image` swaps it.
29
+ //
30
+ // The emulator ignores SigV4 and does not check that a role exists, both
31
+ // verified on 1.4.8. That is what lets this component deploy over plain
32
+ // unsigned HTTP from the daemon and skip IAM entirely.
33
+ import { readFile, readdir, stat } from "node:fs/promises";
34
+ import path from "node:path";
35
+ import { deflateRawSync } from "node:zlib";
36
+ import { certificate, provides, proxy, SELF_SERVICE_TOKEN } from "../index.js";
37
+ import { pauseRecording, resumeRecording } from "../recorder.js";
38
+ /** Backing image, pinned internally (not part of the documented surface). */
39
+ const AWS_IMAGE = "ministackorg/ministack:1.4.8";
40
+ /** Port the emulator serves every AWS API on. Internal: callers reach the
41
+ * emulator through the AWS hostnames, never through this port. */
42
+ const AWS_PORT = 4566;
43
+ // Every AWS region, so the component can answer for all of them and the user
44
+ // never has to declare which ones the app uses. Enumeration is forced by TLS,
45
+ // not by routing: a wildcard *route* matches any depth, but a wildcard
46
+ // *certificate* covers exactly one label (RFC 6125, enforced by every
47
+ // client), so `*.amazonaws.com` cannot serve `states.us-east-1.amazonaws.com`
48
+ // — each region needs its own `*.<region>.amazonaws.com` name. They all ride
49
+ // ONE certificate as SANs and one shared upstream, so the list costs a few
50
+ // route-table entries, not a key generation each.
51
+ //
52
+ // Sourced from AWS's own published `ip-ranges.json` (2026-07-31). A region
53
+ // added later is simply not claimed: its endpoints fail to resolve, which
54
+ // says plainly what happened — add it here.
55
+ const AWS_REGIONS = [
56
+ "af-south-1", "ap-east-1", "ap-east-2", "ap-northeast-1", "ap-northeast-2",
57
+ "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2",
58
+ "ap-southeast-3", "ap-southeast-4", "ap-southeast-5", "ap-southeast-6",
59
+ "ap-southeast-7", "ca-central-1", "ca-west-1", "eu-central-1", "eu-central-2",
60
+ "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3",
61
+ "eusc-de-east-1", "il-central-1", "me-central-1", "me-south-1", "me-west-1",
62
+ "mx-central-1", "sa-east-1", "sa-west-1", "us-east-1", "us-east-2",
63
+ "us-gov-east-1", "us-gov-west-1", "us-south-1", "us-west-1", "us-west-2",
64
+ ];
65
+ /** China is a separate partition on its own domain suffix. */
66
+ const AWS_CN_REGIONS = ["cn-north-1", "cn-northwest-1"];
67
+ /** Every hostname pattern the emulator answers to: the two partitions' global
68
+ * endpoints (`sts.amazonaws.com`, `iam.amazonaws.com`) plus one per region
69
+ * for the regional ones (`states.us-east-1.amazonaws.com`). */
70
+ const AWS_HOST_PATTERNS = [
71
+ "*.amazonaws.com",
72
+ ...AWS_REGIONS.map((r) => `*.${r}.amazonaws.com`),
73
+ "*.amazonaws.com.cn",
74
+ ...AWS_CN_REGIONS.map((r) => `*.${r}.amazonaws.com.cn`),
75
+ ];
76
+ /** Region the emulator's own tools default to — the AWS CLI refuses to run
77
+ * without one. Only the *container's* default; it constrains nothing about
78
+ * the app, and every region is served regardless. A `setup` hook that drives
79
+ * the CLI against another region passes `--region`. */
80
+ const CONTAINER_DEFAULT_REGION = "us-east-1";
81
+ /** Role every declared function is created with. The emulator does not
82
+ * enforce IAM, so this only has to be a well-formed ARN — which is why the
83
+ * component creates no role and takes no IAM options. A project that wants a
84
+ * real-looking role can create one itself and set `role` on the function. */
85
+ const DEFAULT_ROLE_ARN = "arn:aws:iam::000000000000:role/spectest-lambda";
86
+ /** Ready-check budget. The emulator boots in a couple of seconds; the slow
87
+ * part is a cold image pull on a machine that has never run it. */
88
+ const READY_TIMEOUT_SECS = 120;
89
+ /** Memory every declared function is created with. Kept at what this
90
+ * component has always used, rather than the emulator's own default, so the
91
+ * removal of the `memoryMb` option changed no behaviour. */
92
+ const MEMORY_MB = 512;
93
+ /**
94
+ * The AWS cloud APIs, emulated in the environment and answering at their real
95
+ * endpoints. Drop into `environment.services`:
96
+ *
97
+ * ```ts
98
+ * import { aws } from "@specific.dev/spectest/components";
99
+ *
100
+ * services: {
101
+ * aws: aws({
102
+ * lambdas: {
103
+ * add: { source: "lambda/add" },
104
+ * subtract: { source: "lambda/subtract" },
105
+ * },
106
+ * }),
107
+ * app: {
108
+ * image: { type: "dockerfile", content: appDockerfile },
109
+ * // Whatever the app already reads in production. An AWS SDK needs a
110
+ * // region and credentials; the emulator accepts any credential value.
111
+ * env: {
112
+ * AWS_REGION: "us-east-1",
113
+ * AWS_ACCESS_KEY_ID: "test",
114
+ * AWS_SECRET_ACCESS_KEY: "test",
115
+ * },
116
+ * dependsOn: ["aws"],
117
+ * },
118
+ * }
119
+ * ```
120
+ *
121
+ * The app keeps its production configuration — `new SFNClient({})`, no
122
+ * endpoint — because the component owns DNS and TLS for the AWS domains. It
123
+ * answers for **every region**, so an app that talks to two of them, or that
124
+ * reads its region from configuration, needs nothing declared here.
125
+ *
126
+ * Tests reach the same cloud with the AWS CLI, which the emulator's image
127
+ * ships as `awslocal` (the CLI, already pointed at it):
128
+ *
129
+ * ```ts
130
+ * const listed = await ctx.exec("aws", "awslocal stepfunctions list-state-machines");
131
+ * expect(listed.exitCode).toBe(0);
132
+ * const machines = listed.stdout.transform("machines", (out) =>
133
+ * (JSON.parse(out) as { stateMachines: unknown[] }).stateMachines,
134
+ * );
135
+ * expect(machines).toHaveLength(1);
136
+ * ```
137
+ *
138
+ * For S3, prefer the `s3()` component and give it the endpoint your app uses
139
+ * (`s3({ hosts: ["s3.us-east-1.amazonaws.com"] })`). An exact hostname always
140
+ * beats this component's wildcard, so the two compose without further
141
+ * configuration.
142
+ */
143
+ export function aws(opts = {}) {
144
+ const lambdas = opts.lambdas ?? {};
145
+ const service = {
146
+ image: { type: "registry", reference: AWS_IMAGE },
147
+ env: { AWS_DEFAULT_REGION: CONTAINER_DEFAULT_REGION },
148
+ ports: [AWS_PORT],
149
+ readyCheck: {
150
+ type: "http",
151
+ port: AWS_PORT,
152
+ path: "/_ministack/health",
153
+ timeoutSecs: READY_TIMEOUT_SECS,
154
+ },
155
+ ...(Object.keys(lambdas).length > 0
156
+ ? {
157
+ setup: async ({ name, projectRoot }) => {
158
+ for (const [fn, spec] of Object.entries(lambdas)) {
159
+ await deployLambda(name, projectRoot, fn, spec);
160
+ }
161
+ },
162
+ }
163
+ : {}),
164
+ };
165
+ // The low-level primitives rather than the `tls` field, for one reason:
166
+ // `tls` mints a separate leaf certificate per entry, and this component
167
+ // claims several dozen names. One `certificate(...)` decl carries them all
168
+ // as SANs of a single leaf — one key generation at bring-up instead of
169
+ // dozens — while the proxies are just route-table entries.
170
+ return provides(service, [
171
+ certificate(AWS_HOST_PATTERNS),
172
+ ...AWS_HOST_PATTERNS.map((hostname) => proxy(hostname, { service: SELF_SERVICE_TOKEN, port: AWS_PORT })),
173
+ ]);
174
+ }
175
+ // ──────────────────────────────────────────────────────────────────────────
176
+ // Talking to the emulator directly
177
+ //
178
+ // The emulator ignores request signatures, so the daemon reaches its APIs
179
+ // over plain unsigned HTTP. That keeps deployment independent of what tools
180
+ // the image happens to ship, and keeps a poll loop cheap.
181
+ // ──────────────────────────────────────────────────────────────────────────
182
+ /** One JSON-protocol AWS call (Step Functions, DynamoDB, …), by target. */
183
+ async function request(service, method, urlPath, init = {}) {
184
+ // Never let the component's own traffic land on the timeline: these calls
185
+ // are bring-up and polling, not something a test asked for.
186
+ pauseRecording();
187
+ try {
188
+ const res = await fetch(`http://${service}:${AWS_PORT}${urlPath}`, {
189
+ method,
190
+ headers: { "content-type": "application/json", ...(init.headers ?? {}) },
191
+ ...(init.body !== undefined ? { body: init.body } : {}),
192
+ });
193
+ // Coerced rather than read directly: `fetch` is wrapped during a test, so
194
+ // `res.status` is a provenance carrier there and a plain number elsewhere.
195
+ const status = Number(res.status);
196
+ const text = String(await res.text());
197
+ if (status >= 400) {
198
+ const err = new Error(`aws: ${method} ${urlPath} failed: HTTP ${status} ${text.slice(0, 400)}`);
199
+ err.status = status;
200
+ throw err;
201
+ }
202
+ return text === "" ? undefined : JSON.parse(text);
203
+ }
204
+ finally {
205
+ resumeRecording();
206
+ }
207
+ }
208
+ // ──────────────────────────────────────────────────────────────────────────
209
+ // Lambda deployment
210
+ // ──────────────────────────────────────────────────────────────────────────
211
+ /** Refuse a package that no real deployment would accept either. */
212
+ const MAX_PACKAGE_BYTES = 64 * 1024 * 1024;
213
+ async function deployLambda(service, projectRoot, name, spec) {
214
+ if (typeof spec?.source !== "string" || spec.source.trim() === "") {
215
+ throw new Error(`aws: lambda "${name}" needs a \`source\` path to its code`);
216
+ }
217
+ const zipped = await packageSource(projectRoot, name, spec.source);
218
+ if (zipped.length > MAX_PACKAGE_BYTES) {
219
+ throw new Error(`aws: lambda "${name}" packages to ${Math.round(zipped.length / 1e6)} MB from ` +
220
+ `${spec.source} — over the ${MAX_PACKAGE_BYTES / 1e6} MB limit. Point \`source\` at ` +
221
+ `the function's own directory, not a whole repository.`);
222
+ }
223
+ const code = Buffer.from(zipped).toString("base64");
224
+ const config = {
225
+ Runtime: spec.runtime ?? "nodejs20.x",
226
+ Handler: spec.handler ?? "index.handler",
227
+ Role: spec.role ?? DEFAULT_ROLE_ARN,
228
+ Timeout: spec.timeoutSecs ?? 30,
229
+ // Fixed, and not an option: the emulated cloud runs handlers in a shared
230
+ // worker pool rather than a memory-capped sandbox, so the number changes
231
+ // nothing about how a function behaves here.
232
+ MemorySize: MEMORY_MB,
233
+ ...(spec.env ? { Environment: { Variables: spec.env } } : {}),
234
+ };
235
+ try {
236
+ await request(service, "POST", "/2015-03-31/functions", {
237
+ body: JSON.stringify({ FunctionName: name, Code: { ZipFile: code }, ...config }),
238
+ });
239
+ }
240
+ catch (err) {
241
+ // Already there: a re-run of bring-up against an emulator that kept its
242
+ // state. Update instead, so the deployed code always matches the repo.
243
+ if (err.status !== 409)
244
+ throw err;
245
+ await request(service, "PUT", `/2015-03-31/functions/${encodeURIComponent(name)}/code`, {
246
+ body: JSON.stringify({ ZipFile: code }),
247
+ });
248
+ await request(service, "PUT", `/2015-03-31/functions/${encodeURIComponent(name)}/configuration`, {
249
+ body: JSON.stringify(config),
250
+ });
251
+ }
252
+ await waitActive(service, name);
253
+ // One invoke with an empty event, purely to leave a warm worker behind in
254
+ // the snapshot, so no test pays a cold start. The handler may well reject
255
+ // the event — that is fine, the worker is started either way.
256
+ try {
257
+ await request(service, "POST", `/2015-03-31/functions/${encodeURIComponent(name)}/invocations`, {
258
+ body: "{}",
259
+ });
260
+ }
261
+ catch {
262
+ // Ignored on purpose: warming is an optimisation, never a gate.
263
+ }
264
+ }
265
+ /** Wait for a newly created function to leave `Pending`, exactly as a real
266
+ * deployment must. Tolerates an emulator that reports no state at all. */
267
+ async function waitActive(service, name, timeoutMs = 60_000) {
268
+ const deadline = Date.now() + timeoutMs;
269
+ for (;;) {
270
+ const cfg = (await request(service, "GET", `/2015-03-31/functions/${encodeURIComponent(name)}/configuration`));
271
+ const state = cfg?.State;
272
+ if (state === undefined || state === "Active")
273
+ return;
274
+ if (state === "Failed") {
275
+ throw new Error(`aws: lambda "${name}" failed to deploy: ${cfg?.StateReason ?? "no reason given"}`);
276
+ }
277
+ if (Date.now() > deadline) {
278
+ throw new Error(`aws: lambda "${name}" was still ${state} after ${timeoutMs} ms`);
279
+ }
280
+ await new Promise((resolve) => setTimeout(resolve, 100));
281
+ }
282
+ }
283
+ async function packageSource(projectRoot, fnName, source) {
284
+ const root = path.isAbsolute(source) ? source : path.join(projectRoot, source);
285
+ let info;
286
+ try {
287
+ info = await stat(root);
288
+ }
289
+ catch {
290
+ throw new Error(`aws: lambda "${fnName}" has no code at ${source} (looked in ${root}). ` +
291
+ `\`source\` is a path in your repository, relative to its root.`);
292
+ }
293
+ const entries = [];
294
+ if (info.isDirectory()) {
295
+ await collect(root, "", entries);
296
+ if (entries.length === 0) {
297
+ throw new Error(`aws: lambda "${fnName}" has no files in ${source}`);
298
+ }
299
+ }
300
+ else {
301
+ entries.push({ name: path.basename(root), data: await readFile(root) });
302
+ }
303
+ // Sorted so the same source always packages to the same bytes.
304
+ entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
305
+ return buildZip(entries);
306
+ }
307
+ async function collect(dir, prefix, out) {
308
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
309
+ const full = path.join(dir, entry.name);
310
+ const rel = prefix === "" ? entry.name : `${prefix}/${entry.name}`;
311
+ if (entry.isDirectory()) {
312
+ await collect(full, rel, out);
313
+ }
314
+ else if (entry.isFile()) {
315
+ out.push({ name: rel, data: await readFile(full) });
316
+ }
317
+ // Symlinks and everything else are skipped: a deployment package holds
318
+ // regular files.
319
+ }
320
+ }
321
+ function crc32(buf) {
322
+ let crc = 0xffffffff;
323
+ for (let i = 0; i < buf.length; i++) {
324
+ let c = (crc ^ buf[i]) & 0xff;
325
+ for (let k = 0; k < 8; k++)
326
+ c = c & 1 ? (c >>> 1) ^ 0xedb88320 : c >>> 1;
327
+ crc = (crc >>> 8) ^ c;
328
+ }
329
+ return (crc ^ 0xffffffff) >>> 0;
330
+ }
331
+ /**
332
+ * Build a zip archive. Entries are deflated (method 8), or stored (method 0)
333
+ * when deflating makes them no smaller. Timestamps are fixed, so identical
334
+ * sources always produce identical bytes.
335
+ */
336
+ function buildZip(entries) {
337
+ const encoder = new TextEncoder();
338
+ const local = [];
339
+ const central = [];
340
+ let offset = 0;
341
+ for (const entry of entries) {
342
+ const nameBytes = encoder.encode(entry.name);
343
+ const crc = crc32(entry.data);
344
+ const deflated = new Uint8Array(deflateRawSync(entry.data));
345
+ const stored = deflated.length >= entry.data.length;
346
+ const payload = stored ? entry.data : deflated;
347
+ const method = stored ? 0 : 8;
348
+ const header = new DataView(new ArrayBuffer(30));
349
+ header.setUint32(0, 0x04034b50, true); // local file header
350
+ header.setUint16(4, 20, true); // version needed
351
+ header.setUint16(6, 0, true); // flags
352
+ header.setUint16(8, method, true);
353
+ header.setUint16(10, 0, true); // time — fixed
354
+ header.setUint16(12, 0x21, true); // date — fixed (1 Jan 1980)
355
+ header.setUint32(14, crc, true);
356
+ header.setUint32(18, payload.length, true);
357
+ header.setUint32(22, entry.data.length, true);
358
+ header.setUint16(26, nameBytes.length, true);
359
+ header.setUint16(28, 0, true); // extra length
360
+ const headerBytes = new Uint8Array(header.buffer);
361
+ local.push(headerBytes, nameBytes, payload);
362
+ const dirEntry = new DataView(new ArrayBuffer(46));
363
+ dirEntry.setUint32(0, 0x02014b50, true); // central directory header
364
+ dirEntry.setUint16(4, 20, true); // version made by
365
+ dirEntry.setUint16(6, 20, true); // version needed
366
+ dirEntry.setUint16(8, 0, true); // flags
367
+ dirEntry.setUint16(10, method, true);
368
+ dirEntry.setUint16(12, 0, true);
369
+ dirEntry.setUint16(14, 0x21, true);
370
+ dirEntry.setUint32(16, crc, true);
371
+ dirEntry.setUint32(20, payload.length, true);
372
+ dirEntry.setUint32(24, entry.data.length, true);
373
+ dirEntry.setUint16(28, nameBytes.length, true);
374
+ // Permissions in the high half of the external attributes: 0644 for a
375
+ // regular file, which is what a Lambda runtime expects to find.
376
+ dirEntry.setUint32(38, 0o100644 << 16, true);
377
+ dirEntry.setUint32(42, offset, true);
378
+ central.push(new Uint8Array(dirEntry.buffer), nameBytes);
379
+ offset += headerBytes.length + nameBytes.length + payload.length;
380
+ }
381
+ const centralSize = central.reduce((n, part) => n + part.length, 0);
382
+ const end = new DataView(new ArrayBuffer(22));
383
+ end.setUint32(0, 0x06054b50, true); // end of central directory
384
+ end.setUint16(8, entries.length, true);
385
+ end.setUint16(10, entries.length, true);
386
+ end.setUint32(12, centralSize, true);
387
+ end.setUint32(16, offset, true);
388
+ const parts = [...local, ...central, new Uint8Array(end.buffer)];
389
+ const total = parts.reduce((n, part) => n + part.length, 0);
390
+ const zipped = new Uint8Array(total);
391
+ let cursor = 0;
392
+ for (const part of parts) {
393
+ zipped.set(part, cursor);
394
+ cursor += part.length;
395
+ }
396
+ return zipped;
397
+ }
@@ -5,4 +5,5 @@ export { k3s, type K3sOptions, type K3sHelpers, type K3sClient, type TaggedObjec
5
5
  export { expo, type ExpoOptions, type ExpoHelpers, } from "./expo.js";
6
6
  export { supabase, type SupabaseOptions, type SupabaseHelpers, type SupabaseStack, } from "./supabase.js";
7
7
  export { email, type EmailOptions, type EmailHelpers, type EmailMessage, type EmailSummary, type EmailMatch, type EmailAttachment, } from "./email.js";
8
+ export { aws, type AwsOptions, type LambdaOptions, } from "./aws.js";
8
9
  export { replayFake, type ReplayFakeOptions, type ReplayMatch, type InjectRule, type InjectMatch, type StringMatch, type SignConfig, type AwsSigV4Sign, type ReplayHelpers, type ReplaySummary, type Cassette, type CassetteInteraction, type CassetteRequest, type CassetteResponse, type CassetteState, } from "./replayFake.js";
@@ -15,4 +15,5 @@ export { k3s, } from "./k3s.js";
15
15
  export { expo, } from "./expo.js";
16
16
  export { supabase, } from "./supabase.js";
17
17
  export { email, } from "./email.js";
18
+ export { aws, } from "./aws.js";
18
19
  export { replayFake, } from "./replayFake.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specific.dev/spectest",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "Spectest SDK for defining test environments in TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",