Our legislation is far from ideal. It does not go as far as your legislation.
But the governments that listen to generals don't always listen wisely. If President Johnson had listened to the CIA analysts in relation to Vietnam, for example, that war would probably have ended much earlier. The massive buildup of American troops, and the lesser, but significant buildup of Australian troops, may never have occurred. President Johnson listened to General Westmoreland, not the CIA analysts.
So when listening to the generals, politicians are still going to make their own judgment. In the end, they are political decisions.