From 4b91fde81b388441bfbf4f9d684a14ff864f249f Mon Sep 17 00:00:00 2001 From: Amy Lin Date: Wed, 29 Jul 2026 11:26:24 -0500 Subject: [PATCH 1/2] feat(package-vulnerability-scanner): show an in-app setup screen When the viewer's session can't be read or the Visitor API Key integration is missing (content.ts/user.ts's setupRequired, from the previous PR), show a setup message with the specific reason instead of hanging on the loading spinner or a generic error. A separate error state still shows when something else fails to load. --- .../manifest.json | 10 +-- .../src/App.test.ts | 61 +++++++++++++++ .../package-vulnerability-scanner/src/App.vue | 61 ++++++++++++++- .../src/stores/content.test.ts | 78 +++++++++++++++++++ .../src/stores/content.ts | 14 +++- 5 files changed, 215 insertions(+), 9 deletions(-) create mode 100644 extensions/package-vulnerability-scanner/src/App.test.ts create mode 100644 extensions/package-vulnerability-scanner/src/stores/content.test.ts diff --git a/extensions/package-vulnerability-scanner/manifest.json b/extensions/package-vulnerability-scanner/manifest.json index 80c4ca99..bed1b9b6 100644 --- a/extensions/package-vulnerability-scanner/manifest.json +++ b/extensions/package-vulnerability-scanner/manifest.json @@ -20,14 +20,14 @@ }, "packages": {}, "files": { - "dist/assets/index-CGfl-rCQ.css": { - "checksum": "b4dadccacaa63c585d549a30e09ed801" + "dist/assets/index-Bd7WoAqv.css": { + "checksum": "980b7708188eee5f84707dcc6cf3b01d" }, - "dist/assets/index-SEZBmp0A.js": { - "checksum": "5045b070467147359ba4430ff5a5d602" + "dist/assets/index-DDPGfFmA.js": { + "checksum": "b6d254fb7554759a23d54603d83fd836" }, "dist/index.html": { - "checksum": "35a9caef18b056356d5caff6e12b3c10" + "checksum": "58ca7cb5afb344897d80bf2bb8a0b1ac" }, "main.py": { "checksum": "331f2474111a6280734062de89152bb6" diff --git a/extensions/package-vulnerability-scanner/src/App.test.ts b/extensions/package-vulnerability-scanner/src/App.test.ts new file mode 100644 index 00000000..ff697c87 --- /dev/null +++ b/extensions/package-vulnerability-scanner/src/App.test.ts @@ -0,0 +1,61 @@ +// @vitest-environment happy-dom +import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; +import { setActivePinia, createPinia } from "pinia"; +import { mount, flushPromises } from "@vue/test-utils"; + +import App from "./App.vue"; + +// A fetch stub that fails every request with a 424 carrying the given detail, +// as the backend does for the setup cases. +function stub424(detail: string) { + return vi.fn(async () => ({ + ok: false, + status: 424, + json: async () => ({ detail }), + })); +} + +beforeEach(() => { + setActivePinia(createPinia()); + vi.spyOn(console, "error").mockImplementation(() => {}); +}); + +afterEach(() => { + vi.unstubAllGlobals(); +}); + +describe("App setup screen", () => { + it("shows the reason when the viewer's session can't be read", async () => { + vi.stubGlobal( + "fetch", + stub424( + "Couldn't read your Connect session. In the content settings, on the " + + "Access tab, add a Connect Visitor API Key integration under " + + "Integrations, to scan content as you.", + ), + ); + + const wrapper = mount(App); + await flushPromises(); + + expect(wrapper.text()).toContain("Setup"); + expect(wrapper.text()).toContain("Couldn't read your Connect session"); + }); + + it("shows the reason when the integration is missing", async () => { + vi.stubGlobal( + "fetch", + stub424( + "In the content settings, on the Access tab, add a Connect Visitor API " + + "Key integration under Integrations, to scan your content.", + ), + ); + + const wrapper = mount(App); + await flushPromises(); + + expect(wrapper.text()).toContain("add a Connect Visitor API Key"); + // Each cause shows its own reason, not the other one. + expect(wrapper.text()).not.toContain("Couldn't read your Connect session"); + }); +}); diff --git a/extensions/package-vulnerability-scanner/src/App.vue b/extensions/package-vulnerability-scanner/src/App.vue index 0a40095e..c8847f6e 100644 --- a/extensions/package-vulnerability-scanner/src/App.vue +++ b/extensions/package-vulnerability-scanner/src/App.vue @@ -1,7 +1,9 @@