-
Notifications
You must be signed in to change notification settings - Fork 283
Update hopsAway when packets are received #988
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -95,18 +95,43 @@ describe("NodeDB store", () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { useNodeDBStore } = await freshStore(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const db = useNodeDBStore.getState().addNodeDB(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| db.processPacket({ from: 50, time: 1111, snr: 7 } as any); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| db.processPacket({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from: 50, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| time: 1111, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| snr: 7, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hopStart: 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hopLimit: 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hasBitfield: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } as any); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(db.getNode(50)).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(db.getNode(50)?.lastHeard).toBe(1111); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(db.getNode(50)?.snr).toBe(7); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| db.processPacket({ from: 50, time: 2222, snr: 9 } as any); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(db.getNode(50)?.hopsAway).toBe(3); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| db.processPacket({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from: 50, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| time: 2222, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| snr: 9, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hopStart: 6, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hopLimit: 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hasBitfield: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } as any); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(db.getNode(50)?.lastHeard).toBe(2222); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(db.getNode(50)?.snr).toBe(9); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| db.processPacket({ from: 50, time: 0, snr: 9 } as any); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(db.getNode(50)?.hopsAway).toBe(3); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // when hopStart===0 and hasBitfield is false, hopsAway should be undefined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| db.processPacket({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from: 50, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| time: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| snr: 9, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hopStart: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hopLimit: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hasBitfield: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } as any); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(db.getNode(50)?.lastHeard).toBeCloseTo(Date.now() / 1000, -1); // within 1s, note lastHeard is in seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(db.getNode(50)?.lastHeard).toBeCloseTo(Date.now() / 1000, -1); // within 1s, note lastHeard is in seconds | |
| expect(db.getNode(50)?.lastHeard).toBeCloseTo(Date.now() / 1000, -1); // approximate current time in seconds, with broad tolerance |
Copilot
AI
Apr 24, 2026
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.
The new hopsAway disambiguation logic has a few key branches, but the test only covers the hopStart===0 && !hasBitfield (undefined) path. Please add assertions for at least: (1) hopStart===0 && hasBitfield===true (should yield hopsAway === 0), and (2) hopLimit > hopStart (should yield undefined).
| expect(db.getNode(50)?.hopsAway).toBeUndefined(); | |
| expect(db.getNode(50)?.hopsAway).toBeUndefined(); | |
| // when hopStart===0 and hasBitfield is true, hopsAway should be 0 | |
| db.processPacket({ | |
| from: 50, | |
| time: 3333, | |
| snr: 10, | |
| hopStart: 0, | |
| hopLimit: 0, | |
| hasBitfield: true, | |
| } as any); | |
| expect(db.getNode(50)?.lastHeard).toBe(3333); | |
| expect(db.getNode(50)?.snr).toBe(10); | |
| expect(db.getNode(50)?.hopsAway).toBe(0); | |
| // when hopLimit > hopStart, hopsAway should be undefined | |
| db.processPacket({ | |
| from: 50, | |
| time: 4444, | |
| snr: 11, | |
| hopStart: 1, | |
| hopLimit: 2, | |
| hasBitfield: true, | |
| } as any); | |
| expect(db.getNode(50)?.lastHeard).toBe(4444); | |
| expect(db.getNode(50)?.snr).toBe(11); | |
| expect(db.getNode(50)?.hopsAway).toBeUndefined(); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,9 @@ type ProcessPacketParams = { | |||||
| from: number; | ||||||
| snr: number; | ||||||
| time: number; | ||||||
| hopStart: number; | ||||||
| hopLimit: number; | ||||||
| hasBitfield: boolean; | ||||||
|
||||||
| hasBitfield: boolean; | |
| hasPayloadBitfield: boolean; |
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.
These
processPacket(...)calls now satisfyProcessPacketParams, so theas anycasts are no longer needed. Dropping them will keep the test type-safe and prevent accidentally omitting fields in future updates.