Files
bowenliang123 87a2893190 refactor(comments): clean up the test-suite comments to the guideline
Apply the AGENTS.md comments guideline to every .ts under tests/: remove
what the code already expresses, keep only what it cannot.

Removed: spec-header coverage inventories the describe/test tree already
names; comments restating the next line's assertion or its message; helper
JSDoc whose body already says it; within-file duplicates; five stale
claims (trendChart's "six aggregated turns" against agg.length === 8,
agentGraph's "six categories" against CATS' seven, fold-timing's "cheapest
call LAST" against a loop that feeds it first, fold-surface's unreachable
plain-JSON note, contextView's "two turns" for a one-turn fixture).

Kept and condensed: the projection-freeze class, strict wire/state-schema
hazards, retention and pricing windows, pairing rules, hostile-input
rationale, fixture and expectation-array ground truth, jsdom mechanics,
and issue-numbered regressions.

Comment lines 2604 -> 2014 (-22%); 85 module headers kept, 30 coverage
inventories dropped; every surviving comment line is within the 140-column
limit, with 36 wrapped lines joined onto fuller ones.

No logic, string, identifier, import or directive changed: a comment-strip
gate proves each file's comment-free code is byte-identical to HEAD, and a
line-level proof pairs all 845 changed lines with an unchanged code part.
pnpm run lint && pnpm run test (106 files / 2061 tests, per-file 100%
coverage) && pnpm run build all pass.
2026-10-10 00:50:55 +08:00

60 lines
3.1 KiB
TypeScript

// The specs pin the locale files' shape AND their listing in package.json's `files`/`exports` — a locale file those
// lists miss would work from a linked checkout and silently vanish from the published package.
import { readFile, readdir } from 'node:fs/promises'
import assert from 'node:assert/strict'
import { describe, test } from 'vitest'
interface PackageManifest {
exports: Record<string, string>
files: string[]
icon?: string
}
const manifest = JSON.parse(await readFile('package.json', 'utf8')) as PackageManifest
describe('package meta localization', () => {
test('the locale directory carries well-formed meta dictionaries', async () => {
const names = (await readdir('locale')).filter(name => name.endsWith('.json')).sort()
assert.ok(names.includes('en.json'), 'en.json is the fallback dictionary and gates the meta scan')
for (const name of names) {
assert.match(name, /^en\.json$|^[A-Za-z]{2,8}(-[A-Za-z0-9]{1,8})*\.json$/, `${name}: language-id filename`)
const parsed = JSON.parse(await readFile(`locale/${name}`, 'utf8')) as {
meta?: { title?: unknown; description?: unknown }
}
assert.equal(typeof parsed.meta?.title, 'string', `${name}: meta.title`)
assert.equal(typeof parsed.meta?.description, 'string', `${name}: meta.description`)
}
})
test('the zh dictionary is a real translation of the en one', async () => {
// The Host resolves the active locale against these entries with `en`
// as the final fallback — a copy-pasted zh file would read as English.
const en = JSON.parse(await readFile('locale/en.json', 'utf8')) as { meta: Record<string, string> }
const zh = JSON.parse(await readFile('locale/zh.json', 'utf8')) as { meta: Record<string, string> }
assert.deepEqual(Object.keys(zh.meta).sort(), Object.keys(en.meta).sort())
for (const field of Object.keys(en.meta)) {
assert.notEqual(zh.meta[field], en.meta[field], `zh ${field} is translated`)
}
})
test('package.json resolves and ships the locale dictionaries', async () => {
// The exports entry is a PATTERN the Node resolver matches each
// dictionary's full specifier (`dsh-context/locale/zh.json`) against.
assert.equal(manifest.exports['./locale/*.json'], './locale/*.json', 'the locale exports pattern')
const names = (await readdir('locale')).filter(name => name.endsWith('.json'))
for (const name of names) {
assert.match(name.slice(0, -'.json'.length), /^[A-Za-z][A-Za-z0-9-]*$/, `locale/${name}: matchable id`)
}
assert.equal(manifest.exports['./package.json'], './package.json', 'the meta reader resolves the manifest itself')
assert.ok(manifest.files.includes('locale/*.json'), 'the dictionaries ship')
})
test('the icon declaration stays aligned with the manifest and the shipped file', async () => {
assert.equal(manifest.icon, 'icon.svg')
assert.ok(manifest.files.includes('icon.svg'), 'the icon ships')
const svg = await readFile('icon.svg', 'utf8')
assert.match(svg, /^<svg xmlns="http:\/\/www\.w3\.org\/2000\/svg" viewBox="0 0 1024 1024">/)
})
})