fix(ui): #3429 round-2 — never fall back to authority or placeholder (Codex MUST-FIX)

Codex re-check: degenerate URIs still leaked — gpt://folder123 returned the
authority, gpt://folder123/${MODEL} returned the placeholder. Removed the _all[0]
authority fallback and guarded the literal-last-path fallback against placeholders;
a URI with no usable model segment now falls back to the raw id. Added regression
cases for gpt://folder123 and gpt://folder123/${MODEL}.
This commit is contained in:
nesquena-hermes
2026-06-02 20:49:29 +00:00
parent c223b418a5
commit 25e95a7366
2 changed files with 20 additions and 3 deletions
+6 -3
View File
@@ -2930,9 +2930,12 @@ function getModelLabel(modelId){
if (!_lastUsable) _lastUsable = _seg;
if (!_isVersionTail(_seg)) { _pick = _seg; break; }
}
// Fallbacks: last non-placeholder path segment, else the literal last path
// segment, else the authority, else the raw id. Never an env-var placeholder.
_last = _pick || _lastUsable || _path[_path.length - 1] || _all[0] || modelId;
// Fallbacks: the chosen non-version segment, else the last non-placeholder
// path segment. NEVER the authority and NEVER a `${...}` placeholder — for
// a degenerate id (`gpt://folder123`, `gpt://folder123/${MODEL}`) fall all
// the way back to the raw id rather than leak the folder/host or env var.
const _lastPath = _path[_path.length - 1] || '';
_last = _pick || _lastUsable || (_lastPath && !_isPlaceholder(_lastPath) ? _lastPath : '') || modelId;
} else {
_last = modelId.includes('/') ? (modelId.slice(modelId.indexOf('/')+1) || modelId) : modelId;
}
@@ -88,6 +88,20 @@ def test_uri_label_edge_cases_never_return_authority_or_drop_digit_models():
assert label != "folder123", "authority/folder leaked into label"
def test_uri_degenerate_ids_fall_back_to_raw_not_authority_or_placeholder():
"""#3429 follow-up 2 (Codex gate): a URI with no usable model segment must
fall back to the raw id — never the authority/folder, never a ${...} env-var."""
out = _labels([
"gpt://folder123", # authority only, no path
"gpt://folder123/${MODEL}", # path is only an env-var placeholder
])
assert out["gpt://folder123"] == "gpt://folder123"
assert out["gpt://folder123/${MODEL}"] == "gpt://folder123/${MODEL}"
for label in out.values():
assert label != "folder123", "authority leaked into label"
assert label not in ("${MODEL}",), "env-var placeholder leaked into label"
def test_uri_fix_does_not_regress_multi_slash_or_bare_ids():
"""#3360 multi-slash hierarchy + single-slash/bare ids stay correct."""
out = _labels([