@bevel-software/platform-core-frontend 0.37.0 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +22 -10
- package/src/core/__tests__/AppChrome.test.tsx +27 -10
- package/src/core/__tests__/ShellRoutes.test.tsx +43 -2
- package/src/core/registry.ts +43 -2
- package/src/core/shell-paths.ts +30 -0
- package/src/lib/api.ts +7 -1
- package/src/modules/auth/__tests__/LoginScreen.test.tsx +9 -0
- package/src/modules/auth/__tests__/useAuthState.test.ts +92 -0
- package/src/modules/auth/components/LoginScreen.tsx +2 -0
- package/src/modules/auth/hooks/useAuthState.ts +4 -1
- package/src/modules/auth/index.ts +2 -0
- package/src/modules/auth/state/accountStorage.ts +32 -0
- package/src/modules/auth/state/tokenAccount.ts +53 -0
- package/src/modules/layout/index.ts +1 -1
- package/src/modules/settings/components/SettingsLayout.tsx +52 -9
- package/src/modules/settings/components/SettingsNav.tsx +24 -3
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +266 -5
- package/src/modules/settings/index.ts +1 -1
- package/src/modules/settings/settings-nav-items.tsx +130 -10
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +20 -5
- package/src/modules/toolbar/commands/actions.tsx +1 -0
- package/src/modules/toolbar/components/ProfileMenu.tsx +13 -1
- package/src/modules/toolbar/components/Toolbar.tsx +3 -2
- package/src/modules/toolbar/components/__tests__/ProfileMenu.app-sections.test.tsx +87 -0
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +1 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +2 -1
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +80 -32
- package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +78 -8
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +10 -3
- package/src/modules/workspace/components/renderers/__tests__/pageConsentMemory.test.ts +177 -0
- package/src/modules/workspace/components/renderers/__tests__/useHtmlToolBridge.test.tsx +249 -23
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +52 -16
- package/src/modules/workspace/components/renderers/pageConsentMemory.ts +75 -0
- package/src/modules/workspace/components/renderers/useHtmlToolBridge.tsx +46 -11
|
@@ -51,6 +51,14 @@ describe('coreCommandActions', () => {
|
|
|
51
51
|
row({ id: 'node-label', label: <b>Fancy</b>, path: '/fancy' }),
|
|
52
52
|
],
|
|
53
53
|
adminItems: [row({ id: 'roles', label: 'App roles', path: '/roles-and-members' })],
|
|
54
|
+
// A row in a section of the app's own, for the holders of a role it defines (here: Ada), admin or not.
|
|
55
|
+
appSections: [
|
|
56
|
+
{
|
|
57
|
+
id: 'infra',
|
|
58
|
+
label: 'Infrastructure only',
|
|
59
|
+
items: [row({ id: 'executors', label: 'Executors', path: '/agents/executors', isShown: (u: { email: string }) => u.email === 'ada@example.com' })],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
54
62
|
};
|
|
55
63
|
const all = coreCommandActions({ apps: APPS, settings });
|
|
56
64
|
|
|
@@ -61,9 +69,15 @@ describe('coreCommandActions', () => {
|
|
|
61
69
|
'Go to Knowledge',
|
|
62
70
|
'Go to Skills & Tools',
|
|
63
71
|
'Settings: Secrets',
|
|
72
|
+
'Settings: Executors',
|
|
64
73
|
]);
|
|
65
74
|
});
|
|
66
75
|
|
|
76
|
+
it('offers a row of the app\'s own section only to whom its isShown names, admin or not', () => {
|
|
77
|
+
const other = ctx({ isAdmin: true, user: { ...USER, email: 'bob@example.com' } });
|
|
78
|
+
expect(labels(visibleActions(all, other))).not.toContain('Settings: Executors');
|
|
79
|
+
});
|
|
80
|
+
|
|
67
81
|
it('adds Invite people and the admin settings for an admin', () => {
|
|
68
82
|
expect(labels(visibleActions(all, ctx({ isAdmin: true })))).toEqual([
|
|
69
83
|
'Create new page',
|
|
@@ -72,6 +86,7 @@ describe('coreCommandActions', () => {
|
|
|
72
86
|
'Go to Knowledge',
|
|
73
87
|
'Go to Skills & Tools',
|
|
74
88
|
'Settings: Secrets',
|
|
89
|
+
'Settings: Executors',
|
|
75
90
|
'Settings: App roles',
|
|
76
91
|
]);
|
|
77
92
|
});
|
|
@@ -96,7 +111,7 @@ describe('coreCommandActions', () => {
|
|
|
96
111
|
const onSelect = vi.fn(({ navigate }: { navigate(to: string): void }) => navigate('/chosen'));
|
|
97
112
|
const [action] = coreCommandActions({
|
|
98
113
|
apps: [],
|
|
99
|
-
settings: { defaultItems: [row({ id: 'x', label: 'X', path: '/declared', onSelect })], adminItems: [] },
|
|
114
|
+
settings: { defaultItems: [row({ id: 'x', label: 'X', path: '/declared', onSelect })], adminItems: [], appSections: [] },
|
|
100
115
|
}).filter((a) => a.id === 'settings:x');
|
|
101
116
|
const c = ctx();
|
|
102
117
|
void action.run(c);
|
|
@@ -109,7 +124,7 @@ describe('coreCommandActions', () => {
|
|
|
109
124
|
const isShown = vi.fn((user: { email: string }) => user.email === 'ada@example.com');
|
|
110
125
|
const actions = coreCommandActions({
|
|
111
126
|
apps: [],
|
|
112
|
-
settings: { defaultItems: [row({ id: 'undo', label: 'Ask again', onSelect: vi.fn(), isShown })], adminItems: [] },
|
|
127
|
+
settings: { defaultItems: [row({ id: 'undo', label: 'Ask again', onSelect: vi.fn(), isShown })], adminItems: [], appSections: [] },
|
|
113
128
|
});
|
|
114
129
|
expect(labels(visibleActions(actions, ctx()))).toContain('Settings: Ask again');
|
|
115
130
|
expect(labels(visibleActions(actions, ctx({ user: { ...USER, email: 'bob@example.com' } })))).not.toContain(
|
|
@@ -125,7 +140,7 @@ describe('coreCommandActions', () => {
|
|
|
125
140
|
|
|
126
141
|
describe('shortcut hints', () => {
|
|
127
142
|
it('come from the table the shortcuts are bound by, and only for bound commands', () => {
|
|
128
|
-
const all = coreCommandActions({ apps: APPS, settings: { defaultItems: [], adminItems: [] } });
|
|
143
|
+
const all = coreCommandActions({ apps: APPS, settings: { defaultItems: [], adminItems: [], appSections: [] } });
|
|
129
144
|
const hint = (id: string) => all.find((a) => a.id === id)?.shortcut;
|
|
130
145
|
expect(hint('new-page')).toEqual({ key: 'c' });
|
|
131
146
|
expect(hint('invite')).toEqual({ key: 'i', shift: true });
|
|
@@ -144,7 +159,7 @@ describe('shortcut hints', () => {
|
|
|
144
159
|
});
|
|
145
160
|
|
|
146
161
|
describe('suggestedActions', () => {
|
|
147
|
-
const all = coreCommandActions({ apps: APPS, settings: { defaultItems: [], adminItems: [] } });
|
|
162
|
+
const all = coreCommandActions({ apps: APPS, settings: { defaultItems: [], adminItems: [], appSections: [] } });
|
|
148
163
|
const suggest = (c: CommandContext) => labels(suggestedActions(visibleActions(all, c), c));
|
|
149
164
|
|
|
150
165
|
it('suggests the commonest verbs and the way to the other app', () => {
|
|
@@ -159,7 +174,7 @@ describe('suggestedActions', () => {
|
|
|
159
174
|
});
|
|
160
175
|
|
|
161
176
|
describe('mergeCommandActions / visibleActions', () => {
|
|
162
|
-
const core = coreCommandActions({ apps: [], settings: { defaultItems: [], adminItems: [] } });
|
|
177
|
+
const core = coreCommandActions({ apps: [], settings: { defaultItems: [], adminItems: [], appSections: [] } });
|
|
163
178
|
|
|
164
179
|
it('puts the registry’s commands after core’s and drops a reused id', () => {
|
|
165
180
|
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
@@ -222,6 +222,7 @@ function settingsActions(settings: MenuSections): CommandAction[] {
|
|
|
222
222
|
};
|
|
223
223
|
return [
|
|
224
224
|
...settings.defaultItems.map((item) => toAction(item, false)),
|
|
225
|
+
...settings.appSections.flatMap((section) => section.items.map((item) => toAction(item, false))),
|
|
225
226
|
...settings.adminItems.map((item) => toAction(item, true)),
|
|
226
227
|
].filter((a): a is CommandAction => a !== null);
|
|
227
228
|
}
|
|
@@ -89,7 +89,7 @@ export function ProfileMenu() {
|
|
|
89
89
|
const navigate = useNavigate();
|
|
90
90
|
const { user, logout } = useAuth();
|
|
91
91
|
const { isAdmin, unreadCount } = useAdmin();
|
|
92
|
-
const { defaultItems, adminItems } = useMenuSections();
|
|
92
|
+
const { defaultItems, adminItems, appSections } = useMenuSections();
|
|
93
93
|
const [open, setOpen] = useState(false);
|
|
94
94
|
// Per-row dialog open flags, keyed by item id. A plain map (rather than one
|
|
95
95
|
// "active dialog" slot) preserves the historical behavior where two dialogs
|
|
@@ -184,6 +184,10 @@ export function ProfileMenu() {
|
|
|
184
184
|
// Rows offered to this person right now (see `AdminMenuItem.isShown`).
|
|
185
185
|
const shownDefaultItems = defaultItems.filter((item) => item.isShown?.(user) ?? true);
|
|
186
186
|
const shownAdminItems = adminItems.filter((item) => item.isShown?.(user) ?? true);
|
|
187
|
+
// The app's sections, each with the rows offered to this person; a section none of whose rows is shown is left out.
|
|
188
|
+
const shownAppSections = appSections
|
|
189
|
+
.map((section) => ({ ...section, items: section.items.filter((item) => item.isShown?.(user) ?? true) }))
|
|
190
|
+
.filter((section) => section.items.length > 0);
|
|
187
191
|
|
|
188
192
|
return (
|
|
189
193
|
<div className="relative">
|
|
@@ -271,6 +275,13 @@ export function ProfileMenu() {
|
|
|
271
275
|
|
|
272
276
|
{shownDefaultItems.map(renderRow)}
|
|
273
277
|
|
|
278
|
+
{shownAppSections.map((section) => (
|
|
279
|
+
<div key={section.id} role="group" aria-labelledby={`profile-menu-section-${section.id}-label`}>
|
|
280
|
+
<MenuLabel id={`profile-menu-section-${section.id}-label`}>{section.label}</MenuLabel>
|
|
281
|
+
{section.items.map(renderRow)}
|
|
282
|
+
</div>
|
|
283
|
+
))}
|
|
284
|
+
|
|
274
285
|
{isAdmin && shownAdminItems.length > 0 && (
|
|
275
286
|
<div role="group" aria-labelledby="profile-menu-admin-section-label">
|
|
276
287
|
<MenuLabel id="profile-menu-admin-section-label">Admin only</MenuLabel>
|
|
@@ -293,6 +304,7 @@ export function ProfileMenu() {
|
|
|
293
304
|
{/* Dialogs opened by the menu rows above. Mounted at the menu root so they
|
|
294
305
|
persist independently of the (transient) dropdown. */}
|
|
295
306
|
{renderDialogs(defaultItems)}
|
|
307
|
+
{renderDialogs(appSections.flatMap((section) => section.items))}
|
|
296
308
|
{isAdmin && renderDialogs(adminItems)}
|
|
297
309
|
</div>
|
|
298
310
|
);
|
|
@@ -7,7 +7,7 @@ import { SearchPalette } from './SearchPalette';
|
|
|
7
7
|
import { useLayout, useMediaQuery, toggleSidebar, useSidebar, TOOLBAR_STACK_QUERY } from '../../layout';
|
|
8
8
|
import { useActiveAppId, useAppRegistry } from '../../../core/registry';
|
|
9
9
|
import { SidebarToggle } from '../../layout/components/SidebarToggle';
|
|
10
|
-
import { isSettingsNavPath } from '../../settings';
|
|
10
|
+
import { isSettingsNavPath, useSettingsNavPaths } from '../../settings';
|
|
11
11
|
import { InviteButton } from '../../onboarding/components/InviteButton';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -50,8 +50,9 @@ export function Toolbar() {
|
|
|
50
50
|
// branch switcher, for one) does not fit alongside the toolbar essentials,
|
|
51
51
|
// so it drops onto a second row instead of overflowing offscreen.
|
|
52
52
|
const isCompact = useMediaQuery(TOOLBAR_STACK_QUERY);
|
|
53
|
+
const settingsPaths = useSettingsNavPaths();
|
|
53
54
|
const hasSidebar =
|
|
54
|
-
onLibrary || canToggleExplorer || (isSettingsNavPath(location.pathname) && !isCompact);
|
|
55
|
+
onLibrary || canToggleExplorer || (isSettingsNavPath(location.pathname, settingsPaths) && !isCompact);
|
|
55
56
|
|
|
56
57
|
// Registry-contributed left-cluster items. The CORE toolbar has none of its
|
|
57
58
|
// own: the branch switcher is an enterprise contribution scoped (by the
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen, within } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
5
|
+
import { AuthContext, type AuthContextValue } from '../../../auth';
|
|
6
|
+
import { AdminContext } from '../../../admin';
|
|
7
|
+
import { AppRegistryContext, makeRegistry, type AdminMenuItem } from '../../../../core/registry';
|
|
8
|
+
import { ProfileMenu } from '../ProfileMenu';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The profile menu with sections of the app's own, as an app contributes them
|
|
12
|
+
* through the registry: a labelled group between the default rows and "Admin
|
|
13
|
+
* only", for whom each row's `isShown` names — admin or not — and no heading
|
|
14
|
+
* for a section none of whose rows is offered.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const INFRA = { id: 'infra', label: 'Infrastructure only', order: 10 };
|
|
18
|
+
const holder = (email: string) => (user: { email: string }) => user.email === email;
|
|
19
|
+
|
|
20
|
+
const rows: AdminMenuItem[] = [
|
|
21
|
+
{ id: 'agents-settings', section: INFRA, label: 'Agents', path: '/agents/settings', isShown: holder('ada@example.com') },
|
|
22
|
+
{ id: 'executors', section: INFRA, order: 5, label: 'Executors', path: '/agents/executors', isShown: holder('ada@example.com') },
|
|
23
|
+
{ id: 'billing', section: { id: 'billing', label: 'Billing only' }, label: 'Invoices', path: '/invoices', isShown: () => false },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
function mount(email: string, isAdmin: boolean) {
|
|
27
|
+
const auth: AuthContextValue = {
|
|
28
|
+
user: { id: 'u', email, name: 'Ada Lovelace', avatarUrl: '' },
|
|
29
|
+
token: 'token',
|
|
30
|
+
isLoading: false,
|
|
31
|
+
login: async () => {},
|
|
32
|
+
logout: () => {},
|
|
33
|
+
};
|
|
34
|
+
render(
|
|
35
|
+
<MemoryRouter>
|
|
36
|
+
<AppRegistryContext.Provider value={makeRegistry({ adminMenuItems: rows })}>
|
|
37
|
+
<AuthContext.Provider value={auth}>
|
|
38
|
+
<AdminContext.Provider
|
|
39
|
+
value={{
|
|
40
|
+
isAdmin,
|
|
41
|
+
unreadCount: 0,
|
|
42
|
+
lastSeen: null,
|
|
43
|
+
markSeen: () => {},
|
|
44
|
+
refresh: () => {},
|
|
45
|
+
rolesConfigCorrupted: false,
|
|
46
|
+
rolesConfigErrors: [],
|
|
47
|
+
runRolesRecovery: async () => {},
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<ProfileMenu />
|
|
51
|
+
</AdminContext.Provider>
|
|
52
|
+
</AuthContext.Provider>
|
|
53
|
+
</AppRegistryContext.Provider>
|
|
54
|
+
</MemoryRouter>,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('ProfileMenu: the app\'s own sections', () => {
|
|
59
|
+
it('draws the section for a person its rows are for, admin or not, its rows in their order', async () => {
|
|
60
|
+
mount('ada@example.com', false);
|
|
61
|
+
await userEvent.click(screen.getByRole('button', { name: 'Ada Lovelace' }));
|
|
62
|
+
const section = screen.getByRole('group', { name: 'Infrastructure only' });
|
|
63
|
+
expect(within(section).getAllByRole('button').map((b) => b.textContent)).toEqual(['Executors', 'Agents']);
|
|
64
|
+
// Not an admin: no Admin only section, and the section nobody is offered has no heading.
|
|
65
|
+
expect(screen.queryByText('Admin only')).toBeNull();
|
|
66
|
+
expect(screen.queryByText('Billing only')).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('draws it for an admin its rows are for too, after the default rows and before Admin only', async () => {
|
|
70
|
+
mount('ada@example.com', true);
|
|
71
|
+
await userEvent.click(screen.getByRole('button', { name: 'Ada Lovelace' }));
|
|
72
|
+
const section = screen.getByRole('group', { name: 'Infrastructure only' });
|
|
73
|
+
const lastDefault = screen.getByRole('button', { name: 'Account' });
|
|
74
|
+
const adminHeading = screen.getByText('Admin only');
|
|
75
|
+
expect(within(section).getAllByRole('button').map((b) => b.textContent)).toEqual(['Executors', 'Agents']);
|
|
76
|
+
expect(lastDefault.compareDocumentPosition(section) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
77
|
+
expect(section.compareDocumentPosition(adminHeading) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('draws nothing of it for anyone else, even an admin', async () => {
|
|
81
|
+
mount('bob@example.com', true);
|
|
82
|
+
await userEvent.click(screen.getByRole('button', { name: 'Ada Lovelace' }));
|
|
83
|
+
expect(screen.queryByText('Infrastructure only')).toBeNull();
|
|
84
|
+
expect(screen.queryByRole('button', { name: 'Executors' })).toBeNull();
|
|
85
|
+
expect(screen.getByText('Admin only')).toBeInTheDocument();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -21,6 +21,7 @@ vi.mock('../../../settings/settings-nav-items', () => ({
|
|
|
21
21
|
useMenuSections: () => ({
|
|
22
22
|
defaultItems: [{ id: 'account', label: 'Account', path: '/account' }],
|
|
23
23
|
adminItems: [hidden('hidden-a', 'Hidden A'), hidden('hidden-b', 'Hidden B')],
|
|
24
|
+
appSections: [],
|
|
24
25
|
}),
|
|
25
26
|
}));
|
|
26
27
|
|
|
@@ -94,7 +94,8 @@ export function HtmlRenderer({
|
|
|
94
94
|
// chase it; and a distribution's document carries its inlined libraries,
|
|
95
95
|
// which a key built from it would compare on every render.
|
|
96
96
|
const viewKey = useMemo(() => ({ reloadKey, mode, savedValue, filePath }), [reloadKey, mode, savedValue, filePath]);
|
|
97
|
-
|
|
97
|
+
// The source a preview's document is built from is the saved content.
|
|
98
|
+
const { toolBridge, cards } = useHtmlToolBridge({ iframeRef, filePath, viewKey, source: savedValue });
|
|
98
99
|
|
|
99
100
|
const dirty = !readOnly && value !== savedValue;
|
|
100
101
|
|
|
@@ -2,9 +2,11 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
2
2
|
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
3
3
|
import { MemoryRouter } from 'react-router-dom';
|
|
4
4
|
import { OpenPageInPlatformContext, PageToolsContext, RendererSurfaceContext, getFileRenderer, type RendererSurface } from '..';
|
|
5
|
+
import { AuthContext, type AuthContextValue } from '../../../../auth';
|
|
5
6
|
import { GitContext, type GitContextValue } from '../../../../git';
|
|
6
7
|
import { clearToken, setToken } from '../../../../../lib/api';
|
|
7
8
|
import { WorkspaceContext, type WorkspaceContextValue } from '../../../state/workspace.context';
|
|
9
|
+
import { sha256Hex } from '@bevel-software/platform-shared';
|
|
8
10
|
import { frameChannel, stubServer } from './pageToolsHarness';
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -17,9 +19,25 @@ import { frameChannel, stubServer } from './pageToolsHarness';
|
|
|
17
19
|
const HtmlRenderer = getFileRenderer('Dashboards/Roadmap.html');
|
|
18
20
|
const PATH = 'knowledge-base/Dashboards/Roadmap.html';
|
|
19
21
|
const PAGE = 'Dashboards/Roadmap.html';
|
|
22
|
+
const CARD = "You're allowing changes using your account. Do you want to allow that?";
|
|
20
23
|
|
|
21
24
|
const workspace = { workspaceId: 'main', kbDirName: 'knowledge-base' } as unknown as WorkspaceContextValue;
|
|
22
25
|
const git = { status: { branch: 'main' } } as unknown as GitContextValue;
|
|
26
|
+
/** The account on the file page, as the app's auth gate carries it above the renderer. */
|
|
27
|
+
const auth = { user: { id: 'user-a' } } as unknown as AuthContextValue;
|
|
28
|
+
/** user-a's session token, as the server signs it: a JWT whose `userId` claim names the account (the signature is not checked here). */
|
|
29
|
+
const VIEWER_SESSION = (() => {
|
|
30
|
+
const part = (value: object) => btoa(JSON.stringify(value)).replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
31
|
+
return `${part({ alg: 'HS256', typ: 'JWT' })}.${part({ userId: 'user-a', email: 'user-a@example.com' })}.signature`;
|
|
32
|
+
})();
|
|
33
|
+
/** Where the browser keeps the account's Allow: one entry per digest, holding when it was allowed. */
|
|
34
|
+
const ALLOWED_PAGE_KEY_PREFIX = 'bevel.account/user-a/htmlPage.allowedWrite.';
|
|
35
|
+
/** The digests stored in localStorage, least recently allowed first: read through the storage API, as another tab would. */
|
|
36
|
+
const rememberedDigests = (): string[] =>
|
|
37
|
+
Array.from({ length: window.localStorage.length }, (_, i) => window.localStorage.key(i)!)
|
|
38
|
+
.filter((key) => key.startsWith(ALLOWED_PAGE_KEY_PREFIX) && Number.isFinite(Number(window.localStorage.getItem(key))))
|
|
39
|
+
.sort((a, b) => Number(window.localStorage.getItem(a)) - Number(window.localStorage.getItem(b)))
|
|
40
|
+
.map((key) => key.slice(ALLOWED_PAGE_KEY_PREFIX.length));
|
|
23
41
|
|
|
24
42
|
/**
|
|
25
43
|
* The page on the app's file page: in the app, with the file page's provider.
|
|
@@ -27,16 +45,20 @@ const git = { status: { branch: 'main' } } as unknown as GitContextValue;
|
|
|
27
45
|
* save arriving): the same frame, a new document in it.
|
|
28
46
|
*/
|
|
29
47
|
function onFilePage({ readOnly = true }: { readOnly?: boolean } = {}) {
|
|
48
|
+
// Signed in as user-a: its session token is the stored one.
|
|
49
|
+
setToken(VIEWER_SESSION);
|
|
30
50
|
const tree = (content: string) => (
|
|
31
|
-
<
|
|
32
|
-
<
|
|
33
|
-
<
|
|
34
|
-
<
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
<AuthContext.Provider value={auth}>
|
|
52
|
+
<MemoryRouter initialEntries={['/workspace/main/knowledge-base/Dashboards/Roadmap.html']}>
|
|
53
|
+
<WorkspaceContext.Provider value={workspace}>
|
|
54
|
+
<GitContext.Provider value={git}>
|
|
55
|
+
<PageToolsContext.Provider value={{ pagePath: PAGE }}>
|
|
56
|
+
<HtmlRenderer content={content} filePath={PATH} onSave={async () => undefined} readOnly={readOnly} />
|
|
57
|
+
</PageToolsContext.Provider>
|
|
58
|
+
</GitContext.Provider>
|
|
59
|
+
</WorkspaceContext.Provider>
|
|
60
|
+
</MemoryRouter>
|
|
61
|
+
</AuthContext.Provider>
|
|
40
62
|
);
|
|
41
63
|
const result = render(tree('<h1>Roadmap</h1>'));
|
|
42
64
|
return { ...result, receive: (content: string) => result.rerender(tree(content)) };
|
|
@@ -118,41 +140,45 @@ describe('the consent card on the file page', () => {
|
|
|
118
140
|
frame.post({ type: 'bevel.tool.call', requestId: 'r1', fn: 'callTool', args: ['read_file', {}] });
|
|
119
141
|
await waitFor(() => expect(frame.replies).toEqual([{ type: 'bevel.tool.response', requestId: 'r1', ok: true, result: { ran: 'read_file' } }]));
|
|
120
142
|
expect(server.mcp).toEqual(['read_file']);
|
|
121
|
-
expect(screen.queryByText(
|
|
143
|
+
expect(screen.queryByText(CARD)).toBeNull();
|
|
122
144
|
});
|
|
123
145
|
|
|
124
|
-
it('asks on the first write with the page\'s
|
|
146
|
+
it('asks on the first write in the plain sentence with the page\'s path; Allow runs it and holds for the view', async () => {
|
|
125
147
|
const server = stubServer();
|
|
126
148
|
const { container } = onFilePage();
|
|
127
149
|
const frame = frameChannel(await frameOf(container));
|
|
128
150
|
frame.post({ type: 'bevel.tool.call', requestId: 'w1', fn: 'callTool', args: ['edit_file', {}] });
|
|
129
|
-
expect(await screen.findByText(
|
|
151
|
+
expect(await screen.findByText(CARD)).toBeTruthy();
|
|
130
152
|
expect(screen.getByText(PAGE)).toBeTruthy();
|
|
131
153
|
expect(server.mcp).toEqual([]);
|
|
132
154
|
|
|
133
|
-
fireEvent.click(screen.getByRole('button', { name: 'Allow
|
|
155
|
+
fireEvent.click(screen.getByRole('button', { name: 'Allow' }));
|
|
134
156
|
await waitFor(() => expect(frame.replies.at(-1)).toMatchObject({ requestId: 'w1', ok: true, result: { ran: 'edit_file' } }));
|
|
135
157
|
|
|
136
158
|
frame.post({ type: 'bevel.tool.call', requestId: 'w2', fn: 'callToolChain', args: ['return 1'] });
|
|
137
159
|
await waitFor(() => expect(frame.replies.at(-1)).toMatchObject({ requestId: 'w2', ok: true }));
|
|
138
|
-
expect(screen.queryByText(
|
|
160
|
+
expect(screen.queryByText(CARD)).toBeNull();
|
|
139
161
|
expect(server.mcp).toEqual(['edit_file', 'call_tool_chain']);
|
|
140
162
|
});
|
|
141
163
|
|
|
142
|
-
it('
|
|
164
|
+
it("Don't allow answers denied and runs nothing; the next write asks again; a reload after an Allow asks nothing", async () => {
|
|
143
165
|
const server = stubServer();
|
|
144
166
|
const { container } = onFilePage();
|
|
145
167
|
const frame = frameChannel(await frameOf(container));
|
|
146
168
|
frame.post({ type: 'bevel.tool.call', requestId: 'w1', fn: 'callTool', args: ['edit_file', {}] });
|
|
147
|
-
fireEvent.click(await screen.findByRole('button', { name: '
|
|
169
|
+
fireEvent.click(await screen.findByRole('button', { name: "Don't allow" }));
|
|
148
170
|
await waitFor(() => expect(frame.replies.at(-1)).toEqual({ type: 'bevel.tool.response', requestId: 'w1', ok: false, error: 'denied', code: 'denied' }));
|
|
149
171
|
expect(server.mcp).toEqual([]);
|
|
172
|
+
expect(window.localStorage.getItem(ALLOWED_PAGE_KEY_PREFIX + sha256Hex('<h1>Roadmap</h1>'))).toBeNull();
|
|
173
|
+
expect(Array.from({ length: window.localStorage.length }, (_, i) => window.localStorage.key(i)!).filter((key) => key.startsWith(ALLOWED_PAGE_KEY_PREFIX))).toEqual([]);
|
|
150
174
|
|
|
151
175
|
frame.post({ type: 'bevel.tool.call', requestId: 'w2', fn: 'callTool', args: ['edit_file', {}] });
|
|
152
|
-
fireEvent.click(await screen.findByRole('button', { name: 'Allow
|
|
176
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Allow' }));
|
|
153
177
|
await waitFor(() => expect(frame.replies.at(-1)).toMatchObject({ requestId: 'w2', ok: true }));
|
|
178
|
+
// The digest of the source the renderer received, not of the document it built.
|
|
179
|
+
expect(rememberedDigests()).toEqual([sha256Hex('<h1>Roadmap</h1>')]);
|
|
154
180
|
|
|
155
|
-
// Reload the page: a new view, a new frame window, and
|
|
181
|
+
// Reload the page: a new view, a new frame window, and no card for the same source.
|
|
156
182
|
fireEvent.click(screen.getByTitle('Reload preview'));
|
|
157
183
|
const reloaded = frameChannel(await waitFor(() => {
|
|
158
184
|
const el = container.querySelector('iframe')!;
|
|
@@ -160,15 +186,16 @@ describe('the consent card on the file page', () => {
|
|
|
160
186
|
return el;
|
|
161
187
|
}));
|
|
162
188
|
reloaded.post({ type: 'bevel.tool.call', requestId: 'w3', fn: 'callTool', args: ['edit_file', {}] });
|
|
163
|
-
|
|
189
|
+
await waitFor(() => expect(reloaded.replies.at(-1)).toMatchObject({ requestId: 'w3', ok: true }));
|
|
190
|
+
expect(screen.queryByText(CARD)).toBeNull();
|
|
164
191
|
});
|
|
165
192
|
|
|
166
|
-
it('asks
|
|
193
|
+
it('asks nothing after Edit and back to Preview: the source is the same', async () => {
|
|
167
194
|
stubServer();
|
|
168
195
|
const { container } = onFilePage({ readOnly: false });
|
|
169
196
|
const frame = frameChannel(await frameOf(container));
|
|
170
197
|
frame.post({ type: 'bevel.tool.call', requestId: 'w1', fn: 'callTool', args: ['edit_file', {}] });
|
|
171
|
-
fireEvent.click(await screen.findByRole('button', { name: 'Allow
|
|
198
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Allow' }));
|
|
172
199
|
await waitFor(() => expect(frame.replies.at(-1)).toMatchObject({ requestId: 'w1', ok: true }));
|
|
173
200
|
|
|
174
201
|
fireEvent.click(screen.getByRole('button', { name: 'Edit' }));
|
|
@@ -176,7 +203,28 @@ describe('the consent card on the file page', () => {
|
|
|
176
203
|
fireEvent.click(screen.getByRole('button', { name: 'Preview' }));
|
|
177
204
|
const back = frameChannel(await frameOf(container));
|
|
178
205
|
back.post({ type: 'bevel.tool.call', requestId: 'w2', fn: 'callTool', args: ['edit_file', {}] });
|
|
179
|
-
|
|
206
|
+
await waitFor(() => expect(back.replies.at(-1)).toMatchObject({ requestId: 'w2', ok: true }));
|
|
207
|
+
expect(screen.queryByText(CARD)).toBeNull();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('asks again when one character of the source changed, and keeps the earlier Allow', async () => {
|
|
211
|
+
stubServer();
|
|
212
|
+
const { container, receive } = onFilePage();
|
|
213
|
+
const frame = frameChannel(await frameOf(container));
|
|
214
|
+
frame.post({ type: 'bevel.tool.call', requestId: 'w1', fn: 'callTool', args: ['edit_file', {}] });
|
|
215
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Allow' }));
|
|
216
|
+
await waitFor(() => expect(frame.replies.at(-1)).toMatchObject({ requestId: 'w1', ok: true }));
|
|
217
|
+
|
|
218
|
+
receive('<h1>Roadmap!</h1>');
|
|
219
|
+
const changed = frameChannel(await frameOf(container));
|
|
220
|
+
changed.post({ type: 'bevel.tool.call', requestId: 'w2', fn: 'callTool', args: ['edit_file', {}] });
|
|
221
|
+
expect(await screen.findByText(CARD)).toBeTruthy();
|
|
222
|
+
fireEvent.click(screen.getByRole('button', { name: 'Allow' }));
|
|
223
|
+
await waitFor(() => expect(changed.replies.at(-1)).toMatchObject({ requestId: 'w2', ok: true }));
|
|
224
|
+
expect(rememberedDigests()).toEqual([
|
|
225
|
+
sha256Hex('<h1>Roadmap</h1>'),
|
|
226
|
+
sha256Hex('<h1>Roadmap!</h1>'),
|
|
227
|
+
]);
|
|
180
228
|
});
|
|
181
229
|
|
|
182
230
|
it('answers requireTools true with nothing shown', async () => {
|
|
@@ -222,23 +270,23 @@ describe('an upload from the file page', () => {
|
|
|
222
270
|
const file = () => new File([new Uint8Array([0x50, 0x4b, 0x03, 0x04])], 'Assets.xlsx');
|
|
223
271
|
|
|
224
272
|
it('asks with the write card, and on Allow runs the three steps in order with the viewer\'s session', async () => {
|
|
225
|
-
setToken(
|
|
273
|
+
setToken(VIEWER_SESSION);
|
|
226
274
|
try {
|
|
227
275
|
const server = stubUploadServer();
|
|
228
276
|
const { container } = onFilePage();
|
|
229
277
|
const frame = frameChannel(await frameOf(container));
|
|
230
278
|
frame.post({ type: 'bevel.tool.call', requestId: 'u1', fn: 'uploadFile', args: [file(), { branch: 'main', destination: 'Data/Campaigns/Easter' }] });
|
|
231
|
-
expect(await screen.findByText(
|
|
279
|
+
expect(await screen.findByText(CARD)).toBeTruthy();
|
|
232
280
|
expect(server.requests).toEqual([]);
|
|
233
281
|
|
|
234
|
-
fireEvent.click(screen.getByRole('button', { name: 'Allow
|
|
282
|
+
fireEvent.click(screen.getByRole('button', { name: 'Allow' }));
|
|
235
283
|
await waitFor(() => expect(frame.replies.at(-1)).toMatchObject({ requestId: 'u1', ok: true, result: { count: 1, destination: 'Data/Campaigns/Easter' } }));
|
|
236
284
|
expect(server.requests.map((r) => r.step)).toEqual([
|
|
237
285
|
'request_file_upload',
|
|
238
286
|
'POST /api/agent/uploads?filename=Assets.xlsx',
|
|
239
287
|
'apply_file_upload',
|
|
240
288
|
]);
|
|
241
|
-
for (const r of server.requests) expect(r.headers.get('Authorization')).toBe(
|
|
289
|
+
for (const r of server.requests) expect(r.headers.get('Authorization')).toBe(`Bearer ${VIEWER_SESSION}`);
|
|
242
290
|
for (const r of server.requests.filter((x) => x.step.endsWith('_upload'))) {
|
|
243
291
|
expect(decodeURIComponent(r.headers.get('X-Bevel-Page')!)).toBe(PAGE);
|
|
244
292
|
}
|
|
@@ -250,18 +298,18 @@ describe('an upload from the file page', () => {
|
|
|
250
298
|
// Allow holds for the view: the next upload runs with no card.
|
|
251
299
|
frame.post({ type: 'bevel.tool.call', requestId: 'u2', fn: 'uploadFile', args: [file(), { branch: 'main', destination: 'Data' }] });
|
|
252
300
|
await waitFor(() => expect(frame.replies.at(-1)).toMatchObject({ requestId: 'u2', ok: true }));
|
|
253
|
-
expect(screen.queryByText(
|
|
301
|
+
expect(screen.queryByText(CARD)).toBeNull();
|
|
254
302
|
} finally {
|
|
255
303
|
clearToken();
|
|
256
304
|
}
|
|
257
305
|
});
|
|
258
306
|
|
|
259
|
-
it('
|
|
307
|
+
it("Don't allow answers denied, uploads nothing, and reports a refused apply_file_upload under the page", async () => {
|
|
260
308
|
const server = stubUploadServer();
|
|
261
309
|
const { container } = onFilePage();
|
|
262
310
|
const frame = frameChannel(await frameOf(container));
|
|
263
311
|
frame.post({ type: 'bevel.tool.call', requestId: 'u1', fn: 'uploadFile', args: [file(), { branch: 'main', destination: 'Data/Campaigns/Easter' }] });
|
|
264
|
-
fireEvent.click(await screen.findByRole('button', { name: '
|
|
312
|
+
fireEvent.click(await screen.findByRole('button', { name: "Don't allow" }));
|
|
265
313
|
await waitFor(() => expect(frame.replies.at(-1)).toEqual({ type: 'bevel.tool.response', requestId: 'u1', ok: false, error: 'denied', code: 'denied' }));
|
|
266
314
|
await waitFor(() => expect(server.requests.map((r) => r.step)).toEqual(['refusal']));
|
|
267
315
|
expect(server.requests[0]!.body).toMatchObject({ page: PAGE, tool: 'apply_file_upload' });
|
|
@@ -350,7 +398,7 @@ describe('a call whose view ended before it was decided', () => {
|
|
|
350
398
|
server.releaseManual();
|
|
351
399
|
await settled();
|
|
352
400
|
|
|
353
|
-
expect(screen.queryByText(
|
|
401
|
+
expect(screen.queryByText(CARD)).toBeNull();
|
|
354
402
|
expect(server.mcp).toEqual([]);
|
|
355
403
|
expect(changed.replies).toEqual([]);
|
|
356
404
|
});
|
|
@@ -362,7 +410,7 @@ describe('a call whose view ended before it was decided', () => {
|
|
|
362
410
|
const frame = frameChannel(iframe);
|
|
363
411
|
// A chain asks without the manual: Allow it, so the view holds an Allow.
|
|
364
412
|
frame.post({ type: 'bevel.tool.call', requestId: 'w1', fn: 'callToolChain', args: ['return 1'] });
|
|
365
|
-
fireEvent.click(await screen.findByRole('button', { name: 'Allow
|
|
413
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Allow' }));
|
|
366
414
|
await waitFor(() => expect(frame.replies.at(-1)).toMatchObject({ requestId: 'w1', ok: true }));
|
|
367
415
|
|
|
368
416
|
frame.post({ type: 'bevel.tool.call', requestId: 'w2', fn: 'callTool', args: ['edit_file', {}] });
|
|
@@ -389,7 +437,7 @@ describe('a call whose view ended before it was decided', () => {
|
|
|
389
437
|
server.releaseManual();
|
|
390
438
|
await settled();
|
|
391
439
|
|
|
392
|
-
expect(screen.queryByText(
|
|
440
|
+
expect(screen.queryByText(CARD)).toBeNull();
|
|
393
441
|
expect(server.mcp).toEqual([]);
|
|
394
442
|
// Neither document hears an answer meant for a view that is gone.
|
|
395
443
|
expect(frame.replies).toEqual([]);
|