Files
hapi/cli/src/modules/team/teamMemory.test.ts
T
wushenghua ef33332dc5 refactor(hub,cli,web): move team memory into the repo (runner side)
Team memory now lives with the code, like CLAUDE.md: <main repo>/.hapi/team/
on the machine where the agent runs. Worktrees resolve to the main repo so
every member shares one directory. The CLI creates charter.md + handoffs/ at
session start (team env only), points the agent at it in the system prompt,
and reports the path in session metadata; the web reads it through the
session file API, so remote runners work too.

Hub keeps only coordination data (teams.db): members/tasks/messages/status.
Its memory-dir management and the /memory API are removed.
2026-09-15 11:40:51 +08:00

49 lines
2.0 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { ensureTeamMemory, resolveMainRepoRoot, resolveTeamMemoryDir } from './teamMemory'
function makeRepos() {
const root = mkdtempSync(join(tmpdir(), 'hapi-team-memory-'))
const main = join(root, 'repo')
const worktree = join(root, 'wt')
mkdirSync(join(main, '.git', 'worktrees', 'feat'), { recursive: true })
mkdirSync(worktree, { recursive: true })
writeFileSync(join(worktree, '.git'), `gitdir: ${join(main, '.git', 'worktrees', 'feat')}\n`, 'utf8')
return { root, main, worktree }
}
describe('teamMemory', () => {
it('resolves the repo root for a plain checkout and a linked worktree', () => {
const { root, main, worktree } = makeRepos()
try {
expect(resolveMainRepoRoot(main)).toBe(main)
expect(resolveMainRepoRoot(worktree)).toBe(main)
expect(resolveTeamMemoryDir(worktree)).toBe(join(main, '.hapi', 'team'))
} finally {
rmSync(root, { recursive: true, force: true })
}
})
it('creates charter.md + handoffs only for team sessions', () => {
const { root, worktree } = makeRepos()
try {
expect(ensureTeamMemory({}, worktree)).toBeNull()
const dir = ensureTeamMemory({ HAPI_TEAM_ID: 'team-1', HAPI_TEAM_NAME: 'Auth 重构' }, worktree)
expect(dir).toBe(join(root, 'repo', '.hapi', 'team'))
const charter = readFileSync(join(dir!, 'charter.md'), 'utf8')
expect(charter).toContain('Auth 重构')
// Idempotent: an existing charter is not overwritten.
writeFileSync(join(dir!, 'charter.md'), 'custom', 'utf8')
ensureTeamMemory({ HAPI_TEAM_ID: 'team-1' }, worktree)
expect(readFileSync(join(dir!, 'charter.md'), 'utf8')).toBe('custom')
} finally {
rmSync(root, { recursive: true, force: true })
}
})
})