refactor: checkTabAccess uses options object, add own-only tab policy

Refactors checkTabAccess(tabId, clientId, isWrite) to use an options
object { isWrite?, ownOnly? }. Adds tabPolicy === 'own-only' support
in the server command dispatch — scoped tokens with this policy are
restricted to their own tabs for all commands, not just writes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-04-06 00:34:32 -07:00
parent 7cf7f6e76e
commit 001ba59be0
3 changed files with 16 additions and 14 deletions

View File

@@ -28,19 +28,19 @@ describe('Tab Isolation', () => {
describe('checkTabAccess', () => {
it('root can always access any tab (read)', () => {
expect(bm.checkTabAccess(1, 'root', false)).toBe(true);
expect(bm.checkTabAccess(1, 'root', { isWrite: false })).toBe(true);
});
it('root can always access any tab (write)', () => {
expect(bm.checkTabAccess(1, 'root', true)).toBe(true);
expect(bm.checkTabAccess(1, 'root', { isWrite: true })).toBe(true);
});
it('any agent can read an unowned tab', () => {
expect(bm.checkTabAccess(1, 'agent-1', false)).toBe(true);
expect(bm.checkTabAccess(1, 'agent-1', { isWrite: false })).toBe(true);
});
it('scoped agent cannot write to unowned tab', () => {
expect(bm.checkTabAccess(1, 'agent-1', true)).toBe(false);
expect(bm.checkTabAccess(1, 'agent-1', { isWrite: true })).toBe(false);
});
it('scoped agent can read another agent tab', () => {
@@ -49,12 +49,12 @@ describe('Tab Isolation', () => {
// with a known owner via the internal state
// We'll use transferTab which only checks pages map... let's test checkTabAccess directly
// checkTabAccess reads from tabOwnership map, which is empty here
expect(bm.checkTabAccess(1, 'agent-2', false)).toBe(true);
expect(bm.checkTabAccess(1, 'agent-2', { isWrite: false })).toBe(true);
});
it('scoped agent cannot write to another agent tab', () => {
// With no ownership set, this is an unowned tab -> denied
expect(bm.checkTabAccess(1, 'agent-2', true)).toBe(false);
expect(bm.checkTabAccess(1, 'agent-2', { isWrite: true })).toBe(false);
});
});