@bevel-software/platform-core-frontend 0.13.6 → 0.15.1
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 +18 -17
- package/src/core/__tests__/bootstrap.test.ts +33 -1
- package/src/core/bootstrap.ts +30 -1
- package/src/lib/__tests__/api.test.ts +38 -0
- package/src/lib/__tests__/utils.test.ts +43 -0
- package/src/lib/api.ts +19 -2
- package/src/lib/utils.ts +17 -7
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +111 -1
- package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
- package/src/modules/access/api.ts +52 -4
- package/src/modules/access/components/ManageAccessDialog.tsx +112 -83
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
- package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
- package/src/modules/layout/components/SidebarFrame.tsx +1 -1
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +2 -1
- package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +1 -1
- package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +121 -0
- package/src/modules/library/__tests__/LockedPluginView.test.tsx +6 -0
- package/src/modules/library/__tests__/McpServerSection.test.tsx +7 -1
- package/src/modules/library/__tests__/NewPluginDialog.test.tsx +5 -4
- package/src/modules/library/__tests__/PluginExtras.test.tsx +15 -0
- package/src/modules/library/__tests__/PluginPage.test.tsx +195 -1
- package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +1 -1
- package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +1 -1
- package/src/modules/library/__tests__/PluginsSidebar.test.tsx +64 -3
- package/src/modules/library/__tests__/SkillPage.test.tsx +9 -2
- package/src/modules/library/__tests__/SkillsTree.test.tsx +172 -0
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +216 -8
- package/src/modules/library/__tests__/ToolPage.test.tsx +23 -3
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +7 -7
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +115 -4
- package/src/modules/library/__tests__/library-data.stale.test.tsx +90 -0
- package/src/modules/library/__tests__/library-paths.test.ts +32 -0
- package/src/modules/library/__tests__/link-membership.test.ts +120 -0
- package/src/modules/library/__tests__/plugin-summary.test.ts +32 -0
- package/src/modules/library/__tests__/status.test.ts +84 -0
- package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +33 -0
- package/src/modules/library/components/LibraryCard.tsx +21 -1
- package/src/modules/library/components/LibraryLayout.tsx +24 -14
- package/src/modules/library/components/LinkSkillPanel.tsx +171 -0
- package/src/modules/library/components/LockedPluginView.tsx +2 -2
- package/src/modules/library/components/NewPluginDialog.tsx +4 -4
- package/src/modules/library/components/PageActions.tsx +21 -1
- package/src/modules/library/components/PersonalPluginPage.tsx +2 -1
- package/src/modules/library/components/PluginExtras.tsx +3 -1
- package/src/modules/library/components/PluginPage.tsx +92 -12
- package/src/modules/library/components/PluginsIndexPage.tsx +11 -6
- package/src/modules/library/components/PluginsSidebar.tsx +110 -53
- package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
- package/src/modules/library/components/SkillsTree.tsx +91 -0
- package/src/modules/library/components/StatusDot.tsx +1 -0
- package/src/modules/library/components/plugin-page-parts.tsx +32 -9
- package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +218 -0
- package/src/modules/library/components/skill-page/SkillPage.tsx +75 -7
- package/src/modules/library/components/tool-page/McpServerSection.tsx +9 -1
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +223 -8
- package/src/modules/library/components/tool-page/ToolPage.tsx +30 -2
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +30 -8
- package/src/modules/library/hooks/useJoinRequests.ts +48 -18
- package/src/modules/library/hooks/useToolPage.ts +28 -11
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +180 -83
- package/src/modules/library/routes/library-paths.ts +21 -8
- package/src/modules/library/services/library.api.ts +55 -1
- package/src/modules/library/services/plugins.api.ts +94 -3
- package/src/modules/library/state/library-data.tsx +115 -22
- package/src/modules/library/utils/plugin-summary.ts +36 -0
- package/src/modules/library/utils/status.ts +173 -17
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +3 -2
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +29 -14
- package/src/modules/secrets-vault/components/SecretsPage.tsx +4 -1
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +4 -1
- package/src/modules/secrets-vault/services/tool-secrets.api.ts +36 -0
- package/src/modules/settings/components/ClaudeConnectionCard.tsx +169 -0
- package/src/modules/settings/components/DeploymentPage.tsx +15 -1
- package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +10 -0
- package/src/modules/settings/services/github-facade.api.ts +43 -0
- package/src/modules/setup/__tests__/setup.test.tsx +118 -0
- package/src/modules/setup/components/SetupGate.tsx +1 -1
- package/src/modules/setup/components/SetupScreen.tsx +195 -2
- package/src/modules/setup/services/setup.api.ts +78 -0
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +301 -93
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +129 -6
- package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +1 -0
- package/src/modules/workspace/components/FileExplorer.tsx +292 -236
- package/src/modules/workspace/components/FileRoute.tsx +37 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +39 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +1 -0
- package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +70 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +17 -3
- package/src/modules/workspace/routing/kb-routes.ts +1 -1
- package/src/modules/workspace/state/workspace.context.ts +8 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +15 -0
- package/src/modules/workspace/utils/fileTree.ts +14 -16
- package/src/shared/__tests__/marketplace-url.test.ts +54 -0
- package/src/shared/components/Badge.tsx +3 -1
- package/src/shared/components/Banner.tsx +5 -1
- package/src/shared/marketplace-url.ts +90 -0
- package/src/shared/theme/tokens.css +9 -0
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { act, render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
3
3
|
import { MemoryRouter, useLocation } from 'react-router-dom';
|
|
4
4
|
import type { ReactNode } from 'react';
|
|
5
|
+
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
5
6
|
import {
|
|
6
7
|
WorkspaceContext,
|
|
7
8
|
type WorkspaceContextValue,
|
|
8
9
|
} from '../../workspace/state/workspace.context';
|
|
9
|
-
import
|
|
10
|
+
import {
|
|
11
|
+
checkToolConnection,
|
|
12
|
+
setAdminVar,
|
|
13
|
+
type ProbeVerdict,
|
|
14
|
+
type ToolSecrets,
|
|
15
|
+
type ToolSetup,
|
|
16
|
+
} from '../../secrets-vault/services/tool-secrets.api';
|
|
10
17
|
|
|
11
18
|
/**
|
|
12
19
|
* The section frame: the Secrets deep link, the setup banner's three audiences,
|
|
@@ -19,12 +26,20 @@ vi.mock('../../secrets-vault/services/tool-secrets.api', () => ({
|
|
|
19
26
|
setUserVar: vi.fn(),
|
|
20
27
|
deleteAdminVar: vi.fn(),
|
|
21
28
|
setOAuthClientSecret: vi.fn(),
|
|
29
|
+
checkToolConnection: vi.fn(),
|
|
22
30
|
}));
|
|
23
31
|
vi.mock('../../secrets-vault/services/connect.api', () => ({ startToolOAuth: vi.fn() }));
|
|
24
32
|
vi.mock('../utils/navigate-external', () => ({ navigateExternal: vi.fn() }));
|
|
25
33
|
|
|
26
34
|
import { ToolConnectionSection } from '../components/tool-page/ToolConnectionSection';
|
|
27
35
|
|
|
36
|
+
// `checkToolConnection` is one module-level mock shared by every test here.
|
|
37
|
+
// `resetAllMocks`, not `clearAllMocks`: clearing kept whatever implementation
|
|
38
|
+
// the previous test installed with `mockResolvedValue`, which is exactly the
|
|
39
|
+
// ordering hazard this line claims to prevent — a test that forgot its own
|
|
40
|
+
// implementation inherited its neighbour's and passed by accident. Reset
|
|
41
|
+
// drops implementations too, so every test states what its probe answers.
|
|
42
|
+
beforeEach(() => vi.resetAllMocks());
|
|
28
43
|
function workspace(kbDirName: string | null): WorkspaceContextValue {
|
|
29
44
|
return { workspaceId: 'target-company-state', kbDirName } as unknown as WorkspaceContextValue;
|
|
30
45
|
}
|
|
@@ -35,13 +50,25 @@ function LocationProbe() {
|
|
|
35
50
|
return <div aria-label="pathname">{location.pathname}</div>;
|
|
36
51
|
}
|
|
37
52
|
|
|
53
|
+
// The rendered tree reaches for the signed-in identity, so the provider has to
|
|
54
|
+
// be present even though this section no longer reads it itself.
|
|
55
|
+
const AUTH = {
|
|
56
|
+
user: { email: 'user@x.com', name: 'User' },
|
|
57
|
+
token: 't',
|
|
58
|
+
isLoading: false,
|
|
59
|
+
login: vi.fn(),
|
|
60
|
+
logout: vi.fn(),
|
|
61
|
+
} as unknown as AuthContextValue;
|
|
62
|
+
|
|
38
63
|
function wrap(children: ReactNode, kbDirName: string | null = 'knowledge-base') {
|
|
39
64
|
return (
|
|
40
65
|
<MemoryRouter>
|
|
41
|
-
<
|
|
42
|
-
{
|
|
43
|
-
|
|
44
|
-
|
|
66
|
+
<AuthContext.Provider value={AUTH}>
|
|
67
|
+
<WorkspaceContext.Provider value={workspace(kbDirName)}>
|
|
68
|
+
{children}
|
|
69
|
+
<LocationProbe />
|
|
70
|
+
</WorkspaceContext.Provider>
|
|
71
|
+
</AuthContext.Provider>
|
|
45
72
|
</MemoryRouter>
|
|
46
73
|
);
|
|
47
74
|
}
|
|
@@ -67,7 +94,7 @@ const OAUTH_MANUAL: ToolSetup = {
|
|
|
67
94
|
function renderSection(t: ToolSecrets, kbDirName: string | null = 'knowledge-base') {
|
|
68
95
|
return render(
|
|
69
96
|
wrap(
|
|
70
|
-
<ToolConnectionSection tool={t} onChanged={vi.fn()} onError={vi.fn()} />,
|
|
97
|
+
<ToolConnectionSection tool={t} configRevision={0} onChanged={vi.fn()} onError={vi.fn()} />,
|
|
71
98
|
kbDirName,
|
|
72
99
|
),
|
|
73
100
|
);
|
|
@@ -287,4 +314,185 @@ describe('ToolConnectionSection', () => {
|
|
|
287
314
|
expect(screen.queryByRole('status')).toBeNull();
|
|
288
315
|
},
|
|
289
316
|
);
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* The word "Connected" and the evidence for it.
|
|
320
|
+
*
|
|
321
|
+
* Nothing stores a verdict, so this component's own state is the only place
|
|
322
|
+
* one exists — which is exactly why the claim can be trusted: it cannot
|
|
323
|
+
* outlive the page that watched the call succeed.
|
|
324
|
+
*/
|
|
325
|
+
describe('the verdict', () => {
|
|
326
|
+
const settled = () =>
|
|
327
|
+
tool({
|
|
328
|
+
variables: [
|
|
329
|
+
{
|
|
330
|
+
name: 'API_KEY',
|
|
331
|
+
scope: 'user',
|
|
332
|
+
label: null,
|
|
333
|
+
key: 'github_API_KEY',
|
|
334
|
+
adminConfigured: true,
|
|
335
|
+
userConfigured: true,
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('says Key saved — never Connected — before anything has been tested', () => {
|
|
341
|
+
renderSection(settled());
|
|
342
|
+
expect(screen.getByTestId('tool-health')).toHaveTextContent('Key saved');
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it('earns Connected from a passing probe, and only then', async () => {
|
|
346
|
+
vi.mocked(checkToolConnection).mockResolvedValue({
|
|
347
|
+
status: 'ok',
|
|
348
|
+
detail: null,
|
|
349
|
+
checkedAt: new Date().toISOString(),
|
|
350
|
+
});
|
|
351
|
+
renderSection(settled());
|
|
352
|
+
|
|
353
|
+
fireEvent.click(screen.getByRole('button', { name: 'Test connection: github' }));
|
|
354
|
+
|
|
355
|
+
await waitFor(() => expect(screen.getByTestId('tool-health')).toHaveTextContent('Connected'));
|
|
356
|
+
expect(checkToolConnection).toHaveBeenCalledWith('github');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("goes red with the provider's own words when the credential is rejected", async () => {
|
|
360
|
+
vi.mocked(checkToolConnection).mockResolvedValue({
|
|
361
|
+
status: 'failed',
|
|
362
|
+
detail: 'Invalid API key.',
|
|
363
|
+
checkedAt: new Date().toISOString(),
|
|
364
|
+
});
|
|
365
|
+
renderSection(settled());
|
|
366
|
+
|
|
367
|
+
fireEvent.click(screen.getByRole('button', { name: 'Test connection: github' }));
|
|
368
|
+
|
|
369
|
+
// A rejected credential needs a person, so it escalates from the quiet
|
|
370
|
+
// line to a banner.
|
|
371
|
+
await waitFor(() => expect(screen.getByRole('alert')).toHaveTextContent('Invalid API key.'));
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('keeps the button disabled while the probe is in flight', async () => {
|
|
375
|
+
let release: (v: ProbeVerdict) => void = () => {};
|
|
376
|
+
vi.mocked(checkToolConnection).mockReturnValue(
|
|
377
|
+
new Promise<ProbeVerdict>((r) => {
|
|
378
|
+
release = r;
|
|
379
|
+
}),
|
|
380
|
+
);
|
|
381
|
+
renderSection(settled());
|
|
382
|
+
const button = screen.getByRole('button', { name: 'Test connection: github' });
|
|
383
|
+
|
|
384
|
+
fireEvent.click(button);
|
|
385
|
+
|
|
386
|
+
// The in-flight state lives beside the button precisely so it survives
|
|
387
|
+
// the refetch a save triggers — a remount would re-enable it mid-probe.
|
|
388
|
+
await waitFor(() => expect(screen.getByRole('button', { name: /Test connection/ })).toBeDisabled());
|
|
389
|
+
expect(screen.getByRole('button', { name: /Test connection/ })).toHaveTextContent('Testing…');
|
|
390
|
+
release({ status: 'ok', detail: null, checkedAt: new Date().toISOString() });
|
|
391
|
+
await waitFor(() => expect(screen.getByRole('button', { name: /Test connection/ })).toBeEnabled());
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('does not claim a verdict when the CHECK itself failed', async () => {
|
|
395
|
+
// Our own network trouble is not evidence about someone else's credential.
|
|
396
|
+
vi.mocked(checkToolConnection).mockRejectedValue(new Error('Network down'));
|
|
397
|
+
const onError = vi.fn();
|
|
398
|
+
render(wrap(<ToolConnectionSection tool={settled()} configRevision={0} onChanged={vi.fn()} onError={onError} />));
|
|
399
|
+
|
|
400
|
+
fireEvent.click(screen.getByRole('button', { name: 'Test connection: github' }));
|
|
401
|
+
|
|
402
|
+
// The section's OWN banner, not the page's shared one: page state
|
|
403
|
+
// outlived its subject (another action's error cleared by a probe, a
|
|
404
|
+
// previous tool's probe touching the current tool's banner).
|
|
405
|
+
await waitFor(() => expect(screen.getByTestId('tool-probe-error')).toHaveTextContent('Network down'));
|
|
406
|
+
expect(onError).not.toHaveBeenCalled();
|
|
407
|
+
expect(screen.getByTestId('tool-health')).toHaveTextContent('Key saved');
|
|
408
|
+
|
|
409
|
+
// The next clean probe clears it.
|
|
410
|
+
vi.mocked(checkToolConnection).mockResolvedValue({ status: 'ok', detail: null, checkedAt: new Date().toISOString() });
|
|
411
|
+
fireEvent.click(screen.getByRole('button', { name: 'Test connection: github' }));
|
|
412
|
+
await waitFor(() => expect(screen.queryByTestId('tool-probe-error')).toBeNull());
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('stops claiming Connected once the server definition changes', async () => {
|
|
416
|
+
// A verdict describes the endpoint and headers it was probed against.
|
|
417
|
+
// Editing the mcp.json server replaces those, so the old answer is about
|
|
418
|
+
// a server that is no longer configured — and the page not remounting on
|
|
419
|
+
// a same-slug reload is exactly why it would otherwise survive.
|
|
420
|
+
vi.mocked(checkToolConnection).mockResolvedValue({
|
|
421
|
+
status: 'ok',
|
|
422
|
+
detail: null,
|
|
423
|
+
checkedAt: new Date().toISOString(),
|
|
424
|
+
});
|
|
425
|
+
const view = render(
|
|
426
|
+
wrap(<ToolConnectionSection tool={settled()} configRevision={0} onChanged={vi.fn()} onError={vi.fn()} />),
|
|
427
|
+
);
|
|
428
|
+
fireEvent.click(screen.getByRole('button', { name: 'Test connection: github' }));
|
|
429
|
+
await waitFor(() => expect(screen.getByTestId('tool-health')).toHaveTextContent('Connected'));
|
|
430
|
+
|
|
431
|
+
view.rerender(
|
|
432
|
+
wrap(<ToolConnectionSection tool={settled()} configRevision={1} onChanged={vi.fn()} onError={vi.fn()} />),
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
expect(screen.getByTestId('tool-health')).toHaveTextContent('Key saved');
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it('lets the NEWER of two overlapping probes win, however they finish', async () => {
|
|
439
|
+
// Two saves in quick succession start two probes. If the first answers
|
|
440
|
+
// last, its verdict is about the credential the second one replaced —
|
|
441
|
+
// the same stale-answer bug this feature exists to remove, one layer up.
|
|
442
|
+
//
|
|
443
|
+
// Driven through SAVES, not the button: the button disables itself while
|
|
444
|
+
// a probe runs, so it cannot start the second one. A save can, because
|
|
445
|
+
// nothing stops a user typing the next key while the last check is still
|
|
446
|
+
// in flight — which is what makes this reachable at all.
|
|
447
|
+
let releaseFirst: (v: ProbeVerdict) => void = () => {};
|
|
448
|
+
vi.mocked(checkToolConnection)
|
|
449
|
+
.mockReturnValueOnce(
|
|
450
|
+
new Promise<ProbeVerdict>((r) => {
|
|
451
|
+
releaseFirst = r;
|
|
452
|
+
}),
|
|
453
|
+
)
|
|
454
|
+
.mockResolvedValueOnce({ status: 'failed', detail: 'Invalid API key.', checkedAt: new Date().toISOString() });
|
|
455
|
+
vi.mocked(setAdminVar).mockResolvedValue(undefined);
|
|
456
|
+
|
|
457
|
+
// An ADMIN variable a writer can replace: a user-scope row offers no way
|
|
458
|
+
// back into the editor once its key is stored, so it cannot produce the
|
|
459
|
+
// second save this race needs.
|
|
460
|
+
renderSection(
|
|
461
|
+
tool({
|
|
462
|
+
canWrite: true,
|
|
463
|
+
variables: [
|
|
464
|
+
{
|
|
465
|
+
name: 'API_KEY',
|
|
466
|
+
scope: 'admin',
|
|
467
|
+
label: null,
|
|
468
|
+
key: 'github_API_KEY',
|
|
469
|
+
adminConfigured: true,
|
|
470
|
+
userConfigured: false,
|
|
471
|
+
},
|
|
472
|
+
],
|
|
473
|
+
}),
|
|
474
|
+
);
|
|
475
|
+
const save = async (value: string) => {
|
|
476
|
+
fireEvent.click(screen.getByRole('button', { name: 'Replace' }));
|
|
477
|
+
fireEvent.change(screen.getByLabelText('Value for API_KEY'), { target: { value } });
|
|
478
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
|
479
|
+
await waitFor(() => expect(screen.queryByLabelText('Value for API_KEY')).toBeNull());
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
await save('first-key');
|
|
483
|
+
await save('second-key');
|
|
484
|
+
await waitFor(() => expect(checkToolConnection).toHaveBeenCalledTimes(2));
|
|
485
|
+
await waitFor(() => expect(screen.getByRole('alert')).toHaveTextContent('Invalid API key.'));
|
|
486
|
+
|
|
487
|
+
// The first probe now answers "ok" — about `first-key`, which no longer
|
|
488
|
+
// exists — and must not be believed. `act` flushes the re-render that a
|
|
489
|
+
// BROKEN guard would schedule here; a bare microtask await did not, so
|
|
490
|
+
// the assertions below used to pass with the guard removed.
|
|
491
|
+
await act(async () => {
|
|
492
|
+
releaseFirst({ status: 'ok', detail: null, checkedAt: new Date().toISOString() });
|
|
493
|
+
});
|
|
494
|
+
expect(screen.getByRole('alert')).toHaveTextContent('Invalid API key.');
|
|
495
|
+
expect(screen.queryByTestId('tool-health')).toBeNull();
|
|
496
|
+
});
|
|
497
|
+
});
|
|
290
498
|
});
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type WorkspaceContextValue,
|
|
8
8
|
} from '../../workspace/state/workspace.context';
|
|
9
9
|
import { AdminContext } from '../../admin/state/admin.context';
|
|
10
|
+
import { AuthContext, type AuthContextValue } from '../../auth/state/auth.context';
|
|
10
11
|
import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
|
|
11
12
|
import type { ToolManualDetail } from '../services/tools.api';
|
|
12
13
|
|
|
@@ -45,6 +46,13 @@ vi.mock('../services/library.api', () => ({
|
|
|
45
46
|
getSkill: libraryMock.getSkill,
|
|
46
47
|
}));
|
|
47
48
|
|
|
49
|
+
// The page resolves the tool's plugin through `useLibrary()`. With an empty
|
|
50
|
+
// catalog the folder name stands in as the label — which is what the frame
|
|
51
|
+
// tests assert on — and the provider's own fetches stay out of the picture.
|
|
52
|
+
vi.mock('../state/library-data', () => ({
|
|
53
|
+
useLibrary: () => ({ pluginSummaries: [] }),
|
|
54
|
+
}));
|
|
55
|
+
|
|
48
56
|
const sourceMock = vi.hoisted(() => ({ readFileOnBranch: vi.fn() }));
|
|
49
57
|
vi.mock('../../change-requests/services/change-requests.api', () => sourceMock);
|
|
50
58
|
|
|
@@ -122,11 +130,23 @@ function LocationProbe() {
|
|
|
122
130
|
return <div aria-label="pathname">{location.pathname}</div>;
|
|
123
131
|
}
|
|
124
132
|
|
|
133
|
+
// The connection section this page renders reads the signed-in identity to
|
|
134
|
+
// scope its probe queue, so the page needs an auth context to mount at all.
|
|
135
|
+
const AUTH = {
|
|
136
|
+
user: { email: 'user@x.com', name: 'User' },
|
|
137
|
+
token: 't',
|
|
138
|
+
isLoading: false,
|
|
139
|
+
login: vi.fn(),
|
|
140
|
+
logout: vi.fn(),
|
|
141
|
+
} as unknown as AuthContextValue;
|
|
142
|
+
|
|
125
143
|
function wrap(children: ReactNode, isAdmin: boolean) {
|
|
126
144
|
return (
|
|
127
|
-
<
|
|
128
|
-
<
|
|
129
|
-
|
|
145
|
+
<AuthContext.Provider value={AUTH}>
|
|
146
|
+
<AdminContext.Provider value={admin(isAdmin)}>
|
|
147
|
+
<WorkspaceContext.Provider value={workspace}>{children}</WorkspaceContext.Provider>
|
|
148
|
+
</AdminContext.Provider>
|
|
149
|
+
</AuthContext.Provider>
|
|
130
150
|
);
|
|
131
151
|
}
|
|
132
152
|
|
|
@@ -130,9 +130,9 @@ describe('ToolVarRow: admin scope', () => {
|
|
|
130
130
|
});
|
|
131
131
|
|
|
132
132
|
describe('ToolVarRow: user scope, typed value', () => {
|
|
133
|
-
it('shows
|
|
133
|
+
it('shows Key saved when the caller has their own value', () => {
|
|
134
134
|
renderRow(variable({ scope: 'user', userConfigured: true }));
|
|
135
|
-
expect(screen.getByText('
|
|
135
|
+
expect(screen.getByText('Key saved')).toBeInTheDocument();
|
|
136
136
|
expect(screen.getByText('Each person sets their own')).toBeInTheDocument();
|
|
137
137
|
});
|
|
138
138
|
|
|
@@ -160,13 +160,13 @@ describe('ToolVarRow: oauth', () => {
|
|
|
160
160
|
...over,
|
|
161
161
|
});
|
|
162
162
|
|
|
163
|
-
it('shows
|
|
163
|
+
it('shows Signed in once authorized', () => {
|
|
164
164
|
renderRow(signin({ authorized: true }));
|
|
165
165
|
expect(screen.getByText('GitHub sign-in')).toBeInTheDocument();
|
|
166
|
-
expect(screen.getByText('
|
|
166
|
+
expect(screen.getByText('Signed in')).toBeInTheDocument();
|
|
167
167
|
});
|
|
168
168
|
|
|
169
|
-
it('offers Reconnect beside
|
|
169
|
+
it('offers Reconnect beside Signed in, for everyone, and it re-enters the same sign-in flow', async () => {
|
|
170
170
|
// A provider can widen what it grants after the fact (HubSpot answers
|
|
171
171
|
// REQUIRES_REAUTHORIZATION until the user consents again) or revoke a
|
|
172
172
|
// grant — the caller needs a way back into consent that doesn't wait for
|
|
@@ -174,7 +174,7 @@ describe('ToolVarRow: oauth', () => {
|
|
|
174
174
|
// row's terminal state at a glance.
|
|
175
175
|
renderRow(signin({ authorized: true }));
|
|
176
176
|
const reconnect = screen.getByRole('button', { name: 'Reconnect' });
|
|
177
|
-
expect(reconnect.compareDocumentPosition(screen.getByText('
|
|
177
|
+
expect(reconnect.compareDocumentPosition(screen.getByText('Signed in')) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
178
178
|
fireEvent.click(reconnect);
|
|
179
179
|
await waitFor(() =>
|
|
180
180
|
expect(connectMock.startToolOAuth).toHaveBeenCalledWith('github', 'SIGNIN', { returnTo: RETURN_TO }),
|
|
@@ -231,7 +231,7 @@ describe('ToolVarRow: oauth', () => {
|
|
|
231
231
|
await waitFor(() => expect(onChanged).toHaveBeenCalled());
|
|
232
232
|
});
|
|
233
233
|
|
|
234
|
-
it('offers a writer Replace client secret alongside
|
|
234
|
+
it('offers a writer Replace client secret alongside Signed in', () => {
|
|
235
235
|
renderRow(signin({ authorized: true }), { canWrite: true, setupKind: 'oauth-manual' });
|
|
236
236
|
expect(screen.getByRole('button', { name: 'Replace client secret' })).toBeInTheDocument();
|
|
237
237
|
});
|
|
@@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
2
2
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
3
|
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
|
|
4
4
|
import type { ReactNode } from 'react';
|
|
5
|
-
import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
|
|
5
|
+
import { DEFAULT_BRANCH, type FileTreeEntry } from '@bevel-software/platform-shared';
|
|
6
6
|
import {
|
|
7
7
|
WorkspaceContext,
|
|
8
8
|
type WorkspaceContextValue,
|
|
@@ -66,7 +66,7 @@ const CATALOG: LibraryData = {
|
|
|
66
66
|
|
|
67
67
|
const KB = 'knowledge-base';
|
|
68
68
|
|
|
69
|
-
function wrap(children: ReactNode) {
|
|
69
|
+
function wrap(children: ReactNode, fileTree: FileTreeEntry | null = null) {
|
|
70
70
|
const adminValue = {
|
|
71
71
|
isAdmin: false,
|
|
72
72
|
unreadCount: 0,
|
|
@@ -80,6 +80,8 @@ function wrap(children: ReactNode) {
|
|
|
80
80
|
const workspaceValue = {
|
|
81
81
|
workspaceId: 'ws',
|
|
82
82
|
kbDirName: KB,
|
|
83
|
+
fileTree,
|
|
84
|
+
pendingUploads: new Map(),
|
|
83
85
|
} as unknown as WorkspaceContextValue;
|
|
84
86
|
return (
|
|
85
87
|
<AdminContext.Provider value={adminValue}>
|
|
@@ -92,10 +94,17 @@ function wrap(children: ReactNode) {
|
|
|
92
94
|
|
|
93
95
|
function LocationProbe() {
|
|
94
96
|
const location = useLocation();
|
|
95
|
-
|
|
97
|
+
const rawFile = (location.state as { rawFile?: boolean } | null)?.rawFile === true;
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
<div aria-label="pathname">{location.pathname}</div>
|
|
101
|
+
<div aria-label="hash">{location.hash}</div>
|
|
102
|
+
<div aria-label="raw-file">{String(rawFile)}</div>
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
96
105
|
}
|
|
97
106
|
|
|
98
|
-
function renderAt(url: string) {
|
|
107
|
+
function renderAt(url: string, fileTree: FileTreeEntry | null = null) {
|
|
99
108
|
// The same two mounts the shell's CoreSurfaces gives this surface.
|
|
100
109
|
return render(
|
|
101
110
|
<MemoryRouter initialEntries={[url]}>
|
|
@@ -104,6 +113,7 @@ function renderAt(url: string) {
|
|
|
104
113
|
<Route path="/skills-and-tools/*" element={<LibraryRoutes />} />
|
|
105
114
|
<Route path="/workspace/*" element={<LibraryRoutes />} />
|
|
106
115
|
</Routes>,
|
|
116
|
+
fileTree,
|
|
107
117
|
)}
|
|
108
118
|
<LocationProbe />
|
|
109
119
|
</MemoryRouter>,
|
|
@@ -476,6 +486,107 @@ describe('WorkspaceItemRoute', () => {
|
|
|
476
486
|
);
|
|
477
487
|
});
|
|
478
488
|
|
|
489
|
+
/**
|
|
490
|
+
* The shared-skills root: skills and the scope folders that own them, no
|
|
491
|
+
* plugin around them. The same evidence rules as under `Plugins/`, with
|
|
492
|
+
* the two plugin destinations replaced — a scope has no page, and a file
|
|
493
|
+
* filed directly in a scope opens as the plain file it is.
|
|
494
|
+
*/
|
|
495
|
+
describe('a skill under the shared Skills/ root', () => {
|
|
496
|
+
const SHARED: LibraryData = {
|
|
497
|
+
...CATALOG,
|
|
498
|
+
skills: [
|
|
499
|
+
...CATALOG.skills,
|
|
500
|
+
{ name: 'discovery-call', description: '', path: 'Skills/Sales/discovery-call' },
|
|
501
|
+
],
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
beforeEach(() => {
|
|
505
|
+
dataMock.useLibraryData.mockReturnValue(SHARED);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it("renders a shared skill file on that file's tab, inside the library nav", async () => {
|
|
509
|
+
renderAt(itemUrl('Skills/Sales/discovery-call/checklist.md'));
|
|
510
|
+
expect(await screen.findByLabelText('skill-page')).toHaveTextContent('discovery-call::checklist.md');
|
|
511
|
+
expect(screen.getByRole('button', { name: /^All plugins/ })).toBeInTheDocument();
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it('opens a bare shared skill folder on SKILL.md', async () => {
|
|
515
|
+
renderAt(itemUrl('Skills/Sales/discovery-call'));
|
|
516
|
+
expect(await screen.findByLabelText('skill-page')).toHaveTextContent('discovery-call::SKILL.md');
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it('resolves a just-created shared skill from its SKILL.md alone', async () => {
|
|
520
|
+
dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
|
|
521
|
+
renderAt(itemUrl('Skills/Sales/brand-new/SKILL.md'));
|
|
522
|
+
expect(await screen.findByLabelText('skill-page')).toHaveTextContent('brand-new::SKILL.md');
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it('sends a SCOPE folder home — the sidebar tree is where scopes are browsed', async () => {
|
|
526
|
+
renderAt(itemUrl('Skills/Sales'));
|
|
527
|
+
await waitFor(() =>
|
|
528
|
+
expect(screen.getByLabelText('pathname')).toHaveTextContent(/^\/skills-and-tools$/),
|
|
529
|
+
);
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
it("opens a scope's own file as a plain file, in the pane workspace", async () => {
|
|
533
|
+
renderAt(itemUrl('Skills/Sales/access.md'));
|
|
534
|
+
await waitFor(() => expect(screen.getByLabelText('raw-file')).toHaveTextContent('true'));
|
|
535
|
+
// Same URL — the raw view is router state, never a different address.
|
|
536
|
+
expect(screen.getByLabelText('pathname')).toHaveTextContent(itemUrl('Skills/Sales/access.md'));
|
|
537
|
+
expect(screen.queryByLabelText('skill-page')).not.toBeInTheDocument();
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it("carries a scope file's #fragment into the raw view — a heading deep link still lands", async () => {
|
|
541
|
+
renderAt(`${itemUrl('Skills/Sales/README.md')}#goal`);
|
|
542
|
+
await waitFor(() => expect(screen.getByLabelText('raw-file')).toHaveTextContent('true'));
|
|
543
|
+
expect(screen.getByLabelText('hash')).toHaveTextContent('#goal');
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
it("opens a scope's loose file as a plain file when the TREE shows no SKILL.md there — before the catalog answers", async () => {
|
|
547
|
+
// A scope with nothing the caller may read beneath it: the catalog has
|
|
548
|
+
// no evidence, but the workspace tree has the folder and no SKILL.md in
|
|
549
|
+
// it, and a folder without one is no skill.
|
|
550
|
+
dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
|
|
551
|
+
const d = (rel: string, children: FileTreeEntry[]): FileTreeEntry => ({
|
|
552
|
+
name: rel.split('/').pop() ?? rel,
|
|
553
|
+
relativePath: rel,
|
|
554
|
+
type: 'directory',
|
|
555
|
+
children,
|
|
556
|
+
});
|
|
557
|
+
const tree = d('.', [
|
|
558
|
+
d(KB, [d(`${KB}/Skills`, [d(`${KB}/Skills/Sales`, [{ name: 'notes.md', relativePath: `${KB}/Skills/Sales/notes.md`, type: 'file' }])])]),
|
|
559
|
+
]);
|
|
560
|
+
renderAt(itemUrl('Skills/Sales/notes.md'), tree);
|
|
561
|
+
await waitFor(() => expect(screen.getByLabelText('raw-file')).toHaveTextContent('true'));
|
|
562
|
+
expect(screen.queryByLabelText('skill-page')).not.toBeInTheDocument();
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("does not read a SKILL.md URL into a folder the tree shows has none as a skill", async () => {
|
|
566
|
+
dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
|
|
567
|
+
const d = (rel: string, children: FileTreeEntry[]): FileTreeEntry => ({
|
|
568
|
+
name: rel.split('/').pop() ?? rel,
|
|
569
|
+
relativePath: rel,
|
|
570
|
+
type: 'directory',
|
|
571
|
+
children,
|
|
572
|
+
});
|
|
573
|
+
const tree = d('.', [
|
|
574
|
+
d(KB, [d(`${KB}/Skills`, [d(`${KB}/Skills/Sales`, [{ name: 'notes.md', relativePath: `${KB}/Skills/Sales/notes.md`, type: 'file' }])])]),
|
|
575
|
+
]);
|
|
576
|
+
renderAt(itemUrl('Skills/Sales/SKILL.md'), tree);
|
|
577
|
+
await waitFor(() => expect(screen.getByLabelText('raw-file')).toHaveTextContent('true'));
|
|
578
|
+
expect(screen.queryByLabelText('skill-page')).not.toBeInTheDocument();
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
it('waits for the catalog rather than guessing a scope is a skill', async () => {
|
|
582
|
+
dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
|
|
583
|
+
renderAt(itemUrl('Skills/Sales'));
|
|
584
|
+
await waitFor(() => expect(screen.getByRole('button', { name: /^All plugins/ })).toBeInTheDocument());
|
|
585
|
+
expect(screen.queryByLabelText('skill-page')).not.toBeInTheDocument();
|
|
586
|
+
expect(screen.getByLabelText('pathname')).toHaveTextContent(itemUrl('Skills/Sales'));
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
|
|
479
590
|
it('a non-default branch never renders an item page', async () => {
|
|
480
591
|
renderAt(itemUrl('Plugins/Sales/create-sales-deck/SKILL.md', 'razvan/some-draft'));
|
|
481
592
|
await waitFor(() =>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { render, act } from '@testing-library/react';
|
|
3
|
+
import type { LibraryData } from '../hooks/useLibraryData';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The catalog's own view of change requests refreshes on the same event the
|
|
7
|
+
* shell's change-request provider refreshes on. Two stores that each fetch
|
|
8
|
+
* requests are tolerable only while they move together.
|
|
9
|
+
*/
|
|
10
|
+
const dataMock = vi.hoisted(() => ({ useLibraryData: vi.fn() }));
|
|
11
|
+
vi.mock('../hooks/useLibraryData', () => ({ useLibraryData: dataMock.useLibraryData }));
|
|
12
|
+
vi.mock('../services/plugins.api', () => ({ listPlugins: vi.fn().mockResolvedValue([]) }));
|
|
13
|
+
|
|
14
|
+
import { LibraryProvider, useLibrary } from '../state/library-data';
|
|
15
|
+
import { PR_STALE_EVENT } from '../../../core/events';
|
|
16
|
+
|
|
17
|
+
describe('LibraryProvider', () => {
|
|
18
|
+
it('reloads the catalog when change requests go stale', async () => {
|
|
19
|
+
const reload = vi.fn();
|
|
20
|
+
const data: LibraryData = {
|
|
21
|
+
loading: false,
|
|
22
|
+
error: null,
|
|
23
|
+
skills: [],
|
|
24
|
+
pendingSkills: [],
|
|
25
|
+
tools: [],
|
|
26
|
+
ownedSkills: new Set(),
|
|
27
|
+
allowedToolsBySkill: new Map(),
|
|
28
|
+
crs: [],
|
|
29
|
+
myCrNumbers: new Set(),
|
|
30
|
+
reload,
|
|
31
|
+
};
|
|
32
|
+
dataMock.useLibraryData.mockReturnValue(data);
|
|
33
|
+
const { listPlugins } = await import('../services/plugins.api');
|
|
34
|
+
vi.mocked(listPlugins).mockClear();
|
|
35
|
+
const view = render(<LibraryProvider>x</LibraryProvider>);
|
|
36
|
+
await act(async () => undefined);
|
|
37
|
+
expect(reload).not.toHaveBeenCalled();
|
|
38
|
+
expect(listPlugins).toHaveBeenCalledTimes(1);
|
|
39
|
+
await act(async () => {
|
|
40
|
+
window.dispatchEvent(new Event(PR_STALE_EVENT));
|
|
41
|
+
});
|
|
42
|
+
expect(reload).toHaveBeenCalledTimes(1);
|
|
43
|
+
// A merged change can move plugin links and access: the summaries
|
|
44
|
+
// refresh with the catalog, not only on a page's own reload.
|
|
45
|
+
expect(listPlugins).toHaveBeenCalledTimes(2);
|
|
46
|
+
view.unmount();
|
|
47
|
+
await act(async () => {
|
|
48
|
+
window.dispatchEvent(new Event(PR_STALE_EVENT));
|
|
49
|
+
});
|
|
50
|
+
expect(reload).toHaveBeenCalledTimes(1);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("the context's reload refreshes the plugin summaries with the catalog", async () => {
|
|
54
|
+
// A page that reloads after a link, a repair or an access edit must get
|
|
55
|
+
// fresh plugin counts too — the broken-link number lives in the summary.
|
|
56
|
+
const reload = vi.fn();
|
|
57
|
+
const data: LibraryData = {
|
|
58
|
+
loading: false,
|
|
59
|
+
error: null,
|
|
60
|
+
skills: [],
|
|
61
|
+
pendingSkills: [],
|
|
62
|
+
tools: [],
|
|
63
|
+
ownedSkills: new Set(),
|
|
64
|
+
allowedToolsBySkill: new Map(),
|
|
65
|
+
crs: [],
|
|
66
|
+
myCrNumbers: new Set(),
|
|
67
|
+
reload,
|
|
68
|
+
};
|
|
69
|
+
dataMock.useLibraryData.mockReturnValue(data);
|
|
70
|
+
const { listPlugins } = await import('../services/plugins.api');
|
|
71
|
+
vi.mocked(listPlugins).mockClear();
|
|
72
|
+
let ctx: ReturnType<typeof useLibrary> | null = null;
|
|
73
|
+
function Probe() {
|
|
74
|
+
ctx = useLibrary();
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
render(
|
|
78
|
+
<LibraryProvider>
|
|
79
|
+
<Probe />
|
|
80
|
+
</LibraryProvider>,
|
|
81
|
+
);
|
|
82
|
+
await act(async () => undefined);
|
|
83
|
+
expect(listPlugins).toHaveBeenCalledTimes(1);
|
|
84
|
+
await act(async () => {
|
|
85
|
+
ctx!.reload();
|
|
86
|
+
});
|
|
87
|
+
expect(reload).toHaveBeenCalledTimes(1);
|
|
88
|
+
expect(listPlugins).toHaveBeenCalledTimes(2);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { LIBRARY_ROOT, libraryHomeForItemPath, pathForPlugin } from '../routes/library-paths';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where "back" goes from an item page. The plugin is named by its IDENTITY
|
|
6
|
+
* (resolved by the caller through the catalog) but a personal shelf is a
|
|
7
|
+
* place decided by the FOLDER — a personal item's identity is null, and it
|
|
8
|
+
* must still go home to "Yours".
|
|
9
|
+
*/
|
|
10
|
+
describe('libraryHomeForItemPath', () => {
|
|
11
|
+
it('sends a personal item to Yours even though it has no plugin identity', () => {
|
|
12
|
+
expect(libraryHomeForItemPath('Plugins/personal-u1/skills/notes', null)).toEqual({
|
|
13
|
+
label: 'Yours',
|
|
14
|
+
path: `${LIBRARY_ROOT}/yours`,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('sends a plugin item to its plugin by identity, labelled by the caller', () => {
|
|
19
|
+
expect(libraryHomeForItemPath('Plugins/GTM/skills/outreach', 'go-to-market', () => 'Go To Market')).toEqual({
|
|
20
|
+
label: 'Go To Market',
|
|
21
|
+
path: pathForPlugin('go-to-market'),
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('falls back to the folder when the caller resolved no identity', () => {
|
|
26
|
+
expect(libraryHomeForItemPath('Plugins/GTM/skills/outreach')).toEqual({ label: 'GTM', path: pathForPlugin('GTM') });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('sends a shared skill to the root', () => {
|
|
30
|
+
expect(libraryHomeForItemPath('Skills/Eng/deploy', null).path).toBe(LIBRARY_ROOT);
|
|
31
|
+
});
|
|
32
|
+
});
|