Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Dev mode: a type change no longer leaves every file unread (0.7.7, F-1) (#448)

Oleksandr Ivanchenko6f43a0b37902
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 809a4a2f..fe2a1ad2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## Unreleased
### Changed
-- **Dev mode reviews only fresh work.** A branch or PR gets a review card only if it moved in the last 7 days, so old branches no longer fill the desk or spend model calls. Cards on branches that went quiet go stale, and a new push brings a branch back. The newest branches are reviewed first, and Dev mode's status says how many old ones it skipped. A card that couldn't read a big file now says "Couldn't read N files (too large to diff)" instead of "(no diff from GitHub)".
+- **Dev mode reviews only fresh work.** A branch or PR gets a review card only if it moved in the last 7 days, so old branches no longer fill the desk or spend model calls. Cards on branches that went quiet go stale, and a new push brings a branch back. The newest branches are reviewed first, and Dev mode's status says how many old ones it skipped. A card that couldn't read a file now says "Couldn't read N files (no diff available)" instead of "(no diff from GitHub)". A type change (a symlink turned into a file) no longer leaves every file in the change unread.
### Fixed
- **A checkpoint's git commit only comes from the task's own git files.** When a mission takes a checkpoint, kwant notes the commit the task's folder is on. It now never follows a symlink inside `.git`, ignores a `ref:` that points outside it, skips FIFOs and oversized files, and keeps the value only when it's a real 40- or 64-character commit id. Before, a bot that could write its task folder could make a checkpoint show the first 64 characters of another file kwant can read. (#443)
diff --git a/src/server/dev/git.rs b/src/server/dev/git.rs
index 04d75491..8d454322 100644
--- a/src/server/dev/git.rs
+++ b/src/server/dev/git.rs
@@ -23,6 +23,7 @@
use super::facts::FileDiff;
use super::source::{Commit, Person};
use chrono::{DateTime, Utc};
+use std::collections::HashMap;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::path::{Path, PathBuf};
use std::process::Stdio;
@@ -1278,14 +1279,9 @@ impl Repo {
f.deletions = d;
}
}
- // Hunks: one section per file, in the same order; anything else and none are kept
+ // Hunks: each file takes its own section, found by path (a type change prints two)
if let Ok(p) = self.git(&with(&["-p", "--no-color", "--no-ext-diff", "--no-textconv", "--src-prefix=a/", "--dst-prefix=b/"])).await {
- let patches = split_patches(&String::from_utf8_lossy(&p));
- if patches.len() == files.len() {
- for (f, p) in files.iter_mut().zip(patches) {
- f.patch = p;
- }
- }
+ match_patches(&mut files, split_patches(&String::from_utf8_lossy(&p)));
}
files.truncate(MAX_FILES);
Ok(files)
@@ -1497,24 +1493,116 @@ fn parse_numstat(out: &[u8]) -> Vec<(u64, u64)> {
out
}
-/// A `-p` diff split per file: each file's hunks from its first `@@` (GitHub's `patch`), `None`
-/// for a binary file or one with no hunks (a mode change, an empty file).
-fn split_patches(text: &str) -> Vec<Option<String>> {
+/// One file's section of a `-p` diff: the paths on its `--- a/` and `+++ b/` lines (`None` for
+/// `/dev/null`, or when the section has no hunks and so no such lines) and its hunks from the
+/// first `@@` (GitHub's `patch`).
+#[derive(Debug, PartialEq)]
+struct Section {
+ old: Option<String>,
+ new: Option<String>,
+ patch: Option<String>,
+}
+
+/// A `-p` diff split per section. `patch` is `None` for a binary file or one with no hunks (a
+/// mode change, an empty file, a pure rename). A type change (symlink to file) prints two
+/// sections for one file: a delete, then an add.
+fn split_patches(text: &str) -> Vec<Section> {
if text.trim().is_empty() {
return Vec::new();
}
let Some(body) = text.strip_prefix("diff --git ") else { return Vec::new() };
body.split("\ndiff --git ")
.map(|sec| {
- let hunks = sec.find("\n@@ ").map(|i| &sec[i + 1..])?;
- if sec[..sec.len() - hunks.len()].contains("\nBinary files ") {
- return None;
+ let none = Section { old: None, new: None, patch: None };
+ let Some(i) = sec.find("\n@@ ") else { return none };
+ let (head, hunks) = (&sec[..i], &sec[i + 1..]);
+ if head.contains("\nBinary files ") {
+ return none;
}
- Some(hunks.trim_end_matches('\n').to_string())
+ let side = |mark: &str, prefix: &str| head.lines().find_map(|l| l.strip_prefix(mark)).and_then(|n| patch_path(n, prefix));
+ Section { old: side("--- ", "a/"), new: side("+++ ", "b/"), patch: Some(hunks.trim_end_matches('\n').to_string()) }
})
.collect()
}
+/// A path from a `---`/`+++` line, without its `a/` or `b/`: `None` for `/dev/null`. Git ends
+/// the line with a tab when the name has a space, and C-quotes a name with control characters,
+/// `"` or `\` (and bytes over 0x7f while `core.quotePath` is on).
+fn patch_path(name: &str, prefix: &str) -> Option<String> {
+ let name = name.strip_suffix('\t').unwrap_or(name);
+ if name == "/dev/null" {
+ return None;
+ }
+ let name = match name.strip_prefix('"').and_then(|n| n.strip_suffix('"')) {
+ Some(q) => unquote_c(q)?,
+ None => name.to_string(),
+ };
+ name.strip_prefix(prefix).map(str::to_string)
+}
+
+/// Git's C-style quoting undone: `\\`, `\"`, `\t`, `\n` and the like, and `\ooo` octal bytes.
+fn unquote_c(q: &str) -> Option<String> {
+ let b = q.as_bytes();
+ let mut out = Vec::with_capacity(b.len());
+ let mut i = 0;
+ while i < b.len() {
+ if b[i] != b'\\' {
+ out.push(b[i]);
+ i += 1;
+ continue;
+ }
+ let c = *b.get(i + 1)?;
+ i += 2;
+ out.push(match c {
+ b'a' => 7,
+ b'b' => 8,
+ b't' => b'\t',
+ b'n' => b'\n',
+ b'v' => 11,
+ b'f' => 12,
+ b'r' => b'\r',
+ b'0'..=b'3' => {
+ let d = b.get(i..i + 2)?;
+ if !d.iter().all(|x| (b'0'..=b'7').contains(x)) {
+ return None;
+ }
+ i += 2;
+ (c - b'0') * 64 + (d[0] - b'0') * 8 + (d[1] - b'0')
+ }
+ other => other,
+ });
+ }
+ Some(String::from_utf8_lossy(&out).into_owned())
+}
+
+/// Gives each file the hunks of its own section, matched by path, never by position: the `+++ b/`
+/// path for a modify, add, rename or copy, the `--- a/` path for a delete. A type change takes
+/// its add section's hunks (the new side, where review comments go), else its delete section's.
+/// A file with no section of its own, or whose section is binary or has no hunks, keeps `None`.
+fn match_patches(files: &mut [FileDiff], sections: Vec<Section>) {
+ let mut by_new: HashMap<String, String> = HashMap::new();
+ let mut deleted: HashMap<String, String> = HashMap::new();
+ for s in sections {
+ let Some(patch) = s.patch else { continue };
+ match (s.old, s.new) {
+ (_, Some(n)) => {
+ by_new.entry(n).or_insert(patch);
+ }
+ (Some(o), None) => {
+ deleted.entry(o).or_insert(patch);
+ }
+ (None, None) => {}
+ }
+ }
+ for f in files.iter_mut() {
+ f.patch = match f.status.as_str() {
+ "removed" => deleted.remove(&f.path),
+ "changed" => by_new.remove(&f.path).or_else(|| deleted.remove(&f.path)),
+ _ => by_new.remove(&f.path),
+ };
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -2157,8 +2245,93 @@ mod tests {
assert_eq!(files.iter().map(|f| (f.path.as_str(), f.status.as_str(), f.previous_path.as_deref())).collect::<Vec<_>>(), [("src/a.rs", "modified", None), ("new.txt", "added", None), ("new.rs", "renamed", Some("old.rs"))]);
assert_eq!(parse_numstat(b"3\t1\tsrc/a.rs\0-\t-\tnew.txt\x002\t0\t\0old.rs\0new.rs\0"), [(3, 1), (0, 0), (2, 0)]);
let p = "diff --git a/x b/x\nindex 1..2 100644\n--- a/x\n+++ b/x\n@@ -1 +1 @@\n-a\n+b\ndiff --git a/y b/y\nBinary files a/y and b/y differ\ndiff --git a/z b/z\nold mode 100644\nnew mode 100755\n";
- assert_eq!(split_patches(p), [Some("@@ -1 +1 @@\n-a\n+b".to_string()), None, None]);
+ let sec = |old: Option<&str>, new: Option<&str>, patch: Option<&str>| Section { old: old.map(Into::into), new: new.map(Into::into), patch: patch.map(Into::into) };
+ assert_eq!(split_patches(p), [sec(Some("x"), Some("x"), Some("@@ -1 +1 @@\n-a\n+b")), sec(None, None, None), sec(None, None, None)]);
assert!(split_patches("").is_empty());
+ // A name with a space ends in a tab; an odd one is C-quoted, prefix and all
+ let p = "diff --git a/sp ace b/sp ace\n--- a/sp ace\t\n+++ b/sp ace\t\n@@ -1 +1 @@\n-a\n+b\ndiff --git \"a/q\\\"t\\303\\251\" \"b/q\\\"t\\303\\251\"\ndeleted file mode 100644\n--- \"a/q\\\"t\\303\\251\"\n+++ /dev/null\n@@ -1 +0,0 @@\n-a\n";
+ assert_eq!(split_patches(p), [sec(Some("sp ace"), Some("sp ace"), Some("@@ -1 +1 @@\n-a\n+b")), sec(Some("q\"t\u{e9}"), None, Some("@@ -1 +0,0 @@\n-a"))]);
+ assert_eq!(unquote_c("a\\tb\\\\c\\nd"), Some("a\tb\\c\nd".into()));
+ assert_eq!(unquote_c("bad\\9"), Some("bad9".into()), "an unknown escape is the character itself");
+ assert_eq!(unquote_c("cut\\30"), None);
+ assert_eq!(unquote_c("cut\\"), None);
+ }
+
+ /// Rigel's F-1 on #447: patches were matched to files by position, and dropped when the counts
+ /// differed. Now each file finds its own section by path, so a section too many or too few
+ /// costs only the file it belongs to.
+ #[test]
+ fn patches_are_matched_to_files_by_path() {
+ let file = |path: &str, status: &str| FileDiff { path: path.into(), status: status.into(), additions: 1, deletions: 1, patch: None, previous_path: None };
+ let sec = |old: Option<&str>, new: Option<&str>, patch: Option<&str>| Section { old: old.map(Into::into), new: new.map(Into::into), patch: patch.map(Into::into) };
+ let mut files = vec![file("gone.rs", "removed"), file("link", "changed"), file("new.rs", "renamed"), file("lost.rs", "modified"), file("mode.sh", "modified"), file("back", "changed")];
+ match_patches(
+ &mut files,
+ vec![
+ sec(Some("gone.rs"), None, Some("@@ gone")),
+ // A type change: the delete, then the add; the add (the new side) wins
+ sec(Some("link"), None, Some("@@ old link")),
+ sec(None, Some("link"), Some("@@ new link")),
+ sec(Some("old.rs"), Some("new.rs"), Some("@@ renamed")),
+ // mode.sh: a mode change has no hunks
+ sec(None, None, None),
+ // A type change whose new side is binary: the old side's hunks
+ sec(Some("back"), None, Some("@@ old back")),
+ sec(None, None, None),
+ // A section for no file in the list is ignored
+ sec(Some("other.rs"), Some("other.rs"), Some("@@ other")),
+ ],
+ );
+ let got: Vec<_> = files.iter().map(|f| (f.path.as_str(), f.patch.as_deref())).collect();
+ assert_eq!(got, [("gone.rs", Some("@@ gone")), ("link", Some("@@ new link")), ("new.rs", Some("@@ renamed")), ("lost.rs", None), ("mode.sh", None), ("back", Some("@@ old back"))]);
+ // A delete never takes an add's hunks, nor a modify a delete's
+ let mut files = vec![file("a", "removed"), file("b", "modified")];
+ match_patches(&mut files, vec![sec(None, Some("a"), Some("@@ a")), sec(Some("b"), None, Some("@@ b"))]);
+ assert!(files.iter().all(|f| f.patch.is_none()), "{files:?}");
+ }
+
+ /// F-1 with real git: a symlink turned into a file prints two `-p` sections for one `T` file.
+ /// The edited text file next to it keeps its patch, the type-changed file gets its new side,
+ /// and the card has no unread reason. A rename next to a modify still matches too.
+ #[cfg(unix)]
+ #[tokio::test]
+ async fn a_type_change_keeps_every_files_patch() {
+ let tmp = tempfile::tempdir().unwrap();
+ let w = tmp.path().join("work");
+ std::fs::create_dir_all(&w).unwrap();
+ sh(&w, &["init", "-q"]);
+ write(&w, "a.txt", b"hi\n");
+ std::os::unix::fs::symlink("a.txt", w.join("link")).unwrap();
+ write(&w, "old name.rs", b"fn one() {}\nfn two() {}\nfn three() {}\nfn four() {}\n");
+ write(&w, "src/m.rs", b"fn m() {}\n");
+ let base = commit_all(&w, "Base");
+ std::fs::remove_file(w.join("link")).unwrap();
+ write(&w, "link", b"real file now\n");
+ write(&w, "a.txt", b"hi\nmore\n");
+ let head = commit_all(&w, "Tiny change");
+ let repo = Repo::local(&w, &tmp.path().join("data")).await.unwrap();
+ let files = repo.diff(Some(&base), &head).await.unwrap();
+ let got: Vec<_> = files.iter().map(|f| (f.path.as_str(), f.status.as_str(), f.additions, f.deletions, f.patch.as_deref())).collect();
+ assert_eq!(got, [("a.txt", "modified", 1, 0, Some("@@ -1 +1,2 @@\n hi\n+more")), ("link", "changed", 1, 1, Some("@@ -0,0 +1 @@\n+real file now"))]);
+ assert!(super::super::risk::unread_files(&files).is_empty());
+ let r = super::super::risk::assess(&super::super::risk::Inputs { files: &files, ..Default::default() });
+ assert!(r.reasons.iter().all(|x| !x.starts_with("Couldn't read")), "{:?}", r.reasons);
+ assert_eq!(r.level, super::super::risk::Level::Low, "{:?}", r.reasons);
+
+ // A rename (with a space in its name) next to a modify, and a delete
+ sh(&w, &["mv", "old name.rs", "new name.rs"]);
+ write(&w, "new name.rs", b"fn one() {}\nfn two() {}\nfn three() {}\nfn four() {}\nfn five() {}\n");
+ write(&w, "src/m.rs", b"fn m() { 1 }\n");
+ std::fs::remove_file(w.join("a.txt")).unwrap();
+ let next = commit_all(&w, "Rename and edit");
+ let files = repo.diff(Some(&head), &next).await.unwrap();
+ let by = |p: &str| files.iter().find(|f| f.path == p).unwrap_or_else(|| panic!("{p}: {files:?}")).clone();
+ assert_eq!(files.len(), 3, "{files:?}");
+ assert_eq!(by("a.txt").status, "removed");
+ assert_eq!(by("a.txt").patch.as_deref(), Some("@@ -1,2 +0,0 @@\n-hi\n-more"));
+ assert_eq!((by("new name.rs").status.as_str(), by("new name.rs").previous_path.as_deref()), ("renamed", Some("old name.rs")));
+ assert_eq!(by("new name.rs").patch.as_deref(), Some("@@ -2,3 +2,4 @@ fn one() {}\n fn two() {}\n fn three() {}\n fn four() {}\n+fn five() {}"));
+ assert_eq!(by("src/m.rs").patch.as_deref(), Some("@@ -1 +1 @@\n-fn m() {}\n+fn m() { 1 }"));
}
// -----------------------------------------------------------------------------------------
diff --git a/src/server/dev/review.rs b/src/server/dev/review.rs
index 92a5cb1a..2ac1cc5d 100644
--- a/src/server/dev/review.rs
+++ b/src/server/dev/review.rs
@@ -701,7 +701,7 @@ mod tests {
f.files.push(FileDiff { path: "tests/big_test.rs".into(), status: "modified".into(), additions: 0, deletions: 300, patch: None, previous_path: None });
let (_, c) = card::<Stub>(&f, None, None).await;
assert_eq!(c["tamper"]["unread"], json!(["tests/big_test.rs"]));
- assert!(c["risk"]["reasons"].as_array().unwrap().contains(&json!("Couldn't read 1 file (too large to diff)")), "{}", c["risk"]);
+ assert!(c["risk"]["reasons"].as_array().unwrap().contains(&json!("Couldn't read 1 file (no diff available)")), "{}", c["risk"]);
assert_ne!(c["risk"]["level"], "low");
}
diff --git a/src/server/dev/risk.rs b/src/server/dev/risk.rs
index c8cbca2e..9def0704 100644
--- a/src/server/dev/risk.rs
+++ b/src/server/dev/risk.rs
@@ -147,16 +147,17 @@ pub fn assess(i: &Inputs) -> Risk {
Risk { level, reasons }
}
-/// Files with changed lines but no patch (too large to diff, from git or the forge alike). Binary
-/// files (no lines) aren't counted: there's no text to read.
+/// Files with changed lines but no patch, from git or the forge alike: too large to diff, or a
+/// forge that sends no patch at all (Gitea's fallback to its files list). Binary files (no lines)
+/// aren't counted: there's no text to read.
pub fn unread_files(files: &[FileDiff]) -> Vec<&str> {
files.iter().filter(|f| f.patch.is_none() && f.additions + f.deletions > 0).map(|f| f.path.as_str()).collect()
}
-/// "Couldn't read 2 files (too large to diff)". It names no host: the files may have come from
-/// git, GitHub, GitLab, Gitea or Forgejo.
+/// "Couldn't read 2 files (no diff available)". It names no host (the files may have come from
+/// git, GitHub, GitLab, Gitea or Forgejo) and no single cause: size is only one of them.
pub fn unread_reason(n: usize) -> String {
- format!("Couldn't read {n} file{} (too large to diff)", if n == 1 { "" } else { "s" })
+ format!("Couldn't read {n} file{} (no diff available)", if n == 1 { "" } else { "s" })
}
/// "+27 −9 in 2 files" (a real minus sign, as the design writes it).
@@ -663,16 +664,17 @@ mod tests {
assert!(has_ddl("ALTER TABLE x") && has_ddl("alter table x") && has_ddl("ALTER TABLE") && !has_ddl("alter table"));
}
- /// 0.7.7: the reason names no host. A GitLab repo read with plain git said "no diff from
- /// GitHub"; git and every forge leave the patch out for the same reason, its size.
+ /// 0.7.7: the reason names no host and no cause. A GitLab repo read with plain git said "no
+ /// diff from GitHub"; then "too large to diff" showed on a +2/−1 type change (Rigel's F-1),
+ /// and Gitea's fallback to its files list sends no patch whatever the size.
#[test]
- fn the_unread_reason_says_why_and_names_no_host() {
- assert_eq!(unread_reason(1), "Couldn't read 1 file (too large to diff)");
- assert_eq!(unread_reason(3), "Couldn't read 3 files (too large to diff)");
+ fn the_unread_reason_names_no_host_and_no_cause() {
+ assert_eq!(unread_reason(1), "Couldn't read 1 file (no diff available)");
+ assert_eq!(unread_reason(3), "Couldn't read 3 files (no diff available)");
for n in [1, 2] {
let r = unread_reason(n);
- for host in ["GitHub", "GitLab", "Gitea", "Forgejo", "git"] {
- assert!(!r.contains(host), "{r}");
+ for word in ["GitHub", "GitLab", "Gitea", "Forgejo", "git", "large", "size"] {
+ assert!(!r.contains(word), "{r}");
}
}
}
@@ -685,14 +687,14 @@ mod tests {
// A test file losing 300 lines, unread: at least Medium, and said
let r = risk(&[unread("tests/a_test.rs", 0, 300)]);
assert_eq!(r.level, Level::Medium);
- assert_eq!(r.reasons, vec!["Couldn't read 1 file (too large to diff)".to_string(), "+0 \u{2212}300 in 1 file".into()]);
+ assert_eq!(r.reasons, vec!["Couldn't read 1 file (no diff available)".to_string(), "+0 \u{2212}300 in 1 file".into()]);
// A big source file, unread: large plus unread
let r = risk(&[unread("src/a.rs", 900, 0)]);
assert!(r.level >= Level::Medium);
- assert!(r.reasons.contains(&"Couldn't read 1 file (too large to diff)".into()));
+ assert!(r.reasons.contains(&"Couldn't read 1 file (no diff available)".into()));
// Next to a small read change: still no "Small change"
let r = risk(&[code("src/runner.rs", 2), test_edit("tests/runner_test.rs"), unread("src/big.rs", 4, 0), unread("tests/big_test.rs", 1, 9)]);
- assert!(r.reasons.contains(&"Couldn't read 2 files (too large to diff)".into()), "{:?}", r.reasons);
+ assert!(r.reasons.contains(&"Couldn't read 2 files (no diff available)".into()), "{:?}", r.reasons);
assert!(r.reasons.iter().all(|x| !x.starts_with("Small change") && !x.contains("no code changed")), "{:?}", r.reasons);
// A binary file (no lines) has no text to read: not counted
let png = FileDiff { path: "site/a.png".into(), status: "modified".into(), additions: 0, deletions: 0, patch: None, previous_path: None };
diff --git a/tests/dev_fresh_reviews_test.rs b/tests/dev_fresh_reviews_test.rs
index 718c5efc..3eb3064a 100644
--- a/tests/dev_fresh_reviews_test.rs
+++ b/tests/dev_fresh_reviews_test.rs
@@ -294,3 +294,41 @@ async fn forge_prs_are_reviewed_only_while_updated_in_the_window() {
assert_eq!(all.iter().filter(|c| c.ref_ == "pr:20").map(|c| c.status.as_str()).collect::<Vec<_>>(), [STALE], "the old MR's card went stale and got no new one");
assert_eq!(poller::old_reviews_skipped(space.as_str(), &row.key), 2);
}
+
+/// Rigel's probe2 on #447 (F-1): a fresh branch that turns a symlink into a file next to a +1
+/// edit. git prints two `-p` sections for the one type-changed file, and every patch used to be
+/// dropped, so the card said "Couldn't read 2 files (too large to diff)" and went to Medium for a
+/// +2 −1 change. Now every file keeps its own patch and nothing is unread.
+#[cfg(unix)]
+#[tokio::test]
+async fn a_type_change_leaves_no_file_unread() {
+ let env = setup().await;
+ let (folder, row) = watched(&env, "typechange").await;
+ std::fs::write(folder.join("a.txt"), "hi\n").unwrap();
+ std::os::unix::fs::symlink("a.txt", folder.join("link")).unwrap();
+ git(&folder, &["add", "-A"]);
+ git_at(&folder, &["commit", "-q", "-m", "Add a.txt and a link to it"], Some(days_ago(60)));
+ git(&folder, &["checkout", "-q", "-b", "typechange", "main"]);
+ std::fs::remove_file(folder.join("link")).unwrap();
+ std::fs::write(folder.join("link"), "real file now\n").unwrap();
+ std::fs::write(folder.join("a.txt"), "hi\nmore\n").unwrap();
+ git(&folder, &["add", "-A"]);
+ git_at(&folder, &["commit", "-q", "-m", "Tiny change"], Some(days_ago(1)));
+ git(&folder, &["checkout", "-q", "main"]);
+
+ poll(&env).await;
+ let all = cards(&env, &row.key).await;
+ assert_eq!(all.len(), 1, "{all:?}");
+ let f: DevFacts = serde_json::from_str(&all[0].facts).unwrap();
+ let got: Vec<_> = f.files.iter().map(|x| (x.path.as_str(), x.status.as_str(), x.additions, x.deletions, x.patch.is_some())).collect();
+ assert_eq!(got, [("a.txt", "modified", 1, 0, true), ("link", "changed", 1, 1, true)]);
+ assert!(kwnt::server::dev::risk::unread_files(&f.files).is_empty());
+ let r = kwnt::server::dev::risk::assess(&kwnt::server::dev::risk::Inputs { files: &f.files, ..Default::default() });
+ assert!(r.reasons.iter().all(|x| !x.starts_with("Couldn't read")), "{:?}", r.reasons);
+ // The card itself, once made, says the same
+ if let Some(card) = &all[0].card {
+ let c: Value = serde_json::from_str(card).unwrap();
+ assert!(c["risk"]["reasons"].as_array().into_iter().flatten().all(|x| !x.as_str().unwrap_or("").starts_with("Couldn't read")), "{}", c["risk"]);
+ assert_eq!(c["tamper"]["unread"].as_array().map_or(0, Vec::len), 0, "{}", c["tamper"]);
+ }
+}