Skip to content

Commit 727a5da

Browse files
saphidclaude
authored andcommitted
fix(server): t3 service uninstall leaves another T3 home's service alone
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c0ec87a commit 727a5da

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

‎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.",

0 commit comments

Comments
 (0)