Skip to content

test(conversation-store): 20 tests for sourceFromRole() + kindFromRole() + add --experimental-sqlite to test runner - #1214

Closed
bassilkhilo-ag2 wants to merge 1 commit into
sonichi:mainfrom
bassilkhilo-ag2:test/conversation-store-coverage
Closed

bassilkhilo-ag2 wants to merge 1 commit into
sonichi:mainfrom
bassilkhilo-ag2:test/conversation-store-coverage

Conversation

@bassilkhilo-ag2

Copy link
Copy Markdown
Collaborator

Summary

Adds 20 unit tests for the two pure routing helpers in src/conversation-store.ts, and updates the npm test runner to pass --experimental-sqlite so the test can import the module.

Why the flag is needed

conversation-store.ts imports DatabaseSync from 'node:sqlite' at the top level. In Node 22, node:sqlite is available but requires --experimental-sqlite; without the flag, the entire test suite fails at module load time with ERR_UNKNOWN_BUILTIN_MODULE. The flag does not affect any currently-passing tests.

Tests added (tests/conversation-store.test.ts, 20 tests)

sourceFromRole() (8 tests) — determines which SQLite surface a conversation record writes to:

  • phone-* prefix → 'phone'
  • discord-* prefix → 'discord-voice'
  • all other roles (including empty string, SESSION_END) → 'voice'

kindFromRole() (12 tests) — normalizes legacy role strings to the per-surface kind taxonomy:

  • 'user', *-user, *-caller → 'user'
  • 'assistant', 'sutando', *-agent, *-assistant → 'agent'
  • 'discord-peer' → 'peer'
  • Unknown event names (SESSION_END, health.degraded) → verbatim passthrough

All 20/20 pass. The SQLite DB is never opened — only pure functions are exercised.

…e() pure routing helpers

Guards the two exported pure functions that determine which SQLite surface
(voice / phone / discord-voice) and canonical kind (user / agent / peer)
a conversation record maps to:

sourceFromRole() (8 tests):
  - phone-* prefix → 'phone'
  - discord-* prefix → 'discord-voice'
  - all other roles → 'voice'
  - empty string and unknown events → 'voice'

kindFromRole() (12 tests):
  - 'user', *-user, *-caller → 'user'
  - 'assistant', 'sutando', *-agent, *-assistant → 'agent'
  - 'discord-peer' → 'peer'
  - SESSION_END, health.degraded and other events → verbatim passthrough

Also adds --experimental-sqlite to tsx test command (node:sqlite is
available in Node 22 but requires the flag; without it, the
conversation-store module fails to import at test-suite load time).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@VasiliyRad VasiliyRad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20 tests for sourceFromRole / kindFromRole; package.json adds --experimental-sqlite to the tsx test runner so DatabaseSync-using code can import cleanly. The test wisely only imports the two pure helpers to avoid module-init I/O.

Heads-up: this PR's package.json change to the test script line conflicts with #1207 (which extends test:py glob + adds test:sh). Whichever lands second will need a small rebase. Easy 3-way merge — both touch the same script entries with different intents.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants