| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
- import plugin from './index';
- 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');
- });
- });
|