|
534 | 534 |
|
535 | 535 | print(" ✓ No compression applied by default") |
536 | 536 |
|
| 537 | + @setup_s3() |
| 538 | + def test_nix_prefetch_url(bucket): |
| 539 | + """Test that nix-prefetch-url retrieves actual file content from S3, not empty files (issue #8862)""" |
| 540 | + print("\n=== Testing nix-prefetch-url S3 Content Retrieval (issue #8862) ===") |
| 541 | +
|
| 542 | + # Create a test file with known content |
| 543 | + test_content = "This is test content to verify S3 downloads work correctly!\n" |
| 544 | + test_file_size = len(test_content) |
| 545 | +
|
| 546 | + server.succeed(f"echo -n '{test_content}' > /tmp/test-file.txt") |
| 547 | +
|
| 548 | + # Upload to S3 |
| 549 | + server.succeed(f"mc cp /tmp/test-file.txt minio/{bucket}/test-file.txt") |
| 550 | +
|
| 551 | + # Calculate expected hash |
| 552 | + expected_hash = server.succeed( |
| 553 | + "nix hash file --type sha256 --base32 /tmp/test-file.txt" |
| 554 | + ).strip() |
| 555 | +
|
| 556 | + print(f" ✓ Uploaded test file to S3 ({test_file_size} bytes)") |
| 557 | +
|
| 558 | + # Use nix-prefetch-url to download from S3 |
| 559 | + s3_url = make_s3_url(bucket, path="/test-file.txt") |
| 560 | +
|
| 561 | + prefetch_output = client.succeed( |
| 562 | + f"{ENV_WITH_CREDS} nix-prefetch-url --print-path '{s3_url}'" |
| 563 | + ) |
| 564 | +
|
| 565 | + # Extract hash and store path |
| 566 | + # With --print-path, output is: <hash>\n<store-path> |
| 567 | + lines = prefetch_output.strip().split('\n') |
| 568 | + prefetch_hash = lines[0] # First line is the hash |
| 569 | + store_path = lines[1] # Second line is the store path |
| 570 | +
|
| 571 | + # Verify hash matches |
| 572 | + if prefetch_hash != expected_hash: |
| 573 | + raise Exception( |
| 574 | + f"Hash mismatch: expected {expected_hash}, got {prefetch_hash}" |
| 575 | + ) |
| 576 | +
|
| 577 | + print(" ✓ nix-prefetch-url completed with correct hash") |
| 578 | +
|
| 579 | + # Verify the downloaded file is NOT empty (the bug in #8862) |
| 580 | + file_size = int(client.succeed(f"stat -c %s {store_path}").strip()) |
| 581 | +
|
| 582 | + if file_size == 0: |
| 583 | + raise Exception("Downloaded file is EMPTY - issue #8862 regression detected!") |
| 584 | +
|
| 585 | + if file_size != test_file_size: |
| 586 | + raise Exception( |
| 587 | + f"File size mismatch: expected {test_file_size}, got {file_size}" |
| 588 | + ) |
| 589 | +
|
| 590 | + print(f" ✓ File has correct size ({file_size} bytes, not empty)") |
| 591 | +
|
| 592 | + # Verify actual content matches by comparing hashes instead of printing entire file |
| 593 | + downloaded_hash = client.succeed(f"nix hash file --type sha256 --base32 {store_path}").strip() |
| 594 | +
|
| 595 | + if downloaded_hash != expected_hash: |
| 596 | + raise Exception(f"Content hash mismatch: expected {expected_hash}, got {downloaded_hash}") |
| 597 | +
|
| 598 | + print(" ✓ File content verified correct (hash matches)") |
| 599 | +
|
537 | 600 | # ============================================================================ |
538 | 601 | # Main Test Execution |
539 | 602 | # ============================================================================ |
|
562 | 625 | test_compression_narinfo_gzip() |
563 | 626 | test_compression_mixed() |
564 | 627 | test_compression_disabled() |
| 628 | + test_nix_prefetch_url() |
565 | 629 |
|
566 | 630 | print("\n" + "="*80) |
567 | 631 | print("✓ All S3 Binary Cache Store Tests Passed!") |
|
0 commit comments