Files
PaperClipAI/ui/vitest.setup.ts
T
Harold KimandPaperclip 98df214917 fix: fail closed on unusable Codex auth during sandbox auth merge
When reusing a Codex sandbox, the workspace-restore step now performs
an auth-merge check before adopting the sandbox's auth.json. The merge
fails closed when:

- host or sandbox Codex auth is unusable (missing token or account)
- the subscription payload shapes differ between host and sandbox
- subscription account identities do not match

Additional hardening: node absence on PATH during the embedded decision
script now exits non-zero instead of silently falling through. Co-change
comments link parseAuth (the embedded script) to hasUsableAuthPayload
(codex-home.ts) so a future auth-format change cannot silently diverge
between the two implementations.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-07-09 10:08:57 +00:00

41 lines
1.4 KiB
TypeScript

const storageEntries = new Map<string, string>();
function installStorageMock(target: Record<string, unknown>) {
Object.defineProperty(target, "localStorage", {
configurable: true,
value: {
getItem: (key: string) => storageEntries.get(key) ?? null,
setItem: (key: string, value: string) => {
storageEntries.set(key, String(value));
},
removeItem: (key: string) => {
storageEntries.delete(key);
},
clear: () => {
storageEntries.clear();
},
},
});
}
if (
typeof globalThis.localStorage?.getItem !== "function"
|| typeof globalThis.localStorage?.setItem !== "function"
|| typeof globalThis.localStorage?.removeItem !== "function"
|| typeof globalThis.localStorage?.clear !== "function"
) {
installStorageMock(globalThis);
}
if (typeof window !== "undefined" && window.localStorage !== globalThis.localStorage) {
installStorageMock(window as unknown as Record<string, unknown>);
}
// jsdom does not implement Element.prototype.scrollIntoView. Several surfaces
// (e.g. IssueChatThread's auto-scroll-to-latest) call it during normal render,
// so provide a no-op default. Tests that assert on scroll behaviour override
// this on the prototype themselves and restore it afterwards.
if (typeof Element !== "undefined" && typeof Element.prototype.scrollIntoView !== "function") {
Element.prototype.scrollIntoView = function scrollIntoView() {};
}