Skip to content

Commit e5b2165

Browse files
committed
fix typecheck failed
1 parent fec8931 commit e5b2165

20 files changed

Lines changed: 269 additions & 129 deletions

packages/codingcode/src/client/http.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { createHttpClients } from './http/index.js';
44

55
export type { AgentClient, StreamChunk } from './types.js';
66
export { createHttpClients } from './http/index.js';
7-
export type { HttpClients, AgentRuntimeClient, SessionClient, ModelClient, SettingsClient } from './http/index.js';
7+
export type {
8+
HttpClients,
9+
AgentRuntimeClient,
10+
SessionClient,
11+
ModelClient,
12+
SettingsClient,
13+
} from './http/index.js';
814

915
export async function createHttpClient(serverUrl: string): Promise<AgentClient> {
1016
let currentSessionId: string | undefined;

packages/codingcode/src/memory/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function enforceMaxBytes(content: string, maxBytes: number): string {
6969
}
7070

7171
const sections = content.split(/^### /m).filter(Boolean);
72-
const namedSections = sections.map((s) => {
72+
const namedSections = sections.map((s) => {
7373
const lines = s.split('\n');
7474
const name = lines[0]!;
7575
const body = lines.slice(1).join('\n');

packages/codingcode/test/agent/agent-concurrent.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,18 @@ describe('runReActLoop 锟?concurrent tool execution', () => {
127127
toolCalls,
128128
(tc: any) =>
129129
mockExecutor.execute(tc.name, tc.arguments ?? {}).pipe(
130-
Effect.matchEffect({
131-
onSuccess: (output) =>
130+
(Effect.matchEffect as any)({
131+
onSuccess: (output: any) =>
132132
Effect.succeed({ type: 'ok' as const, id: tc.id, name: tc.name, output }),
133-
onFailure: (err) =>
133+
onFailure: (err: any) =>
134134
Effect.succeed({
135135
type: 'error' as const,
136136
id: tc.id,
137137
name: tc.name,
138138
output: String(err),
139139
}),
140140
}),
141-
Effect.catchAllDefect((defect) =>
141+
(Effect.catchAllDefect as any)((defect: any) =>
142142
Effect.succeed({
143143
type: 'error' as const,
144144
id: tc.id,
@@ -196,18 +196,18 @@ describe('runReActLoop 锟?concurrent tool execution', () => {
196196
toolCalls,
197197
(tc: any) =>
198198
mockExecutor.execute(tc.name, tc.arguments ?? {}).pipe(
199-
Effect.matchEffect({
200-
onSuccess: (output) =>
199+
(Effect.matchEffect as any)({
200+
onSuccess: (output: any) =>
201201
Effect.succeed({ type: 'ok' as const, id: tc.id, name: tc.name, output }),
202-
onFailure: (err) =>
202+
onFailure: (err: any) =>
203203
Effect.succeed({
204204
type: 'error' as const,
205205
id: tc.id,
206206
name: tc.name,
207207
output: String(err),
208208
}),
209209
}),
210-
Effect.catchAllDefect((defect) =>
210+
(Effect.catchAllDefect as any)((defect: any) =>
211211
Effect.succeed({
212212
type: 'error' as const,
213213
id: tc.id,

packages/codingcode/test/context/context.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,27 @@ const mockState = {
2424
};
2525

2626
const mockLlm = {
27-
modelInfo: { maxTokens: 1000, model: 'test-model' },
28-
complete: () => Promise.resolve(Result.ok({ content: 'Hello world', finishReason: 'stop' })),
27+
modelInfo: {
28+
provider: 'mock',
29+
model: 'test-model',
30+
maxTokens: 1000,
31+
supportsToolCalling: true,
32+
supportsStreaming: true,
33+
},
34+
complete: () =>
35+
Promise.resolve(Result.ok({ content: 'Hello world', finishReason: 'stop' as const })),
2936
completeStream: (_params: any) => {
3037
const stream = (async function* () {
3138
yield 'Hello';
3239
yield ' ';
3340
yield 'world';
3441
})();
35-
return { stream, response: Promise.resolve(Result.ok({ content: 'Hello world', finishReason: 'stop' })) };
42+
return {
43+
stream,
44+
response: Promise.resolve(
45+
Result.ok({ content: 'Hello world', finishReason: 'stop' as const })
46+
),
47+
};
3648
},
3749
};
3850

@@ -122,9 +134,9 @@ function makeMockSessionLayer(state: any) {
122134
getSessionId: () => state.sessionId,
123135
getMessageCount: () => 0,
124136
incrementTurn: () => 0,
125-
findSessionIndex: () => Effect.succeed(null),
126-
} as any)
127-
);
137+
findSessionIndex: () => Effect.succeed(null),
138+
} as any)
139+
);
128140
}
129141

130142
describe('ContextService', () => {

packages/codingcode/test/context/organizer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe('pruneByTokens', () => {
267267
];
268268
const result = pruneByTokens(events, baseConfig, 100);
269269
// Summary should remain
270-
expect(result[0].type).toBe('summary');
270+
expect(result[0]!.type).toBe('summary');
271271
expect((result[0] as any).summaryText).toBe('Summary text');
272272
// Oldest tool results cleared
273273
expect((result[3] as ToolResultEvent).output).toBe('[Old tool result content cleared]');

packages/codingcode/test/hooks/config.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ describe('writeHookConfigs', () => {
4444
]);
4545
const result = loadHookConfigs(testDir);
4646
expect(result).toHaveLength(1);
47-
expect(result[0].name).toBe('test-hook');
48-
expect(result[0].point).toBe('session.save.before');
49-
expect(result[0].type).toBe('observer');
47+
expect(result[0]!.name).toBe('test-hook');
48+
expect(result[0]!.point).toBe('session.save.before');
49+
expect(result[0]!.type).toBe('observer');
5050
});
5151

5252
it('should overwrite existing hooks', () => {
@@ -58,8 +58,8 @@ describe('writeHookConfigs', () => {
5858
]);
5959
const result = loadHookConfigs(testDir);
6060
expect(result).toHaveLength(1);
61-
expect(result[0].name).toBe('new');
62-
expect(result[0].enabled).toBe(false);
61+
expect(result[0]!.name).toBe('new');
62+
expect(result[0]!.enabled).toBe(false);
6363
});
6464

6565
it('should preserve other top-level keys', () => {

packages/codingcode/test/mcp/config.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ describe('loadMcpConfig', () => {
3737

3838
const configs = loadMcpConfig(join(__dirname, '..', '..', '..'));
3939
expect(configs).toHaveLength(1);
40-
expect(configs[0].name).toBe('test-stdio');
41-
expect(configs[0].command).toBe('npx');
42-
expect(configs[0].args).toEqual(['-y', 'test-server']);
40+
expect(configs[0]!.name).toBe('test-stdio');
41+
expect(configs[0]!.command).toBe('npx');
42+
expect(configs[0]!.args).toEqual(['-y', 'test-server']);
4343
});
4444

4545
it('should load SSE server config from mcp.yaml', () => {
@@ -56,9 +56,9 @@ describe('loadMcpConfig', () => {
5656

5757
const configs = loadMcpConfig(join(__dirname, '..', '..', '..'));
5858
expect(configs).toHaveLength(1);
59-
expect(configs[0].name).toBe('test-sse');
60-
expect(configs[0].url).toBe('https://mcp.example.com/sse');
61-
expect(configs[0].concurrency).toBe(5);
59+
expect(configs[0]!.name).toBe('test-sse');
60+
expect(configs[0]!.url).toBe('https://mcp.example.com/sse');
61+
expect(configs[0]!.concurrency).toBe(5);
6262
});
6363

6464
it('should resolve ${ENV_VAR} placeholders', () => {
@@ -74,7 +74,7 @@ describe('loadMcpConfig', () => {
7474
);
7575

7676
const configs = loadMcpConfig(join(__dirname, '..', '..', '..'));
77-
expect(configs[0].headers!.Authorization).toBe('Bearer resolved-token');
77+
expect(configs[0]!.headers!.Authorization).toBe('Bearer resolved-token');
7878

7979
delete process.env.TEST_TOKEN;
8080
});
@@ -91,7 +91,7 @@ describe('loadMcpConfig', () => {
9191
);
9292

9393
const configs = loadMcpConfig(join(__dirname, '..', '..', '..'));
94-
expect(configs[0].headers!.Authorization).toBeUndefined();
94+
expect(configs[0]!.headers!.Authorization).toBeUndefined();
9595
});
9696
});
9797

@@ -113,8 +113,8 @@ describe('writeMcpConfig', () => {
113113
writeMcpConfig(projectRoot, servers);
114114
const result = loadMcpConfig(projectRoot);
115115
expect(result).toHaveLength(1);
116-
expect(result[0].name).toBe('test-server');
117-
expect(result[0].concurrency).toBe(5);
116+
expect(result[0]!.name).toBe('test-server');
117+
expect(result[0]!.concurrency).toBe(5);
118118
});
119119

120120
it('should overwrite existing servers list', () => {
@@ -123,7 +123,7 @@ describe('writeMcpConfig', () => {
123123
writeMcpConfig(projectRoot, [{ name: 'new', command: 'ls' }]);
124124
const result = loadMcpConfig(projectRoot);
125125
expect(result).toHaveLength(1);
126-
expect(result[0].name).toBe('new');
126+
expect(result[0]!.name).toBe('new');
127127
});
128128

129129
it('should preserve other top-level keys in the yaml', () => {

packages/codingcode/test/memory/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('Memory Config', () => {
101101

102102
const types = getEffectiveTypes(cfg);
103103
expect(types).toHaveLength(1);
104-
expect(types[0].name).toBe('reference');
104+
expect(types[0]!.name).toBe('reference');
105105
});
106106

107107
it('filters disabled extra types', () => {

packages/codingcode/test/memory/extractor.test.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,28 @@ import type { MemoryTypeConfig } from '@codingcode/infra';
55

66
describe('Memory Extractor', () => {
77
const createMockLlm = (response: string) => ({
8+
complete: vi.fn(() =>
9+
Promise.resolve({
10+
ok: true as const,
11+
value: { content: response, finishReason: 'stop' as const },
12+
})
13+
),
814
completeStream: vi.fn(() => ({
915
stream: (async function* () {
1016
yield response;
1117
})(),
1218
response: Promise.resolve({
13-
ok: true,
14-
value: { content: response },
19+
ok: true as const,
20+
value: { content: response, finishReason: 'stop' as const },
1521
}),
1622
})),
23+
modelInfo: {
24+
provider: 'mock',
25+
model: 'mock',
26+
maxTokens: 4096,
27+
supportsToolCalling: true,
28+
supportsStreaming: true,
29+
},
1730
});
1831

1932
const defaultTypes: MemoryTypeConfig[] = [
@@ -83,6 +96,12 @@ describe('Memory Extractor', () => {
8396

8497
it('handles LLM call failure gracefully', async () => {
8598
const llm = {
99+
complete: vi.fn(() =>
100+
Promise.resolve({
101+
ok: false,
102+
value: { content: '' },
103+
} as any)
104+
),
86105
completeStream: vi.fn(() => ({
87106
stream: (async function* () {
88107
throw new Error('Stream error');
@@ -92,6 +111,13 @@ describe('Memory Extractor', () => {
92111
value: { content: '' },
93112
} as any),
94113
})),
114+
modelInfo: {
115+
provider: 'mock',
116+
model: 'mock',
117+
maxTokens: 4096,
118+
supportsToolCalling: true,
119+
supportsStreaming: true,
120+
},
95121
};
96122

97123
const transcript: StructuredTranscript = {
@@ -129,7 +155,7 @@ describe('Memory Extractor', () => {
129155
llm: mockLlm,
130156
});
131157

132-
const callArgs = mockLlm.completeStream.mock.calls[0][0];
158+
const callArgs = (mockLlm.completeStream.mock.calls as any)[0][0] as any;
133159
expect(callArgs.messages[0].content).toContain('已有记忆');
134160
expect(callArgs.messages[0].content).toContain('Old info');
135161
});
@@ -150,7 +176,7 @@ describe('Memory Extractor', () => {
150176
llm: mockLlm,
151177
});
152178

153-
const callArgs = mockLlm.completeStream.mock.calls[0][0];
179+
const callArgs = (mockLlm.completeStream.mock.calls as any)[0][0] as any;
154180
expect(callArgs.messages[0].content).toContain('[user]');
155181
expect(callArgs.messages[0].content).toContain('[user+assistant]');
156182
expect(callArgs.messages[0].content).toContain('[user+tool]');
@@ -173,7 +199,7 @@ describe('Memory Extractor', () => {
173199
llm: mockLlm,
174200
});
175201

176-
const callArgs = mockLlm.completeStream.mock.calls[0][0];
202+
const callArgs = (mockLlm.completeStream.mock.calls as any)[0][0] as any;
177203
// Should not mention reference guidance
178204
expect(callArgs.system).not.toContain('reference');
179205
});
@@ -194,7 +220,7 @@ describe('Memory Extractor', () => {
194220
llm: mockLlm,
195221
});
196222

197-
const callArgs = mockLlm.completeStream.mock.calls[0][0];
223+
const callArgs = (mockLlm.completeStream.mock.calls as any)[0][0] as any;
198224
expect(callArgs.messages).toHaveLength(1);
199225
expect(callArgs.messages[0].role).toBe('user');
200226
expect(callArgs.messages[0].content).toBeTruthy();
@@ -216,7 +242,7 @@ describe('Memory Extractor', () => {
216242
llm: mockLlm,
217243
});
218244

219-
const callArgs = mockLlm.completeStream.mock.calls[0][0];
245+
const callArgs = (mockLlm.completeStream.mock.calls as any)[0][0] as any;
220246
// system contains instructions, not transcript data
221247
expect(callArgs.system).toContain('规则');
222248
expect(callArgs.system).toContain('记忆类型');

packages/codingcode/test/memory/llm-resolver.test.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, it, expect, vi, afterEach } from 'vitest';
22
import { resolveMemoryLLM } from '../../src/memory/llm-resolver.js';
3+
import type { LLMClient } from '../../src/llm/client.js';
34
import type { MemoryConfig } from '@codingcode/infra';
45

56
vi.mock('../../src/llm/factory.js', () => ({
@@ -20,13 +21,21 @@ vi.mock('../../src/llm/factory.js', () => ({
2021
},
2122
],
2223
})),
23-
createClient: vi.fn(async (modelInfo: any) => ({
24+
createClient: vi.fn(async (_modelInfo: any) => ({
2425
ok: true,
2526
value: {
27+
complete: () => Promise.resolve({ ok: true, value: { content: '' } }),
2628
completeStream: () => ({
2729
stream: async function* () {},
2830
response: Promise.resolve({ ok: true, value: { content: '' } }),
2931
}),
32+
modelInfo: {
33+
provider: 'mock',
34+
model: 'mock',
35+
maxTokens: 4096,
36+
supportsToolCalling: true,
37+
supportsStreaming: true,
38+
},
3039
} as any,
3140
})),
3241
}));
@@ -49,7 +58,7 @@ describe('Memory LLM Resolver', () => {
4958

5059
it('returns fallback when model is empty', async () => {
5160
const cfg = createCfg('');
52-
const fallback = {} as LLMStreamAdapter;
61+
const fallback = {} as LLMClient;
5362
const result = await resolveMemoryLLM(cfg, fallback);
5463
expect(result).toBe(fallback);
5564
});
@@ -59,14 +68,14 @@ describe('Memory LLM Resolver', () => {
5968
vi.mocked(listModels).mockReturnValue({ ok: false, error: 'error' } as any);
6069

6170
const cfg = createCfg('claude-opus-4-7');
62-
const fallback = {} as LLMStreamAdapter;
71+
const fallback = {} as LLMClient;
6372
const result = await resolveMemoryLLM(cfg, fallback);
6473
expect(result).toBe(fallback);
6574
});
6675

6776
it('returns fallback when model not found', async () => {
6877
const cfg = createCfg('nonexistent-model');
69-
const fallback = {} as LLMStreamAdapter;
78+
const fallback = {} as LLMClient;
7079
const result = await resolveMemoryLLM(cfg, fallback);
7180
expect(result).toBe(fallback);
7281
});
@@ -91,14 +100,14 @@ describe('Memory LLM Resolver', () => {
91100

92101
it('creates and returns client when model matches by id', async () => {
93102
const cfg = createCfg('claude-opus-4-7');
94-
const fallback = {} as any;
103+
const fallback = {} as LLMClient;
95104
const result = await resolveMemoryLLM(cfg, fallback);
96105
expect(result).not.toBe(fallback);
97106
});
98107

99108
it('creates and returns client when model matches by bare id', async () => {
100109
const cfg = createCfg('deepseek-chat');
101-
const fallback = {} as any;
110+
const fallback = {} as LLMClient;
102111
const result = await resolveMemoryLLM(cfg, fallback);
103112
expect(result).not.toBe(fallback);
104113
});

0 commit comments

Comments
 (0)