Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkgs/atlas-search/crates/atlas-core/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,11 @@ fn next_shard_part(shard_dir: &Path, tier: Tier, topic: &str) -> Result<u32> {
let Some(stem) = p.file_stem().and_then(|s| s.to_str()) else {
continue;
};
if let Some((t, tp, part)) = crate::shards::parse_shard_name(stem) {
if t == tier && tp == topic {
next = next.max(part + 1);
}
if let Some((t, tp, part)) = crate::shards::parse_shard_name(stem)
&& t == tier
&& tp == topic
{
next = next.max(part + 1);
}
}
Ok(next)
Expand Down
2 changes: 1 addition & 1 deletion pkgs/atlas-search/crates/atlas-core/src/c8_fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub fn group_occurrences(occurrences: &[ErrorOccurrence]) -> Vec<FingerprintGrou
.occurrences
.sort_by(|a, b| (&a.observed_at, &a.source_id).cmp(&(&b.observed_at, &b.source_id)));
}
groups.sort_by(|a, b| a.fingerprint.id().cmp(&b.fingerprint.id()));
groups.sort_by_key(|a| a.fingerprint.id());
groups
}

Expand Down
6 changes: 4 additions & 2 deletions pkgs/atlas-search/crates/atlas-core/src/embed_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ fn vector_to_blob(v: &[f32]) -> Vec<u8> {
}

fn blob_to_vector(b: &[u8]) -> Option<Vec<f32>> {
if b.is_empty() || b.len() % 4 != 0 {
if b.is_empty() || !b.len().is_multiple_of(4) {
return None;
}
Some(
b.chunks_exact(4)
b.as_chunks::<4>()
.0
.iter()
.map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]]))
.collect(),
)
Expand Down
117 changes: 61 additions & 56 deletions pkgs/atlas-search/crates/atlas-core/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,17 @@ mod tests {
}
}

/// One generated duplicate-key case: (raw runs text, signal
/// named in the error, query named, clean runs text, expected
/// surviving runs as (signal, [(query, doc ids)])).
type DupKeyCase<'a> = (
String,
String,
String,
String,
Vec<(&'a str, Vec<(&'a str, &'a [&'a str])>)>,
);

// Oracle: the #6390 parser invariant, property-style over
// generated documents (the repo testing doctrine for parsers):
// for arbitrary query ids (including ids that need JSON
Expand Down Expand Up @@ -1058,66 +1069,60 @@ mod tests {
let r2: &[&str] = &["d3"];
let ro: &[&str] = &["d9"];

// (raw runs text, signal named in the error, query named)
let (dup_runs, dup_signal, dup_query, clean_runs, expected): (
String,
String,
String,
String,
Vec<(&str, Vec<(&str, &[&str])>)>,
) = match case % 3 {
0 => (
run_obj(
&signal,
&results_obj(&[(&q_dup, r1), (&q_dup, r2)]),
results_first,
),
signal.clone(),
q_dup.clone(),
run_obj(&signal, &results_obj(&[(&q_dup, r1)]), results_first),
vec![(signal.as_str(), vec![(q_dup.as_str(), r1)])],
),
1 => (
run_obj(
&signal,
&results_obj(&[(&q_dup, r1), (&q_other, ro), (&q_dup, r2)]),
results_first,
),
signal.clone(),
q_dup.clone(),
run_obj(
&signal,
&results_obj(&[(&q_dup, r1), (&q_other, ro)]),
results_first,
),
vec![(
signal.as_str(),
vec![(q_dup.as_str(), r1), (q_other.as_str(), ro)],
)],
),
_ => (
format!(
"{}, {}",
let (dup_runs, dup_signal, dup_query, clean_runs, expected): DupKeyCase<'_> =
match case % 3 {
0 => (
run_obj(
&signal,
&results_obj(&[(&q_dup, r1), (&q_dup, r2)]),
results_first,
),
signal.clone(),
q_dup.clone(),
run_obj(&signal, &results_obj(&[(&q_dup, r1)]), results_first),
vec![(signal.as_str(), vec![(q_dup.as_str(), r1)])],
),
1 => (
run_obj(
&signal2,
&results_obj(&[(&q_other, ro), (&q_other, r1)]),
results_first
)
&signal,
&results_obj(&[(&q_dup, r1), (&q_other, ro), (&q_dup, r2)]),
results_first,
),
signal.clone(),
q_dup.clone(),
run_obj(
&signal,
&results_obj(&[(&q_dup, r1), (&q_other, ro)]),
results_first,
),
vec![(
signal.as_str(),
vec![(q_dup.as_str(), r1), (q_other.as_str(), ro)],
)],
),
signal2.clone(),
q_other.clone(),
format!(
"{}, {}",
run_obj(&signal, &results_obj(&[(&q_dup, r1)]), results_first),
run_obj(&signal2, &results_obj(&[(&q_other, ro)]), results_first)
_ => (
format!(
"{}, {}",
run_obj(&signal, &results_obj(&[(&q_dup, r1)]), results_first),
run_obj(
&signal2,
&results_obj(&[(&q_other, ro), (&q_other, r1)]),
results_first
)
),
signal2.clone(),
q_other.clone(),
format!(
"{}, {}",
run_obj(&signal, &results_obj(&[(&q_dup, r1)]), results_first),
run_obj(&signal2, &results_obj(&[(&q_other, ro)]), results_first)
),
vec![
(signal.as_str(), vec![(q_dup.as_str(), r1)]),
(signal2.as_str(), vec![(q_other.as_str(), ro)]),
],
),
vec![
(signal.as_str(), vec![(q_dup.as_str(), r1)]),
(signal2.as_str(), vec![(q_other.as_str(), ro)]),
],
),
};
};

let queries: Vec<&str> = vec![&q_dup, &q_other];
let err = EvalData::from_json(&document(&queries, &dup_runs))
Expand Down
4 changes: 2 additions & 2 deletions pkgs/atlas-search/crates/atlas-core/src/github_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl CommentKind {
}

/// Parse the record spelling, if it is one.
pub fn from_str(s: &str) -> Option<Self> {
pub fn parse(s: &str) -> Option<Self> {
match s {
"issue_comment" => Some(CommentKind::IssueComment),
"review_comment" => Some(CommentKind::ReviewComment),
Expand Down Expand Up @@ -238,7 +238,7 @@ pub fn document_from_record(record: &Json) -> Option<CommentDocument> {
thread_number: record.get("thread_number")?.as_u64()?,
is_pr: record.get("thread_kind")?.as_str()? == "pull_request",
comment_id: record.get("comment_id")?.as_u64()?,
kind: CommentKind::from_str(record.get("kind")?.as_str()?)?,
kind: CommentKind::parse(record.get("kind")?.as_str()?)?,
author: record.get("author")?.as_str()?.to_string(),
created_at: record.get("created_at")?.as_str()?.to_string(),
updated_at: record.get("updated_at")?.as_str()?.to_string(),
Expand Down
10 changes: 5 additions & 5 deletions pkgs/atlas-search/crates/atlas-core/src/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,11 @@ fn push_highlight(highlights: &mut Vec<Range<usize>>, range: Range<usize>) {
if range.is_empty() {
return;
}
if let Some(last) = highlights.last_mut() {
if range.start <= last.end {
last.end = last.end.max(range.end);
return;
}
if let Some(last) = highlights.last_mut()
&& range.start <= last.end
{
last.end = last.end.max(range.end);
return;
}
highlights.push(range);
}
Expand Down
6 changes: 1 addition & 5 deletions pkgs/atlas-search/crates/atlas-core/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,7 @@ impl LocalBackend {
let mut prepared = con
.prepare(&stmt.sql)
.map_err(|e| Error::backend(e.to_string()))?;
let col_names: Vec<String> = prepared
.column_names()
.into_iter()
.map(str::to_string)
.collect();
let col_names: Vec<String> = prepared.column_names().map(str::to_string).collect();
let params: Vec<RValue> = stmt.args.iter().map(to_rvalue).collect();
let mut rows = prepared
.query(rusqlite::params_from_iter(params.iter()))
Expand Down
36 changes: 16 additions & 20 deletions pkgs/atlas-search/crates/atlas-core/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,23 +386,19 @@ fn run_search_impl(
let mut permitted: std::collections::HashSet<i64> = std::collections::HashSet::new();
let mut withheld = 0usize;
for e in &ranked {
match all_details.get(&e.chunk_id) {
Some(d) => {
let class = chunk_classification(d.eff_sensitivity.as_deref());
if opts
.context
.permits_with_grant(class, filters.max_sensitivity)
{
permitted.insert(e.chunk_id);
} else {
withheld += 1;
}
// No detail row: the candidate renders nowhere (the
// flat/grouped paths already skip it), and it is not a
// disclosure decision, so it is not counted as withheld.
if let Some(d) = all_details.get(&e.chunk_id) {
let class = chunk_classification(d.eff_sensitivity.as_deref());
if opts
.context
.permits_with_grant(class, filters.max_sensitivity)
{
permitted.insert(e.chunk_id);
} else {
withheld += 1;
}
// No detail row: the candidate renders nowhere
// (the flat/grouped paths already skip it), and it
// is not a disclosure decision, so it is not
// counted as withheld.
None => {}
}
}
if withheld > 0 {
Expand Down Expand Up @@ -587,10 +583,10 @@ fn collect_served(v: Option<&Json>, acc: &mut Vec<i64>) {
}
}
Some(Json::Object(map)) => {
if let Some(id) = map.get("chunk_id").and_then(Json::as_i64) {
if !acc.contains(&id) {
acc.push(id);
}
if let Some(id) = map.get("chunk_id").and_then(Json::as_i64)
&& !acc.contains(&id)
{
acc.push(id);
}
for val in map.values() {
if val.is_array() {
Expand Down
6 changes: 4 additions & 2 deletions pkgs/atlas-search/crates/atlas-core/src/shards/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ use crate::types::{Row, Stmt, Value};
type RValue = rusqlite::types::Value;

fn blob_to_f32(b: &[u8]) -> Option<Vec<f32>> {
if b.len() % 4 != 0 {
if !b.len().is_multiple_of(4) {
return None;
}
Some(
b.chunks_exact(4)
b.as_chunks::<4>()
.0
.iter()
.map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]]))
.collect(),
)
Expand Down
2 changes: 1 addition & 1 deletion pkgs/atlas-search/crates/atlas-core/src/shingles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ pub struct RescoreReport {
/// (deterministic). Entries beyond `depth` are untouched and keep
/// their fused order after the union.
pub fn rescore_fused(
entries: &mut Vec<FusedEntry>,
entries: &mut [FusedEntry],
query: &ShingleSet,
sets: &HashMap<i64, ShingleSet>,
depth: usize,
Expand Down
23 changes: 11 additions & 12 deletions pkgs/atlas-search/crates/atlas-core/src/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,11 @@ pub struct MergeManifest {
/// database reports `_schema_version = 1` and exactly
/// [`STAGE_V1_TABLES`].
pub fn provision_staging_db(path: &Path) -> Result<()> {
if let Some(parent) = path.parent() {
if !parent.as_os_str().is_empty() {
std::fs::create_dir_all(parent).map_err(|e| {
Error::backend(format!("staging: creating {}: {e}", parent.display()))
})?;
}
if let Some(parent) = path.parent()
&& !parent.as_os_str().is_empty()
{
std::fs::create_dir_all(parent)
.map_err(|e| Error::backend(format!("staging: creating {}: {e}", parent.display())))?;
}
let conn = open(path)?;
let existing = user_tables(&conn)?;
Expand Down Expand Up @@ -715,12 +714,12 @@ impl Registry {
/// Open (creating if needed) a registry at `path` and ensure its
/// v1 table exists.
pub fn open(path: &Path) -> Result<Registry> {
if let Some(parent) = path.parent() {
if !parent.as_os_str().is_empty() {
std::fs::create_dir_all(parent).map_err(|e| {
Error::backend(format!("registry: creating {}: {e}", parent.display()))
})?;
}
if let Some(parent) = path.parent()
&& !parent.as_os_str().is_empty()
{
std::fs::create_dir_all(parent).map_err(|e| {
Error::backend(format!("registry: creating {}: {e}", parent.display()))
})?;
}
let conn = open(path)?;
ensure_registry(&conn)?;
Expand Down
Loading