397777089e
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
89 lines
3.0 KiB
JavaScript
89 lines
3.0 KiB
JavaScript
// tools/subagent-prompt-prefix-h10.test.mjs
|
|
// Stream H Task 10 — worktree-bootstrap helper tests (vitest, separate file
|
|
// because subagent-prompt-prefix.test.mjs is in vitest config exclude list
|
|
// and uses node:test for subprocess-style runs).
|
|
import { describe, it, expect } from 'vitest';
|
|
import { detectWorktreeMode, buildSetupBlock } from './subagent-prompt-prefix.mjs';
|
|
|
|
describe('detectWorktreeMode (Stream H Task 10)', () => {
|
|
it('returns isWorktree=false when cwd .git is the same as common dir', () => {
|
|
const r = detectWorktreeMode({
|
|
cwd: 'c:/repo',
|
|
gitDir: 'c:/repo/.git',
|
|
gitCommonDir: 'c:/repo/.git',
|
|
});
|
|
expect(r.isWorktree).toBe(false);
|
|
expect(r.parentRepoRoot).toBeNull();
|
|
});
|
|
|
|
it('returns isWorktree=true when cwd is a linked worktree', () => {
|
|
const r = detectWorktreeMode({
|
|
cwd: 'c:/parent/v4-stream-A',
|
|
gitDir: 'c:/parent/.git/worktrees/v4-stream-A',
|
|
gitCommonDir: 'c:/parent/.git',
|
|
});
|
|
expect(r.isWorktree).toBe(true);
|
|
expect(r.parentRepoRoot).toBe('c:/parent');
|
|
});
|
|
|
|
it('handles null inputs gracefully', () => {
|
|
expect(detectWorktreeMode({}).isWorktree).toBe(false);
|
|
expect(detectWorktreeMode({ cwd: null, gitDir: null, gitCommonDir: null }).isWorktree).toBe(false);
|
|
});
|
|
|
|
it('handles different separators (backslashes) for parentRepoRoot extraction', () => {
|
|
const r = detectWorktreeMode({
|
|
cwd: 'c:/parent/wt-X',
|
|
gitDir: 'c:\\parent\\.git\\worktrees\\wt-X',
|
|
gitCommonDir: 'c:\\parent\\.git',
|
|
});
|
|
expect(r.isWorktree).toBe(true);
|
|
expect(r.parentRepoRoot).toBe('c:/parent');
|
|
});
|
|
});
|
|
|
|
describe('buildSetupBlock (Stream H Task 10)', () => {
|
|
it('returns empty string when not in a worktree', () => {
|
|
expect(buildSetupBlock({ isWorktree: false, parentRepoRoot: null })).toBe('');
|
|
});
|
|
|
|
it('returns a SETUP — worktree bootstrap block when in a worktree (win32)', () => {
|
|
const s = buildSetupBlock({
|
|
isWorktree: true,
|
|
parentRepoRoot: 'c:/parent',
|
|
platform: 'win32',
|
|
});
|
|
expect(s).toContain('SETUP — worktree bootstrap');
|
|
expect(s).toContain('mklink /D vendor');
|
|
expect(s).toContain('c:/parent/app/vendor');
|
|
expect(s).toContain('storage/framework');
|
|
});
|
|
|
|
it('returns a SETUP block with ln -s on linux/darwin', () => {
|
|
const s = buildSetupBlock({
|
|
isWorktree: true,
|
|
parentRepoRoot: '/home/u/repo',
|
|
platform: 'linux',
|
|
});
|
|
expect(s).toContain('SETUP — worktree bootstrap');
|
|
expect(s).toContain('ln -s');
|
|
expect(s).toContain('/home/u/repo/app/vendor');
|
|
});
|
|
|
|
it('mentions mkdir for cache/sessions/views/testing dirs', () => {
|
|
const s = buildSetupBlock({
|
|
isWorktree: true,
|
|
parentRepoRoot: 'c:/parent',
|
|
platform: 'win32',
|
|
});
|
|
expect(s).toContain('cache');
|
|
expect(s).toContain('sessions');
|
|
expect(s).toContain('views');
|
|
expect(s).toContain('testing');
|
|
});
|
|
|
|
it('returns empty when isWorktree=true but parentRepoRoot missing', () => {
|
|
expect(buildSetupBlock({ isWorktree: true, parentRepoRoot: null })).toBe('');
|
|
});
|
|
});
|