Files
accounted/extensions/general/mcp-server/__tests__/to-summary.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

56 lines
2.5 KiB
TypeScript

/**
* Unit tests for toSummary: trims the long, keyword-stuffed SKILL.md
* frontmatter descriptions into clean one-liners for gnubok_list_skills and
* gnubok_get_agent_briefing, so the client never truncates one mid-sentence.
*/
import { describe, it, expect } from 'vitest'
import { toSummary } from '../skills/atoms'
describe('toSummary', () => {
it('returns short input unchanged (idempotent)', () => {
const s = 'Swedish VAT compliance reference.'
expect(toSummary(s)).toBe(s)
expect(toSummary(toSummary(s))).toBe(s)
})
it('collapses internal whitespace', () => {
expect(toSummary('Foo bar\n\tbaz')).toBe('Foo bar baz')
})
it('prefers the first sentence when it ends within the cap', () => {
const s = 'Project accounting basics. ' + 'tail '.repeat(60) // well over the cap
expect(toSummary(s, 60)).toBe('Project accounting basics.')
})
it('cuts at a word boundary with an ellipsis when no sentence ends within the cap', () => {
const long = 'a '.repeat(300).trim() // 300 single-char words, no punctuation
const out = toSummary(long, 50)
expect(out.length).toBeLessThanOrEqual(51) // <= maxLen + ellipsis
expect(out.endsWith('…')).toBe(true)
expect(out).not.toMatch(/\s…$/) // trimmed before the ellipsis
expect(out.includes(' ')).toBe(false)
})
it('never cuts in the middle of a word', () => {
const s = 'alpha bravo charlie delta echo foxtrot golf hotel india juliet kilo lima'
const out = toSummary(s, 25)
const body = out.replace(/…$/, '').trim()
// every whitespace-delimited token in the output is a whole word from the input
const words = new Set(s.split(/\s+/))
for (const tok of body.split(/\s+/)) expect(words.has(tok)).toBe(true)
})
it('handles the real project-accounting description without a mid-word cut', () => {
const desc =
'Swedish project accounting (projektredovisning) covering dimensional tagging of bokföringsposter with project codes, WIP accounting (pågående arbeten), revenue recognition under K2 and K3 (successiv vinstavräkning, färdigställandemetoden), construction contracts (entreprenadavtal), BAS account patterns for project tracking (1470, 1620, 2420, 2450, 4970), SIE4 dimension encoding (#DIM 6, #OBJEKT, #TRANS object lists)'
const out = toSummary(desc)
expect(out.length).toBeLessThanOrEqual(201)
expect(out.endsWith('…')).toBe(true)
})
it('tolerates empty/blank input', () => {
expect(toSummary('')).toBe('')
expect(toSummary(' ')).toBe('')
})
})