From: Ian Jackson Date: Fri, 26 Feb 2021 23:19:26 +0000 (+0000) Subject: apitest: Set positions of library load markers X-Git-Tag: otter-0.4.0~345 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a84e25a01b80ba17149c6291bd8ed9666de9e4f9;p=otter.git apitest: Set positions of library load markers Signed-off-by: Ian Jackson --- diff --git a/apitest.rs b/apitest.rs index 4fbd060b..a367ddc2 100644 --- a/apitest.rs +++ b/apitest.rs @@ -19,6 +19,7 @@ pub use arrayvec::ArrayVec; pub use boolinator::Boolinator; pub use fehler::{throw, throws}; pub use if_chain::if_chain; +pub use itertools::izip; pub use log::{debug, error, info, trace, warn}; pub use log::{log, log_enabled}; pub use nix::unistd::LinkatFlags; @@ -61,14 +62,15 @@ pub use otter::commands::{MgmtGameInstruction, MgmtGameResponse}; pub use otter::commands::{MgmtGameUpdateMode}; pub use otter::config::*; pub use otter::{deref_to_field, deref_to_field_mut}; -pub use otter::gamestate::{self, Generation, PlayerId}; +pub use otter::gamestate::{self, Generation, PieceId, PlayerId}; pub use otter::global::InstanceName; pub use otter::mgmtchannel::MgmtChannel; pub use otter::slotmap_slot_idx::KeyDataExt; -pub use otter::spec::{Coord, GameSpec, Pos, PosC}; +pub use otter::spec::{Coord, GameSpec, Pos, PosC, RawToken}; pub use otter::toml_de; pub use otter::ui::{AbbrevPresentationLayout, PresentationLayout}; pub use otter::ui::player_num_dasharray; +pub use otter::updates::RawClientSequence; pub use otter::utils::*; pub const MS: time::Duration = time::Duration::from_millis(1); diff --git a/apitest/at-otter.rs b/apitest/at-otter.rs index 62a470be..cd61d337 100644 --- a/apitest/at-otter.rs +++ b/apitest/at-otter.rs @@ -22,8 +22,12 @@ struct Player { } struct Session { + pub ctoken: RawToken, + pub gen: Generation, + pub cseq: RawClientSequence, pub dom: scraper::Html, pub updates: UnixStream, + pub client: reqwest::blocking::Client, } mod scraper_ext { @@ -123,7 +127,13 @@ impl Ctx { eprintln!("copy_to'd!"); }); - Session { dom: session, updates: reader } + Session { + client, gen, + cseq: 42, + ctoken: RawToken(ctoken.to_string()), + dom: session, + updates: reader, + } } } @@ -156,6 +166,25 @@ impl Session { }) .collect() } + + #[throws(AE)] + fn api_piece_op(&mut self, su: &SetupCore, piece: &str, + opname: &str, op: serde_json::Value) { + self.cseq += 1; + let cseq = self.cseq; + + let resp = self.client.post(&su.ds.also(&[("opname",opname)]) + .subst("@url@/_/api/@opname@")?) + .json(&json!({ + "ctoken": self.ctoken, + "piece": piece, + "gen": self.gen, + "cseq": cseq, + "op": op, + })) + .send()?; + ensure_eq!(resp.status(), 200); + } } impl Ctx { @@ -179,7 +208,7 @@ impl Ctx { ensure_eq!(add_err.downcast::()?.0.code(), Some(EXIT_NOTFOUND)); - let session = self.connect_player(&self.alice)?; + let mut session = self.connect_player(&self.alice)?; let pieces = session.pieces()?; dbg!(&pieces); let llm = pieces.into_iter() @@ -187,9 +216,12 @@ impl Ctx { .collect::>(); let llm: [_;2] = llm.into_inner().unwrap(); dbg!(&llm); - // xxx find load markers ids - // xxx find load markers' locations + for (llm, pos) in izip!(&llm, [PosC([5,5]), PosC([50,25])].iter()) { + session.api_piece_op(&self.su, &llm.id, "grab", json!({}))?; + session.api_piece_op(&self.su, &llm.id, "m", json![pos.0])?; + } + // xxx send api requests to move markers // run library-add again } diff --git a/src/updates.rs b/src/updates.rs index 43f54a29..7774153e 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -11,9 +11,11 @@ use crate::prelude::*; // ---------- newtypes, type aliases, basic definitions ---------- +pub type RawClientSequence = u64; + #[derive(Debug,Copy,Clone,Eq,PartialEq,Deserialize,Serialize)] #[serde(transparent)] -pub struct ClientSequence(u64); +pub struct ClientSequence(RawClientSequence); // ---------- from manamgenet operations ----------