Skip to content

Commit 46c9da1

Browse files
committed
chore(build-notes): merge staging
2 parents 305b1f3 + b660380 commit 46c9da1

15 files changed

Lines changed: 678 additions & 114 deletions

File tree

‎apps/desktop/src/main/browser-agent/driver.test.ts‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,115 @@ describe('executeTool', () => {
10201020
}
10211021
)
10221022

1023+
describe('a tab still loading its first page', () => {
1024+
const openLoadingTab = async () => {
1025+
await driver.executeTool('chat-test', 'browser_open_tab', {})
1026+
const contents = session.requireTab().view.webContents
1027+
vi.mocked(contents.getURL).mockReturnValue('')
1028+
vi.mocked(contents.isLoading).mockReturnValue(true)
1029+
const listeners = (event: string) =>
1030+
vi
1031+
.mocked(contents.on)
1032+
.mock.calls.filter(([name]) => String(name) === event)
1033+
.map(([, listener]) => listener as (...args: unknown[]) => void)
1034+
const registered = listeners('did-stop-loading').length
1035+
const waiting = () =>
1036+
vi.waitFor(() => expect(listeners('did-stop-loading').length).toBeGreaterThan(registered))
1037+
return { contents, listeners, registered, waiting }
1038+
}
1039+
1040+
it('snapshots the page once it commits instead of calling the tab blank', async () => {
1041+
const { contents, listeners, registered, waiting } = await openLoadingTab()
1042+
vi.mocked(contents.executeJavaScript).mockResolvedValue({
1043+
url: 'http://127.0.0.1/popup',
1044+
title: 'popup',
1045+
outline: '- link "Open popup" [ref=0]',
1046+
truncated: false,
1047+
refIds: [0],
1048+
refLineIndexes: { 0: 0 },
1049+
nextElementId: 1,
1050+
})
1051+
1052+
const snapshot = driver.executeTool('chat-test', 'browser_snapshot', {})
1053+
await waiting()
1054+
expect(contents.executeJavaScript).not.toHaveBeenCalled()
1055+
1056+
vi.mocked(contents.getURL).mockReturnValue('http://127.0.0.1/popup')
1057+
vi.mocked(contents.isLoading).mockReturnValue(false)
1058+
for (const onNavigate of listeners('did-navigate')) onNavigate({}, 'http://127.0.0.1/popup')
1059+
for (const onLoaded of listeners('did-stop-loading').slice(registered)) onLoaded()
1060+
1061+
await expect(snapshot).resolves.toMatchObject({
1062+
ok: true,
1063+
result: { outline: expect.stringContaining('Open popup') },
1064+
})
1065+
})
1066+
1067+
it('never acts on the page when the action is cancelled during the wait', async () => {
1068+
const { contents, listeners, registered, waiting } = await openLoadingTab()
1069+
1070+
const scroll = driver.executeTool(
1071+
'chat-test',
1072+
'browser_scroll',
1073+
{ direction: 'down' },
1074+
'scroll-into-loading-popup'
1075+
)
1076+
await waiting()
1077+
expect(driver.cancelTool('chat-test', 'scroll-into-loading-popup')).toBe(true)
1078+
await expect(scroll).resolves.toMatchObject({
1079+
ok: false,
1080+
error: expect.stringContaining('cancelled'),
1081+
})
1082+
1083+
// The page commits after the cancel; a wait that ignored the cancel would act on it now.
1084+
vi.mocked(contents.getURL).mockReturnValue('http://127.0.0.1/popup')
1085+
vi.mocked(contents.isLoading).mockReturnValue(false)
1086+
for (const onLoaded of listeners('did-stop-loading').slice(registered)) onLoaded()
1087+
await driver.executeTool('chat-test', 'browser_list_tabs', {})
1088+
expect(contents.executeJavaScript).not.toHaveBeenCalled()
1089+
expect(contents.debugger.sendCommand).not.toHaveBeenCalledWith(
1090+
'Input.dispatchMouseEvent',
1091+
expect.anything()
1092+
)
1093+
})
1094+
1095+
it('refuses a page that outlasts the bounded wait, and never acts on it once it loads', async () => {
1096+
const { contents, listeners, registered } = await openLoadingTab()
1097+
const watchdogMs = driver.browserToolWatchdogMs('browser_scroll', { direction: 'down' })
1098+
const navigationTimeoutMs = 25_000
1099+
const waitMs =
1100+
watchdogMs === null
1101+
? navigationTimeoutMs
1102+
: Math.min(navigationTimeoutMs, Math.floor(watchdogMs / 2))
1103+
vi.useFakeTimers()
1104+
try {
1105+
let outcome: unknown
1106+
void driver
1107+
.executeTool('chat-test', 'browser_scroll', { direction: 'down' }, 'scroll-slow-popup')
1108+
.then((result) => {
1109+
outcome = result
1110+
})
1111+
await vi.advanceTimersByTimeAsync(0)
1112+
expect(listeners('did-stop-loading').length).toBeGreaterThan(registered)
1113+
1114+
await vi.advanceTimersByTimeAsync(waitMs + 1)
1115+
expect(outcome).toEqual({
1116+
ok: false,
1117+
error:
1118+
'The active tab is blank. Call browser_navigate before using page inspection or interaction tools.',
1119+
})
1120+
1121+
vi.mocked(contents.getURL).mockReturnValue('http://127.0.0.1/popup')
1122+
vi.mocked(contents.isLoading).mockReturnValue(false)
1123+
for (const onLoaded of listeners('did-stop-loading').slice(registered)) onLoaded()
1124+
await vi.advanceTimersByTimeAsync(0)
1125+
expect(contents.executeJavaScript).not.toHaveBeenCalled()
1126+
} finally {
1127+
vi.useRealTimers()
1128+
}
1129+
})
1130+
})
1131+
10231132
it('leaves no watchdog timer pending once a tool finishes', async () => {
10241133
vi.useFakeTimers()
10251134
try {

‎apps/desktop/src/main/browser-agent/driver.ts‎

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,11 +1633,16 @@ function unwrapPageResult(result: unknown): unknown {
16331633
return result
16341634
}
16351635

1636-
function waitForLoadComplete(contents: WebContents, timeoutMs: number): Promise<void> {
1636+
function waitForLoadComplete(
1637+
contents: WebContents,
1638+
timeoutMs: number,
1639+
signal?: AbortSignal
1640+
): Promise<void> {
16371641
return new Promise((resolve, reject) => {
16381642
let settled = false
16391643
let sawStart = contents.isLoading()
16401644
const cleanup = () => {
1645+
signal?.removeEventListener('abort', finish)
16411646
contents.removeListener('did-start-loading', start)
16421647
contents.removeListener('did-stop-loading', finish)
16431648
contents.removeListener('did-fail-load', fail)
@@ -1688,9 +1693,60 @@ function waitForLoadComplete(contents: WebContents, timeoutMs: number): Promise<
16881693
contents.on('did-stop-loading', finish)
16891694
contents.on('did-fail-load', fail)
16901695
contents.on('destroyed', destroyed)
1696+
signal?.addEventListener('abort', finish)
16911697
})
16921698
}
16931699

1700+
/** Tools that read or act in the page itself, which a tab with no page yet cannot serve. */
1701+
const BROWSER_TOOL_USES_PAGE = {
1702+
browser_navigate: false,
1703+
browser_open_url: false,
1704+
browser_go_back: false,
1705+
browser_go_forward: false,
1706+
browser_reload: false,
1707+
browser_open_tab: false,
1708+
browser_switch_tab: false,
1709+
browser_close_tab: false,
1710+
browser_list_tabs: false,
1711+
browser_list_sessions: false,
1712+
browser_list_downloads: false,
1713+
browser_save_download: false,
1714+
browser_wait_for: true,
1715+
browser_snapshot: true,
1716+
browser_find: true,
1717+
browser_read_text: true,
1718+
browser_screenshot: true,
1719+
browser_extract: true,
1720+
browser_click: true,
1721+
browser_click_at: true,
1722+
browser_type: true,
1723+
browser_fill_form: true,
1724+
browser_batch: true,
1725+
browser_insert_text: true,
1726+
browser_press_key: true,
1727+
browser_scroll: true,
1728+
browser_select_option: true,
1729+
browser_set_checked: true,
1730+
browser_upload_file: true,
1731+
browser_hover: true,
1732+
browser_drag: true,
1733+
browser_zoom: false,
1734+
browser_request_takeover: false,
1735+
} as const satisfies Readonly<Record<BrowserToolName, boolean>>
1736+
1737+
/**
1738+
* A tab a link or popup just opened reports no URL until its first page commits, so a page tool
1739+
* reaching it first would refuse it as blank. Returns the wait for that first load, run before the
1740+
* action records any page state, or null when the agent's tab already has a page.
1741+
*/
1742+
function firstPageLoad(signal: AbortSignal, maxWaitMs: number): Promise<void> | null {
1743+
const contents = session.automationTab()?.view.webContents
1744+
if (!contents || contents.isDestroyed() || !contents.isLoading()) return null
1745+
const url = contents.getURL()
1746+
if (url !== '' && url !== 'about:blank') return null
1747+
return waitForLoadComplete(contents, maxWaitMs, signal)
1748+
}
1749+
16941750
async function navigationResult(
16951751
contents: WebContents,
16961752
completion = waitForLoadComplete(contents, NAVIGATION_TIMEOUT_MS)
@@ -5454,6 +5510,22 @@ export async function executeTool(
54545510
: Math.min(USER_TAKEOVER_MAX_WAIT_MS, Math.floor(watchdogMs / 2))
54555511
)
54565512
}
5513+
const firstPage = BROWSER_TOOL_USES_PAGE[tool]
5514+
? firstPageLoad(
5515+
executionController.signal,
5516+
watchdogMs === null
5517+
? NAVIGATION_TIMEOUT_MS
5518+
: Math.min(NAVIGATION_TIMEOUT_MS, Math.floor(watchdogMs / 2))
5519+
)
5520+
: null
5521+
if (firstPage) {
5522+
// Raced with the cancellation so its rejection is observed; a cancel aborts the wait
5523+
// before it rejects, which is why the abort is checked again afterwards.
5524+
await Promise.race([firstPage, cancellation])
5525+
if (executionController.signal.aborted) {
5526+
throw new ToolError('This browser action was cancelled.')
5527+
}
5528+
}
54575529
const response = dialogResponse(tool, params)
54585530
state.dialogResponse = response
54595531
? { contents: session.requireAutomationTab().view.webContents, response }

‎apps/docs/content/docs/platform/enterprise/scim/index.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ Sim tracks grants made through directory mappings. Removing a member from a grou
170170

171171
Other directory mappings and independent access can still keep the person in a workspace. Removing a permission-group membership changes their governing policy; it does not remove workspace access. Sim then uses another applicable workspace policy, the organization default, or no permission-group restrictions if neither exists. An empty mapped group applies to nobody and never turns into an all-members policy. Verify both workspace access and the fallback policy when testing a removal.
172172

173-
**Lock managed membership** is enabled by default on a new connection. It makes the directory authoritative for provisioned members: Sim refuses manual invitations, workspace grants, workspace role changes, and organization role changes for them. Manual access already held when a mapping begins covering it becomes directory-managed and is withdrawn with that mapping. Administrators can still remove access in an emergency.
173+
**Lock managed membership** is enabled by default on a new connection. It makes the directory authoritative for provisioned members: Sim refuses manual organization invitations and organization role changes for them, and manual grants and role changes on any workspace one of their groups is mapped to. Other workspace access stays shareable by hand, since the directory does not manage it. To have the directory own a member's access to a workspace, map one of their groups to it. Manual access already held when a mapping begins covering it becomes directory-managed and is withdrawn with that mapping. Administrators can still remove access in an emergency.
174174

175175
The lock does not prevent editing permission-group membership directly in Sim. A manual removal can be restored by reconciliation, and a manual addition to an overlapping policy can block a directory assignment. Manage mapped policy membership through the directory and check **Group mappings** for unassigned members after resolving conflicts.
176176

177177
With locking off, prior manual workspace access is preserved. If a member had manual Read access and a directory mapping raises it to Admin, removing the mapping restores Read. A role manually raised above the directory's level also remains. [Older grants have a baseline limitation](#deployment-and-upgrades).
178178

179-
You can manually invite people the directory does not manage. For managed members with locking on, grant access through directory groups.
179+
You can manually invite people the directory does not manage. For managed members with locking on, change access to workspaces their groups are mapped to through the directory; share other workspaces with them as usual.
180180

181181
## Provisioning and SSO together
182182

‎apps/docs/content/docs/platform/enterprise/scim/okta.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ For example, use `Sim users` to assign the app and `Finance` as the pushed group
118118

119119
<Image src="/static/enterprise/okta/group-push.png" alt="Header Auth Test App Group Push selecting an engineering group and Create Group for the downstream group" width={1001} height={927} maxWidth="xl" className="mx-auto h-auto w-full" />
120120

121-
With **Lock managed membership** enabled, Sim blocks manual invitations and grants for provisioned members. Read [How access is withdrawn](/platform/enterprise/scim#how-access-is-withdrawn) before mapping groups that overlap existing manual access.
121+
With **Lock managed membership** enabled, Sim blocks manual grants for provisioned members on workspaces their groups are mapped to. Read [How access is withdrawn](/platform/enterprise/scim#how-access-is-withdrawn) before mapping groups that overlap existing manual access.
122122

123123
## Rotate a token
124124

‎apps/sim/app/api/workspaces/[id]/permissions/route.test.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import {
2424
} from '@sim/testing/mocks/workspace-context.mock'
2525
import { beforeEach, describe, expect, it, vi } from 'vitest'
2626

27-
const { mockAssertMembershipNotScimManaged } = vi.hoisted(() => ({
28-
mockAssertMembershipNotScimManaged: vi.fn(),
27+
const { mockAssertWorkspaceAccessNotScimManaged } = vi.hoisted(() => ({
28+
mockAssertWorkspaceAccessNotScimManaged: vi.fn(),
2929
}))
3030

3131
vi.mock('@/ee/scim/lib/managed-membership', () => ({
32-
assertMembershipNotScimManaged: mockAssertMembershipNotScimManaged,
32+
assertWorkspaceAccessNotScimManaged: mockAssertWorkspaceAccessNotScimManaged,
3333
}))
3434

3535
vi.mock('@sim/audit', () => auditMock)
@@ -441,7 +441,7 @@ describe('workspace permissions route', () => {
441441

442442
it('refuses a role change for a member the directory manages', async () => {
443443
queueOrgWorkspace([], [permissionRow(MEMBER_ID, 'read')])
444-
mockAssertMembershipNotScimManaged.mockRejectedValueOnce(
444+
mockAssertWorkspaceAccessNotScimManaged.mockRejectedValueOnce(
445445
new ForbiddenOperationError('SCIM_MANAGED_MEMBERSHIP', 'Managed by the directory')
446446
)
447447

@@ -452,8 +452,12 @@ describe('workspace permissions route', () => {
452452

453453
expect(response.status).toBe(403)
454454
await expect(response.json()).resolves.toMatchObject({ error: 'Managed by the directory' })
455-
expect(mockAssertMembershipNotScimManaged).toHaveBeenCalledWith(
456-
expect.objectContaining({ organizationId: ORG_ID, userId: MEMBER_ID })
455+
expect(mockAssertWorkspaceAccessNotScimManaged).toHaveBeenCalledWith(
456+
expect.objectContaining({
457+
organizationId: ORG_ID,
458+
userId: MEMBER_ID,
459+
workspaceIds: [WORKSPACE_ID],
460+
})
457461
)
458462
expect(dbChainMockFns.update).not.toHaveBeenCalled()
459463
})

‎apps/sim/ee/scim/components/options.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const SETTING_TOGGLES = [
2222
key: 'lockManualMembership',
2323
label: 'Lock managed membership',
2424
description:
25-
'Prevent manual invitations, role changes, and access grants for provisioned members.',
25+
'Prevent manual organization changes for provisioned members, and manual access changes on workspaces their directory groups are mapped to.',
2626
},
2727
{
2828
key: 'disableJit',

0 commit comments

Comments
 (0)