Skip to content

Commit 192f01f

Browse files
committed
Merge remote-tracking branch 'github/main' into feat/textgen-error-model
# Conflicts: # apps/server/src/textGeneration/CodexTextGeneration.test.ts
2 parents c9094be + 10af8ee commit 192f01f

1,191 files changed

Lines changed: 57162 additions & 12262 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/actions/setup-ci-deps/action.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ runs:
123123
key: ${{ steps.pnpm_verified.outputs.cache-primary-key }}
124124

125125
# A filtered install that started from the current full store adds nothing
126-
# worth a second copy of it.
126+
# worth a second copy of it. A stacked PR, based on a branch other than the
127+
# default, saves a ~1 GB store only its own reruns can read, so it only restores.
127128
- name: Save pnpm store
128129
if: >-
129130
inputs.install == 'true' &&
131+
(github.event_name != 'pull_request' || github.base_ref == github.event.repository.default_branch) &&
130132
steps.pnpm_cache.outputs.cache-hit != 'true' &&
131133
(steps.pnpm_store.outputs.namespace == 'full' ||
132134
steps.pnpm_cache.outputs.cache-matched-key != format('pnpm-full-v1-{0}-{1}-{2}', runner.os, runner.arch, hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json')))

‎.github/workflows/ci.yml‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,41 @@ jobs:
192192
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
193193
run: node apps/desktop/scripts/verify-preload-bundle.mjs
194194

195+
# Browser tests run source modules; this boots the production chunk graph. The
196+
# desktop build above already produced apps/web/dist, and the client waits about
197+
# 15s for a session that never comes, so this runs here instead of in Test Web,
198+
# which gates the whole run. Chromium comes from the cache Test Web shares.
199+
- name: Resolve Playwright version
200+
id: playwright_version
201+
if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }}
202+
run: echo "version=$(node -p "require('./apps/web/node_modules/playwright/package.json').version")" >> "$GITHUB_OUTPUT"
203+
204+
- name: Cache Chromium
205+
id: chromium_cache
206+
if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }}
207+
uses: actions/cache@v6
208+
with:
209+
path: ~/.cache/ms-playwright
210+
key: playwright-chromium-shell-${{ runner.os }}-${{ runner.arch }}-${{ steps.playwright_version.outputs.version }}
211+
212+
- name: Install Chromium for the built web client boot check
213+
if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' && steps.chromium_cache.outputs.cache-hit != 'true' }}
214+
run: node apps/web/node_modules/playwright/cli.js install --only-shell chromium
215+
216+
- name: Install missing Chromium system dependencies
217+
if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }}
218+
run: |
219+
browser=$(find "$HOME/.cache/ms-playwright" -name chrome-headless-shell -type f -print -quit)
220+
test -n "$browser"
221+
if ldd "$browser" | grep '=> not found'; then
222+
node apps/web/node_modules/playwright/cli.js install-deps chromium
223+
fi
224+
225+
- name: Boot the built web client
226+
if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }}
227+
timeout-minutes: 3
228+
run: node apps/web/scripts/verify-built-boot.ts
229+
195230
- name: Typecheck
196231
if: ${{ !cancelled() && steps.typecheck.outcome == 'success' }}
197232
timeout-minutes: 5
@@ -340,12 +375,6 @@ jobs:
340375
- name: Test
341376
run: vp run --filter @t3tools/web test
342377

343-
# Browser tests run source modules; this boots the production chunk graph.
344-
- name: Boot the built web client
345-
run: |
346-
vp run --filter @t3tools/web build
347-
node apps/web/scripts/verify-built-boot.ts
348-
349378
# apps/server sets `fileParallelism: false`, so its test files run strictly
350379
# one at a time. Sharding spreads them over separate runners instead of
351380
# separate workers, so no two server test files ever share a machine and the

‎.github/workflows/release-desktop.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ jobs:
449449
name: cli-${{ inputs.platform }}-${{ inputs.arch }}
450450
path: release-cli/*
451451
if-no-files-found: error
452+
# The archive is already gzip or zip; deflating it again saves under 2%.
453+
compression-level: 0
452454

453455
- name: Install Linux desktop build libraries
454456
if: inputs.platform == 'linux'
@@ -761,6 +763,8 @@ jobs:
761763
name: desktop-${{ inputs.platform }}-${{ inputs.arch }}
762764
path: release-publish/*
763765
if-no-files-found: error
766+
# Installers, zips and blockmaps are already compressed; deflating them again saves under 0.3%.
767+
compression-level: 0
764768

765769
- name: Upload resource monitor
766770
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7

‎.macroscope/ignore.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,7 @@ native/libghostty-vt/include/**
279279
# it needs. Regenerated by apps/mobile/scripts/generate-highlights.mts; review
280280
# that script and cpp/t3_highlights.c instead.
281281
apps/mobile/modules/t3-highlights/Vendor/**
282+
283+
# Nitro bindings for T3Highlights. Regenerated by `vp run generate:nitro` in
284+
# apps/mobile from modules/t3-highlights/src/T3Highlights.nitro.ts.
285+
apps/mobile/modules/t3-highlights/nitrogen/generated/**

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

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { assert, it } from "@effect/vitest";
22
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
33
import * as Deferred from "effect/Deferred";
44
import * as Effect from "effect/Effect";
5+
import * as Exit from "effect/Exit";
56
import * as Layer from "effect/Layer";
67
import * as FileSystem from "effect/FileSystem";
78
import * as Path from "effect/Path";
@@ -69,14 +70,19 @@ import * as ElectronWindow from "../electron/ElectronWindow.ts";
6970
import * as MacPermissions from "../permissions/MacPermissions.ts";
7071
import * as PreviewManager from "../preview/Manager.ts";
7172

72-
it.effect(
73-
"starts the backend and window while Linux registration is stalled and cancels it on shutdown",
74-
() =>
73+
it.effect.each([false, true])(
74+
"stops backends together before flushing history and cancels Linux registration, stop defect=%s",
75+
(stopDefect) =>
7576
Effect.gen(function* () {
7677
const registrationStarted = yield* Deferred.make<void>();
7778
const releaseRegistration = yield* Deferred.make<void>();
7879
const registrationStopped = yield* Deferred.make<void>();
7980
const windowStarted = yield* Deferred.make<void>();
81+
const firstStopStarted = yield* Deferred.make<void>();
82+
const secondStopStarted = yield* Deferred.make<void>();
83+
const releaseStops = yield* Deferred.make<void>();
84+
const historyStarted = yield* Deferred.make<void>();
85+
const releaseHistory = yield* Deferred.make<void>();
8086
const quitting = yield* Ref.make(false);
8187
const events: string[] = [];
8288
const record = (event: string) =>
@@ -169,7 +175,21 @@ it.effect(
169175
start: record("backend"),
170176
currentConfig: Effect.succeedSome({ preflightFailure: Option.none() }),
171177
}),
172-
list: Effect.succeed([]),
178+
list: Effect.succeed([
179+
{
180+
stop: () =>
181+
Deferred.succeed(firstStopStarted, undefined).pipe(
182+
Effect.andThen(Deferred.await(releaseStops)),
183+
Effect.andThen(stopDefect ? Effect.die("stop defect") : Effect.void),
184+
),
185+
},
186+
{
187+
stop: () =>
188+
Deferred.succeed(secondStopStarted, undefined).pipe(
189+
Effect.andThen(Deferred.await(releaseStops)),
190+
),
191+
},
192+
]),
173193
} as unknown as DesktopBackendPool.DesktopBackendPool["Service"]),
174194
Effect.provideService(DesktopServerExposure.DesktopServerExposure, {
175195
configureFromSettings: () => Effect.succeed({ mode: "local-only" }),
@@ -182,7 +202,10 @@ it.effect(
182202
start: Effect.void,
183203
} as unknown as DesktopAppActivation.DesktopAppActivation["Service"]),
184204
Effect.provideService(DesktopRendererHistory.DesktopRendererHistory, {
185-
shutdown: Effect.void,
205+
shutdown: Deferred.succeed(historyStarted, undefined).pipe(
206+
Effect.andThen(Deferred.await(releaseHistory)),
207+
Effect.asVoid,
208+
),
186209
} as DesktopRendererHistory.DesktopRendererHistory["Service"]),
187210
);
188211
const app = yield* runApp.pipe(
@@ -226,8 +249,19 @@ it.effect(
226249
yield* Deferred.await(windowStarted);
227250
assert.deepEqual(events, ["identity", "ready", "identity", "backend", "window"]);
228251
assert.isFalse(yield* Deferred.isDone(registrationStopped));
229-
yield* (yield* DesktopShutdown.DesktopShutdown).request;
230-
yield* Fiber.join(app);
252+
const shutdown = yield* DesktopShutdown.DesktopShutdown;
253+
yield* shutdown.request;
254+
yield* Deferred.await(firstStopStarted);
255+
yield* Deferred.await(secondStopStarted);
256+
assert.isFalse(yield* Deferred.isDone(historyStarted));
257+
assert.isFalse(yield* shutdown.isComplete);
258+
yield* Deferred.succeed(releaseStops, undefined);
259+
yield* Deferred.await(historyStarted);
260+
assert.isFalse(yield* shutdown.isComplete);
261+
yield* Deferred.succeed(releaseHistory, undefined);
262+
const result = yield* Fiber.await(app);
263+
assert.equal(Exit.isFailure(result), stopDefect);
264+
assert.isTrue(yield* shutdown.isComplete);
231265
assert.isTrue(yield* Deferred.isDone(registrationStopped));
232266
}).pipe(Effect.provide(DesktopShutdown.layer)),
233267
);

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Cause from "effect/Cause";
2-
import * as Duration from "effect/Duration";
2+
import * as Config from "effect/Config";
33
import * as Effect from "effect/Effect";
44
import * as Option from "effect/Option";
55
import * as Ref from "effect/Ref";
@@ -18,6 +18,7 @@ import * as DesktopClerk from "./DesktopClerk.ts";
1818
import * as DesktopApplicationMenu from "../window/DesktopApplicationMenu.ts";
1919
import * as DesktopWindow from "../window/DesktopWindow.ts";
2020
import * as PreviewPasskeys from "../preview/Passkeys.ts";
21+
import * as DesktopBackendManager from "../backend/DesktopBackendManager.ts";
2122
import * as DesktopBackendPool from "../backend/DesktopBackendPool.ts";
2223
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
2324
import * as DesktopLegacyLocalStorage from "./DesktopLegacyLocalStorage.ts";
@@ -42,6 +43,11 @@ const DEFAULT_DESKTOP_BACKEND_PORT = 3773;
4243
const MAX_TCP_PORT = 65_535;
4344
const DESKTOP_BACKEND_PORT_PROBE_HOSTS = ["127.0.0.1", "0.0.0.0", "::"] as const;
4445

46+
const LinuxDesktopSessionConfig = Config.all({
47+
current: Config.String("XDG_CURRENT_DESKTOP").pipe(Config.option),
48+
session: Config.String("XDG_SESSION_DESKTOP").pipe(Config.option),
49+
});
50+
4551
const makeDesktopRunId = SecureRandom.SecureRandom.pipe(
4652
Effect.flatMap((random) => random.uuidV4()),
4753
Effect.map((value) => value.replaceAll("-", "").slice(0, 12)),
@@ -154,7 +160,7 @@ const stopAllPoolInstances = Effect.fn("desktop.app.stopAllPoolInstances")(
154160
const instances = yield* pool.list;
155161
yield* Effect.forEach(
156162
instances,
157-
(instance) => instance.stop({ timeout: Duration.seconds(5) }),
163+
(instance) => instance.stop({ timeout: DesktopBackendManager.BACKEND_QUIT_STOP_TIMEOUT }),
158164
{ concurrency: "unbounded" },
159165
);
160166
},
@@ -307,12 +313,13 @@ const startup = Effect.gen(function* () {
307313
yield* desktopSettings.load;
308314

309315
if (linuxElectronOptions !== null) {
316+
const xdgDesktop = yield* LinuxDesktopSessionConfig;
310317
yield* logStartupInfo("linux password store configured", {
311318
passwordStore: hasCommandLinePasswordStore
312319
? "command-line"
313320
: (linuxElectronOptions.passwordStore ?? "electron-default"),
314-
xdgCurrentDesktop: process.env.XDG_CURRENT_DESKTOP ?? null,
315-
xdgSessionDesktop: process.env.XDG_SESSION_DESKTOP ?? null,
321+
xdgCurrentDesktop: Option.getOrNull(xdgDesktop.current),
322+
xdgSessionDesktop: Option.getOrNull(xdgDesktop.session),
316323
});
317324
}
318325

@@ -356,6 +363,7 @@ const scopedProgram = Effect.scoped(
356363
stopAllPoolInstances().pipe(
357364
Effect.ensuring(rendererHistory.shutdown),
358365
Effect.ensuring(shutdown.markComplete),
366+
Effect.withSpan("desktop.app.shutdown"),
359367
),
360368
);
361369

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
2-
import { afterEach, beforeEach, expect, it } from "@effect/vitest";
2+
import { expect, it } from "@effect/vitest";
33
import * as HostProcess from "@t3tools/shared/HostProcess";
44
import * as Effect from "effect/Effect";
55
import * as FileSystem from "effect/FileSystem";
@@ -29,7 +29,13 @@ const environmentFor = (
2929
} as unknown as DesktopEnvironment.DesktopEnvironment["Service"]);
3030

3131
const commandIn = (
32-
input: { home: string; baseDir?: string; platform?: NodeJS.Platform; isPackaged?: boolean },
32+
input: {
33+
home: string;
34+
baseDir?: string;
35+
platform?: NodeJS.Platform;
36+
isPackaged?: boolean;
37+
env?: NodeJS.ProcessEnv;
38+
},
3339
spawner?: ChildProcessSpawner.ChildProcessSpawner["Service"],
3440
) =>
3541
Effect.gen(function* () {
@@ -42,6 +48,7 @@ const commandIn = (
4248
DesktopEnvironment.DesktopEnvironment,
4349
environmentFor(path, { ...input, baseDir }),
4450
),
51+
Effect.provideService(HostProcess.Environment, input.env ?? { PATH: "" }),
4552
);
4653
return yield* spawner
4754
? make.pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner))
@@ -84,14 +91,6 @@ const fakePowerShell = (initial: string) => {
8491
return { registry, spawner };
8592
};
8693

87-
const machinePath = process.env.PATH;
88-
beforeEach(() => {
89-
process.env.PATH = "";
90-
});
91-
afterEach(() => {
92-
process.env.PATH = machinePath;
93-
});
94-
9594
it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
9695
it.effect("links the launcher onto PATH and removes only that link", () =>
9796
Effect.gen(function* () {
@@ -124,7 +123,8 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
124123
const fs = yield* FileSystem.FileSystem;
125124
const path = yield* Path.Path;
126125
const home = yield* fs.makeTempDirectoryScoped();
127-
const command = yield* commandIn({ home });
126+
const env: NodeJS.ProcessEnv = { PATH: "" };
127+
const command = yield* commandIn({ home, env });
128128
const theirs = path.join(home, ".local", "bin", "t3");
129129
yield* fs.makeDirectory(path.dirname(theirs), { recursive: true });
130130
yield* fs.writeFileString(theirs, "npm's t3\n");
@@ -139,7 +139,7 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
139139

140140
const launcher = path.join(home, ".t3", "bin", "t3");
141141
yield* fs.writeFileString(launcher, "npm's t3\n");
142-
process.env.PATH = path.dirname(launcher);
142+
env.PATH = path.dirname(launcher);
143143
expect(yield* command.state).toMatchObject({ onPath: false, shadowedBy: launcher });
144144
expect((yield* Effect.flip(command.install)).message).toContain("Could not set up");
145145
yield* command.uninstall;
@@ -173,9 +173,9 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
173173
const shadow = path.join(home, "shadow");
174174
yield* fs.makeDirectory(shadow);
175175
yield* fs.writeFileString(path.join(shadow, "t3"), "#!/bin/sh\n", { mode: 0o755 });
176-
process.env.PATH = [shadow, path.join(home, ".local", "bin")].join(":");
176+
const env = { PATH: [shadow, path.join(home, ".local", "bin")].join(":") };
177177

178-
const command = yield* commandIn({ home });
178+
const command = yield* commandIn({ home, env });
179179
const theirs = path.join(shadow, "t3");
180180
expect((yield* command.state).shadowedBy).toBe(theirs);
181181
const error = yield* Effect.flip(command.install);
@@ -209,9 +209,9 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
209209
yield* fs.chmod(path.join(plain, "t3"), process.getuid?.() === 0 ? 0o600 : 0o601);
210210
yield* fs.makeDirectory(shadow);
211211
yield* fs.writeFileString(path.join(shadow, "t3"), "#!/bin/sh\n", { mode: 0o755 });
212-
process.env.PATH = [folder, plain, shadow, path.join(home, ".local", "bin")].join(":");
212+
const env = { PATH: [folder, plain, shadow, path.join(home, ".local", "bin")].join(":") };
213213

214-
const command = yield* commandIn({ home });
214+
const command = yield* commandIn({ home, env });
215215
expect((yield* command.state).shadowedBy).toBe(path.join(shadow, "t3"));
216216

217217
const error = yield* Effect.flip(command.install);
@@ -231,9 +231,9 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
231231
const path = yield* Path.Path;
232232
const home = yield* fs.makeTempDirectoryScoped();
233233
const launcher = path.join(home, ".t3", "bin", "t3");
234-
process.env.PATH = [path.dirname(launcher), path.join(home, ".local", "bin")].join(":");
234+
const env = { PATH: [path.dirname(launcher), path.join(home, ".local", "bin")].join(":") };
235235

236-
const command = yield* commandIn({ home });
236+
const command = yield* commandIn({ home, env });
237237
const installed = yield* command.install;
238238

239239
expect(yield* fs.exists(launcher)).toBe(true);

0 commit comments

Comments
 (0)