codeant-ai-for-open-source[bot] commented on code in PR #39171:
URL: https://github.com/apache/superset/pull/39171#discussion_r3561087002


##########
superset-frontend/packages/superset-core/src/extensions/index.ts:
##########
@@ -24,9 +24,80 @@
  * including querying extension metadata and monitoring extension lifecycle 
events.
  * Extensions can use this API to discover other extensions and react to 
changes
  * in the extension ecosystem.
+ *
+ * Extensions can access their own context via `getContext()`, which provides:
+ * - Extension metadata (id, name, version, etc.)
+ * - Extension-scoped storage (localStorage, sessionStorage, ephemeral cache)
+ *
+ * @example
+ * ```typescript
+ * import { extensions } from '@apache-superset/core';
+ *
+ * // Get the current extension's context
+ * const ctx = extensions.getContext();
+ *
+ * // Access extension metadata
+ * console.log(`Running ${ctx.extension.name} v${ctx.extension.version}`);
+ *
+ * // Access extension-scoped storage
+ * await ctx.storage.local.set('preference', { theme: 'dark' });
+ * await ctx.storage.ephemeral.set('cache', data, { ttl: 300 });
+ * ```
  */
 
 import { Extension } from '../common';
+import { ExtensionStorage } from '../storage';
+
+/**
+ * Context object providing extension-specific resources.
+ *
+ * This context is only available during extension execution.
+ * Calling `getContext()` outside of an extension will throw an error.
+ */
+export interface ExtensionContext {
+  /**
+   * Metadata about the current extension.
+   */
+  extension: Extension;
+
+  /**
+   * Extension-scoped storage across all tiers.
+   * All keys are automatically namespaced to prevent collisions.
+   */
+  storage: ExtensionStorage;
+}
+
+/**
+ * Get the current extension's context.
+ *
+ * This function returns the context for the currently executing extension,
+ * providing access to extension metadata and scoped resources like storage.
+ *
+ * @returns The current extension's context.
+ * @throws Error if called outside of an extension context.
+ *
+ * @example
+ * ```typescript
+ * import { extensions } from '@apache-superset/core';
+ *
+ * const ctx = extensions.getContext();
+ *
+ * // Access extension metadata
+ * console.log(`Extension: ${ctx.extension.id}`);
+ * console.log(`Version: ${ctx.extension.version}`);
+ *
+ * // Access extension-scoped storage
+ * await ctx.storage.local.set('userPref', { sidebar: 'collapsed' });
+ * const pref = await ctx.storage.local.get('userPref');
+ *
+ * // Use ephemeral storage with TTL
+ * await ctx.storage.ephemeral.set('tempData', data, { ttl: 3600 });
+ *
+ * // Access shared (cross-user) storage
+ * await ctx.storage.ephemeral.shared.set('globalCounter', count);

Review Comment:
   **Suggestion:** The JSDoc example calls `ephemeral.shared.set` without the 
required TTL options argument, which contradicts the declared API contract and 
will fail for consumers who copy this example. Update the example to pass an 
options object with `ttl` so it matches the actual method signature. [docstring 
mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   ❌ Extensions using shared ephemeral storage crash on writes.
   ⚠️ TypeScript consumers hit compile errors copying JSDoc example.
   ⚠️ Documentation misleads about TTL requirements for shared cache.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open `superset-frontend/packages/superset-core/src/extensions/index.ts` 
and locate the
   `getContext()` JSDoc example at lines 79–98 (verified via Read), which shows 
`await
   ctx.storage.ephemeral.shared.set('globalCounter', count);` on line 97 with 
only two
   arguments.
   
   2. Open `superset-frontend/packages/superset-core/src/storage/index.ts` and 
inspect
   `EphemeralStorageAccessor` at lines 132–138 and `EphemeralStorageTier` at 
lines 145–147
   (verified via Read); note that `set` is declared as `set(key, value, options:
   EphemeralSetOptions): Promise<void>` and that `.shared` is typed as
   `EphemeralStorageAccessor`, meaning the third `options` argument with TTL is 
required for
   shared calls.
   
   3. Open the concrete implementation 
`superset-frontend/src/core/storage/ephemeralState.ts`
   and inspect the `shared` accessor definition at lines 44–55 (verified via 
Read);
   `shared.set` is implemented as `async set(key, value, options: 
EphemeralSetOptions)` and
   immediately uses `options.codec` and `options.ttl`, so calling it without 
the `options`
   object will result in `options` being `undefined` and a runtime `TypeError` 
when
   `options.codec` is accessed in JavaScript.
   
   4. As an extension author, copy the JSDoc example from `extensions/index.ts` 
into a
   TypeScript extension module that imports `extensions` from 
`@apache-superset/core`, call
   `ctx.storage.ephemeral.shared.set('globalCounter', count)` exactly as shown, 
and observe
   either (a) a TypeScript compile-time error due to the missing `options` 
argument based on
   `EphemeralStorageTier`/`EphemeralStorageAccessor` types, or (b) in a plain 
JavaScript
   extension, a runtime crash when `createEphemeralState.shared.set` 
dereferences
   `options.codec` and `options.ttl`, demonstrating that the documented call 
shape is
   incorrect.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b2e1e063ba77430f926457fbf1364121&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=b2e1e063ba77430f926457fbf1364121&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/packages/superset-core/src/extensions/index.ts
   **Line:** 96:97
   **Comment:**
        *Docstring Mismatch: The JSDoc example calls `ephemeral.shared.set` 
without the required TTL options argument, which contradicts the declared API 
contract and will fail for consumers who copy this example. Update the example 
to pass an options object with `ttl` so it matches the actual method signature.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=5b63ad9de8d122b241ec9aa4fb2648cf6bad5d04e2ca5d4ac5360249d45c575f&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=5b63ad9de8d122b241ec9aa4fb2648cf6bad5d04e2ca5d4ac5360249d45c575f&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to