From 2b185c7daa63d29c6c7cc5707ff309ffcbb074b1 Mon Sep 17 00:00:00 2001 From: Gabriel Darbord <78592838+Gabriel-Darbord@users.noreply.github.com> Date: Mon, 23 Nov 2026 00:25:19 +0100 Subject: [PATCH] Delete the launcher's logs of an image with it A delete removed the image's directory and left the launcher's logs of its starts behind for good. It now asks the launcher to delete them once the directory is gone, which needs pharo-launcher-mcp's deleteLaunchLogs, so the pin moves to the release that has it. A launcher that cannot be opened fails nothing: the image is gone, and the launcher's next start sweeps the logs of images that no longer exist. Co-Authored-By: Claude Opus 5.5 --- README.md | 8 +++--- packages/plexus/src/images/delete.ts | 18 ++++++++++--- .../src/launcher/pharoLauncherMcpClient.ts | 2 ++ .../plexus/test/images/stopAndDelete.test.ts | 27 +++++++++++++++++-- .../launcher/pharoLauncherMcpClient.test.ts | 21 +++++++++++++++ packages/plexus/test/support/fakeLauncher.ts | 10 +++++++ 6 files changed, 78 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 12b9ec5..155c8e8 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,8 @@ stdout; a refusal is `{"ok":false,"code":...,"error":...}` with exit status 1. already answers is left as it is, and answered the same way with `alreadyRunning: true`; one a VM runs that does not answer is refused (`image-running`). It fails as soon as the VM reports a failure or exits, - naming the launcher's logs. It never creates: a missing image is refused. + naming the launcher's logs, which the launcher keeps for the image's last + few starts. It never creates: a missing image is refused. - **stop** does not save: the image starts again as it was last saved. The image is asked to quit, by evaluating `Smalltalk snapshot: false andQuit: true` with the `evaluate` tool its MCP server lists, so that it does what it @@ -83,8 +84,9 @@ stdout; a refusal is `{"ok":false,"code":...,"error":...}` with exit status 1. lists no evaluate tool. Evaluating `Smalltalk saveSession` in the image saves it without stopping it. An image that is not running is already stopped. -- **delete** removes the image's directory, and refuses while a VM runs it or - a create or a start is still at work on it. +- **delete** removes the image's directory and the launcher's logs of its + starts, and refuses while a VM runs it or a create or a start is still at + work on it. - **list** shows each image, its state, its pids, its endpoint, its template, Pharo version, how MCP got into it, and whether it records its calls when that is known (see [Telemetry](#telemetry)). It pings nothing and diff --git a/packages/plexus/src/images/delete.ts b/packages/plexus/src/images/delete.ts index c395a01..64b68d0 100644 --- a/packages/plexus/src/images/delete.ts +++ b/packages/plexus/src/images/delete.ts @@ -4,12 +4,13 @@ import type { ImagesContext } from "./context.js"; import { buildingState, stillBuilding } from "./create.js"; import { hostProcesses, vmsOn } from "./processes.js"; import { beingStarted, launchLockState } from "./start.js"; -import { exists, imageFiles, noSuchImage, removeDirectory } from "./store.js"; +import { exists, imageFiles, noSuchImage, removeDirectory, type ImageFiles } from "./store.js"; /** * Remove the image's directory, complete or not, unless a VM runs it, or a - * create or a start is still working on it. An image whose create ended - * before it was done is removed like any other. + * create or a start is still working on it, and then the launcher's logs of + * its starts. An image whose create ended before it was done is removed like + * any other. */ export async function deleteImage( context: ImagesContext, @@ -32,5 +33,16 @@ export async function deleteImage( throw beingStarted(files, lock.holder); } removeDirectory(context.home, files.dir); + deleteLaunchLogs(context, files); return { name }; } + +// The image is gone whatever happens to its logs: a launcher that cannot be +// opened leaves them to the sweep of the next start. +function deleteLaunchLogs(context: ImagesContext, files: ImageFiles): void { + try { + context.launcher().deleteLaunchLogs({ imageName: files.diskName }); + } catch { + // Left for the launcher's next start. + } +} diff --git a/packages/plexus/src/launcher/pharoLauncherMcpClient.ts b/packages/plexus/src/launcher/pharoLauncherMcpClient.ts index c5419a2..8d5b5c7 100644 --- a/packages/plexus/src/launcher/pharoLauncherMcpClient.ts +++ b/packages/plexus/src/launcher/pharoLauncherMcpClient.ts @@ -21,6 +21,7 @@ export type LauncherPort = Pick< PharoLauncher, | "createImage" | "startImage" + | "deleteLaunchLogs" | "listProcesses" | "killProcess" | "listTemplateCategories" @@ -44,6 +45,7 @@ export function openLauncherPort(home: string): LauncherPort { createImage: (input) => longLauncher().createImage(input), startImage: (input) => (input.detached ? quickLauncher() : longLauncher()).startImage(input), + deleteLaunchLogs: (input) => quickLauncher().deleteLaunchLogs(input), listProcesses: (input) => quickLauncher().listProcesses(input), killProcess: (input) => quickLauncher().killProcess(input), listTemplateCategories: (input) => quickLauncher().listTemplateCategories(input), diff --git a/packages/plexus/test/images/stopAndDelete.test.ts b/packages/plexus/test/images/stopAndDelete.test.ts index e038c5e..24be31f 100644 --- a/packages/plexus/test/images/stopAndDelete.test.ts +++ b/packages/plexus/test/images/stopAndDelete.test.ts @@ -511,11 +511,33 @@ describe("stop with save", () => { }); describe("delete", () => { - it("removes the image's directory", async () => { - const { home, context } = setup(); + it("removes the image's directory, then the launcher's logs of its starts", async () => { + const { home, launcher, dir, context } = setup(); + launcher.deleteLaunchLogs = (input) => { + launcher.calls.push({ method: "deleteLaunchLogs", input }); + expect(fs.existsSync(dir)).toBe(false); + }; expect(await deleteImage(context, "dev")).toEqual({ name: "dev" }); expect(fs.readdirSync(storeRoot(home))).toEqual([]); expect(fs.readdirSync(tmpRoot(home))).toEqual([]); + expect(launcher.called("deleteLaunchLogs")).toEqual([{ imageName: "dev" }]); + }); + + it("names the logs by the image's name on disk, which holds its scope", async () => { + const home = tempHome(); + const launcher = new FakeLauncher(home); + writeLauncherImage(launcher.imageDir("shop-dev"), "shop-dev"); + const context = testContext(home, launcher, { scope: "shop" }); + + await deleteImage(context, "dev"); + expect(launcher.called("deleteLaunchLogs")).toEqual([{ imageName: "shop-dev" }]); + }); + + it("is done when the launcher cannot delete the logs", async () => { + const { home, launcher, context } = setup(); + launcher.deleteLogsFailure = new Error("no launcher installation"); + expect(await deleteImage(context, "dev")).toEqual({ name: "dev" }); + expect(fs.readdirSync(storeRoot(home))).toEqual([]); }); it("removes an image whose create ended before it was done", async () => { @@ -572,6 +594,7 @@ describe("delete", () => { details: { pids: [vm.pid] }, }); expect(fs.existsSync(dir)).toBe(true); + expect(launcher.called("deleteLaunchLogs")).toEqual([]); }); it("refuses while a start is launching it", async () => { diff --git a/packages/plexus/test/launcher/pharoLauncherMcpClient.test.ts b/packages/plexus/test/launcher/pharoLauncherMcpClient.test.ts index 21aadfa..53f6f08 100644 --- a/packages/plexus/test/launcher/pharoLauncherMcpClient.test.ts +++ b/packages/plexus/test/launcher/pharoLauncherMcpClient.test.ts @@ -1,3 +1,4 @@ +import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { openPharoLauncher } from "@evref-bl/pharo-launcher-mcp/launcher"; @@ -6,8 +7,10 @@ import { plexusHome, storeRoot } from "../../src/home.js"; import { launcherFailureMessage, launchLogPaths, + openLauncherPort, } from "../../src/launcher/pharoLauncherMcpClient.js"; import { homeProfileEnvironment } from "../../src/launcher/pharoLauncherProfile.js"; +import { tempHome } from "../support/fakeLauncher.js"; describe("the home", () => { it("is PLEXUS_HOME, or ~/.plexus", () => { @@ -136,3 +139,21 @@ describe("a detached launch", () => { expect(launchLogPaths({ ok: false })).toEqual([]); }); }); + +describe("a deleted image's logs", () => { + it("go from the home's logs directory, and no other image's", () => { + const home = tempHome(); + const logs = path.join(home, "profiles", "logs"); + fs.mkdirSync(logs, { recursive: true }); + fs.mkdirSync(path.join(storeRoot(home), "shop-kept"), { recursive: true }); + const log = (image: string) => path.join(logs, `2026-11-23T10-00-00-000Z-${image}-launch.out.log`); + for (const image of ["shop-gone", "shop-kept"]) { + fs.writeFileSync(log(image), ""); + } + + openLauncherPort(home).deleteLaunchLogs({ imageName: "shop-gone" }); + + expect(fs.existsSync(log("shop-gone"))).toBe(false); + expect(fs.existsSync(log("shop-kept"))).toBe(true); + }); +}); diff --git a/packages/plexus/test/support/fakeLauncher.ts b/packages/plexus/test/support/fakeLauncher.ts index c26771a..e99f50c 100644 --- a/packages/plexus/test/support/fakeLauncher.ts +++ b/packages/plexus/test/support/fakeLauncher.ts @@ -131,6 +131,16 @@ export class FakeLauncher implements LauncherPort { return launched(vm.pid, this.home); } + /** Throws this instead of deleting nothing. */ + deleteLogsFailure?: Error; + + deleteLaunchLogs(input: { imageName: string }): void { + this.calls.push({ method: "deleteLaunchLogs", input }); + if (this.deleteLogsFailure) { + throw this.deleteLogsFailure; + } + } + async listProcesses(): Promise> { this.calls.push({ method: "listProcesses", input: undefined }); return ok([...this.processes]);