mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
chore(lint): replace ESLint with Oxlint and clear anti-slop findings
This commit is contained in:
1 parent
c6c13335e5
commit
b625acfc0c
1083 files changed
+67089
-80136
No files matched your search
@@ -1,17 +1,14 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { applyTestEnv } from '../helpers/test-env'
|
||||
import { executeCommand } from '../../src/utils/process'
|
||||
import { logger } from '../../src/utils/logger'
|
||||
import { expectLoggedMessage, testLogEntries } from '../helpers/log-assertions'
|
||||
|
||||
describe('executeCommand signal handling', () => {
|
||||
it('reports a signal-terminated child as a non-zero exit code when exit codes are ignored', async () => {
|
||||
const result = await executeCommand(['sh', '-c', 'kill -KILL $$'], {
|
||||
ignoreExitCode: true,
|
||||
silent: true,
|
||||
})
|
||||
const structured = typeof result === 'string' ? { exitCode: 0, stdout: result, stderr: '' } : result
|
||||
const result = await executeCommand(['sh', '-c', 'kill -KILL $$'], { ignoreExitCode: true, silent: true } as const)
|
||||
|
||||
expect(structured.exitCode).not.toBe(0)
|
||||
expect(structured.stderr).toContain('Command terminated by signal SIGKILL')
|
||||
expect(result.exitCode).not.toBe(0)
|
||||
expect(result.stderr).toContain('Command terminated by signal SIGKILL')
|
||||
})
|
||||
|
||||
it('rejects a signal-terminated child when exit codes are enforced', async () => {
|
||||
@@ -21,7 +18,7 @@ describe('executeCommand signal handling', () => {
|
||||
})
|
||||
|
||||
it('resolves a zero exit code as success when exit codes are ignored', async () => {
|
||||
const result = await executeCommand(['sh', '-c', 'true'], { ignoreExitCode: true, silent: true })
|
||||
const result = await executeCommand(['sh', '-c', 'true'], { ignoreExitCode: true, silent: true } as const)
|
||||
|
||||
expect(result).toEqual({ exitCode: 0, stdout: '', stderr: '' })
|
||||
})
|
||||
@@ -32,14 +29,13 @@ describe('executeCommand signal handling', () => {
|
||||
{ maxOutputChars: 100, silent: true },
|
||||
)
|
||||
|
||||
expect(typeof result).toBe('string')
|
||||
expect(result).toHaveLength(100)
|
||||
})
|
||||
|
||||
it('flags truncated output on the structured result when exit codes are ignored', async () => {
|
||||
const result = await executeCommand(
|
||||
['sh', '-c', 'i=0; while [ $i -lt 1000 ]; do printf "0123456789"; i=$((i+1)); done'],
|
||||
{ maxOutputChars: 100, silent: true, ignoreExitCode: true },
|
||||
{ maxOutputChars: 100, silent: true, ignoreExitCode: true } as const,
|
||||
)
|
||||
|
||||
expect(result.truncated).toBe(true)
|
||||
@@ -52,20 +48,25 @@ describe('executeCommand signal handling', () => {
|
||||
expect(result).toBe('hello')
|
||||
})
|
||||
|
||||
it('logs a git command as one debug line and never at info level', async () => {
|
||||
const infoSpy = vi.spyOn(logger, 'info').mockImplementation(() => {})
|
||||
const debugSpy = vi.spyOn(logger, 'debug').mockImplementation(() => {})
|
||||
|
||||
it('logs only a git command at debug level', async () => {
|
||||
const restoreEnv = applyTestEnv({ DEBUG: '1' })
|
||||
try {
|
||||
await executeCommand(['git', '--version'], { silent: true })
|
||||
await executeCommand(['sh', '-c', 'true'], { silent: true })
|
||||
|
||||
expect(infoSpy).not.toHaveBeenCalled()
|
||||
expect(debugSpy).toHaveBeenCalledTimes(1)
|
||||
expect(debugSpy.mock.calls[0]).toHaveLength(1)
|
||||
expect(debugSpy.mock.calls[0]?.[0]).toContain('git --version')
|
||||
const debugEntries = testLogEntries('debug')
|
||||
expect(debugEntries).toHaveLength(1)
|
||||
expect(debugEntries[0]?.message).toContain('git --version')
|
||||
expect(testLogEntries().map((entry) => entry.level)).toEqual(['debug'])
|
||||
} finally {
|
||||
infoSpy.mockRestore()
|
||||
debugSpy.mockRestore()
|
||||
restoreEnv()
|
||||
}
|
||||
})
|
||||
|
||||
it('logs a failing command at error level', async () => {
|
||||
await expect(executeCommand(['sh', '-c', 'exit 3'])).rejects.toThrow('Command failed')
|
||||
|
||||
expectLoggedMessage('Command failed', 'error')
|
||||
expect(testLogEntries().map((entry) => entry.level)).toEqual(['error'])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user