mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-08-27 14:17:10 -04:00
## Description Stop `headroom wrap codex --memory` from pinning the global `headroom_memory` MCP server to one absolute SQLite path. Today the wrapper writes `--db <wrap-cwd>/.headroom/memory.db` into `~/.codex/config.toml`, which makes later Codex sessions either reopen a stale project-local DB or fail with `unable to open database file` when that original path disappears. This change lets the MCP server use its existing per-cwd default again, so each Codex session resolves `.headroom/memory.db` from the active project instead of a serialized past cwd. Closes #1147 The current Codex-memory config surface was shaped by https://github.com/chopratejas/headroom/issues/462 and https://github.com/chopratejas/headroom/issues/730; this PR keeps that surface project-scoped again instead of globally pinning one DB. ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - remove the injected `--db` argument from the global `headroom_memory` Codex MCP block while keeping `--user` intact - preserve the wrap-time local `.headroom/memory.db` setup and Claude-memory import path for the current project - treat only wrap-owned Codex markers as snapshot-suppression and unwrap-cleanup signals, so pre-existing named MCP blocks still back up and restore - log a startup diagnostic from `headroom.memory.mcp_server` that records the configured DB path, config source, cwd/project root, resolved storage scope, path existence/readability, and whether the path was static or cwd-derived - add a shared MCP SDK test stub so both the memory MCP and CCR MCP test surfaces still run in CI when `mcp` is absent - make the shared MCP stub re-import target modules under the stubbed dependency set and restore any pre-existing target module object plus dotted parent-package attribute state after cleanup - add focused regressions and guard coverage for the persisted Codex config shape, named-MCP marker backup and restore, the no-backup memory-only unwrap path, the wrap-memory-then-unwrap cleanup path, the failed-wrap memory-only cleanup path, the startup-diagnostic path classification, the shared-store CCR retrieval path, and the shared MCP stub import lifecycle - add a `CHANGELOG.md` entry for the user-visible Codex memory scoping fix ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [ ] Type checking passes (`uv run mypy headroom`) - [x] New tests added for new functionality - [ ] Manual testing performed ### Test Output ```text uv run pytest tests/test_ccr_mcp_server.py tests/test_memory/test_mcp_server.py tests/test_cli/test_wrap_codex.py tests/test_mcp_stub.py ======================== 78 passed, 1 warning in 5.96s ======================== Pytest warning: PytestConfigWarning: Unknown config option: asyncio_mode Pytest post-success atexit noise: PermissionError: [WinError 5] Access is denied: 'C:\Users\Rod\AppData\Local\Temp\pytest-of-Rod\pytest-current' uv run ruff check headroom/cli/wrap.py headroom/memory/mcp_server.py tests/_mcp_stub.py tests/test_ccr_mcp_server.py tests/test_cli/test_wrap_codex.py tests/test_mcp_stub.py tests/test_memory/test_mcp_server.py All checks passed! uv run ruff format headroom/cli/wrap.py headroom/memory/mcp_server.py tests/_mcp_stub.py tests/test_ccr_mcp_server.py tests/test_cli/test_wrap_codex.py tests/test_mcp_stub.py tests/test_memory/test_mcp_server.py --check 7 files already formatted ``` ## Real Behavior Proof - Environment: isolated temp project directories, a temp Codex home, the real `wrap codex` and `unwrap codex` CLI commands under pytest, a mocked missing-`codex` launch path for the failed-wrap cleanup case, and shared MCP-SDK stubs for the memory MCP and CCR MCP test modules so CI still exercises those paths without a real `mcp` install. - Exact command / steps: run `uv run pytest tests/test_ccr_mcp_server.py tests/test_memory/test_mcp_server.py tests/test_cli/test_wrap_codex.py tests/test_mcp_stub.py`; prove the persisted config shape with `TestCodexMemoryMcpConfig::test_inject_omits_db_and_replaces_existing_memory_block`; prove prepare-only wrap cleanup with `test_wrap_codex_memory_prepare_only_unwrap_removes_memory_mcp_without_prior_config`; prove failed-wrap cleanup with `test_wrap_codex_memory_launch_failure_unwrap_cleans_memory_only_config`; guard pre-existing named Codex MCP preservation with `test_memory_only_wrap_restores_preexisting_named_mcp_block` and `test_memory_only_wrap_without_backup_preserves_named_mcp_block`; prove the startup diagnostic classifications with `test_memory_mcp_startup_context_reports_dynamic_project_db` and `test_memory_mcp_startup_context_reports_static_external_db`; prove the shared-store CCR retrieval path with `test_mcp_uses_shared_singleton_store` and `test_mcp_retrieves_proxy_stored_content`; prove stub import cleanup with `test_import_module_with_mcp_stub_imports_target_and_cleans_up`, `test_import_module_with_mcp_stub_reimports_target_and_restores_originals`, and `test_import_module_with_mcp_stub_cleans_up_dotted_target_attribute`. - Observed result: the persisted global `headroom_memory` block now keeps `--user` but omits `--db`; prepare-only memory setup still bootstraps the current project's `.headroom/memory.db`; `headroom unwrap codex --no-stop-proxy` now removes both the prepare-only generated config and the failed-wrap memory-only config instead of leaving `[mcp_servers.headroom_memory]` behind; pre-existing named Codex MCP blocks remain restorable across both normal and no-backup memory-only unwrap paths because only wrap-owned markers suppress backups or trigger named-block cleanup; the memory MCP server now logs whether its DB path came from the cwd default or an explicit static path, along with the resolved path and scope it will open; CI can exercise both MCP test modules even when the `mcp` package is absent from the shard environment, and the shared stub now re-imports target modules under the stubbed SDK while restoring both dependency and dotted parent-package target-module import state after cleanup. - Not tested: full end-to-end interactive Codex CLI launch. ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] I have updated the CHANGELOG.md if applicable ## Additional Notes The code change stays narrowly scoped to Codex memory config persistence, cleanup, and startup observability. It does not widen into larger memory-routing redesign or startup-failure recovery logic.
140 lines
5.3 KiB
YAML
140 lines
5.3 KiB
YAML
name: Init Native E2E
|
|
|
|
# Cross-platform (linux / macos / windows) smoke tests for the per-subcommand
|
|
# ``headroom init -g <target>`` flows. Each matrix cell drops a noop shim for
|
|
# the target agent onto PATH and asserts ``headroom init -g <target>``
|
|
# succeeds, writes the expected settings file, and (for claude/codex) places
|
|
# hooks in the right place.
|
|
#
|
|
# Deliberately scoped to pull_request + push-to-main + workflow_dispatch to
|
|
# avoid bloating CI minutes on every push to every feature branch. The Docker
|
|
# init-e2e.yml still runs on every PR and provides the deeper functional
|
|
# coverage; this workflow exists to catch platform-specific bugs (Windows
|
|
# path separators, macos keychain prompts, PowerShell-vs-bash hook matchers)
|
|
# that the single-platform Docker suite can miss.
|
|
#
|
|
# Extending to other commands (``headroom install``, ``headroom wrap``) is
|
|
# expected to be a near-copy of this file. The shared composite action at
|
|
# ``.github/actions/headroom-e2e-setup`` absorbs the Python + shim setup so
|
|
# each per-command workflow only supplies its matrix and assertion steps.
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [main]
|
|
paths:
|
|
- "headroom/cli/init.py"
|
|
- "headroom/install/**"
|
|
- "e2e/_lib/**"
|
|
- "e2e/init/**"
|
|
- ".github/actions/headroom-e2e-setup/**"
|
|
- ".github/workflows/init-native-e2e.yml"
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
init-native:
|
|
runs-on: ${{ matrix.os }}
|
|
timeout-minutes: 25
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
# Windows is excluded today: upstream `esaxx-rs` (transitively from
|
|
# `tokenizers`) and `ort-sys` (onnxruntime via `fastembed`) link
|
|
# with conflicting MSVC C runtime libraries (/MT vs /MD), so the
|
|
# Rust extension cannot build for `win_amd64` until the upstream
|
|
# CRT conflict is resolved. Re-add `windows-latest` once the wheel
|
|
# builds cleanly there. Tracked in the project plan; not a blocker
|
|
# for headroom-ai installs on Linux + macOS.
|
|
os: [ubuntu-latest, macos-latest]
|
|
target: [claude, codex, copilot, openclaw]
|
|
exclude:
|
|
# openclaw delegates to ``headroom wrap openclaw`` which needs a
|
|
# running OpenClaw CLI; it can't be shimmed cheaply, so it's
|
|
# covered by the bundled Docker e2e instead.
|
|
- target: openclaw
|
|
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
|
|
- name: Setup (shim=${{ matrix.target }})
|
|
uses: ./.github/actions/headroom-e2e-setup
|
|
with:
|
|
install-mode: deps-only-proxy
|
|
python-version: "3.11"
|
|
shim-target: ${{ matrix.target }}
|
|
|
|
- name: Verify shim is on PATH (POSIX)
|
|
if: runner.os != 'Windows'
|
|
shell: bash
|
|
run: |
|
|
which "${{ matrix.target }}"
|
|
|
|
- name: Verify shim is on PATH (Windows)
|
|
if: runner.os == 'Windows'
|
|
shell: pwsh
|
|
run: |
|
|
# On Windows the shim is ``<target>.cmd``; Get-Command resolves via
|
|
# PATHEXT (same as Python's ``shutil.which`` used by headroom init).
|
|
# Git Bash's ``which`` cannot find ``.cmd`` shims, so we use pwsh.
|
|
$cmd = Get-Command "${{ matrix.target }}" -ErrorAction Stop
|
|
Write-Output $cmd.Source
|
|
|
|
- name: Run headroom init -g ${{ matrix.target }}
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
headroom init -g "${{ matrix.target }}"
|
|
|
|
- name: Assert settings file (POSIX)
|
|
if: runner.os != 'Windows'
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
case "${{ matrix.target }}" in
|
|
claude)
|
|
test -f "$HOME/.claude/settings.json"
|
|
grep -q "ANTHROPIC_BASE_URL" "$HOME/.claude/settings.json"
|
|
;;
|
|
codex)
|
|
test -f "$HOME/.codex/config.toml"
|
|
test -f "$HOME/.codex/hooks.json"
|
|
grep -q "headroom" "$HOME/.codex/config.toml"
|
|
;;
|
|
copilot)
|
|
test -f "$HOME/.copilot/config.json"
|
|
grep -q "SessionStart" "$HOME/.copilot/config.json"
|
|
;;
|
|
esac
|
|
|
|
- name: Assert settings file (Windows)
|
|
if: runner.os == 'Windows'
|
|
shell: pwsh
|
|
run: |
|
|
$ErrorActionPreference = "Stop"
|
|
$home_ = $env:USERPROFILE
|
|
switch ("${{ matrix.target }}") {
|
|
"claude" {
|
|
$p = Join-Path $home_ ".claude\settings.json"
|
|
if (-not (Test-Path $p)) { throw "Missing $p" }
|
|
if (-not ((Get-Content $p -Raw) -match "ANTHROPIC_BASE_URL")) {
|
|
throw "settings.json missing ANTHROPIC_BASE_URL"
|
|
}
|
|
}
|
|
"codex" {
|
|
$c = Join-Path $home_ ".codex\config.toml"
|
|
$h = Join-Path $home_ ".codex\hooks.json"
|
|
if (-not (Test-Path $c)) { throw "Missing $c" }
|
|
if (-not (Test-Path $h)) { throw "Missing $h" }
|
|
if (-not ((Get-Content $c -Raw) -match "headroom")) {
|
|
throw "config.toml missing headroom provider"
|
|
}
|
|
}
|
|
"copilot" {
|
|
$p = Join-Path $home_ ".copilot\config.json"
|
|
if (-not (Test-Path $p)) { throw "Missing $p" }
|
|
if (-not ((Get-Content $p -Raw) -match "SessionStart")) {
|
|
throw "copilot config missing SessionStart hooks"
|
|
}
|
|
}
|
|
}
|