feat(import): complete OpenAPI onboarding and verify delivery
CI / Rust Checks (pull_request) Failing after 1s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped

This commit is contained in:
bsodfather committed 2026-10-09 17:50:38 +03:00
1 parent bb3e376767
commit e93de7015a
244 files changed
+57020 -5139

No files matched your search

@@ -0,0 +1,166 @@
use super::*;
/// A server-authored, immutable OpenAPI import plan.
///
/// The `digest` is not supplied by callers: the registry derives it from the
/// deterministic byte encoding of `payload` at creation time, so a replay can
/// be recognized as byte-identical material versus a changed conflict.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ImportPlan {
pub id: ImportPlanId,
pub workspace_id: WorkspaceId,
pub job_id: ImportJobId,
pub digest: String,
pub payload: Value,
#[serde(with = "time::serde::rfc3339")]
pub created_at: OffsetDateTime,
#[serde(with = "time::serde::rfc3339")]
pub expires_at: OffsetDateTime,
}
/// Request to persist a new immutable import plan.
///
/// There is deliberately no `digest` field: the registry computes it from the
/// server-authored `payload`, so client-supplied digests can never bind.
#[derive(Clone, Debug, PartialEq)]
pub struct CreateImportPlanRequest<'a> {
pub id: &'a ImportPlanId,
pub workspace_id: &'a WorkspaceId,
pub job_id: &'a ImportJobId,
pub payload: &'a Value,
pub created_at: &'a OffsetDateTime,
pub expires_at: &'a OffsetDateTime,
}
/// Applies a stored, immutable import plan atomically.
///
/// The registry loads and revalidates the plan itself: client candidate
/// material is never accepted. The request carries only the plan reference,
/// the caller-confirmed plan digest, a bounded idempotency key and the
/// service-recomputed preview fingerprint. A replay of a committed
/// `(workspace, idempotency_key, plan_digest)` triple returns the stored
/// immutable report even after the plan and its job have been cleaned up.
#[derive(Clone, Debug, PartialEq)]
pub struct ApplyImportPlanRequest<'a> {
pub workspace_id: &'a WorkspaceId,
pub plan_id: &'a ImportPlanId,
/// Caller-confirmed digest of the immutable plan payload (64 lowercase
/// hex). Replays must match the digest stored with the key; a different
/// digest under an already-used key is a typed conflict.
pub plan_digest: &'a str,
/// Bounded idempotency key identifying this logical apply.
pub idempotency_key: &'a str,
/// Preview fingerprint recomputed by the service from the revalidated
/// source/dependencies (importer/projection/preview digests). For new
/// attempts the registry compares it against the immutable plan
/// fingerprint inside the apply transaction: a mismatch is a typed
/// re-preview conflict. Committed replays skip this comparison.
pub verified_fingerprint: &'a Value,
pub applied_at: &'a OffsetDateTime,
}
/// Stored application evidence for a scoped idempotency key: the plan
/// digest the apply was committed under plus the immutable report. The row
/// outlives the plan and its job, so Admin can return committed replays
/// (or detect a changed-digest conflict) before the plan/job can be looked
/// up at all.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ImportPlanApplication {
pub plan_digest: String,
pub result: ApplyImportPlanResult,
}
/// Result of one `apply_import_plan` call.
///
/// `replayed` is a separate transport marker: the stored immutable report
/// is returned byte-for-byte on replay and never mutated.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ApplyImportPlanResult {
/// True when the report came from committed replay evidence instead of
/// being produced by this call.
pub replayed: bool,
pub report: ImportPlanApplyReport,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ImportPlanApplyStatus {
Applied,
Rejected,
}
/// Per-candidate outcome vocabulary of an import plan apply report.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ImportPlanCandidateOutcome {
Created,
Versioned,
Renamed,
Skipped,
Excluded,
Rejected,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ImportPlanCandidateReport {
pub key: String,
pub name: String,
pub outcome: ImportPlanCandidateOutcome,
/// Authoritative target identifier for `renamed` (new operation),
/// `versioned` (targeted operation) and `skipped`/`rejected` (exact
/// authorized target, when the plan carried one).
pub operation_id: Option<String>,
/// Draft version produced by `created`/`versioned`/`renamed`.
pub version: Option<u32>,
/// Bounded redacted machine reason (for example `not_selected`, the
/// blocked-candidate finding code, `operation_name_conflict`).
pub reason: Option<String>,
}
/// The immutable, redacted machine view of one import plan apply.
///
/// Contains only digests, identifiers, names and reasons — never credentials
/// (secret material lives in the secrets table and is only referenced here
/// through bounded id strings). Successful applies persist this exact
/// object as the replay evidence; rejected applies return it without
/// persisting, so it is always readable in the Admin/UI response.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ImportPlanApplyReport {
pub schema_version: String,
pub status: ImportPlanApplyStatus,
pub plan_id: String,
pub plan_digest: String,
pub job_id: String,
pub idempotency_key: String,
pub source_id: String,
pub source_digest: String,
pub dependencies: Vec<ImportPlanDependencyRef>,
pub counts: ImportPlanApplyCounts,
pub outcomes: Vec<ImportPlanCandidateReport>,
/// Bounded human summary (RU) derived from the machine fields.
pub summary: String,
/// Stable recovery guidance: `none`, `repreview_required` or
/// `confirm_skip_rename_or_new_version`.
pub recovery: String,
#[serde(with = "time::serde::rfc3339")]
pub applied_at: OffsetDateTime,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct ImportPlanApplyCounts {
pub created: u32,
pub versioned: u32,
pub renamed: u32,
pub skipped: u32,
pub excluded: u32,
pub rejected: u32,
}
/// Bounded verified-source digest reference carried by an apply report.
/// Plain strings keep the report serializable without reusing artifact
/// internals; the registry populates it from the immutable plan material.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ImportPlanDependencyRef {
pub source_id: String,
pub digest: String,
}