f8b919e883
This keeps the existing CPA, SUB2API, and contribution flows intact while introducing codex2api as a separate source that plugs into Step 7 and Step 10 through backend APIs instead of page DOM. The sidepanel now exposes codex2api settings, preserves the built-in local default through placeholder-only UI, and accepts user-provided public admin URLs. Step 7 now treats missing or invalid management secrets as terminal config errors so the flow stops instead of retrying needlessly. Constraint: New source must be additive and must not break existing CPA/SUB2API/contribution paths Rejected: Drive codex2api through admin page button clicks | too brittle against frontend DOM changes Rejected: Reuse contribution mode as a source surface | violates existing panelMode/runtime-mode boundary Confidence: high Scope-risk: moderate Reversibility: clean Directive: Keep codex2api on the protocol path unless its API becomes insufficient; do not add a panel content script without proving the protocol path cannot work Tested: npm test; targeted codex2api/auth retry loops repeated 40 times; full suite repeated 5 times Not-tested: Real browser run against a live codex2api instance with a real Admin Secret and OpenAI authorization
38 lines
1.5 KiB
JavaScript
38 lines
1.5 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
|
|
test('background imports navigation utils module', () => {
|
|
const source = fs.readFileSync('background.js', 'utf8');
|
|
assert.match(source, /background\/navigation-utils\.js/);
|
|
});
|
|
|
|
test('navigation utils module exposes a factory', () => {
|
|
const source = fs.readFileSync('background/navigation-utils.js', 'utf8');
|
|
const globalScope = {};
|
|
|
|
const api = new Function('self', `${source}; return self.MultiPageBackgroundNavigationUtils;`)(globalScope);
|
|
|
|
assert.equal(typeof api?.createNavigationUtils, 'function');
|
|
});
|
|
|
|
test('navigation utils support codex2api mode and url normalization', () => {
|
|
const source = fs.readFileSync('background/navigation-utils.js', 'utf8');
|
|
const globalScope = {};
|
|
|
|
const api = new Function('self', `${source}; return self.MultiPageBackgroundNavigationUtils;`)(globalScope);
|
|
const utils = api.createNavigationUtils({
|
|
DEFAULT_CODEX2API_URL: 'http://localhost:8080/admin/accounts',
|
|
DEFAULT_SUB2API_URL: 'https://sub.example.com/admin/accounts',
|
|
normalizeLocalCpaStep9Mode: (value) => value,
|
|
});
|
|
|
|
assert.equal(utils.normalizeCodex2ApiUrl('localhost:8080/admin'), 'http://localhost:8080/admin/accounts');
|
|
assert.equal(
|
|
utils.normalizeCodex2ApiUrl('https://codex-admin.example.com/'),
|
|
'https://codex-admin.example.com/admin/accounts'
|
|
);
|
|
assert.equal(utils.getPanelMode({ panelMode: 'codex2api' }), 'codex2api');
|
|
assert.equal(utils.getPanelModeLabel('codex2api'), 'Codex2API');
|
|
});
|