GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(id-mail): salvage deploy probe from duplicate PR #3767; guard na… · developing-today/code@c0c5a85

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • nixos/services/id-mail/worker
    • deploy.mjs
    • deploy.test.mjs
    • package.json
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎nixos/services/id-mail/worker/deploy.mjs‎

Copy file name to clipboardExpand all lines: nixos/services/id-mail/worker/deploy.mjs
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ const PLACEHOLDER = "{code}";
2020
// check silently treated every unrecognized argument as a request for
2121
// the real deploy sequence (retire, deploy, secret put).
2222
const args = process.argv.slice(2);
23-
if (args.length > 1 || args.some((arg) => arg !== "--dry-run")) {
24-
console.error("usage: deploy.mjs [--dry-run]");
23+
const unknownArgs = args.filter((arg) => arg !== "--dry-run");
24+
if (args.length > 1 || unknownArgs.length > 0) {
25+
const offenders = unknownArgs.length > 0 ? unknownArgs : args;
26+
console.error(`unrecognized argument(s): ${offenders.join(" ")}\nusage: deploy.mjs [--dry-run]`);
2527
process.exit(2);
2628
}
2729
const dryRun = args.includes("--dry-run");
Collapse file

‎nixos/services/id-mail/worker/deploy.test.mjs‎

Copy file name to clipboard
+99Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Probe for deploy.mjs argument handling (issue #3281).
2+
//
3+
// Runs deploy.mjs in a temp dir with stubbed `bws` / `wrangler` binaries on
4+
// PATH and a stubbed global fetch (via --import), and pins the three cases:
5+
// --dry-run -> validation only, exits 0, nothing deployed
6+
// --dry-rnu -> usage error, non-zero exit, ZERO external calls logged
7+
// (no args) -> the real deploy sequence runs against the stubs
8+
// Run with: node --test deploy.test.mjs
9+
import assert from "node:assert/strict";
10+
import { execFile } from "node:child_process";
11+
import { chmodSync, copyFileSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
12+
import { tmpdir } from "node:os";
13+
import { dirname, join } from "node:path";
14+
import test from "node:test";
15+
import { fileURLToPath } from "node:url";
16+
import { promisify } from "node:util";
17+
18+
const run = promisify(execFile);
19+
const here = dirname(fileURLToPath(import.meta.url));
20+
21+
function makeSandbox() {
22+
const dir = mkdtempSync(join(tmpdir(), "deploy-probe-"));
23+
const bin = join(dir, "bin");
24+
mkdirSync(bin);
25+
copyFileSync(join(here, "deploy.mjs"), join(dir, "deploy.mjs"));
26+
copyFileSync(join(here, "config.json"), join(dir, "config.json"));
27+
const log = join(dir, "calls.log");
28+
writeFileSync(log, "");
29+
// bws stub: logs the call, returns a stub value for every secret
30+
// deploy.mjs looks up (the account token plus each caller's tokenKey,
31+
// derived from config.json so the probe survives config edits).
32+
const config = JSON.parse(readFileSync(join(here, "config.json"), "utf8"));
33+
const keys = ["cloudflare.api-token-account-wide", ...Object.values(config.callers).map((caller) => caller.tokenKey)];
34+
const secretsJson = JSON.stringify(keys.map((key) => ({ key, value: `stub-${key}` })));
35+
writeFileSync(join(bin, "bws"), `#!/bin/sh\necho "bws $@" >> "${log}"\nprintf '%s' '${secretsJson}'\n`);
36+
writeFileSync(join(bin, "wrangler"), `#!/bin/sh\necho "wrangler $@" >> "${log}"\nexit 0\n`);
37+
chmodSync(join(bin, "bws"), 0o755);
38+
chmodSync(join(bin, "wrangler"), 0o755);
39+
// fetch stub: every retired Worker reports 404 (already gone), so the
40+
// retire loop logs and moves on without a wrangler delete.
41+
const fetchStub = join(dir, "fetch-stub.mjs");
42+
writeFileSync(fetchStub, `globalThis.fetch = async () => ({ status: 404, ok: false });\n`);
43+
return { dir, bin, log, fetchStub };
44+
}
45+
46+
async function runDeploy(sb, args) {
47+
try {
48+
const { stdout, stderr } = await run("node", ["--import", sb.fetchStub, join(sb.dir, "deploy.mjs"), ...args], {
49+
env: {
50+
...process.env,
51+
PATH: `${sb.bin}:${process.env.PATH}`,
52+
CLOUDFLARE_ACCOUNT_ID: "stub-account",
53+
},
54+
});
55+
return { code: 0, stdout, stderr };
56+
} catch (error) {
57+
return { code: error.code, stdout: error.stdout ?? "", stderr: error.stderr ?? "" };
58+
}
59+
}
60+
61+
test("--dry-run validates only and deploys nothing", async () => {
62+
const sb = makeSandbox();
63+
const result = await runDeploy(sb, ["--dry-run"]);
64+
assert.equal(result.code, 0, result.stderr);
65+
assert.match(result.stdout, /nothing deployed/);
66+
const calls = readFileSync(sb.log, "utf8");
67+
assert.match(calls, /bws secret list/);
68+
assert.match(calls, /wrangler deploy --dry-run/);
69+
assert.doesNotMatch(calls, /wrangler deploy --config/);
70+
assert.doesNotMatch(calls, /secret put/);
71+
});
72+
73+
test("--dry-rnu (typo) aborts with a usage error before any external call", async () => {
74+
const sb = makeSandbox();
75+
const result = await runDeploy(sb, ["--dry-rnu"]);
76+
assert.notEqual(result.code, 0);
77+
assert.match(result.stderr, /usage: deploy\.mjs \[--dry-run\]/);
78+
assert.equal(readFileSync(sb.log, "utf8"), "", "no bws/wrangler call may be logged");
79+
});
80+
81+
test("--bogus-flag aborts with a usage error before any external call", async () => {
82+
const sb = makeSandbox();
83+
const result = await runDeploy(sb, ["--bogus-flag"]);
84+
assert.notEqual(result.code, 0);
85+
assert.match(result.stderr, /unrecognized argument\(s\): --bogus-flag/);
86+
assert.equal(readFileSync(sb.log, "utf8"), "", "no bws/wrangler call may be logged");
87+
});
88+
89+
test("no args runs the real deploy sequence against the stubs", async () => {
90+
const sb = makeSandbox();
91+
const result = await runDeploy(sb, []);
92+
assert.equal(result.code, 0, result.stderr);
93+
assert.match(result.stdout, /deployed mail with callers/);
94+
const calls = readFileSync(sb.log, "utf8");
95+
assert.match(calls, /bws secret list/);
96+
assert.match(calls, /wrangler deploy --dry-run/);
97+
assert.match(calls, /wrangler deploy --config/);
98+
assert.match(calls, /wrangler secret put CALLERS/);
99+
});
Collapse file

‎nixos/services/id-mail/worker/package.json‎

Copy file name to clipboard
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"name": "mail",
33
"private": true,
4-
"type": "module"
4+
"type": "module",
5+
"scripts": {
6+
"test": "node --test deploy.test.mjs"
7+
}
58
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.