@bevel-software/platform-core-frontend 0.1.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 (203) hide show
  1. package/LICENSE +202 -0
  2. package/package.json +70 -0
  3. package/src/core/CoreAppShell.tsx +444 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +95 -0
  5. package/src/core/events.ts +29 -0
  6. package/src/core/registry.ts +336 -0
  7. package/src/css-side-effect-imports.d.ts +7 -0
  8. package/src/html-extensions.ts +12 -0
  9. package/src/index.css +49 -0
  10. package/src/index.ts +23 -0
  11. package/src/lib/api.ts +57 -0
  12. package/src/lib/utils.ts +138 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +130 -0
  14. package/src/modules/access/__tests__/useFileAccess.test.tsx +253 -0
  15. package/src/modules/access/api.ts +205 -0
  16. package/src/modules/access/components/AccessRestrictedBanner.tsx +31 -0
  17. package/src/modules/access/components/ManageAccessDialog.tsx +1232 -0
  18. package/src/modules/access/components/NodeOwnersBanner.tsx +30 -0
  19. package/src/modules/access/hooks/useFileAccess.ts +151 -0
  20. package/src/modules/admin/components/AdminRolesPage.tsx +943 -0
  21. package/src/modules/admin/components/RolesCorruptedBanner.tsx +74 -0
  22. package/src/modules/admin/services/admin.api.ts +92 -0
  23. package/src/modules/admin/services/roles.api.ts +136 -0
  24. package/src/modules/admin/state/admin.context.tsx +223 -0
  25. package/src/modules/auth/components/LoginScreen.tsx +135 -0
  26. package/src/modules/auth/hooks/useAuthState.ts +59 -0
  27. package/src/modules/auth/services/auth.api.ts +24 -0
  28. package/src/modules/auth/services/microsoft-oauth.ts +57 -0
  29. package/src/modules/auth/state/auth.context.ts +18 -0
  30. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +347 -0
  31. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +201 -0
  32. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +82 -0
  33. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +441 -0
  34. package/src/modules/git/__tests__/git.api.test.ts +113 -0
  35. package/src/modules/git/__tests__/pr.api.test.ts +44 -0
  36. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +212 -0
  37. package/src/modules/git/components/BranchSwitcher.tsx +527 -0
  38. package/src/modules/git/components/DiffView.tsx +30 -0
  39. package/src/modules/git/components/FileComparisonPanel.tsx +377 -0
  40. package/src/modules/git/components/FileHistoryPanel.tsx +320 -0
  41. package/src/modules/git/components/ProtectedBranchBanner.tsx +42 -0
  42. package/src/modules/git/components/PullNeededBanner.tsx +204 -0
  43. package/src/modules/git/components/PullRequestsForMe.tsx +244 -0
  44. package/src/modules/git/components/UnifiedDiffView.tsx +37 -0
  45. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +99 -0
  46. package/src/modules/git/hooks/useAutoPullUpdates.ts +121 -0
  47. package/src/modules/git/hooks/useGitState.ts +335 -0
  48. package/src/modules/git/services/__tests__/error-messages.test.ts +134 -0
  49. package/src/modules/git/services/error-messages.ts +257 -0
  50. package/src/modules/git/services/git.api.ts +163 -0
  51. package/src/modules/git/services/pr-prompts.ts +159 -0
  52. package/src/modules/git/services/pr.api.ts +39 -0
  53. package/src/modules/git/state/auto-update.context.ts +21 -0
  54. package/src/modules/git/state/git.context.ts +82 -0
  55. package/src/modules/layout/components/AppLayout.tsx +40 -0
  56. package/src/modules/layout/components/DemoBanner.tsx +57 -0
  57. package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -0
  58. package/src/modules/layout/components/MobileChatLayout.tsx +153 -0
  59. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +203 -0
  60. package/src/modules/layout/components/SlideOverlay.tsx +224 -0
  61. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +77 -0
  62. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +57 -0
  63. package/src/modules/layout/hooks/useMediaQuery.ts +23 -0
  64. package/src/modules/layout/state/__tests__/layout.context.test.tsx +39 -0
  65. package/src/modules/layout/state/layout.context.ts +46 -0
  66. package/src/modules/library/__tests__/DetailDialog.test.tsx +200 -0
  67. package/src/modules/library/__tests__/diff.test.ts +62 -0
  68. package/src/modules/library/__tests__/loadout.test.tsx +72 -0
  69. package/src/modules/library/__tests__/status.test.ts +117 -0
  70. package/src/modules/library/components/ChangeRequestDock.tsx +47 -0
  71. package/src/modules/library/components/CompareView.tsx +357 -0
  72. package/src/modules/library/components/DetailDialog.tsx +566 -0
  73. package/src/modules/library/components/GearIcon.tsx +12 -0
  74. package/src/modules/library/components/LibraryCard.tsx +132 -0
  75. package/src/modules/library/components/LibraryPage.tsx +254 -0
  76. package/src/modules/library/components/LoadoutSidebar.tsx +156 -0
  77. package/src/modules/library/components/StatusGem.tsx +21 -0
  78. package/src/modules/library/components/SuggestChange.tsx +171 -0
  79. package/src/modules/library/components/particles.ts +50 -0
  80. package/src/modules/library/hooks/useLibraryData.ts +119 -0
  81. package/src/modules/library/hooks/useSkillDetail.ts +74 -0
  82. package/src/modules/library/library.css +320 -0
  83. package/src/modules/library/services/library.api.ts +164 -0
  84. package/src/modules/library/state/loadout.tsx +129 -0
  85. package/src/modules/library/state/toast.tsx +42 -0
  86. package/src/modules/library/utils/diff.ts +102 -0
  87. package/src/modules/library/utils/status.ts +116 -0
  88. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +93 -0
  89. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +158 -0
  90. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +44 -0
  91. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +360 -0
  92. package/src/modules/pr/__tests__/bucketize-comments.test.ts +85 -0
  93. package/src/modules/pr/__tests__/parsePatch.test.ts +104 -0
  94. package/src/modules/pr/__tests__/usePrViewerState.test.ts +72 -0
  95. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +193 -0
  96. package/src/modules/pr/components/PrApprovalBadge.tsx +80 -0
  97. package/src/modules/pr/components/PrCancelButton.tsx +99 -0
  98. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +119 -0
  99. package/src/modules/pr/components/PrCommentComposer.tsx +92 -0
  100. package/src/modules/pr/components/PrCommentThread.tsx +168 -0
  101. package/src/modules/pr/components/PrCommentsPanel.tsx +143 -0
  102. package/src/modules/pr/components/PrDiffPane.tsx +425 -0
  103. package/src/modules/pr/components/PrFileRow.tsx +164 -0
  104. package/src/modules/pr/components/PrFilesList.tsx +53 -0
  105. package/src/modules/pr/components/PrHeader.tsx +45 -0
  106. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +58 -0
  107. package/src/modules/pr/components/PrMergeButton.tsx +268 -0
  108. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +112 -0
  109. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +110 -0
  110. package/src/modules/pr/components/PrViewer.tsx +364 -0
  111. package/src/modules/pr/hooks/usePrViewerState.ts +150 -0
  112. package/src/modules/pr/services/pr-approvals.api.ts +31 -0
  113. package/src/modules/pr/services/pr-cancel.api.ts +19 -0
  114. package/src/modules/pr/services/pr-comments.api.ts +45 -0
  115. package/src/modules/pr/services/pr-detail.api.ts +17 -0
  116. package/src/modules/pr/services/pr-merge.api.ts +53 -0
  117. package/src/modules/pr/services/pr-open.api.ts +30 -0
  118. package/src/modules/pr/state/pr-viewer.context.ts +34 -0
  119. package/src/modules/pr/utils/bucketize-comments.ts +55 -0
  120. package/src/modules/pr/utils/parsePatch.ts +57 -0
  121. package/src/modules/review/__tests__/review.api.test.ts +121 -0
  122. package/src/modules/review/components/BinaryChangePlaceholder.tsx +15 -0
  123. package/src/modules/review/components/DiffViewer.tsx +78 -0
  124. package/src/modules/review/components/MarkdownDiffViewer.tsx +263 -0
  125. package/src/modules/review/components/ReviewFileRow.tsx +114 -0
  126. package/src/modules/review/components/ReviewPanel.tsx +260 -0
  127. package/src/modules/review/components/ReviewPanelSurface.tsx +52 -0
  128. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +106 -0
  129. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +88 -0
  130. package/src/modules/review/hooks/useReviewState.ts +256 -0
  131. package/src/modules/review/services/review.api.ts +72 -0
  132. package/src/modules/review/state/ReviewProvider.tsx +28 -0
  133. package/src/modules/review/state/review.context.ts +29 -0
  134. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +488 -0
  135. package/src/modules/secrets-vault/components/SecretsPage.tsx +276 -0
  136. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +362 -0
  137. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +51 -0
  138. package/src/modules/secrets-vault/services/connect.api.ts +113 -0
  139. package/src/modules/secrets-vault/services/secrets.api.ts +82 -0
  140. package/src/modules/secrets-vault/services/tool-secrets.api.ts +116 -0
  141. package/src/modules/toolbar/components/AdminMenu.tsx +250 -0
  142. package/src/modules/toolbar/components/AppSwitcher.tsx +108 -0
  143. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -0
  144. package/src/modules/toolbar/components/Toolbar.tsx +123 -0
  145. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +122 -0
  146. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +353 -0
  147. package/src/modules/toolbar/services/external-api-keys.api.ts +65 -0
  148. package/src/modules/tools/ToolsExplorerPage.tsx +380 -0
  149. package/src/modules/workflow/hooks/useEventBusSubscription.ts +24 -0
  150. package/src/modules/workflow/hooks/useFileLock.ts +430 -0
  151. package/src/modules/workflow/services/lock.api.ts +139 -0
  152. package/src/modules/workflow/state/EventBusFocusBinder.tsx +25 -0
  153. package/src/modules/workflow/state/EventBusProvider.tsx +232 -0
  154. package/src/modules/workflow/state/event-bus.context.ts +75 -0
  155. package/src/modules/workspace/__tests__/testFixtures.ts +54 -0
  156. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +91 -0
  157. package/src/modules/workspace/components/EditorTabs.tsx +384 -0
  158. package/src/modules/workspace/components/FileExplorer.tsx +1068 -0
  159. package/src/modules/workspace/components/FileRoute.tsx +392 -0
  160. package/src/modules/workspace/components/FileViewer.tsx +906 -0
  161. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +241 -0
  162. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +666 -0
  163. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +330 -0
  164. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +492 -0
  165. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +174 -0
  166. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +87 -0
  167. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +231 -0
  168. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +50 -0
  169. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +287 -0
  170. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +252 -0
  171. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +268 -0
  172. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +81 -0
  173. package/src/modules/workspace/components/renderers/TextRenderer.tsx +86 -0
  174. package/src/modules/workspace/components/renderers/ToolForm.tsx +404 -0
  175. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +417 -0
  176. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +157 -0
  177. package/src/modules/workspace/components/renderers/__tests__/CsvRenderer.test.ts +57 -0
  178. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +95 -0
  179. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +328 -0
  180. package/src/modules/workspace/components/renderers/__tests__/PdfRenderer.test.tsx +167 -0
  181. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +318 -0
  182. package/src/modules/workspace/components/renderers/csvUtils.ts +76 -0
  183. package/src/modules/workspace/components/renderers/htmlSandbox.ts +332 -0
  184. package/src/modules/workspace/components/renderers/index.ts +39 -0
  185. package/src/modules/workspace/components/renderers/types.ts +27 -0
  186. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +298 -0
  187. package/src/modules/workspace/hooks/useWorkspaceState.ts +1315 -0
  188. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +99 -0
  189. package/src/modules/workspace/routing/kb-routes.ts +266 -0
  190. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +72 -0
  191. package/src/modules/workspace/services/workspace.api.ts +185 -0
  192. package/src/modules/workspace/state/workspace.context.ts +235 -0
  193. package/src/modules/workspace/utils/__tests__/frontmatter.test.ts +107 -0
  194. package/src/modules/workspace/utils/diff.ts +53 -0
  195. package/src/modules/workspace/utils/fileTree.ts +179 -0
  196. package/src/modules/workspace/utils/frontmatter.ts +80 -0
  197. package/src/modules/workspace/utils/readDroppedEntries.ts +119 -0
  198. package/src/modules/workspace/utils/tab-persistence.ts +23 -0
  199. package/src/shared/components/Dialog.tsx +198 -0
  200. package/src/shared/components/PageShell.tsx +51 -0
  201. package/src/shared/components/useModalLayer.ts +35 -0
  202. package/src/shared/markdown/Markdown.tsx +62 -0
  203. package/src/test-setup.ts +59 -0
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Tiny line-level LCS differ for the Library's compare view and the inline
3
+ * own-suggestion marks. No dependency — the module only needs "which lines were
4
+ * removed / added", not a full myers implementation.
5
+ */
6
+
7
+ export interface DiffLine {
8
+ kind: 'same' | 'removed' | 'added';
9
+ text: string;
10
+ }
11
+
12
+ /** Split keeping no trailing phantom line for a trailing newline. */
13
+ function toLines(s: string): string[] {
14
+ if (s === '') return [];
15
+ const lines = s.split('\n');
16
+ if (lines[lines.length - 1] === '') lines.pop();
17
+ return lines;
18
+ }
19
+
20
+ /**
21
+ * Diff `before` → `after` line-wise. Output is ordered: for each change run,
22
+ * removed lines (from `before`) come before added lines (from `after`).
23
+ *
24
+ * Cost guard: common prefix/suffix are trimmed first; if the remaining middle
25
+ * is still enormous (> ~4M cells) the middle collapses to one whole-block
26
+ * replace instead of an exact LCS — visually "everything here changed", which
27
+ * is the honest rendering for a file that big anyway.
28
+ */
29
+ export function diffLines(before: string, after: string): DiffLine[] {
30
+ const a = toLines(before);
31
+ const b = toLines(after);
32
+
33
+ // Trim common prefix / suffix.
34
+ let start = 0;
35
+ while (start < a.length && start < b.length && a[start] === b[start]) start++;
36
+ let endA = a.length;
37
+ let endB = b.length;
38
+ while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {
39
+ endA--;
40
+ endB--;
41
+ }
42
+
43
+ const midA = a.slice(start, endA);
44
+ const midB = b.slice(start, endB);
45
+ const out: DiffLine[] = a.slice(0, start).map((text) => ({ kind: 'same' as const, text }));
46
+
47
+ if (midA.length * midB.length > 4_000_000) {
48
+ for (const text of midA) out.push({ kind: 'removed', text });
49
+ for (const text of midB) out.push({ kind: 'added', text });
50
+ } else {
51
+ out.push(...lcsDiff(midA, midB));
52
+ }
53
+
54
+ for (const text of a.slice(endA)) out.push({ kind: 'same', text });
55
+ return out;
56
+ }
57
+
58
+ function lcsDiff(a: string[], b: string[]): DiffLine[] {
59
+ const n = a.length;
60
+ const m = b.length;
61
+ // dp[i][j] = LCS length of a[i:], b[j:]
62
+ const dp: Uint32Array[] = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1));
63
+ for (let i = n - 1; i >= 0; i--) {
64
+ for (let j = m - 1; j >= 0; j--) {
65
+ dp[i][j] = a[i] === b[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
66
+ }
67
+ }
68
+ const out: DiffLine[] = [];
69
+ let i = 0;
70
+ let j = 0;
71
+ // Walk emitting removed-before-added per change run.
72
+ while (i < n && j < m) {
73
+ if (a[i] === b[j]) {
74
+ out.push({ kind: 'same', text: a[i] });
75
+ i++;
76
+ j++;
77
+ } else {
78
+ // Collect one contiguous change run.
79
+ const removed: string[] = [];
80
+ const added: string[] = [];
81
+ while (i < n && j < m && a[i] !== b[j]) {
82
+ if (dp[i + 1][j] >= dp[i][j + 1]) {
83
+ removed.push(a[i]);
84
+ i++;
85
+ } else {
86
+ added.push(b[j]);
87
+ j++;
88
+ }
89
+ }
90
+ for (const text of removed) out.push({ kind: 'removed', text });
91
+ for (const text of added) out.push({ kind: 'added', text });
92
+ }
93
+ }
94
+ while (i < n) out.push({ kind: 'removed', text: a[i++] });
95
+ while (j < m) out.push({ kind: 'added', text: b[j++] });
96
+ return out;
97
+ }
98
+
99
+ /** True when the diff contains at least one removed/added line. */
100
+ export function hasChanges(lines: DiffLine[]): boolean {
101
+ return lines.some((l) => l.kind !== 'same');
102
+ }
@@ -0,0 +1,116 @@
1
+ import type { ToolSecrets, ToolVarStatus } from '../../secrets-vault/services/tool-secrets.api';
2
+
3
+ /**
4
+ * Status derivation for the Library. Everything the cards, gems and loadout
5
+ * rows show is computed from the secrets-vault browser surface
6
+ * (`GET /api/secrets/tools` — see `tool-secrets.api.ts`), which exposes per
7
+ * variable: adminConfigured / userConfigured / oauth / authorized /
8
+ * needsReauth, plus per-tool `canWrite`. Design rule from the approved mock:
9
+ * status is only shown when something needs attention — healthy items render
10
+ * clean.
11
+ */
12
+
13
+ export type GemState = 'ok' | 'warn' | 'err' | 'off';
14
+
15
+ export interface AttentionStatus {
16
+ state: GemState;
17
+ /** User-facing state line (glossary-compliant plain words). */
18
+ text: string;
19
+ }
20
+
21
+ const OK: AttentionStatus = { state: 'ok', text: 'Connected' };
22
+
23
+ /** Severity order for aggregation: broken sign-in > not set up > user action pending. */
24
+ const RANK: Record<GemState, number> = { ok: 0, warn: 1, off: 2, err: 3 };
25
+
26
+ function varStatus(v: ToolVarStatus, canWrite: boolean): AttentionStatus {
27
+ if (v.oauth) {
28
+ if (!v.adminConfigured) {
29
+ return {
30
+ state: 'off',
31
+ text: canWrite ? 'Not set up yet — you maintain this integration' : 'Not set up yet',
32
+ };
33
+ }
34
+ if (v.authorized && v.needsReauth) return { state: 'err', text: 'Sign in again to keep this working' };
35
+ if (!v.authorized) return { state: 'warn', text: 'Needs your sign-in' };
36
+ return OK;
37
+ }
38
+ if (v.scope === 'user') {
39
+ return v.userConfigured ? OK : { state: 'warn', text: 'Needs a key from you' };
40
+ }
41
+ return v.adminConfigured
42
+ ? OK
43
+ : {
44
+ state: 'off',
45
+ text: canWrite ? 'Not set up yet — you maintain this integration' : 'Not set up yet',
46
+ };
47
+ }
48
+
49
+ /** Aggregate connection state of one integration for the current user. */
50
+ export function toolStatus(tool: ToolSecrets): AttentionStatus {
51
+ let worst = OK;
52
+ for (const v of tool.variables) {
53
+ const s = varStatus(v, tool.canWrite);
54
+ if (RANK[s.state] > RANK[worst.state]) worst = s;
55
+ }
56
+ return worst;
57
+ }
58
+
59
+ /** Per-variable status rows for the integration detail dialog. */
60
+ export function toolVariableStatuses(tool: ToolSecrets): { v: ToolVarStatus; status: AttentionStatus }[] {
61
+ return tool.variables.map((v) => ({ v, status: varStatus(v, tool.canWrite) }));
62
+ }
63
+
64
+ /**
65
+ * Which integrations a skill needs, derived from the skill's `allowed-tools`
66
+ * frontmatter. Entries are agent tool names, typically namespaced by the
67
+ * manual (`slack_post_message`, `slack.slack_post_message`) or the bare manual
68
+ * name; generic agent tools (`Bash`, `Read`) match no manual and are ignored.
69
+ * Best-effort by design — there is no dedicated skill→integration link in the
70
+ * backend contract today.
71
+ */
72
+ export function neededToolsFor(
73
+ skill: { allowedTools?: string[] },
74
+ tools: ToolSecrets[],
75
+ ): ToolSecrets[] {
76
+ const entries = (skill.allowedTools ?? []).map((e) => e.toLowerCase());
77
+ if (entries.length === 0) return [];
78
+ return tools.filter((t) => {
79
+ const n = t.name.toLowerCase();
80
+ return entries.some((e) => e === n || e.startsWith(`${n}_`) || e.startsWith(`${n}.`));
81
+ });
82
+ }
83
+
84
+ /** A skill is ready when every integration it needs is fully connected. */
85
+ export function skillStatus(neededTools: ToolSecrets[]): AttentionStatus {
86
+ const broken = neededTools.some((t) => toolStatus(t).state !== 'ok');
87
+ return broken ? { state: 'warn', text: 'Needs setup' } : { state: 'ok', text: 'Ready' };
88
+ }
89
+
90
+ /* ── gallery filtering ── */
91
+
92
+ export type LibraryCategory = 'skills' | 'integrations' | 'owned';
93
+
94
+ export interface LibraryFilterable {
95
+ kind: 'skill' | 'integration';
96
+ name: string;
97
+ description: string;
98
+ owned: boolean;
99
+ }
100
+
101
+ /** The chip + search filter from the mock: category narrows, query matches name/description. */
102
+ export function filterLibraryItems<T extends LibraryFilterable>(
103
+ items: T[],
104
+ category: LibraryCategory,
105
+ query: string,
106
+ ): T[] {
107
+ const q = query.trim().toLowerCase();
108
+ return items.filter((item) => {
109
+ if (q && !item.name.toLowerCase().includes(q) && !item.description.toLowerCase().includes(q)) {
110
+ return false;
111
+ }
112
+ if (category === 'skills') return item.kind === 'skill';
113
+ if (category === 'integrations') return item.kind === 'integration';
114
+ return item.owned;
115
+ });
116
+ }
@@ -0,0 +1,93 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { render } from '@testing-library/react';
3
+ import type { FileApprovalState } from '@bevel-software/platform-shared';
4
+ import { PrApprovalBadge } from '../components/PrApprovalBadge';
5
+
6
+ const ALICE = { name: 'Alice', email: 'alice@bevel.software' };
7
+
8
+ function state(overrides: Partial<FileApprovalState>): FileApprovalState {
9
+ // Spread after defaults so an explicit empty `eligibleApprovers` (the
10
+ // "outside the gate" case) passes through.
11
+ return {
12
+ path: 'Foo.md',
13
+ eligibleApprovers: { roles: [], users: [ALICE] },
14
+ approvedBy: [],
15
+ isApproved: false,
16
+ viewerCanApprove: false,
17
+ ...overrides,
18
+ };
19
+ }
20
+
21
+ describe('PrApprovalBadge', () => {
22
+ it('renders nothing when state is missing', () => {
23
+ const { container } = render(<PrApprovalBadge state={undefined} />);
24
+ expect(container.firstChild).toBeNull();
25
+ });
26
+
27
+ it('shows the "confirmed" tooltip including the eligible approver', () => {
28
+ const { container } = render(
29
+ <PrApprovalBadge
30
+ state={state({
31
+ isApproved: true,
32
+ approvedBy: [
33
+ { email: 'alice@bevel.software', name: 'Alice', approvedAt: 'x', isStale: false, isSelfApproval: false },
34
+ ],
35
+ })}
36
+ />,
37
+ );
38
+ const tooltipNode = container.querySelector('[title]');
39
+ expect(tooltipNode?.getAttribute('title')).toMatch(/confirmed by/i);
40
+ expect(tooltipNode?.getAttribute('title')).toMatch(/Alice/);
41
+ });
42
+
43
+ it('renders nothing for md files with no eligible approvers (outside the gate)', () => {
44
+ const { container } = render(
45
+ <PrApprovalBadge state={state({ eligibleApprovers: { roles: [], users: [] } })} />,
46
+ );
47
+ expect(container.firstChild).toBeNull();
48
+ });
49
+
50
+ it('renders nothing for non-md files regardless of eligibility', () => {
51
+ const { container } = render(
52
+ <PrApprovalBadge state={state({ path: 'src/foo.ts' })} />,
53
+ );
54
+ expect(container.firstChild).toBeNull();
55
+ });
56
+
57
+ it('shows the outdated indicator when only stale approvals exist', () => {
58
+ const { container } = render(
59
+ <PrApprovalBadge
60
+ state={state({
61
+ isApproved: false,
62
+ approvedBy: [
63
+ { email: 'alice@bevel.software', name: 'Alice', approvedAt: 'x', isStale: true, isSelfApproval: false },
64
+ ],
65
+ })}
66
+ />,
67
+ );
68
+ const tooltipNode = container.querySelector('[title]');
69
+ expect(tooltipNode?.getAttribute('title')).toMatch(/confirmation outdated/i);
70
+ });
71
+
72
+ it('shows the waiting indicator when there are eligible approvers but none have approved', () => {
73
+ const { container } = render(
74
+ <PrApprovalBadge state={state({ isApproved: false, approvedBy: [] })} />,
75
+ );
76
+ const tooltipNode = container.querySelector('[title]');
77
+ expect(tooltipNode?.getAttribute('title')).toMatch(/waiting on/i);
78
+ expect(tooltipNode?.getAttribute('title')).toMatch(/Alice/);
79
+ });
80
+
81
+ it('renders for files where eligibility comes from a role grant', () => {
82
+ const { container } = render(
83
+ <PrApprovalBadge
84
+ state={state({
85
+ eligibleApprovers: { roles: ['Admin'], users: [] },
86
+ isApproved: false,
87
+ })}
88
+ />,
89
+ );
90
+ const tooltipNode = container.querySelector('[title]');
91
+ expect(tooltipNode?.getAttribute('title')).toMatch(/Admin/);
92
+ });
93
+ });
@@ -0,0 +1,158 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
3
+ import type { PullRequestDetail } from '@bevel-software/platform-shared';
4
+
5
+ // API mock — replaces the network call. Each test resets and configures.
6
+ vi.mock('../services/pr-cancel.api', () => ({
7
+ cancelPullRequest: vi.fn(),
8
+ }));
9
+
10
+ import { PrCancelButton } from '../components/PrCancelButton';
11
+ import { cancelPullRequest } from '../services/pr-cancel.api';
12
+
13
+ const cancelMock = cancelPullRequest as unknown as ReturnType<typeof vi.fn>;
14
+
15
+ function detail(overrides: Partial<PullRequestDetail>): PullRequestDetail {
16
+ return {
17
+ number: 42,
18
+ title: 'Test PR',
19
+ author: { login: 'alice' },
20
+ branch: 'feature/x',
21
+ base: 'current-company-state',
22
+ state: 'open',
23
+ createdAt: '2026-05-01T00:00:00Z',
24
+ touchedNodePaths: [],
25
+ review: { approvals: 0, changesRequested: 0, pendingLogins: [] },
26
+ url: 'https://github.com/acme/repo/pull/42',
27
+ body: '',
28
+ headSha: 'head',
29
+ baseSha: 'base',
30
+ files: [],
31
+ comments: [],
32
+ approvals: [],
33
+ mergeableInBevel: true,
34
+ mergeBlockedReasons: [],
35
+ mergeWarnings: [],
36
+ viewerCanBypassMerge: false,
37
+ viewerCanCancel: true,
38
+ ...overrides,
39
+ };
40
+ }
41
+
42
+ describe('PrCancelButton', () => {
43
+ beforeEach(() => {
44
+ cancelMock.mockReset();
45
+ });
46
+ afterEach(() => {
47
+ cancelMock.mockReset();
48
+ });
49
+
50
+ it('renders nothing for a merged PR', () => {
51
+ const { container } = render(
52
+ <PrCancelButton detail={detail({ state: 'merged' })} onCancelled={() => {}} />,
53
+ );
54
+ expect(container.firstChild).toBeNull();
55
+ });
56
+
57
+ it('renders nothing for a closed PR', () => {
58
+ const { container } = render(
59
+ <PrCancelButton detail={detail({ state: 'closed' })} onCancelled={() => {}} />,
60
+ );
61
+ expect(container.firstChild).toBeNull();
62
+ });
63
+
64
+ it('marks the button aria-disabled with the only-author-or-admin tooltip when viewerCanCancel is false', () => {
65
+ render(
66
+ <PrCancelButton
67
+ detail={detail({ viewerCanCancel: false })}
68
+ onCancelled={() => {}}
69
+ />,
70
+ );
71
+ const btn = screen.getByRole('button', { name: /cancel change request/i });
72
+ // aria-disabled (not the disabled attribute) so the button stays focusable
73
+ // for keyboard users and screen readers announce the unauthorized state.
74
+ expect(btn).toHaveAttribute('aria-disabled', 'true');
75
+ expect(btn).not.toBeDisabled();
76
+ expect(btn.getAttribute('title')).toMatch(/only the author or an admin/i);
77
+ // Click should still be a no-op (component-level guard).
78
+ fireEvent.click(btn);
79
+ expect(cancelMock).not.toHaveBeenCalled();
80
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
81
+ });
82
+
83
+ it('clicking the enabled button opens the confirm dialog without firing the API', () => {
84
+ render(
85
+ <PrCancelButton detail={detail({})} onCancelled={() => {}} />,
86
+ );
87
+ const btn = screen.getByRole('button', { name: /cancel change request/i });
88
+ fireEvent.click(btn);
89
+ // Dialog opens — both heading and a "Keep open" affordance are visible.
90
+ expect(screen.getByRole('dialog')).toBeInTheDocument();
91
+ expect(screen.getByRole('heading', { name: /cancel this change request/i })).toBeInTheDocument();
92
+ expect(screen.getByRole('button', { name: /keep open/i })).toBeInTheDocument();
93
+ expect(cancelMock).not.toHaveBeenCalled();
94
+ });
95
+
96
+ it('confirms in the dialog: calls the API, dispatches bevel:pr-stale, and calls onCancelled', async () => {
97
+ cancelMock.mockResolvedValue({ prNumber: 42, cancelledAt: '2026-05-11T15:00:00.000Z' });
98
+ const onCancelled = vi.fn();
99
+ const eventSpy = vi.fn();
100
+ window.addEventListener('bevel:pr-stale', eventSpy);
101
+ try {
102
+ render(<PrCancelButton detail={detail({})} onCancelled={onCancelled} />);
103
+ fireEvent.click(screen.getByRole('button', { name: /^cancel change request$/i }));
104
+ // Click the *confirm* button inside the dialog — there are two buttons
105
+ // with this label (the trigger and the confirm); the dialog's confirm
106
+ // is the second match.
107
+ const confirmButtons = screen.getAllByRole('button', { name: /^cancel change request$/i });
108
+ fireEvent.click(confirmButtons[confirmButtons.length - 1]);
109
+ await waitFor(() => expect(cancelMock).toHaveBeenCalledTimes(1));
110
+ expect(cancelMock).toHaveBeenCalledWith(42);
111
+ expect(onCancelled).toHaveBeenCalledTimes(1);
112
+ expect(eventSpy).toHaveBeenCalled();
113
+ } finally {
114
+ window.removeEventListener('bevel:pr-stale', eventSpy);
115
+ }
116
+ });
117
+
118
+ it('on API error: surfaces friendly error inline and does NOT fire onCancelled or bevel:pr-stale', async () => {
119
+ cancelMock.mockRejectedValue(new Error('This change request was already applied.'));
120
+ const onCancelled = vi.fn();
121
+ const eventSpy = vi.fn();
122
+ window.addEventListener('bevel:pr-stale', eventSpy);
123
+ try {
124
+ render(<PrCancelButton detail={detail({})} onCancelled={onCancelled} />);
125
+ fireEvent.click(screen.getByRole('button', { name: /^cancel change request$/i }));
126
+ const confirmButtons = screen.getAllByRole('button', { name: /^cancel change request$/i });
127
+ fireEvent.click(confirmButtons[confirmButtons.length - 1]);
128
+ await waitFor(() => expect(cancelMock).toHaveBeenCalledTimes(1));
129
+ // Friendly mapping should kick in (see error-messages.ts).
130
+ const errorEl = await screen.findByRole('alert');
131
+ expect(errorEl.textContent).toMatch(/already applied/i);
132
+ expect(onCancelled).not.toHaveBeenCalled();
133
+ expect(eventSpy).not.toHaveBeenCalled();
134
+ } finally {
135
+ window.removeEventListener('bevel:pr-stale', eventSpy);
136
+ }
137
+ });
138
+
139
+ it('guards against double-confirm: a second click while busy does not fire the API twice', async () => {
140
+ // Deferred resolve so the first call stays in-flight while we fire a second.
141
+ let resolveFirst!: (v: { prNumber: number; cancelledAt: string }) => void;
142
+ cancelMock.mockImplementation(
143
+ () =>
144
+ new Promise((res) => {
145
+ resolveFirst = res;
146
+ }),
147
+ );
148
+ render(<PrCancelButton detail={detail({})} onCancelled={() => {}} />);
149
+ fireEvent.click(screen.getByRole('button', { name: /^cancel change request$/i }));
150
+ const confirmButtons = screen.getAllByRole('button', { name: /^cancel change request$/i });
151
+ const dialogConfirm = confirmButtons[confirmButtons.length - 1];
152
+ fireEvent.click(dialogConfirm);
153
+ // Double-click while busy
154
+ fireEvent.click(dialogConfirm);
155
+ await waitFor(() => expect(cancelMock).toHaveBeenCalledTimes(1));
156
+ resolveFirst({ prNumber: 42, cancelledAt: '2026-05-11T15:00:00.000Z' });
157
+ });
158
+ });
@@ -0,0 +1,44 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { fireEvent, render, screen } from '@testing-library/react';
3
+ import { PrCancelConfirmDialog } from '../components/PrCancelConfirmDialog';
4
+
5
+ describe('PrCancelConfirmDialog', () => {
6
+ it('renders title, body copy, and both action buttons', () => {
7
+ render(<PrCancelConfirmDialog busy={false} onConfirm={() => {}} onCancel={() => {}} />);
8
+ expect(screen.getByRole('heading', { name: /cancel this change request/i })).toBeInTheDocument();
9
+ expect(screen.getByText(/won't delete your draft/i)).toBeInTheDocument();
10
+ expect(screen.getByRole('button', { name: /keep open/i })).toBeInTheDocument();
11
+ // The bottom confirm button has the destructive label.
12
+ expect(screen.getByRole('button', { name: /^cancel change request$/i })).toBeInTheDocument();
13
+ });
14
+
15
+ it('Escape key fires onCancel when not busy', () => {
16
+ const onCancel = vi.fn();
17
+ render(<PrCancelConfirmDialog busy={false} onConfirm={() => {}} onCancel={onCancel} />);
18
+ fireEvent.keyDown(window, { key: 'Escape' });
19
+ expect(onCancel).toHaveBeenCalledTimes(1);
20
+ });
21
+
22
+ it('Escape is suppressed while busy', () => {
23
+ const onCancel = vi.fn();
24
+ render(<PrCancelConfirmDialog busy={true} onConfirm={() => {}} onCancel={onCancel} />);
25
+ fireEvent.keyDown(window, { key: 'Escape' });
26
+ expect(onCancel).not.toHaveBeenCalled();
27
+ });
28
+
29
+ it('Keep open button fires onCancel; Cancel change request button fires onConfirm', () => {
30
+ const onCancel = vi.fn();
31
+ const onConfirm = vi.fn();
32
+ render(<PrCancelConfirmDialog busy={false} onConfirm={onConfirm} onCancel={onCancel} />);
33
+ fireEvent.click(screen.getByRole('button', { name: /keep open/i }));
34
+ expect(onCancel).toHaveBeenCalledTimes(1);
35
+ fireEvent.click(screen.getByRole('button', { name: /^cancel change request$/i }));
36
+ expect(onConfirm).toHaveBeenCalledTimes(1);
37
+ });
38
+
39
+ it('confirm button shows Cancelling… and is disabled when busy', () => {
40
+ render(<PrCancelConfirmDialog busy={true} onConfirm={() => {}} onCancel={() => {}} />);
41
+ const btn = screen.getByRole('button', { name: /cancelling/i });
42
+ expect(btn).toBeDisabled();
43
+ });
44
+ });