feat: add checkout service make targets (#1311)

This commit is contained in:
Carlos Florêncio
2026-06-08 19:30:21 +01:00
committed by GitHub
parent aac2afbf93
commit fc4bf8a40c
6 changed files with 167 additions and 3 deletions
@@ -25,6 +25,7 @@ const (
installKindHomebrew = "homebrew"
installKindNPM = "npm"
installKindNPX = "npx"
installKindLocal = "local"
manualServiceInstall = "kandev service install"
manualServiceRestart = "kandev service restart"
)
@@ -114,6 +114,47 @@ func TestService_GetForeignServiceDisablesApply(t *testing.T) {
}
}
func TestService_GetLocalBundleServiceDisablesApply(t *testing.T) {
homeDir := t.TempDir()
metadataPath, _ := writeServiceInstallForTest(t, homeDir, serviceInstallMetadata{
Manager: "systemd",
Mode: "user",
Kind: installKindLocal,
HomeDir: homeDir,
LogDir: filepath.Join(homeDir, "logs"),
ServicePath: filepath.Join(homeDir, "kandev.service"),
NodePath: "/usr/local/bin/node",
CLIEntry: "/Users/alice/src/kandev/dist/kandev/cli/bin/cli.js",
BundleDir: "/Users/alice/src/kandev/dist/kandev",
})
t.Setenv(envRunningAsService, "true")
t.Setenv(envServiceMode, "user")
t.Setenv(envServiceManager, "systemd")
t.Setenv(envInstallKind, installKindLocal)
t.Setenv(envServiceMetadata, metadataPath)
svc := NewService(newTestPool(t), "v1.0.0", nil, logger.Default(), WithHomeDir(homeDir))
resp, err := svc.Get()
if err != nil {
t.Fatalf("Get: %v", err)
}
if !resp.Install.ManagedService {
t.Fatalf("expected service to be recognised as managed")
}
if resp.ApplySupported {
t.Fatalf("ApplySupported=true for local bundle service")
}
if resp.ApplyUnsupportedReason == "" {
t.Fatalf("expected unsupported reason for local bundle service")
}
if !hasString(resp.ManualCommands, "kandev service install") {
t.Fatalf("manual commands = %v, want service install command", resp.ManualCommands)
}
if !hasString(resp.ManualCommands, "kandev service restart") {
t.Fatalf("manual commands = %v, want service restart command", resp.ManualCommands)
}
}
func TestManualCommandsNPXHasNoDuplicateBinaryName(t *testing.T) {
cmds := manualCommands(InstallStateResponse{Kind: installKindNPX, Mode: installModeUser}, "v1.2.3")
if !hasString(cmds, "npx -y kandev@1.2.3 service install") {
+13
View File
@@ -187,4 +187,17 @@ describe("captureLauncher shim resolution", () => {
expect(info.kind).toBe("homebrew");
expect(info.shimPath).toBeUndefined();
});
it("classifies a non-Cellar bundle as a local checkout install", () => {
const cliEntry = "/Users/alice/src/kandev/dist/kandev/cli/bin/cli.js";
process.argv = ["/path/to/node", cliEntry];
vi.stubEnv("KANDEV_BUNDLE_DIR", "/Users/alice/src/kandev/dist/kandev");
vi.spyOn(fs, "existsSync").mockImplementation((p) => p === cliEntry);
vi.spyOn(fs, "realpathSync").mockReturnValue(cliEntry);
const info = captureLauncher();
expect(info.kind).toBe("local");
expect(info.bundleDir).toBe("/Users/alice/src/kandev/dist/kandev");
expect(info.shimPath).toBeUndefined();
});
});
+5 -3
View File
@@ -34,7 +34,7 @@ export function macosSystemPlistPath(): string {
return path.join(MACOS_SYSTEM_DAEMON_DIR, `${LAUNCHD_LABEL}.plist`);
}
export type LauncherKind = "homebrew" | "npm" | "npx" | "unknown";
export type LauncherKind = "homebrew" | "npm" | "npx" | "local" | "unknown";
export type LauncherInfo = {
/** Absolute path to node executable (process.execPath at install time). */
@@ -43,7 +43,7 @@ export type LauncherInfo = {
cliEntry: string;
/** Best-guess of how kandev was installed. Used to seed env vars. */
kind: LauncherKind;
/** KANDEV_BUNDLE_DIR if set (Homebrew sets this). */
/** KANDEV_BUNDLE_DIR if set (Homebrew and local checkout installs set this). */
bundleDir?: string;
/** KANDEV_VERSION if set (Homebrew sets this). */
version?: string;
@@ -96,7 +96,9 @@ export function captureLauncher(): LauncherInfo {
const bundleDir = process.env.KANDEV_BUNDLE_DIR;
const version = process.env.KANDEV_VERSION;
const kind: LauncherKind = bundleDir
? "homebrew"
? homebrewShimPath(cliEntry)
? "homebrew"
: "local"
: looksLikeNpxEntry(cliEntry)
? "npx"
: cliEntry.includes(`${path.sep}node_modules${path.sep}`)