|
@@ -15,10 +15,7 @@ import {
|
|
|
writeBackgroundSubagentsBlock,
|
|
writeBackgroundSubagentsBlock,
|
|
|
} from './background-subagents';
|
|
} from './background-subagents';
|
|
|
import { parseArgs } from './index';
|
|
import { parseArgs } from './index';
|
|
|
-import {
|
|
|
|
|
- configureBackgroundSubagents,
|
|
|
|
|
- shouldPromptForBackgroundSubagents,
|
|
|
|
|
-} from './install';
|
|
|
|
|
|
|
+import { configureBackgroundSubagents } from './install';
|
|
|
|
|
|
|
|
describe('background subagents helpers', () => {
|
|
describe('background subagents helpers', () => {
|
|
|
test('detects true-like environment values', () => {
|
|
test('detects true-like environment values', () => {
|
|
@@ -127,6 +124,11 @@ describe('background subagents writing', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('parseArgs background subagents', () => {
|
|
describe('parseArgs background subagents', () => {
|
|
|
|
|
+ test('defaults background subagents to ask', () => {
|
|
|
|
|
+ expect(parseArgs([]).backgroundSubagents).toBe('ask');
|
|
|
|
|
+ expect(parseArgs(['--no-tui']).backgroundSubagents).toBe('ask');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
test('parses mode and target override', () => {
|
|
test('parses mode and target override', () => {
|
|
|
expect(
|
|
expect(
|
|
|
parseArgs([
|
|
parseArgs([
|
|
@@ -138,9 +140,17 @@ describe('parseArgs background subagents', () => {
|
|
|
backgroundSubagentsTarget: '/tmp/profile',
|
|
backgroundSubagentsTarget: '/tmp/profile',
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
- test('--no-tui defaults background subagents to no', () => {
|
|
|
|
|
- expect(parseArgs(['--no-tui']).backgroundSubagents).toBe('no');
|
|
|
|
|
|
|
+describe('parseArgs companion', () => {
|
|
|
|
|
+ test('defaults companion install to ask', () => {
|
|
|
|
|
+ expect(parseArgs([]).companion).toBe('ask');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('parses companion mode override', () => {
|
|
|
|
|
+ expect(parseArgs(['--companion=yes']).companion).toBe('yes');
|
|
|
|
|
+ expect(parseArgs(['--companion=no']).companion).toBe('no');
|
|
|
|
|
+ expect(parseArgs(['--companion=ask']).companion).toBe('ask');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -160,47 +170,34 @@ describe('configureBackgroundSubagents', () => {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- test('does not prompt for ask mode when noninteractive', async () => {
|
|
|
|
|
|
|
+ test('writes shell config without prompting', async () => {
|
|
|
tempDir = mkdtempSync(join(tmpdir(), 'omoo-bg-'));
|
|
tempDir = mkdtempSync(join(tmpdir(), 'omoo-bg-'));
|
|
|
delete process.env.OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS;
|
|
delete process.env.OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS;
|
|
|
- const target = join(tempDir, '.bashrc');
|
|
|
|
|
const log = spyOn(console, 'log').mockImplementation(() => undefined);
|
|
const log = spyOn(console, 'log').mockImplementation(() => undefined);
|
|
|
- const originalIsTty = process.stdin.isTTY;
|
|
|
|
|
- Object.defineProperty(process.stdin, 'isTTY', {
|
|
|
|
|
- configurable: true,
|
|
|
|
|
- value: false,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const originalShell = process.env.SHELL;
|
|
|
|
|
+ const originalHome = process.env.HOME;
|
|
|
|
|
+ process.env.SHELL = '/bin/zsh';
|
|
|
|
|
+ process.env.HOME = tempDir;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- expect(
|
|
|
|
|
- shouldPromptForBackgroundSubagents({
|
|
|
|
|
- hasTmux: false,
|
|
|
|
|
- installCustomSkills: false,
|
|
|
|
|
- promptForStar: false,
|
|
|
|
|
- reset: false,
|
|
|
|
|
- backgroundSubagents: 'ask',
|
|
|
|
|
- backgroundSubagentsTarget: target,
|
|
|
|
|
- }),
|
|
|
|
|
- ).toBe(false);
|
|
|
|
|
-
|
|
|
|
|
const result = await configureBackgroundSubagents({
|
|
const result = await configureBackgroundSubagents({
|
|
|
hasTmux: false,
|
|
hasTmux: false,
|
|
|
installCustomSkills: false,
|
|
installCustomSkills: false,
|
|
|
promptForStar: false,
|
|
promptForStar: false,
|
|
|
reset: false,
|
|
reset: false,
|
|
|
- backgroundSubagents: 'ask',
|
|
|
|
|
- backgroundSubagentsTarget: target,
|
|
|
|
|
|
|
+ backgroundSubagents: 'yes',
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- expect(result).toEqual({ enabledNow: false });
|
|
|
|
|
|
|
+ expect(result.configuredTarget?.endsWith('/.zshrc')).toBe(true);
|
|
|
|
|
+ expect(readFileSync(join(tempDir, '.zshrc'), 'utf8')).toContain(
|
|
|
|
|
+ 'OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS',
|
|
|
|
|
+ );
|
|
|
expect(log.mock.calls.join('\n')).toContain(
|
|
expect(log.mock.calls.join('\n')).toContain(
|
|
|
- 'Skipped background subagents shell configuration.',
|
|
|
|
|
|
|
+ 'Background subagents enabled',
|
|
|
);
|
|
);
|
|
|
} finally {
|
|
} finally {
|
|
|
- Object.defineProperty(process.stdin, 'isTTY', {
|
|
|
|
|
- configurable: true,
|
|
|
|
|
- value: originalIsTty,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ process.env.SHELL = originalShell;
|
|
|
|
|
+ process.env.HOME = originalHome;
|
|
|
log.mockRestore();
|
|
log.mockRestore();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -208,10 +205,13 @@ describe('configureBackgroundSubagents', () => {
|
|
|
test('returns no configured target when writing shell config fails', async () => {
|
|
test('returns no configured target when writing shell config fails', async () => {
|
|
|
tempDir = mkdtempSync(join(tmpdir(), 'omoo-bg-'));
|
|
tempDir = mkdtempSync(join(tmpdir(), 'omoo-bg-'));
|
|
|
delete process.env.OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS;
|
|
delete process.env.OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS;
|
|
|
- const blockingFile = join(tempDir, 'not-a-directory');
|
|
|
|
|
- writeFileSync(blockingFile, 'already a file');
|
|
|
|
|
- const target = join(blockingFile, '.bashrc');
|
|
|
|
|
|
|
+ rmSync(tempDir, { recursive: true, force: true });
|
|
|
|
|
+ writeFileSync(tempDir, 'not a directory');
|
|
|
const log = spyOn(console, 'log').mockImplementation(() => undefined);
|
|
const log = spyOn(console, 'log').mockImplementation(() => undefined);
|
|
|
|
|
+ const originalShell = process.env.SHELL;
|
|
|
|
|
+ const originalHome = process.env.HOME;
|
|
|
|
|
+ process.env.SHELL = '/bin/zsh';
|
|
|
|
|
+ process.env.HOME = tempDir;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
const result = await configureBackgroundSubagents({
|
|
const result = await configureBackgroundSubagents({
|
|
@@ -220,7 +220,6 @@ describe('configureBackgroundSubagents', () => {
|
|
|
promptForStar: false,
|
|
promptForStar: false,
|
|
|
reset: false,
|
|
reset: false,
|
|
|
backgroundSubagents: 'yes',
|
|
backgroundSubagents: 'yes',
|
|
|
- backgroundSubagentsTarget: target,
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
expect(result).toEqual({ enabledNow: false });
|
|
expect(result).toEqual({ enabledNow: false });
|
|
@@ -229,6 +228,8 @@ describe('configureBackgroundSubagents', () => {
|
|
|
);
|
|
);
|
|
|
expect(log.mock.calls.join('\n')).toContain('Add the setting manually');
|
|
expect(log.mock.calls.join('\n')).toContain('Add the setting manually');
|
|
|
} finally {
|
|
} finally {
|
|
|
|
|
+ process.env.SHELL = originalShell;
|
|
|
|
|
+ process.env.HOME = originalHome;
|
|
|
log.mockRestore();
|
|
log.mockRestore();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|