@bevel-software/platform-core-frontend 0.32.0 → 0.34.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 +2 -2
- package/src/core/CoreAppShell.tsx +1 -1
- package/src/lib/__tests__/api.test.ts +28 -1
- package/src/lib/api.ts +4 -2
- package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +53 -1
- package/src/modules/access/api.ts +4 -5
- package/src/modules/access/components/ManageAccessDialog.tsx +11 -12
- package/src/modules/access/hooks/useAccessRequests.ts +1 -1
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/access/index.ts +11 -0
- package/src/modules/access/requests.api.ts +1 -1
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/AddMemberInput.tsx +1 -1
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- package/src/modules/admin/components/UserAccountsPage.tsx +3 -3
- package/src/modules/admin/index.ts +7 -0
- package/src/modules/admin/services/groups.api.ts +11 -1
- package/src/modules/admin/state/admin.context.tsx +1 -1
- package/src/modules/agents/__tests__/useConnectAsChoice.test.ts +56 -0
- package/src/modules/agents/components/ConnectAsChoice.tsx +81 -0
- package/src/modules/agents/connect-as.ts +15 -0
- package/src/modules/agents/index.ts +5 -0
- package/src/modules/agents/services/agent-choices.api.ts +39 -0
- package/src/modules/agents/useConnectAsChoice.ts +66 -0
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +13 -0
- package/src/modules/audit/components/AuditEventsPanel.tsx +1 -1
- package/src/modules/audit/components/AuditLogPage.tsx +11 -2
- package/src/modules/audit/services/audit.api.ts +5 -0
- package/src/modules/auth/__tests__/AccountPage.test.tsx +21 -0
- package/src/modules/auth/__tests__/account.api.test.ts +69 -0
- package/src/modules/auth/components/AccountPage.tsx +8 -2
- package/src/modules/auth/index.ts +12 -0
- package/src/modules/auth/services/account.api.ts +18 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.edit.test.tsx +166 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +0 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +0 -1
- package/src/modules/change-requests/components/BranchFilePreview.tsx +4 -12
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +138 -30
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +2 -3
- package/src/modules/change-requests/components/CrFileTree.tsx +1 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +2 -3
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +3 -5
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +1 -1
- package/src/modules/change-requests/index.ts +14 -0
- package/src/modules/change-requests/services/change-requests.api.ts +2 -2
- package/src/modules/change-requests/services/denied-file.api.ts +2 -2
- package/src/modules/change-requests/services/propose.api.ts +3 -4
- package/src/modules/change-requests/utils/diff.ts +1 -1
- package/src/modules/change-requests/utils/readFailure.ts +1 -1
- package/src/modules/embed/__tests__/EmbedView.test.tsx +19 -2
- package/src/modules/embed/components/EmbedLinkPage.tsx +1 -2
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +0 -14
- package/src/modules/git/__tests__/git.api.test.ts +2 -2
- package/src/modules/git/components/BranchSwitcher.tsx +3 -4
- package/src/modules/git/components/FileHistoryPanel.tsx +2 -2
- package/src/modules/git/components/GitSyncFailedBanner.tsx +2 -4
- package/src/modules/git/components/HistoryVersionPreview.tsx +4 -15
- package/src/modules/git/components/PullNeededBanner.tsx +1 -1
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +1 -1
- package/src/modules/git/hooks/useAutoPullUpdates.ts +1 -1
- package/src/modules/git/index.ts +11 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +1 -1
- package/src/modules/layout/index.ts +9 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +268 -24
- package/src/modules/library/__tests__/propose-change.test.ts +75 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +1 -1
- package/src/modules/library/components/ChangeRequestDock.tsx +1 -1
- package/src/modules/library/components/LibraryLayout.tsx +2 -2
- package/src/modules/library/components/LibraryPage.tsx +3 -3
- package/src/modules/library/components/ManagedPluginRequests.tsx +1 -1
- package/src/modules/library/components/NewSkillPanel.tsx +2 -2
- package/src/modules/library/components/PersonalAddDialog.tsx +1 -1
- package/src/modules/library/components/PersonalPluginPage.tsx +1 -1
- package/src/modules/library/components/PluginExtras.tsx +1 -4
- package/src/modules/library/components/PluginPage.tsx +1 -1
- package/src/modules/library/components/PluginRows.tsx +1 -1
- package/src/modules/library/components/SkillsTree.tsx +1 -4
- package/src/modules/library/components/plugin-page-parts.tsx +1 -1
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +74 -14
- package/src/modules/library/components/skill-page/SkillPage.tsx +80 -47
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +2 -4
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +2 -2
- package/src/modules/library/hooks/useJoinRequests.ts +1 -1
- package/src/modules/library/hooks/useLibraryData.ts +3 -3
- package/src/modules/library/hooks/useToolPage.ts +1 -1
- package/src/modules/library/hooks/useToolSource.ts +1 -1
- package/src/modules/library/index.ts +12 -0
- package/src/modules/library/routes/LibraryRoutes.tsx +1 -1
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +1 -3
- package/src/modules/library/routes/library-paths.ts +1 -1
- package/src/modules/library/services/library.api.ts +10 -8
- package/src/modules/library/services/plugins.api.ts +1 -1
- package/src/modules/library/services/teams.api.ts +1 -1
- package/src/modules/library/utils/status.ts +2 -2
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +1 -1
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +2 -3
- package/src/modules/onboarding/components/GetStartedColumn.tsx +6 -13
- package/src/modules/onboarding/components/InviteButton.tsx +2 -2
- package/src/modules/onboarding/components/InviteDialog.tsx +4 -6
- package/src/modules/onboarding/components/RootLanding.tsx +2 -2
- package/src/modules/onboarding/components/StarterPackCard.tsx +1 -1
- package/src/modules/onboarding/components/WelcomePage.tsx +2 -5
- package/src/modules/onboarding/index.ts +10 -0
- package/src/modules/onboarding/paths.ts +1 -1
- package/src/modules/onboarding/state/agent-connection.ts +2 -2
- package/src/modules/onboarding/state/onboarding.ts +1 -1
- package/src/modules/onboarding/state/starter-packs.ts +1 -1
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +1 -1
- package/src/modules/pr/index.ts +14 -0
- package/src/modules/pr/services/pr-approvals.api.ts +1 -1
- package/src/modules/pr/services/pr-cancel.api.ts +1 -1
- package/src/modules/pr/services/pr-detail.api.ts +2 -2
- package/src/modules/pr/services/pr-edit.api.ts +22 -0
- package/src/modules/pr/services/pr-merge.api.ts +1 -1
- package/src/modules/pr/services/pr-open.api.ts +1 -1
- package/src/modules/review/components/DiffViewer.tsx +1 -1
- package/src/modules/review/components/MarkdownDiffViewer.tsx +24 -3
- package/src/modules/review/components/ReviewPanel.tsx +10 -5
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
- package/src/modules/review/state/ReviewProvider.tsx +2 -2
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +79 -16
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +112 -2
- package/src/modules/secrets-vault/index.ts +6 -0
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- package/src/modules/settings/components/DeploymentPage.tsx +2 -2
- package/src/modules/settings/components/SettingsLayout.tsx +2 -2
- package/src/modules/settings/index.ts +8 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +1 -1
- package/src/modules/setup/index.ts +6 -0
- package/src/modules/toolbar/commands/actions.tsx +3 -3
- package/src/modules/toolbar/commands/useCommandActions.ts +5 -9
- package/src/modules/toolbar/components/AgentInstructionsCard.tsx +2 -2
- package/src/modules/toolbar/components/AppSwitcher.tsx +1 -2
- package/src/modules/toolbar/components/CoworkSetupSteps.tsx +1 -1
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +39 -5
- package/src/modules/toolbar/components/ProfileMenu.tsx +3 -3
- package/src/modules/toolbar/components/SearchPalette.tsx +4 -8
- package/src/modules/toolbar/components/Toolbar.tsx +2 -5
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +91 -2
- package/src/modules/toolbar/index.ts +6 -0
- package/src/modules/toolbar/search/sources.ts +4 -7
- package/src/modules/toolbar/services/agent-instructions.api.ts +1 -1
- package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
- package/src/modules/tools/ToolsExplorerPage.tsx +217 -18
- package/src/modules/tools/__tests__/ToolsExplorerPage.read-only.test.tsx +220 -0
- package/src/modules/tools/tool-hints.api.ts +44 -0
- package/src/modules/workflow/index.ts +7 -0
- package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +1 -0
- package/src/modules/workflow/state/EventBusFocusBinder.tsx +1 -1
- package/src/modules/workspace/components/FileExplorer.tsx +35 -8
- package/src/modules/workspace/components/FilePaneCard.tsx +37 -12
- package/src/modules/workspace/components/FileRoute.tsx +10 -3
- package/src/modules/workspace/components/FileViewer.tsx +169 -25
- package/src/modules/workspace/components/FullScreenView.tsx +93 -0
- package/src/modules/workspace/components/KbFileRail.tsx +1 -1
- package/src/modules/workspace/components/KbPageHeader.tsx +9 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +163 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +11 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +487 -3
- package/src/modules/workspace/components/readingCarry.ts +59 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +74 -180
- package/src/modules/workspace/components/renderers/KbAppLink.tsx +56 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +30 -10
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +37 -40
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.links.test.tsx +185 -0
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +168 -42
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.sectionReclick.test.tsx +88 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +199 -29
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +57 -7
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +122 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +235 -1
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +29 -4
- package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
- package/src/modules/workspace/components/renderers/__tests__/pageToolsHarness.ts +79 -0
- package/src/modules/workspace/components/renderers/__tests__/useHtmlToolBridge.test.tsx +316 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +123 -28
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +215 -25
- package/src/modules/workspace/components/renderers/index.ts +10 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +35 -28
- package/src/modules/workspace/components/renderers/scrollToHeading.ts +35 -0
- package/src/modules/workspace/components/renderers/useHtmlToolBridge.tsx +253 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +6 -0
- package/src/modules/workspace/hooks/useFullScreenView.ts +52 -0
- package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +1 -1
- package/src/modules/workspace/hooks/useLastCommit.ts +1 -1
- package/src/modules/workspace/hooks/useLinksOut.ts +12 -6
- package/src/modules/workspace/hooks/useWorkspaceState.ts +4 -4
- package/src/modules/workspace/index.ts +50 -2
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
- package/src/modules/workspace/routing/kb-routes.ts +222 -54
- package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +0 -1
- package/src/modules/workspace/state/open-change-requests.tsx +1 -1
- package/src/modules/workspace/utils/fileTree.ts +1 -1
- package/src/modules/workspace/utils/frameEscape.ts +15 -0
- package/src/modules/workspace/utils/treeConfirm.ts +1 -1
- package/src/shared/theme/measure.ts +7 -0
- package/src/modules/pr/services/pr-comments.api.ts +0 -45
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { buildSandboxedHtml, sanitizeAgentHtml } from '../htmlSandbox';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The `### Live data` subsection of the agent guide's `## HTML views` tells
|
|
9
|
+
* page authors how a data-driven page loads: final shell first, one consistent
|
|
10
|
+
* dataset at a time, refresh over the current board, a failed read with a
|
|
11
|
+
* retry, reads in bounded parallel, links by root-relative path. Its reference
|
|
12
|
+
* page is the one example an agent copies, so this suite runs THAT page —
|
|
13
|
+
* taken out of the guide, not a copy of it — and holds it to every one of
|
|
14
|
+
* those rules.
|
|
15
|
+
*
|
|
16
|
+
* The page goes through the renderer's own pipeline: the sanitizer, the
|
|
17
|
+
* sandbox document and its tool-bridge runtime. The test plays the app on the
|
|
18
|
+
* other side of the bridge, answering each `bevel.tool.call` the page posts
|
|
19
|
+
* when the test decides — which is how a slow, partial or failed load is
|
|
20
|
+
* produced without touching the page. The section is core-backend's file and
|
|
21
|
+
* is read here as TEXT, in a test only, like `htmlViewsGuide.test.ts` does.
|
|
22
|
+
*/
|
|
23
|
+
const HTML_VIEWS_MD = path.resolve(
|
|
24
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
25
|
+
'../../../../../../../core-backend/agent-guide/html-views.md',
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
/** The checkout folder the guide is rendered for here: any name will do. */
|
|
29
|
+
const KB_DIR_NAME = 'knowledge-base';
|
|
30
|
+
|
|
31
|
+
function referencePage(): string {
|
|
32
|
+
// Read as LF whatever the checkout's line endings.
|
|
33
|
+
const section = readFileSync(HTML_VIEWS_MD, 'utf8').replace(/\r\n/g, '\n');
|
|
34
|
+
const live = /\n### Live data[^\n]*\n([\s\S]*?)(?=\n### |$)/.exec(section);
|
|
35
|
+
if (!live) throw new Error('the `## HTML views` section has no `### Live data` subsection');
|
|
36
|
+
const page = /```html\n([\s\S]*?)\n```/.exec(live[1]!);
|
|
37
|
+
if (!page) throw new Error('the `### Live data` subsection has no reference page');
|
|
38
|
+
// Rendered as the guide renders it for a deployment.
|
|
39
|
+
return page[1]!.replaceAll('{{kbDirName}}', KB_DIR_NAME);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const FOLDER = 'Data/Tickets';
|
|
43
|
+
|
|
44
|
+
interface ToolCall {
|
|
45
|
+
requestId: string;
|
|
46
|
+
fn: string;
|
|
47
|
+
args: [string, { body: { branch: string; path: string } }];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The reference page, mounted the way the renderer mounts it on the app's
|
|
52
|
+
* file page, with the test as the app behind `window.bevel.tools`.
|
|
53
|
+
*/
|
|
54
|
+
async function mountReferencePage(branch = 'main') {
|
|
55
|
+
const srcdoc = buildSandboxedHtml({
|
|
56
|
+
title: 'Tickets',
|
|
57
|
+
libModuleSources: [],
|
|
58
|
+
bodyHtml: sanitizeAgentHtml(referencePage()),
|
|
59
|
+
toolBridge: true,
|
|
60
|
+
branch,
|
|
61
|
+
});
|
|
62
|
+
document.body.innerHTML = /<body>([\s\S]*)<\/body>/.exec(srcdoc)![1]!;
|
|
63
|
+
|
|
64
|
+
const calls: ToolCall[] = [];
|
|
65
|
+
const answered = new Set<string>();
|
|
66
|
+
const listeners: Array<(event: { source: unknown; data: unknown }) => void> = [];
|
|
67
|
+
const parent = {
|
|
68
|
+
postMessage(msg: { type: string }) {
|
|
69
|
+
if (msg.type === 'bevel.tool.call') calls.push(msg as unknown as ToolCall);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const frameGlobal: Record<string, unknown> = {
|
|
73
|
+
addEventListener(type: string, fn: (event: { source: unknown; data: unknown }) => void) {
|
|
74
|
+
if (type === 'message') listeners.push(fn);
|
|
75
|
+
},
|
|
76
|
+
removeEventListener() {},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Module scripts in document order over one global, as the frame runs them;
|
|
80
|
+
// the page's own script may use top-level await.
|
|
81
|
+
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor as new (
|
|
82
|
+
...args: string[]
|
|
83
|
+
) => (...values: unknown[]) => Promise<void>;
|
|
84
|
+
for (const script of Array.from(document.querySelectorAll('script[type="module"]'))) {
|
|
85
|
+
const body = script.textContent!.replace(/<\\\/(script)/gi, '</$1');
|
|
86
|
+
void new AsyncFunction('globalThis', 'window', 'document', 'parent', body)(
|
|
87
|
+
frameGlobal,
|
|
88
|
+
frameGlobal,
|
|
89
|
+
document,
|
|
90
|
+
parent,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
await settle();
|
|
94
|
+
|
|
95
|
+
function respond(call: ToolCall, outcome: { ok: true; result: unknown } | { ok: false; error: string }) {
|
|
96
|
+
answered.add(call.requestId);
|
|
97
|
+
const data = { type: 'bevel.tool.response', requestId: call.requestId, ...outcome };
|
|
98
|
+
for (const listener of listeners) listener({ source: parent, data });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
calls,
|
|
103
|
+
/** The calls the page is still waiting on. */
|
|
104
|
+
pending: () => calls.filter((c) => !answered.has(c.requestId)),
|
|
105
|
+
respond,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type Page = Awaited<ReturnType<typeof mountReferencePage>>;
|
|
110
|
+
|
|
111
|
+
/** Let the page's promise chains and the bridge's replies run. */
|
|
112
|
+
function settle() {
|
|
113
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function ticket(name: string, status: string, eol = '\n') {
|
|
117
|
+
return ['---', 'nodeType: "[Ticket](../NodeTypes/Ticket.md)"', '---', '', '# Name', name, '', '# Status', status, ''].join(eol);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The knowledge base the app answers from: file name → markdown. */
|
|
121
|
+
type Files = Record<string, string>;
|
|
122
|
+
|
|
123
|
+
const FIRST: Files = {
|
|
124
|
+
'A.md': ticket('Alpha', 'todo'),
|
|
125
|
+
'B.md': ticket('Bravo', 'todo'),
|
|
126
|
+
'C.md': ticket('Charlie', 'doing'),
|
|
127
|
+
'D.md': ticket('Delta', 'done'),
|
|
128
|
+
'E.md': ticket('Echo', 'done'),
|
|
129
|
+
'F.md': ticket('Foxtrot', 'done'),
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const SECOND: Files = { ...FIRST, 'A.md': ticket('Alpha', 'done'), 'G.md': ticket('Golf', 'doing') };
|
|
133
|
+
|
|
134
|
+
/** Answer the page's pending `list_files` from `files`, naming paths as the tool does: checkout folder first. */
|
|
135
|
+
async function answerListing(page: Page, files: Files) {
|
|
136
|
+
const listing = page.pending().find((c) => c.args[0] === 'list_files');
|
|
137
|
+
expect(listing, 'the page lists its folder first').toBeDefined();
|
|
138
|
+
page.respond(listing!, {
|
|
139
|
+
ok: true,
|
|
140
|
+
result: {
|
|
141
|
+
path: `${KB_DIR_NAME}/${FOLDER}`,
|
|
142
|
+
entries: Object.keys(files).map((name) => ({ name, type: 'file', canWrite: false })),
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
await settle();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Answer up to `count` of the page's pending reads from `files` (all of them
|
|
150
|
+
* when omitted), failing the one named by `fail`.
|
|
151
|
+
*/
|
|
152
|
+
async function answerReads(page: Page, files: Files, { count = Infinity, fail }: { count?: number; fail?: string } = {}) {
|
|
153
|
+
let left = count;
|
|
154
|
+
while (left > 0) {
|
|
155
|
+
const read = page.pending().find((c) => c.args[0] === 'read_file');
|
|
156
|
+
if (!read) break;
|
|
157
|
+
const name = read.args[1].body.path.slice(FOLDER.length + 1);
|
|
158
|
+
if (name === fail) page.respond(read, { ok: false, error: `You cannot read ${read.args[1].body.path}.` });
|
|
159
|
+
else
|
|
160
|
+
page.respond(read, {
|
|
161
|
+
ok: true,
|
|
162
|
+
// The tool answers the path checkout folder first, whatever spelling it was asked with.
|
|
163
|
+
result: { path: `${KB_DIR_NAME}/${read.args[1].body.path}`, content: files[name], canWrite: false },
|
|
164
|
+
});
|
|
165
|
+
left -= 1;
|
|
166
|
+
await settle();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const el = (id: string) => document.getElementById(id)!;
|
|
171
|
+
const status = () => el('status').textContent;
|
|
172
|
+
const countOf = (column: string) => document.querySelector(`[data-status="${column}"] .count`)!.textContent;
|
|
173
|
+
const cardsOf = (column: string) =>
|
|
174
|
+
Array.from(document.querySelectorAll(`[data-status="${column}"] li`)).map((li) =>
|
|
175
|
+
li.classList.contains('placeholder') ? '…' : li.textContent,
|
|
176
|
+
);
|
|
177
|
+
const boardText = () => ['todo', 'doing', 'done'].map((c) => [countOf(c), ...cardsOf(c)].join('|')).join(' / ');
|
|
178
|
+
|
|
179
|
+
const FIRST_BOARD = '(2)|Alpha|Bravo / (1)|Charlie / (3)|Delta|Echo|Foxtrot';
|
|
180
|
+
const SECOND_BOARD = '(1)|Bravo / (2)|Charlie|Golf / (4)|Alpha|Delta|Echo|Foxtrot';
|
|
181
|
+
const LOADING_BOARD = '|…|… / |…|… / |…|…';
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The shell's elements, and a watch on the page's top level: a load that
|
|
185
|
+
* replaces the page instead of filling it shows up as a changed element or a
|
|
186
|
+
* child added to or removed from `<body>`.
|
|
187
|
+
*/
|
|
188
|
+
function watchShell() {
|
|
189
|
+
const ids = ['board', 'status', 'refresh', 'retry'];
|
|
190
|
+
const elements = [...ids.map(el), ...Array.from(document.querySelectorAll('.column, .column ul'))];
|
|
191
|
+
const topLevel: MutationRecord[] = [];
|
|
192
|
+
const observer = new MutationObserver((records) => topLevel.push(...records));
|
|
193
|
+
observer.observe(document.body, { childList: true });
|
|
194
|
+
return {
|
|
195
|
+
expectUnchanged() {
|
|
196
|
+
topLevel.push(...observer.takeRecords());
|
|
197
|
+
expect(topLevel, 'nothing is added to or removed from <body>').toEqual([]);
|
|
198
|
+
const now = [...ids.map(el), ...Array.from(document.querySelectorAll('.column, .column ul'))];
|
|
199
|
+
expect(now.length).toBe(elements.length);
|
|
200
|
+
now.forEach((node, i) => expect(node, 'the same shell element').toBe(elements[i]));
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
afterEach(() => {
|
|
206
|
+
document.body.innerHTML = '';
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe("the guide's live-data reference page", () => {
|
|
210
|
+
it('is plain HTML with inline script: the sanitizer keeps all of it', () => {
|
|
211
|
+
const page = referencePage();
|
|
212
|
+
expect(page).not.toMatch(/<script[^>]*\bsrc=|import\s|React|useState/);
|
|
213
|
+
const kept = sanitizeAgentHtml(page);
|
|
214
|
+
for (const id of ['board', 'status', 'refresh', 'retry']) expect(kept).toContain(`id="${id}"`);
|
|
215
|
+
expect(kept).toContain('<script type="module">');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('cold load: the final shell at once, no partial data, then the whole board in one step', async () => {
|
|
219
|
+
const page = await mountReferencePage();
|
|
220
|
+
const shell = watchShell();
|
|
221
|
+
|
|
222
|
+
// Before any data: the board's columns, with placeholders inside them.
|
|
223
|
+
expect(status()).toBe('Loading…');
|
|
224
|
+
expect(el('board').getAttribute('aria-busy')).toBe('true');
|
|
225
|
+
expect(boardText()).toBe(LOADING_BOARD);
|
|
226
|
+
expect((el('refresh') as HTMLButtonElement).disabled).toBe(true);
|
|
227
|
+
|
|
228
|
+
await answerListing(page, FIRST);
|
|
229
|
+
await answerReads(page, FIRST, { count: 4 });
|
|
230
|
+
// Four of six read: no count, card or empty column is shown yet.
|
|
231
|
+
expect(boardText()).toBe(LOADING_BOARD);
|
|
232
|
+
expect(status()).toBe('Loading…');
|
|
233
|
+
|
|
234
|
+
await answerReads(page, FIRST);
|
|
235
|
+
expect(boardText()).toBe(FIRST_BOARD);
|
|
236
|
+
expect(el('board').getAttribute('aria-busy')).toBe('false');
|
|
237
|
+
expect(status()).toMatch(/^Updated /);
|
|
238
|
+
expect((el('refresh') as HTMLButtonElement).disabled).toBe(false);
|
|
239
|
+
shell.expectUnchanged();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('links each card to the file on the branch it read it from, by the path the tool answered', async () => {
|
|
243
|
+
const page = await mountReferencePage();
|
|
244
|
+
await answerListing(page, FIRST);
|
|
245
|
+
await answerReads(page, FIRST);
|
|
246
|
+
const hrefs = Array.from(document.querySelectorAll('.column a')).map((a) => a.getAttribute('href'));
|
|
247
|
+
// The tool's path already carries the checkout folder; the page adds nothing in front of it.
|
|
248
|
+
expect(hrefs).toEqual(Object.keys(FIRST).map((name) => `/workspace/main/${KB_DIR_NAME}/${FOLDER}/${name}`));
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('keeps a name carrying `#`, `?` or `%` in the link, each segment encoded on its own', async () => {
|
|
252
|
+
const files: Files = { 'A#1.md': ticket('Sharp', 'todo'), 'B?2.md': ticket('Query', 'doing'), 'C%3.md': ticket('Percent', 'done') };
|
|
253
|
+
const page = await mountReferencePage();
|
|
254
|
+
await answerListing(page, files);
|
|
255
|
+
await answerReads(page, files);
|
|
256
|
+
const hrefs = Array.from(document.querySelectorAll('.column a')).map((a) => a.getAttribute('href'));
|
|
257
|
+
// `#1.md` would otherwise be the URL's fragment, and the card would open `A`.
|
|
258
|
+
expect(hrefs).toEqual([
|
|
259
|
+
`/workspace/main/${KB_DIR_NAME}/Data/Tickets/A%231.md`,
|
|
260
|
+
`/workspace/main/${KB_DIR_NAME}/Data/Tickets/B%3F2.md`,
|
|
261
|
+
`/workspace/main/${KB_DIR_NAME}/Data/Tickets/C%253.md`,
|
|
262
|
+
]);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('reads a file saved with Windows line endings like any other', async () => {
|
|
266
|
+
const page = await mountReferencePage();
|
|
267
|
+
const crlf: Files = { 'A.md': ticket('Alpha', 'todo', '\r\n'), 'B.md': ticket('Bravo', 'done', '\r\n') };
|
|
268
|
+
await answerListing(page, crlf);
|
|
269
|
+
await answerReads(page, crlf);
|
|
270
|
+
expect(boardText()).toBe('(1)|Alpha / (0)|None / (1)|Bravo');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('reads its data and links its cards on the branch it is viewed on, read from window.bevel.branch', async () => {
|
|
274
|
+
const page = await mountReferencePage('alice/drafts');
|
|
275
|
+
expect(page.calls.map((c) => [c.args[0], c.args[1].body.branch])).toEqual([['list_files', 'alice/drafts']]);
|
|
276
|
+
await answerListing(page, FIRST);
|
|
277
|
+
expect(page.pending().every((c) => c.args[1].body.branch === 'alice/drafts')).toBe(true);
|
|
278
|
+
await answerReads(page, FIRST);
|
|
279
|
+
const hrefs = Array.from(document.querySelectorAll('.column a')).map((a) => a.getAttribute('href'));
|
|
280
|
+
expect(hrefs).toEqual(Object.keys(FIRST).map((name) => `/workspace/alice%2Fdrafts/${KB_DIR_NAME}/${FOLDER}/${name}`));
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('reads in bounded parallel, only after listing, through read-only tools, never a chain', async () => {
|
|
284
|
+
const page = await mountReferencePage();
|
|
285
|
+
expect(page.calls.map((c) => c.args[0])).toEqual(['list_files']);
|
|
286
|
+
|
|
287
|
+
await answerListing(page, FIRST);
|
|
288
|
+
// Six files to read, four at a time.
|
|
289
|
+
expect(page.pending().length).toBe(4);
|
|
290
|
+
await answerReads(page, FIRST, { count: 1 });
|
|
291
|
+
expect(page.pending().length).toBe(4);
|
|
292
|
+
await answerReads(page, FIRST);
|
|
293
|
+
|
|
294
|
+
expect(page.calls.filter((c) => c.args[0] === 'read_file').map((c) => c.args[1].body.path).sort()).toEqual(
|
|
295
|
+
Object.keys(FIRST).map((name) => `${FOLDER}/${name}`),
|
|
296
|
+
);
|
|
297
|
+
for (const call of page.calls) {
|
|
298
|
+
expect(call.fn).toBe('callTool');
|
|
299
|
+
expect(['list_files', 'read_file']).toContain(call.args[0]);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('warm refresh: the current board stays, marked busy, while a small refreshing state shows, then is replaced whole', async () => {
|
|
304
|
+
const page = await mountReferencePage();
|
|
305
|
+
await answerListing(page, FIRST);
|
|
306
|
+
await answerReads(page, FIRST);
|
|
307
|
+
const shell = watchShell();
|
|
308
|
+
|
|
309
|
+
(el('refresh') as HTMLButtonElement).click();
|
|
310
|
+
await settle();
|
|
311
|
+
expect(status()).toBe('Refreshing…');
|
|
312
|
+
expect(el('board').getAttribute('aria-busy')).toBe('true');
|
|
313
|
+
expect((el('refresh') as HTMLButtonElement).disabled).toBe(true);
|
|
314
|
+
expect(boardText()).toBe(FIRST_BOARD);
|
|
315
|
+
|
|
316
|
+
await answerListing(page, SECOND);
|
|
317
|
+
await answerReads(page, SECOND, { count: 5 });
|
|
318
|
+
// Part of the new dataset is in: the board is still the last whole one.
|
|
319
|
+
expect(boardText()).toBe(FIRST_BOARD);
|
|
320
|
+
expect(status()).toBe('Refreshing…');
|
|
321
|
+
|
|
322
|
+
await answerReads(page, SECOND);
|
|
323
|
+
expect(boardText()).toBe(SECOND_BOARD);
|
|
324
|
+
expect(el('board').getAttribute('aria-busy')).toBe('false');
|
|
325
|
+
expect(status()).toMatch(/^Updated /);
|
|
326
|
+
expect((el('refresh') as HTMLButtonElement).disabled).toBe(false);
|
|
327
|
+
shell.expectUnchanged();
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('a failed read on refresh keeps the last good board, says why, and retry recovers', async () => {
|
|
331
|
+
const page = await mountReferencePage();
|
|
332
|
+
await answerListing(page, FIRST);
|
|
333
|
+
await answerReads(page, FIRST);
|
|
334
|
+
const shell = watchShell();
|
|
335
|
+
|
|
336
|
+
(el('refresh') as HTMLButtonElement).click();
|
|
337
|
+
await settle();
|
|
338
|
+
await answerListing(page, SECOND);
|
|
339
|
+
await answerReads(page, SECOND, { fail: 'C.md' });
|
|
340
|
+
|
|
341
|
+
expect(boardText()).toBe(FIRST_BOARD);
|
|
342
|
+
expect(el('status').className).toBe('error');
|
|
343
|
+
expect(status()).toBe('Could not refresh; showing the last loaded board. You cannot read Data/Tickets/C.md.');
|
|
344
|
+
expect(el('retry').hidden).toBe(false);
|
|
345
|
+
|
|
346
|
+
el('retry').click();
|
|
347
|
+
await settle();
|
|
348
|
+
expect(el('retry').hidden).toBe(true);
|
|
349
|
+
expect(status()).toBe('Refreshing…');
|
|
350
|
+
await answerListing(page, SECOND);
|
|
351
|
+
await answerReads(page, SECOND);
|
|
352
|
+
expect(boardText()).toBe(SECOND_BOARD);
|
|
353
|
+
expect(el('status').className).toBe('');
|
|
354
|
+
shell.expectUnchanged();
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('a failed read starts no further read and offers Retry only once the reads in flight settle', async () => {
|
|
358
|
+
const page = await mountReferencePage();
|
|
359
|
+
await answerListing(page, FIRST);
|
|
360
|
+
const reads = () => page.calls.filter((c) => c.args[0] === 'read_file').length;
|
|
361
|
+
expect(reads()).toBe(4);
|
|
362
|
+
|
|
363
|
+
await answerReads(page, FIRST, { count: 1, fail: 'A.md' });
|
|
364
|
+
// Three reads still in flight; the two files left are not started.
|
|
365
|
+
expect(page.pending().length).toBe(3);
|
|
366
|
+
expect(reads()).toBe(4);
|
|
367
|
+
expect(el('retry').hidden).toBe(true);
|
|
368
|
+
expect(status()).toBe('Loading…');
|
|
369
|
+
|
|
370
|
+
await answerReads(page, FIRST);
|
|
371
|
+
expect(reads()).toBe(4);
|
|
372
|
+
expect(status()).toBe('Could not load the tickets. You cannot read Data/Tickets/A.md.');
|
|
373
|
+
expect(el('retry').hidden).toBe(false);
|
|
374
|
+
expect(boardText()).toBe(LOADING_BOARD);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('a failed read on the first load keeps the shell, says why, and retry recovers', async () => {
|
|
378
|
+
const page = await mountReferencePage();
|
|
379
|
+
const shell = watchShell();
|
|
380
|
+
await answerListing(page, FIRST);
|
|
381
|
+
await answerReads(page, FIRST, { fail: 'E.md' });
|
|
382
|
+
|
|
383
|
+
// The reads that succeeded are not shown as if they were the board.
|
|
384
|
+
expect(boardText()).toBe(LOADING_BOARD);
|
|
385
|
+
expect(status()).toBe('Could not load the tickets. You cannot read Data/Tickets/E.md.');
|
|
386
|
+
expect(el('retry').hidden).toBe(false);
|
|
387
|
+
|
|
388
|
+
el('retry').click();
|
|
389
|
+
await settle();
|
|
390
|
+
expect(status()).toBe('Loading…');
|
|
391
|
+
await answerListing(page, FIRST);
|
|
392
|
+
await answerReads(page, FIRST);
|
|
393
|
+
expect(boardText()).toBe(FIRST_BOARD);
|
|
394
|
+
expect(el('retry').hidden).toBe(true);
|
|
395
|
+
shell.expectUnchanged();
|
|
396
|
+
});
|
|
397
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
/** Everything the app posted to a frame window, shared by every channel taken on it. */
|
|
4
|
+
const postedTo = new WeakMap<Window, Array<Record<string, unknown>>>();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The two ends of the page tool bridge a test drives, shared by the app's
|
|
8
|
+
* renderer suite and the controller's own: the frame (what its runtime posts,
|
|
9
|
+
* what the app posts back) and the server (the hosted MCP endpoint and the
|
|
10
|
+
* manual, as the app's fetch sees them).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Post `data` as the frame's CURRENT document would — stamped with the
|
|
15
|
+
* identity the app built into it (`documentId="…"` in the srcdoc), as the
|
|
16
|
+
* runtime stamps every message — and collect what the app posts back. A
|
|
17
|
+
* channel taken before a view change keeps the old document's identity, so
|
|
18
|
+
* it posts as that document would.
|
|
19
|
+
*/
|
|
20
|
+
export function frameChannel(iframe: HTMLIFrameElement) {
|
|
21
|
+
const win = iframe.contentWindow!;
|
|
22
|
+
const documentId = /documentId\s*=\s*"([^"]+)"/.exec(iframe.getAttribute('srcdoc') ?? '')?.[1];
|
|
23
|
+
// One collector per window, however many channels are taken on it: a
|
|
24
|
+
// channel's `replies` are what the app posted to the window since the
|
|
25
|
+
// channel was taken, so a reply meant for a replaced document shows up on
|
|
26
|
+
// the old channel AND the new one, and neither assertion is vacuous.
|
|
27
|
+
let posted = postedTo.get(win);
|
|
28
|
+
if (!posted) {
|
|
29
|
+
posted = [];
|
|
30
|
+
postedTo.set(win, posted);
|
|
31
|
+
const all = posted;
|
|
32
|
+
vi.spyOn(win, 'postMessage').mockImplementation(((msg: Record<string, unknown>) => void all.push(msg)) as never);
|
|
33
|
+
}
|
|
34
|
+
const since = posted.length;
|
|
35
|
+
const all = posted;
|
|
36
|
+
return {
|
|
37
|
+
get replies(): Array<Record<string, unknown>> {
|
|
38
|
+
return all.slice(since);
|
|
39
|
+
},
|
|
40
|
+
documentId,
|
|
41
|
+
post: (data: unknown) =>
|
|
42
|
+
window.dispatchEvent(
|
|
43
|
+
new MessageEvent('message', {
|
|
44
|
+
data: documentId && data && typeof data === 'object' ? { documentId, ...(data as object) } : data,
|
|
45
|
+
source: win,
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The hosted server and the manual: `read_file` reads, `edit_file` writes.
|
|
53
|
+
* `mcp` records every tool the server was asked to run. With `holdManual`,
|
|
54
|
+
* the manual is not answered until `releaseManual()` — a lookup still in
|
|
55
|
+
* flight.
|
|
56
|
+
*/
|
|
57
|
+
export function stubServer({ holdManual = false }: { holdManual?: boolean } = {}) {
|
|
58
|
+
const mcp: string[] = [];
|
|
59
|
+
let releaseManual: () => void = () => undefined;
|
|
60
|
+
const manualHeld = holdManual ? new Promise<void>((resolve) => (releaseManual = resolve)) : Promise.resolve();
|
|
61
|
+
vi.stubGlobal(
|
|
62
|
+
'fetch',
|
|
63
|
+
vi.fn(async (url: string, init?: RequestInit) => {
|
|
64
|
+
if (url === '/api/agent/utcp') {
|
|
65
|
+
await manualHeld;
|
|
66
|
+
return Response.json({ tools: [{ name: 'read_file', tags: [] }, { name: 'edit_file', tags: ['write'] }] });
|
|
67
|
+
}
|
|
68
|
+
if (url === '/api/mcp/page-refusals') return new Response(null, { status: 204 });
|
|
69
|
+
const body = JSON.parse(String(init!.body)) as { id: number; params: { name: string } };
|
|
70
|
+
mcp.push(body.params.name);
|
|
71
|
+
return Response.json({
|
|
72
|
+
jsonrpc: '2.0',
|
|
73
|
+
id: body.id,
|
|
74
|
+
result: { content: [{ type: 'text', text: JSON.stringify({ ran: body.params.name }) }] },
|
|
75
|
+
});
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
return { mcp, releaseManual: () => releaseManual() };
|
|
79
|
+
}
|