feat(runs): add deleting files from a run
- add 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 - add a delete button with confirmation to the run detail files table - bump version to 1.17.0
This commit is contained in:
1 parent
ac12301818
commit
1c5c906cbb
12 files changed
+249
-5
No files matched your search
@@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
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
|
## 1.16.1 - 2026-09-30
|
||||||
|
|
||||||
Changes since 1.16.0:
|
Changes since 1.16.0:
|
||||||
|
|||||||
@@ -409,4 +409,9 @@ export const runFiles = {
|
|||||||
contentUrl(scenarioId: string, runId: string, fileId: string): string {
|
contentUrl(scenarioId: string, runId: string, fileId: string): string {
|
||||||
return `${BASE_URL}/scenarios/${scenarioId}/runs/${runId}/files/${fileId}/content`;
|
return `${BASE_URL}/scenarios/${scenarioId}/runs/${runId}/files/${fileId}/content`;
|
||||||
},
|
},
|
||||||
|
remove(scenarioId: string, runId: string, fileId: string): Promise<void> {
|
||||||
|
return request(`/scenarios/${scenarioId}/runs/${runId}/files/${fileId}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
@@ -334,6 +334,10 @@
|
|||||||
"expiresAtLabel": "Expires At (optional)",
|
"expiresAtLabel": "Expires At (optional)",
|
||||||
"createdAt": "Created",
|
"createdAt": "Created",
|
||||||
"download": "Download",
|
"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",
|
"expiredTooltip": "File is expired",
|
||||||
"empty": "No files uploaded.",
|
"empty": "No files uploaded.",
|
||||||
"totalCount": "Total: {{count}} file(s)",
|
"totalCount": "Total: {{count}} file(s)",
|
||||||
|
|||||||
@@ -14,7 +14,11 @@ import type {
|
|||||||
FileMetadata,
|
FileMetadata,
|
||||||
} from '../../api';
|
} from '../../api';
|
||||||
import { scenarios } from '../../api';
|
import { scenarios } from '../../api';
|
||||||
import { ExportLogsModal, type LogExportFormat } from '../../components/modals';
|
import {
|
||||||
|
DeleteConfirmationModal,
|
||||||
|
ExportLogsModal,
|
||||||
|
type LogExportFormat,
|
||||||
|
} from '../../components/modals';
|
||||||
import {
|
import {
|
||||||
AutoRefreshIndicator,
|
AutoRefreshIndicator,
|
||||||
Badge,
|
Badge,
|
||||||
@@ -38,6 +42,7 @@ import {
|
|||||||
ClipboardList,
|
ClipboardList,
|
||||||
Activity,
|
Activity,
|
||||||
Download,
|
Download,
|
||||||
|
Trash2,
|
||||||
RotateCcw,
|
RotateCcw,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
@@ -103,6 +108,8 @@ function RunDetail() {
|
|||||||
const [exportLogsOpen, setExportLogsOpen] = useState(false);
|
const [exportLogsOpen, setExportLogsOpen] = useState(false);
|
||||||
const [exportLogsFormat, setExportLogsFormat] = useState<LogExportFormat>('md');
|
const [exportLogsFormat, setExportLogsFormat] = useState<LogExportFormat>('md');
|
||||||
const [exportingLogs, setExportingLogs] = useState(false);
|
const [exportingLogs, setExportingLogs] = useState(false);
|
||||||
|
const [pendingDeleteFile, setPendingDeleteFile] = useState<FileMetadata | null>(null);
|
||||||
|
const [deletingFile, setDeletingFile] = useState(false);
|
||||||
const [repeating, setRepeating] = useState(false);
|
const [repeating, setRepeating] = useState(false);
|
||||||
const logSearchRef = useRef('');
|
const logSearchRef = useRef('');
|
||||||
const LOG_PAGE_SIZE = 25;
|
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 = () => {
|
const manualRefresh = () => {
|
||||||
if (!id || !runId) return;
|
if (!id || !runId) return;
|
||||||
runs
|
runs
|
||||||
@@ -611,6 +633,21 @@ function RunDetail() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'delete',
|
||||||
|
header: '',
|
||||||
|
render: (f) => (
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
title={t('files.delete')}
|
||||||
|
aria-label={t('files.delete')}
|
||||||
|
onClick={() => setPendingDeleteFile(f)}
|
||||||
|
>
|
||||||
|
<Trash2 size={14} />
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
] satisfies TableColumn<FileMetadata>[]
|
] satisfies TableColumn<FileMetadata>[]
|
||||||
}
|
}
|
||||||
emptyMessage={t('files.empty')}
|
emptyMessage={t('files.empty')}
|
||||||
@@ -628,6 +665,15 @@ function RunDetail() {
|
|||||||
onExport={handleExportLogs}
|
onExport={handleExportLogs}
|
||||||
isExporting={exportingLogs}
|
isExporting={exportingLogs}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<DeleteConfirmationModal
|
||||||
|
open={pendingDeleteFile != null}
|
||||||
|
title={t('files.deleteTitle')}
|
||||||
|
message={t('files.confirmDelete', { name: pendingDeleteFile?.name ?? '' })}
|
||||||
|
onClose={() => setPendingDeleteFile(null)}
|
||||||
|
onConfirm={handleDeleteFile}
|
||||||
|
isDeleting={deletingFile}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+2
-1
@@ -77,7 +77,8 @@ The server currently registers the following tools.
|
|||||||
| Tool | Description |
|
| Tool | Description |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `list_run_files` | List files (artifacts) created during a scenario run (paginated) |
|
| `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
|
## Binary Content Handling
|
||||||
|
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "liqa",
|
"name": "liqa",
|
||||||
"version": "1.16.1",
|
"version": "1.17.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "liqa",
|
"name": "liqa",
|
||||||
"version": "1.16.1",
|
"version": "1.17.0",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"server",
|
"server",
|
||||||
"client"
|
"client"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "liqa",
|
"name": "liqa",
|
||||||
"version": "1.16.1",
|
"version": "1.17.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"server",
|
"server",
|
||||||
|
|||||||
@@ -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(
|
server.registerTool(
|
||||||
"get_run_file_content",
|
"get_run_file_content",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -434,4 +434,17 @@ export class ScenarioController {
|
|||||||
) {
|
) {
|
||||||
return this.scenarioService.getRunFileContent(id, runId, fileId, res);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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<void> {
|
||||||
|
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(
|
async getRunFileContent(
|
||||||
scenarioId: string,
|
scenarioId: string,
|
||||||
runId: string,
|
runId: string,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Repository } from "typeorm";
|
|||||||
import { buildTestApp } from "./app.harness";
|
import { buildTestApp } from "./app.harness";
|
||||||
import { FileStorageService } from "../src/file/file-storage.service";
|
import { FileStorageService } from "../src/file/file-storage.service";
|
||||||
import { FileEntity } from "../src/file/file.entity";
|
import { FileEntity } from "../src/file/file.entity";
|
||||||
|
import { ScenarioRunFileEntity } from "../src/file/scenario-run-file.entity";
|
||||||
import { ScenarioEntity } from "../src/scenario/scenario.entity";
|
import { ScenarioEntity } from "../src/scenario/scenario.entity";
|
||||||
import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity";
|
import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity";
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ describe("File Controller Integration Tests", () => {
|
|||||||
let fileRepo: Repository<FileEntity>;
|
let fileRepo: Repository<FileEntity>;
|
||||||
let scenarioRepo: Repository<ScenarioEntity>;
|
let scenarioRepo: Repository<ScenarioEntity>;
|
||||||
let runRepo: Repository<ScenarioRunEntity>;
|
let runRepo: Repository<ScenarioRunEntity>;
|
||||||
|
let runFileRepo: Repository<ScenarioRunFileEntity>;
|
||||||
let filesDir: string;
|
let filesDir: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
@@ -27,6 +29,9 @@ describe("File Controller Integration Tests", () => {
|
|||||||
runRepo = app.get<Repository<ScenarioRunEntity>>(
|
runRepo = app.get<Repository<ScenarioRunEntity>>(
|
||||||
getRepositoryToken(ScenarioRunEntity),
|
getRepositoryToken(ScenarioRunEntity),
|
||||||
);
|
);
|
||||||
|
runFileRepo = app.get<Repository<ScenarioRunFileEntity>>(
|
||||||
|
getRepositoryToken(ScenarioRunFileEntity),
|
||||||
|
);
|
||||||
|
|
||||||
// Get the files directory from the service
|
// Get the files directory from the service
|
||||||
filesDir = fileStorageService.getAbsolutePath("");
|
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 ───────────────────────────────────────────────────────────
|
// ── File cleanup ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
describe("File cleanup", () => {
|
describe("File cleanup", () => {
|
||||||
|
|||||||
@@ -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", () => {
|
describe("get_run_file_content", () => {
|
||||||
it("returns run artifact bytes as base64 for a valid file", async () => {
|
it("returns run artifact bytes as base64 for a valid file", async () => {
|
||||||
const { sc, run } = await createRunArtifactFixture("mcp-run-file-content-test");
|
const { sc, run } = await createRunArtifactFixture("mcp-run-file-content-test");
|
||||||
|
|||||||
Reference in new issue
Block a user