Skip to content

Commit 6d194f2

Browse files
pditommasoclaude
andcommitted
Fix AzureRepositoryProvider readBytes method for binary content
Changed Azure API call from JSON-embedded content to direct binary download using 'download: true' parameter. This prevents binary data corruption that occurred when converting JSON-escaped strings back to bytes. The test now passes with correct file size (22,915 bytes) and SHA256 hash. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 592a259 commit 6d194f2

4 files changed

Lines changed: 38 additions & 23 deletions

File tree

modules/nextflow/src/main/groovy/nextflow/scm/AzureRepositoryProvider.groovy

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,35 @@ final class AzureRepositoryProvider extends RepositoryProvider {
183183
"${config.server}/${urlPath}"
184184
}
185185

186-
/** {@inheritDoc} */
187186
@Override
188-
byte[] readBytes(String path) {
187+
String readText( String path ) {
189188
final url = getContentUrl(path)
190189
final response = invokeAndParseResponse(url)
191-
return response.get('content')?.toString()?.getBytes()
190+
return response.get('content')?.toString()
191+
}
192+
193+
/** {@inheritDoc} */
194+
@Override
195+
byte[] readBytes(String path) {
196+
// For binary content, use direct download instead of JSON embedding
197+
final queryParams = [
198+
'download': true,
199+
'includeContent': false,
200+
'includeContentMetadata': false,
201+
"api-version": 6.0,
202+
'path': path
203+
] as Map<String,Object>
204+
205+
if( revision ) {
206+
queryParams['versionDescriptor.version'] = revision
207+
if( COMMIT_REGEX.matcher(revision).matches() )
208+
queryParams['versionDescriptor.versionType'] = 'commit'
209+
}
210+
211+
final queryString = queryParams.collect({ "$it.key=$it.value"}).join('&')
212+
final url = "$endpointUrl/items?$queryString"
213+
// Use invokeBytes for direct binary content download
214+
return invokeBytes(url)
192215
}
193216

194217
}

modules/nextflow/src/test/groovy/nextflow/cli/CmdConfigTest.groovy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import nextflow.extension.FilesEx
2424
import nextflow.plugin.Plugins
2525
import nextflow.secret.SecretsLoader
2626
import spock.lang.IgnoreIf
27+
import spock.lang.Requires
2728
import spock.lang.Specification
2829
/**
2930
*
@@ -384,10 +385,12 @@ class CmdConfigTest extends Specification {
384385

385386
}
386387

387-
388388
@IgnoreIf({System.getenv('NXF_SMOKE')})
389+
@Requires({System.getenv('NXF_GITHUB_ACCESS_TOKEN')})
389390
def 'should resolve remote config' () {
390391
given:
392+
SysEnv.push(GITHUB_TOKEN: System.getenv('NXF_GITHUB_ACCESS_TOKEN'))
393+
and:
391394
def buffer = new ByteArrayOutputStream()
392395
def cmd = new CmdConfig(
393396
args: ['https://github.com/nextflow-io/hello'],
@@ -404,6 +407,9 @@ class CmdConfigTest extends Specification {
404407
}
405408
'''
406409
.stripIndent()
410+
411+
cleanup:
412+
SysEnv.pop()
407413
}
408414

409415
@IgnoreIf({System.getenv('NXF_SMOKE')})

modules/nextflow/src/test/groovy/nextflow/scm/AzureRepositoryProviderTest.groovy

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ import nextflow.exception.AbortOperationException
2020
import spock.lang.IgnoreIf
2121
import spock.lang.Requires
2222
import spock.lang.Specification
23-
24-
import javax.imageio.ImageIO
25-
import javax.imageio.stream.MemoryCacheImageInputStream
26-
2723
/**
2824
*
2925
* @author Tobias Neumann <tobias.neumann.at@gmail.com>
@@ -153,11 +149,7 @@ class AzureRepositoryProviderTest extends Specification {
153149

154150
then:
155151
result.length == 22915
156-
and:
157-
def inputStream = new ByteArrayInputStream(result)
158-
def imageInput = new MemoryCacheImageInputStream(inputStream)
159-
final readers = ImageIO.getImageReaders(imageInput)
160-
readers.hasNext()
152+
result.sha256() == '7a396344498750f614155f6e4f38b7d6ca98ced45daf0921b64acf73b18efaf4'
161153
}
162154

163155

modules/nextflow/src/test/groovy/nextflow/scm/GiteaRepositoryProviderTest.groovy

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ package nextflow.scm
1919
import spock.lang.IgnoreIf
2020
import spock.lang.Requires
2121
import spock.lang.Specification
22-
23-
import javax.imageio.ImageIO
24-
import javax.imageio.stream.MemoryCacheImageInputStream
25-
2622
/**
2723
*
2824
* @author Akira Sekiguchi <pachiras.yokohama@gmail.com>
@@ -112,20 +108,18 @@ class GiteaRepositoryProviderTest extends Specification {
112108

113109

114110
@IgnoreIf({System.getenv('NXF_SMOKE')})
115-
@Requires({System.getenv('NXF_AZURE_REPOS_TOKEN')})
111+
@Requires({System.getenv('NXF_GITEA_ACCESS_TOKEN')})
116112
def 'should read bytes file content'() {
117113
given:
118114
def token = System.getenv('NXF_GITEA_ACCESS_TOKEN')
119115
def config = new ProviderConfig('gitea', new ConfigSlurper().parse(CONFIG).providers.mygitea as ConfigObject).setAuth(token)
120116

121117
when:
122-
def repo = new GiteaRepositoryProvider('swingingsimiangitea/rnaseq', config)
118+
def repo = new GiteaRepositoryProvider('pditommaso/test-hello', config)
123119
def result = repo.readBytes('docs/images/nf-core-rnaseq_logo_light.png')
124120

125121
then:
126-
def inputStream = new ByteArrayInputStream(result)
127-
def imageInput = new MemoryCacheImageInputStream(inputStream)
128-
final readers = ImageIO.getImageReaders(imageInput)
129-
readers.hasNext()
122+
result.length == 22915
123+
result.sha256() == '7a396344498750f614155f6e4f38b7d6ca98ced45daf0921b64acf73b18efaf4'
130124
}
131125
}

0 commit comments

Comments
 (0)