Skip to content

fix: emit kv storage events from concrete implementations#481

Merged
sroussey merged 2 commits into
mainfrom
claude/fix-kv-storage-events-Zlx2s
May 11, 2026
Merged

fix: emit kv storage events from concrete implementations#481
sroussey merged 2 commits into
mainfrom
claude/fix-kv-storage-events-Zlx2s

Conversation

@sroussey
Copy link
Copy Markdown
Collaborator

KvStorage defined put/get/getAll/delete/deleteall events and exposed
on/off/emit plumbing, but neither KvViaTabularStorage nor FsFolderKvStorage
ever emitted them, so listeners never fired. Wire up the emits in both
implementations, make FsFolderKvStorage.deleteAll idempotent so repeated
calls don't throw, and add a generic test that verifies events fire across
all KV backends.

KvStorage defined put/get/getAll/delete/deleteall events and exposed
on/off/emit plumbing, but neither KvViaTabularStorage nor FsFolderKvStorage
ever emitted them, so listeners never fired. Wire up the emits in both
implementations, make FsFolderKvStorage.deleteAll idempotent so repeated
calls don't throw, and add a generic test that verifies events fire across
all KV backends.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 11, 2026

Open in StackBlitz

@workglow/cli

npm i https://pkg.pr.new/@workglow/cli@481

@workglow/ai

npm i https://pkg.pr.new/@workglow/ai@481

@workglow/job-queue

npm i https://pkg.pr.new/@workglow/job-queue@481

@workglow/knowledge-base

npm i https://pkg.pr.new/@workglow/knowledge-base@481

@workglow/storage

npm i https://pkg.pr.new/@workglow/storage@481

@workglow/task-graph

npm i https://pkg.pr.new/@workglow/task-graph@481

@workglow/tasks

npm i https://pkg.pr.new/@workglow/tasks@481

@workglow/util

npm i https://pkg.pr.new/@workglow/util@481

workglow

npm i https://pkg.pr.new/workglow@481

commit: ebc9787

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR ensures IKvStorage event listeners actually fire by emitting KV operation events from concrete storage implementations, and adds a backend-agnostic test to prevent regressions.

Changes:

  • Emit put/get/getAll/delete/deleteall events from KvViaTabularStorage operations (including per-item emission for putBulk).
  • Emit put/get/delete/deleteall events from FsFolderKvStorage, and make deleteAll() idempotent via rm(..., { force: true }).
  • Add generic KV tests asserting events fire (including putBulk emitting per item).

Reviewed changes

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

File Description
packages/test/src/test/storage-kv/genericKvRepositoryTests.ts Adds generic event-emission assertions for KV backends.
packages/storage/src/kv/KvViaTabularStorage.ts Wires KV event emissions into the tabular-backed KV implementation.
packages/storage/src/kv/FsFolderKvStorage.ts Wires KV event emissions into the filesystem-backed KV implementation; makes deleteAll() idempotent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +68 to +94
it("should emit put, get, delete and deleteall events", async () => {
const putFn = vi.fn();
const getFn = vi.fn();
const deleteFn = vi.fn();
const deleteAllFn = vi.fn();

repository.on("put", putFn);
repository.on("get", getFn);
repository.on("delete", deleteFn);
repository.on("deleteall", deleteAllFn);

await repository.put("k1", "v1");
expect(putFn).toHaveBeenCalledWith("k1", "v1");

const value = await repository.get("k1");
expect(value).toEqual("v1");
expect(getFn).toHaveBeenCalledWith("k1", "v1");

await repository.get("missing");
expect(getFn).toHaveBeenCalledWith("missing", undefined);

await repository.delete("k1");
expect(deleteFn).toHaveBeenCalledWith("k1");

await repository.deleteAll();
expect(deleteAllFn).toHaveBeenCalled();
});
Comment on lines 117 to 121
: "utf-8";
const content = (await readFile(localPath, { encoding })).toString().trim();

let value: Value;
if (encoding === "utf-8") {
… assertion

GitMCP at https://gitmcp.io/docs has been failing the public MCP integration
test, taking down both test-vitest-integration and test-bun-integration jobs.
Remove it from the rotation.

Also add a generic-KV test that exercises the getAll event (empty and
populated cases), which was emitted by KvViaTabularStorage but not covered
by the new event tests. Probes for getAll support so FsFolderKvStorage
(which doesn't implement getAll) is skipped automatically.
@github-actions
Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 61.67% 19924 / 32304
🔵 Statements 61.52% 20606 / 33490
🔵 Functions 64.36% 3856 / 5991
🔵 Branches 50.84% 9592 / 18867
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/storage/src/kv/KvViaTabularStorage.ts 41.46% 47.61% 23.07% 41.46% 52, 71-77, 100-103, 114-166
Generated in workflow #2144 for commit ebc9787 by the Vitest Coverage Report Action

@sroussey sroussey merged commit c8c9860 into main May 11, 2026
22 checks passed
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