refactor(cli): remove trivial findRunningDashboardPid wrapper

The function was a one-line pass-through to findPidByPort with no added
logic. Callers now import findPidByPort from @composio/ao-core directly.
waitForPortFree calls findPidByPort inline. Deleted the test file that
only tested the pass-through.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Priyanshu Choudhary 2026-04-09 02:03:26 +05:30
parent 5ce89025af
commit 750a7140d4
5 changed files with 3 additions and 57 deletions

View File

@ -76,27 +76,6 @@ describe("cleanNextCache", () => {
});
});
describe("findRunningDashboardPid", () => {
it("returns PID when a process is listening", async () => {
mockFindPidByPort.mockResolvedValue("12345");
const { findRunningDashboardPid } = await import("../../src/lib/dashboard-rebuild.js");
const pid = await findRunningDashboardPid(3000);
expect(pid).toBe("12345");
expect(mockFindPidByPort).toHaveBeenCalledWith(3000);
});
it("returns null when no process is listening", async () => {
mockFindPidByPort.mockResolvedValue(null);
const { findRunningDashboardPid } = await import("../../src/lib/dashboard-rebuild.js");
const pid = await findRunningDashboardPid(3000);
expect(pid).toBeNull();
});
});
describe("isInstalledUnderNodeModules", () => {
it("returns true for a Unix node_modules path segment", async () => {
const { isInstalledUnderNodeModules } = await import("../../src/lib/dashboard-rebuild.js");

View File

@ -119,7 +119,6 @@ vi.mock("../../src/lib/web-dir.js", () => ({
}));
vi.mock("../../src/lib/dashboard-rebuild.js", () => ({
findRunningDashboardPid: vi.fn().mockResolvedValue(null),
rebuildDashboardProductionArtifacts: vi.fn().mockResolvedValue(undefined),
waitForPortFree: vi.fn(),
}));

View File

@ -1,23 +0,0 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
vi.mock("@composio/ao-core", async (importOriginal) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
const actual = await importOriginal<typeof import("@composio/ao-core")>();
return {
...actual,
findPidByPort: vi.fn().mockResolvedValue(null),
};
});
describe("findRunningDashboardPid", () => {
beforeEach(() => {
vi.resetModules();
});
it("delegates to findPidByPort from platform adapter", async () => {
const { findPidByPort } = await import("@composio/ao-core");
const { findRunningDashboardPid } = await import("../../src/lib/dashboard-rebuild.js");
await findRunningDashboardPid(3000);
expect(findPidByPort).toHaveBeenCalledWith(3000);
});
});

View File

@ -2,11 +2,10 @@ import { spawn } from "node:child_process";
import { resolve } from "node:path";
import chalk from "chalk";
import type { Command } from "commander";
import { isWindows, killProcessTree, loadConfig } from "@composio/ao-core";
import { findPidByPort, isWindows, killProcessTree, loadConfig } from "@composio/ao-core";
import { findWebDir, buildDashboardEnv, waitForPortAndOpen } from "../lib/web-dir.js";
import { forwardSignalsToChild } from "../lib/shell.js";
import {
findRunningDashboardPid,
isInstalledUnderNodeModules,
rebuildDashboardProductionArtifacts,
waitForPortFree,
@ -35,7 +34,7 @@ export function registerDashboard(program: Command): void {
if (opts.rebuild) {
// Check if a dashboard is already running on this port.
const runningPid = await findRunningDashboardPid(port);
const runningPid = await findPidByPort(port);
if (runningPid) {
// Stop the running server before rebuilding or restarting below.

View File

@ -30,14 +30,6 @@ export function assertDashboardRebuildSupported(webDir: string): void {
}
}
/**
* Find the PID of a process listening on the given port.
* Returns null if no process is found.
*/
export async function findRunningDashboardPid(port: number): Promise<string | null> {
return findPidByPort(port);
}
/**
* Wait for a port to be free (no process listening).
* Throws if the port is still busy after the timeout.
@ -45,7 +37,7 @@ export async function findRunningDashboardPid(port: number): Promise<string | nu
export async function waitForPortFree(port: number, timeoutMs: number): Promise<void> {
const start = Date.now();
while (Date.now() - start < timeoutMs) {
const pid = await findRunningDashboardPid(port);
const pid = await findPidByPort(port);
if (!pid) return;
await new Promise((r) => setTimeout(r, 200));
}