MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / buildSessionFixture

Function buildSessionFixture

apps/vis/server/test/fixtures/build.ts:7–42  ·  view source on GitHub ↗
(name: string)

Source from the content-addressed store, hash-verified

5/** Copy a fixture session into a temp dir, rewriting state.json.agents.*.homedir
6 * to the real path so wire-reader / agent-tree can resolve them. */
7export async function buildSessionFixture(name: string): Promise<{
8 home: string;
9 sessionDir: string;
10 cleanup: () => Promise<void>;
11}> {
12 const src = new URL(`./sessions/${name}`, import.meta.url).pathname;
13 const home = await mkdtemp();
14 const sessionsDir = join(home, 'sessions', 'wd_test_000000000000');
15 const sessionDir = join(sessionsDir, 'session_fixture');
16 await mkdir(sessionsDir, { recursive: true });
17 await cp(src, sessionDir, { recursive: true });
18
19 // Rewrite homedir placeholders.
20 const statePath = join(sessionDir, 'state.json');
21 const state = JSON.parse(await readFile(statePath, 'utf8'));
22 for (const id of Object.keys(state.agents)) {
23 state.agents[id].homedir = join(sessionDir, 'agents', id);
24 }
25 await writeFile(statePath, JSON.stringify(state, null, 2));
26
27 // Write session_index.jsonl.
28 await writeFile(
29 join(home, 'session_index.jsonl'),
30 JSON.stringify({
31 sessionId: 'session_fixture',
32 sessionDir,
33 workDir: '/tmp/work',
34 }) + '\n',
35 );
36
37 return {
38 home,
39 sessionDir,
40 cleanup: () => rm(home, { recursive: true, force: true }),
41 };
42}
43
44async function mkdtemp(): Promise<string> {
45 const base = join(tmpdir(), `vis-fixture-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`);

Callers 10

logs.test.tsFile · 0.90
cron.test.tsFile · 0.90
context.test.tsFile · 0.90
tasks.test.tsFile · 0.90
blobs.test.tsFile · 0.90
task-store.test.tsFile · 0.90
cron-store.test.tsFile · 0.90

Calls 5

mkdtempFunction · 0.85
keysMethod · 0.80
mkdirFunction · 0.50
readFileFunction · 0.50
writeFileFunction · 0.50

Tested by

no test coverage detected