[ -e (ahci0,gpt1) ] works only if device is mounted.
IMHO it should work always if device exist and use following to check if filesystem is mounted
[ -e (ahci0,gpt1)/ ] works only if device is mounted.
test is implemented in grub-core/commands/test.c
get_fileinfo() seems to be reponsible for a lot of bad assumptions
expand if (! fs) and keep track of (.*)/ trailing /
if (! fs)
Or check before fs = grub_fs_probe (dev); if strings is equal to device_name (so without any trailing characters) and if so - return true for device before if (! fs) . Probably checking path length would be enough in that place
fs = grub_fs_probe (dev);