Skip to content

Read a checkout's HEAD with openDox's own reader, not doc_health's RealGit (plan 034 T012) - #47

Merged
brettheap merged 2 commits into
mainfrom
build/034-p1a-t012-own-head-reader
Sep 27, 2026
Merged

brettheap merged 2 commits into
mainfrom
build/034-p1a-t012-own-head-reader

Conversation

@brettheap

@brettheap brettheap commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Plan 034, task T012, slice P1-A (the route seam). The plan is specs/034-opendox-standalone-operation/tasks.md at opensoft/openxFactory main. It has been unchanged since a65230f6 and was re-read at bca4a260. This PR realizes box 4.3 of the ratified add-neutral-product-standalone-operability (openxFactory#1144), for one of its eight reaches into openxFactory.

The task entry, as it reads at bca4a260:

  • T012 [US1] [oDc] serve.py:713 (doc_health.corpus.RealGit in _head_of). Replace it with openDox's own HEAD reader. It must keep degrading to None.
    • Realizes: 4.3 (1 of the 8 reaches into openxFactory).
    • Falsifier: F4.1's scan no longer lists serve.py:713.
    • Ruled: R1Q22 (a).
    • After: T011.

:713 was measured before T011 added its comments. At main 0e88454a the same reach is at serve.py:723.

What changes

  • src/opendox/serve.py:
    • _head_of imported doc_health.corpus.RealGit inside its try. openDox never has that package, so the import raised first. Standalone, the HEAD was always None, and an injected git= reader was never consulted.
    • _CheckoutHead (new, private) is openDox's own reader. It makes the read RealGit.head_sha made, git -C <checkout> rev-parse HEAD, with the same 30-second bound. Every failure is None.
    • _head_of keeps its signature, its git= seam and its outer except Exception: return None.
    • import subprocess joins the standard-library imports.
  • tests/test_checkout_head.py (new) has 8 cases:
    • a real checkout's HEAD is read with doc_health made unimportable through sys.modules, so the case holds where openxFactory's package is installed too;
    • None for a directory that is not a repository (GIT_CEILING_DIRECTORIES keeps git from finding one above it), an unborn HEAD, no git on the PATH, a git that does not answer in time, and an injected reader that raises;
    • an injected reader answers instead of git, and is handed the checkout as a Path;
    • serve.py imports doc_health nowhere, function-local imports included.

Parity with the reader it replaces

openxFactory main's scripts/doc_health/corpus.py, at 3c077874:

_GIT_TIMEOUT_SECONDS = 30                                    # :417

    def _run(self, repo: Path, *args: str) -> str | None:    # :424
        try:
            proc = subprocess.run(["git", "-C", str(repo), *args],
                                  capture_output=True, text=True,
                                  timeout=_GIT_TIMEOUT_SECONDS)
        except (subprocess.TimeoutExpired, OSError):
            return None
        return proc.stdout if proc.returncode == 0 else None

    def head_sha(self, repo: Path) -> str | None:             # :739
        out = self._run(repo, "rev-parse", "HEAD")
        return out.strip() if out else None

The argv, the bound and the verdict on a non-zero exit are the same. There are two differences, and both answer None:

  • subprocess.SubprocessError is caught. It is TimeoutExpired's base class.
  • An answer that is all whitespace is None, where RealGit returned "".

Where doc_health is importable, as in openxFactory, the same git command runs as before.

The falsifier

F4.1's scan is scan_deferred_reaches.py from research.md's appendix. Its sha256 is fe11620319b0…, the digest evidence/remeasure-2026-09-25.md records. It was run from the repository root, as research R5 runs it.

At main 0e88454a it prints 21 deferred reaches, three of them in serve.py:

src/opendox/serve.py:639: openxdox.corpus_root  [in _checkout_real]
src/opendox/serve.py:723: doc_health.corpus  [in _head_of]
src/opendox/serve.py:2032: openxdox.corpus_root  [in _refuse_impossible_checkout_root]

At this head 05b3b5e it prints 20 deferred reaches, two of them in serve.py:

src/opendox/serve.py:640: openxdox.corpus_root  [in _checkout_real]
src/opendox/serve.py:2055: openxdox.corpus_root  [in _refuse_impossible_checkout_root]

With line numbers set aside, the two lists differ by _head_of's entry alone. The two that remain are phase 2's (research R5).

The new tests: 8 passed, with and without the conftest.

Five mutations of the reader were each made in a scratch copy and run with --noconftest. Each is caught:

mutation result the cases that fail
T1: back to doc_health's RealGit 4 failed the HEAD read with doc_health unimportable; the timeout; the injected reader that answers; serve.py imports doc_health nowhere
T2: no timeout 1 failed the timeout
T3: the exit status ignored 1 failed the unborn HEAD. There, git rev-parse HEAD prints HEAD and exits 128
T4: the injected reader ignored 2 failed both injected-reader cases
T5: no degrade around the reader 1 failed the injected reader that raises

Standalone, through build_server. A scratch probe builds a server over a fresh one-commit checkout. doc_health is made unimportable and no head= is passed, so _head_of runs. The probe uses section 6's three phase-1 stand-ins, from tests/test_route_handler_contribution.py. It reads the bound class's head, which _divergence_headers sends as X-Source-Head:

  • at main 0e88454a: None, so the header was empty and the divergence unknown;
  • at this head: the checkout's own git rev-parse HEAD.

The repository's own check

The three report-producing pytest steps of .github/workflows/validate.yml were run locally. Their file lists were read out of the file itself, and the results were summed the way Pin the triple sums them. The venv was Python 3.12.3 with -c constraints-cpython312-linux.txt -e ".[test]".

  • At 05b3b5e: selected=1122 passed=1119 skipped=3 failures=0 errors=0, as at main. The pins are >=1114, >=1111 and ==3.
  • The new file is not one of the triple's named files. T036 makes the required check run the whole suite, and so this file.

The whole suite, with the conftest, in the same venv:

  • main 0e88454a: 19 failed, 1418 passed, 13 skipped, 66 errors;
  • this head: 19 failed, 1426 passed, 13 skipped, 66 errors.

The 85 red cases are the same at both, none new and none gone. The 8 added cases are this PR's, and all pass. The red files are research R3's nine, less test_consumer_reach, which #46 turned green. They also include T030's own test, which in a .[test]-only venv names the missing runtime extra, as #46 recorded.

F2.1, run verbatim at e47a482 with only PATH and TMPDIR set, exits 0: every module of opendox imports with no sibling, then 1 passed. T012 removes no import-time reach, but serve.py gains a module-level import, so the sweep was re-run. The install left an untracked build/, which was removed. 05b3b5e changes only tests/test_checkout_head.py, which the sweep does not run.

pyflakes on serve.py reports 92 warnings at main and the same 92 here. The new test file has none.

Review

Copilot 5328572760 at e47a482 recommended approval. It reported no findings and opened no thread. Its overview raised one nit: test_a_checkouts_head_is_read_with_doc_health_unimportable reads awkwardly. 05b3b5e renames it test_the_head_of_a_checkout_is_read_with_doc_health_unimportable.

SonarCloud's quality gate passed, with two new issues. Both were python:S9083, "Remove empty parentheses from this decorator", on the new file's two @pytest.fixture() lines. 05b3b5e makes both bare.

No assertion changed. The new tests, the five mutations, F4.1, the triple and the whole suite were re-run at 05b3b5e, with the results above.

Copilot 5328584437 at 05b3b5e recommended approval, with no findings. SonarCloud reports no open issue at 05b3b5e.

Landing

Arc: neutral-product-standalone-operability
Lane: openxfactory-4 (openXfactory-4-openDox_extraction)

🤖 Generated with Claude Code

Summary by Sourcery

Replace the deferred doc_health HEAD lookup with openDox's standalone checkout reader while preserving the existing fallback and injection behavior.

New Features:

  • Read checkout HEAD revisions directly through openDox when no external reader is available.

Bug Fixes:

  • Restore standalone HEAD detection while preserving graceful degradation for Git and reader failures.

Enhancements:

  • Remove serve.py's dependency on doc_health and retain the injectable HEAD-reader seam.

Tests:

  • Add coverage for successful standalone HEAD reads, failure cases, injected readers, and absence of doc_health imports.

…alGit (plan 034 T012)

serve.py's _head_of read the checkout's HEAD through openxFactory's
doc_health.corpus.RealGit, a deferred reach into a package a standalone
openDox never has (openxFactory#1144 task 4.3, one of the eight reaches
into openxFactory). In a lone checkout the import failed first, so the HEAD was
always unknown, and even an injected `git=` reader was never consulted.

_CheckoutHead is openDox's own reader. It makes the read RealGit.head_sha
made, `git -C <checkout> rev-parse HEAD`, bounded by the same 30 seconds.
_head_of still degrades to None on every failure: no git on the path, not a
repository, an unborn HEAD, a timeout, or an injected reader that raises.
Its `git=` seam is unchanged: any reader with head_sha(repo), which the
suite's FakeGit has.

The falsifier is F4.1's scan, which no longer lists _head_of: 20 deferred
reaches remain, down from 21. The new tests/test_checkout_head.py covers
each case above. It reads a real checkout's HEAD with doc_health made
unimportable, and five mutations of the reader are each caught. The whole
suite's red set is unchanged, so no test depended on the HEAD being
unknown.

Arc: neutral-product-standalone-operability
Lane: openxfactory-4 (openXfactory-4-openDox_extraction)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 27, 2026 02:32
@sourcery-ai

sourcery-ai Bot commented Sep 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR makes checkout HEAD discovery self-contained in openDox by implementing a subprocess-based reader with the same command, timeout, and failure semantics as doc_health.RealGit, while retaining the injectable seam and adding comprehensive standalone and regression tests.

Sequence diagram for standalone checkout HEAD discovery

sequenceDiagram
    participant Caller
    participant HeadOf as _head_of
    participant Reader as _CheckoutHead
    participant Git as git

    Caller->>HeadOf: _head_of(checkout_root, git)
    alt injected reader provided
        HeadOf->>Reader: head_sha(Path(checkout_root))
    else no injected reader
        HeadOf->>Reader: head_sha(Path(checkout_root))
        Reader->>Git: rev-parse HEAD with 30s timeout
        Git-->>Reader: stdout and returncode
        Reader-->>HeadOf: HEAD or None
    end
    HeadOf-->>Caller: HEAD or None

    alt reader raises or subprocess fails
        HeadOf-->>Caller: None
    end
Loading

File-Level Changes

Change Details Files
Replace the deferred doc_health dependency with an internal, failure-tolerant checkout HEAD reader while preserving the existing injection seam.
  • Add _CheckoutHead using git -C <checkout> rev-parse HEAD with a 30-second timeout.
  • Return None for subprocess failures, non-zero exits, empty output, and exceptions from injected readers.
  • Keep _head_of's signature, git= override, and outer degradation behavior unchanged.
src/opendox/serve.py
Add focused coverage for standalone operation, reader parity, failure handling, and removal of the deferred import reach.
  • Verify HEAD reads succeed when doc_health is unavailable and injected readers receive a Path.
  • Cover non-repositories, unborn repositories, missing git, timeout, and reader exceptions.
  • Statically assert serve.py imports no doc_health module, including function-local imports.
tests/test_checkout_head.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

Copilot review overview

🟢 Approval recommended

Only a minor naming nit remains, with no blocking issues.

Review effort: Lite
Findings: None

What changed in this PR

Updates checkout HEAD detection to use openDox’s own bounded Git reader instead of the optional doc_health dependency.

Changes:

  • Adds _CheckoutHead using git rev-parse HEAD.
  • Preserves injection support and graceful None fallback.
  • Adds coverage for success, failures, timeouts, and dependency isolation.
File Summary
tests/​test_checkout_head.py Adds comprehensive HEAD-reader tests. Nit: rename a_checkouts_head to a_checkout_head.
src/​opendox/​serve.py Implements standalone, timeout-bounded checkout HEAD reading.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

… (T012 review)

Copilot's overview at e47a482 recommended approval, with one nit: the
case name `test_a_checkouts_head_is_read_with_doc_health_unimportable`
reads awkwardly. It is now
`test_the_head_of_a_checkout_is_read_with_doc_health_unimportable`.
SonarCloud's two new issues on the PR were python:S9083, "Remove empty
parentheses from this decorator", on the file's two `@pytest.fixture()`
lines. Both are now bare `@pytest.fixture`. No assertion changed.

Arc: neutral-product-standalone-operability
Lane: openxfactory-4 (openXfactory-4-openDox_extraction)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings September 27, 2026 02:38
@sonarqubecloud

Copy link
Copy Markdown

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.

Copilot review overview

🟢 Approval recommended

All reviewed changes and tests are complete with no unresolved blocking issues.

Review effort: Lite
Findings: None

@brettheap
brettheap marked this pull request as ready for review September 27, 2026 02:41

@sourcery-ai sourcery-ai 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.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 18 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@brettheap

Copy link
Copy Markdown
Contributor Author

READY at 05b3b5e — Lane: openxfactory-4 (openXfactory-4-openDox_extraction)

@brettheap
brettheap merged commit 2768302 into main Sep 27, 2026
5 checks passed
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-4 (openXfactory-4-openDox_extraction)

LANDED — lane openxfactory-4, 2026-09-27T02:47:22Z, PR #47 → 2768302 (opensoft/openDox-code main; plain gate)

Brett: land the phase 1 PRs when green

brettheap added a commit that referenced this pull request Sep 27, 2026
Brings in T011 (#46, 0e88454: remove serve.py's two import-time
reaches) and T012 (#47, 2768302: read a checkout's HEAD with openDox's
own reader), plus the T010/T025/T026/T027 merges already folded into
main earlier. opendox.cli and opendox.serve now import cleanly, so
T021's named test can run for real (no shim, no importorskip skip).

Lane: openxfactory-4 (openXfactory-4-openDox_extraction)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
brettheap added a commit that referenced this pull request Sep 27, 2026
main is 2768302. It carries P1-A's T010 (#40), T011 (#46) and T012 (#47),
which T016 waits for, and P1-E's T025 (#43) and T027 (#41).

Arc: neutral-product-standalone-operability
Lane: openxfactory-4 (openXfactory-4-openDox_extraction)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
brettheap added a commit that referenced this pull request Sep 27, 2026
…nded)

#44 (T021) squash-landed as 9d13bd1, bringing T011 (#46) and T012 (#47)
in with it (already merged into #44's own branch earlier this session,
now folded in via main's squash instead). T022's own diff (cli.py,
serve.py, corpus_adapter.py, local_git_adapter.py,
tests/test_authoring_seam.py) is layered on top of what main now has.

Lane: openxfactory-4 (openXfactory-4-openDox_extraction)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

# Conflicts:
#	tests/test_authoring_seam.py
brettheap added a commit that referenced this pull request Sep 27, 2026
…ly before a build (T016) (#42)

## Summary

Plan 034's **T016** (openxFactory `specs/034-opendox-standalone-operation/tasks.md`, slice P1-B), which realizes box **3.2** of the ratified `add-neutral-product-standalone-operability` (#1144): registration semantics, on R1Q3 (a) with (i) and (ii), and RN-1 (a).

- **The entry points register openDox's default where nothing is registered.** `cli.build_parser()`, `serve.build_server()`, `cli.main()` and `serve.main()` each open with `domain_profile.register_default(default_profile)`, one line each. Afterwards `is_registered()` answers True. The default is an entry-point registration and never a fallback inside `current()`.
- **A bare process that builds nothing still meets `ProfileNotRegistered`** (R1Q3 (i)). `profile_proxy`'s nothing-registered refusal is kept, never weakened into `()`. `current()`'s refusal now names the default. It says that nothing is registered now, either because nothing was built through an entry point or because `unregister()` has dropped the registration since.
- **A host registration made before anything is built replaces the default** (RN-1 (a)). That covers a host that registered first, which the default then never displaces. It also covers a default an entry point registered that nothing has been built from yet, for example after `serve.main()` has registered it at process start.
- **After a parser or a server was built from the default, a host registration is refused** with today's `AlreadyRegistered` (R1Q3 (ii); RN-1 (a)). The message names the default and the build, and says to register before the first build, or to call `unregister()` first for a deliberate swap.
- **Re-registering the object already registered stays a no-op, the default included.** The registration keeps its kind, a host's or the entry point's default, and a build from the default stays on record.
- **What counts as a build.** Only a composition point's read of the facet it composes from. Those are `SUBCOMMAND_EXTENSIONS` in `cli.build_parser()` and `ROUTE_EXTENSIONS` in `serve.build_server()`, the two facets `profile_proxy._LateProfile.READERS` names. Those reads go through `domain_profile.current_for_build()`, which is `current()` plus the record. Every other read only asks and records nothing: `is_registered()`, `current()`, `repr`, a dunder probe, the proxy's `resolve()`, and the `DISPLAY` and `VIEW_EXTENSIONS` reads. So none of these closes the window in which a host still replaces the default: openXdox's `_upstream()`, `view_extension.host_profile_name()`, `display_profile.host_display()`, `view_extension.host_view_facet()` and `canvas_drafts`. T010's optional `HANDLER_CONTRIBUTIONS` is not one of the two reads either: a server's build is recorded at its `ROUTE_EXTENSIONS` read.

## Authority

- Ratified packet: openxFactory#656 comment [`5815412869`](opensoft/openXfactory#656 (comment)).
- **R1Q3 (a)**, with (i) and (ii): openxFactory#656 comment [`5817152735`](opensoft/openXfactory#656 (comment)). *"The default profile and the default adapter are both entry-point registrations, and F3.1 line 2 is amended. 3.2's 'ambiguous registration' wording is corrected. A late host registration replaces the default until something is built, and is refused after that."*
- **RN-1 (a)**: openxFactory#656 comment [`5850003126`](opensoft/openXfactory#656 (comment)). *"reword requirement 3 so a host registration overrides the default only before anything is built from it, and add the after-build refusal scenario."* The requirement's text was amended by openxFactory#1170 (T007 batch D) → `79a720a2`. Its two scenarios are what this PR's cases assert. "A host registers its own profile" covers a registration before a build, which replaces the default. "A host registers a profile after a build from the default" covers the refusal.
- **T007 batch A**, openxFactory#1171 → `bca4a260`, records the ruled amendments to box 3.2 and to F3.1's line 2 in the packet. T016 carries out both, and the amended line 2 is the one run below.
- **R1Q22 (a)**: `cli.py` and `serve.py` are carved files, and no declared-edit act precedes an arc edit.
- The holder's readings on `DISPLAY` and on U4 (`ProjectSubcommand` stays out of the default) are recorded on openxFactory#656 comment [`5851560764`](opensoft/openXfactory#656 (comment)). `default_profile.py` cites both.
- **After**: T015, #38 → `a435aecf`; T012, #47 → `27683028`, with T010 (#40 → `0f10b1f5`) and T011 (#46 → `0e88454a`) before it. All are on `main`, and `main` @ `9d13bd16` is merged in.
- Claim: openxFactory#656 comment [`5850105728`](opensoft/openXfactory#656 (comment)).

## The falsifier

tasks.md, T016: *"**Falsifier**: F3.1 with line 2 as amended (T007 batch A); `tests/test_profile_registration.py`."* Batch A's amendment, now in the packet at `bca4a260`: *"The line asks after `build_parser()`: `python -c "from opendox.cli import build_parser; from opendox import domain_profile as d; build_parser(); print('OK', d.name_of(d.current()))"`. The prose under it adds that a bare process that builds nothing still meets `ProfileNotRegistered`, which `tests/test_profile_registration.py` asserts."*

F3.1 as #1144 writes it, with line 2 as amended, run from the checkout root. The run uses `python3` for `python`, and `pip install -q` to quiet the install:

```sh
set -euo pipefail
W=$(mktemp -d)
python3 -m venv --clear "$W/v3"
. "$W/v3/bin/activate"
pip install -q ".[test]"
python -c "from opendox.cli import build_parser; build_parser(); print('OK')"
python -c "from opendox.cli import build_parser; from opendox import domain_profile as d; build_parser(); print('OK', d.name_of(d.current()))"
python -m pytest -q tests/test_profile_registration.py
```

At `69fecb9d`, in a fresh venv, with nothing on `PYTHONPATH`. T011 is on `main`, so no shim stands in any more:

```
== F3.1, amended line 2, from the checkout root at 69fecb9, no shim
OK
OK opendox.default_profile
...................................................                      [100%]
51 passed in 1.25s
rc=0
```

Line 3 ran with the root conftest in play, as F3.1 runs it.

`tests/test_profile_registration.py` grows from 30 to 51 cases. Its new section 10 asserts the three cases and the seams between them:

| case (R1Q3, RN-1) | test |
|---|---|
| a bare process that builds nothing refuses (i) | `test_a_bare_process_that_builds_nothing_still_meets_the_refusal`, in a fresh interpreter that imports `opendox.cli`, `opendox.serve` and the default, and builds nothing |
| the entry points register the default (a) | `test_f3_1s_second_line_as_amended_names_the_default` (F3.1 line 2, verbatim, in a fresh process); `test_build_parser_registers_the_default_and_builds_on_it`; `test_cli_main_registers_the_default_and_builds_on_it`; `test_build_server_registers_the_default_before_its_first_read` |
| a host registration before a build replaces it (RN-1 (a)) | `test_a_host_registered_before_any_entry_point_keeps_its_own_tree` (no `runtime` command, so a host keeps its 31-entry tree); `test_a_host_registration_replaces_a_default_nothing_was_built_from`; `test_serve_main_registers_the_default_first_and_a_host_may_still_replace_it` |
| a host registration after a build is refused (ii) | `test_a_host_registration_after_a_build_from_the_default_is_refused`, whose message names the default, the build, `5634195861`, R1Q3 (ii), RN-1 (a) and `unregister()` |
| what is a build | a composition point's read of its facet is, once per `READERS` facet (`test_a_composition_points_read_of_its_facet_is_a_build`). Asking is not (`test_asking_which_profile_is_registered_is_not_a_build`), and nor is a read that only asks: the profile's name, `DISPLAY`, `VIEW_EXTENSIONS`, `canvas_drafts` and `resolve()` (`test_a_read_that_only_asks_is_not_a_build`) |
| the other seams | `unregister()` clears the default and its build. Re-registering the object already registered is a no-op, the default included (three cases). `register_default()` never displaces a registration and refuses `None`. The refusal names the default, and after `unregister()` it claims nothing about what the process built |

`build_server()` and `serve.main()` are held from their own lines, lifted by AST, as this file already holds the server's composition point: a server still reaches `openxdox` to be BUILT in phase 1 (research R7), and `serve.main()`'s `--ref` default reads `openxdox.snapshot_registry` (T055, phase 2). The parser and `cli.main()` are run for real.

**Runs at `69fecb9d`**, in a venv built as `validate` builds one (`pip install -c constraints-cpython312-linux.txt -e ".[test]"`):

| run | result |
|---|---|
| `--noconftest tests/test_profile_registration.py tests/test_default_profile.py` | `68 passed` |
| `validate.yml`'s three pytest steps with its "Pin the triple" arithmetic | `selected=1143 passed=1140 skipped=3 failures=0 errors=0`, OK. `main` @ `9d13bd16` gives `1122 / 1119 / 3`, and the 21 more are this slice's new cases |
| CI at `69fecb9d` | `validate`, `runtime` and SonarCloud all green |
| the whole suite, `python -m pytest -q` with the root conftest in play, `main` @ `9d13bd16` against this branch | `19 failed, 1427 passed, 13 skipped, 66 errors` against `19 failed, 1448 passed, 13 skipped, 66 errors`. The 85 red results are the same set on both, in nine files. Eight are research R3's, and T011 cleared its ninth, `tests/test_consumer_reach.py`. The other is `tests/test_imports_standalone.py` (T011), which asks for every extra and passes on both under `pip install -e ".[runtime,test]"` |

**The tests can fail.** Each mutation below was applied to the checkout at `69fecb9d`, `tests/test_profile_registration.py` re-run without any shim, and the file restored:

| mutation | failed |
|---|---|
| `build_parser()` loses its registration line | 3: F3.1 line 2, the parser test, the after-build refusal |
| a host always replaces the default, even after a build (RN-1 (b)) | 6: the server test, the `cli.main()` test, the after-build refusal, both composition-facet builds, the build kept on record |
| a host never replaces the default | 7: both before-build replacements, the after-build refusal's wording, both not-a-build cases, both re-registrations of the default |
| `current()` falls back to the default (R1Q3 (b)) | 9: every refusal case, the bare process among them |
| `current()` records a build | 4: the `serve.main()` window, both not-a-build cases, re-registering before a build |
| `build_server()` reads `ROUTE_EXTENSIONS` before it registers | 1: the server test |
| `serve.main()` loses its registration line | 1: the `serve.main()` test |
| no read records a build | 6: the server test, the `cli.main()` test, the after-build refusal, both composition-facet builds, the build kept on record |
| every read records a build, `resolve()` included (`46519d61`'s proxy) | 1: the read that only asks |
| re-registering the same object falls through (`c755147b`'s `register()`) | 2: both re-registrations of the default |
| the refusal claims the process built nothing (`aee57d5e`'s text) | 1: the refusal after `unregister()` |

`tests/test_default_profile.py`'s facets test now also asserts that the default declares no `HANDLER_CONTRIBUTIONS`. Declaring `HANDLER_CONTRIBUTIONS = ()` fails it.

## Copilot's review

- **At `c755147b`**, *"Changes recommended"*, one thread. `register()` fell through on the object already registered, so re-registering the default cleared its bookkeeping. Fixed in `1dee448e` (the re-registration row above). The thread was answered with the failing run, and it is resolved.
- **At `46519d61`**, *"Changes recommended"*, one thread. Every proxy read went through `current_for_build()`, so `view_extension.host_profile_name()` and `canvas_drafts._facet()` closed the window with nothing built. I reproduced it read by read in fresh processes: all eight reads were refused before the fix, and after it six let a host replace the default. Fixed in `aee57d5e`, at the proxy (the two read-recording rows above). The thread was answered and is resolved.
- **At `aee57d5e`**, *"Needs a closer look"*, no thread, and one note under "previously missed". `current()`'s refusal claimed "this process has built nothing through one", even after `unregister()` had dropped a default that a parser was built from. Fixed in `16d597b8` (the last row above).
- **At `16d597b8`** and **at `69fecb9d`**, *"Needs a closer look"*, Findings: None. At `69fecb9d`: *"The registration lifecycle and build-boundary changes require final human review."* No thread is open.

## The files, and why each is touched

- `src/opendox/domain_profile.py`: `register_default()` and `current_for_build()` are new. `register()` gains a same-object early return, the before-build replacement and the after-build refusal. The refusal texts and the docstrings say what is now true. `is_registered()` and `current()`, the duck-typed contract openXdox's `_upstream()` reads, answer as before, and only the refusal's words changed.
- `src/opendox/profile_proxy.py`: `__getattr__` records a build for the `READERS` facets only. `resolve()` and every other read go through `current()`. The docstrings say which read is a build, and that the nothing-registered refusal is kept.
- `src/opendox/cli.py` and `src/opendox/serve.py`: the one-line calls, and the one paragraph each that said the unregistered case refuses.
- `src/opendox/default_profile.py`: its registration paragraph now describes what the entry points do. Its facet list names T010's `HANDLER_CONTRIBUTIONS`, which it does not declare, and it cites the holder's readings on `DISPLAY` and U4. `tests/test_default_profile.py` asserts that absence.
- `docs/profile-registration-runbook.md`: `current()`'s refusal cites it as the operational contract, and its body described the contract this PR changes. It is a `Status: record`, so it is not rewritten. It gains a pointer under its introduction and a closing section, "The default profile, since plan 034". That section states the new contract, says what counts as a build, and lists what it supersedes, down to rows of the first refusal table. `README.md`'s index row for it follows, one line.

## Left for the tasks that own them

- `tests/test_consumer_reach.py` (T034), `.github/workflows/validate.yml` (T036) and the root `conftest.py` (T035) are not touched. `opendox.default_profile` is not in `test_consumer_reach.py`'s `NEUTRAL_MODULES`. `tests/test_default_profile.py` asserts its import claim in a fresh interpreter with the siblings blocked, and T034 re-derives the census. `conftest.py`'s comment still says *"openDox ships no profile"*. Its `_SuiteProfile` registration stays correct: it registers before any build, so every suite keeps composing the core surface.
- `build_parser()`'s and `build_server()`'s docstrings still carry the stale pre-carve sentence the runbook lists as owed. This PR adds nothing false there, and it leaves that debt to the act that takes it.
- A suite that registers a stand-in profile should register it before it builds, or call `unregister()` first. Once an entry point has built from the default in a process, the default is that process's registration. The suites that register today are this file, `tests/test_view_registry.py` and `tests/test_route_handler_contribution.py`, and all three unregister around every case that registers. The other two put back what they found through `register()`. So an entry point's default found there would come back as a host's registration. No suite depends on that difference today, and neither file is this slice's.

Arc: neutral-product-standalone-operability
Lane: openxfactory-4 (openXfactory-4-openDox_extraction)

🤖 Generated with [Claude Code](https://claude.com/claude-code)


Arc: neutral-product-standalone-operability
Lane: openxfactory-4 (openXfactory-4-openDox_extraction)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
brettheap added a commit that referenced this pull request Sep 27, 2026
> **READY.** #44 (T021) LANDED (squashed as `9d13bd16`); this PR retargeted to `main` directly. T016 (P1-B, #42) has ALSO LANDED (`19370adc`) and is merged into this branch (`ea83200`). T011/T012 landed earlier still. Every gate this task's own "After:" line named is on `main` and merged into this head. Since the merge, Copilot's review ran to completion across eleven rounds at this head and its predecessors -- every finding fixed, verified red-before/green-after, and either replied-and-resolved (a threaded finding) or explained in the landing commit (an untitled "previously missed" one with no thread to reply to). See "Copilot's review, in full" below for what those eleven rounds actually found and fixed -- several were genuine security/correctness bugs, not nitpicks. Final head `9283278`, all three `validate.yml` steps and the whole authoring-seam suite green, zero unresolved review threads.
>
> **RULING, applied at head `d6abe60`, carried forward unchanged through every merge and fix since: the default reads the working tree, not git HEAD.** Brett, 2026-09-27, via the holder: working tree. Standalone users edit files in their own editor, and the hosted openxFactory adapter already shows worktree bytes — so the standalone default must show the same uncommitted bytes, not the session branch's last commit. Recorded on opensoft/openXfactory#656 by the holder. See "The working-tree ruling" section below.

Arc: neutral-product-standalone-operability
Lane: openxfactory-4 (openXfactory-4-openDox_extraction)

**Plan 034, slice P1-D, task T022.** The plan is `specs/034-opendox-standalone-operation/tasks.md` in opensoft/openxFactory, read at #1167's head `42f34ab7` (landed as `a65230f6`, unchanged on `main` at `b5ec3899`). The claim is opensoft/openXfactory#656 comment [`5850371775`](opensoft/openXfactory#656 (comment)) (both T021 and T022).

- **Realizes**: 4.1a.
- **Ruled**: R1Q3 (a), R1Q22 (a), comment `5817152735`.
- **After**: T020 (LANDED, #37 → `e295b1a9`), T021 (LANDED, #44 → `9d13bd16`), T016 (LANDED, #42 → `19370adc`). All landed; all merged into this branch.

## What it does

Where no host has called `corpus_adapter.register_home(...)`, openDox's own entry points now register a `home_corpus`-shaped factory over its own conformant `WorkingTreeCorpus` (`src/opendox/runtime/local_git_adapter.py`, a `LocalGitCorpus` subclass — see the ruling below) — exactly as the default profile stands in for an unregistered host (Group 3, T016). It starts at bare defaults (`required_fields=()`); phase 2's T054 sets the neutral fields R1Q13 decides. A bare process that builds nothing still meets 4.2's `ADAPTER_NOT_REGISTERED` refusal (T020, unchanged). `_default_home_factory` builds a fresh `WorkingTreeCorpus()` on every call — no listing cache keyed on HEAD, so there is nothing to invalidate when the working tree changes under it.

**The seam gains one function, mirroring T016's `domain_profile.register_default()`.** While authoring this task I found T016's own draft PR (#42, not yet landed) already open, and it puts the "register only where nothing is" check *inside* `domain_profile.py` as `register_default(profile)`, so `cli.build_parser()`'s own call is genuinely one line. `corpus_adapter.py` had no such helper (only `register_home()`/`home()`, T020), so this task adds `corpus_adapter.register_default_home(factory)`: it calls `home()` first, and registers `factory` only on the ONE refusal kind that means "nothing is registered yet" (any other `CorpusRefused` is re-raised, never swallowed). Unlike `register_default()`, there is no after-build refusal to track — box 4.1a asks for nothing like RN-1's after-build semantics for the corpus adapter, so this stays as simple as `register_home()` itself.

`LocalGitCorpus`'s own factory (`_default_home_factory`) is duplicated, byte-identical, in `cli.py` and `serve.py` rather than living in `corpus_adapter.py`: that module cannot import `local_git_adapter` without creating the cycle `local_git_adapter.py` already has the other way (`from opendox.corpus_adapter import …`).

**Four call sites**, mirroring T016's four exactly:
- `cli.build_parser()` — the FIRST statement, ahead of the (pre-T016) profile read that can still refuse `ProfileNotRegistered` today.
- `cli.main()` — redundant with `build_parser()`'s own call (which `main()` calls next), kept for the same reason T016 keeps its own match: the outermost entry point states the contract on its own.
- `serve.build_server()` — the FIRST statement, ahead of the profile read two lines below.
- `serve.main()` — redundant with `build_server()`'s own call, same reasoning.

Files: `src/opendox/cli.py`, `src/opendox/serve.py`, `src/opendox/corpus_adapter.py`, `src/opendox/runtime/local_git_adapter.py`, `tests/test_authoring_seam.py`.

## The working-tree ruling: `WorkingTreeCorpus`

`LocalGitCorpus` (the conformant local-git adapter RULING C3 asks for) reads via git plumbing at a resolved revision — `git ls-tree`/`git cat-file blob` at `resolve()`'s revision, defaulting to git HEAD. That is the right read for a *hosted* session bound to a commit, but the wrong one for a standalone default: a standalone user's uncommitted edit would be invisible until they committed it, which is not what "point openDox at my working directory" means to someone editing in their own editor.

`WorkingTreeCorpus(LocalGitCorpus)`, appended to `local_git_adapter.py`, overrides exactly the two methods that decide *where bytes come from*, and nothing else:

- `_list_documents_bound` — `git ls-files -z --cached --others --exclude-standard` (tracked + untracked-but-not-ignored), not `git ls-tree`.
- `_read_bound` — `(Path(corpus.location) / document.key).read_bytes()` when no explicit `revision` is named, falling back to the parent's commit-based read (`super()._read_bound(...)`) when the caller DOES name one. An explicit revision still means what it always meant; only the *default*, no-revision read moved to disk.

`resolve()`, `classify()` (which reads through `read()`, so the override already flows into it), `check()` and `write_back()` are inherited unchanged — `check()`'s existing "uncommitted change" divergence semantics are deliberately untouched by this ruling, which is only about where the DEFAULT corpus's bytes come from.

**The edge case the ruling doesn't mention, and had to be decided anyway:** the repository openDox's own "create a repository" act produces is **bare** (RULING C3, confirmed by `tests_runtime/test_local_git_adapter.py`'s own fixtures) — no working tree at all. `WorkingTreeCorpus` refuses `CorpusRefused(CORPUS_UNREADABLE, ...)` with a detail naming the reason ("this repository is bare … register a host adapter instead, or point this default at an ordinary checkout") rather than silently falling back to git-HEAD reads or crashing on a missing directory.

**Falsifier**, added to `tests/test_authoring_seam.py`:
`test_an_uncommitted_edit_is_visible_through_the_default` builds an ORDINARY (non-bare) checkout by hand, commits one file, resolves it through the registered default, reads the committed bytes, edits the file on disk WITHOUT committing, reads again through the *same resolved corpus object*, and asserts the new bytes are visible; then adds a brand-new untracked file and asserts `list_documents` includes it too.

**Red-checked**: temporarily reverting `cli.py`'s factory back to plain `LocalGitCorpus()` makes this same test fail with `AssertionError: the default served the committed bytes after an uncommitted edit -- it is reading git HEAD, not the working tree` — proving the test actually exercises the ruling, not a vacuous assertion. Restored immediately after confirming the failure; the PR's actual head builds `WorkingTreeCorpus()`.

**A second, unplanned falsifier this class tripped**: `tests_runtime/test_runtime_cli.py`'s anti-leak walk (an AST scan, run over *every* module in the runtime package, that a `except <non-package-exception> as exc` handler may not format `exc`'s text into evidence except through `_safe_message`/`redact_credentials`/`redact_remote_url` — the A25-1 regression class) flagged my first cut of `_read_bound`'s `except OSError as failed:` branch, which passed `str(failed)` straight to `_refuse(...)`. Fixed by routing it through this file's own established idiom for the identical concern (`redact_credentials(str(exc))`, already used for `GitCommandFailed`'s OS-error path, with the exact same rationale recorded there: *"An OS error's text can carry the argv's filename, so it is cleaned where it is composed"* — here it is the working-tree file's own path, read by `Path.read_bytes()`, that could otherwise leak). Confirmed red before the fix (`1 failed, 360 passed`, the one failure being exactly this finding) and green after (`361 passed`) in `tests_runtime`'s full three-file replay of `validate.yml`'s step 3.

## Falsifier: the named test -- now genuinely real, T011 has landed

`tests/test_authoring_seam.py::test_an_entry_point_registers_the_local_git_corpus_when_no_host_has` calls `cli.build_parser()` with nothing registered, then requires `corpus_adapter.home()` to return a factory whose adapter is a `WorkingTreeCorpus` instance (updated for the ruling above; was `LocalGitCorpus` before it).

**T011 (#46 → `0e88454a`), T012 (#47 → `2768302`) and T016 (#42 → `19370adc`) have all landed**, so `opendox.cli`/`opendox.serve` import cleanly, `domain_profile.register_default()` runs at the same entry points this task's own registration does, and this whole file runs for real -- the ordinary way, with the root conftest in play, no `--noconftest`, no shim, no skip:

```
$ python -m pytest -q tests/test_authoring_seam.py
............
12 passed in 0.30s
```

All twelve pass (ten at the T016 merge, plus two more added during the Copilot remediation below: an end-to-end classify-through-the-default falsifier, and the same entry-point coverage for `serve.build_server()`). Every `try: cli.build_parser() except domain_profile.ProfileNotRegistered: pass` tolerance in this file is now genuinely dead code -- T016 landed, so `build_parser()` no longer raises at all -- kept only as a harmless compatibility fallback, and the two stale docstrings/comments that used to describe this as a live "SKIPS today" condition were corrected during the Copilot rounds below.

The remaining two cases (`test_register_default_home_leaves_an_existing_registration_alone`, `test_register_default_home_registers_where_nothing_has`) exercise `corpus_adapter.register_default_home()` directly, over stand-in factories, and always ran unconditionally -- no shim, no `--noconftest`, needed neither before this merge nor after.

(Historical note, preserved for the record: before this merge, the two `importorskip`-gated cases above skipped under both plain and `--noconftest` runs -- `8 passed, 2 skipped` -- and were verified only under the Group 2 simulation shim, `research.md`'s Appendix, giving `10 passed`. That shim is no longer needed for anything in this PR and was never committed.)

## Falsifier: F4.1's scan is unchanged

This task registers a default; it does not remove a deferred reach, and `corpus_adapter`/`local_git_adapter` name neither `openxdox` nor `ideation_dashboard` nor `doc_health` nor `corpus_adapter_openxfactory`. Re-run at the `main`-merged head (`8a3625e`) against `main`'s OWN current tip (`9d13bd16`, carrying T021+T011+T012 -- T011/T030 and T012 each removed a hit of their own, which is why the absolute count dropped from the 23/24 seen in earlier rounds of this PR to **19** here): both `main` at `9d13bd16` and this merged head scan to exactly **19**, identical hits by identity (same file, same imported name, same enclosing function) -- the only per-line differences are the expected line-number shifts in `cli.py` (610→618) and `serve.py` (640→647, 2055→2106) from this task's own registration call and `_default_home_factory` sitting above them. Zero new reaches, zero removed, confirmed by a normalized diff against a fresh worktree at `main`'s exact merged-in commit.

**Not re-run against the full scan tool after the T016 merge or the Copilot remediation rounds below**, since neither touched an import statement: T016's own two files (`domain_profile.py`, `cli.py`/`serve.py`'s registration lines) are unrelated to this scan's targets, and every file the Copilot rounds touched (`local_git_adapter.py`, `tests_runtime/test_local_git_adapter.py`, `tests/test_authoring_seam.py`) was grepped directly for the same four names at the final head -- the only hits are pre-existing prose in `authoring.py`'s comments/docstrings (`doc_health.corpus...`, `doc_health.lines...`, and the `corpus_adapter_openxfactory` name inside a docstring describing what T021 REMOVED), none of them an actual import or attribute reach.

## The repository's own checks, replayed locally

`validate.yml`'s three pytest steps are unaffected (no slice edits `validate.yml` before T036; this task's new/changed tests are not in any of its file lists, except `tests_runtime/test_local_git_adapter.py`, which IS on the `runtime, hermetic` step's list) — replayed at each stage, file lists read directly from the workflow file each time:

| step | at #44's head (`f6f07ae`) | pre-ruling (`d86677c`) | post-ruling (`d6abe60`) | `main`+T016 merged in, final (`9283278`) |
|---|---|---|---|---|
| `pytest` | 745 passed, 2 skipped | 745 passed, 2 skipped | 745 passed, 2 skipped | 767 passed, 2 skipped |
| `pytest (S7 residue)` | 13 passed | 13 passed | 13 passed | 13 passed |
| `pytest (runtime, hermetic)` | 361 passed | 361 passed | 361 passed\* | 372 passed |

(The `pytest` step's `746 → 767` climbs further than the earlier `745 → 746` because several more upstream PRs (T025/T026/T027 and others) merged into `main` between the earlier checkpoints and this final one, all touching files already on that step's list, none of them this task's own doing -- same reasoning as the earlier `745→746`, just a larger number of intervening merges by this point. The `runtime, hermetic` step's `361 → 372` is fully this task's own: 11 new cases added across the Copilot remediation rounds below, all in `tests_runtime/test_local_git_adapter.py`.)

(The `pytest` step's `745 -> 746` is identical to what #44 itself measured post-merge -- not investigated to the single test name, but confirmed NOT this task's doing: this task's own new tests are all in `tests/test_authoring_seam.py`, which is not on this step's file list at all, and the same `+1` appears on #44's branch, which carries none of T022's changes. `tests_runtime`'s total floats by ±1 across repeated runs at the SAME commit -- a pre-existing, environment-timed flake unrelated to this change, recorded once and not re-investigated at every stage.)

**\*One genuine regression surfaced mid-way, caught before commit, not a flake:** `WorkingTreeCorpus`'s first cut of `_read_bound`'s `except OSError as failed:` branch put `str(failed)` straight into a refusal, and `tests_runtime/test_runtime_cli.py`'s anti-leak walk correctly flagged it (`1 failed, 360 passed` — see "The working-tree ruling" section above for the fix and the exact failure text). Fixed by routing the text through `redact_credentials(str(failed))`, matching this file's own established idiom; every `361 passed` in the table above (including at this PR's very first, pre-ruling head, where the bug did not yet exist) is genuinely clean.

**The whole `tests/` directory** (real conftest throughout at and after the `main` merge; the Group 2 shim only for the two earlier, pre-T011 stages):

| tree | result |
|---|---|
| #44's head (`f6f07ae`), with shim | `20 failed, 1242 passed, 13 skipped, 66 errors` |
| #45 pre-ruling (`d86677c`), with shim | `20 failed, 1245 passed, 13 skipped, 66 errors` |
| #45 post-ruling (`d6abe60`), with shim | `20 failed, 1246 passed, 13 skipped, 66 errors` |
| `main` merged in (`8a3625e`), REAL conftest, no shim | `18 failed, 1432 passed, 13 skipped, 66 errors` |

The `20→18` failed and `66` unchanged errors match #44's own post-merge numbers exactly (both branches merged the same `main`). JUnit test-by-test diff (by `classname::name`, exact) between the pre-ruling and post-ruling shimmed heads: zero outcomes changed, one new passing test (the working-tree falsifier). The jump to `1432` passed at the merged head is `main`'s own T010/T011/T012 tests joining the run for the first time (this PR touches none of them) plus this file's own count going from 6 (T021-only, on the old base) to 10 (all of T022's, all genuinely running now).

## T016 merged in

Merged `main` (carrying T016, `19370adc`) into this branch at `ea83200`. One real conflict, in `cli.py`/`serve.py`: both T016's `domain_profile.register_default(default_profile)` and this task's own `corpus_adapter.register_default_home(_default_home_factory)` wanted to be the literal first statement in `build_parser()`/`main()` and `build_server()`/`main()`. Resolved by keeping T016's call first (it has an immediate downstream read in the same function) and this task's second, with a comment explaining the order; also fixed a now-stale comment in `serve.py` left over from before the merge. A second conflict, in `tests/test_authoring_seam.py` (main's squashed T021 and this branch's pre-squash T021 ancestor carrying the same content by different commit objects, the identical class of conflict the earlier `main` merge hit), resolved the same way -- "theirs" contributed nothing, confirmed by an empty post-resolution diff.

## Copilot's review, in full: eleven rounds, every finding fixed

Per the standing instruction to wait for Copilot's review AT THE HEAD before READY -- and to read the review body, not just trust a green check-run conclusion -- eleven successive rounds of Copilot review each found something real after the T016 merge, every one fixed and verified red-before/green-after before moving to the next. In finding order:

1. **Temp-directory classification was broken by the T016 merge's own registration**: once the default registered for real, `authoring._classify_proposal()` staged its input in a plain, non-git `TemporaryDirectory`, and `WorkingTreeCorpus.resolve()` requires a git repository -- every classification call started refusing `CORPUS_UNCLASSIFIABLE`. Fixed with a `_stage_as_a_repository_if_git_is_available()` step, gated by the registered adapter's own MODULE NAME (never `isinstance`, preserving `_classify_proposal`'s "no privileged direct call" principle) so a host's non-git adapter is never affected.
2. **Path-traversal and symlink-escape in `_read_bound`**: a plain `Path(corpus.location) / document.key` open was vulnerable to an absolute-key override, `..` traversal, and a symlinked intermediate component. Fixed with a new `_open_confined()` -- a component-by-component, `O_NOFOLLOW`-at-every-step, descriptor-relative open -- plus name-based rejection of absolute/`..`/`.git`/NUL keys.
3. **The listing could advertise what `read()` could not serve**: gitlinks, untracked nested checkouts, and tracked-but-deleted files. Fixed with mode-based gitlink filtering, trailing-slash nested-repo filtering, and a per-candidate existence check through the same confined open.
4. **A pinned `CorpusRef.revision` was silently ignored** in favor of current disk bytes. Fixed by also checking `corpus.ref.revision`.
5. **`git init`'s ambient environment**: `GIT_TEMPLATE_DIR` was missing from the shared environment sanitizer, so an ambient template directory could plant a repository-local `info/exclude` into a staged tree (demonstrated live: a hostile template really does get copied in unsanitized, and doesn't once filtered); a test helper (`_init_ordinary_checkout`) and this PR's OWN new test for the fix above BOTH separately built their git subprocess environment from a raw `os.environ` copy instead of the shared sanitizer, the identical hazard found and fixed three times in three different places across this remediation, plus once more in this file's own long-standing shared `_GIT_ENV` fixture (exposed, not introduced, by this task's first fixture to call `git init` on a fresh location).
6. **A blocking read of a tracked FIFO could hang forever**, taking `list_documents()`'s own existence check down with it. Fixed with `O_NONBLOCK` on the leaf open plus an `S_ISREG` check.
7. **`read()` exposed files the corpus's own definition excludes**: a directly-constructed `DocumentId` for a `.gitignore`d secret (a `.env`, say) was served, because confinement-to-the-root is not the same guarantee as membership-in-the-corpus. Fixed with a new `_tracked_or_not_ignored()` check ("tracked always wins" over a later ignore rule; a git failure here is `CORPUS_UNREADABLE`, never a false "not tracked" -- the eleventh finding, on this fix's own first cut).
8. **Stale historical documentation**, twice: a module docstring and two individual test docstrings/comments still described `--noconftest`/skip behavior in the present tense after T011 and T016 had already landed on this branch, which would misreport current coverage to a future reader.
9. **Missing runtime test coverage** for `WorkingTreeCorpus` itself (a large new class with zero direct `tests_runtime/` cases before this remediation) and for `serve.build_server()`'s own registration line (AST-lifted, mirroring `test_profile_registration.py`'s established technique for the identical problem).

Every fix above was verified by first reproducing the exact failure against the pre-fix code (a manual repro script, a temporary revert via `sed`/direct text substitution, or a deliberately broken assertion), confirming it failed for the stated reason, fixing it, confirming green, and -- for anything touching a committed file -- confirming the revert-and-restore cycle left the file byte-identical to before. One mistake was caught and fixed within this same remediation, before it shipped: the first cut of finding 7's fix used `:(literal)key` pathspec magic, which `GitRunner`'s own pre-existing `--literal-pathspecs` flag (predating this session) turns from protective into actively wrong -- measured directly, then fixed by passing the bare key.

Every threaded finding got a reply citing the exact fixing commit, then was resolved via GraphQL; two "previously missed" findings (9's `WorkingTreeCorpus` coverage gap, and one instance of 5's `_GIT_ENV` hazard) had no inline thread to reply to at all -- Copilot's overview lists them without a `#discussion_r` link -- so their reasoning lives only in the fixing commit's own message. **Zero unresolved review threads remain as of the final head.**

## Status: READY

Final head `9283278`. Working tree clean, T016/T011/T012 all landed and merged in, all three `validate.yml` steps green (767p/2s, 13p, 372p), `tests/test_authoring_seam.py` at 12 passed, the anti-leak scan and the home-vocabulary scan both green, zero unresolved Copilot review threads.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


Arc: neutral-product-standalone-operability
Lane: openxfactory-4 (openXfactory-4-openDox_extraction)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
brettheap added a commit that referenced this pull request Sep 27, 2026
…into openxFactory at all (#49)

Plan 034, task **T032**, slice P1-F (the sweep and the nine-file repair). The plan is `specs/034-opendox-standalone-operation/tasks.md` at opensoft/openxFactory `main` `468863d1`, where round 2 (#1176) has landed. The T032 through T035 entries there are byte-identical to `0d48231b`'s, which this record was first written against. This PR realizes box **2.3** of the ratified `add-neutral-product-standalone-operability`.

- **Ruled:** R1Q22 (a), openxFactory#656 comment `5817152735`.
- **Claim:** openxFactory#656 comment `5852380744`.
- **After:** T011, T012, T016, T021, T022, T025–T027 ("every lane joins here"). **All have landed.** T022 landed last, as #45 → `255514df`, merged in at `5270acf0`. T038 then landed as #48 → `796838e8`, and `main` at `796838e8` is merged in (`dc8fa87a`, no force-push). Everything below was re-run at this head, `b53b9db2`.

## The sweep (2.3)

The four names in import position under `src/`: import statements, and `importlib.import_module(...)` or `__import__(...)` with a literal name. Every hit is classified by when it runs. It was run at the arc's base, openDox-code `1e4a57fb` (ARC_BASE, `evidence/arc-base.md`), and at `main` `796838e8`. That is where the last lane (T022) joined, plus T038's console script. This PR changes nothing under `src/`, so this head gives the same result.

| | at `1e4a57fb` | at `796838e8` |
|---|---|---|
| import-time reaches | 2 (`ideation_dashboard`) | **0** |
| deferred reaches into openxFactory | 8 | **0** |
| deferred reaches into `openxdox` | 19 | **19** |

**Closed: every reach into openxFactory, and every import-time reach.**

| reach at `1e4a57fb` | target | closed by | landed |
|---|---|---|---|
| `serve.py:199`, `:206` (import time) | `ideation_dashboard.serve_openxfactory_lanes` | T011 (2.1), the handler-contribution facet | #46 → `0e88454a` |
| `serve.py:713`, `_head_of` | `doc_health.corpus` (`RealGit`) | T012, openDox's own HEAD reader | #47 → `27683028` |
| `authoring.py:318`, `_classify_proposal` | `corpus_adapter_openxfactory` | T021, `corpus_adapter.home()` | #44 → `9d13bd16` |
| `workbench.py:746`, `session_documents` | `doc_health.corpus` | T025, the registered adapter's `list_documents` | #43 → `c46430fb` |
| `workbench.py:1407`, `:1408`, `:1409`, `run_scoped_doc_health` | `doc_health`, `.families`, `.runner` | T026, the health-check seam | #39 → `582ed073` |
| `serve_wire.py:1369`, `default_doxbench_validators` | `ideation_dashboard.doxbench_contracts` | T027, the doxBench validator seam | #41 → `8017cd52` |
| `doxbench_packet.py:177`, `_status_exemption` | `ideation_dashboard.doxbench_status_exemption` | T027, the status-exemption seam | #41 → `8017cd52` |

**Deferred: 19 reaches, all into `openxdox`, each inside a function body.** Each is routed no later than the phase whose surface calls it (research R5, the release map). openXdox-code's `OPENDOX_BACK_IMPORTS` ratchet counts them by module: `branch_session` 7, `serve_workbench` 7, `serve` 2, `serve_project` 2, `cli` 1.

| reach at `796838e8` | target | inside | reason it stays, and who routes it |
|---|---|---|---|
| `branch_session.py:1568` | `openxdox.generator` | `_change_rows` | the snapshot generator is openXdox's column; phase 2, T055 (5.4/5.5) |
| `branch_session.py:1587` | `openxdox.register` | `_active_pick_fallbacks` | the cross-reference register; phase 3, T084 |
| `branch_session.py:2005` | `openxdox.kickoff` | `proposal_state_for` | the kickoff column; phase 3, T084 |
| `branch_session.py:2105`, `:2151`, `:2228`, `:3573` | `openxdox.snapshot_registry` | `session_entry`, `register_session_entry`, `refresh_session_snapshot`, `refresh_main_view` | the snapshot registry; phase 2, T055 |
| `cli.py:628` | `openxdox.snapshot_registry` | `_session_registry` | the snapshot registry; phase 2, T055 |
| `serve.py:648` | `openxdox.corpus_root` | `_checkout_real`, called by every `build_server` | the corpus-root predicate; phase 2, T055 (research R7) |
| `serve.py:2118` | `openxdox.corpus_root` | `_refuse_impossible_checkout_root`, called by `serve.main()` | the corpus-root predicate; phase 2, T055 |
| `serve_project.py:246`, `:247` | `openxdox.gate_console`, `openxdox.kickoff` | `_serve_project_register` | the gate console and kickoff; phase 3, T084 |
| `serve_workbench.py:347`, `:544`, `:1665`, `:2607` | `openxdox.doxbench_scope` | `_is_live_session_ref`, `_handle_workbench_thread`, `_handle_workbench_chat_turn`, `_handle_workbench_document_abstract` | doxBench scope; phase 3, T084 |
| `serve_workbench.py:407`, `:408` | `openxdox.gate_console`, `openxdox.gate_routes` | `_thread_gate` | the gate column; phase 3, T084 |
| `serve_workbench.py:1215` | `openxdox.gate_console` | `_handle_workbench_model_approval` | the gate column; phase 3, T084 |

The line numbers moved since research R5 (`cli.py:610` → `:628`, `serve.py:629` → `:648`, `serve.py:1993` → `:2118`), with the code that phase 1, T022 and T038 added. The reaches and their functions did not.

**The late seam, which the scan cannot read.** `consumer_reach.py` holds seven `module(...)` stand-ins (`gate_console`, `snapshot`, `snapshot_registry`, `corpus_root`, `generator`, `serve_projection`, `serve_gate`). Each resolves `openxdox.<name>` at first use. `module()` refuses a prefixed name, so no stand-in can name another package. Research R6's census is unchanged: 65 use sites, in `serve.py` 22, `branch_session.py` 20, `cli.py` 18, `serve_workbench.py` 4 and `workbench.py` 1. They are deferred too, into `openxdox` alone, and T084 retires the module.

**Prose, not import position.** `git grep -w` finds each name in `src/` beyond these: `ideation_dashboard` on 44 lines, `doc_health` on 25, `corpus_adapter_openxfactory` on 2, and the rest of `openxdox`'s 57. Every one of them outside the table above is a comment, a docstring or a string. Several docstrings still describe the pre-carve layout. `serve_project.py:30`, `serve_wire.py:80`, `serve_workbench.py:33` and `doxbench_scope_types.py:40` say *"this module uses ABSOLUTE `ideation_dashboard.*` imports"*. None of them is a reach. They sit in carved files with other writers, so this PR leaves them. A later edit to each file can correct its sentence.

## What changes

**`tests/test_reach_sweep.py`**, a new file, so the sweep's result is held and not only recorded here. It parses `src/` whole, the two top-level extension modules included, as F4.1 parses the package, and it asserts four things:
1. no reach into any of the four runs at import time;
2. no reach of any kind names `ideation_dashboard`, `doc_health` or `corpus_adapter_openxfactory`, in either spelling (the pre-carve `scripts.` one too), the phase-1 cut of 4.3;
3. every reach left is deferred and into `openxdox`, the positive form of F4.1 "lists only `openxdox` targets";
4. no code under `src/` spells an openxFactory package's name at all. That means no string or bytes literal outside documentation, because every import needs the name, however the importer is reached.

**It does not pin the count of 19.** openXdox-code's ratchet already counts those reaches, and each one that T055 or T084 routes simply stops being one. So no later task has to edit this file when a reach closes. A reach may not come back at import time, and none may go into openxFactory. No instrument watched that direction (#1144 task 9.2a), and `tests/test_imports_standalone.py` proves only its import-time half, where no sibling is installed. On this tree, the sweep itself finds exactly F4.1's 19, all `openxdox` and all deferred.

**How it reads a module.** It reads by syntax, not by grep. Prose names the four packages on purpose.
- **Statements.** Import statements, including `from a import b`'s members as the submodules they may be (`from scripts import doc_health`). A star member is named too.
- **Calls.** `import_module` and `__import__` calls with a literal name, by position, as `name=`, or spelled out of a literal `*[...]`/`**{...}`, and under an import alias.
- **Relative names.** They are resolved against a literal `package`. `__import__` resolves against its `globals`: `globals()` is the module's own, and a literal `{"__package__": ...}` resolves. `__import__`'s literal `fromlist` also counts.
- **A module that holds an importer as a value** (assigns, passes, stores it, or looks it up by name) is read strictly. Every call with a literal module name counts there, read as either importer, since it may be bound to either.
- **Refused as UNREADABLE:** a call whose module a spread hides; a relative call whose package or context is unknown; a relative call that leans on `globals()` or `__package__` in a module that rebinds them; a `fromlist` that is not a literal; and a star import, in either form, from a package a sibling lives under (`from scripts import *`). A star from `os` names nothing.
- **Not refused:** a computed name, which is how `consumer_reach`'s seam imports.
- **Timing.** Where position and run time part (`TYPE_CHECKING`, postponed annotations, a generator), it reads position, the stricter reading. PEP 695's lazy positions are read as deferred.
- **What it is not.** It is a regression guard for the code this repository writes, not a sandbox. A name built from pieces at run time is review's to hold, and at import time the runtime sweeps (`test_imports_standalone.py`, `test_consumer_reach.py`) hold it too.

**`tests/import_scan.py`**, the shared reader, which exists so that no direction check keeps its own copy of the extraction. The node reader `names_imported_by` and its helpers live there, and `imported_modules` reads with it. Every new behaviour is opt-in, so `imported_modules`' output, `bound_names`', and `string_literals`' default output are identical to `main`'s reader over every parsed file in this repository: 141 files, 1524 imports, 0 differ. The three callers of `imported_modules` give the same result with and without the edit.

## The falsifier: F4.1's scan, which lists only `openxdox` targets

`scan_deferred_reaches.py`, research.md's appendix, persisted in opensoft/brett-wip. Its sha256 is `fe11620319b02c23dd9a014bc581e1f4867f013f3c26890d43b12dccce5530a0`, which matches the digest `evidence/remeasure-2026-09-25.md` records. Run from this head, `python3 scan_deferred_reaches.py src/opendox`:

```
src/opendox/branch_session.py:1568: openxdox  [in _change_rows]
src/opendox/branch_session.py:1587: openxdox.register  [in _active_pick_fallbacks]
src/opendox/branch_session.py:2005: openxdox  [in proposal_state_for]
src/opendox/branch_session.py:2105: openxdox.snapshot_registry  [in session_entry]
src/opendox/branch_session.py:2151: openxdox.snapshot_registry  [in register_session_entry]
src/opendox/branch_session.py:2228: openxdox.snapshot_registry  [in refresh_session_snapshot]
src/opendox/branch_session.py:3573: openxdox.snapshot_registry  [in refresh_main_view]
src/opendox/cli.py:628: openxdox.snapshot_registry  [in _session_registry]
src/opendox/serve.py:648: openxdox.corpus_root  [in _checkout_real]
src/opendox/serve.py:2118: openxdox.corpus_root  [in _refuse_impossible_checkout_root]
src/opendox/serve_project.py:246: openxdox.gate_console  [in _serve_project_register]
src/opendox/serve_project.py:247: openxdox.kickoff  [in _serve_project_register]
src/opendox/serve_workbench.py:347: openxdox  [in _is_live_session_ref]
src/opendox/serve_workbench.py:407: openxdox  [in _thread_gate]
src/opendox/serve_workbench.py:408: openxdox  [in _thread_gate]
src/opendox/serve_workbench.py:544: openxdox  [in _handle_workbench_thread]
src/opendox/serve_workbench.py:1215: openxdox  [in _handle_workbench_model_approval]
src/opendox/serve_workbench.py:1665: openxdox  [in _handle_workbench_chat_turn]
src/opendox/serve_workbench.py:2607: openxdox  [in _handle_workbench_document_abstract]
19 deferred reaches
```

Every target is `openxdox`. At `1e4a57fb` the same tool printed 27, eight of them into openxFactory. F4.1 WHOLE, *"no deferred reach names the consumer or the publisher"*, is T089's, after T084 routes the last 19 and retires `consumer_reach.py`.

**The new test.** `python -m pytest -q tests/test_reach_sweep.py` at this head gives `35 passed`, with the root conftest and under `--noconftest`. The same file, with this head's `tests/import_scan.py`, run over `1e4a57fb`'s tree fails the three reach assertions:

```
AssertionError: 2 reach(es) into a sibling run at IMPORT time, so the module cannot be imported without it (#1144 task 2.1's defect): src/opendox/serve.py:199: ideation_dashboard (AT IMPORT TIME, in <module>); src/opendox/serve.py:206: ideation_dashboard.serve_openxfactory_lanes (AT IMPORT TIME, in <module>)
AssertionError: 10 reach(es) into openxFactory, which openDox can never install (#1144 task 4.3's phase-1 cut), or imports the source does not spell out (behind a spread, a star, or a context that is not a literal), which could be: src/opendox/authoring.py:318: corpus_adapter_openxfactory (deferred, in _classify_proposal); …
3 failed, 32 passed
```

**83 mutations, and each fails its assertion.** Each is a copy of this tree with one change. Roughly a third plant a reach in `src/`, and the rest weaken the reader or the sweep. The list is in the review record below, and the spec is kept with the slice's tools. Every finding in the review record was also planted at the head it was raised on, where it passed, before its fix.

## The repository's own check

`.github/workflows/validate.yml`'s three report-producing pytest steps, run as the file writes them, and summed as `Pin the triple` sums them. The venv was Python 3.12.3 with `-c constraints-cpython312-linux.txt -e ".[test]"`:

```
triple: selected=1155 passed=1152 skipped=3 failures=0 errors=0
pins:   selected>=1114 (margin 41) passed>=1111 (margin 41) skipped==3
```

This matches `main`. The new file is not on the workflow's list, and neither is any caller of `tests/import_scan.py`. T036 owns `validate.yml` and makes the whole suite the required run.

**The whole suite, with the root conftest**, in the same venv: `main` `796838e8` gives `19 failed, 1454 passed, 13 skipped, 66 errors`, and this head gives `19 failed, 1489 passed, 13 skipped, 66 errors`. A test-by-test JUnit diff shows no changed outcome, nothing gone, and 35 new cases, all this file's and all passing. The 85 red cases are research R3's nine files and T030's `.[test]`-only case. T034 repairs the nine.

## Review record (Copilot)

There were eighteen threads over fifteen rounds, plus four findings raised without a thread. Every thread is answered with its evidence and resolved. Copilot's review at `19b0ecc2` recommends approval, with no findings. Every finding was a way to reach a sibling that the reader did not follow. Each was planted at the head it was raised on, where it passed, and it fails since its fix.

| round, at | finding | fixed in |
|---|---|---|
| 1, `61b308ed` | `import_module(name=...)`; PEP 695 type parameters; one shared reader | `ae82e2b5` |
| 2, `ae82e2b5` | an import alias of `import_module` | `eece371e` |
| 3, `eece371e` | a relative `import_module` against a literal `package` | `9862669f` |
| 4, `9862669f` | "matched by the name it spells" (docstring) | `ab022702` |
| 5, `ab022702` | a destructured alias; a lawful consumer case | `d9d3f3f9` (a module holding an importer as a value is read strictly) |
| 6, `d9d3f3f9` | literal `*[...]` and `**{...}` | `981fce65` |
| 7, `5270acf0` | nested literal spreads | `e6bd5ef5` (UNREADABLE for any other spread) |
| 8, `e6bd5ef5` | an alias looked up by name; a keyword an unreadable entry overwrites | `4b0cb725` |
| 9–10, `4b0cb725`, `aa92f71a` | a bound package; custom `globals` | `aa92f71a` (the spelling check), `6cf729ef`, `c3283e55` |
| 11, `6cf729ef` | the `scripts.` spelling; the full-name match; a concatenated lookup key | `c3283e55` |
| 12, `c3283e55` | a shadowed `globals`; a rebound `__package__` | `1fdd7fbb` |
| 13, `1fdd7fbb` | `from scripts import doc_health` | `a5a7f745` |
| 14, `a5a7f745` | `__import__`'s `fromlist` | `0f7af1a1` |
| 15, `0f7af1a1` | a star import from `scripts`; with it, found in measuring, a strict module's calls read by one importer's rule only | `19b0ecc2`; `b53b9db2` names UNREADABLE for each case it stands for |

## Landing

- T022 (#45) and T038 (#48) have landed, and `main` `796838e8` is merged in. Everything above was re-run at this head.
- T034 comes after it: T034 re-derives `tests/test_consumer_reach.py`'s record against this sweep.
- Squash or merge, never rebase. Each commit message carries both trailers, and so does this body.

Arc: neutral-product-standalone-operability
Lane: openxfactory-4 (openXfactory-4-openDox_extraction)

🤖 Generated with [Claude Code](https://claude.com/claude-code)


Arc: neutral-product-standalone-operability
Lane: openxfactory-4 (openXfactory-4-openDox_extraction)
Co-Authored-By: Claude Opus 5.5 (1M context) <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.

2 participants