Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

test(web): reject all native button title hints (#1526)

Bingxi Zhao (Frank)75e9192315c5
diff --git a/web/tests/native-button-title-baseline.json b/web/tests/native-button-title-baseline.json
deleted file mode 100644
index 25c93cfa7..000000000
--- a/web/tests/native-button-title-baseline.json
+++ /dev/null
@@ -1,92 +0,0 @@
-{
- "app/(admin)/admin/users/page.tsx": ["2062b4d5ddb4c30d","472e77d1046643e1","5db5f4b744aa129d"],
- "app/(utility)/session-handoff/page.tsx": ["ea0758b3abef58d5"],
- "app/(workspace)/co-writer/page.tsx": ["c4b460087174c7d1"],
- "app/(workspace)/kanban/page.tsx": ["9fbc9c11a1180034","a7565e650e5aba54","aeccd7575e9820b7"],
- "app/(workspace)/learning/books/components/BookChatPanel.tsx": ["4dd0ddd866978e50"],
- "app/(workspace)/learning/books/components/BookCreator.tsx": ["4a81c6dfb255ee77"],
- "app/(workspace)/learning/books/components/BookHealthBanner.tsx": ["39044f87184bce61","805a5d47c999eaea"],
- "app/(workspace)/learning/books/components/BookLibrary.tsx": ["94d4fce96270ab32"],
- "app/(workspace)/learning/books/components/BookSidebar.tsx": ["5cc9cef7cc744776","9726d994424b74b4","a0e52ce02849fb58","fa3b55fb791ae302"],
- "app/(workspace)/learning/books/components/LearningCapturePanel.tsx": ["f263bc4350540dcf"],
- "app/(workspace)/learning/books/components/PageOutlineNav.tsx": ["438c97f8d456752d","542eab7e9945df98"],
- "app/(workspace)/learning/books/components/PageReader.tsx": ["451d97ffd70b2cce","53b7fc0beb53cf4d","9a0ebb5a90deee8e"],
- "app/(workspace)/learning/books/components/blocks/BlockRenderer.tsx": ["104d0957f4b4f517","40a02aeb89b2f7ab","48d62d6823995f15","6a981344f3174a7c","76e9fa63f5b286ff","f2109d5b66da4b67"],
- "app/(workspace)/learning/books/components/blocks/DeepDiveBlock.tsx": ["085a7b26057b8828"],
- "app/(workspace)/learning/books/components/blocks/UserNoteBlock.tsx": ["94600886694d29f8"],
- "app/(workspace)/partners/[partnerId]/page.tsx": ["087215314c6987da","504883adb4c02e80","550e828ba3bbf720","5cdc5fa3c2a39503","67d0cac91be25bd1","e6e304c6f49e7795"],
- "app/(workspace)/partners/groups/[groupId]/page.tsx": ["aefb4192588e78e5"],
- "components/agents/ConnectedAgents.tsx": ["8d1b1b9a9ab7f1d3"],
- "components/auth/LogoutButton.tsx": ["fe803f9f9c035c7b"],
- "components/chat/MyAgentsPicker.tsx": ["9de41a24dfd55c5a"],
- "components/chat/home/ChatComposer.tsx": ["8a2e4aeb0d05841e","b9d19f8a62dbe1dc","c4cdd71599b0a6e5"],
- "components/chat/home/ComposerRail.tsx": ["064d6f5464f66ecc"],
- "components/chat/home/ModelSelector.tsx": ["3152db27d320353d","9cfe996e2a7ef139","da77f8a2bb413fd7"],
- "components/chat/home/SelectedResources.tsx": ["104c56119ad6d653"],
- "components/chat/home/SessionActivityPanel.tsx": ["c4e6fa254275dd34"],
- "components/chat/home/SessionViewerPanel.tsx": ["3fbe3782aa64cd06","50553880b9e5710c","6df6a6968069c06d","7457e0cbd0b881b9"],
- "components/chat/home/StarterSuggestions.tsx": ["31b4f8d5b0483a5e"],
- "components/chat/preview/FilePreviewDrawer.tsx": ["4a8b532fc93d841e","801709683650aed7","a6508430d1c2c5b0"],
- "components/chat/preview/previewers/XlsxPreview.tsx": ["644e66fec714a278"],
- "components/cli-apps/CliAppsSection.tsx": ["4297890756842a8d"],
- "components/common/GeogebraOpenCTA.tsx": ["c922f34a7cbab6fc"],
- "components/knowledge/CreateKbModal.tsx": ["f0b47e25abfa183a"],
- "components/knowledge/FileDropZone.tsx": ["b090b69445b9626c"],
- "components/knowledge/KbDocumentList.tsx": ["0cb9a2f0be64dc21","22f74a32c8edf442","2d2d8d0a367709a3","9e8b922f0bd9649e","c70d02d3d88edea7","cf62e1c80305f6d2","d586e779faf3fe93","e1b1b9985a06297e","e9ab1ad073047aec","f493f2282f2d952c"],
- "components/knowledge/KbFilePreview.tsx": ["3fcd4dcde9a8c49f","74872960f708a6a5","74872960f708a6a5","d899aee2a951ffda"],
- "components/knowledge/KbGitHubSourcesSection.tsx": ["a45507814306d2b0"],
- "components/knowledge/KbIndexVersionsSection.tsx": ["cca712cf150b8e34"],
- "components/knowledge/KbLinkedFoldersSection.tsx": ["02bdc6724cac8ecb","0e03400573df5031","5a86fb5a135080df"],
- "components/knowledge/KbUpdateHistory.tsx": ["16f6d96751e34943"],
- "components/knowledge/KbWebSourcesSection.tsx": ["05e0e41adba1dff1","36c0e1d57f9215fe","5432c20c4bd61669"],
- "components/knowledge/KnowledgeBaseDetail.tsx": ["3a15884928eef782"],
- "components/learning/practice/PracticeInsights.tsx": ["3b4b2336e855eea4"],
- "components/memory/MemoryRunPanel.tsx": ["060a159e01bddd43","4e6edc77c87d1d60","55172231371dae47","6af569ad63057100","c6f3fe36c916e65c","d99a915c7452ea52"],
- "components/memory/MemorySection.tsx": ["607d03f9841c16ed","607d03f9841c16ed","8ef98453cb691350"],
- "components/notebook/NotebookConsole.tsx": ["ce6e5b9219b029ca"],
- "components/notebook/NotebookRecordRow.tsx": ["224834fc8c082451"],
- "components/partners/AssetPicker.tsx": ["ce740dd43aa500fe"],
- "components/partners/PartnerArchives.tsx": ["58540567c02eb130","73792ac6d7f0e598","857df68488445e96"],
- "components/partners/PartnerChannels.tsx": ["4e6c301b7c8893de"],
- "components/partners/PartnerComposer.tsx": ["4dd0ddd866978e50","89c6cfcb9ec5af55"],
- "components/partners/SoulPicker.tsx": ["d89d6e61f57764c9"],
- "components/partners/group/GroupComposer.tsx": ["ab299ea7f4504c51","b6d0dbdef35684e7"],
- "components/partners/group/GroupSessionPicker.tsx": ["bb3aae75b685744f"],
- "components/partners/group/PartnerSeat.tsx": ["04e2114ac19fdaf5","c5e52a4103c00279"],
- "components/partners/schema-form.tsx": ["7cf112e40158bc18"],
- "components/quiz/QuizConfigPanel.tsx": ["6cfc3e0690b46adb","f52fe91070af5cb1"],
- "components/quiz/QuizViewer.tsx": ["10fe5ac34f0e5b5c","155eb455409f5fee","5914ded12426314c","68d30d274f1cfd3f","867faa22062895ed","f34db87829bd639a"],
- "components/reading/AnnotationLayer.tsx": ["2ea1d9af29459edb"],
- "components/reading/AnnotationList.tsx": ["9f2a45a2887e1a3f"],
- "components/reading/ReaderDisplayControls.tsx": ["f7ceaa362f776884"],
- "components/reading/ReaderPane.tsx": ["5287ce04aaaee4f8","f7ceaa362f776884"],
- "components/reading/ReadingExtensionBar.tsx": ["090161977d5e7acf","b03082aae3a3777b"],
- "components/reading/library/FolderDialog.tsx": ["289f0e3e0693cd09"],
- "components/reading/library/ReadingFolder.tsx": ["314253c02a6ff29a","79a4406eb0165bf7"],
- "components/reading/workspace/SourceNavigator.tsx": ["77d599c76a538534","942c1a2294e92e5a"],
- "components/settings/CodeBuddyAuthCard.tsx": ["7471c9e2a8e28339"],
- "components/settings/ModelsWorkspace.tsx": ["ce53e95e372ce024"],
- "components/settings/ProvidersWorkspace.tsx": ["6a01d5cc51cde922"],
- "components/settings/RegistryControls.tsx": ["d2e5a59d961d98ba"],
- "components/settings/ServiceConfigEditor.tsx": ["8ae3f2f23cc44037"],
- "components/settings/SettingsToolbar.tsx": ["66830400e0fd25e6"],
- "components/space/ArchivedConversations.tsx": ["1e3aeb7319e5f65a","5f4cfea0cda04a3e"],
- "components/space/MyAgentsSection.tsx": ["9d284f1f46bbdc41","df7468919c9a7ea8"],
- "components/space/PersonasSection.tsx": ["1be81f8b4229bc9e","6746a68137fe2391","89ef0ac70d058a20"],
- "components/space/SkillsSection.tsx": ["6581aa3354cc6d2d","6746a68137fe2391","789eee2908c10770","ad71bc1aca08d1a5","d1c86b5ddb329174"],
- "components/space/learning/MasteryStudy.tsx": ["67d0cac91be25bd1"],
- "components/space/learning/ModeSwitch.tsx": ["6c98276670c94312"],
- "components/space/learning/PathTitle.tsx": ["142069af8906d16c","85b37242c76f46a3","ac6d10ef156c74dd"],
- "components/space/learning/ReviewTrail.tsx": ["67432e520fac2bd8"],
- "components/space/learning/StudyOutline.tsx": ["b61001c8756d0f9d","ea2c9a7f429a8944"],
- "components/visualize/VisualizationViewer.tsx": ["b58434ec29492df8","be23e619c1d2e3e3","ed6a8d0dc50cedcc"],
- "components/visualize/VisualizeConfigPanel.tsx": ["1927f8cc6fe4ecb1"],
- "components/workspaces/WorkspaceChatGroups.tsx": ["c3c3c760376dc6d6"],
- "components/workspaces/WorkspacePill.tsx": ["30841304e8b58ccc","53da125ababd5a38","c3990b73bc43d246"],
- "features/chat/components/ChatWorkspace.tsx": ["01c3aa61603e3336"],
- "features/co-writer/components/CoWriterWorkspace.tsx": ["0219f3bd0cfce757","369bed5cfffcda93","53f44662b8d95095","ab73950bcdb666a5","b34363d5acaef69f","c8340c792e0fc256","d4b48fe0bd46c01d","e66eeeac83db6144"],
- "features/settings/components/UsageActivity.tsx": ["044bb0f681e7b117"],
- "features/settings/sections/ArchivedChatsSettingsSection.tsx": ["3b6ca9ed135e8910"],
- "features/settings/sections/ToolsSettingsSection.tsx": ["89d0d5d67ee69c8f"],
- "features/settings/sections/WorkspaceSettingsSection.tsx": ["8ddce9eae1d2450c","be4c3b734823542f","e71d8dc6e998551d"]
-}
diff --git a/web/tests/native-button-title.test.ts b/web/tests/native-button-title.test.ts
index f7927487b..ba9851c9a 100644
--- a/web/tests/native-button-title.test.ts
+++ b/web/tests/native-button-title.test.ts
@@ -1,94 +1,58 @@
-import assert from "node:assert/strict";
-import { createHash } from "node:crypto";
-import { readFileSync, readdirSync } from "node:fs";
-import path from "node:path";
-import test from "node:test";
-import ts from "typescript";
+import assert from 'node:assert/strict'
+import { readFileSync, readdirSync } from 'node:fs'
+import path from 'node:path'
+import test from 'node:test'
+import ts from 'typescript'
-type TitleDebt = Record<string, string[]>;
-
-const root = process.cwd();
-// Existing native hints remain in this debt snapshot. Deleting one needs no
-// fixture update; adding one fails even when another file was cleaned up.
-const baseline: TitleDebt = JSON.parse(
- readFileSync(path.join(root, "tests/native-button-title-baseline.json"), "utf8"),
-);
+const root = process.cwd()
function sourceFiles(directory: string): string[] {
- return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
- const file = path.join(directory, entry.name);
- if (entry.isDirectory()) return sourceFiles(file);
- return entry.name.endsWith(".tsx") ? [file] : [];
- });
+ return readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
+ const file = path.join(directory, entry.name)
+ if (entry.isDirectory()) return sourceFiles(file)
+ return entry.name.endsWith('.tsx') ? [file] : []
+ })
}
function attribute(
node: ts.JsxOpeningElement | ts.JsxSelfClosingElement,
- name: string,
+ name: string
): ts.JsxAttribute | undefined {
return node.attributes.properties.find(
(property): property is ts.JsxAttribute =>
- ts.isJsxAttribute(property) && property.name.getText() === name,
- );
-}
-
-function signature(
- node: ts.JsxOpeningElement | ts.JsxSelfClosingElement,
- source: ts.SourceFile,
-): string {
- // Ignore styling and line movement. The hint and action identify a legacy
- // control; adding another control with the same pair still exceeds its
- // allowed occurrence count.
- const details = ["title", "onClick", "aria-label"]
- .map((name) => attribute(node, name)?.initializer?.getText(source) ?? "")
- .map((value) => value.replace(/\s+/g, " ").trim())
- .join("|");
- return createHash("sha256").update(details).digest("hex").slice(0, 16);
+ ts.isJsxAttribute(property) && property.name.getText() === name
+ )
}
-test("new native button titles must use the shared Tooltip", () => {
- const violations: string[] = [];
- for (const sourceRoot of [
- "app",
- "components",
- "context",
- "features",
- "hooks",
- "lib",
- "shared",
- ]) {
+test('native button hints must use the shared Tooltip', () => {
+ const violations: string[] = []
+ for (const sourceRoot of ['app', 'components', 'context', 'features', 'hooks', 'lib', 'shared']) {
for (const file of sourceFiles(path.join(root, sourceRoot))) {
- const relative = path.relative(root, file).split(path.sep).join("/");
+ const relative = path.relative(root, file).split(path.sep).join('/')
const source = ts.createSourceFile(
file,
- readFileSync(file, "utf8"),
+ readFileSync(file, 'utf8'),
ts.ScriptTarget.Latest,
true,
- ts.ScriptKind.TSX,
- );
- const allowed = [...(baseline[relative] ?? [])];
+ ts.ScriptKind.TSX
+ )
const visit = (node: ts.Node) => {
if (
(ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) &&
- node.tagName.getText(source) === "button" &&
- attribute(node, "title")
+ node.tagName.getText(source) === 'button' &&
+ attribute(node, 'title')
) {
- const hash = signature(node, source);
- const index = allowed.indexOf(hash);
- if (index >= 0) allowed.splice(index, 1);
- else {
- const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
- violations.push(`${relative}:${line}`);
- }
+ const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1
+ violations.push(`${relative}:${line}`)
}
- ts.forEachChild(node, visit);
- };
- visit(source);
+ ts.forEachChild(node, visit)
+ }
+ visit(source)
}
}
assert.deepEqual(
violations,
[],
- "Replace new <button title> hints with @/shared/ui/Tooltip and an accessible button name",
- );
-});
+ 'Replace <button title> hints with @/shared/ui/Tooltip and an accessible button name'
+ )
+})