Skip to content

fix(test): isolate the test suite from a live B12 install - #212

Merged
dorukardahan merged 5 commits into
mainfrom
fix/test-isolation
Oct 21, 2026
Merged

dorukardahan merged 5 commits into
mainfrom
fix/test-isolation

Conversation

@dorukardahan

Copy link
Copy Markdown
Owner

Summary

Running the test suite on a machine where B12 is installed reached the live install:

  • Installer tests run install.sh with a temporary HOME, but the launchd job domain is per account. reload_daemon_if_running() saw the live com.b12.mcp.daemon, and install_mcp_daemon() unloaded it through the temporary plist (same label) and loaded the temporary one, so launchd kept respawning a daemon from a pytest temp dir.
  • restart_embed_daemon_if_running() read the live PID file under /tmp and stopped the live embed daemon.
  • The memory DB path is computed from HOME at import time, so a test MCP session wrote its session summary into the live database.

B12_EMBED_RUNTIME_DIR and B12_MCP_DAEMON_SOCK existed but were only honored by the daemons and a few helpers; about 30 hook and script call sites, plus the installer's socket wait and uninstall, still used hardcoded /tmp/b12-* paths. So even a custom runtime dir would not have isolated clients from the live daemon.

This change:

  • honors B12_EMBED_RUNTIME_DIR (embed socket, PID and lock) and B12_MCP_DAEMON_SOCK (socket and the PID file next to it) everywhere; default paths are unchanged
  • adds a root conftest.py whose pytest_configure runs before any test module is imported: HOME, the embed runtime dir and the MCP socket point into a private temp tree, inherited B12_* settings are dropped, no-op launchctl and crontab stubs come first on PATH, and the Hugging Face cache keeps its real location; the tree is removed at pytest_unconfigure
  • adds tests/test_suite_isolation.py, which fails if the isolation is not active
  • documents the rule in CONTRIBUTING.md

Test plan

  • bash -n for all hooks and install.sh; Python heredoc syntax check passes
  • os is imported at module level (or earlier in the same heredoc) at every changed Python site
  • Default paths unchanged (/tmp/b12-mcp-<UID>.pid, /tmp/b12-embed-<UID>.sock)
  • Full suite on macOS with B12 installed and running, twice: 525 passed, 9 skipped, 6 failed. The 6 failures are the same set that fails on unmodified main on macOS (they pass in CI). Before/after snapshots of the live launchd job (plist path and PID), embed daemon PID, crontab, DB max id / row count / deleted count, LaunchAgents and setup settings files were identical. The stub log shows 14 launchctl list com.b12.mcp.daemon calls during the run, each of which used to trigger the hijack
  • tests/test_suite_isolation.py: 4 passed with the conftest, 4 failed with --noconftest
  • No temp trees left behind after the run
  • Net diff under 300 lines

Docs sync

  • README.md updated: not needed
  • docs/architecture.md updated: not needed
  • CHANGELOG.md entries added under Unreleased / Fixed
  • CONTRIBUTING.md documents the isolation and the rule for new code
  • No personal paths committed

Anti-Claude trailer check

  • No Co-Authored-By trailers
  • No generated-with footer

Dependencies

  • No new pip/npm deps

Installer tests rebound the live com.b12.mcp.daemon launchd job to a
temporary plist and stopped the live embed daemon through its /tmp PID
file, and a test MCP session wrote its summary into the live database,
because launchd, /tmp sockets and the HOME-derived DB path are shared with
the developer's real install.

Honor B12_EMBED_RUNTIME_DIR and B12_MCP_DAEMON_SOCK at every hook, script
and installer site (defaults unchanged), and add a root conftest.py that
points HOME and the runtime knobs at a private temp tree and puts no-op
launchctl/crontab stubs first on PATH before any test module is imported.
A self-check test fails if the isolation is not active.
@dorukardahan

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T06:19:27.929750Z 7a0835d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

LoCoMo bench — skipped

locomo10.json fixture not available on this runner

The regression gate runs against the monthly scheduled bench and explicit bench label opt-in.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0945ee5f9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install.sh
install_mcp_daemon() waited for ${B12_MCP_DAEMON_SOCK} but the rendered plist did not carry it, so the daemon bound the default socket and the installer timed out. Write B12_MCP_DAEMON_SOCK and B12_EMBED_RUNTIME_DIR into the job's EnvironmentVariables when they are set. Also make the suite-isolation DB check independent of test order.
@dorukardahan

Copy link
Copy Markdown
Owner Author

@codex review

@github-actions

Copy link
Copy Markdown

LoCoMo bench — skipped

locomo10.json fixture not available on this runner

The regression gate runs against the monthly scheduled bench and explicit bench label opt-in.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 064d842354

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/test_suite_isolation.py Outdated
pwd and os.getuid are Unix-only, so importing the module failed on native Windows. Skip the login-home checks when they are unavailable and the POSIX stub check on Windows.
@dorukardahan

Copy link
Copy Markdown
Owner Author

@codex review

@github-actions

Copy link
Copy Markdown

LoCoMo bench — skipped

locomo10.json fixture not available on this runner

The regression gate runs against the monthly scheduled bench and explicit bench label opt-in.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 97b68b3487

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread conftest.py
The isolated HOME hid ~/.local/b12-venv, so the pagerank guard tests skipped themselves. The conftest now exports the installed interpreter as B12_TEST_VENV_PYTHON (data paths stay isolated) and the pagerank tests use it.
@dorukardahan

Copy link
Copy Markdown
Owner Author

@codex review

@github-actions

Copy link
Copy Markdown

LoCoMo bench — skipped

locomo10.json fixture not available on this runner

The regression gate runs against the monthly scheduled bench and explicit bench label opt-in.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ecc0934051

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread conftest.py
… home

On native Windows os.path.expanduser() reads USERPROFILE, not HOME, so module-level DB paths could still resolve to the live AppData database. Point USERPROFILE at the isolated home and add a platform-neutral self-check that expanduser('~') resolves there.
@dorukardahan

Copy link
Copy Markdown
Owner Author

@codex review

@github-actions

Copy link
Copy Markdown

LoCoMo bench — skipped

locomo10.json fixture not available on this runner

The regression gate runs against the monthly scheduled bench and explicit bench label opt-in.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 7a0835d045

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dorukardahan
dorukardahan merged commit 11927d4 into main Oct 21, 2026
3 checks passed
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