From c846a3ed0c30ed84e42cc2c277e6f6fa9ce94990 Mon Sep 17 00:00:00 2001 From: felix Date: Mon, 23 Nov 2026 17:23:07 +0000 Subject: [PATCH] test(atlas+pm): metadata version conformance fixture set (#9095) Acceptance item 4 of #9095: metadata at every historical version parses and is usable by the current reader, in the #8525-#8528 fixture-family practice. - Fixture set under the schema v1 design folder: PM pm_meta v1 in its historical shapes (section 12 canonical, aggregator links-only and minimal-link blocks, float version, unknown keys, populated extras, type mismatch, plus fail-closed rejection cases), Atlas schema_version 1 item/embed/classification shapes alongside the unversioned atlas_stage v1 producer meta bag, and exact-byte digest vectors for the design section 2 identity rule. - Executable conformance: the fleet crate test runs every PM case through parse_metadata_block and the stamp assembly round-trip; the atlas-core test round-trips every executable Atlas case through a provisioned atlas_stage v1 database and list_staged_items, byte-exact. - Doctrine-projection cases (extras relocation, lossless-only coercion, sensitivity fallback, unknown closed enums) are recorded as oracle data for design section 7 slices 2/6; no current reader projects, so they are not asserted against one. - No new persisted fields, no store writes: CEN-04 section 3.10 already owns the PM block/mirror facts (see fixtures README). --- .../fixtures/README.md | 73 ++++++ .../fixtures/atlas-metadata-v1.json | 215 ++++++++++++++++++ .../fixtures/digest-vectors.json | 18 ++ .../fixtures/pm-metadata-v1.json | 116 ++++++++++ .../atlas-core/tests/metadata_conformance.rs | 106 +++++++++ pkgs/fleet/crates/fleet/src/gh_metadata.rs | 81 +++++++ 6 files changed, 609 insertions(+) create mode 100644 doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/README.md create mode 100644 doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/atlas-metadata-v1.json create mode 100644 doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/digest-vectors.json create mode 100644 doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/pm-metadata-v1.json create mode 100644 pkgs/atlas-search/crates/atlas-core/tests/metadata_conformance.rs diff --git a/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/README.md b/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/README.md new file mode 100644 index 0000000000..5b7e3cde46 --- /dev/null +++ b/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/README.md @@ -0,0 +1,73 @@ +# Metadata version conformance fixtures (#9095) + +The conformance fixture set for the Metadata schema v1 + evolution +doctrine specified in [`../note.md`](../note.md). Acceptance item 4 of +#9095: *metadata at every historical version parses and is usable by +the current reader*, in the fixture-family practice of #8525–#8528 — +hand-authored cases with recorded expectations, consumed by tests in +the crates that own the readers. + +Only one version of each surface has ever been published (PM +`pm_meta: 1`; Atlas `schema_version: 1`), so "every historical +version" is v1 in all of its historical *shapes*: the canonical form, +the pre-doctrine producer shapes still carried by live data, and the +doctrine edge cases those shapes must survive. + +## Files + +- **`pm-metadata-v1.json`** — PM issue/PR Metadata cases. Each case + carries a full issue body, a `reader_parse` expectation (`ok` / + `reject`), and the top-level keys the reader must preserve. + Asserted executably by the fleet crate conformance test + (`pkgs/fleet/crates/fleet/src/gh_metadata.rs`, + `pm_metadata_version_conformance_fixtures`), which runs every case + through `parse_metadata_block` and the stamp assembly round-trip. +- **`atlas-metadata-v1.json`** — Atlas corpus metadata cases. Cases + marked `executable: true` carry a `stage_row` and are asserted by + the atlas-core conformance test + (`pkgs/atlas-search/crates/atlas-core/tests/metadata_conformance.rs`): + the row is inserted into a provisioned `atlas_stage` v1 database + and read back through `list_staged_items`; `meta` must round-trip + byte-exact and the database schema version must be 1. +- **`digest-vectors.json`** — exact-byte identity vectors for the + design §2 rule (`sha256:` + lowercase hex of the SHA-256 of the + exact metadata bytes). Each vector records its input bytes and the + expected artifact ID, so any implementation can pin the rule + byte-exactly. + +## Doctrine-projection cases + +Some cases carry a `doctrine_projection` (Atlas cases with +`executable: false`, PM cases with the field present). These record +the expected *projection* under the doctrine — extras relocation, +lossless-only coercion, fail-closed sensitivity fallback, +unknown-closed-enum preservation (§3.1–3.2 of the design). No current +reader projects; projection is design §7 slice 2/6 work. These cases +are the oracle those implementations must satisfy. They are +deliberately **not** asserted against today's readers, whose +conforming behavior is parse-and-preserve (PM) and byte-exact +round-trip (Atlas staging). + +## Rules for this set + +- **Additive-only, like the schema.** A new schema version appends + new case files (`pm-metadata-v2.json`, …) and new cases; historical + cases are never edited or removed. If a case's expectation must + change, that is a doctrine event: record it in the design note's + change record and in the PR that changes it. +- Every case names its `historical_source` — the real shape, test, or + doctrine rule it comes from. Synthetic cases with no source do not + belong here. +- Rejection cases are part of conformance: a block with no version + key, or a version newer than the reader, must fail closed. + +## CEN-04 conformance + +This set introduces no persisted field and writes no store, so it +needs no new field-admission row under CEN-04 §5 +(`doc/2026-11-23T13-51-45Z_design_cen04_schema_owner_migration_compatibility/`). +The facts it exercises already have owners there: the pm-metadata +block in the GitHub body is the record and `pm_metadata_items` is its +rebuildable projection (CEN-04 §3.10); Atlas staging rows are owned +by the Atlas producer profile (design §3.1). Fixtures are test data +about those facts, not a new home for them. diff --git a/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/atlas-metadata-v1.json b/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/atlas-metadata-v1.json new file mode 100644 index 0000000000..5002689712 --- /dev/null +++ b/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/atlas-metadata-v1.json @@ -0,0 +1,215 @@ +{ + "fixture_set": "atlas-metadata-version-conformance", + "issue": "developing-today/code#9095", + "surface": "atlas", + "version_key": "schema_version", + "current_version": 1, + "source_design": "doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/note.md", + "notes": "Cases with executable=true and a stage_row are asserted by the atlas-core conformance test (pkgs/atlas-search/crates/atlas-core/tests/metadata_conformance.rs): the row is inserted into a provisioned atlas_stage v1 database and read back through list_staged_items; meta must round-trip byte-exact and the database schema version must be 1. Cases with executable=false carry doctrine_projection: the recorded oracle for the projection behavior in design section 7 slices 2 and 6, not asserted against any current reader.", + "cases": [ + { + "id": "atlas-stage-v1-producer-meta", + "historical_source": "The meta bag atlas_core::stage::stage_artifact writes today (atlas_stage v1, pkgs/atlas-search/schema/atlas_stage_v1.sql): an unversioned open JSON bag. This is the historical shape every staged item in the wild carries; the staging reader returns it byte-exact.", + "object": { + "repo": "developing-today/code", + "path": "pkgs/atlas-search/README.md", + "commit_sha": "0123456789abcdef0123456789abcdef01234567", + "kind": "prose", + "language": "md", + "unit": "whole-file", + "embedded_at": "2026-11-04T00:00:00Z", + "chunks": 3 + }, + "stage_row": { + "unit_id": "fixture-9095", + "kind": "prose", + "source": "developing-today/code:pkgs/atlas-search/README.md@0123456789abcdef0123456789abcdef01234567", + "sensitivity": "internal", + "text": "fixture body text", + "meta": "{\"chunks\":3,\"commit_sha\":\"0123456789abcdef0123456789abcdef01234567\",\"embedded_at\":\"2026-11-04T00:00:00Z\",\"kind\":\"prose\",\"language\":\"md\",\"path\":\"pkgs/atlas-search/README.md\",\"repo\":\"developing-today/code\",\"unit\":\"whole-file\"}" + }, + "executable": true + }, + { + "id": "atlas-v1-item-envelope", + "historical_source": "The doctrine v1 envelope (design section 2) for a corpus item: identity, content hash, source, chunking, provenance, extras. Rides the staging items.meta bag until the Atlas producer profile adopts it natively.", + "object": { + "schema_version": 1, + "fields": { + "identity": "sha256:1111111111111111111111111111111111111111111111111111111111111111", + "content_hash": "sha256:2222222222222222222222222222222222222222222222222222222222222222", + "source": "developing-today/code:pkgs/atlas-search/README.md@0123456789abcdef0123456789abcdef01234567", + "kind": "prose", + "sensitivity": "internal", + "chunking": { + "strategy": "boundary-safe", + "chunk_count": 3 + }, + "provenance": { + "producer": "atlas-stage", + "staged_at": "2026-11-21T00:00:00Z" + } + }, + "extras": {} + }, + "stage_row": { + "unit_id": "fixture-9095", + "kind": "prose", + "source": "developing-today/code:pkgs/atlas-search/README.md@0123456789abcdef0123456789abcdef01234567", + "sensitivity": "internal", + "text": "fixture body text", + "meta": "{\"extras\":{},\"fields\":{\"chunking\":{\"chunk_count\":3,\"strategy\":\"boundary-safe\"},\"content_hash\":\"sha256:2222222222222222222222222222222222222222222222222222222222222222\",\"identity\":\"sha256:1111111111111111111111111111111111111111111111111111111111111111\",\"kind\":\"prose\",\"provenance\":{\"producer\":\"atlas-stage\",\"staged_at\":\"2026-11-21T00:00:00Z\"},\"sensitivity\":\"internal\",\"source\":\"developing-today/code:pkgs/atlas-search/README.md@0123456789abcdef0123456789abcdef01234567\"},\"schema_version\":1}" + }, + "executable": true + }, + { + "id": "atlas-v1-embed-record", + "historical_source": "Per-embed record (issue scope: identity, content hash, source, chunking, embedder identity + model revision). The model named is the promotion-time embedder of record (atlas-stage book reference).", + "object": { + "schema_version": 1, + "fields": { + "item": "sha256:1111111111111111111111111111111111111111111111111111111111111111", + "content_hash": "sha256:2222222222222222222222222222222222222222222222222222222222222222", + "chunk": { + "index": 0, + "of": 3 + }, + "embedder": { + "id": "atlas-aggregator", + "model": "Snowflake/snowflake-arctic-embed-m-v2.0", + "model_revision": "v2.0" + }, + "dims": 1024, + "provenance": { + "embedded_at": "2026-11-21T00:00:00Z" + } + }, + "extras": {} + }, + "stage_row": { + "unit_id": "fixture-9095", + "kind": "prose", + "source": "developing-today/code:pkgs/atlas-search/README.md@0123456789abcdef0123456789abcdef01234567", + "sensitivity": "internal", + "text": "fixture body text", + "meta": "{\"extras\":{},\"fields\":{\"chunk\":{\"index\":0,\"of\":3},\"content_hash\":\"sha256:2222222222222222222222222222222222222222222222222222222222222222\",\"dims\":1024,\"embedder\":{\"id\":\"atlas-aggregator\",\"model\":\"Snowflake/snowflake-arctic-embed-m-v2.0\",\"model_revision\":\"v2.0\"},\"item\":\"sha256:1111111111111111111111111111111111111111111111111111111111111111\",\"provenance\":{\"embedded_at\":\"2026-11-21T00:00:00Z\"}},\"schema_version\":1}" + }, + "executable": true + }, + { + "id": "atlas-v1-classification-record", + "historical_source": "Classification record per workstream D: the strict core enums kind/area/group/sensitivity with a ladder sensitivity value (shareable < personal < local-only < secret-bearing).", + "object": { + "schema_version": 1, + "fields": { + "item": "sha256:1111111111111111111111111111111111111111111111111111111111111111", + "kind": "prose", + "area": "atlas", + "group": "ingest", + "sensitivity": "local-only", + "classifications": [ + { + "scheme": "workstream-d", + "label": "documentation" + } + ], + "provenance": { + "classifier": "atlas-classify", + "classified_at": "2026-11-21T00:00:00Z" + } + }, + "extras": {} + }, + "stage_row": { + "unit_id": "fixture-9095", + "kind": "prose", + "source": "developing-today/code:pkgs/atlas-search/README.md@0123456789abcdef0123456789abcdef01234567", + "sensitivity": "internal", + "text": "fixture body text", + "meta": "{\"extras\":{},\"fields\":{\"area\":\"atlas\",\"classifications\":[{\"label\":\"documentation\",\"scheme\":\"workstream-d\"}],\"group\":\"ingest\",\"item\":\"sha256:1111111111111111111111111111111111111111111111111111111111111111\",\"kind\":\"prose\",\"provenance\":{\"classified_at\":\"2026-11-21T00:00:00Z\",\"classifier\":\"atlas-classify\"},\"sensitivity\":\"local-only\"},\"schema_version\":1}" + }, + "executable": true + }, + { + "id": "atlas-v1-invalid-sensitivity", + "historical_source": "A typo'd sensitivity token from a producer ('secrit'). Doctrine rule 5 / design section 3.1: sensitivity is safety-critical and closed; an invalid value resolves to the most restrictive ladder value and the original is retained in extras for correction.", + "object": { + "schema_version": 1, + "fields": { + "kind": "prose", + "sensitivity": "secrit" + }, + "extras": {} + }, + "executable": false, + "doctrine_projection": { + "fields": { + "kind": "prose", + "sensitivity": "secret-bearing" + }, + "extras": { + "sensitivity": "secrit" + }, + "reason": "unknown-enum" + } + }, + { + "id": "atlas-v1-coercion", + "historical_source": "Type-directed handling (doctrine rule 4 / design section 3.2): an integer array offered to a string-array field converts losslessly; a string array that does not fully convert to an integer array relocates to extras unchanged. Partial conversion is forbidden.", + "object": { + "schema_version": 1, + "fields": { + "tags": [ + 1, + 2, + 3 + ], + "counts": [ + "10", + "x" + ] + }, + "extras": {} + }, + "executable": false, + "doctrine_projection": { + "fields": { + "tags": [ + "1", + "2", + "3" + ] + }, + "extras": { + "counts": [ + "10", + "x" + ] + }, + "reason": "unconvertible" + } + }, + { + "id": "atlas-v1-unknown-closed-enum", + "historical_source": "An unknown value in the closed kind enum. Doctrine rule 5 / design section 3.1: preserve the original in extras with its source path and report unclassified; never substitute a guessed category.", + "object": { + "schema_version": 1, + "fields": { + "kind": "hologram", + "sensitivity": "personal" + }, + "extras": {} + }, + "executable": false, + "doctrine_projection": { + "fields": { + "sensitivity": "personal" + }, + "extras": { + "kind": "hologram" + }, + "reason": "unknown-enum" + } + } + ] +} diff --git a/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/digest-vectors.json b/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/digest-vectors.json new file mode 100644 index 0000000000..54dbfba151 --- /dev/null +++ b/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/digest-vectors.json @@ -0,0 +1,18 @@ +{ + "fixture_set": "metadata-digest-vectors", + "issue": "developing-today/code#9095", + "rule": "MetadataArtifactId = \"sha256:\" + lowercase_hex(SHA-256(exact_metadata_bytes)) (design section 2). For a PM block, the exact bytes are the JSON object text between the pm-metadata markers with one opening fence line and its closing fence line removed and leading/trailing ASCII whitespace trimmed. For a metadata file, the exact bytes are the file bytes unchanged.", + "vectors": [ + { + "id": "pm-v1-canonical-block", + "body": "Issue text.\n\n\n```json\n{\n \"pm_meta\": 1,\n \"direct_parent\": null,\n \"links\": [],\n \"lineage\": {\n \"design\": null,\n \"roadmap_item\": null,\n \"priority\": null\n },\n \"provenance\": {},\n \"extras\": {}\n}\n```\n\n", + "extracted_bytes": "{\n \"pm_meta\": 1,\n \"direct_parent\": null,\n \"links\": [],\n \"lineage\": {\n \"design\": null,\n \"roadmap_item\": null,\n \"priority\": null\n },\n \"provenance\": {},\n \"extras\": {}\n}", + "artifact_id": "sha256:a07878cdef9194e25ff2e44bff15c347e06aa2774d0a062e7fc25101f7515c44" + }, + { + "id": "atlas-v1-item-envelope-file", + "file_bytes": "{\"extras\":{},\"fields\":{\"chunking\":{\"chunk_count\":3,\"strategy\":\"boundary-safe\"},\"content_hash\":\"sha256:2222222222222222222222222222222222222222222222222222222222222222\",\"identity\":\"sha256:1111111111111111111111111111111111111111111111111111111111111111\",\"kind\":\"prose\",\"provenance\":{\"producer\":\"atlas-stage\",\"staged_at\":\"2026-11-21T00:00:00Z\"},\"sensitivity\":\"internal\",\"source\":\"developing-today/code:pkgs/atlas-search/README.md@0123456789abcdef0123456789abcdef01234567\"},\"schema_version\":1}", + "artifact_id": "sha256:ba9fb0c1c49930908593c7917fe9a5dc26b3bd5d75092ae93ab76fb73923e078" + } + ] +} diff --git a/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/pm-metadata-v1.json b/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/pm-metadata-v1.json new file mode 100644 index 0000000000..ffe422c713 --- /dev/null +++ b/doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/pm-metadata-v1.json @@ -0,0 +1,116 @@ +{ + "fixture_set": "pm-metadata-version-conformance", + "issue": "developing-today/code#9095", + "surface": "pm", + "version_key": "pm_meta", + "current_version": 1, + "source_design": "doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/note.md", + "notes": "reader_parse / preserved_keys are the executable expectations asserted by the fleet crate conformance test (pkgs/fleet/crates/fleet/src/gh_metadata.rs). doctrine_projection, where present, is the recorded oracle for the projection behavior specified in design section 7 slice 2; it is not asserted against any current reader.", + "cases": [ + { + "id": "pm-v1-canonical", + "historical_source": "PM hierarchy design section 12 canonical form, restated in the schema v1 design section 2.", + "body": "Issue text.\n\n\n```json\n{\n \"pm_meta\": 1,\n \"direct_parent\": null,\n \"links\": [],\n \"lineage\": {\n \"design\": null,\n \"roadmap_item\": null,\n \"priority\": null\n },\n \"provenance\": {},\n \"extras\": {}\n}\n```\n\n", + "reader_parse": "ok", + "preserved_keys": [ + "pm_meta", + "direct_parent", + "links", + "lineage", + "provenance", + "extras" + ] + }, + { + "id": "pm-v1-legacy-links-only", + "historical_source": "Aggregator genealogy practice (pm-stack/aggregator/test/genealogy.test.ts): a links-only block written before extras/lineage injection existed. Absent extras reads as {} (design section 2); the reader must not synthesize and write it back.", + "body": "Issue text.\n\n\n```json\n{\"pm_meta\":1,\"links\":[{\"target\":{\"repo\":\"developing-today/code\",\"number\":99},\"relation\":\"parent\",\"status\":\"historical\",\"since\":\"2026-11-02\",\"until\":\"2026-11-12\",\"reason\":\"split\"},{\"target\":{\"repo\":\"developing-today/code\",\"number\":98},\"relation\":\"parent\",\"status\":\"removed\"}]}\n```\n\n", + "reader_parse": "ok", + "preserved_keys": [ + "pm_meta", + "links" + ] + }, + { + "id": "pm-v1-minimal-link", + "historical_source": "Aggregator epic-reparent practice (pm-stack/aggregator/test/epic-reparent.test.ts): a link carrying only relation and target; every other link field is optional.", + "body": "Issue text\n\n\n```json\n{\"pm_meta\":1,\"links\":[{\"relation\":\"blockedBy\",\"target\":{\"repo\":\"x/y\",\"number\":7}}]}\n```\n\n", + "reader_parse": "ok", + "preserved_keys": [ + "pm_meta", + "links" + ] + }, + { + "id": "pm-v1-float-version", + "historical_source": "Version written as the JSON number 1.0 by non-Rust producers; both current readers accept it as version 1.", + "body": "Issue text.\n\n\n```json\n{\n \"pm_meta\": 1.0,\n \"links\": []\n}\n```\n\n", + "reader_parse": "ok", + "preserved_keys": [ + "pm_meta", + "links" + ] + }, + { + "id": "pm-v1-unknown-keys", + "historical_source": "A v1 block carrying unlisted top-level keys written by a classifying agent. The current reader parses and preserves them verbatim.", + "body": "Issue text.\n\n\n```json\n{\n \"pm_meta\": 1,\n \"direct_parent\": null,\n \"links\": [],\n \"lineage\": {\n \"design\": null,\n \"roadmap_item\": null,\n \"priority\": null\n },\n \"provenance\": {},\n \"extras\": {},\n \"sprint\": \"2026-W47\",\n \"review\": {\"round\": 2, \"verdict\": \"accept\"}\n}\n```\n\n", + "reader_parse": "ok", + "preserved_keys": [ + "pm_meta", + "direct_parent", + "links", + "lineage", + "provenance", + "extras", + "sprint", + "review" + ], + "doctrine_projection": "The canonical PM form holds unknown keys in the extras object (design section 2). Relocation into extras is projection behavior (design section 7 slice 2), not a read error; until a projector lands, preservation in place is the conforming reader behavior." + }, + { + "id": "pm-v1-populated-extras", + "historical_source": "A v1 block whose extras dictionary already carries relocated/unlisted data; extras content is preserved byte-for-byte semantically (same JSON value) through parse and re-stamp.", + "body": "Issue text.\n\n\n```json\n{\n \"pm_meta\": 1,\n \"links\": [],\n \"extras\": {\n \"legacy_tool\": \"metadata-sweeper\",\n \"confidence\": 0.75\n }\n}\n```\n\n", + "reader_parse": "ok", + "preserved_keys": [ + "pm_meta", + "links", + "extras" + ] + }, + { + "id": "pm-v1-type-mismatch", + "historical_source": "Declared field links carrying an object instead of an array (a producer bug shape). The block parser gates on the version key only, so the block parses; the value is caller data, preserved as written by the stamp path.", + "body": "Issue text.\n\n\n```json\n{\n \"pm_meta\": 1,\n \"links\": {\"relation\": \"parent\", \"target\": {\"repo\": \"developing-today/code\", \"number\": 9060}}\n}\n```\n\n", + "reader_parse": "ok", + "preserved_keys": [ + "pm_meta", + "links" + ], + "doctrine_projection": "Type-directed handling (design section 3.2): the mismatched value relocates to extras unchanged, the declared links view defaults to [], and the mismatch is reported - never an error, never a silent coercion. Projection behavior is design section 7 slice 2; no current reader projects, so this case's executable expectation is parse-and-preserve only." + }, + { + "id": "pm-no-version", + "historical_source": "A fenced block without the version key is not a versioned Metadata object (doctrine rule 1: version always carried).", + "body": "Issue text.\n\n\n```json\n{\n \"links\": []\n}\n```\n\n", + "reader_parse": "reject", + "preserved_keys": [] + }, + { + "id": "pm-future-version", + "historical_source": "pm_meta 2 is newer than every published reader. Readers accept every prior version indefinitely; a version newer than the reader is refused fail-closed, never guessed at.", + "body": "Issue text.\n\n\n```json\n{\n \"pm_meta\": 2,\n \"links\": []\n}\n```\n\n", + "reader_parse": "reject", + "preserved_keys": [] + }, + { + "id": "pm-no-block", + "historical_source": "An ordinary issue body with no pm-metadata markers parses successfully with no block; absence of Metadata is not an error.", + "body": "Just an issue body, no metadata block.\n", + "reader_parse": "ok", + "block": "absent", + "preserved_keys": [] + } + ] +} diff --git a/pkgs/atlas-search/crates/atlas-core/tests/metadata_conformance.rs b/pkgs/atlas-search/crates/atlas-core/tests/metadata_conformance.rs new file mode 100644 index 0000000000..c430b75b62 --- /dev/null +++ b/pkgs/atlas-search/crates/atlas-core/tests/metadata_conformance.rs @@ -0,0 +1,106 @@ +//! Metadata version conformance fixtures for Atlas (issue #9095, +//! design `doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1`). +//! +//! Oracle: the hand-authored fixture set at +//! `doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/atlas-metadata-v1.json` +//! — every historical shape of Atlas item metadata, from the +//! unversioned `atlas_stage` v1 producer meta bag through the doctrine +//! v1 envelope. For each executable case this test inserts the case's +//! stage row into a freshly provisioned `atlas_stage` v1 database +//! (the staging design's write path is unmediated: the unit's owner +//! writes rows directly) and reads it back through the current reader, +//! `list_staged_items`. The stored `meta` must round-trip byte-exact — +//! old metadata remains valid and unrewritten under a newer system — +//! and the database schema version must be 1. +//! +//! Cases marked `executable: false` in the fixture carry a +//! `doctrine_projection` expectation (extras relocation, lossless-only +//! coercion, fail-closed sensitivity fallback). No current reader +//! projects; those cases are the recorded oracle for the design's §7 +//! slices 2 and 6 and are deliberately not asserted here. + +use std::path::PathBuf; + +use atlas_core::stage::{list_staged_items_in_db, provision_staging_db, schema_version}; +use rusqlite::Connection; +use serde_json::Value; + +fn fixture_set() -> Value { + let path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../../../doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/atlas-metadata-v1.json" + ); + let raw = std::fs::read_to_string(path) + .unwrap_or_else(|e| panic!("conformance fixture set unreadable at {path}: {e}")); + serde_json::from_str(&raw).expect("fixture set is valid JSON") +} + +fn temp_db(tag: &str) -> PathBuf { + let dir = std::env::temp_dir().join(format!( + "atlas-metadata-conformance-{}-{}-{tag}", + std::process::id(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos() + )); + std::fs::create_dir_all(&dir).unwrap(); + dir.join("stage.db") +} + +#[test] +fn atlas_metadata_version_conformance_fixtures() { + let set = fixture_set(); + let cases = set["cases"].as_array().expect("fixture set carries cases"); + assert!(!cases.is_empty(), "fixture set must not be empty"); + let mut executed = 0; + for case in cases { + let id = case["id"].as_str().expect("case id"); + if case["executable"].as_bool() != Some(true) { + continue; + } + executed += 1; + let row = &case["stage_row"]; + let db = temp_db(id); + provision_staging_db(&db).unwrap_or_else(|e| panic!("{id}: provision failed: {e}")); + + let conn = Connection::open(&db).unwrap(); + assert_eq!( + schema_version(&conn).unwrap(), + 1, + "{id}: staging schema version" + ); + conn.execute( + "INSERT INTO items (unit_id, kind, source, text, sensitivity, created_at, meta) \ + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)", + rusqlite::params![ + row["unit_id"].as_str().expect("unit_id"), + row["kind"].as_str().expect("kind"), + row["source"].as_str().expect("source"), + row["text"].as_str().expect("text"), + row["sensitivity"].as_str().expect("sensitivity"), + "2026-11-23T00:00:00Z", + row["meta"].as_str().expect("meta"), + ], + ) + .unwrap_or_else(|e| panic!("{id}: insert failed: {e}")); + drop(conn); + + let items = list_staged_items_in_db(&db, Some(row["unit_id"].as_str().unwrap())) + .unwrap_or_else(|e| panic!("{id}: readback failed: {e}")); + assert_eq!(items.len(), 1, "{id}: exactly one staged item"); + let meta = items[0].meta.as_deref().expect("meta present"); + assert_eq!( + meta, + row["meta"].as_str().unwrap(), + "{id}: meta must round-trip byte-exact, unrewritten" + ); + // And it must still parse as the fixture's object: usable, not + // merely stored. + let parsed: Value = serde_json::from_str(meta).unwrap(); + assert_eq!(parsed, case["object"], "{id}: meta parses to the fixture object"); + + let _ = std::fs::remove_dir_all(db.parent().unwrap()); + } + assert!(executed >= 4, "expected at least 4 executable cases, ran {executed}"); +} diff --git a/pkgs/fleet/crates/fleet/src/gh_metadata.rs b/pkgs/fleet/crates/fleet/src/gh_metadata.rs index 3e38d77cb1..de61bd6ee8 100644 --- a/pkgs/fleet/crates/fleet/src/gh_metadata.rs +++ b/pkgs/fleet/crates/fleet/src/gh_metadata.rs @@ -2433,4 +2433,85 @@ mod tests { _ => panic!("expected NoUrl"), } } + + // -- #9095 version conformance ------------------------------------ + // + // Oracle: the hand-authored fixture set at + // doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/ + // pm-metadata-v1.json — every historical shape of the pm_meta v1 + // block, with its recorded reader expectation. Each `ok` case must + // parse and preserve its declared keys through parse and through + // the stamp assembly round-trip; each `reject` case must fail + // closed. Doctrine-projection expectations in the fixture are the + // oracle for design §7 slice 2 and are not asserted here. + #[test] + fn pm_metadata_version_conformance_fixtures() { + let path = concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../../../doc/2026-11-21T17-56-24Z_design_atlas_metadata_schema_v1/fixtures/pm-metadata-v1.json" + ); + let raw = std::fs::read_to_string(path) + .unwrap_or_else(|e| panic!("conformance fixture set unreadable at {path}: {e}")); + let set: Value = serde_json::from_str(&raw).expect("fixture set is valid JSON"); + let cases = set["cases"].as_array().expect("fixture set carries cases"); + assert!(!cases.is_empty(), "fixture set must not be empty"); + for case in cases { + let id = case["id"].as_str().expect("case id"); + let body = case["body"].as_str().expect("case body"); + let parsed = parse_metadata_block(body); + match case["reader_parse"].as_str().expect("reader_parse") { + "reject" => { + assert!(parsed.is_err(), "{id}: expected fail-closed rejection"); + } + "ok" => { + let parsed = parsed + .unwrap_or_else(|e| panic!("{id}: expected parse success, got: {e}")); + if case["block"].as_str() == Some("absent") { + assert!(parsed.block.is_none(), "{id}: expected no block"); + continue; + } + let block = parsed.block.unwrap_or_else(|| panic!("{id}: expected a block")); + let keys = case["preserved_keys"] + .as_array() + .expect("preserved_keys") + .iter() + .map(|k| k.as_str().expect("key")) + .collect::>(); + for key in &keys { + assert!( + block.get(key).is_some(), + "{id}: key {key} lost at parse" + ); + } + // Stamp round-trip: re-stamping with the block's own + // provenance must preserve every preserved key's + // value exactly. + let provenance = block + .get("provenance") + .cloned() + .unwrap_or_else(|| json!({})); + let assembled = assemble_stamped_block(Some(&block), provenance); + for key in &keys { + // pm_meta is the one key assembly rewrites on + // purpose: it pins the integer current version + // (a float 1.0 input normalizes to 1). + if *key == "pm_meta" { + continue; + } + assert_eq!( + assembled.get(key), + block.get(key), + "{id}: key {key} changed by stamp assembly" + ); + } + assert_eq!( + assembled.get("pm_meta"), + Some(&json!(1)), + "{id}: stamp assembly must pin pm_meta to integer 1" + ); + } + other => panic!("{id}: unknown reader_parse expectation {other}"), + } + } + } }