create-disposabl-app 0.12.0 → 0.13.1
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/bun.lock +5 -0
- 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/server/files-functions.ts +1 -1
- 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/package.json +1 -1
|
@@ -2,7 +2,13 @@ import config from "../../../../disposabl.json";
|
|
|
2
2
|
import { makeFunctionReference } from "convex/server";
|
|
3
3
|
|
|
4
4
|
export type TelemetryEvent =
|
|
5
|
-
|
|
5
|
+
| "api_operation"
|
|
6
|
+
| "mcp_operation"
|
|
7
|
+
| "page_view"
|
|
8
|
+
| "screen_view"
|
|
9
|
+
| "app_setup"
|
|
10
|
+
| "app_created"
|
|
11
|
+
| "platform_deployment";
|
|
6
12
|
export type TelemetryProperties = {
|
|
7
13
|
source?: "api" | "cli" | "sdk" | "mcp";
|
|
8
14
|
operation?: string;
|
|
@@ -16,6 +22,23 @@ export type TelemetryProperties = {
|
|
|
16
22
|
| "account"
|
|
17
23
|
| "other";
|
|
18
24
|
duration_ms?: number;
|
|
25
|
+
/** Server-owned app identity; hashed before leaving the backend. */
|
|
26
|
+
app_id?: string;
|
|
27
|
+
time_since_app_creation_ms?: number;
|
|
28
|
+
run_number?: number;
|
|
29
|
+
run_attempt?: number;
|
|
30
|
+
platform?:
|
|
31
|
+
| "web"
|
|
32
|
+
| "android"
|
|
33
|
+
| "ios"
|
|
34
|
+
| "macos"
|
|
35
|
+
| "windows"
|
|
36
|
+
| "linux"
|
|
37
|
+
| "api"
|
|
38
|
+
| "mcp"
|
|
39
|
+
| "typescript-sdk"
|
|
40
|
+
| "cli";
|
|
41
|
+
channel?: "production" | "preview";
|
|
19
42
|
};
|
|
20
43
|
|
|
21
44
|
type AnalyticsConfig = {
|
|
@@ -45,7 +68,16 @@ export function telemetryEnabled(settingsOverride: AnalyticsConfig = settings) {
|
|
|
45
68
|
);
|
|
46
69
|
}
|
|
47
70
|
|
|
48
|
-
|
|
71
|
+
async function opaqueId(value: string) {
|
|
72
|
+
return Array.from(
|
|
73
|
+
new Uint8Array(
|
|
74
|
+
await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value)),
|
|
75
|
+
),
|
|
76
|
+
(b) => b.toString(16).padStart(2, "0"),
|
|
77
|
+
).join("");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Only trusted server callers can supply a user or app ID. */
|
|
49
81
|
export async function captureTelemetry(
|
|
50
82
|
event: TelemetryEvent,
|
|
51
83
|
properties: TelemetryProperties,
|
|
@@ -58,17 +90,12 @@ export async function captureTelemetry(
|
|
|
58
90
|
process.env.POSTHOG_PROJECT_TOKEN!;
|
|
59
91
|
const host = settingsOverride.analytics?.host ?? process.env.POSTHOG_HOST!;
|
|
60
92
|
const identity = userId
|
|
61
|
-
?
|
|
62
|
-
new Uint8Array(
|
|
63
|
-
await crypto.subtle.digest(
|
|
64
|
-
"SHA-256",
|
|
65
|
-
new TextEncoder().encode(`disposabl:${token}:${userId}`),
|
|
66
|
-
),
|
|
67
|
-
),
|
|
68
|
-
(b) => b.toString(16).padStart(2, "0"),
|
|
69
|
-
).join("")
|
|
93
|
+
? await opaqueId(`disposabl:${token}:${userId}`)
|
|
70
94
|
: crypto.randomUUID();
|
|
71
95
|
const safe = {
|
|
96
|
+
...(properties.app_id && {
|
|
97
|
+
app_id: await opaqueId(`disposabl:${token}:app:${properties.app_id}`),
|
|
98
|
+
}),
|
|
72
99
|
...(["api", "cli", "sdk", "mcp"].includes(properties.source ?? "") && {
|
|
73
100
|
source: properties.source,
|
|
74
101
|
}),
|
|
@@ -88,11 +115,34 @@ export async function captureTelemetry(
|
|
|
88
115
|
"account",
|
|
89
116
|
"other",
|
|
90
117
|
].includes(properties.page ?? "") && { page: properties.page }),
|
|
118
|
+
...([
|
|
119
|
+
"web",
|
|
120
|
+
"android",
|
|
121
|
+
"ios",
|
|
122
|
+
"macos",
|
|
123
|
+
"windows",
|
|
124
|
+
"linux",
|
|
125
|
+
"api",
|
|
126
|
+
"mcp",
|
|
127
|
+
"typescript-sdk",
|
|
128
|
+
"cli",
|
|
129
|
+
].includes(properties.platform ?? "") && { platform: properties.platform }),
|
|
130
|
+
...(["production", "preview"].includes(properties.channel ?? "") && {
|
|
131
|
+
channel: properties.channel,
|
|
132
|
+
}),
|
|
91
133
|
...(Number.isFinite(properties.duration_ms) &&
|
|
92
134
|
properties.duration_ms! >= 0 &&
|
|
93
|
-
properties.duration_ms! <=
|
|
135
|
+
properties.duration_ms! <= Number.MAX_SAFE_INTEGER && {
|
|
94
136
|
duration_ms: Math.round(properties.duration_ms!),
|
|
95
137
|
}),
|
|
138
|
+
...Object.fromEntries(
|
|
139
|
+
(["time_since_app_creation_ms", "run_number", "run_attempt"] as const)
|
|
140
|
+
.filter(
|
|
141
|
+
(key) =>
|
|
142
|
+
Number.isSafeInteger(properties[key]) && properties[key]! >= 0,
|
|
143
|
+
)
|
|
144
|
+
.map((key) => [key, properties[key]]),
|
|
145
|
+
),
|
|
96
146
|
};
|
|
97
147
|
try {
|
|
98
148
|
await fetch(`${host}/capture/`, {
|
|
@@ -25,6 +25,8 @@ The initial flows check the public web page, the dashboard's authentication boun
|
|
|
25
25
|
|
|
26
26
|
The repository's agent fixture flow (`flows/agent.e2e.ts`) creates test users, an app, and component history to verify ownership, pagination, and worker state without calling Boat. It requires `E2E_CONVEX_ADMIN_KEY` and explicitly skips when the key is absent; admin fixture calls are restricted to a loopback backend. Use only a disposable local deployment and keep the key out of source control and logs. Run through the `bun run e2e` or `bun run test` wrappers so E2E telemetry stays disabled.
|
|
27
27
|
|
|
28
|
+
The storage fallback flow (`flows/files.e2e.ts`) uses the same loopback/admin restriction to confirm R2 is not configured before uploading. It checks downloaded bytes, anonymous and cross-user rejection, and owner deletion, removing only its own new file. It makes no R2 requests and skips when R2 is fully configured.
|
|
29
|
+
|
|
28
30
|
The connections browser flow additionally exercises invalid Autumn key submission when `E2E_CONNECTIONS_ENABLED=1`. Set a temporary `CONNECTIONS_ENCRYPTION_KEY` on the isolated backend for that run; the invalid input is rejected before any Autumn request. Restore the backend setting afterward.
|
|
29
31
|
|
|
30
32
|
## Email provider verification
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import {
|
|
4
|
+
mkdtempSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
rmSync,
|
|
9
|
+
} from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join, resolve } from "node:path";
|
|
12
|
+
import { execFileSync } from "node:child_process";
|
|
13
|
+
test("iOS builds can be paused independently of Android", () => {
|
|
14
|
+
const dir = mkdtempSync(join(tmpdir(), "disposabl-platforms-"));
|
|
15
|
+
try {
|
|
16
|
+
mkdirSync(join(dir, "bin"));
|
|
17
|
+
writeFileSync(
|
|
18
|
+
join(dir, "bin/gh"),
|
|
19
|
+
'#!/bin/sh\ncase "$*" in *pulls/1/files*) echo apps/mobile/src/app/index.tsx;; *) exit 1;; esac\n',
|
|
20
|
+
{ mode: 0o755 },
|
|
21
|
+
);
|
|
22
|
+
writeFileSync(
|
|
23
|
+
join(dir, "disposabl.json"),
|
|
24
|
+
JSON.stringify({ platforms: ["web", "android", "ios"], features: [] }),
|
|
25
|
+
);
|
|
26
|
+
const out = join(dir, "output");
|
|
27
|
+
const env = {
|
|
28
|
+
...process.env,
|
|
29
|
+
PATH: join(dir, "bin") + ":" + process.env.PATH,
|
|
30
|
+
PR: "1",
|
|
31
|
+
GH_REPO: "fixture/app",
|
|
32
|
+
RUNNER_TEMP: dir,
|
|
33
|
+
GITHUB_OUTPUT: out,
|
|
34
|
+
EXPO_CONNECTED: "true",
|
|
35
|
+
};
|
|
36
|
+
execFileSync(
|
|
37
|
+
"bash",
|
|
38
|
+
[resolve(import.meta.dirname, "../../.github/scripts/platforms.sh")],
|
|
39
|
+
{ cwd: dir, env: { ...env, IOS_BUILDS_ENABLED: "false" } },
|
|
40
|
+
);
|
|
41
|
+
assert.match(readFileSync(out, "utf8"), /^ios=false$/m);
|
|
42
|
+
assert.match(readFileSync(out, "utf8"), /^android=true$/m);
|
|
43
|
+
writeFileSync(out, "");
|
|
44
|
+
execFileSync(
|
|
45
|
+
"bash",
|
|
46
|
+
[resolve(import.meta.dirname, "../../.github/scripts/platforms.sh")],
|
|
47
|
+
{ cwd: dir, env: { ...env, IOS_BUILDS_ENABLED: "true" } },
|
|
48
|
+
);
|
|
49
|
+
assert.match(readFileSync(out, "utf8"), /^ios=true$/m);
|
|
50
|
+
} finally {
|
|
51
|
+
rmSync(dir, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
@@ -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
|
+
});
|