Dever v0.0.2

This commit is contained in:
Codex committed 2026-11-27 06:03:56 +00:00
commit e6e175ebcf
816 files changed
+120349

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
use super::*;
#[test]
fn provider_verify_restricts_the_entire_call_graph_to_global_reads() {
let root = project(
"verify-global-contract",
r#"
type Identity { id: Text, user_id: demo.user.data.id?, tenant_id: data.id? }
flow lookup(session: Text) (out: data.Article?)
| step | kind | do |
| out | data | data.first(title == session) |
flow verify(claims: dever.auth.Claims) (identity: Identity)
| step | kind | do |
| session | flow | lookup(claims.session) |
| - | check | session != null else Unauthorized |
| identity | calc | Identity {id = claims.subject, user_id = null, tenant_id = null} |
"#,
);
let model = root.join("module/demo/article/data/main.dever");
write_source(&model, "global type Article {title:Text}").unwrap();
analyze(&root);
write_source(&model, "type Article {title:Text}").unwrap();
let loaded = Project::load(&root).unwrap();
let error = program::check(&loaded.declarations, &loaded.modules)
.err()
.unwrap();
assert!(error.message.contains("tenant Model"), "{error:?}");
write_source(&model, "global type Article {title:Text}").unwrap();
for operation in [
"| - | data | data.create({title = claims.subject}) |",
"| - | flow | dever.time.sleep(1) |",
"| - | flow | dever.io.println(claims.subject) |",
] {
let app = format!(
"type Identity {{ id: Text, user_id: demo.user.data.id?, tenant_id: data.id? }}\nflow verify(claims: dever.auth.Claims) (identity: Identity)\n| step | kind | do |\n{operation}\n| identity | calc | Identity {{id=claims.subject,user_id=null,tenant_id=null}} |\n"
);
write_source(root.join("module/demo/article/app/main.dever"), app).unwrap();
let loaded = Project::load(&root).unwrap();
let error = program::check(&loaded.declarations, &loaded.modules)
.err()
.unwrap();
assert_eq!(error.code, "C014", "{operation}: {error:?}");
assert!(error.message.contains("Provider verify"), "{error:?}");
}
for identity in [
"type Identity {id:Text,user_id:Int?,tenant_id:Int?}",
"type Identity {id:Text,user_id:demo.user.data.id?,tenant_id:data.id?,extra:Text?}",
"type Identity {private id:Text,user_id:demo.user.data.id?,tenant_id:data.id?}",
] {
let app = format!(
"{identity}\nflow verify(claims: dever.auth.Claims) (identity: Identity)\n| step | kind | do |\n| identity | calc | Identity {{id=claims.subject,user_id=null,tenant_id=null{} }} |\n",
if identity.contains("extra") {
",extra=null"
} else {
""
}
);
write_source(root.join("module/demo/article/app/main.dever"), app).unwrap();
let loaded = Project::load(&root).unwrap();
assert!(
program::check(&loaded.declarations, &loaded.modules).is_err(),
"{identity}"
);
}
}