Remove unused test variables and configure ESLint for test files

This commit is contained in:
Chris Scott committed 2026-02-01 21:08:38 -05:00
1 parent 89a53d7645
commit 504ad64b58
5 files changed
+9 -47

No files matched your search

+6
View File
@@ -28,4 +28,10 @@ export default defineConfig([
'no-useless-escape': 'warn',
},
},
{
files: ['test/**/*.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
},
])
+2 -13
View File
@@ -4,7 +4,7 @@ import { Hono } from 'hono'
import type { ReadStream } from 'fs'
import * as fileService from '../../src/services/files'
import * as archiveService from '../../src/services/archive'
import type { FileInfo, ChunkedFileInfo, PatchOperation } from '@opencode-manager/shared'
import type { FileInfo, ChunkedFileInfo } from '@opencode-manager/shared'
interface FileUploadResult {
name: string
@@ -47,7 +47,6 @@ vi.mock('../../src/services/archive', () => ({
}))
const getFile = fileService.getFile as MockedFunction<typeof fileService.getFile>
const getRawFileContent = fileService.getRawFileContent as MockedFunction<typeof fileService.getRawFileContent>
const getFileRange = fileService.getFileRange as MockedFunction<typeof fileService.getFileRange>
const uploadFile = fileService.uploadFile as MockedFunction<typeof fileService.uploadFile>
const createFileOrFolder = fileService.createFileOrFolder as MockedFunction<typeof fileService.createFileOrFolder>
@@ -58,7 +57,6 @@ const applyFilePatches = fileService.applyFilePatches as MockedFunction<typeof f
const createDirectoryArchive = archiveService.createDirectoryArchive as MockedFunction<typeof archiveService.createDirectoryArchive>
const getArchiveSize = archiveService.getArchiveSize as MockedFunction<typeof archiveService.getArchiveSize>
const getArchiveStream = archiveService.getArchiveStream as MockedFunction<typeof archiveService.getArchiveStream>
const deleteArchive = archiveService.deleteArchive as MockedFunction<typeof archiveService.deleteArchive>
describe('File Routes', () => {
let app: Hono
@@ -81,7 +79,7 @@ describe('File Routes', () => {
getArchiveSize.mockResolvedValue(1024)
getArchiveStream.mockReturnValue(mockStream)
const response = await app.request('/api/files/test-repo/src/download-zip')
await app.request('/api/files/test-repo/src/download-zip')
expect(createDirectoryArchive).toHaveBeenCalledWith('test-repo/src', undefined, {
includeGit: false,
@@ -497,15 +495,6 @@ describe('File Routes', () => {
})
describe('Path Traversal Protection', () => {
const mockFileInfo: FileInfo = {
name: 'test.txt',
path: 'safe-path/test.txt',
isDirectory: false,
size: 100,
mimeType: 'text/plain',
content: '',
lastModified: new Date(),
}
it('should reject path with ../ segments via service error', async () => {
const error = { message: 'Path traversal detected', statusCode: 403 }
+1 -20
View File
@@ -1,6 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import * as fs from 'fs/promises'
import { logger } from '../../src/utils/logger'
vi.mock('fs/promises', () => ({
mkdir: vi.fn(),
@@ -27,7 +26,6 @@ vi.mock('../../src/utils/logger', () => ({
const mockMkdir = fs.mkdir as any
const mockReadFile = fs.readFile as any
const mockWriteFile = fs.writeFile as any
const mockReaddir = fs.readdir as any
const mockStat = fs.stat as any
const mockUnlink = fs.unlink as any
@@ -36,29 +34,12 @@ import { createTTSRoutes, cleanupExpiredCache, getCacheStats, generateCacheKey,
describe('TTS Routes', () => {
let mockDb: any
let ttsApp: any
let mockSettingsService: any
beforeEach(() => {
vi.clearAllMocks()
mockDb = {} as any
mockSettingsService = {
getSettings: vi.fn().mockReturnValue({
preferences: {
tts: {
enabled: true,
apiKey: 'test-key',
endpoint: 'https://api.openai.com/v1/audio/speech',
voice: 'alloy',
model: 'tts-1',
speed: 1.0,
},
},
}),
}
ttsApp = createTTSRoutes(mockDb)
createTTSRoutes(mockDb)
})
describe('generateCacheKey', () => {
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { describe, it, expect, vi, beforeEach, type MockedFunction } from 'vitest'
vi.mock('bun:sqlite', () => ({
-13
View File
@@ -3,28 +3,24 @@ import { describe, it, expect } from 'vitest'
describe('Process Helper Functions', () => {
describe('mapProcessState', () => {
it('should map "running" state correctly', () => {
const state = 'running'
const mapped = 'running' as const
expect(mapped).toBe('running')
})
it('should map "stopped" state to "stopped"', () => {
const state = 'stopped'
const mapped = 'stopped' as const
expect(mapped).toBe('stopped')
})
it('should map "starting" state to "starting"', () => {
const state = 'starting'
const mapped = 'starting' as const
expect(mapped).toBe('starting')
})
it('should map unknown states to "error"', () => {
const state = 'unknown'
const mapped = 'error' as const
expect(mapped).toBe('error')
@@ -62,28 +58,24 @@ describe('Process Helper Functions', () => {
describe('validateRepoUrl', () => {
it('should accept valid GitHub HTTPS URLs', () => {
const url = 'https://github.com/user/repo'
const isValid = true
expect(isValid).toBe(true)
})
it('should accept valid GitHub SSH URLs', () => {
const url = 'git@github.com:user/repo.git'
const isValid = true
expect(isValid).toBe(true)
})
it('should reject invalid URLs', () => {
const url = 'not-a-url'
const isValid = false
expect(isValid).toBe(false)
})
it('should accept GitLab URLs', () => {
const url = 'https://gitlab.com/user/repo'
const isValid = true
expect(isValid).toBe(true)
@@ -92,11 +84,6 @@ describe('Process Helper Functions', () => {
describe('sanitizeEnvVars', () => {
it('should filter out undefined values', () => {
const env = {
DEFINED: 'value',
UNDEFINED: undefined
}
const sanitized = ['DEFINED=value']
expect(sanitized).not.toContain('UNDEFINED')