A Question on Flatness of Complete Local Rings Let $f\colon A\to B$ be a morphism of finitely-generated $k$-algebras. Assume that $f$ is flat, and that $\mathfrak{p}=f^{-1}(\mathfrak{q})$ are the corresponding prime ideals. Then we have a flat local ring map $g\colon A_{\mathfrak{p}}\to B_{\mathfrak{q}}$, since this is the composition of $A_{\mathfrak{p}}\to B_{\mathfrak{p}}$ with $B_{\mathfrak{p}}\to B_{\mathfrak{q}}$. The first is flat via base change, since $B_{\mathfrak{p}}=B\otimes_A A_{\mathfrak{p}}$, the second is a localization.
Let $\hat{\mathfrak{p}}$ and $\hat{\mathfrak{q}}$ be the corredponding maximal ideals.
We moreover assume that $\hat{\mathfrak{p}}B_{\mathfrak{q}}=\hat{\mathfrak{q}}$, and that the residue fields of the two local rings are isomorphic. This implies the following:

*

*The local ring map of the completions
$\hat{g}\colon \hat{A}_{\mathfrak{p}}\to  \hat{B}_{\mathfrak{q}} 
$ is also a flat ring map.

*We have isomorphism $\hat{B}_{\mathfrak{q}} \cong \hat{A}_{\mathfrak{p}}\otimes_{A_{\mathfrak{p}}}  B_{\mathfrak{q}}$ .

Here is my question.
Now assume that $f\colon Spec(B)\to Spec(A); \mathfrak{q}\mapsto \mathfrak{p}$ is etale, then it forces $\hat{g}$ to be an isomorphism. Meanwhile, since $B_{\mathfrak{q}}$ is a flat $A_{\mathfrak{p}}$-module, it's free. Say $B_{\mathfrak{q}}\cong A_{\mathfrak{p}}^{\oplus n}$. Then we have
$$
\hat{B}_{\mathfrak{q}}\cong \hat{A}_{\mathfrak{p}}\otimes_{A_{\mathfrak{p}}}  B_{\mathfrak{q}} \cong \hat{A}_{\mathfrak{p}}^{\oplus n}
$$
This forces $n=1$ and $B_{\mathfrak{q}}\cong A_{\mathfrak{p}}$, which I believe is not true for etale morphisms.
Can anyone help me figuring out where I messed up in the above argument ?
Edit:
I think the problem might be that, $B_{\mathfrak{q}}\cong A_{\mathfrak{p}}$ as $A_{\mathfrak{p}}$-module via $g$ doesnot imply that $g$ is a ring isomorphism. But I cannot think of an example.
 A: Let’s slightly redefine the setting: $A$ and $B$ are noetherian local algebras essentially of finite type over a base field $k$, and we have a local étale $k$-morphism $A \rightarrow B$. Let us call $m$ the maximal ideal of $A$, and $\hat{-}$ is the $m$-adic completion. We want to prove that $\hat{B}$ is flat over $\hat{A}$.
Since $B$ is unramified over $A$, the residue field extension is finite. We can thus find $b_1,\ldots,b_n \in B$ such that they form a basis of $B/m$ over $A/m$. In particular, for every $t \geq 0$, $B/m^t$ is flat over $A/m^t$ thus free, and by the above it is free of rank $n$.
Consider the morphism $\psi: A^n \rightarrow B$ mapping $e_i$ to $b_i$. By assumption, if $P=\psi(A^n)$, then $B=mB+P$. By induction, for every $t \geq 1$, $B=m^tB+P$, so that $\psi \otimes A/m^t$ is a surjection of free modules of same rank over a local ring, so it is an isomorphism. Thus the map $\hat{A}^n \rightarrow \hat{B}$ sending the $i$-th basis element to $b_i$ is an isomorphism. So $\hat{B}$ is free, hence flat, over $\hat{A}$.
