Merge branch 'master' into feat/desktop-operation-diagnostics
This commit is contained in:
commit
dee4969d5f
1969 files changed
+31900
-1828
No files matched your search
@@ -546,6 +546,7 @@ export const LINK_MAP: Readonly<Record<string, string>> = {
|
||||
ScheduleListRequest: 'schedule.md',
|
||||
ScheduleDeleteRequest: 'schedule.md',
|
||||
ScheduleDeleteResult: 'schedule.md',
|
||||
ScheduleDeleteInactiveResult: 'schedule.md',
|
||||
ScheduleTimingChange: 'schedule.md',
|
||||
ScheduleUpdateRequest: 'schedule.md',
|
||||
ScheduleUpdateResult: 'schedule.md',
|
||||
|
||||
@@ -7,6 +7,8 @@ import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { ON_DEMAND_BUNDLES } from '../packages/boot/official-bundles/src/index.ts'
|
||||
import { generateOfficialBundleCatalog, renderOfficialBundleCatalog, syncOfficialBundleCatalog } from './gen-official-bundle-catalog.ts'
|
||||
|
||||
import { SHIPPED_LOCALE_IDS } from './shipped-locales.ts'
|
||||
|
||||
const roots: string[] = []
|
||||
const output = 'packages/boot/official-bundles/src/catalog.generated.ts'
|
||||
|
||||
@@ -32,6 +34,7 @@ function fixture(): string {
|
||||
write(root, `${dir}/locale/en.json`, { meta: { title: 'Native agent', description: 'Delegate a task.' } })
|
||||
write(root, `${dir}/locale/zh.json`, { meta: { title: '原生智能体', description: '委派任务。' } })
|
||||
write(root, `${dir}/locale/ja.json`, { meta: { title: 'ネイティブエージェント', description: 'タスクを委派します。' } })
|
||||
for (const language of ['es', 'fr', 'de', 'ru', 'pt']) write(root, `${dir}/locale/${language}.json`, { meta: { title: 'Native agent', description: 'Delegate a task.' } })
|
||||
}
|
||||
write(root, output, '')
|
||||
return root
|
||||
@@ -50,8 +53,8 @@ describe('Official bundle catalog generation', () => {
|
||||
const entries = generateOfficialBundleCatalog(fixture())
|
||||
expect(entries.map(entry => entry.packageName)).toEqual(ON_DEMAND_BUNDLES)
|
||||
expect(entries[0]?.meta).toEqual({
|
||||
title: { en: 'Native agent', zh: '原生智能体', ja: 'ネイティブエージェント' },
|
||||
description: { en: 'Delegate a task.', zh: '委派任务。', ja: 'タスクを委派します。' },
|
||||
title: { en: 'Native agent', zh: '原生智能体', ja: 'ネイティブエージェント', ...Object.fromEntries(['es', 'fr', 'de', 'ru', 'pt'].map(id => [id, 'Native agent'])) },
|
||||
description: { en: 'Delegate a task.', zh: '委派任务。', ja: 'タスクを委派します。', ...Object.fromEntries(['es', 'fr', 'de', 'ru', 'pt'].map(id => [id, 'Delegate a task.'])) },
|
||||
icon: `data:image/svg+xml;base64,${Buffer.from('<svg xmlns="http://www.w3.org/2000/svg"/>').toString('base64')}`,
|
||||
})
|
||||
expect(renderOfficialBundleCatalog(entries)).not.toContain('1.2.3')
|
||||
@@ -81,14 +84,14 @@ describe('Official bundle catalog generation', () => {
|
||||
expect(() => generateOfficialBundleCatalog(root, [ON_DEMAND_BUNDLES[0]!, ON_DEMAND_BUNDLES[0]!])).toThrow('distinct package names')
|
||||
})
|
||||
|
||||
it.each(['icon', 'en', 'zh', 'ja'])('rejects missing %s metadata', (resource) => {
|
||||
it.each(['icon', ...SHIPPED_LOCALE_IDS])('rejects missing %s metadata', (resource) => {
|
||||
const root = fixture()
|
||||
const dir = directory(ON_DEMAND_BUNDLES[0]!)
|
||||
rmSync(join(root, dir, resource === 'icon' ? 'icon.svg' : `locale/${resource}.json`))
|
||||
expect(() => generateOfficialBundleCatalog(root)).toThrow()
|
||||
})
|
||||
|
||||
it.each(['en', 'zh', 'ja'])('requires explicit %s fields instead of metadata fallback text', (language) => {
|
||||
it.each(SHIPPED_LOCALE_IDS)('requires explicit %s fields instead of metadata fallback text', (language) => {
|
||||
const root = fixture()
|
||||
write(root, `${directory(ON_DEMAND_BUNDLES[0]!)}/locale/${language}.json`, { meta: { description: 'Only a description.' } })
|
||||
expect(() => generateOfficialBundleCatalog(root)).toThrow(`explicit ${language} title and description`)
|
||||
|
||||
@@ -9,6 +9,8 @@ import { ON_DEMAND_BUNDLES } from '../packages/boot/official-bundles/src/bundles
|
||||
import type { OfficialBundleCatalogEntry } from '../packages/boot/official-bundles/src/index.ts'
|
||||
import { readPluginMeta, resolvePluginResource } from '../packages/boot/app-boot/src/package-meta.ts'
|
||||
|
||||
import { SHIPPED_LOCALE_IDS } from './shipped-locales.ts'
|
||||
|
||||
const OUTPUT = 'packages/boot/official-bundles/src/catalog.generated.ts'
|
||||
|
||||
/**
|
||||
@@ -49,7 +51,7 @@ export function generateOfficialBundleCatalog(root: string, names: readonly stri
|
||||
throw new Error(`${packageName}: Official catalog entries must be public DSH bundle packages`)
|
||||
}
|
||||
const parentURL = pathToFileURL(resolve(root, entry.path)).href
|
||||
for (const language of ['en', 'zh', 'ja']) {
|
||||
for (const language of SHIPPED_LOCALE_IDS) {
|
||||
const file = resolvePluginResource(`${packageName}/locale/${language}.json`, parentURL)
|
||||
const dictionary = JSON.parse(readFileSync(file, 'utf8')) as { meta?: { title?: unknown; description?: unknown } }
|
||||
if (typeof dictionary.meta?.title !== 'string' || dictionary.meta.title.trim() === ''
|
||||
@@ -63,7 +65,7 @@ export function generateOfficialBundleCatalog(root: string, names: readonly stri
|
||||
throw new Error(`${packageName}: Official catalog entries require an icon and localized title and description`)
|
||||
}
|
||||
for (const value of [meta.title, meta.description]) {
|
||||
for (const language of ['en', 'zh', 'ja']) {
|
||||
for (const language of SHIPPED_LOCALE_IDS) {
|
||||
if (typeof value[language] !== 'string' || value[language].trim() === '') {
|
||||
throw new Error(`${packageName}: Official metadata requires ${language} text`)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Gate for the invariant `FALLBACK_LOCALE` rests on: every shipped dictionary
|
||||
* declares the same keys in `zh`, `en`, and `ja`; Japanese dictionaries also
|
||||
* preserve the English literal-template placeholders.
|
||||
* declares the same keys in every shipped language; translations also
|
||||
* preserve the English placeholders, command examples, and API field names.
|
||||
*
|
||||
* The locale runtime resolves a key through the active locale, then through
|
||||
* the single fallback locale (`en`), then surfaces the key itself. With
|
||||
@@ -27,6 +27,8 @@ import { fileURLToPath } from 'node:url'
|
||||
import ts from 'typescript'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { SHIPPED_LOCALE_IDS, localeTokens, hasInvisibleLocaleCharacters, type ShippedLocaleId } from './shipped-locales.ts'
|
||||
|
||||
const root = fileURLToPath(new URL('..', import.meta.url))
|
||||
|
||||
/** Repo-relative path with `/` separators, so messages and suffix tests match on every OS. */
|
||||
@@ -101,7 +103,7 @@ function dictionariesIn(file: string): Dictionary[] {
|
||||
// before parsing — the silent narrowing this gate exists to prevent. A bare
|
||||
// `\b(zh|en)\b` misses `zhSettings`/`accessZh`, because `\b` does not hold
|
||||
// between `h` and an uppercase letter.
|
||||
if (!/\b(zh|en|ja)\b|\b(zh|en|ja)[A-Z]|(Zh|En|Ja)\b/.test(text)) return []
|
||||
if (!/\b(zh|en|ja|es|fr|de|ru|pt)\b|\b(zh|en|ja|es|fr|de|ru|pt)[A-Z]|(Zh|En|Ja|Es|Fr|De|Ru|Pt)\b/.test(text)) return []
|
||||
const source = ts.createSourceFile(file, text, ts.ScriptTarget.ESNext, true)
|
||||
const found: Dictionary[] = []
|
||||
const rel = relative(file)
|
||||
@@ -153,7 +155,7 @@ function dictionariesIn(file: string): Dictionary[] {
|
||||
if (name === 'register' && node.arguments.length >= 3) {
|
||||
const [ns, tag, dict] = node.arguments
|
||||
if (ns === undefined || tag === undefined || !ts.isStringLiteral(tag)) return
|
||||
if (tag.text !== 'zh' && tag.text !== 'en' && tag.text !== 'ja') return
|
||||
if (!SHIPPED_LOCALE_IDS.some(id => id === tag.text)) return
|
||||
const raw = unwrap(dict)
|
||||
const literal = raw !== undefined && ts.isIdentifier(raw)
|
||||
? (() => {
|
||||
@@ -185,7 +187,7 @@ function dictionariesIn(file: string): Dictionary[] {
|
||||
const literal = unwrap(dict)
|
||||
if (tag === undefined || !ts.isStringLiteral(tag)) continue
|
||||
if (literal === undefined || !ts.isObjectLiteralExpression(literal)) continue
|
||||
if (tag.text !== 'zh' && tag.text !== 'en' && tag.text !== 'ja') continue
|
||||
if (!SHIPPED_LOCALE_IDS.some(id => id === tag.text)) continue
|
||||
found.push({ file: rel, name: `${tag.text}@inline:${site}`, keys: keysOf(literal), templates: templatesOf(literal) })
|
||||
}
|
||||
}
|
||||
@@ -239,8 +241,8 @@ function unwrap(node: ts.Expression | undefined): ts.Expression | undefined {
|
||||
* @param name - export name or synthetic inline name.
|
||||
* @returns locale plus pair key, or undefined when the name names no locale.
|
||||
*/
|
||||
function localeOf(name: string): { locale: 'zh' | 'en' | 'ja'; pair: string } | undefined {
|
||||
for (const locale of ['zh', 'en', 'ja'] as const) {
|
||||
function localeOf(name: string): { locale: ShippedLocaleId; pair: string } | undefined {
|
||||
for (const locale of SHIPPED_LOCALE_IDS) {
|
||||
const other = locale[0]!.toUpperCase() + locale.slice(1)
|
||||
if (name === locale) return { locale, pair: '' }
|
||||
// Synthetic names for inline shapes carry their own pair key after the
|
||||
@@ -255,9 +257,9 @@ function localeOf(name: string): { locale: 'zh' | 'en' | 'ja'; pair: string } |
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that each object-form registration supplies its Japanese dictionary.
|
||||
* Check that each object-form registration supplies every shipped-language dictionary.
|
||||
* @param file - absolute source path.
|
||||
* @returns registration sites missing Japanese, or using an unresolved local identifier.
|
||||
* @returns registration sites missing a shipped language, or using an unresolved local identifier.
|
||||
*/
|
||||
function registrationProblems(file: string): string[] {
|
||||
const text = readFileSync(file, 'utf8')
|
||||
@@ -289,11 +291,13 @@ function registrationProblems(file: string): string[] {
|
||||
}
|
||||
}
|
||||
if (entries.has('zh') && entries.has('en')) {
|
||||
const ja = entries.get('ja')
|
||||
const site = `${relative(file)}:${source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1}`
|
||||
if (ja === undefined) problems.push(`${site}: registration has no Japanese dictionary`)
|
||||
else if (ts.isIdentifier(ja) && !imported.has(ja.text) && !locals.has(ja.text)) {
|
||||
problems.push(`${site}: Japanese dictionary ${ja.text} is not imported or declared`)
|
||||
for (const language of SHIPPED_LOCALE_IDS) {
|
||||
const dictionary = entries.get(language)
|
||||
if (dictionary === undefined) problems.push(`${site}: registration has no ${language} dictionary`)
|
||||
else if (ts.isIdentifier(dictionary) && !imported.has(dictionary.text) && !locals.has(dictionary.text)) {
|
||||
problems.push(`${site}: ${language} dictionary ${dictionary.text} is not imported or declared`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -305,11 +309,11 @@ function registrationProblems(file: string): string[] {
|
||||
}
|
||||
|
||||
describe('shipped locale dictionaries', () => {
|
||||
it('registers Japanese alongside every object-form bilingual dictionary', () => {
|
||||
it('registers every shipped language alongside every object-form bilingual dictionary', () => {
|
||||
expect(sourceFiles().flatMap(registrationProblems)).toEqual([])
|
||||
})
|
||||
|
||||
it('keeps bilingual keys aligned and Japanese keys and placeholders complete', () => {
|
||||
it('keeps bilingual keys aligned and shipped-language keys and placeholders complete', () => {
|
||||
const files = sourceFiles()
|
||||
// Guard the discovery itself: an empty or narrowed sweep would pass every
|
||||
// assertion below while checking nothing.
|
||||
@@ -322,12 +326,18 @@ describe('shipped locale dictionaries', () => {
|
||||
const perFile = new Map<string, Dictionary[]>()
|
||||
for (const file of files) {
|
||||
const dicts = dictionariesIn(file)
|
||||
if (dicts.length > 0) perFile.set(relative(file), dicts)
|
||||
if (dicts.length > 0) {
|
||||
expect(hasInvisibleLocaleCharacters(readFileSync(file, 'utf8')), relative(file)).toBe(false)
|
||||
for (const dictionary of dicts) {
|
||||
for (const text of Object.values(dictionary.templates)) expect(hasInvisibleLocaleCharacters(text), relative(file)).toBe(false)
|
||||
}
|
||||
perFile.set(relative(file), dicts)
|
||||
}
|
||||
}
|
||||
|
||||
const groups = new Map<string, Map<'zh' | 'en' | 'ja', Dictionary>>()
|
||||
const place = (key: string, locale: 'zh' | 'en' | 'ja', dict: Dictionary): void => {
|
||||
const slot = groups.get(key) ?? new Map<'zh' | 'en' | 'ja', Dictionary>()
|
||||
const groups = new Map<string, Map<ShippedLocaleId, Dictionary>>()
|
||||
const place = (key: string, locale: ShippedLocaleId, dict: Dictionary): void => {
|
||||
const slot = groups.get(key) ?? new Map<ShippedLocaleId, Dictionary>()
|
||||
if (slot.has(locale)) {
|
||||
throw new Error(`two ${locale} dictionaries claim pair ${key}: ${slot.get(locale)?.file} and ${dict.file}`)
|
||||
}
|
||||
@@ -367,21 +377,23 @@ describe('shipped locale dictionaries', () => {
|
||||
const enOnly = en.keys.filter(k => !zh.keys.includes(k))
|
||||
if (zhOnly.length > 0) problems.push(`${zh.file} ${zh.name} has keys absent from ${en.name}: ${zhOnly.join(', ')}`)
|
||||
if (enOnly.length > 0) problems.push(`${en.file} ${en.name} has keys absent from ${zh.name}: ${enOnly.join(', ')}`)
|
||||
const ja = slot.get('ja')
|
||||
if (ja === undefined) {
|
||||
problems.push(`${key} has no Japanese dictionary`)
|
||||
} else {
|
||||
const missing = en.keys.filter(k => !ja.keys.includes(k))
|
||||
const extra = ja.keys.filter(k => !en.keys.includes(k))
|
||||
if (missing.length > 0 || extra.length > 0) {
|
||||
problems.push(`${ja.file} ${ja.name}: missing [${missing.join(', ')}], extra [${extra.join(', ')}]`)
|
||||
}
|
||||
for (const [name, text] of Object.entries(en.templates)) {
|
||||
const translated = ja.templates[name]
|
||||
if (translated === undefined) continue
|
||||
const placeholders = (value: string): string => (value.match(/\{\w+\}/gu) ?? []).sort().join(', ')
|
||||
if (placeholders(text) !== placeholders(translated)) {
|
||||
problems.push(`${ja.file} ${ja.name}.${name} changes placeholders from ${en.name}`)
|
||||
for (const language of SHIPPED_LOCALE_IDS.filter(id => id !== 'en' && id !== 'zh')) {
|
||||
const translatedDictionary = slot.get(language)
|
||||
if (translatedDictionary === undefined) {
|
||||
problems.push(`${key} has no ${language} dictionary`)
|
||||
} else {
|
||||
const missing = en.keys.filter(k => !translatedDictionary.keys.includes(k))
|
||||
const extra = translatedDictionary.keys.filter(k => !en.keys.includes(k))
|
||||
if (missing.length > 0 || extra.length > 0) {
|
||||
problems.push(`${translatedDictionary.file} ${translatedDictionary.name}: missing [${missing.join(', ')}], extra [${extra.join(', ')}]`)
|
||||
}
|
||||
for (const [name, text] of Object.entries(en.templates)) {
|
||||
const translated = translatedDictionary.templates[name]
|
||||
if (translated === undefined) continue
|
||||
const placeholders = (value: string): string => localeTokens(value).join(', ')
|
||||
if (placeholders(text) !== placeholders(translated)) {
|
||||
problems.push(`${translatedDictionary.file} ${translatedDictionary.name}.${name} changes placeholders or literal tokens from ${en.name}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,9 +459,6 @@
|
||||
"packages/client/ui-commands/tests/browser-plugin.client.spec.ts": {
|
||||
"04984a2ce1486250236e638e0197da0a1a840855ed3975c59130a85358c7e5fe": 1
|
||||
},
|
||||
"packages/client/ui-conversation/src/client/apply.ts": {
|
||||
"4c73f40f3ce989f285848573d7154fb295886bba707ad829e2c8c089e326aeea": 1
|
||||
},
|
||||
"packages/client/ui-conversation/src/client/conversation/location-index.ts": {
|
||||
"a7d8cc8d42e37ad5cc4882241492ac572ed8163c7fb8663180e893c7178e906f": 1
|
||||
},
|
||||
|
||||
@@ -392,8 +392,8 @@ function ciSharedStaticGates(): Gate[] {
|
||||
function i18nGates(includeDictionaries: boolean): Gate[] {
|
||||
return [
|
||||
pnpmScript('installer-locales', 'verify-installer-locales', { label: 'Windows installer locales' }),
|
||||
pnpmScript('locale-metadata', 'verify-locale-metadata', { label: 'Japanese plugin metadata' }),
|
||||
...includeDictionaries ? [pnpmExec('locale-dictionaries', ['vitest', 'run', 'scripts/locale-dictionary-parity.spec.ts'], { label: 'locale dictionaries' })] : [],
|
||||
pnpmScript('locale-metadata', 'verify-locale-metadata', { label: 'plugin locale metadata' }),
|
||||
...includeDictionaries ? [pnpmExec('locale-dictionaries', ['vitest', 'run', 'scripts/locale-dictionary-parity.spec.ts', 'scripts/shipped-locales.spec.ts', 'packages/client/locale/tests/apply.client.spec.ts'], { label: 'locale dictionaries' })] : [],
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import * as desktop from '../apps/desktop/src/locale.ts'
|
||||
import { readInstallerLocales } from '../apps/desktop/scripts/installer-locales.mjs'
|
||||
/** Translations preserve executable command examples and named interpolation fields. */
|
||||
import { expect, it } from 'vitest'
|
||||
import { SHIPPED_LOCALE_IDS, localeTokens, hasInvisibleLocaleCharacters } from './shipped-locales.ts'
|
||||
|
||||
it('retains repeated placeholders, commands, and API identifiers', () => {
|
||||
expect(localeTokens('Use /plan off, /compact and /THEME=dark with {count}, {count} and reasoning_effort.'))
|
||||
.toEqual(['/THEME=dark', '/compact', '/plan off', 'reasoning_effort', '{count}', '{count}'])
|
||||
})
|
||||
|
||||
it('ignores translated prose and non-command slashes', () => {
|
||||
expect(localeTokens('Cmd/Ctrl+Enter · tok/s · https://example.test/v1')).toEqual([])
|
||||
expect(localeTokens('Используйте /plan off и {count}'))
|
||||
.toEqual(localeTokens('Use /plan off and {count}'))
|
||||
})
|
||||
|
||||
it.each([['/plan off', '/plan désactivé'], ['/THEME=light', '/THEME=claro'], ['reasoning_effort', 'Reasoning_effort'], ['{count}', '{other}']])('detects a change from %s to %s', (source, translated) => {
|
||||
expect(localeTokens(translated)).not.toEqual(localeTokens(source))
|
||||
})
|
||||
|
||||
it('recognizes commands at the start of copy or after CJK punctuation', () => {
|
||||
expect(localeTokens('/THEME=auto、/THEME=light')).toEqual(['/THEME=auto', '/THEME=light'])
|
||||
})
|
||||
|
||||
it.each(['\u200b', '\ufeff'])('rejects an invisible translation character', (character) => {
|
||||
expect(hasInvisibleLocaleCharacters(`text${character}text`)).toBe(true)
|
||||
expect(hasInvisibleLocaleCharacters('normal text')).toBe(false)
|
||||
})
|
||||
|
||||
it('matches Desktop dictionaries, resolution and installer resources to the shipped catalog', () => {
|
||||
const dictionaries = Object.keys(desktop).filter(name => /^[a-z]{2}$/u.test(name)).sort()
|
||||
expect(dictionaries).toEqual([...SHIPPED_LOCALE_IDS].sort())
|
||||
for (const id of SHIPPED_LOCALE_IDS) {
|
||||
expect(desktop.resolveDesktopLocale(id).id).toBe(id === 'zh' ? 'zh-CN' : id)
|
||||
expect(desktop.resolveDesktopStartupLocale(null, [id]).id).toBe(id === 'zh' ? 'zh-CN' : id)
|
||||
}
|
||||
expect(readInstallerLocales().map(locale => locale.id.split('_')[0]).sort()).toEqual(dictionaries)
|
||||
})
|
||||
|
||||
it('rejects invisible characters in the Desktop locale source', () => {
|
||||
expect(hasInvisibleLocaleCharacters(readFileSync(new URL('../apps/desktop/src/locale.ts', import.meta.url), 'utf8'))).toBe(false)
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
/** Languages whose UI dictionaries and package metadata ship with Harness. */
|
||||
export const SHIPPED_LOCALE_IDS = ['en', 'zh', 'ja', 'es', 'fr', 'de', 'ru', 'pt'] as const
|
||||
|
||||
/** Locale id required by repository translation checks. */
|
||||
export type ShippedLocaleId = typeof SHIPPED_LOCALE_IDS[number]
|
||||
|
||||
/**
|
||||
* Extract copy tokens that translations must preserve verbatim.
|
||||
* @param text - Dictionary text containing placeholders, slash commands or API field names.
|
||||
* @returns Sorted tokens, retaining repeated occurrences.
|
||||
*/
|
||||
export function localeTokens(text: string): string[] {
|
||||
return (text.match(/\{\w+\}|(?<![A-Za-z0-9/])\/[A-Za-z][\w-]*(?:=[\w-]+| (?:on|off))?|\b[a-z]+_[a-z_]+\b/gu) ?? []).sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect translation-service artifacts that must not enter locale resources.
|
||||
* @param text - Raw resource or localized text.
|
||||
* @returns Whether the text contains a zero-width space or byte-order mark.
|
||||
*/
|
||||
export function hasInvisibleLocaleCharacters(text: string): boolean {
|
||||
return /[\u200b\ufeff]/u.test(text)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/** Unit suites cannot reach the official DeepSeek model listing unless they answer `fetch` themselves. */
|
||||
import { createServer } from 'node:http'
|
||||
import { afterEach, expect, it } from 'vitest'
|
||||
import type { Server } from 'node:http'
|
||||
|
||||
const servers: Server[] = []
|
||||
afterEach(async () => {
|
||||
await Promise.all(servers.splice(0).map(server => new Promise(resolve => server.close(resolve))))
|
||||
})
|
||||
|
||||
it.each([
|
||||
['string', () => fetch('https://api.deepseek.com/models')],
|
||||
['URL', () => fetch(new URL('https://api.deepseek.com/models'))],
|
||||
['Request', () => fetch(new Request('https://api.deepseek.com/models', { headers: { 'x-api-key': 'fixture-key' } }))],
|
||||
])('rejects the official model listing given as a %s', async (_kind, request) => {
|
||||
await expect(request()).rejects.toThrow('unit suites do not reach https://api.deepseek.com/models; answer it with a fetch stub')
|
||||
})
|
||||
|
||||
it('passes every other request to the ambient fetch', async () => {
|
||||
const server = createServer((_request, response) => { response.end('local') })
|
||||
servers.push(server)
|
||||
await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve))
|
||||
const address = server.address()
|
||||
if (address === null || typeof address === 'string') throw new Error('no port')
|
||||
await expect((await fetch(`http://127.0.0.1:${address.port}/models`)).text()).resolves.toBe('local')
|
||||
})
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Keep unit suites from requesting the official DeepSeek model listing.
|
||||
*
|
||||
* The API-key and account routes request `GET https://api.deepseek.com/models` whenever they hold a
|
||||
* credential for the official endpoint, and suites routinely boot those routes with a dummy key or
|
||||
* inherit a developer's real one. Such a request would reach production and, on a network that never
|
||||
* answers, hold the route's first catalog access for its whole listing deadline. Here it fails at once,
|
||||
* so the route serves its built-in catalog; a suite that exercises the listing replaces `fetch` itself.
|
||||
* @module
|
||||
*/
|
||||
|
||||
/** The listing endpoint of the official DeepSeek API. */
|
||||
const OFFICIAL_LISTING = 'https://api.deepseek.com/models'
|
||||
|
||||
const ambientFetch = globalThis.fetch
|
||||
globalThis.fetch = (input, init) => {
|
||||
const url = input instanceof Request ? input.url : input instanceof URL ? input.href : input
|
||||
if (url === OFFICIAL_LISTING) {
|
||||
return Promise.reject(new TypeError(`unit suites do not reach ${OFFICIAL_LISTING}; answer it with a fetch stub`))
|
||||
}
|
||||
return ambientFetch(input, init)
|
||||
}
|
||||
@@ -307,6 +307,11 @@
|
||||
"symbol": "LegacyScheduleRecord",
|
||||
"source": "packages/schedule/schedule/src/types.ts"
|
||||
},
|
||||
{
|
||||
"doc": "docs/subsystems/schedule.md",
|
||||
"symbol": "ScheduleDeleteInactiveResult",
|
||||
"source": "packages/schedule/schedule/src/types.ts"
|
||||
},
|
||||
{
|
||||
"doc": "docs/subsystems/schedule.md",
|
||||
"symbol": "LocalAtInput",
|
||||
|
||||
@@ -50,7 +50,7 @@ export function findConcreteTermViolations(file: string, source: string): Concre
|
||||
}
|
||||
|
||||
function trackedFiles(repoRoot: string): string[] {
|
||||
const files = execFileSync('git', ['ls-files', '-z'], { cwd: repoRoot, encoding: 'utf8' })
|
||||
const files = execFileSync('git', ['ls-files', '-z'], { cwd: repoRoot, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 })
|
||||
.split('\0')
|
||||
.filter(file => file !== '')
|
||||
if (!files.includes('AGENTS.md')
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/** Metadata coverage rejects missing translations through the same checker used by CI. */
|
||||
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs'
|
||||
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, expect, it } from 'vitest'
|
||||
import { localeMetadataProblems } from './verify-locale-metadata.ts'
|
||||
|
||||
import { SHIPPED_LOCALE_IDS } from './shipped-locales.ts'
|
||||
|
||||
const roots: string[] = []
|
||||
afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }) })
|
||||
|
||||
@@ -16,6 +18,9 @@ function fixture(ja: unknown = { meta: { title: '名前 {name}', description: '
|
||||
writeFileSync(join(directory, 'en.json'), JSON.stringify({ meta: { title: 'Name {name}' } }))
|
||||
writeFileSync(join(directory, 'zh.json'), JSON.stringify({ meta: { title: '名称 {name}', description: '描述' } }))
|
||||
writeFileSync(join(directory, 'ja.json'), JSON.stringify(ja))
|
||||
for (const language of ['es', 'fr', 'de', 'ru', 'pt']) {
|
||||
writeFileSync(join(directory, `${language}.json`), JSON.stringify({ meta: { title: 'Name {name}', description: 'Localized description.' } }))
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
@@ -41,8 +46,8 @@ it.each([
|
||||
it('checks referenced detail documents', () => {
|
||||
const root = fixture()
|
||||
const directory = join(root, 'packages/demo/plugin/locale')
|
||||
const meta = { title: 'Name {name}', description: 'Description.', detail: 'docs/DETAIL.md' }
|
||||
for (const language of ['en', 'zh', 'ja']) writeFileSync(join(directory, `${language}.json`), JSON.stringify({ meta }))
|
||||
const meta = { title: 'Name {name}', detail: 'docs/DETAIL.md' }
|
||||
for (const language of SHIPPED_LOCALE_IDS) writeFileSync(join(directory, `${language}.json`), JSON.stringify({ meta }))
|
||||
expect(localeMetadataProblems(root).join('\n')).toContain('missing detail resource')
|
||||
mkdirSync(join(directory, '../docs'))
|
||||
writeFileSync(join(directory, '../docs/DETAIL.md'), '# Detail\n')
|
||||
@@ -84,6 +89,7 @@ it('checks nested subpath locale resources and package-relative detail files', (
|
||||
expect(localeMetadataProblems(root).join('\n')).toContain('locale/tools')
|
||||
expect(localeMetadataProblems(root).join('\n')).toContain('ja.json')
|
||||
writeFileSync(join(directory, 'ja.json'), JSON.stringify({ meta: { title: 'ツール', detail: 'docs/TOOLS.md' } }))
|
||||
for (const language of ['es', 'fr', 'de', 'ru', 'pt']) writeFileSync(join(directory, `${language}.json`), JSON.stringify({ meta: { title: 'Tools', detail: 'docs/TOOLS.md' } }))
|
||||
expect(localeMetadataProblems(root)).toEqual([])
|
||||
})
|
||||
|
||||
@@ -97,7 +103,7 @@ it('requires sentence punctuation for English descriptions', () => {
|
||||
const file = join(root, 'packages/demo/plugin/locale/en.json')
|
||||
writeFileSync(file, JSON.stringify({ meta: { title: 'Name {name}', description: 'Description' } }))
|
||||
expect(localeMetadataProblems(root).join('\n')).toContain('sentence punctuation')
|
||||
writeFileSync(file, JSON.stringify({ meta: { title: 'Name {name}', description: 'Description.' } }))
|
||||
writeFileSync(file, JSON.stringify({ meta: { title: 'Name {name}', description: 'English description.' } }))
|
||||
expect(localeMetadataProblems(root)).toEqual([])
|
||||
})
|
||||
|
||||
@@ -108,6 +114,7 @@ it('permits missing Chinese resources for loadable plugins', () => {
|
||||
writeFileSync(join(directory, 'src/index.ts'), 'export function apply() {}')
|
||||
writeFileSync(join(directory, 'package.json'), JSON.stringify({ name: '@deepseek-ai/dsh-demo' }))
|
||||
rmSync(join(directory, 'locale/zh.json'))
|
||||
for (const language of ['es', 'fr', 'de', 'ru', 'pt']) writeFileSync(join(directory, `locale/${language}.json`), JSON.stringify({ meta: { title: 'Name {name}' } }))
|
||||
expect(localeMetadataProblems(root)).toEqual([])
|
||||
})
|
||||
|
||||
@@ -119,3 +126,30 @@ it('excludes packages formally classified as test helpers', () => {
|
||||
writeFileSync(join(directory, 'package.json'), JSON.stringify({ name: '@deepseek-ai/dsh-llm-replay' }))
|
||||
expect(localeMetadataProblems(root)).toEqual([])
|
||||
})
|
||||
|
||||
it.each(['es', 'fr', 'de', 'ru', 'pt'])('rejects missing %s metadata', (language) => {
|
||||
const root = fixture()
|
||||
rmSync(join(root, `packages/demo/plugin/locale/${language}.json`))
|
||||
expect(localeMetadataProblems(root).join('\n')).toContain(`${language}.json`)
|
||||
})
|
||||
|
||||
it.each(['es', 'fr', 'de', 'ru', 'pt'])('rejects untranslated Chinese descriptions in %s metadata', (language) => {
|
||||
const root = fixture()
|
||||
writeFileSync(join(root, 'packages/demo/plugin/locale/en.json'), JSON.stringify({ meta: { title: 'Name {name}', description: 'English description.' } }))
|
||||
writeFileSync(join(root, `packages/demo/plugin/locale/${language}.json`), JSON.stringify({ meta: { title: 'Name {name}', description: '描述' } }))
|
||||
expect(localeMetadataProblems(root).join('\n')).toContain(`${language}.json: meta.description contains untranslated source text`)
|
||||
})
|
||||
|
||||
it.each(['es', 'fr', 'de', 'ru', 'pt'])('rejects copied English descriptions in %s metadata', (language) => {
|
||||
const root = fixture()
|
||||
writeFileSync(join(root, 'packages/demo/plugin/locale/en.json'), JSON.stringify({ meta: { title: 'Name {name}', description: 'English description.' } }))
|
||||
writeFileSync(join(root, `packages/demo/plugin/locale/${language}.json`), JSON.stringify({ meta: { title: 'Name {name}', description: 'English description.' } }))
|
||||
expect(localeMetadataProblems(root).join('\n')).toContain(`${language}.json: meta.description contains untranslated source text`)
|
||||
})
|
||||
|
||||
it.each(['\u200b', '\ufeff', String.raw`\u200b`, String.raw`\ufeff`])('rejects invisible characters in JSON resources', (character) => {
|
||||
const root = fixture()
|
||||
const file = join(root, 'packages/demo/plugin/locale/es.json')
|
||||
writeFileSync(file, readFileSync(file, 'utf8').replace('Localized description.', `Localized${character} description.`))
|
||||
expect(localeMetadataProblems(root).join('\n')).toContain('invisible locale character')
|
||||
})
|
||||
@@ -1,8 +1,9 @@
|
||||
/** Check Japanese coverage of package metadata and plugin templates without loading plugins. */
|
||||
/** Check shipped-language coverage of package metadata and plugin templates without loading plugins. */
|
||||
import { existsSync, globSync, readFileSync } from 'node:fs'
|
||||
import { basename, posix, join, resolve } from 'node:path'
|
||||
import { detailPath } from '../packages/util/plugin-detail/src/document.ts'
|
||||
import { PRODUCT_PACKAGE_POLICY } from './product-package-policy.ts'
|
||||
import { SHIPPED_LOCALE_IDS, localeTokens, hasInvisibleLocaleCharacters } from './shipped-locales.ts'
|
||||
import { collectConfigCatalog } from './gen-config-catalog.ts'
|
||||
|
||||
/** Flatten metadata strings and reject values that cannot be translated. */
|
||||
@@ -13,14 +14,14 @@ function strings(value: unknown, key = ''): Record<string, string> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare Japanese metadata with every field supplied by English or Chinese.
|
||||
* Compare shipped-language metadata with every field supplied by English or Chinese.
|
||||
* @param root - repository or fixture root.
|
||||
* @returns actionable missing-file, field, placeholder and resource diagnostics.
|
||||
*/
|
||||
export function localeMetadataProblems(root: string): string[] {
|
||||
const directories = new Set(globSync('packages/**/locale/**/*.json', {
|
||||
cwd: root, exclude: ['packages/**/node_modules/**', 'packages/**/lib/**', 'packages/**/tests/**'],
|
||||
}).map(file => file.replaceAll('\\', '/')).filter(file => ['en.json', 'zh.json', 'ja.json'].includes(basename(file))).map(file => posix.dirname(file)))
|
||||
}).map(file => file.replaceAll('\\', '/')).filter(file => SHIPPED_LOCALE_IDS.some(language => basename(file) === `${language}.json`)).map(file => posix.dirname(file)))
|
||||
for (const entry of collectConfigCatalog(root)) {
|
||||
const dir = entry.dir.replaceAll('\\', '/')
|
||||
if (PRODUCT_PACKAGE_POLICY[dir]?.category === 'test') continue
|
||||
@@ -34,7 +35,9 @@ export function localeMetadataProblems(root: string): string[] {
|
||||
try {
|
||||
const read = (language: string): Record<string, string> => {
|
||||
const file = join(root, directory, `${language}.json`)
|
||||
const value: unknown = JSON.parse(readFileSync(file, 'utf8'))
|
||||
const source = readFileSync(file, 'utf8')
|
||||
if (hasInvisibleLocaleCharacters(source) || /\\u(?:200b|feff)/iu.test(source)) throw new Error(`${language}.json: invisible locale character`)
|
||||
const value: unknown = JSON.parse(source)
|
||||
const dictionary = strings(value)
|
||||
const detail = detailPath(dictionary['meta.detail'], `${directory}/${language}.json: meta.detail`)
|
||||
const packageDir = directory.slice(0, directory.lastIndexOf('/locale'))
|
||||
@@ -47,14 +50,20 @@ export function localeMetadataProblems(root: string): string[] {
|
||||
const zh = existsSync(join(root, directory, 'zh.json')) ? read('zh') : {}
|
||||
const description = en['meta.description']
|
||||
if (description !== undefined && !/[.!?]$/u.test(description)) problems.push(`${directory}/en.json: meta.description must end with sentence punctuation`)
|
||||
const ja = read('ja')
|
||||
const expected = { ...zh, ...en }
|
||||
for (const key of new Set([...Object.keys(expected), ...Object.keys(ja)])) {
|
||||
if (ja[key] === undefined) problems.push(`${directory}/ja.json: missing ${key}`)
|
||||
else if (expected[key] === undefined) problems.push(`${directory}/ja.json: unexpected ${key}`)
|
||||
else {
|
||||
const placeholders = (text: string): string => (text.match(/\{\w+\}/gu) ?? []).sort().join(',')
|
||||
if (placeholders(ja[key]) !== placeholders(expected[key])) problems.push(`${directory}/ja.json: ${key} changes placeholders`)
|
||||
for (const language of SHIPPED_LOCALE_IDS.filter(id => id !== 'en' && id !== 'zh')) {
|
||||
const translated = read(language)
|
||||
for (const key of new Set([...Object.keys(expected), ...Object.keys(translated)])) {
|
||||
if (translated[key] === undefined) problems.push(`${directory}/${language}.json: missing ${key}`)
|
||||
else if (expected[key] === undefined) problems.push(`${directory}/${language}.json: unexpected ${key}`)
|
||||
else {
|
||||
if (language !== 'ja' && key === 'meta.description' && ((zh[key] !== undefined && /\p{Script=Han}/u.test(zh[key]) && translated[key] === zh[key])
|
||||
|| (en[key] !== undefined && translated[key] === en[key]))) {
|
||||
problems.push(`${directory}/${language}.json: ${key} contains untranslated source text`)
|
||||
}
|
||||
const placeholders = (text: string): string => localeTokens(text).join(',')
|
||||
if (placeholders(translated[key]) !== placeholders(expected[key])) problems.push(`${directory}/${language}.json: ${key} changes placeholders or literal tokens`)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -68,5 +77,5 @@ if (import.meta.filename === resolve(process.argv[1] ?? '')) {
|
||||
const problems = localeMetadataProblems(resolve(import.meta.dirname, '..'))
|
||||
for (const problem of problems) console.error(problem)
|
||||
if (problems.length > 0) process.exitCode = 1
|
||||
else console.log('verify-locale-metadata: all package and template metadata has complete Japanese translations.')
|
||||
else console.log('verify-locale-metadata: all package and template metadata has complete shipped-language translations.')
|
||||
}
|
||||
@@ -66,7 +66,7 @@ export function findUnavailableRepositoryReferences(file: string, source: string
|
||||
}
|
||||
|
||||
function trackedFiles(repoRoot: string): string[] {
|
||||
return execFileSync('git', ['ls-files', '-z'], { cwd: repoRoot, encoding: 'utf8' })
|
||||
return execFileSync('git', ['ls-files', '-z'], { cwd: repoRoot, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 })
|
||||
.split('\0')
|
||||
.filter(file => file !== '')
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user