-
Notifications
You must be signed in to change notification settings - Fork 0
Add MCP review drafts #46
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,22 @@ | ||
| -- Draft transactions proposed through the MCP server remain pending until the | ||
| -- user explicitly confirms them in the Finance Manager UI. | ||
| ALTER TABLE transactions ADD COLUMN pending_kind TEXT NOT NULL DEFAULT 'upcoming' | ||
| CHECK (pending_kind IN ('upcoming', 'mcp_review')); | ||
| ALTER TABLE transactions ADD COLUMN review_source TEXT NOT NULL DEFAULT 'manual' | ||
| CHECK (review_source IN ('manual', 'chatgpt_mcp')); | ||
| ALTER TABLE transactions ADD COLUMN review_batch_id TEXT; | ||
| ALTER TABLE transactions ADD COLUMN review_flags TEXT NOT NULL DEFAULT '[]'; | ||
|
|
||
| -- The MCP server uses this small ledger to make batch creation idempotent. The | ||
| -- signed proposal token contains the proposal contents and expiry; only its | ||
| -- canonical hash needs to be retained here. | ||
| CREATE TABLE IF NOT EXISTS mcp_draft_batches ( | ||
| id TEXT PRIMARY KEY, | ||
| proposal_hash TEXT NOT NULL, | ||
| created_at INTEGER NOT NULL | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_transactions_status_pending_kind_date | ||
| ON transactions(status, pending_kind, date); | ||
| CREATE INDEX IF NOT EXISTS idx_transactions_review_batch_id | ||
| ON transactions(review_batch_id); |
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
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,127 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { TransactionMapper } from '../mappers/transaction.mapper' | ||
| import { TransactionRepository } from '../repositories/transaction.repository' | ||
|
|
||
| function createDb(rows: Record<string, unknown>[] = []) { | ||
| const calls: Array<{ sql: string; values: unknown[] }> = [] | ||
|
|
||
| const db = { | ||
| prepare: vi.fn((sql: string) => { | ||
| const statement = { | ||
| values: [] as unknown[], | ||
| bind(...values: unknown[]) { | ||
| this.values = values | ||
| calls.push({ sql, values }) | ||
| return this | ||
| }, | ||
| async all<T>() { | ||
| return { results: rows as T[] } | ||
| }, | ||
| async first<T>() { | ||
| return (rows[0] as T | undefined) || null | ||
| }, | ||
| async run() { | ||
| return { meta: { changes: 1 } } | ||
| }, | ||
| } | ||
| return statement | ||
| }), | ||
| } | ||
|
|
||
| return { db: db as unknown as D1Database, calls } | ||
| } | ||
|
|
||
| describe('transaction review metadata', () => { | ||
| it('maps persisted MCP metadata and parses review flags', async () => { | ||
| const { db } = createDb([{ | ||
| id: 'tx-1', | ||
| account_id: 'account-1', | ||
| category_id: null, | ||
| amount: -250, | ||
| description: 'Market', | ||
| date: '2026-08-03', | ||
| linked_transaction_id: null, | ||
| exclude_from_estimate: 0, | ||
| status: 'pending', | ||
| pending_kind: 'mcp_review', | ||
| review_source: 'chatgpt_mcp', | ||
| review_batch_id: 'batch-1', | ||
| review_flags: '["possible_duplicate"]', | ||
| }]) | ||
|
|
||
| const transactions = await new TransactionRepository(db).findUpcoming() | ||
|
|
||
| expect(transactions[0]).toMatchObject({ | ||
| pending_kind: 'mcp_review', | ||
| review_source: 'chatgpt_mcp', | ||
| review_batch_id: 'batch-1', | ||
| review_flags: ['possible_duplicate'], | ||
| }) | ||
| }) | ||
|
|
||
| it('uses safe metadata defaults for legacy rows and malformed flags', async () => { | ||
| const { db } = createDb([{ | ||
| id: 'tx-1', | ||
| account_id: 'account-1', | ||
| amount: 250, | ||
| date: '2026-08-03', | ||
| exclude_from_estimate: 0, | ||
| status: 'pending', | ||
| review_flags: '{"not":"an-array"}', | ||
| }]) | ||
|
|
||
| const transaction = await new TransactionRepository(db).findById('tx-1') | ||
|
|
||
| expect(transaction).toMatchObject({ | ||
| pending_kind: 'upcoming', | ||
| review_source: 'manual', | ||
| review_flags: [], | ||
| }) | ||
| }) | ||
|
|
||
| it('persists normalized metadata for repository-created transactions', async () => { | ||
| const { db, calls } = createDb() | ||
| const repository = new TransactionRepository(db) | ||
|
|
||
| await repository.create({ | ||
| id: 'tx-1', | ||
| account_id: 'account-1', | ||
| amount: -250, | ||
| date: '2026-08-03', | ||
| status: 'pending', | ||
| pending_kind: 'mcp_review', | ||
| review_source: 'chatgpt_mcp', | ||
| review_batch_id: 'batch-1', | ||
| review_flags: ['possible_duplicate'], | ||
| }) | ||
|
|
||
| expect(calls[0].values.slice(8, 13)).toEqual([ | ||
| 'pending', | ||
| 'mcp_review', | ||
| 'chatgpt_mcp', | ||
| 'batch-1', | ||
| '["possible_duplicate"]', | ||
| ]) | ||
| }) | ||
|
|
||
| it('exposes normalized review metadata in API response DTOs', () => { | ||
| const response = TransactionMapper.toResponseDto({ | ||
| id: 'tx-1', | ||
| account_id: 'account-1', | ||
| amount: -250, | ||
| date: '2026-08-03', | ||
| status: 'pending', | ||
| pending_kind: 'mcp_review', | ||
| review_source: 'chatgpt_mcp', | ||
| review_batch_id: 'batch-1', | ||
| review_flags: ['possible_duplicate'], | ||
| }) | ||
|
|
||
| expect(response).toMatchObject({ | ||
| pending_kind: 'mcp_review', | ||
| review_source: 'chatgpt_mcp', | ||
| review_batch_id: 'batch-1', | ||
| review_flags: ['possible_duplicate'], | ||
| }) | ||
| }) | ||
| }) |
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.
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.