Skip to content

Commit f719da1

Browse files
committed
Merge remote-tracking branch 'origin/main' into t3/opencode-service-update-takeover
2 parents c7e2cb5 + c58f472 commit f719da1

789 files changed

Lines changed: 41628 additions & 7234 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,16 @@ jobs:
140140
- name: Start installing browser secret helper build libraries
141141
if: needs.changes.outputs.build != 'false'
142142
run: |
143-
sudo sed -i 's|http://|https://|g' /etc/apt/blacksmith-ubuntu-mirrors.txt /etc/apt/sources.list.d/ubuntu.sources
143+
# Fetch only the indexes these main and universe packages need. The full set is ~42 MB,
144+
# which a slow mirror can stretch past the wait below.
145+
sudo sed -i -e 's|http://|https://|g' -e 's/^Components: .*/Components: main universe/' \
146+
/etc/apt/blacksmith-ubuntu-mirrors.txt /etc/apt/sources.list.d/ubuntu.sources
144147
(
145148
set +e
146-
sudo apt-get update && sudo apt-get install -y libsecret-1-dev pkg-config xvfb
149+
sudo apt-get update -o Acquire::Languages=none \
150+
-o Acquire::IndexTargets::deb::DEP-11::DefaultEnabled=false \
151+
-o Acquire::IndexTargets::deb::CNF::DefaultEnabled=false &&
152+
sudo apt-get install -y libsecret-1-dev pkg-config xvfb
147153
echo "$?" > "$RUNNER_TEMP/apt-status"
148154
) > "$RUNNER_TEMP/apt.log" 2>&1 < /dev/null &
149155
@@ -287,10 +293,16 @@ jobs:
287293
# the background while Vite+ installs; the step before the tests waits for it.
288294
- name: Start installing browser secret helper build libraries
289295
run: |
290-
sudo sed -i 's|http://|https://|g' /etc/apt/blacksmith-ubuntu-mirrors.txt /etc/apt/sources.list.d/ubuntu.sources
296+
# Fetch only the indexes these main and universe packages need. The full set is ~42 MB,
297+
# which a slow mirror can stretch past the wait below.
298+
sudo sed -i -e 's|http://|https://|g' -e 's/^Components: .*/Components: main universe/' \
299+
/etc/apt/blacksmith-ubuntu-mirrors.txt /etc/apt/sources.list.d/ubuntu.sources
291300
(
292301
set +e
293-
sudo apt-get update && sudo apt-get install -y libsecret-1-dev pkg-config
302+
sudo apt-get update -o Acquire::Languages=none \
303+
-o Acquire::IndexTargets::deb::DEP-11::DefaultEnabled=false \
304+
-o Acquire::IndexTargets::deb::CNF::DefaultEnabled=false &&
305+
sudo apt-get install -y libsecret-1-dev pkg-config
294306
echo "$?" > "$RUNNER_TEMP/apt-status"
295307
) > "$RUNNER_TEMP/apt.log" 2>&1 < /dev/null &
296308
@@ -343,16 +355,22 @@ jobs:
343355
344356
# The web suite is the largest outside the server. In the shared Test job it
345357
# started last and ran alone for about 40s after everything else finished.
346-
# release.yml mirrors this test, test_web, and test_server split.
358+
# Browser tests are bound by the Vite server transforming modules for each
359+
# file, not by Chromium, so a second runner (and Vite server) halves the job
360+
# that gated every run. release.yml mirrors this test, test_web, and test_server split.
347361
test_web:
348362
permissions:
349363
contents: read
350364
id-token: write
351-
name: Test Web
365+
name: Test Web ${{ matrix.shard }}
352366
needs: changes
353367
if: ${{ !cancelled() && needs.changes.outputs.test_web != 'false' }}
354368
runs-on: blacksmith-8vcpu-ubuntu-2404
355369
timeout-minutes: 10
370+
strategy:
371+
fail-fast: false
372+
matrix:
373+
shard: [1, 2]
356374
steps:
357375
- name: Checkout
358376
uses: actions/checkout@v6
@@ -394,7 +412,7 @@ jobs:
394412
fi
395413
396414
- name: Test
397-
run: vp run --filter @t3tools/web test
415+
run: vp run --filter @t3tools/web test --shard ${{ matrix.shard }}/${{ strategy.job-total }}
398416

399417
# apps/server sets `fileParallelism: false`, so its test files run strictly
400418
# one at a time. Sharding spreads them over separate runners instead of
@@ -469,6 +487,17 @@ jobs:
469487
node apps/server/node_modules/playwright-core/cli.js install-deps chromium
470488
fi
471489
490+
# Each server test file runs in its own Vitest process, and a fresh install starts
491+
# Vitest's content-keyed module cache empty, so every file re-transformed its imports.
492+
# Only pushes to main save it, so pull requests never evict each other's entries.
493+
- name: Restore Vitest module cache
494+
if: steps.changes.outputs.test_server != 'false'
495+
uses: actions/cache/restore@v6
496+
with:
497+
path: node_modules/.vitest-cache
498+
key: vitest-modules-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }}
499+
restore-keys: vitest-modules-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-
500+
472501
- name: Test
473502
if: steps.changes.outputs.test_server != 'false'
474503
env:
@@ -477,15 +506,14 @@ jobs:
477506
run: >-
478507
vp run test:cached -- --shard ${{ matrix.shard }}/${{ strategy.job-total }}
479508
--uncached apps/server/integration/transferBudgetV2.integration.test.ts
480-
--verify-hits 1 --report "${{ runner.temp }}/test-cache-${{ matrix.shard }}.json" apps/server
509+
--verify-hits 1 apps/server
481510
482-
- name: Upload test cache measurements
483-
if: always() && steps.changes.outputs.test_server != 'false'
484-
uses: actions/upload-artifact@v7
511+
- name: Save Vitest module cache
512+
if: github.event_name == 'push' && steps.changes.outputs.test_server != 'false'
513+
uses: actions/cache/save@v6
485514
with:
486-
name: test-cache-${{ matrix.shard }}
487-
path: ${{ runner.temp }}/test-cache-${{ matrix.shard }}.json
488-
if-no-files-found: error
515+
path: node_modules/.vitest-cache
516+
key: vitest-modules-server-${{ matrix.shard }}-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }}
489517

490518
# integration/transferBudgetV2.integration.test.ts writes the report; exactly one shard
491519
# produces these files. Gating the upload on their presence keeps a

‎.github/workflows/release.yml‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,15 @@ jobs:
300300
# Web browser tests time out when they share a runner with the other package
301301
# suites: Chromium gets too little CPU and diff workers miss their 10s start budget.
302302
test_web:
303-
name: Release web tests
303+
name: Release web tests ${{ matrix.shard }}
304304
needs: [preflight]
305305
if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' }}
306306
runs-on: blacksmith-8vcpu-ubuntu-2404
307307
timeout-minutes: 10
308+
strategy:
309+
fail-fast: false
310+
matrix:
311+
shard: [1, 2]
308312
steps:
309313
- name: Checkout
310314
uses: actions/checkout@v6
@@ -344,10 +348,11 @@ jobs:
344348
fi
345349
346350
- name: Test
347-
run: vp run --filter @t3tools/web test
351+
run: vp run --filter @t3tools/web test --shard ${{ matrix.shard }}/${{ strategy.job-total }}
348352

349353
# Browser tests run source modules; this boots the production chunk graph.
350354
- name: Boot the built web client
355+
if: matrix.shard == 1
351356
run: |
352357
vp run --filter @t3tools/web build
353358
node apps/web/scripts/verify-built-boot.ts
@@ -1482,7 +1487,18 @@ jobs:
14821487
14831488
git add apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json pnpm-lock.yaml
14841489
git commit --no-verify -m "chore(release): prepare $RELEASE_TAG"
1485-
git push origin HEAD:main
1490+
1491+
# main moves while this job runs, so a rejected push rebases and retries.
1492+
for attempt in 1 2 3 4 5; do
1493+
if git push origin HEAD:main; then
1494+
exit 0
1495+
fi
1496+
echo "Push rejected (attempt $attempt). Rebasing onto latest main."
1497+
git pull --rebase origin main
1498+
done
1499+
1500+
echo "Could not push the version bump after 5 attempts." >&2
1501+
exit 1
14861502
14871503
announce_discord:
14881504
name: Announce release on Discord

‎apps/desktop/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@t3tools/desktop",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"private": true,
55
"type": "module",
66
"main": "dist-electron/boot.cjs",
@@ -37,6 +37,7 @@
3737
"acorn": "8.16.0",
3838
"cross-env": "^10.1.0",
3939
"electron-builder": "26.16.1",
40+
"jsdom": "^30.0.1",
4041
"tailwindcss": "^4.0.0",
4142
"vite-plus": "catalog:"
4243
},

‎apps/desktop/src/app/ClerkTokenStore.test.ts‎

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import * as NodeFS from "node:fs";
33
import * as NodeOS from "node:os";
44
import * as NodePath from "node:path";
55
import { assert, describe, it } from "@effect/vitest";
6-
import { vi } from "vite-plus/test";
7-
8-
vi.mock("node:fs", { spy: true });
96

107
import { openClerkTokenStorage, type ClerkTokenStorage } from "./ClerkTokenStore.ts";
118

@@ -91,24 +88,6 @@ describePosix("ClerkTokenStore", () => {
9188
});
9289
});
9390

94-
it("removes the legacy token file when the private copy already exists", async () => {
95-
await withStateDir((stateDir) => {
96-
const directory = NodePath.join(stateDir, "clerk");
97-
const legacyPath = NodePath.join(stateDir, "clerk-tokens.json");
98-
const tokenPath = NodePath.join(directory, "clerk-tokens.json");
99-
NodeFS.mkdirSync(directory, { mode: 0o755 });
100-
writeLoose(legacyPath, "stale-credential");
101-
writeLoose(tokenPath, "kept-credential");
102-
103-
openClerkTokenStorage(stateDir, () => idleStorage());
104-
105-
assert.equal(NodeFS.existsSync(legacyPath), false);
106-
assert.equal(modeOf(directory), 0o700);
107-
assert.equal(modeOf(tokenPath), 0o600);
108-
assert.equal(NodeFS.readFileSync(tokenPath, "utf8"), "kept-credential");
109-
});
110-
});
111-
11291
it("resolves a relative state directory before opening storage", async () => {
11392
await withStateDir(async (stateDir) => {
11493
const relativeStateDir = NodePath.relative(process.cwd(), stateDir);
@@ -150,23 +129,6 @@ describePosix("ClerkTokenStore", () => {
150129
});
151130
});
152131

153-
it("migrates tokens when the legacy directory is on another filesystem", async () => {
154-
await withStateDir((stateDir) => {
155-
const legacyPath = NodePath.join(stateDir, "clerk-tokens.json");
156-
writeLoose(legacyPath, "existing-session");
157-
using _rename = vi.spyOn(NodeFS, "renameSync").mockImplementation(() => {
158-
throw Object.assign(new Error("cross-device link"), { code: "EXDEV" });
159-
});
160-
161-
openClerkTokenStorage(stateDir, idleStorage);
162-
163-
const tokenPath = NodePath.join(stateDir, "clerk", "clerk-tokens.json");
164-
assert.equal(NodeFS.readFileSync(tokenPath, "utf8"), "existing-session");
165-
assert.equal(modeOf(tokenPath), 0o600);
166-
assert.equal(NodeFS.existsSync(legacyPath), false);
167-
});
168-
});
169-
170132
it("does not follow a symlinked clerk directory or token file", async () => {
171133
await withStateDir(async (stateDir) => {
172134
const outsideDirectory = NodePath.join(stateDir, "outside-dir");

‎apps/desktop/src/app/DesktopApp.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Layer from "effect/Layer";
77
import * as FileSystem from "effect/FileSystem";
88
import * as Path from "effect/Path";
99
import * as HttpClient from "effect/http/HttpClient";
10+
import { ChildProcessSpawner } from "effect/process";
1011
import * as NetService from "@t3tools/shared/Net";
1112
import * as Fiber from "effect/Fiber";
1213
import * as Option from "effect/Option";
@@ -213,6 +214,7 @@ it.effect.each([false, true])(
213214
Effect.provide(
214215
Layer.mergeAll(
215216
Layer.mock(BrowserImport.BrowserImport, {}),
217+
Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {}),
216218
Layer.mock(DesktopBackendConfiguration.DesktopBackendConfiguration, {}),
217219
Layer.mock(DesktopCliCommand.DesktopCliCommand, {}),
218220
Layer.mock(DesktopClientSettings.DesktopClientSettings, {}),

‎apps/desktop/src/app/DesktopClerk.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ export const make = Effect.gen(function* () {
116116
yield* electronApp.quit;
117117
return yield* Effect.interrupt;
118118
}
119+
// Chromium opens these caches at the first event-loop turn, before ready.
120+
yield* DesktopUserData.clearStaleGpuCaches({
121+
userDataPath,
122+
electronVersion: process.versions.electron,
123+
});
119124

120125
const pendingSecondInstances: Array<readonly string[]> = [];
121126
let handleSecondInstance = (argv: readonly string[]) => {

‎apps/desktop/src/app/DesktopPreReadyFileSystem.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ export const make = FileSystem.makeNoop({
4949
syncFs("makeDirectory", path, () => {
5050
NodeFS.mkdirSync(path, { recursive: options?.recursive ?? false });
5151
}),
52+
remove: (path, options) =>
53+
syncFs("remove", path, () =>
54+
NodeFS.rmSync(path, {
55+
recursive: options?.recursive ?? false,
56+
force: options?.force ?? false,
57+
}),
58+
),
5259
writeFileString: (path, data, options) =>
5360
syncFs("writeFileString", path, () =>
5461
NodeFS.writeFileSync(path, data, { flag: options?.flag ?? "w" }),

‎apps/desktop/src/app/DesktopUserData.test.ts‎

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { assert, it } from "@effect/vitest";
33
import * as Effect from "effect/Effect";
44
import * as FileSystem from "effect/FileSystem";
55
import * as Path from "effect/Path";
6+
import * as PlatformError from "effect/PlatformError";
67

7-
import { resolveUserDataPath } from "./DesktopUserData.ts";
8+
import { clearStaleGpuCaches, resolveUserDataPath } from "./DesktopUserData.ts";
89

910
it.effect.each(["t3code", "T3 Code (Alpha)"])(
1011
"preserves Windows credential keys from %s without copying browser databases",
@@ -40,3 +41,100 @@ it.effect.each(["t3code", "T3 Code (Alpha)"])(
4041
);
4142
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
4243
);
44+
45+
const gpuCacheDirectories = [
46+
"GPUCache",
47+
"GrShaderCache",
48+
"ShaderCache",
49+
"DawnGraphiteCache",
50+
"DawnWebGPUCache",
51+
"GPUPersistentCache",
52+
];
53+
54+
it.effect.each([
55+
{ profile: "written by Electron 44.10.0", marker: "44.10.0" },
56+
{ profile: "with no recorded Electron version", marker: undefined },
57+
])("clears GPU caches $profile once when Electron 44.10.1 starts", ({ marker }) =>
58+
Effect.gen(function* () {
59+
const fs = yield* FileSystem.FileSystem;
60+
const path = yield* Path.Path;
61+
const userDataPath = yield* fs.makeTempDirectoryScoped({ prefix: "t3-v2-gpu-cache-" });
62+
for (const name of gpuCacheDirectories) {
63+
yield* fs.makeDirectory(path.join(userDataPath, name), { recursive: true });
64+
yield* fs.writeFileString(path.join(userDataPath, name, "data_0"), "44.10.0 shaders");
65+
}
66+
yield* fs.makeDirectory(path.join(userDataPath, "Local Storage"), { recursive: true });
67+
yield* fs.writeFileString(path.join(userDataPath, "Local Storage", "LOCK"), "profile");
68+
yield* fs.writeFileString(path.join(userDataPath, "Local State"), "profile");
69+
if (marker !== undefined) {
70+
yield* fs.writeFileString(path.join(userDataPath, "gpu-cache-electron-version"), marker);
71+
}
72+
73+
yield* clearStaleGpuCaches({ userDataPath, electronVersion: "44.10.1" });
74+
75+
const survivingCaches: Array<string> = [];
76+
for (const name of gpuCacheDirectories) {
77+
if (yield* fs.exists(path.join(userDataPath, name))) survivingCaches.push(name);
78+
}
79+
assert.deepStrictEqual(survivingCaches, []);
80+
assert.equal(
81+
yield* fs.readFileString(path.join(userDataPath, "Local Storage", "LOCK")),
82+
"profile",
83+
);
84+
assert.equal(yield* fs.readFileString(path.join(userDataPath, "Local State")), "profile");
85+
86+
yield* fs.makeDirectory(path.join(userDataPath, "GPUCache"));
87+
yield* fs.writeFileString(path.join(userDataPath, "GPUCache", "data_0"), "44.10.1 shaders");
88+
yield* clearStaleGpuCaches({ userDataPath, electronVersion: "44.10.1" });
89+
assert.equal(
90+
yield* fs.readFileString(path.join(userDataPath, "GPUCache", "data_0")),
91+
"44.10.1 shaders",
92+
);
93+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
94+
);
95+
96+
it.effect("keeps GPU caches built on the first launch of a fresh install", () =>
97+
Effect.gen(function* () {
98+
const fs = yield* FileSystem.FileSystem;
99+
const path = yield* Path.Path;
100+
const appData = yield* fs.makeTempDirectoryScoped({ prefix: "t3-v2-fresh-" });
101+
const userDataPath = path.join(appData, "t3code-v2");
102+
103+
yield* clearStaleGpuCaches({ userDataPath, electronVersion: "44.10.1" });
104+
yield* fs.makeDirectory(path.join(userDataPath, "GPUCache"));
105+
yield* fs.writeFileString(path.join(userDataPath, "GPUCache", "data_0"), "44.10.1 shaders");
106+
yield* clearStaleGpuCaches({ userDataPath, electronVersion: "44.10.1" });
107+
108+
assert.equal(
109+
yield* fs.readFileString(path.join(userDataPath, "GPUCache", "data_0")),
110+
"44.10.1 shaders",
111+
);
112+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
113+
);
114+
115+
it.effect("retries on the next launch when a GPU cache cannot be removed", () =>
116+
Effect.gen(function* () {
117+
const writes: Array<string> = [];
118+
const fileSystem = FileSystem.makeNoop({
119+
remove: (path) =>
120+
Effect.fail(
121+
PlatformError.systemError({
122+
_tag: "PermissionDenied",
123+
module: "FileSystem",
124+
method: "remove",
125+
pathOrDescriptor: path,
126+
}),
127+
),
128+
writeFileString: (path) =>
129+
Effect.sync(() => {
130+
writes.push(path);
131+
}),
132+
});
133+
134+
yield* clearStaleGpuCaches({ userDataPath: "/profile", electronVersion: "44.10.1" }).pipe(
135+
Effect.provideService(FileSystem.FileSystem, fileSystem),
136+
);
137+
138+
assert.deepStrictEqual(writes, []);
139+
}).pipe(Effect.provide(NodeServices.layer)),
140+
);

0 commit comments

Comments
 (0)