From 8ffc8903e2f2b4de4f406896dde4945e665946f7 Mon Sep 17 00:00:00 2001 From: Yoann Padioleau Date: Mon, 9 Dec 2024 12:32:23 +0100 Subject: [PATCH] Fix the new match_based_id alias (#327) Using a string wrap was causing semgrep-pro to fail to compile about a missing pp_match_based_id test plan: related PR in semgrep-pro - [x] I ran `make setup && make` to update the generated code after editing a `.atd` file (TODO: have a CI check) - [x] I made sure we're still backward compatible with old versions of the CLI. For example, the Semgrep backend need to still be able to *consume* data generated by Semgrep 1.50.0. See https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades Note that the types related to the semgrep-core JSON output or the semgrep-core RPC do not need to be backward compatible! --- semgrep_output_v1.atd | 11 +++++++---- semgrep_output_v1.jsonschema | 2 +- semgrep_output_v1.proto | 2 +- semgrep_output_v1.ts | 20 ++++++++++---------- semgrep_output_v1_j.ml | 17 +++-------------- semgrep_output_v1_j.mli | 1 + 6 files changed, 23 insertions(+), 30 deletions(-) diff --git a/semgrep_output_v1.atd b/semgrep_output_v1.atd index d574714..d7f9857 100644 --- a/semgrep_output_v1.atd +++ b/semgrep_output_v1.atd @@ -100,8 +100,6 @@ type uuid = string wrap (* RFC 3339 format *) type datetime = string wrap -type match_based_id = string wrap - (*****************************************************************************) (* Versioning *) (*****************************************************************************) @@ -258,6 +256,8 @@ type product | Secrets ] +type match_based_id = string (* ex:"ab023_1"*) + (*****************************************************************************) (* Matches *) (*****************************************************************************) @@ -1163,6 +1163,7 @@ type features = { type triage_ignored = { ~triage_ignored_syntactic_ids: string list; + (* TODO: use match_based_id list *) ~triage_ignored_match_based_ids: string list; } @@ -1462,7 +1463,7 @@ type finding = { commit_date: string; syntactic_id: string; - (* since semgrep 0.98 *) + (* since semgrep 0.98 TODO: use match_based_id option *) ?match_based_id: string option; (* since semgrep 1.14.0 *) ?hashes: finding_hashes option; @@ -1633,7 +1634,9 @@ type ci_scan_complete_response = { ~app_block_override: bool; (* only when app_block_override is true *) ~app_block_reason: string; - (* match_based_ids of findings that semgrep-app determined should cause the scan to block *) + (* since 1.100.0. match_based_ids of findings that semgrep-app determined + * should cause the scan to block + *) ~app_blocking_match_based_ids : match_based_id list; } diff --git a/semgrep_output_v1.jsonschema b/semgrep_output_v1.jsonschema index 2b2f044..caad1c8 100644 --- a/semgrep_output_v1.jsonschema +++ b/semgrep_output_v1.jsonschema @@ -41,7 +41,6 @@ "sha1": { "type": "string" }, "uuid": { "type": "string" }, "datetime": { "type": "string" }, - "match_based_id": { "type": "string" }, "version": { "type": "string" }, "position": { "type": "object", @@ -121,6 +120,7 @@ { "const": "sast" }, { "const": "sca" }, { "const": "secrets" } ] }, + "match_based_id": { "type": "string" }, "cli_match": { "type": "object", "required": [ "check_id", "path", "start", "end", "extra" ], diff --git a/semgrep_output_v1.proto b/semgrep_output_v1.proto index 858051c..beb1a58 100644 --- a/semgrep_output_v1.proto +++ b/semgrep_output_v1.proto @@ -1,6 +1,6 @@ // Generated by jsonschema2protobuf. DO NOT EDIT! // Source file: semgrep_output_v1.jsonschema -// Source file sha256 digest: 3c5ed14031f0dd72ed2f739c26ab80f76a94337b5caa1da7e9a04d0facae95da +// Source file sha256 digest: 92c23e510cfd829fd7fd8599a6ea113ccef901d0f1bd64b28936450c16105afe syntax = "proto3"; diff --git a/semgrep_output_v1.ts b/semgrep_output_v1.ts index a9dc911..6cbd09b 100644 --- a/semgrep_output_v1.ts +++ b/semgrep_output_v1.ts @@ -26,8 +26,6 @@ export type Uuid = string export type Datetime = string -export type MatchBasedId = string - export type Version = string export type Position = { @@ -82,6 +80,8 @@ export type Product = | { kind: 'SCA' /* JSON: "sca" */ } | { kind: 'Secrets' /* JSON: "secrets" */ } +export type MatchBasedId = string + export type CliMatch = { check_id: RuleId; path: Fpath; @@ -1056,14 +1056,6 @@ export function readDatetime(x: any, context: any = x): Datetime { return _atd_read_string(x, context); } -export function writeMatchBasedId(x: MatchBasedId, context: any = x): any { - return _atd_write_string(x, context); -} - -export function readMatchBasedId(x: any, context: any = x): MatchBasedId { - return _atd_read_string(x, context); -} - export function writeVersion(x: Version, context: any = x): any { return _atd_write_string(x, context); } @@ -1291,6 +1283,14 @@ export function readProduct(x: any, context: any = x): Product { } } +export function writeMatchBasedId(x: MatchBasedId, context: any = x): any { + return _atd_write_string(x, context); +} + +export function readMatchBasedId(x: any, context: any = x): MatchBasedId { + return _atd_read_string(x, context); +} + export function writeCliMatch(x: CliMatch, context: any = x): any { return { 'check_id': _atd_write_required_field('CliMatch', 'check_id', writeRuleId, x.check_id, x), diff --git a/semgrep_output_v1_j.ml b/semgrep_output_v1_j.ml index 3a80b16..9d81914 100644 --- a/semgrep_output_v1_j.ml +++ b/semgrep_output_v1_j.ml @@ -726,6 +726,7 @@ type output_format = Semgrep_output_v1_t.output_format = [@@deriving show] type match_based_id = Semgrep_output_v1_t.match_based_id + [@@deriving show, eq] type manifest = Semgrep_output_v1_t.manifest = { kind: manifest_kind; @@ -28465,27 +28466,15 @@ let read_output_format = ( ) let output_format_of_string s = read_output_format (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__string_wrap = ( - Yojson.Safe.write_string -) -let string_of__string_wrap ?(len = 1024) x = - let ob = Buffer.create len in - write__string_wrap ob x; - Buffer.contents ob -let read__string_wrap = ( - Atdgen_runtime.Oj_run.read_string -) -let _string_wrap_of_string s = - read__string_wrap (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write_match_based_id = ( - write__string_wrap + Yojson.Safe.write_string ) let string_of_match_based_id ?(len = 1024) x = let ob = Buffer.create len in write_match_based_id ob x; Buffer.contents ob let read_match_based_id = ( - read__string_wrap + Atdgen_runtime.Oj_run.read_string ) let match_based_id_of_string s = read_match_based_id (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/semgrep_output_v1_j.mli b/semgrep_output_v1_j.mli index e3ed818..63cbdd1 100644 --- a/semgrep_output_v1_j.mli +++ b/semgrep_output_v1_j.mli @@ -726,6 +726,7 @@ type output_format = Semgrep_output_v1_t.output_format = [@@deriving show] type match_based_id = Semgrep_output_v1_t.match_based_id + [@@deriving show, eq] type manifest = Semgrep_output_v1_t.manifest = { kind: manifest_kind;