-
Notifications
You must be signed in to change notification settings - Fork 0
feat(app): chart plugin registry — contract + registry primitives (#220) #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
360d929
fix: UX crawler findings — login a11y, error sanitization, error hand…
alfredorubin96 3c6a80f
Merge pull request #376 from alfredo1996/fix/ux-crawler-bugs
alfredo1996 4e7cc1a
feat(app): chart plugin registry — contract + registry primitives (#220)
alfredorubin96 9b43772
ci: re-trigger flaky data-grid test
alfredorubin96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| import { describe, it, expect, beforeEach } from "vitest"; | ||
| import { | ||
| defineChartPlugin, | ||
| createPluginRegistry, | ||
| type ChartPlugin, | ||
| } from "../chart-plugin-registry"; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Fixtures | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| const fakeComponent = () => null; | ||
|
|
||
| const makePlugin = (overrides: Partial<ChartPlugin> = {}): ChartPlugin => | ||
| defineChartPlugin({ | ||
| type: "bar", | ||
| label: "Bar Chart", | ||
| component: fakeComponent, | ||
| transform: (rows) => rows, | ||
| ...overrides, | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // defineChartPlugin — config normalization | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe("defineChartPlugin", () => { | ||
| it("creates a plugin with minimal required fields", () => { | ||
| const plugin = defineChartPlugin({ | ||
| type: "bar", | ||
| label: "Bar Chart", | ||
| component: fakeComponent, | ||
| transform: (rows) => rows, | ||
| }); | ||
| expect(plugin.type).toBe("bar"); | ||
| expect(plugin.label).toBe("Bar Chart"); | ||
| expect(plugin.component).toBe(fakeComponent); | ||
| }); | ||
|
|
||
| it("applies sensible defaults to capabilities", () => { | ||
| const plugin = makePlugin(); | ||
| expect(plugin.capabilities.supportsClickAction).toBe(true); | ||
| expect(plugin.capabilities.supportsStyling).toBe(false); | ||
| expect(plugin.capabilities.requiresQuery).toBe(true); | ||
| expect(plugin.capabilities.isECharts).toBe(false); | ||
| }); | ||
|
|
||
| it("enables supportsStyling when stylingTargets is provided", () => { | ||
| const plugin = makePlugin({ | ||
| stylingTargets: [{ value: "color", label: "Color" }], | ||
| }); | ||
| expect(plugin.capabilities.supportsStyling).toBe(true); | ||
| }); | ||
|
|
||
| it("allows explicit capability overrides", () => { | ||
| const plugin = makePlugin({ | ||
| capabilities: { | ||
| supportsClickAction: false, | ||
| requiresQuery: false, | ||
| supportsStyling: false, | ||
| isECharts: false, | ||
| }, | ||
| }); | ||
| expect(plugin.capabilities.supportsClickAction).toBe(false); | ||
| expect(plugin.capabilities.requiresQuery).toBe(false); | ||
| }); | ||
|
|
||
| it("preserves options when provided", () => { | ||
| const plugin = makePlugin({ | ||
| options: [ | ||
| { | ||
| key: "stacked", | ||
| label: "Stacked", | ||
| type: "boolean", | ||
| default: false, | ||
| category: "Layout", | ||
| }, | ||
| ], | ||
| }); | ||
| expect(plugin.options).toHaveLength(1); | ||
| expect(plugin.options?.[0].key).toBe("stacked"); | ||
| }); | ||
|
|
||
| it("defaults options to empty array when not provided", () => { | ||
| const plugin = makePlugin(); | ||
| expect(plugin.options).toEqual([]); | ||
| }); | ||
|
|
||
| it("preserves compatibleWith list", () => { | ||
| const plugin = makePlugin({ compatibleWith: ["neo4j"] }); | ||
| expect(plugin.compatibleWith).toEqual(["neo4j"]); | ||
| }); | ||
|
|
||
| it("preserves queryHint", () => { | ||
| const plugin = makePlugin({ queryHint: "Return label, value" }); | ||
| expect(plugin.queryHint).toBe("Return label, value"); | ||
| }); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Registry — register / lookup | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe("createPluginRegistry", () => { | ||
| let registry: ReturnType<typeof createPluginRegistry>; | ||
|
|
||
| beforeEach(() => { | ||
| registry = createPluginRegistry(); | ||
| }); | ||
|
|
||
| it("registers a plugin and retrieves it by type", () => { | ||
| const plugin = makePlugin({ type: "bar" }); | ||
| registry.register(plugin); | ||
| expect(registry.get("bar")).toBe(plugin); | ||
| }); | ||
|
|
||
| it("returns undefined for unknown type", () => { | ||
| expect(registry.get("unknown-chart")).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("throws on duplicate registration of same type", () => { | ||
| registry.register(makePlugin({ type: "bar" })); | ||
| expect(() => registry.register(makePlugin({ type: "bar" }))).toThrow( | ||
| /already registered/i, | ||
| ); | ||
| }); | ||
|
|
||
| it("allows multiple distinct plugins", () => { | ||
| registry.register(makePlugin({ type: "bar", label: "Bar" })); | ||
| registry.register(makePlugin({ type: "line", label: "Line" })); | ||
| registry.register(makePlugin({ type: "pie", label: "Pie" })); | ||
| expect(registry.getAll()).toHaveLength(3); | ||
| }); | ||
|
|
||
| it("lists all registered plugins in registration order", () => { | ||
| registry.register(makePlugin({ type: "bar" })); | ||
| registry.register(makePlugin({ type: "line" })); | ||
| const all = registry.getAll(); | ||
| expect(all.map((p) => p.type)).toEqual(["bar", "line"]); | ||
| }); | ||
|
|
||
| it("has() returns true for registered types", () => { | ||
| registry.register(makePlugin({ type: "bar" })); | ||
| expect(registry.has("bar")).toBe(true); | ||
| expect(registry.has("line")).toBe(false); | ||
| }); | ||
|
|
||
| it("getTypes() returns all registered type names", () => { | ||
| registry.register(makePlugin({ type: "bar" })); | ||
| registry.register(makePlugin({ type: "pie" })); | ||
| expect(registry.getTypes()).toEqual(["bar", "pie"]); | ||
| }); | ||
|
|
||
| it("unregister() removes a plugin", () => { | ||
| registry.register(makePlugin({ type: "bar" })); | ||
| registry.unregister("bar"); | ||
| expect(registry.get("bar")).toBeUndefined(); | ||
| expect(registry.has("bar")).toBe(false); | ||
| }); | ||
|
|
||
| it("unregister() is safe on unknown types", () => { | ||
| expect(() => registry.unregister("nope")).not.toThrow(); | ||
| }); | ||
|
|
||
| it("filters plugins by compatible connector type", () => { | ||
| registry.register(makePlugin({ type: "graph", compatibleWith: ["neo4j"] })); | ||
| registry.register( | ||
| makePlugin({ type: "bar", compatibleWith: ["neo4j", "postgresql"] }), | ||
| ); | ||
| registry.register(makePlugin({ type: "pie" })); // no compatibleWith = all | ||
|
|
||
| const neo4jPlugins = registry.getCompatibleWith("neo4j"); | ||
| expect(neo4jPlugins.map((p) => p.type).sort()).toEqual([ | ||
| "bar", | ||
| "graph", | ||
| "pie", | ||
| ]); | ||
|
|
||
| const pgPlugins = registry.getCompatibleWith("postgresql"); | ||
| expect(pgPlugins.map((p) => p.type).sort()).toEqual(["bar", "pie"]); | ||
| }); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Validation — defineChartPlugin guards invalid configs | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe("defineChartPlugin validation", () => { | ||
| it("throws when type is empty", () => { | ||
| expect(() => | ||
| defineChartPlugin({ | ||
| type: "", | ||
| label: "Empty", | ||
| component: fakeComponent, | ||
| transform: (r) => r, | ||
| }), | ||
| ).toThrow(/type.*required/i); | ||
| }); | ||
|
|
||
| it("throws when label is empty", () => { | ||
| expect(() => | ||
| defineChartPlugin({ | ||
| type: "bar", | ||
| label: "", | ||
| component: fakeComponent, | ||
| transform: (r) => r, | ||
| }), | ||
| ).toThrow(/label.*required/i); | ||
| }); | ||
|
|
||
| it("throws when transform is not a function", () => { | ||
| expect(() => | ||
| defineChartPlugin({ | ||
| type: "bar", | ||
| label: "Bar", | ||
| component: fakeComponent, | ||
| // @ts-expect-error -- deliberately invalid | ||
| transform: "not a function", | ||
| }), | ||
| ).toThrow(/transform.*function/i); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
NextAuth v5 signIn function return value with redirect false💡 Result:
In NextAuth.js (Auth.js) v5, when calling the client-side signIn function with { redirect: false }, it returns a Promise object containing { ok: boolean, error?: string, code?: string }. This allows checking if sign-in succeeded without automatic redirection: if (response.ok) { // success, manually redirect or update UI } else { // handle error: response.error }. The exact shape differs slightly from v4 (which had { ok, error, status, url }), and v5 beta versions have reported inconsistencies where it sometimes returns a URL string instead of the object, or ok: true despite errors (ongoing issues
#9465,#6040). Official docs confirm SignInResponse has ok, error, code for client use with redirect: false. Use .then or await to access it, as one example showed: await signIn(...).then(({ ok, error }) => ...). For server actions, signIn throws AuthError on failure instead of returning response.Citations:
🏁 Script executed:
Repository: alfredo1996/neoboard
Length of output: 99
🏁 Script executed:
Repository: alfredo1996/neoboard
Length of output: 130
🏁 Script executed:
Repository: alfredo1996/neoboard
Length of output: 200
🏁 Script executed:
Repository: alfredo1996/neoboard
Length of output: 987
🏁 Script executed:
Repository: alfredo1996/neoboard
Length of output: 91
🏁 Script executed:
Repository: alfredo1996/neoboard
Length of output: 46
The
elsebranch is unreachable — but the real issue is the unsafe condition above it.NextAuth v5
signIn("credentials", { redirect: false })always returns aSignInResponseobject{ ok, error, code }on both success and failure. It only throws on network errors (caught by yourcatchblock). Theelsebranch will never execute.However, the bigger problem is
else if (result)at line 44 — it allows redirect even whenresult.okisfalseandresult.erroris undefined. Change toelse if (result?.ok)to safely verify success before redirecting:♻️ Suggested fix
if (result?.error) { setError("Invalid email or password"); setLoading(false); - } else if (result) { + } else if (result?.ok) { router.push(callbackUrl); } else { setError("Unable to sign in. Please try again."); setLoading(false); }🤖 Prompt for AI Agents