-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathruntime-release-identity.test.ts
More file actions
226 lines (212 loc) · 8.23 KB
/
Copy pathruntime-release-identity.test.ts
File metadata and controls
226 lines (212 loc) · 8.23 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import { describe, expect, it } from "vitest";
import {
type ReleaseDispatchInputs,
validateReleaseDispatch,
validateRuntimeReleaseIdentity,
} from "../scripts/runtime-release-identity.js";
const runtime = {
run_id: "34640000001",
sha: "abcdef0123456789abcdef0123456789abcdef01",
version: "1.0.83-5.unstable.r34640000001.gabcdef0",
};
const inputs: ReleaseDispatchInputs = {
distTag: "unstable",
mode: "publish",
runtimeJson: "",
testPolicy: "required",
version: "",
};
describe("runtime version identity", () => {
it.each([
["canary", "1.2.4-canary.r34640000001.gabcdef0.signed"],
["canary", "1.2.4-canary.r34640000001.gabcdef0.unsigned"],
["canary", "1.2.4-7.canary.r34640000001.gabcdef0.signed"],
["canary", "1.2.4-7.canary.r34640000001.gabcdef0.unsigned"],
["unstable", "1.2.4-unstable.r34640000001.gabcdef0"],
["unstable", "1.2.4-7.unstable.r34640000001.gabcdef0"],
] as const)("accepts a %s runtime version: %s", (channel, runtimeVersion) => {
expect(() =>
validateRuntimeReleaseIdentity({
channel,
runId: runtime.run_id,
sha: runtime.sha,
version: runtimeVersion,
})
).not.toThrow();
});
it.each([
["wrong channel", "unstable", "1.2.4-canary.r34640000001.gabcdef0.signed"],
["test suffix", "unstable", "1.2.4-unstable.r34640000001.gabcdef0.test"],
["canary test suffix", "canary", "1.2.4-canary.r34640000001.gabcdef0.test"],
["old numeric run", "unstable", "1.2.4-unstable.34640000001.gabcdef0"],
["missing r", "unstable", "1.2.4-unstable.34640000001.gabcdef0"],
["mismatched run", "unstable", "1.2.4-unstable.r34640000002.gabcdef0"],
["mismatched sha", "unstable", "1.2.4-unstable.r34640000001.g1234567"],
["build metadata", "unstable", "1.2.4-unstable.r34640000001.gabcdef0+build.42"],
["canary without signing", "canary", "1.2.4-canary.r34640000001.gabcdef0"],
[
"canary extra signing suffix",
"canary",
"1.2.4-canary.r34640000001.gabcdef0.signed.extra",
],
["unstable signed", "unstable", "1.2.4-unstable.r34640000001.gabcdef0.signed"],
[
"non-numeric baseline prerelease",
"unstable",
"1.2.4-preview.unstable.r34640000001.gabcdef0",
],
["not a prerelease", "unstable", "1.2.4"],
["surrounding whitespace", "unstable", " 1.2.4-unstable.r34640000001.gabcdef0"],
] as const)("rejects %s: %s", (_name, channel, runtimeVersion) => {
expect(() =>
validateRuntimeReleaseIdentity({
channel,
runId: runtime.run_id,
sha: runtime.sha,
version: runtimeVersion,
})
).toThrow();
});
});
describe("release dispatch", () => {
it.each(["latest", "prerelease", "unstable"] as const)(
"accepts direct %s publication",
(distTag) => {
expect(validateReleaseDispatch({ ...inputs, distTag })).toEqual({
kind: "direct",
runtimeRunId: "",
runtimeSha: "",
runtimeVersion: "",
testPolicy: "required",
});
}
);
it("accepts direct unstable dry-run", () => {
expect(
validateReleaseDispatch({ ...inputs, distTag: "unstable", mode: "dry-run" }).kind
).toBe("direct");
});
it.each([
["canary", "dry-run", "1.0.83-5.canary.r34640000001.gabcdef0.unsigned"],
["canary", "publish", "1.0.83-5.canary.r34640000001.gabcdef0.signed"],
["unstable", "dry-run", runtime.version],
["unstable", "publish", runtime.version],
] as const)("accepts runtime-backed %s %s", (distTag, mode, version) => {
expect(
validateReleaseDispatch({
...inputs,
distTag,
mode,
runtimeJson: JSON.stringify({ ...runtime, version }),
})
).toEqual({
kind: "runtime",
runtimeRunId: runtime.run_id,
runtimeSha: runtime.sha,
runtimeVersion: version,
testPolicy: "required",
});
});
it.each(["required", "advisory", "skipped"] as const)(
"accepts runtime-backed releases with %s tests",
(testPolicy) => {
expect(
validateReleaseDispatch({
...inputs,
runtimeJson: JSON.stringify(runtime),
testPolicy,
}).testPolicy
).toBe(testPolicy);
}
);
it("rejects canary without runtime JSON", () => {
expect(() => validateReleaseDispatch({ ...inputs, distTag: "canary" })).toThrow(
"Canary releases require runtime JSON"
);
});
it.each(["latest", "prerelease"] as const)("rejects %s dry-run", (distTag) => {
expect(() => validateReleaseDispatch({ ...inputs, distTag, mode: "dry-run" })).toThrow(
"Dry-run mode is supported only for canary and unstable releases"
);
});
it.each(["latest", "prerelease"] as const)("rejects runtime JSON for %s", (distTag) => {
expect(() =>
validateReleaseDispatch({
...inputs,
distTag,
runtimeJson: JSON.stringify(runtime),
})
).toThrow("Runtime JSON is supported only for canary and unstable releases");
});
it("rejects a direct version with runtime JSON", () => {
expect(() =>
validateReleaseDispatch({
...inputs,
runtimeJson: JSON.stringify(runtime),
version: "2.0.0-unstable.manual",
})
).toThrow("direct version input");
});
it.each(["advisory", "skipped"] as const)(
"rejects %s tests for direct releases",
(testPolicy) => {
expect(() => validateReleaseDispatch({ ...inputs, testPolicy })).toThrow(
"Direct releases require the default runtime E2E test policy"
);
}
);
it("rejects unknown dist-tags, modes, and test policies", () => {
expect(() =>
validateReleaseDispatch({ ...inputs, distTag: "preview" as "unstable" })
).toThrow("Invalid release dist-tag");
expect(() => validateReleaseDispatch({ ...inputs, mode: "test" as "publish" })).toThrow(
"Invalid release mode"
);
expect(() =>
validateReleaseDispatch({ ...inputs, testPolicy: "optional" as "required" })
).toThrow("Invalid runtime E2E test policy");
});
it.each([
["malformed JSON", "{"],
["whitespace-only input", " "],
["surrounding whitespace", ` ${JSON.stringify(runtime)}`],
["null", "null"],
["array", "[]"],
["missing key", JSON.stringify({ version: runtime.version, sha: runtime.sha })],
["extra key", JSON.stringify({ ...runtime, source: "github-packages" })],
["non-string field", JSON.stringify({ ...runtime, run_id: 123 })],
["zero run ID", JSON.stringify({ ...runtime, run_id: "0" })],
["non-canonical run ID", JSON.stringify({ ...runtime, run_id: "0123" })],
["uppercase SHA", JSON.stringify({ ...runtime, sha: runtime.sha.toUpperCase() })],
[
"wrong channel",
JSON.stringify({
...runtime,
version: "1.0.83-5.canary.r34640000001.gabcdef0.signed",
}),
],
[
"mismatched version run ID",
JSON.stringify({
...runtime,
version: "1.0.83-5.unstable.r34640000002.gabcdef0",
}),
],
[
"mismatched version SHA",
JSON.stringify({
...runtime,
version: "1.0.83-5.unstable.r34640000001.g1234567",
}),
],
[
"obsolete test version",
JSON.stringify({
...runtime,
version: "1.0.83-5.unstable.r34640000001.gabcdef0.test",
}),
],
])("rejects %s", (_name, runtimeJson) => {
expect(() => validateReleaseDispatch({ ...inputs, runtimeJson })).toThrow();
});
});