Skip to content

Commit

Permalink
fix: include ID in serialized matches (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed Jul 19, 2024
1 parent 8043cfa commit 86b88bf
Show file tree
Hide file tree
Showing 39 changed files with 105 additions and 41 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/cli_bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tracing-subscriber = { version = "0.3", default-features = false, optional = tru
serde_json = "1.0.96"
tempfile = "3.1"
rayon = "1.8.0"
insta = { version = "1.30.0", features = ["yaml", "redactions"] }
insta = { version = "1.30.0", features = ["yaml", "redactions", "filters"] }
predicates = "3.0.3"
fs_extra = "1.3"
ntest = "0.9.0"
Expand Down
6 changes: 4 additions & 2 deletions crates/cli_bin/tests/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rayon::iter::ParallelIterator;
use regex::Regex;
use std::sync::Once;

use crate::common::{get_fixture, get_fixtures_root, run_init_cmd};
use crate::common::{get_fixture, get_fixtures_root, run_init_cmd, INSTA_FILTERS};

mod common;

Expand Down Expand Up @@ -1708,7 +1708,9 @@ fn output_jsonl() -> Result<()> {
);

let content = fs_err::read_to_string(dir.join("output.jsonl"))?;
assert_snapshot!(content);
insta::with_settings!({filters => INSTA_FILTERS.to_vec()}, {
assert_snapshot!(content);
});

let line_count = content.lines().count();
assert_eq!(line_count, 3);
Expand Down
4 changes: 4 additions & 0 deletions crates/cli_bin/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use marzano_gritmodule::config::GRIT_GLOBAL_DIR_ENV;
use tempfile::tempdir;

pub const BIN_NAME: &str = "marzano";
pub const INSTA_FILTERS: &[(&str, &str)] = &[(
r"\b[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}\b",
"[UUID]",
)];

#[allow(dead_code)]
pub fn get_test_cmd() -> Result<Command> {
Expand Down
4 changes: 2 additions & 2 deletions crates/cli_bin/tests/snapshots/apply__output_jsonl.snap

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ grit-util = { path = "../grit-util" }
tracing = { version = "0.1.40", default-features = false, features = [] }
tracing-opentelemetry = { version = "0.22.0", optional = true, default-features = false, features = [
] }

uuid = { version = "1.1", features = ["v4", "serde"] }
regex = { version = "1.7.3" }
anyhow = { version = "1.0.70" }
itertools = { version = "0.10.5" }
Expand All @@ -47,7 +47,7 @@ fs-err = { version = "2.11.0" }
[dev-dependencies]
similar = "2.2.1"
lazy_static = "1.4.0"
insta = { version = "1.30.0", features = ["yaml", "redactions"] }
insta = { version = "1.30.0", features = ["yaml", "redactions", "filters"] }
trim-margin = "0.1.0"
marzano-auth = { path = "../auth", features = ["test-utils"] }
walkdir = "2.3.3"
Expand Down
12 changes: 12 additions & 0 deletions crates/core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
use serde_json::to_string_pretty;
use std::path::PathBuf;
use std::{fmt, str::FromStr, vec};
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -343,6 +344,8 @@ pub struct Match {
pub ranges: Vec<Range>,
#[serde(default)]
pub reason: Option<MatchReason>,
#[serde(default)]
pub id: Uuid,
}

impl From<EntireFile> for Match {
Expand All @@ -354,6 +357,7 @@ impl From<EntireFile> for Match {
ranges: file_match.ranges,
reason: None,
content: file_match.content,
id: Uuid::new_v4(),
}
}
}
Expand Down Expand Up @@ -456,6 +460,8 @@ pub struct Rewrite {
pub rewritten: EntireFile,
#[serde(default)]
pub reason: Option<MatchReason>,
#[serde(default)]
pub id: Uuid,
}

impl From<Rewrite> for MatchResult {
Expand Down Expand Up @@ -558,6 +564,7 @@ impl Rewrite {
original,
rewritten,
reason,
id: Uuid::new_v4(),
}
}
}
Expand All @@ -568,6 +575,8 @@ pub struct CreateFile {
pub rewritten: EntireFile,
range: Option<Vec<Range>>,
pub reason: Option<MatchReason>,
#[serde(default)]
pub id: Uuid,
}

impl From<CreateFile> for MatchResult {
Expand All @@ -582,6 +591,7 @@ impl CreateFile {
rewritten: EntireFile::file_to_entire_file(name, body, None),
range: None,
reason: None,
id: Uuid::new_v4(),
}
}
}
Expand Down Expand Up @@ -622,6 +632,8 @@ pub struct RemoveFile {
pub original: EntireFile,
#[serde(default)]
pub reason: Option<MatchReason>,
#[serde(default)]
pub id: Uuid,
}

impl From<RemoveFile> for MatchResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ expression: results
end: 68
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ expression: results
end: 68
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ expression: results
end: 16
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ expression: results
end: 15
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: foo.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ expression: results
end: 19
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: foo.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ expression: results
end: 19
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ expression: results
end: 16
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ expression: results
content: "import { findConfigs } from './configs';\n// Remember: ./packages/timekeeper/src/__generated__/stdlib.ts\nexport const stdlib = {\n show,\n apply,\n sh,\n};\n\nexport type StdLibFunctions = typeof stdlib;"
ranges: []
reason: ~
id: [UUID]
- __typename: Rewrite
original:
messages: []
Expand Down Expand Up @@ -123,6 +124,7 @@ expression: results
end: 47
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: ~/dev/rewriter/packages/sdk/src/stdlib/index.ts
- __typename: DoneFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ expression: results
end: 12
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: foo.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ expression: results
end: 27
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ expression: results
end: 13
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ expression: results
end: 7
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,6 @@ expression: results
startByte: 9
endByte: 12
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,6 @@ expression: results
end: 95
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,6 @@ expression: results
end: 114
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@ expression: results
startByte: 9
endByte: 12
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ expression: results
end: 63
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: foo.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ expression: results
end: 63
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: foo.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ expression: results
end: 30
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: foo.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ expression: results
end: 27
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: foo.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ expression: results
end: 27
ranges: []
reason: ~
id: [UUID]
- __typename: Rewrite
original:
messages: []
Expand Down Expand Up @@ -294,6 +295,7 @@ expression: results
end: 34
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: file1.tsx
- __typename: DoneFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ expression: results
content: foo(1)
ranges: []
reason: ~
id: [UUID]
- __typename: Rewrite
original:
messages: []
Expand Down Expand Up @@ -141,6 +142,7 @@ expression: results
end: 6
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: file1.tsx
- __typename: DoneFile
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/snapshots/marzano_core__test__program.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ expression: results
end: 30
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ expression: results
end: 7
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ expression: results
byteRanges: []
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ expression: results
end: 110
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ expression: results
end: 18
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ expression: results
startByte: 8
endByte: 11
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ expression: results
end: 42
ranges: []
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ expression: results
startByte: 0
endByte: 13
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ expression: results
startByte: 0
endByte: 13
reason: ~
id: [UUID]
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Loading

0 comments on commit 86b88bf

Please sign in to comment.