docs(production): standardiserad produktionsberedskap och gap-analys

Lägger docs/production-readiness.md och siax/production-gaps.json enligt SIAX Master Definition of Done. Underlag: git-, kod- och live-evidens 2026-11-11. Nivån är evidensbaserad, inte ett leveransgodkännande.
This commit is contained in:
2026-11-10 09:15:21 +01:00
parent 0fda8cae48
commit 2bee8eb778
6135 changed files with 4 additions and 1718997 deletions
@@ -1,133 +0,0 @@
import { describe, it, expect } from 'vitest'
import {
computeNeighbors,
listContextKey,
readListContext,
writeListContext,
type ListContext,
} from '@/lib/navigation/list-context'
function makeStorage(initial: Record<string, string> = {}) {
const map = new Map<string, string>(Object.entries(initial))
return {
getItem: (key: string) => map.get(key) ?? null,
setItem: (key: string, value: string) => {
map.set(key, value)
},
}
}
describe('listContextKey', () => {
it('builds a company-scoped key', () => {
expect(listContextKey('invoices', 'c-1')).toBe('Accounted:list-context:invoices:c-1')
})
it('falls back to default when no company id exists', () => {
expect(listContextKey('invoices', null)).toBe('Accounted:list-context:invoices:default')
expect(listContextKey('invoices', undefined)).toBe('Accounted:list-context:invoices:default')
})
})
describe('writeListContext / readListContext', () => {
it('round-trips a context', () => {
const storage = makeStorage()
const context: ListContext = { ids: ['a', 'b', 'c'] }
writeListContext('key', context, storage)
expect(readListContext('key', storage)).toEqual(context)
})
it('returns null when nothing was written', () => {
expect(readListContext('missing', makeStorage())).toBeNull()
})
it('returns null on garbage JSON', () => {
const storage = makeStorage({ key: '{not json' })
expect(readListContext('key', storage)).toBeNull()
})
it('returns null on valid JSON with the wrong shape', () => {
expect(readListContext('key', makeStorage({ key: '"a string"' }))).toBeNull()
expect(readListContext('key', makeStorage({ key: 'null' }))).toBeNull()
expect(readListContext('key', makeStorage({ key: '{"ids":"nope"}' }))).toBeNull()
expect(readListContext('key', makeStorage({ key: '{"ids":["a",1]}' }))).toBeNull()
expect(readListContext('key', makeStorage({ key: '{"other":["a"]}' }))).toBeNull()
})
it('tolerates extra properties, so contexts stored by older builds still parse', () => {
// Older builds wrote a listPath field alongside ids.
const stored = makeStorage({ key: '{"ids":["a","b"],"listPath":"/invoices"}' })
expect(readListContext('key', stored)).toEqual({ ids: ['a', 'b'] })
})
it('keeps keys isolated from each other', () => {
const storage = makeStorage()
writeListContext(listContextKey('invoices', 'c-1'), { ids: ['inv-1'] }, storage)
writeListContext(listContextKey('supplier-invoices', 'c-1'), { ids: ['sup-1'] }, storage)
writeListContext(listContextKey('invoices', 'c-2'), { ids: ['inv-9'] }, storage)
expect(readListContext(listContextKey('invoices', 'c-1'), storage)?.ids).toEqual(['inv-1'])
expect(readListContext(listContextKey('supplier-invoices', 'c-1'), storage)?.ids).toEqual([
'sup-1',
])
expect(readListContext(listContextKey('invoices', 'c-2'), storage)?.ids).toEqual(['inv-9'])
})
it('does not throw when storage is unavailable', () => {
expect(() => writeListContext('key', { ids: [] }, null)).not.toThrow()
expect(readListContext('key', null)).toBeNull()
})
it('swallows setItem failures (quota exceeded)', () => {
const storage = {
getItem: () => null,
setItem: () => {
throw new Error('QuotaExceededError')
},
}
expect(() => writeListContext('key', { ids: ['a'] }, storage)).not.toThrow()
})
})
describe('computeNeighbors', () => {
const ids = ['a', 'b', 'c', 'd']
it('finds both neighbors in the middle of the list', () => {
expect(computeNeighbors(ids, 'b')).toEqual({
prevId: 'a',
nextId: 'c',
index: 2,
total: 4,
})
})
it('has no prev at the start', () => {
expect(computeNeighbors(ids, 'a')).toEqual({
prevId: null,
nextId: 'b',
index: 1,
total: 4,
})
})
it('has no next at the end', () => {
expect(computeNeighbors(ids, 'd')).toEqual({
prevId: 'c',
nextId: null,
index: 4,
total: 4,
})
})
it('handles a single-record list', () => {
expect(computeNeighbors(['only'], 'only')).toEqual({
prevId: null,
nextId: null,
index: 1,
total: 1,
})
})
it('returns null when the record is not in the context (stale/foreign context)', () => {
expect(computeNeighbors(ids, 'zzz')).toBeNull()
expect(computeNeighbors([], 'a')).toBeNull()
})
})
-97
View File
@@ -1,97 +0,0 @@
/**
* Session-scoped list context for prev/next record navigation on detail pages.
*
* List pages write the full ordered id array (post filter/sort, not just the
* visible slice) when the user navigates into a record; the detail page reads
* it back to offer "bladdra" between records without returning to the list.
*
* sessionStorage on purpose: the context is a per-tab browsing session. A deep
* link or a new tab has no context and the pager simply does not render.
* Client-side lists sort with rules that are not expressible server-side
* (e.g. lib/invoices/invoice-list-sort.ts uses an sv Intl.Collator with
* display fallbacks), so the id order must be captured where it was computed.
*/
export interface ListContext {
/** Ordered record ids exactly as the list presented them. */
ids: string[]
}
export interface ListNeighbors {
prevId: string | null
nextId: string | null
/** 1-based position of the current record, for "n av m" display. */
index: number
total: number
}
type StorageLike = Pick<Storage, 'getItem' | 'setItem'>
function defaultStorage(): StorageLike | null {
// Guarded twice: window is absent during SSR, and accessing sessionStorage
// itself can throw (disabled storage / strict privacy modes).
try {
if (typeof window === 'undefined') return null
return window.sessionStorage
} catch {
return null
}
}
/** Builds the per-company storage key, e.g. 'Accounted:list-context:invoices:<companyId>'. */
export function listContextKey(scope: string, companyId: string | null | undefined): string {
return `Accounted:list-context:${scope}:${companyId ?? 'default'}`
}
export function writeListContext(
key: string,
context: ListContext,
storage: StorageLike | null = defaultStorage(),
): void {
if (!storage) return
try {
storage.setItem(key, JSON.stringify(context))
} catch {
// Quota exceeded or storage blocked: the pager just won't appear on the
// detail page. Row navigation itself must never fail on this.
}
}
export function readListContext(
key: string,
storage: StorageLike | null = defaultStorage(),
): ListContext | null {
if (!storage) return null
try {
const raw = storage.getItem(key)
if (!raw) return null
const parsed: unknown = JSON.parse(raw)
if (typeof parsed !== 'object' || parsed === null) return null
const candidate = parsed as { ids?: unknown }
if (!Array.isArray(candidate.ids)) return null
if (candidate.ids.some((id) => typeof id !== 'string')) return null
// Deliberately tolerant of extra properties (e.g. the listPath field
// older builds wrote): only ids is consumed, and previously stored
// contexts must keep parsing.
return { ids: candidate.ids as string[] }
} catch {
// Garbage in storage (manual edits, older shapes): behave as no context.
return null
}
}
/**
* Pure neighbor computation for the detail pager. Returns null when the
* current record is not part of the context (stale context after a delete,
* or a context written from another list).
*/
export function computeNeighbors(ids: string[], currentId: string): ListNeighbors | null {
const position = ids.indexOf(currentId)
if (position === -1) return null
return {
prevId: position > 0 ? ids[position - 1] : null,
nextId: position < ids.length - 1 ? ids[position + 1] : null,
index: position + 1,
total: ids.length,
}
}