@bevel-software/platform-core-frontend 0.12.1 → 0.13.3

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.1",
3
+ "version": "0.13.3",
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.1"
48
+ "@bevel-software/platform-shared": "0.13.3"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@testing-library/jest-dom": "^6.9.1",
@@ -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
  });
@@ -240,9 +240,50 @@ function renderPage(
240
240
  library?: Partial<LibraryContextValue>,
241
241
  /** Props the canonical /workspace mount passes; the legacy route passes none. */
242
242
  pageProps?: { provisional?: boolean },
243
+ /** Git state — overridden to test what the page does when there is no log. */
244
+ gitValue: GitContextValue = git,
243
245
  ) {
244
246
  libraryMock.value = { ...libraryValue(owned, crs, mine), ...library };
245
- return render(
247
+ return render(harness(bus, gitValue, routerState, pageProps));
248
+ }
249
+
250
+ /**
251
+ * Wait for the page to stop loading before driving it.
252
+ *
253
+ * The reading pane is the LAST thing to arrive: it needs the skill detail
254
+ * (which is also what puts the second tab on screen) and then the file's bytes
255
+ * off the default branch. Waiting on a TAB instead can resolve earlier —
256
+ * `findByRole('tab', …)` is satisfied by the SKILL.md tab, which renders
257
+ * before either of those lands.
258
+ *
259
+ * Why the keyboard tests use it: `jumps to the first and last file with Home
260
+ * and End` was seen failing in full-suite runs on a loaded machine, never in
261
+ * isolation (0 in 20 runs). The cause was NOT established — a deliberately
262
+ * delayed detail load does not reproduce it, and the same runs on the
263
+ * unmodified file were too few to tell the two versions apart. What is certain
264
+ * is that both keyboard tests were driving the tablist while several requests
265
+ * were still in flight, and they are about arrow keys, not about loading. So
266
+ * they start from a settled page. If the flake outlives this, the cause is
267
+ * somewhere else and this at least stops the tablist tests from being where it
268
+ * is hunted.
269
+ */
270
+ async function settled() {
271
+ await screen.findByTestId('md-view');
272
+ }
273
+
274
+ /**
275
+ * The provider tree `renderPage` mounts, as a value — so a test can hand the
276
+ * SAME tree back to `rerender` with a different git state and watch the page
277
+ * react WITHOUT remounting it. Remounting would reset the very state
278
+ * (`historyOpen`) those tests are about, and pass whatever the page did.
279
+ */
280
+ function harness(
281
+ bus: EventBusContextValue,
282
+ gitValue: GitContextValue,
283
+ routerState?: Record<string, unknown>,
284
+ pageProps?: { provisional?: boolean },
285
+ ) {
286
+ return (
246
287
  <MemoryRouter
247
288
  initialEntries={[
248
289
  { pathname: '/skills-and-tools/skills/newsletter', state: routerState ?? null },
@@ -250,7 +291,7 @@ function renderPage(
250
291
  >
251
292
  <AuthContext.Provider value={auth}>
252
293
  <WorkspaceContext.Provider value={workspace}>
253
- <GitContext.Provider value={git}>
294
+ <GitContext.Provider value={gitValue}>
254
295
  <EventBusContext.Provider value={bus}>
255
296
  {/* The real toast provider: the success message IS the page's
256
297
  report that the merge landed, so a stubbed-out toast would
@@ -267,7 +308,7 @@ function renderPage(
267
308
  </GitContext.Provider>
268
309
  </WorkspaceContext.Provider>
269
310
  </AuthContext.Provider>
270
- </MemoryRouter>,
311
+ </MemoryRouter>
271
312
  );
272
313
  }
273
314
 
@@ -371,7 +412,8 @@ describe('SkillPage', () => {
371
412
  */
372
413
  it('moves selection AND focus with the arrow keys', async () => {
373
414
  renderPage(false);
374
- const skillTab = await screen.findByRole('tab', { name: /SKILL\.md/ });
415
+ await settled();
416
+ const skillTab = screen.getByRole('tab', { name: /SKILL\.md/ });
375
417
  const sourcesTab = screen.getByRole('tab', { name: /sources\.yaml/ });
376
418
 
377
419
  skillTab.focus();
@@ -387,7 +429,8 @@ describe('SkillPage', () => {
387
429
 
388
430
  it('jumps to the first and last file with Home and End', async () => {
389
431
  renderPage(false);
390
- const skillTab = await screen.findByRole('tab', { name: /SKILL\.md/ });
432
+ await settled();
433
+ const skillTab = screen.getByRole('tab', { name: /SKILL\.md/ });
391
434
  const sourcesTab = screen.getByRole('tab', { name: /sources\.yaml/ });
392
435
 
393
436
  skillTab.focus();
@@ -1123,4 +1166,165 @@ describe('SkillPage: deciding on a change', () => {
1123
1166
  fireEvent.click(withdraw);
1124
1167
  await waitFor(() => expect(apiMock.cancelPullRequest).toHaveBeenCalledWith(7));
1125
1168
  });
1169
+
1170
+ /**
1171
+ * A skill is a file in the repository, and this page is the ONLY surface it
1172
+ * has: the shell routes every default-branch `Plugins/` URL here
1173
+ * (`isLibraryLocation`) and the Knowledge tree does not list `Plugins/` at
1174
+ * all, so a `⋯` missing here means the git log for every skill in the
1175
+ * deployment is unreachable — the audit trail the product is sold on,
1176
+ * available for Knowledge pages and for nothing else.
1177
+ */
1178
+ describe('version history', () => {
1179
+ it('opens the log for the file on screen, at its workspace path', async () => {
1180
+ renderPage(false);
1181
+
1182
+ fireEvent.click(await screen.findByRole('button', { name: 'More actions' }));
1183
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Version history' }));
1184
+
1185
+ // The path the panel asks git about is the workspace-relative one the
1186
+ // Knowledge viewer would hand it — kbDirName included. Getting this
1187
+ // wrong asks about a file that does not exist and reports an empty
1188
+ // history for one that does.
1189
+ expect(
1190
+ await screen.findByText('Timeline: knowledge-base/Skills/newsletter/SKILL.md'),
1191
+ ).toBeInTheDocument();
1192
+ expect(screen.getByText('Version history: SKILL.md')).toBeInTheDocument();
1193
+
1194
+ // And there is a way back, because history is not in the URL.
1195
+ fireEvent.click(screen.getByRole('button', { name: 'Back to the file' }));
1196
+ expect(await screen.findByTestId('md-view')).toBeInTheDocument();
1197
+ });
1198
+
1199
+ it('does not follow you to another file of the skill', async () => {
1200
+ renderPage(false);
1201
+
1202
+ fireEvent.click(await screen.findByRole('button', { name: 'More actions' }));
1203
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Version history' }));
1204
+ await screen.findByText('Timeline: knowledge-base/Skills/newsletter/SKILL.md');
1205
+
1206
+ // A tab switch is a switch of file, and history is a lens on ONE file.
1207
+ // Carrying it across would show the previous file's log under the new
1208
+ // file's heading.
1209
+ fireEvent.click(screen.getByRole('tab', { name: 'sources.yaml' }));
1210
+ expect(screen.queryByText(/^Timeline:/)).toBeNull();
1211
+
1212
+ // And it does not come BACK on the way home. Keying the open flag to
1213
+ // the file it was opened for is not enough on its own: returning to
1214
+ // that tab then reopens a log nobody asked for a second time, which is
1215
+ // how you land on history when you meant to read the file.
1216
+ fireEvent.click(screen.getByRole('tab', { name: 'SKILL.md' }));
1217
+ expect(screen.queryByText(/^Timeline:/)).toBeNull();
1218
+ expect(await screen.findByTestId('md-view')).toBeInTheDocument();
1219
+ });
1220
+
1221
+ /**
1222
+ * `SkillFileEditor` holds the draft in its own state, so swapping it out
1223
+ * for the history panel throws away whatever was typed, with no warning
1224
+ * and no way back. The menu is withdrawn for exactly as long as that is
1225
+ * true.
1226
+ */
1227
+ it('is withdrawn while the editor is open, so a draft cannot be discarded', async () => {
1228
+ accessMock.result = {
1229
+ canWrite: true,
1230
+ eligible: { roles: [], users: [] },
1231
+ owners: { roles: [], users: [] },
1232
+ };
1233
+ renderPage(true);
1234
+
1235
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit' }));
1236
+ await screen.findByRole('textbox', { name: /Edit SKILL\.md/ });
1237
+ expect(screen.queryByRole('button', { name: 'More actions' })).toBeNull();
1238
+
1239
+ // It comes back the moment the draft is gone.
1240
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
1241
+ expect(await screen.findByRole('button', { name: 'More actions' })).toBeInTheDocument();
1242
+ });
1243
+
1244
+ /**
1245
+ * `availability` is re-derived from a POLLED status call, so one failed
1246
+ * poll flips it to `error` and the next good one flips it back. If the
1247
+ * open flag survived that, the log would reappear over the file minutes
1248
+ * after the reader had gone back to reading.
1249
+ */
1250
+ it('closes for good when git stops answering mid-read', async () => {
1251
+ const bus = makeFakeBus();
1252
+ const { rerender } = renderPage(false, [], [], bus);
1253
+ fireEvent.click(await screen.findByRole('button', { name: 'More actions' }));
1254
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Version history' }));
1255
+ await screen.findByText(/^Timeline:/);
1256
+
1257
+ // A poll fails: the log goes away, and so does its trigger.
1258
+ rerender(harness(bus, { ...git, availability: 'error' } as GitContextValue));
1259
+ expect(screen.queryByText(/^Timeline:/)).toBeNull();
1260
+
1261
+ // The next poll succeeds. The file is still what is on screen.
1262
+ rerender(harness(bus, git));
1263
+ expect(await screen.findByTestId('md-view')).toBeInTheDocument();
1264
+ expect(screen.queryByText(/^Timeline:/)).toBeNull();
1265
+ expect(screen.getByRole('button', { name: 'More actions' })).toBeInTheDocument();
1266
+ });
1267
+
1268
+ /**
1269
+ * The MENU flag needs the same treatment as the log's, and it is a
1270
+ * separate flag: the trigger and its panel both live behind
1271
+ * `historyAvailable`, so an open menu unmounts with them and leaves its
1272
+ * flag set behind an element nobody can see. Found by cubic on #103.
1273
+ */
1274
+ it('does not spring the menu back open when git recovers', async () => {
1275
+ const bus = makeFakeBus();
1276
+ const { rerender } = renderPage(false, [], [], bus);
1277
+ const trigger = await screen.findByRole('button', { name: 'More actions' });
1278
+ fireEvent.click(trigger);
1279
+ expect(screen.getByRole('menuitem', { name: 'Version history' })).toBeInTheDocument();
1280
+
1281
+ // A poll fails while the menu is OPEN — trigger and panel go together.
1282
+ rerender(harness(bus, { ...git, availability: 'error' } as GitContextValue));
1283
+ expect(screen.queryByRole('button', { name: 'More actions' })).toBeNull();
1284
+
1285
+ // The next poll succeeds. The trigger is back, and it is CLOSED.
1286
+ rerender(harness(bus, git));
1287
+ const back = await screen.findByRole('button', { name: 'More actions' });
1288
+ expect(back).toHaveAttribute('aria-expanded', 'false');
1289
+ expect(screen.queryByRole('menuitem', { name: 'Version history' })).toBeNull();
1290
+ });
1291
+
1292
+ /**
1293
+ * `editing` is the same state by a second door, and it is reachable
1294
+ * without a mouse: `useDismissableMenu` dismisses on outside POINTERDOWN,
1295
+ * so tabbing from the open menu to Edit and pressing Enter never dismisses
1296
+ * it. Cancel then used to hand the menu back open over the file.
1297
+ */
1298
+ it('does not spring the menu back open when the editor closes', async () => {
1299
+ accessMock.result = {
1300
+ canWrite: true,
1301
+ eligible: { roles: [], users: [] },
1302
+ owners: { roles: [], users: [] },
1303
+ };
1304
+ renderPage(true);
1305
+ fireEvent.click(await screen.findByRole('button', { name: 'More actions' }));
1306
+ expect(screen.getByRole('menuitem', { name: 'Version history' })).toBeInTheDocument();
1307
+
1308
+ // Reached by keyboard, so no outside pointerdown ever dismissed the menu.
1309
+ fireEvent.click(screen.getByRole('button', { name: 'Edit' }));
1310
+ await screen.findByRole('textbox', { name: /Edit SKILL\.md/ });
1311
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
1312
+
1313
+ const back = await screen.findByRole('button', { name: 'More actions' });
1314
+ expect(back).toHaveAttribute('aria-expanded', 'false');
1315
+ expect(screen.queryByRole('menuitem', { name: 'Version history' })).toBeNull();
1316
+ });
1317
+
1318
+ it('has no trigger at all when git cannot answer', async () => {
1319
+ renderPage(false, [], [], makeFakeBus(), undefined, undefined, undefined, {
1320
+ ...git,
1321
+ availability: 'loading',
1322
+ } as GitContextValue);
1323
+
1324
+ // Version history is the whole menu, so no log means no `⋯` — an
1325
+ // overflow opening onto an empty panel is worse than no overflow.
1326
+ expect(await screen.findByRole('heading', { name: 'newsletter' })).toBeInTheDocument();
1327
+ expect(screen.queryByRole('button', { name: 'More actions' })).toBeNull();
1328
+ });
1329
+ });
1126
1330
  });
@@ -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();