Repository navigation
fix(test): run every test against <db>_test, never the configured database - #190
Merged
Merged
Conversation
…abase npm test used whatever database config/local.js names. In a dev or production checkout that is the real database. Its after() then deleted AuditLog rows by name prefix, which could remove real audit rows. Every test record (hosts, users, the agent root Setting) also landed there. test:ui did the same through its server child. - tools/lib/test-db.js resolves the test database from the config: the configured name plus _test, always appended. It handles a url, a url with a top-level database, and the installer's host/port/database shape, and adds authSource when the url has credentials. It drops only a name that ends in _test and differs from the configured name. - test/lifecycle.test.js and tools/smoke/ui.js (test:ui and test:ui:prod) lift on that database. config/bootstrap.js refuses a lift on any other database before its index writes, and the suite and ui.js check the database the models really use before any test or browser action. - test:install drops fog_install_smoke_test (was fog_install_smoke), and never the configured database. - The prefix-based audit cleanup is gone: nothing in a _test database is real. tools/lib/database.js datastoreUrl is the one installer-shape URL builder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
npm testlifted against whatever databaseconfig/local.jsnames. In a dev or production checkout, that is the real database. Itsafter()hook then deletedAuditLogrows by name prefix (mocha,mc,mpa,mph), so a real host such asmcafee-01could lose its audit rows. Every test record (hosts, users, the agent root Setting) also landed in the real database.test:uiandtest:ui:proddid the same through their server child.The fix
Every test run now uses a separate database, as is standard practice for test suites.
tools/lib/test-db.jsresolves the test database as the configured name plus_test, always appended (fog_testbecomesfog_test_test). It handles:url;urlwith a top-leveldatabase(sails-mongo prefers the top-level key);It adds
authSource=<configured db>when the URL carries credentials. It drops only a name that ends in_testand differs from the configured name. No error or log line prints a URL.Three guards, before any write:
config/bootstrap.jsrefuses a lift on any database other thancustom.testDatabase, before its index writes. It is inert when that key is unset, as it always is in production.test/lifecycle.test.jschecks the database the models really use, straight after the lift.tools/smoke/ui.jschecks the child server's database before the browser starts.test:installnow dropsfog_install_smoke_test, never the configured database.Cleanup: the prefix-based audit cleanup is gone, because nothing in a
_testdatabase is real.datastoreUrlintools/lib/database.jsis now the one installer-shape URL builder (it no longer emitsuser:@or:undefined). ADR 0003 is updated.Test
npm test: 432 passing.test:ui,test:ui:prodandtest:install: green._testsuffix rule,authSource, anddatastoreUrl.🤖 Generated with Claude Code