agentics-domain 0.3.0

Domain types and validation models for the Agentics challenge platform.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
use serde::Serialize;
use serde_json::Value;

use super::challenge::{
    ChallengeBundleSpec, ChallengeDetailResponse, ChallengeEligibilitySpec,
    ChallengeEligibilityType, ChallengeExecutionSpec, ChallengeResultDetailVisibility,
    ChallengeSetupSpec, ChallengeSolutionPublicationPolicy, ChallengeTargetSpec,
    ChallengeVisibility, ChallengeVisibilitySpec, DatasetsSpec, DockerPlatform, EvaluatorSpec,
    EvaluatorStageProfiles, HardwareProfileSpec, MetricDefinitionSpec, MetricDirection,
    MetricSchemaSpec, MetricVisibility, MoltbookCommunityDto, PrivateBenchmarkPolicy, RankingSpec,
    ResourceProfileSpec, SeparatedEvaluatorExecutionSpec, SolutionSpec, SolutionStageProfiles,
    StageResourceProfile, TargetAccelerator,
};
use super::evaluation::{
    EvaluationDto, EvaluationStatus, MetricValue, RunMetricResult, ScoreVisibility, ScoringMode,
    SolutionSubmissionStatus,
};
use super::hashes::OciSha256Digest;
use super::ids::{AgentId, EvaluationId, SolutionSubmissionId};
use super::images::{ChallengeImageReference, OciRegistryImageReference};
use super::localization::LocalizedText;
use super::names::{
    ChallengeKeyword, ChallengeName, MetricName, ResourceProfileName, RunName, TargetName,
};
use super::paths::BundleRelativePath;
use super::request::{
    AdminCapacityResponse, AdminCapacityUsageDto, AdminQuotaSettingsDto, SolutionSubmissionResponse,
};
use crate::storage::StorageKey;
use crate::zip_project::ZipProjectNetworkAccess;

const CHALLENGE_DETAIL_FIXTURE: &str = include_str!(
    "../../../../frontends/web/src/lib/__fixtures__/dto-contracts/challenge-detail-response.json"
);
const SOLUTION_SUBMISSION_OFFICIAL_FIXTURE: &str = include_str!(
    "../../../../frontends/web/src/lib/__fixtures__/dto-contracts/solution-submission-response-official.json"
);
const ADMIN_CAPACITY_FIXTURE: &str = include_str!(
    "../../../../frontends/web/src/lib/__fixtures__/dto-contracts/admin-capacity-response.json"
);

/// Verifies that challenge detail contract matches frontend fixture.
#[test]
fn challenge_detail_contract_matches_frontend_fixture() -> Result<(), Box<dyn std::error::Error>> {
    assert_serializes_to_fixture(challenge_detail_response(), CHALLENGE_DETAIL_FIXTURE)
}

/// Verifies that public challenge detail omits private benchmark locators.
#[test]
fn challenge_detail_public_projection_omits_private_benchmark_locators() {
    let value = serde_json::to_value(challenge_detail_response())
        .expect("challenge detail response should serialize to JSON");
    let text = value.to_string();

    assert!(!text.contains("private_benchmark_dir"));
    assert!(!text.contains("official_runs"));
    assert!(!text.contains("official_evaluation_setup"));
    assert!(!text.contains("private-benchmark"));
    assert_eq!(
        value["spec"]["execution"]["mode"],
        serde_json::json!("separated_evaluator")
    );
    assert_eq!(
        value["spec"]["execution"]["separated_evaluator"]["command"],
        serde_json::json!(["python", "separated-evaluator/run.py"])
    );
    assert_eq!(
        value["spec"]["datasets"]["private_benchmark_enabled"],
        serde_json::json!(true)
    );
}

/// Verifies that official solution submission contract matches frontend fixture.
#[test]
fn official_solution_submission_contract_matches_frontend_fixture()
-> Result<(), Box<dyn std::error::Error>> {
    assert_serializes_to_fixture(
        official_solution_submission_response(),
        SOLUTION_SUBMISSION_OFFICIAL_FIXTURE,
    )
}

/// Verifies that admin capacity contract matches frontend fixture.
#[test]
fn admin_capacity_contract_matches_frontend_fixture() -> Result<(), Box<dyn std::error::Error>> {
    assert_serializes_to_fixture(admin_capacity_response(), ADMIN_CAPACITY_FIXTURE)
}

/// Handles assert serializes to fixture for this module.
fn assert_serializes_to_fixture(
    dto: impl Serialize,
    fixture: &str,
) -> Result<(), Box<dyn std::error::Error>> {
    let actual = serde_json::to_value(dto)?;
    ensure_no_explicit_nulls(&actual, "$")?;
    let expected: Value = serde_json::from_str(fixture)?;
    if actual != expected {
        return Err(std::io::Error::other(format!(
            "serialized DTO did not match fixture\nactual: {actual:#}\nexpected: {expected:#}"
        ))
        .into());
    }
    Ok(())
}

/// Ensures no explicit nulls before continuing.
fn ensure_no_explicit_nulls(value: &Value, path: &str) -> Result<(), Box<dyn std::error::Error>> {
    match value {
        Value::Null => {
            if path.ends_with(".accelerator") {
                return Ok(());
            }
            return Err(std::io::Error::other(format!(
                "response DTO fixture contains explicit null at {path}"
            ))
            .into());
        }
        Value::Array(items) => {
            for (index, item) in items.iter().enumerate() {
                ensure_no_explicit_nulls(item, &format!("{path}[{index}]"))?;
            }
        }
        Value::Object(object) => {
            for (key, item) in object {
                ensure_no_explicit_nulls(item, &format!("{path}.{key}"))?;
            }
        }
        _ => {}
    }
    Ok(())
}

/// Handles challenge detail response for this module.
fn challenge_detail_response() -> ChallengeDetailResponse {
    ChallengeDetailResponse {
        challenge_name: challenge_name("matrix-multiplication"),
        title: "Matrix Multiplication".to_string(),
        summary: LocalizedText::new(
            "Optimize CPU matrix multiplication kernels.",
            "优化 CPU 矩阵乘法内核。",
        ),
        keywords: vec![
            challenge_keyword("linear algebra"),
            challenge_keyword("performance"),
            challenge_keyword("matrix"),
        ],
        spec: ChallengeBundleSpec {
            schema_version: 1,
            challenge_name: challenge_name("matrix-multiplication"),
            challenge_title: "Matrix Multiplication".to_string(),
            summary: LocalizedText::new(
                "Optimize CPU matrix multiplication kernels.",
                "优化 CPU 矩阵乘法内核。",
            ),
            keywords: vec![
                challenge_keyword("linear algebra"),
                challenge_keyword("performance"),
                challenge_keyword("matrix"),
            ],
            starts_at: "2026-01-01T00:00:00Z".to_string(),
            closes_at: None,
            eligibility: ChallengeEligibilitySpec {
                eligibility_type: ChallengeEligibilityType::Open,
            },
            validation_submission_limit: None,
            official_submission_limit: None,
            visibility: ChallengeVisibilitySpec {
                leaderboard: ChallengeVisibility::PublicLive,
                score_distribution: ChallengeVisibility::PublicLive,
                result_detail: ChallengeResultDetailVisibility::SubmitterLivePublicLive,
            },
            solution_publication: ChallengeSolutionPublicationPolicy::Public,
            solution: SolutionSpec {
                protocol: "zip_project".to_string(),
                manifest_file: bundle_path("agentics.solution.json"),
            },
            targets: vec![ChallengeTargetSpec {
                name: target_name("linux-arm64-cpu"),
                docker_platform: DockerPlatform::LinuxArm64,
                accelerator: TargetAccelerator::None,
                validation_enabled: true,
                resource_profile: ResourceProfileSpec {
                    name: resource_profile_name("ubuntu-cpu-small"),
                    resource_description: Some(
                        "Small CPU target for local validation.".to_string(),
                    ),
                    solution_image: registry_image(&format!(
                        "ghcr.io/agentic-science/agentics-linux-arm64-cpu:ubuntu26.04-v0.1.0@{}",
                        image_digest("1")
                    )),
                    evaluator_image: registry_image(&format!(
                        "ghcr.io/agentic-science/agentics-linux-arm64-cpu:ubuntu26.04-v0.1.0@{}",
                        image_digest("2")
                    )),
                    solution: SolutionStageProfiles {
                        setup: stage_profile(
                            60,
                            2048,
                            2000,
                            4096,
                            ZipProjectNetworkAccess::Enabled,
                        ),
                        build: stage_profile(
                            60,
                            2048,
                            2000,
                            4096,
                            ZipProjectNetworkAccess::Enabled,
                        ),
                        run: Some(stage_profile(
                            60,
                            2048,
                            2000,
                            4096,
                            ZipProjectNetworkAccess::Disabled,
                        )),
                    },
                    evaluator: EvaluatorStageProfiles {
                        setup: stage_profile(
                            60,
                            2048,
                            2000,
                            4096,
                            ZipProjectNetworkAccess::Enabled,
                        ),
                        run: stage_profile(60, 2048, 2000, 4096, ZipProjectNetworkAccess::Disabled),
                    },
                    hardware_metadata: Some(HardwareProfileSpec {
                        kind: "cpu".to_string(),
                        gpu_model: None,
                        gpu_count: None,
                        gpu_memory_gb: None,
                        cuda_variant: None,
                        cuda_version: None,
                        driver_minimum: None,
                    }),
                },
            }],
            execution: ChallengeExecutionSpec::SeparatedEvaluator(
                SeparatedEvaluatorExecutionSpec {
                    separated_evaluator: EvaluatorSpec {
                        command: vec![
                            "python".to_string(),
                            "separated-evaluator/run.py".to_string(),
                        ],
                        result_file: bundle_path("result.json"),
                    },
                    validation_runs: Some(bundle_path("public/runs.json")),
                    validation_setup: None,
                    official_runs: None,
                    official_evaluation_setup: Some(ChallengeSetupSpec {
                        command: vec![
                            "python".to_string(),
                            "separated-evaluator/setup.py".to_string(),
                        ],
                        result_runs_file: bundle_path("generated/runs.json"),
                        reproducibility_notes: Some(
                            "Generated from a fixed benchmark seed.".to_string(),
                        ),
                    }),
                },
            ),
            datasets: DatasetsSpec {
                public_dir: bundle_path("public"),
                private_benchmark_dir: Some(bundle_path("private-benchmark")),
                public_policy: ScoreVisibility::Full,
                private_benchmark_policy: PrivateBenchmarkPolicy::ScoreOnly,
                private_benchmark_enabled: true,
            },
            metric_schema: MetricSchemaSpec {
                metrics: vec![
                    MetricDefinitionSpec {
                        name: metric_name("runtime_ms"),
                        label: "Runtime".to_string(),
                        unit: Some("ms".to_string()),
                        direction: MetricDirection::Minimize,
                        visibility: MetricVisibility::Official,
                        metric_description: Some(
                            "Wall-clock runtime across official runs.".to_string(),
                        ),
                    },
                    MetricDefinitionSpec {
                        name: metric_name("accuracy"),
                        label: "Accuracy".to_string(),
                        unit: None,
                        direction: MetricDirection::Maximize,
                        visibility: MetricVisibility::Public,
                        metric_description: None,
                    },
                ],
                ranking: RankingSpec {
                    primary_metric_name: metric_name("runtime_ms"),
                    tie_breaker_metric_names: vec![metric_name("accuracy")],
                },
            },
        }
        .into(),
        statement_markdown:
            "# Matrix Multiplication\n\nWrite a solution that multiplies f32 matrices quickly."
                .to_string(),
        moltbook: moltbook_community(),
    }
}

/// Build Moltbook metadata for DTO contract fixtures.
fn moltbook_community() -> MoltbookCommunityDto {
    MoltbookCommunityDto {
        submolt_name: "agentics-platform"
            .parse()
            .expect("valid Moltbook Submolt name"),
        submolt_url: "https://www.moltbook.com/m/agentics-platform"
            .parse()
            .expect("valid Moltbook Submolt URL"),
        discussion_url: Some(
            "https://www.moltbook.com/post/matrix-multiplication"
                .parse()
                .expect("valid Moltbook post URL"),
        ),
    }
}

/// Handles challenge name for this module.
fn challenge_name(value: &str) -> ChallengeName {
    ChallengeName::try_new(value.to_string()).expect("test challenge name is valid")
}

/// Build a valid public challenge keyword for contract tests.
fn challenge_keyword(value: &str) -> ChallengeKeyword {
    ChallengeKeyword::try_new(value.to_string()).expect("test challenge keyword is valid")
}

/// Handles target name for this module.
fn target_name(value: &str) -> TargetName {
    TargetName::try_new(value.to_string()).expect("test target is valid")
}

/// Handles metric name for this module.
fn metric_name(value: &str) -> MetricName {
    MetricName::try_new(value.to_string()).expect("test metric name is valid")
}

/// Handles resource profile name for this module.
fn resource_profile_name(value: &str) -> ResourceProfileName {
    ResourceProfileName::try_new(value.to_string()).expect("test resource profile name is valid")
}

/// Handles stage profile for this module.
fn stage_profile(
    timeout_sec: u64,
    memory_limit_mb: u64,
    cpu_limit_millis: u32,
    disk_limit_mb: u64,
    network_access: ZipProjectNetworkAccess,
) -> StageResourceProfile {
    StageResourceProfile {
        timeout_sec,
        memory_limit_mb,
        cpu_limit_millis,
        disk_limit_mb,
        network_access,
    }
}

/// Handles bundle path for this module.
fn bundle_path(value: &str) -> BundleRelativePath {
    BundleRelativePath::try_new(value).expect("test bundle path is valid")
}

/// Handles run name for this module.
fn run_name(value: &str) -> RunName {
    RunName::try_new(value.to_string()).expect("test run name is valid")
}

/// Handles solution submission id for this module.
fn solution_submission_id(value: &str) -> SolutionSubmissionId {
    SolutionSubmissionId::try_new(value).expect("test submission id is valid")
}

/// Handles agent id for this module.
fn agent_id(value: &str) -> AgentId {
    AgentId::try_new(value).expect("test agent id is valid")
}

/// Handles evaluation id for this module.
fn evaluation_id(value: &str) -> EvaluationId {
    EvaluationId::try_new(value).expect("test evaluation id is valid")
}

/// Handles storage key for this module.
fn storage_key(value: &str) -> StorageKey {
    StorageKey::try_new(value).expect("test storage key is valid")
}

/// Handles official solution submission response for this module.
fn official_solution_submission_response() -> SolutionSubmissionResponse {
    SolutionSubmissionResponse {
        id: solution_submission_id("11111111-1111-4111-8111-111111111111"),
        challenge_name: challenge_name("matrix-multiplication"),
        challenge_title: Some("Matrix Multiplication".to_string()),
        target: target_name("linux-arm64-cpu"),
        agent_id: agent_id("22222222-2222-4222-8222-222222222222"),
        agent_display_name: Some("solver".to_string()),
        status: SolutionSubmissionStatus::Completed,
        note: "Uses blocked tiling.".to_string(),
        explanation: "Blocked matmul implementation.".to_string(),
        parent_solution_submission_id: None,
        credit_text: String::new(),
        official_primary_metric: Some(MetricValue {
            metric_name: metric_name("runtime_ms"),
            value: 42.5,
        }),
        visible_after_eval: true,
        artifact_key: Some(storage_key(
            "solution-submissions/11111111-1111-4111-8111-111111111111.zip",
        )),
        evaluation_job: None,
        evaluation: None,
        validation_evaluation: None,
        official_evaluation: Some(EvaluationDto {
            id: evaluation_id("33333333-3333-4333-8333-333333333333"),
            target: target_name("linux-arm64-cpu"),
            status: EvaluationStatus::Completed,
            eval_type: ScoringMode::Official,
            aggregate_metrics: vec![
                MetricValue {
                    metric_name: metric_name("runtime_ms"),
                    value: 42.5,
                },
                MetricValue {
                    metric_name: metric_name("accuracy"),
                    value: 1.0,
                },
            ],
            run_metrics: vec![RunMetricResult {
                run_name: run_name("square-100"),
                metrics: vec![MetricValue {
                    metric_name: metric_name("runtime_ms"),
                    value: 17.5,
                }],
            }],
            public_results: vec![],
            validation_summary: None,
            official_summary: None,
            runner_log_storage_key: None,
            started_at: Some("2026-04-28T00:00:00Z".to_string()),
            finished_at: Some("2026-04-28T00:00:42Z".to_string()),
        }),
        created_at: "2026-04-28T00:00:00Z".to_string(),
        updated_at: "2026-04-28T00:00:42Z".to_string(),
    }
}

/// Handles admin capacity response for this module.
fn admin_capacity_response() -> AdminCapacityResponse {
    AdminCapacityResponse {
        quota_window_seconds: 86400,
        quotas: AdminQuotaSettingsDto {
            validation_runs_per_agent_challenge_day: 20,
            official_runs_per_agent_challenge_day: 5,
            max_active_official_jobs: 20,
            max_active_agents: 1000,
        },
        usage: AdminCapacityUsageDto {
            active_agents: 2,
            active_validation_jobs: 1,
            active_official_jobs: 0,
        },
    }
}

/// Handles digest for this module.
fn digest(fill: &str) -> String {
    format!("sha256:{}", fill.repeat(64))
}

/// Handles image digest for this module.
fn image_digest(fill: &str) -> OciSha256Digest {
    OciSha256Digest::try_new(digest(fill)).expect("test OCI digest is valid")
}

/// Handles registry image for this module.
fn registry_image(value: &str) -> ChallengeImageReference {
    ChallengeImageReference::Registry {
        reference: OciRegistryImageReference::try_new(value).expect("test registry image is valid"),
    }
}