From 504793d88c6b754f5181f48dc7abde073ff9146a Mon Sep 17 00:00:00 2001 From: Seongho Bae Date: Tue, 1 Sep 2026 07:29:09 +0000 Subject: [PATCH] feat(api): enumerate authorized exports via loopback collection GET GAP-003A unique slice stacked on export retrieval GET: loopback GET /v1/exports lists metric-free purpose-bound identities on AnalysisRunLiveService / tepp-loopback. LineageWeave refused. NaruonLiveService stays POST-only. ADR 0075. --- CHANGELOG.d/export-collection-get.md | 1 + DOCUMENTATION.md | 1 + crates/tepp_api/src/analysis_run_live.rs | 72 +++++-- crates/tepp_api/src/export_collection_http.rs | 204 ++++++++++++++++++ crates/tepp_api/src/lib.rs | 19 ++ .../tests/export_collection_http_contract.rs | 33 +++ docs/API_CONTRACT.md | 3 +- docs/TRACEABILITY.md | 2 +- docs/adr/0075-export-collection-get.md | 100 +++++++++ docs/adr/README.md | 1 + docs/connectors/naruon-artifact-consumer.md | 1 + docs/research/export-collection-http.md | 54 +++++ 12 files changed, 472 insertions(+), 19 deletions(-) create mode 100644 CHANGELOG.d/export-collection-get.md create mode 100644 crates/tepp_api/src/export_collection_http.rs create mode 100644 crates/tepp_api/tests/export_collection_http_contract.rs create mode 100644 docs/adr/0075-export-collection-get.md create mode 100644 docs/research/export-collection-http.md diff --git a/CHANGELOG.d/export-collection-get.md b/CHANGELOG.d/export-collection-get.md new file mode 100644 index 000000000..696b98f0a --- /dev/null +++ b/CHANGELOG.d/export-collection-get.md @@ -0,0 +1 @@ +- `tepp_api` loopback `GET /v1/exports` enumerates authorized purpose-bound export identities on `AnalysisRunLiveService` / `tepp-loopback` (ADR 0075). Metric-free receipts only. `tepp.scientific_acceptance.v1` never appears. Does not infer causality. LineageWeave refused. `NaruonLiveService` stays POST-only. Not export retrieval GET, not GAP-010 Figma/export, not persistence. diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 6fa4b9683..9eb2aa102 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -13,6 +13,7 @@ TEPP's approved PRD v0.4 and implementation plan are the primary product baselin | naruon modular consumer contract | [`docs/connectors/naruon-artifact-consumer.md`](docs/connectors/naruon-artifact-consumer.md) | | contextual-orchestrator interpretation port | [`docs/connectors/contextual-orchestrator-interpretation-port.md`](docs/connectors/contextual-orchestrator-interpretation-port.md) | | Orchestrator live HTTP doctoring | [`docs/research/orchestrator-live-http.md`](docs/research/orchestrator-live-http.md) | +| Export collection GET doctoring | [`docs/research/export-collection-http.md`](docs/research/export-collection-http.md) | | UML/runtime/scientific flows | [`docs/UML.md`](docs/UML.md) | | Logical/physical ERD | [`docs/ERD.md`](docs/ERD.md) | | Security policy | [`SECURITY.md`](SECURITY.md) | diff --git a/crates/tepp_api/src/analysis_run_live.rs b/crates/tepp_api/src/analysis_run_live.rs index a5f1f9f93..bb3ce1c82 100644 --- a/crates/tepp_api/src/analysis_run_live.rs +++ b/crates/tepp_api/src/analysis_run_live.rs @@ -3,7 +3,8 @@ //! This module keeps the Naruon compatibility listener intact while providing //! the shared `/v1/analysis-runs` and cutoff-safe `/v1/temporal-context` //! boundaries needed by Naruon and `LineageWeave`. Naruon may also POST and -//! GET `/v1/exports/{export_id}` for metric-free purpose-bound retrieval. +//! GET `/v1/exports/{export_id}` for metric-free purpose-bound retrieval and +//! `GET /v1/exports` to enumerate those identities. //! It accepts transport acknowledgements, temporal evidence context, and //! export identities only; completed psychometric results remain outside this //! crate. @@ -12,9 +13,13 @@ use std::collections::HashMap; use std::io::Write; use std::net::{SocketAddr, TcpListener}; +use crate::export_collection_http::{ + is_export_collection_path, page_export_collection_items, parse_export_collection_page_cursor, + parse_export_collection_page_limit, ExportCollection, +}; use crate::export_http::{export_retrieval_path_id, refuse_metrics_on_export_retrieval_payload}; use crate::lineageweave_http::{ - LINEAGEWEAVE_CONSUMER_CODE, NARUON_CONSUMER_CODE, consumer_is_supported, + consumer_is_supported, LINEAGEWEAVE_CONSUMER_CODE, NARUON_CONSUMER_CODE, }; use crate::live_http::{ header_value, map_io_error, parse_headers, parse_request_line, read_http_request_with_limit, @@ -22,12 +27,12 @@ use crate::live_http::{ }; use crate::naruon_http::{NARUON_ANALYSIS_RUN_PATH, NARUON_EXPORT_PATH}; use crate::{ - AnalysisRunAccepted, AnalysisRunRequest, AnalyticalPurpose, ApiError, - DEFAULT_PROJECT_HISTORY_BYTE_LIMIT, ErrorEnvelope, ExportAuthorizationRequest, ExportRetrieval, - NARUON_LIVE_IO_TIMEOUT, NaruonLiveResponse, PROJECT_HISTORY_PATH, ProjectHistoryProjection, - ProjectHistoryRequest, TEMPORAL_CONTEXT_PATH, TemporalContextRequest, authorize_export, - build_temporal_context, project_history_projection, requests_are_idempotent_matches, - require_export_allowed, + authorize_export, build_temporal_context, project_history_projection, + requests_are_idempotent_matches, require_export_allowed, AnalysisRunAccepted, + AnalysisRunRequest, AnalyticalPurpose, ApiError, ErrorEnvelope, ExportAuthorizationRequest, + ExportRetrieval, NaruonLiveResponse, ProjectHistoryProjection, ProjectHistoryRequest, + TemporalContextRequest, DEFAULT_PROJECT_HISTORY_BYTE_LIMIT, NARUON_LIVE_IO_TIMEOUT, + PROJECT_HISTORY_PATH, TEMPORAL_CONTEXT_PATH, }; const MAX_LIVE_REQUEST_BODY_BYTES: usize = DEFAULT_PROJECT_HISTORY_BYTE_LIMIT; @@ -162,6 +167,9 @@ impl AnalysisRunLiveService { let (method, path) = parse_request_line(lines.next().unwrap_or(""))?; let headers = parse_headers(&mut lines)?; if method == "GET" { + if is_export_collection_path(path) { + return self.list_exports(&headers, body); + } if matches!( export_retrieval_path_id(path), Ok(_) | Err(ApiError::LimitExceeded) @@ -342,6 +350,37 @@ impl AnalysisRunLiveService { Ok(json_response(200, "OK", response_body)) } + fn list_exports( + &self, + headers: &HashMap, + body: &str, + ) -> Result { + if !body.trim().is_empty() { + return Err(ApiError::InvalidWirePayload); + } + refuse_metrics_on_export_retrieval_payload(body)?; + let consumer = require_headers(headers, self.bound_addr, false)?; + if consumer != NARUON_CONSUMER_CODE { + return Err(ApiError::InvalidWirePayload); + } + if headers.contains_key("idempotency-key") { + return Err(ApiError::InvalidWirePayload); + } + let limit = + parse_export_collection_page_limit(headers.get("tepp-page-limit").map(String::as_str))?; + let cursor = parse_export_collection_page_cursor( + headers.get("tepp-page-cursor").map(String::as_str), + )?; + let items = self + .authorized_exports + .values() + .map(|stored| stored.retrieval.clone()) + .collect(); + let (page, next_cursor) = page_export_collection_items(items, cursor.as_deref(), limit); + let collection = ExportCollection::new(page, next_cursor)?; + Ok(json_response(200, "OK", collection.to_json()?)) + } + fn response_from_error(&mut self, error: ApiError) -> NaruonLiveResponse { let request_id = format!("analysis-run-live-{}", self.next_request_serial); self.next_request_serial += 1; @@ -417,17 +456,16 @@ mod tests { use std::time::Duration; use super::{ - AnalysisRunLiveService, consumer_tenant_idempotency_key, declared_content_length, - error_envelope_json, host_implies_table_access, map_io_error, parse_headers, - require_headers, split_header_line, status_for, + consumer_tenant_idempotency_key, declared_content_length, error_envelope_json, + host_implies_table_access, map_io_error, parse_headers, require_headers, split_header_line, + status_for, AnalysisRunLiveService, }; use crate::live_http::{host_is_loopback, read_http_request, split_request}; use crate::{ - ANALYSIS_RUN_CONTRACT_VERSION, AnalysisRunRequest, ApiError, - DEFAULT_ANALYSIS_RUN_BYTE_LIMIT, ErrorEnvelope, LINEAGEWEAVE_CONSUMER_CODE, - NARUON_ANALYSIS_RUN_PATH, NARUON_CONSUMER_CODE, NARUON_EXPORT_PATH, - NARUON_LIVE_HEADER_BYTE_LIMIT, NARUON_LIVE_HEADER_COUNT_LIMIT, NARUON_LIVE_IO_TIMEOUT, - TEMPORAL_CONTEXT_PATH, + AnalysisRunRequest, ApiError, ErrorEnvelope, ANALYSIS_RUN_CONTRACT_VERSION, + DEFAULT_ANALYSIS_RUN_BYTE_LIMIT, LINEAGEWEAVE_CONSUMER_CODE, NARUON_ANALYSIS_RUN_PATH, + NARUON_CONSUMER_CODE, NARUON_EXPORT_PATH, NARUON_LIVE_HEADER_BYTE_LIMIT, + NARUON_LIVE_HEADER_COUNT_LIMIT, NARUON_LIVE_IO_TIMEOUT, TEMPORAL_CONTEXT_PATH, }; fn sample_run() -> AnalysisRunRequest { @@ -1135,7 +1173,7 @@ mod tests { "GET {NARUON_EXPORT_PATH} HTTP/1.1\r\nHost: 127.0.0.1\r\ncontent-type: application/json\r\ntepp-consumer: naruon\r\ntepp-contract-version: 1\r\ncontent-length: 0\r\n\r\n" )) .status_code, - 400 + 200 ); assert_eq!( service diff --git a/crates/tepp_api/src/export_collection_http.rs b/crates/tepp_api/src/export_collection_http.rs new file mode 100644 index 000000000..425165448 --- /dev/null +++ b/crates/tepp_api/src/export_collection_http.rs @@ -0,0 +1,204 @@ +//! Provider-owned export collection GET contracts. +//! +//! GAP-003A unique slice: `GET /v1/exports` enumerates metric-free identities +//! of purpose-bound exports that `AnalysisRunLiveService` / `tepp-loopback` +//! already authorized. Operators do not guess `export_id` values. This module +//! does not duplicate export retrieval GET (#411), export-retrieval CLI +//! (#417), export-authorize CLI (#410), interpretation-run collection GET +//! (#433), project-history collection GET (#424), GET-by-id (#359), Leiden, +//! or GAP-010 Figma/export. Persistence remains GAP-003B. `LineageWeave` is +//! refused. `NaruonLiveService` stays POST-only. + +use serde::{Deserialize, Serialize}; + +use crate::export_http::{ + refuse_metrics_on_export_retrieval_payload, ExportRetrieval, EXPORT_RETRIEVAL_ID_MAX_LEN, +}; +use crate::naruon_http::{compose_https_target, NaruonHttpExchange, NARUON_EXPORT_PATH}; +use crate::wire::{require_byte_limit, require_nonempty, to_json}; +use crate::{ApiError, DEFAULT_ANALYSIS_RUN_BYTE_LIMIT}; + +/// Default page size for export collection GET. +pub const EXPORT_COLLECTION_DEFAULT_LIMIT: usize = 32; +/// Maximum page size for export collection GET. +pub const EXPORT_COLLECTION_MAX_LIMIT: usize = 64; +/// Maximum opaque cursor length on export collection GET. +pub const EXPORT_COLLECTION_CURSOR_MAX_LEN: usize = EXPORT_RETRIEVAL_ID_MAX_LEN; + +/// Metric-free export collection page. +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct ExportCollection { + /// Metric-free authorized export identities on this page. + pub items: Vec, + /// Exclusive `export_id` cursor for the next page, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_cursor: Option, +} + +impl ExportCollection { + /// Construct a validated collection page. + /// + /// # Errors + /// + /// Returns a fail-closed error for oversized pages or hostile cursors. + pub fn new(items: Vec, next_cursor: Option) -> Result { + if items.len() > EXPORT_COLLECTION_MAX_LIMIT { + return Err(ApiError::LimitExceeded); + } + if let Some(cursor) = next_cursor.as_deref() { + require_nonempty(cursor)?; + if cursor.len() > EXPORT_COLLECTION_CURSOR_MAX_LEN { + return Err(ApiError::LimitExceeded); + } + if cursor.contains('/') || cursor.contains('\0') { + return Err(ApiError::InvalidWirePayload); + } + } + let collection = Self { items, next_cursor }; + let payload = to_json(&collection)?; + require_byte_limit(&payload, DEFAULT_ANALYSIS_RUN_BYTE_LIMIT)?; + refuse_metrics_on_export_retrieval_payload(&payload)?; + Ok(collection) + } + + /// Serialize this collection after metric refusal. + /// + /// # Errors + /// + /// Returns a validation or metric-key error. + pub fn to_json(&self) -> Result { + let payload = to_json(self)?; + require_byte_limit(&payload, DEFAULT_ANALYSIS_RUN_BYTE_LIMIT)?; + refuse_metrics_on_export_retrieval_payload(&payload)?; + Ok(payload) + } +} + +/// Whether a path is the export collection resource. +#[must_use] +pub fn is_export_collection_path(path: &str) -> bool { + path == NARUON_EXPORT_PATH +} + +/// Parse the optional `tepp-page-limit` header. +/// +/// # Errors +/// +/// Returns [`ApiError::InvalidWirePayload`] for a non-integer and +/// [`ApiError::LimitExceeded`] when above [`EXPORT_COLLECTION_MAX_LIMIT`]. +pub fn parse_export_collection_page_limit(raw: Option<&str>) -> Result { + let Some(raw) = raw else { + return Ok(EXPORT_COLLECTION_DEFAULT_LIMIT); + }; + require_nonempty(raw)?; + let limit: usize = raw.parse().map_err(|_| ApiError::InvalidWirePayload)?; + if limit == 0 { + return Err(ApiError::InvalidWirePayload); + } + if limit > EXPORT_COLLECTION_MAX_LIMIT { + return Err(ApiError::LimitExceeded); + } + Ok(limit) +} + +/// Parse the optional exclusive `tepp-page-cursor` header. +/// +/// # Errors +/// +/// Returns a fail-closed error for empty, slash, NUL, or oversized cursors. +pub fn parse_export_collection_page_cursor(raw: Option<&str>) -> Result, ApiError> { + let Some(raw) = raw else { + return Ok(None); + }; + require_nonempty(raw)?; + if raw.contains('/') || raw.contains('\0') { + return Err(ApiError::InvalidWirePayload); + } + if raw.len() > EXPORT_COLLECTION_CURSOR_MAX_LEN { + return Err(ApiError::LimitExceeded); + } + Ok(Some(raw.to_owned())) +} + +/// Page stored collection rows with an exclusive `export_id` cursor. +#[must_use] +pub fn page_export_collection_items( + mut items: Vec, + cursor: Option<&str>, + limit: usize, +) -> (Vec, Option) { + items.sort_by(|left, right| left.export_id.cmp(&right.export_id)); + let start = cursor.map_or(0, |cursor| { + items + .iter() + .position(|item| item.export_id.as_str() > cursor) + .unwrap_or(items.len()) + }); + let end = (start + limit).min(items.len()); + let next_cursor = (end < items.len()).then(|| items[end - 1].export_id.clone()); + (items[start..end].to_vec(), next_cursor) +} + +/// Build a credential-free naruon collection GET exchange. +/// +/// # Errors +/// +/// Returns a fail-closed origin error. +pub fn naruon_export_collection_exchange(origin: &str) -> Result { + let target_url = compose_https_target(origin, NARUON_EXPORT_PATH)?; + Ok(NaruonHttpExchange { + method: "GET", + target_url, + headers: vec![ + ("content-type".into(), "application/json".into()), + ("tepp-consumer".into(), "naruon".into()), + ("tepp-contract-version".into(), "1".into()), + ], + body: String::new(), + }) +} + +#[cfg(test)] +mod tests { + use super::{ + is_export_collection_path, naruon_export_collection_exchange, + parse_export_collection_page_cursor, parse_export_collection_page_limit, + EXPORT_COLLECTION_MAX_LIMIT, + }; + use crate::naruon_http::NARUON_EXPORT_PATH; + use crate::ApiError; + + #[test] + fn collection_exchange_is_metric_free_get_without_credentials() { + assert!(is_export_collection_path(NARUON_EXPORT_PATH)); + assert!(!is_export_collection_path("/v1/exports/export-1")); + let exchange = + naruon_export_collection_exchange("https://tepp.example.test").expect("exchange"); + assert_eq!(exchange.method, "GET"); + assert!(exchange.target_url.ends_with("/v1/exports")); + assert!(exchange.body.is_empty()); + assert!(!exchange + .headers + .iter() + .any(|(name, _)| name.eq_ignore_ascii_case("authorization") + || name.eq_ignore_ascii_case("idempotency-key"))); + assert_eq!( + naruon_export_collection_exchange("http://tepp.example.test"), + Err(ApiError::InvalidWirePayload) + ); + assert_eq!( + parse_export_collection_page_limit(None).expect("default"), + 32 + ); + assert_eq!( + parse_export_collection_page_limit(Some("99")), + Err(ApiError::LimitExceeded) + ); + assert_eq!( + parse_export_collection_page_cursor(Some("a/b")), + Err(ApiError::InvalidWirePayload) + ); + assert_eq!(EXPORT_COLLECTION_MAX_LIMIT, 64); + } +} diff --git a/crates/tepp_api/src/lib.rs b/crates/tepp_api/src/lib.rs index bd8a933e0..da946cef1 100644 --- a/crates/tepp_api/src/lib.rs +++ b/crates/tepp_api/src/lib.rs @@ -20,6 +20,7 @@ mod corpus_split_manifest; mod envelope; mod error; mod export; +mod export_collection_http; mod export_http; mod lineage_criterion_anchor; mod lineage_pair_criterion; @@ -104,6 +105,24 @@ pub use export_http::EXPORT_RETRIEVAL_ID_MAX_LEN; pub use export_http::ExportRetrieval; /// Build a naruon export-retrieval GET exchange. pub use export_http::naruon_export_retrieval_exchange; +/// Build a credential-free naruon export collection GET exchange. +pub use export_collection_http::naruon_export_collection_exchange; +/// Whether a path is the export collection resource. +pub use export_collection_http::is_export_collection_path; +/// Page stored export collection rows with an exclusive export-id cursor. +pub use export_collection_http::page_export_collection_items; +/// Parse the optional exclusive `tepp-page-cursor` header. +pub use export_collection_http::parse_export_collection_page_cursor; +/// Parse the optional `tepp-page-limit` header. +pub use export_collection_http::parse_export_collection_page_limit; +/// Metric-free export collection page. +pub use export_collection_http::ExportCollection; +/// Maximum opaque cursor length on export collection GET. +pub use export_collection_http::EXPORT_COLLECTION_CURSOR_MAX_LEN; +/// Default page size for export collection GET. +pub use export_collection_http::EXPORT_COLLECTION_DEFAULT_LIMIT; +/// Maximum page size for export collection GET. +pub use export_collection_http::EXPORT_COLLECTION_MAX_LIMIT; /// Refuse scientific-metric keys on export-retrieval JSON. pub use export_http::refuse_metrics_on_export_retrieval_payload; diff --git a/crates/tepp_api/tests/export_collection_http_contract.rs b/crates/tepp_api/tests/export_collection_http_contract.rs new file mode 100644 index 000000000..6044fdd88 --- /dev/null +++ b/crates/tepp_api/tests/export_collection_http_contract.rs @@ -0,0 +1,33 @@ +//! Contract tests for naruon export collection GET. + +use tepp_api::{ + is_export_collection_path, naruon_export_collection_exchange, ApiError, NARUON_CONSUMER_CODE, +}; + +#[test] +fn export_collection_is_metric_free_get_without_credentials() { + let exchange = + naruon_export_collection_exchange("https://tepp.example.test").expect("exchange"); + assert_eq!(exchange.method, "GET"); + assert!(exchange.target_url.ends_with("/v1/exports")); + assert!(exchange.body.is_empty()); + assert!(exchange + .headers + .iter() + .any(|(name, value)| name == "tepp-consumer" && value == NARUON_CONSUMER_CODE)); + assert!(!exchange + .headers + .iter() + .any(|(name, _)| name.eq_ignore_ascii_case("authorization") + || name.eq_ignore_ascii_case("idempotency-key"))); + assert!(is_export_collection_path("/v1/exports")); + assert!(!is_export_collection_path("/v1/exports/export-1")); +} + +#[test] +fn export_collection_refuses_insecure_origins() { + assert_eq!( + naruon_export_collection_exchange("http://tepp.example.test"), + Err(ApiError::InvalidWirePayload) + ); +} diff --git a/docs/API_CONTRACT.md b/docs/API_CONTRACT.md index 1142e99fe..04c0bbb69 100644 --- a/docs/API_CONTRACT.md +++ b/docs/API_CONTRACT.md @@ -8,7 +8,7 @@ TEPP must work both as a standalone product and as a modular CWL component. Integrations with `naruon`, `contextual-orchestrator`, `.github`, or other repositories use explicit versioned API/artifact contracts. Cross-service direct table access is prohibited. -Current protected main exposes Rust library/domain contracts. The active stack adds a loopback HTTP/1.1 listener for naruon analysis-run, LineageWeave temporal-context, and export POSTs, including `POST /v1/project-histories` on the `AnalysisRunLiveService` contract boundary. `tepp-loopback` runs the shared consumer listener on `127.0.0.1:18081` by default; a caller may pass another loopback socket address and an optional maximum request count as its two arguments. The container is intended for a trusted same-host or shared-network-namespace sidecar, checks readiness through a synthetic bounded temporal-context request, and deliberately cannot bind a public or bridge address. It is not a production TLS/`$PORT` service. Endpoint examples below that are not covered by `NaruonLiveService` or `AnalysisRunLiveService` remain target interface shapes. Loopback `GET /v1/exports/{export_id}` on `AnalysisRunLiveService` is the executable export-retrieval route (ADR 0054); `NaruonLiveService` stays POST-only. +Current protected main exposes Rust library/domain contracts. The active stack adds a loopback HTTP/1.1 listener for naruon analysis-run, LineageWeave temporal-context, and export POSTs, including `POST /v1/project-histories` on the `AnalysisRunLiveService` contract boundary. `tepp-loopback` runs the shared consumer listener on `127.0.0.1:18081` by default; a caller may pass another loopback socket address and an optional maximum request count as its two arguments. The container is intended for a trusted same-host or shared-network-namespace sidecar, checks readiness through a synthetic bounded temporal-context request, and deliberately cannot bind a public or bridge address. It is not a production TLS/`$PORT` service. Endpoint examples below that are not covered by `NaruonLiveService` or `AnalysisRunLiveService` remain target interface shapes. Loopback `GET /v1/exports/{export_id}` on `AnalysisRunLiveService` is the executable export-retrieval route (ADR 0054); `GET /v1/exports` enumerates those identities (ADR 0075); `NaruonLiveService` stays POST-only. ## 2. Contract families @@ -68,6 +68,7 @@ POST /v1/temporal-context GET /v1/analysis-runs/{run_id} POST /v1/analysis-runs/{run_id}/cancel GET /v1/model-artifacts/{artifact_id} +GET /v1/exports GET /v1/exports/{export_id} ``` diff --git a/docs/TRACEABILITY.md b/docs/TRACEABILITY.md index 20d4b7f01..2bef6941c 100644 --- a/docs/TRACEABILITY.md +++ b/docs/TRACEABILITY.md @@ -52,7 +52,7 @@ The full APA 7th standards/literature register remains `docs/research/standards- | recovery metrics (RMSE, bias, coverage, graph, temporal order, Monte Carlo SE gates) | PRD; Test Strategy; ADR 0007/0014 | `validation_core` on protected main (PR #19); SE-aware Monte Carlo gates included | implemented-main | | PostgreSQL bitemporal/lineage persistence | ADR 0013; Architecture/ERD | `persistence_postgres` migration contracts, in-memory adapters, live SQL session/document SQL port, tenant RLS (`0002` + session GUC/role helpers), `DATABASE_URL` SQLx gate, optional session-affine `live-sqlx` `PgPool` driver, exact-head live PostgreSQL CI with isolation proof, append-only immutability triggers (`0004`), temporal interval ordering CHECKs (`0005`), typed membership assignment (`0006` implemented-main), event-relation/mention/instance SQL (#37–#39 implemented-main), source-artifact SQL (#40 implemented-main), audit-event SQL (#41 implemented-main), concurrent document-write stress (#43 implemented-main), backup/restore integrity revalidation (#44 implemented-main), `revision_order` later-revision system-time ordering implemented-main, entity/project target SQL on PR #131; remaining physical ERD constraints | partial | | known-truth temporal/event simulation manifests | PRD; TRD; Test Strategy | `tepp_simulation` on protected main; recovery metrics in `validation_core` | implemented-main | -| versioned service/API contracts and exports | PRD; API contract; ADR 0011/0013/0054 | `tepp_api` analysis-run/export/JSON-LD/GraphML contracts on protected main (PR #21); loopback `GET /v1/exports/{export_id}` is the executable retrieval route on this PR; request-bound terminal result active in PR #157; production TLS remaining | partial | +| versioned service/API contracts and exports | PRD; API contract; ADR 0011/0013/0054/0075 | `tepp_api` analysis-run/export/JSON-LD/GraphML contracts on protected main (PR #21); loopback `GET /v1/exports/{export_id}` is the executable retrieval route; loopback `GET /v1/exports` enumerates authorized identities on this PR; request-bound terminal result active in PR #157; production TLS remaining | partial | | executable cutoff-safe analysis-run readiness | ADR 0021; temporal research; API terminal-result contract | stacked `analysis_engine` PR on #157: availability cutoff, snapshot binding, multiple-membership aggregation, digest-bound artifact, realistic end-to-end tests | active-PR | | delayed-reporting cutoff eligibility in truth corpora | ADR 0002; research | `tepp_simulation` eligible-at-cutoff filter on the active PR | active-PR | | versioned service/API contracts and exports | PRD; API contract; ADR 0011/0013 | `tepp_api` analysis-run/export/JSON-LD/GraphML contracts on protected main (PR #21); HTTP service remaining accepted-target | partial | diff --git a/docs/adr/0075-export-collection-get.md b/docs/adr/0075-export-collection-get.md new file mode 100644 index 000000000..321a68560 --- /dev/null +++ b/docs/adr/0075-export-collection-get.md @@ -0,0 +1,100 @@ +# ADR 0075 — Loopback export collection GET + +**Decision status:** Accepted +**Implementation maturity:** active-PR +**Date:** 2026-09-01 +**Supersedes:** None; complements ADR 0054 for enumerating authorized export identities. Does not supersede ADR 0014 claim-promotion authority. This ADR number is unique versus protected main; live vs-main and sibling GAP-003A PRs already occupy 0026–0074. + +## Context + +ADR 0054 retrieves one authorized export by `export_id`. Operators who hold a +200 authorization receipt still had no loopback path to enumerate minted +identities without guessing UUIDs. Duplicating export retrieval GET (#411), +export-retrieval CLI (#417), export-authorize CLI (#410), interpretation-run +collection GET (#433), project-history collection GET (#424), Leiden, Driver +p.16, or GAP-010 Figma/export would collide with live PRs. LineageWeave is +refused on this naruon-owned adapter; `NaruonLiveService` stays POST-only. + +## Decision + +`AnalysisRunLiveService` publishes loopback-only `GET /v1/exports` on +`tepp-loopback`: + +- Consumer is `naruon` only. Empty body. Identity does not travel in a header. + `idempotency-key` is refused. +- Extra path segments fail closed as GET-by-id parsing, not as collection. +- Pagination uses `tepp-page-limit` (default 32, max 64) and exclusive + `tepp-page-cursor` on `export_id`. +- Each row is the same metric-free `ExportRetrieval` identity as ADR 0054: + `export_id`, `artifact_id`, `decision_code=purpose_bound_export_allowed`, + `purpose`, `idempotency_key`. Tenant, principal, source text, RMSE, bias, + coverage, SE-gate, and `tepp.scientific_acceptance.v1` never appear. +- Collection does not infer causality, persist, or return a completed + psychometric result. +- This slice does not implement a collection CLI. + +## Alternatives considered + +1. **Keep GET-by-id without a collection** — rejected; operators still guess + UUID v7 identities after ADR 0054. +2. **Reuse interpretation-run collection GET (#433)** — rejected; that is a + different live resource and a contextual-orchestrator consumer. +3. **Add GET collection to `NaruonLiveService`** — rejected; that listener + stays POST-only. +4. **Loopback `GET /v1/exports`** — accepted. + +## Consequences + +- Operators can enumerate authorized export identities without guessing + `export_id`. +- Collection JSON cannot be mistaken for a succeeded scientific-acceptance + result or a causal score. +- Collection success is not release evidence and is not an ADR 0014 claim. + +## Failure and recovery + +Non-`naruon` consumers, nonempty GET bodies, present `idempotency-key`, extra +path segments, slash/NUL cursors, credential flags, and metric keys fail +closed. The in-memory listener is not durable. + +## Security, privacy, scientific-integrity, and governance impact + +- No credential headers cross the consumer boundary. +- Tenant, principal, and source text stay off the collection page. +- HTTP 200 on collection is not measurement evidence and is not a causal + claim. + +## Compatibility and migration + +GET-by-id, POST `/v1/exports` on `AnalysisRunLiveService`, and +`NaruonLiveService` POST-only remain unchanged. A collection CLI remains a +later slice. Persistence remains GAP-003B. + +## Verification + +Falsifiable evidence: + +- GET collection of authorized exports returns metric-free identities without + RMSE/bias/coverage/SE-gate/tenant/principal/source-text/ + `tepp.scientific_acceptance.v1` keys; +- LineageWeave, nonempty body, present `idempotency-key`, extra segments, and + unknown keys fail closed; +- `NaruonLiveService` still refuses GET; +- Clippy `-D warnings`, `tepp_api` tests, rustdoc, and exact-head review + remain required. + +## Rollback and supersession + +Rollback removes collection GET; GET-by-id and POST remain valid. A +superseding ADR is required to persist the collection, bind a public address, +emit scientific-acceptance on collection, open LineageWeave, add GET to +`NaruonLiveService`, or treat collection success as an ADR 0014 claim. + +## Related authority + +- ADR 0054 owns loopback export retrieval GET. +- ADR 0055 owns the export-retrieval CLI (live #417). +- ADR 0026 owns the export-authorize CLI (live #410). +- ADR 0014 owns scientific claim promotion. +- RFC 9110 owns GET semantics (Fielding, Nottingham, & Reschke, 2022). It + does not authorize scientific claims. diff --git a/docs/adr/README.md b/docs/adr/README.md index 5e43e54fb..9153090dc 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -31,6 +31,7 @@ Read [`ADR_POLICY.md`](ADR_POLICY.md) first. **Decision status and implementatio | [0024](0024-lineage-pair-criterion-and-project-journey-posterior.md) | Independent Event Lineage pair criterion and posterior Project Journey | Proposed | active-PR | Strict artifacts preserve criterion/event-time draws, branches, ties, and CPU/GPU receipts without claiming the scientific estimator is complete. | | [0025](0025-macos-native-rust-mlx-metal-boundary.md) | macOS-native Rust-owned MLX Metal execution | Accepted | accepted-target | Compose authenticates to a native host service; Linux never claims Metal, and actual backend/parity receipts fail closed. | | [0054](0054-export-retrieval-get.md) | Loopback export retrieval GET | Accepted | active-PR | `AnalysisRunLiveService` mints a metric-free `export_id` on naruon `POST /v1/exports` and serves `GET /v1/exports/{export_id}`; `NaruonLiveService` stays POST-only. | +| [0075](0075-export-collection-get.md) | Loopback export collection GET | Accepted | active-PR | Complements ADR 0054; `GET /v1/exports` enumerates metric-free authorized identities. Unique versus protected main (0026–0074 occupied). `NaruonLiveService` stays POST-only. | | [0023](0023-lineage-criterion-anchor-contract.md) | TEPP-owned Event Lineage criterion anchor | Accepted | active-PR | PR #237 publishes the strict accepted/rejected artifact and identities; estimator execution remains fail-closed future work. | | [0024](0024-independent-topic-importance-anchor.md) | Posterior topic-context producer contract | Accepted | contract-only active-PR | Strict DTO/schema only; the current estimator does not emit it. fast-mlsirm owns case-deletion influence. | | [0001](0001-rust-first-modular-msa.md) | Rust-first numerical core and CPU `f64` reference | Accepted | partial | ADR 0011 owns cross-service/MSA authority; 0001 retains numerical/backend authority. | diff --git a/docs/connectors/naruon-artifact-consumer.md b/docs/connectors/naruon-artifact-consumer.md index f9f356c6d..90bea97d9 100644 --- a/docs/connectors/naruon-artifact-consumer.md +++ b/docs/connectors/naruon-artifact-consumer.md @@ -29,6 +29,7 @@ TEPP remains the scientific authority for estimation, recovery metrics, temporal | HTTP export authorize | `tepp_api` `naruon_export_exchange` → `POST /v1/exports` | naruon → TEPP | | Live loopback POST | `tepp_api` `NaruonLiveService` → `POST /v1/analysis-runs` and `/v1/exports` | naruon → TEPP | | Live loopback export retrieval | `tepp_api` `AnalysisRunLiveService` → `POST /v1/exports` then `GET /v1/exports/{export_id}` | naruon → TEPP | +| Live loopback export collection | `tepp_api` `AnalysisRunLiveService` → `GET /v1/exports` | naruon → TEPP | Committed examples live under `examples/`. Schemas for analysis-run requests and corpus-split manifests live under `schemas/`. diff --git a/docs/research/export-collection-http.md b/docs/research/export-collection-http.md new file mode 100644 index 000000000..c05f823d3 --- /dev/null +++ b/docs/research/export-collection-http.md @@ -0,0 +1,54 @@ +# Export collection GET (doctoring) + +## Scope + +`GET /v1/exports` is the operator-visible enumeration of authorized +purpose-bound export identities on `AnalysisRunLiveService` / +`tepp-loopback`. HTTP method, path, and header semantics follow current HTTP +semantics (Fielding, Nottingham, & Reschke, 2022). Fail-closed refusal of +unpublished consumers, nonempty GET bodies, present `idempotency-key`, extra +path segments, review/Copilot/GitHub credential flags, and +scientific-authority promotion is repository contract authority (ADR 0075; +ADR 0054; ADR 0014), not an RFC inference rule. + +Collection JSON is metric-free. Tenant, principal, source text, and +`tepp.scientific_acceptance.v1` never appear. HTTP 200 is not a completed +psychometric result, calibrated score, theta estimate, uncertainty statement, +causal inference, or scientific claim. + +## Authority + +### External standards (HTTP only) + +Fielding, R., Nottingham, M., & Reschke, J. (Eds.). (2022). *HTTP semantics* +(RFC 9110). IETF. https://doi.org/10.17487/RFC9110 + +RFC 9110 §9.3.1 describes GET as a method for retrieving a current +representation of the target resource. TEPP maps that retrieval onto a +bounded, in-memory page of metric-free export identities. The RFC does not +define psychometric acceptance, RMSE, causality, or claim promotion. + +### Internal contract evidence + +- `docs/adr/0075-export-collection-get.md` — this collection +- `docs/adr/0054-export-retrieval-get.md` — GET-by-id +- `docs/adr/0014-scientific-claim-promotion-and-release-evidence.md` — HTTP + 200 is not a scientific claim +- `crates/tepp_api/tests/export_collection_http_contract.rs` — fail-closed + collection proofs + +## Verification + +- `GET /v1/exports` of authorized naruon exports returns metric-free + identities without RMSE/bias/coverage/SE-gate keys, tenant, principal, + source text, or `tepp.scientific_acceptance.v1`; +- LineageWeave, nonempty body, present `idempotency-key`, extra path + segments, slash/NUL cursors fail closed; +- `NaruonLiveService` still refuses GET. + +## Non-claims + +This slice does not implement a collection CLI, GAP-010 Figma/export, +analysis-run collection GET, interpretation-run collection GET, persistence, +production TLS, Leiden consensus, provider execution, causal inference, or an +ADR 0014 scientific claim-promotion package.