@bevel-software/platform-core-frontend 0.12.0 → 0.13.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bevel-software/platform-core-frontend",
3
- "version": "0.12.0",
3
+ "version": "0.13.1",
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.12.0"
48
+ "@bevel-software/platform-shared": "0.13.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@testing-library/jest-dom": "^6.9.1",
@@ -0,0 +1,181 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { act, render, screen } from '@testing-library/react';
3
+ import { GitSyncFailedBanner } from '../components/GitSyncFailedBanner';
4
+ import {
5
+ EventBusContext,
6
+ type EventBusContextValue,
7
+ } from '../../workflow/state/event-bus.context';
8
+ import {
9
+ WorkspaceContext,
10
+ type WorkspaceContextValue,
11
+ } from '../../workspace/state/workspace.context';
12
+ import { makeWorkspaceFixture } from '../../workspace/__tests__/testFixtures';
13
+
14
+ /**
15
+ * A minimal stand-in for the SSE bus: keeps the handlers the component
16
+ * registers and lets a test push events through them, so these assertions
17
+ * drive the banner exactly the way the real backend does — by event, not by
18
+ * poking state.
19
+ */
20
+ function makeBus() {
21
+ // Handlers are stored untyped: the test emits plain event-shaped objects and
22
+ // the component's own subscription types are what's under test, not the bus.
23
+ const handlers = new Map<string, Set<(e: unknown) => void>>();
24
+ const ctx = {
25
+ subscribe(kind: string, handler: (e: unknown) => void) {
26
+ const set = handlers.get(kind) ?? new Set<(e: unknown) => void>();
27
+ set.add(handler);
28
+ handlers.set(kind, set);
29
+ return () => set.delete(handler);
30
+ },
31
+ } as unknown as EventBusContextValue;
32
+ return {
33
+ ctx,
34
+ emit(event: { kind: string; workspaceId: string; branch: string; reason?: string }) {
35
+ act(() => {
36
+ for (const h of handlers.get(event.kind) ?? []) h(event);
37
+ });
38
+ },
39
+ };
40
+ }
41
+
42
+ function renderBanner(workspace: Partial<WorkspaceContextValue> = {}) {
43
+ const bus = makeBus();
44
+ const view = render(
45
+ <EventBusContext.Provider value={bus.ctx}>
46
+ <WorkspaceContext.Provider value={makeWorkspaceFixture(workspace)}>
47
+ <GitSyncFailedBanner />
48
+ </WorkspaceContext.Provider>
49
+ </EventBusContext.Provider>,
50
+ );
51
+ const rerender = (next: Partial<WorkspaceContextValue>) =>
52
+ view.rerender(
53
+ <EventBusContext.Provider value={bus.ctx}>
54
+ <WorkspaceContext.Provider value={makeWorkspaceFixture(next)}>
55
+ <GitSyncFailedBanner />
56
+ </WorkspaceContext.Provider>
57
+ </EventBusContext.Provider>,
58
+ );
59
+ return { ...bus, rerender };
60
+ }
61
+
62
+ const FAILED = {
63
+ kind: 'git-sync-failed',
64
+ workspaceId: 'ws-1',
65
+ branch: 'feat/x',
66
+ reason: 'git push failed: fatal: Authentication failed',
67
+ };
68
+
69
+ describe('GitSyncFailedBanner', () => {
70
+ it('renders nothing until a failure arrives — the healthy case is invisible', () => {
71
+ renderBanner();
72
+ expect(screen.queryByRole('alert')).toBeNull();
73
+ });
74
+
75
+ it('tells the author their work is safe and points an admin at the logs', () => {
76
+ const bus = renderBanner();
77
+ bus.emit(FAILED);
78
+
79
+ const alert = screen.getByRole('alert');
80
+ // The two things this banner exists to say: the save is not lost, and
81
+ // whoever can act should look at the server logs. Neither is negotiable —
82
+ // an author reading "sync failed" with no reassurance re-types their work.
83
+ expect(alert.textContent).toContain('saved here');
84
+ expect(alert.textContent).toContain('server logs');
85
+ expect(alert.textContent).toContain('feat/x');
86
+ });
87
+
88
+ it('shows the sanitised git reason as the detail line', () => {
89
+ const bus = renderBanner();
90
+ bus.emit(FAILED);
91
+ expect(screen.getByRole('alert').textContent).toContain('Authentication failed');
92
+ });
93
+
94
+ it('clears when the backend reports the push recovered', () => {
95
+ const bus = renderBanner();
96
+ bus.emit(FAILED);
97
+ expect(screen.queryByRole('alert')).not.toBeNull();
98
+
99
+ bus.emit({ kind: 'git-sync-recovered', workspaceId: 'ws-1', branch: 'feat/x' });
100
+ expect(screen.queryByRole('alert')).toBeNull();
101
+ });
102
+
103
+ it('ignores events for another workspace', () => {
104
+ // Focus changes race with in-flight events; a failure on the branch the
105
+ // user just left must not paint a banner over the one they are on.
106
+ const bus = renderBanner();
107
+ bus.emit({ ...FAILED, workspaceId: 'ws-2', branch: 'feat/other' });
108
+ expect(screen.queryByRole('alert')).toBeNull();
109
+ });
110
+
111
+ it('does not let another workspace recovering clear this one’s banner', () => {
112
+ const bus = renderBanner();
113
+ bus.emit(FAILED);
114
+ bus.emit({ kind: 'git-sync-recovered', workspaceId: 'ws-2', branch: 'feat/other' });
115
+ expect(screen.queryByRole('alert')).not.toBeNull();
116
+ });
117
+
118
+ it('matches a slashed feature branch across the encode/decode split', () => {
119
+ // Local `workspace.id` is URL-encoded; the SSE event id is URL-decoded.
120
+ // A raw `===` drops every event on a `<user>/<branch>` workspace — which
121
+ // is every feature branch — so the banner would never show, silently
122
+ // recreating the invisible-failure bug this whole feature fixes.
123
+ const bus = renderBanner({ workspaceId: 'razvan-radulescu%2Ffeat' });
124
+ bus.emit({
125
+ kind: 'git-sync-failed',
126
+ workspaceId: 'razvan-radulescu/feat', // decoded, as the backend emits it
127
+ branch: 'razvan-radulescu/feat',
128
+ reason: 'git push failed: fatal: Authentication failed',
129
+ });
130
+ expect(screen.getByRole('alert').textContent).toContain('Authentication failed');
131
+
132
+ bus.emit({
133
+ kind: 'git-sync-recovered',
134
+ workspaceId: 'razvan-radulescu/feat',
135
+ branch: 'razvan-radulescu/feat',
136
+ });
137
+ expect(screen.queryByRole('alert')).toBeNull();
138
+ });
139
+
140
+ it('keeps each branch’s failure separately — returning to a broken branch still shows it', () => {
141
+ // A single retained record let branch B's failure overwrite branch A's;
142
+ // switching back to A then showed nothing despite A being unresolved.
143
+ const bus = renderBanner({ workspaceId: 'ws-1' });
144
+ bus.emit(FAILED); // ws-1 fails
145
+
146
+ act(() => bus.rerender({ workspaceId: 'ws-2' }));
147
+ bus.emit({ ...FAILED, workspaceId: 'ws-2', branch: 'feat/y', reason: 'ws-2 broke too' });
148
+ expect(screen.getByRole('alert').textContent).toContain('ws-2 broke too');
149
+
150
+ act(() => bus.rerender({ workspaceId: 'ws-1' }));
151
+ expect(screen.getByRole('alert').textContent).toContain('feat/x');
152
+
153
+ // ws-1 recovering clears only ws-1's record.
154
+ bus.emit({ kind: 'git-sync-recovered', workspaceId: 'ws-1', branch: 'feat/x' });
155
+ expect(screen.queryByRole('alert')).toBeNull();
156
+ act(() => bus.rerender({ workspaceId: 'ws-2' }));
157
+ expect(screen.getByRole('alert').textContent).toContain('ws-2 broke too');
158
+ });
159
+
160
+ it('clears a stale banner when the focused workspace changes', () => {
161
+ // FileViewer is not keyed by workspace, so this component survives a branch
162
+ // switch. A failure from the branch just left must not paint over the new
163
+ // one — and no recovered event would ever arrive for it.
164
+ const bus = renderBanner({ workspaceId: 'ws-1' });
165
+ bus.emit(FAILED);
166
+ expect(screen.queryByRole('alert')).not.toBeNull();
167
+
168
+ act(() => bus.rerender({ workspaceId: 'ws-2' }));
169
+ expect(screen.queryByRole('alert')).toBeNull();
170
+ });
171
+
172
+ it('stays up across repeated failures, showing the latest reason', () => {
173
+ const bus = renderBanner();
174
+ bus.emit(FAILED);
175
+ bus.emit({ ...FAILED, reason: 'git push failed: could not read Username' });
176
+
177
+ const alert = screen.getByRole('alert');
178
+ expect(alert.textContent).toContain('could not read Username');
179
+ expect(screen.getAllByRole('alert')).toHaveLength(1);
180
+ });
181
+ });
@@ -0,0 +1,106 @@
1
+ import { useCallback, useState } from 'react';
2
+ import { CloudOff } from 'lucide-react';
3
+ import { useEventBusSubscription } from '../../workflow/hooks/useEventBusSubscription';
4
+ import { canonicalizeWorkspaceId } from '../../workflow/state/event-bus.context';
5
+ import { useWorkspace } from '../../workspace/state/workspace.context';
6
+
7
+ /**
8
+ * Shown when a commit landed locally but could not be pushed to the remote.
9
+ *
10
+ * The save itself is fine and is NOT rolled back — the commit is on the
11
+ * server's disk and the retry paths keep running — so this is a warning, not
12
+ * an error state, and nothing here blocks the user. It exists because the
13
+ * failure is otherwise completely invisible: pushes happen behind saves, the
14
+ * one path that does surface an error only reaches a still-mounted editor, and
15
+ * a deployment with a broken git credential therefore looks perfectly healthy
16
+ * while every commit stacks up locally. One self-hosted install ran two days
17
+ * and 136 commits that way.
18
+ *
19
+ * Deliberately not addressed to the author: every cause of a failing push —
20
+ * an expired token, a revoked repo grant, an unreachable host — is an operator
21
+ * concern, and there is nothing the person writing a page can do about it. So
22
+ * the copy tells them their work is safe and points whoever can act at the
23
+ * logs, rather than explaining git.
24
+ *
25
+ * Clears on `git-sync-recovered`, which the backend emits when a push
26
+ * succeeds after failing. No dismiss control, same as `PullNeededBanner`: the
27
+ * condition is real until the server says otherwise, and the next failing save
28
+ * would re-raise it anyway.
29
+ */
30
+ export function GitSyncFailedBanner() {
31
+ const workspace = useWorkspace();
32
+ const workspaceId = workspace.workspaceId;
33
+ // Local state (`workspace.id`) is URL-encoded (`user%2Ffeat`); event ids
34
+ // arrive URL-decoded (`user/feat`, Express auto-decodes `req.params.id`).
35
+ // Comparing them raw drops every event on a slashed feature branch — the
36
+ // exact silent-failure symptom this banner exists to surface — so both
37
+ // sides are canonicalised, the same way every other SSE consumer does.
38
+ const canonId = workspaceId ? canonicalizeWorkspaceId(workspaceId) : null;
39
+ // One record PER workspace, keyed by canonical id. FileViewer is mounted at
40
+ // a catch-all route and is NOT keyed by workspace, so this component
41
+ // survives every branch switch: a single record would let branch B's
42
+ // failure overwrite branch A's, hiding A's unresolved state on return. The
43
+ // render gate below shows only the focused workspace's record.
44
+ //
45
+ // Known limit, accepted deliberately: SSE events are focus-scoped, so a
46
+ // recovery that happens while the user is on another branch never arrives —
47
+ // a retained record can be stale on return until that branch's next push
48
+ // settles it (failures re-emit on every attempt, recoveries on the next
49
+ // transition). The alternative — clearing on switch — hides real, still-
50
+ // broken state, which is the exact failure mode this PR exists to fix.
51
+ const [failures, setFailures] = useState<ReadonlyMap<string, { branch: string; reason: string }>>(
52
+ new Map(),
53
+ );
54
+
55
+ useEventBusSubscription(
56
+ 'git-sync-failed',
57
+ useCallback(
58
+ (e) => {
59
+ // The bus already filters to the focused workspace, but a focus change
60
+ // races with in-flight events — checking here keeps another branch's
61
+ // failure from being recorded under this one's key.
62
+ if (!canonId || canonicalizeWorkspaceId(e.workspaceId) !== canonId) return;
63
+ setFailures((prev) =>
64
+ new Map(prev).set(canonId, { branch: e.branch, reason: e.reason }),
65
+ );
66
+ },
67
+ [canonId],
68
+ ),
69
+ );
70
+
71
+ useEventBusSubscription(
72
+ 'git-sync-recovered',
73
+ useCallback(
74
+ (e) => {
75
+ if (!canonId || canonicalizeWorkspaceId(e.workspaceId) !== canonId) return;
76
+ setFailures((prev) => {
77
+ if (!prev.has(canonId)) return prev;
78
+ const next = new Map(prev);
79
+ next.delete(canonId);
80
+ return next;
81
+ });
82
+ },
83
+ [canonId],
84
+ ),
85
+ );
86
+
87
+ const failure = canonId ? failures.get(canonId) : undefined;
88
+ if (!failure) return null;
89
+
90
+ return (
91
+ <div
92
+ role="alert"
93
+ className="px-3 py-1.5 bg-sunken border-b border-line text-xs text-ink shrink-0"
94
+ >
95
+ <div className="flex items-center gap-2">
96
+ <CloudOff size={13} className="shrink-0" />
97
+ <span className="flex-1">
98
+ Changes on <span className="font-mono font-semibold">{failure.branch}</span> aren’t
99
+ reaching the remote repository. Your work is saved here — an administrator should check
100
+ the server logs.
101
+ </span>
102
+ </div>
103
+ <div className="mt-1 ml-5 text-ink-muted break-words">{failure.reason}</div>
104
+ </div>
105
+ );
106
+ }
@@ -135,4 +135,99 @@ describe('McpServerSection', () => {
135
135
  await waitFor(() => expect(apiMock.putMcpServer).toHaveBeenCalledTimes(1));
136
136
  expect(apiMock.putMcpServer.mock.calls[0]![1]).toMatchObject({ newName: 'vendor_eu' });
137
137
  });
138
+
139
+ it('shows everything the two files store: headers, variables, and a declared sign-in', async () => {
140
+ // What mcp.json + plugin.json say is what the reader sees — no opening
141
+ // either file to learn what is configured.
142
+ apiMock.getMcpServer.mockResolvedValue({
143
+ ...VIEW,
144
+ canWrite: false,
145
+ description: 'Vendor CRM',
146
+ variables: [
147
+ { name: 'VENDOR_KEY', scope: 'user' },
148
+ {
149
+ name: 'SIGNIN',
150
+ scope: 'user',
151
+ label: 'Vendor sign-in',
152
+ oauth: { clientId: 'app-1', scopes: ['crm.read'], pkce: false },
153
+ },
154
+ ],
155
+ });
156
+ renderSection();
157
+ expect(await screen.findByText('X-V: 2')).toBeInTheDocument();
158
+ expect(screen.getByText('Authorization: Bearer ${VENDOR_KEY}')).toBeInTheDocument();
159
+ expect(screen.getByText('Vendor CRM')).toBeInTheDocument();
160
+ expect(screen.getByText('${SIGNIN}')).toBeInTheDocument();
161
+ expect(screen.getByText('app-1')).toBeInTheDocument();
162
+ expect(screen.getByText('Endpoints: discovered from the server')).toBeInTheDocument();
163
+ expect(screen.getByText('Scopes: crm.read')).toBeInTheDocument();
164
+ expect(screen.getByText('PKCE: off')).toBeInTheDocument();
165
+ });
166
+
167
+ it('declares a sign-in on a user variable: client id only, endpoints discovered, header pre-filled', async () => {
168
+ apiMock.getMcpServer.mockResolvedValue({
169
+ ...VIEW,
170
+ authHeaders: {},
171
+ variables: [{ name: 'HUBSPOT_TOKEN', scope: 'user' }],
172
+ });
173
+ renderSection();
174
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit server' }));
175
+ fireEvent.click(screen.getByRole('checkbox', { name: 'Variable 1 OAuth sign-in' }));
176
+ // The header the token needs appears where the writer can see and change it.
177
+ expect(screen.getByRole('textbox', { name: /Auth headers/ })).toHaveValue(
178
+ 'Authorization: Bearer ${HUBSPOT_TOKEN}',
179
+ );
180
+ fireEvent.change(screen.getByRole('textbox', { name: 'Variable 1 client id' }), {
181
+ target: { value: ' app-1 ' },
182
+ });
183
+ fireEvent.change(screen.getByRole('textbox', { name: 'Variable 1 scopes' }), {
184
+ target: { value: 'crm.read crm.write' },
185
+ });
186
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }));
187
+ await waitFor(() => expect(apiMock.putMcpServer).toHaveBeenCalledTimes(1));
188
+ const write = apiMock.putMcpServer.mock.calls[0]![1];
189
+ expect(write).toMatchObject({
190
+ authHeaders: { Authorization: 'Bearer ${HUBSPOT_TOKEN}' },
191
+ variables: [
192
+ { name: 'HUBSPOT_TOKEN', scope: 'user', oauth: { clientId: 'app-1', scopes: ['crm.read', 'crm.write'] } },
193
+ ],
194
+ });
195
+ // Exactly what the file will store: no endpoints (discovered), no
196
+ // `pkce` (on is the default — only an opt-out is written).
197
+ expect(write.variables[0].oauth).not.toHaveProperty('authorizationUrl');
198
+ expect(write.variables[0].oauth).not.toHaveProperty('pkce');
199
+ });
200
+
201
+ it('sends hand-entered endpoints and the PKCE opt-out exactly as the file will store them', async () => {
202
+ apiMock.getMcpServer.mockResolvedValue({
203
+ ...VIEW,
204
+ variables: [{ name: 'SIGNIN', scope: 'user', oauth: { clientId: 'app-1' } }],
205
+ });
206
+ renderSection();
207
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit server' }));
208
+ // An Authorization header already exists — nothing is pre-filled over it.
209
+ expect(screen.getByRole('textbox', { name: /Auth headers/ })).toHaveValue('Authorization: Bearer ${VENDOR_KEY}');
210
+ fireEvent.click(screen.getByRole('radio', { name: 'Variable 1 endpoints by hand' }));
211
+ fireEvent.change(screen.getByRole('textbox', { name: 'Variable 1 authorization URL' }), {
212
+ target: { value: 'https://p.example/auth' },
213
+ });
214
+ fireEvent.change(screen.getByRole('textbox', { name: 'Variable 1 token URL' }), {
215
+ target: { value: 'https://p.example/token' },
216
+ });
217
+ fireEvent.click(screen.getByRole('checkbox', { name: 'Variable 1 PKCE' }));
218
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }));
219
+ await waitFor(() => expect(apiMock.putMcpServer).toHaveBeenCalledTimes(1));
220
+ expect(apiMock.putMcpServer.mock.calls[0]![1].variables).toEqual([
221
+ {
222
+ name: 'SIGNIN',
223
+ scope: 'user',
224
+ oauth: {
225
+ authorizationUrl: 'https://p.example/auth',
226
+ tokenUrl: 'https://p.example/token',
227
+ clientId: 'app-1',
228
+ pkce: false,
229
+ },
230
+ },
231
+ ]);
232
+ });
138
233
  });
@@ -122,6 +122,37 @@ describe('ToolConnectionSection', () => {
122
122
  expect(screen.queryByRole('button', { name: 'Edit the tool file' })).toBeNull();
123
123
  });
124
124
 
125
+ it('sends the owner of an mcp.json server to "Edit server" on this page, not to a file', () => {
126
+ renderSection(tool({ path: 'Plugins/GTM/mcp.json', setup: OAUTH_MANUAL, canWrite: true }));
127
+ expect(screen.getByRole('status')).toHaveTextContent(/under "Edit server" below/);
128
+ expect(screen.queryByRole('button', { name: 'Edit the tool file' })).toBeNull();
129
+ });
130
+
131
+ it('once the sign-in is declared, asks the owner only for the client secret', () => {
132
+ renderSection(
133
+ tool({
134
+ setup: { kind: 'oauth-manual' },
135
+ canWrite: true,
136
+ variables: [
137
+ {
138
+ name: 'SIGNIN',
139
+ scope: 'user',
140
+ label: null,
141
+ key: 'github_SIGNIN',
142
+ adminConfigured: false,
143
+ userConfigured: false,
144
+ oauth: true,
145
+ authorized: false,
146
+ },
147
+ ],
148
+ }),
149
+ );
150
+ expect(screen.getByRole('status')).toHaveTextContent(
151
+ 'the sign-in is declared — set its client secret below to finish',
152
+ );
153
+ expect(screen.queryByRole('button', { name: 'Edit the tool file' })).toBeNull();
154
+ });
155
+
125
156
  it('omits the edit link while the workspace has no kb directory yet', () => {
126
157
  renderSection(tool({ setup: OAUTH_MANUAL, canWrite: true }), null);
127
158
  expect(screen.getByRole('status')).toBeInTheDocument();
@@ -166,6 +166,24 @@ describe('ToolVarRow: oauth', () => {
166
166
  expect(screen.getByText('Connected')).toBeInTheDocument();
167
167
  });
168
168
 
169
+ it('offers Reconnect beside Connected, for everyone, and it re-enters the same sign-in flow', async () => {
170
+ // A provider can widen what it grants after the fact (HubSpot answers
171
+ // REQUIRES_REAUTHORIZATION until the user consents again) or revoke a
172
+ // grant — the caller needs a way back into consent that doesn't wait for
173
+ // the scope check to notice. Left of the chip, so the chip stays the
174
+ // row's terminal state at a glance.
175
+ renderRow(signin({ authorized: true }));
176
+ const reconnect = screen.getByRole('button', { name: 'Reconnect' });
177
+ expect(reconnect.compareDocumentPosition(screen.getByText('Connected')) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
178
+ fireEvent.click(reconnect);
179
+ await waitFor(() =>
180
+ expect(connectMock.startToolOAuth).toHaveBeenCalledWith('github', 'SIGNIN', { returnTo: RETURN_TO }),
181
+ );
182
+ await waitFor(() =>
183
+ expect(navMock.navigateExternal).toHaveBeenCalledWith('https://provider.example/authorize'),
184
+ );
185
+ });
186
+
169
187
  it('asks for a fresh sign-in when the token is under-scoped', () => {
170
188
  renderRow(signin({ authorized: true, needsReauth: true }));
171
189
  expect(screen.getByRole('button', { name: 'Sign in again' })).toBeInTheDocument();