~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/knotless

git that lives in your Atmosphere account

knotless.dev
1 collaborator

knotless 0.17.0 Latest 2 packages, 1 image

1
10

Tests that list everyone's records look for their own among them

Merged chadtmiller.com asked to merge into main from chadtmiller.com/knotless:serve/feed-flake
crates/knotless-serve/tests/gateway.rs+28−14
@@ -2664,8 +2664,18 @@ fn themes_from_the_pages() {
let ink = json!({"colorScheme": "dark", "background": "#0d1117", "text": "#e6edf3",
"primary": "#2f81f7", "accent": "#58a6ff", "panel": "not a colour"});
// Everyone's are other tests' too, from this run and those before it:
// what is listed is told apart by its maker.
let handle = &maker.account.handle;
let theirs_only = |found: &Value| {
let themes = found["themes"].as_array().unwrap().iter();
let made = themes.filter(|t| t["creator"]["did"] == maker.account.did.as_str());
made.cloned().collect::<Vec<_>>()
};
let names = |themes: Vec<Value>| themes.iter().map(|t| t["name"].clone()).collect::<Vec<_>>();
// None yet; then one, as its maker's record, named as written.
assert_eq!(list("").2, json!({"themes": []}));
assert_eq!(list(&format!("?actor={handle}")).2, json!({"themes": []}));
let made = send(
"createTheme",
me,
@@ -2709,22 +2719,21 @@ fn themes_from_the_pages() {
let second = send("createTheme", me, json!({"name": "Ink", "palette": ink}));
assert_eq!(second.0, 200, "{}", second.2);
// Listed the latest first, a page at a time, everyone's or its maker's.
let first = list("?limit=1").2;
// Listed the latest first, a page at a time, its maker's or everyone's.
let first = list(&format!("?actor={handle}&limit=1")).2;
assert_eq!(first["themes"][0]["name"], "Ink");
let cursor = first["cursor"].as_str().unwrap().replace(' ', "%20");
let next = list(&format!("?limit=1&cursor={cursor}")).2;
let next = list(&format!("?actor={handle}&limit=1&cursor={cursor}")).2;
assert_eq!(next["themes"][0]["uri"], uri.as_str());
assert_eq!(next.get("cursor"), None);
let by = list(&format!("?actor={}", maker.account.handle)).2;
assert_eq!(by["themes"].as_array().unwrap().len(), 2);
let everyone = list("?limit=100").2;
assert_eq!(
names(theirs_only(&everyone)),
[json!("Ink"), json!("Paper")]
);
assert_eq!(list("?actor=nobody.invalid").0, 400);
// Found by how its name starts, in any case, in the order of names.
let named = |q: &str| {
let found = list(&format!("?q={q}")).2;
let names = found["themes"].as_array().unwrap().iter();
names.map(|t| t["name"].clone()).collect::<Vec<_>>()
};
let named = |q: &str| names(theirs_only(&list(&format!("?q={q}&limit=100")).2));
assert_eq!(named("pA"), [json!("Paper")]);
assert_eq!(named("%20"), [json!("Ink"), json!("Paper")]);
assert_eq!(named("ox"), Vec::<Value>::new());
@@ -2752,7 +2761,8 @@ fn themes_from_the_pages() {
let (status, _, said) = send("deleteTheme", me, json!({ "uri": uri }));
assert_eq!(status, 200, "{said}");
assert_eq!(maker.records("dev.knotless.theme").len(), 1);
assert_eq!(list("").2["themes"].as_array().unwrap().len(), 1);
let left = list(&format!("?actor={handle}")).2;
assert_eq!(names(theirs_only(&left)), [json!("Ink")]);
}
/// An operator moderates the appview from its pages, logged in to them, as
@@ -3170,9 +3180,13 @@ fn private_repositories_on_the_pages() {
let (_, cache, _, said) = looked(&search, theirs);
assert_eq!(cache, "private, no-store");
assert!(said.contains("\"private\":true"), "{said}");
// Others' public repositories on the PDS may match: only this one is
// looked for.
for cookie in [None, Some(outsider_in.as_str())] {
let said = looked(&search, cookie).3;
assert!(!said.contains("hidden"), "{search}: {said}");
let said: Value = serde_json::from_str(&looked(&search, cookie).3).unwrap();
let mut repos = said["repos"].as_array().unwrap().iter();
let this = |r: &Value| r["did"] == did.as_str() && r["name"] == "hidden";
assert!(!repos.any(this), "{search}: {said}");
}
// To anyone else, and in any card, it is not there, as one never made
crates/knotless-serve/tests/pages.rs+4−1
@@ -1233,9 +1233,12 @@ fn private_repositories_settings_and_forks() {
assert_eq!(status, 200, "{found}");
assert_eq!(found["repos"][0]["name"], "hidden", "{found}");
assert_eq!(found["repos"][0]["private"], true);
// Others' public repositories on the PDS may match: only this one is
// looked for.
let (_, _, found) = browse("GET", &search, None, None);
let mut repos = found["repos"].as_array().unwrap().iter();
assert!(repos.all(|r| r["name"] != "hidden"), "{found}");
let this = |r: &Value| r["did"] == owner.account.did.as_str() && r["name"] == "hidden";
assert!(!repos.any(this), "{found}");
// An issue opened from the pages is read back at once, as the page it
// goes to reads it: from this server's index of the space, before its
crates/knotless-serve/tests/web.rs+37−17
@@ -2647,8 +2647,14 @@ fn the_feed() {
assert!(!events.is_empty(), "{kind}: {only}");
assert!(events.iter().all(|e| of(e) == kind), "{kind}: {only}");
}
// No stars in everyone's feed, and nothing of a kind not known. Of
// gists, only this account's: everyone's holds other tests' too.
assert_eq!(page("?kind=stars")["events"], json!([]));
assert_eq!(page("?kind=gists")["events"], json!([]));
assert_eq!(page("?kind=nothing")["events"], json!([]));
assert_eq!(
page(&format!("?actor={did}&kind=gists"))["events"],
json!([])
);
// How much each did, a day at a time, and each repository's pushes.
let activity = |did: &str, q: &str| {
@@ -5277,26 +5283,35 @@ fn searching_code() {
let site = serve_with(Sandbox::new(), true, true);
let s = person(account(), &site);
let handle = s.account.handle.clone();
// Others' repositories on the PDS are searched too, this test's own
// from a run before among them: the needle is this account's alone.
let needle = format!("needle_{}_", s.account.did.rsplit(':').next().unwrap());
// With nothing pushed, there is nothing to index.
ok(&s, &["repo", "create", &s.url("unpushed")]);
// Pushed before code is indexed: what has no shards yet is indexed as
// indexing starts.
for (name, n) in [("needle-one", 1), ("needle-two", 2)] {
let work = s.work(name, 1);
let lib = format!("// the haystack\nfn needle_{n}() {{}}\nfn other() {{}}\n");
let lib = format!("// the haystack\nfn {needle}{n}() {{}}\nfn other() {{}}\n");
write(&work, "src/lib.rs", lib.as_bytes());
s.git(&work, &["add", "-A"]);
s.git(&work, &["commit", "-q", "-m", "Hide a needle"]);
s.git(&work, &["push", "-q", &s.url(name), "main"]);
}
wait_until(|| names(&site.search("needle")["repos"]).len() == 2);
let ours = |found: Value| {
let repos = found["repos"].as_array().unwrap().clone().into_iter();
repos
.filter(|r| r["owner"]["handle"] == handle.as_str())
.count()
};
wait_until(|| ours(site.search("needle")) == 2);
let follow = knotless_serve::code::follow(site.app.clone());
site._rt.spawn(follow.expect("a code index"));
let search = |q: &str| site.json(&format!("/xrpc/dev.knotless.searchCode?q={q}"));
let search = |q: &str| site.json(&format!("/xrpc/dev.knotless.searchCode?q={needle}{q}"));
let found = |q: &str| search(q)["files"].as_array().unwrap().len();
wait_until(|| found("needle_") == 2);
wait_until(|| found("") == 2);
let one = search("needle_1");
let one = search("1");
assert_eq!(
(one["fileCount"].as_u64(), one["matchCount"].as_u64()),
(Some(1), Some(1))
@@ -5307,7 +5322,7 @@ fn searching_code() {
serde_json::json!([{"name": "Rust", "color": "#dea584", "files": 1}])
);
// Picking another language finds nothing, but still lists them all.
let other = search("needle_+lang:Markdown");
let other = search("+lang:Markdown");
assert_eq!(other["files"].as_array().unwrap().len(), 0, "{other}");
assert_eq!(other["languages"][0]["files"], 2, "{other}");
let file = &one["files"][0];
@@ -5321,28 +5336,29 @@ fn searching_code() {
assert_eq!(chunk["startLine"], 1, "{chunk}");
assert_eq!(
chunk["content"],
"// the haystack\nfn needle_1() {}\nfn other() {}"
format!("// the haystack\nfn {needle}1() {{}}\nfn other() {{}}")
);
let end = 3 + needle.len() + 1;
assert_eq!(
chunk["ranges"],
serde_json::json!([{"line": 2, "byteStart": 3, "byteEnd": 11}])
serde_json::json!([{"line": 2, "byteStart": 3, "byteEnd": end}])
);
// Painted as its file's language reads: the comment first.
let painted = chunk["highlights"].as_str().unwrap();
assert!(painted.starts_with("comment:0,"), "{painted}");
// A page at a time, the best first, and the next after the cursor.
let first = search("needle_&limit=1");
let first = search("&limit=1");
assert_eq!(first["files"].as_array().unwrap().len(), 1, "{first}");
assert_eq!(first["cursor"], "1", "{first}");
let next = search("needle_&limit=1&cursor=1");
let next = search("&limit=1&cursor=1");
assert_eq!(next["files"].as_array().unwrap().len(), 1, "{next}");
assert_ne!(next["files"][0]["repo"], first["files"][0]["repo"]);
assert!(next.get("cursor").is_none(), "{next}");
// Its languages were listed with the first.
assert_eq!(next["languages"], serde_json::json!([]), "{next}");
// No deeper than the pages go.
let deep = search("needle_&cursor=1000");
let deep = search("&cursor=1000");
assert_eq!(deep["files"].as_array().unwrap().len(), 0, "{deep}");
let bad = site.status("/xrpc/dev.knotless.searchCode?q=x&cursor=no");
assert_eq!(bad.0, 400, "{}", bad.1);
@@ -5351,7 +5367,7 @@ fn searching_code() {
let within = |name: &str| {
let repo = format!("at://{handle}/dev.knotless.repo/{name}");
site.json(&format!(
"/xrpc/dev.knotless.searchCode?q=needle_&repo={repo}&limit=5"
"/xrpc/dev.knotless.searchCode?q={needle}&repo={repo}&limit=5"
))
};
let two = within("needle-two");
@@ -5360,11 +5376,15 @@ fn searching_code() {
// A push is found once it is indexed again.
let work = s.path("needle-two");
write(&work, "src/more.rs", b"fn needle_3() {}\n");
write(
&work,
"src/more.rs",
format!("fn {needle}3() {{}}\n").as_bytes(),
);
s.git(&work, &["add", "-A"]);
s.git(&work, &["commit", "-q", "-m", "Hide another"]);
s.git(&work, &["push", "-q", &s.url("needle-two"), "main"]);
wait_until(|| found("needle_3") == 1);
wait_until(|| found("3") == 1);
// A query Zoekt cannot read is the asker's to fix.
let bad = site.status("/xrpc/dev.knotless.searchCode?q=(");
@@ -5392,10 +5412,10 @@ fn searching_code() {
assert_eq!(status["code"]["ok"], true, "{status}");
assert!(status["code"]["shards"].as_u64().unwrap() >= 2, "{status}");
ok(&s, &["repo", "delete", &s.url("needle-one"), "--yes"]);
wait_until(|| found("needle_1") == 0);
wait_until(|| found("1") == 0);
// And its shards are deleted.
wait_until(|| shards() == 1);
wait_until(|| found("needle_") == 2);
wait_until(|| found("") == 2);
}
/// A gist is a repository whose record says so: listed by getActorGists