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 — Merge pull request #13753 from developing-today/queue/3403-production… · developing-today/code@cec643b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github
    • test-suite-registry.json
  • pkgs/id/hosted-worker
    • package.json
    • src
      • enablement.ts
      • provisioning.ts
    • test
      • enablement.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/test-suite-registry.json‎

Copy file name to clipboardExpand all lines: .github/test-suite-registry.json
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@
284284
"pkgs/id/hosted-worker/test/routing.test.ts",
285285
"pkgs/id/hosted-worker/test/admission-gate.test.ts",
286286
"pkgs/id/hosted-worker/test/provisioning.test.ts",
287+
"pkgs/id/hosted-worker/test/provisioning-surface.test.ts",
288+
"pkgs/id/hosted-worker/test/enablement.test.ts",
287289
"pkgs/id/hosted-worker/test/blobs.test.ts",
288290
"pkgs/id/hosted-worker/test/canonical-cbor.test.ts",
289291
"pkgs/id/hosted-worker/test/usage.test.ts",
@@ -297,7 +299,7 @@
297299
"pkgs/id/hosted-worker/test/bridge-session.test.ts",
298300
"pkgs/id/hosted-worker/test/bridge-do.test.ts"
299301
],
300-
"invocation": "cd pkgs/id/hosted-worker && npm test (node --experimental-transform-types --test test/routing.test.ts test/admission-gate.test.ts test/provisioning.test.ts test/blobs.test.ts test/canonical-cbor.test.ts test/usage.test.ts test/currency.test.ts test/front-door.test.ts test/id-uri-vectors.test.ts test/bridge-blake3.test.ts test/bridge-event.test.ts test/bridge-range.test.ts test/bridge-store.test.ts test/bridge-session.test.ts test/bridge-do.test.ts)",
302+
"invocation": "cd pkgs/id/hosted-worker && npm test (node --experimental-transform-types --test test/routing.test.ts test/admission-gate.test.ts test/provisioning.test.ts test/provisioning-surface.test.ts test/enablement.test.ts test/blobs.test.ts test/canonical-cbor.test.ts test/usage.test.ts test/currency.test.ts test/front-door.test.ts test/id-uri-vectors.test.ts test/bridge-blake3.test.ts test/bridge-event.test.ts test/bridge-range.test.ts test/bridge-store.test.ts test/bridge-session.test.ts test/bridge-do.test.ts)",
301303
"venue": {
302304
"workflow": ".github/workflows/id-hosted-worker-tests.yml",
303305
"job_step": "hosted-worker-tests / Run the hosted-worker routing suite",
Collapse file

‎pkgs/id/hosted-worker/package.json‎

Copy file name to clipboardExpand all lines: pkgs/id/hosted-worker/package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"dev": "wrangler dev",
88
"typecheck": "tsc --noEmit",
9-
"test": "node --experimental-transform-types --test test/routing.test.ts test/admission-gate.test.ts test/provisioning.test.ts test/provisioning-surface.test.ts test/blobs.test.ts test/canonical-cbor.test.ts test/usage.test.ts test/currency.test.ts test/front-door.test.ts test/id-uri-vectors.test.ts test/bridge-blake3.test.ts test/bridge-event.test.ts test/bridge-range.test.ts test/bridge-store.test.ts test/bridge-session.test.ts test/bridge-do.test.ts test/export.test.ts",
9+
"test": "node --experimental-transform-types --test test/routing.test.ts test/admission-gate.test.ts test/provisioning.test.ts test/provisioning-surface.test.ts test/enablement.test.ts test/blobs.test.ts test/canonical-cbor.test.ts test/usage.test.ts test/currency.test.ts test/front-door.test.ts test/id-uri-vectors.test.ts test/bridge-blake3.test.ts test/bridge-event.test.ts test/bridge-range.test.ts test/bridge-store.test.ts test/bridge-session.test.ts test/bridge-do.test.ts test/export.test.ts",
1010
"smoke": "node smoke/smoke.mjs"
1111
},
1212
"devDependencies": {
Collapse file

‎pkgs/id/hosted-worker/src/enablement.ts‎

Copy file name to clipboard
+111Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Production enablement point for hosted signup and migration
2+
// (#3403; decision record on #3403, 2026-11-22). The provisioning
3+
// gate (./provisioning.ts) validates a configuration against
4+
// deployed-account evidence and returns a plan; this module is the
5+
// only place that plan becomes production enablement, and the only
6+
// place that answers whether production signup or migration may run.
7+
//
8+
// Visibility is the acceptance criterion. Today there is no live
9+
// production signup/migration enable path — the deployment surface
10+
// is local-only — so the criterion "production cannot enable
11+
// signup or migration with missing/unverified jurisdiction,
12+
// unsupported runtime/types, or missing/mismatched bucket" holds
13+
// vacuously. The failure mode this module closes is the inverse:
14+
// if a caller could enable production with a structurally identical
15+
// but never-validated plan, the gate's verdict would be decorative.
16+
// So creation accepts only a value issued by `validateEnablement`
17+
// (established by identity, never by re-spelling the fields), and
18+
// the per-mode check accepts only a value issued here. A forged
19+
// look-alike, however exact, is refused as `unvalidated_plan`; an
20+
// absent enablement leaves every mode `production_disabled`.
21+
//
22+
// Nothing here authorizes a deployment or makes a residency claim:
23+
// the plan carries the gate's consumed evidence shape, not a vendor
24+
// guarantee.
25+
26+
import { FailClosed } from "./routing.ts";
27+
import { isValidatedEnablementPlan } from "./provisioning.ts";
28+
import type { EnablementPlan } from "./provisioning.ts";
29+
import type { Jurisdiction } from "./routing.ts";
30+
31+
/** The production hosted modes this enablement point knows. Signup
32+
* and migration enable independently; anything else is refused as
33+
* `unknown_enablement_mode`. */
34+
export const HOSTED_PRODUCTION_MODES = ["signup", "migration"] as const;
35+
export type HostedProductionMode = (typeof HOSTED_PRODUCTION_MODES)[number];
36+
37+
/** An active production enablement: the gate's plan plus the modes
38+
* it authorizes. Frozen at creation along with its plan; enabling a
39+
* mode outside `HOSTED_PRODUCTION_MODES` is impossible. */
40+
export interface ProductionEnablement {
41+
readonly jurisdiction: Jurisdiction;
42+
readonly durableObjectBinding: string;
43+
readonly bucket: { readonly binding: string; readonly bucketName: string; readonly jurisdiction: Jurisdiction };
44+
readonly modes: readonly HostedProductionMode[];
45+
}
46+
47+
/** The enablements this module has issued. Module-private: a value
48+
* carried here has passed through `createProductionEnablement` with
49+
* the gate's own verdict, so `requireProductionEnablement`
50+
* answers on authority rather than on shape. */
51+
const issuedEnablements = new WeakSet<object>();
52+
53+
function orderModes(modes: readonly HostedProductionMode[]): HostedProductionMode[] {
54+
return HOSTED_PRODUCTION_MODES.filter((m) => modes.includes(m));
55+
}
56+
57+
/** Create the production enablement for the gate's plan. Accepts
58+
* only a plan object returned by `validateEnablement` — a forged
59+
* copy of its fields throws FailClosed(503, "unvalidated_plan").
60+
* Modes outside `HOSTED_PRODUCTION_MODES` throw `unknown_enablement_mode`;
61+
* an empty mode list throws `no_enablement_mode`. */
62+
export function createProductionEnablement(plan: unknown, modes: readonly string[]): ProductionEnablement {
63+
if (!isValidatedEnablementPlan(plan)) {
64+
throw new FailClosed(
65+
503,
66+
"unvalidated_plan",
67+
"production enablement requires the provisioning gate's validated plan, not a re-spelled configuration",
68+
);
69+
}
70+
const unknown = modes.filter(
71+
(m): m is string => !(HOSTED_PRODUCTION_MODES as readonly string[]).includes(m),
72+
);
73+
if (unknown.length > 0) {
74+
throw new FailClosed(
75+
503,
76+
"unknown_enablement_mode",
77+
`unknown production enablement mode "${unknown[0]}"; failing closed`,
78+
);
79+
}
80+
if (modes.length === 0) {
81+
throw new FailClosed(503, "no_enablement_mode", "production enablement requires at least one mode");
82+
}
83+
const enablement: ProductionEnablement = Object.freeze({
84+
jurisdiction: plan.jurisdiction,
85+
durableObjectBinding: plan.durableObjectBinding,
86+
bucket: plan.bucket,
87+
modes: Object.freeze(orderModes(modes as HostedProductionMode[])),
88+
});
89+
issuedEnablements.add(enablement);
90+
return enablement;
91+
}
92+
93+
/** Answer whether a production mode may run. Refuses with
94+
* `production_disabled` when no enablement issued here is active,
95+
* and with `mode_not_enabled` when this enablement does not cover
96+
* the requested mode. Returns the enablement for callers that need
97+
* its plan details. */
98+
export function requireProductionEnablement(enablement: unknown, mode: HostedProductionMode): ProductionEnablement {
99+
if (typeof enablement !== "object" || enablement === null || !issuedEnablements.has(enablement)) {
100+
throw new FailClosed(
101+
503,
102+
"production_disabled",
103+
`production ${mode} is disabled: no provisioning-gate enablement is active`,
104+
);
105+
}
106+
const active = enablement as ProductionEnablement;
107+
if (!active.modes.includes(mode)) {
108+
throw new FailClosed(503, "mode_not_enabled", `production ${mode} is not enabled; failing closed`);
109+
}
110+
return active;
111+
}
Collapse file

‎pkgs/id/hosted-worker/src/provisioning.ts‎

Copy file name to clipboardExpand all lines: pkgs/id/hosted-worker/src/provisioning.ts
+24-3Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ function refuse(code: string, message: string): never {
8989
throw new FailClosed(503, code, message);
9090
}
9191

92+
/** The plans this module has issued. Module-private: a value carried
93+
* here cannot be constructed outside `validateEnablement`, so a
94+
* production enablement path can require the gate's verdict itself
95+
* rather than a look-alike object that merely spells its fields. */
96+
const issuedPlans = new WeakSet<object>();
97+
98+
/** True only for a plan object returned by `validateEnablement`.
99+
* Structural equality is not enough — the gate's verdict is what
100+
* authorizes enablement. */
101+
export function isValidatedEnablementPlan(value: unknown): value is EnablementPlan {
102+
return typeof value === "object" && value !== null && issuedPlans.has(value);
103+
}
104+
105+
/** Validate a configuration against deployed-account evidence and
106+
* return the frozen plan a production deployment may enable. The
107+
* returned object is registered here, so
108+
* `isValidatedEnablementPlan` distinguishes it from a look-alike: the
109+
* production enablement point (./enablement.ts) accepts only this
110+
* verdict, never a re-spelled configuration. */
92111
export function validateEnablement(config: EnablementConfig, evidence: AccountEvidence): EnablementPlan {
93112
// 1. The jurisdiction must be explicitly configured and supported.
94113
// The design's policy constant is not a silent runtime fallback: an
@@ -189,9 +208,11 @@ export function validateEnablement(config: EnablementConfig, evidence: AccountEv
189208
);
190209
}
191210

192-
return {
211+
const plan: EnablementPlan = Object.freeze({
193212
jurisdiction,
194213
durableObjectBinding: config.durableObjectBinding,
195-
bucket: { binding: bucket.binding, bucketName: bucket.bucketName, jurisdiction },
196-
};
214+
bucket: Object.freeze({ binding: bucket.binding, bucketName: bucket.bucketName, jurisdiction }),
215+
});
216+
issuedPlans.add(plan);
217+
return plan;
197218
}
Collapse file

‎pkgs/id/hosted-worker/test/enablement.test.ts‎

Copy file name to clipboard
+142Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import { test } from "node:test";
2+
import assert from "node:assert/strict";
3+
import { FailClosed } from "../src/routing.ts";
4+
import {
5+
validateEnablement,
6+
type AccountEvidence,
7+
type EnablementConfig,
8+
type EnablementPlan,
9+
} from "../src/provisioning.ts";
10+
import {
11+
createProductionEnablement,
12+
requireProductionEnablement,
13+
HOSTED_PRODUCTION_MODES,
14+
} from "../src/enablement.ts";
15+
16+
// Tests for the #3403 production enablement point: the place any
17+
// production hosted signup or migration path must pass through. The
18+
// acceptance criterion is that production cannot enable signup or
19+
// migration without the provisioning gate's verdict, so an
20+
// enablement that was not produced by `validateEnablement` — a
21+
// hand-built look-alike plan, a configuration object, a literal — is
22+
// not enablement at all, and an absent enablement leaves both modes
23+
// disabled.
24+
25+
const US_CONFIG: EnablementConfig = {
26+
jurisdiction: "us",
27+
restrictedNamespace: true,
28+
durableObjectBinding: "USERS",
29+
bucket: { binding: "BLOBS_US", bucketName: "user-blobs-us", declaredJurisdiction: "us" },
30+
};
31+
32+
const US_EVIDENCE: AccountEvidence = {
33+
jurisdictions: { us: { durableObjects: "supported", runtimeTypes: "supported" } },
34+
buckets: [{ bucketName: "user-blobs-us", actualJurisdiction: "us" }],
35+
};
36+
37+
function refusal(fn: () => unknown): { code: string; status: number } {
38+
try {
39+
fn();
40+
} catch (e) {
41+
if (e instanceof FailClosed) return { code: e.code, status: e.status };
42+
throw e;
43+
}
44+
throw new Error("expected a FailClosed refusal, but the call was allowed");
45+
}
46+
47+
test("a plan issued by the provisioning gate enables the requested modes", () => {
48+
const plan = validateEnablement(US_CONFIG, US_EVIDENCE);
49+
const enablement = createProductionEnablement(plan, ["signup", "migration"]);
50+
assert.deepEqual(enablement.modes, ["signup", "migration"]);
51+
assert.equal(enablement.jurisdiction, "us");
52+
assert.equal(enablement.durableObjectBinding, "USERS");
53+
assert.deepEqual(enablement.bucket, { binding: "BLOBS_US", bucketName: "user-blobs-us", jurisdiction: "us" });
54+
assert.equal(Object.isFrozen(enablement), true);
55+
assert.equal(Object.isFrozen(enablement.modes), true);
56+
});
57+
58+
test("a hand-built plan that copies the gate's fields is not a validated plan", () => {
59+
// The production path is reachable only with the gate's verdict,
60+
// and structural equality must not stand in for it: otherwise
61+
// anything that can spell the fields could enable production
62+
// without ever consuming deployed-account evidence.
63+
const forged: EnablementPlan = {
64+
jurisdiction: "us",
65+
durableObjectBinding: "USERS",
66+
bucket: { binding: "BLOBS_US", bucketName: "user-blobs-us", jurisdiction: "us" },
67+
};
68+
assert.deepEqual(validateEnablement(US_CONFIG, US_EVIDENCE), forged);
69+
assert.deepEqual(refusal(() => createProductionEnablement(forged, ["signup"])), {
70+
code: "unvalidated_plan",
71+
status: 503,
72+
});
73+
});
74+
75+
test("a configuration object is not a validated plan", () => {
76+
assert.equal(refusal(() => createProductionEnablement(US_CONFIG, ["signup"])).code, "unvalidated_plan");
77+
assert.equal(refusal(() => createProductionEnablement(null, ["signup"])).code, "unvalidated_plan");
78+
assert.equal(refusal(() => createProductionEnablement(undefined, ["signup"])).code, "unvalidated_plan");
79+
});
80+
81+
test("enablement must name at least one production mode", () => {
82+
const plan = validateEnablement(US_CONFIG, US_EVIDENCE);
83+
assert.equal(refusal(() => createProductionEnablement(plan, [])).code, "no_enablement_mode");
84+
});
85+
86+
test("enablement rejects modes other than signup and migration", () => {
87+
const plan = validateEnablement(US_CONFIG, US_EVIDENCE);
88+
assert.equal(refusal(() => createProductionEnablement(plan, ["backfill"])).code, "unknown_enablement_mode");
89+
assert.equal(
90+
refusal(() => createProductionEnablement(plan, ["signup", "unrestricted"])).code,
91+
"unknown_enablement_mode",
92+
);
93+
assert.deepEqual([...HOSTED_PRODUCTION_MODES], ["signup", "migration"]);
94+
});
95+
96+
test("duplicate modes collapse to the canonical order", () => {
97+
const plan = validateEnablement(US_CONFIG, US_EVIDENCE);
98+
assert.deepEqual(createProductionEnablement(plan, ["migration", "signup", "signup"]).modes, [
99+
"signup",
100+
"migration",
101+
]);
102+
});
103+
104+
test("with no enablement active, production signup and migration are both disabled", () => {
105+
for (const mode of HOSTED_PRODUCTION_MODES) {
106+
assert.deepEqual(refusal(() => requireProductionEnablement(null, mode)), {
107+
code: "production_disabled",
108+
status: 503,
109+
});
110+
assert.equal(refusal(() => requireProductionEnablement(undefined, mode)).code, "production_disabled");
111+
}
112+
});
113+
114+
test("a hand-built enablement is not an enablement", () => {
115+
const forged = {
116+
jurisdiction: "us",
117+
durableObjectBinding: "USERS",
118+
bucket: { binding: "BLOBS_US", bucketName: "user-blobs-us", jurisdiction: "us" },
119+
modes: ["signup", "migration"],
120+
};
121+
assert.equal(refusal(() => requireProductionEnablement(forged, "signup")).code, "production_disabled");
122+
});
123+
124+
test("a mode that was not enabled is refused even when the other is", () => {
125+
const plan = validateEnablement(US_CONFIG, US_EVIDENCE);
126+
const signupOnly = createProductionEnablement(plan, ["signup"]);
127+
assert.equal(requireProductionEnablement(signupOnly, "signup"), signupOnly);
128+
assert.deepEqual(refusal(() => requireProductionEnablement(signupOnly, "migration")), {
129+
code: "mode_not_enabled",
130+
status: 503,
131+
});
132+
});
133+
134+
test("a gate-issued plan cannot be edited to widen what it enables", () => {
135+
const plan = validateEnablement(US_CONFIG, US_EVIDENCE);
136+
assert.equal(Object.isFrozen(plan), true);
137+
assert.equal(Object.isFrozen(plan.bucket), true);
138+
assert.throws(() => {
139+
(plan as { jurisdiction: string }).jurisdiction = "fedramp";
140+
}, TypeError);
141+
assert.equal(plan.jurisdiction, "us");
142+
});

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.