Move OpenCode UI into Electron shell
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import { parseServerSentEvent } from '../packages/opencode-bridge/ts/index.js';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import { parseServerSentEvent, sanitizeOpenCodeEventForRenderer } from '../packages/opencode-bridge/ts/index.js';
|
||||
|
||||
tap.test('should parse named opencode sse events', async () => {
|
||||
const event = parseServerSentEvent('id: 1\nevent: server.connected\ndata: {"type":"server.connected"}\n');
|
||||
@@ -14,4 +15,26 @@ tap.test('should infer opencode event type from json data', async () => {
|
||||
expect(event!.data).toEqual({ type: 'session.updated', properties: { id: 'abc' } });
|
||||
});
|
||||
|
||||
tap.test('should sanitize opencode events for renderer delivery', async () => {
|
||||
const event = parseServerSentEvent('id: 2\nretry: 1000\nevent: permission.asked\ndata: {"permissionID":"perm-1"}\n')!;
|
||||
const sanitized = sanitizeOpenCodeEventForRenderer(event);
|
||||
|
||||
expect(sanitized).toEqual({
|
||||
type: 'permission.asked',
|
||||
id: '2',
|
||||
retry: 1000,
|
||||
data: { permissionID: 'perm-1' },
|
||||
});
|
||||
expect(Object.prototype.hasOwnProperty.call(sanitized, 'raw')).toEqual(false);
|
||||
});
|
||||
|
||||
tap.test('should keep electron shell opencode resolution IDE-local', async () => {
|
||||
const source = await fs.readFile(new URL('../applications/electron-shell/ts/main.ts', import.meta.url), 'utf8');
|
||||
|
||||
expect(source.includes('process.env.OPENCODE_BINARY')).toEqual(false);
|
||||
expect(source.includes("'.opencode', 'bin', 'opencode'")).toEqual(false);
|
||||
expect(source.includes('/usr/local/bin/opencode')).toEqual(false);
|
||||
expect(source.includes('/usr/bin/opencode')).toEqual(false);
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
|
||||
Reference in New Issue
Block a user