Welcome to the forum @Garulfo ,
This is a classic case of Why is the value I receive from context always content? .
Solution will require you to move the context expression outside of the x-height definition. Hint: turn it into a function and provide context to it.
// Requires `context`
#let x-height(body) = {
{
measure(
box(
inset: 0pt,
outset: 0pt,
text(top-edge: "bounds", body),
),
)
}.height
}
#let body = [= Test
#lorem(20)]
#body
#context {
let height = x-height(body)
set text(
top-edge: 2.8 * height * 0.72,
bottom-edge: 2.8 * height * 0.28,
)
set par(leading: 2.8 * height * 0.28)
body
}
If you could please edit your first code snippet and enclose it in back ticks ``` snippet ```, that would help us copy/paste/read your code more easily. Thanks.