Disallow redundant typecasts. (#15030)

This commit is contained in:
Christian Gunderman
2025-12-12 17:43:43 -08:00
committed by GitHub
parent fcc3b2b5ec
commit 942bcfc61e
86 changed files with 235 additions and 371 deletions
@@ -519,7 +519,7 @@ export class LoopDetectionService {
signal: AbortSignal,
): Promise<Record<string, unknown> | null> {
try {
const result = (await this.config.getBaseLlmClient().generateJson({
const result = await this.config.getBaseLlmClient().generateJson({
modelConfigKey: { model },
contents,
schema: LOOP_DETECTION_SCHEMA,
@@ -527,7 +527,7 @@ export class LoopDetectionService {
abortSignal: signal,
promptId: this.promptId,
maxAttempts: 2,
})) as Record<string, unknown>;
});
if (
result &&
@@ -258,10 +258,7 @@ export class ModelConfigService {
// TODO(joshualitt): Consider knobs here, i.e. opt-in to deep merging
// arrays on a case-by-case basis.
if (this.isObject(accValue) && this.isObject(objValue)) {
acc[key] = this.deepMerge(
accValue as Record<string, unknown>,
objValue as Record<string, unknown>,
);
acc[key] = this.deepMerge(accValue, objValue);
} else {
acc[key] = objValue;
}
@@ -36,10 +36,9 @@ vi.mock('@lydell/node-pty', () => ({
spawn: mockPtySpawn,
}));
vi.mock('node:child_process', async (importOriginal) => {
const actual =
(await importOriginal()) as typeof import('node:child_process');
const actual = await importOriginal();
return {
...actual,
...(actual as object),
spawn: mockCpSpawn,
};
});
@@ -90,7 +89,7 @@ const createMockSerializeTerminalToObjectReturnValue = (
text: string | string[],
): AnsiOutput => {
const lines = Array.isArray(text) ? text : text.split('\n');
const len = (shellExecutionConfig.terminalHeight ?? 24) as number;
const len = shellExecutionConfig.terminalHeight ?? 24;
const expected: AnsiOutput = Array.from({ length: len }, (_, i) => [
{
text: (lines[i] || '').trim(),
@@ -108,7 +107,7 @@ const createMockSerializeTerminalToObjectReturnValue = (
const createExpectedAnsiOutput = (text: string | string[]): AnsiOutput => {
const lines = Array.isArray(text) ? text : text.split('\n');
const len = (shellExecutionConfig.terminalHeight ?? 24) as number;
const len = shellExecutionConfig.terminalHeight ?? 24;
const expected: AnsiOutput = Array.from({ length: len }, (_, i) => [
{
text: expect.stringMatching((lines[i] || '').trim()),
@@ -419,7 +418,7 @@ describe('ShellExecutionService', () => {
it('should write to the pty and trigger a render', async () => {
vi.useFakeTimers();
await simulateExecution('interactive-app', (pty) => {
ShellExecutionService.writeToPty(pty.pid!, 'input');
ShellExecutionService.writeToPty(pty.pid, 'input');
pty.onExit.mock.calls[0][0]({ exitCode: 0, signal: null });
});
@@ -434,7 +433,7 @@ describe('ShellExecutionService', () => {
it('should resize the pty and the headless terminal', async () => {
await simulateExecution('ls -l', (pty) => {
pty.onData.mock.calls[0][0]('file1.txt\n');
ShellExecutionService.resizePty(pty.pid!, 100, 40);
ShellExecutionService.resizePty(pty.pid, 100, 40);
pty.onExit.mock.calls[0][0]({ exitCode: 0, signal: null });
});
@@ -448,7 +447,7 @@ describe('ShellExecutionService', () => {
.mockReturnValue(false);
await simulateExecution('ls -l', (pty) => {
ShellExecutionService.resizePty(pty.pid!, 100, 40);
ShellExecutionService.resizePty(pty.pid, 100, 40);
pty.onExit.mock.calls[0][0]({ exitCode: 0, signal: null });
});
@@ -468,7 +467,7 @@ describe('ShellExecutionService', () => {
// We don't expect this test to throw an error
await expect(
simulateExecution('ls -l', (pty) => {
ShellExecutionService.resizePty(pty.pid!, 100, 40);
ShellExecutionService.resizePty(pty.pid, 100, 40);
pty.onExit.mock.calls[0][0]({ exitCode: 0, signal: null });
}),
).resolves.not.toThrow();
@@ -484,7 +483,7 @@ describe('ShellExecutionService', () => {
await expect(
simulateExecution('ls -l', (pty) => {
ShellExecutionService.resizePty(pty.pid!, 100, 40);
ShellExecutionService.resizePty(pty.pid, 100, 40);
pty.onExit.mock.calls[0][0]({ exitCode: 0, signal: null });
}),
).rejects.toThrow('Some other error');
@@ -493,7 +492,7 @@ describe('ShellExecutionService', () => {
it('should scroll the headless terminal', async () => {
await simulateExecution('ls -l', (pty) => {
pty.onData.mock.calls[0][0]('file1.txt\n');
ShellExecutionService.scrollPty(pty.pid!, 10);
ShellExecutionService.scrollPty(pty.pid, 10);
pty.onExit.mock.calls[0][0]({ exitCode: 0, signal: null });
});
@@ -715,9 +715,7 @@ export class ShellExecutionService {
error,
aborted: abortSignal.aborted,
pid: ptyProcess.pid,
executionMethod:
(ptyInfo?.name as 'node-pty' | 'lydell-node-pty') ??
'node-pty',
executionMethod: ptyInfo?.name ?? 'node-pty',
});
};