mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-08-03 05:24:54 +00:00
* feat(klient): contract-driven facade with http/ipc/memory transports - add zod-validated contract sections (global/session/agent) under src/contract and a facade exposing global.*, session(id).*, agent(id).* - select transport once at creation via subpath entries (@moonshot-ai/klient/http|ipc|memory); drop legacy channel/client/ httpChannel/wsChannel/wsKlient/proxy implementations - absorb packages/server-e2e into packages/klient test/e2e suites (dual-backend, legacy v1, v2 wire) and remove the server-e2e workspace - expose model registry and catalog services on kap-server v2 RPC surface * fix(klient): derive session status from agentActivityView The engine retired its sessionActivity service in #1751 (session busy is now derived from agent activity views), but the facade still called the deleted wire channel and imported the deleted engine module, breaking typecheck and every klient suite at import time. - drop the sessionActivity contract/registry entries and mirror the agentActivityView service instead (agent scope) - compose session status() client-side from the pending interaction lists and each agent's agentActivityView, keeping the retired service's precedence and typing SessionStatus locally in the facade - replace the deleted-channel call in the v2 smoke suite with a sessionInteractionService probe - fix the legacy image-file suite to wait with the harness's waitForSessionBusy
74 lines
2.6 KiB
TypeScript
74 lines
2.6 KiB
TypeScript
import { rm } from 'node:fs/promises';
|
|
import { join } from 'node:path';
|
|
import { tmpdir } from 'node:os';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import { defineKlientConformance } from './helpers/conformance.js';
|
|
import { createKlient, serveKlientIpc, type KlientIpcHost } from '../src/transports/ipc/index.js';
|
|
import { makeEngine, type TestEngine } from './helpers/engine.js';
|
|
|
|
defineKlientConformance('ipc', async () => {
|
|
const { homeDir, app } = await makeEngine();
|
|
const socketPath = join(homeDir, 'klient.sock');
|
|
const host = await serveKlientIpc({ scope: app, socketPath });
|
|
const klient = createKlient({ socketPath });
|
|
return {
|
|
klient,
|
|
cleanup: async () => {
|
|
await klient.close();
|
|
await host.close();
|
|
app.dispose();
|
|
await rm(homeDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 25 });
|
|
},
|
|
};
|
|
});
|
|
|
|
describe('ipc transport specifics', () => {
|
|
let homeDir: string;
|
|
let app: TestEngine['app'];
|
|
let host: KlientIpcHost | undefined;
|
|
|
|
async function setup(opts: { token?: string } = {}): Promise<string> {
|
|
({ homeDir, app } = await makeEngine());
|
|
const socketPath = join(homeDir, 'klient.sock');
|
|
host = await serveKlientIpc({ scope: app, socketPath, token: opts.token });
|
|
return socketPath;
|
|
}
|
|
|
|
async function teardown(): Promise<void> {
|
|
await host?.close();
|
|
host = undefined;
|
|
app.dispose();
|
|
await rm(homeDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 25 });
|
|
}
|
|
|
|
it('rejects calls when the socket path does not exist', async () => {
|
|
const klient = createKlient({ socketPath: join(tmpdir(), 'klient-no-such.sock') });
|
|
await expect(klient.global.env()).rejects.toThrow();
|
|
await klient.close();
|
|
});
|
|
|
|
it('rejects calls made after close', async () => {
|
|
const socketPath = await setup();
|
|
const klient = createKlient({ socketPath });
|
|
await klient.global.env();
|
|
await klient.close();
|
|
// env() is served from its frozen-snapshot cache after the first call, so
|
|
// probe the closed channel with an uncached method instead.
|
|
await expect(klient.global.workspaces.list()).rejects.toThrow('ipc closed');
|
|
await teardown();
|
|
});
|
|
|
|
it('drops clients whose hello token mismatches', async () => {
|
|
const socketPath = await setup({ token: 'right' });
|
|
const klient = createKlient({ socketPath, token: 'wrong' });
|
|
await expect(klient.global.env()).rejects.toThrow();
|
|
await klient.close();
|
|
|
|
const ok = createKlient({ socketPath, token: 'right' });
|
|
await expect(ok.global.env()).resolves.toMatchObject({ platform: process.platform });
|
|
await ok.close();
|
|
await teardown();
|
|
});
|
|
});
|