Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { describe, expect, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import * as Path from "effect/Path";
6
7import {
8 hasDeployChanges,
9 missingRelayPublicConfigFields,
10 publicConfigFromOutput,
11 reconcileRootEnvPublicConfig,
12 RelayDeployError,
13 RelayDeployPublicConfigUnavailableError,
14 serializeGithubOutput,
15 serializeRelayClientTracingEnvironment,
16} from "./deploy.ts";
17
18describe("RelayDeployError", () => {
19 it("reports the incomplete state source, stage, and missing fields", () => {
20 const missingFields = missingRelayPublicConfigFields({
21 url: "https://relay.example.test",
22 mobileTracingUrl: "https://api.axiom.co/v1/traces",
23 });
24 const error = new RelayDeployError({
25 source: "alchemy_state",
26 stage: "production",
27 missingFields,
28 });
29
30 expect(error).toMatchObject({
31 source: "alchemy_state",
32 stage: "production",
33 missingFields: [
34 "mobileTracingDataset",
35 "mobileTracingToken",
36 "clientTracingUrl",
37 "clientTracingDataset",
38 "clientTracingToken",
39 ],
40 });
41 expect(error.message).toBe(
42 "Relay deploy output from 'alchemy_state' for stage 'production' is missing required public config fields: mobileTracingDataset, mobileTracingToken, clientTracingUrl, clientTracingDataset, clientTracingToken",
43 );
44 });
45
46 it("distinguishes deploy results that do not produce public config", () => {
47 const error = new RelayDeployPublicConfigUnavailableError({
48 result: "dry-run",
49 stage: "production",
50 outputPath: "/tmp/relay-client.env",
51 });
52
53 expect(error.message).toBe(
54 "Relay deploy result 'dry-run' for stage 'production' did not produce public config required by GitHub environment output '/tmp/relay-client.env'.",
55 );
56 });
57});
58
59describe("hasDeployChanges", () => {
60 it("detects resource, binding, and deletion changes", () => {
61 expect(hasDeployChanges({ resources: {}, deletions: {} } as never)).toBe(false);
62 expect(
63 hasDeployChanges({
64 resources: {
65 api: { action: "create", bindings: [] },
66 },
67 deletions: {},
68 } as never),
69 ).toBe(true);
70 expect(
71 hasDeployChanges({
72 resources: {
73 api: { action: "noop", bindings: [{ action: "update" }] },
74 },
75 deletions: {},
76 } as never),
77 ).toBe(true);
78 expect(
79 hasDeployChanges({
80 resources: {},
81 deletions: {
82 api: { action: "delete", bindings: [] },
83 },
84 } as never),
85 ).toBe(true);
86 });
87});
88
89describe("reconcileRootEnvPublicConfig", () => {
90 const config = {
91 relayUrl: "https://relay.example.test",
92 mobileTracingUrl: "https://api.axiom.co/v1/traces",
93 mobileTracingDataset: "t3-code-mobile-traces-dev",
94 mobileTracingToken: "xaat-public-ingest",
95 clientTracingUrl: "https://api.axiom.co/v1/traces",
96 clientTracingDataset: "t3-code-relay-client-traces-dev",
97 clientTracingToken: "xaat-relay-client-ingest",
98 } as const;
99
100 it("adds the complete local client config", () => {
101 expect(reconcileRootEnvPublicConfig("", config)).toBe(
102 [
103 "T3CODE_RELAY_URL=https://relay.example.test",
104 "T3CODE_MOBILE_OTLP_TRACES_URL=https://api.axiom.co/v1/traces",
105 "T3CODE_MOBILE_OTLP_TRACES_DATASET=t3-code-mobile-traces-dev",
106 "T3CODE_MOBILE_OTLP_TRACES_TOKEN=xaat-public-ingest",
107 "T3CODE_RELAY_CLIENT_OTLP_TRACES_URL=https://api.axiom.co/v1/traces",
108 "T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET=t3-code-relay-client-traces-dev",
109 "T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN=xaat-relay-client-ingest",
110 "",
111 ].join("\n"),
112 );
113 });
114
115 it("replaces stale values while preserving unrelated entries", () => {
116 expect(
117 reconcileRootEnvPublicConfig(
118 [
119 "T3CODE_CLERK_PUBLISHABLE_KEY=pk_test_example",
120 "T3CODE_RELAY_URL=https://old.example.test",
121 "T3CODE_MOBILE_OTLP_TRACES_URL=https://old.example.test/v1/traces",
122 "T3CODE_MOBILE_OTLP_TRACES_DATASET=old-dataset",
123 "T3CODE_MOBILE_OTLP_TRACES_TOKEN=old-token",
124 "T3CODE_RELAY_CLIENT_OTLP_TRACES_URL=https://old.example.test/v1/traces",
125 "T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET=old-client-dataset",
126 "T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN=old-client-token",
127 "",
128 ].join("\n"),
129 config,
130 ),
131 ).toBe(
132 [
133 "T3CODE_CLERK_PUBLISHABLE_KEY=pk_test_example",
134 "T3CODE_RELAY_URL=https://relay.example.test",
135 "T3CODE_MOBILE_OTLP_TRACES_URL=https://api.axiom.co/v1/traces",
136 "T3CODE_MOBILE_OTLP_TRACES_DATASET=t3-code-mobile-traces-dev",
137 "T3CODE_MOBILE_OTLP_TRACES_TOKEN=xaat-public-ingest",
138 "T3CODE_RELAY_CLIENT_OTLP_TRACES_URL=https://api.axiom.co/v1/traces",
139 "T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET=t3-code-relay-client-traces-dev",
140 "T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN=xaat-relay-client-ingest",
141 "",
142 ].join("\n"),
143 );
144 });
145});
146
147describe("serializeGithubOutput", () => {
148 it("serializes relay deploy metadata for GitHub Actions outputs", () => {
149 expect(
150 serializeGithubOutput({
151 changed: false,
152 result: "noop",
153 relay_url: "https://relay.example.test",
154 }),
155 ).toBe("changed=false\nresult=noop\nrelay_url=https://relay.example.test\n");
156 });
157});
158
159describe("serializeRelayClientTracingEnvironment", () => {
160 it("serializes tracing config for downstream GITHUB_ENV loading", () => {
161 expect(
162 serializeRelayClientTracingEnvironment({
163 relayUrl: "https://relay.example.test",
164 mobileTracingUrl: "https://api.axiom.co/v1/traces",
165 mobileTracingDataset: "mobile",
166 mobileTracingToken: "mobile-token",
167 clientTracingUrl: "https://api.axiom.co/v1/traces",
168 clientTracingDataset: "relay",
169 clientTracingToken: "client-token",
170 }),
171 ).toBe(
172 [
173 "T3CODE_RELAY_CLIENT_OTLP_TRACES_URL=https://api.axiom.co/v1/traces",
174 "T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET=relay",
175 "T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN=client-token",
176 "",
177 ].join("\n"),
178 );
179 });
180});
181
182describe("release workflow tracing config propagation", () => {
183 it.effect("uses an artifact instead of a masked cross-job token output", () =>
184 Effect.gen(function* () {
185 const fileSystem = yield* FileSystem.FileSystem;
186 const path = yield* Path.Path;
187 const workflowPath = yield* path.fromFileUrl(
188 new URL("../../../.github/workflows/release.yml", import.meta.url),
189 );
190 const workflow = yield* fileSystem.readFileString(workflowPath);
191
192 expect(workflow).not.toContain("client_tracing_token:");
193 expect(workflow).not.toContain("needs.relay_public_config.outputs.client_tracing_token");
194 expect(workflow).toContain('--github-env-file "$RUNNER_TEMP/relay-client-tracing.env"');
195 expect(workflow).toContain("name: relay-client-tracing-config");
196 expect(workflow).toContain('cat "$config_path" >> "$GITHUB_ENV"');
197 }).pipe(Effect.provide(NodeServices.layer)),
198 );
199});
200
201describe("publicConfigFromOutput", () => {
202 it("reads the complete public tracing config from persisted Alchemy output", () => {
203 expect(
204 publicConfigFromOutput({
205 url: "https://relay.example.test",
206 mobileTracingUrl: "https://api.axiom.co/v1/traces",
207 mobileTracingDataset: "mobile",
208 mobileTracingToken: "mobile-token",
209 clientTracingUrl: "https://api.axiom.co/v1/traces",
210 clientTracingDataset: "relay",
211 clientTracingToken: "client-token",
212 }),
213 ).toEqual({
214 relayUrl: "https://relay.example.test",
215 mobileTracingUrl: "https://api.axiom.co/v1/traces",
216 mobileTracingDataset: "mobile",
217 mobileTracingToken: "mobile-token",
218 clientTracingUrl: "https://api.axiom.co/v1/traces",
219 clientTracingDataset: "relay",
220 clientTracingToken: "client-token",
221 });
222 });
223
224 it("rejects incomplete stack output", () => {
225 expect(publicConfigFromOutput({ url: "https://relay.example.test" })).toBeNull();
226 });
227});