Just thought I'd report an issue that I ran into that might - or might not - be a bug. I have a file-handling class that has been working fine in unit tests and within Controllers. However, when I wrote a task that used it, it failed to behave as expected.
After a bit of digging, it turned out to be that the DOCROOT constant is defined differently within tasks. Usually it points to the /public directory, but within a task, it's defined as the project root (ie. one directory above /public). My config files defined a couple of directory locations relative to DOCROOT, so these were no longer being located correctly when accessed from within the task.
I fixed this by defining them relative to APPPATH instead, which seems to work (perhaps that's what I should have done all along), but thought I'd report this because it was unexpected behaviour and seems like a possible bug.
This has been discussed for at least 3 years now. ;-)
Short answer: there is no way the oil frontloader can determine what your definition of DOCROOT is, so it's set to a default value the same way it's done in index.php.
If you have a need to make it the same, you have to modify it yourself.