Skip to content

maintenance: one location contract, and grade the canonical checkout - #232

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/workspace-location-contracts
Sep 18, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/workspace-location-contracts

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Part of PyAutoLabs/PyAutoBrain#391 (phase 1a). Changes no directory layout. Companion to PyAutoLabs/PyAutoBrain#392; mergeable in any order.

What was wrong

Heart answered "where is the workspace root" in nine places and they disagreed:

  • heart/_common.sh:31 hard-coded a path under $HOME
  • heart/dashboard.py:172 fell back to ~/Code — not ~/Code/PyAutoLabs — so root/"PyAutoBrain" named a path that does not exist
  • eight checks tested whether a parent directory was literally named after this workspace

The dashboard.py fallback is a real bug, masked only because it is last in a candidate chain an earlier candidate satisfies. Reproduced before the fix:

_workspace_root() -> /home/jammy/Code            (exists)
  root/"PyAutoBrain"              -> exists: False
  HEART_HOME.parent/"PyAutoBrain" -> exists: True   <- the mask

The split that matters

heart/_workspace.{py,sh} is now the single door, and it separates two concepts that were conflated:

workspace_root() "where am I" — siblings, config, the Brain, the theme. Follows the marker, so inside a bundle it is the bundle.
canonical_root() the main checkout: the tree health grades. $PYAUTO_ROOT → git --git-common-dir → workspace root.

Health is a release gate. The established rule is that it grades the canonical checkout, with PYAUTO_ROOT=<worktree> as the documented opt-in for grading a branch. Naively following the resolver would have inverted that default: run from a bundle, Heart reported 0 orphan / 5 dirty where canonical reports 6 orphan / 7 dirty — the more flattering answer, reached by the easy mistake of running Heart from the directory you happen to be working in. A gate must not relax because of cwd.

Canonical is derived from git, not a literal, so it stays true on any machine. Verified in all four layouts (linked worktree, canonical, symlinked repo, non-repo → honest fallback). wt_root() follows canonical too.

Acceptance: from inside a task bundle with env -u PYAUTO_ROOT -u PYAUTO_WT_ROOT -u PYAUTO_BRAIN, Heart reproduces the canonical verdict exactly (6 orphan / 0 missing / 7 dirty). PYAUTO_ROOT=<bundle> still grades the bundle (0 orphan / 5 dirty) — the opt-in survives.

Scope note

Every grading path is repointed — worktree_drift, manifest_drift, profiling_drift, script_timing, version_skew, test_run, unit_test_timing, workspace_testmode_timing, tick.sh's three guards, repo_state.sh, url_sweep.sh, and the three health_*.sh scripts (which resolve inside a subshell so sourcing them from a shell profile doesn't export PYAUTO_ROOT into every interactive shell).

That is wider than the four sites originally scoped. Converting only those would have left Heart internally disagreeing — which is the defect being fixed. Flag it if you'd rather the extra files were a separate PR.

Degradation and skew

With no PyAutoBrain in reach the shim degrades exactly as dashboard.theme() already does, suffixing every reason string so a degraded answer never reads as authoritative. It also tolerates a Brain that predates this resolver — canonical main sets PYAUTO_ROOT but not PYAUTO_ROOT_REASON, which under set -u was a crash. That is what makes the four PRs order-independent.

admin_jammy

Dropped from config/repos.yaml — not part of the PyAutoLabs ecosystem. Verified excluded: is documentation only: no leg consumes it, so removing an entry cannot newly include anything.

Verification

pytest tests → 1026 passed (baseline 1026). Escape hatches spot-checked live: $PYAUTO_ROOT, $PYAUTO_WT_ROOT, $PYAUTO_BRAIN, $PYAUTO_AUDIT_ROOT, $HEART_STATE_DIR all still override.

Deliberately untouched

heart/smoke.py — it drives a flat pip install ./PyAutoFit ./PyAutoArray … chain with cwd=organism_root, and (contrary to an early assumption) Heart runs that script locally, not only in CI. Adopting the marker rule would hand it a regrouped root it cannot honour. Phase 3.

🤖 Generated with Claude Code

https://claude.ai/code/session_0161NLKVzbBMzhaBfjpGogor

Heart answered "where is the workspace root" in nine places and they disagreed:
_common.sh hard-coded a path under $HOME; dashboard.py fell back to ~/Code
(NOT ~/Code/PyAutoLabs, so `root/"PyAutoBrain"` pointed at a path that does not
exist — a real bug, masked only because it is last in a candidate chain and an
earlier candidate catches it); eight checks tested whether a parent directory
was *literally named* after this workspace.

heart/_workspace.{py,sh} is now the single door, and it separates two concepts
that were conflated:

  workspace_root()  — "where am I": siblings, config, the Brain, the theme.
                      Follows the marker, so inside a bundle it is the bundle.
  canonical_root()  — the MAIN checkout: THE TREE HEALTH GRADES.
                      $PYAUTO_ROOT -> git --git-common-dir -> workspace root.

That split is the point. Health is a release gate, and the established rule is
that it grades the canonical checkout while `PYAUTO_ROOT=<worktree>` is the
documented opt-in for grading a branch. Following the resolver would have
inverted that default: run from a bundle, Heart reported 0 orphan / 5 dirty
where canonical reports 6 orphan / 7 dirty — the more flattering answer,
reached by the easy mistake of running Heart from the directory you are working
in. A gate must not relax because of cwd. Deriving canonical from git rather
than a literal keeps it true on any machine; wt_root() follows canonical too.

Every grading path is repointed: worktree_drift, manifest_drift,
profiling_drift, script_timing, version_skew, test_run, unit_test_timing,
workspace_testmode_timing, tick.sh's three guards, repo_state.sh, url_sweep.sh
and the three health_*.sh scripts (which resolve inside a subshell so sourcing
them from a shell profile does not export PYAUTO_ROOT into every interactive
shell).

With no PyAutoBrain in reach the shim degrades exactly as the surrounding code
already does, suffixing every reason string so a degraded answer never reads as
authoritative. It also tolerates a Brain that predates the resolver, so this can
merge before or after PyAutoBrain#391's half.

admin_jammy dropped from config/repos.yaml: it is not part of the PyAutoLabs
ecosystem. `excluded:` is documentation only — no leg consumes it — so removing
an entry cannot newly include anything.

Suite 1026 passed (baseline 1026). Acceptance: from inside a task bundle with no
environment set, Heart reproduces the canonical verdict exactly; PYAUTO_ROOT
still grades the bundle.

Part of PyAutoBrain#391 (phase 1a). smoke.py deliberately untouched — its flat
`pip install ./PyAutoFit ...` chain is phase 3.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161NLKVzbBMzhaBfjpGogor
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.

1 participant