@bevel-software/platform-core-frontend 0.21.0 → 0.23.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.
Files changed (72) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +2 -0
  3. package/src/core/registry.ts +140 -0
  4. package/src/lib/api.ts +49 -0
  5. package/src/modules/access/__tests__/ManageAccessDialog.request.test.tsx +376 -0
  6. package/src/modules/access/api.ts +6 -4
  7. package/src/modules/access/components/AccessRequestControl.tsx +155 -0
  8. package/src/modules/{library → access}/components/AccessRequestsBanner.tsx +62 -24
  9. package/src/modules/access/components/ManageAccessDialog.tsx +81 -4
  10. package/src/modules/access/hooks/useAccessRequests.ts +183 -0
  11. package/src/modules/access/requests.api.ts +121 -0
  12. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +89 -1
  13. package/src/modules/admin/components/UserAccountsPage.tsx +93 -5
  14. package/src/modules/auth/components/LoginScreen.tsx +8 -0
  15. package/src/modules/auth/services/account.api.ts +26 -3
  16. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +171 -38
  17. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +34 -19
  18. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +173 -6
  19. package/src/modules/change-requests/components/BranchFilePreview.tsx +7 -1
  20. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +155 -98
  21. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +89 -10
  22. package/src/modules/git/__tests__/HistoryVersionPreview.test.tsx +479 -0
  23. package/src/modules/git/components/FileHistoryPanel.tsx +52 -65
  24. package/src/modules/git/components/HistoryVersionPreview.tsx +410 -0
  25. package/src/modules/layout/__tests__/ReadOnlyBanner.test.tsx +157 -0
  26. package/src/modules/layout/components/ReadOnlyBanner.tsx +96 -0
  27. package/src/modules/library/__tests__/SkillPage.test.tsx +15 -0
  28. package/src/modules/library/__tests__/ToolPage.test.tsx +15 -1
  29. package/src/modules/library/__tests__/title-row-actions.ts +53 -1
  30. package/src/modules/library/components/PluginJoinRequests.tsx +2 -2
  31. package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
  32. package/src/modules/library/components/tool-page/ToolPage.tsx +11 -1
  33. package/src/modules/library/hooks/useJoinRequests.ts +26 -101
  34. package/src/modules/pr/services/pr-merge.api.ts +10 -2
  35. package/src/modules/settings/components/DeploymentPage.tsx +22 -0
  36. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +72 -4
  37. package/src/modules/setup/__tests__/setup.first-run.test.tsx +276 -0
  38. package/src/modules/setup/__tests__/setup.github.test.tsx +416 -0
  39. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +275 -0
  40. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +296 -0
  41. package/src/modules/setup/__tests__/setup.repository.test.tsx +463 -0
  42. package/src/modules/setup/__tests__/setup.test.tsx +13 -17
  43. package/src/modules/setup/components/GitHubRepositoryPanel.tsx +369 -0
  44. package/src/modules/setup/components/SetupGate.tsx +1 -0
  45. package/src/modules/setup/components/SetupScreen.tsx +608 -41
  46. package/src/modules/setup/services/setup.api.ts +171 -3
  47. package/src/modules/setup/utils/kept-draft.ts +86 -0
  48. package/src/modules/workspace/components/FileExplorer.tsx +140 -12
  49. package/src/modules/workspace/components/FileViewer.tsx +11 -1
  50. package/src/modules/workspace/components/TreeActionConfirm.tsx +5 -7
  51. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +603 -29
  52. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +23 -6
  53. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +41 -8
  54. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +20 -5
  55. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +39 -16
  56. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +27 -7
  57. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +20 -5
  58. package/src/modules/workspace/components/renderers/RetryReadButton.tsx +37 -0
  59. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +20 -5
  60. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +186 -7
  61. package/src/modules/workspace/components/renderers/__tests__/readPane.test.tsx +59 -0
  62. package/src/modules/workspace/components/renderers/htmlSandbox.ts +80 -20
  63. package/src/modules/workspace/components/renderers/index.ts +6 -1
  64. package/src/modules/workspace/components/renderers/readPane.ts +22 -0
  65. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +50 -9
  66. package/src/modules/workspace/components/renderers/useReadRetry.ts +27 -0
  67. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +79 -0
  68. package/src/modules/workspace/routing/kb-routes.ts +25 -10
  69. package/src/modules/workspace/services/workspace.api.ts +22 -1
  70. package/src/shared/components/SlotBoundary.tsx +51 -0
  71. package/src/shared/markdown/__tests__/hrefs.test.ts +111 -0
  72. package/src/shared/markdown/hrefs.ts +80 -4
@@ -7,6 +7,7 @@ import {
7
7
  CanDownloadContext,
8
8
  DownloadFileButton,
9
9
  } from '../../workspace/components/renderers/DownloadFileButton';
10
+ import { READ_PANE } from '../../workspace/components/renderers/readPane';
10
11
  import {
11
12
  RendererWorkspaceContext,
12
13
  getFileRenderer,
@@ -298,7 +299,12 @@ export function BranchFilePreview({
298
299
  return (
299
300
  <div className="flex h-full min-h-0 flex-col">
300
301
  {header}
301
- <div className="min-h-0 flex-1">{body}</div>
302
+ {/* The pane's own region: a viewer's "Try again" unmounts itself, and
303
+ this is what stays mounted around it for focus to land on — see
304
+ `RetryReadButton`. */}
305
+ <div {...READ_PANE} className="min-h-0 flex-1">
306
+ {body}
307
+ </div>
302
308
  </div>
303
309
  );
304
310
  }
@@ -142,23 +142,36 @@ export function ChangeRequestDialog({
142
142
  const [baseRevision, setBaseRevision] = useState(0);
143
143
 
144
144
  /**
145
- * The request has fallen behind AND this reader is one of the people who
146
- * may bring it up to date (its author, an admin, or anyone who may apply
147
- * it). The server re-checks the same predicate; this only decides whether
148
- * the dialog reaches for the update at all.
145
+ * This request needs bringing up to date AND this reader is one of the
146
+ * people who may do it (its author, an admin, or anyone who may apply it).
147
+ * The server re-checks the same predicate; this only decides whether the
148
+ * dialog reaches for the update at all.
149
+ *
150
+ * `needsUpdate`, NOT `behind`. `behind` is true whenever the target holds
151
+ * any commit this request does not — which, on a knowledge base where every
152
+ * shared save commits to the default branch, is true again minutes after
153
+ * every update. Reaching for the merge on that answer made opening a
154
+ * request pay for one on almost every open, for a change to a file the
155
+ * request does not contain. `needsUpdate` adds the half that matters: the
156
+ * target moved in a file THIS request also changes.
149
157
  */
150
- const behindAndUpdatable =
151
- detail !== null && detail.state === 'open' && detail.behind && detail.viewerCanUpdate;
158
+ const needsUpdateByThisReader =
159
+ detail !== null && detail.state === 'open' && detail.needsUpdate && detail.viewerCanUpdate;
152
160
  /**
153
- * Mid-update: the dialog shows one status line and NO file content.
161
+ * Mid-update: the files are on screen, with one status line above them, and
162
+ * the two verbs that would act on them are held.
163
+ *
164
+ * The files are NOT hidden. They are the proposal, read at the fork point,
165
+ * and a target that moved in one of them does not make the other nineteen
166
+ * untrue — where hiding them made every reader wait out a merge before
167
+ * seeing anything. What the update can change is the verdict, so Approve
168
+ * and Apply wait for it and the reading does not.
154
169
  *
155
170
  * Derived rather than stored, so it is already true on the very render the
156
- * detail arrives on — a frame of pre-update files, immediately replaced,
157
- * would be the dialog showing a version of the change that is about to stop
158
- * being true. It also holds the file reads back (see the read effect), so
159
- * nothing is fetched against a head the server is in the middle of moving.
171
+ * detail arrives on: the note and the disabled verbs appear WITH the files,
172
+ * never a frame after them.
160
173
  */
161
- const bringingUpToDate = !autoUpdateSettled && behindAndUpdatable && !blocked;
174
+ const bringingUpToDate = !autoUpdateSettled && needsUpdateByThisReader && !blocked;
162
175
 
163
176
  const isTop = useModalLayer(true);
164
177
  useEffect(() => {
@@ -308,25 +321,19 @@ export function ChangeRequestDialog({
308
321
  const asked = useRef<Map<string, object>>(new Map());
309
322
  useEffect(() => {
310
323
  // `selected` is '' until the detail names any file in an unscoped dialog —
311
- // nothing to read yet. Binary files are never read at all (above). A read
312
- // held back while the request is being brought up to date is not skipped:
313
- // `bringingUpToDate` is a dependency, so it fires the moment the update
314
- // settles — against the head the merge left, never the one it replaced.
324
+ // nothing to read yet. Binary files are never read at all (above).
325
+ //
326
+ // A running update does NOT hold this back. The content read here is the
327
+ // proposal as it stands, which is what the reader opened the dialog for;
328
+ // an update in flight can move it, and when it lands it says which files
329
+ // it moved (`updatedPaths`) and exactly those are read again. Waiting
330
+ // instead bought one thing — never showing a line the merge later changes
331
+ // — at the price of showing nothing at all for as long as the merge took.
315
332
  //
316
- // Nothing is read before the DETAIL either, even though a dialog opened
317
- // about a file has a selection from the first render (`initialPath`): until
318
- // the detail says whether this request is behind and whether this reader
319
- // may update it, there is no way to know that the branch is not about to
320
- // move. Reading first would spend a request on content the update then
321
- // throws away, and the pane cannot draw a diff before the detail names its
322
- // fork point regardless.
323
- if (
324
- detail !== null &&
325
- !bringingUpToDate &&
326
- selected &&
327
- !selectedIsBinary &&
328
- !asked.current.has(selected)
329
- ) {
333
+ // Nothing is read before the DETAIL, though: a dialog opened about a file
334
+ // has a selection from the first render (`initialPath`), and the pane
335
+ // cannot draw a diff before the detail names its fork point.
336
+ if (detail !== null && selected && !selectedIsBinary && !asked.current.has(selected)) {
330
337
  const token = {};
331
338
  asked.current.set(selected, token);
332
339
  const current = () => asked.current.get(selected) === token;
@@ -347,7 +354,7 @@ export function ChangeRequestDialog({
347
354
  }),
348
355
  );
349
356
  }
350
- }, [selected, selectedIsBinary, cr.branch, branchRevision, bringingUpToDate, detail]);
357
+ }, [selected, selectedIsBinary, cr.branch, branchRevision, detail]);
351
358
 
352
359
  /**
353
360
  * Read the selected file again, both sides — the Retry link the retryable
@@ -415,11 +422,13 @@ export function ChangeRequestDialog({
415
422
  // Raw-vs-raw: the skills API hands back SKILL.md's PARSED body (frontmatter
416
423
  // stripped), and diffing that against a raw branch read renders the
417
424
  // frontmatter as a deletion and the whole file as changed.
418
- // Nothing is read while the request is being brought up to date, on this
419
- // side either: the fork point is exactly what the merge moves, so a read
420
- // started now would answer about a fork point that no longer exists.
425
+ // A running update moves the fork point, so this read can answer about one
426
+ // that is about to be replaced — and is re-run when it is (`baseRevision`,
427
+ // bumped with `branchRevision` when an update lands). Reading now is what
428
+ // lets the reader see the change at once; the correction, where there is
429
+ // one, costs the files the merge actually touched.
421
430
  const beforePath =
422
- isAdded || renameWithoutOldPath || !selected || selectedIsBinary || bringingUpToDate
431
+ isAdded || renameWithoutOldPath || !selected || selectedIsBinary
423
432
  ? null
424
433
  : (movedFrom ?? selected);
425
434
  /**
@@ -647,8 +656,16 @@ export function ChangeRequestDialog({
647
656
  setVerbError(null);
648
657
  }, [selected]);
649
658
 
659
+ /**
660
+ * Approving and applying are held while the open's update runs — the two
661
+ * verbs that decide the request, and the only two things the merge can
662
+ * change the answer to. An approval recorded now would be pinned to a head
663
+ * the merge is about to replace, and an apply would be a second merge on
664
+ * the same two branches. The buttons are disabled; these guards are what
665
+ * make that true rather than merely drawn.
666
+ */
650
667
  async function toggleApprove(path: string, approved: boolean) {
651
- if (!detail || verbBusy) return;
668
+ if (!detail || verbBusy || bringingUpToDate) return;
652
669
  setVerbBusy(true);
653
670
  setVerbError(null);
654
671
  try {
@@ -670,7 +687,7 @@ export function ChangeRequestDialog({
670
687
  * instead of one per file.
671
688
  */
672
689
  async function approveAllMine(paths: string[]) {
673
- if (!detail || verbBusy) return;
690
+ if (!detail || verbBusy || bringingUpToDate) return;
674
691
  setVerbBusy(true);
675
692
  setVerbError(null);
676
693
  try {
@@ -800,9 +817,22 @@ export function ChangeRequestDialog({
800
817
  detail.approvals.length > 0 &&
801
818
  detail.approvals.filter((a) => a.inMergeGate).every((a) => a.isApproved);
802
819
 
803
- /** Admin-only: delete the request and its branch, with an armed confirm. */
820
+ /**
821
+ * The author's or an admin's: delete the request AND its branch, with an
822
+ * armed confirm. `viewerCanDelete` is the server's verdict on both grants.
823
+ */
804
824
  const [deleteArmed, setDeleteArmed] = useState(false);
805
825
  const [deleting, setDeleting] = useState(false);
826
+ /**
827
+ * The armed button names the branch it is about to remove — except for a
828
+ * `suggestions/...` branch, which the platform named for the author and
829
+ * which they never chose: showing them that internal path asks them to
830
+ * confirm something they have no way to recognise. Authors and admins read
831
+ * the same sentence; what varies is the branch, not who is looking.
832
+ */
833
+ const armedDeleteLabel = cr.branch.startsWith('suggestions/')
834
+ ? 'Really delete request and branch?'
835
+ : `Really delete request and branch ${cr.branch}?`;
806
836
  async function deleteRequest() {
807
837
  if (deleting) return;
808
838
  setDeleting(true);
@@ -856,28 +886,45 @@ export function ChangeRequestDialog({
856
886
  setUpdating(true);
857
887
  setError(null);
858
888
  try {
859
- await refreshChangeRequestFromTarget(cr.number);
889
+ const result = await refreshChangeRequestFromTarget(cr.number);
860
890
  // The branch moved, so every list and every change box behind this
861
891
  // dialog is out of date — including their fork points, which this is
862
892
  // the only thing that moves.
863
893
  window.dispatchEvent(new Event(PR_STALE_EVENT));
864
- // The branch has moved: every copy read so far predates the merge.
865
- // Forget them now, before anything else can fail, so the dialog never
866
- // goes on showing the pre-update text for a branch the server merged.
867
- asked.current.clear();
868
- setBranchContents({});
869
- setBranchFailure(new Map());
870
- try {
871
- // Re-read in the same render the fresh detail (and so the fresh fork
872
- // point) lands in.
873
- const seq = ++detailSeq.current;
874
- const next = await fetchPrDetail(cr.number, { fresh: true });
875
- if (seq === detailSeq.current) setDetail(next);
876
- } catch {
877
- setError("Updated, but couldn't reload this change request. Close it and open it again.");
878
- } finally {
879
- setBranchRevision((r) => r + 1);
894
+ // Forget the copies the merge actually changed — git's own verdict on
895
+ // which, from the server that ran it — before anything else can fail,
896
+ // so the dialog never goes on showing pre-update text for a file the
897
+ // merge rewrote.
898
+ //
899
+ // ONLY those. The reader is looking at these files right now: dropping
900
+ // every copy would blank the pane they are mid-sentence in and re-read
901
+ // the whole request to replace the one file that moved. An unknown
902
+ // answer is not silence — the server sends the request's whole file
903
+ // list when it could not diff, so "drop everything" is still reachable,
904
+ // just no longer the default.
905
+ for (const path of result.updatedPaths) {
906
+ asked.current.delete(path);
880
907
  }
908
+ if (result.updatedPaths.length > 0) {
909
+ const updated = new Set(result.updatedPaths);
910
+ setBranchContents((c) =>
911
+ Object.fromEntries(Object.entries(c).filter(([path]) => !updated.has(path))),
912
+ );
913
+ setBranchFailure((m) => new Map([...m].filter(([path]) => !updated.has(path))));
914
+ }
915
+ // The Update's own answer IS the fresh detail — the server assembled it
916
+ // after the merge, with the carried approvals already in it. Fetching
917
+ // the detail again here would make the server build a second one that
918
+ // can only say the same thing, on the slowest path the dialog has.
919
+ //
920
+ // `detailSeq` still gates it: a detail fetch this dialog started before
921
+ // the update must not land on top of this one.
922
+ const seq = ++detailSeq.current;
923
+ if (seq === detailSeq.current) setDetail(result);
924
+ // The fork point moved with the branch, so the "before" side of the
925
+ // open file is re-read too — one file, not the request.
926
+ setBranchRevision((r) => r + 1);
927
+ setBaseRevision((r) => r + 1);
881
928
  setBroughtUpToDate(true);
882
929
  } catch (err) {
883
930
  const conflicts =
@@ -909,10 +956,11 @@ export function ChangeRequestDialog({
909
956
  const autoUpdateStarted = useRef(false);
910
957
  useEffect(() => {
911
958
  if (autoUpdateStarted.current || autoUpdateSettled) return;
912
- // A viewer who may not update it, a request that is not open or not
913
- // behind, and a conflict already on screen are all ruled out here rather
914
- // than recorded: none of them can turn back into an update this open owes.
915
- if (detail === null || !behindAndUpdatable || blocked) return;
959
+ // A viewer who may not update it, a request that is not open or does not
960
+ // need one, and a conflict already on screen are all ruled out here
961
+ // rather than recorded: none of them can turn back into an update this
962
+ // open owes.
963
+ if (detail === null || !needsUpdateByThisReader || blocked) return;
916
964
  // An apply is a merge on the same two branches; two at once is how a
917
965
  // request ends up half-landed. Not settled — just held, so an apply that
918
966
  // fails without conflicting still lets this through afterwards.
@@ -923,15 +971,15 @@ export function ChangeRequestDialog({
923
971
  autoUpdateStarted.current = true;
924
972
  // The synchronous setState this reaches is the in-flight marker every
925
973
  // effect that starts async work has to raise — the render it costs is the
926
- // one that swaps the files for "Bringing this up to date…", which is the
927
- // whole point. Deferring it would show the pre-update files for a frame.
974
+ // one that disables Approve and Apply. Deferring it would leave them live
975
+ // for a frame, over a verdict the merge is about to move.
928
976
  // eslint-disable-next-line react-hooks/set-state-in-effect
929
977
  void updateFromTarget();
930
978
  // `updateFromTarget` is re-created every render and is deliberately not a
931
979
  // dependency: the guards above are what make this run once, not the dep
932
980
  // list.
933
981
  // eslint-disable-next-line react-hooks/exhaustive-deps
934
- }, [autoUpdateSettled, detail, behindAndUpdatable, blocked, applyBusy]);
982
+ }, [autoUpdateSettled, detail, needsUpdateByThisReader, blocked, applyBusy]);
935
983
 
936
984
  // Name the step: recording approvals and merging are separately slow, and one
937
985
  // label over both makes the longer half look stalled.
@@ -1087,15 +1135,16 @@ export function ChangeRequestDialog({
1087
1135
  </Banner>
1088
1136
  )}
1089
1137
 
1090
- {/* The target moved on after this was proposed, and this reader is not
1091
- one of the people who can do anything about it. Everyone who can
1092
- never sees this: the dialog has already brought the request up to
1093
- date by the time it would render, or is saying so above.
1138
+ {/* The target moved on IN A FILE THIS REQUEST CHANGES, and this reader
1139
+ is not one of the people who can do anything about it. A target
1140
+ that moved elsewhere says nothing here, because nothing about this
1141
+ request has gone stale. Everyone who CAN update it never sees this
1142
+ either: the dialog is already doing it, or has said so above.
1094
1143
  "What everyone sees" is the phrase the Deployment page uses for
1095
1144
  the same thing — a business user does not know what a branch is,
1096
1145
  and this dialog never tells them. */}
1097
1146
  {detail !== null &&
1098
- detail.behind &&
1147
+ detail.needsUpdate &&
1099
1148
  detail.state === 'open' &&
1100
1149
  !detail.viewerCanUpdate &&
1101
1150
  !blocked && (
@@ -1116,31 +1165,33 @@ export function ChangeRequestDialog({
1116
1165
  </p>
1117
1166
  )}
1118
1167
 
1119
- {/* The update the open is running, in place of the files. NOT beside
1120
- them: the file content that exists right now is the proposal
1121
- against text that has already moved, and showing it for the second
1122
- or two the merge takes would be the dialog answering the reader's
1123
- question wrongly and then correcting itself. */}
1124
- {bringingUpToDate ? (
1125
- <div className="mt-4 min-h-0 flex-1 px-8">
1126
- <p
1127
- role="status"
1128
- className="mx-auto max-w-[52ch] py-10 text-center text-detail text-ink-faint"
1129
- >
1130
- Bringing this up to date with what everyone sees…
1131
- </p>
1132
- </div>
1133
- ) : /* A request that no longer changes anything — everything it proposed
1168
+ {/* The update the open is running, ABOVE the files rather than in
1169
+ place of them. The proposal is on screen from the first render and
1170
+ stays there: a merge into a file it changes can move a line or two
1171
+ of it, which is worth saying and is not worth making every reader
1172
+ wait through a merge to see anything at all. What the update can
1173
+ change is the VERDICT, so Approve and Apply are the two things
1174
+ that wait for it (below), and the reading does not. */}
1175
+ {bringingUpToDate && (
1176
+ <p role="status" className="mt-3 px-8 text-detail text-ink-faint">
1177
+ Checking against the latest version…
1178
+ </p>
1179
+ )}
1180
+
1181
+ {/* A request that no longer changes anything — everything it proposed
1134
1182
  has since landed on (or been removed from) the target, or its only
1135
1183
  change was one the merge never takes (roles.yaml). The file grid
1136
1184
  below would render a blank pill over an eternal "Loading…", which
1137
- reads as a hang; the truth is simpler and gets said instead. */
1138
- detail !== null && allFiles.length === 0 ? (
1185
+ reads as a hang; the truth is simpler and gets said instead. */}
1186
+ {detail !== null && allFiles.length === 0 ? (
1139
1187
  <div className="mt-4 min-h-0 flex-1 px-8">
1140
1188
  <p className="mx-auto max-w-[52ch] py-10 text-center text-detail text-ink-faint">
1141
1189
  This request doesn't change anything anymore. What it proposed is already part of
1142
1190
  the current text, or has since been removed on its branch — there is nothing left
1143
- to review or apply. {firstName} can withdraw it.
1191
+ to review or apply.{' '}
1192
+ {/* Withdraw is not in this dialog; Delete is, right below. Point
1193
+ at the verb the reader can actually reach from here. */}
1194
+ {detail.viewerIsAuthor ? 'You can delete it below.' : `${firstName} can delete it.`}
1144
1195
  </p>
1145
1196
  </div>
1146
1197
  ) : (
@@ -1185,7 +1236,7 @@ export function ChangeRequestDialog({
1185
1236
  variant={headerVerb === 'approve' ? 'primary' : 'outline'}
1186
1237
  size="tiny"
1187
1238
  className="ml-auto shrink-0"
1188
- disabled={verbBusy || applyBusy}
1239
+ disabled={verbBusy || applyBusy || bringingUpToDate}
1189
1240
  onClick={() => void toggleApprove(selected, headerVerb === 'undo')}
1190
1241
  >
1191
1242
  {headerVerb === 'approve' ? 'Approve this file' : 'Approved – Undo'}
@@ -1309,11 +1360,11 @@ export function ChangeRequestDialog({
1309
1360
  <div className="mt-4 border-t border-line bg-sunken px-8 py-4">
1310
1361
  {/* What is the viewer's to approve, above the verdict: a count and
1311
1362
  one button for all of them, or who everyone is waiting on. */}
1312
- {/* Nothing to approve or wait on while the files are hidden: the
1313
- verdict belongs to the request as it will stand after the
1314
- update, which is a second away. */}
1363
+ {/* Shown during a running update too, with its button disabled: the
1364
+ files are on screen, so the line that says whose approval they
1365
+ are waiting on belongs on screen with them. Only the ACT of
1366
+ approving waits for the merge. */}
1315
1367
  {!blocked &&
1316
- !bringingUpToDate &&
1317
1368
  detail !== null &&
1318
1369
  allFiles.length > 0 &&
1319
1370
  (mine.length > 0 || !canApply) && (
@@ -1330,7 +1381,7 @@ export function ChangeRequestDialog({
1330
1381
  <Button
1331
1382
  variant="outline"
1332
1383
  size="sm"
1333
- disabled={verbBusy || applyBusy}
1384
+ disabled={verbBusy || applyBusy || bringingUpToDate}
1334
1385
  onClick={() => void approveAllMine(mine)}
1335
1386
  >
1336
1387
  Approve all mine
@@ -1352,10 +1403,13 @@ export function ChangeRequestDialog({
1352
1403
  ? 'Every agent that connects after this picks it up. There is no staged rollout.'
1353
1404
  : ''}
1354
1405
  </p>
1355
- {/* Admins carry the moderation verb: delete the request AND its
1356
- branch, armed on the first click. `viewerCanBypassMerge` is the
1357
- server's admin verdict — the DELETE route re-checks it. */}
1358
- {!blocked && detail?.viewerCanBypassMerge && (
1406
+ {/* The author and admins carry the destructive verb: delete the
1407
+ request AND its branch, armed on the first click.
1408
+ `viewerCanDelete` is the server's verdict on both grants — the
1409
+ DELETE route re-checks it. Shown while `blocked` on purpose: a
1410
+ request stuck on a conflict is exactly the one its author most
1411
+ wants to throw away and propose again. */}
1412
+ {detail?.viewerCanDelete && (
1359
1413
  deleteArmed ? (
1360
1414
  <>
1361
1415
  <Button
@@ -1364,7 +1418,7 @@ export function ChangeRequestDialog({
1364
1418
  disabled={deleting}
1365
1419
  onClick={() => void deleteRequest()}
1366
1420
  >
1367
- {deleting ? 'Deleting…' : 'Really delete request and branch?'}
1421
+ {deleting ? 'Deleting…' : armedDeleteLabel}
1368
1422
  </Button>
1369
1423
  <Button variant="quiet" size="sm" disabled={deleting} onClick={() => setDeleteArmed(false)}>
1370
1424
  Keep
@@ -1386,11 +1440,14 @@ export function ChangeRequestDialog({
1386
1440
  but every one of them approvable BY THIS VIEWER (write access) →
1387
1441
  the same click, named for what it is: their authority covers the
1388
1442
  missing approvals. Anyone else gets the waiting line above. */}
1389
- {!blocked && !bringingUpToDate && canApply && (
1443
+ {/* Rendered throughout a running update, disabled rather than
1444
+ absent: a primary button that appears under the reader's cursor
1445
+ a second after the dialog opens is a click they did not aim. */}
1446
+ {!blocked && canApply && (
1390
1447
  <Button
1391
1448
  variant="primary"
1392
1449
  size="sm"
1393
- disabled={applyBusy || verbBusy}
1450
+ disabled={applyBusy || verbBusy || bringingUpToDate}
1394
1451
  onClick={() => applying.apply(cr)}
1395
1452
  >
1396
1453
  {applyBusy ? applyLabel : allApproved ? 'Apply changes' : 'Bypass approval and apply'}
@@ -1,7 +1,22 @@
1
- import { describe, it, expect, vi } from 'vitest';
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
2
  import { render, screen, waitFor, fireEvent } from '@testing-library/react';
3
+ import { MemoryRouter } from 'react-router-dom';
3
4
  import type { BranchInfo, CommitAttribution, WorkingTreeStatus } from '@bevel-software/platform-shared';
4
5
 
6
+ /**
7
+ * The version pane the panel now mounts for every non-markdown file reads
8
+ * bytes and resolves the file's `download:` verb. Both are stubbed so these
9
+ * tests stay about the PANEL — which save is selected, and which of the two
10
+ * histories it routes to.
11
+ */
12
+ const apiMock = vi.hoisted(() => ({ authFetch: vi.fn() }));
13
+ vi.mock('../../../lib/api', () => ({ authFetch: apiMock.authFetch }));
14
+ const accessMock = vi.hoisted(() => ({ fetchFileAccess: vi.fn() }));
15
+ vi.mock('../../access/api', async (importOriginal) => ({
16
+ ...(await importOriginal<object>()),
17
+ fetchFileAccess: accessMock.fetchFileAccess,
18
+ }));
19
+
5
20
  import { FileHistoryPanel } from '../components/FileHistoryPanel';
6
21
  import { GitContext, type GitContextValue } from '../state/git.context';
7
22
  import {
@@ -53,14 +68,38 @@ const workspace = {
53
68
 
54
69
  function renderWith(git: GitContextValue, filePath = 'knowledge-base/Knowledge/Foo.md') {
55
70
  return render(
56
- <WorkspaceContext.Provider value={workspace}>
57
- <GitContext.Provider value={git}>
58
- <FileHistoryPanel filePath={filePath} />
59
- </GitContext.Provider>
60
- </WorkspaceContext.Provider>,
71
+ <MemoryRouter initialEntries={[`/workspace/ws-1/${filePath}`]}>
72
+ <WorkspaceContext.Provider value={workspace}>
73
+ <GitContext.Provider value={git}>
74
+ <FileHistoryPanel filePath={filePath} />
75
+ </GitContext.Provider>
76
+ </WorkspaceContext.Provider>
77
+ </MemoryRouter>,
61
78
  );
62
79
  }
63
80
 
81
+ beforeEach(() => {
82
+ apiMock.authFetch.mockReset();
83
+ apiMock.authFetch.mockResolvedValue({
84
+ ok: true,
85
+ status: 200,
86
+ blob: async () => new Blob(['bytes']),
87
+ arrayBuffer: async () => new ArrayBuffer(8),
88
+ text: async () => '',
89
+ });
90
+ accessMock.fetchFileAccess.mockReset();
91
+ accessMock.fetchFileAccess.mockResolvedValue({
92
+ canWrite: false,
93
+ canDownload: true,
94
+ eligible: { roles: [], users: [] },
95
+ owners: { roles: [], users: [] },
96
+ });
97
+ (globalThis.URL as unknown as { createObjectURL: unknown }).createObjectURL = vi.fn(
98
+ () => 'blob:fake-url',
99
+ );
100
+ (globalThis.URL as unknown as { revokeObjectURL: unknown }).revokeObjectURL = vi.fn();
101
+ });
102
+
64
103
  describe('FileHistoryPanel', () => {
65
104
  it('renders the timeline returned from fetchFileHistory', async () => {
66
105
  const history = [
@@ -105,7 +144,7 @@ describe('FileHistoryPanel', () => {
105
144
  expect(screen.getByText('shared paragraph')).toBeInTheDocument();
106
145
  });
107
146
 
108
- it('loads the raw diff when a non-markdown file\'s commit is selected', async () => {
147
+ it('loads the line changes for a text file no viewer renders', async () => {
109
148
  const fetchFileDiff = vi.fn(async () => '--- a\n+++ b\n@@ -1 +1 @@\n-foo\n+bar\n');
110
149
  const history = [makeAttr({ sha: 'aaaaaaa0000000000', subject: 'edit' })];
111
150
  renderWith(
@@ -113,13 +152,13 @@ describe('FileHistoryPanel', () => {
113
152
  fetchFileHistory: async () => history,
114
153
  fetchFileDiff,
115
154
  }),
116
- 'knowledge-base/Knowledge/data.csv',
155
+ 'knowledge-base/Knowledge/notes.txt',
117
156
  );
118
157
  const row = await screen.findByText('edit');
119
158
  fireEvent.click(row);
120
159
  await waitFor(() =>
121
160
  expect(fetchFileDiff).toHaveBeenCalledWith(
122
- 'knowledge-base/Knowledge/data.csv',
161
+ 'knowledge-base/Knowledge/notes.txt',
123
162
  'aaaaaaa0000000000',
124
163
  ),
125
164
  );
@@ -133,12 +172,52 @@ describe('FileHistoryPanel', () => {
133
172
  fetchFileHistory: async () => history,
134
173
  fetchFileDiff: async () => '',
135
174
  }),
136
- 'knowledge-base/Knowledge/data.csv',
175
+ 'knowledge-base/Knowledge/notes.txt',
137
176
  );
138
177
  fireEvent.click(await screen.findByText('edit'));
139
178
  expect(await screen.findByText(/No file changes in this save/i)).toBeInTheDocument();
140
179
  });
141
180
 
181
+ it('routes a previewable file\'s save to the version pane, not the patch', async () => {
182
+ // A CSV is previewable, so the pane shows the table of that save with the
183
+ // line changes a click away — where it used to show the patch and nothing
184
+ // else.
185
+ const history = [makeAttr({ sha: 'aaaaaaa0000000000', subject: 'edit' })];
186
+ renderWith(
187
+ makeGit({
188
+ fetchFileHistory: async () => history,
189
+ fetchFileDiff: async () => '--- a\n+++ b\n@@ -1 +1 @@\n-a,b\n+a,c\n',
190
+ fetchFileAtChange: async () => ({ baseline: 'a,b', current: 'region,total\n EMEA,7' }),
191
+ }),
192
+ 'knowledge-base/Knowledge/data.csv',
193
+ );
194
+ fireEvent.click(await screen.findByText('edit'));
195
+ expect(await screen.findByText('region')).toBeInTheDocument();
196
+ expect(await screen.findByRole('button', { name: 'Download this version' })).toBeInTheDocument();
197
+ fireEvent.click(screen.getByRole('button', { name: 'Source changes' }));
198
+ expect(await screen.findByText(/\+a,c/)).toBeInTheDocument();
199
+ });
200
+
201
+ it('leaves a markdown history untouched: no version pane, no download', async () => {
202
+ const fetchFileDiff = vi.fn(async () => 'unused');
203
+ const history = [makeAttr({ sha: 'aaaaaaa0000000000', subject: 'edit' })];
204
+ renderWith(
205
+ makeGit({
206
+ fetchFileHistory: async () => history,
207
+ fetchFileDiff,
208
+ fetchFileAtChange: async () => ({ baseline: '# Old\n', current: '# New\n' }),
209
+ }),
210
+ );
211
+ fireEvent.click(await screen.findByText('edit'));
212
+ expect(await screen.findByRole('heading', { name: 'New' })).toBeInTheDocument();
213
+ // The markdown path reads before/after contents and nothing else — no
214
+ // patch, no version pane, no bytes.
215
+ expect(fetchFileDiff).not.toHaveBeenCalled();
216
+ expect(screen.queryByRole('button', { name: 'Download this version' })).toBeNull();
217
+ expect(screen.queryByText(/As saved/)).toBeNull();
218
+ expect(apiMock.authFetch).not.toHaveBeenCalled();
219
+ });
220
+
142
221
  it('renders the empty state for a markdown save where the file is absent on both sides', async () => {
143
222
  const history = [makeAttr({ sha: 'aaaaaaa0000000000', subject: 'edit' })];
144
223
  renderWith(