Skip to content

Commit e863eff

Browse files
lroolleclaude
andcommitted
fix: per-agent version cache + versioned-name parsing, extend slug tests
Review findings on #424: - extract_agent_from_name only matched ^--([a-z]+)-- and fell back to "share" for versioned segments; accept optional -v<version> - agent_version_tag cached one value regardless of agent; key the cache by agent - test-container-slug.sh: source agent_version_tag, stub docker for versioned-name cases, accept optional version in dry-run patterns (63 tests pass, dry-run shows live versioned names) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent c007398 commit e863eff

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

deva.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,11 +935,12 @@ compute_shape_hash() {
935935
# sharing the same config home (#420). check_image runs before any name is
936936
# built, so the inspect is reliable; label-less images fall back to the
937937
# bare agent name.
938-
AGENT_VERSION_TAG_CACHE="__unset__"
938+
AGENT_VERSION_TAG_CACHE_AGENT=""
939+
AGENT_VERSION_TAG_CACHE=""
939940
agent_version_tag() {
940941
local agent="$1"
941942

942-
if [ "$AGENT_VERSION_TAG_CACHE" != "__unset__" ]; then
943+
if [ "$AGENT_VERSION_TAG_CACHE_AGENT" = "$agent" ]; then
943944
printf '%s' "$AGENT_VERSION_TAG_CACHE"
944945
return
945946
fi
@@ -960,6 +961,7 @@ agent_version_tag() {
960961
ver=$(printf '%s' "$ver" | tr -cd 'a-zA-Z0-9._-')
961962
fi
962963

964+
AGENT_VERSION_TAG_CACHE_AGENT="$agent"
963965
AGENT_VERSION_TAG_CACHE="$ver"
964966
printf '%s' "$ver"
965967
}
@@ -1117,8 +1119,8 @@ extract_agent_from_name() {
11171119
local name="$1"
11181120
local rest="${name#"${DEVA_CONTAINER_PREFIX}"}"
11191121

1120-
# New format: deva--<agent>--<auth>--<slug>..<hash>
1121-
if [[ "$rest" =~ ^--([a-z]+)-- ]]; then
1122+
# New format: deva--<agent>[-v<version>]--<auth>--<slug>..<hash>
1123+
if [[ "$rest" =~ ^--([a-z]+)(-v[A-Za-z0-9._-]+)?-- ]]; then
11221124
printf '%s' "${BASH_REMATCH[1]}"
11231125
return
11241126
fi

scripts/test-container-slug.sh

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ source_helpers() {
5252
eval "$(sed -n '/^generate_container_slug_for_path()/,/^}/p' "$REPO_ROOT/deva.sh")"
5353
eval "$(sed -n '/^compute_slug_components_for_path()/,/^}/p' "$REPO_ROOT/deva.sh")"
5454
eval "$(sed -n '/^extract_agent_from_name()/,/^}/p' "$REPO_ROOT/deva.sh")"
55+
eval "$(sed -n '/^agent_version_tag()/,/^}/p' "$REPO_ROOT/deva.sh")"
56+
AGENT_VERSION_TAG_CACHE_AGENT=""
57+
AGENT_VERSION_TAG_CACHE=""
58+
# No image label in unit tests unless a test stubs docker itself
59+
docker_image_ref() { printf 'deva-test:none'; }
5560
DEVA_CONTAINER_PREFIX="deva"
5661
}
5762

@@ -178,6 +183,26 @@ name=$(build_container_name "deva" "gemini" "vertex" "big-project" "11223344" "f
178183
assert_eq "persistent vertex auth" \
179184
"deva--gemini--vertex--big-project..11223344" "$name"
180185

186+
# Versioned agent segment (#420): stub docker to return an image label
187+
docker() {
188+
if [ "$1" = "image" ] && [ "$2" = "inspect" ]; then
189+
printf '2.1.204\n'
190+
return 0
191+
fi
192+
return 1
193+
}
194+
AGENT_VERSION_TAG_CACHE_AGENT="" AGENT_VERSION_TAG_CACHE=""
195+
name=$(build_container_name "deva" "claude" "auth-file-max" "myrepo" "ab12cd34" "false" "")
196+
assert_eq "persistent with agent version" \
197+
"deva--claude-v2.1.204--auth-file-max--myrepo..ab12cd34" "$name"
198+
199+
AGENT_VERSION_TAG_CACHE_AGENT="" AGENT_VERSION_TAG_CACHE=""
200+
name=$(build_container_name "deva" "mystery" "auth-default" "myrepo" "ab12cd34" "false" "")
201+
assert_eq "unmapped agent stays bare" \
202+
"deva--mystery--auth-default--myrepo..ab12cd34" "$name"
203+
unset -f docker
204+
AGENT_VERSION_TAG_CACHE_AGENT="" AGENT_VERSION_TAG_CACHE=""
205+
181206
# ──────────────────────────────────────
182207
echo "=== extract_agent_from_name ==="
183208
# ──────────────────────────────────────
@@ -194,6 +219,12 @@ assert_eq "new format gemini" "gemini" \
194219
assert_eq "new format ephemeral" "claude" \
195220
"$(extract_agent_from_name "deva--claude--api-key-abcd--myrepo..ab12cd34--99999")"
196221

222+
assert_eq "versioned agent segment" "claude" \
223+
"$(extract_agent_from_name "deva--claude-v2.1.204--auth-file-max--myrepo..ab12cd34")"
224+
225+
assert_eq "versioned ephemeral" "codex" \
226+
"$(extract_agent_from_name "deva--codex-v0.131.0--auth-default--myrepo..ab12cd34--4242")"
227+
197228
assert_eq "legacy ephemeral" "claude" \
198229
"$(extract_agent_from_name "deva-myrepo..i47b207-claude-12345")"
199230

@@ -254,7 +285,7 @@ out="$(run_dry claude --debug --dry-run || true)"
254285
cname="$(extract_container_name "$out")"
255286
if [ -n "$cname" ]; then
256287
assert_match "dry-run: new format structure" \
257-
"^deva--claude--auth-default--" "$cname"
288+
"^deva--claude(-v[A-Za-z0-9._-]+)?--auth-default--" "$cname"
258289
assert_match "dry-run: ends with ..hash" \
259290
'\.\.[a-f0-9]{8}$' "$cname"
260291
assert_no_match "dry-run: no old-style ..i prefix" \
@@ -267,7 +298,7 @@ out="$(run_dry codex --debug --dry-run || true)"
267298
cname="$(extract_container_name "$out")"
268299
if [ -n "$cname" ]; then
269300
assert_match "dry-run codex: agent in name" \
270-
"^deva--codex--" "$cname"
301+
"^deva--codex(-v[A-Za-z0-9._-]+)?--" "$cname"
271302
else
272303
fail "dry-run codex: could not extract container name"
273304
fi
@@ -276,7 +307,7 @@ out="$(run_dry gemini --debug --dry-run || true)"
276307
cname="$(extract_container_name "$out")"
277308
if [ -n "$cname" ]; then
278309
assert_match "dry-run gemini: agent in name" \
279-
"^deva--gemini--" "$cname"
310+
"^deva--gemini(-v[A-Za-z0-9._-]+)?--" "$cname"
280311
else
281312
fail "dry-run gemini: could not extract container name"
282313
fi
@@ -288,7 +319,7 @@ if [ -n "$cname" ]; then
288319
assert_match "dry-run ephemeral: has PID suffix" \
289320
'--[0-9]+$' "$cname"
290321
assert_match "dry-run ephemeral: agent in name" \
291-
"^deva--claude--" "$cname"
322+
"^deva--claude(-v[A-Za-z0-9._-]+)?--" "$cname"
292323
else
293324
fail "dry-run ephemeral: could not extract container name"
294325
fi

0 commit comments

Comments
 (0)