core: type operation timestamps

This commit is contained in:
a.tolmachev
2026-04-19 07:27:12 +00:00
parent 8d1f5284ba
commit 179165838a
15 changed files with 229 additions and 212 deletions
+12 -8
View File
@@ -2,6 +2,7 @@ use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use time::OffsetDateTime;
use crate::{
ids::{AuthProfileId, DescriptorId, OperationId, SampleId},
@@ -231,10 +232,13 @@ pub struct Operation<TSchema, TMapping> {
pub generated_draft: Option<GeneratedDraft>,
#[serde(skip_serializing_if = "Option::is_none")]
pub config_export: Option<ConfigExport>,
pub created_at: String,
pub updated_at: String,
#[serde(with = "time::serde::rfc3339")]
pub created_at: OffsetDateTime,
#[serde(with = "time::serde::rfc3339")]
pub updated_at: OffsetDateTime,
#[serde(skip_serializing_if = "Option::is_none")]
pub published_at: Option<String>,
#[serde(with = "time::serde::rfc3339::option")]
pub published_at: Option<OffsetDateTime>,
}
impl<TSchema, TMapping> Operation<TSchema, TMapping> {
@@ -419,8 +423,8 @@ mod tests {
samples: Some(Samples::default()),
generated_draft: None,
config_export: None,
created_at: "2026-03-25T08:00:00Z".to_owned(),
updated_at: "2026-03-25T08:00:00Z".to_owned(),
created_at: timestamp("2026-03-25T08:00:00Z"),
updated_at: timestamp("2026-03-25T08:00:00Z"),
published_at: None,
};
@@ -500,9 +504,9 @@ mod tests {
format_version: "1".to_owned(),
export_mode: ExportMode::Portable,
}),
created_at: "2026-03-25T08:00:00Z".to_owned(),
updated_at: "2026-03-25T08:10:00Z".to_owned(),
published_at: Some("2026-03-25T08:15:00Z".to_owned()),
created_at: timestamp("2026-03-25T08:00:00Z"),
updated_at: timestamp("2026-03-25T08:10:00Z"),
published_at: Some(timestamp("2026-03-25T08:15:00Z")),
};
let yaml = serde_yaml::to_string(&operation).unwrap();
+5 -5
View File
@@ -211,9 +211,9 @@ pub struct OperationSummary {
pub status: OperationStatus,
pub current_draft_version: u32,
pub latest_published_version: Option<u32>,
pub created_at: String,
pub updated_at: String,
pub published_at: Option<String>,
pub created_at: OffsetDateTime,
pub updated_at: OffsetDateTime,
pub published_at: Option<OffsetDateTime>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@@ -239,7 +239,7 @@ pub struct OperationVersionRecord {
pub version: u32,
pub status: OperationStatus,
pub change_note: Option<String>,
pub created_at: String,
pub created_at: OffsetDateTime,
pub created_by: Option<String>,
pub snapshot: RegistryOperation,
}
@@ -370,7 +370,7 @@ pub struct PublishRequest<'a> {
pub workspace_id: &'a WorkspaceId,
pub operation_id: &'a OperationId,
pub version: u32,
pub published_at: &'a str,
pub published_at: &'a OffsetDateTime,
pub published_by: Option<&'a str>,
}
+4 -4
View File
@@ -452,9 +452,9 @@ impl PostgresRegistry {
o.display_name,
o.category,
o.protocol,
to_char(o.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"operation_created_at!\",
to_char(o.updated_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"operation_updated_at!\",
to_char(o.published_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as operation_published_at,
o.created_at as \"operation_created_at!: time::OffsetDateTime\",
o.updated_at as \"operation_updated_at!: time::OffsetDateTime\",
o.published_at as \"operation_published_at: time::OffsetDateTime\",
ov.version,
ov.status,
ov.target_json,
@@ -468,7 +468,7 @@ impl PostgresRegistry {
ov.generated_draft_json,
ov.config_export_json,
ov.change_note,
to_char(ov.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"created_at!\",
ov.created_at as \"created_at!: time::OffsetDateTime\",
ov.created_by
from workspaces w
join agents a on a.workspace_id = w.id
+15 -15
View File
@@ -385,7 +385,7 @@ async fn insert_version_row(
.bind(serialize_option_json_value(&snapshot.generated_draft)?.map(Json))
.bind(serialize_option_json_value(&snapshot.config_export)?.map(Json))
.bind(change_note)
.bind(&snapshot.updated_at)
.bind(snapshot.updated_at)
.bind(created_by)
.execute(&mut **tx)
.await?;
@@ -717,9 +717,9 @@ fn build_operation_summary(
status: String,
current_draft_version: i32,
latest_published_version: Option<i32>,
created_at: String,
updated_at: String,
published_at: Option<String>,
created_at: OffsetDateTime,
updated_at: OffsetDateTime,
published_at: Option<OffsetDateTime>,
) -> Result<OperationSummary, RegistryError> {
let target: Target = deserialize_json_value(target_json)?;
let (target_url, target_action) = target_summary(&target);
@@ -830,9 +830,9 @@ fn build_operation_version_record(
display_name: String,
category: String,
protocol: String,
operation_created_at: String,
operation_updated_at: String,
operation_published_at: Option<String>,
operation_created_at: OffsetDateTime,
operation_updated_at: OffsetDateTime,
operation_published_at: Option<OffsetDateTime>,
version: i32,
status: String,
target_json: Value,
@@ -846,7 +846,7 @@ fn build_operation_version_record(
generated_draft_json: Option<Value>,
config_export_json: Option<Value>,
change_note: Option<String>,
created_at: String,
created_at: OffsetDateTime,
created_by: Option<String>,
) -> Result<OperationVersionRecord, RegistryError> {
let operation_id = OperationId::new(id);
@@ -859,7 +859,7 @@ fn build_operation_version_record(
version,
status,
change_note,
created_at: created_at.clone(),
created_at,
created_by,
snapshot: RegistryOperation {
id: operation_id,
@@ -1190,7 +1190,7 @@ mod tests {
workspace_id: &test_workspace_id(),
operation_id: &operation_v2.id,
version: operation_v2.version,
published_at: "2026-03-25T12:10:00Z",
published_at: &timestamp("2026-03-25T12:10:00Z"),
published_by: Some("alice"),
})
.await
@@ -1275,7 +1275,7 @@ mod tests {
operation.generated_draft = None;
operation.samples = None;
operation.config_export = None;
operation.updated_at = "2026-03-25T12:34:00Z".to_owned();
operation.updated_at = timestamp("2026-03-25T12:34:00Z");
registry
.update_operation_draft(&test_workspace_id(), &operation)
@@ -1824,7 +1824,7 @@ mod tests {
workspace_id: &test_workspace_id(),
operation_id: &operation.id,
version: operation_v2.version,
published_at: "2026-03-25T12:10:00Z",
published_at: &timestamp("2026-03-25T12:10:00Z"),
published_by: Some("alice"),
})
.await
@@ -1904,7 +1904,7 @@ mod tests {
workspace_id: &test_workspace_id(),
operation_id: &operation.id,
version: operation_v2.version,
published_at: "2026-03-25T12:10:00Z",
published_at: &timestamp("2026-03-25T12:10:00Z"),
published_by: Some("alice"),
})
.await
@@ -2415,8 +2415,8 @@ mod tests {
format_version: "v1".to_owned(),
export_mode: ExportMode::Portable,
}),
created_at: "2026-03-25T11:58:00Z".to_owned(),
updated_at: format!("2026-03-25T12:{version:02}:00Z"),
created_at: timestamp("2026-03-25T11:58:00Z"),
updated_at: timestamp(&format!("2026-03-25T12:{version:02}:00Z")),
published_at: None,
}
}
+28 -28
View File
@@ -61,9 +61,9 @@ impl PostgresRegistry {
.as_ref()
.map(|_| to_db_version(snapshot.version)),
)
.bind(&snapshot.created_at)
.bind(&snapshot.updated_at)
.bind(snapshot.published_at.as_deref())
.bind(snapshot.created_at)
.bind(snapshot.updated_at)
.bind(snapshot.published_at)
.execute(&mut *tx)
.await?;
@@ -116,7 +116,7 @@ impl PostgresRegistry {
)
.bind(serialize_enum_text(&request.snapshot.status, "status")?)
.bind(to_db_version(request.snapshot.version))
.bind(&request.snapshot.updated_at)
.bind(request.snapshot.updated_at)
.bind(request.snapshot.id.as_str())
.execute(&mut *tx)
.await?;
@@ -162,7 +162,7 @@ impl PostgresRegistry {
.bind(&snapshot.display_name)
.bind(&snapshot.category)
.bind(serialize_enum_text(&snapshot.status, "status")?)
.bind(&snapshot.updated_at)
.bind(snapshot.updated_at)
.bind(workspace_id.as_str())
.bind(snapshot.id.as_str())
.execute(&mut *tx)
@@ -207,7 +207,7 @@ impl PostgresRegistry {
&self,
workspace_id: &WorkspaceId,
operation_id: &OperationId,
archived_at: &str,
archived_at: &time::OffsetDateTime,
) -> Result<(), RegistryError> {
let Some(summary) = self
.get_operation_summary(workspace_id, operation_id)
@@ -320,9 +320,9 @@ impl PostgresRegistry {
operations.status,
operations.current_draft_version,
operations.latest_published_version,
to_char(operations.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"created_at!\",
to_char(operations.updated_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"updated_at!\",
to_char(operations.published_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as published_at
operations.created_at as \"created_at!: time::OffsetDateTime\",
operations.updated_at as \"updated_at!: time::OffsetDateTime\",
operations.published_at as \"published_at: time::OffsetDateTime\"
from operations
join operation_versions ov
on ov.operation_id = operations.id
@@ -432,9 +432,9 @@ impl PostgresRegistry {
operations.status,
operations.current_draft_version,
operations.latest_published_version,
to_char(operations.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"created_at!\",
to_char(operations.updated_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"updated_at!\",
to_char(operations.published_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as published_at
operations.created_at as \"created_at!: time::OffsetDateTime\",
operations.updated_at as \"updated_at!: time::OffsetDateTime\",
operations.published_at as \"published_at: time::OffsetDateTime\"
from operations
join operation_versions ov
on ov.operation_id = operations.id
@@ -480,9 +480,9 @@ impl PostgresRegistry {
o.display_name,
o.category,
o.protocol,
to_char(o.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"operation_created_at!\",
to_char(o.updated_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"operation_updated_at!\",
to_char(o.published_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as operation_published_at,
o.created_at as \"operation_created_at!: time::OffsetDateTime\",
o.updated_at as \"operation_updated_at!: time::OffsetDateTime\",
o.published_at as \"operation_published_at: time::OffsetDateTime\",
ov.version,
ov.status,
ov.target_json,
@@ -496,7 +496,7 @@ impl PostgresRegistry {
ov.generated_draft_json,
ov.config_export_json,
ov.change_note,
to_char(ov.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"created_at!\",
ov.created_at as \"created_at!: time::OffsetDateTime\",
ov.created_by
from operation_versions ov
join operations o on o.id = ov.operation_id
@@ -552,9 +552,9 @@ impl PostgresRegistry {
o.display_name,
o.category,
o.protocol,
to_char(o.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"operation_created_at!\",
to_char(o.updated_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"operation_updated_at!\",
to_char(o.published_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as operation_published_at,
o.created_at as \"operation_created_at!: time::OffsetDateTime\",
o.updated_at as \"operation_updated_at!: time::OffsetDateTime\",
o.published_at as \"operation_published_at: time::OffsetDateTime\",
ov.version,
ov.status,
ov.target_json,
@@ -568,7 +568,7 @@ impl PostgresRegistry {
ov.generated_draft_json,
ov.config_export_json,
ov.change_note,
to_char(ov.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"created_at!\",
ov.created_at as \"created_at!: time::OffsetDateTime\",
ov.created_by
from operation_versions ov
join operations o on o.id = ov.operation_id
@@ -691,9 +691,9 @@ impl PostgresRegistry {
o.display_name,
o.category,
o.protocol,
to_char(o.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"operation_created_at!\",
to_char(o.updated_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"operation_updated_at!\",
to_char(o.published_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as operation_published_at,
o.created_at as \"operation_created_at!: time::OffsetDateTime\",
o.updated_at as \"operation_updated_at!: time::OffsetDateTime\",
o.published_at as \"operation_published_at: time::OffsetDateTime\",
ov.version,
ov.status,
ov.target_json,
@@ -707,7 +707,7 @@ impl PostgresRegistry {
ov.generated_draft_json,
ov.config_export_json,
ov.change_note,
to_char(ov.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"created_at!\",
ov.created_at as \"created_at!: time::OffsetDateTime\",
ov.created_by
from published_operations po
join operation_versions ov
@@ -760,9 +760,9 @@ impl PostgresRegistry {
o.display_name,
o.category,
o.protocol,
to_char(o.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"operation_created_at!\",
to_char(o.updated_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"operation_updated_at!\",
to_char(o.published_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as operation_published_at,
o.created_at as \"operation_created_at!: time::OffsetDateTime\",
o.updated_at as \"operation_updated_at!: time::OffsetDateTime\",
o.published_at as \"operation_published_at: time::OffsetDateTime\",
ov.version,
ov.status,
ov.target_json,
@@ -776,7 +776,7 @@ impl PostgresRegistry {
ov.generated_draft_json,
ov.config_export_json,
ov.change_note,
to_char(ov.created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') as \"created_at!\",
ov.created_at as \"created_at!: time::OffsetDateTime\",
ov.created_by
from published_operations po
join operation_versions ov
+26 -21
View File
@@ -521,11 +521,16 @@ mod tests {
use crank_schema::{Schema, SchemaKind};
use futures_util::{SinkExt, StreamExt, stream};
use serde_json::{Value, json};
use time::{OffsetDateTime, format_description::well_known::Rfc3339};
use tokio::net::TcpListener;
use tokio_tungstenite::accept_async;
use crate::{RuntimeError, RuntimeExecutor, RuntimeOperation};
fn timestamp(value: &str) -> OffsetDateTime {
OffsetDateTime::parse(value, &Rfc3339).unwrap()
}
#[tokio::test]
async fn executes_rest_operation_end_to_end() {
let base_url = spawn_runtime_server().await;
@@ -1053,9 +1058,9 @@ mod tests {
warnings: Vec::new(),
}),
config_export: None,
created_at: "2026-03-25T20:00:00Z".to_owned(),
updated_at: "2026-03-25T20:00:00Z".to_owned(),
published_at: Some("2026-03-25T20:00:00Z".to_owned()),
created_at: timestamp("2026-03-25T20:00:00Z"),
updated_at: timestamp("2026-03-25T20:00:00Z"),
published_at: Some(timestamp("2026-03-25T20:00:00Z")),
})
}
@@ -1129,9 +1134,9 @@ mod tests {
warnings: Vec::new(),
}),
config_export: None,
created_at: "2026-03-25T20:00:00Z".to_owned(),
updated_at: "2026-03-25T20:00:00Z".to_owned(),
published_at: Some("2026-03-25T20:00:00Z".to_owned()),
created_at: timestamp("2026-03-25T20:00:00Z"),
updated_at: timestamp("2026-03-25T20:00:00Z"),
published_at: Some(timestamp("2026-03-25T20:00:00Z")),
})
}
@@ -1204,9 +1209,9 @@ mod tests {
warnings: Vec::new(),
}),
config_export: None,
created_at: "2026-03-25T20:00:00Z".to_owned(),
updated_at: "2026-03-25T20:00:00Z".to_owned(),
published_at: Some("2026-03-25T20:00:00Z".to_owned()),
created_at: timestamp("2026-03-25T20:00:00Z"),
updated_at: timestamp("2026-03-25T20:00:00Z"),
published_at: Some(timestamp("2026-03-25T20:00:00Z")),
})
}
@@ -1286,9 +1291,9 @@ mod tests {
samples: None,
generated_draft: None,
config_export: None,
created_at: "2026-04-06T12:00:00Z".to_owned(),
updated_at: "2026-04-06T12:00:00Z".to_owned(),
published_at: Some("2026-04-06T12:00:00Z".to_owned()),
created_at: timestamp("2026-04-06T12:00:00Z"),
updated_at: timestamp("2026-04-06T12:00:00Z"),
published_at: Some(timestamp("2026-04-06T12:00:00Z")),
})
}
@@ -1370,9 +1375,9 @@ mod tests {
warnings: Vec::new(),
}),
config_export: None,
created_at: "2026-04-06T12:00:00Z".to_owned(),
updated_at: "2026-04-06T12:00:00Z".to_owned(),
published_at: Some("2026-04-06T12:00:00Z".to_owned()),
created_at: timestamp("2026-04-06T12:00:00Z"),
updated_at: timestamp("2026-04-06T12:00:00Z"),
published_at: Some(timestamp("2026-04-06T12:00:00Z")),
})
}
@@ -1459,9 +1464,9 @@ mod tests {
samples: None,
generated_draft: None,
config_export: None,
created_at: "2026-04-06T12:00:00Z".to_owned(),
updated_at: "2026-04-06T12:00:00Z".to_owned(),
published_at: Some("2026-04-06T12:00:00Z".to_owned()),
created_at: timestamp("2026-04-06T12:00:00Z"),
updated_at: timestamp("2026-04-06T12:00:00Z"),
published_at: Some(timestamp("2026-04-06T12:00:00Z")),
})
}
@@ -1570,9 +1575,9 @@ mod tests {
samples: None,
generated_draft: None,
config_export: None,
created_at: "2026-04-06T12:00:00Z".to_owned(),
updated_at: "2026-04-06T12:00:00Z".to_owned(),
published_at: Some("2026-04-06T12:00:00Z".to_owned()),
created_at: timestamp("2026-04-06T12:00:00Z"),
updated_at: timestamp("2026-04-06T12:00:00Z"),
published_at: Some(timestamp("2026-04-06T12:00:00Z")),
})
}