[skip ci] wip: preserve Hermes crank development checkpoint

Owner-authorized recovery of accumulated source changes.
Includes accepted work and in-progress changes; NOT a release or acceptance.
Parent baseline 1b6db09bd1. Runtime data, build caches and local credentials excluded.
This commit is contained in:
Hermes DevOps committed 2026-10-25 08:05:37 +00:00
1 parent 1b6db09bd1
commit 301dce301a
357 files changed
+118831 -5113

No files matched your search

@@ -5,8 +5,13 @@ mod artifact_metadata;
mod import_plan;
mod legacy_adoption;
mod preflight;
mod resource_security_revocations;
mod rollback;
mod schema_removal;
pub(crate) use schema_removal::*;
static EVENT_TRIGGER_TEST_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
fn legacy_preservation_row_expr(table: &str) -> &'static str {
@@ -57,6 +62,14 @@ async fn controlled_authority_is_versioned_and_safe_under_concurrent_apply() {
(13, "artifact-cleanup-indexes-v13"),
(14, "import-plan-v14"),
(15, "onboarding-import-selection-v15"),
(16, "resource-drafts-v16"),
(17, "resource-publications-v17"),
(18, "agent-resource-bindings-v18"),
(19, "resource-security-revocations-v19"),
(20, "resource-template-sources-v20"),
(21, "prompts-v21"),
(22, "prompt-publications-v22"),
(23, "prompt-dependencies-v23"),
];
assert_eq!(rows.len(), expected.len());
for (row, (version, name)) in rows.iter().zip(expected) {
@@ -121,11 +134,105 @@ async fn controlled_authority_is_versioned_and_safe_under_concurrent_apply() {
.await
.expect("V14 import plan relations must be readable");
assert_eq!(import_plan_relations.len(), 2);
let publication_relations = sqlx::query(
"select table_name
from information_schema.tables
where table_schema = current_schema()
and table_name in ('resource_publications', 'resource_versions')
order by table_name",
)
.fetch_all(first.pool())
.await
.expect("V17 publication relation must be readable");
assert_eq!(
publication_relations.len(),
2,
"V17 must add resource_publications beside resource_versions"
);
let binding_relations = sqlx::query(
"select table_name
from information_schema.tables
where table_schema = current_schema()
and table_name = 'agent_resource_bindings'",
)
.fetch_all(first.pool())
.await
.expect("V18 binding relation must be readable");
assert_eq!(
binding_relations.len(),
1,
"V18 must add the typed agent_resource_bindings table"
);
let binding_fks: i64 = sqlx::query_scalar(
"select count(*)::bigint
from pg_catalog.pg_constraint c
join pg_catalog.pg_class t on t.oid = c.conrelid
join pg_catalog.pg_namespace n on n.oid = t.relnamespace
where n.nspname = current_schema()
and t.relname = 'agent_resource_bindings' and c.contype = 'f'",
)
.fetch_one(first.pool())
.await
.expect("V18 binding constraints must be readable");
assert_eq!(
binding_fks, 3,
"V18 must keep workspace equality on both ends plus the exact Agent version"
);
assert_eq!(
MigrationAuthority::preflight(first.pool()).await.unwrap(),
MigrationPreflight::Current { version: 15 }
MigrationPreflight::Current { version: 23 }
);
}
#[tokio::test]
async fn v18_guard_rejects_missing_agent_resource_binding_trigger() {
let database_url = crank_test_support::postgres_schema_url("test_v18_guard_drift").await;
let pool = sqlx::PgPool::connect(&database_url).await.unwrap();
MigrationAuthority::apply(&pool).await.unwrap();
sqlx::query("drop trigger agent_resource_bindings_immutable_guard on agent_resource_bindings")
.execute(&pool)
.await
.expect("the V18 trigger must be droppable for the drift fixture");
let error = MigrationAuthority::preflight(&pool).await.unwrap_err();
assert_eq!(error.code(), "partial_sequence");
assert_eq!(
error.version(),
Some(18),
"a missing V18 immutability trigger must be attributed to V18: {error}"
);
assert_eq!(error.stage(), "v18.immutable_trigger");
sqlx::raw_sql(
"create trigger agent_resource_bindings_immutable_guard
before insert or update or delete on agent_resource_bindings
for each row
execute function crank_reject_published_agent_binding_mutation();",
)
.execute(&pool)
.await
.expect("the canonical trigger must be restorable");
let function_drift = MigrationAuthority::preflight(&pool).await.unwrap_err();
assert_eq!(
function_drift.code(),
"partial_sequence",
"V18 guard must pin the V18-local OLD+NEW function, not the V9 function"
);
assert_eq!(function_drift.stage(), "v18.immutable_trigger");
sqlx::raw_sql(
"drop trigger agent_resource_bindings_immutable_guard on agent_resource_bindings;
create trigger agent_resource_bindings_immutable_guard
before insert or update or delete on agent_resource_bindings
for each row
execute function crank_reject_published_agent_resource_binding_mutation();",
)
.execute(&pool)
.await
.expect("the V18-local guard must be restorable");
assert_eq!(
MigrationAuthority::preflight(&pool).await.unwrap(),
MigrationPreflight::Current { version: 23 },
"restoring the exact V18 contract must return the current verdict"
);
}
#[tokio::test]
async fn service_connect_is_read_only_on_fresh_database() {
let database_url = crank_test_support::postgres_schema_url("test_read_only_startup").await;
@@ -247,7 +354,7 @@ async fn ledgerless_legacy_baseline_is_consolidated_without_data_loss() {
MigrationAuthority::preflight(&pool).await.unwrap(),
MigrationPreflight::MigrationRequired {
current: 0,
target: 15,
target: 23,
}
);
MigrationAuthority::apply(&pool).await.unwrap();
@@ -360,13 +467,13 @@ async fn healthy_v2_is_reported_as_migration_required_and_upgrades_to_v3() {
MigrationAuthority::preflight(&pool).await.unwrap(),
MigrationPreflight::MigrationRequired {
current: 2,
target: 15,
target: 23,
}
);
MigrationAuthority::apply(&pool).await.unwrap();
assert_eq!(
MigrationAuthority::preflight(&pool).await.unwrap(),
MigrationPreflight::Current { version: 15 }
MigrationPreflight::Current { version: 23 }
);
let trace_column: bool = sqlx::query_scalar(
"select exists (
@@ -409,7 +516,7 @@ async fn healthy_v3_upgrades_to_v4_with_honest_legacy_snapshot_provenance() {
MigrationAuthority::preflight(&pool).await.unwrap(),
MigrationPreflight::MigrationRequired {
current: 3,
target: 15,
target: 23,
}
);
MigrationAuthority::apply(&pool).await.unwrap();
@@ -469,7 +576,7 @@ async fn healthy_v4_upgrades_to_v5_without_fabricating_legacy_outcomes() {
MigrationAuthority::preflight(&pool).await.unwrap(),
MigrationPreflight::MigrationRequired {
current: 4,
target: 15,
target: 23,
}
);
MigrationAuthority::apply(&pool).await.unwrap();
@@ -723,207 +830,6 @@ async fn v3_upgrade_ignores_oversized_legacy_request_ids_in_partial_index() {
MigrationAuthority::apply(&pool).await.unwrap();
assert_eq!(
MigrationAuthority::preflight(&pool).await.unwrap(),
MigrationPreflight::Current { version: 15 }
MigrationPreflight::Current { version: 23 }
);
}
async fn remove_v3_schema(pool: &sqlx::PgPool) {
sqlx::raw_sql(
"drop index if exists invocation_logs_workspace_request_id_idx;
alter table invocation_logs drop column if exists trace_id;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v4_schema(pool: &sqlx::PgPool) {
remove_v5_schema(pool).await;
sqlx::raw_sql(
"drop trigger if exists operation_versions_immutable_guard on operation_versions;
drop function if exists crank_guard_operation_version_immutable();
drop trigger if exists published_operations_monotonic_guard on published_operations;
drop function if exists crank_guard_published_operation_pointer();
drop trigger if exists operations_latest_pointer_monotonic_guard on operations;
drop function if exists crank_guard_operation_latest_pointer();
alter table operation_versions
drop constraint if exists operation_versions_snapshot_provenance_check,
drop column if exists name,
drop column if exists display_name,
drop column if exists category,
drop column if exists protocol,
drop column if exists security_level,
drop column if exists snapshot_provenance,
drop column if exists snapshot_observed_at,
drop column if exists published_at,
drop column if exists published_by;
delete from __crank_migrations where version = 4;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v5_schema(pool: &sqlx::PgPool) {
remove_v6_schema(pool).await;
sqlx::raw_sql(
"drop index if exists invocation_logs_workspace_operation_version_idx;
alter table invocation_logs
drop column if exists operation_version,
drop column if exists execution_stage,
drop column if exists execution_error_code,
drop column if exists retryability,
drop column if exists outcome_certainty;
delete from __crank_migrations where version = 5;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v6_schema(pool: &sqlx::PgPool) {
remove_v7_schema(pool).await;
sqlx::raw_sql(
"drop index if exists platform_api_keys_workspace_name_active_idx;
create unique index if not exists platform_api_keys_workspace_name_idx on platform_api_keys(workspace_id, name);
delete from __crank_migrations where version = 6;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v7_schema(pool: &sqlx::PgPool) {
remove_v8_schema(pool).await;
sqlx::raw_sql(
"alter table secret_versions drop constraint if exists secret_versions_target_all_or_none_check,
drop constraint if exists secret_versions_target_epoch_check,
drop constraint if exists secret_versions_master_key_epoch_check,
drop column if exists target_master_key_epoch, drop column if exists target_key_version,
drop column if exists target_ciphertext, drop column if exists master_key_epoch;
drop table if exists master_key_rotations;
drop table if exists master_key_identities;
delete from __crank_migrations where version = 7;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v8_schema(pool: &sqlx::PgPool) {
remove_v9_schema(pool).await;
sqlx::raw_sql(
"drop table if exists admin_security_audit_events;
drop table if exists admin_login_backoff;
drop table if exists admin_bootstrap_contracts;
alter table user_sessions
drop constraint if exists user_sessions_csrf_hash_check,
drop column if exists csrf_hash,
drop column if exists revoked_at;
delete from __crank_migrations where version = 8;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v9_schema(pool: &sqlx::PgPool) {
remove_v10_schema(pool).await;
sqlx::raw_sql(
"drop trigger if exists published_agents_monotonic_guard on published_agents;
drop function if exists crank_reject_published_agent_pointer_rewind();
drop trigger if exists agent_operation_bindings_immutable_guard on agent_operation_bindings;
drop function if exists crank_reject_published_agent_binding_mutation();
drop trigger if exists agent_versions_immutable_guard on agent_versions;
drop function if exists crank_reject_published_agent_version_mutation();
alter table published_agents
drop constraint if exists published_agents_catalog_revision_check,
drop column if exists catalog_revision;
alter table agents
drop constraint if exists agents_catalog_revision_check,
drop column if exists catalog_revision;
delete from __crank_migrations where version = 9;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v10_schema(pool: &sqlx::PgPool) {
remove_v11_schema(pool).await;
sqlx::raw_sql(
"drop index if exists approval_requests_pending_scope_fingerprint_idx;
drop index if exists approval_requests_workspace_request_trace_idx;
alter table approval_requests drop constraint if exists approval_requests_request_id_check;
alter table approval_requests drop constraint if exists approval_requests_trace_id_check;
alter table approval_requests drop column if exists request_id;
alter table approval_requests drop column if exists trace_id;
create unique index if not exists approval_requests_pending_fingerprint_idx
on approval_requests(agent_id, operation_id, operation_version, request_fingerprint)
where status = 'pending' and request_fingerprint is not null;
delete from __crank_migrations where version = 10;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v11_schema(pool: &sqlx::PgPool) {
remove_v12_schema(pool).await;
sqlx::raw_sql(
"drop table if exists onboarding_selections;
drop trigger if exists product_events_append_only_guard on product_events;
drop function if exists crank_reject_product_event_mutation();
drop table if exists product_event_daily_rollups;
drop table if exists product_events;
drop index if exists invocation_logs_workspace_agent_key_success_idx;
alter table invocation_logs drop constraint if exists invocation_logs_platform_key_scope_fk;
alter table invocation_logs drop column if exists platform_api_key_id;
alter table platform_api_keys drop constraint if exists platform_api_keys_workspace_agent_id_unique;
delete from __crank_migrations where version = 11;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v14_schema(pool: &sqlx::PgPool) {
remove_v15_schema(pool).await;
sqlx::raw_sql(
"drop table if exists import_plan_applications;
drop table if exists import_plans;
drop function if exists crank_reject_import_plan_mutation();
alter table import_jobs drop constraint if exists import_jobs_workspace_id_unique;
delete from __crank_migrations where version = 14;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v15_schema(pool: &sqlx::PgPool) {
sqlx::raw_sql(
"drop table if exists onboarding_import_selections;
alter table operations drop constraint if exists operations_workspace_id_unique;
alter table product_events drop constraint if exists product_events_name_check;
alter table product_events add constraint product_events_name_check check (event_name in (
'onboarding_eligible', 'onboarding_started', 'onboarding_resumed',
'onboarding_dismissed', 'onboarding_abandoned', 'onboarding_completed'
));
alter table product_event_daily_rollups drop constraint if exists product_event_daily_rollups_name_check;
alter table product_event_daily_rollups add constraint product_event_daily_rollups_name_check check (event_name in (
'onboarding_eligible', 'onboarding_started', 'onboarding_resumed',
'onboarding_dismissed', 'onboarding_abandoned', 'onboarding_completed'
));
delete from __crank_migrations where version = 15;",
)
.execute(pool)
.await
.unwrap();
}
async fn remove_v12_schema(pool: &sqlx::PgPool) {
remove_v14_schema(pool).await;
sqlx::raw_sql(
"drop index if exists import_jobs_openapi_source_idx;
drop index if exists import_jobs_expires_at_idx;
drop index if exists artifact_sources_openapi_dangling_idx;
drop index if exists artifact_sources_blob_lifecycle_detached_idx;
drop index if exists artifact_blobs_expired_claim_idx;
delete from __crank_migrations where version = 13;
drop table if exists artifact_sources;
drop table if exists artifact_blobs;
delete from __crank_migrations where version = 12;",
)
.execute(pool)
.await
.unwrap();
}