-
-
Notifications
You must be signed in to change notification settings - Fork 27
feat: add 'messages command' for slash command capture #51
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
Open
Eduard-Kuzhyr
wants to merge
6
commits into
shaharia-lab:main
Choose a base branch
from
Eduard-Kuzhyr:feat/messages-command-50
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c25c791
feat: add 'messages command' for slash command capture
Eduard-Kuzhyr e362e95
fix: #50: tighten ephemeral match + bound pre-hello wait GENAI=YES
Eduard-Kuzhyr f3050f7
feat: #50: collect ephemerals across full --timeout window
Eduard-Kuzhyr 7284855
Merge branch 'main' into feat/messages-command-50
shahariaazam a33e483
fix: #50: address PR review feedback on slash-command capture
Eduard-Kuzhyr 947380d
Merge branch 'main' into feat/messages-command-50
Eduard-Kuzhyr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| import { describe, expect, it } from 'bun:test'; | ||
| import { renderBlocks, renderAttachments } from './block-renderer.ts'; | ||
|
|
||
| const stripAnsi = (s: string) => s.replace(/\[[0-9;]*m/g, ''); | ||
|
|
||
| describe('renderBlocks', () => { | ||
| it('renders header text', () => { | ||
| const out = stripAnsi(renderBlocks([{ type: 'header', text: { text: 'Hello' } }], 0)); | ||
| expect(out).toBe('Hello\n'); | ||
| }); | ||
|
|
||
| it('skips header without text', () => { | ||
| expect(renderBlocks([{ type: 'header' }], 0)).toBe(''); | ||
| }); | ||
|
|
||
| it('renders section text preserving newlines and indents', () => { | ||
| const out = stripAnsi(renderBlocks([{ type: 'section', text: { text: 'a\nb' } }], 2)); | ||
| expect(out).toBe(' a\n b\n'); | ||
| }); | ||
|
|
||
| it('renders section fields as bullets and flattens internal newlines', () => { | ||
| const out = stripAnsi(renderBlocks([ | ||
| { type: 'section', fields: [{ text: 'one' }, { text: 'two\nlines' }] }, | ||
| ], 0)); | ||
| expect(out).toBe(' • one\n • two lines\n'); | ||
| }); | ||
|
|
||
| it('renders context elements joined with space', () => { | ||
| const out = stripAnsi(renderBlocks([ | ||
| { type: 'context', elements: [{ text: 'foo' }, { alt_text: 'bar' }, {}] }, | ||
| ], 0)); | ||
| expect(out).toBe('foo bar\n'); | ||
| }); | ||
|
|
||
| it('skips empty context', () => { | ||
| expect(renderBlocks([{ type: 'context', elements: [] }], 0)).toBe(''); | ||
| }); | ||
|
|
||
| it('renders divider', () => { | ||
| const out = stripAnsi(renderBlocks([{ type: 'divider' }], 0)); | ||
| expect(out).toBe('─────────\n'); | ||
| }); | ||
|
|
||
| it('skips actions and image blocks', () => { | ||
| expect(renderBlocks([{ type: 'actions' }, { type: 'image' }], 0)).toBe(''); | ||
| }); | ||
|
|
||
| it('falls back to default renderer when block.type is unknown', () => { | ||
| const out = stripAnsi(renderBlocks([{ type: 'mystery', text: { text: 'x' } }], 0)); | ||
| expect(out).toBe('x\n'); | ||
| }); | ||
|
|
||
| it('renders rich_text plain text + link + user + channel + emoji', () => { | ||
| const out = stripAnsi(renderBlocks([{ | ||
| type: 'rich_text', | ||
| elements: [{ | ||
| type: 'rich_text_section', | ||
| elements: [ | ||
| { type: 'text', text: 'hi ' }, | ||
| { type: 'link', text: 'site', url: 'https://x' }, | ||
| { type: 'text', text: ' ' }, | ||
| { type: 'user', user_id: 'U1' }, | ||
| { type: 'text', text: ' ' }, | ||
| { type: 'channel', channel_id: 'C1' }, | ||
| { type: 'text', text: ' ' }, | ||
| { type: 'emoji', name: 'wave' }, | ||
| ], | ||
| }], | ||
| }], 0)); | ||
| // Trailing blank line is from rich_text_section appending \n, then the | ||
| // outer per-line loop emitting one more newline for the empty tail. | ||
| expect(out).toBe('hi site <@U1> <#C1> :wave:\n\n'); | ||
| }); | ||
|
|
||
| it('renders link url when text is missing', () => { | ||
| const out = stripAnsi(renderBlocks([{ | ||
| type: 'rich_text', | ||
| elements: [{ | ||
| type: 'rich_text_section', | ||
| elements: [{ type: 'link', url: 'https://x' }], | ||
| }], | ||
| }], 0)); | ||
| expect(out).toBe('https://x\n\n'); | ||
| }); | ||
|
|
||
| it('renders rich_text_list as bullets', () => { | ||
| const out = stripAnsi(renderBlocks([{ | ||
| type: 'rich_text', | ||
| elements: [{ | ||
| type: 'rich_text_list', | ||
| elements: [ | ||
| { type: 'rich_text_section', elements: [{ type: 'text', text: 'one' }] }, | ||
| { type: 'rich_text_section', elements: [{ type: 'text', text: 'two' }] }, | ||
| ], | ||
| }], | ||
| }], 0)); | ||
| expect(out).toBe('• one\n• two\n\n'); | ||
| }); | ||
|
|
||
| it('renders rich_text_quote with leading >', () => { | ||
| const out = stripAnsi(renderBlocks([{ | ||
| type: 'rich_text', | ||
| elements: [{ | ||
| type: 'rich_text_quote', | ||
| elements: [{ type: 'rich_text_section', elements: [{ type: 'text', text: 'q' }] }], | ||
| }], | ||
| }], 0)); | ||
| expect(out).toBe('> q\n\n'); | ||
| }); | ||
|
|
||
| it('renders rich_text_preformatted as code fence', () => { | ||
| const out = stripAnsi(renderBlocks([{ | ||
| type: 'rich_text', | ||
| elements: [{ | ||
| type: 'rich_text_preformatted', | ||
| elements: [{ type: 'text', text: 'code' }], | ||
| }], | ||
| }], 0)); | ||
| expect(out).toBe('```\ncode\n```\n\n'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('renderAttachments', () => { | ||
| it('renders pretext, title, text, footer in order', () => { | ||
| const out = stripAnsi(renderAttachments([{ | ||
| pretext: 'P', | ||
| title: 'T', | ||
| text: 'body\nline2', | ||
| footer: 'F', | ||
| }], 0)); | ||
| expect(out).toBe('P\nT\nbody\nline2\nF\n'); | ||
| }); | ||
|
|
||
| it('appends title_link in parens after title', () => { | ||
| const out = stripAnsi(renderAttachments([{ title: 'T', title_link: 'https://x' }], 0)); | ||
| expect(out).toBe('T (https://x)\n'); | ||
| }); | ||
|
|
||
| it('renders fields with title: value and indents', () => { | ||
| const out = stripAnsi(renderAttachments([{ | ||
| fields: [ | ||
| { title: 'k', value: 'v' }, | ||
| { value: 'multi\nline' }, | ||
| { title: '', value: '' }, | ||
| ], | ||
| }], 0)); | ||
| expect(out).toBe(' k: v\n multi\n line\n'); | ||
| }); | ||
|
|
||
| it('renders nested blocks at indent+2', () => { | ||
| const out = stripAnsi(renderAttachments([{ | ||
| blocks: [{ type: 'header', text: { text: 'H' } }], | ||
| }], 0)); | ||
| expect(out).toBe(' H\n'); | ||
| }); | ||
|
|
||
| it('honours outer indent', () => { | ||
| const out = stripAnsi(renderAttachments([{ title: 'T' }], 4)); | ||
| expect(out).toBe(' T\n'); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.