From 8fa73f5721b1de15e7a6548a848301ef945840c2 Mon Sep 17 00:00:00 2001 From: Blake Hice <92403082+blakehice4@users.noreply.github.com> Date: Tue, 5 Nov 2024 09:59:16 -0700 Subject: [PATCH 1/4] MRF Version and Validator Version Mismatch https://github.com/CMSgov/price-transparency-guide-validator/issues/121 --- src/SchemaManager.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SchemaManager.ts b/src/SchemaManager.ts index a08dccaa..a8e14979 100644 --- a/src/SchemaManager.ts +++ b/src/SchemaManager.ts @@ -44,7 +44,8 @@ export class SchemaManager { const tags = tagResult.stdout .split('\n') .map(tag => tag.trim()) - .filter(tag => tag.length > 0); + .filter(tag => tag.length > 0) + .flatMap(tag => tag.startsWith('v') ? [tag, tag.slice(1)] : [tag]); // Adds both "vX.Y.Z" and "X.Y.Z" formats if (tags.includes(version)) { await util.promisify(exec)(`git -C "${this.repoDirectory}" checkout ${version}`); this._version = version; From e40bc95f6d60e097833b464dc91aabc274ff3d9a Mon Sep 17 00:00:00 2001 From: Blake Hice Date: Tue, 5 Nov 2024 10:30:10 -0700 Subject: [PATCH 2/4] MRF Version and Validator Version Mismatch https://github.com/CMSgov/price-transparency-guide-validator/issues/121 --- src/SchemaManager.ts | 19 ++++++++++++++----- test/SchemaManager.test.ts | 11 +++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/SchemaManager.ts b/src/SchemaManager.ts index a8e14979..fe1dfbd8 100644 --- a/src/SchemaManager.ts +++ b/src/SchemaManager.ts @@ -45,15 +45,24 @@ export class SchemaManager { .split('\n') .map(tag => tag.trim()) .filter(tag => tag.length > 0) - .flatMap(tag => tag.startsWith('v') ? [tag, tag.slice(1)] : [tag]); // Adds both "vX.Y.Z" and "X.Y.Z" formats - if (tags.includes(version)) { - await util.promisify(exec)(`git -C "${this.repoDirectory}" checkout ${version}`); - this._version = version; + .reduce((acc, tag) => { + if (tag.startsWith('v')) { + acc[tag] = tag; // Key with 'v' prefix + acc[tag.slice(1)] = tag; // Key without 'v' prefix + } else { + acc[tag] = 'v' + tag; // If no 'v' prefix, add one as the value + } + return acc; + }, {} as Record); + + if (version in tags) { + await util.promisify(exec)(`git -C "${this.repoDirectory}" checkout ${tags[version]}`); + this._version = tags[version]; return true; } else { // we didn't find your tag. maybe you mistyped it, so show the available ones. throw new Error( - `Could not find a schema version named "${version}". Available versions are:\n${tags.join( + `Could not find a schema version named "${version}". Available versions are:\n${Object.keys(tags).join( '\n' )}` ); diff --git a/test/SchemaManager.test.ts b/test/SchemaManager.test.ts index fc42167b..621e94c1 100644 --- a/test/SchemaManager.test.ts +++ b/test/SchemaManager.test.ts @@ -108,10 +108,21 @@ describe('SchemaManager', () => { await expect(schemaManager.useVersion('v0.7')).resolves.toBe(true); }); + it('should resolve to true when the version exists in the repo2', async () => { + const schemaManager = new SchemaManager(repoDirectory); + await expect(schemaManager.useVersion('0.7')).resolves.toBe(true); + }); + it('should reject when the version does not exist in the repo', async () => { const schemaManager = new SchemaManager(repoDirectory); await expect(schemaManager.useVersion('v0.6')).toReject(); }); + + it('should reject when the version does not exist in the repo2', async () => { + const schemaManager = new SchemaManager(repoDirectory); + await expect(schemaManager.useVersion('0.6')).toReject(); + }); + }); describe('#useSchema', () => { From 90e0fd370004e8f41ca049666ac7514259b02c8b Mon Sep 17 00:00:00 2001 From: Blake Hice Date: Tue, 5 Nov 2024 11:28:26 -0700 Subject: [PATCH 3/4] MRF Version and Validator Version Mismatch updating version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 487fdd74..2ce32800 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cms-mrf-validator", - "version": "2.1.0", + "version": "2.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cms-mrf-validator", - "version": "2.1.0", + "version": "2.2.0", "license": "Apache-2.0", "dependencies": { "@streamparser/json": "^0.0.21", diff --git a/package.json b/package.json index c88c6412..c86161cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cms-mrf-validator", - "version": "2.1.0", + "version": "2.2.0", "description": "Node-based entry point for machine-readable file validator", "main": "out/index.js", "bin": { From 737e47098abbe69d9cced893c19a603c6f470e9d Mon Sep 17 00:00:00 2001 From: mint thompson Date: Fri, 22 Nov 2024 12:22:36 -0500 Subject: [PATCH 4/4] Apply formatting rules, update test descriptions --- src/SchemaManager.ts | 27 +++++++++++++++------------ test/SchemaManager.test.ts | 5 ++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/SchemaManager.ts b/src/SchemaManager.ts index fe1dfbd8..50580c3b 100644 --- a/src/SchemaManager.ts +++ b/src/SchemaManager.ts @@ -45,15 +45,18 @@ export class SchemaManager { .split('\n') .map(tag => tag.trim()) .filter(tag => tag.length > 0) - .reduce((acc, tag) => { - if (tag.startsWith('v')) { - acc[tag] = tag; // Key with 'v' prefix - acc[tag.slice(1)] = tag; // Key without 'v' prefix - } else { - acc[tag] = 'v' + tag; // If no 'v' prefix, add one as the value - } - return acc; - }, {} as Record); + .reduce( + (acc, tag) => { + if (tag.startsWith('v')) { + acc[tag] = tag; // Key with 'v' prefix + acc[tag.slice(1)] = tag; // Key without 'v' prefix + } else { + acc[tag] = 'v' + tag; // If no 'v' prefix, add one as the value + } + return acc; + }, + {} as Record + ); if (version in tags) { await util.promisify(exec)(`git -C "${this.repoDirectory}" checkout ${tags[version]}`); @@ -62,9 +65,9 @@ export class SchemaManager { } else { // we didn't find your tag. maybe you mistyped it, so show the available ones. throw new Error( - `Could not find a schema version named "${version}". Available versions are:\n${Object.keys(tags).join( - '\n' - )}` + `Could not find a schema version named "${version}". Available versions are:\n${Object.keys( + tags + ).join('\n')}` ); } } diff --git a/test/SchemaManager.test.ts b/test/SchemaManager.test.ts index 621e94c1..fb146c5a 100644 --- a/test/SchemaManager.test.ts +++ b/test/SchemaManager.test.ts @@ -108,7 +108,7 @@ describe('SchemaManager', () => { await expect(schemaManager.useVersion('v0.7')).resolves.toBe(true); }); - it('should resolve to true when the version exists in the repo2', async () => { + it('should resolve to true when the version exists in the repo with a prefixed v', async () => { const schemaManager = new SchemaManager(repoDirectory); await expect(schemaManager.useVersion('0.7')).resolves.toBe(true); }); @@ -118,11 +118,10 @@ describe('SchemaManager', () => { await expect(schemaManager.useVersion('v0.6')).toReject(); }); - it('should reject when the version does not exist in the repo2', async () => { + it('should reject when the version does not exist in the repo with a prefixed v', async () => { const schemaManager = new SchemaManager(repoDirectory); await expect(schemaManager.useVersion('0.6')).toReject(); }); - }); describe('#useSchema', () => {