@@ -4,7 +4,11 @@ import { spawnSync } from "node:child_process";
44import { randomFillSync } from "node:crypto";
55import * as fs from "node:fs";
66import * as path from "node:path";
7- import { findWranglerConfig, ParseError } from "@cloudflare/workers-utils";
7+ import {
8+ APIError,
9+ findWranglerConfig,
10+ ParseError,
11+ } from "@cloudflare/workers-utils";
812import { normalizeString } from "@cloudflare/workers-utils/test-helpers";
913import { sync } from "command-exists";
1014import * as esbuild from "esbuild";
@@ -15633,6 +15637,61 @@ export default{
1563315637 `);
1563415638 });
1563515639
15640+ it("should handle the remote secrets fetching check for new workers", async () => {
15641+ writeWorkerSource();
15642+ writeWranglerConfig(
15643+ {
15644+ compatibility_date: "2024-04-24",
15645+ main: "./index.js",
15646+ vars: {
15647+ MY_SECRET: 123,
15648+ },
15649+ observability: {
15650+ enabled: true,
15651+ },
15652+ },
15653+ "./wrangler.json"
15654+ );
15655+ mockSubDomainRequest();
15656+ mockUploadWorkerRequest({ wranglerConfigPath: "./wrangler.json" });
15657+
15658+ msw.use(
15659+ http.get(
15660+ `*/accounts/:accountId/workers/scripts/:scriptName/secrets`,
15661+ () => {
15662+ const workerNotFoundAPIError = new APIError({
15663+ status: 404,
15664+ text: "A request to the Cloudflare API (/accounts/xxx/workers/scripts/yyy/secrets) failed.",
15665+ });
15666+
15667+ workerNotFoundAPIError.code = 10007;
15668+ throw workerNotFoundAPIError;
15669+ },
15670+ { once: true }
15671+ )
15672+ );
15673+
15674+ await runWrangler("deploy");
15675+
15676+ expect(fetchSecrets).toHaveBeenCalled();
15677+ expect(std.warn).toMatchInlineSnapshot(`""`);
15678+ expect(std.out).toMatchInlineSnapshot(`
15679+ "
15680+ ⛅️ wrangler x.x.x
15681+ ──────────────────
15682+ Total Upload: xx KiB / gzip: xx KiB
15683+ Worker Startup Time: 100 ms
15684+ Your Worker has access to the following bindings:
15685+ Binding Resource
15686+ env.MY_SECRET (123) Environment Variable
15687+
15688+ Uploaded test-name (TIMINGS)
15689+ Deployed test-name triggers (TIMINGS)
15690+ https://test-name.test-sub-domain.workers.dev
15691+ Current Version ID: Galaxy-Class"
15692+ `);
15693+ });
15694+
1563615695 it("should not fetch remote secrets in dry-run mode", async () => {
1563715696 writeWorkerSource();
1563815697 writeWranglerConfig(
0 commit comments