Skip to content

Commit 04fda2e

Browse files
authored
Merge branch 'main' into fix/clone-default-destination-repo-name
2 parents 3b8392d + 61b2e74 commit 04fda2e

192 files changed

Lines changed: 6307 additions & 673 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/pr-assets/6424-after.svg‎

Lines changed: 1 addition & 0 deletions
Loading

‎.github/pr-assets/6424-before.svg‎

Lines changed: 1 addition & 0 deletions
Loading

‎.github/pr-assets/6503-after.svg‎

Lines changed: 1 addition & 0 deletions
Loading

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const makeElectronAppLayer = (calls: ElectronAppCalls) =>
4040
Layer.succeed(ElectronApp.ElectronApp, {
4141
metadata: Effect.die("unexpected metadata read"),
4242
name: Effect.succeed("T3 Code"),
43+
systemLocale: Effect.succeed("en-US"),
4344
whenReady: Effect.void,
4445
quit: Effect.void,
4546
exit: () => Effect.void,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe("DesktopLifecycle", () => {
2121
const electronAppLayer = Layer.succeed(ElectronApp.ElectronApp, {
2222
metadata: Effect.die("unexpected metadata read"),
2323
name: Effect.succeed("T3 Code"),
24+
systemLocale: Effect.succeed("en-US"),
2425
whenReady: Effect.void,
2526
quit: Effect.void,
2627
exit: () => Effect.void,

‎apps/desktop/src/backend/DesktopBackendManager.test.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,84 @@ describe("DesktopBackendManager", () => {
701701
),
702702
);
703703

704+
it.effect(
705+
"re-probes readiness after the first budget expires while the backend is still alive",
706+
() =>
707+
Effect.scoped(
708+
Effect.gen(function* () {
709+
const requestUrls: Array<string> = [];
710+
let requestCount = 0;
711+
let readyCount = 0;
712+
let readinessTimeoutCount = 0;
713+
const firstProbe = yield* Deferred.make<void>();
714+
const childExit = yield* Deferred.make<void>();
715+
716+
const spawnerLayer = Layer.succeed(
717+
ChildProcessSpawner.ChildProcessSpawner,
718+
ChildProcessSpawner.make(() =>
719+
Effect.succeed(
720+
makeProcess({
721+
exitCode: Deferred.await(childExit).pipe(
722+
Effect.as(ChildProcessSpawner.ExitCode(0)),
723+
),
724+
}),
725+
),
726+
),
727+
);
728+
729+
// The backend stays 503 through the first *two* readiness budgets
730+
// and only becomes healthy (200) for the third round, i.e. it comes
731+
// up well after the initial 50ms budget has expired.
732+
const httpLayer = httpClientLayer((request) =>
733+
Effect.gen(function* () {
734+
requestCount += 1;
735+
requestUrls.push(request.url);
736+
yield* Deferred.succeed(firstProbe, void 0);
737+
return responseForRequest(request, requestCount <= 2 ? 503 : 200);
738+
}),
739+
);
740+
741+
const runFiber = yield* DesktopBackendManager.runBackendProcess({
742+
...baseConfig,
743+
desktopTelemetryStream: Stream.empty,
744+
readinessTimeout: Duration.millis(50),
745+
onReady: () =>
746+
Effect.sync(() => {
747+
readyCount += 1;
748+
}),
749+
onReadinessFailure: () =>
750+
Effect.sync(() => {
751+
readinessTimeoutCount += 1;
752+
}),
753+
}).pipe(Effect.provide(Layer.merge(spawnerLayer, httpLayer)), Effect.forkChild);
754+
755+
yield* Deferred.await(firstProbe);
756+
assert.equal(readyCount, 0);
757+
assert.equal(readinessTimeoutCount, 0);
758+
759+
// The first 50ms readiness budget expires while the backend still
760+
// answers 503. The child is alive and may yet become healthy, so the
761+
// probe must start a fresh round instead of stopping permanently —
762+
// the pre-fix behavior left the app stuck on "Connecting to WSL…"
763+
// forever even though the backend kept running.
764+
yield* TestClock.adjust(Duration.millis(50));
765+
assert.equal(readinessTimeoutCount, 1);
766+
assert.equal(readyCount, 0);
767+
768+
// The second budget also expires (backend still 503), then the third
769+
// round connects. The point is the probe persisted across budgets
770+
// while the process was alive instead of giving up after the first.
771+
yield* TestClock.adjust(Duration.millis(100));
772+
assert.equal(readinessTimeoutCount, 2);
773+
assert.equal(readyCount, 1);
774+
assert.equal(requestUrls.length, 3);
775+
776+
yield* Deferred.succeed(childExit, void 0);
777+
assert.equal((yield* Fiber.join(runFiber)).code.pipe(Option.getOrUndefined), 0);
778+
}).pipe(Effect.provide(TestClock.layer())),
779+
),
780+
);
781+
704782
it.effect("starts the configured backend and closes the scoped process on stop", () =>
705783
Effect.scoped(
706784
Effect.gen(function* () {

‎apps/desktop/src/backend/DesktopBackendManager.ts‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -563,20 +563,33 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
563563
).pipe(Effect.forkScoped),
564564
);
565565
}
566-
yield* waitForHttpReady({
567-
executablePath: options.executablePath,
568-
entryPath: options.entryPath,
569-
cwd: options.cwd,
570-
httpBaseUrl: options.httpBaseUrl,
571-
timeout: options.readinessTimeout ?? DEFAULT_BACKEND_READINESS_TIMEOUT,
572-
}).pipe(
573-
Effect.tap(() => options.onReady?.() ?? Effect.void),
574-
Effect.catchTags({
575-
BackendReadinessTimeoutError: (error) => options.onReadinessFailure?.(error) ?? Effect.void,
576-
}),
577-
Effect.forkScoped,
566+
// Probe readiness in a loop while the backend process is still alive
567+
// instead of giving up after the first budget. A slow cold boot (the
568+
// WSL bundle loading across /mnt/c, or a first launch right after an
569+
// update) can exceed the initial readiness budget while the backend is
570+
// about to come up moments later; a one-shot probe left the app stuck
571+
// on "Connecting to WSL…" forever even though the backend kept running
572+
// and became healthy. Each round gets a fresh budget, and the forked
573+
// loop is torn down with the run scope once the child exits.
574+
const probeReadiness = Effect.fn("desktop.backendProcess.probeReadiness")(() =>
575+
waitForHttpReady({
576+
executablePath: options.executablePath,
577+
entryPath: options.entryPath,
578+
cwd: options.cwd,
579+
httpBaseUrl: options.httpBaseUrl,
580+
timeout: options.readinessTimeout ?? DEFAULT_BACKEND_READINESS_TIMEOUT,
581+
}).pipe(
582+
Effect.flatMap(() => options.onReady?.() ?? Effect.void),
583+
Effect.as(true),
584+
Effect.catchTags({
585+
BackendReadinessTimeoutError: (error) =>
586+
(options.onReadinessFailure?.(error) ?? Effect.void).pipe(Effect.as(false)),
587+
}),
588+
),
578589
);
579590

591+
yield* probeReadiness().pipe(Effect.repeat({ while: (ready) => !ready }), Effect.forkScoped);
592+
580593
const exit = yield* handle.exitCode.pipe(
581594
Effect.mapError(
582595
(cause) =>

‎apps/desktop/src/electron/ElectronApp.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
autoUpdaterRemoveListenerMock,
99
exitMock,
1010
getAppPathMock,
11+
getSystemLocaleMock,
1112
getVersionMock,
1213
isDefaultProtocolClientMock,
1314
onMock,
@@ -29,6 +30,7 @@ const {
2930
autoUpdaterRemoveListenerMock: vi.fn(),
3031
exitMock: vi.fn(),
3132
getAppPathMock: vi.fn(() => "/app"),
33+
getSystemLocaleMock: vi.fn(() => "en-GB"),
3234
getVersionMock: vi.fn(() => "1.2.3"),
3335
isDefaultProtocolClientMock: vi.fn(() => false),
3436
onMock: vi.fn(),
@@ -60,6 +62,7 @@ vi.mock("electron", () => ({
6062
setIcon: setDockIconMock,
6163
},
6264
getAppPath: getAppPathMock,
65+
getSystemLocale: getSystemLocaleMock,
6366
getVersion: getVersionMock,
6467
isDefaultProtocolClient: isDefaultProtocolClientMock,
6568
isPackaged: true,
@@ -111,6 +114,23 @@ describe("ElectronApp", () => {
111114
}).pipe(Effect.provide(ElectronApp.layer)),
112115
);
113116

117+
it.effect("reads the OS locale through the service", () =>
118+
Effect.gen(function* () {
119+
const electronApp = yield* ElectronApp.ElectronApp;
120+
121+
assert.strictEqual(yield* electronApp.systemLocale, "en-GB");
122+
}).pipe(Effect.provide(ElectronApp.layer)),
123+
);
124+
125+
it.effect("normalizes POSIX-style locale identifiers that Intl rejects", () =>
126+
Effect.gen(function* () {
127+
getSystemLocaleMock.mockImplementationOnce(() => "en_GB");
128+
const electronApp = yield* ElectronApp.ElectronApp;
129+
130+
assert.strictEqual(yield* electronApp.systemLocale, "en-GB");
131+
}).pipe(Effect.provide(ElectronApp.layer)),
132+
);
133+
114134
it.effect("reports which app metadata property failed", () =>
115135
Effect.gen(function* () {
116136
const cause = new Error("version unavailable");

‎apps/desktop/src/electron/ElectronApp.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ export class ElectronApp extends Context.Service<
4343
{
4444
readonly metadata: Effect.Effect<ElectronAppMetadata, ElectronAppMetadataReadError>;
4545
readonly name: Effect.Effect<string>;
46+
/**
47+
* The OS locale, read from the operating system rather than from Chromium's
48+
* resolved application locale — the packaged app ships only the `en-US`
49+
* locale pak, so `app.getLocale()` and the renderer's `Intl` default are
50+
* pinned to `en-US` however the machine is configured.
51+
*/
52+
readonly systemLocale: Effect.Effect<string>;
4653
readonly whenReady: Effect.Effect<void, ElectronAppWhenReadyError>;
4754
readonly quit: Effect.Effect<void>;
4855
readonly exit: (code: number) => Effect.Effect<void>;
@@ -119,6 +126,10 @@ export const make = ElectronApp.of({
119126
};
120127
}),
121128
name: Effect.sync(() => Electron.app.name),
129+
// macOS derives this from NSLocale, which uses POSIX-style identifiers
130+
// (`en_GB`). `Intl` rejects those outright rather than normalizing them, so
131+
// the tag is normalized here rather than in the renderer that consumes it.
132+
systemLocale: Effect.sync(() => Electron.app.getSystemLocale().replace(/_/g, "-")),
122133
whenReady: Effect.gen(function* () {
123134
const isPackaged = Electron.app.isPackaged;
124135
yield* Effect.tryPromise({

‎apps/desktop/src/ipc/DesktopIpcHandlers.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
getAppBranding,
3535
getLocalEnvironmentBootstraps,
3636
getLocalEnvironmentBearerToken,
37+
getSystemLocale,
3738
getWindowFullscreenState,
3839
openExternal,
3940
probeRemoteEditors,
@@ -50,6 +51,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
5051
yield* PreviewIpc.installPreviewEventForwarding();
5152

5253
yield* ipc.handleSync(getAppBranding);
54+
yield* ipc.handleSync(getSystemLocale);
5355
yield* ipc.handleSync(getWindowFullscreenState);
5456
yield* ipc.handleSync(getLocalEnvironmentBootstraps);
5557
yield* ipc.handle(getLocalEnvironmentBearerToken);

0 commit comments

Comments
 (0)