Repository navigation
fix: open the What's New page only once its feed has loaded #2102
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
Open
ralphstodomingo
wants to merge
4
commits into
master
Choose a base branch
from
fix/whats-new-feed-unavailable
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+660
−55
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3da3399
fix: open the What's New page only once its feed has loaded
ralphstodomingo ea41bb0
fix: share the activation fetch with a manual open; never reject the …
ralphstodomingo 1423e2b
fix: do not reopen a page the user closed while the activation fetch …
ralphstodomingo f6d2614
fix: keep the activation fetch for a page that is still loading
ralphstodomingo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,241 @@ | ||
| import { beforeEach, describe, expect, it, jest } from "@jest/globals"; | ||
| import fetch from "node-fetch"; | ||
| import { | ||
| WhatsNewPanel, | ||
| feedFailureReason, | ||
| } from "../../webview_provider/whatsNewPanel"; | ||
|
|
||
| const MANIFEST_CACHE_KEY = "whatsNew.cachedManifest"; | ||
|
|
||
| const FEED = `<?xml version="1.0"?><rss><channel> | ||
| <lastBuildDate>Tue, 14 Oct 2026 10:00:00 GMT</lastBuildDate> | ||
| <item><title>[Feature] Fetch before opening</title><category>dbt-power-user</category> | ||
| <link>https://altimate.ai/changelog#fetch</link><pubDate>Mon, 13 Oct 2026 10:00:00 GMT</pubDate> | ||
| <description>desc</description></item> | ||
| </channel></rss>`; | ||
|
|
||
| /** | ||
| * Builds the panel with only the collaborators the manifest path touches; | ||
| * node-fetch is the jest-mapped mock, so every network outcome can be | ||
| * replayed. The response the page receives is captured through | ||
| * sendResponseToWebview. | ||
| */ | ||
| const manifestHarness = (opts: { trigger?: "auto" | "manual" } = {}) => { | ||
| const store = new Map<string, unknown>(); | ||
| const responses: Record<string, unknown>[] = []; | ||
| const telemetry = { | ||
| sendTelemetryEvent: jest.fn(), | ||
| sendTelemetryError: jest.fn(), | ||
| }; | ||
| const dbtTerminal = { debug: jest.fn(), warn: jest.fn(), error: jest.fn() }; | ||
| const panel = Object.create(WhatsNewPanel.prototype) as Record< | ||
| string, | ||
| unknown | ||
| > & { | ||
| serveManifest: (id: string) => Promise<void>; | ||
| fetchManifest: (trigger: "auto" | "manual") => Promise<unknown>; | ||
| }; | ||
| panel.dbtProjectContainer = { | ||
| extensionVersion: "0.66.0", | ||
| getFromGlobalState: (key: string) => store.get(key), | ||
| setToGlobalState: (key: string, value: unknown): void => { | ||
| store.set(key, value); | ||
| }, | ||
| }; | ||
| panel.telemetry = telemetry; | ||
| panel.dbtTerminal = dbtTerminal; | ||
| panel.currentTrigger = opts.trigger ?? "manual"; | ||
| panel.sendResponseToWebview = (r: Record<string, unknown>) => { | ||
| responses.push(r); | ||
| }; | ||
| return { panel, store, responses, telemetry, dbtTerminal }; | ||
| }; | ||
|
|
||
| // jest.config.js maps node-fetch to src/test/mock/node-fetch.ts (a jest.fn). | ||
| const fetchMock = fetch as unknown as jest.Mock< | ||
| (...args: unknown[]) => Promise<unknown> | ||
| >; | ||
| const okFeed = () => | ||
| fetchMock.mockResolvedValue({ | ||
| ok: true, | ||
| status: 200, | ||
| text: async () => FEED, | ||
| }); | ||
| const httpStatus = (status: number) => | ||
| fetchMock.mockResolvedValue({ ok: false, status, text: async () => "" }); | ||
| const networkDown = () => | ||
| fetchMock.mockRejectedValue( | ||
| Object.assign(new TypeError("fetch failed"), { | ||
| cause: { code: "ECONNREFUSED" }, | ||
| }), | ||
| ); | ||
|
|
||
| describe("feedFailureReason", () => { | ||
| it.each([ | ||
| [ | ||
| Object.assign(new Error("This operation was aborted"), { | ||
| name: "AbortError", | ||
| }), | ||
| "timeout", | ||
| ], | ||
| [new Error("Feed request failed with 403"), "http_403"], | ||
| [new Error("Feed request failed with 503"), "http_503"], | ||
| [ | ||
| new Error( | ||
| "request to https://x failed, reason: getaddrinfo ENOTFOUND altimate.ai", | ||
| ), | ||
| "dns", | ||
| ], | ||
| [ | ||
| new Error( | ||
| "request to https://x failed, reason: unable to verify the first certificate", | ||
| ), | ||
| "tls", | ||
| ], | ||
| [ | ||
| Object.assign(new TypeError("fetch failed"), { | ||
| cause: { code: "SELF_SIGNED_CERT_IN_CHAIN" }, | ||
| }), | ||
| "tls", | ||
| ], | ||
| [ | ||
| new Error("request to https://x failed, reason: read ECONNRESET"), | ||
| "network", | ||
| ], | ||
| [ | ||
| new Error( | ||
| "request to https://x failed, reason: Failed to establish a socket connection to proxies: PROXY 10.0.0.1:8080", | ||
| ), | ||
| "proxy", | ||
| ], | ||
| [ | ||
| new Error("tunneling socket could not be established, statusCode=407"), | ||
| "proxy", | ||
| ], | ||
| [ | ||
| Object.assign(new TypeError("fetch failed"), { | ||
| cause: { code: "ECONNREFUSED" }, | ||
| }), | ||
| "network", | ||
| ], | ||
| [ | ||
| new Error( | ||
| "Client network socket disconnected before secure TLS connection was established", | ||
| ), | ||
| "network", | ||
| ], | ||
| [new Error("something else entirely"), "other"], | ||
| ["not even an error", "other"], | ||
| ])("%s -> %s", (error, reason) => { | ||
| expect(feedFailureReason(error)).toBe(reason); | ||
| }); | ||
| }); | ||
|
|
||
| describe("WhatsNewPanel manifest path", () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("serves a fetched manifest, caches it and reports the page open", async () => { | ||
| okFeed(); | ||
| const h = manifestHarness({ trigger: "manual" }); | ||
|
|
||
| await h.panel.serveManifest("req-1"); | ||
|
|
||
| expect(h.responses).toHaveLength(1); | ||
| expect(h.responses[0]).toMatchObject({ | ||
| syncRequestId: "req-1", | ||
| status: true, | ||
| }); | ||
| const data = h.responses[0].data as { items: unknown[]; version: string }; | ||
| expect(data.items).toHaveLength(1); | ||
| expect(data.version).toBe("0.66.0"); | ||
| expect(h.store.get(MANIFEST_CACHE_KEY)).toBe(data); | ||
| expect(h.telemetry.sendTelemetryEvent).toHaveBeenCalledWith( | ||
| "whats_new_page_opened", | ||
| { version: "0.66.0", trigger: "manual" }, | ||
| { items_shown: 1 }, | ||
| ); | ||
| expect(h.dbtTerminal.warn).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("answers a blocked feed with a failed response and a feed-unavailable event, not an error", async () => { | ||
| httpStatus(403); | ||
| const h = manifestHarness({ trigger: "manual" }); | ||
|
|
||
| await h.panel.serveManifest("req-2"); | ||
|
|
||
| expect(h.responses[0]).toMatchObject({ | ||
| syncRequestId: "req-2", | ||
| status: false, | ||
| error: "Feed request failed with 403", | ||
| }); | ||
| expect(h.telemetry.sendTelemetryEvent).toHaveBeenCalledTimes(1); | ||
| expect(h.telemetry.sendTelemetryEvent).toHaveBeenCalledWith( | ||
| "whats_new_feed_unavailable", | ||
| { reason: "http_403", trigger: "manual", fallback: "none" }, | ||
| ); | ||
| expect(h.telemetry.sendTelemetryError).not.toHaveBeenCalled(); | ||
| expect(h.dbtTerminal.error).not.toHaveBeenCalled(); | ||
| expect(h.dbtTerminal.warn).toHaveBeenCalledTimes(1); | ||
| expect(String(h.dbtTerminal.warn.mock.calls[0][1])).toContain("(http_403)"); | ||
| }); | ||
|
|
||
| it("falls back to the cached manifest when the network is down, and says so", async () => { | ||
| networkDown(); | ||
| const h = manifestHarness({ trigger: "auto" }); | ||
| const cached = { | ||
| product: "dbt-power-user", | ||
| version: "0.65.0", | ||
| items: [{ title: "old" }], | ||
| }; | ||
| h.store.set(MANIFEST_CACHE_KEY, cached); | ||
|
|
||
| await h.panel.serveManifest("req-3"); | ||
|
|
||
| expect(h.responses[0]).toMatchObject({ status: true, data: cached }); | ||
| expect(h.telemetry.sendTelemetryEvent).toHaveBeenCalledWith( | ||
| "whats_new_feed_unavailable", | ||
| { reason: "network", trigger: "auto", fallback: "cache" }, | ||
| ); | ||
| expect(h.telemetry.sendTelemetryEvent).toHaveBeenCalledWith( | ||
| "whats_new_page_opened", | ||
| { version: "0.65.0", trigger: "auto" }, | ||
| { items_shown: 1 }, | ||
| ); | ||
| expect(String(h.dbtTerminal.warn.mock.calls[0][1])).toContain( | ||
| "showing the cached manifest", | ||
| ); | ||
| }); | ||
|
|
||
| it("serves the manifest fetched before an automatic open without fetching again", async () => { | ||
| const h = manifestHarness({ trigger: "auto" }); | ||
| const preloaded = { | ||
| product: "dbt-power-user", | ||
| version: "0.66.0", | ||
| items: [], | ||
| }; | ||
| h.panel.pending = Promise.resolve(preloaded); | ||
|
|
||
| await h.panel.serveManifest("req-4"); | ||
|
|
||
| expect(fetchMock).not.toHaveBeenCalled(); | ||
| expect(h.responses[0]).toMatchObject({ status: true, data: preloaded }); | ||
| expect(h.panel.pending).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("a timed-out feed is classed as a timeout", async () => { | ||
| fetchMock.mockRejectedValue( | ||
| Object.assign(new Error("This operation was aborted"), { | ||
| name: "AbortError", | ||
| }), | ||
| ); | ||
| const h = manifestHarness(); | ||
|
|
||
| await expect(h.panel.fetchManifest("auto")).rejects.toThrow("aborted"); | ||
| expect(h.telemetry.sendTelemetryEvent).toHaveBeenCalledWith( | ||
| "whats_new_feed_unavailable", | ||
| { reason: "timeout", trigger: "auto", fallback: "none" }, | ||
| ); | ||
| }); | ||
| }); |
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.
On a minor upgrade where the feed resolves but
show("auto")throws—for example, a test can stubshowto throw—showWhenFeedAvailabledoes not catch that exception, socheckAndShowOnActivation()rejects. This fire-and-forget call has no rejection handler, producing an unhandled rejection instead of the former synchronous exception being caught byactivate's surroundingtry; this directly violates C6. Await the promise or attach a catch that reports the failure.Useful? React with 👍 / 👎.
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.
Fixed in ea41bb0. checkAndShowOnActivation wraps its whole body (state read/write, setting, fetch, show) in try/catch and logs through dbtTerminal.error, so the fire-and-forget call at activation cannot reject; a show() failure also drops the pending fetch. Tests: "a page that fails to open is logged, and activation still settles" and "a failing state read is logged, and activation still settles".