-
Notifications
You must be signed in to change notification settings - Fork 20
feat(linkedin): home_feed via content-script scrape #1151
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import { beforeAll, describe, expect, mock, test } from 'bun:test'; | ||
|
|
||
| // linkedin.ts imports ConnectorRuntime / calculateEngagementScore / | ||
| // extensionNetworkSync from @lobu/connector-sdk, which pulls in playwright. | ||
| // Stub the SDK so the connector can be imported + instantiated without the | ||
| // real browser stack. ConnectorRuntime is a no-op base class here; the | ||
| // home-feed path only needs the dispatcher we pass in. | ||
| mock.module('@lobu/connector-sdk', () => ({ | ||
| ConnectorRuntime: class {}, | ||
| calculateEngagementScore: () => 0, | ||
| extensionNetworkSync: () => { | ||
| throw new Error('not used in home_feed unit tests'); | ||
| }, | ||
| })); | ||
|
|
||
| // biome-ignore lint/suspicious/noExplicitAny: dynamic import after mock | ||
| let LinkedInConnector: any; | ||
| // biome-ignore lint/suspicious/noExplicitAny: dynamic import after mock | ||
| let buildHomeFeedEvents: any; | ||
|
|
||
| beforeAll(async () => { | ||
| const mod = await import('../linkedin'); | ||
| LinkedInConnector = mod.default; | ||
| buildHomeFeedEvents = mod.buildHomeFeedEvents; | ||
| }); | ||
|
|
||
| describe('buildHomeFeedEvents', () => { | ||
| test('maps a token-id row to li_home_<token> with /feed/ source_url', () => { | ||
| const occurredAt = new Date('2026-05-29T12:00:00.000Z'); | ||
| const events = buildHomeFeedEvents( | ||
| [{ id: 'aBc123_token', body: 'Hello from the home feed', author: 'Jane Doe' }], | ||
| occurredAt | ||
| ); | ||
|
|
||
| expect(events).toHaveLength(1); | ||
| const [ev] = events; | ||
| expect(ev.origin_id).toBe('li_home_aBc123_token'); | ||
| expect(ev.payload_text).toBe('Hello from the home feed'); | ||
| expect(ev.author_name).toBe('Jane Doe'); | ||
| expect(ev.origin_type).toBe('post'); | ||
| // Token id is NOT numeric → no urn:li:activity permalink, link to /feed/. | ||
| expect(ev.source_url).toBe('https://www.linkedin.com/feed/'); | ||
| expect(ev.occurred_at).toBe(occurredAt); | ||
| expect(ev.metadata).toEqual({ author: 'Jane Doe' }); | ||
| }); | ||
|
|
||
| test('defaults author to empty string when missing', () => { | ||
| const [ev] = buildHomeFeedEvents([{ id: 'tok', body: 'body only' }], new Date()); | ||
| expect(ev.author_name).toBe(''); | ||
| expect(ev.metadata).toEqual({ author: '' }); | ||
| }); | ||
|
|
||
| test('drops rows without id or body and dedupes by id', () => { | ||
| const events = buildHomeFeedEvents( | ||
| [ | ||
| { id: 'a', body: 'first' }, | ||
| { id: '', body: 'no id' }, | ||
| { id: 'b' }, // no body | ||
| { id: 'a', body: 'dup id' }, | ||
| ], | ||
| new Date() | ||
| ); | ||
| expect(events.map((e: { origin_id: string }) => e.origin_id)).toEqual(['li_home_a']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('LinkedInConnector home_feed', () => { | ||
| test('declares a home_feed feed with no required company_url', () => { | ||
| const def = new LinkedInConnector().definition; | ||
| expect(def.feeds.home_feed).toBeDefined(); | ||
| expect(def.feeds.home_feed.configSchema.required).toBeUndefined(); | ||
| }); | ||
|
|
||
| test('syncHomeFeed dispatches cs_scrape and maps rows to events', async () => { | ||
| const calls: Array<{ action: string; input: Record<string, unknown> }> = []; | ||
| const dispatcher = { | ||
| dispatch: async (action: string, input: Record<string, unknown>) => { | ||
| calls.push({ action, input }); | ||
| return { | ||
| tab_id: 1, | ||
| cs_scrape: true, | ||
| result: { | ||
| loggedIn: true, | ||
| rows: [ | ||
| { id: 'tok1', body: 'post one', author: 'Alice' }, | ||
| { id: 'tok2', body: 'post two', author: 'Bob' }, | ||
| ], | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
|
|
||
| const connector = new LinkedInConnector(); | ||
| const ctx = { | ||
| feedKey: 'home_feed', | ||
| config: { max_scrolls: 4 }, | ||
| checkpoint: {}, | ||
| sessionState: { chrome_dispatcher: dispatcher }, | ||
| }; | ||
| const res = await connector.sync(ctx); | ||
|
|
||
| // Dispatched a cs_scrape navigate against /feed/ with the home-feed config. | ||
| expect(calls).toHaveLength(1); | ||
| expect(calls[0].action).toBe('navigate'); | ||
| expect(calls[0].input.cs_scrape).toBe(true); | ||
| expect(calls[0].input.persistent).toBe(true); | ||
| expect(calls[0].input.url).toBe('https://www.linkedin.com/feed/'); | ||
| expect((calls[0].input.scrape_config as { scroll: { max: number } }).scroll.max).toBe(4); | ||
|
|
||
| expect(res.events).toHaveLength(2); | ||
| expect(res.events[0].origin_id).toBe('li_home_tok1'); | ||
| expect(res.events[1].origin_id).toBe('li_home_tok2'); | ||
| expect(res.metadata.backend).toBe('extension-cs-scrape'); | ||
| }); | ||
|
|
||
| test('throws a clear error when not logged into LinkedIn', async () => { | ||
| const dispatcher = { | ||
| dispatch: async () => ({ result: { loggedIn: false, rows: [] } }), | ||
| }; | ||
| const connector = new LinkedInConnector(); | ||
| const ctx = { | ||
| feedKey: 'home_feed', | ||
| config: {}, | ||
| checkpoint: {}, | ||
| sessionState: { chrome_dispatcher: dispatcher }, | ||
| }; | ||
| await expect(connector.sync(ctx)).rejects.toThrow(/Not logged into LinkedIn/); | ||
| }); | ||
| }); |
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
Submodule owletto
updated
from ab5064 to 1f1c02
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.
Persist a home-feed cursor instead of passing the old checkpoint through.
Line 515 returns the incoming checkpoint unchanged even though
buildHomeFeedEvents()only dedupes within one scrape and every emitted event gets a fresh sync-timeoccurred_at. If LinkedIn keeps the same posts visible across runs, this path will emit them again on every sync. Store a bounded set of seen home-feed ids (or another stable cursor) and filter before returning events.🤖 Prompt for AI Agents