-
Notifications
You must be signed in to change notification settings - Fork 835
feat(logViewer): correctness, performance, and UX improvements #3446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { | ||
| countLogEntries, | ||
| getLastNEntries, | ||
| trimBufferToLastNewline, | ||
| } from '../ipc'; | ||
|
|
||
| describe('trimBufferToLastNewline', () => { | ||
| it('returns nothing consumed when the buffer has no newline', () => { | ||
| const buf = Buffer.from('partial line without newline'); | ||
| const { consumed, bytesConsumed } = trimBufferToLastNewline(buf); | ||
| expect(bytesConsumed).toBe(0); | ||
| expect(consumed.length).toBe(0); | ||
| }); | ||
|
|
||
| it('consumes up to and including the last newline mid-buffer', () => { | ||
| const buf = Buffer.from('line one\nline two\npartial line three'); | ||
| const { consumed, bytesConsumed } = trimBufferToLastNewline(buf); | ||
|
|
||
| expect(consumed.toString('utf-8')).toBe('line one\nline two\n'); | ||
| expect(bytesConsumed).toBe(Buffer.byteLength('line one\nline two\n')); | ||
| expect(buf.subarray(bytesConsumed).toString('utf-8')).toBe( | ||
| 'partial line three' | ||
| ); | ||
| }); | ||
|
|
||
| it('consumes the entire buffer when it ends with a newline', () => { | ||
| const buf = Buffer.from('line one\nline two\n'); | ||
| const { consumed, bytesConsumed } = trimBufferToLastNewline(buf); | ||
|
|
||
| expect(bytesConsumed).toBe(buf.length); | ||
| expect(consumed.equals(buf)).toBe(true); | ||
| }); | ||
|
|
||
| it('does not split a multi-byte UTF-8 character across the cut point', () => { | ||
| // "café" ends with a 2-byte UTF-8 char (é = 0xC3 0xA9); make sure the | ||
| // cut happens strictly after a newline, never inside a multi-byte char. | ||
| const completeLine = 'café logged\n'; | ||
| const partialMultiByteTail = 'café'; // "café" without trailing newline | ||
| const buf = Buffer.concat([ | ||
| Buffer.from(completeLine, 'utf-8'), | ||
| Buffer.from(partialMultiByteTail, 'utf-8'), | ||
| ]); | ||
|
|
||
| const { consumed, bytesConsumed } = trimBufferToLastNewline(buf); | ||
|
|
||
| expect(bytesConsumed).toBe(Buffer.byteLength(completeLine, 'utf-8')); | ||
| expect(consumed.toString('utf-8')).toBe(completeLine); | ||
|
|
||
| const remainder = buf.subarray(bytesConsumed); | ||
| expect(remainder.toString('utf-8')).toBe(partialMultiByteTail); | ||
| }); | ||
|
|
||
| it('returns an empty consumed buffer for an empty input', () => { | ||
| const { consumed, bytesConsumed } = trimBufferToLastNewline( | ||
| Buffer.alloc(0) | ||
| ); | ||
| expect(bytesConsumed).toBe(0); | ||
| expect(consumed.length).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getLastNEntries', () => { | ||
| const buildLog = (count: number): string => | ||
| Array.from( | ||
| { length: count }, | ||
| (_, i) => | ||
| `[2024-01-01 10:00:${String(i).padStart(2, '0')}.000] [info] [main] Entry ${i}` | ||
| ).join('\n'); | ||
|
|
||
| it('returns all content and correct total when limit exceeds entry count', () => { | ||
| const log = buildLog(3); | ||
| const { content, totalEntries } = getLastNEntries(log, 10); | ||
| expect(totalEntries).toBe(3); | ||
| expect(content).toBe(log); | ||
| }); | ||
|
|
||
| it('returns only the last N entries', () => { | ||
| const log = buildLog(5); | ||
| const { content, totalEntries } = getLastNEntries(log, 2); | ||
| expect(totalEntries).toBe(5); | ||
| expect(content.split('\n')).toHaveLength(2); | ||
| expect(content).toContain('Entry 3'); | ||
| expect(content).toContain('Entry 4'); | ||
| expect(content).not.toContain('Entry 2'); | ||
| }); | ||
|
|
||
| it('returns empty content and zero entries for a non-positive limit', () => { | ||
| const { content, totalEntries } = getLastNEntries(buildLog(3), 0); | ||
| expect(content).toBe(''); | ||
| expect(totalEntries).toBe(0); | ||
| }); | ||
|
|
||
| it('falls back to the last N lines when no entries match the log pattern', () => { | ||
| const content = 'plain line 1\nplain line 2\nplain line 3'; | ||
| const result = getLastNEntries(content, 2); | ||
| expect(result.totalEntries).toBe(0); | ||
| expect(result.content).toBe('plain line 2\nplain line 3'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('countLogEntries', () => { | ||
| it('counts entry-start lines and ignores continuation lines', () => { | ||
| const content = [ | ||
| '[2024-01-01 10:00:00.000] [info] [main] First', | ||
| ' continuation line', | ||
| '[2024-01-01 10:00:01.000] [warn] [main] Second', | ||
| ].join('\n'); | ||
|
|
||
| expect(countLogEntries(content)).toBe(2); | ||
| }); | ||
|
|
||
| it('returns 0 for content with no matching entries', () => { | ||
| expect(countLogEntries('just some text\nanother line')).toBe(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { | ||
| MAX_COLLAPSED_MESSAGE_LINES, | ||
| splitMessageForCollapse, | ||
| splitTextForHighlight, | ||
| } from '../textHighlight'; | ||
|
|
||
| describe('splitTextForHighlight', () => { | ||
| it('returns a single unmatched segment when query is empty', () => { | ||
| expect(splitTextForHighlight('hello world', '')).toEqual([ | ||
| { text: 'hello world', matched: false }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('returns a single unmatched segment when there is no match', () => { | ||
| expect(splitTextForHighlight('hello world', 'xyz')).toEqual([ | ||
| { text: 'hello world', matched: false }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('splits and marks a single case-insensitive match', () => { | ||
| const result = splitTextForHighlight('Hello World', 'world'); | ||
| expect(result).toEqual([ | ||
| { text: 'Hello ', matched: false }, | ||
| { text: 'World', matched: true }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('marks all occurrences of the query', () => { | ||
| const result = splitTextForHighlight('foo bar foo', 'foo'); | ||
| expect(result).toEqual([ | ||
| { text: 'foo', matched: true }, | ||
| { text: ' bar ', matched: false }, | ||
| { text: 'foo', matched: true }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('escapes regex special characters in the query', () => { | ||
| const result = splitTextForHighlight('a.b*c', '.b*'); | ||
| expect(result).toEqual([ | ||
| { text: 'a', matched: false }, | ||
| { text: '.b*', matched: true }, | ||
| { text: 'c', matched: false }, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('splitMessageForCollapse', () => { | ||
| it('returns all lines with zero hidden count when under the threshold', () => { | ||
| const message = Array.from({ length: 3 }, (_, i) => `line ${i}`).join('\n'); | ||
| const { visibleLines, hiddenLineCount } = splitMessageForCollapse(message); | ||
| expect(visibleLines).toHaveLength(3); | ||
| expect(hiddenLineCount).toBe(0); | ||
| }); | ||
|
|
||
| it('returns exactly the threshold with zero hidden count at the boundary', () => { | ||
| const message = Array.from( | ||
| { length: MAX_COLLAPSED_MESSAGE_LINES }, | ||
| (_, i) => `line ${i}` | ||
| ).join('\n'); | ||
| const { visibleLines, hiddenLineCount } = splitMessageForCollapse(message); | ||
| expect(visibleLines).toHaveLength(MAX_COLLAPSED_MESSAGE_LINES); | ||
| expect(hiddenLineCount).toBe(0); | ||
| }); | ||
|
|
||
| it('truncates to the threshold and reports the hidden count when over it', () => { | ||
| const totalLines = MAX_COLLAPSED_MESSAGE_LINES + 4; | ||
| const message = Array.from( | ||
| { length: totalLines }, | ||
| (_, i) => `line ${i}` | ||
| ).join('\n'); | ||
| const { visibleLines, hiddenLineCount } = splitMessageForCollapse(message); | ||
| expect(visibleLines).toHaveLength(MAX_COLLAPSED_MESSAGE_LINES); | ||
| expect(visibleLines).toEqual([ | ||
| 'line 0', | ||
| 'line 1', | ||
| 'line 2', | ||
| 'line 3', | ||
| 'line 4', | ||
| 'line 5', | ||
| ]); | ||
| expect(hiddenLineCount).toBe(4); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: RocketChat/Rocket.Chat.Electron
Length of output: 50388
🏁 Script executed:
Repository: RocketChat/Rocket.Chat.Electron
Length of output: 50387
🏁 Script executed:
Repository: RocketChat/Rocket.Chat.Electron
Length of output: 27986
🌐 Web query:
i18next 23.7 pluralization count _one _other missing plural suffix behavior💡 Result:
In i18next (including version 23.7), pluralization relies on the Intl.PluralRules API to determine which suffix (e.g., _one, _other, _few, _many) to append to your translation key [1][2]. The behavior regarding "missing" plural suffixes follows these key principles: 1. Mandatory Suffixes: i18next maps counts to specific CLDR plural categories [3]. If the language’s current plural rule dictates a specific category (e.g., "many" for 14 in Polish) but that suffix is missing from your JSON (e.g., key_many is undefined), i18next will not automatically fall back to _other [4]. Instead, it will fail to find the translation and return the key name (or trigger the missing key handler) [3][4]. 2. The Role of _other: The _other suffix is not a universal fallback for all missing categories; it is itself a specific CLDR category [3]. While _other is required by the CLDR specification and serves as the fallback for categories that cannot be matched otherwise, it will not be used if the PluralRules engine explicitly determines that the count belongs to a different category (like _many or _few) that is not defined in your files [3][4]. 3. Requirement of 'count': Pluralization is only triggered when the count option is provided to the t function [1][3]. If you call t('key') without {count: n}, i18next looks for the base key (e.g., 'key') and will not attempt to resolve any plural suffixes [3][4]. 4. Intl.PluralRules Dependency: i18next v23 uses the Intl API to determine these categories [2][5]. If your environment lacks this support (e.g., certain older engines), it degrades to a basic English-style rule (_one and _other only) or requires a polyfill [1][2]. To ensure consistent behavior, you must provide all CLDR-defined plural forms for the languages you support [4]. You can identify the required suffixes for a language using the browser console: new Intl.PluralRules('your-language-code').resolvedOptions.pluralCategories [4]. If you are experiencing unexpected key returns, verify that you are providing the count variable and that your JSON contains all necessary categories for that language, not just _one and _other [3][4].
Citations:
Add plural forms for
newEntriesPaused.logViewerWindow.tsxpassescount: pendingNewEntryCountto this translation. The current template can render “1 new entries.” AddnewEntriesPaused_oneandnewEntriesPaused_other.The
matcheskey has no matching translation call in the inspected source.📍 Affects 1 file
src/i18n/en.i18n.json#L740-L740(this comment)src/i18n/en.i18n.json#L808-L808🤖 Prompt for AI Agents