Skip to content

Commit d9bca16

Browse files
spoooshclaude
andcommitted
test(codec): env-gate AVIF encode tests for slow virtualised CI
The macos-14 GitHub runner has no hardware AV1 encoder, so the AVIF SwiftPM tests that go through ImageIO's software path can take many minutes per case. Phase 4 capped each AVIF test at .timeLimit(.minutes(1)) but a 4-case parameterised SSIM matrix plus avifBounds plus avifRoundTrip plus the .avif arm of the decoder dispatch sweep collectively blew past the workflow's 30-minute job-timeout on a cold \`swift test\`. Gate AVIF encode tests on \`IMAGECRC_TEST_SKIP_AVIF != 1\` (mirrors the existing IMAGECRC_TEST_REQUIRE_PNGQUANT pattern). Set the var to "1" at workflow level so CI skips the slow path; locally it stays unset so Apple Silicon hardware AV1 keeps them sub-second and they remain part of the regression net. The decoder-dispatch parameterised test filters .avif out of its arguments via a static helper instead of \`.enabled(if:)\`, since the gate applies to one of N cases rather than the whole test. AVIF DECODE remains untouched — only encode is the bottleneck. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ac7f74e commit d9bca16

5 files changed

Lines changed: 23 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ jobs:
2828
timeout-minutes: 30
2929
env:
3030
IMAGECRC_TEST_REQUIRE_PNGQUANT: "1"
31+
# AVIF software encoding on virtualised macos-14 runners (no hardware
32+
# AV1) can take minutes per file — even 4 quality cases blow past
33+
# job-timeout. Skip AVIF encode tests on CI; they remain enabled
34+
# locally where Apple Silicon hardware AV1 keeps them sub-second.
35+
IMAGECRC_TEST_SKIP_AVIF: "1"
3136
steps:
3237
- name: Checkout
3338
uses: actions/checkout@v4

Tests/CodecTests/EncoderSizeTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ struct EncoderSizeBoundsTests {
3737
}
3838

3939
@Test("AVIF q=80 output is smaller than raw, larger than zero",
40-
.timeLimit(.minutes(1)))
40+
.timeLimit(.minutes(1)),
41+
.enabled(if: ProcessInfo.processInfo.environment["IMAGECRC_TEST_SKIP_AVIF"] != "1"))
4142
func avifBounds() throws {
4243
let src = SyntheticImage.gradient(width: 256, height: 256)
4344
let data = try AVIFEncoder.encode(image: src, quality: 0.8)

Tests/CodecTests/ImageDecoderTests.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import Testing
66

77
@Suite("ImageDecoder — dispatch by InputFormat")
88
struct ImageDecoderDispatchTests {
9+
/// AVIF encode is slow on virtualised CI runners (no hardware AV1).
10+
/// Filter it out of the dispatch sweep when IMAGECRC_TEST_SKIP_AVIF=1.
11+
private static let formatsToTest: [InputFormat] = {
12+
let all: [InputFormat] = [.jpeg, .png, .heic, .avif, .webp]
13+
if ProcessInfo.processInfo.environment["IMAGECRC_TEST_SKIP_AVIF"] == "1" {
14+
return all.filter { $0 != .avif }
15+
}
16+
return all
17+
}()
18+
919
private func encodeAndWrap(
1020
format: InputFormat, in tmp: TempDirectory
1121
) throws -> ImageFile {
@@ -33,7 +43,7 @@ struct ImageDecoderDispatchTests {
3343
}
3444

3545
@Test("decode dispatches correctly for each raster InputFormat",
36-
arguments: [InputFormat.jpeg, .png, .heic, .avif, .webp])
46+
arguments: ImageDecoderDispatchTests.formatsToTest)
3747
func dispatch(_ format: InputFormat) throws {
3848
let tmp = try TempDirectory()
3949
let file = try encodeAndWrap(format: format, in: tmp)

Tests/CodecTests/ImageIOEncodersTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ struct ImageIOEncodersRoundTripTests {
4848
}
4949

5050
@Test("AVIF round-trip preserves dimensions",
51-
.timeLimit(.minutes(1)))
51+
.timeLimit(.minutes(1)),
52+
.enabled(if: ProcessInfo.processInfo.environment["IMAGECRC_TEST_SKIP_AVIF"] != "1"))
5253
func avifRoundTrip() throws {
53-
// AVIF encode is slow on macOS 14 — bound the test.
54+
// AVIF encode is slow on macOS 14 — bound the test. Virtualised CI
55+
// runners without hardware AV1 may take 10x longer; gate via env.
5456
let tmp = try TempDirectory()
5557
let src = SyntheticImage.gradient(width: 64, height: 32)
5658
let data = try AVIFEncoder.encode(image: src, quality: 0.8)

Tests/CodecTests/PerceptualQualityTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct HEICQualityMatrixTests {
8686
struct AVIFQualityMatrixTests {
8787
@Test("AVIF SSIM thresholds across quality matrix",
8888
.timeLimit(.minutes(1)),
89+
.enabled(if: ProcessInfo.processInfo.environment["IMAGECRC_TEST_SKIP_AVIF"] != "1"),
8990
arguments: [
9091
// macOS ImageIO AVIF rejects q=1.0 (lossless codepath unsupported);
9192
// q=0.99 is the practical ceiling — observed SSIM ≈ 0.9999.

0 commit comments

Comments
 (0)