Skip to content

Commit 40f63d0

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-4812
# Conflicts: # pnpm-workspace.yaml
2 parents 806cfba + b015ffd commit 40f63d0

668 files changed

Lines changed: 32898 additions & 4766 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/release.yml‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,18 @@ jobs:
14821482
14831483
git add apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json pnpm-lock.yaml
14841484
git commit --no-verify -m "chore(release): prepare $RELEASE_TAG"
1485-
git push origin HEAD:main
1485+
1486+
# main moves while this job runs, so a rejected push rebases and retries.
1487+
for attempt in 1 2 3 4 5; do
1488+
if git push origin HEAD:main; then
1489+
exit 0
1490+
fi
1491+
echo "Push rejected (attempt $attempt). Rebasing onto latest main."
1492+
git pull --rebase origin main
1493+
done
1494+
1495+
echo "Could not push the version bump after 5 attempts." >&2
1496+
exit 1
14861497
14871498
announce_discord:
14881499
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/backend/DesktopBackendManager.test.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ describe("DesktopBackendManager", () => {
421421
),
422422
);
423423

424-
it.effect("starts the configured backend and closes the scoped process on stop", () =>
424+
it.effect("stops the scoped process with output still pending", () =>
425425
Effect.scoped(
426426
Effect.gen(function* () {
427427
let startCount = 0;
@@ -458,6 +458,7 @@ describe("DesktopBackendManager", () => {
458458
yield* Scope.addFinalizer(scope, close);
459459

460460
return makeProcess({
461+
stdout: Stream.never,
461462
exitCode: Deferred.await(closed).pipe(Effect.as(ChildProcessSpawner.ExitCode(0))),
462463
kill: () => close,
463464
});
@@ -721,14 +722,12 @@ describe("DesktopBackendManager", () => {
721722
),
722723
);
723724

724-
it.effect("the quit stop deadline waits for a backend that only exits at the force kill", () =>
725+
it.effect("the quit stop keeps waiting for a backend that outlasts its deadline", () =>
725726
Effect.scoped(
726727
Effect.gen(function* () {
727728
const spawned = yield* Deferred.make<void>();
728729
const teardownStarted = yield* Deferred.make<void>();
729730
const teardownFinished = yield* Deferred.make<void>();
730-
// The real spawner sends SIGTERM, waits the grace, then SIGKILLs. A backend that
731-
// ignores SIGTERM therefore finishes tearing down just after the grace.
732731
const instance = yield* makeTestInstance({
733732
spawnerLayer: Layer.succeed(
734733
ChildProcessSpawner.ChildProcessSpawner,
@@ -739,7 +738,7 @@ describe("DesktopBackendManager", () => {
739738
yield* Scope.addFinalizer(
740739
scope,
741740
Deferred.succeed(teardownStarted, undefined).pipe(
742-
Effect.andThen(Effect.sleep(Duration.seconds(6))),
741+
Effect.andThen(Effect.sleep(Duration.seconds(10))),
743742
Effect.andThen(Deferred.succeed(teardownFinished, undefined)),
744743
Effect.asVoid,
745744
),
@@ -764,11 +763,11 @@ describe("DesktopBackendManager", () => {
764763
.pipe(Effect.andThen(Deferred.succeed(quitDone, undefined)), Effect.forkChild);
765764

766765
yield* Deferred.await(teardownStarted);
767-
// Past the SIGTERM grace but before the force kill lands: quit must still be waiting.
768-
yield* TestClock.adjust(Duration.millis(5_500));
766+
// Past the quit deadline, quit must still wait for the backend to exit.
767+
yield* TestClock.adjust(Duration.seconds(9));
769768
assert.isFalse(yield* Deferred.isDone(quitDone));
770769

771-
yield* TestClock.adjust(Duration.millis(500));
770+
yield* TestClock.adjust(Duration.seconds(1));
772771
yield* Fiber.join(quitFiber);
773772
assert.isTrue(yield* Deferred.isDone(teardownFinished));
774773
}).pipe(Effect.provide(TestClock.layer())),

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ export interface DesktopBackendInstance {
240240
readonly id: BackendInstanceId;
241241
readonly label: Effect.Effect<string>;
242242
readonly start: Effect.Effect<void>;
243+
/** Timeout controls the warning; stop still waits for process teardown and exit. */
243244
readonly stop: (options?: { readonly timeout?: Duration.Duration }) => Effect.Effect<void>;
244245
readonly currentConfig: Effect.Effect<Option.Option<DesktopBackendStartConfig>>;
245246
readonly snapshot: Effect.Effect<DesktopBackendSnapshot>;
@@ -307,7 +308,7 @@ const closeRun = (
307308
run: ActiveBackendRun,
308309
parentScope: Scope.Scope,
309310
options?: { readonly timeout?: Duration.Duration },
310-
): Effect.Effect<boolean> => {
311+
) => {
311312
const waitForFiber = Option.match(run.fiber, {
312313
onNone: () => Effect.void,
313314
onSome: (fiber) => Fiber.await(fiber).pipe(Effect.asVoid),
@@ -319,12 +320,24 @@ const closeRun = (
319320
const timeout = options?.timeout;
320321

321322
if (!timeout) {
322-
return close.pipe(Effect.as(true));
323+
return close;
323324
}
324325

325-
return Effect.forkIn(close, parentScope).pipe(
326+
return Effect.forkIn(close, parentScope, { startImmediately: true }).pipe(
326327
Effect.flatMap((closeFiber) =>
327-
Fiber.await(closeFiber).pipe(Effect.timeoutOption(timeout), Effect.map(Option.isSome)),
328+
Fiber.await(closeFiber).pipe(
329+
Effect.timeoutOption(timeout),
330+
Effect.tap((completed) =>
331+
Option.isNone(completed)
332+
? logBackendProcessWarning("backend shutdown exceeded timeout; waiting for exit", {
333+
timeoutMs: Duration.toMillis(timeout),
334+
})
335+
: Effect.void,
336+
),
337+
// Parent-scope interruption still finishes release; do not cancel sibling stops.
338+
Effect.andThen(Fiber.await(closeFiber)),
339+
Effect.asVoid,
340+
),
328341
),
329342
);
330343
};
@@ -1099,10 +1112,7 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
10991112
onNone: () => Effect.void,
11001113
// The enclosing operation owns the span for this inline handler.
11011114
onSome: Effect.fnUntraced(function* (run) {
1102-
const closed = yield* closeRun(run, parentScope, options);
1103-
if (!closed) {
1104-
return;
1105-
}
1115+
yield* closeRun(run, parentScope, options);
11061116
const cleanup = yield* mutex.withPermits(1)(
11071117
SubscriptionRef.modify(
11081118
state,

0 commit comments

Comments
 (0)