11// Raster image adapter tests cover image operation integration with RasterMill.
2- import { afterEach , describe , expect , it , vi } from "vitest" ;
2+ import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
33
44describe ( "image ops Rastermill adapter" , ( ) => {
5+ beforeEach ( ( ) => {
6+ vi . resetModules ( ) ;
7+ } ) ;
8+
59 afterEach ( ( ) => {
610 vi . doUnmock ( "rastermill" ) ;
711 vi . doUnmock ( "@silvia-odwyer/photon-node" ) ;
@@ -10,18 +14,16 @@ describe("image ops Rastermill adapter", () => {
1014 } ) ;
1115
1216 it ( "does not load Photon for Rastermill-backed operations" , async ( ) => {
17+ const actualRastermill = await vi . importActual < typeof import ( "rastermill" ) > ( "rastermill" ) ;
1318 const encode = vi . fn ( async ( ) => ( { data : Buffer . from ( "jpeg" ) } ) ) ;
1419 const photonModuleFactory = vi . fn ( ( ) => {
1520 throw new Error ( "Photon loaded eagerly" ) ;
1621 } ) ;
1722
1823 vi . doMock ( "@silvia-odwyer/photon-node" , photonModuleFactory ) ;
1924 vi . doMock ( "rastermill" , ( ) => ( {
20- RastermillUnavailableError : class RastermillUnavailableError extends Error {
21- causes = [ ] ;
22- } ,
25+ ...actualRastermill ,
2326 createRastermill : vi . fn ( ( ) => ( { encode } ) ) ,
24- isRastermillUnavailableError : ( ) => false ,
2527 readImageMetadataFromHeader : vi . fn ( ( ) => ( { width : 1 , height : 1 } ) ) ,
2628 readImageProbeFromHeader : vi . fn ( ( ) => ( { width : 1 , height : 1 , format : "jpeg" } ) ) ,
2729 } ) ) ;
@@ -35,16 +37,14 @@ describe("image ops Rastermill adapter", () => {
3537 } ) ;
3638
3739 it ( "configures Rastermill with OpenClaw limits, temp root, and command resolution" , async ( ) => {
40+ const actualRastermill = await vi . importActual < typeof import ( "rastermill" ) > ( "rastermill" ) ;
3841 const encode = vi . fn ( async ( ) => ( { data : Buffer . from ( "jpeg" ) } ) ) ;
3942 const createRastermill = vi . fn ( ( _options : unknown ) => ( { encode } ) ) ;
4043 const resolveSystemBin = vi . fn ( ( ) => "/usr/bin/tool" ) ;
4144
4245 vi . doMock ( "rastermill" , ( ) => ( {
43- RastermillUnavailableError : class RastermillUnavailableError extends Error {
44- causes = [ ] ;
45- } ,
46+ ...actualRastermill ,
4647 createRastermill,
47- isRastermillUnavailableError : ( ) => false ,
4848 readImageMetadataFromHeader : vi . fn ( ( ) => ( { width : 1 , height : 1 } ) ) ,
4949 readImageProbeFromHeader : vi . fn ( ( ) => ( { width : 1 , height : 1 , format : "png" } ) ) ,
5050 } ) ) ;
@@ -79,19 +79,21 @@ describe("image ops Rastermill adapter", () => {
7979 } ) ;
8080
8181 it ( "exposes Rastermill unavailable errors through the SDK alias" , async ( ) => {
82- class RastermillUnavailableError extends Error {
83- readonly causes = [ new Error ( "missing backend" ) ] ;
84- }
82+ const actualRastermill = await vi . importActual < typeof import ( "rastermill" ) > ( "rastermill" ) ;
83+ const unavailableError = new actualRastermill . RastermillUnavailableError (
84+ "encode" ,
85+ "Image processor unavailable" ,
86+ [ new Error ( "missing backend" ) ] ,
87+ ) ;
8588 const createRastermill = vi . fn ( ( ) => ( {
8689 encode : vi . fn ( async ( ) => {
87- throw new RastermillUnavailableError ( "Image processor unavailable" ) ;
90+ throw unavailableError ;
8891 } ) ,
8992 } ) ) ;
9093
9194 vi . doMock ( "rastermill" , ( ) => ( {
92- RastermillUnavailableError ,
95+ ... actualRastermill ,
9396 createRastermill,
94- isRastermillUnavailableError : ( error : unknown ) => error instanceof RastermillUnavailableError ,
9597 readImageMetadataFromHeader : vi . fn ( ( ) => ( { width : 1 , height : 1 } ) ) ,
9698 readImageProbeFromHeader : vi . fn ( ( ) => ( { width : 1 , height : 1 , format : "png" } ) ) ,
9799 } ) ) ;
0 commit comments