An alliance with Poland in 1386 led the two countries into a union through the person of a common ruler .