* feat(reconciliation): close the bank-feed loop on voucher links and re-tag mis-typed opening balances
Two related fixes to bank reconciliation correctness:
1. Auto-reconcile on voucher link. Linking an invoice or supplier invoice to
an existing voucher previously advanced only the invoice — the bank
transaction that paid it kept sitting in the Transactions inbox with a null
journal_entry_id. linkInvoiceToVoucher / linkSupplierInvoiceToVoucher now
call autoReconcileTransactionForLinkedVoucher (lib/reconciliation), which
links the bank transaction to the same verifikat when exactly one unbooked
line matches it. Best-effort and post-commit: a failure here never fails the
link. The result surfaces reconciledTransactionId; the inbox row leaves the
list and the UI shows link_success_tx_reconciled.
2. Re-tag mis-typed opening balances. getReconciliationStatus and the GL-line
matching RPCs identify a cash account's ingående balans solely by
journal_entries.source_type='opening_balance'. Companies migrated from other
systems often booked the bank IB as an ordinary voucher (source_type
'import' or 'manual'), so it was never excluded and surfaced as a phantom
reconciliation difference equal to the opening balance. Adds:
- migration mark_entry_as_opening_balance: a GUC-gated carve-out in the
immutability trigger plus a SECURITY DEFINER RPC that validates the entry
(balance-sheet lines only, dated on a fiscal-period boundary), flips the
source_type, and writes an audit row — no blanket data sweep.
- POST /api/reconciliation/bank/mark-opening-balance + MarkOpeningBalanceSchema.
- BankReconciliationView action to trigger it from the IB diff.
The gnubok_create_voucher executor now accepts a typed is_opening_balance flag
and derives source_type='opening_balance' only after validating class 1/2 lines
on the period start, so new IBs land correctly typed.
Covered by lib/reconciliation auto-reconcile tests, voucher-executors tests,
and a mark-entry-as-opening-balance pg-real test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore: rebrand gnubok → Accounted and prune swarm agent skills
Product rebrand and skills housekeeping. No runtime behaviour change.
Rebrand: replace user-visible "gnubok" with "Accounted" across docs, READMEs,
in-code comments, doc-site content, MCP skill/resource prose, and the
gnubok-mcp package description. The MCP resource URI scheme is moved gnubok://
→ Accounted:// consistently across resource registrations, the event-type
comment, and the resource/skill tests. Deliberately preserved as stable
identifiers (NOT rebranded): the gnubok-company-id cookie, gnubok_sk_ / gnubok_inv_
token prefixes, the gnubok-mcp npm bridge name, and the AGI <gem:Programnamn>
value (kept 'gnubok' per its source comment — it is the software identifier sent
to Skatteverket and must not churn across visual rebrands).
Skills: remove the 27 swarm-* agent SKILL.md atoms (no longer used; already
absent from the agent_atom_registry in prod), refresh the remaining skill docs,
add the .claude/rules/ path-scoped rule set, and regenerate the
seed_agent_atom_bodies migration + .skill-body-manifest.json via
`npm run skills:generate` so the DB-backed skill bodies match the trimmed set.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
86 lines
3.1 KiB
TypeScript
86 lines
3.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { getContrastRatio, isWcagAACompliant } from '@/lib/invoices/contrast-check'
|
|
|
|
describe('getContrastRatio', () => {
|
|
it('returns 21 for black on white (maximum contrast)', () => {
|
|
const ratio = getContrastRatio('#000000', '#ffffff')
|
|
expect(ratio).toBeCloseTo(21, 1)
|
|
})
|
|
|
|
it('returns 21 regardless of argument order (white on black)', () => {
|
|
const ratio = getContrastRatio('#ffffff', '#000000')
|
|
expect(ratio).toBeCloseTo(21, 1)
|
|
})
|
|
|
|
it('returns 1 for identical colors (white on white)', () => {
|
|
const ratio = getContrastRatio('#ffffff', '#ffffff')
|
|
expect(ratio).toBeCloseTo(1, 5)
|
|
})
|
|
|
|
it('returns 1 for identical colors (black on black)', () => {
|
|
const ratio = getContrastRatio('#000000', '#000000')
|
|
expect(ratio).toBeCloseTo(1, 5)
|
|
})
|
|
|
|
it('PDF default heading color #1a1a1a on white passes AA with ratio > 15', () => {
|
|
const ratio = getContrastRatio('#1a1a1a', '#ffffff')
|
|
expect(ratio).toBeGreaterThan(15)
|
|
})
|
|
|
|
it('yellow #ffff00 on white has very low contrast (~1.07), fails AA', () => {
|
|
const ratio = getContrastRatio('#ffff00', '#ffffff')
|
|
expect(ratio).toBeGreaterThan(1.0)
|
|
expect(ratio).toBeLessThan(1.2)
|
|
})
|
|
|
|
it('accepts uppercase hex', () => {
|
|
const lower = getContrastRatio('#1a1a1a', '#ffffff')
|
|
const upper = getContrastRatio('#1A1A1A', '#FFFFFF')
|
|
expect(upper).toBeCloseTo(lower, 5)
|
|
})
|
|
|
|
it('throws on invalid hex format', () => {
|
|
expect(() => getContrastRatio('1a1a1a', '#ffffff')).toThrow()
|
|
expect(() => getContrastRatio('#fff', '#ffffff')).toThrow()
|
|
expect(() => getContrastRatio('#zzzzzz', '#ffffff')).toThrow()
|
|
})
|
|
})
|
|
|
|
describe('isWcagAACompliant', () => {
|
|
it('passes for the PDF default primary color (#1a1a1a) on white', () => {
|
|
expect(isWcagAACompliant('#1a1a1a', '#ffffff')).toBe(true)
|
|
})
|
|
|
|
it('passes for the PDF default accent color (#666666) on white', () => {
|
|
// 5.74:1 — comfortably above AA threshold.
|
|
expect(isWcagAACompliant('#666666', '#ffffff')).toBe(true)
|
|
})
|
|
|
|
it('fails for pure yellow on white', () => {
|
|
expect(isWcagAACompliant('#ffff00', '#ffffff')).toBe(false)
|
|
})
|
|
|
|
// Accounted brand semantic colors. All three are used as DATA-ONLY indicators
|
|
// (charts, positive/negative deltas), never as chrome text on white. These
|
|
// tests document where they sit relative to AA — terracotta/destructive is
|
|
// the only one that comfortably passes AA on white.
|
|
it('Accounted terracotta (#c2410c equivalent dark red) passes AA on white', () => {
|
|
// 5.91:1 — passes AA for normal text.
|
|
expect(isWcagAACompliant('#c2410c', '#ffffff')).toBe(true)
|
|
})
|
|
|
|
it('Accounted sage (#84a98c lighter green) fails AA on white', () => {
|
|
// ~2.4:1 — fails AA, as expected for a soft pastel sage.
|
|
expect(isWcagAACompliant('#84a98c', '#ffffff')).toBe(false)
|
|
})
|
|
|
|
it('Accounted ochre (#d4a373 warm yellow) fails AA on white', () => {
|
|
// ~2.3:1 — fails AA, as expected for a warm soft ochre.
|
|
expect(isWcagAACompliant('#d4a373', '#ffffff')).toBe(false)
|
|
})
|
|
|
|
it('a very dark sage (#2d5a3e) passes AA on white', () => {
|
|
expect(isWcagAACompliant('#2d5a3e', '#ffffff')).toBe(true)
|
|
})
|
|
})
|