Skip to content

Commit 9fb482e

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-30435
# Conflicts: # scripts/build-npm-launcher.test.ts
2 parents 30ae4ca + ad4bb6d commit 9fb482e

155 files changed

Lines changed: 3410 additions & 618 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.

‎apps/desktop/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@t3tools/tailscale": "workspace:*",
2323
"dbus-next": "0.10.2",
2424
"effect": "catalog:",
25-
"electron": "44.10.0",
25+
"electron": "44.10.1",
2626
"electron-store": "^8.2.0",
2727
"electron-updater": "^6.8.9",
2828
"electron-webauthn": "catalog:",

‎apps/desktop/src/shell/DesktopShellEnvironment.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,17 +694,28 @@ describe("DesktopShellEnvironment", () => {
694694
it.effect("gives up on a Windows shell that survives the kill", () =>
695695
Effect.gen(function* () {
696696
const commands: Array<string> = [];
697+
// Both PowerShell probes spawn pwsh, time out, then spawn powershell. Each probe's timeout
698+
// is armed before its spawn runs, so waiting for the spawns keeps the clock in step.
699+
const spawned = yield* Effect.forEach([0, 1, 2, 3], () => Deferred.make<void>());
697700
const fiber = yield* runShellEnvironment({
698701
env: { PATH: "C:\\Windows", APPDATA: "C:\\Roaming" },
699702
platform: "win32",
700703
handler: () => "",
701704
processSpawner: ChildProcessSpawner.make((command) => {
705+
const spawn = spawned[commands.length];
702706
commands.push(command._tag === "StandardCommand" ? command.command : "");
703-
return Effect.acquireRelease(Effect.succeed(makeHungProcess()), () => Effect.never);
707+
return (spawn ? Deferred.succeed(spawn, undefined) : Effect.void).pipe(
708+
Effect.andThen(
709+
Effect.acquireRelease(Effect.succeed(makeHungProcess()), () => Effect.never),
710+
),
711+
);
704712
}),
705713
}).pipe(Effect.forkChild({ startImmediately: true }));
706714

707-
for (let probe = 0; probe < 4; probe++) yield* TestClock.adjust("5 seconds");
715+
yield* Effect.forEach(spawned.slice(0, 2), Deferred.await);
716+
yield* TestClock.adjust("5 seconds");
717+
yield* Effect.forEach(spawned.slice(2), Deferred.await);
718+
yield* TestClock.adjust("5 seconds");
708719
yield* Fiber.join(fiber);
709720
assert.deepEqual([...new Set(commands)], ["pwsh.exe", "powershell.exe"]);
710721
}),

‎apps/server/src/attachmentStore.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import * as NodeFS from "node:fs";
44
import * as NodePath from "node:path";
55

66
import type { ChatAttachment } from "@t3tools/contracts";
7-
import { htmlRenderFromToolItem, mcpAppFromToolItem } from "@t3tools/shared/toolOutput";
7+
import {
8+
htmlRenderFromToolItem,
9+
mcpAppFromToolItem,
10+
previewRecordingIdFromToolItem,
11+
} from "@t3tools/shared/toolOutput";
812

913
import {
1014
normalizeAttachmentRelativePath,
@@ -13,7 +17,7 @@ import {
1317
import { inferImageExtension, SAFE_IMAGE_FILE_EXTENSIONS } from "./imageMime.ts";
1418

1519
const ATTACHMENT_FILENAME_EXTENSIONS = [...SAFE_IMAGE_FILE_EXTENSIONS, ".bin"];
16-
const ATTACHMENT_ID_THREAD_SEGMENT_MAX_CHARS = 80;
20+
export const ATTACHMENT_ID_THREAD_SEGMENT_MAX_CHARS = 80;
1721
const ATTACHMENT_ID_THREAD_SEGMENT_PATTERN = "[a-z0-9_]+(?:-[a-z0-9_]+)*";
1822
const ATTACHMENT_ID_UUID_PATTERN = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
1923
const ATTACHMENT_ID_FILE_EXTENSION_PATTERN = "[a-z0-9]{1,10}";
@@ -133,7 +137,9 @@ export function threadHtmlRenderAttachmentIds(
133137
if (segment === null) return [];
134138
return Array.from(items).flatMap((item) => {
135139
const attachmentId =
136-
htmlRenderFromToolItem(item)?.attachmentId ?? mcpAppFromToolItem(item)?.attachmentId;
140+
htmlRenderFromToolItem(item)?.attachmentId ??
141+
mcpAppFromToolItem(item)?.attachmentId ??
142+
previewRecordingIdFromToolItem(item);
137143
return attachmentId !== undefined &&
138144
parseThreadSegmentFromAttachmentId(attachmentId) === segment
139145
? [attachmentId]

‎apps/server/src/checkpointing/CheckpointStore.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ it.layer(layerTest)("CheckpointStore.layer", (it) => {
159159
yield* initRepoWithCommit(tmp);
160160
yield* git(tmp, ["config", "diff.noprefix", "true"]);
161161
yield* git(tmp, ["config", "diff.suppressBlankEmpty", "true"]);
162+
yield* git(tmp, ["config", "diff.submodule", "log"]);
163+
const sub = NodePath.join(tmp, "sub");
164+
yield* git(tmp, ["init", "sub"]);
165+
yield* initRepoWithCommit(sub);
162166
const checkpointStore = yield* CheckpointStore.CheckpointStore;
163167
const threadId = ThreadId.make("thread-checkpoint-store-noprefix");
164168
const fromCheckpointRef = checkpointRefForThreadTurn(threadId, 0);
@@ -170,6 +174,7 @@ it.layer(layerTest)("CheckpointStore.layer", (it) => {
170174
checkpointRef: fromCheckpointRef,
171175
});
172176
yield* writeTextFile(NodePath.join(tmp, "README.md"), "# test\n\nafter\n");
177+
yield* git(sub, ["commit", "--allow-empty", "-m", "moved"]);
173178
yield* checkpointStore.captureCheckpoint({
174179
cwd: tmp,
175180
checkpointRef: toCheckpointRef,
@@ -184,6 +189,8 @@ it.layer(layerTest)("CheckpointStore.layer", (it) => {
184189

185190
expect(diff).toContain("diff --git a/README.md b/README.md");
186191
expect(diff).toContain(" # test\n \n-before\n+after\n");
192+
expect(diff).toContain("diff --git a/sub b/sub");
193+
expect(diff).toContain("+Subproject commit ");
187194
}),
188195
);
189196

‎apps/server/src/cli/service.test.ts‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function makeTestService(
3232
) {
3333
const installOptions: Array<Parameters<BootService.BootService["Service"]["install"]>[0]> = [];
3434
const restarts: Array<true> = [];
35+
const uninstalls: Array<true> = [];
3536
const service = BootService.BootService.of({
3637
status: Effect.succeed(serviceStatus),
3738
withStopped: (operation) => operation,
@@ -49,9 +50,12 @@ function makeTestService(
4950
logPath: serviceStatus.logPath,
5051
};
5152
}),
52-
uninstall: Effect.succeed(false),
53+
uninstall: Effect.sync(() => {
54+
uninstalls.push(true);
55+
return serviceStatus.installed;
56+
}),
5357
});
54-
return { service, installOptions, restarts };
58+
return { service, installOptions, restarts, uninstalls };
5559
}
5660

5761
it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands", (it) => {
@@ -194,4 +198,48 @@ it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands
194198
expect(installOptions).toEqual([]);
195199
}),
196200
);
201+
202+
it.effect.each([
203+
{ label: "this home's service", otherHome: false, unreadable: false, removed: [true] },
204+
{ label: "another home's service", otherHome: true, unreadable: false, removed: [] },
205+
{ label: "an unreadable service", otherHome: false, unreadable: true, removed: [true] },
206+
])("uninstall removes only $label", (input) =>
207+
Effect.gen(function* () {
208+
const fs = yield* FileSystem.FileSystem;
209+
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-service-cli-test-" });
210+
const { service, uninstalls } = makeTestService({
211+
...status,
212+
installedBaseDir: input.otherHome ? "/home/me/.t3" : baseDir,
213+
});
214+
vi.spyOn(BootService, "layer").mockReturnValue(
215+
Layer.succeed(
216+
BootService.BootService,
217+
input.unreadable
218+
? {
219+
...service,
220+
status: Effect.fail(new BootService.BootServiceInstallError({ cause: "EACCES" })),
221+
}
222+
: service,
223+
),
224+
);
225+
226+
const output = yield* Command.runWith(serviceCommand, { version: packageJson.version })([
227+
"uninstall",
228+
"--base-dir",
229+
baseDir,
230+
]).pipe(
231+
Effect.andThen(TestConsole.logLines),
232+
Effect.map((lines) => lines.join("\n")),
233+
Effect.provideService(HostProcess.Environment, {}),
234+
Effect.provide(
235+
Layer.mergeAll(
236+
ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
237+
Layer.fresh(TestConsole.layer),
238+
),
239+
),
240+
);
241+
expect(uninstalls).toEqual(input.removed);
242+
expect(output).toContain(input.otherHome ? "another T3 home" : "Removed");
243+
}),
244+
);
197245
});

‎apps/server/src/cli/service.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@ const serviceUninstallCommand = Command.make("uninstall", projectLocationFlags).
278278
flags,
279279
Effect.gen(function* () {
280280
const service = yield* BootService.BootService;
281+
const path = yield* Path.Path;
282+
const { baseDir } = yield* ServerConfig.ServerConfig;
283+
// An unreadable unit stays removable; only a unit known to serve another home is kept.
284+
const installedBaseDir = yield* service.status.pipe(
285+
Effect.map((status) => status.installedBaseDir),
286+
Effect.orElseSucceed(() => undefined),
287+
);
288+
if (
289+
installedBaseDir !== undefined &&
290+
path.resolve(installedBaseDir) !== path.resolve(baseDir)
291+
) {
292+
yield* Console.log(
293+
"The installed service runs another T3 home, so it was not removed. Pass its --base-dir.",
294+
);
295+
return;
296+
}
281297
const removed = yield* service.uninstall;
282298
yield* Console.log(
283299
removed ? "Removed the T3 Code service." : "T3 Code service is not installed.",

‎apps/server/src/cli/update.test.ts‎

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import * as Layer from "effect/Layer";
1010
import * as Option from "effect/Option";
1111
import * as Path from "effect/Path";
1212
import * as TestClock from "effect/testing/TestClock";
13+
import * as TestConsole from "effect/testing/TestConsole";
1314
import { HttpClient, HttpClientResponse } from "effect/http";
1415
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1516
import { afterEach, vi } from "vite-plus/test";
1617

18+
import packageJson from "../../package.json" with { type: "json" };
1719
import * as BootService from "../cloud/bootService.ts";
18-
import { prunePinnedRuntimes } from "../cloud/pinnedRuntime.ts";
20+
import { pinnedRuntimePaths, prunePinnedRuntimes } from "../cloud/pinnedRuntime.ts";
1921
import * as ManagedPolicy from "../policy/ManagedPolicy.ts";
2022
import * as ProcessRunner from "../processRunner.ts";
2123
import {
@@ -434,3 +436,96 @@ it.layer(NodeServices.layer)("t3 update launcher", (it) => {
434436
}).pipe(Effect.scoped, Effect.provideService(HostProcess.Platform, "linux")),
435437
);
436438
});
439+
440+
// Without terminals, update skips its restart prompt whatever runs the test.
441+
const withoutTerminals = Effect.acquireRelease(
442+
Effect.sync(() =>
443+
[process.stdin, process.stdout].map((stream) => {
444+
const descriptor = Object.getOwnPropertyDescriptor(stream, "isTTY");
445+
Object.defineProperty(stream, "isTTY", { configurable: true, value: false });
446+
return { stream, descriptor };
447+
}),
448+
),
449+
(saved) =>
450+
Effect.sync(() => {
451+
for (const { stream, descriptor } of saved) {
452+
if (descriptor === undefined) Reflect.deleteProperty(stream, "isTTY");
453+
else Object.defineProperty(stream, "isTTY", descriptor);
454+
}
455+
}),
456+
);
457+
458+
it.layer(NodeServices.layer)("t3 update with a background service", (it) => {
459+
it.effect("names the version a service with a pending restart still runs", () =>
460+
Effect.gen(function* () {
461+
yield* withoutTerminals;
462+
const fs = yield* FileSystem.FileSystem;
463+
const path = yield* Path.Path;
464+
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-update-" });
465+
const version = packageJson.version;
466+
const runtime = pinnedRuntimePaths(path, baseDir, version, "linux");
467+
yield* fs.makeDirectory(runtime.versionDir, { recursive: true });
468+
yield* fs.writeFileString(runtime.entryPath, "");
469+
yield* fs.writeFileString(runtime.sentinelPath, `${version}\n`);
470+
const unitPath = path.join(baseDir, "t3code.service");
471+
const logPath = path.join(baseDir, "boot-service.log");
472+
// An earlier `t3 update` pointed the service at this version without restarting it.
473+
const service = Layer.mock(BootService.BootService, {
474+
status: Effect.succeed<BootService.BootServiceStatus>({
475+
supported: true,
476+
installed: true,
477+
current: false,
478+
installedVersion: version,
479+
installedBaseDir: baseDir,
480+
problems: ["restart-pending"],
481+
unitPath,
482+
logPath,
483+
}),
484+
install: () => Effect.succeed({ program: [runtime.entryPath], baseDir, unitPath, logPath }),
485+
});
486+
vi.spyOn(BootService, "layer").mockReturnValue(service);
487+
const runner = ProcessRunner.ProcessRunner.of({
488+
run: (input) =>
489+
input.args?.includes("--version") === true
490+
? unrelatedLsof
491+
.run(input)
492+
.pipe(Effect.map((result) => ({ ...result, stdout: `t3 v${version}\n` })))
493+
: unrelatedLsof.run(input),
494+
});
495+
496+
const output = yield* runUpdate({
497+
baseDir,
498+
logsDir: baseDir,
499+
serverRuntimeStatePath: path.join(baseDir, "server-runtime.json"),
500+
channel: undefined,
501+
requestedVersion: version,
502+
allowDowngrade: false,
503+
assumeYes: false,
504+
}).pipe(
505+
Effect.andThen(TestConsole.logLines),
506+
Effect.map((lines) => lines.join("\n")),
507+
Effect.provide(
508+
Layer.mergeAll(
509+
service,
510+
Layer.succeed(ProcessRunner.ProcessRunner, runner),
511+
ManagedPolicy.layerTest(),
512+
Layer.succeed(
513+
HttpClient.HttpClient,
514+
HttpClient.make(() => Effect.die("unexpected release lookup")),
515+
),
516+
Layer.fresh(TestConsole.layer),
517+
),
518+
),
519+
);
520+
521+
assert.include(
522+
output,
523+
`Background service still running the version before ${version}. Run \`t3 service restart\` when you are ready to switch it to ${version}.`,
524+
);
525+
}).pipe(
526+
Effect.scoped,
527+
Effect.provideService(HostProcess.Platform, "linux"),
528+
Effect.provideService(HostProcess.Environment, { PATH: "" }),
529+
),
530+
);
531+
});

‎apps/server/src/cli/update.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,15 @@ export const runUpdate = Effect.fn("cli.update.run")(function* (input: {
603603
} else if (serviceInstalled && serviceCurrent) {
604604
yield* Console.log(` Background service already on ${targetVersion}`);
605605
} else if (serviceInstalled) {
606+
// A pending restart means the service already points at serviceVersion but runs an older one.
607+
const running =
608+
serviceVersion === undefined
609+
? "an unknown version"
610+
: restartPending
611+
? `the version before ${serviceVersion}`
612+
: serviceVersion;
606613
yield* Console.log(
607-
` Background service still running ${serviceVersion ?? "an unknown version"}. Run \`t3 service restart\` when you are ready to switch it to ${targetVersion}.`,
614+
` Background service still running ${running}. Run \`t3 service restart\` when you are ready to switch it to ${targetVersion}.`,
608615
);
609616
} else if (status.installed && !servesThisHome) {
610617
yield* Console.log(

0 commit comments

Comments
 (0)