kimi-code/packages/server-e2e/vitest.config.ts
haozhe.yang 304883ab81 refactor(kap-server): rename server-v2 package to kap-server
- rename packages/server-v2 to packages/kap-server and update every
  @moonshot-ai/server-v2 reference across apps, packages, flake.nix,
  and build scripts
- remove the experimental `kimi v2` CLI prefix and its tests from the
  apps/kimi-code main entry
- add legacy BackgroundTask protocol types and the `blocked` turn
  interrupt reason for cross-engine compatibility
2026-07-07 16:56:19 +08:00

63 lines
2 KiB
TypeScript

import { existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig, type Plugin } from 'vitest/config';
import { rawTextPlugin } from '../../build/raw-text-plugin.mjs';
function findPackageRoot(importer: string | undefined): string | undefined {
if (!importer) return undefined;
let dir = dirname(importer.split('?')[0] ?? importer);
for (;;) {
if (existsSync(join(dir, 'package.json'))) return dir;
const parent = dirname(dir);
if (parent === dir) return undefined;
dir = parent;
}
}
/**
* Resolve `#/` subpath imports scoped to the importer's owning package. Required
* because the v2 SDK tests import `@moonshot-ai/kap-server`, which inlines
* `@moonshot-ai/agent-core-v2` source whose internal `#/foo` imports must
* resolve against that package's own `src/`. Mirrors
* `packages/kap-server/vitest.config.ts`.
*/
function hashImportsPlugin(): Plugin {
return {
name: 'resolve-hash-imports',
enforce: 'pre',
resolveId(id, importer) {
if (!id.startsWith('#/')) return null;
const pkgRoot = findPackageRoot(importer);
if (!pkgRoot) return null;
const sub = id.slice(2);
for (const candidate of [`src/${sub}.ts`, `src/${sub}/index.ts`]) {
const full = join(pkgRoot, candidate);
if (existsSync(full)) return full;
}
return null;
},
};
}
// `rawTextPlugin` is required because importing `@moonshot-ai/kap-server` (for
// the v2 SDK tests) pulls in agent-core-v2's barrel, which imports `*.md?raw`
// prompt templates. Both plugins are no-ops for the legacy v1 tests, which do
// not import server-v2.
export default defineConfig({
plugins: [rawTextPlugin(), hashImportsPlugin()],
resolve: {
alias: {
'@moonshot-ai/protocol': fileURLToPath(
new URL('../protocol/src/index.ts', import.meta.url),
),
},
},
test: {
name: 'server-e2e',
include: ['test/**/*.test.ts'],
reporters: ['default', './test/report/vitest-reporter.ts'],
},
});