Repository navigation
test: explicit test data instead of migration seed rows - #78
Merged
Merged
Conversation
The shell-bookmark tests added a bookmark but read back id 1, which is the Google row seeded by the first migration. They never exercised the shell bookmark and still passed. Read the bookmark by the id the repository assigned, and assert it is the one added. Use a TempDir-backed file DB instead of :memory:, where each pooled connection could open a separate database.
The first migration inserted 14 sample rows that every test DB inherited implicitly. Remove the INSERT so tests start empty, and let each test declare the rows it needs. 18 tests failed without the rows and now add their own data. 12 more passed vacuously on an empty DB (assertions only inside loops over results, or <=/>= comparisons); they now assert exact, non-empty result sets. Each rewritten test was verified to fail when the code path it covers is broken. Drop the empty_bookmark_table() calls in tests that directly followed setup_test_db(); a fresh DB is empty now. Existing databases are unaffected: Diesel does not re-run applied migrations, and create-db already emptied the table.
main.rs routes the create-db command to handle_create_db_command before any CLI dispatch, and cli::execute_command returns an error for CreateDb. The copy in bookmark_commands.rs had no callers.
create-db emptied the bookmarks table after migrating, only to remove the sample rows the first migration used to insert. Those rows are gone, so drop the call and the now unused empty_bookmark_table(). Replace the ignored create-db stub in test_main with two guard tests: create-db yields an empty database, and create-db --pre-fill yields exactly the demo entries.
…ipts seed.sh built both datasets with dozens of `bkmr add` calls, and the hsearch rows took their descriptions from live web pages, so the data depended on the network and drifted over time. Move both datasets to bkmr/tests/resources/datasets/*.json and load them with `bkmr load-json`. Each entry keeps a group/why field that documents its purpose; the importer ignores unknown fields. The hsearch descriptions are the ones previously fetched, frozen. load-json drops unknown system-style tags, so the hsearch tag `_procedure_` becomes the plain tag `procedure`. verify.sh now expects exactly 4 matches for the tag filter and exactly 2 for the limit check, so an empty result can no longer pass. A new stdio test loads the lsp dataset and asserts the completion table documented in TESTING.md.
Add a "Test data" section to TESTING.md: every test starts from an empty database, declares its rows, uses returned ids, and asserts exact result sets. Describe the JSON datasets shared by seed.sh and tests/lsp, and note that the LSP completion table is now asserted by make test. Follow the hsearch tag rename (_procedure_ -> procedure) and correct two statements that were already wrong: group E entries are embedded, and in TC-01 the verbatim shell entry ranks first. CONTRIBUTING.md links the rule from its testing checklist.
The show test ran `bkmr show 1,2` against whatever the shared test DB contained and only checked the exit code. show exits 0 even for missing ids, so the test could not fail. Seed a temp DB with three bookmarks, show two of them, and assert that exactly those appear in the JSON and detailed output.
sysid
force-pushed
the
test/explicit-test-data
branch
from
September 30, 2026 14:46
85c2294 to
1dc3cdc
Compare
Under GNU make >= 3.82 .ONESHELL runs a recipe in one shell, so without set -e only the last line's status counted in the test target. The search regression check grepped for "bookmarks", which also matched "Found 0 bookmarks"; assert the piped id list instead.
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.
Why
The first migration inserted 14 sample rows (incl. local
/Users/...paths) that every test DB inherited implicitly. Tests depended on them without saying so —get_bookmark(1)was Google — andcreate-dbdeleted them again right after migrating. One test (action_serviceshell bookmark) never exercised the bookmark it added and passed anyway.What
INSERT. Existing databases are unaffected (Diesel does not re-run applied migrations;create-dbalready emptied the table).for b in &resultsor<=/>=); they now assert exact, non-empty result sets.empty_bookmark_table()workaround increate-db, the method itself, and an unreachable duplicatecreate_dbincli/bookmark_commands.rs.lspandhsearchmove frombkmr addcalls inseed.shtobkmr/tests/resources/datasets/*.json, loaded viabkmr load-json— one source for cargo tests, scenario scripts and manual editor testing. hsearch descriptions are frozen, so scenarios no longer depend on live web pages.create-dbguards (empty DB;--pre-fillyields exactly the demo entries), the documented LSP completion table asserted over stdio, and theshowtest now checks displayed entries instead of only the exit code.TESTING.md; one line inCONTRIBUTING.md.Behaviour notes
load-jsondrops unknown system-style tags, so the hsearch tag_procedure_is now the plain tagprocedure(dataset,verify.sh,TESTING.md). Rank-based TC expectations (TC-02/03/04/14) re-checked: unchanged.verify.shtag-filter and limit checks now require exact counts, so an empty result can no longer pass.TESTING.mdcorrections of pre-existing inaccuracies: hsearch group E is embedded; TC-01 ranks the verbatim shell entry first.Verification
make test-scenariosOut of scope (possible follow-ups)
bkmr hsearch --jsonprints nothing instead of[]on an empty result.bkmr addkeeps unknown_x_tags whileload-jsondrops them.