diff --git a/CHANGELOG.md b/CHANGELOG.md index 51d0fac..c648e1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. +## 1.17.0 - 2026-09-30 + +Changes since 1.16.1: + +### Added + +- Files can be deleted from a run: a delete button (with confirmation) in the Files section of the run detail page, `DELETE /scenarios/:id/runs/:runId/files/:fileId`, and the `delete_run_file` MCP tool. The stored file is removed once no scenario or run references it. + ## 1.16.1 - 2026-09-30 Changes since 1.16.0: diff --git a/client/src/api/client.ts b/client/src/api/client.ts index 7dd7f8a..e3644d4 100644 --- a/client/src/api/client.ts +++ b/client/src/api/client.ts @@ -409,4 +409,9 @@ export const runFiles = { contentUrl(scenarioId: string, runId: string, fileId: string): string { return `${BASE_URL}/scenarios/${scenarioId}/runs/${runId}/files/${fileId}/content`; }, + remove(scenarioId: string, runId: string, fileId: string): Promise { + return request(`/scenarios/${scenarioId}/runs/${runId}/files/${fileId}`, { + method: 'DELETE', + }); + }, }; diff --git a/client/src/i18n/locales/en.json b/client/src/i18n/locales/en.json index 422ac54..b78292e 100644 --- a/client/src/i18n/locales/en.json +++ b/client/src/i18n/locales/en.json @@ -334,6 +334,10 @@ "expiresAtLabel": "Expires At (optional)", "createdAt": "Created", "download": "Download", + "delete": "Delete", + "deleteTitle": "Delete file", + "confirmDelete": "Are you sure you want to delete \"{{name}}\" from this run?", + "deleteSuccess": "File deleted", "expiredTooltip": "File is expired", "empty": "No files uploaded.", "totalCount": "Total: {{count}} file(s)", diff --git a/client/src/pages/run/RunDetailPage.tsx b/client/src/pages/run/RunDetailPage.tsx index 03966cc..22e02b8 100644 --- a/client/src/pages/run/RunDetailPage.tsx +++ b/client/src/pages/run/RunDetailPage.tsx @@ -14,7 +14,11 @@ import type { FileMetadata, } from '../../api'; import { scenarios } from '../../api'; -import { ExportLogsModal, type LogExportFormat } from '../../components/modals'; +import { + DeleteConfirmationModal, + ExportLogsModal, + type LogExportFormat, +} from '../../components/modals'; import { AutoRefreshIndicator, Badge, @@ -38,6 +42,7 @@ import { ClipboardList, Activity, Download, + Trash2, RotateCcw, } from 'lucide-react'; import styles from '../Page.module.css'; @@ -103,6 +108,8 @@ function RunDetail() { const [exportLogsOpen, setExportLogsOpen] = useState(false); const [exportLogsFormat, setExportLogsFormat] = useState('md'); const [exportingLogs, setExportingLogs] = useState(false); + const [pendingDeleteFile, setPendingDeleteFile] = useState(null); + const [deletingFile, setDeletingFile] = useState(false); const [repeating, setRepeating] = useState(false); const logSearchRef = useRef(''); const LOG_PAGE_SIZE = 25; @@ -167,6 +174,21 @@ function RunDetail() { } }; + const handleDeleteFile = async () => { + if (!id || !runId || !pendingDeleteFile) return; + setDeletingFile(true); + try { + await runFiles.remove(id, runId, pendingDeleteFile.id); + toast.success(t('files.deleteSuccess')); + setPendingDeleteFile(null); + await loadArtifacts(); + } catch { + // error toast is already emitted by the API client + } finally { + setDeletingFile(false); + } + }; + const manualRefresh = () => { if (!id || !runId) return; runs @@ -611,6 +633,21 @@ function RunDetail() { ); }, }, + { + key: 'delete', + header: '', + render: (f) => ( + + ), + }, ] satisfies TableColumn[] } emptyMessage={t('files.empty')} @@ -628,6 +665,15 @@ function RunDetail() { onExport={handleExportLogs} isExporting={exportingLogs} /> + + setPendingDeleteFile(null)} + onConfirm={handleDeleteFile} + isDeleting={deletingFile} + /> ); } diff --git a/docs/mcp.md b/docs/mcp.md index e66c75c..04e8da3 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -77,7 +77,8 @@ The server currently registers the following tools. | Tool | Description | |---|---| | `list_run_files` | List files (artifacts) created during a scenario run (paginated) | -| `get_run_file_content` | Retrieve run artifact content as base64 with metadata; run artifacts are read-only and inherit expiry from the run artifact subsystem | +| `get_run_file_content` | Retrieve run artifact content as base64 with metadata; run artifact content can't be modified and inherits expiry from the run artifact subsystem | +| `delete_run_file` | Delete a file from a run; the stored file is removed once no scenario or run references it (also `DELETE /scenarios/:id/runs/:runId/files/:fileId` and the delete button on the run detail page) | ## Binary Content Handling diff --git a/package-lock.json b/package-lock.json index 2af2984..2efa8c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "liqa", - "version": "1.16.1", + "version": "1.17.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "liqa", - "version": "1.16.1", + "version": "1.17.0", "workspaces": [ "server", "client" diff --git a/package.json b/package.json index 169bea0..35b849b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "liqa", - "version": "1.16.1", + "version": "1.17.0", "private": true, "workspaces": [ "server", diff --git a/server/src/mcp/mcp.service.ts b/server/src/mcp/mcp.service.ts index f7b38ea..cd9b424 100644 --- a/server/src/mcp/mcp.service.ts +++ b/server/src/mcp/mcp.service.ts @@ -1556,6 +1556,37 @@ export class McpService { }, ); + server.registerTool( + "delete_run_file", + { + description: + "Delete a file from a run. The stored file is removed once nothing else references it", + inputSchema: { + scenarioId: z.uuid().describe("Scenario ID"), + runId: z.uuid().describe("Run ID"), + fileId: z.uuid().describe("File ID (from list_run_files)"), + }, + }, + async ({ scenarioId, runId, fileId }) => { + try { + await this.scenarioService.deleteRunFile(scenarioId, runId, fileId); + return { + content: [ + { + type: "text" as const, + text: `File ${fileId} deleted from run ${runId}`, + }, + ], + }; + } catch (err) { + return { + isError: true, + content: [{ type: "text" as const, text: (err as Error).message }], + }; + } + }, + ); + server.registerTool( "get_run_file_content", { diff --git a/server/src/scenario/scenario.controller.ts b/server/src/scenario/scenario.controller.ts index e2c0e87..1a0d550 100644 --- a/server/src/scenario/scenario.controller.ts +++ b/server/src/scenario/scenario.controller.ts @@ -434,4 +434,17 @@ export class ScenarioController { ) { return this.scenarioService.getRunFileContent(id, runId, fileId, res); } + + @Delete(":id/runs/:runId/files/:fileId") + @HttpCode(204) + @ApiOperation({ summary: "Delete a file from a run" }) + @ApiResponse({ status: 204, description: "File deleted" }) + @ApiResponse({ status: 404, description: "Scenario, run, or file not found" }) + deleteRunFile( + @Param("id", ParseUUIDPipe) id: string, + @Param("runId", ParseUUIDPipe) runId: string, + @Param("fileId", ParseUUIDPipe) fileId: string, + ) { + return this.scenarioService.deleteRunFile(id, runId, fileId); + } } diff --git a/server/src/scenario/scenario.service.ts b/server/src/scenario/scenario.service.ts index bf34f9d..5b9ba81 100644 --- a/server/src/scenario/scenario.service.ts +++ b/server/src/scenario/scenario.service.ts @@ -1116,6 +1116,28 @@ export class ScenarioService implements OnModuleInit { }; } + /** + * Removes a file from a run. The stored file itself is deleted once no + * scenario or run references it any more. + */ + async deleteRunFile( + scenarioId: string, + runId: string, + fileId: string, + ): Promise { + await this.findOne(scenarioId); // 404 guard + const run = await this.runRepo.findOneBy({ id: runId, scenarioId }); + if (!run) { + throw new NotFoundException(`Run ${runId} not found in scenario ${scenarioId}`); + } + const link = await this.scenarioRunFileRepo.findOneBy({ runId, fileId }); + if (!link) { + throw new NotFoundException(`File ${fileId} not found in run ${runId}`); + } + await this.scenarioRunFileRepo.delete(link.id); + await this.fileStorageService.deleteFile(fileId); + } + async getRunFileContent( scenarioId: string, runId: string, diff --git a/server/test/file.controller.spec.ts b/server/test/file.controller.spec.ts index 9495136..daeeb6d 100644 --- a/server/test/file.controller.spec.ts +++ b/server/test/file.controller.spec.ts @@ -6,6 +6,7 @@ import { Repository } from "typeorm"; import { buildTestApp } from "./app.harness"; import { FileStorageService } from "../src/file/file-storage.service"; import { FileEntity } from "../src/file/file.entity"; +import { ScenarioRunFileEntity } from "../src/file/scenario-run-file.entity"; import { ScenarioEntity } from "../src/scenario/scenario.entity"; import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity"; @@ -15,6 +16,7 @@ describe("File Controller Integration Tests", () => { let fileRepo: Repository; let scenarioRepo: Repository; let runRepo: Repository; + let runFileRepo: Repository; let filesDir: string; beforeAll(async () => { @@ -27,6 +29,9 @@ describe("File Controller Integration Tests", () => { runRepo = app.get>( getRepositoryToken(ScenarioRunEntity), ); + runFileRepo = app.get>( + getRepositoryToken(ScenarioRunFileEntity), + ); // Get the files directory from the service filesDir = fileStorageService.getAbsolutePath(""); @@ -335,6 +340,79 @@ describe("File Controller Integration Tests", () => { }); }); + // ── DELETE /scenarios/:id/runs/:runId/files/:fileId ─────────────────────── + + describe("DELETE /scenarios/:id/runs/:runId/files/:fileId", () => { + async function createArtifact(runId: string, name = "to-delete.txt") { + return fileStorageService.createAndSaveRunArtifact( + runId, + Buffer.from("delete me"), + name, + "text/plain", + ); + } + + it("removes the file from the run and deletes the stored file", async () => { + const scenario = await createScenario("run-file-delete"); + const run = await createRun(scenario.id); + const file = await createArtifact(run.id); + const physicalPath = fileStorageService.getAbsolutePath(file.filePath); + + await request(app.getHttpServer()) + .delete(`/scenarios/${scenario.id}/runs/${run.id}/files/${file.id}`) + .expect(204); + + const list = await request(app.getHttpServer()) + .get(`/scenarios/${scenario.id}/runs/${run.id}/files`) + .expect(200); + expect(list.body.items).toHaveLength(0); + expect(await fileRepo.findOneBy({ id: file.id })).toBeNull(); + await expect(fs.access(physicalPath)).rejects.toThrow(); + }); + + it("keeps the stored file while another run still references it", async () => { + const scenario = await createScenario("run-file-delete-shared"); + const run = await createRun(scenario.id); + const otherRun = await createRun(scenario.id); + const file = await createArtifact(run.id, "shared.txt"); + await runFileRepo.save( + runFileRepo.create({ runId: otherRun.id, fileId: file.id }), + ); + + await request(app.getHttpServer()) + .delete(`/scenarios/${scenario.id}/runs/${run.id}/files/${file.id}`) + .expect(204); + + expect(await fileRepo.findOneBy({ id: file.id })).not.toBeNull(); + await request(app.getHttpServer()) + .get( + `/scenarios/${scenario.id}/runs/${otherRun.id}/files/${file.id}/content`, + ) + .expect(200); + }); + + it("returns 404 for a file that belongs to a different run", async () => { + const scenario = await createScenario("run-file-delete-mismatch"); + const run = await createRun(scenario.id); + const otherRun = await createRun(scenario.id); + const file = await createArtifact(otherRun.id); + + await request(app.getHttpServer()) + .delete(`/scenarios/${scenario.id}/runs/${run.id}/files/${file.id}`) + .expect(404); + expect(await fileRepo.findOneBy({ id: file.id })).not.toBeNull(); + }); + + it("returns 404 when the run does not exist", async () => { + const scenario = await createScenario("run-file-delete-no-run"); + await request(app.getHttpServer()) + .delete( + `/scenarios/${scenario.id}/runs/00000000-0000-0000-0000-000000000000/files/00000000-0000-0000-0000-000000000000`, + ) + .expect(404); + }); + }); + // ── File cleanup ─────────────────────────────────────────────────────────── describe("File cleanup", () => { diff --git a/server/test/mcp.controller.spec.ts b/server/test/mcp.controller.spec.ts index 0f7dd09..eb47f00 100644 --- a/server/test/mcp.controller.spec.ts +++ b/server/test/mcp.controller.spec.ts @@ -611,6 +611,42 @@ describe("McpController", () => { }); }); + describe("delete_run_file", () => { + it("deletes a run artifact so it is no longer listed", async () => { + const { sc, run } = await createRunArtifactFixture("mcp-run-file-delete"); + const listFiles = async () => + JSON.parse( + ( + (await mcpCall("list_run_files", { scenarioId: sc.id, runId: run.id })) + .rpc.result as { content: { text: string }[] } + ).content[0].text, + ) as { items: Array<{ id: string; name: string }>; total: number }; + + const file = (await listFiles()).items.find((f) => f.name === "artifact.bin")!; + const { status, rpc } = await mcpCall("delete_run_file", { + scenarioId: sc.id, + runId: run.id, + fileId: file.id, + }); + expect(status).toBe(200); + const result = rpc.result as { isError?: boolean; content: { text: string }[] }; + expect(result.isError).toBeFalsy(); + expect(result.content[0].text).toContain(file.id); + expect((await listFiles()).items.map((f) => f.id)).not.toContain(file.id); + }); + + it("returns an MCP error for a file not in the run", async () => { + const { sc, run } = await createRunArtifactFixture("mcp-run-file-delete-missing"); + const { status, rpc } = await mcpCall("delete_run_file", { + scenarioId: sc.id, + runId: run.id, + fileId: "00000000-0000-0000-0000-000000000000", + }); + expect(status).toBe(200); + expect((rpc.result as { isError: boolean }).isError).toBe(true); + }); + }); + describe("get_run_file_content", () => { it("returns run artifact bytes as base64 for a valid file", async () => { const { sc, run } = await createRunArtifactFixture("mcp-run-file-content-test");