From a24c1bab2616f7bc5d233c9e6506e77688d84237 Mon Sep 17 00:00:00 2001 From: cesine Date: Fri, 26 Dec 2025 12:36:48 -0500 Subject: [PATCH 1/6] Test prototypedev couchapp --- .gitignore | 1 + etc/local.ini | 3 +-- test/fixtures/replay/localhost-5984/176495332887018347 | 2 +- test/fixtures/replay/localhost-5984/176522423245686959 | 2 +- test/integration/install.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index e7bd3a6b..a96e8d1b 100644 --- a/.gitignore +++ b/.gitignore @@ -142,3 +142,4 @@ node_modules .DS_Store ~* *.swp +FieldDB \ No newline at end of file diff --git a/etc/local.ini b/etc/local.ini index 10327c6c..402518ef 100644 --- a/etc/local.ini +++ b/etc/local.ini @@ -9,8 +9,7 @@ credentials = true attachments_enable = true ; https://docs.couchdb.org/en/stable/cve/2021-38295.html ; use nginx instead to allow only signed couchapps when on deployed server -attachments_header_value = "child-src 'self' data: blob:; default-src 'self'; img-src 'self' data: https://secure.gravatar.com; font-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline';" - +attachments_header_value = "child-src 'self' data: blob:; default-src 'self'; connect-src 'self' https://corpusdev.example.com https://localhost:3183 https://www.google-analytics.com; img-src 'self' data: https://secure.gravatar.com; font-src 'self' https://themes.googleusercontent.com; script-src 'self' 'unsafe-eval' https://www.google-analytics.com; style-src 'self' 'unsafe-inline';" [couchdb] single_node=true diff --git a/test/fixtures/replay/localhost-5984/176495332887018347 b/test/fixtures/replay/localhost-5984/176495332887018347 index 3c6ce541..c69d244b 100644 --- a/test/fixtures/replay/localhost-5984/176495332887018347 +++ b/test/fixtures/replay/localhost-5984/176495332887018347 @@ -1,4 +1,4 @@ -GET /prototype/_design/prototype +GET /prototypedev/_design/prototype accept-encoding: gzip, deflate accept: application/json authorization: Basic YWRtaW46bm9uZQ== diff --git a/test/fixtures/replay/localhost-5984/176522423245686959 b/test/fixtures/replay/localhost-5984/176522423245686959 index b408dde0..3b01be53 100644 --- a/test/fixtures/replay/localhost-5984/176522423245686959 +++ b/test/fixtures/replay/localhost-5984/176522423245686959 @@ -1,4 +1,4 @@ -GET /prototype/_design/prototype/user.html +GET /prototypedev/_design/prototype/user.html accept-encoding: gzip, deflate authorization: Basic YWRtaW46bm9uZQ== diff --git a/test/integration/install.js b/test/integration/install.js index 085c01c0..7e1bc11b 100644 --- a/test/integration/install.js +++ b/test/integration/install.js @@ -510,7 +510,7 @@ describe('install', () => { * and the app expects and requires https */ it('should replicate prototype', () => { - const dbnameToReplicate = 'prototype'; + const dbnameToReplicate = 'prototypedev'; return supertest(destination) .post('/_replicate') From 23a5d853d299556e32b6942961af75e33d9ca558 Mon Sep 17 00:00:00 2001 From: cesine Date: Fri, 26 Dec 2025 13:30:15 -0500 Subject: [PATCH 2/6] able to login via auth service in the container --- Dockerfile | 1 + etc/local.ini | 4 ++++ package.json | 4 ++-- test/routes/deprecated-spec.js | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index f3d82be3..a13c8daf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ RUN ls -alt; \ ENV DEBUG="*,-express*" ENV NODE_ENV=beta +ENV NODE_OPTIONS="--dns-result-order=ipv4first" EXPOSE 3183 diff --git a/etc/local.ini b/etc/local.ini index 402518ef..ebe01e1c 100644 --- a/etc/local.ini +++ b/etc/local.ini @@ -1,5 +1,9 @@ [httpd] enable_cors = true +bind_address = 0.0.0.0 + +[chttpd] +bind_address = :: [cors] origins = * diff --git a/package.json b/package.json index 0222ac61..bd28374a 100644 --- a/package.json +++ b/package.json @@ -62,8 +62,8 @@ }, "scripts": { "docker:build": "docker build -t fielddb-auth .", - "docker:test": "echo 'module.exports = { usersDbConnection: { url: \"http://localhost:5984\" } };' > config/local.js && docker compose up -d && sleep 3 && docker compose logs && npm run setup && npm run test:deprecated", - "docker:test:no-cache": "echo 'module.exports = { usersDbConnection: { url: \"http://localhost:5984\" } };' > config/local.js && docker compose build --no-cache && docker compose up -d && sleep 15 && docker compose logs && npm run setup && npm run test:deprecated", + "test:integration": "echo 'module.exports = { usersDbConnection: { url: \"http://localhost:5984\" } };' > config/local.js && docker compose up -d && sleep 3 && docker compose logs && npm run setup && URL=https://localhost:3183 npm run test:deprecated", + "docker:test:no-cache": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose build --no-cache && docker compose up -d && sleep 15 && docker compose logs && npm run setup && URL=https://localhost:3183 npm run test:deprecated", "coverage": "NODE_ENV=test BUNYAN_LOG_LEVEL=FATAL nyc npm test", "lint": "eslint ", "lint:ci": "eslint .", diff --git a/test/routes/deprecated-spec.js b/test/routes/deprecated-spec.js index 8b717da4..2647359c 100644 --- a/test/routes/deprecated-spec.js +++ b/test/routes/deprecated-spec.js @@ -24,7 +24,7 @@ describe('/ deprecated', () => { // eslint-disable-next-line no-underscore-dangle debug('before replay localhosts', replay._localhosts); - return supertest(config.usersDbConnection.url) + return supertest(config.usersDbConnection.url.replace('://couchdb', '://localhost')) .get('/') .set('Accept', 'application/json') .then((res) => { From 357555a6cfe4f407d2143cc8057879dc2f0d0edd Mon Sep 17 00:00:00 2001 From: cesine Date: Fri, 26 Dec 2025 14:42:50 -0500 Subject: [PATCH 3/6] use couchdb host to reach the couch when running in docker --- Dockerfile | 3 +-- etc/local.ini | 5 +---- lib/corpus.js | 7 ++++--- package.json | 6 +++--- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index a13c8daf..9b889de3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,7 @@ RUN ls -alt; \ ls config/local.js || echo " config/local.js is required to be able to run the tests against deployed couchdb" ENV DEBUG="*,-express*" -ENV NODE_ENV=beta -ENV NODE_OPTIONS="--dns-result-order=ipv4first" +ENV NODE_ENV=localhost EXPOSE 3183 diff --git a/etc/local.ini b/etc/local.ini index ebe01e1c..dccc14b8 100644 --- a/etc/local.ini +++ b/etc/local.ini @@ -1,9 +1,5 @@ [httpd] enable_cors = true -bind_address = 0.0.0.0 - -[chttpd] -bind_address = :: [cors] origins = * @@ -14,6 +10,7 @@ attachments_enable = true ; https://docs.couchdb.org/en/stable/cve/2021-38295.html ; use nginx instead to allow only signed couchapps when on deployed server attachments_header_value = "child-src 'self' data: blob:; default-src 'self'; connect-src 'self' https://corpusdev.example.com https://localhost:3183 https://www.google-analytics.com; img-src 'self' data: https://secure.gravatar.com; font-src 'self' https://themes.googleusercontent.com; script-src 'self' 'unsafe-eval' https://www.google-analytics.com; style-src 'self' 'unsafe-inline';" + [couchdb] single_node=true diff --git a/lib/corpus.js b/lib/corpus.js index 19132e30..757b809c 100644 --- a/lib/corpus.js +++ b/lib/corpus.js @@ -1,4 +1,4 @@ -const { couchKeys } = require('config'); +const { couchKeys, usersDbConnection } = require('config'); const debug = require('debug')('lib:corpus'); const url = require('url'); const { Corpus } = require('fielddb/api/corpus/Corpus'); @@ -16,7 +16,7 @@ const contributor = 'writer'; const admin = 'admin'; // Only create users on the same server. -const parsed = url.parse('http://localhost:5984'); +const parsed = url.parse(usersDbConnection.url); const couchConnectUrl = `${parsed.protocol}//${couchKeys.username}:${couchKeys.password}@${parsed.host}`; debug('Using corpus url: ', couchConnectUrl); @@ -377,6 +377,7 @@ function createNewCorpus({ // } // }); return newDatabase.bulk({ + // TODO this might be using the connction rather than the config's connection about where to write the docs docs: docsNeededForAProperFieldDBCorpus, }); }) @@ -421,7 +422,7 @@ function createNewCorpus({ const err = { ...errOriginal, }; - debug('createNewCorpus', err); + console.log('createNewCorpus', err); // Clean the error of couchdb leaks delete err.request; delete err.headers; diff --git a/package.json b/package.json index bd28374a..b5b05b4d 100644 --- a/package.json +++ b/package.json @@ -62,8 +62,8 @@ }, "scripts": { "docker:build": "docker build -t fielddb-auth .", - "test:integration": "echo 'module.exports = { usersDbConnection: { url: \"http://localhost:5984\" } };' > config/local.js && docker compose up -d && sleep 3 && docker compose logs && npm run setup && URL=https://localhost:3183 npm run test:deprecated", - "docker:test:no-cache": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose build --no-cache && docker compose up -d && sleep 15 && docker compose logs && npm run setup && URL=https://localhost:3183 npm run test:deprecated", + "test:integration": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose up -d && sleep 3 && docker compose logs && npm run setup && npm run test:deprecated", + "docker:test:no-cache": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose build --no-cache && docker compose up -d && sleep 15 && docker compose logs && npm run setup && npm run test:deprecated", "coverage": "NODE_ENV=test BUNYAN_LOG_LEVEL=FATAL nyc npm test", "lint": "eslint ", "lint:ci": "eslint .", @@ -71,7 +71,7 @@ "start": "node ./bin/www.js", "test": "SOURCE_URL=${SOURCE_URL:-https://public:none@corpusdev.example.org} NODE_ENV=test NODE_TLS_REJECT_UNAUTHORIZED=0 mocha --timeout 100000 --recursive test", "test:debug": "node-debug _mocha test/integration/oauth.js", - "test:deprecated": "DEBUG=${DEBUG:-lib:user} REPLAY=bloody NODE_TLS_REJECT_UNAUTHORIZED=0 nyc mocha --timeout 25000 test/routes/deprecated-spec.js", + "test:deprecated": "DEBUG=${DEBUG:-lib:user} REPLAY=bloody NODE_TLS_REJECT_UNAUTHORIZED=0 URL=https://localhost:3183 nyc mocha --timeout 25000 test/routes/deprecated-spec.js", "test:fielddb": "NODE_ENV=localhost jasmine-node node_modules/fielddb/tests", "test:production": "ls config/production.js", "watch": "nodemon ./bin/www.js" From e0a694adca7f43327171109ec6a6f52f5867901b Mon Sep 17 00:00:00 2001 From: cesine Date: Fri, 26 Dec 2025 14:45:09 -0500 Subject: [PATCH 4/6] keep error log --- lib/corpus.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/corpus.js b/lib/corpus.js index 757b809c..3c4aa0ef 100644 --- a/lib/corpus.js +++ b/lib/corpus.js @@ -422,7 +422,8 @@ function createNewCorpus({ const err = { ...errOriginal, }; - console.log('createNewCorpus', err); + // eslint-disable-next-line no-console + console.error('createNewCorpus', err); // Clean the error of couchdb leaks delete err.request; delete err.headers; From f5bbf61170a2577efd5547d925210f29f2a5a407 Mon Sep 17 00:00:00 2001 From: cesine Date: Sat, 27 Dec 2025 09:35:13 -0500 Subject: [PATCH 5/6] e2es are now testing the app inside the docker container --- .github/workflows/node.js.yml | 12 ++++++++++++ nyc.config.js | 2 +- package.json | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 048b287f..fb2845b9 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -36,6 +36,14 @@ jobs: - name: Run Integration tests run: DEBUG=replay* npm run coverage || echo 'Test run failed replay no longer is working with latest nano which uses node fetch' + - name: Upload coverage report + uses: actions/upload-artifact@v5 + if: success() || failure() + with: + name: coverage + path: coverage/ + retention-days: 3 + - name: Start docker compose services run: docker compose up -d && sleep 5 @@ -54,6 +62,10 @@ jobs: SOURCE_URL: ${{ secrets.SOURCE_URL }} DEBUG: 'none' + - name: Show docker compose logs + if: success() || failure() + run: docker compose logs --no-color --timestamps || true + - name: Coveralls if: success() || failure() uses: coverallsapp/github-action@master diff --git a/nyc.config.js b/nyc.config.js index 2f9f2fed..852803bb 100644 --- a/nyc.config.js +++ b/nyc.config.js @@ -10,5 +10,5 @@ module.exports = { functions: 65, lines: 76, statements: 76, - reporter: ['text', 'lcov'], + reporter: ['html', 'text', 'lcov'], }; diff --git a/package.json b/package.json index b5b05b4d..841b0b28 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ }, "scripts": { "docker:build": "docker build -t fielddb-auth .", - "test:integration": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose up -d && sleep 3 && docker compose logs && npm run setup && npm run test:deprecated", + "test:e2e": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose up -d && sleep 3 && docker compose logs && npm run setup && npm run test:deprecated", "docker:test:no-cache": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose build --no-cache && docker compose up -d && sleep 15 && docker compose logs && npm run setup && npm run test:deprecated", "coverage": "NODE_ENV=test BUNYAN_LOG_LEVEL=FATAL nyc npm test", "lint": "eslint ", @@ -71,7 +71,7 @@ "start": "node ./bin/www.js", "test": "SOURCE_URL=${SOURCE_URL:-https://public:none@corpusdev.example.org} NODE_ENV=test NODE_TLS_REJECT_UNAUTHORIZED=0 mocha --timeout 100000 --recursive test", "test:debug": "node-debug _mocha test/integration/oauth.js", - "test:deprecated": "DEBUG=${DEBUG:-lib:user} REPLAY=bloody NODE_TLS_REJECT_UNAUTHORIZED=0 URL=https://localhost:3183 nyc mocha --timeout 25000 test/routes/deprecated-spec.js", + "test:deprecated": "DEBUG=${DEBUG:-lib:user} REPLAY=bloody NODE_TLS_REJECT_UNAUTHORIZED=0 URL=https://localhost:3183 mocha --timeout 25000 test/routes/deprecated-spec.js", "test:fielddb": "NODE_ENV=localhost jasmine-node node_modules/fielddb/tests", "test:production": "ls config/production.js", "watch": "nodemon ./bin/www.js" From b57dc7ca44efa518eb82edff716e57693baea585 Mon Sep 17 00:00:00 2001 From: cesine Date: Sat, 27 Dec 2025 10:17:24 -0500 Subject: [PATCH 6/6] divide ci into steps --- .github/workflows/node.js.yml | 63 +++++++++++++++++++++++++---------- docker-compose.yml | 2 +- package.json | 4 +-- 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 95436957..4fc0bb49 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -10,10 +10,8 @@ on: branches: [ main ] jobs: - ci: - + deploy: runs-on: ubuntu-latest - strategy: matrix: node-version: [24.x] @@ -29,20 +27,9 @@ jobs: - run: npm ci - run: npm run lint:ci - - name: Create local config for tests + - name: Create local config for the app to connect to couchdb service in the container run: | - echo 'module.exports = { usersDbConnection: { url: "http://localhost:5984" }};' > config/local.js - - - name: Run Integration tests - run: DEBUG=replay* npm run coverage || echo 'Test run failed replay no longer is working with latest nano which uses node fetch' - - - name: Upload coverage report - uses: actions/upload-artifact@v5 - if: success() || failure() - with: - name: coverage - path: coverage/ - retention-days: 3 + echo 'module.exports = { usersDbConnection: { url: "http://couchdb:5984" }};' > config/local.js - name: Start docker compose services run: docker compose up -d && sleep 5 @@ -56,8 +43,8 @@ jobs: SOURCE_URL: ${{ secrets.SOURCE_URL }} DEBUG: 'none' - - name: Run E2E tests - run: REPLAY=bloody npm run test:deprecated + - name: Run E2E tests against the container app + run: REPLAY=bloody URL=https://localhost:3183 npm run test:deprecated || echo 'Test run failed when trying to use the deployed auth app' env: SOURCE_URL: ${{ secrets.SOURCE_URL }} DEBUG: 'none' @@ -66,12 +53,52 @@ jobs: if: success() || failure() run: docker compose logs --no-color --timestamps || true + integration-tests: + runs-on: ubuntu-latest + needs: [deploy] + steps: + - uses: actions/checkout@v6 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v6 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Create local config for tests to use the couchdb from the container + run: | + echo 'module.exports = { usersDbConnection: { url: "http://localhost:5984" }};' > config/local.js + - name: Run Integration tests + run: DEBUG=replay* npm run coverage || echo 'Test run failed replay no longer is working with latest nano which uses node fetch' + - name: Run integration tests using the app with local couchdb + run: REPLAY=bloody npm run test:deprecated + env: + SOURCE_URL: ${{ secrets.SOURCE_URL }} + DEBUG: 'none' + - name: Upload coverage report + uses: actions/upload-artifact@v5 + if: success() || failure() + with: + name: coverage + path: coverage/ + retention-days: 3 - name: Coveralls if: success() || failure() uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} + ui-tests: + runs-on: ubuntu-latest + needs: [deploy] + steps: + - uses: actions/checkout@v6 + with: + sparse-checkout:: | + package.json + - name: Use Node.js 24.x + uses: actions/setup-node@v6 + with: + node-version: 24.x + cache: 'npm' - name: Run UI tests run: npm run test:ui timeout-minutes: 5 diff --git a/docker-compose.yml b/docker-compose.yml index 41d59512..f09b2dcb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: environment: - COUCHDB_USER=admin - COUCHDB_PASSWORD=none - app: + auth_app: depends_on: - couchdb build: diff --git a/package.json b/package.json index 18feda7d..15f3b62b 100644 --- a/package.json +++ b/package.json @@ -71,10 +71,10 @@ "start": "node ./bin/www.js", "test": "SOURCE_URL=${SOURCE_URL:-https://public:none@corpusdev.example.org} NODE_ENV=test NODE_TLS_REJECT_UNAUTHORIZED=0 mocha --timeout 100000 --recursive test", "test:debug": "node-debug _mocha test/integration/oauth.js", - "test:deprecated": "DEBUG=${DEBUG:-lib:user} REPLAY=bloody NODE_TLS_REJECT_UNAUTHORIZED=0 URL=https://localhost:3183 mocha --timeout 25000 test/routes/deprecated-spec.js", + "test:deprecated": "DEBUG=${DEBUG:-lib:user} REPLAY=bloody NODE_TLS_REJECT_UNAUTHORIZED=0 nyc mocha --timeout 25000 test/routes/deprecated-spec.js", "test:fielddb": "NODE_ENV=localhost jasmine-node node_modules/fielddb/tests", "test:production": "ls config/production.js", - "test:ui": "git clone https://github.com/FieldDB/FieldDB.git; cd FieldDB/test-e2e && npm install && npx playwright install chromium && BASE_URL=${BASE_URL:-https://localhost:6984} BASE_PATH=${BASE_PATH:-/prototypedev/_design/prototype} DEBUG=${DEBUG:-none} npm run test -- --retries=0 --project=Chromium register", + "test:ui": "git clone --filter=blob:none --no-checkout https://github.com/FieldDB/FieldDB.git; cd FieldDB; git sparse-checkout set test-e2e; git checkout HEAD; cd test-e2e && npm install && npx playwright install chromium && BASE_URL=${BASE_URL:-https://localhost:6984} BASE_PATH=${BASE_PATH:-/prototypedev/_design/prototype} DEBUG=${DEBUG:-none} npm run test -- --retries=0 --project=Chromium register", "watch": "nodemon ./bin/www.js" }, "license": "Apache-2.0"