| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
use axum::body::Body; |
| 6 |
use axum::http::{header, Request, StatusCode}; |
| 7 |
use http_body_util::BodyExt; |
| 8 |
use oxy_core::protocol::{open_remote, RemoteOptions}; |
| 9 |
use oxy_core::repo::Repo; |
| 10 |
use oxygenhub::config::Config; |
| 11 |
use oxygenhub::repos::RepoName; |
| 12 |
use oxygenhub::{db, Shared}; |
| 13 |
use std::path::Path; |
| 14 |
use tower::ServiceExt; |
| 15 |
|
| 16 |
const ROOTFS: &str = "36fc4e3238044e424219a2b9002bf61bbe1805fec14d52cf37e17fae77c9ff16"; |
| 17 |
|
| 18 |
fn hermetic() { |
| 19 |
static ONCE: std::sync::Once = std::sync::Once::new(); |
| 20 |
static DIR: std::sync::OnceLock<tempfile::TempDir> = std::sync::OnceLock::new(); |
| 21 |
ONCE.call_once(|| { |
| 22 |
let d = tempfile::tempdir().unwrap(); |
| 23 |
std::env::set_var("OXY_HOME", d.path()); |
| 24 |
DIR.set(d).ok(); |
| 25 |
}); |
| 26 |
} |
| 27 |
|
| 28 |
fn write(root: &Path, rel: &str, content: &str) { |
| 29 |
let p = root.join(rel); |
| 30 |
std::fs::create_dir_all(p.parent().unwrap()).unwrap(); |
| 31 |
std::fs::write(p, content).unwrap(); |
| 32 |
} |
| 33 |
|
| 34 |
struct Hub { |
| 35 |
app: Shared, |
| 36 |
base: String, |
| 37 |
_dir: tempfile::TempDir, |
| 38 |
} |
| 39 |
|
| 40 |
async fn hub() -> Hub { |
| 41 |
hermetic(); |
| 42 |
let dir = tempfile::tempdir().unwrap(); |
| 43 |
let mut config = Config::load(dir.path()).unwrap(); |
| 44 |
config.auth.push_tokens = vec!["site".into()]; |
| 45 |
config.flow.runner_tokens = vec!["runner-secret".into()]; |
| 46 |
config.flow.repos = vec!["andy/*".into()]; |
| 47 |
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); |
| 48 |
let port = listener.local_addr().unwrap().port(); |
| 49 |
config.server.base_url = format!("http://127.0.0.1:{port}"); |
| 50 |
let app = oxygenhub::build(config).await.unwrap(); |
| 51 |
let router = oxygenhub::router(app.clone()); |
| 52 |
tokio::spawn(async move { axum::serve(listener, router).await.unwrap() }); |
| 53 |
Hub { app, base: format!("http://127.0.0.1:{port}"), _dir: dir } |
| 54 |
} |
| 55 |
|
| 56 |
async fn call(app: &Shared, method: &str, path: &str, bearer: Option<&str>, json: Option<String>) -> (StatusCode, String) { |
| 57 |
let mut req = Request::builder().method(method).uri(path); |
| 58 |
if let Some(b) = bearer { |
| 59 |
req = req.header(header::AUTHORIZATION, format!("Bearer {b}")); |
| 60 |
} |
| 61 |
let body = match json { |
| 62 |
Some(j) => { |
| 63 |
req = req.header(header::CONTENT_TYPE, "application/json"); |
| 64 |
Body::from(j) |
| 65 |
} |
| 66 |
None => Body::empty(), |
| 67 |
}; |
| 68 |
let res = oxygenhub::router(app.clone()).oneshot(req.body(body).unwrap()).await.unwrap(); |
| 69 |
let status = res.status(); |
| 70 |
let bytes = res.into_body().collect().await.unwrap().to_bytes(); |
| 71 |
(status, String::from_utf8_lossy(&bytes).into_owned()) |
| 72 |
} |
| 73 |
|
| 74 |
async fn claim(app: &Shared) -> Option<serde_json::Value> { |
| 75 |
let (st, body) = |
| 76 |
call(app, "POST", "/api/v1/flow/claim", Some("runner-secret"), Some(r#"{"runner":"test-1","runtimes":["microvm"]}"#.into())).await; |
| 77 |
match st { |
| 78 |
StatusCode::NO_CONTENT => None, |
| 79 |
StatusCode::OK => Some(serde_json::from_str(&body).unwrap()), |
| 80 |
other => panic!("claim: {other} {body}"), |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
fn receipt(job: &str, pipeline_hash: &str, exit: u32) -> serde_json::Value { |
| 85 |
serde_json::json!({ |
| 86 |
"job_name": job, "pipeline_hash": pipeline_hash, "scope_tree_hash": "11".repeat(32), |
| 87 |
"inputs": [], "environment": "22".repeat(32), "outputs": [], "exit_code": exit, "duration_ms": 640 |
| 88 |
}) |
| 89 |
} |
| 90 |
|
| 91 |
async fn finish(app: &Shared, id: i64, body: serde_json::Value) -> StatusCode { |
| 92 |
call(app, "POST", &format!("/api/v1/flow/jobs/{id}/finish"), Some("runner-secret"), Some(body.to_string())).await.0 |
| 93 |
} |
| 94 |
|
| 95 |
async fn create(app: &Shared, owner: &str, name: &str) { |
| 96 |
app.repos.create(&RepoName::parse(&format!("{owner}/{name}")).unwrap(), None).unwrap(); |
| 97 |
db::repos::create(&app.db, owner, name, "", hub_api::Visibility::Public).await.unwrap(); |
| 98 |
} |
| 99 |
|
| 100 |
fn client(url: &str, work: &Path) -> Repo { |
| 101 |
let mut c = Repo::init(work).unwrap(); |
| 102 |
c.config.set("remote.origin.url", url).unwrap(); |
| 103 |
c.config.set("remote.origin.token", "site").unwrap(); |
| 104 |
c.save_config().unwrap(); |
| 105 |
c |
| 106 |
} |
| 107 |
|
| 108 |
fn pipeline(extra: &str) -> String { |
| 109 |
format!( |
| 110 |
"schema-version 1\nsandbox \"alpine\" {{\n rootfs \"cas://blob/{ROOTFS}\"\n}}\njob \"build\" {{\n sandbox \"alpine\"\n exec \"make\"\n}}\njob \"test\" {{\n sandbox \"alpine\"\n depends-on \"build\"\n exec \"sh\" \"-eu\" \"test.sh\"\n}}\njob \"lint\" {{\n sandbox \"alpine\"\n exec \"true\"\n}}\n{extra}" |
| 111 |
) |
| 112 |
} |
| 113 |
|
| 114 |
async fn runs_of(app: &Shared, owner: &str, name: &str) -> Vec<db::flow::Run> { |
| 115 |
let row = db::repos::get(&app.db, owner, name).await.unwrap().unwrap(); |
| 116 |
for _ in 0..100 { |
| 117 |
let r = db::flow::runs(&app.db, row.id, 10, None).await.unwrap(); |
| 118 |
if !r.is_empty() { |
| 119 |
return r; |
| 120 |
} |
| 121 |
tokio::time::sleep(std::time::Duration::from_millis(50)).await; |
| 122 |
} |
| 123 |
vec![] |
| 124 |
} |
| 125 |
|
| 126 |
#[tokio::test(flavor = "multi_thread")] |
| 127 |
async fn a_push_runs_the_pipeline_through_a_runner() { |
| 128 |
let h = hub().await; |
| 129 |
create(&h.app, "andy", "demo").await; |
| 130 |
create(&h.app, "andy", "secret").await; |
| 131 |
create(&h.app, "other", "plain").await; |
| 132 |
let url = format!("{}/andy/demo", h.base); |
| 133 |
let work = tempfile::tempdir().unwrap(); |
| 134 |
let mut c = client(&url, work.path()); |
| 135 |
write(work.path(), ".flow/pipeline.kdl", &pipeline("")); |
| 136 |
write(work.path(), "test.sh", "echo ok\n"); |
| 137 |
c.snapshot("test").unwrap(); |
| 138 |
c.commit("Add a pipeline", &[]).unwrap(); |
| 139 |
assert!(c.push("origin", false).unwrap().iter().all(|r| r.ok)); |
| 140 |
|
| 141 |
|
| 142 |
let runs = runs_of(&h.app, "andy", "demo").await; |
| 143 |
assert_eq!(runs.len(), 1); |
| 144 |
let run = &runs[0]; |
| 145 |
assert_eq!((run.bookmark.as_str(), run.status.as_str(), run.actor.as_str()), ("main", "queued", "site token")); |
| 146 |
assert_eq!(run.pipeline_hash.len(), 64); |
| 147 |
let jobs = db::flow::jobs(&h.app.db, run.id).await.unwrap(); |
| 148 |
assert_eq!(jobs.iter().map(|j| (j.name.as_str(), j.depth)).collect::<Vec<_>>(), [("build", 0), ("lint", 0), ("test", 1)]); |
| 149 |
let checks = db::hooks::checks_for_state(&h.app.db, run.repo_id, &run.state).await.unwrap(); |
| 150 |
assert_eq!( |
| 151 |
checks.iter().map(|c| (c.name.as_str(), c.status.as_str())).collect::<Vec<_>>(), |
| 152 |
[("flow/build", "queued"), ("flow/lint", "queued"), ("flow/test", "queued")] |
| 153 |
); |
| 154 |
|
| 155 |
|
| 156 |
assert_eq!( |
| 157 |
call(&h.app, "POST", "/api/v1/flow/claim", Some("site"), Some(r#"{"runner":"x","runtimes":["microvm"]}"#.into())).await.0, |
| 158 |
StatusCode::UNAUTHORIZED |
| 159 |
); |
| 160 |
assert_eq!( |
| 161 |
call(&h.app, "POST", "/api/v1/flow/claim", None, Some(r#"{"runner":"x","runtimes":["microvm"]}"#.into())).await.0, |
| 162 |
StatusCode::UNAUTHORIZED |
| 163 |
); |
| 164 |
|
| 165 |
let (st, _) = |
| 166 |
call(&h.app, "POST", "/api/v1/flow/claim", Some("runner-secret"), Some(r#"{"runner":"x","runtimes":["wasm"]}"#.into())).await; |
| 167 |
assert_eq!(st, StatusCode::NO_CONTENT); |
| 168 |
|
| 169 |
|
| 170 |
let a = claim(&h.app).await.unwrap(); |
| 171 |
let b = claim(&h.app).await.unwrap(); |
| 172 |
assert_eq!((a["job"]["name"].as_str(), b["job"]["name"].as_str()), (Some("build"), Some("lint"))); |
| 173 |
assert!(claim(&h.app).await.is_none(), "test waits for build"); |
| 174 |
assert_eq!(a["repo"], "andy/demo"); |
| 175 |
assert_eq!(a["clone_url"], url.as_str()); |
| 176 |
assert_eq!(a["sandbox"]["rootfs"], ROOTFS); |
| 177 |
assert_eq!(a["job"]["exec"], serde_json::json!(["make"])); |
| 178 |
assert_eq!(a["timeout_s"], 3600); |
| 179 |
let heads: Vec<String> = a["heads"].as_array().unwrap().iter().map(|v| v.as_str().unwrap().to_string()).collect(); |
| 180 |
assert_eq!(heads.join("+"), run.heads); |
| 181 |
let checks = db::hooks::checks_for_state(&h.app.db, run.repo_id, &run.state).await.unwrap(); |
| 182 |
assert_eq!(checks.iter().find(|c| c.name == "flow/build").unwrap().status, "running"); |
| 183 |
|
| 184 |
|
| 185 |
let token = a["token"].as_str().unwrap().to_string(); |
| 186 |
assert!(token.starts_with("flowjob_")); |
| 187 |
let opts = RemoteOptions { token: Some(token.clone()), ca: None, repo_id: None }; |
| 188 |
open_remote(&url, &opts).unwrap().refs().unwrap(); |
| 189 |
assert!(open_remote(&format!("{}/andy/secret", h.base), &opts).unwrap().refs().is_err(), "another repository"); |
| 190 |
let bad = RemoteOptions { token: Some("flowjob_00".into()), ca: None, repo_id: None }; |
| 191 |
assert!(open_remote(&url, &bad).unwrap().refs().is_err(), "an unknown job token"); |
| 192 |
|
| 193 |
c.config.set("remote.origin.token", &token).unwrap(); |
| 194 |
c.save_config().unwrap(); |
| 195 |
write(work.path(), "more.txt", "x\n"); |
| 196 |
c.snapshot("test").unwrap(); |
| 197 |
c.commit("More", &[]).unwrap(); |
| 198 |
let pushed = c.push("origin", false); |
| 199 |
assert!(pushed.is_err() || pushed.unwrap().iter().all(|r| !r.ok), "a job token cannot push"); |
| 200 |
c.config.set("remote.origin.token", "site").unwrap(); |
| 201 |
c.save_config().unwrap(); |
| 202 |
|
| 203 |
|
| 204 |
let a_id = a["job_id"].as_i64().unwrap(); |
| 205 |
let b_id = b["job_id"].as_i64().unwrap(); |
| 206 |
let log = serde_json::json!({ "records": [ |
| 207 |
{ "t": 5, "stream": "flow", "text": "booting" }, |
| 208 |
{ "t": 120, "stream": "out", "text": "cc -o demo demo.c" }, |
| 209 |
{ "t": 130, "stream": "weird", "text": "x".repeat(20_000) }, |
| 210 |
]}); |
| 211 |
assert_eq!( |
| 212 |
call(&h.app, "POST", &format!("/api/v1/flow/jobs/{a_id}/log"), Some("runner-secret"), Some(log.to_string())).await.0, |
| 213 |
StatusCode::NO_CONTENT |
| 214 |
); |
| 215 |
let lines = db::flow::log(&h.app.db, a_id, 0, 100).await.unwrap(); |
| 216 |
assert_eq!(lines.len(), 3); |
| 217 |
assert_eq!((lines[2].stream.as_str(), lines[2].text.len()), ("console", 16 * 1024), "streams are known ones, text is capped"); |
| 218 |
let ph = a["pipeline_hash"].as_str().unwrap(); |
| 219 |
assert_eq!( |
| 220 |
finish(&h.app, a_id, serde_json::json!({ "exit_code": 0, "duration_ms": 700, "receipt": receipt("lint", ph, 0) })).await, |
| 221 |
StatusCode::BAD_REQUEST, |
| 222 |
"a receipt for another job" |
| 223 |
); |
| 224 |
assert_eq!( |
| 225 |
finish(&h.app, a_id, serde_json::json!({ "exit_code": 0, "duration_ms": 700, "receipt": receipt("build", ph, 0) })).await, |
| 226 |
StatusCode::NO_CONTENT |
| 227 |
); |
| 228 |
assert_eq!(finish(&h.app, a_id, serde_json::json!({ "exit_code": 0, "duration_ms": 700 })).await, StatusCode::CONFLICT, "only once"); |
| 229 |
assert!(open_remote(&url, &opts).unwrap().refs().is_err(), "the token ends with its job"); |
| 230 |
assert_eq!( |
| 231 |
finish(&h.app, b_id, serde_json::json!({ "exit_code": 0, "duration_ms": 300, "receipt": receipt("lint", ph, 0) })).await, |
| 232 |
StatusCode::NO_CONTENT |
| 233 |
); |
| 234 |
let t = claim(&h.app).await.unwrap(); |
| 235 |
assert_eq!(t["job"]["name"], "test"); |
| 236 |
let t_id = t["job_id"].as_i64().unwrap(); |
| 237 |
assert_eq!( |
| 238 |
finish(&h.app, t_id, serde_json::json!({ "exit_code": 3, "duration_ms": 500, "receipt": receipt("test", ph, 3) })).await, |
| 239 |
StatusCode::NO_CONTENT |
| 240 |
); |
| 241 |
|
| 242 |
let run = db::flow::run_by_id(&h.app.db, run.id).await.unwrap().unwrap(); |
| 243 |
assert_eq!(run.status, "failed"); |
| 244 |
let jobs = db::flow::jobs(&h.app.db, run.id).await.unwrap(); |
| 245 |
let build = jobs.iter().find(|j| j.name == "build").unwrap(); |
| 246 |
assert_eq!((build.status.as_str(), build.exit_code, build.receipt_hash.len()), ("passed", Some(0), 64)); |
| 247 |
assert_eq!(jobs.iter().find(|j| j.name == "test").unwrap().status, "failed"); |
| 248 |
let checks = db::hooks::checks_for_state(&h.app.db, run.repo_id, &run.state).await.unwrap(); |
| 249 |
assert_eq!( |
| 250 |
checks.iter().map(|c| (c.name.as_str(), c.status.as_str())).collect::<Vec<_>>(), |
| 251 |
[("flow/build", "passed"), ("flow/lint", "passed"), ("flow/test", "failed")] |
| 252 |
); |
| 253 |
assert!(checks[2].summary.contains("exit 3") && checks[2].url.ends_with(&format!("/andy/demo/flow/{}", run.id))); |
| 254 |
|
| 255 |
|
| 256 |
let (st, list) = call(&h.app, "GET", "/andy/demo/flow", None, None).await; |
| 257 |
assert_eq!(st, StatusCode::OK); |
| 258 |
assert!(list.contains(&format!("/andy/demo/flow/{}", run.id)) && list.contains("st-failed"), "{list}"); |
| 259 |
let (st, page) = call(&h.app, "GET", &format!("/andy/demo/flow/{}", run.id), None, None).await; |
| 260 |
assert_eq!(st, StatusCode::OK); |
| 261 |
assert!(page.contains("<svg class=\"flow-graph\""), "graph"); |
| 262 |
assert_eq!(page.matches("data-job-node=").count(), 3); |
| 263 |
assert_eq!(page.matches("<path class=\"edge").count(), 1, "one dependency edge"); |
| 264 |
assert!(page.contains("cc -o demo demo.c"), "log shown"); |
| 265 |
assert!(!page.contains("data-flow-live"), "a finished run does not poll"); |
| 266 |
let (st, live) = call(&h.app, "GET", &format!("/andy/demo/flow/{}/live?after={a_id}:1", run.id), None, None).await; |
| 267 |
assert_eq!(st, StatusCode::OK); |
| 268 |
let live: serde_json::Value = serde_json::from_str(&live).unwrap(); |
| 269 |
assert_eq!(live["status"], "failed"); |
| 270 |
let build_live = live["jobs"].as_array().unwrap().iter().find(|j| j["name"] == "build").unwrap().clone(); |
| 271 |
assert_eq!(build_live["lines"].as_array().unwrap().len(), 2, "lines after seq 1"); |
| 272 |
assert_eq!(call(&h.app, "GET", "/andy/demo/flow/999", None, None).await.0, StatusCode::NOT_FOUND); |
| 273 |
|
| 274 |
|
| 275 |
write(work.path(), ".flow/pipeline.kdl", &pipeline("")); |
| 276 |
write(work.path(), "test.sh", "echo changed\n"); |
| 277 |
c.snapshot("test").unwrap(); |
| 278 |
c.commit("Change the test", &[]).unwrap(); |
| 279 |
assert!(c.push("origin", false).unwrap().iter().all(|r| r.ok)); |
| 280 |
let mut second = None; |
| 281 |
for _ in 0..100 { |
| 282 |
let r = runs_of(&h.app, "andy", "demo").await; |
| 283 |
if r.len() == 2 { |
| 284 |
second = Some(r[0].clone()); |
| 285 |
break; |
| 286 |
} |
| 287 |
tokio::time::sleep(std::time::Duration::from_millis(50)).await; |
| 288 |
} |
| 289 |
let second = second.expect("a second run"); |
| 290 |
let x = claim(&h.app).await.unwrap(); |
| 291 |
let y = claim(&h.app).await.unwrap(); |
| 292 |
let (build_id, lint_id) = if x["job"]["name"] == "build" { |
| 293 |
(x["job_id"].as_i64().unwrap(), y["job_id"].as_i64().unwrap()) |
| 294 |
} else { |
| 295 |
(y["job_id"].as_i64().unwrap(), x["job_id"].as_i64().unwrap()) |
| 296 |
}; |
| 297 |
assert_eq!( |
| 298 |
finish(&h.app, build_id, serde_json::json!({ "exit_code": null, "duration_ms": 10, "error": "rootfs is not on this runner" })) |
| 299 |
.await, |
| 300 |
StatusCode::NO_CONTENT |
| 301 |
); |
| 302 |
assert_eq!(finish(&h.app, lint_id, serde_json::json!({ "exit_code": 0, "duration_ms": 10 })).await, StatusCode::NO_CONTENT); |
| 303 |
assert!(claim(&h.app).await.is_none(), "test was skipped"); |
| 304 |
let jobs = db::flow::jobs(&h.app.db, second.id).await.unwrap(); |
| 305 |
assert_eq!( |
| 306 |
jobs.iter().map(|j| (j.name.as_str(), j.status.as_str())).collect::<Vec<_>>(), |
| 307 |
[("build", "error"), ("lint", "passed"), ("test", "skipped")] |
| 308 |
); |
| 309 |
assert_eq!(db::flow::run_by_id(&h.app.db, second.id).await.unwrap().unwrap().status, "failed"); |
| 310 |
|
| 311 |
|
| 312 |
write(work.path(), ".flow/pipeline.kdl", &pipeline("job \"broken\" {\n sandbox \"missing\"\n exec \"x\"\n}\n")); |
| 313 |
c.snapshot("test").unwrap(); |
| 314 |
c.commit("Break the pipeline", &[]).unwrap(); |
| 315 |
assert!(c.push("origin", false).unwrap().iter().all(|r| r.ok)); |
| 316 |
let mut third = None; |
| 317 |
for _ in 0..100 { |
| 318 |
let r = runs_of(&h.app, "andy", "demo").await; |
| 319 |
if r.len() == 3 { |
| 320 |
third = Some(r[0].clone()); |
| 321 |
break; |
| 322 |
} |
| 323 |
tokio::time::sleep(std::time::Duration::from_millis(50)).await; |
| 324 |
} |
| 325 |
let third = third.expect("a third run"); |
| 326 |
assert_eq!(third.status, "error"); |
| 327 |
assert!(third.error.contains("line 18") && third.error.contains("\"missing\""), "{}", third.error); |
| 328 |
let (_, page) = call(&h.app, "GET", &format!("/andy/demo/flow/{}", third.id), None, None).await; |
| 329 |
assert!(page.contains("The pipeline is not valid")); |
| 330 |
|
| 331 |
|
| 332 |
let work2 = tempfile::tempdir().unwrap(); |
| 333 |
let c2 = client(&format!("{}/other/plain", h.base), work2.path()); |
| 334 |
write(work2.path(), ".flow/pipeline.kdl", &pipeline("")); |
| 335 |
c2.snapshot("test").unwrap(); |
| 336 |
c2.commit("Pipeline", &[]).unwrap(); |
| 337 |
assert!(c2.push("origin", false).unwrap().iter().all(|r| r.ok)); |
| 338 |
tokio::time::sleep(std::time::Duration::from_millis(500)).await; |
| 339 |
let row = db::repos::get(&h.app.db, "other", "plain").await.unwrap().unwrap(); |
| 340 |
assert!(db::flow::runs(&h.app.db, row.id, 10, None).await.unwrap().is_empty()); |
| 341 |
let (_, page) = call(&h.app, "GET", "/other/plain/flow", None, None).await; |
| 342 |
assert!(page.contains("not enabled for this repository")); |
| 343 |
} |
| 344 |
|
| 345 |
#[tokio::test(flavor = "multi_thread")] |
| 346 |
async fn claims_carry_pinned_subrepos_and_the_job_token_reads_only_those() { |
| 347 |
let h = hub().await; |
| 348 |
for n in ["lib", "vault", "other", "app"] { |
| 349 |
create(&h.app, "andy", n).await; |
| 350 |
} |
| 351 |
let push = |name: &str, file: &str| { |
| 352 |
let work = tempfile::tempdir().unwrap(); |
| 353 |
let c = client(&format!("{}/andy/{name}", h.base), work.path()); |
| 354 |
write(work.path(), file, "x\n"); |
| 355 |
c.snapshot("t").unwrap(); |
| 356 |
c.commit("first", &[]).unwrap(); |
| 357 |
assert!(c.push("origin", false).unwrap().iter().all(|r| r.ok)); |
| 358 |
let heads = c.bookmark_heads().unwrap(); |
| 359 |
(work, heads) |
| 360 |
}; |
| 361 |
let (_l, lib_heads) = push("lib", "lib.rs"); |
| 362 |
let (_v, _) = push("vault", "secret.rs"); |
| 363 |
let (_o, _) = push("other", "o.rs"); |
| 364 |
|
| 365 |
|
| 366 |
let work = tempfile::tempdir().unwrap(); |
| 367 |
let app = client(&format!("{}/andy/app", h.base), work.path()); |
| 368 |
app.submodule_add(&format!("{}/andy/lib", h.base), "deps/lib", Some("main")).unwrap(); |
| 369 |
app.submodule_add(&format!("{}/andy/vault", h.base), "deps/vault", Some("main")).unwrap(); |
| 370 |
|
| 371 |
sqlx::query("UPDATE repositories SET visibility = 'private' WHERE name = 'vault'").execute(&h.app.db).await.unwrap(); |
| 372 |
write(work.path(), ".flow/pipeline.kdl", &pipeline("")); |
| 373 |
write(work.path(), "Makefile", "all:\n"); |
| 374 |
app.snapshot("t").unwrap(); |
| 375 |
app.commit("app with deps", &[]).unwrap(); |
| 376 |
assert!(app.push("origin", false).unwrap().iter().all(|r| r.ok)); |
| 377 |
assert!(!runs_of(&h.app, "andy", "app").await.is_empty()); |
| 378 |
|
| 379 |
let job = claim(&h.app).await.unwrap(); |
| 380 |
let subs = job["subrepos"].as_array().cloned().unwrap_or_default(); |
| 381 |
assert_eq!(subs.len(), 1, "vault is private and the pusher has no account: {subs:?}"); |
| 382 |
assert_eq!(subs[0]["path"], "deps/lib"); |
| 383 |
assert_eq!(subs[0]["repo"], "andy/lib"); |
| 384 |
assert_eq!(subs[0]["heads"], serde_json::json!(lib_heads.iter().map(|h| h.to_hex()).collect::<Vec<_>>())); |
| 385 |
assert!(subs[0]["clone_url"].as_str().unwrap().ends_with("/andy/lib")); |
| 386 |
|
| 387 |
|
| 388 |
let token = job["token"].as_str().unwrap().to_string(); |
| 389 |
let read = |name: &str| { |
| 390 |
let opts = RemoteOptions { token: Some(token.clone()), ..Default::default() }; |
| 391 |
open_remote(&format!("{}/andy/{name}", h.base), &opts).and_then(|r| r.refs()).is_ok() |
| 392 |
}; |
| 393 |
assert!(read("app") && read("lib")); |
| 394 |
assert!(!read("vault"), "not pinned for this pusher"); |
| 395 |
assert!(!read("other"), "public, but not the job's to read"); |
| 396 |
} |