buildChatGptUrl and its fitToBudget helpers have had no production caller since prepareAction took over routing; the 2026-10-05 plan kept them only for existing tests until then. They also shortened silently, against the ask-before-shortening rule, so they were a trap to reuse. Port the tests that guard live code onto applyTemplate and serializePrompt, including the $&, $`, $' and $$ regressions (checked to fail against the string-replacement form), and cover prepareAction's whole-word cut, which nothing tested before. Also drop getContext's inputType password check. menus.OnClickData has no inputType, so it never fired; Firefox already withholds password fields from selectionText via mozIsTextField(true) in SelectionUtils (bug 565717). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
2.1 KiB
JavaScript
33 lines
2.1 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { DEFAULT_SETTINGS as defaults } from '../lib/defaults.js';
|
|
const actions = await import('../lib/actions.js').catch(() => ({}));
|
|
|
|
test('context prioritizes selection over link and excludes unrelated targets', () => {
|
|
assert.equal(typeof actions.getContext, 'function');
|
|
assert.deepEqual(actions.getContext({selectionText:'code',linkUrl:'https://example.com',contexts:['selection','link']}), {kind:'selection',source:'code'});
|
|
assert.deepEqual(actions.getContext({selectionText:' ',linkUrl:'https://example.com'}), {kind:'link',source:'https://example.com'});
|
|
assert.equal(actions.getContext({mediaType:'image',pageUrl:'https://example.com'}), null);
|
|
assert.equal(actions.getContext({editable:true,pageUrl:'https://example.com'}), null);
|
|
assert.equal(actions.getContext({pageUrl:'https://example.com'}).kind, 'page');
|
|
});
|
|
test('selection actions and optional translation reflect settings', () => {
|
|
assert.equal(typeof actions.getActions, 'function');
|
|
assert.deepEqual(actions.getActions({kind:'selection'}, defaults).map(a=>a.id), ['ask','explain','summarize','debug']);
|
|
const list = actions.getActions({kind:'selection'}, {...defaults,showTranslate:true,translationMode:'preferred',translationLanguage:'A & B'});
|
|
assert.equal(list.at(-1).title,'Translate to A && B');
|
|
});
|
|
test('dedicated prompts ignore personal template and preserve literal source', () => {
|
|
assert.equal(typeof actions.renderPrompt, 'function');
|
|
const request = {actionId:'ask',source:'$& $$ `code` 😀',settings:{...defaults,promptTemplate:'French: {query}'}};
|
|
assert.equal(actions.renderPrompt(request), 'French: $& $$ `code` 😀');
|
|
assert.equal(actions.renderPrompt({...request,source:''}), '');
|
|
for (const actionId of ['explain','summarize','debug']) {
|
|
const prompt = actions.renderPrompt({...request,actionId});
|
|
assert.ok(prompt.includes(request.source));
|
|
assert.ok(!prompt.includes('French:'));
|
|
}
|
|
assert.match(actions.renderPrompt({...request,actionId:'translate',language:'Spanish'}), /Spanish/);
|
|
assert.match(actions.renderPrompt({...request,actionId:'review-link'}), /uncertainty/);
|
|
});
|