Skip to content

feat: Add --wait-db-ms for --exec - #153

Merged
rufuspollock merged 6 commits into
flowershow:mainfrom
knu:feat/exec-wait-db-ms
May 20, 2026
Merged

feat: Add --wait-db-ms for --exec#153
rufuspollock merged 6 commits into
flowershow:mainfrom
knu:feat/exec-wait-db-ms

Conversation

@knu

@knu knu commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

When running mddb --watch in the background, the database may be in the middle of an update when you execute a query. This can lead to unexpected or incomplete results. The new --wait-db-ms option allows you to wait for the database to settle (i.e., wait until no writes have occurred for the specified duration) before executing the query, ensuring consistent results.

@changeset-bot

changeset-bot Bot commented Feb 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3fbedaf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@knu

knu commented Feb 2, 2026

Copy link
Copy Markdown
Contributor Author

Test is failing. Node 16 may be too old; can we require Node 20 or better?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new CLI option to make mddb --exec safer to run alongside a background mddb --watch process by waiting for the SQLite DB file to become “idle” before executing a script.

Changes:

  • Adds --wait-db-ms <ms> parsing to the CLI --exec path and waits until markdown.db has been unchanged for the specified duration.
  • Documents the new option in the README with usage examples.
  • Adds a CLI integration test covering the new waiting behavior.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/bin/index.js Adds --wait-db-ms argument parsing and an async “wait until db file is stable” loop before running exec scripts.
src/tests/cli.spec.ts Adds an integration test intended to verify the new wait behavior for --exec.
README.md Documents --wait-db-ms under the --exec section with an example invocation.

Comment thread src/tests/cli.spec.ts Outdated
Comment on lines +125 to +139
const start = Date.now();
const result = spawnSync(
process.execPath,
[cliPath, "--exec", "--wait-db-ms", "200", tmpScript, sampleDir],
{
encoding: "utf8",
cwd: tmpDir,
}
);
const duration = Date.now() - start;

expect(result.status).toBe(0);
expect(result.stdout.trim()).toBe("ok");
expect(duration).toBeGreaterThanOrEqual(150);
} finally {

Copilot AI Feb 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new duration assertion can pass even if --wait-db-ms is not actually waiting, since spawnSync + Node startup overhead may exceed 150ms on slower machines/CI. Consider making the test more deterministic (e.g., use a larger wait like 400–500ms and assert close to that value, or otherwise assert on observable behavior that only occurs after the wait).

Copilot uses AI. Check for mistakes.
@rufuspollock

Copy link
Copy Markdown
Contributor

@knu you are right - let's get to node 20. implementing that now. do you want to check again once that is merged?

@rufuspollock

Copy link
Copy Markdown
Contributor

@knu we now have node 20. any updates?

@knu
knu force-pushed the feat/exec-wait-db-ms branch from 3fbedaf to 90cc30d Compare April 28, 2026 10:58
@knu

knu commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

@rufuspollock Thanks! Rebased onto main (now on Node 20). All tests pass locally with the latest base.

@copilot Fixed in 90cc30d: the test now compares the waited run against a baseline run (no --wait-db-ms) and asserts the delta is >= waitMs - 100, which factors out spawn/startup overhead.

@knu
knu force-pushed the feat/exec-wait-db-ms branch 2 times, most recently from c0e1680 to 1cbd3c3 Compare April 28, 2026 11:57
@knu

knu commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

I'm fixing existing problems...

@knu

knu commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

@rufuspollock Done! I have no idea what's going on with Node 16 & 18 builds, nor whether they still matter.

@knu knu closed this Apr 28, 2026
@knu

knu commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

@rufuspollock Done! I have no idea what's going on with Node 16 & 18 builds, nor whether they still matter.

@knu knu reopened this Apr 28, 2026
knu added 6 commits May 20, 2026 19:19
Add --wait-db-ms for --exec to wait until markdown.db has been idle
for the specified duration before running.
Per PR review, comparing the waited run to a baseline run (without
--wait-db-ms) makes the assertion robust to spawn/startup overhead
that could otherwise let the previous threshold pass without the
wait actually elapsing.
@rufuspollock
rufuspollock force-pushed the feat/exec-wait-db-ms branch from 9c7e056 to 5f457df Compare May 20, 2026 17:19
@rufuspollock rufuspollock changed the title Add --wait-db-ms for --exec feat: Add --wait-db-ms for --exec May 20, 2026
@rufuspollock
rufuspollock merged commit 279c2ff into flowershow:main May 20, 2026
2 checks passed
@knu
knu deleted the feat/exec-wait-db-ms branch May 20, 2026 17:56
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.

3 participants