Skip to content

Commit 48a3e7b

Browse files
committed
temp
1 parent ef9cf2b commit 48a3e7b

10 files changed

Lines changed: 310 additions & 154 deletions

File tree

packages/miniflare/src/config/schema.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,27 +195,24 @@ const MiniflareFlagshipBindingSchema = FlagshipBindingSchema.omit({
195195
id: z.string(),
196196
});
197197

198-
/**
199-
* AWS SigV4 credentials for miniflare's local S3-compatible R2 endpoint.
200-
* Local-only, so not in the shared config schema.
201-
*/
202-
export const R2S3CredentialsSchema = z.object({
203-
accessKeyId: z.string(),
204-
secretAccessKey: z.string(),
205-
}) satisfies z.ZodType<S3Credentials>;
206-
207-
export type R2S3Credentials = z.infer<typeof R2S3CredentialsSchema>;
208-
209198
/**
210199
* Force name to be required. `s3Credentials` is a local-dev-only field (used to
211200
* expose the bucket via the S3-compatible endpoint), so it lives here rather
212-
* than in the shared config schema.
201+
* than in the shared config schema. The credentials shape is inlined (rather
202+
* than a named schema) to keep it out of the bundled public API surface;
203+
* consumers derive the type from the R2 binding via `Extract<MiniflareBinding,
204+
* { type: "r2" }>`.
213205
*/
214206
const MiniflareR2BindingSchema = R2BindingSchema.omit({
215207
name: true,
216208
}).extend({
217209
name: z.string(),
218-
s3Credentials: R2S3CredentialsSchema.optional(),
210+
s3Credentials: z
211+
.object({
212+
accessKeyId: z.string(),
213+
secretAccessKey: z.string(),
214+
})
215+
.optional() satisfies z.ZodType<S3Credentials | undefined>,
219216
});
220217

221218
/**

packages/miniflare/src/plugins/r2/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ import type {
2222
Worker_Binding,
2323
Worker_Binding_DurableObjectNamespaceDesignator,
2424
} from "../../runtime";
25-
import type { ParsedWorkerOptions, Plugin, R2S3Credentials } from "../shared";
25+
import type { MiniflareBinding, ParsedWorkerOptions, Plugin } from "../shared";
26+
27+
/** Local-dev S3 credentials, derived from the parsed R2 binding. */
28+
type R2S3Credentials = NonNullable<
29+
Extract<MiniflareBinding, { type: "r2" }>["s3Credentials"]
30+
>;
2631

2732
export const R2_PLUGIN_NAME = "r2";
2833
const R2_STORAGE_SERVICE_NAME = `${R2_PLUGIN_NAME}:storage`;

packages/miniflare/src/plugins/shared/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,4 @@ export type {
267267
ParsedLegacyConfig,
268268
ParsedMiniflareWorkerConfig,
269269
ParsedWorkerOptions,
270-
R2S3Credentials,
271270
} from "../../config/schema";

packages/miniflare/test/index.spec.ts

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,8 +2515,14 @@ test("Miniflare: manually triggered email handler - structured result", async ({
25152515
expect,
25162516
}) => {
25172517
const mf = new Miniflare({
2518-
modules: true,
2519-
script: `
2518+
unsafeTriggerHandlers: true,
2519+
workers: [
2520+
{
2521+
config: {
2522+
type: "worker",
2523+
name: "",
2524+
compatibilityDate: "2025-05-01",
2525+
manifest: singleModuleManifest(`
25202526
import { EmailMessage } from "cloudflare:email";
25212527
25222528
export default {
@@ -2542,8 +2548,10 @@ test("Miniflare: manually triggered email handler - structured result", async ({
25422548
throw new Error("sensitive handler error");
25432549
}
25442550
}
2545-
}`,
2546-
unsafeTriggerHandlers: true,
2551+
}`),
2552+
},
2553+
},
2554+
],
25472555
});
25482556
useDispose(mf);
25492557

@@ -3581,16 +3589,24 @@ test("Miniflare: workerd crash during startup => ERR_RUNTIME_FAILURE", async ({
35813589
onTestFinished,
35823590
}) => {
35833591
const mf = new Miniflare({
3584-
modules: true,
3585-
script: `
3592+
workers: [
3593+
{
3594+
config: {
3595+
type: "worker",
3596+
name: "",
3597+
compatibilityDate: "2025-05-01",
3598+
manifest: singleModuleManifest(`
35863599
import { abortIsolate } from "cloudflare:workers";
35873600
abortIsolate("crash!");
35883601
export default {
35893602
fetch(request) {
35903603
return new Response("ok");
35913604
},
35923605
}
3593-
`,
3606+
`),
3607+
},
3608+
},
3609+
],
35943610
});
35953611
// dispose() on a startup-failed instance propagates the same
35963612
// ERR_RUNTIME_FAILURE
@@ -3605,9 +3621,14 @@ test("Miniflare: workerd crash during startup => ERR_RUNTIME_FAILURE", async ({
36053621
test("Miniflare: workerd crash in handler => restart", async ({ expect }) => {
36063622
const runtimeRestarted = new DeferredPromise<void>();
36073623
const mf = new Miniflare({
3608-
modules: true,
36093624
unsafeHandleRuntimeRestart: () => runtimeRestarted.resolve(),
3610-
script: `
3625+
workers: [
3626+
{
3627+
config: {
3628+
type: "worker",
3629+
name: "",
3630+
compatibilityDate: "2025-05-01",
3631+
manifest: singleModuleManifest(`
36113632
import { abortIsolate } from "cloudflare:workers";
36123633
let counter = 1;
36133634
export default {
@@ -3618,7 +3639,10 @@ test("Miniflare: workerd crash in handler => restart", async ({ expect }) => {
36183639
return new Response(\`ok \${counter++}\`);
36193640
},
36203641
}
3621-
`,
3642+
`),
3643+
},
3644+
},
3645+
],
36223646
});
36233647
useDispose(mf);
36243648

@@ -3653,12 +3677,17 @@ test("Miniflare: logs post-restart callback failures", async ({ expect }) => {
36533677
const callbackCalled = new DeferredPromise<void>();
36543678
const mf = new Miniflare({
36553679
log,
3656-
modules: true,
36573680
async unsafeHandleRuntimeRestart() {
36583681
callbackCalled.resolve();
36593682
throw new Error("callback failed");
36603683
},
3661-
script: `
3684+
workers: [
3685+
{
3686+
config: {
3687+
type: "worker",
3688+
name: "",
3689+
compatibilityDate: "2025-05-01",
3690+
manifest: singleModuleManifest(`
36623691
import { abortIsolate } from "cloudflare:workers";
36633692
export default {
36643693
fetch(request) {
@@ -3668,7 +3697,10 @@ test("Miniflare: logs post-restart callback failures", async ({ expect }) => {
36683697
return new Response("ok");
36693698
},
36703699
}
3671-
`,
3700+
`),
3701+
},
3702+
},
3703+
],
36723704
});
36733705
useDispose(mf);
36743706

packages/miniflare/test/plugins/core/observability.spec.ts

Lines changed: 78 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assert from "node:assert";
22
import { Miniflare, type WorkerOptions } from "miniflare";
33
import { describe, test } from "vitest";
44
import { OBSERVABILITY_COLLECTOR_SERVICE_NAME } from "../../../src/plugins/core/constants";
5-
import { useDispose } from "../../test-shared";
5+
import { singleModuleManifest, useDispose } from "../../test-shared";
66

77
// Local observability wiring.
88
//
@@ -16,10 +16,12 @@ import { useDispose } from "../../test-shared";
1616

1717
function plainWorker(script: string): WorkerOptions {
1818
return {
19-
name: "user",
20-
modules: true,
21-
compatibilityDate: "2026-06-01",
22-
script,
19+
config: {
20+
type: "worker",
21+
name: "user",
22+
compatibilityDate: "2026-06-01",
23+
manifest: singleModuleManifest(script),
24+
},
2325
};
2426
}
2527

@@ -190,19 +192,25 @@ export default {
190192

191193
function storeWorker(): WorkerOptions {
192194
return {
193-
name: "user",
194-
modules: true,
195-
compatibilityDate: "2026-06-01",
196-
script: STORE_HARNESS,
197-
// Bind the collector's internal TraceStore DO (cross-script) to seed it,
198-
// and the collector service to read it back through the HTTP read API.
199-
durableObjects: {
200-
TRACE_STORE: {
201-
className: "TraceStore",
202-
scriptName: OBSERVABILITY_COLLECTOR_SERVICE_NAME,
195+
config: {
196+
type: "worker",
197+
name: "user",
198+
compatibilityDate: "2026-06-01",
199+
manifest: singleModuleManifest(STORE_HARNESS),
200+
// Bind the collector's internal TraceStore DO (cross-script) to seed it,
201+
// and the collector service to read it back through the HTTP read API.
202+
env: {
203+
TRACE_STORE: {
204+
type: "durable-object",
205+
workerName: OBSERVABILITY_COLLECTOR_SERVICE_NAME,
206+
exportName: "TraceStore",
207+
},
208+
WOBS: {
209+
type: "worker",
210+
workerName: OBSERVABILITY_COLLECTOR_SERVICE_NAME,
211+
},
203212
},
204213
},
205-
serviceBindings: { WOBS: { name: OBSERVABILITY_COLLECTOR_SERVICE_NAME } },
206214
};
207215
}
208216

@@ -396,12 +404,19 @@ const CAPTURE_WORKER = `export default {
396404

397405
function captureWorker(): WorkerOptions {
398406
return {
399-
name: "user",
400-
modules: true,
401-
compatibilityDate: "2026-06-01",
402-
script: CAPTURE_WORKER,
403-
kvNamespaces: { CACHE: "cache-namespace" },
404-
serviceBindings: { WOBS: { name: OBSERVABILITY_COLLECTOR_SERVICE_NAME } },
407+
config: {
408+
type: "worker",
409+
name: "user",
410+
compatibilityDate: "2026-06-01",
411+
manifest: singleModuleManifest(CAPTURE_WORKER),
412+
env: {
413+
CACHE: { type: "kv", id: "cache-namespace" },
414+
WOBS: {
415+
type: "worker",
416+
workerName: OBSERVABILITY_COLLECTOR_SERVICE_NAME,
417+
},
418+
},
419+
},
405420
};
406421
}
407422

@@ -530,21 +545,30 @@ const UPSTREAM_WORKER = `export default {
530545
function multiWorkerSetup(): WorkerOptions[] {
531546
return [
532547
{
533-
name: "upstream",
534-
modules: true,
535-
compatibilityDate: "2026-06-01",
536-
script: UPSTREAM_WORKER,
537-
serviceBindings: {
538-
DOWNSTREAM: "downstream",
539-
WOBS: { name: OBSERVABILITY_COLLECTOR_SERVICE_NAME },
548+
config: {
549+
type: "worker",
550+
name: "upstream",
551+
compatibilityDate: "2026-06-01",
552+
manifest: singleModuleManifest(UPSTREAM_WORKER),
553+
env: {
554+
DOWNSTREAM: { type: "worker", workerName: "downstream" },
555+
WOBS: {
556+
type: "worker",
557+
workerName: OBSERVABILITY_COLLECTOR_SERVICE_NAME,
558+
},
559+
},
540560
},
541561
},
542562
{
543-
name: "downstream",
544-
modules: true,
545-
compatibilityDate: "2026-06-01",
546-
script: DOWNSTREAM_WORKER,
547-
kvNamespaces: { CACHE: "cache-namespace" },
563+
config: {
564+
type: "worker",
565+
name: "downstream",
566+
compatibilityDate: "2026-06-01",
567+
manifest: singleModuleManifest(DOWNSTREAM_WORKER),
568+
env: {
569+
CACHE: { type: "kv", id: "cache-namespace" },
570+
},
571+
},
548572
},
549573
];
550574
}
@@ -586,23 +610,32 @@ export default {
586610
},
587611
};`;
588612

589-
describe("unsafeObservability (workflows)", () => {
613+
// NOTE(miniflare v5 options-schema migration): Workflows support is temporarily
614+
// disabled during the config-format migration (the `workflow` binding type is not
615+
// yet in the new schema and the Workflows plugin is a no-op stub). Re-enable this
616+
// test once Workflows is re-implemented against the new config format.
617+
describe.skip("unsafeObservability (workflows)", () => {
590618
test("captures the Workflows engine invocation, attributed to the workflow", async ({
591619
expect,
592620
}) => {
593621
const mf = new Miniflare({
594622
unsafeObservability: true,
595-
name: "wf-user",
596-
modules: true,
597-
compatibilityDate: "2026-06-01",
598-
script: WORKFLOW_CAPTURE_WORKER,
599-
workflows: {
600-
CAPTURE_WORKFLOW: {
601-
className: "CaptureWorkflow",
602-
name: "capture-workflow",
623+
workers: [
624+
{
625+
config: {
626+
type: "worker",
627+
name: "wf-user",
628+
compatibilityDate: "2026-06-01",
629+
manifest: singleModuleManifest(WORKFLOW_CAPTURE_WORKER),
630+
env: {
631+
WOBS: {
632+
type: "worker",
633+
workerName: OBSERVABILITY_COLLECTOR_SERVICE_NAME,
634+
},
635+
},
636+
},
603637
},
604-
},
605-
serviceBindings: { WOBS: { name: OBSERVABILITY_COLLECTOR_SERVICE_NAME } },
638+
],
606639
});
607640
useDispose(mf);
608641

packages/miniflare/test/plugins/email/index.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,9 +2372,8 @@ describe("EMAIL_PLUGIN.getServices", () => {
23722372
options: {
23732373
config: { env: { SEND_EMAIL: { type: "send-email" } } },
23742374
},
2375-
sharedOptions: {},
2375+
sharedOptions: { resourceTmpPath: projectTmpPath },
23762376
tmpPath: tmp,
2377-
resourceTmpPath: projectTmpPath,
23782377
workerNames: ["default"],
23792378
workerIndex: 0,
23802379
} as unknown as Parameters<typeof EMAIL_PLUGIN.getServices>[0]);

packages/miniflare/test/plugins/images/transform.spec.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Miniflare } from "miniflare";
22
import sharp from "sharp";
33
import { afterAll, beforeAll, describe, test } from "vitest";
4+
import { singleModuleManifest } from "../../test-shared";
45
import type { MiniflareOptions } from "miniflare";
56

67
// A worker that runs env.IMAGES.input(...).transform(...).output(...) with
@@ -59,10 +60,17 @@ describe("Images binding local transforms", () => {
5960
.toBuffer();
6061

6162
mf = new Miniflare({
62-
compatibilityDate: "2025-04-01",
63-
modules: true,
64-
script: WORKER_SCRIPT,
65-
images: { binding: "IMAGES" },
63+
workers: [
64+
{
65+
config: {
66+
type: "worker",
67+
name: "",
68+
compatibilityDate: "2025-04-01",
69+
manifest: singleModuleManifest(WORKER_SCRIPT),
70+
env: { IMAGES: { type: "images" } },
71+
},
72+
},
73+
],
6674
} satisfies MiniflareOptions);
6775
});
6876

0 commit comments

Comments
 (0)