Let's say we have a system in contact with a large reservoir. Let's also fix the number of particles in the system, as well its volume, so that the only thing that could be exchanged is energy. Now we know that any increase in entropy must be the sum of any increase in entropy in the system plus any increase in entropy in the reservoir:
$$dS_{total} = dS + dS_R.$$
Generally speaking, any change in entropy is due to the following factors:
$$dS = \frac{1}{T}dU + \frac{P}{T}dV + \frac{\mu}{T}dN.$$
But as we said above, we are fixing the volume and the number of particles, so in our case:
$$dS = \frac{1}{T}dU.$$
This is also true of the reservoir:
$$dS_R = \frac{1}{T_R}dU_R.$$
Putting this into our equation for the total entropy:
$$dS_{total} = dS + \frac{1}{T_R}dU_R.$$
We also know that any change in the energy of the system is a loss for the reservoir:
$$dU = -dU_R.$$
Up to here, I have no issues. However, the textbook I am looking at now makes the following assertion:
"...the temperature of the reservoir is the same as the temperature of the system,"
which means that $T_R = T$.
Substituting $T_R$ for $T$ and $U_R$ with $-U_R$:
$$dS_{total} = dS - \frac{1}{T}dU = -\frac{1}{T}(dU - TdS) = -\frac{1}{T}dF,$$
where F is the Helmholtz free energy, $U-TS$. In the other words, increasing total entropy involves lowering the system's Helmholtz free energy.
Using a similar argument, where the pressure, rather than the volume, is kept constant, it can be shown that $dS_{total} = -\frac{1}{T}dG$, where G is the Gibbs free energy, $U+PV-TS$.
Here's my dilemma: why do you assume that the temperature of the system is equal to that of the reservoir? Generally speaking, a system and its environment's temperatures wouldn't necessarily be the same.
Okay, so maybe the intent of all this is to imply that the equation only holds once the system has reached the same temperature as the reservoir. But if this were the case, would that really make sense? After all, since the system and the reservoir are the same temperature, there will be no net heat flow between the two. And in the first case, since the volume is fixed, there is no expansion of either the system or the reservoir. By the first law of thermodynamics, $U=W+Q$. We've already said that Q would have to be 0 and W cannot be an work that comes from a changing volume. This only leaves "other" work ("such as electrical work", whatever that even means). Then the equation would just say:
$$dS_{total} = dS + dS_R = \frac{1}{T}dU + \frac{1}{T}dU_R.$$
Since I don't really get what $W_{other}$ is, I can't say for sure that $dU_R = -dU$, but let's say it is so and that the reservoir is doing the "other" work on the system. Otherwise the assumption that $dU_R = -dU$ is wrong, which is specifically against the textbook's assumptions. So if we make this assumption then we get:
$$dS_{total} = \frac{1}{T}dU - \frac{1}{T}dU = 0.$$
So it's trivial: If they are the same temperature there is no heat flow, plus there is no expansion work done by constraint, and any "other" work done must increase one's entropy by the exact decrease in the other, since they are both at the same temperature.
So either $T_R=T$ and the answer is trivial, or $T_R\neq T$ which is not what the textbook said, making the textbook's whole derivation wrong.
Yet the textbook has to be correct so I must be wrong, but how?