Skip to content

fix(scope): _primary_scope_for empty-prefix guard (vhsm e2e catch on PR #144) - #150

Merged
joelteply merged 1 commit into
canaryfrom
fix/primary-scope-resolution-leading-dot
Apr 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/primary-scope-resolution-leading-dot

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Bug (vhsm-d1f4 PR #144 e2e, 2026-04-27)

`airc join --general` silently no-op'd: parted_rooms stayed populated, sidecar stayed skipped, the "previously parted" notice fired every retry. README #143 documents `airc join --general` as THE re-opt-in path — would have shipped broken-as-documented if this hadn't been caught in the canary→main pre-merge e2e.

Root cause (full trace, vhsm's analysis)

`_primary_scope_for` regex `s/\.[a-z0-9-]+$//` over-strips when basename IS a leading-dot-name:

Input Regex output (prefix) Old behavior
`.airc` (primary, canonical) `""` (empty) returned `/` — BOGUS
`.airc.general` (sidecar) `.airc` returned `/.airc` ✓
`state` (test fixture) `state` returned scope ✓
`state.general` (test sidecar) `state` returned `/state` ✓

The "is this a sidecar?" check (`prefix != self_base`) was true for `.airc` (since `"" != ".airc"`), so the function returned a bogus path. Downstream `_clear_parted_room` got that path, found no config.json there, silently no-op'd via the python wrapper's FileNotFoundError → sys.exit(0).

Fix

Empty-prefix guard: if the regex eats the entire basename, the basename was a leading-dot-only name (canonical primary), not a sidecar. Return self.

```bash
if [ -z "$prefix" ] || [ "$prefix" = "$self_base" ]; then
printf '%s' "$scope"
else
printf '%s' "$parent/$prefix"
fi
```

Test fix (the deeper lesson)

`scenario_part_persists` used fixture path `state`/`state.general`. Basename `state` has no dots → regex no-ops → primary case. The leading-dot code path was NEVER exercised by integration tests. Real deployments use `$repo/.airc`.

Renamed fixture: `/tmp/airc-it-pp/state` → `/tmp/airc-it-pp/.airc`. With `.airc` basename, the test reproduces vhsm's bug pre-fix, passes post-fix.

pre-fix post-fix
.airc fixture phase 4 fails (2 assertions) 8/8 pass
state fixture (old) 8/8 (false-pass — bypasses code path) 8/8

Class of bug

Test fixture paths that diverge from real-world layout in ways that hide code paths. Any regex over basenames should account for leading-dot directories. Worth a grep over the codebase for similar patterns — separate audit.

Unblocks

PR #144 (canary→main). vhsm's e2e was a HOLD on this exact issue; with this fix merged to canary, vhsm can re-run step 5 of their e2e and #144 ships.

…g-dot-only

Bug found by vhsm-d1f4 in PR #144 e2e (2026-04-27): \`airc join --general\`
silently failed to clear parted_rooms after a /part. Trace:

1. cmd_part on .airc.general writes parted_rooms=['general'] to primary's
   config.json (works — _primary_scope_for(.airc.general) → .airc, correct).
2. airc join --general triggers _force_general_sidecar=1 in cmd_connect.
3. cmd_connect calls _primary_scope_for "$AIRC_WRITE_DIR" where
   AIRC_WRITE_DIR is the PRIMARY scope ('.airc').
4. The regex 's/\.[a-z0-9-]+\$//' over-strips '.airc' (the entire basename
   IS one dot-segment) → prefix=''.
5. The 'is this a sidecar?' check (prefix != self_base) was true (since
   '' != '.airc'), so _primary_scope_for returned '<parent>/' (bogus).
6. _clear_parted_room got that bogus path, the python wrapper caught
   FileNotFoundError, sys.exit(0), silent no-op.

Net: --general printed the same "previously parted" message every time,
parted_rooms never cleared, sidecar never resubscribed. README #143 already
documented "airc join --general" as THE recovery path; would have shipped
broken-as-documented to main without the e2e catch.

## Fix

Add empty-prefix guard: if the regex eats the entire basename, the basename
was a leading-dot-only name (canonical primary scope), not a sidecar.
Return self instead of the bogus parent/empty-string concat.

## Why integration tests missed it

scenario_part_persists used fixture path '/tmp/airc-it-pp/state' /
'state.general'. Basename 'state' has no dots → regex no-ops → prefix=='state'
== self_base → primary case. The leading-dot code path was never exercised.
Real deployments use $repo/.airc — which IS leading-dot.

## Test fix

Renamed scenario_part_persists fixture from 'state' → '.airc' so the
basename matches production layout. Verified:
- pre-fix + .airc fixture: phase 4 fails (--general didn't respawn / parted_rooms didn't clear)
- post-fix + .airc fixture: 8/8 phases green

The class of bug ("test fixture diverges from real layout in a way that
hides a code path") is worth grepping for elsewhere — paths starting with
'.' are common enough that any regex over basename should account for them.
Copilot AI review requested due to automatic review settings April 27, 2026 16:40
@joelteply
joelteply merged commit f3c7557 into canary Apr 27, 2026
2 checks passed
@joelteply
joelteply deleted the fix/primary-scope-resolution-leading-dot branch April 27, 2026 16:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression in primary-scope resolution when the scope basename is a leading-dot directory (e.g., .airc), which broke airc join --general by routing _clear_parted_room to an incorrect path and causing a silent no-op. This aligns scope handling with real-world deployment layout ($repo/.airc) and updates integration coverage to prevent recurrence.

Changes:

  • Add an empty-prefix guard in _primary_scope_for so .airc is treated as a primary scope (not a sidecar).
  • Update scenario_part_persists integration fixture to use /tmp/airc-it-pp/.airc so the leading-dot basename code path is exercised.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
airc Fixes _primary_scope_for to correctly handle leading-dot primary scope basenames like .airc.
test/integration.sh Adjusts the part_persists fixture path to .airc to cover the real-world layout and catch the regression.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants