|
| 1 | +import { afterEach, describe, expect, test } from 'bun:test' |
| 2 | +import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' |
| 3 | +import { tmpdir } from 'node:os' |
| 4 | +import { join } from 'node:path' |
| 5 | + |
| 6 | +import { |
| 7 | + getSteps, |
| 8 | + isProjectOnboardingComplete, |
| 9 | +} from './projectOnboardingSteps.js' |
| 10 | +import { runWithCwdOverride } from './utils/cwd.js' |
| 11 | + |
| 12 | +let tempDir: string | undefined |
| 13 | + |
| 14 | +afterEach(async () => { |
| 15 | + if (tempDir) { |
| 16 | + await rm(tempDir, { recursive: true, force: true }) |
| 17 | + tempDir = undefined |
| 18 | + } |
| 19 | +}) |
| 20 | + |
| 21 | +describe('project onboarding completion', () => { |
| 22 | + test('is incomplete when neither AGENTS.md nor CLAUDE.md exists', async () => { |
| 23 | + tempDir = await mkdtemp(join(tmpdir(), 'project-onboarding-')) |
| 24 | + |
| 25 | + await runWithCwdOverride(tempDir, async () => { |
| 26 | + expect(isProjectOnboardingComplete()).toBe(false) |
| 27 | + expect(getSteps()[1]?.text).toContain('/init') |
| 28 | + expect(getSteps()[1]?.text).toContain('AGENTS.md') |
| 29 | + expect(getSteps()[1]?.text).toContain('CLAUDE.md') |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + test('is complete when only CLAUDE.md exists', async () => { |
| 34 | + tempDir = await mkdtemp(join(tmpdir(), 'project-onboarding-')) |
| 35 | + await writeFile(join(tempDir, 'CLAUDE.md'), '# CLAUDE.md\n') |
| 36 | + |
| 37 | + await runWithCwdOverride(tempDir, async () => { |
| 38 | + expect(isProjectOnboardingComplete()).toBe(true) |
| 39 | + }) |
| 40 | + }) |
| 41 | + |
| 42 | + test('is complete when only AGENTS.md exists', async () => { |
| 43 | + tempDir = await mkdtemp(join(tmpdir(), 'project-onboarding-')) |
| 44 | + await writeFile(join(tempDir, 'AGENTS.md'), '# AGENTS.md\n') |
| 45 | + |
| 46 | + await runWithCwdOverride(tempDir, async () => { |
| 47 | + expect(isProjectOnboardingComplete()).toBe(true) |
| 48 | + }) |
| 49 | + }) |
| 50 | + |
| 51 | + test('is complete from a nested cwd when repo instructions exist in an ancestor directory', async () => { |
| 52 | + tempDir = await mkdtemp(join(tmpdir(), 'project-onboarding-')) |
| 53 | + const nestedDir = join(tempDir, 'packages', 'app') |
| 54 | + await writeFile(join(tempDir, 'AGENTS.md'), '# AGENTS.md\n') |
| 55 | + await mkdir(nestedDir, { recursive: true }) |
| 56 | + await writeFile(join(nestedDir, 'index.ts'), 'export {}\n') |
| 57 | + |
| 58 | + await runWithCwdOverride(nestedDir, async () => { |
| 59 | + expect(isProjectOnboardingComplete()).toBe(true) |
| 60 | + }) |
| 61 | + }) |
| 62 | +}) |
0 commit comments