Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions apps/server/src/cli/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function makeTestService(
) {
const installOptions: Array<Parameters<BootService.BootService["Service"]["install"]>[0]> = [];
const restarts: Array<true> = [];
const uninstalls: Array<true> = [];
const service = BootService.BootService.of({
status: Effect.succeed(serviceStatus),
withStopped: (operation) => operation,
Expand All @@ -49,9 +50,12 @@ function makeTestService(
logPath: serviceStatus.logPath,
};
}),
uninstall: Effect.succeed(false),
uninstall: Effect.sync(() => {
uninstalls.push(true);
return serviceStatus.installed;
}),
});
return { service, installOptions, restarts };
return { service, installOptions, restarts, uninstalls };
}

it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands", (it) => {
Expand Down Expand Up @@ -194,4 +198,48 @@ it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands
expect(installOptions).toEqual([]);
}),
);

it.effect.each([
{ label: "this home's service", otherHome: false, unreadable: false, removed: [true] },
{ label: "another home's service", otherHome: true, unreadable: false, removed: [] },
{ label: "an unreadable service", otherHome: false, unreadable: true, removed: [true] },
])("uninstall removes only $label", (input) =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-service-cli-test-" });
const { service, uninstalls } = makeTestService({
...status,
installedBaseDir: input.otherHome ? "/home/me/.t3" : baseDir,
});
vi.spyOn(BootService, "layer").mockReturnValue(
Layer.succeed(
BootService.BootService,
input.unreadable
? {
...service,
status: Effect.fail(new BootService.BootServiceInstallError({ cause: "EACCES" })),
}
: service,
),
);

const output = yield* Command.runWith(serviceCommand, { version: packageJson.version })([
"uninstall",
"--base-dir",
baseDir,
]).pipe(
Effect.andThen(TestConsole.logLines),
Effect.map((lines) => lines.join("\n")),
Effect.provideService(HostProcess.Environment, {}),
Effect.provide(
Layer.mergeAll(
ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
Layer.fresh(TestConsole.layer),
),
),
);
expect(uninstalls).toEqual(input.removed);
expect(output).toContain(input.otherHome ? "another T3 home" : "Removed");
}),
);
});
16 changes: 16 additions & 0 deletions apps/server/src/cli/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,22 @@ const serviceUninstallCommand = Command.make("uninstall", projectLocationFlags).
flags,
Effect.gen(function* () {
const service = yield* BootService.BootService;
const path = yield* Path.Path;
const { baseDir } = yield* ServerConfig.ServerConfig;
// An unreadable unit stays removable; only a unit known to serve another home is kept.
const installedBaseDir = yield* service.status.pipe(
Effect.map((status) => status.installedBaseDir),
Effect.orElseSucceed(() => undefined),
);
if (
installedBaseDir !== undefined &&
path.resolve(installedBaseDir) !== path.resolve(baseDir)
) {
yield* Console.log(
"The installed service runs another T3 home, so it was not removed. Pass its --base-dir.",
);
return;
}
const removed = yield* service.uninstall;
yield* Console.log(
removed ? "Removed the T3 Code service." : "T3 Code service is not installed.",
Expand Down
Loading