Solution (source code)

= Solution

Discarding zero observations and resolving ties is unnecessary with probability one under the stated independent continuous model. Rank the absolute observations from $1$ to $n$, let $R_i$ be the rank of $|X_i|$, and form the positive <Wilcoxon signed-rank statistic>
$$
W^+=\sum_iR_i\mathbf1_{X_i>0}.
$$
Reject the <null hypothesis> for large $W^+$. Under symmetry about zero, each sign is a fair independent binary variable, independent of all the absolute values. To see this <independence>, for every <measurable> positive set $B$, symmetry gives $\Pr(X\in B)=\Pr(X\in-B)=\tfrac12\Pr(|X|\in B)$. <Independence> of observations then gives <independence> of the whole sign vector from the absolute-value vector. Conditional on those absolute values, relabeling by rank therefore gives
$$
W^+\overset d=\sum_{r=1}^n rB_r,\qquad B_r\text{ independent Bernoulli}(1/2).
$$
The null distribution is consequently independent of the unknown symmetric shape. Its <probability generating function> is $2^{-n}\prod_{r=1}^n(1+z^r)$, so the coefficient of $z^w$ gives the exact probability of $W^+=w$. Choose an upper critical value with null tail probability at most the desired level, or randomize at the boundary to obtain that level exactly. The observed upper-tail probability is an exact one-sided <p-value>. A positive translation raises each <Walsh average>, as established below, so this upper-tail rule has the correct direction against positive centers for every fixed symmetric shape.

The independent-sign representation proves
$$
\boxed{E_0W^+=\frac12\sum_{r=1}^n r=\frac{n(n+1)}4,\qquad \operatorname{Var}_0W^+=\frac14\sum_{r=1}^n r^2=\frac{n(n+1)(2n+1)}{24}.}
$$
The asymptotic null distribution, stated without proof, is
$$
\boxed{\frac{W^+-n(n+1)/4}{\sqrt{n(n+1)(2n+1)/24}}\ \xrightarrow{d}\ N(0,1).}
$$
This supplies the usual upper <normal distribution> critical value when exact calculation is inconvenient; for the discrete upper tail $\Pr(W^+\ge c)$, use $c-1/2$ in the <continuity correction>.

For exact equivalence with the proposed <statistic>, reorder the observations so $|X_{(1)}|<\cdots<|X_{(n)}|$. Partition the unordered pairs, including diagonals, by the member with larger absolute value. The block belonging to $X_{(r)}$ consists of the $r-1$ pairs with an earlier member and its diagonal pair. For an earlier member $X_{(j)}$, the strict inequality $|X_{(j)}|<|X_{(r)}|$ means the sign of $X_{(j)}+X_{(r)}$ is the sign of $X_{(r)}$; the diagonal sum has that same sign. Thus the entire block supplies exactly $r$ positive averages when $X_{(r)}>0$, and none otherwise. Summing the blocks proves
$$
\boxed{\#\{(i,j):i\le j,\ (X_i+X_j)/2>0\}=\sum_{r=1}^n r\mathbf1_{X_{(r)}>0}=W^+.}
$$
The two tests therefore have exactly the same <statistic>, critical values and <p-values>, not merely the same limiting distribution. The <Walsh averages> are dependent, so their positivity indicators must not instead be treated as an independent binomial sample. For a translation $X_i=Z_i+\theta$ of any null-symmetric sample, every <Walsh average> increases by $\theta$; their positive count is nondecreasing, which also verifies the direction of the one-sided test.