Files
accounted/extensions/general/mcp-server/__tests__/qualified-ids.test.ts
T
Jakob WennbergandClaude Sonnet 5 ec27228a8e style: remove em/en dashes repo-wide, add CLAUDE.md rule against them (#890)
Em dashes (—) and en dashes (–) had spread across comments, docs, tests,
and a few UI strings, reading as AI-generated boilerplate rather than
house style. Replaced each with punctuation matching its context: colon
for explanatory clauses, comma for asides, plain hyphen for numeric/legal
ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for
paired-dash asides. messages/en.json and messages/sv.json were fixed by
hand together to keep sv/en in sync.

Left untouched where the dash is the functional subject rather than
decorative punctuation: date-range-parser.ts's separator regex,
charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE
encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the
agent system-prompt files that already instruct against em dashes, and
a golden iXBRL test fixture compared byte-for-byte.

Also fixes two bugs surfaced along the way: an off-by-one in
ApiKeysPanel's scope-label split (a leftover from an earlier partial
pass), and a charset-repair test that had lost the literal en-dash it
exists to verify.

Regenerated the agent atom seed migration (skills:generate) since 27
SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes,
with an explicit carve-out for the functional-dash cases above.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-04 15:58:06 +02:00

85 lines
3.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { tools } from '../server'
/**
* Identifier discipline (mcp_optimization_plan P1-2): agents grabbed the
* wrong id when list rows exposed a bare `id` next to qualified ids like
* `journal_entry_id` with no type distinction, got NOT_FOUND, and had to
* re-derive. Every identifier in a tool OUTPUT schema must be fully
* qualified (`transaction_id`, `journal_entry_id`, `fact_id`, …).
*
* Bare `id` survives only as a deprecated alias at the GRANDFATHERED paths
* below, each shipping alongside its qualified sibling. This list may only
* SHRINK (remove entries as the deprecated aliases are dropped): a new bare
* `id` anywhere fails this test; add the qualified name instead.
*/
const GRANDFATHERED_BARE_ID_PATHS = [
'gnubok_forget_fact',
'gnubok_get_agent_briefing.atoms[]',
'gnubok_get_agent_briefing.company',
'gnubok_get_agent_briefing.memory[]',
'gnubok_list_dimension_values.dimension',
'gnubok_list_dimension_values.values[]',
'gnubok_list_dimensions.dimensions[]',
'gnubok_list_dimensions.dimensions[].values[]',
'gnubok_list_transactions_without_documents.transactions[]',
'gnubok_list_uncategorized_transactions.transactions[]',
'gnubok_remember_fact',
].sort()
type SchemaNode = {
properties?: Record<string, unknown>
items?: unknown
}
function collectBareIdPaths(): { path: string; siblingKeys: string[] }[] {
const found: { path: string; siblingKeys: string[] }[] = []
const walk = (schema: unknown, path: string) => {
if (!schema || typeof schema !== 'object') return
const s = schema as SchemaNode
if (s.properties) {
const keys = Object.keys(s.properties)
if (keys.includes('id')) found.push({ path, siblingKeys: keys })
for (const [key, val] of Object.entries(s.properties)) walk(val, `${path}.${key}`)
}
if (s.items) walk(s.items, `${path}[]`)
}
for (const t of tools) walk(t.outputSchema, t.name)
return found
}
describe('qualified identifiers in tool output schemas', () => {
it('no tool exposes a bare `id` outside the shrinking grandfathered list', () => {
const actual = collectBareIdPaths()
.map((f) => f.path)
.sort()
const newOffenders = actual.filter((p) => !GRANDFATHERED_BARE_ID_PATHS.includes(p))
expect(
newOffenders,
`New bare \`id\` in an output schema: use a qualified name (transaction_id, journal_entry_id, …) instead:\n${newOffenders.join('\n')}`,
).toEqual([])
})
it('every remaining bare `id` ships alongside its qualified sibling', () => {
const missingSibling = collectBareIdPaths().filter(
(f) => !f.siblingKeys.some((k) => k !== 'id' && k.endsWith('_id')),
)
expect(
missingSibling.map((f) => f.path),
'bare `id` without a qualified *_id sibling: agents cannot migrate off the deprecated alias',
).toEqual([])
})
it('the grandfathered list only shrinks (entries removed when aliases are dropped)', () => {
const actual = collectBareIdPaths()
.map((f) => f.path)
.sort()
const stale = GRANDFATHERED_BARE_ID_PATHS.filter((p) => !actual.includes(p))
expect(
stale,
`Grandfathered paths no longer exist: remove them from GRANDFATHERED_BARE_ID_PATHS:\n${stale.join('\n')}`,
).toEqual([])
})
})