- 删除 AksrtFrontend registry/rehydrate 双路架构及 build/public.js 拼包入口,
前台唯一初始路径为 PHP 本地栈(jQuery 1.9.1 → Bootstrap 3.4.1)
→ loader_js(_win/aksrtData 唯一注入)→ tbquire(['main']) → runtime/main.min.js
- window.auto_fun = debounce(z_auto_fun, 100) 为唯一重扫入口;所有模块改为
执行一次 + off/on('auto_fun.aksrt-*') 命名空间重扫,data/class 标记幂等
- 局部更新协议统一:HTML 注入 → post_ajax.ed → auto_fun();
远程 modal → loaded.bs.modal → auto_fun();JSON 成功 → zib_ajax.success
- 灯箱恢复 Miniimgbox/imgbox 唯一 owner(imgbox-container、a[data-imgbox]、
imgbox_data),删除 AksrtLightbox/data-aksrt-lightbox 第二实现及 CSS/overlay,
_win.imgbox* 重新接上 post-display 设置
- 死代码清理:runtime 下 11 组被自有实现替代的旧模块副本、无消费 vendored 库、
顶层 grade.min.js、revenue.js、无调用方的 aksrt_get_win_runtime_config(),
以及 loader 中 16 条死 mapping
- PHP 入队改为本地栈 + loader_js,routed/widget/submit 依赖统一换绑;
用户卡片发布按钮恢复 nav_user_newposts_btn 设置门控
- 测试对齐:新增 frontend-lifecycle-contract,重写 navigation/lazyload/toast/
auth-source/comment/page-display/post-visual 等断言为目标架构契约
验证:node --test widget-system+navigation 223 通过 0 失败;
构建脚本重建 main/imgbox min 与 CSS bundles;改动 PHP php -l、JS node --check
全部通过;git diff --check 干净;credits 重入 harness 通过。
110 lines
3.8 KiB
JavaScript
110 lines
3.8 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const test = require('node:test');
|
|
const vm = require('node:vm');
|
|
|
|
const root = path.resolve(__dirname, '..', '..');
|
|
const runtime = fs.readFileSync(path.join(root, 'assets/js/captcha-front.js'), 'utf8');
|
|
|
|
function createInput(name, value = '') {
|
|
return { name, value, remove() {}, nodeType: 1 };
|
|
}
|
|
|
|
function createHarness() {
|
|
const fields = new Map();
|
|
const challenge = createInput('aksrt_captcha_challenge', 'challenge-token');
|
|
const proof = createInput('aksrt_captcha_proof', '');
|
|
const verified = createInput('captcha_verified', '0');
|
|
fields.set(challenge.name, challenge);
|
|
fields.set(proof.name, proof);
|
|
fields.set(verified.name, verified);
|
|
|
|
const container = {
|
|
nodeType: 1,
|
|
contains: () => true,
|
|
querySelector(selector) {
|
|
const match = selector.match(/input\[name="([^"]+)"\]/);
|
|
return match ? fields.get(match[1]) || null : null;
|
|
},
|
|
querySelectorAll(selector) {
|
|
const value = this.querySelector(selector);
|
|
return value ? [value] : [];
|
|
},
|
|
appendChild(field) { fields.set(field.name, field); },
|
|
};
|
|
const box = {
|
|
nodeType: 1,
|
|
parentElement: container,
|
|
closest: () => container,
|
|
contains: () => false,
|
|
querySelector: () => null,
|
|
appendChild() {},
|
|
innerHTML: '',
|
|
};
|
|
const mount = {
|
|
nodeType: 1,
|
|
dataset: {},
|
|
parentElement: container,
|
|
contains: () => true,
|
|
setAttribute() {},
|
|
};
|
|
const scripts = [];
|
|
const document = {
|
|
readyState: 'complete',
|
|
documentElement: { nodeType: 1 },
|
|
querySelectorAll(selector) { return selector === '[data-aksrt-captcha-config]' ? [mount] : []; },
|
|
querySelector: () => null,
|
|
getElementById(id) { return id === 'captcha-box' ? box : verified; },
|
|
createElement(tag) {
|
|
if (tag === 'input') return createInput('', '');
|
|
return { setAttribute() {}, addEventListener() {}, appendChild() {}, style: {}, dataset: {} };
|
|
},
|
|
addEventListener() {},
|
|
head: { appendChild(script) { scripts.push(script); } },
|
|
body: { appendChild() {} },
|
|
};
|
|
mount.getAttribute = () => JSON.stringify({
|
|
provider: 'tencent', scene: 'login', uid: 'captcha-box', vid: 'captcha-verified',
|
|
tc: { app_id: '1' }, challenge_url: '/challenge', exchange_url: '/exchange',
|
|
});
|
|
|
|
let providerCallback;
|
|
const window = {
|
|
fetch(url) {
|
|
if (url === '/challenge') return Promise.resolve({ ok: true, json: () => Promise.resolve({ success: true, data: { challenge: 'challenge-token' } }) });
|
|
if (url === '/exchange') return Promise.resolve({ ok: true, json: () => Promise.resolve({ success: true, data: { proof: 'proof-token' } }) });
|
|
throw new Error('unexpected URL ' + url);
|
|
},
|
|
TencentCaptcha: class {
|
|
constructor(_id, callback) { providerCallback = callback; }
|
|
show() { providerCallback({ ret: 0, ticket: 'ticket', randstr: 'rand' }); }
|
|
},
|
|
setTimeout,
|
|
clearTimeout,
|
|
Promise,
|
|
};
|
|
vm.runInNewContext(runtime, { window, document, Promise, MutationObserver: undefined, setTimeout, clearTimeout, console });
|
|
return { api: window.AKSRTCaptcha, container };
|
|
}
|
|
|
|
test('captcha run is single-flight until the owning business request resets', async () => {
|
|
const { api, container } = createHarness();
|
|
await Promise.resolve();
|
|
await Promise.resolve();
|
|
const first = api.run('login', container);
|
|
const second = api.run('login', container);
|
|
const firstPayload = await first;
|
|
assert.equal(firstPayload.aksrt_captcha_proof, 'proof-token');
|
|
|
|
let secondSettled = false;
|
|
second.then(() => { secondSettled = true; });
|
|
await Promise.resolve();
|
|
assert.equal(secondSettled, false, 'concurrent caller settled before the owner reset');
|
|
|
|
api.reset('login', container);
|
|
assert.equal(await second, null);
|
|
});
|