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

+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 = {
buffer,
originalname: name,
mimetype: mimeType || "application/octet-stream",
} as any;
};
// Call the service method
const result = await this.scenarioService.uploadFile(
@@ -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";
+5 -3
View File
@@ -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)}`;
});
+14 -5
View File
@@ -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<FileMetadata, "path">[];
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<MulterFile, "buffer" | "originalname" | "mimetype">,
expiresAtStr?: string,
): Promise<any> {
): Promise<Omit<FileMetadata, "path" | "sha256">> {
// Verify scenario exists
await this.findOne(scenarioId);
@@ -990,7 +999,7 @@ export class ScenarioService implements OnModuleInit {
scenarioId: string,
limit?: number,
offset?: number,
): Promise<any> {
): Promise<FileListResult> {
// Verify scenario exists
await this.findOne(scenarioId);
@@ -1088,7 +1097,7 @@ export class ScenarioService implements OnModuleInit {
runId: string,
limit?: number,
offset?: number,
): Promise<any> {
): Promise<FileListResult> {
// Verify scenario and run exist
await this.findOne(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 { 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");
+8 -10
View File
@@ -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(
+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 { 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 () => {