Skip to content

Conversation

@AnthonyRonning
Copy link
Contributor

@AnthonyRonning AnthonyRonning commented Nov 23, 2025

Implements the delete all KV endpoint in both Rust and TypeScript SDKs.

Summary by CodeRabbit

  • New Features

    • Added a one-click bulk delete to remove all key-value pairs.
    • Exposed a public delete-all method in the app context/API for callers to trigger the bulk removal.
  • Tests

    • Added integration tests covering insertion, listing, and the new delete-all flow to ensure correctness.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 23, 2025

Walkthrough

Added a bulk-delete KV operation across the SDK: Rust client exposes kv_delete_all(), TypeScript exposes fetchDeleteAllKV(), React context exposes delAll, and integration tests validate the end-to-end behavior by inserting keys, invoking delete-all, and asserting an empty store.

Changes

Cohort / File(s) Summary
Rust client bulk-delete
rust/src/client.rs
Added pub async fn kv_delete_all(&self) -> Result<()> which issues a DELETE to /protected/kv via the existing encrypted_api_call helper and returns Ok(()) on success.
Rust integration test
rust/tests/api_integration.rs
Added test_kv_delete_all() that registers a guest, inserts three KV entries, asserts presence, calls kv_delete_all, and asserts the KV store is empty.
TypeScript API function
src/lib/api.ts
Added exported fetchDeleteAllKV(): Promise<void> calling authenticatedApiCall with method DELETE to ${apiUrl}/protected/kv.
React context binding
src/lib/main.tsx
Added delAll: typeof api.fetchDeleteAllKV to OpenSecretContextType, default context value, and provider wiring; maps delAll to api.fetchDeleteAllKV.
Test minor edits
src/lib/test/integration/ai.test.ts, src/lib/test/integration/api.test.ts
Normalized quote style in ai.test.ts; added test imports and usages for fetchPut, fetchList, and fetchDeleteAllKV in api.test.ts.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as Frontend (React)
  participant API as TS API Layer
  participant Server
  participant Client as Rust OpenSecretClient

  User->>UI: trigger "Delete All" (delAll)
  UI->>API: fetchDeleteAllKV() (DELETE /protected/kv)
  API->>Server: authenticated DELETE /protected/kv
  Server-->>API: 200 OK
  API-->>UI: resolve
  Note right of UI `#D6F5D6`: UI updates state (list becomes empty)

  %% Rust client flow (integration test)
  Client->>Server: DELETE /protected/kv (kv_delete_all)
  Server-->>Client: 200 OK
  Client-->>Test: Ok(())
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Changes are localized but span Rust, TypeScript, React, and tests.
  • Review focus:
    • Confirm endpoint path /protected/kv consistency.
    • Verify authentication/authorization behavior matches other KV ops.
    • Ensure tests reliably isolate state (guest registration and cleanup).

Possibly related PRs

Poem

🐰 I nibble keys beneath the moon,
One hush, one hop — then gone too soon.
Rust and TS and React agree,
A single call, the meadow free.
Keys scattered, cleared — a springtime tune.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: implement delete all KV endpoint' clearly and concisely summarizes the main change: adding a bulk-delete operation for key-value pairs across both Rust and TypeScript SDKs.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kv-delete-all

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 23, 2025

Deploying opensecret-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5a43b0c
Status: ✅  Deploy successful!
Preview URL: https://cf81a97c.opensecret-sdk.pages.dev
Branch Preview URL: https://kv-delete-all.opensecret-sdk.pages.dev

View logs

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 23, 2025

Greptile Overview

Greptile Summary

This PR implements the delete all KV endpoint in both Rust and TypeScript SDKs, following the established pattern from the recent delete all conversations feature.

Key Changes:

  • Added kv_delete_all() method in Rust SDK that calls DELETE on /protected/kv
  • Added fetchDeleteAllKV() function in TypeScript SDK with matching behavior
  • Exposed delAll method in React context with proper JSDoc documentation
  • Comprehensive integration tests in both SDKs verify setup, deletion, and empty state
  • Minor whitespace formatting fixes in ai.test.ts

The implementation is consistent with existing patterns, properly tested, and follows the same endpoint differentiation strategy (path-based vs query-based) used throughout the codebase.

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • Implementation follows established patterns from delete_conversations, uses proper authentication and encryption, includes comprehensive tests with proper assertions, and has clear documentation
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
rust/src/client.rs 5/5 Added kv_delete_all() method following existing pattern, makes encrypted DELETE call to /protected/kv
rust/tests/api_integration.rs 5/5 Added comprehensive test for kv_delete_all() with proper assertions and isolation using guest registration
src/lib/api.ts 5/5 Added fetchDeleteAllKV() function with proper error message, calls DELETE on /protected/kv endpoint
src/lib/main.tsx 5/5 Exposed delAll method in context with proper JSDoc documentation, added to all context instances
src/lib/test/integration/api.test.ts 5/5 Added comprehensive test for fetchDeleteAllKV() with proper setup, assertions, and cleanup verification

Sequence Diagram

sequenceDiagram
    participant Client as SDK Client
    participant SDK as OpenSecret SDK
    participant API as Encrypted API
    participant KV as KV Storage

    Client->>SDK: kv_delete_all() / delAll()
    SDK->>API: DELETE /protected/kv
    Note over SDK,API: Encrypted API call
    API->>KV: Delete all user's KV pairs
    KV-->>API: Success
    API-->>SDK: Empty response
    SDK-->>Client: Ok(()) / void
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@AnthonyRonning AnthonyRonning merged commit 4a5ab74 into master Nov 23, 2025
6 of 8 checks passed
@AnthonyRonning AnthonyRonning deleted the kv-delete-all branch November 23, 2025 18:37
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/lib/test/integration/api.test.ts (1)

452-473: Improve test isolation to prevent flakiness.

The test assumes a clean KV store but doesn't isolate its test data. This could cause failures if other tests leave keys behind or run concurrently.

Consider these improvements:

  1. Verify the specific keys (key1, key2, key3) exist before deletion rather than just counting (line 465)
  2. Use unique key names (e.g., timestamp or UUID prefix) to avoid collisions
  3. Add a try/finally block to ensure cleanup even if assertions fail

Apply this diff to improve test isolation:

 test("KV Store - Delete All", async () => {
   // Login first to get authenticated
   const { access_token, refresh_token } = await tryEmailLogin();
   window.localStorage.setItem("access_token", access_token);
   window.localStorage.setItem("refresh_token", refresh_token);
 
-  // Add multiple keys
-  await fetchPut("key1", "value1");
-  await fetchPut("key2", "value2");
-  await fetchPut("key3", "value3");
+  // Use unique keys to avoid collisions with other tests
+  const testPrefix = `test-${Date.now()}-`;
+  await fetchPut(`${testPrefix}key1`, "value1");
+  await fetchPut(`${testPrefix}key2`, "value2");
+  await fetchPut(`${testPrefix}key3`, "value3");
 
-  // Verify they exist
+  // Verify our keys exist
   const listBefore = await fetchList();
-  expect(listBefore.length).toBeGreaterThanOrEqual(3);
+  const ourKeys = listBefore.filter(item => item.key.startsWith(testPrefix));
+  expect(ourKeys.length).toBe(3);
 
   // Delete all keys
   await fetchDeleteAllKV();
 
   // Verify they are gone
   const listAfter = await fetchList();
   expect(listAfter.length).toBe(0);
 });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38fb0b5 and 5a43b0c.

📒 Files selected for processing (6)
  • rust/src/client.rs (1 hunks)
  • rust/tests/api_integration.rs (1 hunks)
  • src/lib/api.ts (1 hunks)
  • src/lib/main.tsx (3 hunks)
  • src/lib/test/integration/ai.test.ts (2 hunks)
  • src/lib/test/integration/api.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • rust/src/client.rs
  • rust/tests/api_integration.rs
  • src/lib/test/integration/ai.test.ts
  • src/lib/api.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/lib/test/integration/api.test.ts (1)
src/lib/api.ts (3)
  • fetchPut (143-150)
  • fetchList (185-192)
  • fetchDeleteAllKV (161-168)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (4)
src/lib/test/integration/api.test.ts (1)

20-23: LGTM!

The imports are correctly added and align with the API exports. The addition of setDefaultInstruction fixes a missing import for line 344, and the new KV methods support the test added below.

src/lib/main.tsx (3)

198-203: LGTM!

The JSDoc and type definition for delAll are clear and consistent with the existing KV operation methods in the context.


869-869: LGTM!

The default context value correctly maps delAll to api.fetchDeleteAllKV, consistent with other KV operations.


1280-1280: LGTM!

The provider value correctly wires delAll to api.fetchDeleteAllKV, completing the integration into the OpenSecret context.

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.

2 participants