Skip to content

Commit 46bd10f

Browse files
Merge remote-tracking branch 'origin/main' into t3code/pr-28584/fix/reselected-project-icon-refetch
# Conflicts: # packages/client-runtime/src/state/assets.test.ts
2 parents 3066c86 + e6e2ab0 commit 46bd10f

568 files changed

Lines changed: 23621 additions & 2902 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/scripts/ci-changes.cjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const INERT = [
1414

1515
// Shared test setup and vendored mobile dependencies affect every package.
1616
const RUNS_EVERYTHING = [
17-
/^packages\/shared\/src\/(HostProcess|testing\/longTempDir)\.ts$/,
17+
/^packages\/shared\/src\/(HostProcess|testing\/(longTempDir|providerEnv))\.ts$/,
1818
/^apps\/mobile\/deps\//,
1919
];
2020

‎.github/scripts/thread-transfer-report.cjs‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -300,18 +300,28 @@ async function resolve({ github, context, core }) {
300300
core.setOutput("publish", "false");
301301
return;
302302
}
303-
const workflowRuns = await github.paginate(github.rest.actions.listWorkflowRuns, {
304-
owner,
305-
repo,
306-
workflow_id: source.workflow_id,
307-
branch: pull.base.ref,
308-
event: "push",
309-
status: "success",
310-
per_page: 100,
311-
});
303+
// One page each for the exact base and the newest runs; paging through
304+
// every successful main run costs up to ten requests to keep 20.
305+
const listRuns = async (filters) => {
306+
const { data } = await github.rest.actions.listWorkflowRuns({
307+
owner,
308+
repo,
309+
workflow_id: source.workflow_id,
310+
branch: pull.base.ref,
311+
event: "push",
312+
status: "success",
313+
per_page: 20,
314+
...filters,
315+
});
316+
return data.workflow_runs;
317+
};
318+
const [baseRuns, recentRuns] = await Promise.all([
319+
listRuns({ head_sha: pull.base.sha }),
320+
listRuns({}),
321+
]);
312322
const orderedRuns = [
313-
...workflowRuns.filter((run) => run.head_sha === pull.base.sha),
314-
...workflowRuns.filter((run) => run.head_sha !== pull.base.sha),
323+
...baseRuns,
324+
...recentRuns.filter((run) => run.head_sha !== pull.base.sha),
315325
].slice(0, 20);
316326

317327
let baselineRun;

‎.github/scripts/thread-transfer-report.test.cjs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,18 @@ test("validates the fixed artifact schema", () => {
5555
test("resolves a fallback PR with a redacted head repo and exact main baseline", async () => {
5656
const outputs = {};
5757
const listWorkflowRunArtifacts = () => {};
58-
const listWorkflowRuns = () => {};
58+
// The exact base run sits far past the newest page of main CI runs.
59+
const mainRuns = Array.from({ length: 1_000 }, (_, index) => ({
60+
id: 1_000 - index,
61+
head_sha: index === 900 ? "base-sha" : `main-sha-${index}`,
62+
}));
63+
const listWorkflowRuns = async ({ head_sha, per_page }) => ({
64+
data: {
65+
workflow_runs: mainRuns
66+
.filter((run) => head_sha === undefined || run.head_sha === head_sha)
67+
.slice(0, per_page),
68+
},
69+
});
5970
const listPullRequestsAssociatedWithCommit = () => {};
6071
const github = {
6172
paginate: async (method, input) => {
@@ -77,9 +88,6 @@ test("resolves a fallback PR with a redacted head repo and exact main baseline",
7788
},
7889
];
7990
}
80-
if (method === listWorkflowRuns) {
81-
return [{ id: 1, head_sha: "base-sha" }];
82-
}
8391
throw new Error("unexpected pagination call");
8492
},
8593
rest: {
@@ -123,7 +131,7 @@ test("resolves a fallback PR with a redacted head repo and exact main baseline",
123131
assert.equal(outputs.publish, "true");
124132
assert.equal(outputs.pull_number, "5350");
125133
assert.equal(outputs.pr_artifact, "true");
126-
assert.equal(outputs.baseline_run_id, "1");
134+
assert.equal(outputs.baseline_run_id, "100");
127135
assert.equal(outputs.baseline_matches_base, "true");
128136
});
129137

‎.github/workflows/pr-vouch.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ permissions:
2020
jobs:
2121
collect-targets:
2222
name: Collect PR targets
23+
# Most comments are not recheck commands; skip them before a runner starts.
24+
if: >-
25+
github.event_name != 'issue_comment' ||
26+
(github.event.issue.pull_request && contains(github.event.comment.body, '/recheck-vouch'))
2327
runs-on: ubuntu-24.04
2428
outputs:
2529
targets: ${{ steps.collect.outputs.targets }}

‎apps/desktop/scripts/main-process-bundle.test.mjs‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as NodeFSP from "node:fs/promises";
33
import * as NodeOS from "node:os";
44
import * as NodePath from "node:path";
55
import * as NodeVM from "node:vm";
6+
import * as NodeURL from "node:url";
67
import { build } from "vite-plus/pack";
78
import { assert, it } from "vite-plus/test";
89

@@ -114,18 +115,16 @@ it("loads the emitted packaged boot entry and backend cache preload", async () =
114115
const directory = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-desktop-boot-"));
115116
try {
116117
const entries = ["src/boot.ts", "src/compileCache.ts"];
117-
await NodeFSP.mkdir(NodePath.join(directory, "src"));
118-
await Promise.all(
119-
entries.map((entry) =>
120-
NodeFSP.copyFile(new URL(`../${entry}`, import.meta.url), NodePath.join(directory, entry)),
121-
),
122-
);
123118
assert.ok(Array.isArray(desktopConfig.pack));
124119
for (const packConfig of desktopConfig.pack) {
125120
if (!Array.isArray(packConfig.entry)) continue;
126121
if (!packConfig.entry.some((entry) => entries.includes(entry))) continue;
127122
await build({
128123
...packConfig,
124+
entry: packConfig.entry.map((entry) =>
125+
NodeURL.fileURLToPath(new URL(`../${entry}`, import.meta.url)),
126+
),
127+
outDir: NodePath.join(directory, "dist-electron"),
129128
config: false,
130129
cwd: directory,
131130
tsconfig: false,

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as Layer from "effect/Layer";
55
import * as Ref from "effect/Ref";
66
import * as TestClock from "effect/testing/TestClock";
77

8+
import * as HostProcess from "@t3tools/shared/HostProcess";
9+
810
import type * as Electron from "electron";
911

1012
import * as ElectronApp from "../electron/ElectronApp.ts";
@@ -20,6 +22,7 @@ function layerElectronApp(
2022
appListeners: Map<string, (...args: readonly unknown[]) => void>,
2123
quit: Effect.Effect<void> = Effect.void,
2224
exit: (code: number) => Effect.Effect<void> = () => Effect.void,
25+
relaunch: (options: Electron.RelaunchOptions) => Effect.Effect<void> = () => Effect.void,
2326
) {
2427
const registerListener = (eventName: string, listener: (...args: readonly unknown[]) => void) =>
2528
Effect.acquireRelease(
@@ -40,7 +43,7 @@ function layerElectronApp(
4043
requestSingleInstanceLock: Effect.succeed(true),
4144
quit,
4245
exit,
43-
relaunch: () => Effect.void,
46+
relaunch,
4447
setPath: () => Effect.void,
4548
setName: () => Effect.void,
4649
setAboutPanelOptions: () => Effect.void,
@@ -223,6 +226,50 @@ describe("DesktopLifecycle", () => {
223226
}),
224227
);
225228

229+
it.effect("relaunches without the app link that launched it", () =>
230+
Effect.gen(function* () {
231+
const relaunched = yield* Deferred.make<Electron.RelaunchOptions>();
232+
const layerEnvironment = Layer.succeed(DesktopEnvironment.DesktopEnvironment, {
233+
platform: "linux",
234+
isDevelopment: false,
235+
} as DesktopEnvironment.DesktopEnvironment["Service"]);
236+
const layer = DesktopLifecycle.layer.pipe(
237+
Layer.provideMerge(
238+
layerElectronApp(
239+
new Map(),
240+
Effect.void,
241+
() => Effect.void,
242+
(options) => Deferred.succeed(relaunched, options).pipe(Effect.asVoid),
243+
),
244+
),
245+
Layer.provideMerge(layerElectronTheme),
246+
Layer.provideMerge(layerElectronWindow()),
247+
Layer.provideMerge(layerDesktopWindow()),
248+
Layer.provideMerge(layerEnvironment),
249+
Layer.provideMerge(DesktopShutdown.layer),
250+
Layer.provideMerge(DesktopState.layer),
251+
);
252+
253+
const options = yield* Effect.gen(function* () {
254+
const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;
255+
yield* (yield* DesktopShutdown.DesktopShutdown).markComplete;
256+
yield* lifecycle.relaunch("network access changed");
257+
return yield* Deferred.await(relaunched);
258+
}).pipe(
259+
Effect.provide(layer),
260+
Effect.provideService(HostProcess.ExecutablePath, "/opt/T3 Code/t3code"),
261+
Effect.provideService(HostProcess.Arguments, [
262+
"/opt/T3 Code/t3code",
263+
"--no-sandbox",
264+
"T3CODE://pair?token=spent",
265+
"t3code://new?prompt=hello",
266+
]),
267+
);
268+
269+
assert.deepEqual(options, { execPath: "/opt/T3 Code/t3code", args: ["--no-sandbox"] });
270+
}),
271+
);
272+
226273
it.effect("exits on a repeated quit only once shutdown has stalled", () =>
227274
Effect.gen(function* () {
228275
const appListeners = new Map<string, (...args: readonly unknown[]) => void>();

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import * as Scope from "effect/Scope";
99

1010
import type * as Electron from "electron";
1111

12+
import * as HostProcess from "@t3tools/shared/HostProcess";
13+
1214
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
1315
import { makeComponentLogger } from "./DesktopObservability.ts";
1416
import * as DesktopShutdown from "./DesktopShutdown.ts";
1517
import * as ElectronApp from "../electron/ElectronApp.ts";
18+
import * as ElectronProtocol from "../electron/ElectronProtocol.ts";
1619
import * as ElectronTheme from "../electron/ElectronTheme.ts";
1720
import * as ElectronWindow from "../electron/ElectronWindow.ts";
1821
import * as DesktopState from "./DesktopState.ts";
@@ -223,9 +226,12 @@ export const make = DesktopLifecycle.of({
223226
yield* electronApp.exit(75);
224227
return;
225228
}
229+
// Startup already acted on the app link that launched it; passing it on replays it.
230+
const appLinkPrefix = `${ElectronProtocol.getDesktopScheme(environment.isDevelopment)}:`;
231+
const args = yield* HostProcess.Arguments;
226232
yield* electronApp.relaunch({
227-
execPath: process.execPath,
228-
args: process.argv.slice(1),
233+
execPath: yield* HostProcess.ExecutablePath,
234+
args: args.slice(1).filter((arg) => !arg.toLowerCase().startsWith(appLinkPrefix)),
229235
});
230236
yield* electronApp.exit(0);
231237
}).pipe(

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

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -366,68 +366,70 @@ describe("DesktopLinuxUrlHandler", () => {
366366
});
367367
});
368368

369-
it.effect.skipIf(HostProcess.Platform.defaultValue() !== "linux")(
370-
"continues registration after a timed-out cache helper ignores SIGTERM",
371-
() =>
372-
Effect.gen(function* () {
373-
const realSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
374-
const nodeExecutable = yield* HostProcess.ExecutablePath;
375-
const recorded = emptyRecording();
376-
const spawned = yield* Deferred.make<ChildProcessSpawner.ChildProcessHandle>();
377-
const ready = yield* Deferred.make<void>();
378-
const processSpawner = ChildProcessSpawner.make((command) =>
379-
Effect.gen(function* () {
380-
if (!ChildProcess.isStandardCommand(command)) {
381-
return yield* Effect.die("expected a single registration command");
382-
}
383-
recorded.commands.push({ command: command.command, args: command.args });
384-
if (command.command !== "update-desktop-database") return mockProcess(0);
385-
const child = yield* realSpawner.spawn(
386-
ChildProcess.make(
387-
nodeExecutable,
388-
[
389-
"-e",
390-
// The watchdog makes the unfixed case exit with a distinguishable code.
391-
"process.on('SIGTERM', () => setTimeout(() => process.exit(99), 5000));" +
392-
"process.stdout.write('ready\\n'); setInterval(() => {}, 2147483647);",
393-
],
394-
{ ...command.options, stdout: "pipe" },
369+
for (const stalledHelper of ["update-desktop-database", "xdg-mime"] as const) {
370+
it.effect.skipIf(HostProcess.Platform.defaultValue() !== "linux")(
371+
`finishes registration after a timed-out ${stalledHelper} ignores SIGTERM`,
372+
() =>
373+
Effect.gen(function* () {
374+
const realSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
375+
const nodeExecutable = yield* HostProcess.ExecutablePath;
376+
const recorded = emptyRecording();
377+
const spawned = yield* Deferred.make<ChildProcessSpawner.ChildProcessHandle>();
378+
const ready = yield* Deferred.make<void>();
379+
const processSpawner = ChildProcessSpawner.make((command) =>
380+
Effect.gen(function* () {
381+
if (!ChildProcess.isStandardCommand(command)) {
382+
return yield* Effect.die("expected a single registration command");
383+
}
384+
recorded.commands.push({ command: command.command, args: command.args });
385+
if (command.command !== stalledHelper) return mockProcess(0);
386+
const child = yield* realSpawner.spawn(
387+
ChildProcess.make(
388+
nodeExecutable,
389+
[
390+
"-e",
391+
// The watchdog makes the unfixed case exit with a distinguishable code.
392+
"process.on('SIGTERM', () => setTimeout(() => process.exit(99), 5000));" +
393+
"process.stdout.write('ready\\n'); setInterval(() => {}, 2147483647);",
394+
],
395+
{ ...command.options, stdout: "pipe" },
396+
),
397+
);
398+
yield* Deferred.succeed(spawned, child);
399+
yield* Stream.runHead(child.stdout);
400+
yield* Deferred.succeed(ready, undefined);
401+
return child;
402+
}),
403+
);
404+
const registration = yield* runRegister(recorded, { processSpawner }).pipe(
405+
Effect.forkScoped,
406+
);
407+
const child = yield* Deferred.await(spawned);
408+
yield* Effect.addFinalizer(() =>
409+
child.isRunning.pipe(
410+
Effect.flatMap((running) =>
411+
running ? child.kill({ killSignal: "SIGKILL" }) : Effect.void,
395412
),
396-
);
397-
yield* Deferred.succeed(spawned, child);
398-
yield* Stream.runHead(child.stdout);
399-
yield* Deferred.succeed(ready, undefined);
400-
return child;
401-
}),
402-
);
403-
const registration = yield* runRegister(recorded, { processSpawner }).pipe(
404-
Effect.forkScoped,
405-
);
406-
const child = yield* Deferred.await(spawned);
407-
yield* Effect.addFinalizer(() =>
408-
child.isRunning.pipe(
409-
Effect.flatMap((running) =>
410-
running ? child.kill({ killSignal: "SIGKILL" }) : Effect.void,
413+
Effect.ignore,
411414
),
412-
Effect.ignore,
413-
),
414-
);
415-
yield* Deferred.await(ready);
416-
yield* TestClock.adjust("5 seconds");
417-
yield* Fiber.join(registration);
418-
419-
const exit = yield* Effect.exit(child.exitCode);
420-
if (Exit.isFailure(exit)) {
421-
assert.include(Cause.pretty(exit.cause), "SIGKILL");
422-
} else {
423-
assert.fail(`cache helper exited with ${exit.value} instead of being force-killed`);
424-
}
425-
assert.deepEqual(
426-
recorded.commands.map(({ command }) => command),
427-
["update-desktop-database", "xdg-mime"],
428-
);
429-
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
430-
);
415+
);
416+
yield* Deferred.await(ready);
417+
yield* TestClock.adjust("5 seconds");
418+
yield* Fiber.join(registration);
419+
420+
const exit = yield* Effect.exit(child.exitCode);
421+
if (Exit.isFailure(exit)) {
422+
assert.include(Cause.pretty(exit.cause), "SIGKILL");
423+
} else {
424+
assert.fail(`${stalledHelper} exited with ${exit.value} instead of being force-killed`);
425+
}
426+
assert.deepEqual(
427+
recorded.commands.map(({ command }) => command),
428+
["update-desktop-database", "xdg-mime"],
429+
);
430+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
431+
);
432+
}
431433
});
432434

433435
interface ThemeIconRun {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,16 @@ export const make = Effect.gen(function* () {
261261
stdin: "ignore",
262262
stdout: "ignore",
263263
stderr: "ignore",
264+
forceKillAfter: "1 second",
264265
},
265266
);
266267
const handle = yield* spawner.spawn(command);
267-
const exitCode = yield* handle.exitCode;
268-
if ((exitCode as unknown as number) !== 0) {
268+
const exitCode = yield* handle.exitCode.pipe(Effect.timeout("5 seconds"));
269+
if (exitCode !== 0) {
269270
return yield* new DesktopLinuxUrlHandlerRegistrationError({
270271
step: "set-default-handler",
271272
scheme,
272-
exitCode: Number(exitCode),
273+
exitCode,
273274
});
274275
}
275276
}),

0 commit comments

Comments
 (0)