Fix some linting/PR comments

This commit is contained in:
Daniel Kennedy
2026-03-10 16:59:38 -04:00
parent addd65e9eb
commit 2bb523088e
2 changed files with 45 additions and 46 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
## 6.2.1 ## 6.2.1
- Support the RFC 5987 `filename*` field in the `content-disposition` header. This allows us to correctly upload and download files and artifacts with Chinese/Japanese/Korean (among other) characters in their name. - Support the RFC 5987 `filename*` field in the `content-disposition` header. This allows us to correctly download files and artifacts with Chinese/Japanese/Korean (among other) characters in their name.
## 6.2.0 ## 6.2.0
@@ -1020,15 +1020,14 @@ describe('download-artifact', () => {
// Simulate Azure Blob Storage URL with rscd containing Chinese filename // Simulate Azure Blob Storage URL with rscd containing Chinese filename
const chineseArtifactName = 'probe-土-x' const chineseArtifactName = 'probe-土-x'
const asciiArtifactName = 'probe-_-x' const asciiArtifactName = 'probe-_-x'
const blobUrlWithChineseName = const blobUrlWithChineseName = `https://blob-storage.local/artifact.zip?rscd=${encodeURIComponent(`attachment; filename="${asciiArtifactName}.zip"; filename*=UTF-8''${encodeURIComponent(`${chineseArtifactName}.zip`)}`)}&rsct=application%2Fzip&sig=abc123`
`https://blob-storage.local/artifact.zip?rscd=${encodeURIComponent(`attachment; filename="${asciiArtifactName}.zip"; filename*=UTF-8''${encodeURIComponent(chineseArtifactName + '.zip')}`)}&rsct=application%2Fzip&sig=abc123`
const mockGetZip = jest.fn(() => { const mockGetZip = jest.fn(() => {
const message = new http.IncomingMessage(new net.Socket()) const message = new http.IncomingMessage(new net.Socket())
message.statusCode = 200 message.statusCode = 200
message.headers['content-type'] = 'application/zip' message.headers['content-type'] = 'application/zip'
message.headers['content-disposition'] = message.headers['content-disposition'] =
`attachment; filename="${asciiArtifactName}.zip"; filename*=UTF-8''${encodeURIComponent(chineseArtifactName + '.zip')}` `attachment; filename="${asciiArtifactName}.zip"; filename*=UTF-8''${encodeURIComponent(`${chineseArtifactName}.zip`)}`
message.push(fs.readFileSync(fixtures.exampleArtifact.path)) message.push(fs.readFileSync(fixtures.exampleArtifact.path))
message.push(null) message.push(null)
return { return {
@@ -1044,10 +1043,7 @@ describe('download-artifact', () => {
} }
) )
await streamExtractExternal( await streamExtractExternal(blobUrlWithChineseName, fixtures.workspaceDir)
blobUrlWithChineseName,
fixtures.workspaceDir
)
expect(mockHttpClient).toHaveBeenCalledWith(getUserAgentString()) expect(mockHttpClient).toHaveBeenCalledWith(getUserAgentString())
// Zip should be extracted normally regardless of Chinese artifact name // Zip should be extracted normally regardless of Chinese artifact name
@@ -1055,48 +1051,51 @@ describe('download-artifact', () => {
}) })
it.each([ it.each([
['土', '_', 'U+571F - known to cause 400 errors'], ['土', '_'], // U+571F - known to cause 400 errors
['日', '_', 'U+65E5 - reported to work fine'], ['日', '_'], // U+65E5 - reported to work fine
['中文测试', '____', 'multiple Chinese characters'], ['中文测试', '____'], // multiple Chinese characters
['文件-2026年', '__-2026_', 'mixed Chinese and numbers'], ['文件-2026年', '__-2026_'], // mixed Chinese and numbers
['データ', '___', 'Japanese katakana'], ['データ', '___'], // Japanese katakana
['테스트', '___', 'Korean characters'] ['테스트', '___'] // Korean characters
])('should prefer filename* over filename for non-ASCII character %s (%s)', async (chars, asciiReplacement, _description) => { ])(
const rawFileContent = `content for ${chars}` 'should prefer filename* over filename for non-ASCII character %s (%s)',
const expectedFileName = `artifact-${chars}.txt` async (chars, asciiReplacement) => {
const asciiFileName = `artifact-${asciiReplacement}.txt` const rawFileContent = `content for ${chars}`
const expectedFileName = `artifact-${chars}.txt`
const asciiFileName = `artifact-${asciiReplacement}.txt`
const mockGetFile = jest.fn(() => { const mockGetFile = jest.fn(() => {
const message = new http.IncomingMessage(new net.Socket()) const message = new http.IncomingMessage(new net.Socket())
message.statusCode = 200 message.statusCode = 200
message.headers['content-type'] = 'text/plain' message.headers['content-type'] = 'text/plain'
// Server sends filename with _ replacing non-ASCII, filename* with proper encoding // Server sends filename with _ replacing non-ASCII, filename* with proper encoding
message.headers['content-disposition'] = message.headers['content-disposition'] =
`attachment; filename="${asciiFileName}"; filename*=UTF-8''${encodeURIComponent(expectedFileName)}` `attachment; filename="${asciiFileName}"; filename*=UTF-8''${encodeURIComponent(expectedFileName)}`
message.push(Buffer.from(rawFileContent, 'utf8')) message.push(Buffer.from(rawFileContent, 'utf8'))
message.push(null) message.push(null)
return {
message
}
})
const mockHttpClient = (HttpClient as jest.Mock).mockImplementation(
() => {
return { return {
get: mockGetFile message
} }
} })
)
await streamExtractExternal( const mockHttpClient = (HttpClient as jest.Mock).mockImplementation(
fixtures.blobStorageUrl, () => {
fixtures.workspaceDir return {
) get: mockGetFile
}
}
)
expect(mockHttpClient).toHaveBeenCalledWith(getUserAgentString()) await streamExtractExternal(
const savedFilePath = path.join(fixtures.workspaceDir, expectedFileName) fixtures.blobStorageUrl,
expect(fs.existsSync(savedFilePath)).toBe(true) fixtures.workspaceDir
expect(fs.readFileSync(savedFilePath, 'utf8')).toBe(rawFileContent) )
})
expect(mockHttpClient).toHaveBeenCalledWith(getUserAgentString())
const savedFilePath = path.join(fixtures.workspaceDir, expectedFileName)
expect(fs.existsSync(savedFilePath)).toBe(true)
expect(fs.readFileSync(savedFilePath, 'utf8')).toBe(rawFileContent)
}
)
}) })
}) })