Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(bug-report): forward screenshot consent through the preload (PRD-7681) (#3112)
Andrew Mikofalvy6084d1bd298f
diff --git a/.changeset/bug-report-screenshot-consent-forwarding.md b/.changeset/bug-report-screenshot-consent-forwarding.mdnew file mode 100644index 000000000..cdbd9f6c5--- /dev/null+++ b/.changeset/bug-report-screenshot-consent-forwarding.md@@ -0,0 +1,13 @@+---+'@inkeep/open-knowledge': patch+---++Screenshots attached to a bug report now actually appear in the report. The previous release added this and it did not work: the screenshot was still left out of every report, silently.++| Before | After |+| --- | --- |+| Report says a screenshot was included; nothing visible | The screenshot is displayed in the report |++The cause was a dropped field. The app asks "does this bundle include a screenshot?" and passes the answer along when sending, but the layer that hands the request from the window to the app's background process was rebuilding it field by field and had never been taught about that answer. The background process saw no answer, took that to mean the reporter had declined, and left the screenshot out. Because "reporter declined" is a perfectly normal outcome, nothing was logged and nothing looked broken.++Unchanged: the screenshot is still opt-in via the checkbox in the report dialog, still previewed before you send, and unchecking it still means no screenshot leaves your machine. Re-sending an older report from the report list still sends it without the inline screenshot, since the capture is no longer in memory by then.diff --git a/packages/desktop/src/preload/bridge-forwarding.test.ts b/packages/desktop/src/preload/bridge-forwarding.test.tsnew file mode 100644index 000000000..66e456078--- /dev/null+++ b/packages/desktop/src/preload/bridge-forwarding.test.ts@@ -0,0 +1,159 @@+/**+ * Preload marshalling contract.+ *+ * The preload sits between the renderer and main and re-assembles requests on+ * the way through, so a field the renderer sends and this layer forgets is+ * simply gone. Nothing else catches that: the main-process tests call the+ * handlers directly, and the renderer DOM tests assert what the component hands+ * a bridge stub. Both sides can be individually correct while the join drops+ * data, and the drop is silent whenever the field is optional and main reads+ * absent as a legitimate value — which is the shape of every consent flag.+ *+ * These tests assert the dispatched payload carries what the caller passed.+ */++import { beforeEach, describe, expect, it, vi } from 'vitest';++const invokeMock = vi.fn(() => Promise.resolve({ ok: true }));+const exposed = new Map<string, Record<string, unknown>>();++// Electron is unavailable in the test runner, and importing the preload module+// executes it — so both halves it touches at import time are stubbed here.+vi.mock('electron', () => ({+ contextBridge: {+ exposeInMainWorld: (key: string, value: Record<string, unknown>) => {+ exposed.set(key, value);+ },+ },+ ipcRenderer: {+ invoke: (...args: unknown[]) => invokeMock(...(args as [])),+ on: () => {},+ removeListener: () => {},+ send: () => {},+ },+}));++/** The `okDesktop` bridge object the preload exposed, typed loosely for probing. */+type BridgeProbe = {+ bugReport: {+ send(request: {+ zipPath: string;+ metadata: Record<string, unknown>;+ includeScreenshot?: boolean;+ }): Promise<unknown>;+ create(request: Record<string, unknown>): Promise<unknown>;+ };+};++async function loadBridge(): Promise<BridgeProbe> {+ exposed.clear();+ vi.resetModules();+ await import('./index.ts');+ const bridge = exposed.get('okDesktop');+ if (bridge === undefined) throw new Error('preload did not expose okDesktop');+ return bridge as unknown as BridgeProbe;+}++/** The payload object handed to `ipcRenderer.invoke` for the given channel. */+function dispatchedPayload(channel: string): Record<string, unknown> {+ const call = invokeMock.mock.calls.find((c) => c[0] === channel);+ if (call === undefined) throw new Error(`nothing dispatched on ${channel}`);+ return call[1] as Record<string, unknown>;+}++beforeEach(() => {+ invokeMock.mockClear();+});++describe('preload bugReport.send marshalling', () => {+ it('forwards the screenshot consent flag to main', async () => {+ // Absent means "reporter declined" on the main side, so dropping the flag+ // here disables the inline screenshot with no trace at all: main's skip+ // logging never fires, because from its view consent was refused.+ const bridge = await loadBridge();++ await bridge.bugReport.send({+ zipPath: '/tmp/report.zip',+ metadata: { level: 'standard' },+ includeScreenshot: true,+ });++ expect(dispatchedPayload('ok:bug-report:dispatch')).toMatchObject({+ kind: 'send',+ zipPath: '/tmp/report.zip',+ includeScreenshot: true,+ });+ });++ it('forwards a withheld consent flag rather than omitting it', async () => {+ // `false` and absent mean the same thing to main today, but they must not be+ // conflated here: an explicit refusal is a decision the reporter made, and a+ // future main-side change that distinguishes them should not be silently+ // deprived of the difference by this layer.+ const bridge = await loadBridge();++ await bridge.bugReport.send({+ zipPath: '/tmp/report.zip',+ metadata: { level: 'standard' },+ includeScreenshot: false,+ });++ expect(dispatchedPayload('ok:bug-report:dispatch').includeScreenshot).toBe(false);+ });++ it('leaves the consent flag absent when the caller omits it', async () => {+ // The retry path in the report list omits the flag: by then the capture is+ // no longer in memory, and absent is what makes main withhold the upload.+ // Nothing may synthesize a value here, in either direction.+ const bridge = await loadBridge();++ await bridge.bugReport.send({+ zipPath: '/tmp/report.zip',+ metadata: { level: 'standard' },+ });++ const payload = dispatchedPayload('ok:bug-report:dispatch');+ expect(payload.includeScreenshot).toBeUndefined();+ });++ it('dispatches the caller request verbatim under the send discriminant', async () => {+ // Compared against the request itself rather than a written-out key list, so+ // a field this file does not know about still has to survive the crossing.+ // What it cannot cover is a field no caller here passes — the request below+ // has to gain one when the contract does.+ const bridge = await loadBridge();+ const request = {+ zipPath: '/tmp/report.zip',+ metadata: { level: 'full', systemWide: false },+ includeScreenshot: true,+ };++ await bridge.bugReport.send(request);++ expect(dispatchedPayload('ok:bug-report:dispatch')).toEqual({ ...request, kind: 'send' });+ });+});++describe('preload bugReport.create marshalling', () => {+ it('dispatches the caller request verbatim under the create discriminant', async () => {+ // `create` was already correct; pinning it keeps the sibling operation from+ // regressing the same way, since it carries the other screenshot opt-in.+ // Asserted with the same exact-equality shape as `send` rather than a+ // per-key loop: a loop cannot see an added key, and the discriminant is+ // part of what the caller is entitled to have dispatched unchanged.+ const bridge = await loadBridge();+ const request = {+ level: 'full',+ note: 'a note',+ includeCrashDump: true,+ includeScreenshot: true,+ };++ await bridge.bugReport.create(request);++ expect(dispatchedPayload('ok:bug-report:dispatch')).toEqual({+ ...request,+ kind: 'create',+ });+ });+});diff --git a/packages/desktop/src/preload/index.ts b/packages/desktop/src/preload/index.tsindex 5af42fe24..4dfef4696 100644--- a/packages/desktop/src/preload/index.ts+++ b/packages/desktop/src/preload/index.ts@@ -26,7 +26,6 @@ import type {OkBugReportDeleteResult,OkBugReportListResult,OkBugReportScreenshot,- OkBugReportSendMetadata,OkBugReportSendResult,ReportBundleLevel,WorktreeCreateRequest,@@ -526,11 +525,19 @@ const bridge: OkDesktopBridge = {invoke('ok:bug-report:dispatch', {kind: 'capture-screenshot',}) as Promise<OkBugReportScreenshot | null>,- send: (request: { zipPath: string; metadata: OkBugReportSendMetadata }) =>+ // Param type derived from the contract, payload spread whole — a hand-copy+ // of this shape drops fields with no type error on either half. A param+ // type listing fewer fields is a SUPERTYPE of the contract's, so it is+ // accepted and the missing field is simply invisible in the body; and an+ // enumerated payload literal satisfies the request union while an optional+ // field is absent. `includeScreenshot` is one such field, and main reads+ // absent as "reporter declined", so a drop here is silent by construction.+ // `kind` sits after the spread so a renderer-supplied `kind` cannot+ // redirect the call to another operation on this channel.+ send: (request: Parameters<OkDesktopBridge['bugReport']['send']>[0]) =>invoke('ok:bug-report:dispatch', {+ ...request,kind: 'send',- zipPath: request.zipPath,- metadata: request.metadata,}) as Promise<OkBugReportSendResult>,crashAck: (request: { eventId: string }) =>invoke('ok:bug-report:dispatch', {diff --git a/packages/desktop/src/shared/bridge-contract.ts b/packages/desktop/src/shared/bridge-contract.tsindex ab1568e19..046e97661 100644--- a/packages/desktop/src/shared/bridge-contract.ts+++ b/packages/desktop/src/shared/bridge-contract.ts@@ -1691,6 +1691,14 @@ export interface OkDesktopBridge {send(request: {zipPath: string;metadata: OkBugReportSendMetadata;+ /**+ * Whether the bundle at `zipPath` contains the app screenshot, taken from+ * the bundle's own file inventory rather than the dialog's checkbox state.+ * The inventory is what the reporter reviewed, so it is the authoritative+ * consent record: absent or false means main must not upload the capture it+ * is still holding.+ */+ includeScreenshot?: boolean;}): Promise<OkBugReportSendResult>;crashAck(request: { eventId: string }): Promise<OkBugReportCrashAckResult>;/** The persisted report history (newest first) read from the sidecars. */