| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
- import plugin, { minimumExpectedToolCount } from './index';
- describe('plugin health thresholds', () => {
- test('accounts only for intentionally disabled baseline tools', () => {
- expect(minimumExpectedToolCount()).toBe(5);
- expect(minimumExpectedToolCount(['wait_for_user'])).toBe(4);
- expect(minimumExpectedToolCount(['wait_for_user', 'wait_for_user'])).toBe(
- 4,
- );
- expect(minimumExpectedToolCount(['unknown_tool'])).toBe(5);
- });
- });
- describe('plugin env disable', () => {
- let originalEnv: typeof process.env;
- beforeEach(() => {
- originalEnv = { ...process.env };
- });
- afterEach(() => {
- process.env = originalEnv;
- });
- test('returns empty hooks without reading plugin context', async () => {
- process.env.OH_MY_OPENCODE_SLIM_DISABLE = '1';
- const ctx = new Proxy(
- {},
- {
- get(_target, property) {
- throw new Error(`disabled plugin read ctx.${String(property)}`);
- },
- },
- );
- const hooks = await plugin(ctx as Parameters<typeof plugin>[0]);
- expect(hooks).toEqual({});
- expect(hooks.config).toBeUndefined();
- expect(hooks.event).toBeUndefined();
- expect(hooks.tool).toBeUndefined();
- });
- });
- describe('plugin tool registration', () => {
- let originalEnv: typeof process.env;
- beforeEach(() => {
- originalEnv = { ...process.env };
- delete process.env.OH_MY_OPENCODE_SLIM_DISABLE;
- process.env.OPENCODE_CONFIG_DIR =
- '/private/tmp/oh-my-opencode-slim-hitl-empty-config';
- process.env.XDG_CONFIG_HOME =
- '/private/tmp/oh-my-opencode-slim-hitl-empty-xdg';
- process.env.XDG_DATA_HOME =
- '/private/tmp/oh-my-opencode-slim-hitl-empty-data';
- process.env.XDG_CACHE_HOME =
- '/private/tmp/oh-my-opencode-slim-hitl-empty-cache';
- process.env.OPENCODE_LOG_DIR =
- '/private/tmp/oh-my-opencode-slim-hitl-empty-logs';
- });
- afterEach(() => {
- process.env = originalEnv;
- });
- test('registers wait_for_user and recovers a stale orchestrator session mapping', async () => {
- const noop = async () => ({});
- const session = new Proxy({}, { get: () => noop }) as Record<
- string,
- unknown
- >;
- const client = new Proxy(
- { app: { log: noop }, session },
- {
- get(target, property) {
- if (property in target) {
- return target[property as keyof typeof target];
- }
- return new Proxy({}, { get: () => noop });
- },
- },
- );
- const hooks = await plugin({
- client,
- directory: '/private/tmp/oh-my-opencode-slim-hitl-project',
- worktree: '/private/tmp/oh-my-opencode-slim-hitl-project',
- serverUrl: new URL('http://127.0.0.1:4096'),
- } as never);
- expect(hooks.tool?.wait_for_user).toBeDefined();
- await expect(
- hooks.tool?.wait_for_user?.execute(
- { reason: 'Complete the external approval.' },
- { sessionID: 'parent-after-reload', agent: 'orchestrator' } as never,
- ),
- ).resolves.toContain('state: waiting_for_user');
- });
- });
|