Skip to content

Commit 486a446

Browse files
committed
fix(release): stabilize Wrangler dry-run receipt
1 parent 1183372 commit 486a446

2 files changed

Lines changed: 50 additions & 8 deletions

File tree

‎scripts/create-deployment-receipt.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
assertActiveWorkerReleaseBindings,
77
assertDeploymentReceiptBindings,
88
assertFrozenDryRunProjection,
9+
hasExpectedDryRunShape,
910
qualifiedContainerImage,
1011
selectQualifiedContainer,
1112
} from "./create-deployment-receipt";
@@ -42,6 +43,11 @@ const generationIsolationProbeSha256 =
4243

4344
describe("deployment receipt frozen dry-run projection", () => {
4445
const workerBundleSha256 = "a".repeat(64);
46+
const file = (name: string) => ({
47+
name,
48+
isFile: () => true,
49+
isSymbolicLink: () => false,
50+
});
4551

4652
it("accepts exactly one byte-identical Worker bundle", () => {
4753
expect(() =>
@@ -53,6 +59,32 @@ describe("deployment receipt frozen dry-run projection", () => {
5359
).not.toThrow();
5460
});
5561

62+
it("accepts the exact Wrangler files independent of directory order", () => {
63+
const readme = file("README.md");
64+
const worker = file("index.js");
65+
66+
expect(hasExpectedDryRunShape([readme, worker])).toBe(true);
67+
expect(hasExpectedDryRunShape([worker, readme])).toBe(true);
68+
});
69+
70+
it("rejects extra, non-file, and symbolic-link entries", () => {
71+
const readme = file("README.md");
72+
const worker = file("index.js");
73+
74+
expect(
75+
hasExpectedDryRunShape([readme, worker, file("metadata.json")]),
76+
).toBe(false);
77+
expect(
78+
hasExpectedDryRunShape([readme, { ...worker, isFile: () => false }]),
79+
).toBe(false);
80+
expect(
81+
hasExpectedDryRunShape([
82+
readme,
83+
{ ...worker, isSymbolicLink: () => true },
84+
]),
85+
).toBe(false);
86+
});
87+
5688
it("rejects changed Worker bytes and every non-singleton projection", () => {
5789
expect(() =>
5890
assertFrozenDryRunProjection({

‎scripts/create-deployment-receipt.ts‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,29 @@ export function assertFrozenDryRunProjection(input: {
124124
}
125125
}
126126

127+
type DryRunDirectoryEntry = {
128+
name: string;
129+
isFile: () => boolean;
130+
isSymbolicLink: () => boolean;
131+
};
132+
133+
export function hasExpectedDryRunShape(
134+
entries: readonly DryRunDirectoryEntry[],
135+
): boolean {
136+
const names = entries.map((entry) => entry.name).sort();
137+
return (
138+
JSON.stringify(names) === JSON.stringify(["README.md", "index.js"]) &&
139+
entries.every((entry) => entry.isFile() && !entry.isSymbolicLink())
140+
);
141+
}
142+
127143
function dryRunWorkerHash(
128144
root: string,
129145
directory: string,
130146
expectedWorkerSha256: string,
131147
) {
132-
const entries = readdirSync(directory, { withFileTypes: true }).sort(
133-
(left, right) => left.name.localeCompare(right.name),
134-
);
135-
if (
136-
JSON.stringify(entries.map((entry) => entry.name)) !==
137-
JSON.stringify(["README.md", "index.js"]) ||
138-
entries.some((entry) => !entry.isFile() || entry.isSymbolicLink())
139-
) {
148+
const entries = readdirSync(directory, { withFileTypes: true });
149+
if (!hasExpectedDryRunShape(entries)) {
140150
throw new Error("Wrangler dry-run output has an unexpected shape");
141151
}
142152
const workerPath = resolve(directory, "index.js");

0 commit comments

Comments
 (0)