mirror of
https://github.com/hanzoai/extension.git
synced 2026-10-31 21:57:06 +00:00
shared/evaluable.ts is the single cross-browser rule for caller-supplied
JS: pickEvaluable accepts every code-param alias (expression/code/script/
function/js); wrapEvaluable passes bare expressions through and wraps
statement bodies in an async IIFE with the trailing value auto-returned.
Both dispatch paths consume it — browser-dispatch.ts (chrome.debugger
Runtime.evaluate, which also gains the plain 'evaluate' method alias
Firefox already accepted) and background-firefox.ts, whose previous
`return (${code})` wrap was a SyntaxError on any multi-statement body
and silently returned undefined for `expr;`. The Firefox path now always
settles promises in-page and routes rejections over the __hanzo_error
channel so callers see the real page-side error.
Tests: behavioral suite for the wrapper (evaluates wrapped output, not
string-matching); revive the three suites dead since the node bridge was
deleted — parity contracts repointed at browser-dispatch.ts, the IAM
contracts updated to the HIP-0111 canonical /v1/iam/oauth/token shape,
hub-wiring trimmed to the live background.ts surface, and the node-bridge
routing suite removed with its subject. 243 passing (was 186 + 3 dead
files).
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
// Verify that background.ts has all hub.* message handlers wired in
|
|
describe('hub message handler wiring', () => {
|
|
const backgroundSrc = fs.readFileSync(
|
|
path.join(__dirname, '../src/background.ts'),
|
|
'utf-8'
|
|
);
|
|
|
|
const requiredHandlers = [
|
|
'hub.search',
|
|
'hub.searchGGUF',
|
|
'hub.model',
|
|
'hub.recommended',
|
|
'hub.searchOllama',
|
|
'hub.downloadOllama',
|
|
'hub.downloadHF',
|
|
'hub.searchMLX',
|
|
'hub.modelCard',
|
|
'hub.modelStats',
|
|
'hub.allModels',
|
|
];
|
|
|
|
for (const handler of requiredHandlers) {
|
|
it(`has case '${handler}' handler`, () => {
|
|
expect(backgroundSrc).toContain(`case '${handler}'`);
|
|
});
|
|
}
|
|
|
|
it('imports model-hub module', () => {
|
|
expect(backgroundSrc).toContain("from './model-hub'");
|
|
});
|
|
});
|
|
|
|
// The node bridge (cdp-bridge-server.ts) and its snake_case hub_* action
|
|
// namespace were removed with it — hub access now rides the ZAP surface
|
|
// into the background.ts `hub.*` handlers asserted above.
|