fix(vscode): restore permission auto-accept parity
Add a VS Code-specific foreground permission responder while preserving the server-owned implementation for web, desktop, and mobile runtimes. Persist the authoritative VS Code policy in extension global state and expose matching GET/PUT bridge routes. Broadcast policy updates to the sidebar, session editor panels, and agent manager so every active webview observes the same explicit per-session policy. Resolve missing child-session lineage through OpenCode, honor nearest explicit ancestor overrides, deduplicate concurrent requests, retry transient replies, and reconcile pending permissions after enablement, bootstrap, and reconnect. Treat resolved requests as handled and route notification suppression through the same responder outcome. Keep post-toggle reconciliation failures non-fatal after policy persistence and fail closed when lineage or replies cannot be confirmed. Document that auto-accept intentionally cannot run while every OpenChamber webview is closed or suspended.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { describe, test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { handlePermissionAutoAcceptBridgeMessage } from './bridge-permission-auto-accept-runtime';
|
||||
|
||||
const createContext = () => {
|
||||
const values = new Map<string, unknown>();
|
||||
return {
|
||||
globalState: {
|
||||
get: (key: string) => values.get(key),
|
||||
update: async (key: string, value: unknown) => { values.set(key, value); },
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
describe('VS Code permission auto-accept policy bridge', () => {
|
||||
test('persists policy and broadcasts the authoritative snapshot', async () => {
|
||||
const context = createContext();
|
||||
const broadcasts: unknown[] = [];
|
||||
const dependencies = { broadcast: async (snapshot: unknown) => { broadcasts.push(snapshot); } };
|
||||
const response = await handlePermissionAutoAcceptBridgeMessage({
|
||||
id: '1',
|
||||
type: 'api:permission-auto-accept:set',
|
||||
payload: { sessionId: 'root', enabled: true },
|
||||
}, context, dependencies);
|
||||
|
||||
assert.equal(response?.success, true);
|
||||
assert.deepEqual(response?.data, { sessions: { root: true } });
|
||||
assert.deepEqual(broadcasts, [{ sessions: { root: true } }]);
|
||||
|
||||
const reloaded = await handlePermissionAutoAcceptBridgeMessage({
|
||||
id: '2',
|
||||
type: 'api:permission-auto-accept:get',
|
||||
}, context, dependencies);
|
||||
assert.deepEqual(reloaded?.data, { sessions: { root: true } });
|
||||
});
|
||||
|
||||
test('rejects malformed policy writes', async () => {
|
||||
const broadcasts: unknown[] = [];
|
||||
const response = await handlePermissionAutoAcceptBridgeMessage({
|
||||
id: '1',
|
||||
type: 'api:permission-auto-accept:set',
|
||||
payload: { sessionId: 'root', enabled: 'yes' },
|
||||
}, createContext(), { broadcast: async (snapshot) => { broadcasts.push(snapshot); } });
|
||||
|
||||
assert.equal(response?.success, false);
|
||||
assert.deepEqual(broadcasts, []);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user