Purpose
-------
The spec-10 §9 discovery-precedence layer for the ``oct test`` v1.0
seed (Plan 189): workspace / ``--package P`` / bare selection over the
workspace manifest, plus the ADR-T-12 single-package fallback walk
(cwd upward for ``pyproject.toml``/``pytest.ini``, four-parent-level
cap, basename inference with the ``[tool.oct.test].package_id``
cross-check override).
Responsibilities
----------------
- :func:`discover` - the §9 precedence table, row for row. Flags are
plain keyword arguments (this is a LIBRARY: no CLI, no flag
parsing, no ``sys.exit``); every exit-4 table branch raises
:class:`oct.testing.errors.OctTestError` with its §12.4 code.
- :func:`walk_for_package` - the ADR-T-12 walk with the ADR's pinned
diagnostic message, verbatim.
- OUT of scope (future slices): pytest collection and the §4
collection-check routing (``COLLECTION_ERROR`` /
``NO_TESTS_COLLECTED``), runners, schedulers, reports.
Diagnostics
-----------
Domain: OCT-TESTING
Levels:
L2: lifecycle (discovery start / resolution failures)
L3: semantic details (resolved mode, selection, walk result)
L4: deep tracing
Contracts
---------
- Discovery is READ-ONLY: nothing is created or mutated.
- Mutual exclusion (``workspace`` + ``package``) is checked before
any filesystem access - a fully valid workspace does not rescue
the call (§9 row 7, "Either").
- The ``--package`` fallback (no manifest found) does NOT walk: the
package roots at cwd and ``P`` must equal the cwd basename (§9
row 6); the ADR-T-12 walk belongs to the bare row only.
- A corrupt ``pyproject.toml`` at a discovered root degrades to
basename inference - the file's existence marks the package root;
only the optional override read is tolerant.
Dependencies
------------
- oct.core.workspace (read-only: find_workspace_root)
- oct.core.diagnostics (_dbg)
- oct.testing.errors (the §12.4 taxonomy as data)
- oct.testing.manifest (the §9 manifest test view)
| DiscoveryResult oct.testing.discovery.discover |
( |
Path | cwd, |
|
|
* | , |
|
|
bool | workspace = False, |
|
|
str | None | package = None ) |
Resolve the §9 discovery precedence from *cwd*.
Parameters
----------
cwd
Directory the (future) invocation runs from; the upward
manifest search and the ADR-T-12 walk both start here.
workspace
Library mirror of the ``--workspace`` flag.
package
Library mirror of the ``--package P`` flag.
Returns
-------
:class:`DiscoveryResult`
Raises
------
OctTestError
Every exit-4 branch of the §9 table:
``WORKSPACE_AND_PACKAGE_BOTH_PASSED`` (row 7, checked before
any IO), ``WORKSPACE_FILE_NOT_FOUND`` (row 4),
``PACKAGE_UNKNOWN`` (rows 5 and 6),
``CWD_RESOLUTION_FAILED`` (row 2), and the manifest ``9101``/
``9102`` codes when a found workspace file is invalid
(rows 1/3/5).
Definition at line 152 of file discovery.py.