[codex] Structure relay domain label errors (#3347)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
71608142c2
commit
cc69aef4dd
2 files changed
+46
-1
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import {
|
||||
managedEndpointDigestInput,
|
||||
@@ -7,11 +8,14 @@ import {
|
||||
isManagedEndpointHostname,
|
||||
managedEndpointTunnelName,
|
||||
relayOwnsManagedEndpointZone,
|
||||
RelayPublicDomainLabelTooLongError,
|
||||
relayPublicDomainForStage,
|
||||
relayResourceNameForStage,
|
||||
relayStageSlug,
|
||||
} from "./deploymentConfig.ts";
|
||||
|
||||
const isRelayPublicDomainLabelTooLongError = Schema.is(RelayPublicDomainLabelTooLongError);
|
||||
|
||||
describe("relayStageSlug", () => {
|
||||
it("matches Alchemy physical-name sanitization for default developer stages", () => {
|
||||
expect(relayStageSlug("dev_julius")).toBe("dev-julius");
|
||||
@@ -28,6 +32,29 @@ describe("relayPublicDomainForStage", () => {
|
||||
"relay-dev-julius.example.com",
|
||||
);
|
||||
});
|
||||
|
||||
it("reports the stage and derived DNS label when the label is too long", () => {
|
||||
const stage = `dev_${"x".repeat(60)}`;
|
||||
let error: unknown;
|
||||
|
||||
try {
|
||||
relayPublicDomainForStage(stage, "example.com");
|
||||
} catch (cause) {
|
||||
error = cause;
|
||||
}
|
||||
|
||||
if (!isRelayPublicDomainLabelTooLongError(error)) {
|
||||
throw error;
|
||||
}
|
||||
expect(error).toMatchObject({
|
||||
stage,
|
||||
label: `relay-dev-${"x".repeat(60)}`,
|
||||
maxLength: 63,
|
||||
});
|
||||
expect(error.message).toBe(
|
||||
`Relay stage '${stage}' produces custom domain label 'relay-dev-${"x".repeat(60)}' (70 characters), exceeding the DNS label limit of 63.`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("relayOwnsManagedEndpointZone", () => {
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
import type { RelayManagedEndpoint } from "@t3tools/contracts/relay";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
const DNS_LABEL_MAX_LENGTH = 63;
|
||||
const MANAGED_ENDPOINT_HASH_LENGTH = 16;
|
||||
const MANAGED_ENDPOINT_TUNNEL_PREFIX = "t3coderelay-managedendpoint";
|
||||
export const MANAGED_ENDPOINT_ZONE_OWNER_STAGE = "prod";
|
||||
|
||||
export class RelayPublicDomainLabelTooLongError extends Schema.TaggedErrorClass<RelayPublicDomainLabelTooLongError>()(
|
||||
"RelayPublicDomainLabelTooLongError",
|
||||
{
|
||||
stage: Schema.String,
|
||||
label: Schema.String,
|
||||
maxLength: Schema.Number,
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `Relay stage '${this.stage}' produces custom domain label '${this.label}' (${this.label.length} characters), exceeding the DNS label limit of ${this.maxLength}.`;
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeZoneName(zoneName: string): string {
|
||||
return zoneName
|
||||
.trim()
|
||||
@@ -62,7 +76,11 @@ export function relayPublicDomainForStage(stage: string, zoneName: string): stri
|
||||
const stageSlug = relayStageSlug(stage);
|
||||
const relayLabel = stage === "prod" ? "relay" : `relay-${stageSlug}`;
|
||||
if (relayLabel.length > DNS_LABEL_MAX_LENGTH) {
|
||||
throw new Error(`Relay stage is too long for a custom domain: ${stage}`);
|
||||
throw new RelayPublicDomainLabelTooLongError({
|
||||
stage,
|
||||
label: relayLabel,
|
||||
maxLength: DNS_LABEL_MAX_LENGTH,
|
||||
});
|
||||
}
|
||||
return `${relayLabel}.${normalizeZoneName(zoneName)}`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user