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
//! Declaration lifecycle enums.
use serde::{Deserialize, Serialize};
/// Server-managed lifecycle state for a Card.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
#[cfg_attr(feature = "server", derive(utoipa::ToSchema))]
#[serde(rename_all = "snake_case")]
pub enum CardLifecycleStatus {
/// Declaration is waiting for artifact upload and verification.
Pending,
/// Card is available for use.
Active,
/// Card has been superseded by a newer version.
Deprecated,
/// Declaration failed and awaits cleanup or retry.
Failed,
/// Declaration expired before completion.
Expired,
/// Card was soft-deleted.
Deleted,
}
/// Result of a declaration write.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
#[cfg_attr(feature = "server", derive(utoipa::ToSchema))]
#[serde(rename_all = "snake_case")]
pub enum DeclarationOutcomeKind {
/// A new Card version was declared.
Declared,
/// The same idempotent request was replayed.
IdempotentNoop,
/// An active card with identical content already exists.
Deduplicated,
}
#[cfg(test)]
mod tests {
use super::{CardLifecycleStatus, DeclarationOutcomeKind};
use crate::error::WyrdError;
#[test]
fn lifecycle_enums_use_snake_case_wire_names() {
assert_eq!(
serde_json::to_string(&CardLifecycleStatus::Pending).unwrap(),
"\"pending\""
);
assert_eq!(
serde_json::to_string(&DeclarationOutcomeKind::IdempotentNoop).unwrap(),
"\"idempotent_noop\""
);
}
#[test]
fn registry_error_variants_expose_stable_public_codes() {
// Task 01 requires every registry-facing WyrdError variant to expose a
// stable public code so language-agnostic clients can route on it. The
// review flagged this as a missing verification gate (V-006); each
// entry below assert-locks the (code, status) pair for one variant.
let cases: &[(WyrdError, &str, u16)] = &[
(
WyrdError::RegistryInvalidCardSpec {
message: "bad".into(),
details: serde_json::json!({}),
},
"WYRD_REGISTRY_400_INVALID_CARD_SPEC",
400,
),
(
WyrdError::RegistryInvalidVersionBlock {
message: "bad".into(),
details: serde_json::json!({}),
},
"WYRD_REGISTRY_400_INVALID_VERSION_BLOCK",
400,
),
(
WyrdError::RegistrySpecTooLarge {
message: "too large".into(),
details: serde_json::json!({}),
},
"WYRD_REGISTRY_400_SPEC_TOO_LARGE",
400,
),
(
WyrdError::RegistryCardNotFound {
message: "missing".into(),
details: serde_json::json!({}),
},
"WYRD_REGISTRY_404_CARD_NOT_FOUND",
404,
),
(
WyrdError::RegistrySpecDrift {
message: "drift".into(),
details: serde_json::json!({}),
},
"WYRD_REGISTRY_409_SPEC_DRIFT",
409,
),
(
WyrdError::RegistryIdempotencyConflict {
message: "conflict".into(),
details: serde_json::json!({}),
},
"WYRD_REGISTRY_409_IDEMPOTENCY_CONFLICT",
409,
),
(
WyrdError::RegistryOperationExpired {
message: "expired".into(),
details: serde_json::json!({}),
},
"WYRD_REGISTRY_410_OPERATION_EXPIRED",
410,
),
(
WyrdError::RegistryArtifactVerifyFailed {
message: "hash mismatch".into(),
details: serde_json::json!({}),
},
"WYRD_REGISTRY_507_ARTIFACT_VERIFY_FAILED",
507,
),
];
for (error, expected_code, expected_status) in cases {
assert_eq!(error.code(), *expected_code);
assert_eq!(error.status(), *expected_status);
}
}
}