create-disposabl-app 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/disposabl.js +14 -10
- package/dist/index.js +40 -2
- package/dist/templates/default/.github/scripts/disposabl.mjs +15 -1
- package/dist/templates/default/.github/scripts/platforms.sh +1 -1
- package/dist/templates/default/.github/scripts/release.sh +1 -1
- package/dist/templates/default/.github/workflows/pipeline.yml +30 -2
- package/dist/templates/default/apps/desktop/README.md +16 -4
- package/dist/templates/default/apps/desktop/build-ci.mjs +7 -0
- package/dist/templates/default/apps/desktop/forge.config.mts +8 -4
- package/dist/templates/default/apps/desktop/package.json +3 -2
- package/dist/templates/default/apps/desktop/publish-update.mjs +93 -0
- package/dist/templates/default/apps/desktop/src/declarations.d.ts +4 -0
- package/dist/templates/default/apps/desktop/src/main.ts +86 -1
- package/dist/templates/default/apps/desktop/src/updates.ts +123 -0
- package/dist/templates/default/apps/desktop/stage-update.mjs +70 -0
- package/dist/templates/default/apps/desktop/vite.main.config.mts +10 -0
- package/dist/templates/default/apps/web/src/routeTree.gen.ts +31 -0
- package/dist/templates/default/apps/web/src/router/mobile-login.tsx +84 -0
- package/dist/templates/default/bun.lock +7 -2
- package/dist/templates/default/package.json +1 -1
- package/dist/templates/default/packages/backend/convex/authSetup.ts +9 -1
- package/dist/templates/default/packages/backend/convex/desktopUpdates/validator.ts +62 -0
- package/dist/templates/default/packages/backend/convex/desktopUpdates.ts +216 -0
- package/dist/templates/default/packages/backend/convex/http.ts +6 -0
- package/dist/templates/default/packages/backend/convex/schema.ts +2 -0
- package/dist/templates/default/packages/cli/auth.ts +1 -20
- package/dist/templates/default/packages/cli/origin.ts +22 -0
- package/dist/templates/default/packages/disposabl-kit/lib/indexing.ts +1 -0
- package/dist/templates/default/packages/disposabl-kit/server/files-functions.ts +1 -1
- package/dist/templates/default/packages/disposabl-kit/server/lib/static.ts +7 -0
- package/dist/templates/default/packages/disposabl-kit/server/lib/telemetry.ts +62 -12
- package/dist/templates/default/packages/tests/README.md +2 -0
- package/dist/templates/default/packages/tests/ci-platform-selection.test.ts +53 -0
- package/dist/templates/default/packages/tests/desktop-publication.test.ts +251 -0
- package/dist/templates/default/packages/tests/desktop-updates.test.ts +200 -0
- package/dist/templates/default/packages/tests/flows/desktop-updates.e2e.ts +102 -0
- package/dist/templates/default/packages/tests/flows/files.e2e.ts +48 -0
- package/dist/templates/default/packages/tests/telemetry.test.ts +170 -0
- package/dist/templates/default/vendor/README.md +7 -4
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.3.tgz +0 -0
- package/package.json +1 -1
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.1.tgz +0 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import {
|
|
4
|
+
publish,
|
|
5
|
+
resolve,
|
|
6
|
+
desktopUpdate,
|
|
7
|
+
} from "../backend/convex/desktopUpdates";
|
|
8
|
+
|
|
9
|
+
const app = "a".repeat(32);
|
|
10
|
+
const original = {
|
|
11
|
+
app,
|
|
12
|
+
channel: "production",
|
|
13
|
+
platform: "win32",
|
|
14
|
+
arch: "x64",
|
|
15
|
+
version: "1.2.1",
|
|
16
|
+
build: 2,
|
|
17
|
+
attempt: 1,
|
|
18
|
+
filename: "app-1.2.1-full.nupkg",
|
|
19
|
+
storageId: "file2",
|
|
20
|
+
sha256: "b".repeat(64),
|
|
21
|
+
sha1: "C".repeat(40),
|
|
22
|
+
size: 7,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
test("publication validates blobs and keeps immutable monotonic feeds isolated", async () => {
|
|
26
|
+
const rows: any[] = [];
|
|
27
|
+
let metadata: any = { sha256: original.sha256, size: 7 };
|
|
28
|
+
const ctx: any = {
|
|
29
|
+
db: {
|
|
30
|
+
system: { get: async () => metadata },
|
|
31
|
+
insert: async (_: unknown, row: any) => rows.push(row),
|
|
32
|
+
query: () => ({
|
|
33
|
+
withIndex: (_: unknown, build: any) => {
|
|
34
|
+
const predicates: [string, unknown][] = [];
|
|
35
|
+
const q = {
|
|
36
|
+
eq: (key: string, value: unknown) => {
|
|
37
|
+
predicates.push([key, value]);
|
|
38
|
+
return q;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
build(q);
|
|
42
|
+
const matching = () =>
|
|
43
|
+
rows.filter((row) =>
|
|
44
|
+
predicates.every(([key, value]) => row[key] === value),
|
|
45
|
+
);
|
|
46
|
+
return {
|
|
47
|
+
order: () => ({
|
|
48
|
+
first: async () =>
|
|
49
|
+
matching().sort(
|
|
50
|
+
(a, b) => b.build - a.build || b.attempt - a.attempt,
|
|
51
|
+
)[0] ?? null,
|
|
52
|
+
}),
|
|
53
|
+
unique: async () => matching()[0] ?? null,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
storage: { getUrl: async (id: string) => `https://storage.test/${id}` },
|
|
59
|
+
};
|
|
60
|
+
const call = (args: any) => (publish as any)._handler(ctx, args);
|
|
61
|
+
await call(original);
|
|
62
|
+
await assert.rejects(
|
|
63
|
+
call({
|
|
64
|
+
...original,
|
|
65
|
+
build: 1,
|
|
66
|
+
version: "1.1.1",
|
|
67
|
+
filename: "app-1.1.1-full.nupkg",
|
|
68
|
+
}),
|
|
69
|
+
/not newer/,
|
|
70
|
+
);
|
|
71
|
+
await call(original);
|
|
72
|
+
assert.equal(rows.length, 1);
|
|
73
|
+
await assert.rejects(
|
|
74
|
+
call({ ...original, sha1: "D".repeat(40) }),
|
|
75
|
+
/not newer|already exists/,
|
|
76
|
+
);
|
|
77
|
+
metadata = { ...metadata, size: 8 };
|
|
78
|
+
await assert.rejects(
|
|
79
|
+
call({
|
|
80
|
+
...original,
|
|
81
|
+
build: 3,
|
|
82
|
+
version: "1.3.1",
|
|
83
|
+
filename: "app-1.3.1-full.nupkg",
|
|
84
|
+
}),
|
|
85
|
+
/does not match/,
|
|
86
|
+
);
|
|
87
|
+
assert.equal(rows.length, 1);
|
|
88
|
+
metadata = { ...metadata, size: 7 };
|
|
89
|
+
await call({
|
|
90
|
+
...original,
|
|
91
|
+
channel: "preview",
|
|
92
|
+
build: 1,
|
|
93
|
+
version: "1.1.1",
|
|
94
|
+
filename: "app-1.1.1-full.nupkg",
|
|
95
|
+
});
|
|
96
|
+
await call({
|
|
97
|
+
...original,
|
|
98
|
+
build: 3,
|
|
99
|
+
version: "1.3.1",
|
|
100
|
+
filename: "app-1.3.1-full.nupkg",
|
|
101
|
+
storageId: "file3",
|
|
102
|
+
});
|
|
103
|
+
const get = (args: any) => (resolve as any)._handler(ctx, args);
|
|
104
|
+
assert.equal(
|
|
105
|
+
(await get({ app, channel: "production", platform: "win32", arch: "x64" }))
|
|
106
|
+
.version,
|
|
107
|
+
"1.3.1",
|
|
108
|
+
);
|
|
109
|
+
assert.equal(
|
|
110
|
+
(
|
|
111
|
+
await get({
|
|
112
|
+
app,
|
|
113
|
+
channel: "production",
|
|
114
|
+
platform: "win32",
|
|
115
|
+
arch: "x64",
|
|
116
|
+
filename: original.filename,
|
|
117
|
+
})
|
|
118
|
+
).url,
|
|
119
|
+
"https://storage.test/file2",
|
|
120
|
+
);
|
|
121
|
+
assert.equal(
|
|
122
|
+
await get({
|
|
123
|
+
app: "d".repeat(32),
|
|
124
|
+
channel: "production",
|
|
125
|
+
platform: "win32",
|
|
126
|
+
arch: "x64",
|
|
127
|
+
}),
|
|
128
|
+
null,
|
|
129
|
+
);
|
|
130
|
+
assert.equal(
|
|
131
|
+
(await get({ app, channel: "preview", platform: "win32", arch: "x64" }))
|
|
132
|
+
.version,
|
|
133
|
+
"1.1.1",
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("feed pointers are fresh and package requests redirect to storage", async () => {
|
|
138
|
+
const url = `https://app.convex.site/desktop/updates/${app}/production/win32/x64/`;
|
|
139
|
+
const row = {
|
|
140
|
+
version: "1.2.1",
|
|
141
|
+
filename: original.filename,
|
|
142
|
+
sha1: original.sha1,
|
|
143
|
+
size: 7,
|
|
144
|
+
url: "https://storage.test/file",
|
|
145
|
+
};
|
|
146
|
+
const ctx = {
|
|
147
|
+
runQuery: async (_: unknown, args: any) => (args.app === app ? row : null),
|
|
148
|
+
};
|
|
149
|
+
const handle = (path: string) =>
|
|
150
|
+
(desktopUpdate as any)._handler(ctx, new Request(url + path));
|
|
151
|
+
const manifest = await handle("RELEASES");
|
|
152
|
+
assert.equal(manifest.headers.get("cache-control"), "no-store");
|
|
153
|
+
assert.equal(
|
|
154
|
+
await manifest.text(),
|
|
155
|
+
`${original.sha1} ${url}${original.filename} 7\n`,
|
|
156
|
+
);
|
|
157
|
+
const binary = await handle(original.filename);
|
|
158
|
+
assert.equal(binary.status, 302);
|
|
159
|
+
assert.equal(binary.headers.get("location"), row.url);
|
|
160
|
+
const macUrl = `https://app.convex.site/desktop/updates/${app}/production/darwin/arm64/RELEASES.json`;
|
|
161
|
+
const macRow = { ...row, filename: "app-darwin-arm64-1.2.1.zip" };
|
|
162
|
+
const mac = await (desktopUpdate as any)._handler(
|
|
163
|
+
{ runQuery: async () => macRow },
|
|
164
|
+
new Request(macUrl),
|
|
165
|
+
);
|
|
166
|
+
const manifestJson = await mac.json();
|
|
167
|
+
assert.equal(manifestJson.currentRelease, "1.2.1");
|
|
168
|
+
assert.equal(
|
|
169
|
+
manifestJson.releases[0].updateTo.url,
|
|
170
|
+
macUrl.replace("RELEASES.json", macRow.filename),
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("publisher uploads bytes before invoking the internal publication", async () => {
|
|
175
|
+
const { mkdtemp, mkdir, copyFile, writeFile, readFile, chmod, rm } =
|
|
176
|
+
await import("node:fs/promises");
|
|
177
|
+
const { createHash } = await import("node:crypto");
|
|
178
|
+
const { createServer } = await import("node:http");
|
|
179
|
+
const { spawn } = await import("node:child_process");
|
|
180
|
+
const { join } = await import("node:path");
|
|
181
|
+
const { tmpdir } = await import("node:os");
|
|
182
|
+
const root = await mkdtemp(join(tmpdir(), "desktop-publish-"));
|
|
183
|
+
let uploaded = "";
|
|
184
|
+
const server = createServer(async (request, response) => {
|
|
185
|
+
for await (const chunk of request) uploaded += chunk.toString();
|
|
186
|
+
response.writeHead(200, { "Content-Type": "application/json" });
|
|
187
|
+
response.end(JSON.stringify({ storageId: "stored-blob" }));
|
|
188
|
+
});
|
|
189
|
+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
190
|
+
try {
|
|
191
|
+
const dir = join(root, "dist/update/production/win32/x64");
|
|
192
|
+
await mkdir(dir, { recursive: true });
|
|
193
|
+
await mkdir(join(root, "packages/backend"), { recursive: true });
|
|
194
|
+
await mkdir(join(root, "apps/desktop"), { recursive: true });
|
|
195
|
+
await mkdir(join(root, "bin"));
|
|
196
|
+
await copyFile(
|
|
197
|
+
new URL("../../apps/desktop/publish-update.mjs", import.meta.url),
|
|
198
|
+
join(root, "apps/desktop/publish-update.mjs"),
|
|
199
|
+
);
|
|
200
|
+
await writeFile(join(dir, original.filename), "package");
|
|
201
|
+
const sha1 = createHash("sha1")
|
|
202
|
+
.update("package")
|
|
203
|
+
.digest("hex")
|
|
204
|
+
.toUpperCase();
|
|
205
|
+
await writeFile(join(dir, "RELEASES"), `${sha1} ${original.filename} 7\n`);
|
|
206
|
+
const fakeBun = join(root, "bin/bun");
|
|
207
|
+
await writeFile(
|
|
208
|
+
fakeBun,
|
|
209
|
+
'#!/bin/sh\nif [ "$8" = "desktopUpdates:uploadUrl" ]; then printf \'"%s"\\n\' "$TEST_UPLOAD_URL"; elif [ "$8" = "desktopUpdates:publish" ]; then printf \'%s\' "$9" > "$TEST_RESULT"; fi\n',
|
|
210
|
+
);
|
|
211
|
+
await chmod(fakeBun, 0o755);
|
|
212
|
+
const address = server.address();
|
|
213
|
+
assert.ok(address && typeof address === "object");
|
|
214
|
+
const env = {
|
|
215
|
+
...process.env,
|
|
216
|
+
PATH: `${join(root, "bin")}:${process.env.PATH}`,
|
|
217
|
+
DISPOSABL_DESKTOP_ID: app,
|
|
218
|
+
DISPOSABL_DESKTOP_PLATFORM: "windows",
|
|
219
|
+
DISPOSABL_RELEASE_VERSION: "1.2.1",
|
|
220
|
+
DISPOSABL_DESKTOP_UPDATE_CHANNEL: "production",
|
|
221
|
+
TEST_UPLOAD_URL: `http://127.0.0.1:${address.port}/`,
|
|
222
|
+
TEST_RESULT: join(root, "result.json"),
|
|
223
|
+
};
|
|
224
|
+
const child = spawn(
|
|
225
|
+
process.execPath,
|
|
226
|
+
[join(root, "apps/desktop/publish-update.mjs")],
|
|
227
|
+
{ cwd: root, env, stdio: ["ignore", "pipe", "pipe"] },
|
|
228
|
+
);
|
|
229
|
+
let errors = "";
|
|
230
|
+
child.stderr.on("data", (chunk) => {
|
|
231
|
+
errors += chunk.toString();
|
|
232
|
+
});
|
|
233
|
+
const code = await new Promise<number | null>((resolve) =>
|
|
234
|
+
child.on("close", resolve),
|
|
235
|
+
);
|
|
236
|
+
assert.equal(code, 0, errors);
|
|
237
|
+
assert.equal(uploaded, "package");
|
|
238
|
+
const result = JSON.parse(
|
|
239
|
+
await readFile(join(root, "result.json"), "utf8"),
|
|
240
|
+
);
|
|
241
|
+
assert.equal(result.storageId, "stored-blob");
|
|
242
|
+
assert.equal(result.sha1, sha1);
|
|
243
|
+
assert.equal(
|
|
244
|
+
result.sha256,
|
|
245
|
+
createHash("sha256").update("package").digest("hex"),
|
|
246
|
+
);
|
|
247
|
+
} finally {
|
|
248
|
+
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
249
|
+
await rm(root, { recursive: true, force: true });
|
|
250
|
+
}
|
|
251
|
+
});
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { describe, test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import {
|
|
5
|
+
createUpdateController,
|
|
6
|
+
feedUrl,
|
|
7
|
+
} from "../../apps/desktop/src/updates";
|
|
8
|
+
|
|
9
|
+
function setup(
|
|
10
|
+
overrides: Partial<Parameters<typeof createUpdateController>[0]> = {},
|
|
11
|
+
) {
|
|
12
|
+
const messages: string[] = [];
|
|
13
|
+
let starts = 0;
|
|
14
|
+
let installs = 0;
|
|
15
|
+
const updates = createUpdateController({
|
|
16
|
+
supported: true,
|
|
17
|
+
feed: "https://updates.example/production/win32/x64",
|
|
18
|
+
start: () => {
|
|
19
|
+
starts++;
|
|
20
|
+
},
|
|
21
|
+
install: () => {
|
|
22
|
+
installs++;
|
|
23
|
+
},
|
|
24
|
+
show: (_kind, message) => messages.push(message),
|
|
25
|
+
confirmRestart: async () => false,
|
|
26
|
+
...overrides,
|
|
27
|
+
});
|
|
28
|
+
return { updates, messages, starts: () => starts, installs: () => installs };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("desktop updates", () => {
|
|
32
|
+
test("isolates feeds and rejects unsafe configuration", () => {
|
|
33
|
+
assert.equal(
|
|
34
|
+
feedUrl("https://example.com/my-app/", "production", "darwin", "arm64"),
|
|
35
|
+
"https://example.com/my-app/production/darwin/arm64",
|
|
36
|
+
);
|
|
37
|
+
assert.equal(
|
|
38
|
+
feedUrl("https://example.com/my-app", "pr-4", "win32", "x64"),
|
|
39
|
+
"https://example.com/my-app/pr-4/win32/x64",
|
|
40
|
+
);
|
|
41
|
+
for (const base of [
|
|
42
|
+
"http://example.com",
|
|
43
|
+
"https://user:pass@example.com",
|
|
44
|
+
"https://example.com/?token=x",
|
|
45
|
+
])
|
|
46
|
+
assert.equal(feedUrl(base, "production", "win32", "x64"), "");
|
|
47
|
+
assert.equal(
|
|
48
|
+
feedUrl("https://example.com", "../production", "win32", "x64"),
|
|
49
|
+
"",
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
test("does not report success for missing feed or unsupported Linux", () => {
|
|
53
|
+
const missing = setup({ feed: "" });
|
|
54
|
+
missing.updates.check();
|
|
55
|
+
assert.equal(missing.starts(), 0);
|
|
56
|
+
assert.ok(missing.messages[0].includes("not configured"));
|
|
57
|
+
const linux = setup({ supported: false });
|
|
58
|
+
linux.updates.check();
|
|
59
|
+
assert.equal(linux.starts(), 0);
|
|
60
|
+
assert.ok(linux.messages[0].includes("unavailable"));
|
|
61
|
+
});
|
|
62
|
+
test("serializes checks, retries after error, and retains downloaded update", async () => {
|
|
63
|
+
const t = setup();
|
|
64
|
+
t.updates.check();
|
|
65
|
+
t.updates.check();
|
|
66
|
+
assert.equal(t.starts(), 1);
|
|
67
|
+
t.updates.error();
|
|
68
|
+
assert.equal(t.updates.state, "idle");
|
|
69
|
+
t.updates.check();
|
|
70
|
+
assert.equal(t.starts(), 2);
|
|
71
|
+
t.updates.available();
|
|
72
|
+
assert.equal(t.updates.state, "downloading");
|
|
73
|
+
t.updates.downloaded();
|
|
74
|
+
await Promise.resolve();
|
|
75
|
+
assert.equal(t.updates.state, "ready");
|
|
76
|
+
t.updates.check();
|
|
77
|
+
await Promise.resolve();
|
|
78
|
+
assert.equal(t.starts(), 2);
|
|
79
|
+
assert.equal(t.installs(), 0);
|
|
80
|
+
});
|
|
81
|
+
test("only confirmed downloaded updates install", async () => {
|
|
82
|
+
const t = setup({ confirmRestart: async () => true });
|
|
83
|
+
t.updates.check();
|
|
84
|
+
t.updates.downloaded();
|
|
85
|
+
await Promise.resolve();
|
|
86
|
+
assert.equal(t.installs(), 1);
|
|
87
|
+
const no = setup();
|
|
88
|
+
no.updates.check();
|
|
89
|
+
no.updates.unavailable();
|
|
90
|
+
assert.ok(no.messages.includes("This app is up to date."));
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("stages isolated Squirrel feeds and refuses ad-hoc macOS feeds", async () => {
|
|
95
|
+
const { mkdtemp, mkdir, copyFile, writeFile, readFile, rm, access } =
|
|
96
|
+
await import("node:fs/promises");
|
|
97
|
+
const { tmpdir } = await import("node:os");
|
|
98
|
+
const { join } = await import("node:path");
|
|
99
|
+
const root = await mkdtemp(join(tmpdir(), "desktop-feed-"));
|
|
100
|
+
try {
|
|
101
|
+
await mkdir(join(root, "apps/desktop"), { recursive: true });
|
|
102
|
+
await mkdir(join(root, "dist/release"), { recursive: true });
|
|
103
|
+
await copyFile(
|
|
104
|
+
new URL("../../apps/desktop/stage-update.mjs", import.meta.url),
|
|
105
|
+
join(root, "apps/desktop/stage-update.mjs"),
|
|
106
|
+
);
|
|
107
|
+
await writeFile(join(root, "dist/release/app-1.0.2-full.nupkg"), "package");
|
|
108
|
+
await writeFile(
|
|
109
|
+
join(root, "dist/release/RELEASES"),
|
|
110
|
+
`${"a".repeat(40)} app-1.0.2-full.nupkg 7\n`,
|
|
111
|
+
);
|
|
112
|
+
const env = {
|
|
113
|
+
...process.env,
|
|
114
|
+
DISPOSABL_DESKTOP_UPDATE_URL: "https://example.com/app",
|
|
115
|
+
DISPOSABL_DESKTOP_UPDATE_CHANNEL: "preview",
|
|
116
|
+
DISPOSABL_DESKTOP_PLATFORM: "windows",
|
|
117
|
+
DISPOSABL_RELEASE_VERSION: "1.0.2",
|
|
118
|
+
};
|
|
119
|
+
const run = (values: Record<string, string>) =>
|
|
120
|
+
spawnSync("node", [join(root, "apps/desktop/stage-update.mjs")], {
|
|
121
|
+
env: { ...env, ...values },
|
|
122
|
+
stdio: "pipe",
|
|
123
|
+
});
|
|
124
|
+
assert.equal(run({}).status, 0);
|
|
125
|
+
assert.equal(
|
|
126
|
+
await readFile(
|
|
127
|
+
join(root, "dist/update/preview/win32/x64/app-1.0.2-full.nupkg"),
|
|
128
|
+
"utf8",
|
|
129
|
+
),
|
|
130
|
+
"package",
|
|
131
|
+
);
|
|
132
|
+
await writeFile(join(root, "dist/release/app.zip"), "zip");
|
|
133
|
+
assert.equal(
|
|
134
|
+
run({ DISPOSABL_DESKTOP_PLATFORM: "macos", MACOS_NOTARIZE: "false" })
|
|
135
|
+
.status,
|
|
136
|
+
0,
|
|
137
|
+
);
|
|
138
|
+
assert.equal(
|
|
139
|
+
await access(join(root, "dist/update/preview/darwin")).then(
|
|
140
|
+
() => true,
|
|
141
|
+
() => false,
|
|
142
|
+
),
|
|
143
|
+
false,
|
|
144
|
+
);
|
|
145
|
+
assert.equal(
|
|
146
|
+
run({ DISPOSABL_DESKTOP_PLATFORM: "macos", MACOS_NOTARIZE: "true" })
|
|
147
|
+
.status,
|
|
148
|
+
0,
|
|
149
|
+
);
|
|
150
|
+
const manifest = JSON.parse(
|
|
151
|
+
await readFile(
|
|
152
|
+
join(root, "dist/update/preview/darwin/arm64/RELEASES.json"),
|
|
153
|
+
"utf8",
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
assert.equal(
|
|
157
|
+
manifest.releases[0].updateTo.url,
|
|
158
|
+
"https://example.com/app/preview/darwin/arm64/app.zip",
|
|
159
|
+
);
|
|
160
|
+
assert.notEqual(
|
|
161
|
+
run({ DISPOSABL_DESKTOP_UPDATE_CHANNEL: "../production" }).status,
|
|
162
|
+
0,
|
|
163
|
+
);
|
|
164
|
+
} finally {
|
|
165
|
+
await rm(root, { recursive: true, force: true });
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("waits for the Windows installer lock before checking", () => {
|
|
170
|
+
let now = 0;
|
|
171
|
+
const t = setup({ now: () => now, readyAt: 10_000 });
|
|
172
|
+
t.updates.check();
|
|
173
|
+
assert.equal(t.starts(), 0);
|
|
174
|
+
assert.ok(t.messages[0].includes("Finishing installation"));
|
|
175
|
+
now = 10_000;
|
|
176
|
+
t.updates.check();
|
|
177
|
+
assert.equal(t.starts(), 1);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("reports restart errors while preserving the downloaded update for retry", async () => {
|
|
181
|
+
let reject = true;
|
|
182
|
+
const t = setup({
|
|
183
|
+
confirmRestart: async () => {
|
|
184
|
+
if (reject) throw new Error("dialog closed");
|
|
185
|
+
return true;
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
t.updates.check();
|
|
189
|
+
t.updates.downloaded();
|
|
190
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
191
|
+
assert.equal(t.updates.state, "ready");
|
|
192
|
+
assert.ok(t.messages.at(-1)?.includes("Could not restart"));
|
|
193
|
+
reject = false;
|
|
194
|
+
t.updates.check();
|
|
195
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
196
|
+
assert.equal(t.installs(), 1);
|
|
197
|
+
t.updates.error();
|
|
198
|
+
assert.equal(t.updates.state, "ready");
|
|
199
|
+
assert.ok(t.messages.at(-1)?.includes("Could not restart"));
|
|
200
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { randomBytes, createHash } from "node:crypto";
|
|
2
|
+
import { test, expect } from "e2e";
|
|
3
|
+
import { backendUrl } from "../project.ts";
|
|
4
|
+
|
|
5
|
+
test(
|
|
6
|
+
"desktop feeds publish immutable packages and recover across build retries",
|
|
7
|
+
{ platforms: ["backend"] },
|
|
8
|
+
async () => {
|
|
9
|
+
const origin = new URL(backendUrl());
|
|
10
|
+
const key = process.env.E2E_CONVEX_ADMIN_KEY;
|
|
11
|
+
test.skip(
|
|
12
|
+
!process.env.E2E_CONVEX_URL ||
|
|
13
|
+
!["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname) ||
|
|
14
|
+
!key,
|
|
15
|
+
"Requires an explicit isolated loopback backend and admin fixture key",
|
|
16
|
+
);
|
|
17
|
+
const site = new URL(process.env.E2E_CONVEX_SITE_URL!);
|
|
18
|
+
if (!["localhost", "127.0.0.1", "[::1]"].includes(site.hostname))
|
|
19
|
+
throw new Error("Feed fixtures require loopback HTTP actions");
|
|
20
|
+
async function call(name: string, args: object, admin = true) {
|
|
21
|
+
return fetch(`${origin.origin}/api/mutation`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
signal: AbortSignal.timeout(15_000),
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "application/json",
|
|
26
|
+
...(admin ? { Authorization: `Convex ${key}` } : {}),
|
|
27
|
+
},
|
|
28
|
+
body: JSON.stringify({
|
|
29
|
+
path: `desktopUpdates:${name}`,
|
|
30
|
+
args,
|
|
31
|
+
format: "json",
|
|
32
|
+
}),
|
|
33
|
+
}).then((r) => r.json());
|
|
34
|
+
}
|
|
35
|
+
const app = randomBytes(16).toString("hex");
|
|
36
|
+
const feed = `${site.origin}/desktop/updates/${app}/production/win32/x64/`;
|
|
37
|
+
async function upload(build: number, attempt: number, bytes: string) {
|
|
38
|
+
const url = await call("uploadUrl", {});
|
|
39
|
+
expect(url.status).toBe("success");
|
|
40
|
+
expect(new URL(url.value).hostname).toBe(origin.hostname);
|
|
41
|
+
const response = await fetch(url.value, { method: "POST", body: bytes });
|
|
42
|
+
expect(response.ok).toBe(true);
|
|
43
|
+
const { storageId } = await response.json();
|
|
44
|
+
const version = `1.${build}.${attempt}`;
|
|
45
|
+
return {
|
|
46
|
+
app,
|
|
47
|
+
channel: "production",
|
|
48
|
+
platform: "win32",
|
|
49
|
+
arch: "x64",
|
|
50
|
+
version,
|
|
51
|
+
build,
|
|
52
|
+
attempt,
|
|
53
|
+
filename: `fixture-${version}-full.nupkg`,
|
|
54
|
+
storageId,
|
|
55
|
+
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
56
|
+
sha1: createHash("sha1").update(bytes).digest("hex").toUpperCase(),
|
|
57
|
+
size: Buffer.byteLength(bytes),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const first = await upload(1, 1, "original");
|
|
61
|
+
expect((await call("publish", first, false)).status).toBe("error");
|
|
62
|
+
const published = await call("publish", first);
|
|
63
|
+
if (published.status !== "success")
|
|
64
|
+
throw new Error(published.errorMessage ?? "Publication failed");
|
|
65
|
+
const repeat = await upload(1, 1, "original");
|
|
66
|
+
expect((await call("publish", repeat)).status).toBe("success");
|
|
67
|
+
expect(
|
|
68
|
+
(await call("discardUpload", { storageId: repeat.storageId })).status,
|
|
69
|
+
).toBe("success");
|
|
70
|
+
// A successfully published blob remains referenced and cannot be discarded.
|
|
71
|
+
expect(
|
|
72
|
+
(await call("discardUpload", { storageId: first.storageId })).status,
|
|
73
|
+
).toBe("success");
|
|
74
|
+
const retry = await upload(1, 2, "rebuilt package");
|
|
75
|
+
expect((await call("publish", retry)).status).toBe("success");
|
|
76
|
+
const manifest = await fetch(`${feed}RELEASES`);
|
|
77
|
+
expect(manifest.headers.get("cache-control")).toBe("no-store");
|
|
78
|
+
expect(await manifest.text()).toBe(
|
|
79
|
+
`${retry.sha1} ${feed}${retry.filename} ${retry.size}\n`,
|
|
80
|
+
);
|
|
81
|
+
expect(await (await fetch(`${feed}${first.filename}`)).text()).toBe(
|
|
82
|
+
"original",
|
|
83
|
+
);
|
|
84
|
+
expect(await (await fetch(`${feed}${retry.filename}`)).text()).toBe(
|
|
85
|
+
"rebuilt package",
|
|
86
|
+
);
|
|
87
|
+
const next = await upload(2, 1, "next run");
|
|
88
|
+
expect((await call("publish", next)).status).toBe("success");
|
|
89
|
+
const stale = await upload(1, 99, "old run retry");
|
|
90
|
+
expect((await call("publish", stale)).status).toBe("error");
|
|
91
|
+
expect(
|
|
92
|
+
(await call("discardUpload", { storageId: stale.storageId })).status,
|
|
93
|
+
).toBe("success");
|
|
94
|
+
expect(await (await fetch(`${feed}RELEASES`)).text()).toBe(
|
|
95
|
+
`${next.sha1} ${feed}${next.filename} ${next.size}\n`,
|
|
96
|
+
);
|
|
97
|
+
expect(
|
|
98
|
+
(await fetch(feed.replace("/production/", "/preview/") + "RELEASES"))
|
|
99
|
+
.status,
|
|
100
|
+
).toBe(404);
|
|
101
|
+
},
|
|
102
|
+
);
|
|
@@ -11,6 +11,40 @@ test(
|
|
|
11
11
|
!["127.0.0.1", "localhost", "[::1]"].includes(url.hostname),
|
|
12
12
|
"File fixtures require a disposable loopback backend",
|
|
13
13
|
);
|
|
14
|
+
const adminKey = process.env.E2E_CONVEX_ADMIN_KEY;
|
|
15
|
+
test.skip(
|
|
16
|
+
!adminKey,
|
|
17
|
+
"Local admin access is required to verify R2 is disabled",
|
|
18
|
+
);
|
|
19
|
+
const configured = await Promise.all(
|
|
20
|
+
[
|
|
21
|
+
"R2_ACCOUNT_ID",
|
|
22
|
+
"R2_BUCKET_NAME",
|
|
23
|
+
"R2_ACCESS_KEY_ID",
|
|
24
|
+
"R2_SECRET_ACCESS_KEY",
|
|
25
|
+
].map(async (name) => {
|
|
26
|
+
const response = await fetch(`${url.origin}/api/query`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
signal: AbortSignal.timeout(15000),
|
|
29
|
+
headers: {
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
Authorization: `Convex ${adminKey}`,
|
|
32
|
+
},
|
|
33
|
+
body: JSON.stringify({
|
|
34
|
+
path: "_system/cli/queryEnvironmentVariables:get",
|
|
35
|
+
args: { name },
|
|
36
|
+
format: "json",
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
const result = await response.json();
|
|
40
|
+
expect(result.status).toBe("success");
|
|
41
|
+
return Boolean(result.value?.value?.trim());
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
test.skip(
|
|
45
|
+
configured.every(Boolean),
|
|
46
|
+
"R2 configured; fallback test must not call a cloud provider",
|
|
47
|
+
);
|
|
14
48
|
async function call(
|
|
15
49
|
kind: string,
|
|
16
50
|
path: string,
|
|
@@ -42,6 +76,15 @@ test(
|
|
|
42
76
|
expect(first.value?.status).toBe("complete");
|
|
43
77
|
const token = first.value.tokens.accessToken as string;
|
|
44
78
|
const content = `Owned file ${randomUUID()}`;
|
|
79
|
+
expect(
|
|
80
|
+
(
|
|
81
|
+
await call("action", "files/index:upload", {
|
|
82
|
+
filename: "anonymous.txt",
|
|
83
|
+
mediaType: "text/plain",
|
|
84
|
+
bytes: { $bytes: Buffer.from(content).toString("base64") },
|
|
85
|
+
})
|
|
86
|
+
).status,
|
|
87
|
+
).toBe("error");
|
|
45
88
|
const uploaded = await call(
|
|
46
89
|
"action",
|
|
47
90
|
"files/index:upload",
|
|
@@ -69,6 +112,11 @@ test(
|
|
|
69
112
|
renewed,
|
|
70
113
|
);
|
|
71
114
|
expect(download.status).toBe("success");
|
|
115
|
+
expect(
|
|
116
|
+
["127.0.0.1", "localhost", "[::1]"].includes(
|
|
117
|
+
new URL(download.value.url).hostname,
|
|
118
|
+
),
|
|
119
|
+
).toBe(true);
|
|
72
120
|
expect(await (await fetch(download.value.url)).text()).toBe(content);
|
|
73
121
|
const other = await call("mutation", "auth:signUpWithUsernamePassword", {
|
|
74
122
|
username: `other${randomUUID().replaceAll("-", "")}`,
|