forked from tiann/hapi
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(hub): dedupe channel SystemEvents on dedupe_key before INSERT #132
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
heavygee
wants to merge
4
commits into
feat/contrib-state-channel-ingest
Choose a base branch
from
fix/system-event-dedupe-key
base: feat/contrib-state-channel-ingest
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
4 commits
Select commit
Hold shift + click to select a range
15927f8
fix(hub): dedupe channel SystemEvents on dedupe_key before INSERT
heavygee 9d91e5a
fix(hub): scope channel event dedupe_key to request namespace
heavygee 3353ee0
fix(hub): migrate events.namespace before dedupe index DDL
heavygee 67f5547
fix(hub): backfill event namespace from related session on migrate
heavygee 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,63 @@ | ||
| import { describe, expect, it } from 'bun:test' | ||
| import { Database } from 'bun:sqlite' | ||
| import { ensureOverseerEventsSchema } from './events' | ||
|
|
||
| describe('ensureOverseerEventsSchema', () => { | ||
| it('migrates legacy events table that predates namespace column', () => { | ||
| const db = new Database(':memory:') | ||
| db.exec(` | ||
| CREATE TABLE events ( | ||
| id INTEGER PRIMARY KEY, | ||
| ts INTEGER NOT NULL, | ||
| source_kind TEXT NOT NULL, | ||
| source_ref TEXT, | ||
| sink_kind TEXT, | ||
| sink_ref TEXT, | ||
| event_type TEXT NOT NULL, | ||
| attention_candidate INTEGER NOT NULL DEFAULT 0, | ||
| operator_action_required INTEGER NOT NULL DEFAULT 0, | ||
| risk_detected INTEGER NOT NULL DEFAULT 0, | ||
| summary TEXT NOT NULL, | ||
| payload_json TEXT, | ||
| artifact_refs TEXT, | ||
| tags TEXT, | ||
| related_session_id TEXT, | ||
| related_event_id INTEGER, | ||
| dedupe_key TEXT, | ||
| expires_at INTEGER, | ||
| provenance TEXT, | ||
| idempotency_key TEXT, | ||
| confidence REAL, | ||
| severity INTEGER | ||
| ); | ||
| CREATE UNIQUE INDEX idx_events_dedupe_key ON events(dedupe_key) WHERE dedupe_key IS NOT NULL; | ||
| CREATE TABLE sessions ( | ||
| id TEXT PRIMARY KEY, | ||
| namespace TEXT NOT NULL DEFAULT 'default' | ||
| ); | ||
| INSERT INTO sessions (id, namespace) VALUES ('legacy-foreign-sess', 'other-ns'); | ||
| INSERT INTO events ( | ||
| ts, source_kind, event_type, attention_candidate, summary, | ||
| related_session_id, dedupe_key, provenance | ||
| ) VALUES ( | ||
| 1, 'channel', 'blocked', 1, 'legacy foreign event', | ||
| 'legacy-foreign-sess', 'contrib:tiann/hapi#1:blocked', 'test' | ||
| ); | ||
| `) | ||
|
|
||
| expect(() => ensureOverseerEventsSchema(db)).not.toThrow() | ||
|
|
||
| const row = db.prepare( | ||
| `SELECT namespace FROM events WHERE dedupe_key = 'contrib:tiann/hapi#1:blocked'` | ||
| ).get() as { namespace: string } | ||
| expect(row.namespace).toBe('other-ns') | ||
|
|
||
| const columns = db.prepare('PRAGMA table_info(events)').all() as Array<{ name: string }> | ||
| expect(columns.some((column) => column.name === 'namespace')).toBe(true) | ||
|
|
||
| const index = db.prepare( | ||
| `SELECT name FROM sqlite_master WHERE type = 'index' AND name = 'idx_events_namespace_dedupe_key'` | ||
| ).get() as { name: string } | null | ||
| expect(index?.name).toBe('idx_events_namespace_dedupe_key') | ||
| }) | ||
| }) |
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
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.