Skip to content

fix(#840): do not apply the --local COUCH_URL check to --archive mode - #841

Open
dylanpulver wants to merge 1 commit into
medic:mainfrom
dylanpulver:fix/archive-mode-ignores-couch-url
Open

dylanpulver wants to merge 1 commit into
medic:mainfrom
dylanpulver:fix/archive-mode-ignores-couch-url

Conversation

@dylanpulver

@dylanpulver dylanpulver commented Sep 1, 2026 •

Copy link
Copy Markdown

Description

Fixes #840. --archive fails when COUCH_URL points at a remote server, with ERROR --local was specified but COUCH_URL env var is set to '<host>' — and --local was not specified.

getApiUrl handled both modes in one branch, so the localhost assertion written for --local also fired for --archive. That was accidental: the assertion arrived with --local in 5b8f893, and f1ab876 (#397) later widened the condition to cmdArgs.local || cmdArgs.archive to give archive mode a placeholder URL, taking the assertion with it. Archive mode never connects to a database — db.js returns ArchivingDB, api.js returns archivingApi — so it now takes the default local placeholder and ignores COUCH_URL. Same principle as #434/#437.

The smaller alternative — keep parsing COUCH_URL, only throw when cmdArgs.local — leaves a remote URL in environment.instanceUrl, which makes environment.isProduction() true in archive mode, so check-git and the production-instance warning in main.js would start prompting for input. Archive mode mostly runs unattended, so that trades an error for a hang. Happy to switch if you prefer it.

Blast radius measured, not assumed: with COUCH_URL unset or set to localhost, the archive output is byte-identical before and after (diff -r on the destination, both cases). Only the unused credentials in the placeholder differ — host, port and path are the same, so warn-upload-overwrite's environment key and hash filename are unchanged. --local still errors on a remote COUCH_URL.

get-api-url.spec.js had no --archive block at all, and the one test covering the throwing branch passes { local: true }, so it could not see this. The three new tests assert the returned URL rather than just "does not throw", which is what separates this fix from the alternative above. 886 → 889 passing locally, eslint clean.

AI Disclosure: prepared with Claude Code — it found the bug and wrote the fix and the tests.

Code review items

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or integration tests where appropriate
  • Backwards compatible: Works with existing data and configuration. Any breaking changes documented in the release notes.

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

--archive never connects to a database (ArchivingDB and archiving-api
replace both), but getApiUrl handled it in the same branch as --local, so
the localhost assertion written for --local also fired for --archive. Any
COUCH_URL pointing at a remote server made --archive fail with an error
that says --local was specified when it was not.

Archive mode now takes the default local placeholder URL and ignores
COUCH_URL. The resulting apiUrl host, port and path are unchanged for the
cases that work today, so the archive output is byte-identical.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--archive fails when COUCH_URL targets a remote server

1 participant