Skip to content

fix(caller): _default_repl_caller convention-safe slug (closes #83)#84

Merged
darw007d merged 1 commit into
mainfrom
fix/repl-caller-leading-digit
Jun 20, 2026
Merged

fix(caller): _default_repl_caller convention-safe slug (closes #83)#84
darw007d merged 1 commit into
mainfrom
fix/repl-caller-leading-digit

Conversation

@darw007d

Copy link
Copy Markdown
Collaborator

Closes #83 — the #80/#82 sibling on the dynamic caller path, surfaced by the PR #82 meta-guard.

Bug

_default_repl_caller (chat.py) built its slug with an inline "".join(c if c.isalnum() else "_" ...) that, unlike caller._sanitize_username (which default_caller uses), did NOT guarantee an [a-z]-leading char, collapse underscores, or fall back on empty. So a leading-digit OS username → USER=3bobcli.repl.3bob → fails ^[a-z]...crashes SwarphCall at runtime (same class as #80, dynamic path).

Fix (DRY — droplet's narrowing: default_caller is the template)

Reuse the one robust sanitizer: return f"cli.repl.{_sanitize_username(user)}". Eliminates the divergence (two sanitizers, one safe one not → now one). No circular import (caller.py imports only getpass/os/re).

USER=3bob -> cli.repl.u_3bob    USER=9 -> cli.repl.u_9
USER=!!!  -> cli.repl.unknown   USER=Bob -> cli.repl.bob   (normal users unchanged)

Tests (TDD — written failing first)

test_repl_caller_convention.py: parametrized over adversarial usernames (leading-digit, all-digit, all-special, uppercase, dotted, hyphenated, underscore-only, whitespace) — each must validate_caller clean; + a guard that it stays cli.repl.* (distinct from cli.oneshot.*). RED before the fix (5 failures), GREEN after. No regression: #80 compress + #82 meta-guard + 53 chat/caller tests green.

Found-by: the #82 meta-guard's ambient-state surface. Narrowing: droplet.

🤖 Generated with Claude Code

The repl-default caller rolled its own slug that — unlike caller._sanitize_username
which default_caller uses — didn't guarantee a leading letter / collapse underscores /
fall back on empty. So a leading-digit OS username produced a non-conforming
'cli.repl.3bob' that crashes SwarphCall at runtime (the #80 crash-class on the dynamic
path). Fix is DRY: reuse the one robust sanitizer, eliminating the divergence
(USER=3bob -> cli.repl.u_3bob; !!! -> cli.repl.unknown). + a parametrized adversarial-
username regression test (leading-digit/all-special/empty/etc). No production behavior
change for normal usernames; 53 chat/caller tests green, #80+#82 unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@darw007d darw007d merged commit b095560 into main Jun 20, 2026
2 checks passed
@darw007d darw007d deleted the fix/repl-caller-leading-digit branch June 20, 2026 21:47
darw007d added a commit that referenced this pull request Jun 21, 2026
…, repl-caller #83/#84)

Ships the dotted caller-convention fixes that were merged to main but unreleased:
- #80: compress shorthand + verify-expand model paths were DEAD at runtime (hyphenated
  callers rejected by swarph_shared's dotted convention) — now dotted constants.
- #82: repo-wide validate_caller meta-guard so the bug class can't be re-introduced.
- #83/#84: _default_repl_caller convention-safe slug (reuses _sanitize_username).
Anyone on 0.13.2 running `swarph compress` hit the dead path; this releases the fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(caller): _default_repl_caller emits a non-conforming caller for a leading-digit username

2 participants