Compare PDFs with ImageMagick compare

We are trying visually compare PDFs with ImageMagick compare. On my local machine everything works great but on the CircleCI tests always pass even if it should be broken and it prints following message:

compare: unable to open image `/home/ubuntu/app/public/files/pdfs/697/199/423_697199423_F3QL2aXzxR.pdf':  @ error/blob.c/OpenBlob/2587.

PDFs are deleted after compare comand is executed so generated file should be there during comparison. When I commented removal code, I’ve got following message:

/home/ubuntu/app/test/fixtures/pdfs/golden_copy.pdf[0] PDF 595x842 595x842+0+0 16-bit DirectClass 30.8KB 0.020u 0:00.370
/home/ubuntu/app/public/files/pdfs/548/159/561_548159561_aeEr5tddp4.pdf[0] PDF 595x842 595x842+0+0 16-bit DirectClass 30.6KB 0.010u 0:00.019
352.253 (0.00537503)

As a test we are using following commands:

golden = "/path/to/golden/file.pdf"
generated = "/path/to/generated/file.pdf"
diff = "/path/to/diff/file.pdf"
command   = "compare -identify -metric MAE #{golden} #{generated} -compose src #{diff} &> /dev/null"
assert system(command), "Diff #{diff} - Generated PDF: #{generated}"

File.delete(generated)
File.delete(diff)

This code pass every time on the CircleCI but it works on our local machines.

Thank you for your help.

Could you please rerun the build with SSH enabled and check how can you get the file opened on CircleCI without the error? Looks essential to me to make it open the file before proceeding to the comparison.