interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-allen / tests / subject_decode_test.rs

91 lines · 2845 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Decoder refusals (unsupported dialect, damage) and the id/derivation rules.
17mod support;
18use aien_allen::subject_v0::{decode, object_id};
19use support::*;
20
21fn good() -> Vec<u8> {
22 encode(&fx("a"), 1, [0; 32], [7, 1000])
23}
24
25#[test]
26fn good_object_decodes() {
27 let s = decode(&good()).unwrap();
28 assert_eq!(s.sequence, 1);
29 assert_eq!(s.intents.len(), 1);
30 assert_eq!(s.intents[0].payload, [7, 1000]);
31}
32
33#[test]
34fn unsupported_dialect_is_refused() {
35 let mut b = good();
36 b[8] = 1; // format version 1
37 assert!(decode(&b).unwrap_err().contains("version"));
38 let mut b = good();
39 b[..8].copy_from_slice(b"AIENSUBX");
40 assert!(decode(&b).unwrap_err().contains("magic"));
41 // unknown intent kind (offset: header 16 + fixed body 184 = 200; id 32, supersedes 32, kind at +64)
42 let mut b = good();
43 b[200 + 64] = 2;
44 assert!(decode(&b).is_err());
45 // unknown origin
46 let mut b = good();
47 b[16 + 32 * 5 + 8] = 9;
48 assert!(decode(&b).unwrap_err().contains("origin"));
49}
50
51#[test]
52fn damage_is_refused() {
53 let g = good();
54 for n in 0..g.len() {
55 assert!(decode(&g[..n]).is_err(), "prefix {n}");
56 }
57 let mut b = g.clone();
58 b.push(0);
59 assert!(decode(&b).is_err());
60 // intent id must derive from content
61 let mut b = g.clone();
62 b[200 + 64 + 4 + 8 + 8] ^= 1; // payload[0]
63 assert!(decode(&b).unwrap_err().contains("derive"));
64}
65
66#[test]
67fn zero_provenance_and_zero_ids_refused() {
68 let mut f = fx("a");
69 f.provenance = [0; 32];
70 assert!(decode(&encode(&f, 1, [0; 32], [7, 1000]))
71 .unwrap_err()
72 .contains("provenance"));
73 let mut f = fx("a");
74 f.agent = [0; 32];
75 assert!(decode(&encode(&f, 1, [0; 32], [7, 1000])).is_err());
76 // sequence 2 with zero previous
77 assert!(decode(&encode(&fx("a"), 2, [0; 32], [7, 1000])).is_err());
78 // genesis naming a previous
79 assert!(decode(&encode(&fx("a"), 1, [9; 32], [7, 1000])).is_err());
80}
81
82#[test]
83fn object_id_depends_on_every_byte() {
84 let g = good();
85 let id = object_id(&g);
86 for i in (0..g.len()).step_by(7) {
87 let mut b = g.clone();
88 b[i] ^= 1;
89 assert_ne!(object_id(&b), id);
90 }
91}