forked from pingdotgg/t3code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.test.ts
More file actions
207 lines (194 loc) · 7.47 KB
/
Copy pathdeploy.test.ts
File metadata and controls
207 lines (194 loc) · 7.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import * as NodeServices from "@effect/platform-node/NodeServices";
import { describe, expect, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Path from "effect/Path";
import {
hasDeployChanges,
publicConfigFromOutput,
reconcileRootEnvPublicConfig,
reconcileRootEnvRelayUrl,
serializeGithubOutput,
serializeRelayClientTracingEnvironment,
} from "./deploy.ts";
describe("hasDeployChanges", () => {
it("detects resource, binding, and deletion changes", () => {
expect(hasDeployChanges({ resources: {}, deletions: {} } as never)).toBe(false);
expect(
hasDeployChanges({
resources: {
api: { action: "create", bindings: [] },
},
deletions: {},
} as never),
).toBe(true);
expect(
hasDeployChanges({
resources: {
api: { action: "noop", bindings: [{ action: "update" }] },
},
deletions: {},
} as never),
).toBe(true);
expect(
hasDeployChanges({
resources: {},
deletions: {
api: { action: "delete", bindings: [] },
},
} as never),
).toBe(true);
});
});
describe("reconcileRootEnvRelayUrl", () => {
it("adds the relay URL to an empty root env file", () => {
expect(reconcileRootEnvRelayUrl("", "https://relay.example.test")).toBe(
"T3CODE_RELAY_URL=https://relay.example.test\n",
);
});
it("preserves unrelated root env entries while replacing a previous relay URL", () => {
expect(
reconcileRootEnvRelayUrl(
"T3CODE_CLERK_PUBLISHABLE_KEY=pk_test_example\nT3CODE_RELAY_URL=https://old.example.test\n",
"https://relay.example.test",
),
).toBe(
"T3CODE_CLERK_PUBLISHABLE_KEY=pk_test_example\nT3CODE_RELAY_URL=https://relay.example.test\n",
);
});
});
describe("reconcileRootEnvPublicConfig", () => {
const config = {
relayUrl: "https://relay.example.test",
mobileTracingUrl: "https://api.axiom.co/v1/traces",
mobileTracingDataset: "t3-code-mobile-traces-dev",
mobileTracingToken: "xaat-public-ingest",
clientTracingUrl: "https://api.axiom.co/v1/traces",
clientTracingDataset: "t3-code-relay-client-traces-dev",
clientTracingToken: "xaat-relay-client-ingest",
} as const;
it("adds the complete local client config", () => {
expect(reconcileRootEnvPublicConfig("", config)).toBe(
[
"T3CODE_RELAY_URL=https://relay.example.test",
"T3CODE_MOBILE_OTLP_TRACES_URL=https://api.axiom.co/v1/traces",
"T3CODE_MOBILE_OTLP_TRACES_DATASET=t3-code-mobile-traces-dev",
"T3CODE_MOBILE_OTLP_TRACES_TOKEN=xaat-public-ingest",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_URL=https://api.axiom.co/v1/traces",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET=t3-code-relay-client-traces-dev",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN=xaat-relay-client-ingest",
"",
].join("\n"),
);
});
it("replaces stale values while preserving unrelated entries", () => {
expect(
reconcileRootEnvPublicConfig(
[
"T3CODE_CLERK_PUBLISHABLE_KEY=pk_test_example",
"T3CODE_RELAY_URL=https://old.example.test",
"T3CODE_MOBILE_OTLP_TRACES_URL=https://old.example.test/v1/traces",
"T3CODE_MOBILE_OTLP_TRACES_DATASET=old-dataset",
"T3CODE_MOBILE_OTLP_TRACES_TOKEN=old-token",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_URL=https://old.example.test/v1/traces",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET=old-client-dataset",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN=old-client-token",
"",
].join("\n"),
config,
),
).toBe(
[
"T3CODE_CLERK_PUBLISHABLE_KEY=pk_test_example",
"T3CODE_RELAY_URL=https://relay.example.test",
"T3CODE_MOBILE_OTLP_TRACES_URL=https://api.axiom.co/v1/traces",
"T3CODE_MOBILE_OTLP_TRACES_DATASET=t3-code-mobile-traces-dev",
"T3CODE_MOBILE_OTLP_TRACES_TOKEN=xaat-public-ingest",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_URL=https://api.axiom.co/v1/traces",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET=t3-code-relay-client-traces-dev",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN=xaat-relay-client-ingest",
"",
].join("\n"),
);
});
});
describe("serializeGithubOutput", () => {
it("serializes relay deploy metadata for GitHub Actions outputs", () => {
expect(
serializeGithubOutput({
changed: false,
result: "noop",
relay_url: "https://relay.example.test",
}),
).toBe("changed=false\nresult=noop\nrelay_url=https://relay.example.test\n");
});
});
describe("serializeRelayClientTracingEnvironment", () => {
it("serializes tracing config for downstream GITHUB_ENV loading", () => {
expect(
serializeRelayClientTracingEnvironment({
relayUrl: "https://relay.example.test",
mobileTracingUrl: "https://api.axiom.co/v1/traces",
mobileTracingDataset: "mobile",
mobileTracingToken: "mobile-token",
clientTracingUrl: "https://api.axiom.co/v1/traces",
clientTracingDataset: "relay",
clientTracingToken: "client-token",
}),
).toBe(
[
"T3CODE_RELAY_CLIENT_OTLP_TRACES_URL=https://api.axiom.co/v1/traces",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET=relay",
"T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN=client-token",
"",
].join("\n"),
);
});
});
describe("release workflow tracing config propagation", () => {
it.effect("keeps relay tracing config isolated to the disabled relay job", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const workflowPath = yield* path.fromFileUrl(
new URL("../../../.github/workflows/release.yml", import.meta.url),
);
const workflow = yield* fileSystem.readFileString(workflowPath);
expect(workflow).not.toContain("client_tracing_token:");
expect(workflow).not.toContain("needs.relay_public_config.outputs.client_tracing_token");
expect(workflow).toContain(
"if: ${{ false }} # Disabled for the fork: no production relay config.",
);
expect(workflow).toContain('--github-env-file "$RUNNER_TEMP/relay-client-tracing.env"');
expect(workflow).toContain("name: relay-client-tracing-config");
expect(workflow).not.toContain('cat "$config_path" >> "$GITHUB_ENV"');
expect(workflow).not.toContain("Download relay client tracing config");
}).pipe(Effect.provide(NodeServices.layer)),
);
});
describe("publicConfigFromOutput", () => {
it("reads the complete public tracing config from persisted Alchemy output", () => {
expect(
publicConfigFromOutput({
url: "https://relay.example.test",
mobileTracingUrl: "https://api.axiom.co/v1/traces",
mobileTracingDataset: "mobile",
mobileTracingToken: "mobile-token",
clientTracingUrl: "https://api.axiom.co/v1/traces",
clientTracingDataset: "relay",
clientTracingToken: "client-token",
}),
).toEqual({
relayUrl: "https://relay.example.test",
mobileTracingUrl: "https://api.axiom.co/v1/traces",
mobileTracingDataset: "mobile",
mobileTracingToken: "mobile-token",
clientTracingUrl: "https://api.axiom.co/v1/traces",
clientTracingDataset: "relay",
clientTracingToken: "client-token",
});
});
it("rejects incomplete stack output", () => {
expect(publicConfigFromOutput({ url: "https://relay.example.test" })).toBeNull();
});
});