diff --git a/pkgs/id/src/commands/peers.rs b/pkgs/id/src/commands/peers.rs index bc603afc55..8ac62c6239 100644 --- a/pkgs/id/src/commands/peers.rs +++ b/pkgs/id/src/commands/peers.rs @@ -499,7 +499,15 @@ mod tests { #[test] fn test_peer_row_control_character_names_stay_one_row() { - for name in ["a\nb", "a\rb", "a\tb", "a\r\nb", "\n", "\u{0}", "x\nforged\trow\t0"] { + for name in [ + "a\nb", + "a\rb", + "a\tb", + "a\r\nb", + "\n", + "\u{0}", + "x\nforged\trow\t0", + ] { let row = format_peer_row(&announcement(1, Some(name))); assert_one_row_four_fields(&row); assert!( diff --git a/pkgs/id/src/commands/tag.rs b/pkgs/id/src/commands/tag.rs index f0c5d3cca1..f01989ba67 100644 --- a/pkgs/id/src/commands/tag.rs +++ b/pkgs/id/src/commands/tag.rs @@ -75,10 +75,7 @@ pub fn hex_decode(input: &str) -> Result> { .strip_prefix("0x") .or_else(|| trimmed.strip_prefix("0X")) .unwrap_or(trimmed); - let cleaned: String = stripped - .chars() - .filter(|c| !c.is_whitespace()) - .collect(); + let cleaned: String = stripped.chars().filter(|c| !c.is_whitespace()).collect(); if !cleaned.len().is_multiple_of(2) { bail!("hex value must have an even number of digits"); } diff --git a/pkgs/id/src/event_store/sync.rs b/pkgs/id/src/event_store/sync.rs index 450a6dda65..702c3bca86 100644 --- a/pkgs/id/src/event_store/sync.rs +++ b/pkgs/id/src/event_store/sync.rs @@ -669,8 +669,7 @@ async fn run_session( }; let receiving = async { - let received = - receive_data(recv, &store, &mut need, now_ms, &commits, batch_bytes).await; + let received = receive_data(recv, &store, &mut need, now_ms, &commits, batch_bytes).await; // Signal on every exit, error included: the sending half waits for this // signal before it can finish, and a failed receive must not hold the // session open until its deadline. diff --git a/pkgs/id/src/groups/tests.rs b/pkgs/id/src/groups/tests.rs index 3fdd604e86..12b65c5746 100644 --- a/pkgs/id/src/groups/tests.rs +++ b/pkgs/id/src/groups/tests.rs @@ -1792,7 +1792,12 @@ fn test_an_admin_scoped_device_grant_is_applied_under_weak_remove_without_a_read fn test_a_device_authored_grant_stands_under_weak_remove_with_a_wide_removal_past() { let g = id("g"); let events = vec![ - custom("g", 1, &[], with_removal(Removal::Weak, Some(Delegation::KeepPrior))), + custom( + "g", + 1, + &[], + with_removal(Removal::Weak, Some(Delegation::KeepPrior)), + ), add("a0", 1, g, 2, Role::Write, &["g"]), add("a1", 1, g, 3, Role::Write, &["a0"]), delegate("d0", 1, g, 2, Role::Write, true, &["a1"]), diff --git a/pkgs/id/src/invite.rs b/pkgs/id/src/invite.rs index d21d3cba35..ace3c0262f 100644 --- a/pkgs/id/src/invite.rs +++ b/pkgs/id/src/invite.rs @@ -235,11 +235,11 @@ mod tests { let err = Invite::from_query(&format!("key={KEY}&key={other_key}&node={NODE}&name=Ann")) .unwrap_err(); assert!(format!("{err:#}").contains("key"), "{err:#}"); - let err = Invite::from_query(&format!("key=invalid&key={KEY}&node={NODE}&name=Ann")) - .unwrap_err(); + let err = + Invite::from_query(&format!("key=invalid&key={KEY}&node={NODE}&name=Ann")).unwrap_err(); assert!(format!("{err:#}").contains("key"), "{err:#}"); - let err = Invite::from_query(&format!("key={KEY}&key=invalid&node={NODE}&name=Ann")) - .unwrap_err(); + let err = + Invite::from_query(&format!("key={KEY}&key=invalid&node={NODE}&name=Ann")).unwrap_err(); assert!(format!("{err:#}").contains("key"), "{err:#}"); // Duplicate node (both valid, invalid first, invalid last) @@ -254,8 +254,8 @@ mod tests { assert!(format!("{err:#}").contains("node"), "{err:#}"); // Duplicate name - let err = Invite::from_query(&format!("key={KEY}&node={NODE}&name=Ann&name=Eve")) - .unwrap_err(); + let err = + Invite::from_query(&format!("key={KEY}&node={NODE}&name=Ann&name=Eve")).unwrap_err(); assert!(format!("{err:#}").contains("name"), "{err:#}"); // Invalid escapes are refused whether they occur first or last assert!(Invite::from_query(&format!("key={KEY}&node={NODE}&name=%zz&name=Eve")).is_err()); diff --git a/pkgs/id/src/repl/input.rs b/pkgs/id/src/repl/input.rs index 7d5d2ca25b..39f10f3604 100644 --- a/pkgs/id/src/repl/input.rs +++ b/pkgs/id/src/repl/input.rs @@ -319,6 +319,78 @@ fn remap_spans( /// ReplInput::NeedMore { delimiter, .. } if delimiter == "EOF" /// )); /// ``` +/// Whether `cmd` ends with the `-` content placeholder in trailing +/// position — a lone `-` as the final token. The supported form puts +/// the placeholder before the stored name (`put - name ...`); a +/// trailing one was historically "handled" by a literal `" -$"` +/// replace, which is not an end anchor and never matched, so the +/// content addressed to it was silently dropped or misrouted +/// (#2280). All three input forms (here-string, pipe, heredoc) +/// reject the trailing form with the error below instead. +fn has_trailing_placeholder(cmd: &str) -> bool { + let t = cmd.trim_end(); + t == "-" || t.ends_with(" -") +} + + +/// `cmd` with every here-string (`<<<` plus its content) removed. +/// Here-string content is literal data, not command syntax: a `-` +/// payload (`<<< -`) is not a trailing placeholder, and a quoted +/// payload is not an operator. Source-level validation that inspects +/// a command containing a here-string must look at the command with +/// the data excluded, or it rejects lines the substitution stages +/// handle correctly (Codex review, PR #3096). An unquoted payload +/// consumes the rest of the line; an unterminated quote drops the +/// remainder here too — the here-string stage itself reports that +/// error when it runs. +fn without_here_strings(cmd: &str) -> String { + let mut result = cmd.to_owned(); + while let Some(pos) = find_unquoted_from(&result, "<<<", &[], 0) { + let before = result[..pos].to_owned(); + let after = result[pos + 3..].trim_start().to_owned(); + let rest = match after.chars().next() { + Some(quote @ ('\'' | '"')) => match after[1..].find(quote) { + Some(end) => after[1 + end + 1..].to_owned(), + None => String::new(), + }, + _ => String::new(), + }; + result = format!("{before}{rest}"); + } + result +} + +fn trailing_placeholder_error() -> anyhow::Error { + anyhow::anyhow!( + "unsupported trailing '-' content placeholder: place '-' before the name (put - name ...)" + ) +} + +// Here-string content is removed before pipes are processed. In particular, +// unquoted content consumes the rest of the line, including any `|>`. +fn source_pipe_position(line: &str) -> Option { + let mut from = 0; + loop { + let pipe = find_unquoted_from(line, "|>", &[], from); + let here = find_unquoted_from(line, "<<<", &[], from); + match (pipe, here) { + (Some(p), Some(h)) if p < h => return Some(p), + (Some(p), None) => return Some(p), + (_, Some(h)) => { + let after = &line[h + 3..]; + let content = after.trim_start(); + let quote = content.chars().next()?; + if quote != '\'' && quote != '"' { + return None; + } + let end = content[1..].find(quote)?; + from = line.len() - content.len() + 1 + end + 1; + } + (None, None) => return None, + } + } +} + pub fn preprocess_repl_line(line: &str) -> Result { let line = line.trim(); if line.is_empty() { @@ -333,6 +405,9 @@ pub fn preprocess_repl_line(line: &str) -> Result { let delimiter = after.trim().to_owned(); if !delimiter.is_empty() { let original_line = line[..heredoc_start].trim().to_owned(); + if has_trailing_placeholder(&original_line) { + return Err(trailing_placeholder_error()); + } return Ok(ReplInput::NeedMore { delimiter, lines: Vec::new(), @@ -342,6 +417,26 @@ pub fn preprocess_repl_line(line: &str) -> Result { } } + // Validate the pipe's trailing placeholder on the SOURCE line, + // before any stage that executes shell code: the $(...) and + // backtick stages below run substitutions while expanding the + // left side, so reaching the pipe stage's own check (after those + // stages) would already have executed `echo $(touch ...)` + // before reporting the placeholder error -- and a failing + // substitution would mask the diagnostic with its own error + // (Codex review, PR #3096). + if let Some(pos) = source_pipe_position(line) { + let right = line[pos + 2..].trim(); + // The right side may carry a here-string whose payload is + // literal data: `echo hi |> put - name <<< -` stores `-` + // under `name` (the payload fills the mid-line placeholder), + // so the trailing check must exclude here-string content or + // it rejects a supported line (Codex review, PR #3096). + if has_trailing_placeholder(&without_here_strings(right)) { + return Err(trailing_placeholder_error()); + } + } + let mut result = line.to_owned(); // Protected spans of stage-inserted text, in `result` coordinates. @@ -374,11 +469,12 @@ pub fn preprocess_repl_line(line: &str) -> Result { (after.trim(), "") }; + if rest.trim().is_empty() && has_trailing_placeholder(before.trim()) { + return Err(trailing_placeholder_error()); + } // Replace - with content marker in the command let before_str = before.trim(); - let new_before = before_str - .replace(" - ", &format!(" __STDIN_CONTENT__:{content} ")) - .replace(" -$", &format!(" __STDIN_CONTENT__:{content}")); + let new_before = before_str.replace(" - ", &format!(" __STDIN_CONTENT__:{content} ")); here_contents.push(content.to_owned()); result = format!("{new_before}{rest}"); protected = content_spans(&result, &here_contents); @@ -518,14 +614,15 @@ pub fn preprocess_repl_line(line: &str) -> Result { let left = result[..pos].trim().to_owned(); let right = result[pos + 2..].trim().to_owned(); + if has_trailing_placeholder(&right) { + return Err(trailing_placeholder_error()); + } + // Execute left side as shell command let output = shell_capture(&left)?; // Replace - in right side with stdin content marker - let mut new_result = right - .replace(" - ", &format!(" __STDIN_CONTENT__:{output} ")) - .replace(" -\n", &format!(" __STDIN_CONTENT__:{output}\n")) - .replace(" -$", &format!(" __STDIN_CONTENT__:{output}")); + let mut new_result = right.replace(" - ", &format!(" __STDIN_CONTENT__:{output} ")); // If no - found, might be at end if !new_result.contains("__STDIN_CONTENT__") { @@ -701,6 +798,157 @@ mod tests { } } + #[test] + fn test_here_string_pipe_is_literal_content() { + for line in [ + "put - name <<< literal |> -", + "put - name <<< 'literal |> -'", + "put - name <<< \"literal |> -\"", + ] { + match preprocess_repl_line(line).unwrap() { + ReplInput::Ready(s) => assert_eq!(s, "put __STDIN_CONTENT__:literal |> - name"), + _ => panic!("expected Ready"), + } + } + } + + #[test] + fn test_pipe_after_quoted_here_string_rejected_before_substitution() { + for quote in ['\'', '"'] { + let line = format!("echo $(exit 3) <<< {quote}literal |> -{quote} |> put name -"); + let error = preprocess_repl_line(&line).unwrap_err().to_string(); + assert!(error.contains("trailing '-' content placeholder"), "{error}"); + } + } + + + #[test] + fn test_pipe_rhs_here_string_dash_payload_is_literal() { + // Codex review, PR #3096: a real pipe before a here-string + // whose payload is `-` — the payload is data for the mid-line + // placeholder, not a trailing placeholder. + for line in [ + "echo hi |> put - name <<< -", + "echo hi |> put - name <<< '-'", + "echo hi |> put - name <<< \"-\"", + ] { + match preprocess_repl_line(line).unwrap() { + ReplInput::Ready(s) => { + assert_eq!(s, "put __STDIN_CONTENT__:- name", "{line}") + } + _ => panic!("expected Ready for {line}"), + } + } + } + + #[test] + fn test_pipe_rhs_trailing_dash_with_here_string_still_rejected() { + // Excluding the here-string payload must not weaken the + // rejection: a trailing placeholder in the command itself is + // still an error, raised before the left side executes. + let result = preprocess_repl_line("exit 3 |> put name - <<< payload"); + assert!(result.is_err()); + assert!( + result + .unwrap_err() + .to_string() + .contains("trailing '-' content placeholder") + ); + } + + #[test] + fn test_preprocess_here_string_trailing_dash_rejected() { + // #2280: the trailing form was silently dropped by a dead + // literal " -$" replace; it is rejected consistently now. + let result = preprocess_repl_line("put name - <<< 'payload'"); + assert!(result.is_err()); + assert!( + result + .unwrap_err() + .to_string() + .contains("trailing '-' content placeholder") + ); + } + + #[test] + fn test_preprocess_pipe_trailing_dash_rejected_before_execution() { + // The left side would fail if it ran; the placeholder error + // must win, proving the rejection precedes pipe execution. + let result = preprocess_repl_line("exit 3 |> put name -"); + assert!(result.is_err()); + assert!( + result + .unwrap_err() + .to_string() + .contains("trailing '-' content placeholder") + ); + } + + #[test] + fn test_preprocess_pipe_trailing_dash_rejected_before_substitution() { + // The substitution on the left would create a file if it ran; + // the placeholder error must win and the file must not exist: + // rejection precedes every stage that executes shell code + // (Codex review, PR #3096). + let marker = std::env::temp_dir().join(format!( + "mcpx-repl-side-effect-{}", + std::process::id() + )); + let _ = std::fs::remove_file(&marker); + let line = format!( + "echo $(touch {}) |> put name -", + marker.display() + ); + let result = preprocess_repl_line(&line); + assert!( + result + .unwrap_err() + .to_string() + .contains("trailing '-' content placeholder") + ); + assert!( + !marker.exists(), + "substitution executed before the placeholder rejection" + ); + // A failing substitution must not mask the diagnostic either. + let result = preprocess_repl_line("echo $(exit 3) |> put name -"); + assert!( + result + .unwrap_err() + .to_string() + .contains("trailing '-' content placeholder") + ); + } + + #[test] + fn test_preprocess_pipe_midline_placeholder_substitutes() { + match preprocess_repl_line("echo hi |> put - name").unwrap() { + ReplInput::Ready(s) => assert_eq!(s, "put __STDIN_CONTENT__:hi name"), + _ => panic!("expected Ready"), + } + } + + #[test] + fn test_preprocess_pipe_without_placeholder_appends() { + match preprocess_repl_line("echo hi |> put name").unwrap() { + ReplInput::Ready(s) => assert_eq!(s, "put name __STDIN_CONTENT__:hi"), + _ => panic!("expected Ready"), + } + } + + #[test] + fn test_preprocess_heredoc_trailing_dash_rejected() { + // Rejected at the start line, before any body is collected. + let result = preprocess_repl_line("put name - <) -> Result<()> { // Heredoc mode - read until delimiter match continue_heredoc(&mut rl, &delimiter, &mut lines) { Ok(Some(content)) => { - // Replace - with content marker in original line - original_line - .replace(" - ", &format!(" __STDIN_CONTENT__:{content} ")) - .replace(" -$", &format!(" __STDIN_CONTENT__:{content}")) + substitute_heredoc_content(&original_line, &content) } Ok(None) => continue, // Cancelled Err(e) => { @@ -431,6 +428,16 @@ async fn execute_repl_command( } } +/// Substitute a collected heredoc body for the `-` placeholder in +/// the original command line. Only the mid-line form can reach this +/// point: a trailing placeholder is rejected when the heredoc starts +/// (see `preprocess_repl_line` in input.rs, #2280), and this helper +/// intentionally has no end-of-line case — the historical literal +/// `" -$"` replace here never matched anything. +fn substitute_heredoc_content(original_line: &str, content: &str) -> String { + original_line.replace(" - ", &format!(" __STDIN_CONTENT__:{content} ")) +} + /// Handle commands containing the `__STDIN_CONTENT__:` marker. /// /// This function processes commands where content was inlined via @@ -1462,6 +1469,31 @@ fn print_peek_words( mod tests { use super::*; + #[test] + fn test_substitute_heredoc_content_midline() { + // Supported form: the placeholder sits before the name, and + // body content with spaces lands inline (#2280 control). + assert_eq!( + substitute_heredoc_content("put - name", "hello world"), + "put __STDIN_CONTENT__:hello world name" + ); + } + + #[test] + fn test_substitute_heredoc_content_multiline() { + assert_eq!( + substitute_heredoc_content("put - name", "line one\nline two"), + "put __STDIN_CONTENT__:line one\nline two name" + ); + } + + #[test] + fn test_substitute_heredoc_content_no_placeholder() { + // No placeholder: the line passes through unchanged (the + // trailing form is rejected at heredoc start, in input.rs). + assert_eq!(substitute_heredoc_content("put name", "body"), "put name"); + } + #[test] fn test_parse_target_node_with_node() { let parts = vec![ diff --git a/pkgs/id/src/web/mod.rs b/pkgs/id/src/web/mod.rs index 79247705b4..dc79ad4e72 100644 --- a/pkgs/id/src/web/mod.rs +++ b/pkgs/id/src/web/mod.rs @@ -389,7 +389,10 @@ mod tests { limiter.record("a.txt").await; let remaining = limiter.check("a.txt").await.unwrap_err(); assert!(remaining <= Duration::from_secs(5) && !remaining.is_zero()); - assert!(limiter.check("b.txt").await.is_ok(), "other files are not limited"); + assert!( + limiter.check("b.txt").await.is_ok(), + "other files are not limited" + ); } #[tokio::test] @@ -410,7 +413,10 @@ mod tests { let limiter = SaveRateLimiter::new(Duration::from_millis(60)); limiter.record("a.txt").await; tokio::time::sleep(Duration::from_millis(200)).await; - assert!(limiter.check("a.txt").await.is_ok(), "the cooldown has lapsed"); + assert!( + limiter.check("a.txt").await.is_ok(), + "the cooldown has lapsed" + ); assert!(limiter.last_save.lock().await.is_empty()); } diff --git a/pkgs/id/src/world/tests.rs b/pkgs/id/src/world/tests.rs index 855272566a..150f40acb5 100644 --- a/pkgs/id/src/world/tests.rs +++ b/pkgs/id/src/world/tests.rs @@ -752,15 +752,15 @@ mod tests { #[tokio::test] async fn subscribed_ticks_arrive_only_while_someone_is_present() { let clock: Arc = Arc::new(ManualClock::new(0)); - let mut core = - WorldCore::new_with_clock( - "ticks", - WorldLimits { - min_tick_ms: 20, - ..WorldLimits::default() - }, - clock.clone(), - ).unwrap(); + let mut core = WorldCore::new_with_clock( + "ticks", + WorldLimits { + min_tick_ms: 20, + ..WorldLimits::default() + }, + clock.clone(), + ) + .unwrap(); core.ledger .set_granted(BTreeSet::from(["time.tick".to_owned()])); let (_, _token) = core @@ -805,15 +805,15 @@ mod tests { #[tokio::test] async fn ticks_follow_the_world_grant_not_a_participant_capability() { let clock: Arc = Arc::new(ManualClock::new(0)); - let mut core = - WorldCore::new_with_clock( - "ticks", - WorldLimits { - min_tick_ms: 20, - ..WorldLimits::default() - }, - clock.clone(), - ).unwrap(); + let mut core = WorldCore::new_with_clock( + "ticks", + WorldLimits { + min_tick_ms: 20, + ..WorldLimits::default() + }, + clock.clone(), + ) + .unwrap(); core.ledger .set_granted(BTreeSet::from(["time.tick".to_owned()])); let owner_scopes = WorldScopes(WorldScopes::GUEST.bits() | WorldScopes::DELEGATE.bits()); @@ -883,16 +883,15 @@ mod tests { #[tokio::test] async fn ticks_speak_for_the_world_not_for_a_present_participant() { let clock: Arc = Arc::new(ManualClock::new(0)); - let mut core = - WorldCore::new_with_clock( - "tick-attribution", - WorldLimits { - min_tick_ms: 20, - ..WorldLimits::default() - }, - clock.clone(), - ) - .unwrap(); + let mut core = WorldCore::new_with_clock( + "tick-attribution", + WorldLimits { + min_tick_ms: 20, + ..WorldLimits::default() + }, + clock.clone(), + ) + .unwrap(); core.ledger.set_granted(BTreeSet::from([ "time.tick".to_owned(), "chat.say".to_owned(), @@ -1127,16 +1126,15 @@ mod tests { #[tokio::test] async fn lowering_the_ceiling_stops_an_active_subscription_and_reports_it_refused() { let clock: Arc = Arc::new(ManualClock::new(0)); - let mut core = - WorldCore::new_with_clock( - "ceiling-ticks", - WorldLimits { - min_tick_ms: 20, - ..WorldLimits::default() - }, - clock.clone(), - ) - .unwrap(); + let mut core = WorldCore::new_with_clock( + "ceiling-ticks", + WorldLimits { + min_tick_ms: 20, + ..WorldLimits::default() + }, + clock.clone(), + ) + .unwrap(); core.ledger .set_granted(BTreeSet::from(["time.tick".to_owned()])); let (_, _token) = core diff --git a/pkgs/id/src/world_ssh.rs b/pkgs/id/src/world_ssh.rs index 2dc8cdbd40..f2d731fee2 100644 --- a/pkgs/id/src/world_ssh.rs +++ b/pkgs/id/src/world_ssh.rs @@ -2963,14 +2963,18 @@ mod tests { ); // ...and the whole drain has a larger, but still finite, total cap, so // a many-page world stops instead of streaming without bound. - const { assert!( - MAX_RECORDS_TOTAL_BYTES > MAX_RECORDS_TERMINAL_BYTES, - "the total cap must exceed the per-page cap" - ) }; - const { assert!( - MAX_RECORDS_TOTAL_BYTES < usize::MAX / 4, - "the total cap must be finite" - ) }; + const { + assert!( + MAX_RECORDS_TOTAL_BYTES > MAX_RECORDS_TERMINAL_BYTES, + "the total cap must exceed the per-page cap" + ) + }; + const { + assert!( + MAX_RECORDS_TOTAL_BYTES < usize::MAX / 4, + "the total cap must be finite" + ) + }; } #[cfg(test)] diff --git a/pkgs/id/tests/attestation_poc.rs b/pkgs/id/tests/attestation_poc.rs index 438d4a3f18..de897ad2e4 100644 --- a/pkgs/id/tests/attestation_poc.rs +++ b/pkgs/id/tests/attestation_poc.rs @@ -28,8 +28,8 @@ use p2panda_core::{Hash, SigningKey}; use tempfile::TempDir; use id::attestation::{ - author_id, compute_state, player_id, sign_claim, sign_genesis, GenesisAgreement, MatchState, - ResultClaim, + GenesisAgreement, MatchState, ResultClaim, author_id, compute_state, player_id, sign_claim, + sign_genesis, }; use id::chain; use id::event_store::{EventStore, Ingest}; diff --git a/pkgs/id/tests/bridge_poc.rs b/pkgs/id/tests/bridge_poc.rs index 02c26e1f6e..3f310c576c 100644 --- a/pkgs/id/tests/bridge_poc.rs +++ b/pkgs/id/tests/bridge_poc.rs @@ -1149,7 +1149,12 @@ async fn bridge_session_converges_with_waiting_events_on_both_sides() { // Hosted receives only x0 first -> x0 is applied hosted.ingest_batch(&[x0.bytes.clone()], NOW_MS); assert_eq!( - hosted.store.chain(&xena.public()).unwrap().unwrap().next_seq, + hosted + .store + .chain(&xena.public()) + .unwrap() + .unwrap() + .next_seq, 1 ); diff --git a/pkgs/id/tests/search.rs b/pkgs/id/tests/search.rs index d821f5a21d..abe78c1587 100644 --- a/pkgs/id/tests/search.rs +++ b/pkgs/id/tests/search.rs @@ -17,11 +17,11 @@ use std::collections::BTreeMap; -use id::chain::{sign, ChainExt, Event}; -use id::documents::{DocumentRef, DOCUMENT_KIND}; +use id::chain::{ChainExt, Event, sign}; +use id::documents::{DOCUMENT_KIND, DocumentRef}; use id::event_store::{EventStore, Ingest}; -use id::search::{search, search_store, search_store_terms, search_terms, Hit, Term, ValueMatch}; -use id::tag_claims::{Claim, TagOp, CLEAR_KIND, SET_KIND}; +use id::search::{Hit, Term, ValueMatch, search, search_store, search_store_terms, search_terms}; +use id::tag_claims::{CLEAR_KIND, Claim, SET_KIND, TagOp}; use id::waiting::WaitingLimits; use p2panda_core::{Hash, SeqNum, SigningKey}; use proptest::prelude::*; @@ -240,12 +240,16 @@ fn test_a_cleared_claim_is_not_returned() { deliver(&mut store, event); } - assert!(search_store(&store, "city", ValueMatch::Any) - .unwrap() - .is_empty()); - assert!(search_store(&store, "city", ValueMatch::Exact("Seattle")) - .unwrap() - .is_empty()); + assert!( + search_store(&store, "city", ValueMatch::Any) + .unwrap() + .is_empty() + ); + assert!( + search_store(&store, "city", ValueMatch::Exact("Seattle")) + .unwrap() + .is_empty() + ); // The clear removes only the claim it names. let names = search_store(&store, "name", ValueMatch::Any).unwrap(); assert_eq!(shape(&names), vec![(subject, vec![kept.id])]); @@ -357,26 +361,32 @@ fn test_hits_are_ordered_by_subject_then_claim_and_do_not_depend_on_delivery_ord .find(|(subject, _)| *subject == subjects[0]) .unwrap(); assert_eq!(on_first.1.len(), 2, "both claims on the first subject"); - assert!(on_first - .1 - .windows(2) - .all(|pair| pair[0].as_bytes() < pair[1].as_bytes())); + assert!( + on_first + .1 + .windows(2) + .all(|pair| pair[0].as_bytes() < pair[1].as_bytes()) + ); } #[test] fn test_a_search_matches_nothing_on_an_empty_store_or_an_unknown_name() { let (_dir, store) = open(); - assert!(search_store(&store, "city", ValueMatch::Any) - .unwrap() - .is_empty()); + assert!( + search_store(&store, "city", ValueMatch::Any) + .unwrap() + .is_empty() + ); let mut a = Writer::new(1); let claim = a.set(Hash::digest(b"s"), "city", Some("Seattle"), vec![]); let (_dir2, mut store) = open(); deliver(&mut store, &claim); - assert!(search_store(&store, "state", ValueMatch::Any) - .unwrap() - .is_empty()); + assert!( + search_store(&store, "state", ValueMatch::Any) + .unwrap() + .is_empty() + ); } /// The live claims' IDs, sorted by ID bytes. @@ -470,9 +480,11 @@ fn test_search_by_author_returns_only_that_authors_claims() { vec![(subject, vec![seattle.id])] ); // An author with no claims matches nothing. - assert!(search_store_terms(&store, &[Term::Author([9; 32])]) - .unwrap() - .is_empty()); + assert!( + search_store_terms(&store, &[Term::Author([9; 32])]) + .unwrap() + .is_empty() + ); } #[test]