personal memory agent
0

Configure Feed

Select the types of activity you want to include in your feed.

test(oura): move real-process lock probes to the integration tier

Commit 91f8fd9f3 on origin/main established that tests using real external
processes belong in operator validation, not unit CI, adding the `integration`
marker and `PYTEST_UNIT_ARGS := -m "not integration and not performance"` to
`make test` / `test-cov` / `coverage`; 2cf9e9585 then pointed `make ci` at
`make test`. The health-lane branch predates that policy, so its two
cross-process Oura lock proofs arrived unmarked and would have run inside the
unit gate — precisely the class of probe the policy exiles. 704d53bb9 shows the
repo actively rewriting tests away from real-process mechanics, so leaving them
unmarked would regress a live policy.

Marking them `integration` alone, however, would leave `make ci` with no
exclusion proof at all, while the scope requires exclusion be demonstrated with
distinct processes *or file descriptors* — not only threads.

So both subprocess probes are marked `integration` (they still run under
`make test-integration`), and the exclusion proof is retained inside the unit
gate by two in-process tests that use distinct file descriptors. This is sound
because hold_lock uses fcntl.flock(LOCK_EX | LOCK_NB), which is per open-file
description: two separate open() calls genuinely exclude one another within a
single process, so this is a real exclusion proof and not a thread simulation.

test_private_import_lock_excludes_distinct_fds_in_one_process pins that
per-open-file-description semantics directly, and fails loudly if the primitive
is ever swapped for POSIX per-process record locking, under which a second
descriptor would silently succeed and invalidate the proof.

test_oura_sync_lock_timeout_with_same_process_distinct_fd drives save-mode sync
against a held lock and asserts the structured OuraSyncLockError names the
journal, lock path, and timeout, leaks no token, request URL, or health payload,
performs no fetch, and writes no bundle, raw, normalized, dedupe, manifest, or
cursor state.

+81
+81
tests/test_oura_importer.py
··· 51 51 approval_path_for_journal, 52 52 oura_sync_approval_path_for_journal, 53 53 ) 54 + from solstone.think.importers.shared import ( 55 + ImportLockTimeout, 56 + hold_private_import_lock, 57 + ) 54 58 from solstone.think.importers.sync import SYNCABLE_REGISTRY, get_syncable_backends 55 59 56 60 FIXTURE_ROOT = ( ··· 1817 1821 ) 1818 1822 1819 1823 1824 + def test_private_import_lock_excludes_distinct_fds_in_one_process( 1825 + tmp_path: Path, 1826 + ) -> None: 1827 + lock_path = tmp_path / "journal" / "imports" / "oura.json" 1828 + 1829 + with hold_private_import_lock(lock_path, timeout=1.0, poll_interval=0.0): 1830 + # This pins flock's per-open-file-description behavior. If this lock ever 1831 + # becomes POSIX per-process locking, the second acquire would succeed. 1832 + with pytest.raises(ImportLockTimeout) as exc_info: 1833 + with hold_private_import_lock( 1834 + lock_path, 1835 + timeout=0.0, 1836 + poll_interval=0.0, 1837 + ): 1838 + pass 1839 + 1840 + assert exc_info.value.path == lock_path 1841 + assert exc_info.value.timeout == 0.0 1842 + 1843 + 1844 + def test_oura_sync_lock_timeout_with_same_process_distinct_fd( 1845 + tmp_path: Path, 1846 + monkeypatch, 1847 + ) -> None: 1848 + journal = _use_journal(tmp_path, monkeypatch) 1849 + _write_sync_artifact(journal, _sync_artifact(journal)) 1850 + lock_path = journal / "imports" / "oura.json" 1851 + transport = _fixture_transport() 1852 + monkeypatch.setattr(oura, "OURA_SYNC_LOCK_TIMEOUT", 0.2) 1853 + 1854 + with hold_private_import_lock(lock_path, timeout=1.0, poll_interval=0.0): 1855 + with pytest.raises(oura.OuraSyncLockError) as exc_info: 1856 + oura.backend.sync( 1857 + journal, 1858 + dry_run=False, 1859 + confirm_health_save=True, 1860 + client=_canned_client(transport), 1861 + today=dt.date(2026, 1, 10), 1862 + ) 1863 + 1864 + payload = exc_info.value.to_dict() 1865 + text = ( 1866 + f"{exc_info.value!s}\n" 1867 + f"{exc_info.value.format_text()}\n" 1868 + f"{exc_info.value.to_dict()!r}" 1869 + ) 1870 + assert payload["error"] == "oura_sync_lock_timeout" 1871 + assert payload["journal_root"] == str(journal) 1872 + assert payload["lock_path"] == str(lock_path) 1873 + assert payload["timeout_seconds"] == 0.2 1874 + assert str(journal) in text 1875 + assert str(lock_path) in text 1876 + for forbidden in ( 1877 + "Bearer", 1878 + "synthetic-access", 1879 + "synthetic-refresh", 1880 + "access_token", 1881 + "refresh_token", 1882 + "api.ouraring", 1883 + "daily_readiness", 1884 + "synthetic-readiness", 1885 + ): 1886 + assert forbidden not in text 1887 + 1888 + assert transport.calls == [] 1889 + contents = _imports_contents(journal) 1890 + assert "imports/oura.json.lock" in contents 1891 + assert "imports/oura.json" not in contents 1892 + assert "imports/health-dedupe.sqlite" not in contents 1893 + assert not any(entry.startswith("imports/2026") for entry in contents) 1894 + assert not any(entry.endswith("manifest.json") for entry in contents) 1895 + assert "imports/content_manifest.jsonl" not in contents 1896 + assert not any("/raw/" in entry or "/normalized/" in entry for entry in contents) 1897 + 1898 + 1899 + @pytest.mark.integration 1820 1900 def test_overlapping_save_sync_loser_gets_structured_lock_timeout( 1821 1901 tmp_path: Path, 1822 1902 monkeypatch, ··· 1894 1974 assert child.returncode == 0, stdout + stderr 1895 1975 1896 1976 1977 + @pytest.mark.integration 1897 1978 def test_in_lock_gate_rechecks_artifact_before_fetch_after_wait( 1898 1979 tmp_path: Path, 1899 1980 monkeypatch,