fix: harden dev stack process detection
This commit is contained in:
@@ -4,10 +4,15 @@ import {
|
||||
createStackConfig,
|
||||
formatServiceLogs,
|
||||
getDefaultTemporalCandidates,
|
||||
getServiceCommandMatchers,
|
||||
isServiceHealthy,
|
||||
isServiceProcessMatch,
|
||||
resolveTemporalCli,
|
||||
selectServicesForLogs,
|
||||
} from "../../scripts/dev-stack/stack.mjs";
|
||||
|
||||
type StackService = ReturnType<typeof createStackConfig>["services"][number];
|
||||
|
||||
describe("createStackConfig", () => {
|
||||
it("derives frontend and sibling backend paths from the workspace root", () => {
|
||||
const config = createStackConfig("/Volumes/DockCase/codes/auto-virtual-tryon-frontend");
|
||||
@@ -181,3 +186,50 @@ describe("formatServiceLogs", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("service process matching", () => {
|
||||
it("does not treat an unrelated process with a reused pid as the frontend service", () => {
|
||||
const config = createStackConfig("/Volumes/DockCase/codes/auto-virtual-tryon-frontend");
|
||||
const frontend = config.services.find((service: StackService) => service.key === "frontend");
|
||||
|
||||
expect(frontend).toBeDefined();
|
||||
expect(
|
||||
isServiceProcessMatch(frontend!, "node /tmp/unrelated-script.js --watch"),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("builds stable command matchers for backend api and worker processes", () => {
|
||||
const config = createStackConfig("/Volumes/DockCase/codes/auto-virtual-tryon-frontend");
|
||||
const backendApi = config.services.find((service: StackService) => service.key === "backend-api");
|
||||
const backendWorker = config.services.find((service: StackService) => service.key === "backend-worker");
|
||||
|
||||
expect(getServiceCommandMatchers(backendApi!)).toEqual(["uvicorn", "app.main:app"]);
|
||||
expect(getServiceCommandMatchers(backendWorker!)).toEqual(["app.workers.runner"]);
|
||||
});
|
||||
|
||||
it("requires the expected port to be open for port-bound services", () => {
|
||||
const config = createStackConfig("/Volumes/DockCase/codes/auto-virtual-tryon-frontend");
|
||||
const backendApi = config.services.find((service: StackService) => service.key === "backend-api");
|
||||
|
||||
expect(
|
||||
isServiceHealthy(backendApi!, {
|
||||
pid: 123,
|
||||
processCommand: "/path/to/python -m uvicorn app.main:app --host 127.0.0.1 --port 8000",
|
||||
portOpen: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("allows worker services without ports when the process command matches", () => {
|
||||
const config = createStackConfig("/Volumes/DockCase/codes/auto-virtual-tryon-frontend");
|
||||
const backendWorker = config.services.find((service: StackService) => service.key === "backend-worker");
|
||||
|
||||
expect(
|
||||
isServiceHealthy(backendWorker!, {
|
||||
pid: 123,
|
||||
processCommand: "/path/to/python -m app.workers.runner",
|
||||
portOpen: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user