The cornerRadius part should be achievable using expr, I tried doing for fill which is showing different color based on condition but it didn't work for cornerRadius configs, it might be a bug. I think the same thing your tried for align is also working in the bar chart sample you provided, but without your config I cannot understand why the align is not working for you.
You can check the sample code below or the editor:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A bar chart with negative values. We can hide the axis domain line, and instead use a conditional grid color to draw a zero baseline.",
"data": {
"values": [
{"a": "A", "b": -28},
{"a": "B", "b": 55},
{"a": "C", "b": -33},
{"a": "D", "b": 91},
{"a": "E", "b": 81},
{"a": "F", "b": 53},
{"a": "G", "b": -19},
{"a": "H", "b": 87},
{"a": "I", "b": 52}
]
},
"config2": {"mark": {"cornerRadius": 20}},
"encoding": {
"y": {
"field": "a",
"type": "nominal",
"axis": {
"domain": false,
"ticks": false,
"labelAngle": 0,
"labelPadding": 4
}
},
"x": {
"field": "b",
"type": "quantitative",
"scale": {"padding": 20}
}
},
"layer": [
{
"mark": {
"type": "bar",
"cornerRadiusEnd": {"expr": "datum.b < 0 ? 0 : 80"},
"fill": {"expr": "datum.b < 0 ? 'red' : 'green'"},
"cornerRadiusBottomRight": {"expr": "datum.b < 0 ? 40 : 0"},
"cornerRadiusTopRight": {"expr": "datum.b < 0 ? 40 : 0"}
}
},
{
"mark": {
"type": "text",
"align": {"expr": "datum.b < 0 ? 'right' : 'left'"},
"dx": {"expr": "datum.b < 0 ? -2 : 2"}
},
"encoding": {"text": {"field": "b", "type": "quantitative"}}
}
]
}