Repository navigation
Description
Problem
nixos/services/id-mail/worker/deploy.mjs opens with the promise that it "Validates config.json" before any bws/wrangler/Cloudflare work, and validate() (deploy.mjs:124-179) is written as an aggregator: it collects every problem into a list and the caller throws one config.json is invalid: error naming them all (deploy.mjs:34-37). That contract fails for two classes of shape the validator itself is the last line of defense against:
1. validate() crashes on null entries instead of reporting them
validate() dereferences nested entries without a null/object check, so a config carrying a null where an object belongs dies with a raw TypeError naming no config field, and any other problems in the same config are never reported:
- top-level
nullconfig →TypeError: Cannot read properties of null (reading 'worker')at deploy.mjs:135 (the very first check) templates: [null]→TypeError ... (reading 'subject')at deploy.mjs:153callers: { "amd": null }→TypeError ... (reading 'tokenKey')at deploy.mjs:163- a null grant (
callers.amd.transports.email: null) →TypeError ... (reading 'mode')at deploy.mjs:169
Control: a merely wrong value (e.g. worker: "BAD NAME") is reported correctly — Error: config.json is invalid:\n worker must be a lowercase name — so the aggregator works for scalar mistakes and only collapses on null object entries.
2. A config that passes validation crashes the real deploy: retire is optional to validate(), required by the deploy flow
validate() checks c.retire ?? [] (deploy.mjs:141 — an absent retire is valid), but the deploy sequence iterates it unconditionally at deploy.mjs:87: for (const name of config.retire). A config with no retire key:
- passes
validate()and--dry-runexits 0 printingdry run: mail config is valid, nothing deployed— the operator is told the config is valid; - the real deploy then crashes with
TypeError: config.retire is not iterableat deploy.mjs:87, after the bws secret read and thewrangler deploy --dry-runstep have already run (observed in the stub call log), midway through the deploy sequence.
Evidence
Verified this run on the laptop against main @ 63f83bef5a, probe ~/git/fleet/probe-idmail-deploy (the real deploy.mjs verbatim, stub bws/wrangler binaries and a stubbed fetch, the same harness as deploy.test.mjs):
- control (the committed
config.json,--dry-run): exit 0,config is valid, nothing deployed - bad-name control: clean aggregated validation error, zero external calls
- the four null shapes above: raw
TypeErrorfrom insidevalidate(), zero external calls, no aggregated report retireomitted:--dry-runexit 0; real run exit 1 withTypeError: config.retire is not iterableat deploy.mjs:87 afterbws secret list+wrangler deploy --dry-runhad already executed
Why it matters
This deploy script is the guarded door for a production mail Worker: #3281 already established that it must fail closed and say why before touching anything external, because its sequence retires (force-deletes) Workers and resets secrets. A validator that crashes on the malformed shapes it exists to catch — and that blesses a config the deploy flow then crashes on halfway through the sequence — sends the operator debugging the validator instead of their config, at exactly the moment the config is broken.
Acceptance criteria
-
validate()never throws for any JSON value ofconfig.json(null/scalar/array top level; null or non-object template, caller, or grant entries): every problem is returned in the aggregated list, each naming the config path it belongs to (e.g.templates[0] must be an object/callers.<name> must be an object), and the run ends with the existingconfig.json is invalid:error and zero external calls. -
retireoptionality agrees between validation and the deploy flow: either validation requires it, or the flow tolerates its absence (config.retire ?? []) — a config that passes--dry-runmust complete the full (stubbed) deploy sequence without aTypeError. - Regression coverage in
deploy.test.mjs(same stub harness): the null-entry shapes produce the aggregated validation error with no bws/wrangler calls logged, and a no-retireconfig completes the deploy sequence against the stubs. - The committed
config.jsonstill validates and--dry-runstill exits 0; the existing id-mail(worker deploy): unrecognized arguments are silently ignored — a typo'd --dry-rnu enters the real deploy sequence and force-deletes the retired 'id-mail' Worker #3281 argument tests still pass.
Activity
developing-today commentedon Nov 7, 2026
CODE-2195
dezren39 commentedon Nov 7, 2026
🤖 Agent note · state: filed
dezren39 commentedon Nov 7, 2026
Additional verified shapes in the same validator (same probe, same run, before fixing):
transports: "email"andtransports: 5→TypeError: (c.transports ?? []).every is not a function;templates: 5andtemplates: {}→TypeError: ... is not iterablefrom the template loop. Control:limits: nullis reported correctly through the aggregatedconfig.json is invalid:error, so the fix scope is exactly the unguarded spots: top-level value, transports.every/.includes, the templates loop, template/caller/grant entries, and theretireflow mismatch. All are covered by the self-solve in progress.dezren39 commentedon Nov 7, 2026
🤖 Agent note · state: done
config.json is invalid:report naming the field; no TypeError, zero external calls), and the deploy flow iteratesconfig.retire ?? [], matching validation. Post-fix probe: all malformed shapes produce the aggregated error; control and retire-less configs complete the (stubbed) deploy. New deploy.test.mjs cases fail pre-fix (2 fail / 4 pass), full worker suite 11/11 on the branch and on merged main e874ed2.