diff --git a/scripts/translation-links.spec.ts b/scripts/translation-links.spec.ts index de87dc500a..f5f6a7a611 100644 --- a/scripts/translation-links.spec.ts +++ b/scripts/translation-links.spec.ts @@ -64,16 +64,8 @@ describe('translation link locale validation', () => { }) }) - it('normalizes an English extensionless file alias but retains a directory-index alias', () => { + it('retains an English directory-index alias', () => { const root = fixture() - expect(translationLinkLocaleViolations( - '[Reference](reference)\n', - { repoRoot: root, sourcePath: 'docs/guide.md' }, - )[0]).toMatchObject({ expectedUrl: 'reference.md' }) - expect(rewriteTranslationLinkLocales( - '[Reference](reference)\n', - { repoRoot: root, sourcePath: 'docs/guide.md' }, - ).content).toBe('[Reference](reference.md)\n') expect(translationLinkLocaleViolations( '[Section](section/)\n', { repoRoot: root, sourcePath: 'docs/guide.md' }, diff --git a/scripts/translation-links.ts b/scripts/translation-links.ts index 8346e401bf..fec370ecac 100644 --- a/scripts/translation-links.ts +++ b/scripts/translation-links.ts @@ -58,7 +58,7 @@ interface Replacement { } type LinkNode = Extract -type ResolutionKind = 'exact' | 'extensionless' | 'directory-index' +type ResolutionKind = 'exact' | 'directory-index' function decodePath(path: string): string { try { @@ -101,14 +101,8 @@ function resolveRepositoryTarget( if (decoded.endsWith('/') && index !== undefined && repositoryFileExists(context, index)) { return { path: index, kind: 'directory-index' } } - if (posix.extname(decoded) === '') { - const markdown = repositoryRelativePath(`${exact}.md`) - if (markdown !== undefined && repositoryFileExists(context, markdown)) { - return { path: markdown, kind: 'extensionless' } - } - if (index !== undefined && repositoryFileExists(context, index)) { - return { path: index, kind: 'directory-index' } - } + if (posix.extname(decoded) === '' && index !== undefined && repositoryFileExists(context, index)) { + return { path: index, kind: 'directory-index' } } return undefined } @@ -142,7 +136,6 @@ function expectedLocalePath( } if (locale === 'en' && rawPath.endsWith('.zh.md')) return rawPath.replace(/\.zh\.md$/, '.md') } - if (kind === 'extensionless') return `${rawPath}${locale === 'zh' ? '.zh.md' : '.md'}` if (kind === 'directory-index' && locale === 'zh') { return `${rawPath}${rawPath.endsWith('/') ? '' : '/'}index.zh.md` } @@ -177,8 +170,7 @@ function resolveTranslationLink( } function hasExpectedLocale(resolved: ResolvedTranslationLink): boolean { - if (resolved.targetPath !== resolved.expectedPath) return false - return !(resolved.locale === 'en' && resolved.kind === 'extensionless') + return resolved.targetPath === resolved.expectedPath } function replacementFor(destination: MarkdownDestination, value: string): Replacement { diff --git a/scripts/translation-pairing.spec.ts b/scripts/translation-pairing.spec.ts index 94c31325a8..96de451189 100644 --- a/scripts/translation-pairing.spec.ts +++ b/scripts/translation-pairing.spec.ts @@ -32,7 +32,11 @@ import { } from './translation-pairing.ts' function signature(markdown: string) { - return translationStructureSignature(parseTranslationMarkdown(markdown), 'counterpart.zh.md') + return translationStructureSignature( + parseTranslationMarkdown(markdown), + 'counterpart.zh.md', + { repoRoot: process.cwd(), sourcePath: 'counterpart.md', markdown }, + ) } function gitSupportsObjectFormat(format: 'sha256'): boolean { @@ -189,7 +193,11 @@ describe('translation pairing switchers', () => { ) expect(linksTo(canonical, targets)).toBe(true) - expect(translationStructureSignature(canonical, targets).links).toEqual([]) + expect(translationStructureSignature(canonical, targets, { + repoRoot: process.cwd(), + sourcePath: 'python/sdk/README.md', + markdown: '[中文](https://github.com/deepseek-ai/deepseek-harness/blob/master/python/sdk/README.zh.md)', + }).links).toEqual([]) expect(linksTo(wrongPath, targets)).toBe(false) }) }) diff --git a/scripts/translation-pairing.ts b/scripts/translation-pairing.ts index 24fa487417..db3e3e10ea 100644 --- a/scripts/translation-pairing.ts +++ b/scripts/translation-pairing.ts @@ -351,7 +351,7 @@ export function requiresSourceLanguageSwitcher(source: string): boolean { export function translationStructureSignature( tree: Nodes, switcherTargets: string | readonly string[], - linkContext?: TranslationLinkContext & { markdown: string }, + linkContext: TranslationLinkContext & { markdown: string }, ): TranslationStructureSignature { const acceptedSwitchers = new Set( typeof switcherTargets === 'string' ? [switcherTargets] : switcherTargets, @@ -364,9 +364,7 @@ export function translationStructureSignature( } collectDefinitions(tree) const linkTarget = (node: Extract): string => ( - linkContext === undefined - ? node.url - : semanticTranslationLinkNodeTarget(node, linkContext.markdown, linkContext) + semanticTranslationLinkNodeTarget(node, linkContext.markdown, linkContext) ) const visit = (node: Nodes): void => { switch (node.type) {