@bevel-software/platform-core-frontend 0.39.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bevel-software/platform-core-frontend",
3
- "version": "0.39.0",
3
+ "version": "0.40.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.39.0"
48
+ "@bevel-software/platform-shared": "0.40.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@modelcontextprotocol/client": "^2.3.1",
@@ -1,71 +1,86 @@
1
- import { describe, it, expect, vi } from 'vitest';
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
2
  import { act, render, screen } from '@testing-library/react';
3
3
  import { GitSyncFailedBanner } from '../components/GitSyncFailedBanner';
4
- import {
5
- EventBusContext,
6
- type EventBusContextValue,
7
- } from '../../version-control/state/event-bus.context';
8
- import {
9
- WorkspaceContext,
10
- type WorkspaceContextValue,
11
- } from '../../workspace/state/workspace.context';
12
- import { makeWorkspaceFixture } from '../../workspace/__tests__/testFixtures';
4
+ import { EventBusProvider } from '../../version-control';
5
+ import { WorkspaceContext, type WorkspaceContextValue } from '../../workspace';
13
6
 
14
7
  // The conflict rendering opens files through the file-navigation hook, which
15
8
  // needs a router and the git context. Neither belongs in this suite: the
16
9
  // banner's contract is what it says and which paths it offers, so the hook
17
- // is replaced with a recorder.
10
+ // the workspace module offers is replaced with a recorder; everything else
11
+ // the module offers stays its own.
18
12
  const { openWorkspacePath } = vi.hoisted(() => ({ openWorkspacePath: vi.fn() }));
19
- vi.mock('../../workspace/routing/kb-routes', () => ({
13
+ vi.mock('../../workspace', async (importOriginal) => ({
14
+ ...(await importOriginal<typeof import('../../workspace')>()),
20
15
  useFileNav: () => ({ openFile: vi.fn(), openWorkspacePath }),
21
16
  }));
22
17
 
23
18
  /**
24
- * A minimal stand-in for the SSE bus: keeps the handlers the component
25
- * registers and lets a test push events through them, so these assertions
26
- * drive the banner exactly the way the real backend does — by event, not by
27
- * poking state.
19
+ * The server's event stream, as the browser offers it. jsdom ships no
20
+ * EventSource; this one keeps the listeners the real `EventBusProvider`
21
+ * registers and lets a test send an event down the stream, so the banner is
22
+ * driven the way the backend drives it: by a message on the wire, through
23
+ * the provider the app mounts.
28
24
  */
29
- function makeBus() {
30
- // Handlers are stored untyped: the test emits plain event-shaped objects and
31
- // the component's own subscription types are what's under test, not the bus.
32
- const handlers = new Map<string, Set<(e: unknown) => void>>();
33
- const ctx = {
34
- subscribe(kind: string, handler: (e: unknown) => void) {
35
- const set = handlers.get(kind) ?? new Set<(e: unknown) => void>();
36
- set.add(handler);
37
- handlers.set(kind, set);
38
- return () => set.delete(handler);
39
- },
40
- } as unknown as EventBusContextValue;
41
- return {
42
- ctx,
43
- emit(event: { kind: string; workspaceId: string; branch: string; reason?: string }) {
44
- act(() => {
45
- for (const h of handlers.get(event.kind) ?? []) h(event);
46
- });
47
- },
48
- };
25
+ class FakeEventSource {
26
+ static latest: FakeEventSource | null = null;
27
+ private readonly listeners = new Map<string, ((e: Event) => void)[]>();
28
+ constructor() {
29
+ FakeEventSource.latest = this;
30
+ }
31
+ addEventListener(type: string, fn: (e: Event) => void) {
32
+ this.listeners.set(type, [...(this.listeners.get(type) ?? []), fn]);
33
+ }
34
+ removeEventListener(type: string, fn: (e: Event) => void) {
35
+ this.listeners.set(type, (this.listeners.get(type) ?? []).filter((f) => f !== fn));
36
+ }
37
+ close() {}
38
+ send(event: unknown) {
39
+ const message = new MessageEvent('message', { data: JSON.stringify(event) });
40
+ for (const fn of [...(this.listeners.get('message') ?? [])]) fn(message);
41
+ }
42
+ }
43
+
44
+ beforeEach(() => {
45
+ FakeEventSource.latest = null;
46
+ vi.stubGlobal('EventSource', FakeEventSource);
47
+ vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ status: 'ok' }), { status: 200 })));
48
+ });
49
+
50
+ afterEach(() => {
51
+ vi.unstubAllGlobals();
52
+ window.sessionStorage.clear();
53
+ });
54
+
55
+ /** Sends one event down the stream the mounted provider opened. */
56
+ function emit(event: {
57
+ kind: string;
58
+ workspaceId: string;
59
+ branch: string;
60
+ reason?: string;
61
+ conflictedPaths?: string[];
62
+ accessRefusal?: { path?: string };
63
+ }) {
64
+ act(() => {
65
+ FakeEventSource.latest?.send(event);
66
+ });
67
+ }
68
+
69
+ /** The workspace the banner stands in: what it reads of it, and nothing else. */
70
+ function workspaceValue(overrides: Partial<WorkspaceContextValue> = {}): WorkspaceContextValue {
71
+ return { workspaceId: 'ws-1', kbDirName: 'knowledge-base', ...overrides } as WorkspaceContextValue;
49
72
  }
50
73
 
51
74
  function renderBanner(workspace: Partial<WorkspaceContextValue> = {}) {
52
- const bus = makeBus();
53
- const view = render(
54
- <EventBusContext.Provider value={bus.ctx}>
55
- <WorkspaceContext.Provider value={makeWorkspaceFixture(workspace)}>
75
+ const tree = (value: Partial<WorkspaceContextValue>) => (
76
+ <EventBusProvider>
77
+ <WorkspaceContext.Provider value={workspaceValue(value)}>
56
78
  <GitSyncFailedBanner />
57
79
  </WorkspaceContext.Provider>
58
- </EventBusContext.Provider>,
80
+ </EventBusProvider>
59
81
  );
60
- const rerender = (next: Partial<WorkspaceContextValue>) =>
61
- view.rerender(
62
- <EventBusContext.Provider value={bus.ctx}>
63
- <WorkspaceContext.Provider value={makeWorkspaceFixture(next)}>
64
- <GitSyncFailedBanner />
65
- </WorkspaceContext.Provider>
66
- </EventBusContext.Provider>,
67
- );
68
- return { ...bus, rerender };
82
+ const view = render(tree(workspace));
83
+ return { emit, rerender: (next: Partial<WorkspaceContextValue>) => view.rerender(tree(next)) };
69
84
  }
70
85
 
71
86
  const FAILED = {
@@ -75,6 +90,10 @@ const FAILED = {
75
90
  reason: 'git push failed: fatal: Authentication failed',
76
91
  };
77
92
 
93
+ /** The backend's sentence for a viewer who may not read the blocking file. */
94
+ const UNNAMED_REFUSAL =
95
+ 'The platform’s access check refused the push of "feat/x": an unshared commit on it changes a file you may not read.';
96
+
78
97
  describe('GitSyncFailedBanner', () => {
79
98
  it('renders nothing until a failure arrives — the healthy case is invisible', () => {
80
99
  renderBanner();
@@ -119,6 +138,37 @@ describe('GitSyncFailedBanner', () => {
119
138
  expect(screen.queryByRole('alert')).toBeNull();
120
139
  });
121
140
 
141
+ it("says the platform's access check refused, not the git host, when the platform refused the push", () => {
142
+ const bus = renderBanner();
143
+ const reason =
144
+ 'The platform’s access check refused the push of "feat/x": "G/a.md" may be written by Admin; qa-b@example.com.';
145
+ bus.emit({ ...FAILED, reason, accessRefusal: { path: 'G/a.md' } });
146
+
147
+ const text = screen.getByRole('alert').textContent ?? '';
148
+ expect(text).toContain('feat/x');
149
+ expect(text).toContain('saved here but were not shared');
150
+ expect(text).toContain(reason);
151
+ // Who refused is said once, by the detail line.
152
+ expect(text.match(/access check refused the push/g)).toHaveLength(1);
153
+ expect(text).not.toMatch(/git host|server logs/i);
154
+ });
155
+
156
+ it('keeps the platform headline when the file was withheld from this person', () => {
157
+ const bus = renderBanner();
158
+ bus.emit({ ...FAILED, reason: UNNAMED_REFUSAL, accessRefusal: {} });
159
+ const text = screen.getByRole('alert').textContent ?? '';
160
+ expect(text).toContain('saved here but were not shared');
161
+ expect(text).toContain(UNNAMED_REFUSAL);
162
+ expect(text).not.toMatch(/git host|server logs/i);
163
+ });
164
+
165
+ it('a host failure after a platform refusal goes back to the git-host headline', () => {
166
+ const bus = renderBanner();
167
+ bus.emit({ ...FAILED, reason: UNNAMED_REFUSAL, accessRefusal: {} });
168
+ bus.emit(FAILED);
169
+ expect(screen.getByRole('alert').textContent).toContain('aren’t reaching your git host');
170
+ });
171
+
122
172
  it('does not let another workspace recovering clear this one’s banner', () => {
123
173
  const bus = renderBanner();
124
174
  bus.emit(FAILED);
@@ -252,18 +302,17 @@ describe('GitSyncFailedBanner — a conflict that arrives before the workspace h
252
302
 
253
303
  describe('GitSyncFailedBanner — for a named workspace (the change-request view)', () => {
254
304
  function renderFor(workspaceId: string, focused: Partial<WorkspaceContextValue> | null) {
255
- const bus = makeBus();
256
305
  const banner = <GitSyncFailedBanner workspaceId={workspaceId} />;
257
306
  render(
258
- <EventBusContext.Provider value={bus.ctx}>
307
+ <EventBusProvider>
259
308
  {focused ? (
260
- <WorkspaceContext.Provider value={makeWorkspaceFixture(focused)}>{banner}</WorkspaceContext.Provider>
309
+ <WorkspaceContext.Provider value={workspaceValue(focused)}>{banner}</WorkspaceContext.Provider>
261
310
  ) : (
262
311
  banner
263
312
  )}
264
- </EventBusContext.Provider>,
313
+ </EventBusProvider>,
265
314
  );
266
- return bus;
315
+ return { emit };
267
316
  }
268
317
 
269
318
  it('follows the named workspace, not the focused one', () => {
@@ -70,7 +70,10 @@ function ConflictFileNames({ paths }: { paths: string[] }) {
70
70
  * an expired token, a revoked repo grant, an unreachable host — is an operator
71
71
  * concern, and there is nothing the person writing a page can do about it. So
72
72
  * the copy tells them their work is safe and points whoever can act at the
73
- * logs, rather than explaining git.
73
+ * logs, rather than explaining git. The one push failure that is not the git
74
+ * host's is a refusal by the platform's own access check (`accessRefusal`):
75
+ * it gets its own headline, which blames no host and points at no logs, and
76
+ * its detail line says the platform refused.
74
77
  *
75
78
  * Clears on `git-sync-recovered`, which the backend emits when a push
76
79
  * succeeds after failing. No dismiss control, same as `PullNeededBanner`: the
@@ -106,7 +109,7 @@ export function GitSyncFailedBanner({ workspaceId: forWorkspaceId }: { workspace
106
109
  // transition). The alternative — clearing on switch — hides real, still-
107
110
  // broken state, which is the exact failure mode this PR exists to fix.
108
111
  const [failures, setFailures] = useState<
109
- ReadonlyMap<string, { branch: string; reason: string; conflictedPaths?: string[] }>
112
+ ReadonlyMap<string, { branch: string; reason: string; conflictedPaths?: string[]; refusedByPlatform: boolean }>
110
113
  >(new Map());
111
114
 
112
115
  useEventBusSubscription(
@@ -122,6 +125,7 @@ export function GitSyncFailedBanner({ workspaceId: forWorkspaceId }: { workspace
122
125
  branch: e.branch,
123
126
  reason: e.reason,
124
127
  conflictedPaths: e.conflictedPaths,
128
+ refusedByPlatform: e.accessRefusal !== undefined,
125
129
  }),
126
130
  );
127
131
  },
@@ -187,6 +191,30 @@ export function GitSyncFailedBanner({ workspaceId: forWorkspaceId }: { workspace
187
191
  );
188
192
  }
189
193
 
194
+ // The platform's own access check refused the push: the git host was never
195
+ // asked, and an operator's logs are not where the answer is. The headline
196
+ // says only that the work is safe and not shared; the detail line is the
197
+ // backend's sentence, which says who refused (the platform) and, as far as
198
+ // this person may be told, which file blocks the branch and who may write
199
+ // it. Saying who refused in both would name the same actor twice.
200
+ if (failure.refusedByPlatform) {
201
+ return (
202
+ <div
203
+ role="alert"
204
+ className="px-3 py-1.5 bg-sunken border-b border-line text-xs text-ink shrink-0"
205
+ >
206
+ <div className="flex items-center gap-2">
207
+ <AlertTriangle size={13} className="shrink-0" />
208
+ <span className="flex-1">
209
+ Changes on <span className="font-mono font-semibold">{failure.branch}</span> are saved
210
+ here but were not shared.
211
+ </span>
212
+ </div>
213
+ <div className="mt-1 ml-5 text-ink-muted break-words">{failure.reason}</div>
214
+ </div>
215
+ );
216
+ }
217
+
190
218
  return (
191
219
  <div
192
220
  role="alert"