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>
83 lines
2.9 KiB
TypeScript
83 lines
2.9 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { fallbackNarrative } from '../fallback'
|
|
import type { ComposerInputs } from '../inputs'
|
|
|
|
// The agent profile narrative has two voices depending on whether the user
|
|
// is a verified director at the company:
|
|
//
|
|
// - confirmed director → "Du driver Coredination AB..."
|
|
// - everyone else → "Coredination AB är..."
|
|
//
|
|
// The Sonnet path injects this via the system prompt (covered manually in
|
|
// system-prompt eval), so these tests target the deterministic fallback:
|
|
// which is what ships when Sonnet times out or the API key is missing.
|
|
// The fallback is the worst-case render and must never put presumptive
|
|
// ownership words in a non-director user's mouth.
|
|
|
|
function makeInputs(overrides: Partial<ComposerInputs>): ComposerInputs {
|
|
return {
|
|
companyId: 'co-1',
|
|
companyName: 'Coredination AB',
|
|
entityType: 'aktiebolag',
|
|
ticSnapshot: null,
|
|
ticFetchedAt: null,
|
|
companySettings: null,
|
|
sieSummary: null,
|
|
bankingSummary: null,
|
|
atomIndex: [],
|
|
userIsConfirmedDirector: false,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
describe('fallbackNarrative voice branching', () => {
|
|
it('uses second-person "Du driver" when user is a confirmed director', () => {
|
|
const text = fallbackNarrative(makeInputs({ userIsConfirmedDirector: true }))
|
|
expect(text).toMatch(/Du driver Coredination AB som aktiebolag\./)
|
|
expect(text).toMatch(/din verksamhet/i)
|
|
})
|
|
|
|
it('uses neutral third-person when user is NOT a confirmed director', () => {
|
|
const text = fallbackNarrative(makeInputs({ userIsConfirmedDirector: false }))
|
|
expect(text).toMatch(/Coredination AB är ett aktiebolag\./)
|
|
// Critical: must not assume the user owns or runs the company.
|
|
expect(text).not.toMatch(/\bDu driver\b/)
|
|
expect(text).not.toMatch(/\bdin verksamhet\b/i)
|
|
})
|
|
|
|
it('keeps neutral voice for enskild firma when not confirmed', () => {
|
|
const text = fallbackNarrative(
|
|
makeInputs({
|
|
entityType: 'enskild_firma',
|
|
companyName: 'Anna Andersson',
|
|
userIsConfirmedDirector: false,
|
|
}),
|
|
)
|
|
expect(text).toMatch(/Anna Andersson är en enskild firma\./)
|
|
expect(text).not.toMatch(/Du driver/)
|
|
})
|
|
|
|
it('uses second-person for enskild firma when director is confirmed', () => {
|
|
const text = fallbackNarrative(
|
|
makeInputs({
|
|
entityType: 'enskild_firma',
|
|
companyName: 'Anna Andersson',
|
|
userIsConfirmedDirector: true,
|
|
}),
|
|
)
|
|
expect(text).toMatch(/Du driver Anna Andersson som enskild firma\./)
|
|
})
|
|
|
|
it('falls back gracefully when entityType is unknown', () => {
|
|
const text = fallbackNarrative(
|
|
makeInputs({
|
|
entityType: 'handelsbolag',
|
|
userIsConfirmedDirector: false,
|
|
}),
|
|
)
|
|
// Generic neutral form: still no "Du driver".
|
|
expect(text).toMatch(/Coredination AB är ett företag/)
|
|
expect(text).not.toMatch(/Du driver/)
|
|
})
|
|
})
|