From 965f262c0fdaf3cb4cbc41ee25d1e30e85c08620 Mon Sep 17 00:00:00 2001 From: Andrii Arsenin Date: Wed, 30 Sep 2026 18:55:17 +0300 Subject: [PATCH] refactor: fix lint errors across server and client - replace any types with explicit types in scenario file listing, import/export and mcp upload code - type test server addresses and list callbacks, drop unused vars - document why e2e export keeps the archiver import-require form - remove unused scenario files total state in the client - require clean lint in both packages in CLAUDE.md --- CLAUDE.md | 2 +- .../src/pages/scenario/ScenarioDetailPage.tsx | 2 -- server/src/mcp/mcp.service.ts | 4 ++-- server/src/scenario/e2e-export.service.ts | 3 +++ server/src/scenario/scenario.controller.ts | 8 +++++--- server/src/scenario/scenario.service.ts | 19 ++++++++++++++----- server/test/exec-context-files.spec.ts | 9 ++++++--- server/test/file.controller.spec.ts | 18 ++++++++---------- server/test/mcp.controller.spec.ts | 3 ++- 9 files changed, 41 insertions(+), 27 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 6903d2d..db61fe0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -41,7 +41,7 @@ cd server && npm run lint && npx tsc --noEmit -p tsconfig.json && npm test && np cd client && npm run lint && npm run build ``` -- The server lint has some pre-existing errors (e.g. `no-explicit-any` in `test/mcp.controller.spec.ts`). Don't add new ones; compare against the last commit if unsure. +- Lint must stay clean in both packages (no errors, no warnings). - Don't run prettier over whole existing files; several aren't prettier-clean and it produces unrelated diffs. Format only new files or the lines you changed. - Server tests use an in-memory DB and a Playwright mock (`server/test/__mocks__/playwright.ts`). They create `server/data/` (git-ignored). diff --git a/client/src/pages/scenario/ScenarioDetailPage.tsx b/client/src/pages/scenario/ScenarioDetailPage.tsx index 0a59090..3a9f7dc 100644 --- a/client/src/pages/scenario/ScenarioDetailPage.tsx +++ b/client/src/pages/scenario/ScenarioDetailPage.tsx @@ -99,7 +99,6 @@ export function ScenarioDetailPage() { // Files state const [files, setFiles] = useState([]); - const [filesTotal, setFilesTotal] = useState(0); const [filesLoading, setFilesLoading] = useState(false); const [uploadOpen, setUploadOpen] = useState(false); const [uploadFile, setUploadFile] = useState(null); @@ -114,7 +113,6 @@ export function ScenarioDetailPage() { try { const result = await scenarioFiles.list(id); setFiles(result.items); - setFilesTotal(result.total); } finally { setFilesLoading(false); } diff --git a/server/src/mcp/mcp.service.ts b/server/src/mcp/mcp.service.ts index cd9b424..1e0a25a 100644 --- a/server/src/mcp/mcp.service.ts +++ b/server/src/mcp/mcp.service.ts @@ -1407,12 +1407,12 @@ export class McpService { }; } - // Create a mock Multer file object for the service + // Build the subset of a Multer file object the service uses const file = { buffer, originalname: name, mimetype: mimeType || "application/octet-stream", - } as any; + }; // Call the service method const result = await this.scenarioService.uploadFile( diff --git a/server/src/scenario/e2e-export.service.ts b/server/src/scenario/e2e-export.service.ts index 6d0850c..44c65d8 100644 --- a/server/src/scenario/e2e-export.service.ts +++ b/server/src/scenario/e2e-export.service.ts @@ -1,4 +1,7 @@ import { Injectable } from "@nestjs/common"; +// archiver is a CommonJS `export =` function without a `default` export, and +// esModuleInterop is off, so TypeScript's import-require form is the one that works +// eslint-disable-next-line @typescript-eslint/no-require-imports import archiver = require("archiver"); import { resolveUsedSnippetAliases } from "../common/snippet-usage"; import { SnippetService } from "../snippet/snippet.service"; diff --git a/server/src/scenario/scenario.controller.ts b/server/src/scenario/scenario.controller.ts index 1a0d550..a3b61ee 100644 --- a/server/src/scenario/scenario.controller.ts +++ b/server/src/scenario/scenario.controller.ts @@ -25,7 +25,7 @@ import { CreateScenarioStepDto } from "./dto/create-scenario-step.dto"; import { CreateScenarioDto } from "./dto/create-scenario.dto"; import { ScenarioQueryDto } from "./dto/pagination-query.dto"; import { RunsQueryDto } from "./dto/runs-query.dto"; -import { ExportEntity } from "./dto/scenario-export.dto"; +import { ExportEntity, ScenarioExportDto } from "./dto/scenario-export.dto"; import { UpdateScenarioStepDto } from "./dto/update-scenario-step.dto"; import { UpdateScenarioDto } from "./dto/update-scenario.dto"; import { ScenarioService } from "./scenario.service"; @@ -52,7 +52,9 @@ export class ScenarioController { @ApiOperation({ summary: "Import a scenario from an export payload (single object or array)" }) @ApiResponse({ status: 201, description: "Scenario imported" }) importScenario(@Body() payload: unknown) { - return this.scenarioService.importScenario(payload as any); + return this.scenarioService.importScenario( + payload as ScenarioExportDto | ExportEntity[], + ); } @Get() @@ -157,7 +159,7 @@ export class ScenarioController { const parts = (entities as ExportEntity[]).map((entity) => { const label = kindLabels[entity.kind ?? ""] ?? entity.kind ?? "Entity"; const comment = `# --- ${label}: ${ - (entity as any).name ?? (entity as any).id ?? "" + entity.name ?? entity.id ?? "" } ---`; return `${comment}\n${yamlStringify(entity)}`; }); diff --git a/server/src/scenario/scenario.service.ts b/server/src/scenario/scenario.service.ts index 5b9ba81..5092e30 100644 --- a/server/src/scenario/scenario.service.ts +++ b/server/src/scenario/scenario.service.ts @@ -21,7 +21,10 @@ import { import type { AppConfig, TraceMode } from "../config/app.config"; import { CredentialEntity } from "../credential/credential.entity"; import { EnvironmentEntity } from "../environment/environment.entity"; -import { FileStorageService } from "../file/file-storage.service"; +import { + FileMetadata, + FileStorageService, +} from "../file/file-storage.service"; import { ScenarioFileEntity } from "../file/scenario-file.entity"; import { ScenarioRunFileEntity } from "../file/scenario-run-file.entity"; import { SnippetEntity } from "../snippet/snippet.entity"; @@ -83,6 +86,12 @@ function stepsSnapshot(steps: ScenarioStepEntity[]): ScenarioStepSnapshot[] { })); } +/** File metadata as returned by the scenario/run file listing endpoints. */ +export interface FileListResult { + items: Omit[]; + total: number; +} + export type UsedSnippet = SnippetEntity & { /** Version pinned via `runSnippet("alias@N")`, or null for the latest. */ pinnedVersion: number | null; @@ -941,9 +950,9 @@ export class ScenarioService implements OnModuleInit { async uploadFile( scenarioId: string, - file: MulterFile, + file: Pick, expiresAtStr?: string, - ): Promise { + ): Promise> { // Verify scenario exists await this.findOne(scenarioId); @@ -990,7 +999,7 @@ export class ScenarioService implements OnModuleInit { scenarioId: string, limit?: number, offset?: number, - ): Promise { + ): Promise { // Verify scenario exists await this.findOne(scenarioId); @@ -1088,7 +1097,7 @@ export class ScenarioService implements OnModuleInit { runId: string, limit?: number, offset?: number, - ): Promise { + ): Promise { // Verify scenario and run exist await this.findOne(scenarioId); const run = await this.runRepo.findOneBy({ id: runId, scenarioId }); diff --git a/server/test/exec-context-files.spec.ts b/server/test/exec-context-files.spec.ts index ae36568..237cc71 100644 --- a/server/test/exec-context-files.spec.ts +++ b/server/test/exec-context-files.spec.ts @@ -13,6 +13,7 @@ import { ScenarioStepEntity } from "../src/scenario/scenario-step.entity"; import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity"; import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity"; import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service"; +import type { AddressInfo } from "net"; describe("Exec Context File Methods Integration Tests", () => { let app: INestApplication; @@ -57,7 +58,7 @@ describe("Exec Context File Methods Integration Tests", () => { // Start a test HTTP server for downloadFile tests testServer = await createTestServer(); - testServerUrl = `http://localhost:${(testServer.address() as any).port}`; + testServerUrl = `http://localhost:${(testServer.address() as AddressInfo).port}`; }); afterAll(async () => { @@ -69,7 +70,7 @@ describe("Exec Context File Methods Integration Tests", () => { // Clean up files directory try { await fs.rm(filesDir, { recursive: true, force: true }); - } catch (err) { + } catch { // Ignore errors if directory doesn't exist } @@ -223,7 +224,9 @@ describe("Exec Context File Methods Integration Tests", () => { expect(output.total).toBeGreaterThanOrEqual(1); // Find the uploaded file in the output - const foundFile = output.items.find((f: any) => f.id === uploadedFile.id); + const foundFile = output.items.find( + (f: { id: string; name: string }) => f.id === uploadedFile.id, + ); expect(foundFile).toBeDefined(); expect(foundFile.name).toBe("test-file.txt"); expect(foundFile.mimeType).toBe("text/plain"); diff --git a/server/test/file.controller.spec.ts b/server/test/file.controller.spec.ts index daeeb6d..e6a6f0a 100644 --- a/server/test/file.controller.spec.ts +++ b/server/test/file.controller.spec.ts @@ -41,7 +41,7 @@ describe("File Controller Integration Tests", () => { // Clean up files directory try { await fs.rm(filesDir, { recursive: true, force: true }); - } catch (err) { + } catch { // Ignore errors if directory doesn't exist } await app.close(); @@ -151,7 +151,9 @@ describe("File Controller Integration Tests", () => { expect(res.body.items.length).toBeGreaterThanOrEqual(1); expect(res.body.total).toBeGreaterThanOrEqual(1); - const file = res.body.items.find((f: any) => f.name === "listed.txt"); + const file = res.body.items.find( + (f: { id: string; name: string }) => f.name === "listed.txt", + ); expect(file).toBeDefined(); expect(file.id).toBeDefined(); expect(file.mimeType).toBe("text/plain"); @@ -279,7 +281,9 @@ describe("File Controller Integration Tests", () => { expect(Array.isArray(res.body.items)).toBe(true); expect(res.body.total).toBeGreaterThanOrEqual(1); - const artifact = res.body.items.find((f: any) => f.id === savedFile.id); + const artifact = res.body.items.find( + (f: { id: string; name: string; size: number }) => f.id === savedFile.id, + ); expect(artifact).toBeDefined(); expect(artifact.name).toBe("artifact.txt"); expect(artifact.size).toBe(fileBuffer.length); @@ -417,8 +421,6 @@ describe("File Controller Integration Tests", () => { describe("File cleanup", () => { it("removes expired files from disk and database", async () => { - const scenario = await createScenario("cleanup-test"); - // Upload a file with a past expiration date const fileBuffer = Buffer.from("to be cleaned up"); const savedFile = await fileStorageService.saveFile( @@ -445,13 +447,11 @@ describe("File Controller Integration Tests", () => { fail("File should have been deleted"); } catch (err) { // Expected: file not found - expect((err as any).code).toBe("ENOENT"); + expect((err as NodeJS.ErrnoException).code).toBe("ENOENT"); } }); it("does not delete files with future expiration dates", async () => { - const scenario = await createScenario("no-cleanup-test"); - // Upload a file with a future expiration date const fileBuffer = Buffer.from("should not be cleaned"); const futureDate = new Date(Date.now() + 24 * 60 * 60 * 1000); @@ -475,8 +475,6 @@ describe("File Controller Integration Tests", () => { }); it("does not delete files without expiration dates", async () => { - const scenario = await createScenario("no-expire-test"); - // Upload a file without expiration const fileBuffer = Buffer.from("permanent file"); const savedFile = await fileStorageService.saveFile( diff --git a/server/test/mcp.controller.spec.ts b/server/test/mcp.controller.spec.ts index eb47f00..fe56b8b 100644 --- a/server/test/mcp.controller.spec.ts +++ b/server/test/mcp.controller.spec.ts @@ -9,6 +9,7 @@ import { ScenarioStepEntity } from "../src/scenario/scenario-step.entity"; import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity"; import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity"; import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service"; +import type { AddressInfo } from "net"; /** * MCP controller integration tests. @@ -50,7 +51,7 @@ describe("McpController", () => { // Start a test HTTP server for downloadFile tests testServer = await createTestServer(); - testServerUrl = `http://localhost:${(testServer.address() as any).port}`; + testServerUrl = `http://localhost:${(testServer.address() as AddressInfo).port}`; }); afterAll(async () => {