@lemonriver/core 1.1.0 → 1.2.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 (92) hide show
  1. package/dist/{build-Dm7gVRhb.js → build-CSkdswfd.js} +1 -1
  2. package/dist/cli/bin.js +5 -5
  3. package/dist/{config-CubOIzrs.js → config-C5-myPY6.js} +129 -2
  4. package/dist/{dev-DgLeXPqp.js → dev-DHtYH8sw.js} +2 -2
  5. package/dist/{mcp-CjYDzcJa.js → mcp-B2UeO1un.js} +1 -1
  6. package/dist/{preview-CxXQpPk5.js → preview-C1B6-umF.js} +1 -1
  7. package/dist/{update-b1dSg_FW.js → update-DzL8fpcI.js} +1 -1
  8. package/dist/vite/index.js +1 -1
  9. package/package.json +5 -2
  10. package/release-notes.json +19 -0
  11. package/src/app/lemonriver/chrome/app-chrome.tsx +52 -0
  12. package/src/app/lemonriver/chrome/sidebar-extras.tsx +8 -1
  13. package/src/app/lemonriver/feedback/dialog.tsx +222 -0
  14. package/src/app/lemonriver/feedback/export.ts +21 -2
  15. package/src/app/lemonriver/feedback/first-success.ts +30 -0
  16. package/src/app/lemonriver/feedback/install.ts +18 -0
  17. package/src/app/lemonriver/feedback/model.ts +88 -0
  18. package/src/app/lemonriver/help/help-page.tsx +16 -1
  19. package/src/app/lemonriver/links.ts +16 -0
  20. package/src/app/lemonriver/settings/backup-section.tsx +13 -0
  21. package/src/app/lemonriver/settings/settings-page.tsx +20 -0
  22. package/src/app/lemonriver/share/editor-share.tsx +6 -3
  23. package/src/app/lemonriver/share/share-dialog.tsx +2 -0
  24. package/src/app/lemonriver/text/en.ts +45 -0
  25. package/src/app/lemonriver/text/es.ts +42 -0
  26. package/src/app/lemonriver/text/ja.ts +41 -0
  27. package/src/app/lemonriver/text/types.ts +44 -0
  28. package/src/app/lemonriver/text/zh-cn.ts +45 -0
  29. package/src/app/lemonriver/text/zh-tw.ts +45 -0
  30. package/src/app/lemonriver/theme/pages.ts +4 -0
  31. package/src/app/lemonriver/update/release-notes.ts +22 -0
  32. package/src/app/lemonriver/update/update-prompt.tsx +28 -4
  33. package/src/app/components/note-markdown.test.tsx +0 -42
  34. package/src/app/components/thumbnail-rail-scroll.test.ts +0 -60
  35. package/src/app/lemonriver/agent-prefs/prefs.test.ts +0 -173
  36. package/src/app/lemonriver/backup/guide.test.ts +0 -45
  37. package/src/app/lemonriver/backup/model.test.ts +0 -108
  38. package/src/app/lemonriver/backup/places.test.ts +0 -154
  39. package/src/app/lemonriver/board/blocks/classify.test.ts +0 -209
  40. package/src/app/lemonriver/board/layout.test.ts +0 -245
  41. package/src/app/lemonriver/board/model/agent-tasks.test.ts +0 -200
  42. package/src/app/lemonriver/board/model/apply-prompt.test.ts +0 -121
  43. package/src/app/lemonriver/board/model/cards.test.ts +0 -332
  44. package/src/app/lemonriver/board/model/changes.test.ts +0 -244
  45. package/src/app/lemonriver/board/model/filter.test.ts +0 -50
  46. package/src/app/lemonriver/board/model/history.test.ts +0 -71
  47. package/src/app/lemonriver/board/model/restructure.test.ts +0 -205
  48. package/src/app/lemonriver/board/model/self-check.test.ts +0 -329
  49. package/src/app/lemonriver/board/model/structure.test.ts +0 -350
  50. package/src/app/lemonriver/board/model/timing.test.ts +0 -113
  51. package/src/app/lemonriver/features.test.ts +0 -49
  52. package/src/app/lemonriver/feedback/pending-toast.test.ts +0 -44
  53. package/src/app/lemonriver/feedback/upload.test.ts +0 -26
  54. package/src/app/lemonriver/help/model.test.ts +0 -179
  55. package/src/app/lemonriver/home/brief.test.ts +0 -38
  56. package/src/app/lemonriver/home/drafts.test.ts +0 -23
  57. package/src/app/lemonriver/home/sorting.test.ts +0 -24
  58. package/src/app/lemonriver/home/time.test.ts +0 -33
  59. package/src/app/lemonriver/outline/files.test.ts +0 -90
  60. package/src/app/lemonriver/outline/model.test.ts +0 -751
  61. package/src/app/lemonriver/public-links.test.ts +0 -32
  62. package/src/app/lemonriver/routes.test.tsx +0 -54
  63. package/src/app/lemonriver/share/codes.test.ts +0 -49
  64. package/src/app/lemonriver/share/compare.test.ts +0 -199
  65. package/src/app/lemonriver/share/folder.test.ts +0 -42
  66. package/src/app/lemonriver/share/guide.test.ts +0 -78
  67. package/src/app/lemonriver/share/naming.test.ts +0 -70
  68. package/src/app/lemonriver/share/paths.test.ts +0 -116
  69. package/src/app/lemonriver/share/pdf.test.ts +0 -79
  70. package/src/app/lemonriver/templates/knobs.test.ts +0 -62
  71. package/src/app/lemonriver/templates/model.test.ts +0 -175
  72. package/src/app/lemonriver/templates/preview-content.test.ts +0 -117
  73. package/src/app/lemonriver/templates/recommend.test.ts +0 -71
  74. package/src/app/lemonriver/text/text.test.ts +0 -90
  75. package/src/app/lemonriver/theme/pages.test.ts +0 -74
  76. package/src/app/lemonriver/theme/themes.test.ts +0 -18
  77. package/src/app/lemonriver/trash/api.test.ts +0 -19
  78. package/src/app/lemonriver/update/prompt.test.ts +0 -84
  79. package/src/app/lemonriver/update/version.test.ts +0 -14
  80. package/src/app/lib/asset-filter.test.ts +0 -176
  81. package/src/app/lib/inspector/fiber.test.ts +0 -154
  82. package/src/app/lib/inspector/geometry.test.ts +0 -324
  83. package/src/app/lib/inspector/text-edit-timeline.test.ts +0 -121
  84. package/src/app/lib/note-markdown.test.ts +0 -147
  85. package/src/app/lib/pptx/css.test.ts +0 -205
  86. package/src/app/lib/pptx/ooxml.test.ts +0 -199
  87. package/src/app/lib/pptx/text-lines.test.ts +0 -82
  88. package/src/app/lib/print-ready.test.ts +0 -32
  89. package/src/app/lib/sdk.test.ts +0 -13
  90. package/src/app/lib/transition.test.ts +0 -31
  91. package/src/app/lib/use-document-title.test.ts +0 -14
  92. package/src/app/lib/utils.test.ts +0 -49
@@ -1,113 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { Block } from '../blocks/classify';
3
- import {
4
- estimateSeconds,
5
- formatDuration,
6
- sanitizeTargetMinutes,
7
- speakingSeconds,
8
- } from './timing.ts';
9
-
10
- const block = (kind: Block['kind'], text = ''): Block => ({
11
- id: `${kind}-${text}`,
12
- kind,
13
- text,
14
- loc: null,
15
- box: { x: 0, y: 0, w: 0, h: 0 },
16
- });
17
-
18
- /** A run of Chinese characters, one second per four of them. */
19
- const han = (count: number) => '字'.repeat(count);
20
- const words = (count: number) => Array.from({ length: count }, (_, i) => `word${i}`).join(' ');
21
-
22
- describe('estimateSeconds', () => {
23
- it('reads Chinese by the character: 240 a minute', () => {
24
- expect(estimateSeconds({ blocks: null, notes: han(240) })).toEqual({
25
- seconds: 60,
26
- basis: 'notes',
27
- });
28
- });
29
-
30
- it('reads English by the word: 150 a minute', () => {
31
- expect(estimateSeconds({ blocks: null, notes: words(150) })).toEqual({
32
- seconds: 60,
33
- basis: 'notes',
34
- });
35
- });
36
-
37
- it('adds up a page that mixes both', () => {
38
- // Half a minute of Chinese plus half a minute of English.
39
- expect(speakingSeconds(`${han(120)} ${words(75)}`)).toBeCloseTo(60, 5);
40
- });
41
-
42
- it('gives a page with only a chart the minimum', () => {
43
- expect(estimateSeconds({ blocks: [block('chart')] })).toEqual({
44
- seconds: 15,
45
- basis: 'page',
46
- });
47
- });
48
-
49
- it('prefers the speaker notes over the words on the page', () => {
50
- const timing = estimateSeconds({ notes: han(240), blocks: [block('text', words(300))] });
51
- expect(timing).toEqual({ seconds: 60, basis: 'notes' });
52
- });
53
-
54
- it('never goes under fifteen seconds', () => {
55
- expect(estimateSeconds({ blocks: null, notes: 'Hi' }).seconds).toBe(15);
56
- expect(estimateSeconds({ blocks: [block('text', han(4))] }).seconds).toBe(15);
57
- });
58
-
59
- it('rounds to five seconds', () => {
60
- // 224 characters is 56 s, 232 is 58 s.
61
- expect(estimateSeconds({ blocks: null, notes: han(224) }).seconds).toBe(55);
62
- expect(estimateSeconds({ blocks: null, notes: han(232) }).seconds).toBe(60);
63
- });
64
-
65
- it('adds five seconds for each picture when the page is the source', () => {
66
- // 120 characters is 30 s, plus two pictures.
67
- const timing = estimateSeconds({
68
- blocks: [block('text', han(120)), block('image'), block('chart')],
69
- });
70
- expect(timing).toEqual({ seconds: 40, basis: 'page' });
71
- });
72
-
73
- it('cannot tell how long a page whose blocks were not read takes', () => {
74
- expect(estimateSeconds({ blocks: null })).toEqual({ seconds: 15, basis: 'none' });
75
- });
76
-
77
- it('falls back to the page when the notes are blank', () => {
78
- expect(estimateSeconds({ notes: ' ', blocks: [block('text', han(120))] })).toEqual({
79
- seconds: 30,
80
- basis: 'page',
81
- });
82
- });
83
- });
84
-
85
- describe('formatDuration', () => {
86
- it('writes seconds, minutes and seconds, and whole minutes', () => {
87
- expect(formatDuration(45, 'en')).toBe('45s');
88
- expect(formatDuration(80, 'en')).toBe('1m 20s');
89
- expect(formatDuration(720, 'en')).toBe('12 min');
90
- });
91
-
92
- it('writes the same in Chinese', () => {
93
- expect(formatDuration(45, 'zh-CN')).toBe('45 秒');
94
- expect(formatDuration(80, 'zh-CN')).toBe('1 分 20 秒');
95
- expect(formatDuration(720, 'zh-CN')).toBe('12 分钟');
96
- });
97
- });
98
-
99
- describe('sanitizeTargetMinutes', () => {
100
- it('keeps a whole number of minutes within an hour and a half', () => {
101
- expect(sanitizeTargetMinutes(12)).toBe(12);
102
- expect(sanitizeTargetMinutes('7')).toBe(7);
103
- expect(sanitizeTargetMinutes(180)).toBe(180);
104
- });
105
-
106
- it('refuses what cannot be a target', () => {
107
- expect(sanitizeTargetMinutes(0)).toBeNull();
108
- expect(sanitizeTargetMinutes(181)).toBeNull();
109
- expect(sanitizeTargetMinutes('')).toBeNull();
110
- expect(sanitizeTargetMinutes('soon')).toBeNull();
111
- expect(sanitizeTargetMinutes(null)).toBeNull();
112
- });
113
- });
@@ -1,49 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { isFeatureEnabled } from './features';
3
-
4
- describe('isFeatureEnabled', () => {
5
- it('opens the board in dev', () => {
6
- expect(isFeatureEnabled('board', { dev: true })).toBe(true);
7
- });
8
-
9
- it('keeps the board closed outside dev', () => {
10
- expect(isFeatureEnabled('board', { dev: false })).toBe(false);
11
- });
12
-
13
- it('returns false for an unknown feature', () => {
14
- expect(isFeatureEnabled('nope' as never, { dev: true })).toBe(false);
15
- });
16
-
17
- it('returns false when the tier is locked', () => {
18
- expect(isFeatureEnabled('board', { dev: true }, () => false)).toBe(false);
19
- });
20
-
21
- it('keeps the trash to dev, where the server that holds it runs', () => {
22
- expect(isFeatureEnabled('trash', { dev: true })).toBe(true);
23
- expect(isFeatureEnabled('trash', { dev: false })).toBe(false);
24
- });
25
-
26
- it('offers settings in a built site too', () => {
27
- expect(isFeatureEnabled('settings', { dev: false })).toBe(true);
28
- });
29
-
30
- it('keeps the guided outline to dev, where the agent it drives runs', () => {
31
- expect(isFeatureEnabled('outline', { dev: true })).toBe(true);
32
- expect(isFeatureEnabled('outline', { dev: false })).toBe(false);
33
- });
34
-
35
- it('keeps the template library to dev, where its files sit', () => {
36
- expect(isFeatureEnabled('templates', { dev: true })).toBe(true);
37
- expect(isFeatureEnabled('templates', { dev: false })).toBe(false);
38
- });
39
-
40
- it('keeps sharing to dev, where the pack and import endpoints run', () => {
41
- expect(isFeatureEnabled('share', { dev: true })).toBe(true);
42
- expect(isFeatureEnabled('share', { dev: false })).toBe(false);
43
- });
44
-
45
- it('keeps backup to dev, where the backup endpoints run', () => {
46
- expect(isFeatureEnabled('backup', { dev: true })).toBe(true);
47
- expect(isFeatureEnabled('backup', { dev: false })).toBe(false);
48
- });
49
- });
@@ -1,44 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { clearPendingToast, savePendingToast, takePendingToast } from './pending-toast';
3
-
4
- function memoryStorage(): Storage {
5
- const map = new Map<string, string>();
6
- return {
7
- get length() {
8
- return map.size;
9
- },
10
- clear: () => map.clear(),
11
- getItem: (k) => map.get(k) ?? null,
12
- key: (i) => [...map.keys()][i] ?? null,
13
- removeItem: (k) => {
14
- map.delete(k);
15
- },
16
- setItem: (k, v) => {
17
- map.set(k, v);
18
- },
19
- };
20
- }
21
-
22
- describe('pending toast', () => {
23
- it('shows once after the reload', () => {
24
- const storage = memoryStorage();
25
- savePendingToast({ kind: 'trashed', slideId: 'alpha', name: 'Alpha' }, storage);
26
- expect(takePendingToast(storage)).toEqual({ kind: 'trashed', slideId: 'alpha', name: 'Alpha' });
27
- expect(takePendingToast(storage)).toBeNull();
28
- });
29
-
30
- it('is dropped when the request fails', () => {
31
- const storage = memoryStorage();
32
- savePendingToast({ kind: 'restored', slideId: 'alpha', name: 'Alpha' }, storage);
33
- clearPendingToast(storage);
34
- expect(takePendingToast(storage)).toBeNull();
35
- });
36
-
37
- it('ignores anything it did not write', () => {
38
- const storage = memoryStorage();
39
- storage.setItem('lemonriver:pending-toast', '{"kind":"trashed","name":"x"}');
40
- expect(takePendingToast(storage)).toBeNull();
41
- storage.setItem('lemonriver:pending-toast', 'not json');
42
- expect(takePendingToast(storage)).toBeNull();
43
- });
44
- });
@@ -1,26 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
-
3
- vi.mock('sonner', () => ({ toast: { error: vi.fn() } }));
4
-
5
- import { toast } from 'sonner';
6
- import { ASSET_MAX_BYTES } from '../../../files/assets';
7
- import { en } from '../../../locale/en';
8
- import { toastUploadFailed, UPLOAD_LIMIT_BYTES } from './upload';
9
-
10
- describe('toastUploadFailed', () => {
11
- it('uses the same limit as the server', () => {
12
- expect(UPLOAD_LIMIT_BYTES).toBe(ASSET_MAX_BYTES);
13
- });
14
-
15
- it('explains a file that is too large', () => {
16
- toastUploadFailed(en, 413);
17
- expect(toast.error).toHaveBeenLastCalledWith('The file is over 25 MB', {
18
- description: 'Compress the image or pick a smaller file, then upload again.',
19
- });
20
- });
21
-
22
- it('keeps the official message for other failures', () => {
23
- toastUploadFailed(en, 500);
24
- expect(toast.error).toHaveBeenLastCalledWith('Upload failed (500)');
25
- });
26
- });
@@ -1,179 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { en } from '../../../locale/en.ts';
3
- import type { Locale } from '../../../locale/types.ts';
4
- import { zhCN } from '../../../locale/zh-cn.ts';
5
- import { zhTW } from '../../../locale/zh-tw.ts';
6
- import { lrTextFor } from '../text/all';
7
- import { filterHelpSections, helpAnchorForPlace, helpStrings, placeholdersIn } from './model.ts';
8
-
9
- const ANCHORS = [
10
- 'guide',
11
- 'guide-prepare',
12
- 'guide-agent',
13
- 'guide-ui',
14
- 'guide-finish',
15
- 'guide-faq',
16
- 'share',
17
- 'import',
18
- 'backup',
19
- 'restore',
20
- 'cloud',
21
- 'cloud-icloud',
22
- 'cloud-baidu',
23
- 'cloud-weiyun',
24
- 'cloud-dropbox',
25
- 'cloud-onedrive',
26
- 'cloud-nutstore',
27
- 'cloud-other',
28
- 'cloud-faq',
29
- ];
30
-
31
- const PLACES = [
32
- 'icloud',
33
- 'dropbox',
34
- 'onedrive',
35
- 'baidu',
36
- 'nutstore',
37
- 'other',
38
- 'local',
39
- 'google',
40
- ] as const;
41
-
42
- const LOCALES: Locale['id'][] = ['en', 'es', 'ja', 'zh-CN', 'zh-TW'];
43
-
44
- /** The two example lines under "Prepare", in the order the guide shows them. */
45
- function agentLists(id: Locale['id']): string[] {
46
- const section = lrTextFor(id).help.sections.find((item) => item.id === 'guide-prepare');
47
- const block = section?.blocks[0];
48
- if (block?.kind !== 'steps') throw new Error(`${id}: guide-prepare does not open with steps`);
49
- return block.items[0]?.children ?? [];
50
- }
51
-
52
- describe('the help page', () => {
53
- const zh = lrTextFor('zh-CN');
54
-
55
- it('has one section for every anchor the app links to', () => {
56
- expect(zh.help.sections.map((section) => section.id)).toEqual(ANCHORS);
57
- for (const place of PLACES) {
58
- expect(ANCHORS, place).toContain(helpAnchorForPlace(place));
59
- }
60
- const ids = new Set(zh.help.sections.map((section) => section.id));
61
- for (const section of zh.help.sections) {
62
- if (section.parent !== undefined) expect(ids, section.id).toContain(section.parent);
63
- }
64
- });
65
-
66
- it('names every app button the way the interface does', () => {
67
- // Japanese and Spanish show the English help, so they keep the English names.
68
- const locale = { en, 'zh-CN': zhCN, 'zh-TW': zhTW } as const;
69
- for (const id of ['en', 'zh-CN', 'zh-TW'] as const) {
70
- const text = lrTextFor(id);
71
- const ui = locale[id];
72
- const buttons = text.help.buttons;
73
- const expected = {
74
- settings: text.settings.title,
75
- backupSection: text.backup.title,
76
- share: text.share.open,
77
- generate: text.share.generate,
78
- import: text.share.importAction,
79
- backupNow: text.backup.runNow,
80
- autoBackup: text.backup.auto,
81
- skipVideos: text.backup.skipVideos,
82
- restore: text.backup.restore,
83
- restoreGo: text.backup.restoreGo,
84
- chooseOtherFile: text.backup.chooseOtherFile,
85
- change: text.backup.change,
86
- chooseOther: text.backup.chooseOther,
87
- reveal: text.backup.reveal,
88
- format: ui.inspector.format,
89
- replaceImage: ui.inspector.replaceImageDialogTitle,
90
- assets: ui.home.assets,
91
- board: text.board.title,
92
- notes: ui.presenter.speakerNotes,
93
- comments: ui.inspector.commentMode,
94
- selfCheck: text.board.selfCheck,
95
- present: ui.slide.present,
96
- duplicate: ui.home.duplicate,
97
- };
98
- for (const [key, value] of Object.entries(expected)) {
99
- expect(buttons[key as keyof typeof buttons], `${id}: ${key}`).toBe(value);
100
- }
101
- }
102
- });
103
-
104
- it('puts the agent line each language leads with first', () => {
105
- const domestic = 'WorkBuddy';
106
- const overseas = 'Claude Code';
107
- for (const id of ['zh-CN', 'zh-TW'] as const) {
108
- const lists = agentLists(id);
109
- expect(lists[0], id).toContain(domestic);
110
- expect(lists[1], id).toContain(overseas);
111
- }
112
- for (const id of ['en', 'ja', 'es'] as const) {
113
- const lists = agentLists(id);
114
- expect(lists[0], id).toContain(overseas);
115
- expect(lists[1], id).toContain(domestic);
116
- }
117
- });
118
-
119
- it('lists the agents word for word as the guide text file does', () => {
120
- expect(agentLists('zh-CN')).toEqual([
121
- '国内常用:WorkBuddy、DuMate、DeepSeek Harness、Trae、千问办公、豆包、Kimi CLI 等',
122
- '海外常用:Claude Code、Codex、Gemini CLI、Grok、Cursor、GitHub Copilot、OpenCode 等',
123
- ]);
124
- expect(agentLists('en')).toEqual([
125
- 'Common elsewhere: Claude Code, Codex, Gemini CLI, Grok, Cursor, GitHub Copilot, OpenCode and others',
126
- 'Common in China: WorkBuddy, DuMate, DeepSeek Harness, Trae, 千问办公, 豆包, Kimi CLI and others',
127
- ]);
128
- });
129
-
130
- it('leads with the usage guide', () => {
131
- for (const id of ['en', 'zh-CN', 'zh-TW'] as const) {
132
- const help = lrTextFor(id).help;
133
- expect(help.sections[0]?.id, id).toBe('guide');
134
- const children = help.sections
135
- .filter((section) => section.parent === 'guide')
136
- .map((s) => s.id);
137
- expect(children, id).toEqual([
138
- 'guide-prepare',
139
- 'guide-agent',
140
- 'guide-ui',
141
- 'guide-finish',
142
- 'guide-faq',
143
- ]);
144
- }
145
- expect(lrTextFor('zh-CN').help.title).toBe('使用指南和帮助');
146
- });
147
-
148
- it('fills every placeholder from the button list', () => {
149
- for (const id of LOCALES) {
150
- const help = lrTextFor(id).help;
151
- const keys = new Set(Object.keys(help.buttons));
152
- for (const text of helpStrings(help)) {
153
- for (const name of placeholdersIn(text)) {
154
- expect(keys, `${id}: ${text}`).toContain(name);
155
- }
156
- }
157
- }
158
- });
159
-
160
- it('searches the body, not only the titles', () => {
161
- const ids = (query: string) => filterHelpSections(zh.help.sections, query).map((s) => s.id);
162
- // Only this section's body says 冲突副本; its title does not.
163
- expect(ids('冲突副本')).toEqual(['cloud-faq']);
164
- expect(ids('iCloud')).toEqual(['cloud-icloud']);
165
- expect(ids('Dropbox')).toEqual(['cloud-dropbox']);
166
- expect(ids('没有这个词')).toEqual([]);
167
- });
168
-
169
- it('has the same sections in every language', () => {
170
- const counts = LOCALES.map((id) => lrTextFor(id).help.sections.length);
171
- expect(counts).toEqual(LOCALES.map(() => ANCHORS.length));
172
- for (const id of LOCALES) {
173
- expect(
174
- lrTextFor(id).help.sections.map((section) => section.id),
175
- id,
176
- ).toEqual(ANCHORS);
177
- }
178
- });
179
- });
@@ -1,38 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
-
3
- vi.mock('@/lib/agent/use-agent', () => ({ requestAgent: vi.fn(), useAgentState: vi.fn() }));
4
-
5
- import { saveBrief, takeBrief } from './brief';
6
-
7
- function memoryStorage(): Storage {
8
- const map = new Map<string, string>();
9
- return {
10
- get length() {
11
- return map.size;
12
- },
13
- clear: () => map.clear(),
14
- getItem: (k) => map.get(k) ?? null,
15
- key: (i) => [...map.keys()][i] ?? null,
16
- removeItem: (k) => {
17
- map.delete(k);
18
- },
19
- setItem: (k, v) => {
20
- map.set(k, v);
21
- },
22
- };
23
- }
24
-
25
- describe('new-deck brief', () => {
26
- it('is handed over once', () => {
27
- const storage = memoryStorage();
28
- saveBrief(' A talk on expenses ', storage);
29
- expect(takeBrief(storage)).toBe('A talk on expenses');
30
- expect(takeBrief(storage)).toBeNull();
31
- });
32
-
33
- it('treats a blank brief as none', () => {
34
- const storage = memoryStorage();
35
- saveBrief(' ', storage);
36
- expect(takeBrief(storage)).toBeNull();
37
- });
38
- });
@@ -1,23 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { suggestsFolder } from './drafts.ts';
3
-
4
- describe('draft folder suggestions', () => {
5
- it('suggests a folder that shares a Chinese word, ignoring generic words', () => {
6
- expect(suggestsFolder('商飞项目', '商飞本体进展汇报')).toBe(true);
7
- });
8
-
9
- it('suggests a folder that shares an English word, whatever its case', () => {
10
- expect(suggestsFolder('Acme', 'Acme launch review')).toBe(true);
11
- expect(suggestsFolder('acme', 'ACME launch review')).toBe(true);
12
- });
13
-
14
- it('leaves unrelated drafts alone', () => {
15
- expect(suggestsFolder('产品培训', '季度经营汇报')).toBe(false);
16
- });
17
-
18
- it('does not match on the generic words alone', () => {
19
- expect(suggestsFolder('商飞项目', 'XX 项目进展')).toBe(false);
20
- expect(suggestsFolder('产品培训', 'XX 项目进展')).toBe(false);
21
- expect(suggestsFolder('项目', '商飞项目进展')).toBe(false);
22
- });
23
- });
@@ -1,24 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { filterDecks, sortDecks } from './sorting';
3
-
4
- const created = { a: 3, b: 1, c: 2 };
5
- const titles: Record<string, string> = { a: 'Zeta', b: 'alpha 10', c: 'Alpha 9' };
6
-
7
- describe('sortDecks', () => {
8
- it('orders by creation time and by title', () => {
9
- const ids = ['a', 'b', 'c'];
10
- expect(sortDecks(ids, 'created-desc', (id) => titles[id], created)).toEqual(['a', 'c', 'b']);
11
- expect(sortDecks(ids, 'created-asc', (id) => titles[id], created)).toEqual(['b', 'c', 'a']);
12
- expect(sortDecks(ids, 'title-asc', (id) => titles[id], created)).toEqual(['c', 'b', 'a']);
13
- expect(sortDecks(ids, 'title-desc', (id) => titles[id], created)).toEqual(['a', 'b', 'c']);
14
- expect(ids).toEqual(['a', 'b', 'c']);
15
- });
16
- });
17
-
18
- describe('filterDecks', () => {
19
- it('matches the id or the title, ignoring case', () => {
20
- expect(filterDecks(['a', 'b', 'c'], ' ALPHA ', titles)).toEqual(['b', 'c']);
21
- expect(filterDecks(['a', 'b', 'c'], 'b', titles)).toEqual(['b']);
22
- expect(filterDecks(['a', 'b'], '', titles)).toEqual(['a', 'b']);
23
- });
24
- });
@@ -1,33 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { daysLeft, greetingFor, relativeTime } from './time';
3
-
4
- const NOW = Date.parse('2026-10-29T12:00:00Z');
5
-
6
- describe('relativeTime', () => {
7
- it('picks the largest unit that fits', () => {
8
- expect(relativeTime(NOW - 3 * 24 * 3600 * 1000, NOW, 'en')).toBe('3 days ago');
9
- expect(relativeTime(NOW - 24 * 3600 * 1000, NOW, 'en')).toBe('yesterday');
10
- expect(relativeTime(NOW - 2 * 3600 * 1000, NOW, 'en')).toBe('2 hours ago');
11
- expect(relativeTime(NOW - 10 * 1000, NOW, 'en')).toBe('now');
12
- expect(relativeTime(NOW - 3 * 24 * 3600 * 1000, NOW, 'zh-CN')).toBe('3天前');
13
- });
14
- });
15
-
16
- describe('greetingFor', () => {
17
- it('splits the day at noon and six', () => {
18
- expect(greetingFor(9)).toBe('morning');
19
- expect(greetingFor(12)).toBe('afternoon');
20
- expect(greetingFor(17)).toBe('afternoon');
21
- expect(greetingFor(18)).toBe('evening');
22
- expect(greetingFor(2)).toBe('evening');
23
- });
24
- });
25
-
26
- describe('daysLeft', () => {
27
- it('rounds up and never shows zero', () => {
28
- const day = 24 * 3600 * 1000;
29
- expect(daysLeft(NOW + 29.2 * day, NOW)).toBe(30);
30
- expect(daysLeft(NOW + day, NOW)).toBe(1);
31
- expect(daysLeft(NOW + 1000, NOW)).toBe(1);
32
- });
33
- });
@@ -1,90 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { format } from '../../../locale/format';
3
- import { lrTextFor } from '../text/all';
4
- import { checkFile, extensionOf, formatSize, MAX_FILE_BYTES } from './files';
5
-
6
- const bytes = (values: number[], fill = 16): Uint8Array => {
7
- const head = new Uint8Array(fill).fill(0x50);
8
- head.set(values);
9
- return head;
10
- };
11
-
12
- const pdf = (text = '') => {
13
- const head = new Uint8Array(1024);
14
- head.set(new TextEncoder().encode(`%PDF-1.7\n${text}`));
15
- return head;
16
- };
17
-
18
- describe('checkFile', () => {
19
- it('accepts an ordinary file of a supported kind', () => {
20
- expect(checkFile({ name: 'notes.pdf', size: 1024, head: pdf() })).toBe('ok');
21
- expect(checkFile({ name: 'sheet.xlsx', size: 2048, head: bytes([0x50, 0x4b, 3, 4]) })).toBe(
22
- 'ok',
23
- );
24
- expect(checkFile({ name: 'Assumptions.MD', size: 10, head: bytes([]) })).toBe('ok');
25
- });
26
-
27
- it('rejects anything over 25 MB', () => {
28
- expect(checkFile({ name: 'big.pdf', size: MAX_FILE_BYTES + 1, head: pdf() })).toBe('too-large');
29
- expect(checkFile({ name: 'exact.pdf', size: MAX_FILE_BYTES, head: pdf() })).toBe('ok');
30
- });
31
-
32
- it('rejects kinds it cannot hand over', () => {
33
- expect(checkFile({ name: 'movie.mp4', size: 100, head: bytes([]) })).toBe('unsupported');
34
- expect(checkFile({ name: 'noext', size: 100, head: bytes([]) })).toBe('unsupported');
35
- });
36
-
37
- it('catches a password-protected PDF', () => {
38
- expect(checkFile({ name: 'locked.pdf', size: 100, head: pdf('/Encrypt 5 0 R') })).toBe(
39
- 'locked',
40
- );
41
- });
42
-
43
- it('ignores /Encrypt past the first kilobyte', () => {
44
- const head = new Uint8Array(4096).fill(0x20);
45
- head.set(new TextEncoder().encode('/Encrypt'), 2048);
46
- expect(checkFile({ name: 'late.pdf', size: 4096, head })).toBe('ok');
47
- });
48
-
49
- it('catches an encrypted Office document by its OLE2 header', () => {
50
- expect(
51
- checkFile({ name: 'locked.docx', size: 100, head: bytes([0xd0, 0xcf, 0x11, 0xe0]) }),
52
- ).toBe('locked');
53
- expect(
54
- checkFile({ name: 'locked.pptx', size: 100, head: bytes([0xd0, 0xcf, 0x11, 0xe0]) }),
55
- ).toBe('locked');
56
- expect(
57
- checkFile({ name: 'locked.xlsx', size: 100, head: bytes([0xd0, 0xcf, 0x11, 0xe0]) }),
58
- ).toBe('locked');
59
- });
60
-
61
- it('leaves the old binary Office formats alone', () => {
62
- expect(checkFile({ name: 'old.doc', size: 100, head: bytes([0xd0, 0xcf, 0x11, 0xe0]) })).toBe(
63
- 'ok',
64
- );
65
- });
66
- });
67
-
68
- describe('helpers', () => {
69
- it('reads the extension case-insensitively', () => {
70
- expect(extensionOf('a/b/Report.PDF')).toBe('pdf');
71
- expect(extensionOf('no-dot')).toBe('');
72
- });
73
-
74
- it('shows sizes as bare numbers', () => {
75
- expect(formatSize(30 * 1024 * 1024)).toBe('30');
76
- expect(formatSize(26.5 * 1024 * 1024)).toBe('27');
77
- expect(formatSize(1.4 * 1024 * 1024)).toBe('1.4');
78
- });
79
-
80
- it('states the unit once in the too-large hint', () => {
81
- const size = formatSize(30 * 1024 * 1024);
82
- const hint = (id: 'en' | 'zh-CN') =>
83
- format(lrTextFor(id).outline.tooLargeHint, { name: 'expense-policy.pdf', size });
84
-
85
- expect(hint('en')).toContain('expense-policy.pdf is 30 MB.');
86
- expect(hint('zh-CN')).toContain('expense-policy.pdf 有 30 MB。');
87
- expect(hint('en')).not.toContain('MB MB');
88
- expect(hint('zh-CN')).not.toContain('MB MB');
89
- });
90
- });