Add persisted thread artifact models (#40509)

## What changed

- Add a `thread_artifacts` SQLite table with per-thread typed identities,
  JSON payloads, cascade deletion, uniqueness enforcement, and an index for
  ordered per-thread reads.
- Export artifact records, attachment and removal outcomes, and paginated
  result models from `codex-state`.

## Testing

- Add a migration test covering preservation of existing thread-section
  metadata and compatibility with the previous migration set.

GitOrigin-RevId: 4e0a8e5bfa168ae2b8871970466e5055e142a4a6
This commit is contained in:
joeytrasatti-openai authored and copyberry committed 2026-08-25 01:10:10 +00:00
1 parent 41ca88e95c
commit 9b2ef38f54
5 files changed
+128

No files matched your search

+61
View File
@@ -188,6 +188,67 @@ INSERT INTO threads (
pool.close().await;
}
#[tokio::test]
async fn thread_artifact_migration_preserves_existing_section_metadata() {
let sqlite_home = crate::runtime::test_support::unique_temp_dir();
tokio::fs::create_dir_all(&sqlite_home)
.await
.expect("sqlite home should be created");
let _cleanup = scopeguard::guard(sqlite_home.clone(), |sqlite_home| {
let _ = std::fs::remove_dir_all(sqlite_home);
});
let sqlite = crate::SqliteConfig::new_for_testing(sqlite_home.as_path().abs());
let pool = sqlite
.open_read_write_pool(&sqlite.state_db_path())
.await
.expect("sqlite database should open");
migrator_through(/*version*/ 50)
.run(&pool)
.await
.expect("released thread migrations should apply");
sqlx::query("UPDATE thread_sections SET appearance = ? WHERE id = ?")
.bind(r#"{"icon":"pin"}"#)
.bind(PINNED_THREAD_SECTION_ID)
.execute(&pool)
.await
.expect("released section appearance should remain writable");
STATE_MIGRATOR
.run(&pool)
.await
.expect("artifact migration should apply without rewriting released migrations");
let section = sqlx::query_as::<_, (String, String, Option<String>)>(
"SELECT id, name, appearance FROM thread_sections WHERE id = ?",
)
.bind(PINNED_THREAD_SECTION_ID)
.fetch_one(&pool)
.await
.expect("existing section metadata should remain available");
assert_eq!(
section,
(
PINNED_THREAD_SECTION_ID.to_string(),
PINNED_THREAD_SECTION_NAME.to_string(),
Some(r#"{"icon":"pin"}"#.to_string()),
)
);
let artifact_tables = sqlx::query_scalar::<_, String>(
"SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'thread_artifacts'",
)
.fetch_all(&pool)
.await
.expect("artifact table should exist");
assert_eq!(artifact_tables, vec!["thread_artifacts"]);
let mut released_migrator = migrator_through(/*version*/ 50);
released_migrator.ignore_missing = true;
released_migrator
.run(&pool)
.await
.expect("released binaries should tolerate the additive artifact migration");
}
#[tokio::test]
async fn thread_section_order_migration_backfills_stably() {
let sqlite_home = crate::runtime::test_support::unique_temp_dir();