From 76857228e3555780060804f1105b7910f718ea9b Mon Sep 17 00:00:00 2001 From: Paul Beaudoin Date: Thu, 10 Jul 2025 12:40:17 -0400 Subject: [PATCH 01/27] Override agg-self-filtering behavior for open search Trying out overriding the policy of _not_ applying namesake filter to aggregations when there is no other search criteria https://newyorkpubliclibrary.atlassian.net/browse/SCC-4789 --- lib/resources.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/resources.js b/lib/resources.js index faf71c79..80682dde 100644 --- a/lib/resources.js +++ b/lib/resources.js @@ -697,6 +697,13 @@ module.exports = function (app, _private = null) { // - one agg representing the counts for all properties _not_ used in filter // - one agg each for each property that is used in a filter, but counts should exclude that filter + // If the search query consists of only a single filter (or a couple + // filters of same type), just do a normal self-filtering aggregation + // for all properties: + if (!params.q && Object.keys(params.filters).length === 1) { + return [buildElasticAggregationsBody(params, Object.keys(AGGREGATIONS_SPEC))] + } + // Build the standard aggregation: const unfilteredAggregationProps = Object.keys(AGGREGATIONS_SPEC) // Aggregate on all properties that aren't involved in filters: From 5d3bf7db80ca405f5d04a84a49ac998f0c88b97d Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 6 Feb 2026 16:44:19 -0500 Subject: [PATCH 02/27] fix gha dep --- .github/workflows/test-and-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 6423821a..90842d52 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -81,7 +81,7 @@ jobs: runs-on: ubuntu-latest needs: - tests - - inte + - integration-test-qa if: github.ref == 'refs/heads/qa2' steps: - name: Checkout repo From ff3261969f4082e2eaa92cbc6142c04b3c727596 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 6 Feb 2026 16:45:44 -0500 Subject: [PATCH 03/27] gha --- .github/workflows/test-and-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 90842d52..afeb5470 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -21,7 +21,7 @@ jobs: contents: read runs-on: ubuntu-latest needs: tests - if: github.ref == 'refs/heads/qa' + if: github.ref == 'refs/heads/qa2' steps: - uses: actions/checkout@v4 - name: Set Node version From ffe1b303f11c75efaca17dd2b0e35fe0a050493f Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Mon, 9 Feb 2026 10:45:20 -0500 Subject: [PATCH 04/27] update gha invocation --- .github/workflows/test-and-deploy.yml | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index afeb5470..579df541 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -33,7 +33,7 @@ jobs: - name: Start service run: ENV=qa npm start & - name: Run tests - run: npm run test-integration + run: node test/integration/delivery-locations-by-barcode.test.js deploy-qa: permissions: id-token: write diff --git a/package.json b/package.json index c4e083b7..8443ec2b 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ }, "scripts": { "test": "./node_modules/.bin/standard --env mocha && NODE_ENV=test ./node_modules/.bin/mocha test --exit", - "test-integration": "./node_modules/.bin/mocha test/integration", "start": "node server.js", "deploy-development": "git checkout development && git pull origin development && eb deploy discovery-api-dev --profile nypl-sandbox", "deploy-qa": "git checkout qa && git pull origin qa && eb deploy discovery-api-qa --profile nypl-digital-dev", From c389071aec21660cf839cfbe8eec37fceb9fa393 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Mon, 9 Feb 2026 10:58:49 -0500 Subject: [PATCH 05/27] config aws in integration test --- .github/workflows/test-and-deploy.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 579df541..ca14ff2b 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -23,6 +23,11 @@ jobs: needs: tests if: github.ref == 'refs/heads/qa2' steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole + aws-region: us-east-1 - uses: actions/checkout@v4 - name: Set Node version uses: actions/setup-node@v4 From 817a05f43e8e199af17e65ad6abb1f11801b96af Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Mon, 9 Feb 2026 13:16:34 -0500 Subject: [PATCH 06/27] update gha workflows --- .github/workflows/integration-tests.yml | 25 ++++++++++++++++++++++++ .github/workflows/test-and-deploy.yml | 26 ------------------------- 2 files changed, 25 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/integration-tests.yml diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 00000000..e1f2a8ee --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,25 @@ +jobs: + integration-test-qa: + permissions: + id-token: write + contents: read + runs-on: ubuntu-latest + needs: tests + if: github.ref == 'refs/heads/qa2' + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole + aws-region: us-east-1 + - uses: actions/checkout@v4 + - name: Set Node version + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + - name: Install dependencies + run: npm ci + - name: Start service + run: ENV=qa npm start & + - name: Run tests + run: node test/integration/delivery-locations-by-barcode.test.js \ No newline at end of file diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index ca14ff2b..415ac41b 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -15,30 +15,6 @@ jobs: run: npm ci - name: Unit Tests run: npm test - integration-test-qa: - permissions: - id-token: write - contents: read - runs-on: ubuntu-latest - needs: tests - if: github.ref == 'refs/heads/qa2' - steps: - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole - aws-region: us-east-1 - - uses: actions/checkout@v4 - - name: Set Node version - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - name: Install dependencies - run: npm ci - - name: Start service - run: ENV=qa npm start & - - name: Run tests - run: node test/integration/delivery-locations-by-barcode.test.js deploy-qa: permissions: id-token: write @@ -50,7 +26,6 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v3 - - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v2 with: @@ -86,7 +61,6 @@ jobs: runs-on: ubuntu-latest needs: - tests - - integration-test-qa if: github.ref == 'refs/heads/qa2' steps: - name: Checkout repo From 691b974fd9ee12a5c98ca15998db9b143587ad3c Mon Sep 17 00:00:00 2001 From: danamansana Date: Tue, 10 Mar 2026 14:55:07 -0400 Subject: [PATCH 07/27] Fix deploy yaml --- .github/workflows/test-and-deploy.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index db2624d0..28b57be9 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -20,19 +20,10 @@ jobs: id-token: write contents: read runs-on: ubuntu-latest - needs: tests -<<<<<<< HEAD - if: github.ref == 'refs/heads/qa2' - steps: - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole - aws-region: us-east-1 -======= + needs: + - tests if: github.ref == 'refs/heads/qa' steps: ->>>>>>> main - uses: actions/checkout@v4 - name: Set Node version uses: actions/setup-node@v4 From 831760a1be28393be6a3c56783d85d10a6586992 Mon Sep 17 00:00:00 2001 From: Emma Mansell <73774046+7emansell@users.noreply.github.com> Date: Tue, 7 Apr 2026 16:18:26 -0400 Subject: [PATCH 08/27] Add series/genre search scopes and tests --- lib/api-request.js | 2 +- lib/elasticsearch/config.js | 24 ++++-- lib/elasticsearch/elastic-query-builder.js | 36 +++++++++ test/api-request.test.js | 5 +- test/elastic-query-builder.test.js | 85 ++++++++++++++++++++-- 5 files changed, 139 insertions(+), 13 deletions(-) diff --git a/lib/api-request.js b/lib/api-request.js index 73779f1c..aaf7070a 100644 --- a/lib/api-request.js +++ b/lib/api-request.js @@ -8,7 +8,7 @@ const QUOTE_CHARS = '"\u201C\u201D\u201E\u201F\u2033\u2036' const IN_QUOTES_PATTERN = new RegExp(`^[${QUOTE_CHARS}][^${QUOTE_CHARS}]+[${QUOTE_CHARS}]$`) class ApiRequest { - static ADVANCED_SEARCH_PARAMS = ['title', 'subject', 'contributor', 'callnumber', 'standard_number'] + static ADVANCED_SEARCH_PARAMS = ['title', 'subject', 'contributor', 'callnumber', 'standard_number', 'series', 'genre'] static IDENTIFIER_NUMBER_PARAMS = ['isbn', 'issn', 'lccn', 'oclc'] constructor (params) { diff --git a/lib/elasticsearch/config.js b/lib/elasticsearch/config.js index bb74f353..721fc019 100644 --- a/lib/elasticsearch/config.js +++ b/lib/elasticsearch/config.js @@ -43,17 +43,17 @@ const SEARCH_SCOPES = { 'titleAlt.folded', 'uniformTitle.folded', 'titleDisplay.folded', - 'seriesStatement.folded', 'contentsTitle.folded', 'donor.folded', 'parallelTitle.folded^5', 'parallelTitleDisplay.folded', - 'parallelSeriesStatement.folded', 'parallelTitleAlt.folded', 'parallelCreatorLiteral.folded', 'parallelUniformTitle', 'formerTitle', - 'addedAuthorTitle' + 'addedAuthorTitle', + 'seriesUniformTitle', + 'parallelSeriesUniformTitle' ] }, contributor: { @@ -63,7 +63,21 @@ const SEARCH_SCOPES = { fields: ['subjectLiteral^2', 'subjectLiteral.folded', 'parallelSubjectLiteral.folded'] }, series: { - fields: ['seriesStatement.folded'] + fields: [ + 'series^2', + 'series.folded', + 'parallelSeries^2', + 'parallelSeries.folded', + 'seriesUniformTitle', + 'parallelSeriesUniformTitle^2', + 'parallelSeriesUniformTitle.folded', + 'seriesAddedEntry', + 'parallelSeriesAddedEntry^2', + 'parallelSeriesAddedEntry.folded' + ] + }, + genre: { + fields: ['genreForm^2', 'genreForm.folded', 'parallelGenreForm^2', 'parallelGenreForm.folded'] }, journal_title: { fields: null @@ -107,7 +121,7 @@ const FILTER_CONFIG = { titleAlt: { operator: 'match', field: ['titleAlt.raw', 'parallelTitleAlt.raw'], repeatable: true }, uniformTitle: { operator: 'match', field: ['uniformTitle.raw', 'parallelUniformTitle.raw'], repeatable: true }, addedAuthorTitle: { operator: 'match', field: ['addedAuthorTitle.raw', 'parallelAddedAuthorTitle.raw'], repeatable: true }, - series: { operator: 'match', field: ['series', 'parallelSeries'], repeatable: true }, + series: { operator: 'match', field: ['series', 'parallelSeries', 'seriesUniformTitle', 'parallelSeriesUniformTitle', 'seriesAddedEntry', 'parallelSeriesAddedEntry'], repeatable: true }, placeOfPublication: { operator: 'match', field: ['placeOfPublication', 'parallelPlaceOfPublication'], repeatable: true }, dateFrom: { operator: 'custom', diff --git a/lib/elasticsearch/elastic-query-builder.js b/lib/elasticsearch/elastic-query-builder.js index d5e0d1b0..29b7a05e 100644 --- a/lib/elasticsearch/elastic-query-builder.js +++ b/lib/elasticsearch/elastic-query-builder.js @@ -30,6 +30,12 @@ class ElasticQueryBuilder { case 'subject': this.buildSubjectQuery() break + case 'series': + this.buildSeriesQuery() + break + case 'genre': + this.buildGenreQuery() + break case 'standard_number': this.buildStandardNumberQuery() break @@ -163,6 +169,36 @@ class ElasticQueryBuilder { this.boostSubjectMatches() } + /** + * Build ES query for 'series' searches + */ + buildSeriesQuery () { + if (!this.request.hasSearch()) return + + // Require a basic multi-match on series fields: + this.requireMultiMatch(SEARCH_SCOPES.series.fields) + + // Apply common boosts: + this.boostNyplOwned() + this.boostOnSite() + this.boostPopular() + } + + /** + * Build ES query for 'genre' searches + */ + buildGenreQuery () { + if (!this.request.hasSearch()) return + + // Require a basic multi-match on genre fields: + this.requireMultiMatch(SEARCH_SCOPES.genre.fields) + + // Apply common boosts: + this.boostNyplOwned() + this.boostOnSite() + this.boostPopular() + } + applySubjectPrefix () { const q = this.request.params.subject_prefix this.query.addMust({ diff --git a/test/api-request.test.js b/test/api-request.test.js index 9a1eca68..d1bfdc38 100644 --- a/test/api-request.test.js +++ b/test/api-request.test.js @@ -31,7 +31,7 @@ describe('ApiRequest', function () { request = ApiRequest.fromParams({ q: '"toast"' }) expect(request.queryIsFullyQuoted()).to.eq(true) - // Test smart-quotes, the great scorge + // Test smart-quotes, the great scourge request = ApiRequest.fromParams({ q: '“toast“' }) expect(request.queryIsFullyQuoted()).to.eq(true) @@ -54,5 +54,8 @@ describe('ApiRequest', function () { request = ApiRequest.fromParams({ title: '"toast"', foo: 'bar' }) expect(request.advancedSearchParamsThatAreAlsoScopes()).to.deep.eq(['title']) + + request = ApiRequest.fromParams({ series: '"Greek volumes"', foo: 'bar' }) + expect(request.advancedSearchParamsThatAreAlsoScopes()).to.deep.eq(['series']) }) }) diff --git a/test/elastic-query-builder.test.js b/test/elastic-query-builder.test.js index 062a9ec0..6bfe8f6b 100644 --- a/test/elastic-query-builder.test.js +++ b/test/elastic-query-builder.test.js @@ -216,6 +216,42 @@ describe('ElasticQueryBuilder', () => { }) }) + describe('search_scope genre', () => { + it('generates a "genre" query', () => { + const request = new ApiRequest({ q: 'toast', search_scope: 'genre' }) + const inst = ElasticQueryBuilder.forApiRequest(request) + + // Expect a multi_match on term: + expect(inst.query.toJson()).to.nested + .include({ 'bool.must[0].multi_match.type': 'cross_fields' }) + .include({ 'bool.must[0].multi_match.query': 'toast' }) + .include({ 'bool.must[0].multi_match.fields[0]': 'genreForm^2' }) + + // Expect only common boosting clauses + expect(inst.query.toJson().bool.should) + .to.be.a('array') + .have.lengthOf(4) + }) + }) + + describe('search_scope series', () => { + it('generates a "series" query', () => { + const request = new ApiRequest({ q: 'toast', search_scope: 'series' }) + const inst = ElasticQueryBuilder.forApiRequest(request) + + // Expect a multi_match on term: + expect(inst.query.toJson()).to.nested + .include({ 'bool.must[0].multi_match.type': 'cross_fields' }) + .include({ 'bool.must[0].multi_match.query': 'toast' }) + .include({ 'bool.must[0].multi_match.fields[0]': 'series^2' }) + + // Expect only common boosting clauses + expect(inst.query.toJson().bool.should) + .to.be.a('array') + .have.lengthOf(4) + }) + }) + describe('multiple id query', () => { it('supports ids=x,y,z', () => { const request = new ApiRequest({ q: '', ids: ['id_a', 'id_b'] }) @@ -371,6 +407,43 @@ describe('ElasticQueryBuilder', () => { }) }) + describe('series=', () => { + it('applies series clauses to query', () => { + const request = new ApiRequest({ series: 'toast' }) + const inst = ElasticQueryBuilder.forApiRequest(request) + + const query = inst.query.toJson() + + // Assert there's a multi-match: + expect(query).to.nested + .include({ + // Multi-match on common series fields: + 'bool.must[0].bool.must[0].multi_match.fields[0]': 'series^2', + 'bool.must[0].bool.must[0].multi_match.fields[4]': 'seriesUniformTitle', + 'bool.must[0].bool.must[0].multi_match.fields[7]': 'seriesAddedEntry', + 'bool.must[0].bool.must[0].multi_match.query': 'toast' + }) + }) + }) + + describe('genre=', () => { + it('applies genre clauses to query', () => { + const request = new ApiRequest({ genre: 'toast' }) + const inst = ElasticQueryBuilder.forApiRequest(request) + + const query = inst.query.toJson() + + // Assert there's a multi-match: + expect(query).to.nested + .include({ + // Multi-match on common genre fields: + 'bool.must[0].bool.must[0].multi_match.fields[0]': 'genreForm^2', + 'bool.must[0].bool.must[0].multi_match.fields[2]': 'parallelGenreForm^2', + 'bool.must[0].bool.must[0].multi_match.query': 'toast' + }) + }) + }) + describe('subject_prefix=', () => { it('applies subject_prefix clauses to query', () => { const request = new ApiRequest({ subject_prefix: 'toast' }) @@ -517,7 +590,7 @@ describe('ElasticQueryBuilder', () => { } }) - // Asset filter clauses: + // Assert filter clauses: expect(query).to.nested.include({ 'bool.filter[0].bool.should[0].nested.path': 'dates', 'bool.filter[0].bool.should[0].nested.query.range.dates\\.range.gte': '2020', @@ -545,7 +618,7 @@ describe('ElasticQueryBuilder', () => { const query = inst.query.toJson() - // Asset filter clauses: + // Assert filter clauses: expect(query).to.nested.include({ 'bool.filter[0].bool.should[0].nested.path': 'dates', 'bool.filter[0].bool.should[0].nested.query.range.dates\\.range.gte': '2020-12-31', @@ -568,7 +641,7 @@ describe('ElasticQueryBuilder', () => { const query = inst.query.toJson() - // Asset filter clauses: + // Assert filter clauses: expect(query).to.nested.include({ 'bool.filter[0].bool.should[0].nested.path': 'dates', 'bool.filter[0].bool.should[0].nested.query.range.dates\\.range.gte': '2020-12-31', @@ -591,7 +664,7 @@ describe('ElasticQueryBuilder', () => { const query = inst.query.toJson() - // Asset filter clauses: + // Assert filter clauses: expect(query).to.nested.include({ 'bool.filter[0].bool.should[0].nested.path': 'dates', 'bool.filter[0].bool.should[0].nested.query.range.dates\\.range.gte': '2020-01', @@ -614,7 +687,7 @@ describe('ElasticQueryBuilder', () => { const query = inst.query.toJson() - // Asset filter clauses: + // Assert filter clauses: expect(query).to.nested.include({ 'bool.filter[0].bool.should[0].nested.path': 'dates', 'bool.filter[0].bool.should[0].nested.query.range.dates\\.range.gte': '2020-01', @@ -637,7 +710,7 @@ describe('ElasticQueryBuilder', () => { const query = inst.query.toJson() - // Asset filter clauses: + // Assert filter clauses: expect(query).to.nested.include({ 'bool.filter[0].bool.should[0].nested.path': 'dates', 'bool.filter[0].bool.should[0].nested.query.range.dates\\.range.gte': '2020-01', From 19ec7642591bce1d67c36d6f1c01118e54d4d76c Mon Sep 17 00:00:00 2001 From: Emma Mansell <73774046+7emansell@users.noreply.github.com> Date: Tue, 7 Apr 2026 17:52:23 -0400 Subject: [PATCH 09/27] no parallel genreForm --- lib/elasticsearch/config.js | 2 +- test/elastic-query-builder.test.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/elasticsearch/config.js b/lib/elasticsearch/config.js index 721fc019..c499a78a 100644 --- a/lib/elasticsearch/config.js +++ b/lib/elasticsearch/config.js @@ -77,7 +77,7 @@ const SEARCH_SCOPES = { ] }, genre: { - fields: ['genreForm^2', 'genreForm.folded', 'parallelGenreForm^2', 'parallelGenreForm.folded'] + fields: ['genreForm^2', 'genreForm.folded'] }, journal_title: { fields: null diff --git a/test/elastic-query-builder.test.js b/test/elastic-query-builder.test.js index 6bfe8f6b..bced9fd8 100644 --- a/test/elastic-query-builder.test.js +++ b/test/elastic-query-builder.test.js @@ -417,7 +417,7 @@ describe('ElasticQueryBuilder', () => { // Assert there's a multi-match: expect(query).to.nested .include({ - // Multi-match on common series fields: + // Multi-match on series fields: 'bool.must[0].bool.must[0].multi_match.fields[0]': 'series^2', 'bool.must[0].bool.must[0].multi_match.fields[4]': 'seriesUniformTitle', 'bool.must[0].bool.must[0].multi_match.fields[7]': 'seriesAddedEntry', @@ -436,9 +436,9 @@ describe('ElasticQueryBuilder', () => { // Assert there's a multi-match: expect(query).to.nested .include({ - // Multi-match on common genre fields: + // Multi-match on genre fields: 'bool.must[0].bool.must[0].multi_match.fields[0]': 'genreForm^2', - 'bool.must[0].bool.must[0].multi_match.fields[2]': 'parallelGenreForm^2', + 'bool.must[0].bool.must[0].multi_match.fields[1]': 'genreForm.folded', 'bool.must[0].bool.must[0].multi_match.query': 'toast' }) }) From 3316e8fc5a579ca00b608211502f86b74bf009b5 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 09:26:19 -0400 Subject: [PATCH 10/27] trigger rollback with integration-test failure --- .github/workflows/integration-tests.yml | 2 +- .github/workflows/rollback-qa2.yml | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index eb0bc040..d0634cb7 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -4,7 +4,7 @@ on: workflow_run: workflows: ["Deploy"] types: [completed] - branches: [production, qa] + branches: [production, qa, qa2] permissions: id-token: write diff --git a/.github/workflows/rollback-qa2.yml b/.github/workflows/rollback-qa2.yml index 925d8b4f..6d54f636 100644 --- a/.github/workflows/rollback-qa2.yml +++ b/.github/workflows/rollback-qa2.yml @@ -1,7 +1,12 @@ name: Rollback qa2 -on: - workflow_dispatch: +on: + workflow_run: + workflows: ["Run Smoke Test"] + types: [completed] + +env: + ENV: ${{ github.event.workflow_run.head_branch }} jobs: # Rollback job in case of failure (Revert qa to the previous task definition) @@ -11,6 +16,7 @@ jobs: contents: read name: Rollback to Previous Version runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' && env.ENV == 'qa2'}} steps: - name: Checkout code uses: actions/checkout@v4 From a19d88f36031f445a56944afc0a71cfdfdbf70ef Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 09:27:10 -0400 Subject: [PATCH 11/27] ensure int test failure --- .../delivery-locations-by-barcode.test.js | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/test/integration/delivery-locations-by-barcode.test.js b/test/integration/delivery-locations-by-barcode.test.js index 23245370..2a8fa699 100644 --- a/test/integration/delivery-locations-by-barcode.test.js +++ b/test/integration/delivery-locations-by-barcode.test.js @@ -46,19 +46,20 @@ const getDeliveryLocations = async (barcode, patronId) => { } const theThing = async () => { - await loadConfig() - const results = await Promise.all(Object.keys(ptypes).map((checkLocationsForPtype))) - const resultsHaveProblems = Object.keys(ptypes).some((ptype, i) => { - const resultsForPtype = results[i] - if (resultsForPtype.problems.length) { - console.error(`Error with ${ptype} ptype delivery results, `, resultsForPtype.problems) - return true - } else { - console.log(`All delivery location checks for ${ptype} patron type successful`) - return false - } - }) - if (resultsHaveProblems) throw new Error('Delivery location checks failed.') + throw new Error('spaghetti') + // await loadConfig() + // const results = await Promise.all(Object.keys(ptypes).map((checkLocationsForPtype))) + // const resultsHaveProblems = Object.keys(ptypes).some((ptype, i) => { + // const resultsForPtype = results[i] + // if (resultsForPtype.problems.length) { + // console.error(`Error with ${ptype} ptype delivery results, `, resultsForPtype.problems) + // return true + // } else { + // console.log(`All delivery location checks for ${ptype} patron type successful`) + // return false + // } + // }) + // if (resultsHaveProblems) throw new Error('Delivery location checks failed.') } theThing() From 4ba6d0d8718668ac9f638da4f03d97db74ab5f9b Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 09:28:44 -0400 Subject: [PATCH 12/27] failure to pass linting --- .../delivery-locations-by-barcode.test.js | 114 +++++++++--------- 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/test/integration/delivery-locations-by-barcode.test.js b/test/integration/delivery-locations-by-barcode.test.js index 2a8fa699..c50f1d0b 100644 --- a/test/integration/delivery-locations-by-barcode.test.js +++ b/test/integration/delivery-locations-by-barcode.test.js @@ -1,65 +1,69 @@ -const { loadConfig } = require('../../lib/load-config') -const { expectations, ptypes } = require('./delivery-locations-constants') -const { makeNyplDataApiClient } = require('../../lib/data-api-client') +// const { loadConfig } = require('../../lib/load-config') +// const { expectations, ptypes } = require('./delivery-locations-constants') +// const { makeNyplDataApiClient } = require('../../lib/data-api-client') -const checkLocationsForPtype = async (ptype) => { - const problems = [] - const match = [] +// const checkLocationsForPtype = async (ptype) => { +// const problems = [] +// const match = [] - await Promise.all(Object.entries(expectations).map(async ([holdingLocation, expectation], i) => { - let deliveryLocationsFromApi - let totalMatch = true - const registerProblem = (problem) => { - problems.push({ holdingLocation, barcode: expectation.barcode, deliveryLocationsFromApi, ...problem }) - totalMatch = false - } - try { - deliveryLocationsFromApi = await getDeliveryLocations(expectation.barcode, ptypes[ptype]) - } catch (e) { - registerProblem({ lookUpFailed: true }) - return - } +// await Promise.all(Object.entries(expectations).map(async ([holdingLocation, expectation], i) => { +// let deliveryLocationsFromApi +// let totalMatch = true +// const registerProblem = (problem) => { +// problems.push({ holdingLocation, barcode: expectation.barcode, deliveryLocationsFromApi, ...problem }) +// totalMatch = false +// } +// try { +// deliveryLocationsFromApi = await getDeliveryLocations(expectation.barcode, ptypes[ptype]) +// } catch (e) { +// registerProblem({ lookUpFailed: true }) +// return +// } - const checkForValue = (expectedValue, action) => { - const includedValueIncluded = deliveryLocationsFromApi.some((label) => label.includes(expectedValue)) - const match = action === 'include' ? includedValueIncluded : !includedValueIncluded - if (!match) { - registerProblem({ [`expectedTo${action}`]: expectedValue }) - } - } - expectation[ptype].includes.forEach((expectedValue) => checkForValue(expectedValue, 'include')) - expectation[ptype].excludes.forEach((expectedValue) => checkForValue(expectedValue, 'exclude')) - if (totalMatch) match.push({ barcode: expectation.barcode, deliveryLocationsFromApi, expectedToInclude: expectation[ptype].includes, expectedToExclude: expectation[ptype].excludes }) - })) - return { match, problems } -} +// const checkForValue = (expectedValue, action) => { +// const includedValueIncluded = deliveryLocationsFromApi.some((label) => label.includes(expectedValue)) +// const match = action === 'include' ? includedValueIncluded : !includedValueIncluded +// if (!match) { +// registerProblem({ [`expectedTo${action}`]: expectedValue }) +// } +// } +// expectation[ptype].includes.forEach((expectedValue) => checkForValue(expectedValue, 'include')) +// expectation[ptype].excludes.forEach((expectedValue) => checkForValue(expectedValue, 'exclude')) +// if (totalMatch) match.push({ barcode: expectation.barcode, deliveryLocationsFromApi, expectedToInclude: expectation[ptype].includes, expectedToExclude: expectation[ptype].excludes }) +// })) +// return { match, problems } +// } -const getDeliveryLocations = async (barcode, patronId) => { - try { - const { itemListElement: itemData } = await makeNyplDataApiClient().get(`request/deliveryLocationsByBarcode?barcodes[]=${barcode}&patronId=${patronId}`) - // per record - return itemData[0] - .deliveryLocation.map(loc => loc.prefLabel.toLowerCase()) - } catch (e) { - console.error(e) - } -} +// const getDeliveryLocations = async (barcode, patronId) => { +// try { +// const { itemListElement: itemData } = await makeNyplDataApiClient().get(`request/deliveryLocationsByBarcode?barcodes[]=${barcode}&patronId=${patronId}`) +// // per record +// return itemData[0] +// .deliveryLocation.map(loc => loc.prefLabel.toLowerCase()) +// } catch (e) { +// console.error(e) +// } +// } + +// const theThing = async () => { +// throw new Error('spaghetti') +// await loadConfig() +// const results = await Promise.all(Object.keys(ptypes).map((checkLocationsForPtype))) +// const resultsHaveProblems = Object.keys(ptypes).some((ptype, i) => { +// const resultsForPtype = results[i] +// if (resultsForPtype.problems.length) { +// console.error(`Error with ${ptype} ptype delivery results, `, resultsForPtype.problems) +// return true +// } else { +// console.log(`All delivery location checks for ${ptype} patron type successful`) +// return false +// } +// }) +// if (resultsHaveProblems) throw new Error('Delivery location checks failed.') +// } const theThing = async () => { throw new Error('spaghetti') - // await loadConfig() - // const results = await Promise.all(Object.keys(ptypes).map((checkLocationsForPtype))) - // const resultsHaveProblems = Object.keys(ptypes).some((ptype, i) => { - // const resultsForPtype = results[i] - // if (resultsForPtype.problems.length) { - // console.error(`Error with ${ptype} ptype delivery results, `, resultsForPtype.problems) - // return true - // } else { - // console.log(`All delivery location checks for ${ptype} patron type successful`) - // return false - // } - // }) - // if (resultsHaveProblems) throw new Error('Delivery location checks failed.') } theThing() From 69d493e991f7d52be039e55a10ea9aa6620f579e Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 09:38:51 -0400 Subject: [PATCH 13/27] add yml to remove in qa2 merge conflict --- .github/workflows/test-and-deploy.yml | 139 ++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 .github/workflows/test-and-deploy.yml diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml new file mode 100644 index 00000000..415ac41b --- /dev/null +++ b/.github/workflows/test-and-deploy.yml @@ -0,0 +1,139 @@ +name: Unit Tests + +on: [push] + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set Node version + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + - name: npm install + run: npm ci + - name: Unit Tests + run: npm test + deploy-qa: + permissions: + id-token: write + contents: read + runs-on: ubuntu-latest + needs: + - tests + if: github.ref == 'refs/heads/qa' + steps: + - name: Checkout repo + uses: actions/checkout@v3 + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole + aws-region: us-east-1 + - name: Log in to ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + - name: Back up previous image for rollback + env: + ECR_REPOSITORY: discovery-api + run: | + MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') + PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') + if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "qa-previous" --image-manifest "$MANIFEST"; fi + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: discovery-api + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:qa-latest + docker push $ECR_REGISTRY/$ECR_REPOSITORY:qa-latest + - name: Force ECS Update + run: | + aws ecs update-service --cluster discovery-api-qa --service discovery-api-qa --force-new-deployment + deploy-qa2: + permissions: + id-token: write + contents: read + runs-on: ubuntu-latest + needs: + - tests + if: github.ref == 'refs/heads/qa2' + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole + aws-region: us-east-1 + + - name: Log in to ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + - name: Back up previous image for rollback + env: + ECR_REPOSITORY: discovery-api + run: | + MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa2-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') + PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa2-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') + if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "qa2-previous" --image-manifest "$MANIFEST"; fi + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: discovery-api + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:qa2-latest + docker push $ECR_REGISTRY/$ECR_REPOSITORY:qa2-latest + + - name: Force ECS Update + run: | + aws ecs update-service --cluster discovery-api-qa2 --service discovery-api-qa2 --force-new-deployment + deploy-production: + permissions: + id-token: write + contents: read + runs-on: ubuntu-latest + needs: tests + if: github.ref == 'refs/heads/production' + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole + aws-region: us-east-1 + + - name: Log in to ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Back up previous image for rollback + env: + ECR_REPOSITORY: discovery-api + run: | + MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="production-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') + PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="production-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') + if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "production-previous" --image-manifest "$MANIFEST"; fi + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: discovery-api + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:production-latest + docker push $ECR_REGISTRY/$ECR_REPOSITORY:production-latest + - name: Force ECS Update + run: | + aws ecs update-service --cluster discovery-api-production --service discovery-api-production --force-new-deployment From a8df84b23d00fb59003ed50c2ff69d49d42e93cf Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 09:39:23 -0400 Subject: [PATCH 14/27] rm test and deploy --- .github/workflows/test-and-deploy.yml | 139 -------------------------- 1 file changed, 139 deletions(-) delete mode 100644 .github/workflows/test-and-deploy.yml diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml deleted file mode 100644 index 415ac41b..00000000 --- a/.github/workflows/test-and-deploy.yml +++ /dev/null @@ -1,139 +0,0 @@ -name: Unit Tests - -on: [push] - -jobs: - tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set Node version - uses: actions/setup-node@v3 - with: - node-version-file: '.nvmrc' - - name: npm install - run: npm ci - - name: Unit Tests - run: npm test - deploy-qa: - permissions: - id-token: write - contents: read - runs-on: ubuntu-latest - needs: - - tests - if: github.ref == 'refs/heads/qa' - steps: - - name: Checkout repo - uses: actions/checkout@v3 - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole - aws-region: us-east-1 - - name: Log in to ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - name: Back up previous image for rollback - env: - ECR_REPOSITORY: discovery-api - run: | - MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') - PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') - if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "qa-previous" --image-manifest "$MANIFEST"; fi - - name: Build, tag, and push image to Amazon ECR - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: discovery-api - IMAGE_TAG: ${{ github.sha }} - run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:qa-latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:qa-latest - - name: Force ECS Update - run: | - aws ecs update-service --cluster discovery-api-qa --service discovery-api-qa --force-new-deployment - deploy-qa2: - permissions: - id-token: write - contents: read - runs-on: ubuntu-latest - needs: - - tests - if: github.ref == 'refs/heads/qa2' - steps: - - name: Checkout repo - uses: actions/checkout@v3 - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole - aws-region: us-east-1 - - - name: Log in to ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - name: Back up previous image for rollback - env: - ECR_REPOSITORY: discovery-api - run: | - MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa2-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') - PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa2-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') - if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "qa2-previous" --image-manifest "$MANIFEST"; fi - - name: Build, tag, and push image to Amazon ECR - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: discovery-api - IMAGE_TAG: ${{ github.sha }} - run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:qa2-latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:qa2-latest - - - name: Force ECS Update - run: | - aws ecs update-service --cluster discovery-api-qa2 --service discovery-api-qa2 --force-new-deployment - deploy-production: - permissions: - id-token: write - contents: read - runs-on: ubuntu-latest - needs: tests - if: github.ref == 'refs/heads/production' - steps: - - name: Checkout repo - uses: actions/checkout@v3 - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole - aws-region: us-east-1 - - - name: Log in to ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Back up previous image for rollback - env: - ECR_REPOSITORY: discovery-api - run: | - MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="production-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') - PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="production-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') - if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "production-previous" --image-manifest "$MANIFEST"; fi - - name: Build, tag, and push image to Amazon ECR - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: discovery-api - IMAGE_TAG: ${{ github.sha }} - run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:production-latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:production-latest - - name: Force ECS Update - run: | - aws ecs update-service --cluster discovery-api-production --service discovery-api-production --force-new-deployment From eca7039400537d61ec83842ea53c68a0875ff073 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Mon, 9 Feb 2026 13:16:34 -0500 Subject: [PATCH 15/27] update gha workflows --- .github/workflows/integration-tests.yml | 25 +++++++++++++++++++++++++ .github/workflows/test-and-deploy.yml | 21 --------------------- 2 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/integration-tests.yml diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 00000000..e1f2a8ee --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,25 @@ +jobs: + integration-test-qa: + permissions: + id-token: write + contents: read + runs-on: ubuntu-latest + needs: tests + if: github.ref == 'refs/heads/qa2' + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole + aws-region: us-east-1 + - uses: actions/checkout@v4 + - name: Set Node version + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + - name: Install dependencies + run: npm ci + - name: Start service + run: ENV=qa npm start & + - name: Run tests + run: node test/integration/delivery-locations-by-barcode.test.js \ No newline at end of file diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 28b57be9..a04f5381 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -15,26 +15,6 @@ jobs: run: npm ci - name: Unit Tests run: npm test - integration-test-qa: - permissions: - id-token: write - contents: read - runs-on: ubuntu-latest - needs: - - tests - if: github.ref == 'refs/heads/qa' - steps: - - uses: actions/checkout@v4 - - name: Set Node version - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - name: Install dependencies - run: npm ci - - name: Start service - run: ENV=qa npm start & - - name: Run tests - run: node test/integration/delivery-locations-by-barcode.test.js deploy-qa: permissions: id-token: write @@ -46,7 +26,6 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v3 - - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v2 with: From b8bdb990d5634aa05af822d323c5ac1d969417da Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 09:41:08 -0400 Subject: [PATCH 16/27] rm test and deploy --- .github/workflows/test-and-deploy.yml | 139 -------------------------- 1 file changed, 139 deletions(-) delete mode 100644 .github/workflows/test-and-deploy.yml diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml deleted file mode 100644 index a04f5381..00000000 --- a/.github/workflows/test-and-deploy.yml +++ /dev/null @@ -1,139 +0,0 @@ -name: Unit Tests - -on: [push] - -jobs: - tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set Node version - uses: actions/setup-node@v3 - with: - node-version-file: '.nvmrc' - - name: npm install - run: npm ci - - name: Unit Tests - run: npm test - deploy-qa: - permissions: - id-token: write - contents: read - runs-on: ubuntu-latest - needs: - - tests - if: github.ref == 'refs/heads/qa' - steps: - - name: Checkout repo - uses: actions/checkout@v3 - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole - aws-region: us-east-1 - - name: Log in to ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - name: Back up previous image for rollback - env: - ECR_REPOSITORY: discovery-api - run: | - MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') - PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') - if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "qa-previous" --image-manifest "$MANIFEST"; fi - - name: Build, tag, and push image to Amazon ECR - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: discovery-api - IMAGE_TAG: ${{ github.sha }} - run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:qa-latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:qa-latest - - name: Force ECS Update - run: | - aws ecs update-service --cluster discovery-api-qa --service discovery-api-qa --force-new-deployment - deploy-qa2: - permissions: - id-token: write - contents: read - runs-on: ubuntu-latest - needs: - - tests - if: github.ref == 'refs/heads/qa2' - steps: - - name: Checkout repo - uses: actions/checkout@v3 - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole - aws-region: us-east-1 - - - name: Log in to ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - name: Back up previous image for rollback - env: - ECR_REPOSITORY: discovery-api - run: | - MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa2-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') - PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="qa2-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') - if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "qa2-previous" --image-manifest "$MANIFEST"; fi - - name: Build, tag, and push image to Amazon ECR - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: discovery-api - IMAGE_TAG: ${{ github.sha }} - run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:qa2-latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:qa2-latest - - - name: Force ECS Update - run: | - aws ecs update-service --cluster discovery-api-qa2 --service discovery-api-qa2 --force-new-deployment - deploy-production: - permissions: - id-token: write - contents: read - runs-on: ubuntu-latest - needs: tests - if: github.ref == 'refs/heads/production' - steps: - - name: Checkout repo - uses: actions/checkout@v3 - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole - aws-region: us-east-1 - - - name: Log in to ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Back up previous image for rollback - env: - ECR_REPOSITORY: discovery-api - run: | - MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="production-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') - PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="production-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') - if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "production-previous" --image-manifest "$MANIFEST"; fi - - name: Build, tag, and push image to Amazon ECR - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: discovery-api - IMAGE_TAG: ${{ github.sha }} - run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:production-latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:production-latest - - name: Force ECS Update - run: | - aws ecs update-service --cluster discovery-api-production --service discovery-api-production --force-new-deployment From d2b9efd6c3c62fbaf7ff7d7a0375a0710f9832b6 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 10:01:34 -0400 Subject: [PATCH 17/27] hard code qa2 for now --- .github/workflows/rollback-qa2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rollback-qa2.yml b/.github/workflows/rollback-qa2.yml index 6d54f636..15b10494 100644 --- a/.github/workflows/rollback-qa2.yml +++ b/.github/workflows/rollback-qa2.yml @@ -16,7 +16,7 @@ jobs: contents: read name: Rollback to Previous Version runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'failure' && env.ENV == 'qa2'}} + if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.head_branch == 'qa2'}} steps: - name: Checkout code uses: actions/checkout@v4 From 3de6b01609be5e5e200991a255012223d73594ee Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 10:24:58 -0400 Subject: [PATCH 18/27] &ai pass branch from deploy script --- .github/workflows/deploy.yml | 11 ++++++++++- .github/workflows/integration-tests.yml | 11 ++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a89f2d98..fc63afec 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -57,4 +57,13 @@ jobs: - name: Force ECS Update run: | - aws ecs update-service --cluster discovery-api-${{ env.ENV_TAG }} --service discovery-api-${{ env.ENV_TAG }} --force-new-deployment \ No newline at end of file + aws ecs update-service --cluster discovery-api-${{ env.ENV_TAG }} --service discovery-api-${{ env.ENV_TAG }} --force-new-deployment + + smoke-test: + permissions: + id-token: write + contents: read + needs: deploy + uses: ./.github/workflows/integration-tests.yml + with: + branch: ${{ github.ref_name }} \ No newline at end of file diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index d0634cb7..cc2c391b 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -1,17 +1,18 @@ name: Run Smoke Tests on: - workflow_run: - workflows: ["Deploy"] - types: [completed] - branches: [production, qa, qa2] + workflow_call: + inputs: + branch: + required: true + type: string permissions: id-token: write contents: read env: - ENV: ${{ github.event.workflow_run.head_branch }} + ENV: ${{ inputs.branch }} jobs: integration-test: From 41d9d24ac06eff19cdfd5696788b8060e173ec9f Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 10:37:21 -0400 Subject: [PATCH 19/27] &ai more gha refactor --- .github/workflows/deploy.yml | 50 ++++++++---------------------- .github/workflows/rollback-qa2.yml | 10 ++---- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fc63afec..613b8662 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,43 +21,11 @@ jobs: permissions: id-token: write contents: read - runs-on: ubuntu-latest needs: tests - steps: - - name: Checkout repo - uses: actions/checkout@v3 - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole - aws-region: us-east-1 - - - name: Log in to ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Back up previous image for rollback - run: | - MANIFEST=$(aws ecr batch-get-image --repository-name ${{ env.ECR_REPOSITORY }} --image-ids imageTag="${{ env.ENV_TAG }}-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') - PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name ${{ env.ECR_REPOSITORY }} --image-ids imageTag="${{ env.ENV_TAG }}-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') - if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then - aws ecr put-image --repository-name ${{ env.ECR_REPOSITORY }} --image-tag "${{ env.ENV_TAG }}-previous" --image-manifest "$MANIFEST" - fi - - - name: Build, tag, and push image to Amazon ECR - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - IMAGE_TAG: ${{ github.sha }} - run: | - docker build -t $ECR_REGISTRY/${{ env.ECR_REPOSITORY }}:$IMAGE_TAG . - docker push $ECR_REGISTRY/${{ env.ECR_REPOSITORY }}:$IMAGE_TAG - docker tag $ECR_REGISTRY/${{ env.ECR_REPOSITORY }}:$IMAGE_TAG $ECR_REGISTRY/${{ env.ECR_REPOSITORY }}:${{ env.ENV_TAG }}-latest - docker push $ECR_REGISTRY/${{ env.ECR_REPOSITORY }}:${{ env.ENV_TAG }}-latest - - - name: Force ECS Update - run: | - aws ecs update-service --cluster discovery-api-${{ env.ENV_TAG }} --service discovery-api-${{ env.ENV_TAG }} --force-new-deployment + uses: ./.github/workflows/deploy-image.yml + with: + env_tag: ${{ github.ref_name }} + image_tag: ${{ github.sha }} smoke-test: permissions: @@ -66,4 +34,12 @@ jobs: needs: deploy uses: ./.github/workflows/integration-tests.yml with: - branch: ${{ github.ref_name }} \ No newline at end of file + branch: ${{ github.ref_name }} + + rollback: + permissions: + id-token: write + contents: read + needs: smoke-test + if: ${{ needs.smoke-test.result == 'failure' && github.ref_name == 'qa2' }} + uses: ./.github/workflows/rollback-qa2.yml \ No newline at end of file diff --git a/.github/workflows/rollback-qa2.yml b/.github/workflows/rollback-qa2.yml index 15b10494..2b949682 100644 --- a/.github/workflows/rollback-qa2.yml +++ b/.github/workflows/rollback-qa2.yml @@ -1,12 +1,7 @@ name: Rollback qa2 -on: - workflow_run: - workflows: ["Run Smoke Test"] - types: [completed] - -env: - ENV: ${{ github.event.workflow_run.head_branch }} +on: + workflow_call: jobs: # Rollback job in case of failure (Revert qa to the previous task definition) @@ -16,7 +11,6 @@ jobs: contents: read name: Rollback to Previous Version runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.head_branch == 'qa2'}} steps: - name: Checkout code uses: actions/checkout@v4 From 7940c605e6adad26ab82094b9c6199f14a6e27b0 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 10:50:55 -0400 Subject: [PATCH 20/27] more gha refactor --- .github/workflows/deploy-image.yml | 55 ++++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 8 +++-- .github/workflows/rollback-qa2.yml | 6 +++- 3 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/deploy-image.yml diff --git a/.github/workflows/deploy-image.yml b/.github/workflows/deploy-image.yml new file mode 100644 index 00000000..ed808f96 --- /dev/null +++ b/.github/workflows/deploy-image.yml @@ -0,0 +1,55 @@ +name: Deploy Image + +on: + workflow_call: + inputs: + env_tag: + required: true + type: string + image_tag: + required: true + type: string + +jobs: + deploy: + permissions: + id-token: write + contents: read + runs-on: ubuntu-latest + env: + ENV_TAG: ${{ inputs.env_tag }} + ECR_REPOSITORY: discovery-api + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole + aws-region: us-east-1 + + - name: Log in to ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Back up previous image for rollback + run: | + MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="${ENV_TAG}-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') + PREVIOUS_MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="${ENV_TAG}-previous" --output json | jq --raw-output --join-output '.images[0].imageManifest') + if [ "$MANIFEST" != "$PREVIOUS_MANIFEST" ]; then + aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "${ENV_TAG}-previous" --image-manifest "$MANIFEST" + fi + + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:${{ inputs.image_tag }} . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{ inputs.image_tag }} + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:${{ inputs.image_tag }} $ECR_REGISTRY/$ECR_REPOSITORY:${ENV_TAG}-latest + docker push $ECR_REGISTRY/$ECR_REPOSITORY:${ENV_TAG}-latest + + - name: Force ECS Update + run: | + aws ecs update-service --cluster discovery-api-${ENV_TAG} --service discovery-api-${ENV_TAG} --force-new-deployment diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 613b8662..a329f546 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy +name: Test-Deploy-Int-Roll on: push: @@ -41,5 +41,7 @@ jobs: id-token: write contents: read needs: smoke-test - if: ${{ needs.smoke-test.result == 'failure' && github.ref_name == 'qa2' }} - uses: ./.github/workflows/rollback-qa2.yml \ No newline at end of file + if: ${{ needs.smoke-test.result == 'failure' }} + uses: ./.github/workflows/rollback-qa2.yml + with: + branch: ${{ github.ref_name }} \ No newline at end of file diff --git a/.github/workflows/rollback-qa2.yml b/.github/workflows/rollback-qa2.yml index 2b949682..c6633efc 100644 --- a/.github/workflows/rollback-qa2.yml +++ b/.github/workflows/rollback-qa2.yml @@ -2,10 +2,14 @@ name: Rollback qa2 on: workflow_call: - + inputs: + branch: + required: true + type: string jobs: # Rollback job in case of failure (Revert qa to the previous task definition) rollback: + if: ${{ inputs.branch == qa2 }} permissions: id-token: write contents: read From 77ae2894fe500e01fcd705dbe9d846aa64b5f127 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 10:54:43 -0400 Subject: [PATCH 21/27] fix qa2 reference --- .github/workflows/rollback-qa2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rollback-qa2.yml b/.github/workflows/rollback-qa2.yml index c6633efc..83e6520c 100644 --- a/.github/workflows/rollback-qa2.yml +++ b/.github/workflows/rollback-qa2.yml @@ -9,7 +9,7 @@ on: jobs: # Rollback job in case of failure (Revert qa to the previous task definition) rollback: - if: ${{ inputs.branch == qa2 }} + if: ${{ inputs.branch == 'qa2' }} permissions: id-token: write contents: read From 962f9b4d90a2c21f5d7dc2fab79f1056c3ea6ff6 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 11:11:30 -0400 Subject: [PATCH 22/27] &ai run rollback on failure --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a329f546..f7d4acf2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -41,7 +41,7 @@ jobs: id-token: write contents: read needs: smoke-test - if: ${{ needs.smoke-test.result == 'failure' }} + if: ${{ failure() && needs.smoke-test.result == 'failure' }} uses: ./.github/workflows/rollback-qa2.yml with: branch: ${{ github.ref_name }} \ No newline at end of file From dfaf858060dfb14e9bb3f0a2132bace821a1233f Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 12:43:25 -0400 Subject: [PATCH 23/27] uncomment integration tests --- .../delivery-locations-by-barcode.test.js | 115 +++++++++--------- 1 file changed, 55 insertions(+), 60 deletions(-) diff --git a/test/integration/delivery-locations-by-barcode.test.js b/test/integration/delivery-locations-by-barcode.test.js index c50f1d0b..23245370 100644 --- a/test/integration/delivery-locations-by-barcode.test.js +++ b/test/integration/delivery-locations-by-barcode.test.js @@ -1,69 +1,64 @@ -// const { loadConfig } = require('../../lib/load-config') -// const { expectations, ptypes } = require('./delivery-locations-constants') -// const { makeNyplDataApiClient } = require('../../lib/data-api-client') +const { loadConfig } = require('../../lib/load-config') +const { expectations, ptypes } = require('./delivery-locations-constants') +const { makeNyplDataApiClient } = require('../../lib/data-api-client') -// const checkLocationsForPtype = async (ptype) => { -// const problems = [] -// const match = [] +const checkLocationsForPtype = async (ptype) => { + const problems = [] + const match = [] -// await Promise.all(Object.entries(expectations).map(async ([holdingLocation, expectation], i) => { -// let deliveryLocationsFromApi -// let totalMatch = true -// const registerProblem = (problem) => { -// problems.push({ holdingLocation, barcode: expectation.barcode, deliveryLocationsFromApi, ...problem }) -// totalMatch = false -// } -// try { -// deliveryLocationsFromApi = await getDeliveryLocations(expectation.barcode, ptypes[ptype]) -// } catch (e) { -// registerProblem({ lookUpFailed: true }) -// return -// } + await Promise.all(Object.entries(expectations).map(async ([holdingLocation, expectation], i) => { + let deliveryLocationsFromApi + let totalMatch = true + const registerProblem = (problem) => { + problems.push({ holdingLocation, barcode: expectation.barcode, deliveryLocationsFromApi, ...problem }) + totalMatch = false + } + try { + deliveryLocationsFromApi = await getDeliveryLocations(expectation.barcode, ptypes[ptype]) + } catch (e) { + registerProblem({ lookUpFailed: true }) + return + } -// const checkForValue = (expectedValue, action) => { -// const includedValueIncluded = deliveryLocationsFromApi.some((label) => label.includes(expectedValue)) -// const match = action === 'include' ? includedValueIncluded : !includedValueIncluded -// if (!match) { -// registerProblem({ [`expectedTo${action}`]: expectedValue }) -// } -// } -// expectation[ptype].includes.forEach((expectedValue) => checkForValue(expectedValue, 'include')) -// expectation[ptype].excludes.forEach((expectedValue) => checkForValue(expectedValue, 'exclude')) -// if (totalMatch) match.push({ barcode: expectation.barcode, deliveryLocationsFromApi, expectedToInclude: expectation[ptype].includes, expectedToExclude: expectation[ptype].excludes }) -// })) -// return { match, problems } -// } - -// const getDeliveryLocations = async (barcode, patronId) => { -// try { -// const { itemListElement: itemData } = await makeNyplDataApiClient().get(`request/deliveryLocationsByBarcode?barcodes[]=${barcode}&patronId=${patronId}`) -// // per record -// return itemData[0] -// .deliveryLocation.map(loc => loc.prefLabel.toLowerCase()) -// } catch (e) { -// console.error(e) -// } -// } + const checkForValue = (expectedValue, action) => { + const includedValueIncluded = deliveryLocationsFromApi.some((label) => label.includes(expectedValue)) + const match = action === 'include' ? includedValueIncluded : !includedValueIncluded + if (!match) { + registerProblem({ [`expectedTo${action}`]: expectedValue }) + } + } + expectation[ptype].includes.forEach((expectedValue) => checkForValue(expectedValue, 'include')) + expectation[ptype].excludes.forEach((expectedValue) => checkForValue(expectedValue, 'exclude')) + if (totalMatch) match.push({ barcode: expectation.barcode, deliveryLocationsFromApi, expectedToInclude: expectation[ptype].includes, expectedToExclude: expectation[ptype].excludes }) + })) + return { match, problems } +} -// const theThing = async () => { -// throw new Error('spaghetti') -// await loadConfig() -// const results = await Promise.all(Object.keys(ptypes).map((checkLocationsForPtype))) -// const resultsHaveProblems = Object.keys(ptypes).some((ptype, i) => { -// const resultsForPtype = results[i] -// if (resultsForPtype.problems.length) { -// console.error(`Error with ${ptype} ptype delivery results, `, resultsForPtype.problems) -// return true -// } else { -// console.log(`All delivery location checks for ${ptype} patron type successful`) -// return false -// } -// }) -// if (resultsHaveProblems) throw new Error('Delivery location checks failed.') -// } +const getDeliveryLocations = async (barcode, patronId) => { + try { + const { itemListElement: itemData } = await makeNyplDataApiClient().get(`request/deliveryLocationsByBarcode?barcodes[]=${barcode}&patronId=${patronId}`) + // per record + return itemData[0] + .deliveryLocation.map(loc => loc.prefLabel.toLowerCase()) + } catch (e) { + console.error(e) + } +} const theThing = async () => { - throw new Error('spaghetti') + await loadConfig() + const results = await Promise.all(Object.keys(ptypes).map((checkLocationsForPtype))) + const resultsHaveProblems = Object.keys(ptypes).some((ptype, i) => { + const resultsForPtype = results[i] + if (resultsForPtype.problems.length) { + console.error(`Error with ${ptype} ptype delivery results, `, resultsForPtype.problems) + return true + } else { + console.log(`All delivery location checks for ${ptype} patron type successful`) + return false + } + }) + if (resultsHaveProblems) throw new Error('Delivery location checks failed.') } theThing() From 3f9f1e20f7daf966f6a93d3ff8d00333aea9e186 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 12:45:06 -0400 Subject: [PATCH 24/27] make it for all branches --- .github/workflows/rollback-qa2.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rollback-qa2.yml b/.github/workflows/rollback-qa2.yml index c6633efc..6025a6a3 100644 --- a/.github/workflows/rollback-qa2.yml +++ b/.github/workflows/rollback-qa2.yml @@ -1,4 +1,4 @@ -name: Rollback qa2 +name: Rollback ${{inputs.branch}} on: workflow_call: @@ -9,7 +9,6 @@ on: jobs: # Rollback job in case of failure (Revert qa to the previous task definition) rollback: - if: ${{ inputs.branch == qa2 }} permissions: id-token: write contents: read @@ -40,10 +39,10 @@ jobs: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: discovery-api run: | - docker pull $ECR_REGISTRY/$ECR_REPOSITORY:qa2-previous - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:qa2-previous $ECR_REGISTRY/$ECR_REPOSITORY:qa2-latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:qa2-latest + docker pull $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-previous + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-previous $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-latest + docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-latest - name: Force ECS Update run: | - aws ecs update-service --cluster discovery-api-qa2 --service discovery-api-qa2 --force-new-deployment \ No newline at end of file + aws ecs update-service --cluster discovery-api-${{inputs.branch}} --service discovery-api-${{inputs.branch}} --force-new-deployment \ No newline at end of file From dd201fff1c017ab3796380d9ef11aec253e93485 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 10 Apr 2026 12:47:15 -0400 Subject: [PATCH 25/27] rm addition from qa2 --- lib/resources.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/resources.js b/lib/resources.js index c4d2f516..5c6dd4e9 100644 --- a/lib/resources.js +++ b/lib/resources.js @@ -748,13 +748,6 @@ module.exports = function (app, _private = null) { // - one agg representing the counts for all properties _not_ used in filter // - one agg each for each property that is used in a filter, but counts should exclude that filter - // If the search query consists of only a single filter (or a couple - // filters of same type), just do a normal self-filtering aggregation - // for all properties: - if (!params.q && Object.keys(params.filters).length === 1) { - return [buildElasticAggregationsBody(params, Object.keys(AGGREGATIONS_SPEC))] - } - // Build the standard aggregation: const unfilteredAggregationProps = Object.keys(AGGREGATIONS_SPEC) // Aggregate on all properties that aren't involved in filters: From 254a0ecb3a412b707c8dd23e099b300fe52345b8 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Mon, 13 Apr 2026 10:50:35 -0400 Subject: [PATCH 26/27] rm production from rollback flow --- .github/workflows/deploy.yml | 4 +-- .github/workflows/rollback-qa2.yml | 48 ------------------------------ 2 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 .github/workflows/rollback-qa2.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a329f546..7ce33ae1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -41,7 +41,7 @@ jobs: id-token: write contents: read needs: smoke-test - if: ${{ needs.smoke-test.result == 'failure' }} - uses: ./.github/workflows/rollback-qa2.yml + if: ${{ needs.smoke-test.result == 'failure' && github.ref_name != 'production' }} + uses: ./.github/workflows/rollback.yml with: branch: ${{ github.ref_name }} \ No newline at end of file diff --git a/.github/workflows/rollback-qa2.yml b/.github/workflows/rollback-qa2.yml deleted file mode 100644 index 6025a6a3..00000000 --- a/.github/workflows/rollback-qa2.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Rollback ${{inputs.branch}} - -on: - workflow_call: - inputs: - branch: - required: true - type: string -jobs: - # Rollback job in case of failure (Revert qa to the previous task definition) - rollback: - permissions: - id-token: write - contents: read - name: Rollback to Previous Version - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - cache: npm - - - name: Configure AWS credentials from qa account - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole - aws-region: us-east-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v2 - - - name: Pull and tag previous image - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: discovery-api - run: | - docker pull $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-previous - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-previous $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-latest - - - name: Force ECS Update - run: | - aws ecs update-service --cluster discovery-api-${{inputs.branch}} --service discovery-api-${{inputs.branch}} --force-new-deployment \ No newline at end of file From f8a715ba0afa0c8f941f6c8d63a1f257bff2ecc6 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Mon, 13 Apr 2026 10:59:42 -0400 Subject: [PATCH 27/27] rename rollback yml --- .github/workflows/rollback.yml | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/rollback.yml diff --git a/.github/workflows/rollback.yml b/.github/workflows/rollback.yml new file mode 100644 index 00000000..6025a6a3 --- /dev/null +++ b/.github/workflows/rollback.yml @@ -0,0 +1,48 @@ +name: Rollback ${{inputs.branch}} + +on: + workflow_call: + inputs: + branch: + required: true + type: string +jobs: + # Rollback job in case of failure (Revert qa to the previous task definition) + rollback: + permissions: + id-token: write + contents: read + name: Rollback to Previous Version + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version-file: ".nvmrc" + cache: npm + + - name: Configure AWS credentials from qa account + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole + aws-region: us-east-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Pull and tag previous image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: discovery-api + run: | + docker pull $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-previous + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-previous $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-latest + docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{inputs.branch}}-latest + + - name: Force ECS Update + run: | + aws ecs update-service --cluster discovery-api-${{inputs.branch}} --service discovery-api-${{inputs.branch}} --force-new-deployment \ No newline at end of file