The corn + alkali could have come about from a chance combination with wood ashes.
As for the cacao beans, I've read that originally the fruit pulp was eaten fresh.* The pulp is juicy and sweet, the seeds are bitter. Perhaps someone left the fresh beans + pulp in a heap and accidentally left it to ferment, then accidentally got fire in contact with the fermented beans... and the rest is history.
*Recommended: Young, Allen M. The Chocolate Tree: A Natural History of Cacao. 1194: Smithsonian Institution Press, Washington, DC and London. 200 pp.
Those are very reasonable scenarios. But the cleverness and inventiveness of “primitive” peoples is still impressive and humbling. Take the development of maize from an insignificant plant, or dozens of potato varieties from a plant whose foliage and young green tubers are full of toxic alkaloids. Today the same adaptations would be expected to require a huge team of Archer Daniels Midland scientists and a budget in 8 to 9 figures.