-
Notifications
You must be signed in to change notification settings - Fork 17
[codex] Extract client list runtime wiring #1048
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // @ts-check | ||
| // client-list-runtime.js - Browser runtime adapters for client-list UI shell hooks. | ||
|
|
||
| function getRuntimeWindow() { | ||
| return typeof window !== 'undefined' | ||
| ? /** @type {any} */ (window) | ||
| : /** @type {any} */ (globalThis); | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} name | ||
| * @returns {Function | null} | ||
| */ | ||
| function getRuntimeFunction(name) { | ||
| const runtime = getRuntimeWindow(); | ||
| return typeof runtime[name] === 'function' ? runtime[name].bind(runtime) : null; | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} name | ||
| * @returns {any} | ||
| */ | ||
| function getRuntimeValue(name) { | ||
| return getRuntimeWindow()[name]; | ||
| } | ||
|
|
||
| export function getClientHaplogroupList() { | ||
| const list = getRuntimeValue('HAPLOGROUP_LIST'); | ||
| return Array.isArray(list) ? list : []; | ||
| } | ||
|
|
||
| /** @param {() => void} [fallback] */ | ||
| export function closeClientListFromRuntime(fallback) { | ||
| const close = getRuntimeFunction('closeClientList') || fallback; | ||
| close?.(); | ||
| } | ||
|
|
||
| /** @param {string} route */ | ||
| export function navigateClientListRoute(route) { | ||
| getRuntimeFunction('navigate')?.(route); | ||
| } | ||
|
|
||
| export function refreshClientProfileButton() { | ||
| getRuntimeFunction('renderProfileButton')?.(); | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} message | ||
| * @param {string} type | ||
| */ | ||
| export function showClientListNotification(message, type) { | ||
| getRuntimeFunction('showNotification')?.(message, type); | ||
| } | ||
|
|
||
| /** @param {string} haplogroup */ | ||
| export function setClientManualHaplogroup(haplogroup) { | ||
| const setManualHaplogroup = getRuntimeFunction('setManualHaplogroup'); | ||
| return setManualHaplogroup ? setManualHaplogroup(haplogroup) : false; | ||
| } | ||
|
|
||
| export function hasClientListAIProvider() { | ||
| try { | ||
| return getRuntimeFunction('hasAIProvider')?.() === true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** @param {Record<string, any>} bindings */ | ||
| export function publishClientListWindowBindings(bindings) { | ||
| if (typeof window === 'undefined') return; | ||
| Object.assign(getRuntimeWindow(), bindings); | ||
| } |
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "inlineEventAttributes": 0, | ||
| "windowReferences": 567, | ||
| "windowReferences": 547, | ||
| "largeJsFilesOver800Lines": 29, | ||
| "maxJsFileLines": 1513 | ||
| } |
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
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,105 @@ | ||
| #!/usr/bin/env node | ||
| // test-client-list-runtime.js - Client-list browser runtime adapter behavior. | ||
|
|
||
| import './_node-shim.js'; | ||
| import { | ||
| closeClientListFromRuntime, | ||
| getClientHaplogroupList, | ||
| hasClientListAIProvider, | ||
| navigateClientListRoute, | ||
| publishClientListWindowBindings, | ||
| refreshClientProfileButton, | ||
| setClientManualHaplogroup, | ||
| showClientListNotification, | ||
| } from '../js/client-list-runtime.js'; | ||
|
|
||
| let pass = 0, fail = 0; | ||
| function assert(name, condition, detail) { | ||
| if (condition) { pass++; console.log(` PASS: ${name}`); } | ||
| else { fail++; console.log(` FAIL: ${name}${detail ? ' — ' + detail : ''}`); } | ||
| } | ||
|
|
||
| console.log('=== Client List Runtime Tests ===\n'); | ||
|
|
||
| const runtimeKeys = [ | ||
| 'HAPLOGROUP_LIST', | ||
| 'closeClientList', | ||
| 'navigate', | ||
| 'renderProfileButton', | ||
| 'showNotification', | ||
| 'setManualHaplogroup', | ||
| 'hasAIProvider', | ||
| '__clientListRuntimeProbe', | ||
| ]; | ||
| const saved = Object.fromEntries(runtimeKeys.map(key => [key, globalThis[key]])); | ||
|
|
||
| function restoreRuntime() { | ||
| for (const key of runtimeKeys) { | ||
| if (typeof saved[key] === 'undefined') delete globalThis[key]; | ||
| else globalThis[key] = saved[key]; | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| const calls = []; | ||
|
|
||
| globalThis.HAPLOGROUP_LIST = ['H1', 'J2']; | ||
| assert('getClientHaplogroupList reads runtime haplogroup list', | ||
| getClientHaplogroupList().join(',') === 'H1,J2'); | ||
| globalThis.HAPLOGROUP_LIST = 'H1'; | ||
| assert('getClientHaplogroupList falls back to empty array for invalid runtime value', | ||
| getClientHaplogroupList().length === 0); | ||
|
|
||
| globalThis.closeClientList = () => calls.push(['close']); | ||
| closeClientListFromRuntime(() => calls.push(['fallback-close'])); | ||
| delete globalThis.closeClientList; | ||
| closeClientListFromRuntime(() => calls.push(['fallback-close'])); | ||
| assert('closeClientListFromRuntime prefers runtime close and falls back when missing', | ||
| calls.filter(call => call[0] === 'close').length === 1 && | ||
| calls.filter(call => call[0] === 'fallback-close').length === 1); | ||
|
|
||
| globalThis.navigate = route => calls.push(['navigate', route]); | ||
| navigateClientListRoute('dashboard'); | ||
| assert('navigateClientListRoute delegates to runtime navigate', | ||
| calls.some(call => call[0] === 'navigate' && call[1] === 'dashboard')); | ||
|
|
||
| globalThis.renderProfileButton = () => calls.push(['render-profile-button']); | ||
| refreshClientProfileButton(); | ||
| assert('refreshClientProfileButton delegates to runtime profile refresh', | ||
| calls.some(call => call[0] === 'render-profile-button')); | ||
|
|
||
| globalThis.showNotification = (message, type) => calls.push(['notification', message, type]); | ||
| showClientListNotification('"Ada" updated', 'info'); | ||
| assert('showClientListNotification delegates runtime notification', | ||
| calls.some(call => call[0] === 'notification' && call[1] === '"Ada" updated' && call[2] === 'info')); | ||
|
|
||
| globalThis.setManualHaplogroup = async haplogroup => { | ||
| calls.push(['set-haplogroup', haplogroup]); | ||
| return true; | ||
| }; | ||
| assert('setClientManualHaplogroup delegates runtime haplogroup setter', | ||
| await setClientManualHaplogroup('H1') === true && | ||
| calls.some(call => call[0] === 'set-haplogroup' && call[1] === 'H1')); | ||
| delete globalThis.setManualHaplogroup; | ||
| assert('setClientManualHaplogroup returns false when hook is missing', | ||
| await setClientManualHaplogroup('J2') === false); | ||
|
|
||
| globalThis.hasAIProvider = () => true; | ||
| assert('hasClientListAIProvider delegates truthy runtime provider state', | ||
| hasClientListAIProvider() === true); | ||
| globalThis.hasAIProvider = () => { throw new Error('provider unavailable'); }; | ||
| assert('hasClientListAIProvider returns false when runtime hook throws', | ||
| hasClientListAIProvider() === false); | ||
| delete globalThis.hasAIProvider; | ||
| assert('hasClientListAIProvider returns false when hook is missing', | ||
| hasClientListAIProvider() === false); | ||
|
|
||
| publishClientListWindowBindings({ __clientListRuntimeProbe: () => 'ok' }); | ||
| assert('publishClientListWindowBindings installs legacy globals', | ||
| globalThis.__clientListRuntimeProbe?.() === 'ok'); | ||
| } finally { | ||
| restoreRuntime(); | ||
| } | ||
|
|
||
| console.log(`\nResults: ${pass} passed, ${fail} failed, ${pass + fail} total`); | ||
| process.exit(fail > 0 ? 1 : 0); |
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.
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.