@bevel-software/platform-core-frontend 0.13.5 → 0.14.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/THIRD-PARTY-NOTICES.md +416 -418
- package/package.json +2 -2
- package/src/lib/__tests__/utils.test.ts +43 -0
- package/src/lib/utils.ts +15 -7
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +1 -0
- package/src/modules/library/__tests__/McpServerSection.test.tsx +7 -1
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +216 -8
- package/src/modules/library/__tests__/ToolPage.test.tsx +164 -3
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +7 -7
- package/src/modules/library/__tests__/status.test.ts +84 -0
- package/src/modules/library/components/LibraryCard.tsx +7 -1
- package/src/modules/library/components/skill-page/SkillPage.tsx +5 -1
- 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 +103 -1
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +30 -8
- package/src/modules/library/hooks/useToolPage.ts +28 -11
- package/src/modules/library/hooks/useToolSource.ts +77 -0
- package/src/modules/library/utils/status.ts +99 -10
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +760 -730
- package/src/modules/onboarding/agent-clients.ts +9 -3
- package/src/modules/onboarding/components/WelcomePage.tsx +9 -7
- 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/toolbar/components/ExternalAgentAccessPage.tsx +6 -10
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +34 -12
- package/src/shared/mcp/ChatGptInstallLink.tsx +45 -0
- package/src/shared/mcp/ClaudeInstallLink.tsx +3 -3
- package/src/shared/mcp/ConnectionInstructions.tsx +17 -11
- package/src/shared/mcp/__tests__/ChatGptInstallLink.test.tsx +34 -0
- package/src/shared/mcp/__tests__/connect-snippets.test.ts +49 -13
- package/src/shared/mcp/connect-snippets.ts +41 -6
- package/src/shared/mcp/index.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bevel-software/platform-core-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Open-source core UI of the Bevel platform (raw TS/TSX source): workspace explorer/viewer, branches & change requests, Library, secrets, tools, access control.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"tailwind-merge": "^3.5.0",
|
|
46
46
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
|
|
47
47
|
"yaml": "^2.9.0",
|
|
48
|
-
"@bevel-software/platform-shared": "0.
|
|
48
|
+
"@bevel-software/platform-shared": "0.14.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@testing-library/jest-dom": "^6.9.1",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { formatRelativeTime } from '../utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One relative-time formatter for the whole app, so the same instant cannot
|
|
6
|
+
* render as "2h ago" in one place and "2 hr ago" in another. These pin the
|
|
7
|
+
* parts the callers rely on: the input shapes they actually hold, and the ''
|
|
8
|
+
* that lets each surface supply its own word for "no timestamp" ("never" for an
|
|
9
|
+
* unused API key, "just now" for a connection verdict) without forking the
|
|
10
|
+
* dialect for every timestamp that DOES exist.
|
|
11
|
+
*/
|
|
12
|
+
describe('formatRelativeTime', () => {
|
|
13
|
+
const agoMs = (ms: number) => Date.now() - ms;
|
|
14
|
+
|
|
15
|
+
it.each([
|
|
16
|
+
[30_000, 'just now'],
|
|
17
|
+
[5 * 60_000, '5m ago'],
|
|
18
|
+
[3 * 3_600_000, '3h ago'],
|
|
19
|
+
[2 * 86_400_000, '2d ago'],
|
|
20
|
+
[10 * 86_400_000, '1w ago'],
|
|
21
|
+
])('formats %i ms ago as %s', (ms, expected) => {
|
|
22
|
+
expect(formatRelativeTime(agoMs(ms))).toBe(expected);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('accepts an ISO string, epoch milliseconds and a Date alike', () => {
|
|
26
|
+
const then = new Date(agoMs(5 * 60_000));
|
|
27
|
+
expect(formatRelativeTime(then.toISOString())).toBe('5m ago');
|
|
28
|
+
expect(formatRelativeTime(then.getTime())).toBe('5m ago');
|
|
29
|
+
expect(formatRelativeTime(then)).toBe('5m ago');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it.each([[null], [undefined], [''], ['not-a-date'], [Number.NaN]])(
|
|
33
|
+
'formats %j as the empty string, leaving the word to the caller',
|
|
34
|
+
(value) => {
|
|
35
|
+
expect(formatRelativeTime(value as string | number | null | undefined)).toBe('');
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
it('falls back to an absolute date past ~a month', () => {
|
|
40
|
+
const old = new Date(agoMs(200 * 86_400_000));
|
|
41
|
+
expect(formatRelativeTime(old)).toBe(old.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' }));
|
|
42
|
+
});
|
|
43
|
+
});
|
package/src/lib/utils.ts
CHANGED
|
@@ -88,14 +88,22 @@ export function getFileExtension(filename: string): string {
|
|
|
88
88
|
* Human-readable relative time ("2h ago", "3d ago"). Falls back to an absolute
|
|
89
89
|
* date past ~a month, where "5w ago" stops meaning anything.
|
|
90
90
|
*
|
|
91
|
-
*
|
|
92
|
-
* rail
|
|
93
|
-
*
|
|
91
|
+
* THE relative-time formatter, not one of several: a file-history entry, a
|
|
92
|
+
* document rail, an API key's last use and a connection check all answer the
|
|
93
|
+
* same question, and per-surface copies drift — "2h ago" beside "2 hr ago" for
|
|
94
|
+
* the same instant, one flooring where the other rounds. Anything that needs a
|
|
95
|
+
* different WORD for a missing timestamp supplies its own around this ('' comes
|
|
96
|
+
* back for nothing to format), rather than a second dialect for the times it
|
|
97
|
+
* can format.
|
|
98
|
+
*
|
|
99
|
+
* Accepts what the surfaces actually hold: an ISO string from the API, epoch
|
|
100
|
+
* milliseconds from a browser-side record, or a `Date`. Anything unparseable
|
|
101
|
+
* formats as '' — a caller's fallback word beats echoing a malformed value.
|
|
94
102
|
*/
|
|
95
|
-
export function formatRelativeTime(
|
|
96
|
-
if (
|
|
97
|
-
const d = new Date(
|
|
98
|
-
if (Number.isNaN(d.getTime())) return
|
|
103
|
+
export function formatRelativeTime(at: string | number | Date | null | undefined): string {
|
|
104
|
+
if (at === null || at === undefined || at === '') return '';
|
|
105
|
+
const d = at instanceof Date ? at : new Date(at);
|
|
106
|
+
if (Number.isNaN(d.getTime())) return '';
|
|
99
107
|
const diffMs = Date.now() - d.getTime();
|
|
100
108
|
const absolute = () =>
|
|
101
109
|
d.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
|
|
@@ -38,7 +38,13 @@ function renderSection(configuredCount = 2) {
|
|
|
38
38
|
const onError = vi.fn();
|
|
39
39
|
render(
|
|
40
40
|
<MemoryRouter>
|
|
41
|
-
<McpServerSection
|
|
41
|
+
<McpServerSection
|
|
42
|
+
slug="vendor"
|
|
43
|
+
reloadSignal={0}
|
|
44
|
+
configuredCount={configuredCount}
|
|
45
|
+
onSaved={onSaved}
|
|
46
|
+
onError={onError}
|
|
47
|
+
/>
|
|
42
48
|
</MemoryRouter>,
|
|
43
49
|
);
|
|
44
50
|
return { onSaved, onError };
|
|
@@ -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,9 @@ vi.mock('../services/library.api', () => ({
|
|
|
45
46
|
getSkill: libraryMock.getSkill,
|
|
46
47
|
}));
|
|
47
48
|
|
|
49
|
+
const sourceMock = vi.hoisted(() => ({ readFileOnBranch: vi.fn() }));
|
|
50
|
+
vi.mock('../../change-requests/services/change-requests.api', () => sourceMock);
|
|
51
|
+
|
|
48
52
|
vi.mock('../../secrets-vault/services/connect.api', () => ({ startToolOAuth: vi.fn() }));
|
|
49
53
|
vi.mock('../utils/navigate-external', () => ({ navigateExternal: vi.fn() }));
|
|
50
54
|
|
|
@@ -72,6 +76,29 @@ const DETAIL: ToolManualDetail = {
|
|
|
72
76
|
],
|
|
73
77
|
};
|
|
74
78
|
|
|
79
|
+
/**
|
|
80
|
+
* A `.tool` with everything a formatter would be tempted to touch: the `---`
|
|
81
|
+
* fences, a folded description, a comment, and a fenced template carrying an
|
|
82
|
+
* unexpanded `${VAR}`. The section shows these bytes or it shows a lie.
|
|
83
|
+
*/
|
|
84
|
+
const SOURCE = [
|
|
85
|
+
'---',
|
|
86
|
+
'name: heyreach',
|
|
87
|
+
'description: >-',
|
|
88
|
+
' Runs LinkedIn',
|
|
89
|
+
' outreach campaigns.',
|
|
90
|
+
'---',
|
|
91
|
+
'',
|
|
92
|
+
'# heyreach',
|
|
93
|
+
'',
|
|
94
|
+
'<!-- keep me: a reader is here precisely for this -->',
|
|
95
|
+
'',
|
|
96
|
+
'```http',
|
|
97
|
+
'GET https://api.heyreach.io/campaigns',
|
|
98
|
+
'Authorization: Bearer ${HEYREACH_API_KEY}',
|
|
99
|
+
'```',
|
|
100
|
+
'',
|
|
101
|
+
].join('\n');
|
|
75
102
|
const workspace = {
|
|
76
103
|
workspaceId: 'target-company-state',
|
|
77
104
|
kbDirName: 'knowledge-base',
|
|
@@ -96,11 +123,23 @@ function LocationProbe() {
|
|
|
96
123
|
return <div aria-label="pathname">{location.pathname}</div>;
|
|
97
124
|
}
|
|
98
125
|
|
|
126
|
+
// The connection section this page renders reads the signed-in identity to
|
|
127
|
+
// scope its probe queue, so the page needs an auth context to mount at all.
|
|
128
|
+
const AUTH = {
|
|
129
|
+
user: { email: 'user@x.com', name: 'User' },
|
|
130
|
+
token: 't',
|
|
131
|
+
isLoading: false,
|
|
132
|
+
login: vi.fn(),
|
|
133
|
+
logout: vi.fn(),
|
|
134
|
+
} as unknown as AuthContextValue;
|
|
135
|
+
|
|
99
136
|
function wrap(children: ReactNode, isAdmin: boolean) {
|
|
100
137
|
return (
|
|
101
|
-
<
|
|
102
|
-
<
|
|
103
|
-
|
|
138
|
+
<AuthContext.Provider value={AUTH}>
|
|
139
|
+
<AdminContext.Provider value={admin(isAdmin)}>
|
|
140
|
+
<WorkspaceContext.Provider value={workspace}>{children}</WorkspaceContext.Provider>
|
|
141
|
+
</AdminContext.Provider>
|
|
142
|
+
</AuthContext.Provider>
|
|
104
143
|
);
|
|
105
144
|
}
|
|
106
145
|
|
|
@@ -126,6 +165,7 @@ beforeEach(() => {
|
|
|
126
165
|
toolsMock.getMcpServer.mockClear();
|
|
127
166
|
libraryMock.listSkills.mockReset().mockResolvedValue([]);
|
|
128
167
|
libraryMock.getSkill.mockReset().mockResolvedValue({ allowedTools: [] });
|
|
168
|
+
sourceMock.readFileOnBranch.mockReset().mockResolvedValue(SOURCE);
|
|
129
169
|
});
|
|
130
170
|
|
|
131
171
|
describe('ToolPage: frame', () => {
|
|
@@ -364,3 +404,124 @@ describe('ToolPage: OAuth round-trip', () => {
|
|
|
364
404
|
);
|
|
365
405
|
});
|
|
366
406
|
});
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* The `.tool` itself, at the bottom of the page.
|
|
410
|
+
*
|
|
411
|
+
* The four things worth pinning are the four the section can get wrong in a
|
|
412
|
+
* way nobody notices: it must be CLOSED (a reader who wanted the tool, not its
|
|
413
|
+
* file, sees no change), the text must be the file's BYTES (a view that
|
|
414
|
+
* reformats is worse than no view — it invents a source that does not exist),
|
|
415
|
+
* a failed read must cost the section and nothing else, and the read must not
|
|
416
|
+
* happen until it is asked for.
|
|
417
|
+
*/
|
|
418
|
+
describe('ToolPage: source', () => {
|
|
419
|
+
const toggle = () => screen.getByRole('button', { name: 'Source' });
|
|
420
|
+
|
|
421
|
+
it('is closed on first visit, with the file path beside its label', async () => {
|
|
422
|
+
renderPage();
|
|
423
|
+
await screen.findByRole('heading', { name: 'heyreach', level: 1 });
|
|
424
|
+
|
|
425
|
+
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
|
|
426
|
+
expect(screen.getByText('Plugins/GTM/heyreach.tool')).toBeInTheDocument();
|
|
427
|
+
expect(document.querySelector('pre')).toBeNull();
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it('reads nothing until it is opened, and then exactly once', async () => {
|
|
431
|
+
renderPage();
|
|
432
|
+
await screen.findByRole('heading', { name: 'heyreach', level: 1 });
|
|
433
|
+
// The whole point of the disclosure: no reader pays for a file they did
|
|
434
|
+
// not ask to see.
|
|
435
|
+
expect(sourceMock.readFileOnBranch).not.toHaveBeenCalled();
|
|
436
|
+
|
|
437
|
+
fireEvent.click(toggle());
|
|
438
|
+
await waitFor(() => expect(sourceMock.readFileOnBranch).toHaveBeenCalledTimes(1));
|
|
439
|
+
// The OFFICIAL version — the file the platform runs, not a draft branch.
|
|
440
|
+
expect(sourceMock.readFileOnBranch).toHaveBeenCalledWith(
|
|
441
|
+
'target-company-state',
|
|
442
|
+
'Plugins/GTM/heyreach.tool',
|
|
443
|
+
);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('shows the file verbatim — fences, comments, folding and all', async () => {
|
|
447
|
+
renderPage();
|
|
448
|
+
await screen.findByRole('heading', { name: 'heyreach', level: 1 });
|
|
449
|
+
fireEvent.click(toggle());
|
|
450
|
+
|
|
451
|
+
await waitFor(() => expect(document.querySelector('pre')).not.toBeNull());
|
|
452
|
+
// Byte for byte. Not "contains", not "matches after trimming".
|
|
453
|
+
expect(document.querySelector('pre')!.textContent).toBe(SOURCE);
|
|
454
|
+
expect(toggle()).toHaveAttribute('aria-expanded', 'true');
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('offers no way to edit what it shows', async () => {
|
|
458
|
+
renderPage();
|
|
459
|
+
await screen.findByRole('heading', { name: 'heyreach', level: 1 });
|
|
460
|
+
fireEvent.click(toggle());
|
|
461
|
+
await waitFor(() => expect(document.querySelector('pre')).not.toBeNull());
|
|
462
|
+
|
|
463
|
+
expect(document.querySelector('textarea')).toBeNull();
|
|
464
|
+
expect(document.querySelector('pre')!.closest('[contenteditable]')).toBeNull();
|
|
465
|
+
expect(screen.queryByRole('button', { name: 'Save' })).toBeNull();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('opening it changes nothing above it', async () => {
|
|
469
|
+
renderPage();
|
|
470
|
+
await screen.findByRole('heading', { name: 'heyreach', level: 1 });
|
|
471
|
+
fireEvent.click(toggle());
|
|
472
|
+
await waitFor(() => expect(document.querySelector('pre')).not.toBeNull());
|
|
473
|
+
|
|
474
|
+
expect(screen.getByText('Runs LinkedIn outreach campaigns.')).toBeInTheDocument();
|
|
475
|
+
expect(screen.getByRole('heading', { name: 'What it lets the assistant do' })).toBeInTheDocument();
|
|
476
|
+
expect(screen.getByRole('heading', { name: 'Powers these skills' })).toBeInTheDocument();
|
|
477
|
+
expect(screen.getByText('Managed by the Admins.')).toBeInTheDocument();
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it('shows a short message in place of the content when the file cannot be read, and retries on reopen', async () => {
|
|
481
|
+
sourceMock.readFileOnBranch.mockRejectedValueOnce(new Error('HTTP 404'));
|
|
482
|
+
renderPage();
|
|
483
|
+
await screen.findByRole('heading', { name: 'heyreach', level: 1 });
|
|
484
|
+
|
|
485
|
+
fireEvent.click(toggle());
|
|
486
|
+
expect(await screen.findByText("Couldn't load the source.")).toBeInTheDocument();
|
|
487
|
+
expect(document.querySelector('pre')).toBeNull();
|
|
488
|
+
// The page around it is untouched — a missing file is not a broken page.
|
|
489
|
+
expect(screen.getByRole('heading', { name: 'heyreach', level: 1 })).toBeInTheDocument();
|
|
490
|
+
expect(screen.getByText('Runs LinkedIn outreach campaigns.')).toBeInTheDocument();
|
|
491
|
+
|
|
492
|
+
fireEvent.click(toggle()); // close
|
|
493
|
+
fireEvent.click(toggle()); // open again — a failed read is never the final answer
|
|
494
|
+
await waitFor(() => expect(document.querySelector('pre')).not.toBeNull());
|
|
495
|
+
expect(document.querySelector('pre')!.textContent).toBe(SOURCE);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it.each(['inline', 'http', 'mcp'] as const)('is present on a %s tool', async (type) => {
|
|
499
|
+
secretsMock.listToolSecrets.mockResolvedValue([{ ...GITHUB, type }]);
|
|
500
|
+
toolsMock.getToolDetail.mockResolvedValue({ ...DETAIL, type, capabilities: [] });
|
|
501
|
+
|
|
502
|
+
renderPage();
|
|
503
|
+
await screen.findByRole('heading', { name: 'heyreach', level: 1 });
|
|
504
|
+
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
it('shows the mcp.json for a tool declared through a plugin, like every other type', async () => {
|
|
508
|
+
const MCP_JSON = '{\n "mcpServers": {\n "notion": { "url": "https://mcp.notion.com/mcp" }\n }\n}\n';
|
|
509
|
+
secretsMock.listToolSecrets.mockResolvedValue([
|
|
510
|
+
{ ...GITHUB, slug: 'notion', name: 'notion', type: 'mcp', path: 'Plugins/GTM/mcp.json' },
|
|
511
|
+
]);
|
|
512
|
+
toolsMock.getToolDetail.mockResolvedValue({ ...DETAIL, slug: 'notion', name: 'notion' });
|
|
513
|
+
sourceMock.readFileOnBranch.mockResolvedValue(MCP_JSON);
|
|
514
|
+
|
|
515
|
+
renderPage({ slug: 'notion' });
|
|
516
|
+
await screen.findByRole('heading', { name: 'notion', level: 1 });
|
|
517
|
+
expect(screen.getByText('Plugins/GTM/mcp.json')).toBeInTheDocument();
|
|
518
|
+
|
|
519
|
+
fireEvent.click(toggle());
|
|
520
|
+
await waitFor(() => expect(document.querySelector('pre')).not.toBeNull());
|
|
521
|
+
expect(sourceMock.readFileOnBranch).toHaveBeenCalledWith(
|
|
522
|
+
'target-company-state',
|
|
523
|
+
'Plugins/GTM/mcp.json',
|
|
524
|
+
);
|
|
525
|
+
expect(document.querySelector('pre')!.textContent).toBe(MCP_JSON);
|
|
526
|
+
});
|
|
527
|
+
});
|
|
@@ -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
|
});
|