forked from yvv/decision
WIP lot S : floor_amend retiré (le quorum le remplace), fixture de production sous tests/fixtures/seed-production-2026-11-02/, reprise des tests (api, inertia, ballots, objections, typos)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,17 @@ use ld_server::{AppState, CSRF_HEADER, CSRF_VALUE, Config, app, open_db, seed};
|
||||
use serde_json::{Value, json};
|
||||
use tower::ServiceExt;
|
||||
|
||||
/// The seed production runs on 2026-11-02 (3f10a0e): texts in force, seeds a minima.
|
||||
fn production_seed_dir() -> std::path::PathBuf {
|
||||
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/seed-production-2026-11-02")
|
||||
}
|
||||
|
||||
fn production_config() -> Config {
|
||||
let mut cfg = Config::for_tests();
|
||||
cfg.seed_dir = production_seed_dir();
|
||||
cfg
|
||||
}
|
||||
|
||||
struct Client {
|
||||
router: axum::Router,
|
||||
cookie: Option<String>,
|
||||
@@ -16,8 +27,19 @@ struct Client {
|
||||
|
||||
impl Client {
|
||||
async fn new() -> (Self, AppState) {
|
||||
Self::seeded(Config::for_tests()).await
|
||||
}
|
||||
|
||||
/// A base seeded as production is before its seed proposal amendment (ADR 0011):
|
||||
/// I1, E1 and E2 in force, seeds a minima — as they stay wherever it is refused.
|
||||
/// For the scenarios that need texts in force; the seed of today has none.
|
||||
async fn production() -> (Self, AppState) {
|
||||
Self::seeded(production_config()).await
|
||||
}
|
||||
|
||||
async fn seeded(cfg: Config) -> (Self, AppState) {
|
||||
let db = open_db("sqlite::memory:").await.expect("db");
|
||||
let state = AppState::new(Config::for_tests(), db).await.expect("state");
|
||||
let state = AppState::new(cfg, db).await.expect("state");
|
||||
seed::ensure(&state).await.expect("seed");
|
||||
(Self { router: app(state.clone()), cookie: None, set_cookie: None }, state)
|
||||
}
|
||||
@@ -88,7 +110,7 @@ async fn anonymous_sees_nothing_and_csrf_is_enforced() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_seed_a_minima_and_the_open_proposals() {
|
||||
async fn the_seed_proposals_and_the_open_proposals() {
|
||||
let (mut c, _) = Client::new().await;
|
||||
c.login("Chiara", false).await;
|
||||
let (_, groups) = c.call("GET", "/api/groups", None).await;
|
||||
@@ -99,16 +121,10 @@ async fn the_seed_a_minima_and_the_open_proposals() {
|
||||
let id = doc_id(&mut c, "monnaie-libre").await;
|
||||
let (s, doc) = c.call("GET", &format!("/api/docs/{id}"), None).await;
|
||||
assert_eq!(s, StatusCode::OK);
|
||||
let in_force: Vec<&str> = doc["units"]
|
||||
.as_array()
|
||||
.expect("units")
|
||||
.iter()
|
||||
.filter(|u| !u["inForce"].is_null())
|
||||
.filter_map(|u| u["code"].as_str())
|
||||
.collect();
|
||||
assert_eq!(in_force, ["I1", "E1", "E2"]);
|
||||
let e1 = &unit(&doc, "E1")["inForce"];
|
||||
assert_eq!(e1["seedMinimal"], true);
|
||||
// No article in force: I1, E1 and E2 are seed proposals (ADR 0011), open, put forward.
|
||||
assert!(doc["units"].as_array().expect("units").iter().all(|u| u["inForce"].is_null()));
|
||||
let e1 = &unit(&doc, "E1")["proposals"][0];
|
||||
assert_eq!((e1["seedProposal"].as_bool(), e1["status"].as_str()), (Some(true), Some("open")));
|
||||
assert_eq!(e1["tally"]["for"], 0);
|
||||
assert_eq!(doc["doc"]["voteFloor"], 50.0);
|
||||
assert_eq!(doc["doc"]["electorate"], 5745);
|
||||
@@ -119,8 +135,11 @@ async fn the_seed_a_minima_and_the_open_proposals() {
|
||||
let labels: Vec<&str> = e3["proposals"].as_array().expect("p").iter().filter_map(|p| p["label"].as_str()).collect();
|
||||
assert_eq!(labels, ["1.0.0", "0.4.0-draft"], "E3 and its 0.4.0 variant");
|
||||
assert_eq!(e3["inertia"], 3);
|
||||
// The two structural commitments start one level up (Yvv, 2026-10-30).
|
||||
assert_eq!((unit(&doc, "E1")["inertia"].as_u64(), unit(&doc, "E2")["inertia"].as_u64()), (Some(4), Some(4)));
|
||||
// The seed proposals start low (Yvv, 2026-11-02).
|
||||
let low = u64::from(ld_server::seed::SEED_PROPOSAL_LEVEL);
|
||||
for code in ["I1", "E1", "E2"] {
|
||||
assert_eq!(unit(&doc, code)["inertia"].as_u64(), Some(low), "{code}");
|
||||
}
|
||||
// Translations seeded.
|
||||
assert!(e1["translations"]["en"]["body"].as_str().expect("en").contains("commit"));
|
||||
}
|
||||
@@ -155,7 +174,7 @@ async fn adoption_in_the_test_group_and_publication_queued_only_where_published(
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_rival_replaces_the_seed_and_the_seed_returns_among_proposals() {
|
||||
let (mut a, _) = Client::new().await;
|
||||
let (mut a, _) = Client::production().await;
|
||||
a.login("Yvv", false).await;
|
||||
let mut b = a.with(None);
|
||||
b.login("Chiara", false).await;
|
||||
@@ -185,7 +204,7 @@ async fn a_rival_replaces_the_seed_and_the_seed_returns_among_proposals() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn editing_is_not_voting() {
|
||||
let (mut a, _) = Client::new().await;
|
||||
let (mut a, _) = Client::production().await;
|
||||
// An administrator of trustinWallet answers for the starting texts (no author).
|
||||
a.login("Yvv", true).await;
|
||||
let mut b = a.with(None);
|
||||
@@ -343,7 +362,7 @@ async fn editing_is_not_voting() {
|
||||
/// the full cycle: tests/objections.rs).
|
||||
#[tokio::test]
|
||||
async fn an_objection_holds_back_the_version_that_is_not_in_force() {
|
||||
let (mut a, _) = Client::new().await;
|
||||
let (mut a, _) = Client::production().await;
|
||||
a.login("Yvv", false).await;
|
||||
let mut b = a.with(None);
|
||||
b.login("Chiara", false).await;
|
||||
@@ -389,7 +408,8 @@ async fn inertia_change_is_voted_at_the_level_of_the_article() {
|
||||
let (_, again) = a.call("POST", &format!("/api/units/{uid}/inertia"), Some(json!({ "target": "max" }))).await;
|
||||
assert_eq!(again["id"], p.as_str());
|
||||
let (_, d) = a.call("GET", &format!("/api/proposals/{p}"), None).await;
|
||||
assert_eq!((d["proposal"]["inertiaTarget"].as_u64(), d["proposal"]["votedAtInertia"].as_u64()), (Some(5), Some(4)));
|
||||
let low = u64::from(ld_server::seed::SEED_PROPOSAL_LEVEL);
|
||||
assert_eq!((d["proposal"]["inertiaTarget"].as_u64(), d["proposal"]["votedAtInertia"].as_u64()), (Some(5), Some(low)));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -400,7 +420,7 @@ async fn previews_and_assistant() {
|
||||
let (_, v) = a.call("GET", &format!("/api/docs/{id}/preview?mode=all"), None).await;
|
||||
assert_eq!(v["units"].as_array().expect("u").len(), 33);
|
||||
let (_, v) = a.call("GET", &format!("/api/docs/{id}/preview?mode=wellrated"), None).await;
|
||||
assert_eq!(v["units"].as_array().expect("u").len(), 3, "nothing is well rated at zero votes");
|
||||
assert_eq!(v["units"].as_array().expect("u").len(), 0, "nothing in force, nothing well rated at zero votes");
|
||||
let (_, v) = a
|
||||
.call("POST", &format!("/api/docs/{id}/assist"), Some(json!({
|
||||
"text": "Je m'engage sur l'honneur à n'avoir jamais qu'un seul compte cocréateur de monnaie G1.\n\nJe m'engage à rester joignable par mes certifieurs.",
|
||||
@@ -741,7 +761,7 @@ async fn publication_writes_the_texts_in_force_to_the_repository() {
|
||||
std::fs::create_dir_all(&dir).expect("dir");
|
||||
let remote = dir.join("textes.git");
|
||||
assert!(Command::new("git").args(["init", "-q", "--bare"]).arg(&remote).status().expect("git").success());
|
||||
let mut cfg = Config::for_tests();
|
||||
let mut cfg = production_config();
|
||||
cfg.data_dir = dir.join("data");
|
||||
cfg.publish = Some(ld_server::config::Publish {
|
||||
remote: remote.display().to_string(),
|
||||
@@ -815,7 +835,7 @@ async fn a_refused_first_push_goes_out_again_and_a_new_empty_repository_receives
|
||||
path
|
||||
};
|
||||
let config = |remote: &std::path::Path| {
|
||||
let mut cfg = Config::for_tests();
|
||||
let mut cfg = production_config();
|
||||
cfg.data_dir = dir.join("data");
|
||||
cfg.publish = Some(ld_server::config::Publish {
|
||||
remote: remote.display().to_string(),
|
||||
@@ -906,12 +926,18 @@ fn today_seed() -> Value {
|
||||
serde_json::from_str(&std::fs::read_to_string(path).expect("seed")).expect("json")
|
||||
}
|
||||
|
||||
/// The seed production runs, I1 in force: the amendment of 30/10 is replayed on it.
|
||||
fn production_seed() -> Value {
|
||||
let path = production_seed_dir().join("acte-engagement-certification.json");
|
||||
serde_json::from_str(&std::fs::read_to_string(path).expect("seed")).expect("json")
|
||||
}
|
||||
|
||||
/// The seed as it was before 2026-10-30: the Préambule in force.
|
||||
fn first_seed_dir(tag: &str) -> std::path::PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!("ld-first-seed-{tag}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).expect("dir");
|
||||
let mut seed = today_seed();
|
||||
let mut seed = production_seed();
|
||||
let i1 = seed["units"].as_array_mut().expect("units").iter_mut().find(|u| u["code"] == "I1").expect("I1");
|
||||
for (lang, title, body) in PREAMBULE {
|
||||
i1["versions"][0]["title"][lang] = json!(title);
|
||||
@@ -931,8 +957,10 @@ async fn base_with_the_preambule(tag: &str, mut cfg: Config) -> (Client, AppStat
|
||||
(Client { router: app(state.clone()), cookie: None, set_cookie: None }, state)
|
||||
}
|
||||
|
||||
/// The same base, started again with today's seed (and its amendments).
|
||||
async fn restart(before: &AppState, cfg: Config) -> (Client, AppState) {
|
||||
/// The same base, started again with the seed of production (and its amendments): the
|
||||
/// seed of today then puts I1 forward (tests/seed_proposals.rs).
|
||||
async fn restart(before: &AppState, mut cfg: Config) -> (Client, AppState) {
|
||||
cfg.seed_dir = production_seed_dir();
|
||||
let state = AppState::new(cfg, before.db.clone()).await.expect("state");
|
||||
seed::ensure(&state).await.expect("seed");
|
||||
(Client { router: app(state.clone()), cookie: None, set_cookie: None }, state)
|
||||
@@ -953,10 +981,12 @@ fn outcomes(rows: &[(String, String, Option<String>, String)]) -> Vec<(&str, &st
|
||||
rows.iter().map(|(g, o, r, _)| (g.as_str(), o.as_str(), r.as_deref())).collect()
|
||||
}
|
||||
|
||||
/// I1 as it reads: its text in force, else its seed proposal (ADR 0011).
|
||||
async fn i1_of(c: &mut Client, group: &str) -> Value {
|
||||
let id = doc_id(c, group).await;
|
||||
let (_, doc) = c.call("GET", &format!("/api/docs/{id}"), None).await;
|
||||
unit(&doc, "I1")["inForce"].clone()
|
||||
let u = unit(&doc, "I1");
|
||||
if u["inForce"].is_null() { u["proposals"][0].clone() } else { u["inForce"].clone() }
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -967,13 +997,13 @@ async fn a_new_base_starts_with_the_raison_d_etre() {
|
||||
let i1 = i1_of(&mut c, group).await;
|
||||
assert_eq!(i1["title"], "Raison d'être");
|
||||
assert!(i1["body"].as_str().expect("body").starts_with(RAISON_D_ETRE), "{i1}");
|
||||
assert_eq!((i1["revision"].as_i64(), i1["seedMinimal"].as_bool()), (Some(1), Some(true)));
|
||||
assert_eq!((i1["revision"].as_i64(), i1["seedProposal"].as_bool()), (Some(1), Some(true)));
|
||||
for (lang, title) in [("en", "Purpose"), ("es", "Razón de ser")] {
|
||||
let tr = &i1["translations"][lang];
|
||||
assert_eq!((tr["title"].as_str(), tr["stale"].as_bool()), (Some(title), Some(false)), "{lang}");
|
||||
}
|
||||
}
|
||||
// Born with the text: nothing to replace, and it is said once.
|
||||
// Born with the text, put forward: nothing to replace, and it is said once.
|
||||
assert_eq!(outcomes(&decisions(&state).await), [("essai", "present", None), ("monnaie-libre", "present", None)]);
|
||||
}
|
||||
|
||||
@@ -986,7 +1016,8 @@ async fn the_shipped_amendment_goes_from_the_preambule_to_the_seed_text() {
|
||||
let seed = today_seed();
|
||||
let i1 = seed["units"].as_array().expect("units").iter().find(|u| u["code"] == "I1").expect("I1");
|
||||
let v = &i1["versions"][0];
|
||||
assert_eq!(v["status"], "in_force");
|
||||
// Today the starting text is a seed proposal (ADR 0011); the text is the same.
|
||||
assert_eq!((v["status"].as_str(), v["seedProposal"].as_bool()), (Some("open"), Some(true)));
|
||||
let (title, body) = (v["title"]["fr"].as_str().expect("title"), v["body"]["fr"].as_str().expect("body"));
|
||||
assert_eq!(ld_server::seed_amend::fingerprint(title, body), a.to, "the text of the seed today");
|
||||
}
|
||||
@@ -999,7 +1030,7 @@ async fn a_seed_amendment_replaces_an_untouched_preambule_once_and_republishes_i
|
||||
std::fs::create_dir_all(&dir).expect("dir");
|
||||
let remote = dir.join("textes.git");
|
||||
assert!(Command::new("git").args(["init", "-q", "--bare"]).arg(&remote).status().expect("git").success());
|
||||
let mut cfg = Config::for_tests();
|
||||
let mut cfg = production_config();
|
||||
cfg.data_dir = dir.join("data");
|
||||
cfg.publish = Some(ld_server::config::Publish {
|
||||
remote: remote.display().to_string(),
|
||||
|
||||
Reference in New Issue
Block a user