145 lines
4.1 KiB
Rust
145 lines
4.1 KiB
Rust
use ids::{BranchId, Lsn, RunId, TenantId};
|
|
use poimen_log::{BlobRef, BranchKey, LogRecord, SchemaVersion, Timestamp, WorkEvent};
|
|
use std::fs;
|
|
use std::path::Path;
|
|
|
|
fn main() {
|
|
if std::env::var("FIXTURE_REGEN").is_ok() {
|
|
regenerate_fixtures();
|
|
}
|
|
}
|
|
|
|
fn regenerate_fixtures() {
|
|
let base_path = Path::new("tests/fixtures/v1");
|
|
fs::create_dir_all(base_path).expect("Failed to create fixtures dir");
|
|
|
|
let tenant = TenantId::new();
|
|
let run = RunId::new();
|
|
let branch = BranchId::new(0);
|
|
let key = BranchKey::new(tenant, run, branch);
|
|
|
|
// Generate fixture for each variant
|
|
let variants = vec![
|
|
(
|
|
"attempt_transition",
|
|
LogRecord::new(
|
|
key,
|
|
Lsn::new(1),
|
|
SchemaVersion::new(1),
|
|
Timestamp::new(1000),
|
|
WorkEvent::AttemptTransition {
|
|
attempt_no: 1,
|
|
from_state: "Pending".to_string(),
|
|
to_state: "Running".to_string(),
|
|
reason: "admitted".to_string(),
|
|
},
|
|
),
|
|
),
|
|
(
|
|
"run_lifecycle",
|
|
LogRecord::new(
|
|
key,
|
|
Lsn::new(2),
|
|
SchemaVersion::new(1),
|
|
Timestamp::new(1001),
|
|
WorkEvent::RunLifecycle {
|
|
lifecycle_event: "started".to_string(),
|
|
},
|
|
),
|
|
),
|
|
(
|
|
"prompt_blob_ref",
|
|
LogRecord::new(
|
|
key,
|
|
Lsn::new(3),
|
|
SchemaVersion::new(1),
|
|
Timestamp::new(1002),
|
|
WorkEvent::PromptBlobRef {
|
|
blob: BlobRef {
|
|
hash: [1u8; 32],
|
|
size: 256,
|
|
},
|
|
},
|
|
),
|
|
),
|
|
(
|
|
"output_blob_ref",
|
|
LogRecord::new(
|
|
key,
|
|
Lsn::new(4),
|
|
SchemaVersion::new(1),
|
|
Timestamp::new(1003),
|
|
WorkEvent::OutputBlobRef {
|
|
blob: BlobRef {
|
|
hash: [2u8; 32],
|
|
size: 512,
|
|
},
|
|
},
|
|
),
|
|
),
|
|
(
|
|
"context_partition",
|
|
LogRecord::new(
|
|
key,
|
|
Lsn::new(5),
|
|
SchemaVersion::new(1),
|
|
Timestamp::new(1004),
|
|
WorkEvent::ContextPartition {
|
|
partition_id: "p1".to_string(),
|
|
},
|
|
),
|
|
),
|
|
(
|
|
"usage",
|
|
LogRecord::new(
|
|
key,
|
|
Lsn::new(6),
|
|
SchemaVersion::new(1),
|
|
Timestamp::new(1005),
|
|
WorkEvent::Usage {
|
|
tokens_input: 100,
|
|
tokens_output: 50,
|
|
},
|
|
),
|
|
),
|
|
(
|
|
"intent_record",
|
|
LogRecord::new(
|
|
key,
|
|
Lsn::new(7),
|
|
SchemaVersion::new(1),
|
|
Timestamp::new(1006),
|
|
WorkEvent::IntentRecord {
|
|
intent_id: "intent1".to_string(),
|
|
},
|
|
),
|
|
),
|
|
(
|
|
"reduced",
|
|
LogRecord::new(
|
|
key,
|
|
Lsn::new(8),
|
|
SchemaVersion::new(1),
|
|
Timestamp::new(1007),
|
|
WorkEvent::Reduced {
|
|
original: BlobRef {
|
|
hash: [3u8; 32],
|
|
size: 1024,
|
|
},
|
|
summary: BlobRef {
|
|
hash: [4u8; 32],
|
|
size: 256,
|
|
},
|
|
},
|
|
),
|
|
),
|
|
];
|
|
|
|
for (name, record) in variants {
|
|
let encoded = poimen_log::encode(&record).expect("encode failed");
|
|
let path = base_path.join(format!("{}.cbor", name));
|
|
fs::write(&path, &encoded).expect(&format!("Failed to write {}", path.display()));
|
|
println!("Generated fixture: {}", path.display());
|
|
}
|
|
}
|