From 86b88bf38252b190af6ef69f4a71a3bcef8dfffe Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Thu, 18 Jul 2024 17:27:10 -0700 Subject: [PATCH] fix: include ID in serialized matches (#426) --- Cargo.lock | 2 + crates/cli_bin/Cargo.toml | 2 +- crates/cli_bin/tests/apply.rs | 6 +- crates/cli_bin/tests/common/mod.rs | 4 + .../tests/snapshots/apply__output_jsonl.snap | 4 +- crates/core/Cargo.toml | 4 +- crates/core/src/api.rs | 12 +++ .../marzano_core__test__add_to_set.snap | 1 + ...no_core__test__add_to_set_via_pattern.snap | 1 + .../marzano_core__test__after_each_file.snap | 1 + .../marzano_core__test__basic_md.snap | 1 + .../marzano_core__test__basic_python.snap | 1 + ...ore__test__before_and_after_each_file.snap | 1 + .../marzano_core__test__before_each_file.snap | 1 + .../marzano_core__test__clone_activites.snap | 2 + .../marzano_core__test__code_span.snap | 1 + .../marzano_core__test__file_rename.snap | 1 + .../marzano_core__test__filename.snap | 1 + .../marzano_core__test__filename_autoset.snap | 1 + ..._core__test__import_all_already_there.snap | 1 + ...arzano_core__test__import_just_insert.snap | 1 + .../marzano_core__test__import_multiple.snap | 1 + .../marzano_core__test__import_none.snap | 1 + ...o_core__test__json_file_match_snippet.snap | 1 + ...no_core__test__json_file_match_string.snap | 1 + ...zano_core__test__md_link_metavariable.snap | 1 + .../marzano_core__test__md_link_node.snap | 1 + ...marzano_core__test__multifile_pattern.snap | 2 + ...tifile_propagates_scope_between_steps.snap | 2 + .../marzano_core__test__program.snap | 1 + .../marzano_core__test__program_autoset.snap | 1 + .../marzano_core__test__rewrite_dot.snap | 1 + ...t__rewrite_or_bubble_pattern_argument.snap | 1 + .../marzano_core__test__saving_info.snap | 1 + .../marzano_core__test__shorthand_log.snap | 1 + ...rzano_core__test__should_log_variable.snap | 1 + .../marzano_core__test__simple_log.snap | 1 + ...zano_core__test__variable_message_log.snap | 1 + crates/core/src/test.rs | 78 +++++++++++-------- 39 files changed, 105 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a952d7e93..398889069 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1804,6 +1804,7 @@ dependencies = [ "linked-hash-map", "pest", "pest_derive", + "regex", "serde", "similar", "yaml-rust", @@ -2216,6 +2217,7 @@ dependencies = [ "tracing-opentelemetry", "tree-sitter-facade-sg", "trim-margin", + "uuid", "walkdir", ] diff --git a/crates/cli_bin/Cargo.toml b/crates/cli_bin/Cargo.toml index 5dca545d0..48d02340e 100644 --- a/crates/cli_bin/Cargo.toml +++ b/crates/cli_bin/Cargo.toml @@ -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" diff --git a/crates/cli_bin/tests/apply.rs b/crates/cli_bin/tests/apply.rs index fc842a561..c3145ed78 100644 --- a/crates/cli_bin/tests/apply.rs +++ b/crates/cli_bin/tests/apply.rs @@ -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; @@ -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); diff --git a/crates/cli_bin/tests/common/mod.rs b/crates/cli_bin/tests/common/mod.rs index 3c79929f3..86e9dd531 100644 --- a/crates/cli_bin/tests/common/mod.rs +++ b/crates/cli_bin/tests/common/mod.rs @@ -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 { diff --git a/crates/cli_bin/tests/snapshots/apply__output_jsonl.snap b/crates/cli_bin/tests/snapshots/apply__output_jsonl.snap index 31c28b411..360059f3b 100644 --- a/crates/cli_bin/tests/snapshots/apply__output_jsonl.snap +++ b/crates/cli_bin/tests/snapshots/apply__output_jsonl.snap @@ -2,6 +2,6 @@ source: crates/cli_bin/tests/apply.rs expression: content --- -{"__typename":"Match","messages":[],"variables":[{"name":"$new_files","scopedName":"0_0_$new_files","ranges":[]},{"name":"$program","scopedName":"0_1_$program","ranges":[]},{"name":"$filename","scopedName":"0_2_$filename","ranges":[]},{"name":"$absolute_filename","scopedName":"0_3_$absolute_filename","ranges":[]},{"name":"$GLOBAL_IMPORTED_SOURCES","scopedName":"0_4_$GLOBAL_IMPORTED_SOURCES","ranges":[]},{"name":"$GLOBAL_IMPORTED_NAMES","scopedName":"0_5_$GLOBAL_IMPORTED_NAMES","ranges":[]},{"name":"$body","scopedName":"2_0_$body","ranges":[{"start":{"line":1,"column":1},"end":{"line":14,"column":2},"startByte":0,"endByte":256}]},{"name":"$p","scopedName":"7_0_$p","ranges":[]},{"name":"$all_imports","scopedName":"7_1_$all_imports","ranges":[]},{"name":"$h","scopedName":"7_2_$h","ranges":[]},{"name":"$statements","scopedName":"7_3_$statements","ranges":[]},{"name":"$anchor","scopedName":"7_4_$anchor","ranges":[]},{"name":"$p","scopedName":"8_0_$p","ranges":[]},{"name":"$all_imports","scopedName":"8_1_$all_imports","ranges":[]},{"name":"$our_source","scopedName":"8_2_$our_source","ranges":[]},{"name":"$imported_names","scopedName":"8_3_$imported_names","ranges":[]},{"name":"$joined_imported_names","scopedName":"8_4_$joined_imported_names","ranges":[]},{"name":"$p","scopedName":"9_0_$p","ranges":[]},{"name":"$our_source","scopedName":"9_1_$our_source","ranges":[]},{"name":"$imported_names","scopedName":"9_2_$imported_names","ranges":[]},{"name":"$all_imports","scopedName":"9_3_$all_imports","ranges":[]},{"name":"$name","scopedName":"9_4_$name","ranges":[]},{"name":"$our_source","scopedName":"10_0_$our_source","ranges":[]},{"name":"$joined_imported_names","scopedName":"10_1_$joined_imported_names","ranges":[]},{"name":"$imports","scopedName":"10_2_$imports","ranges":[]},{"name":"$source","scopedName":"10_3_$source","ranges":[]},{"name":"$statement","scopedName":"10_4_$statement","ranges":[]},{"name":"$imports","scopedName":"11_0_$imports","ranges":[]},{"name":"$source","scopedName":"11_1_$source","ranges":[]},{"name":"$match","scopedName":"12_0_$match","ranges":[{"start":{"line":4,"column":15},"end":{"line":9,"column":4},"startByte":81,"endByte":172},{"start":{"line":6,"column":17},"end":{"line":8,"column":6},"startByte":129,"endByte":168},{"start":{"line":13,"column":10},"end":{"line":13,"column":39},"startByte":223,"endByte":252}]}],"sourceFile":"small.ts","content":"// This is a smaller example\nfunction() { \n console.log(\"thing\");\n const foo = () => {\n console.log(\"bar\");\n const bar = () => {\n console.log(\"baz\");\n }\n };\n // Not this\n // Delay a bit\n // Wow\n handle(() => { console.log(\"foo\"); });\n}","ranges":[{"start":{"line":4,"column":15},"end":{"line":9,"column":4},"startByte":81,"endByte":172},{"start":{"line":6,"column":17},"end":{"line":8,"column":6},"startByte":129,"endByte":168},{"start":{"line":13,"column":10},"end":{"line":13,"column":39},"startByte":223,"endByte":252}],"reason":null} -{"__typename":"Match","messages":[],"variables":[{"name":"$new_files","scopedName":"0_0_$new_files","ranges":[]},{"name":"$program","scopedName":"0_1_$program","ranges":[]},{"name":"$filename","scopedName":"0_2_$filename","ranges":[]},{"name":"$absolute_filename","scopedName":"0_3_$absolute_filename","ranges":[]},{"name":"$GLOBAL_IMPORTED_SOURCES","scopedName":"0_4_$GLOBAL_IMPORTED_SOURCES","ranges":[]},{"name":"$GLOBAL_IMPORTED_NAMES","scopedName":"0_5_$GLOBAL_IMPORTED_NAMES","ranges":[]},{"name":"$body","scopedName":"2_0_$body","ranges":[{"start":{"line":1,"column":1},"end":{"line":120,"column":1},"startByte":0,"endByte":3269}]},{"name":"$p","scopedName":"7_0_$p","ranges":[]},{"name":"$all_imports","scopedName":"7_1_$all_imports","ranges":[]},{"name":"$h","scopedName":"7_2_$h","ranges":[]},{"name":"$statements","scopedName":"7_3_$statements","ranges":[]},{"name":"$anchor","scopedName":"7_4_$anchor","ranges":[]},{"name":"$p","scopedName":"8_0_$p","ranges":[]},{"name":"$all_imports","scopedName":"8_1_$all_imports","ranges":[]},{"name":"$our_source","scopedName":"8_2_$our_source","ranges":[]},{"name":"$imported_names","scopedName":"8_3_$imported_names","ranges":[]},{"name":"$joined_imported_names","scopedName":"8_4_$joined_imported_names","ranges":[]},{"name":"$p","scopedName":"9_0_$p","ranges":[]},{"name":"$our_source","scopedName":"9_1_$our_source","ranges":[]},{"name":"$imported_names","scopedName":"9_2_$imported_names","ranges":[]},{"name":"$all_imports","scopedName":"9_3_$all_imports","ranges":[]},{"name":"$name","scopedName":"9_4_$name","ranges":[]},{"name":"$our_source","scopedName":"10_0_$our_source","ranges":[]},{"name":"$joined_imported_names","scopedName":"10_1_$joined_imported_names","ranges":[]},{"name":"$imports","scopedName":"10_2_$imports","ranges":[]},{"name":"$source","scopedName":"10_3_$source","ranges":[]},{"name":"$statement","scopedName":"10_4_$statement","ranges":[]},{"name":"$imports","scopedName":"11_0_$imports","ranges":[]},{"name":"$source","scopedName":"11_1_$source","ranges":[]},{"name":"$match","scopedName":"12_0_$match","ranges":[{"start":{"line":14,"column":39},"end":{"line":66,"column":4},"startByte":452,"endByte":1767},{"start":{"line":18,"column":19},"end":{"line":22,"column":6},"startByte":590,"endByte":710},{"start":{"line":24,"column":17},"end":{"line":26,"column":6},"startByte":729,"endByte":775},{"start":{"line":32,"column":26},"end":{"line":35,"column":6},"startByte":858,"endByte":933},{"start":{"line":36,"column":26},"end":{"line":39,"column":6},"startByte":961,"endByte":1036},{"start":{"line":40,"column":20},"end":{"line":51,"column":6},"startByte":1058,"endByte":1323},{"start":{"line":52,"column":20},"end":{"line":65,"column":6},"startByte":1345,"endByte":1761},{"start":{"line":71,"column":71},"end":{"line":71,"column":79},"startByte":1882,"endByte":1890},{"start":{"line":107,"column":25},"end":{"line":119,"column":2},"startByte":2904,"endByte":3267},{"start":{"line":109,"column":71},"end":{"line":109,"column":79},"startByte":2997,"endByte":3005}]}],"sourceFile":"big.ts","content":"import type { ChildProcessWithoutNullStreams } from 'child_process';\nimport { spawn } from 'child_process';\nimport type { stdlib } from '@getgrit/api';\n\nexport function wrap_exec({\n callback,\n cp,\n passOnNonZeroExitCode,\n}: {\n callback?: (write: (str: string) => void, end: () => void) => void;\n cp: ChildProcessWithoutNullStreams;\n passOnNonZeroExitCode: boolean | undefined;\n}): Promise {\n return new Promise((resolve) => {\n const allout = [] as string[];\n const stdout = [] as string[];\n const stderr = [] as string[];\n const write = (str: string): void => {\n process.stdin.cork();\n process.stdin.write(str);\n process.stdin.uncork();\n };\n\n const end = (): void => {\n process.stdin.end();\n };\n\n if (callback) {\n callback(write, end);\n }\n\n cp.stdout.on('data', (data: string) => {\n stdout.push(data);\n allout.push(data);\n });\n cp.stderr.on('data', (data: string) => {\n stderr.push(data);\n allout.push(data);\n });\n cp.on('error', (e) => {\n resolve({\n __typename: 'ShResult',\n kind: 'direct',\n success: false,\n code: -1,\n allout: allout.join(''),\n stdout: stdout.join(''),\n stderr: stderr.join(''),\n message: e.message,\n });\n });\n cp.on('close', (code: number) => {\n // Trailing info is more valuable than truncated.\n const message = stderr.join('').slice(-2000);\n resolve({\n __typename: 'ShResult',\n kind: 'direct',\n success: passOnNonZeroExitCode ? true : code === 0,\n code: code || 0,\n allout: allout.join(''),\n stdout: stdout.join(''),\n stderr: stderr.join(''),\n message,\n });\n });\n });\n}\n\nexport function baseSh(\n cmd: string,\n callback: (write: (str: string) => void, end: () => void) => void = () => {},\n cwd: string | URL | undefined = undefined,\n passOnNonZeroExitCode: boolean | undefined = undefined,\n env: NodeJS.ProcessEnv | undefined = undefined,\n detached?: boolean,\n): Promise {\n const cp = spawn(cmd, { shell: true, detached, cwd, env: { ...process.env, ...(env ?? {}) } });\n const interruptCP = function () {\n cp.emit('SIGINT');\n };\n\n try {\n const promise = wrap_exec({ callback, cp, passOnNonZeroExitCode });\n if (!detached) {\n return promise;\n }\n } finally {\n process.removeListener('SIGINT', interruptCP);\n }\n return Promise.resolve({\n __typename: 'ShResult',\n kind: 'detached',\n allout: 'Result is detached',\n stderr: '',\n stdout: 'Result is detached',\n code: 0,\n success: true,\n });\n}\n/**\n * The most basic sh. Sends output to console if anything goes wrong, that is, if status code != 0\n * @param cmd the command to run\n * @param callback the callback to run\n * @returns All output from the command.\n */\n\nexport const simpleSh = async (\n cmd: string,\n callback: (write: (str: string) => void, end: () => void) => void = () => {},\n cwd: string | URL | undefined = undefined,\n): Promise => {\n const res = await baseSh(cmd, callback, cwd);\n if (res.code !== 0) {\n console.log(res.stdout);\n console.error(res.stderr);\n throw new Error(res.stderr);\n }\n return res.allout;\n};\n","ranges":[{"start":{"line":14,"column":39},"end":{"line":66,"column":4},"startByte":452,"endByte":1767},{"start":{"line":18,"column":19},"end":{"line":22,"column":6},"startByte":590,"endByte":710},{"start":{"line":24,"column":17},"end":{"line":26,"column":6},"startByte":729,"endByte":775},{"start":{"line":32,"column":26},"end":{"line":35,"column":6},"startByte":858,"endByte":933},{"start":{"line":36,"column":26},"end":{"line":39,"column":6},"startByte":961,"endByte":1036},{"start":{"line":40,"column":20},"end":{"line":51,"column":6},"startByte":1058,"endByte":1323},{"start":{"line":52,"column":20},"end":{"line":65,"column":6},"startByte":1345,"endByte":1761},{"start":{"line":71,"column":71},"end":{"line":71,"column":79},"startByte":1882,"endByte":1890},{"start":{"line":107,"column":25},"end":{"line":119,"column":2},"startByte":2904,"endByte":3267},{"start":{"line":109,"column":71},"end":{"line":109,"column":79},"startByte":2997,"endByte":3005}],"reason":null} +{"__typename":"Match","messages":[],"variables":[{"name":"$new_files","scopedName":"0_0_$new_files","ranges":[]},{"name":"$program","scopedName":"0_1_$program","ranges":[]},{"name":"$filename","scopedName":"0_2_$filename","ranges":[]},{"name":"$absolute_filename","scopedName":"0_3_$absolute_filename","ranges":[]},{"name":"$GLOBAL_IMPORTED_SOURCES","scopedName":"0_4_$GLOBAL_IMPORTED_SOURCES","ranges":[]},{"name":"$GLOBAL_IMPORTED_NAMES","scopedName":"0_5_$GLOBAL_IMPORTED_NAMES","ranges":[]},{"name":"$body","scopedName":"2_0_$body","ranges":[{"start":{"line":1,"column":1},"end":{"line":14,"column":2},"startByte":0,"endByte":256}]},{"name":"$p","scopedName":"7_0_$p","ranges":[]},{"name":"$all_imports","scopedName":"7_1_$all_imports","ranges":[]},{"name":"$h","scopedName":"7_2_$h","ranges":[]},{"name":"$statements","scopedName":"7_3_$statements","ranges":[]},{"name":"$anchor","scopedName":"7_4_$anchor","ranges":[]},{"name":"$p","scopedName":"8_0_$p","ranges":[]},{"name":"$all_imports","scopedName":"8_1_$all_imports","ranges":[]},{"name":"$our_source","scopedName":"8_2_$our_source","ranges":[]},{"name":"$imported_names","scopedName":"8_3_$imported_names","ranges":[]},{"name":"$joined_imported_names","scopedName":"8_4_$joined_imported_names","ranges":[]},{"name":"$p","scopedName":"9_0_$p","ranges":[]},{"name":"$our_source","scopedName":"9_1_$our_source","ranges":[]},{"name":"$imported_names","scopedName":"9_2_$imported_names","ranges":[]},{"name":"$all_imports","scopedName":"9_3_$all_imports","ranges":[]},{"name":"$name","scopedName":"9_4_$name","ranges":[]},{"name":"$our_source","scopedName":"10_0_$our_source","ranges":[]},{"name":"$joined_imported_names","scopedName":"10_1_$joined_imported_names","ranges":[]},{"name":"$imports","scopedName":"10_2_$imports","ranges":[]},{"name":"$source","scopedName":"10_3_$source","ranges":[]},{"name":"$statement","scopedName":"10_4_$statement","ranges":[]},{"name":"$imports","scopedName":"11_0_$imports","ranges":[]},{"name":"$source","scopedName":"11_1_$source","ranges":[]},{"name":"$match","scopedName":"12_0_$match","ranges":[{"start":{"line":4,"column":15},"end":{"line":9,"column":4},"startByte":81,"endByte":172},{"start":{"line":6,"column":17},"end":{"line":8,"column":6},"startByte":129,"endByte":168},{"start":{"line":13,"column":10},"end":{"line":13,"column":39},"startByte":223,"endByte":252}]}],"sourceFile":"small.ts","content":"// This is a smaller example\nfunction() { \n console.log(\"thing\");\n const foo = () => {\n console.log(\"bar\");\n const bar = () => {\n console.log(\"baz\");\n }\n };\n // Not this\n // Delay a bit\n // Wow\n handle(() => { console.log(\"foo\"); });\n}","ranges":[{"start":{"line":4,"column":15},"end":{"line":9,"column":4},"startByte":81,"endByte":172},{"start":{"line":6,"column":17},"end":{"line":8,"column":6},"startByte":129,"endByte":168},{"start":{"line":13,"column":10},"end":{"line":13,"column":39},"startByte":223,"endByte":252}],"reason":null,"id":"[UUID]"} +{"__typename":"Match","messages":[],"variables":[{"name":"$new_files","scopedName":"0_0_$new_files","ranges":[]},{"name":"$program","scopedName":"0_1_$program","ranges":[]},{"name":"$filename","scopedName":"0_2_$filename","ranges":[]},{"name":"$absolute_filename","scopedName":"0_3_$absolute_filename","ranges":[]},{"name":"$GLOBAL_IMPORTED_SOURCES","scopedName":"0_4_$GLOBAL_IMPORTED_SOURCES","ranges":[]},{"name":"$GLOBAL_IMPORTED_NAMES","scopedName":"0_5_$GLOBAL_IMPORTED_NAMES","ranges":[]},{"name":"$body","scopedName":"2_0_$body","ranges":[{"start":{"line":1,"column":1},"end":{"line":120,"column":1},"startByte":0,"endByte":3269}]},{"name":"$p","scopedName":"7_0_$p","ranges":[]},{"name":"$all_imports","scopedName":"7_1_$all_imports","ranges":[]},{"name":"$h","scopedName":"7_2_$h","ranges":[]},{"name":"$statements","scopedName":"7_3_$statements","ranges":[]},{"name":"$anchor","scopedName":"7_4_$anchor","ranges":[]},{"name":"$p","scopedName":"8_0_$p","ranges":[]},{"name":"$all_imports","scopedName":"8_1_$all_imports","ranges":[]},{"name":"$our_source","scopedName":"8_2_$our_source","ranges":[]},{"name":"$imported_names","scopedName":"8_3_$imported_names","ranges":[]},{"name":"$joined_imported_names","scopedName":"8_4_$joined_imported_names","ranges":[]},{"name":"$p","scopedName":"9_0_$p","ranges":[]},{"name":"$our_source","scopedName":"9_1_$our_source","ranges":[]},{"name":"$imported_names","scopedName":"9_2_$imported_names","ranges":[]},{"name":"$all_imports","scopedName":"9_3_$all_imports","ranges":[]},{"name":"$name","scopedName":"9_4_$name","ranges":[]},{"name":"$our_source","scopedName":"10_0_$our_source","ranges":[]},{"name":"$joined_imported_names","scopedName":"10_1_$joined_imported_names","ranges":[]},{"name":"$imports","scopedName":"10_2_$imports","ranges":[]},{"name":"$source","scopedName":"10_3_$source","ranges":[]},{"name":"$statement","scopedName":"10_4_$statement","ranges":[]},{"name":"$imports","scopedName":"11_0_$imports","ranges":[]},{"name":"$source","scopedName":"11_1_$source","ranges":[]},{"name":"$match","scopedName":"12_0_$match","ranges":[{"start":{"line":14,"column":39},"end":{"line":66,"column":4},"startByte":452,"endByte":1767},{"start":{"line":18,"column":19},"end":{"line":22,"column":6},"startByte":590,"endByte":710},{"start":{"line":24,"column":17},"end":{"line":26,"column":6},"startByte":729,"endByte":775},{"start":{"line":32,"column":26},"end":{"line":35,"column":6},"startByte":858,"endByte":933},{"start":{"line":36,"column":26},"end":{"line":39,"column":6},"startByte":961,"endByte":1036},{"start":{"line":40,"column":20},"end":{"line":51,"column":6},"startByte":1058,"endByte":1323},{"start":{"line":52,"column":20},"end":{"line":65,"column":6},"startByte":1345,"endByte":1761},{"start":{"line":71,"column":71},"end":{"line":71,"column":79},"startByte":1882,"endByte":1890},{"start":{"line":107,"column":25},"end":{"line":119,"column":2},"startByte":2904,"endByte":3267},{"start":{"line":109,"column":71},"end":{"line":109,"column":79},"startByte":2997,"endByte":3005}]}],"sourceFile":"big.ts","content":"import type { ChildProcessWithoutNullStreams } from 'child_process';\nimport { spawn } from 'child_process';\nimport type { stdlib } from '@getgrit/api';\n\nexport function wrap_exec({\n callback,\n cp,\n passOnNonZeroExitCode,\n}: {\n callback?: (write: (str: string) => void, end: () => void) => void;\n cp: ChildProcessWithoutNullStreams;\n passOnNonZeroExitCode: boolean | undefined;\n}): Promise {\n return new Promise((resolve) => {\n const allout = [] as string[];\n const stdout = [] as string[];\n const stderr = [] as string[];\n const write = (str: string): void => {\n process.stdin.cork();\n process.stdin.write(str);\n process.stdin.uncork();\n };\n\n const end = (): void => {\n process.stdin.end();\n };\n\n if (callback) {\n callback(write, end);\n }\n\n cp.stdout.on('data', (data: string) => {\n stdout.push(data);\n allout.push(data);\n });\n cp.stderr.on('data', (data: string) => {\n stderr.push(data);\n allout.push(data);\n });\n cp.on('error', (e) => {\n resolve({\n __typename: 'ShResult',\n kind: 'direct',\n success: false,\n code: -1,\n allout: allout.join(''),\n stdout: stdout.join(''),\n stderr: stderr.join(''),\n message: e.message,\n });\n });\n cp.on('close', (code: number) => {\n // Trailing info is more valuable than truncated.\n const message = stderr.join('').slice(-2000);\n resolve({\n __typename: 'ShResult',\n kind: 'direct',\n success: passOnNonZeroExitCode ? true : code === 0,\n code: code || 0,\n allout: allout.join(''),\n stdout: stdout.join(''),\n stderr: stderr.join(''),\n message,\n });\n });\n });\n}\n\nexport function baseSh(\n cmd: string,\n callback: (write: (str: string) => void, end: () => void) => void = () => {},\n cwd: string | URL | undefined = undefined,\n passOnNonZeroExitCode: boolean | undefined = undefined,\n env: NodeJS.ProcessEnv | undefined = undefined,\n detached?: boolean,\n): Promise {\n const cp = spawn(cmd, { shell: true, detached, cwd, env: { ...process.env, ...(env ?? {}) } });\n const interruptCP = function () {\n cp.emit('SIGINT');\n };\n\n try {\n const promise = wrap_exec({ callback, cp, passOnNonZeroExitCode });\n if (!detached) {\n return promise;\n }\n } finally {\n process.removeListener('SIGINT', interruptCP);\n }\n return Promise.resolve({\n __typename: 'ShResult',\n kind: 'detached',\n allout: 'Result is detached',\n stderr: '',\n stdout: 'Result is detached',\n code: 0,\n success: true,\n });\n}\n/**\n * The most basic sh. Sends output to console if anything goes wrong, that is, if status code != 0\n * @param cmd the command to run\n * @param callback the callback to run\n * @returns All output from the command.\n */\n\nexport const simpleSh = async (\n cmd: string,\n callback: (write: (str: string) => void, end: () => void) => void = () => {},\n cwd: string | URL | undefined = undefined,\n): Promise => {\n const res = await baseSh(cmd, callback, cwd);\n if (res.code !== 0) {\n console.log(res.stdout);\n console.error(res.stderr);\n throw new Error(res.stderr);\n }\n return res.allout;\n};\n","ranges":[{"start":{"line":14,"column":39},"end":{"line":66,"column":4},"startByte":452,"endByte":1767},{"start":{"line":18,"column":19},"end":{"line":22,"column":6},"startByte":590,"endByte":710},{"start":{"line":24,"column":17},"end":{"line":26,"column":6},"startByte":729,"endByte":775},{"start":{"line":32,"column":26},"end":{"line":35,"column":6},"startByte":858,"endByte":933},{"start":{"line":36,"column":26},"end":{"line":39,"column":6},"startByte":961,"endByte":1036},{"start":{"line":40,"column":20},"end":{"line":51,"column":6},"startByte":1058,"endByte":1323},{"start":{"line":52,"column":20},"end":{"line":65,"column":6},"startByte":1345,"endByte":1761},{"start":{"line":71,"column":71},"end":{"line":71,"column":79},"startByte":1882,"endByte":1890},{"start":{"line":107,"column":25},"end":{"line":119,"column":2},"startByte":2904,"endByte":3267},{"start":{"line":109,"column":71},"end":{"line":109,"column":79},"startByte":2997,"endByte":3005}],"reason":null,"id":"[UUID]"} {"__typename":"AllDone","processed":2,"found":2,"reason":"allMatchesFound"} diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index f9b9cee1c..773c608b2 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -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" } @@ -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" diff --git a/crates/core/src/api.rs b/crates/core/src/api.rs index d8a1c4993..4e22b8e0e 100644 --- a/crates/core/src/api.rs +++ b/crates/core/src/api.rs @@ -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")] @@ -343,6 +344,8 @@ pub struct Match { pub ranges: Vec, #[serde(default)] pub reason: Option, + #[serde(default)] + pub id: Uuid, } impl From for Match { @@ -354,6 +357,7 @@ impl From for Match { ranges: file_match.ranges, reason: None, content: file_match.content, + id: Uuid::new_v4(), } } } @@ -456,6 +460,8 @@ pub struct Rewrite { pub rewritten: EntireFile, #[serde(default)] pub reason: Option, + #[serde(default)] + pub id: Uuid, } impl From for MatchResult { @@ -558,6 +564,7 @@ impl Rewrite { original, rewritten, reason, + id: Uuid::new_v4(), } } } @@ -568,6 +575,8 @@ pub struct CreateFile { pub rewritten: EntireFile, range: Option>, pub reason: Option, + #[serde(default)] + pub id: Uuid, } impl From for MatchResult { @@ -582,6 +591,7 @@ impl CreateFile { rewritten: EntireFile::file_to_entire_file(name, body, None), range: None, reason: None, + id: Uuid::new_v4(), } } } @@ -622,6 +632,8 @@ pub struct RemoveFile { pub original: EntireFile, #[serde(default)] pub reason: Option, + #[serde(default)] + pub id: Uuid, } impl From for MatchResult { diff --git a/crates/core/src/snapshots/marzano_core__test__add_to_set.snap b/crates/core/src/snapshots/marzano_core__test__add_to_set.snap index c2d965fe0..18b5181c3 100644 --- a/crates/core/src/snapshots/marzano_core__test__add_to_set.snap +++ b/crates/core/src/snapshots/marzano_core__test__add_to_set.snap @@ -147,6 +147,7 @@ expression: results end: 68 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx - __typename: AnalysisLog diff --git a/crates/core/src/snapshots/marzano_core__test__add_to_set_via_pattern.snap b/crates/core/src/snapshots/marzano_core__test__add_to_set_via_pattern.snap index 659c2f7a2..baa896842 100644 --- a/crates/core/src/snapshots/marzano_core__test__add_to_set_via_pattern.snap +++ b/crates/core/src/snapshots/marzano_core__test__add_to_set_via_pattern.snap @@ -150,6 +150,7 @@ expression: results end: 68 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx - __typename: AnalysisLog diff --git a/crates/core/src/snapshots/marzano_core__test__after_each_file.snap b/crates/core/src/snapshots/marzano_core__test__after_each_file.snap index c23a2856e..000014dcb 100644 --- a/crates/core/src/snapshots/marzano_core__test__after_each_file.snap +++ b/crates/core/src/snapshots/marzano_core__test__after_each_file.snap @@ -59,5 +59,6 @@ expression: results end: 16 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__basic_md.snap b/crates/core/src/snapshots/marzano_core__test__basic_md.snap index 9d7deaebd..180146b59 100644 --- a/crates/core/src/snapshots/marzano_core__test__basic_md.snap +++ b/crates/core/src/snapshots/marzano_core__test__basic_md.snap @@ -51,5 +51,6 @@ expression: results end: 15 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: foo.md diff --git a/crates/core/src/snapshots/marzano_core__test__basic_python.snap b/crates/core/src/snapshots/marzano_core__test__basic_python.snap index 33b25861a..f6e9054cd 100644 --- a/crates/core/src/snapshots/marzano_core__test__basic_python.snap +++ b/crates/core/src/snapshots/marzano_core__test__basic_python.snap @@ -62,5 +62,6 @@ expression: results end: 19 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: foo.py diff --git a/crates/core/src/snapshots/marzano_core__test__before_and_after_each_file.snap b/crates/core/src/snapshots/marzano_core__test__before_and_after_each_file.snap index ccf7980a3..ed95d0d85 100644 --- a/crates/core/src/snapshots/marzano_core__test__before_and_after_each_file.snap +++ b/crates/core/src/snapshots/marzano_core__test__before_and_after_each_file.snap @@ -67,5 +67,6 @@ expression: results end: 19 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__before_each_file.snap b/crates/core/src/snapshots/marzano_core__test__before_each_file.snap index 78c130755..c9e10a5d6 100644 --- a/crates/core/src/snapshots/marzano_core__test__before_each_file.snap +++ b/crates/core/src/snapshots/marzano_core__test__before_each_file.snap @@ -56,5 +56,6 @@ expression: results end: 16 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__clone_activites.snap b/crates/core/src/snapshots/marzano_core__test__clone_activites.snap index 5a1a67a1e..d35ab4351 100644 --- a/crates/core/src/snapshots/marzano_core__test__clone_activites.snap +++ b/crates/core/src/snapshots/marzano_core__test__clone_activites.snap @@ -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: [] @@ -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 diff --git a/crates/core/src/snapshots/marzano_core__test__code_span.snap b/crates/core/src/snapshots/marzano_core__test__code_span.snap index 851f75d06..b0b080366 100644 --- a/crates/core/src/snapshots/marzano_core__test__code_span.snap +++ b/crates/core/src/snapshots/marzano_core__test__code_span.snap @@ -62,5 +62,6 @@ expression: results end: 12 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: foo.md diff --git a/crates/core/src/snapshots/marzano_core__test__file_rename.snap b/crates/core/src/snapshots/marzano_core__test__file_rename.snap index 3a083cd0f..77af59b56 100644 --- a/crates/core/src/snapshots/marzano_core__test__file_rename.snap +++ b/crates/core/src/snapshots/marzano_core__test__file_rename.snap @@ -57,5 +57,6 @@ expression: results end: 27 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__filename.snap b/crates/core/src/snapshots/marzano_core__test__filename.snap index 45ae52e5a..baf3f8c7f 100644 --- a/crates/core/src/snapshots/marzano_core__test__filename.snap +++ b/crates/core/src/snapshots/marzano_core__test__filename.snap @@ -43,5 +43,6 @@ expression: results end: 13 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__filename_autoset.snap b/crates/core/src/snapshots/marzano_core__test__filename_autoset.snap index 04606ab9e..fe18c7ddf 100644 --- a/crates/core/src/snapshots/marzano_core__test__filename_autoset.snap +++ b/crates/core/src/snapshots/marzano_core__test__filename_autoset.snap @@ -51,5 +51,6 @@ expression: results end: 7 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__import_all_already_there.snap b/crates/core/src/snapshots/marzano_core__test__import_all_already_there.snap index a65034efc..1f4820dba 100644 --- a/crates/core/src/snapshots/marzano_core__test__import_all_already_there.snap +++ b/crates/core/src/snapshots/marzano_core__test__import_all_already_there.snap @@ -176,5 +176,6 @@ expression: results startByte: 9 endByte: 12 reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__import_just_insert.snap b/crates/core/src/snapshots/marzano_core__test__import_just_insert.snap index ad8591f25..1c5035e21 100644 --- a/crates/core/src/snapshots/marzano_core__test__import_just_insert.snap +++ b/crates/core/src/snapshots/marzano_core__test__import_just_insert.snap @@ -229,5 +229,6 @@ expression: results end: 95 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__import_multiple.snap b/crates/core/src/snapshots/marzano_core__test__import_multiple.snap index 20a97de38..ab42ee4b0 100644 --- a/crates/core/src/snapshots/marzano_core__test__import_multiple.snap +++ b/crates/core/src/snapshots/marzano_core__test__import_multiple.snap @@ -369,5 +369,6 @@ expression: results end: 114 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__import_none.snap b/crates/core/src/snapshots/marzano_core__test__import_none.snap index 8c29af8ae..1855ccc22 100644 --- a/crates/core/src/snapshots/marzano_core__test__import_none.snap +++ b/crates/core/src/snapshots/marzano_core__test__import_none.snap @@ -153,5 +153,6 @@ expression: results startByte: 9 endByte: 12 reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__json_file_match_snippet.snap b/crates/core/src/snapshots/marzano_core__test__json_file_match_snippet.snap index 69a54e050..58397df54 100644 --- a/crates/core/src/snapshots/marzano_core__test__json_file_match_snippet.snap +++ b/crates/core/src/snapshots/marzano_core__test__json_file_match_snippet.snap @@ -57,5 +57,6 @@ expression: results end: 63 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: foo.package.json diff --git a/crates/core/src/snapshots/marzano_core__test__json_file_match_string.snap b/crates/core/src/snapshots/marzano_core__test__json_file_match_string.snap index 69a54e050..58397df54 100644 --- a/crates/core/src/snapshots/marzano_core__test__json_file_match_string.snap +++ b/crates/core/src/snapshots/marzano_core__test__json_file_match_string.snap @@ -57,5 +57,6 @@ expression: results end: 63 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: foo.package.json diff --git a/crates/core/src/snapshots/marzano_core__test__md_link_metavariable.snap b/crates/core/src/snapshots/marzano_core__test__md_link_metavariable.snap index 7ff13848b..6aa1f386b 100644 --- a/crates/core/src/snapshots/marzano_core__test__md_link_metavariable.snap +++ b/crates/core/src/snapshots/marzano_core__test__md_link_metavariable.snap @@ -73,5 +73,6 @@ expression: results end: 30 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: foo.md diff --git a/crates/core/src/snapshots/marzano_core__test__md_link_node.snap b/crates/core/src/snapshots/marzano_core__test__md_link_node.snap index 60d2e4678..5e41bcae8 100644 --- a/crates/core/src/snapshots/marzano_core__test__md_link_node.snap +++ b/crates/core/src/snapshots/marzano_core__test__md_link_node.snap @@ -73,5 +73,6 @@ expression: results end: 27 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: foo.md diff --git a/crates/core/src/snapshots/marzano_core__test__multifile_pattern.snap b/crates/core/src/snapshots/marzano_core__test__multifile_pattern.snap index e7b3cc42e..3aea425be 100644 --- a/crates/core/src/snapshots/marzano_core__test__multifile_pattern.snap +++ b/crates/core/src/snapshots/marzano_core__test__multifile_pattern.snap @@ -148,6 +148,7 @@ expression: results end: 27 ranges: [] reason: ~ + id: [UUID] - __typename: Rewrite original: messages: [] @@ -294,6 +295,7 @@ expression: results end: 34 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: file1.tsx - __typename: DoneFile diff --git a/crates/core/src/snapshots/marzano_core__test__multifile_propagates_scope_between_steps.snap b/crates/core/src/snapshots/marzano_core__test__multifile_propagates_scope_between_steps.snap index edfd486d6..8297ba059 100644 --- a/crates/core/src/snapshots/marzano_core__test__multifile_propagates_scope_between_steps.snap +++ b/crates/core/src/snapshots/marzano_core__test__multifile_propagates_scope_between_steps.snap @@ -66,6 +66,7 @@ expression: results content: foo(1) ranges: [] reason: ~ + id: [UUID] - __typename: Rewrite original: messages: [] @@ -141,6 +142,7 @@ expression: results end: 6 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: file1.tsx - __typename: DoneFile diff --git a/crates/core/src/snapshots/marzano_core__test__program.snap b/crates/core/src/snapshots/marzano_core__test__program.snap index 9be0bea98..3f79358c5 100644 --- a/crates/core/src/snapshots/marzano_core__test__program.snap +++ b/crates/core/src/snapshots/marzano_core__test__program.snap @@ -40,5 +40,6 @@ expression: results end: 30 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__program_autoset.snap b/crates/core/src/snapshots/marzano_core__test__program_autoset.snap index d0665a3c5..1e82cefae 100644 --- a/crates/core/src/snapshots/marzano_core__test__program_autoset.snap +++ b/crates/core/src/snapshots/marzano_core__test__program_autoset.snap @@ -51,5 +51,6 @@ expression: results end: 7 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__rewrite_dot.snap b/crates/core/src/snapshots/marzano_core__test__rewrite_dot.snap index db50a86c7..1f6b61d6d 100644 --- a/crates/core/src/snapshots/marzano_core__test__rewrite_dot.snap +++ b/crates/core/src/snapshots/marzano_core__test__rewrite_dot.snap @@ -52,6 +52,7 @@ expression: results byteRanges: [] ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx - __typename: AnalysisLog diff --git a/crates/core/src/snapshots/marzano_core__test__rewrite_or_bubble_pattern_argument.snap b/crates/core/src/snapshots/marzano_core__test__rewrite_or_bubble_pattern_argument.snap index bce336742..fffafd229 100644 --- a/crates/core/src/snapshots/marzano_core__test__rewrite_or_bubble_pattern_argument.snap +++ b/crates/core/src/snapshots/marzano_core__test__rewrite_or_bubble_pattern_argument.snap @@ -107,5 +107,6 @@ expression: results end: 110 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx diff --git a/crates/core/src/snapshots/marzano_core__test__saving_info.snap b/crates/core/src/snapshots/marzano_core__test__saving_info.snap index bc42a9d84..d76dec8e8 100644 --- a/crates/core/src/snapshots/marzano_core__test__saving_info.snap +++ b/crates/core/src/snapshots/marzano_core__test__saving_info.snap @@ -262,6 +262,7 @@ expression: results end: 18 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx - __typename: AnalysisLog diff --git a/crates/core/src/snapshots/marzano_core__test__shorthand_log.snap b/crates/core/src/snapshots/marzano_core__test__shorthand_log.snap index dfd2e0c87..6b1fcc895 100644 --- a/crates/core/src/snapshots/marzano_core__test__shorthand_log.snap +++ b/crates/core/src/snapshots/marzano_core__test__shorthand_log.snap @@ -57,6 +57,7 @@ expression: results startByte: 8 endByte: 11 reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx - __typename: AnalysisLog diff --git a/crates/core/src/snapshots/marzano_core__test__should_log_variable.snap b/crates/core/src/snapshots/marzano_core__test__should_log_variable.snap index b87113ced..c7d513ee4 100644 --- a/crates/core/src/snapshots/marzano_core__test__should_log_variable.snap +++ b/crates/core/src/snapshots/marzano_core__test__should_log_variable.snap @@ -73,6 +73,7 @@ expression: results end: 42 ranges: [] reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx - __typename: AnalysisLog diff --git a/crates/core/src/snapshots/marzano_core__test__simple_log.snap b/crates/core/src/snapshots/marzano_core__test__simple_log.snap index 51bd02d8b..00387e95d 100644 --- a/crates/core/src/snapshots/marzano_core__test__simple_log.snap +++ b/crates/core/src/snapshots/marzano_core__test__simple_log.snap @@ -51,6 +51,7 @@ expression: results startByte: 0 endByte: 13 reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx - __typename: AnalysisLog diff --git a/crates/core/src/snapshots/marzano_core__test__variable_message_log.snap b/crates/core/src/snapshots/marzano_core__test__variable_message_log.snap index ab36a4562..ad0a59a87 100644 --- a/crates/core/src/snapshots/marzano_core__test__variable_message_log.snap +++ b/crates/core/src/snapshots/marzano_core__test__variable_message_log.snap @@ -54,6 +54,7 @@ expression: results startByte: 0 endByte: 13 reason: ~ + id: [UUID] - __typename: DoneFile relativeFilePath: test-file.tsx - __typename: AnalysisLog diff --git a/crates/core/src/test.rs b/crates/core/src/test.rs index a76b46d2b..4e29ca5e9 100644 --- a/crates/core/src/test.rs +++ b/crates/core/src/test.rs @@ -2,7 +2,7 @@ use crate::pattern_compiler::src_to_problem_libs; use anyhow::{anyhow, Context, Result}; use api::MatchResult; use grit_util::{Range, VariableMatch}; -use insta::{assert_debug_snapshot, assert_snapshot, assert_yaml_snapshot}; +use insta::{assert_debug_snapshot, assert_snapshot}; use lazy_static::lazy_static; use marzano_auth::env::ENV_VAR_GRIT_API_URL; use marzano_auth::testing::get_testing_auth_info; @@ -41,6 +41,16 @@ impl ExecutionResult { } } +macro_rules! assert_grit_snapshot { + ($value:expr) => {{ + insta::with_settings!({filters => vec![ + (r"\b[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}\b", "[UUID]"), + ]}, { + insta::assert_yaml_snapshot!($value); + }); + }}; +} + // todo: remove after migrating tests // #[deprecated(note = "remove after migrating tests to MatchResult")] #[derive(Debug, Clone)] @@ -3361,7 +3371,7 @@ fn should_log_variable() { let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source.to_owned()), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -3384,7 +3394,7 @@ fn rewrite_dot() { let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source.to_owned()), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -3411,7 +3421,7 @@ fn test_simple_log() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -3439,7 +3449,7 @@ fn test_variable_message_log() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -3468,7 +3478,7 @@ fn test_shorthand_log() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -3496,7 +3506,7 @@ fn test_before_each_file() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -3525,7 +3535,7 @@ fn test_after_each_file() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -3558,7 +3568,7 @@ fn test_before_and_after_each_file() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4084,7 +4094,7 @@ fn test_file_rename() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4114,7 +4124,7 @@ fn test_json_file_match_snippet() { let json_lang: TargetLanguage = PatternLanguage::Json.try_into().unwrap(); let pattern = src_to_problem(pattern, json_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4138,7 +4148,7 @@ fn test_basic_python() { let language: TargetLanguage = PatternLanguage::Python.try_into().unwrap(); let pattern = src_to_problem(pattern, language).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4168,7 +4178,7 @@ fn test_json_file_match_string() { let json_lang: TargetLanguage = PatternLanguage::Json.try_into().unwrap(); let pattern = src_to_problem(pattern, json_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4245,7 +4255,7 @@ fn test_saving_info() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4276,7 +4286,7 @@ fn test_assoc_matcher() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4325,7 +4335,7 @@ fn add_to_set() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern.to_owned(), js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4368,7 +4378,7 @@ fn add_to_set_via_pattern() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern.to_owned(), js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4520,7 +4530,7 @@ fn test_import_none() { .unwrap(); let results = execute(pattern, source); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4548,7 +4558,7 @@ fn rewrite_or_bubble_pattern_argument() { "#; let results = execute(pattern.into(), source.into()); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4576,7 +4586,7 @@ fn test_import_just_insert() { .unwrap(); let results = execute(pattern, source); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4672,7 +4682,7 @@ fn test_import_all_already_there() { .unwrap(); let results = execute(pattern, source); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4708,7 +4718,7 @@ fn test_import_multiple() { .unwrap(); let results = execute(pattern, source); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4820,7 +4830,7 @@ multifile { &context, ); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4852,7 +4862,7 @@ fn test_filename() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4885,7 +4895,7 @@ fn test_program() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4949,7 +4959,7 @@ fn test_filename_autoset() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -4974,7 +4984,7 @@ fn test_program_autoset() { let js_lang: TargetLanguage = PatternLanguage::Tsx.try_into().unwrap(); let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -8337,7 +8347,7 @@ multifile { &context, ); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -8361,7 +8371,7 @@ multifile { &context, ); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -8569,7 +8579,7 @@ fn test_basic_md() { let language: TargetLanguage = PatternLanguage::MarkdownInline.try_into().unwrap(); let pattern = src_to_problem(pattern, language).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -8589,7 +8599,7 @@ fn md_link_metavariable() { let language: TargetLanguage = PatternLanguage::MarkdownInline.try_into().unwrap(); let pattern = src_to_problem(pattern, language).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -8609,7 +8619,7 @@ fn md_link_node() { let language: TargetLanguage = PatternLanguage::MarkdownInline.try_into().unwrap(); let pattern = src_to_problem(pattern, language).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -8630,7 +8640,7 @@ fn code_span() { let pattern = src_to_problem(pattern, language).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source.to_owned()), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test] @@ -11555,7 +11565,7 @@ fn some_every_errors_on_invalid_rewrite() { let pattern = src_to_problem(pattern, js_lang).unwrap(); let results = pattern.execute_file(&RichFile::new(file.to_owned(), source.to_owned()), &context); - assert_yaml_snapshot!(results); + assert_grit_snapshot!(results); } #[test]