Hi Simon!
I tried like you said and the context+requestor works in both cli and ui. But when I add the spider, it works only in Desktop(found around 20 urls in Desktop; in CLI found only 4 urls. By the way the requestor still working in this situation). In other words, spider can't make authentication.
I decided to do an experiment. First, I launched AF via desktop - successfully, the spider found 20 urls. Next, I imported this yaml and ran it through the cli - there were only 4 urls. Now I decided to turn off the zap desktop and turn it on again and run it using the same yaml that I imported earlier - there were also 4 urls.
I looked at the logs, but there are no errors in both, except for one: ERROR JobUtils - Automation Framework failed to find method setUser on org.zaproxy.zap.spider.SpiderParam. This error is present in both scans (desktop and cli). Don't know what's the problem
But I noticed a difference in the logs: when the spider successfully authorizes, the following logs appear after ending spider:
[HSQLDB Timer @14505ee0] INFO ENGINE - Checkpoint start
[HSQLDB Timer @14505ee0] INFO ENGINE - checkpointClose start
[HSQLDB Timer @14505ee0] INFO ENGINE - checkpointClose synched
[HSQLDB Timer @14505ee0] INFO ENGINE - checkpointClose script done
[HSQLDB Timer @14505ee0] INFO ENGINE - dataFileCache commit start