Defining extremeness of test statistic and defining $p$-value for a two-sided test Our tag definition of the $p$-value says

In frequentist hypothesis testing, the $p$-value is the probability of a result as extreme (or more) than the observed result, under the assumption that the null hypothesis is true.

But how do we define what is more extreme? In "A Dialog Between a Teacher and a Thoughtful Student", @whuber shows that extreme can be defined w.r.t. the likelihood ratio under $H_0$ vs. $H_1$ (or $H_A$ in the original notation), $LR=\frac{P(data|H_1)}{P(data|H_0)}$. The larger the LR, the more extreme the result. So far so good.
In @whuber's example, $H_0$ is one-sided, and so is $H_1$. Then it is not so difficult to find which regions of values of the test statistic produce the largest LRs. Thus we have little conceptual trouble in finding the $p$-value; we just integrate the area under the null distribution for all possible values of the test statistic that are equally or more extreme (have equal or larger LR) than the observed value.
However, it is not so clear when $H_1$ is two sided, such as in a two-sided $t$-test. While the left tail of the null distribution would produce the largest LRs for an alternative to the left of the hypothesized value in $H_0$, the left tail would not at all be extreme for an alternative to the right of $H_0$; in fact, it would be the opposite tail that would be extreme. The problem is, both alternatives belong to $H_1$.
Q: How do we deal with such a situation? What is the principled way of defining extremeness when contradicting levels of LRs can arise under different instances within $H_1$?
P.S. I have earlier asked a related question of whether $p$-value ever depends on the alternative. I learned that using the modern (post Fisher) definition of the $p$-value, it does.
Update: I have received a few good answers, but I am still struggling with the intuition: see my comment.
 A: 
Defining extremeness of test statistic and defining p-value for a
two-sided test...

I would suggest that an appropriate perspective here is that, when one has the "right" statistic, the statistic itself tells you what "extremeness" means for the test problem at hand---one-sided or two-sided. The more basic question is therefore what the "right" statistic is. Test problems are special cases of optimization problems---you want to maximize power subject to size constraint. So this means defining the "right" solution concept.
For example, finding the most powerful test for the test problem with a simple null vs. simple alternative is a special case of a linear program:
$$
\sup_{0 \leq \phi \leq 1, \, \\ \\ \int \phi(\omega) f_0(\omega) d\mu \leq \alpha} \int \phi(\omega) f_1(\omega) d\mu.
$$
It is a general fact that a solution $\phi^*$for any such program takes the form
$$
\phi^* = 
  \begin{cases}
    1 & \text{if } f_1 \geq k f_0 \\
    0 & \text{if } f_1 \geq k f_0, 
  \end{cases} 
$$
for some $k$. In the context of a test problem, a natural interpretation is then that one rejects when the likelihood ratio statistic $\frac{f_1}{f_0}$ is larger than $k$.
(It is suggested in the comments that the threshold $k$ is interpreted to be the "shadow price" of the size constraint. Apparently this terminology is borrowed from economics. $k$ is the Kuhn-Tucker-Lagrange multiplier of the problem. For interior solutions, typically one would say that if $\alpha$---the budget, in economic problems---is relaxed by $\epsilon$, the power of the test increases by $k \epsilon$. This interpretation, however, does not really hold for linear programs in general.)
Similarly, finding a most powerful test of composite null vs. simple alternative amounts to solving a linear program. The solution to the corresponding dual program tells us that the most powerful statistic is a likelihood ratio statistic with respect to the least favorable Bayesian prior on the null. (The simple null case is a special case, with trivial prior.)
Tests with one-sided alternatives for models with monotone likelihood ratio (MLR) property is of course another example. MLR means the model admits a ranking of likelihood ratios that's invariant with respect to data $\omega$. So the likelihood ratio test is a most powerful test, almost by assumption.
For two-sided alternatives, e.g. $\Gamma_0 = \{\gamma_0\}$ and $\Gamma_1 = (-\infty,\gamma_0)\cup (\gamma_0, \infty)$ for normal densities parametrized by mean $\gamma \in \mathbb{R}$, the most powerful test does not exist in general. Therefore the right statistic needs to be determined by some other criterion---e.g. one can instead look for a locally most powerful test.
A test $\phi^*$ is a locally most powerful test if for any other test $\phi$, there exists an open neighborhood $N_{\gamma_0, \phi}$ of the null hypothesis such that $\phi^*$ has uniformly higher power than $\phi$ on $N_{\gamma_0, \phi}$. The corresponding first-order optimality condition gives the criterion
$$
\phi^* = 
  \begin{cases}
    1 & \text{if } \frac{\partial^2}{\partial \gamma^2}f_{\gamma_0} \geq k_1 \frac{\partial}{\partial \gamma} f_{\gamma_0} + k_2 f_{\gamma_0}  \\
    0 & \text{if } \frac{\partial^2}{\partial \gamma^2}f_{\gamma_0} < k_1 \frac{\partial}{\partial \gamma} f_{\gamma_0} + k_2 f_{\gamma_0} 
  \end{cases} 
$$
for some $k_1$ and $k_2$. Substituting the normal density into above expressions, we have that $\phi^*$ rejects when $|x- \gamma_0|$ is large---a two-sided test.
A: In addition to scenarios in two-sided tests, this question arises in a less avoidable way in group sequential clinical trials.
In a group sequential trial there are a set of analysis times, and a stopping boundary specifying thresholds at each analysis for the trial to stop.  In calculating $p$-values or confidence intervals it is necessary to specify a ordering of the possible outcomes. For example, if you stop at time 2 out of 4 with a $Z$-score of 3, how does that compare to stopping at time 3 with a $Z$-score of 2.5?
Among the orderings actually proposed are

*

*ordering by the magnitude of difference

*ordering by time, so that any stopping at an earlier time is more extreme than any stopping at a later time

These are genuine choices; different people could legitimately pick different orderings. Ordering by the magnitude of difference tends to lead to narrower confidence intervals, more accurate p-values, and less bias, but it increases the sensitivity of the analysis to the (unobservable) times at which future analyses of a stopped trial would have occurred.
(Reference: short course by Kittleson and Gillen)
A: The answer to this question is what defines the particular test

But how do we define what is more extreme?

This choice is really the essence of what defines the particular hypothesis test under use.  Indeed, a classical hypothesis test can be reduced to a specification of a total order $\preceq$ on the set of possible outcomes for the observable data.  This total order, which I will call an evidential ordering, defines an ordering of which observable outcomes are more conducive to the null hypothesis and which are more conducive to the alternative hypothesis (i.e., "more extreme").
Suppose we have an observable data vector $\mathbf{x} \in \mathscr{X}$ from a model $f_\theta$ and we define hypotheses $H_0: \theta \in \Theta_0$ and $H_A: \theta \in \Theta_A$.  Now suppose we choose an evidential ordering $\preceq$ on the set $\mathscr{X}$, where larger values in the ordering are regarded as being more conducive to the alternative hypothesis.  Then we can define the p-value function for the corresponding hypothesis test as:
$$p(\mathbf{x}) = \sup_{\theta \in \Theta_0} \mathbb{P}( \mathbf{x} \in \mathcal{H}_A(\mathbf{x}) | \theta)
\quad \quad \quad
\mathcal{H}_A(\mathbf{x}) \equiv\{ \mathbf{x}' \in \mathscr{X} | \mathbf{x} \preceq \mathbf{x}' \}.$$
Since the hypothesis test is fully defined by its p-value function, and since this function is fully determined by the evidential ordering, the evidential ordering fully defines the test.  Two hypothesis tests are equivalent if they use the same total order $\preceq$ (e.g., the T-test and F-test in a linear regression are equivalent if there is only one explanatory variable).  In practice, the evidential ordering is usually defined only implicitly through the formation of a test statistic $T:\mathscr{X} \rightarrow \mathbb{R}$ and a specification of an ordering on $\mathbb{R}$.  Nevertheless, the test statistic is really just a mechanism to define the underlying evidential ordering, and two different specifications of test statistics that lead to the same evidential ordering essentially define the same test.  (You can find more discussion of the mathematical structure of a hypothesis test in this related answer.)
Now, we can make different choices of the evidential ordering and this defines different hypothesis tests.  We can then explore the properties of those tests ---e.g., their power function, etc.--- to see which orderings lead to tests with good properties.  Finding a good ordering that yields good properties for the test is an art form in itself, but the general idea is that we usually try to form a statistic that tends to be "small" when the null hypothesis is true, and gets larger the further we depart into the alternative hypothesis.  The likelihood-ratio statistic you use in your question is a statistic that has this property, but there are others as well.  As to how to generalise the likelihood ratio statistic to composite hypotheses, the usual generalisation is:
$$R(\mathbf{x}) = \frac{\sup_{\theta \in \Theta_A} f_\theta(\mathbf{x})}{\sup_{\theta \in \Theta_0} f_\theta(\mathbf{x})}.$$
As you can see, this statistic defines "extremeness" by looking at the constrained maximised likelihood within each composite hypothesis.  Other generalisations are of course possible, and it is open to you to formulate an alternative test statistic leading to a different test (through a different evidentiary ordering).

Trying to clear up your confusion: From what you have written in your question, I think this issue here is a failure to understand why we use "two-sided" hypothesis tests (or statistics like the LR statistic) that count unlikely deviations in any direction as being conducive to the alternative hypothesis.  The reason for this is that we are usually a priori ignorant of the likely direction in which extreme deviations might occur.  If we first observe the data and then see which tail it is in, and then choose a "one-sided" alternative in that direction, we are essentially altering the evidential ordering after seeing the data.  This induces serious confirmatory bias in the test, since the alternative hypothesis is formulated after seeing the data in a way that treats deviations in the observed direction to be conducive to the alternative.
For example, if we have a symmetric distribution and we use a post hoc one-sided test, we essentially halve the p-value (it is now uniformly distributed between zero and a half).  This imposes serious confirmatory bias, and it means that the stipulated size of the test is actually only half the true size.
A: Not taking it further than likelihood ratios ...
$\renewcommand\vec{\boldsymbol}$
The generalized likelihood ratio, for a test of the null hypothesis $\vec\theta \in \Theta_0$ vs the alternative $\vec\theta \in \Theta_\mathrm{A}$ is
$$
\renewcommand\vec{\boldsymbol}
\frac{\sup_{\vec{\theta} \in \Theta_\mathrm{A}} \left[f(\vec{x}; \vec\theta)\right]}{\sup_{\vec{\theta} \in \Theta_0} \left[f(\vec{x}; \vec\theta)\right]}
$$
& for simple, i.e. fully specified, null ($\vec\theta = \vec\theta_0$) & alternative ($\vec\theta=\vec\theta_\mathrm{A}$) reduces to the ordinary likelihood ratio. On the face of it, it's a reasonable measure of extremeness: the ratio of the likelihood of the most likely parameter values consistent with the alternative to the likelihood of the most likely parameter values consistent with the null.
A typical two-tailed test for a scalar $\theta$ of the null $\theta=\theta_0$ vs the unrestricted alternative $\theta \in \Theta$ would use
$$
\frac{f(\vec{x}; \hat\theta)}{f(\vec{x}; \theta_0)}
$$
where $\hat\theta$ is the maximum-likelihood estimate; with the test statistic increasing as $\hat\theta$ moves away from $\theta_0$ in either direction. For the mean of a Gaussian distribution, with known variance, that's
$$\frac{f(\vec{x}; \bar x, \sigma^2)}{f(\vec{x}; \mu_0; \sigma^2)}$$
(where $f(\cdot)$ is the Gaussian density function). When the variance is unknown, i.e. a nuisance parameter, the generalized likelihood ratio becomes
$$\frac{f\left(\vec{x}; \bar{x}, \frac{\sum(x-\bar{x})^2}{n}\right)}{f\left(\vec{x}; \mu_0, \frac{\sum(x-\mu_0)^2}{n}\right)}$$
These equate to the z- & t-statistics—to @Glen_b's point, any sensible test statistics for these cases will.
Note that the generalized likelihood test† doesn't in general enjoy any optimal power properties for small samples. It may be uniformly most powerful (though not for a two-tailed test—see @Michael's answer), locally most powerful (i.e. it coincides with Rao's score test—see @Michael's answer again), uniformly most powerful among unbiased tests, or at least admissible; but it may be inadmissible, or even "worse than useless". (For large samples, given some regularity conditions, Wilks' Theorem applies.)

† More often called just the "likelihood ratio test"; perhaps because in practice testing of point vs point hypotheses is rare & there's little need for the distinction.
