I'm reading two results from Brezis' Functional Analysis
Corollary 4.24 Let $\Omega$ be an open subset of $\mathbb R^d$. Let $f \in L^1_{\text{loc}} (\Omega)$ be such that $$ \int_\Omega f \varphi=0, \quad \forall\varphi \in C^\infty_c (\Omega). $$ Then $f=0$ a.e. on $\Omega$.
Lemma 8.1 Let $I:=(a, b)$ be an interval, possibly unbounded. Let $f \in L^1_{\text{loc}} (I)$ be such that $$ \int_I f \varphi'=0, \quad \forall\varphi \in C^1_c (I). $$ Then there is a constant $C$ such that $f=C$ a.e. on $I$.
In below "spurious" argument, I show that the function $f$ in Lemma 8.1 is such that $f=0$ a.e. on $I$. Could you elaborate where I got wrong?
Fix an arbitrary $\psi \in C^\infty_c (I)$. We define $\varphi:I \to \mathbb R$ by $\varphi (x):= \int_a^x \psi$ for $x \in I$. Then $\varphi$ is well-defined such that $\varphi \in C^\infty_c (I)$ and $\varphi' = \psi$. Then $$ \int_I f \psi = \int_I f \varphi'=0. $$
By Corollary 4.24, $f=0$ a.e. on $I$.
$\varphi$ is not necessarily compactly supported, as to have that condition on $\phi$ you need to have the following: $$0 = \varphi(b) - \varphi(a) = \int_I \varphi' = \int_I \psi$$ which you did not specify as a condition on $\psi$, thus you cannot apply your Corollary $4.24$.