Skip to content

Commit cef38a5

Browse files
author
PR Batch Tester
committed
fix(server): quote service home paths in CLI hints
1 parent 95d64fe commit cef38a5

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
2-
import { expect, it } from "@effect/vitest";
2+
import { expect, it, live } from "@effect/vitest";
33
import * as HostProcess from "@t3tools/shared/HostProcess";
44
import * as NetService from "@t3tools/shared/Net";
55
import * as ConfigProvider from "effect/ConfigProvider";
@@ -8,6 +8,8 @@ import * as FileSystem from "effect/FileSystem";
88
import * as Layer from "effect/Layer";
99
import * as Terminal from "effect/Terminal";
1010
import * as TestConsole from "effect/testing/TestConsole";
11+
import * as ChildProcess from "effect/process/ChildProcess";
12+
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1113
import { Command } from "effect/cli";
1214
import { afterEach, vi } from "vite-plus/test";
1315

@@ -59,6 +61,44 @@ function makeTestService(
5961
return { service, installOptions, restarts };
6062
}
6163

64+
live("quotes another home's directory in the status and error hints", () =>
65+
Effect.gen(function* () {
66+
const fs = yield* FileSystem.FileSystem;
67+
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-service-cli-test-" });
68+
const otherBaseDir = "/home/me/T3's Data/$HOME/$(printf unexpected)";
69+
const { service } = makeTestService({ ...status, current: false, otherBaseDir });
70+
vi.spyOn(BootService, "layer").mockReturnValue(Layer.succeed(BootService.BootService, service));
71+
const output = yield* Command.runWith(serviceCommand, { version: packageJson.version })([
72+
"status",
73+
"--base-dir",
74+
baseDir,
75+
]).pipe(
76+
Effect.andThen(TestConsole.logLines),
77+
Effect.map((lines) => lines.join("\n")),
78+
Effect.provideService(HostProcess.Environment, {}),
79+
Effect.provide(
80+
Layer.mergeAll(
81+
ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
82+
Layer.fresh(TestConsole.layer),
83+
),
84+
),
85+
);
86+
const error = new BootService.BootServiceOtherBaseDirError({
87+
installedBaseDir: otherBaseDir,
88+
baseDir,
89+
});
90+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
91+
for (const message of [output, error.message]) {
92+
const hint = message.match(/Pass `?(--base-dir .*?)`? to manage it/)?.[1];
93+
expect(hint).toBeDefined();
94+
const args = yield* spawner.string(
95+
ChildProcess.make("sh", ["-c", `set -- ${hint}; printf '%s\\n' "$#" "$1" "$2"`]),
96+
);
97+
expect(args).toBe(`2\n--base-dir\n${otherBaseDir}\n`);
98+
}
99+
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NetService.layer))),
100+
);
101+
62102
it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands", (it) => {
63103
it.effect.each(["install", "update"] as const)(
64104
"%s refuses a downgrade before changing the service",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function formatServiceStatus(status: BootService.BootServiceStatus, cliVersion:
8080
"T3 Code service",
8181
" Status: installed for another T3 home",
8282
` Base dir: ${status.otherBaseDir}`,
83-
` Next: Pass \`--base-dir ${status.otherBaseDir}\` to manage it.`,
83+
` Next: Pass \`${BootService.formatBootServiceBaseDirOption(status.otherBaseDir)}\` to manage it.`,
8484
].join("\n");
8585
}
8686
const installedVersion = status.installedVersion ?? cliVersion;

‎apps/server/src/cloud/bootService.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ export class BootServiceDowngradeRefusedError extends Schema.TaggedError<BootSer
463463
}
464464
}
465465

466+
export const formatBootServiceBaseDirOption = (baseDir: string) =>
467+
`--base-dir '${baseDir.replaceAll("'", `'"'"'`)}'`;
468+
466469
export class BootServiceOtherBaseDirError extends Schema.TaggedError<BootServiceOtherBaseDirError>()(
467470
"BootServiceOtherBaseDirError",
468471
{
@@ -471,7 +474,7 @@ export class BootServiceOtherBaseDirError extends Schema.TaggedError<BootService
471474
},
472475
) {
473476
override get message(): string {
474-
return `The T3 Code service on this machine serves ${this.installedBaseDir}, not ${this.baseDir}. Pass --base-dir ${this.installedBaseDir} to manage it, or run \`t3 service uninstall\` first to move it; both data directories are kept.`;
477+
return `The T3 Code service on this machine serves ${this.installedBaseDir}, not ${this.baseDir}. Pass ${formatBootServiceBaseDirOption(this.installedBaseDir)} to manage it, or run \`t3 service uninstall\` first to move it; both data directories are kept.`;
475478
}
476479
}
477480

0 commit comments

Comments
 (0)