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
This commit is contained in:
ars9 committed 2026-09-30 18:55:17 +03:00
1 parent 1c5c906cbb
commit cf56840df9
9 files changed
+41 -27

No files matched your search

+1 -1
View File
@@ -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 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. - 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). - Server tests use an in-memory DB and a Playwright mock (`server/test/__mocks__/playwright.ts`). They create `server/data/` (git-ignored).
@@ -99,7 +99,6 @@ export function ScenarioDetailPage() {
// Files state // Files state
const [files, setFiles] = useState<FileMetadata[]>([]); const [files, setFiles] = useState<FileMetadata[]>([]);
const [filesTotal, setFilesTotal] = useState(0);
const [filesLoading, setFilesLoading] = useState(false); const [filesLoading, setFilesLoading] = useState(false);
const [uploadOpen, setUploadOpen] = useState(false); const [uploadOpen, setUploadOpen] = useState(false);
const [uploadFile, setUploadFile] = useState<File | null>(null); const [uploadFile, setUploadFile] = useState<File | null>(null);
@@ -114,7 +113,6 @@ export function ScenarioDetailPage() {
try { try {
const result = await scenarioFiles.list(id); const result = await scenarioFiles.list(id);
setFiles(result.items); setFiles(result.items);
setFilesTotal(result.total);
} finally { } finally {
setFilesLoading(false); setFilesLoading(false);
} }
+2 -2
View File
@@ -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 = { const file = {
buffer, buffer,
originalname: name, originalname: name,
mimetype: mimeType || "application/octet-stream", mimetype: mimeType || "application/octet-stream",
} as any; };
// Call the service method // Call the service method
const result = await this.scenarioService.uploadFile( const result = await this.scenarioService.uploadFile(
@@ -1,4 +1,7 @@
import { Injectable } from "@nestjs/common"; 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 archiver = require("archiver");
import { resolveUsedSnippetAliases } from "../common/snippet-usage"; import { resolveUsedSnippetAliases } from "../common/snippet-usage";
import { SnippetService } from "../snippet/snippet.service"; import { SnippetService } from "../snippet/snippet.service";
+5 -3
View File
@@ -25,7 +25,7 @@ import { CreateScenarioStepDto } from "./dto/create-scenario-step.dto";
import { CreateScenarioDto } from "./dto/create-scenario.dto"; import { CreateScenarioDto } from "./dto/create-scenario.dto";
import { ScenarioQueryDto } from "./dto/pagination-query.dto"; import { ScenarioQueryDto } from "./dto/pagination-query.dto";
import { RunsQueryDto } from "./dto/runs-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 { UpdateScenarioStepDto } from "./dto/update-scenario-step.dto";
import { UpdateScenarioDto } from "./dto/update-scenario.dto"; import { UpdateScenarioDto } from "./dto/update-scenario.dto";
import { ScenarioService } from "./scenario.service"; 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)" }) @ApiOperation({ summary: "Import a scenario from an export payload (single object or array)" })
@ApiResponse({ status: 201, description: "Scenario imported" }) @ApiResponse({ status: 201, description: "Scenario imported" })
importScenario(@Body() payload: unknown) { importScenario(@Body() payload: unknown) {
return this.scenarioService.importScenario(payload as any); return this.scenarioService.importScenario(
payload as ScenarioExportDto | ExportEntity[],
);
} }
@Get() @Get()
@@ -157,7 +159,7 @@ export class ScenarioController {
const parts = (entities as ExportEntity[]).map((entity) => { const parts = (entities as ExportEntity[]).map((entity) => {
const label = kindLabels[entity.kind ?? ""] ?? entity.kind ?? "Entity"; const label = kindLabels[entity.kind ?? ""] ?? entity.kind ?? "Entity";
const comment = `# --- ${label}: ${ const comment = `# --- ${label}: ${
(entity as any).name ?? (entity as any).id ?? "" entity.name ?? entity.id ?? ""
} ---`; } ---`;
return `${comment}\n${yamlStringify(entity)}`; return `${comment}\n${yamlStringify(entity)}`;
}); });
+14 -5
View File
@@ -21,7 +21,10 @@ import {
import type { AppConfig, TraceMode } from "../config/app.config"; import type { AppConfig, TraceMode } from "../config/app.config";
import { CredentialEntity } from "../credential/credential.entity"; import { CredentialEntity } from "../credential/credential.entity";
import { EnvironmentEntity } from "../environment/environment.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 { ScenarioFileEntity } from "../file/scenario-file.entity";
import { ScenarioRunFileEntity } from "../file/scenario-run-file.entity"; import { ScenarioRunFileEntity } from "../file/scenario-run-file.entity";
import { SnippetEntity } from "../snippet/snippet.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<FileMetadata, "path">[];
total: number;
}
export type UsedSnippet = SnippetEntity & { export type UsedSnippet = SnippetEntity & {
/** Version pinned via `runSnippet("alias@N")`, or null for the latest. */ /** Version pinned via `runSnippet("alias@N")`, or null for the latest. */
pinnedVersion: number | null; pinnedVersion: number | null;
@@ -941,9 +950,9 @@ export class ScenarioService implements OnModuleInit {
async uploadFile( async uploadFile(
scenarioId: string, scenarioId: string,
file: MulterFile, file: Pick<MulterFile, "buffer" | "originalname" | "mimetype">,
expiresAtStr?: string, expiresAtStr?: string,
): Promise<any> { ): Promise<Omit<FileMetadata, "path" | "sha256">> {
// Verify scenario exists // Verify scenario exists
await this.findOne(scenarioId); await this.findOne(scenarioId);
@@ -990,7 +999,7 @@ export class ScenarioService implements OnModuleInit {
scenarioId: string, scenarioId: string,
limit?: number, limit?: number,
offset?: number, offset?: number,
): Promise<any> { ): Promise<FileListResult> {
// Verify scenario exists // Verify scenario exists
await this.findOne(scenarioId); await this.findOne(scenarioId);
@@ -1088,7 +1097,7 @@ export class ScenarioService implements OnModuleInit {
runId: string, runId: string,
limit?: number, limit?: number,
offset?: number, offset?: number,
): Promise<any> { ): Promise<FileListResult> {
// Verify scenario and run exist // Verify scenario and run exist
await this.findOne(scenarioId); await this.findOne(scenarioId);
const run = await this.runRepo.findOneBy({ id: runId, scenarioId }); const run = await this.runRepo.findOneBy({ id: runId, scenarioId });
+6 -3
View File
@@ -13,6 +13,7 @@ import { ScenarioStepEntity } from "../src/scenario/scenario-step.entity";
import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity"; import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity";
import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity"; import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity";
import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service"; import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service";
import type { AddressInfo } from "net";
describe("Exec Context File Methods Integration Tests", () => { describe("Exec Context File Methods Integration Tests", () => {
let app: INestApplication; let app: INestApplication;
@@ -57,7 +58,7 @@ describe("Exec Context File Methods Integration Tests", () => {
// Start a test HTTP server for downloadFile tests // Start a test HTTP server for downloadFile tests
testServer = await createTestServer(); testServer = await createTestServer();
testServerUrl = `http://localhost:${(testServer.address() as any).port}`; testServerUrl = `http://localhost:${(testServer.address() as AddressInfo).port}`;
}); });
afterAll(async () => { afterAll(async () => {
@@ -69,7 +70,7 @@ describe("Exec Context File Methods Integration Tests", () => {
// Clean up files directory // Clean up files directory
try { try {
await fs.rm(filesDir, { recursive: true, force: true }); await fs.rm(filesDir, { recursive: true, force: true });
} catch (err) { } catch {
// Ignore errors if directory doesn't exist // Ignore errors if directory doesn't exist
} }
@@ -223,7 +224,9 @@ describe("Exec Context File Methods Integration Tests", () => {
expect(output.total).toBeGreaterThanOrEqual(1); expect(output.total).toBeGreaterThanOrEqual(1);
// Find the uploaded file in the output // 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).toBeDefined();
expect(foundFile.name).toBe("test-file.txt"); expect(foundFile.name).toBe("test-file.txt");
expect(foundFile.mimeType).toBe("text/plain"); expect(foundFile.mimeType).toBe("text/plain");
+8 -10
View File
@@ -41,7 +41,7 @@ describe("File Controller Integration Tests", () => {
// Clean up files directory // Clean up files directory
try { try {
await fs.rm(filesDir, { recursive: true, force: true }); await fs.rm(filesDir, { recursive: true, force: true });
} catch (err) { } catch {
// Ignore errors if directory doesn't exist // Ignore errors if directory doesn't exist
} }
await app.close(); await app.close();
@@ -151,7 +151,9 @@ describe("File Controller Integration Tests", () => {
expect(res.body.items.length).toBeGreaterThanOrEqual(1); expect(res.body.items.length).toBeGreaterThanOrEqual(1);
expect(res.body.total).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).toBeDefined();
expect(file.id).toBeDefined(); expect(file.id).toBeDefined();
expect(file.mimeType).toBe("text/plain"); expect(file.mimeType).toBe("text/plain");
@@ -279,7 +281,9 @@ describe("File Controller Integration Tests", () => {
expect(Array.isArray(res.body.items)).toBe(true); expect(Array.isArray(res.body.items)).toBe(true);
expect(res.body.total).toBeGreaterThanOrEqual(1); 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).toBeDefined();
expect(artifact.name).toBe("artifact.txt"); expect(artifact.name).toBe("artifact.txt");
expect(artifact.size).toBe(fileBuffer.length); expect(artifact.size).toBe(fileBuffer.length);
@@ -417,8 +421,6 @@ describe("File Controller Integration Tests", () => {
describe("File cleanup", () => { describe("File cleanup", () => {
it("removes expired files from disk and database", async () => { it("removes expired files from disk and database", async () => {
const scenario = await createScenario("cleanup-test");
// Upload a file with a past expiration date // Upload a file with a past expiration date
const fileBuffer = Buffer.from("to be cleaned up"); const fileBuffer = Buffer.from("to be cleaned up");
const savedFile = await fileStorageService.saveFile( const savedFile = await fileStorageService.saveFile(
@@ -445,13 +447,11 @@ describe("File Controller Integration Tests", () => {
fail("File should have been deleted"); fail("File should have been deleted");
} catch (err) { } catch (err) {
// Expected: file not found // 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 () => { 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 // Upload a file with a future expiration date
const fileBuffer = Buffer.from("should not be cleaned"); const fileBuffer = Buffer.from("should not be cleaned");
const futureDate = new Date(Date.now() + 24 * 60 * 60 * 1000); 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 () => { it("does not delete files without expiration dates", async () => {
const scenario = await createScenario("no-expire-test");
// Upload a file without expiration // Upload a file without expiration
const fileBuffer = Buffer.from("permanent file"); const fileBuffer = Buffer.from("permanent file");
const savedFile = await fileStorageService.saveFile( const savedFile = await fileStorageService.saveFile(
+2 -1
View File
@@ -9,6 +9,7 @@ import { ScenarioStepEntity } from "../src/scenario/scenario-step.entity";
import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity"; import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity";
import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity"; import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity";
import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service"; import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service";
import type { AddressInfo } from "net";
/** /**
* MCP controller integration tests. * MCP controller integration tests.
@@ -50,7 +51,7 @@ describe("McpController", () => {
// Start a test HTTP server for downloadFile tests // Start a test HTTP server for downloadFile tests
testServer = await createTestServer(); testServer = await createTestServer();
testServerUrl = `http://localhost:${(testServer.address() as any).port}`; testServerUrl = `http://localhost:${(testServer.address() as AddressInfo).port}`;
}); });
afterAll(async () => { afterAll(async () => {