-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from dcSpark/fix-is-local-message
- fix: refactor isLocalMessage to generalize use cases
- Loading branch information
Showing
9 changed files
with
562 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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,45 @@ | ||
name: PR CI Health checks | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
defaults: | ||
run: | ||
working-directory: ./ | ||
|
||
jobs: | ||
health-checks: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
max-parallel: 1 | ||
matrix: | ||
target: ['lint', 'build', 'test'] | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Use nx set shas | ||
uses: nrwl/nx-set-shas@v3 | ||
|
||
|
||
- name: Setup Node version | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
check-latest: false | ||
registry-url: https://registry.npmjs.org | ||
cache: "npm" | ||
cache-dependency-path: package-lock.json | ||
|
||
- name: Install dependencies | ||
run: | | ||
npm cache verify | ||
npm ci --no-audit --prefer-offline | ||
- name: Run NX target ${{ matrix.target }} on affected projects | ||
run: npx nx affected -t ${{ matrix.target }} --parallel=3 --skip-nx-cache --verbose |
147 changes: 147 additions & 0 deletions
147
libs/shinkai-message-ts/src/utils/shinkai_message_handler.test.ts
This file contains 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,147 @@ | ||
import { isLocalMessage } from './shinkai_message_handler'; | ||
|
||
describe('shinkai_messag_handler isLocalMessage', () => { | ||
const messageSentByNode1MainDevice = `{ | ||
"body": { | ||
"unencrypted": { | ||
"message_data": { | ||
"unencrypted": { | ||
"message_raw_content": "hey!", | ||
"message_content_schema": "TextContent" | ||
} | ||
}, | ||
"internal_metadata": { | ||
"sender_subidentity": "main/device/main_device", | ||
"recipient_subidentity": "", | ||
"inbox": "inbox::@@node1.shinkai/main/device/main_device::@@node2.shinkai::false", | ||
"signature": "", | ||
"encryption": "None" | ||
} | ||
} | ||
}, | ||
"external_metadata": { | ||
"sender": "@@node1.shinkai", | ||
"recipient": "@@node2.shinkai", | ||
"scheduled_time": "2023-08-25T22:44:01.132Z", | ||
"signature": "c6d0115c0878fbf2279f98aab67c0e9cb1af63825f49dca48d6e4420eba0ceb973e00488ba0905c9afd09254f0dac48c468fdcb1d6c5ab5ca4c5dd70a440b903", | ||
"other": "" | ||
}, | ||
"encryption": "None", | ||
"version": "V1_0" | ||
}`; | ||
|
||
const messageSentByNode1SecondaryDevice = `{ | ||
"body": { | ||
"unencrypted": { | ||
"message_data": { | ||
"unencrypted": { | ||
"message_raw_content": "hey!", | ||
"message_content_schema": "TextContent" | ||
} | ||
}, | ||
"internal_metadata": { | ||
"sender_subidentity": "main/device/secondary_device", | ||
"recipient_subidentity": "", | ||
"inbox": "inbox::@@node1.shinkai/main/device/secondary_device::@@node2.shinkai::false", | ||
"signature": "", | ||
"encryption": "None" | ||
} | ||
} | ||
}, | ||
"external_metadata": { | ||
"sender": "@@node1.shinkai", | ||
"recipient": "@@node2.shinkai", | ||
"scheduled_time": "2023-08-25T22:44:01.132Z", | ||
"signature": "c6d0115c0878fbf2279f98aab67c0e9cb1af63825f49dca48d6e4420eba0ceb973e00488ba0905c9afd09254f0dac48c468fdcb1d6c5ab5ca4c5dd70a440b903", | ||
"other": "" | ||
}, | ||
"encryption": "None", | ||
"version": "V1_0" | ||
}`; | ||
|
||
const messageSentByNode1AgentGpt = `{ | ||
"body": { | ||
"unencrypted": { | ||
"message_data": { | ||
"unencrypted": { | ||
"message_raw_content": "hey!", | ||
"message_content_schema": "TextContent" | ||
} | ||
}, | ||
"internal_metadata": { | ||
"sender_subidentity": "main/agent/gpt", | ||
"recipient_subidentity": "", | ||
"inbox": "job_inbox::@@node1.shinkai/main/agent/gpt::@@node2.shinkai::false", | ||
"signature": "", | ||
"encryption": "None" | ||
} | ||
} | ||
}, | ||
"external_metadata": { | ||
"sender": "@@node1.shinkai", | ||
"recipient": "@@node2.shinkai", | ||
"scheduled_time": "2023-08-25T22:44:01.132Z", | ||
"signature": "c6d0115c0878fbf2279f98aab67c0e9cb1af63825f49dca48d6e4420eba0ceb973e00488ba0905c9afd09254f0dac48c468fdcb1d6c5ab5ca4c5dd70a440b903", | ||
"other": "" | ||
}, | ||
"encryption": "None", | ||
"version": "V1_0" | ||
}`; | ||
|
||
const messageSentByNode2MainDevice = `{ | ||
"body": { | ||
"unencrypted": { | ||
"message_data": { | ||
"unencrypted": { | ||
"message_raw_content": "hey!", | ||
"message_content_schema": "TextContent" | ||
} | ||
}, | ||
"internal_metadata": { | ||
"sender_subidentity": "main/device/main_device", | ||
"recipient_subidentity": "", | ||
"inbox": "inbox::@@node2.shinkai/main/device/main_device::@@node1.shinkai::false", | ||
"signature": "", | ||
"encryption": "None" | ||
} | ||
} | ||
}, | ||
"external_metadata": { | ||
"sender": "@@node2.shinkai", | ||
"recipient": "@@node1.shinkai", | ||
"scheduled_time": "2023-08-25T22:44:01.132Z", | ||
"signature": "c6d0115c0878fbf2279f98aab67c0e9cb1af63825f49dca48d6e4420eba0ceb973e00488ba0905c9afd09254f0dac48c468fdcb1d6c5ab5ca4c5dd70a440b903", | ||
"other": "" | ||
}, | ||
"encryption": "None", | ||
"version": "V1_0" | ||
}`; | ||
|
||
const myNodeSetup = { | ||
myNodeIdentity: '@@node1.shinkai', | ||
myProfile: 'main', | ||
}; | ||
it('false when message was sent by agent', () => { | ||
const message = JSON.parse(messageSentByNode1AgentGpt); | ||
const isLocal = isLocalMessage(message, myNodeSetup.myNodeIdentity, myNodeSetup.myProfile); | ||
expect(isLocal).toBe(false); | ||
}); | ||
|
||
it('false when message was sent by a different node', () => { | ||
const message = JSON.parse(messageSentByNode2MainDevice); | ||
const isLocal = isLocalMessage(message, myNodeSetup.myNodeIdentity, myNodeSetup.myProfile); | ||
expect(isLocal).toBe(false); | ||
}); | ||
|
||
it('true when message was sent by same node', () => { | ||
const message = JSON.parse(messageSentByNode1MainDevice); | ||
const isLocal = isLocalMessage(message, myNodeSetup.myNodeIdentity, myNodeSetup.myProfile); | ||
expect(isLocal).toBe(true); | ||
}); | ||
|
||
it('true when message was sent by same node but different device', () => { | ||
const message = JSON.parse(messageSentByNode1SecondaryDevice); | ||
const isLocal = isLocalMessage(message, myNodeSetup.myNodeIdentity, myNodeSetup.myProfile); | ||
expect(isLocal).toBe(true); | ||
}); | ||
}); |
This file contains 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 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 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 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.