The definition of work done in moving from position $A$ to position $B$ is $W_{\text{A to B}} =\displaystyle \int_{\rm A}^{\rm B} \vec F(\rm position) \cdot d\vec s$ where $\vec F(\rm position)$ can depend on position ie it does not have to be constant and $d\vec s$ is an incremental displacement of the force.
For a point mass $m$ Newton's second law can be stated as $\vec F =m\vec a = m \dfrac{d\vec v}{dt}$
The work done on the point mass in moving from position $A$ to position $B$ is
$\displaystyle \int_{\rm A}^{\rm B} m \dfrac{d\vec v}{dt} \cdot d\vec s = \int_{\rm A}^{\rm B} m \,d\vec v \cdot \dfrac{d\vec s}{dt} = \int_{\rm A}^{\rm B} m \vec v \cdot d\vec v=\int_{\rm A}^{\rm B} m \left (v_{\rm x} \hat x+v_{\rm y} \hat y+v_{\rm z} \hat z \right)\cdot \left ( dv_{\rm x} \hat x+dv_{\rm y} \hat y+dv_{\rm z} \hat z\right )$
On doing the integration the result is $\frac 12 m v^2_{\rm B} - \frac 12 m v^2_{\rm A}$ which is the change in kinetic energy.
where $v^2_{\rm B} = v^2_{\rm B,x}+v^2_{\rm B,y}+v^2_{\rm B,z}$ and $v^2_{\rm A} = v^2_{\rm A,x}+v^2_{\rm A,y}+v^2_{\rm A,z}$.
So the work done on a point mass is equal to the change in kinetic energy of the mass even if the force is not constant.
Your introduction of potential energy means that you cannot just be considering a point mass and there must be another mass involved, the two masses being the system under consideration.
It is often the case that an assumption is made that the other mass is very much more massive than the point mass $m$ under consideration and so the other mass does not move when the point mass moves.
In such a case the change in the potential energy of the point mass (and the other mass) when mass $m$ moves from position $A$ to position $B$ is $U_{\rm B}-U_{\rm A} =\displaystyle -\int_{\rm A}^{\rm B} \vec F(\rm position) \cdot d\vec s$