-
Notifications
You must be signed in to change notification settings - Fork 7
fix: sync pre-httpapi stability baseline #506
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 all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
22b162e
fix(provider): sync current reasoning variants
Astro-Han cce1bc2
fix(server): preserve cors on auth failures
Astro-Han 9b0110a
fix(desktop): harden app shell edge cases
Astro-Han 6943f6b
test(desktop): harden ipc source contract
Astro-Han a223a7f
fix(desktop): return after zoom reset
Astro-Han fd62177
fix(provider): align azure gpt chat efforts
Astro-Han 7b6ad1f
fix(desktop): avoid double wrapping console transport
Astro-Han 8812a80
test(desktop): cover webview zoom behavior
Astro-Han 59cbcf4
test(provider): cover small option variants
Astro-Han a92f719
test(desktop): restore global window descriptor
Astro-Han 380dfd0
fix(provider): restrict gemini pro thinking levels
Astro-Han 50d0a32
test(desktop): cover logging fresh imports
Astro-Han b1856a6
test(desktop): avoid zoom float artifact
Astro-Han 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,124 @@ | ||
| import { afterAll, afterEach, describe, expect, mock, test } from "bun:test" | ||
| import { mkdtempSync, rmSync } from "node:fs" | ||
| import { join } from "node:path" | ||
| import { tmpdir } from "node:os" | ||
|
|
||
| let logDir = "" | ||
| const fakeLog: { | ||
| transports: { | ||
| file: { | ||
| maxSize: number | ||
| getFile: () => { path: string } | ||
| } | ||
| console: { | ||
| level: string | false | ||
| wrapCount: number | ||
| writeFn: (options: unknown) => void | ||
| } | ||
| } | ||
| } = { | ||
| transports: { | ||
| file: { | ||
| maxSize: 0, | ||
| getFile: () => ({ path: join(tmpdir(), "desktop.log") }), | ||
| }, | ||
| console: { | ||
| level: "info", | ||
| wrapCount: 0, | ||
| writeFn: () => undefined, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| mock.module("electron-log/main.js", () => ({ | ||
| default: fakeLog, | ||
| })) | ||
|
|
||
| afterEach(() => { | ||
| if (logDir) rmSync(logDir, { recursive: true, force: true }) | ||
| logDir = "" | ||
| }) | ||
|
|
||
| afterAll(() => { | ||
| mock.restore() | ||
| }) | ||
|
|
||
| function setupLog(writeFn: (options: unknown) => void) { | ||
| logDir = mkdtempSync(join(tmpdir(), "pawwork-logging-test-")) | ||
| let currentWriteFn = writeFn | ||
| let wrapCount = 0 | ||
| fakeLog.transports.file = { | ||
| maxSize: 0, | ||
| getFile: () => ({ path: join(logDir, "desktop.log") }), | ||
| } | ||
| fakeLog.transports.console = { | ||
| level: "info", | ||
| get wrapCount() { | ||
| return wrapCount | ||
| }, | ||
| get writeFn() { | ||
| return currentWriteFn | ||
| }, | ||
| set writeFn(next) { | ||
| wrapCount++ | ||
| currentWriteFn = next | ||
| }, | ||
| } | ||
| return fakeLog.transports.console | ||
| } | ||
|
|
||
| function brokenPipe() { | ||
| return Object.assign(new Error("broken pipe"), { code: "EPIPE" }) | ||
| } | ||
|
|
||
| function otherWriteError() { | ||
| return Object.assign(new Error("write failed"), { code: "ENOENT" }) | ||
| } | ||
|
|
||
| describe("desktop logging", () => { | ||
| test("disables the console transport after a broken pipe", async () => { | ||
| const consoleTransport = setupLog(() => { | ||
| throw brokenPipe() | ||
| }) | ||
| const { initLogging } = await import(`./logging?logging-test=${crypto.randomUUID()}`) | ||
|
|
||
| initLogging() | ||
| consoleTransport.writeFn({}) | ||
|
|
||
| expect(consoleTransport.level).toBe(false) | ||
| }) | ||
|
|
||
| test("rethrows non-broken-pipe console transport errors", async () => { | ||
| const err = otherWriteError() | ||
| const consoleTransport = setupLog(() => { | ||
| throw err | ||
| }) | ||
| const { initLogging } = await import(`./logging?logging-test=${crypto.randomUUID()}`) | ||
|
|
||
| initLogging() | ||
|
|
||
| expect(() => consoleTransport.writeFn({})).toThrow(err) | ||
| expect(consoleTransport.level).toBe("info") | ||
| }) | ||
|
|
||
| test("does not wrap the console transport more than once", async () => { | ||
| const consoleTransport = setupLog(() => undefined) | ||
| const { initLogging } = await import(`./logging?logging-test=${crypto.randomUUID()}`) | ||
|
|
||
| initLogging() | ||
| initLogging() | ||
|
|
||
| expect(consoleTransport.wrapCount).toBe(1) | ||
| }) | ||
|
|
||
| test("does not wrap the console transport again across fresh module imports", async () => { | ||
| const consoleTransport = setupLog(() => undefined) | ||
| const first = await import(`./logging?logging-test=${crypto.randomUUID()}`) | ||
| const second = await import(`./logging?logging-test=${crypto.randomUUID()}`) | ||
|
|
||
| first.initLogging() | ||
| second.initLogging() | ||
|
|
||
| expect(consoleTransport.wrapCount).toBe(1) | ||
| }) | ||
| }) |
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
121 changes: 121 additions & 0 deletions
121
packages/desktop-electron/src/renderer/webview-zoom.test.ts
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,121 @@ | ||
| import { afterEach, describe, expect, mock, test } from "bun:test" | ||
|
|
||
| type KeydownHandler = (event: { | ||
| key: string | ||
| ctrlKey: boolean | ||
| metaKey: boolean | ||
| preventDefault: () => void | ||
| }) => void | ||
|
|
||
| const originalNavigator = Object.getOwnPropertyDescriptor(globalThis, "navigator") | ||
| const originalWindow = Object.getOwnPropertyDescriptor(globalThis, "window") | ||
|
|
||
| afterEach(() => { | ||
| if (originalNavigator) Object.defineProperty(globalThis, "navigator", originalNavigator) | ||
| else delete (globalThis as { navigator?: Navigator }).navigator | ||
| if (originalWindow) Object.defineProperty(globalThis, "window", originalWindow) | ||
| else delete (globalThis as { window?: Window }).window | ||
| }) | ||
|
|
||
| function deferred() { | ||
| let resolve!: () => void | ||
| let reject!: (err: unknown) => void | ||
| const promise = new Promise<void>((resolvePromise, rejectPromise) => { | ||
| resolve = resolvePromise | ||
| reject = rejectPromise | ||
| }) | ||
| return { promise, resolve, reject } | ||
| } | ||
|
|
||
| async function loadZoomModule(options?: { userAgent?: string; setZoomFactor?: (factor: number) => Promise<void> }) { | ||
| const handlers: KeydownHandler[] = [] | ||
| const setZoomFactor = mock(options?.setZoomFactor ?? (() => Promise.resolve())) | ||
|
|
||
| Object.defineProperty(globalThis, "navigator", { | ||
| value: { userAgent: options?.userAgent ?? "Windows" }, | ||
| configurable: true, | ||
| writable: true, | ||
| }) | ||
| Object.defineProperty(globalThis, "window", { | ||
| value: { | ||
| api: { setZoomFactor }, | ||
| addEventListener: (type: string, handler: KeydownHandler) => { | ||
| if (type === "keydown") handlers.push(handler) | ||
| }, | ||
| }, | ||
| configurable: true, | ||
| writable: true, | ||
| }) | ||
|
|
||
| const module = await import(`./webview-zoom?webview-zoom-test=${crypto.randomUUID()}`) | ||
| return { | ||
| handler: handlers[0]!, | ||
| setZoomFactor, | ||
| webviewZoom: module.webviewZoom, | ||
| } | ||
| } | ||
|
|
||
| function keyEvent(key: string, overrides?: Partial<Parameters<KeydownHandler>[0]>) { | ||
| return { | ||
| key, | ||
| ctrlKey: true, | ||
| metaKey: false, | ||
| preventDefault: mock(() => undefined), | ||
| ...overrides, | ||
| } | ||
| } | ||
|
|
||
| describe("desktop renderer webview zoom", () => { | ||
| test("only consumes keydown events that actually change zoom", async () => { | ||
| const { handler, setZoomFactor } = await loadZoomModule() | ||
| const unrelated = keyEvent("a") | ||
| const zoomOut = keyEvent("-") | ||
|
|
||
| handler(unrelated) | ||
| handler(zoomOut) | ||
|
|
||
| expect(unrelated.preventDefault).toHaveBeenCalledTimes(0) | ||
| expect(zoomOut.preventDefault).toHaveBeenCalledTimes(1) | ||
| expect(setZoomFactor).toHaveBeenCalledTimes(1) | ||
| expect(setZoomFactor).toHaveBeenCalledWith(0.8) | ||
| }) | ||
|
|
||
| test("keeps requested zoom separate until Electron accepts the zoom change", async () => { | ||
| const zoom = deferred() | ||
| const { handler, webviewZoom } = await loadZoomModule({ setZoomFactor: () => zoom.promise }) | ||
|
|
||
| handler(keyEvent("-")) | ||
|
|
||
| expect(webviewZoom()).toBe(1) | ||
| zoom.resolve() | ||
| await zoom.promise | ||
| await Promise.resolve() | ||
| expect(webviewZoom()).toBe(0.8) | ||
| }) | ||
|
|
||
| test("keeps the current zoom when Electron rejects the zoom change", async () => { | ||
| const zoom = deferred() | ||
| const { handler, webviewZoom } = await loadZoomModule({ setZoomFactor: () => zoom.promise }) | ||
|
|
||
| handler(keyEvent("-")) | ||
|
|
||
| zoom.reject(new Error("zoom failed")) | ||
| await zoom.promise.catch(() => undefined) | ||
| await Promise.resolve() | ||
| expect(webviewZoom()).toBe(1) | ||
| }) | ||
|
|
||
| test("uses requested zoom for rapid repeated shortcuts", async () => { | ||
| const { handler, setZoomFactor } = await loadZoomModule() | ||
|
|
||
| handler(keyEvent("-")) | ||
| handler(keyEvent("-")) | ||
| handler(keyEvent("0")) | ||
|
|
||
| const factors = setZoomFactor.mock.calls.map(([factor]) => factor) | ||
| expect(factors).toHaveLength(3) | ||
| expect(factors[0]).toBeCloseTo(0.8, 10) | ||
| expect(factors[1]).toBeCloseTo(0.6, 10) | ||
| expect(factors[2]).toBe(1) | ||
| }) | ||
| }) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.