diff --git a/AGENTS.md b/AGENTS.md index 7bc4a6a..807dc01 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -24,7 +24,7 @@ TDD required. Red → Green → Refactor. No production code without a failing t Python 3.12, uv, hatchling src layout, pytest, ruff. -**co-core is pinned exactly (`==0.38.0`); Processor owns the pin** (spec D5, §5; since watcher#350 nothing else extracts). `processor_version` = `"+"`; a pin test makes every bump a deliberate, test-failing act. Never let a dependency bot or `uv lock --upgrade` move co-core. A bump gives Watcher notice (it re-baselines on `processor_version`). It is coordinated with Watcher only if it changes the contract: the `content.process` / `content.derived` models or `canonical_text` semantics. Procedure: [docs/DEPENDENCIES.md](docs/DEPENDENCIES.md#bumping-co-core). The extraction stack (co-core's `extract` extra, closure: pypdf, lxml, …) is held too: moving it outside a co-core bump bumps `LOCAL_GENERATION` (#71, [docs/DEPENDENCIES.md](docs/DEPENDENCIES.md#extraction-dependencies)). +**co-core is pinned exactly (`==0.51.1`); Processor owns the pin** (spec D5, §5; since watcher#350 nothing else extracts). `processor_version` = `"+"`; a pin test makes every bump a deliberate, test-failing act. Never let a dependency bot or `uv lock --upgrade` move co-core. A bump gives Watcher notice (it re-baselines on `processor_version`). It is coordinated with Watcher only if it changes the contract: the `content.process` / `content.derived` models or `canonical_text` semantics. Procedure: [docs/DEPENDENCIES.md](docs/DEPENDENCIES.md#bumping-co-core). The extraction stack (co-core's `extract` extra, closure: pypdf, lxml, …) is held too: moving it outside a co-core bump bumps `LOCAL_GENERATION` (#71, [docs/DEPENDENCIES.md](docs/DEPENDENCIES.md#extraction-dependencies)). **The co-pypi index.** `co-core`, `co-core-aio`, `co-core-sync` resolve only from the explicit `co-pypi` Artifact Registry index (`pyproject.toml`, #121). The lock holds each file's sha256, and `uv sync --locked` refuses a miss. `uv lock`, and a `uv sync` that downloads, need the reader's token: `bash scripts/co-pypi.sh uv …` mints it for that one `uv`, and never prints it. After the first `uv sync` in a fresh checkout, `uv sync --reinstall-package processor` if `import processor` fails. diff --git a/docs/DEPENDENCIES.md b/docs/DEPENDENCIES.md index 7ceec20..7224d0a 100644 --- a/docs/DEPENDENCIES.md +++ b/docs/DEPENDENCIES.md @@ -139,7 +139,7 @@ co-core is pinned `==`, and Processor owns the pin (spec D5, §5; amended 2026-1 1. Update the pin in `pyproject.toml` (all three names) and `EXPECTED` in `tests/test_pin.py`, then `bash scripts/co-pypi.sh uv lock --upgrade-package co-core --upgrade-package co-core-aio --upgrade-package co-core-sync`, never `--upgrade`. Nothing else moves: no wheelhouse, no digest table (#121). - **The lock carries the digests.** Each co-core file gets its sha256 from the index, and `uv sync --locked` refuses a miss. cannobserv's publish run fails unless the index lists every file under its local sha256 (from v0.41.0, CannObserv/cannobserv#554). - **Check the diff:** each co-core `source` is the index URL, and nothing outside the bump moved. A moved extraction-stack package belongs to the bump (§ Extraction dependencies). - - **Drop an override the new co-core makes redundant.** `tests/test_lock_floors.py` fails when co-core's own requirement admits an `override-dependencies` floor: remove the entry and its `OVERRIDDEN` row, and keep the floor as a constraint if co-core's own is lower. At ≥ 0.46.1 that is soupsieve's (`>=4.1,<5` in co-core itself; #138). + - **Drop an override the new co-core makes redundant.** `tests/test_lock_floors.py` fails when co-core's own requirement admits an `override-dependencies` floor: remove the entry and its `OVERRIDDEN` row. Keep the floor as a constraint if co-core's own is lower, or as a `CO_CORE_FLOORED` row if co-core's own holds it (a test checks that it still does). #140 did this for soupsieve: co-core 0.51.1 declares `>=4.1,<5` itself (#138's override). 2. A release that adds an essence or an extraction rule gets its cases in `tests/fixtures/parity/cases.json` first, so their goldens come from co-core. Then regenerate the goldens from co-core directly: `uv run python scripts/gen_parity_goldens.py tests/fixtures/parity`. It prints every digest that moved, and every case that started or stopped being refused. Paste that list into the bump note: each line is a deliberate re-baseline. Never regenerate to make a parity test pass outside a bump. A catch-up across releases reads each CHANGELOG's Downstream lines for the extract, bus and blob-store surfaces, and diffs those packages' code between the tags (#29 did 0.19.7 → 0.32.0). 3. The real corpus (`tests/fixtures/parity/real/`) is never regenerated. It passes unchanged, or the bump note says which recorded fingerprints moved. 4. **Notice to Watcher** before deploy: the new `processor_version`, and the moved digests. A change to the contract needs coordination with Watcher first, not just notice. The contract is the `content.process` / `content.derived` models and `canonical_text` semantics. A change to essence resolution is notice, not coordination (spec §5, #57). @@ -154,7 +154,7 @@ co-core is pinned `==`, and Processor owns the pin (spec D5, §5; amended 2026-1 3. Measure what moved: the parity tests (goldens, real corpus) must pass unchanged (a golden that moves is a co-core-pin question, not this one), and run co-core's extractor for the moved package over a wider corpus on both versions (#71 used pypdf's and py-pdf's sample PDFs: 4 of 106 moved). Put the result in the PR. 4. **Notice to Watcher** before deploy: the new `processor_version` and the evidence. Merge, then `scripts/deploy.sh`. -Since #71: `0.38.0+2`, pypdf 6.21.2, opentelemetry-api 1.45.1 (not stack; a floor only). Since #112: `0.38.0+3`, pypdf 6.21.4, pyasn1 0.6.5 (not stack; a floor only). Since #138: `0.38.0+4`, soupsieve 4.1.1 by override past co-core's `<3` (no fingerprint moved over 289 HTML files × 34 selector configs; a complex or nested `:has()` now refuses), opentelemetry-api 1.45.2 (not stack; a floor only). +Since #71: `0.38.0+2`, pypdf 6.21.2, opentelemetry-api 1.45.1 (not stack; a floor only). Since #112: `0.38.0+3`, pypdf 6.21.4, pyasn1 0.6.5 (not stack; a floor only). Since #138: `0.38.0+4`, soupsieve 4.1.1 by override past co-core's `<3` (no fingerprint moved over 289 HTML files × 34 selector configs; a complex or nested `:has()` now refuses), opentelemetry-api 1.45.2 (not stack; a floor only). Since #140: `0.51.1+4`, at the co-core bump, so the generation stayed. soupsieve 4.1.3 rode along (no result moved over 311 HTML files × 34 selector configs), and the override went: co-core floors it at 4.1 itself. ## Parity goldens diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index d4fb1d5..fe3528b 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -141,7 +141,7 @@ A stop mid-reclaim finishes the command in hand and leaves the rest pending. A c - **Drift:** `journalctl -u processor-drift` (MONITORING.md § The drift check). - **Liveness:** `journalctl -u processor -o cat | jq -cR 'fromjson? | select(.logger == "processor.liveness")'` (MONITORING.md § Liveness). -- **Logs:** `journalctl -u processor`. A record's journald `PRIORITY` follows its `level` (CRITICAL 2, ERROR 3, WARNING 4, INFO 6, DEBUG 7; #76), so `journalctl -u processor -p warning` lists WARNING and above, with systemd's own warning lines for the unit; add `-o cat | jq -cR 'fromjson?'` for the JSON alone. Every `processor` entry point (so every unit that runs it: `processor`, `processor-drift`, `processor-patching`) writes an sd-daemon `` prefix only when its stderr is the journal (`JOURNAL_STREAM` names stderr's own device and inode), and journald strips it, so `MESSAGE` stays pure JSON. A terminal, `processor_cli` and any `systemd-run --pipe` never see one. Records from before #76's deploy (`live -> 431b7b569300` at 2026-10-25T15:50:36Z in `journalctl -t processor-deploy`) are all `PRIORITY=6`: filter those by `.level`. Only `logging` records carry a priority: a bare traceback or a `print` to stderr is still `PRIORITY=6`. A record past journald's `LineMax` (48K) is split, and only its first part carries the priority (neither part is JSON). `starting` names the `build`, `child_containment`, `landlock_abi` and `liveness`. Deploys: `journalctl -t processor-deploy`. Each outcome has `command_id`, `info_source_id`, `action` (`ack` / `strike` / `leave_pending` / `dead_letter`), `reason`, `detail`, and timings in `*_ms`. Each also has `input_digest` once it is valid, as bare hex like the command's. A complete fact adds `output_digest` (`sha256:`, as on the fact; the object is `blobs/.bin`; absent when `empty`), `output_size_bytes`, `empty` and `processor_version`, and so does a `leave_pending` whose publish failed after the store. A shadow command's output: `journalctl -u processor -o cat | jq -cR 'fromjson? | select(.command_id == "") | {action, reason, input_digest, output_digest}'` (`-R … fromjson?` skips systemd's own lines, which `-u` includes and plain `jq` aborts on). +- **Logs:** `journalctl -u processor`. A record's journald `PRIORITY` follows its `level` (CRITICAL 2, ERROR 3, WARNING 4, INFO 6, DEBUG 7; #76), so `journalctl -u processor -p warning` lists WARNING and above, with systemd's own warning lines for the unit; add `-o cat | jq -cR 'fromjson?'` for the JSON alone. Every `processor` entry point (so every unit that runs it: `processor`, `processor-drift`, `processor-patching`) writes an sd-daemon `` prefix only when its stderr is the journal (`JOURNAL_STREAM` names stderr's own device and inode), and journald strips it, so `MESSAGE` stays pure JSON. A terminal, `processor_cli` and any `systemd-run --pipe` never see one. Records from before #76's deploy (`live -> 431b7b569300` at 2026-10-25T15:50:36Z in `journalctl -t processor-deploy`) are all `PRIORITY=6`: filter those by `.level`. Only `logging` records carry a priority: a bare traceback or a `print` to stderr is still `PRIORITY=6`. A record past journald's `LineMax` (48K) is split, and only its first part carries the priority (neither part is JSON). `starting` names the `processor_version`, `build`, `child_containment`, `landlock_abi` and `liveness`. Deploys: `journalctl -t processor-deploy`. Each outcome has `command_id`, `info_source_id`, `action` (`ack` / `strike` / `leave_pending` / `dead_letter`), `reason`, `detail`, and timings in `*_ms`. Each also has `input_digest` once it is valid, as bare hex like the command's. A complete fact adds `output_digest` (`sha256:`, as on the fact; the object is `blobs/.bin`; absent when `empty`), `output_size_bytes`, `empty` and `processor_version`, and so does a `leave_pending` whose publish failed after the store. A stored output also has `output_created` (#140): `true` if this call wrote the object, `false` if it was already there. It's a log signal only, because each backend is exact one way only (spec §4). A shadow command's output: `journalctl -u processor -o cat | jq -cR 'fromjson? | select(.command_id == "") | {action, reason, input_digest, output_digest}'` (`-R … fromjson?` skips systemd's own lines, which `-u` includes and plain `jq` aborts on). - **Dead letters:** `processor_cli dlq list | show | drop ` (PROVISIONING.md § `/etc/processor/`). There is no replay. An entry failed to decode, was not a command, or is a command that raised outside the handler on every attempt (`reason` starts `gave up on attempt`): that one is a bug to fix. Before dead-lettering such a command, Processor published a terminal `dead_lettered` whose `detail` starts `dead-lettered:` (best effort), so Watcher has closed it (#17; `extraction_error` before co-core 0.37.0, #21). The journal's `dead-lettering` record says which: `failure_fact` is `published`, `skipped` (a fact had already gone out) or `refused`. On a command given up at the cap, `handle_skipped` is `true` when the record retries a give-up that did not finish (the failure fact refused transiently, or the dead-letter refused), with no re-run of the command and the original traceback (#28). The same entry logging that every ~11 min while it stays pending means `content.process.dlq` refuses it: `journalctl -u processor -o cat | jq -cR 'fromjson? | select(.handle_skipped) | {timestamp, command_id, message_id, reason}'`. - **Lag / missing group:** the broker probe watches `processor.process` (broker#75). - **Strikes** are counted in memory. A restart resets them, so a poison command gets at most 3 more attempts. diff --git a/docs/plans/2026-11-23-140-co-core-0.51.1.md b/docs/plans/2026-11-23-140-co-core-0.51.1.md new file mode 100644 index 0000000..ae1ffe1 --- /dev/null +++ b/docs/plans/2026-11-23-140-co-core-0.51.1.md @@ -0,0 +1,73 @@ +--- +title: co-core 0.38.0 → 0.51.1, the soupsieve override dropped, soupsieve 4.1.3, store_reporting (#140) +date: 2026-11-23 +status: per #140 (body; 2026-11-21 comment; coordinator brief 7107994788, recommendations accepted by the operator; implementer corrections 7110222346); procedure per docs/DEPENDENCIES.md § Bumping co-core +--- + +# co-core 0.51.1 + +## Problem + +- co-core 0.38.0's `extract` extra caps soupsieve `<3`, so #138 reached 4.1.1 by `override-dependencies`, which replaces co-core's requirement. co-core ≥ 0.46.1 declares `soupsieve>=4.1,<5` itself (cannobserv#667), and `tests/test_lock_floors.py` fails the bump until the override goes. +- co-core 0.51.0 maps `extraction.include_description` (cannobserv#559). Archiver's schema accepts the key (archiver#353) only once Processor runs ≥ 0.51.0. On 0.38.0, a spec that sets the key extracts as if it were absent. +- Since v0.41.0 the blob store reports whether a write created the object (cannobserv#530, `store_reporting`). The epic records that Processor adopts it at this bump. + +## Approach + +**Target:** v0.51.1, the latest tag on 2026-11-23. Nothing Processor imports changed between 0.51.0 and 0.51.1. + +**The bump** (one commit, green on its own): +- `pyproject.toml`: pin all three names `==0.51.1`, and remove `override-dependencies` and its comment. +- Re-lock: `bash scripts/co-pypi.sh uv lock --upgrade-package co-core --upgrade-package co-core-aio --upgrade-package co-core-sync --upgrade-package soupsieve`. Expected: the three move to 0.51.1, soupsieve 4.1.1 → 4.1.3, the `overrides` entry goes, and nothing else moves. +- `tests/test_pin.py`: `EXPECTED` 0.51.1, and `EXTRACTION_STACK` soupsieve 4.1.3. `LOCAL_GENERATION` stays 4 (DEPENDENCIES.md § Extraction dependencies, step 2), so `processor_version` = `0.51.1+4`. +- `tests/test_lock_floors.py`: + - `OVERRIDDEN` is empty, and one test holds `override-dependencies` to exactly its names, so a stale override fails. + - soupsieve's 4.1 floor is held by co-core's own requirement (`CO_CORE_FLOORED`), with a test that the requirement floors at 4.1 or higher. If a later co-core drops below that, the test says to add a constraint. + - The guard's parsing tests stay. The override route is still the documented route for the next capped floor. + +**Parity** (DEPENDENCIES.md step 2: the cases come first, so their goldens come from co-core): +- `tests/fixtures/parity/cases.json`: + - `include_description: true` on `tailscale_security_bulletins.xml` (RSS) and `feed.atom` (Atom), `full_page`; + - refusals: on `css`, on an HTML body, on `register.xml` (non-feed root), and a non-bool (`"true"`). +- Regenerate: `uv run python scripts/gen_parity_goldens.py tests/fixtures/parity`. Expected: only the new cases appear, and no existing digest moves. The real corpus passes unchanged. + +**`store_reporting`** (its own commit, TDD): +- `handler.py` calls `deps.stores.output.store_reporting(...)` and takes `.uri` for the fact. +- `output_created` goes into the outcome record of a stored, non-empty output, alongside `output_digest`. An empty output stores nothing and logs no `output_created`. (Planned as `created`. That's a `LogRecord` attribute, and the scratch-bus consumer tests failed on it with `KeyError`, so it was renamed, with a guard test.) +- It's a log signal only, never a branch. A GCS `False` may be this call's own retried create; a local `True` may be a race. +- `FlakyStore` cases that inject on `store` move to `store_reporting` (correction 5). A test holds that the handler never calls plain `store`. + +**Docs** (spec amended 2026-11-23, history kept as written): +- An **Amended** entry in the header; +- D5 `:211` and the Dependencies row `:250`; +- the failure table's refusal list `:437`, which gains `include_description`; +- Section 4's log fields `:529–533`, which gain `output_created`; +- §5: the pin `:572`ff, and the override note `:562` marked removed; +- the pin test `:745`, the quick-reference heading `:818`, and `:859`; +- `docs/DEPENDENCIES.md:157`: a "Since #140" entry; +- `AGENTS.md:27`: `==0.51.1`, with no growth. + +## Evidence + +- **Catch-up:** `git diff v0.38.0 v0.51.1` over every co-core module Processor imports (correction comment). + - The five contract classes are AST-identical. + - Extraction differs only by `include_description` (+105/−32 over 8 files). + - The blob store adds the reporting twins; plain `store` behaves the same. +- **Parity:** the goldens (moved list in the PR), the real corpus unchanged, and `tests/test_child.py` under `required`. +- **soupsieve 4.1.1 → 4.1.3, measured as #138 did:** + - co-core 0.51.1's `HtmlExtractor`, then `canonical_text_fingerprint`. + - Inputs: the parity HTML, the real corpus, and host HTML files over 3 KB, each under a selector battery. + - It runs in two venvs that differ in soupsieve alone. Counts go in the PR. + +## Tradeoffs + +- **soupsieve rides along:** one more package in the same re-baseline, instead of a later generation bump with its own Watcher notice. +- **`output_created` is a log signal only:** it's exact in one direction per backend. As a branch it would be wrong on one of them. + +## Ship + +- PR, with `Refs #140` while live checks remain, then CI green by job. +- Watcher notice on watcher#394, approved before posting. +- FF merge outside Tue 2026-11-24 05:00–10:00Z, then `scripts/deploy.sh`. +- The live `starting` record reads `processor_version` `0.51.1+4`, containment `required`. +- The Archiver relay is the coordinator's. diff --git a/docs/specs/2026-09-29-processor-service-design.md b/docs/specs/2026-09-29-processor-service-design.md index 1ec8b17..f98776e 100644 --- a/docs/specs/2026-09-29-processor-service-design.md +++ b/docs/specs/2026-09-29-processor-service-design.md @@ -166,6 +166,27 @@ on `co-processor`. a backoff. A log record only: no change to backoff, liveness or the wire (Section 3, Health). +**Amended 2026-11-23 (co-core 0.51.1, processor#140):** +- The pin moves from 0.38.0 to **0.51.1** for all three packages (Sections 2 and 5). + Facts report `0.51.1+4`: the version moved, so `LOCAL_GENERATION` stays 4 + (Sections 5 and 7). The contract is unchanged, so Watcher gets notice, not + coordination (D5). +- co-core ≥ 0.46.1 declares `soupsieve>=4.1,<5` itself, so #138's + `override-dependencies` is removed. soupsieve 4.1.1 → 4.1.3 rides along. That + is upstream's further quadratic-time fixes. Over 311 HTML files × 34 selector + configs, no result moved (Section 5). +- co-core 0.51.0 maps `extraction.include_description` (cannobserv#559). A + `true` on `full_page` appends each RSS or Atom item's description to its feed + line. Absent or `false`, the extracted text is byte-identical, and no existing + golden moved. An explicit `false` still moves `spec_fingerprint`, which hashes + the whole spec (the `feed_rss_include_description_false` golden). It brings + new refusals, each one extracted silently before: a + non-bool value; `true` on any algorithm but `full_page`; `true` on an HTML, + PDF, CSV/Excel or JSON body; `true` on a non-feed XML root (Section 4). +- The output store is written through co-core's `store_reporting` + (cannobserv#530, v0.41.0). The outcome record of a stored output logs + `output_created` as a log signal only (Section 4). + --- ## Why a new service @@ -208,7 +229,7 @@ state and UI it should not have). | D2 | **Headless and stateless in v1**: no UI, no database. Idempotency is the write-if-absent store; correlation and dedupe are the issuer's (by `command_id`). | | D3 | **Own identities**: broker ACL user, GCS service account, bucket, tailnet tag. Observo's broker#62 `observo` user is stripped. | | D4 | **Own bucket** `gs://co-gcs-processor`, derived outputs only, so each reader's grant is a plain bucket-level `objectViewer`. *Amended 2026-11-15 (processor#130): was "Watcher's read grant"; Watcher's reader retired on watcher#420.* | -| D5 | **co-core pinned exactly; Processor owns the pin** (0.38.0 today, processor#37). Bumps are deliberate (Section 5). Processor coordinates with Watcher only when a bump changes the contract: the `content.process` / `content.derived` models or `canonical_text` semantics. It **gives Watcher notice whenever `processor_version` moves**, because Watcher re-baselines on it. Watcher still pins co-core for contracts and the bus (`==0.19.7` on 2026-10-10), and that pin no longer has to equal Processor's. *Amended 2026-10-10 (processor#47, after watcher#350). Until then: matched to Watcher, in lockstep, since both sides extracted during shadow. Watcher agreed to that on 2026-10-02 (watcher#325), and neither side deployed a bump until the parity corpus passed on it unchanged. Amended 2026-10-21 (processor#57): essence resolution left the contract, so a change to it is notice (Section 5).* | +| D5 | **co-core pinned exactly; Processor owns the pin** (0.51.1 today, processor#140). Bumps are deliberate (Section 5). Processor coordinates with Watcher only when a bump changes the contract: the `content.process` / `content.derived` models or `canonical_text` semantics. It **gives Watcher notice whenever `processor_version` moves**, because Watcher re-baselines on it. Watcher still pins co-core for contracts and the bus (`==0.19.7` on 2026-10-10), and that pin no longer has to equal Processor's. *Amended 2026-10-10 (processor#47, after watcher#350). Until then: matched to Watcher, in lockstep, since both sides extracted during shadow. Watcher agreed to that on 2026-10-02 (watcher#325), and neither side deployed a bump until the parity corpus passed on it unchanged. Amended 2026-10-21 (processor#57): essence resolution left the contract, so a change to it is notice (Section 5).* | | D6 | **Extraction runs in a killable child process** with a timeout and an address-space limit, never a thread. | | D7 | Broker `NOPERM` and `OOM` are **transient**; a reclaim **re-runs** the extraction (no dedupe key). | | D8 | **v1 scope is #629's requirements only.** | @@ -247,7 +268,7 @@ processor-version pin on the command; no job API — the bus is the interface. | Thing | Value | |---|---| | Repo | `CannObserv/processor` — Python 3.12, uv, hatchling src layout | -| Dependencies | `co-core[extract]`, `co-core-aio[bus]`, `co-core-sync[gcs]`, all `==0.38.0` (Section 5), from the private `co-pypi` Artifact Registry index (amended 2026-11-06, #121) | +| Dependencies | `co-core[extract]`, `co-core-aio[bus]`, `co-core-sync[gcs]`, all `==0.51.1` (Section 5), from the private `co-pypi` Artifact Registry index (amended 2026-11-06, #121) | | CI | the index's token minted through WIF as `co-pypi-reader` (org var `GCP_WIF_PROVIDER`), as in the other cohort repos (amended 2026-11-06, #121) | | VM | exe.dev `co-processor`, 8 GB, default `exeuntu` image, tag `processor` | | Service | systemd unit `processor`: `MemoryMax` below VM RAM, `Restart=on-failure`, `OOMPolicy=continue` (Section 4). Runs as its own user `processor` (no sudo, not in `docker`, no home), from a read-only release at `/srv/processor/live` that `scripts/deploy.sh` builds from a commit on `origin/main` (amended 2026-10-06, #2: the cohort's release standard, broker#22 / status#9) | @@ -434,7 +455,7 @@ above. Elsewhere (a terminal, `systemd-run --pipe`) there is no prefix | Malformed digest, or `input_uri` the input store does not recognize | `invalid_input`, terminal (issuer does not re-fetch) | yes | | Input bytes gone, or the download fails its checksum (`DataCorruption`, amended 2026-09-30) | `input_unreadable`, terminal for the command (issuer re-fetches, capped) | yes | | Bytes hash ≠ `input_digest` | `input_digest_mismatch`, terminal | yes | -| Extractor raises, including `MemoryError` under `RLIMIT_AS`, a JSON body co-core can't parse (`ValueError`, as for PDF and XML), and a spec co-core refuses (`UnsupportedExtractionError` since 0.32.0, cannobserv#523; on 0.38.0: `regex`, an empty `xpath` or `jsonpath`, an invalid `xpath`, `jsonpath` or CSS selector, an unknown algorithm, `xpath` on PDF / CSV / JSON, `css` on XML / PDF / CSV / JSON, `jsonpath` on anything but JSON, `ignore_selectors` on anything but HTML), amended 2026-10-12 and 2026-10-20 | `extraction_error`, terminal | yes | +| Extractor raises, including `MemoryError` under `RLIMIT_AS`, a JSON body co-core can't parse (`ValueError`, as for PDF and XML), and a spec co-core refuses (`UnsupportedExtractionError` since 0.32.0, cannobserv#523; on 0.51.1: `regex`, an empty `xpath` or `jsonpath`, an invalid `xpath`, `jsonpath` or CSS selector, an unknown algorithm, `xpath` on PDF / CSV / JSON, `css` on XML / PDF / CSV / JSON, `jsonpath` on anything but JSON, `ignore_selectors` on anything but HTML, an `include_description` that isn't a bool, and a true one on any algorithm but `full_page` or on any body but an RSS or Atom feed), amended 2026-10-12, 2026-10-20 and 2026-11-23 | `extraction_error`, terminal | yes | | Child timeout or crash | — | no; the 3rd attempt publishes `extraction_error`, terminal, and acks | | A non-transient exception escaping the handler (a bug, or an ack or dead-letter refused), amended 2026-09-30, 2026-10-02, 2026-10-05 and 2026-10-17 | at the cap, `dead_lettered`, terminal, unless this entry's fact already went out (a fact published before a refused ack stands) | no; counted like a strike, and the 3rd attempt publishes, then dead-letters the entry with the exception as its reason. A dead-letter that does not land is retried alone, without running the command again (#28) | | GCS 5xx / 429 / timeout / auth; broker `NOPERM`; broker `OOM command not allowed`; broker `MISCONF` / `BUSY` / `MASTERDOWN` / `TRYAGAIN` / `CLUSTERDOWN` / `NOREPLICAS` (amended 2026-09-30) | — | no; the entry is reclaimed | @@ -531,8 +552,14 @@ above. Elsewhere (a terminal, `systemd-run --pipe`) there is no prefix `invalid_input` detail quotes it. Once a complete fact exists, it adds `output_digest` (absent when `empty`), `output_size_bytes`, `empty` and `processor_version`, taken from that fact (#26). - Whether the store wrote a new object is not logged: co-core's write-if-absent - swallows the 412. + A stored output also logs `output_created`: whether this call created the + object, from co-core's `store_reporting` (cannobserv#530, #140; not `created`, + a `LogRecord` attribute). It's a log signal, never a branch, because each + backend is exact one way only. A GCS `true` is exact, but a `false` may be + the SDK retrying this call's own create into the 412. A local `false` is + exact, but a `true` may be a race. An empty output stores nothing and logs + no `output_created`. *Amended 2026-11-23 (processor#140). Until then the + write wasn't logged, because co-core's write-if-absent swallowed the 412.* These answer the two points broker#62 left for the consumer to state: `NOPERM` is transient, and under `maxmemory` a refused `XADD` is transient, with the @@ -562,21 +589,37 @@ reclaim re-running (not re-publishing) the extraction. its advisories, by `override-dependencies` past co-core 0.38.0's `<3`. No fingerprint moved over 289 HTML files × 34 selector configs, and the goldens and the real corpus held. A complex or nested `:has()` now refuses - (soupsieve 3.0's strict `:has()`). + (soupsieve 3.0's strict `:has()`). The override went at processor#140: co-core + 0.51.1 floors soupsieve at 4.1 itself. soupsieve 4.1.3 rode along with that + bump, so the generation stayed 4. On co-core 0.51.1, over 311 HTML files × 34 + selector configs (the same input classes), 4.1.1 and 4.1.3 gave identical + results run for run. Nothing moved: the same strict-`:has()` refusals, and the + same 2 timeouts on one 10 MB page. - 3 was processor#112: pypdf 6.21.2 → 6.21.4 for its advisories. Over the same corpora at HEAD, 0 of 110 PDFs extracted differently; the goldens and the real corpus held. - 2 was processor#71: pypdf 6.19.0 → 6.21.2 for its advisories. Over pypdf's and py-pdf's sample corpora, 4 of 106 PDFs extracted differently (word spacing); the goldens and the real corpus held. -- **co-core `==0.38.0`** since processor#37 (2026-10-20). Before it, - `==0.37.0` since processor#21 (2026-10-17), and `==0.32.0` since processor#29 - (2026-10-12), the catch-up jump from - 0.19.7, the version Watcher's `uv.lock` resolved at the cutover (Watcher's +- **co-core `==0.51.1`** since processor#140 (2026-11-23). Before it, `==0.38.0` + since processor#37 (2026-10-20), `==0.37.0` since processor#21 (2026-10-17), + and `==0.32.0` since processor#29 (2026-10-12), the catch-up jump from 0.19.7, + the version Watcher's `uv.lock` resolved at the cutover (Watcher's `pyproject.toml` allowed `>=0.19.6,<0.20`), so both sides reported `"0.19.7+1"` from the first shadow command. Since D5's 2026-10-10 amendment, Watcher's lock - no longer constrains this pin. Processor needs `GcsBlobStore` (0.19.3+) and the - `content.process` types (0.19.4). + no longer constrains this pin. Processor needs `GcsBlobStore` (0.19.3+), the + `content.process` types (0.19.4) and `store_reporting` (0.41.0). + - Across 0.38.0 → 0.51.1, the `content.process` / `content.derived` models are + AST-identical, docstrings included. So are `canonical_text`, + `spec_fingerprint`, `dispatch`, `media_type`, the envelope and + `co_core_aio.bus`. `streams.py` changes only in its docstring. The extract + package changes only by `include_description` (cannobserv#559, +105/−32 over + 8 files). The blob store gains `Stored` and the reporting twins + (cannobserv#530); plain `store` is now `store_reporting(...).uri`, with the + same checks and writes. `changes.py` grows its fetch, replicate, capture and + registry models, none of which Processor reads. The child loads no new + module. The goldens did not move; seven cases were added for + `include_description`. Notice, on watcher#394 (processor#140). - Across 0.37.0 → 0.38.0 (0.37.1 between), the `content.process` / `content.derived` models (docstrings aside), `canonical_text`, the stores and `co_core_aio.bus` are unchanged in code. `spec_fingerprint` moves its @@ -742,9 +785,9 @@ TDD, red first. - Parity with Watcher's local path should be proven before shadow, not discovered in it. - **Pin test.** The lock's co-core equals the expected exact version and - `processor_version(LOCAL_GENERATION) == "0.38.0+4"` — a bump is a deliberate, + `processor_version(LOCAL_GENERATION) == "0.51.1+4"` — a bump is a deliberate, test-failing act. So is moving the extraction stack (Section 5, processor#71, - processor#112, processor#138). + processor#112, processor#138, processor#140). - **Shells — one test per Section 4 row.** Input/output stores: a local co-core store on a temp dir behind the same interface, plus fakes raising GCS 5xx / 429 / `NotFound`. Bus: fakeredis (or co-core-aio's test double, if it ships @@ -815,7 +858,7 @@ writing-plans for v1 there. Implementation happens on `co-processor`. --- -## Contract quick reference (co-core 0.19.4–0.38.0, unchanged across them but the refusal, added in 0.32.0, and `dead_lettered`, in 0.37.0) +## Contract quick reference (co-core 0.19.4–0.51.1, unchanged across them but the refusal, added in 0.32.0, `dead_lettered`, in 0.37.0, and `store_reporting`, in 0.41.0) | Need | Name | Module | |---|---|---| @@ -829,7 +872,7 @@ writing-plans for v1 there. Implementation happens on `co-processor`. | Canonical bytes | `canonical_text`, `canonical_text_fingerprint`, `CANONICAL_TEXT_MEDIA_TYPE`, `processor_version` | `co_core.pure.extract.canonical` | | Spec identity | `spec_fingerprint`, `spec_schema_version` | `co_core.pure.extract.spec_fingerprint` | | Digests | `bare_sha256`; `validate_fingerprint` | `co_core.pure.util.hashing`; `co_core.pure.util.blobstore` | -| Stores | `BlobStore` (`open`, `store`, `exists`, `uri_for`); `GcsBlobStore` | `co_core.pure.util.blobstore`; `co_core_sync.drivers.blobstore.gcs` | +| Stores | `BlobStore` (`open`, `store_reporting` → `Stored(uri, created)` since 0.41.0, `exists`, `uri_for`); `GcsBlobStore` | `co_core.pure.util.blobstore`; `co_core_sync.drivers.blobstore.gcs` | | Bus client | `AsyncBusConsumer`, producer | `co-core-aio[bus]` | Field rules the Emit classes enforce: `output_digest` is `sha256:` @@ -856,7 +899,7 @@ echoed, reporting only. `ChangeRevision.processor_version` is never rewritten. `spec_fingerprint` gets the same treatment. 2. ~~**co-core-aio:** does `AsyncBusConsumer` expose a delivery count or a - max-deliveries hook?~~ **Answered, no (0.19.4 through 0.38.0).** It offers + max-deliveries hook?~~ **Answered, no (0.19.4 through 0.51.1).** It offers primitives only: `ensure_group`, `read`, `ack`, `claim_stale` / `claim_stale_page`, and `dead_letter`. It has no delivery count, no hook and no run loop. The in-memory counter stays, and Processor owns its loop. diff --git a/pyproject.toml b/pyproject.toml index 6941ee5..2c68deb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,9 +8,9 @@ dependencies = [ # Exact, and Processor owns the pin (spec D5, §5). processor_version is # "+", so a bump moves every fact Watcher # compares; tests/test_pin.py makes one a deliberate, test-failing act. - "co-core[extract]==0.38.0", - "co-core-aio[bus]==0.38.0", - "co-core-sync[gcs]==0.38.0", + "co-core[extract]==0.51.1", + "co-core-aio[bus]==0.51.1", + "co-core-sync[gcs]==0.51.1", # All three come from the co-pypi index alone ([tool.uv.sources]), each declared # here: uv binds a source to a direct dependency only (#121). "pydantic>=2.12,<3", @@ -122,16 +122,11 @@ co-core-sync = { index = "co-pypi" } # parsing (#138); pyasn1 (via pyasn1-modules, google-auth) 0.6.5 fixes quadratic-time # BER/DER decoding (#112). tests/test_lock_floors.py checks them. # pypdf is also extraction stack: moving it bumps LOCAL_GENERATION (tests/test_pin.py). +# soupsieve's 4.1 floor (#138) needs no entry: co-core 0.51.1's extract extra declares +# >=4.1,<5 itself, and tests/test_lock_floors.py holds it there (#140). constraint-dependencies = [ "certifi>=2026.10.19", "pypdf>=6.21.4", "opentelemetry-api>=1.45.2", "pyasn1>=0.6.5", ] -# soupsieve (via co-core[extract] and bs4) 4.1 fixes three selector DoS advisories on 2.10 -# (GHSA-mmhr-3c5m-f64f, GHSA-6655-6qjp-jx7x, GHSA-7g44-g9rc-x53w; #138). co-core 0.38.0's -# extract extra caps it <3 and a constraint only narrows, so this overrides co-core's -# requirement. Remove it at the co-core bump to >=0.46.1, which declares >=4.1,<5 itself: -# tests/test_lock_floors.py fails once co-core's own requirement admits >=4.1, the cue. -# Extraction stack: LOCAL_GENERATION 4. -override-dependencies = ["soupsieve>=4.1,<5"] diff --git a/src/processor/handler.py b/src/processor/handler.py index d8dccfe..4523699 100644 --- a/src/processor/handler.py +++ b/src/processor/handler.py @@ -20,6 +20,11 @@ Order is store → publish → ack. A publish failure after a store leaves the entry pending; the re-run finds the object already stored (write-if-absent) and publishes. +The store goes through ``store_reporting`` (cannobserv#530, #140), and the outcome +record says whether this call created the object (``output_created``; not +``created``, which is a ``LogRecord`` attribute). A log signal, never a +branch: each backend is exact one way only (GCS's ``True``, the filesystem's +``False``). """ import asyncio @@ -68,7 +73,8 @@ class Disposition: timings: dict[str, float] = field(default_factory=dict) # What the command read and published, in wire form (#26): ``input_digest`` once # valid; from a complete fact, ``output_digest`` (absent when empty), - # ``output_size_bytes``, ``empty`` and ``processor_version``. + # ``output_size_bytes``, ``empty`` and ``processor_version``; and from the store, + # ``output_created`` (absent when empty: nothing stored; #140). log_fields: dict[str, object] = field(default_factory=dict) @@ -126,8 +132,9 @@ async def handle(message: BusMessage, *, attempt: int, deps: Deps) -> Dispositio timer = _Timer() ids = {"command_id": command.command_id, "info_source_id": command.info_source_id} log_fields = input_log_fields(command) + created = None try: - fact = await _derive(command, deps, timer) + fact, created = await _derive(command, deps, timer) except _Terminal as exc: fact = _failed(command, deps, exc.reason, exc.detail) except Exception as exc: @@ -148,7 +155,7 @@ async def handle(message: BusMessage, *, attempt: int, deps: Deps) -> Dispositio fact = _failed(command, deps, "extraction_error", f"gave up on attempt {attempt}: {detail}") if isinstance(fact, ProcessingCompleteEmit): - log_fields = {**log_fields, **_output_log_fields(fact)} + log_fields = {**log_fields, **_output_log_fields(fact, created)} since = time.monotonic() try: @@ -188,19 +195,26 @@ def input_log_fields(command: ContentProcessCommand) -> dict[str, str]: return {} -def _output_log_fields(fact: ProcessingCompleteEmit) -> dict[str, object]: - # From the fact, so the record says what was published. An empty one has no digest. +def _output_log_fields(fact: ProcessingCompleteEmit, created: bool | None) -> dict[str, object]: + # From the fact, so the record says what was published. An empty one has no digest, + # and stored nothing, so no ``output_created`` either. digest = {} if fact.output_digest is None else {"output_digest": fact.output_digest} - return digest | { - "output_size_bytes": fact.output_size_bytes, - "empty": fact.empty, - "processor_version": fact.processor_version, - } + stored = {} if created is None else {"output_created": created} + return ( + digest + | { + "output_size_bytes": fact.output_size_bytes, + "empty": fact.empty, + "processor_version": fact.processor_version, + } + | stored + ) async def _derive( command: ContentProcessCommand, deps: Deps, timer: _Timer -) -> ProcessingCompleteEmit: +) -> tuple[ProcessingCompleteEmit, bool | None]: + # The fact, and whether the store created its output (None: empty, nothing stored). transform = TRANSFORMS.get(command.processor) if transform is None: raise _Terminal("unsupported_processor", f"no transform named {command.processor!r}") @@ -224,17 +238,18 @@ async def _derive( if not isinstance(outcome, ExtractOutcome): raise _Strike(f"child returned {type(outcome).__name__}, not ExtractOutcome") - output_uri = None + output_uri = created = None if not outcome.empty: - output_uri = await asyncio.to_thread( - deps.stores.output.store, + stored = await asyncio.to_thread( + deps.stores.output.store_reporting, outcome.text, bare_sha256(outcome.output_digest), CANONICAL_TEXT_MEDIA_TYPE, ) + output_uri, created = stored.uri, stored.created timer.lap("store_ms", since) - return ProcessingCompleteEmit( + fact = ProcessingCompleteEmit( occurred_at=deps.clock(), command_id=command.command_id, info_source_id=command.info_source_id, @@ -247,6 +262,7 @@ async def _derive( spec_schema_version=outcome.spec_schema_version, processor_version=outcome.processor_version, ) + return fact, created async def _read_input(command: ContentProcessCommand, deps: Deps, timer: _Timer) -> bytes: diff --git a/tests/fixtures/parity/cases.json b/tests/fixtures/parity/cases.json index 67560a6..12c561f 100644 --- a/tests/fixtures/parity/cases.json +++ b/tests/fixtures/parity/cases.json @@ -76,5 +76,28 @@ "media_type": "application/problem+json", "source_spec": {"extraction": {"algorithm": "jsonpath", "selector": "$.items"}}}, {"id": "refused_css_on_json", "input": "items.json", "media_type": "application/json", - "source_spec": {"extraction": {"algorithm": "css", "selector": "#main"}}} + "source_spec": {"extraction": {"algorithm": "css", "selector": "#main"}}}, + {"id": "feed_rss_include_description", "input": "tailscale_security_bulletins.xml", + "media_type": "application/rss+xml", + "source_spec": {"extraction": {"algorithm": "full_page", "include_description": true}}, + "source": "co-core 0.51.0 maps include_description (cannobserv#559; #140)"}, + {"id": "feed_atom_include_description", "input": "feed.atom", + "media_type": "application/atom+xml", + "source_spec": {"extraction": {"include_description": true}}}, + {"id": "feed_rss_include_description_false", "input": "tailscale_security_bulletins.xml", + "media_type": "application/rss+xml", + "source_spec": {"extraction": {"algorithm": "full_page", "include_description": false}}}, + {"id": "refused_include_description_on_css", "input": "agenda.html", + "media_type": "text/html", + "source_spec": {"extraction": {"algorithm": "css", "selector": "#main", + "include_description": true}}}, + {"id": "refused_include_description_on_html", "input": "agenda.html", + "media_type": "text/html", + "source_spec": {"extraction": {"algorithm": "full_page", "include_description": true}}}, + {"id": "refused_include_description_on_non_feed_xml", "input": "register.xml", + "media_type": "application/xml", + "source_spec": {"extraction": {"algorithm": "full_page", "include_description": true}}}, + {"id": "refused_include_description_not_bool", "input": "tailscale_security_bulletins.xml", + "media_type": "application/rss+xml", + "source_spec": {"extraction": {"algorithm": "full_page", "include_description": "true"}}} ] diff --git a/tests/fixtures/parity/goldens.json b/tests/fixtures/parity/goldens.json index d4c364d..73a41ef 100644 --- a/tests/fixtures/parity/goldens.json +++ b/tests/fixtures/parity/goldens.json @@ -1,5 +1,5 @@ { - "co_core": "0.38.0", + "co_core": "0.51.1", "generated_by": "scripts/gen_parity_goldens.py (co-core's pure extract API, direct; #47)", "goldens": { "csv": { @@ -14,6 +14,12 @@ "spec_fingerprint": "spec1:sha256:71ec7a46fe3cd2c105ad4029e31f1fdbe3fdffc17ab976167e793143957c9a60", "spec_schema_version": 1 }, + "feed_atom_include_description": { + "content_fingerprint": "sha256:b06b4586789b168c2538ead939c76f01ffa1e420c41891baa725147028811ba6", + "content_size_bytes": 214, + "spec_fingerprint": "spec1:sha256:86f75c92d51a42f3d8eced4b7ac0c0dafc1426f930af508f9eb12350f0d30159", + "spec_schema_version": 1 + }, "feed_no_items": { "content_fingerprint": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "content_size_bytes": 0, @@ -26,6 +32,18 @@ "spec_fingerprint": "spec1:sha256:71ec7a46fe3cd2c105ad4029e31f1fdbe3fdffc17ab976167e793143957c9a60", "spec_schema_version": 1 }, + "feed_rss_include_description": { + "content_fingerprint": "sha256:bf73076cfcf38403036679e1aeb331fe991f9a7b6d188ff01fb27d57e5288944", + "content_size_bytes": 5579, + "spec_fingerprint": "spec1:sha256:be56040cb09489b8e0e44d034853001acc47520915320a687abb9db1493bde53", + "spec_schema_version": 1 + }, + "feed_rss_include_description_false": { + "content_fingerprint": "sha256:78e284978faf41fbe8ccd8dc06e6d2803d9788097fca633486dfbbbdc024be09", + "content_size_bytes": 422, + "spec_fingerprint": "spec1:sha256:faa689914d2ac79b3847b2f51db6b78e7991d4935725cd5b37a701ffeee9e3e2", + "spec_schema_version": 1 + }, "feed_rss_rss_essence": { "content_fingerprint": "sha256:78e284978faf41fbe8ccd8dc06e6d2803d9788097fca633486dfbbbdc024be09", "content_size_bytes": 422, @@ -128,6 +146,18 @@ "refused_empty_xpath": { "refused": "UnsupportedExtractionError" }, + "refused_include_description_not_bool": { + "refused": "UnsupportedExtractionError" + }, + "refused_include_description_on_css": { + "refused": "UnsupportedExtractionError" + }, + "refused_include_description_on_html": { + "refused": "UnsupportedExtractionError" + }, + "refused_include_description_on_non_feed_xml": { + "refused": "UnsupportedExtractionError" + }, "refused_invalid_xpath": { "refused": "UnsupportedExtractionError" }, diff --git a/tests/processors/test_extract.py b/tests/processors/test_extract.py index fbcb894..6fa0dec 100644 --- a/tests/processors/test_extract.py +++ b/tests/processors/test_extract.py @@ -121,6 +121,42 @@ def test_the_corpus_covers_the_refusals_and_the_dispatched_essences() -> None: } <= REFUSED # Refused until 0.38.0: jsonpath (cannobserv#354) and xpath on HTML (cannobserv#557). assert {"json_jsonpath", "json_jsonpath_titles", "html_xpath"}.isdisjoint(REFUSED) + # Refused since 0.51.0 (cannobserv#559, #140); each extracted silently before. + assert { + "refused_include_description_not_bool", + "refused_include_description_on_css", + "refused_include_description_on_html", + "refused_include_description_on_non_feed_xml", + } <= REFUSED + + +@pytest.mark.parametrize( + "case_id", + [ + "refused_include_description_not_bool", + "refused_include_description_on_css", + "refused_include_description_on_html", + "refused_include_description_on_non_feed_xml", + ], +) +def test_each_include_description_refusal_is_for_that_key(case_id: str) -> None: + # A refused golden records only the type, so this pins the reason: on an HTML body + # css is honoured, so the key alone can refuse (#140). + (case,) = [c for c in CASES if c["id"] == case_id] + with pytest.raises(UnsupportedExtractionError, match="include_description"): + _run(case) + + +def test_include_description_appends_each_item_s_description() -> None: + # cannobserv#559: true adds the description field; false is the plain feed line. + def text(case_id: str) -> bytes: + (case,) = [c for c in CASES if c["id"] == case_id] + return _run(case).text + + description = b"Insufficient validation of 4via6 subnet router destinations" + assert description in text("feed_rss_include_description") + assert description not in text("feed_rss_include_description_false") + assert text("feed_rss_include_description_false") == text("feed_rss") def test_the_fallback_case_uses_an_essence_co_core_does_not_map() -> None: diff --git a/tests/test_consumer.py b/tests/test_consumer.py index 8e72828..6d87d1c 100644 --- a/tests/test_consumer.py +++ b/tests/test_consumer.py @@ -216,6 +216,7 @@ async def test_a_complete_record_names_what_it_read_and_published( assert logged["output_size_bytes"] == len(expected.text) assert logged["empty"] is False assert logged["processor_version"] == PROCESSOR_VERSION + assert logged["output_created"] is True # store_reporting (#140) async def test_an_undecodable_frame_is_dead_lettered(admin, bus, stores) -> None: diff --git a/tests/test_handler.py b/tests/test_handler.py index c3b9048..ecf9130 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -2,6 +2,7 @@ import hashlib import importlib +import logging from dataclasses import dataclass, field from datetime import UTC, datetime from pathlib import Path @@ -305,7 +306,7 @@ async def test_gcs_failures_leave_the_entry_pending(h: Harness, exc, where: str) if where == "input": h.input_override = FlakyStore(h.input, method="open", exc=exc) else: - h.output_override = FlakyStore(h.output, method="store", exc=exc) + h.output_override = FlakyStore(h.output, method="store_reporting", exc=exc) disposition = await h.run(h.message(), attempt=3) # uncapped: even the last attempt assert disposition.action == "leave_pending" assert h.publisher.effects == [] @@ -329,10 +330,12 @@ async def test_publish_failure_leaves_pending_and_the_rerun_converges(h: Harness assert len(stored) == 1 # the store ran; the reclaim's re-run finds it there h.publisher.fail = None - assert (await h.run(h.message())).action == "ack" + rerun = await h.run(h.message()) + assert rerun.action == "ack" (fact,) = h.publisher.facts assert fact.empty is False assert list(h.output.root.rglob("*.bin")) == stored + assert rerun.log_fields["output_created"] is False # found, not written (#140) async def test_a_non_transient_publish_failure_escapes_to_be_counted(h: Harness) -> None: @@ -364,9 +367,43 @@ async def test_a_complete_record_names_its_input_and_the_published_output(h: Har "output_size_bytes": len(expected.text), "empty": False, "processor_version": PROCESSOR_VERSION, + "output_created": True, # this call wrote the object (#140) } +async def test_a_record_for_an_output_already_stored_says_it_was_not_created( + h: Harness, +) -> None: + # A re-delivery, or another command whose output is the same text: store_reporting + # finds the key taken. A log signal only (#140): exact this way on the local store, + # but on GCS a False may be the SDK retrying this call's own create. + expected = extract(HTML, "text/html", SPEC) + h.output.store(expected.text, bare_sha256(expected.output_digest), CANONICAL_TEXT_MEDIA_TYPE) + disposition = await h.run(h.message()) + assert disposition.action == "ack" + assert disposition.log_fields["output_created"] is False + (fact,) = h.publisher.facts + assert fact.output_uri == h.output.uri_for(bare_sha256(expected.output_digest)) + + +async def test_no_record_field_shadows_a_log_record_attribute(h: Harness) -> None: + # The consumer logs these as ``extra``, and logging raises KeyError on a name the + # LogRecord already has: ``created`` is its timestamp, hence ``output_created`` (#140). + reserved = set(vars(logging.LogRecord("x", logging.INFO, "x", 0, "", (), None))) + reserved |= {"message", "asctime"} + disposition = await h.run(h.message()) + assert disposition.reason == "complete" + assert not reserved & disposition.log_fields.keys() + + +async def test_the_handler_stores_through_the_reporting_twin(h: Harness) -> None: + # Plain store is store_reporting(...).uri; calling both would write twice over, and + # a FlakyStore that injects on store would no longer reach the handler (#140). + h.output_override = FlakyStore(h.output, method="store", exc=AssertionError("plain store")) + disposition = await h.run(h.message()) + assert (disposition.action, disposition.reason) == ("ack", "complete") + + async def test_an_empty_record_has_no_output_digest(h: Harness) -> None: disposition = await h.run(h.message(BLANK_PDF, media_type="application/pdf", source_spec={})) assert disposition.log_fields == { @@ -410,6 +447,7 @@ async def test_a_publish_failure_record_names_the_stored_output(h: Harness) -> N assert disposition.action == "leave_pending" assert disposition.log_fields["output_digest"] == extract(HTML, "text/html", SPEC).output_digest assert disposition.log_fields["input_digest"] == hashlib.sha256(HTML).hexdigest() + assert disposition.log_fields["output_created"] is True # --- the consumer's cap (#17) ----------------------------------------------------------- diff --git a/tests/test_lock_floors.py b/tests/test_lock_floors.py index d336651..d551132 100644 --- a/tests/test_lock_floors.py +++ b/tests/test_lock_floors.py @@ -9,11 +9,13 @@ beside certifi's (``test_tls_trust.py``). soupsieve 4.1 fixes three selector DoS advisories against 2.10 (GHSA-mmhr-3c5m-f64f, -GHSA-6655-6qjp-jx7x, GHSA-7g44-g9rc-x53w; #138), but co-core 0.38.0's ``extract`` extra -caps it ``<3``, and a constraint only narrows. So its floor is an -``override-dependencies`` entry, which replaces co-core's requirement until a co-core -bump to 0.46.1 or later declares ``>=4.1`` itself. The guard below fails then, so the -bump removes the override instead of carrying it. +GHSA-6655-6qjp-jx7x, GHSA-7g44-g9rc-x53w; #138). co-core 0.38.0's ``extract`` extra +capped it ``<3``, and a constraint only narrows, so #138 put its floor in +``override-dependencies``, which replaces co-core's requirement. co-core 0.46.1 and later +declare ``>=4.1,<5`` themselves, so the bump to 0.51.1 (#140) removed the override: the +floor is co-core's own (``CO_CORE_FLOORED``), and a test holds it there. The override +route stays for the next floor co-core caps below: an ``OVERRIDDEN`` row, whose guard +fails once co-core's own requirement admits the floor. """ import re @@ -22,6 +24,9 @@ from pathlib import Path import pytest +from packaging.requirements import Requirement +from packaging.utils import canonicalize_name +from packaging.version import InvalidVersion, Version ROOT = Path(__file__).resolve().parent.parent FLOORS = { @@ -30,8 +35,12 @@ "pyasn1": (0, 6, 5), "soupsieve": (4, 1), } -# Floors co-core's own requirement caps below, so they override it (#138). -OVERRIDDEN = {"soupsieve"} +# Floors co-core's own requirement caps below, so they override it. None since #140 +# (soupsieve was #138's). +OVERRIDDEN: set[str] = set() +# Floors co-core's own ``extract`` requirement already holds, so neither a constraint nor +# an override names them (soupsieve: co-core >= 0.46.1 declares >=4.1,<5; #140). +CO_CORE_FLOORED = {"soupsieve"} def _parts(v: str) -> tuple[int, ...]: @@ -76,44 +85,99 @@ def _co_core_spec(name: str) -> str | None: return None +def _bounds(spec: str) -> list: + # (operator, version, specifier) per clause, parsed as PEP 440 (CR 4). Only a plain + # release is read: a pre-, dev-, post- or local version, or a wildcard, says nothing + # simple about a floor, so it fails loudly rather than reading as a number. + out = [] + for clause in Requirement(spec).specifier: + try: + v = Version(clause.version) + except InvalidVersion: + v = None + if v is None or v.pre or v.dev is not None or v.post is not None or v.local: + raise ValueError(f"{spec}: {clause} isn't a plain release; read it by hand") + out.append((clause.operator, v, clause)) + return out + + +def _version(floor: tuple[int, ...]) -> Version: + return Version(".".join(map(str, floor))) + + def _admits(spec: str, floor: tuple[int, ...]) -> bool: - # Whether the requirement allows ``floor`` or later: only an upper bound can refuse it. - width = 4 # pad, so 4.1.0 and 4.1 compare equal - floor = floor + (0,) * (width - len(floor)) - for op, v in re.findall(r"(<=|<)\s*([\d.]+)", spec): - cap = _parts(v) + (0,) * (width - len(_parts(v))) - if cap < floor or (op == "<" and cap == floor): + # Whether the requirement allows ``floor`` or later. A lower bound or an exclusion + # never refuses all of them; an upper bound refuses them when it refuses the floor; + # ==, === and ~= when they refuse the lowest version they could allow from there. + f = _version(floor) + for op, v, clause in _bounds(spec): + if op in ("<", "<=") and not clause.contains(f): + return False + if op in ("==", "===", "~=") and not clause.contains(max(f, v)): return False return True -@pytest.mark.parametrize("name", sorted(FLOORS.keys() - OVERRIDDEN)) -def test_pyproject_constrains_the_floor(name: str) -> None: - floor = ".".join(map(str, FLOORS[name])) - assert f"{name}>={floor}" in _uv()["constraint-dependencies"] +def _floors(spec: str, floor: tuple[int, ...]) -> bool: + # Whether the requirement alone refuses everything below ``floor``: a lower bound at + # or above it. ``>v`` counts only when v is at least the floor (>4.0 admits 4.0.1). + f = _version(floor) + return any(op in (">=", ">", "==", "===", "~=") and v >= f for op, v, _ in _bounds(spec)) -@pytest.mark.parametrize("name", sorted(OVERRIDDEN)) -def test_pyproject_overrides_the_floor(name: str) -> None: +def _requirement_name(spec: str) -> str: + return canonicalize_name(Requirement(spec).name) + + +def test_each_floor_is_held_one_way() -> None: + # An override and co-core's own floor exclude each other, and each names a floor. + assert OVERRIDDEN <= FLOORS.keys() and CO_CORE_FLOORED <= FLOORS.keys() + assert OVERRIDDEN.isdisjoint(CO_CORE_FLOORED) + + +@pytest.mark.parametrize("name", sorted(FLOORS.keys() - OVERRIDDEN - CO_CORE_FLOORED)) +def test_pyproject_constrains_the_floor(name: str) -> None: floor = ".".join(map(str, FLOORS[name])) - (entry,) = [d for d in _uv().get("override-dependencies", []) if _names(d, name)] - assert f">={floor}" in entry, entry - assert name not in " ".join(_uv()["constraint-dependencies"]) + assert f"{name}>={floor}" in _uv()["constraint-dependencies"] -@pytest.mark.parametrize("name", sorted(OVERRIDDEN)) -def test_co_core_still_needs_the_override(name: str) -> None: - # Fails once co-core's own requirement admits the floor: at co-core >= 0.46.1 for - # soupsieve (>=4.1,<5), or at a release that only lifts the cap (>=2.0,<5). Then - # remove the override and its OVERRIDDEN row; if co-core's own floor is lower, keep - # ours as a constraint-dependencies floor (DEPENDENCIES.md, Bumping co-core). +def test_each_override_is_an_overridden_floor_co_core_still_needs() -> None: + # One test, not one per row: OVERRIDDEN is empty between overrides, and a + # parametrization over nothing would be a skip, which reads as something unrun. + entries = {_requirement_name(d): d for d in _uv().get("override-dependencies", [])} + assert entries.keys() == OVERRIDDEN, ( + f"override-dependencies names {sorted(entries)}, OVERRIDDEN {sorted(OVERRIDDEN)}: " + "an override replaces co-core's requirement, so each one is a floor here, and is " + "removed with its row once co-core admits it (DEPENDENCIES.md, Bumping co-core)." + ) + constraints = " ".join(_uv()["constraint-dependencies"]) + for name, entry in entries.items(): + assert f">={'.'.join(map(str, FLOORS[name]))}" in entry, entry + assert name not in constraints + # Fails once co-core's own requirement admits the floor (a raised floor, or only + # a lifted cap). Then remove the override and its row; if co-core's own floor is + # lower, keep ours as a constraint (as soupsieve's override went at #140). + spec = _co_core_spec(name) + assert spec is not None, f"co-core no longer declares {name} under its extract extra" + assert not _admits(spec, FLOORS[name]), ( + f"co-core's own requirement ({spec}) now admits {name} {FLOORS[name]}: the " + "override-dependencies entry is redundant. Remove it and its OVERRIDDEN row, " + "with a constraint floor if co-core's is lower (processor#138, #140)." + ) + + +@pytest.mark.parametrize("name", sorted(CO_CORE_FLOORED)) +def test_co_core_holds_the_floor_itself(name: str) -> None: + # Why no constraint names it. If a co-core bump lowers its own floor, add one. spec = _co_core_spec(name) assert spec is not None, f"co-core no longer declares {name} under its extract extra" - assert not _admits(spec, FLOORS[name]), ( - f"co-core's own requirement ({spec}) now admits {name} {FLOORS[name]}: the " - "override-dependencies entry is redundant. Remove it and its OVERRIDDEN row, " - "with a constraint floor if co-core's is lower (processor#138)." + assert _floors(spec, FLOORS[name]), ( + f"co-core's own requirement ({spec}) no longer floors {name} at {FLOORS[name]}: " + "put the floor in constraint-dependencies and move the name out of " + "CO_CORE_FLOORED (DEPENDENCIES.md, Bumping co-core; processor#140)." ) + assert name not in " ".join(_uv()["constraint-dependencies"]) + assert name not in " ".join(_uv().get("override-dependencies", [])) def test_the_guard_finds_co_core_s_requirement(monkeypatch: pytest.MonkeyPatch) -> None: @@ -148,16 +212,68 @@ def test_a_requirement_names_the_package_exactly(spec: str, named: bool) -> None @pytest.mark.parametrize( ("spec", "admits"), [ - ("soupsieve<3,>=2.0", False), # co-core 0.38.0: the override is needed + ("soupsieve<3,>=2.0", False), # co-core 0.38.0: the override was needed (#138) ("soupsieve<4.1,>=2.0", False), # a cap at the floor excludes it ("soupsieve<4.1.0", False), # however it is spelled ("soupsieve<=4.0", False), - ("soupsieve>=4.1,<5", True), # co-core 0.46.1 + ("soupsieve>=4.1,<5", True), # co-core 0.46.1 to 0.51.1 (#140) ("soupsieve>=2.0,<5", True), # only the cap lifted: a constraint would do ("soupsieve<=4.1", True), + ("soupsieve==4.0", False), # pinned below the floor + ("soupsieve==4.1.3", True), + ("soupsieve~=4.0", True), # >=4.0,<5 + ("soupsieve~=4.0.0", False), # >=4.0.0,<4.1 + ("soupsieve!=4.1", True), # 4.1.1 is still allowed ("soupsieve>=2.0", True), ("soupsieve", True), ], ) def test_the_guard_reads_whether_co_core_admits_the_floor(spec: str, admits: bool) -> None: assert _admits(spec, (4, 1)) is admits + + +@pytest.mark.parametrize( + ("spec", "floors"), + [ + ("soupsieve>=4.1,<5", True), # co-core 0.51.1 (#140) + ("soupsieve<5,>=4.1.0", True), # however it is spelled + ("soupsieve>=4.2", True), + ("soupsieve==4.1.3", True), + ("soupsieve~=4.1", True), + ("soupsieve>4.1", True), + ("soupsieve<3,>=2.0", False), # co-core 0.38.0 + ("soupsieve>=4.0,<5", False), # a floor below ours: add a constraint + ("soupsieve>4.0", False), # admits 4.0.1 + ("soupsieve<=4.1", False), # an upper bound only + ("soupsieve!=4.1", False), + ("soupsieve", False), + ], +) +def test_the_guard_reads_whether_co_core_floors_it(spec: str, floors: bool) -> None: + assert _floors(spec, (4, 1)) is floors + + +@pytest.mark.parametrize( + ("spec", "name"), + [ + ("soupsieve>=4.1,<5", "soupsieve"), + (" SoupSieve [x] >=4.1", "soupsieve"), + ("opentelemetry-api>=1.45.2", "opentelemetry-api"), + ("opentelemetry_api>=1.45.2", "opentelemetry-api"), # normalised (CR 5) + ("Zope.Interface", "zope-interface"), + ], +) +def test_an_override_s_name_is_its_requirement_s(spec: str, name: str) -> None: + assert _requirement_name(spec) == name + + +@pytest.mark.parametrize( + "spec", + ["soupsieve>=4.1rc1", "soupsieve<=4.1rc1", "soupsieve>=4.1.dev0", "soupsieve==4.1.*", + "soupsieve<4.1.post1"], +) # fmt: skip +def test_the_guard_refuses_to_guess_at_a_non_plain_version(spec: str) -> None: + # As numbers, >=4.1rc1 read as floored at 4.1 and <=4.1rc1 as admitting it (CR 4). + for read in (_admits, _floors): + with pytest.raises(ValueError, match="read it by hand"): + read(spec, (4, 1)) diff --git a/tests/test_pin.py b/tests/test_pin.py index 8394578..98529de 100644 --- a/tests/test_pin.py +++ b/tests/test_pin.py @@ -26,7 +26,7 @@ from processor.processors.extract import LOCAL_GENERATION, PROCESSOR_VERSION -EXPECTED = "0.38.0" +EXPECTED = "0.51.1" ROOT = Path(__file__).resolve().parent.parent PINNED = ("co-core", "co-core-aio", "co-core-sync") SRC = ROOT / "src" / "processor" @@ -35,7 +35,8 @@ GENERATION = 4 # The transitive closure of co-core's ``extract`` extra in uv.lock: what turns bytes # into text beside co-core itself. Moved together with GENERATION (#71: pypdf 6.21.2; -# #112: pypdf 6.21.4; #138: soupsieve 4.1.1, by override past co-core's cap). +# #112: pypdf 6.21.4; #138: soupsieve 4.1.1, by override past co-core's cap; #140: +# soupsieve 4.1.3 with co-core 0.51.1, which floors it at 4.1 itself). EXTRACTION_STACK = { "beautifulsoup4": "4.15.0", "et-xmlfile": "2.0.0", @@ -45,7 +46,7 @@ "pypdf": "6.21.4", "python-jsonpath": "2.2.2", "six": "1.17.0", - "soupsieve": "4.1.1", + "soupsieve": "4.1.3", "typing-extensions": "4.16.0", "webencodings": "0.6.1", } diff --git a/uv.lock b/uv.lock index 3de4d06..6cfd238 100644 --- a/uv.lock +++ b/uv.lock @@ -13,7 +13,6 @@ constraints = [ { name = "pyasn1", specifier = ">=0.6.5" }, { name = "pypdf", specifier = ">=6.21.4" }, ] -overrides = [{ name = "soupsieve", specifier = ">=4.1,<5" }] [[package]] name = "annotated-types" @@ -277,15 +276,15 @@ wheels = [ [[package]] name = "co-core" -version = "0.38.0" +version = "0.51.1" source = { registry = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/simple/" } dependencies = [ { name = "dateparser" }, { name = "pydantic" }, ] -sdist = { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core/co_core-0.38.0.tar.gz", hash = "sha256:2ec3cbc6f020792d24b3baff92724567c4eb74102b80e3ed47b54dc3ec39cf29" } +sdist = { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core/co_core-0.51.1.tar.gz", hash = "sha256:0ea6e42d708d458eb7fdcca4494f132f5451a843d25a806b36d96f649e78764d" } wheels = [ - { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core/co_core-0.38.0-py3-none-any.whl", hash = "sha256:44a62404f645de685c6260e087311d3e2cf0cf6074e9a9cfc2d6cf35b3c566f9" }, + { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core/co_core-0.51.1-py3-none-any.whl", hash = "sha256:cad8632b11ecfd8810cfaafd1f2041934d17edbc30d3ccc08c24f5a40a4bd087" }, ] [package.optional-dependencies] @@ -301,15 +300,15 @@ extract = [ [[package]] name = "co-core-aio" -version = "0.38.0" +version = "0.51.1" source = { registry = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/simple/" } dependencies = [ { name = "co-core" }, { name = "httpx" }, ] -sdist = { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core-aio/co_core_aio-0.38.0.tar.gz", hash = "sha256:682de39ea8df87d24e1d02c330375c8bf7e9785ea6bd931964bd4e2ef26c82b1" } +sdist = { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core-aio/co_core_aio-0.51.1.tar.gz", hash = "sha256:881fce7ea6e5648a4092f3732776f147ca0abfe51bdd4ab47a5e97bb08ac4554" } wheels = [ - { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core-aio/co_core_aio-0.38.0-py3-none-any.whl", hash = "sha256:aac71c6f5e8d34e5a9aff856ce0f1c40898b41561ad399df908896ece718aef1" }, + { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core-aio/co_core_aio-0.51.1-py3-none-any.whl", hash = "sha256:4835d85f72659cfda2e603de88ad4035875473d09b0afccb9ad386e7da23ce12" }, ] [package.optional-dependencies] @@ -319,16 +318,16 @@ bus = [ [[package]] name = "co-core-sync" -version = "0.38.0" +version = "0.51.1" source = { registry = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/simple/" } dependencies = [ { name = "co-core" }, { name = "requests" }, { name = "urllib3" }, ] -sdist = { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core-sync/co_core_sync-0.38.0.tar.gz", hash = "sha256:0cfb6c4b1ae16c0217c42de6f070dbea79b2ce9a20140d251fd6b3a73c7c7e14" } +sdist = { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core-sync/co_core_sync-0.51.1.tar.gz", hash = "sha256:1485be9960fc9940d2a8f455a9fde5761d24d51a15cc1b598886780706d4b8fc" } wheels = [ - { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core-sync/co_core_sync-0.38.0-py3-none-any.whl", hash = "sha256:f69d84215d6df4d92b261eed5b11d69a9d4c95a1ce659d362b825d094f5072f4" }, + { url = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/co-core-sync/co_core_sync-0.51.1-py3-none-any.whl", hash = "sha256:a93fcc9c76b5dddf6adca5f59ba15de08a93c66c3e909a8c3e62b8518c288019" }, ] [package.optional-dependencies] @@ -894,9 +893,9 @@ lint = [ [package.metadata] requires-dist = [ - { name = "co-core", extras = ["extract"], specifier = "==0.38.0", index = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/simple/" }, - { name = "co-core-aio", extras = ["bus"], specifier = "==0.38.0", index = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/simple/" }, - { name = "co-core-sync", extras = ["gcs"], specifier = "==0.38.0", index = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/simple/" }, + { name = "co-core", extras = ["extract"], specifier = "==0.51.1", index = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/simple/" }, + { name = "co-core-aio", extras = ["bus"], specifier = "==0.51.1", index = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/simple/" }, + { name = "co-core-sync", extras = ["gcs"], specifier = "==0.51.1", index = "https://us-west1-python.pkg.dev/co-gcs/co-pypi/simple/" }, { name = "google-api-core", specifier = ">=2.27,<3" }, { name = "google-auth", specifier = ">=2,<3" }, { name = "google-cloud-storage", specifier = ">=3,<4" }, @@ -1406,11 +1405,11 @@ wheels = [ [[package]] name = "soupsieve" -version = "4.1.1" +version = "4.1.3" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/1f/52/ee5646b65d98a252e807ccc37725363942372a4113072e0bce7ed22f8b84/soupsieve-4.1.1.tar.gz", hash = "sha256:b296bd2d2f65b1a78149f3d7bf6736a147d2c9e2dfbde0e4404639d748a02e03", size = 169784, upload-time = "2026-11-14T17:23:32.467Z" } +sdist = { url = "https://files.pythonhosted.org/packages/82/77/d59ca6aa338bdd8d880234d15b7c466cb176e44502899a9df81ba2e13cd0/soupsieve-4.1.3.tar.gz", hash = "sha256:13f70186c8f40bf8d0ff7bbab09a18fb149600b465269207b5e5b588f55fda08", size = 181564, upload-time = "2026-11-20T12:58:27.613Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/cd/65/7fae69a095696195334a934eab23aeb12e2715e6c3f08025d2f91942750e/soupsieve-4.1.1-py3-none-any.whl", hash = "sha256:8ff3422dab0b720fb667ee79864d80531a0e57994a13eb701697719ffcb751f6", size = 55089, upload-time = "2026-11-14T17:23:31.001Z" }, + { url = "https://files.pythonhosted.org/packages/f6/f7/be207468cac6ad79389f36cf1fce4f2836960df91659979ec486c727bb2e/soupsieve-4.1.3-py3-none-any.whl", hash = "sha256:7a390d1a57d1ab7bb228531e9b8a750a5ebf87db774e0ef6faeeac057d22a5bf", size = 59792, upload-time = "2026-11-20T12:58:26.459Z" }, ] [[package]]