修复一个偶发的问题

This commit is contained in:
andy committed 2026-09-14 18:24:25 +08:00
1 parent 8d55e930a2
commit 0282c30a2a
20 files changed
+440 -39

No files matched your search

+16 -2
View File
@@ -15,10 +15,11 @@ const adapter = readFileSync(new URL('../chrome-extension/ltjt-order-assistant/l
teamSummaryRequery = async (operation, subpage) => subpage;
assistant.preflightLifecycleOperation = preflightLifecycleOperation;`);
function fixture(type, { occupied = 1, rows = occupied + 2, onSelection = () => {}, onValidate = () => {}, sort = false, onPost = () => {} } = {}) {
function fixture(type, { occupied = 1, rows = occupied + 2, onSelection = () => {}, onValidate = () => {}, sort = false, onPost = () => {}, linkageDelays = [] } = {}) {
let now = 10000;
let posts = 0;
let selections = 0;
let linkageTicks = 0;
let savedForm;
const form = { elements: [], id: 'InfoForm1', isConnected: true };
const fields = new Map();
@@ -73,7 +74,10 @@ function fixture(type, { occupied = 1, rows = occupied + 2, onSelection = () =>
return savedForm.elements.find((control) => control.name === name) || null;
} }, text: 'LW-TEST-HOTEL', response: { ok: true, status: 200 } });
const sandbox = { window, document, location, Event: window.Event, URL, URLSearchParams, TextEncoder,
Date: class extends Date { static now() { return now; } }, setTimeout(callback, ms) { now += ms; callback(); } };
Date: class extends Date { static now() { return now; } }, setTimeout(callback, ms) {
now += selections ? linkageDelays[linkageTicks++] ?? ms : ms;
callback();
} };
window.setTimeout = sandbox.setTimeout;
vm.runInNewContext(inpage, sandbox);
vm.runInNewContext(adapter, sandbox);
@@ -86,6 +90,16 @@ function fixture(type, { occupied = 1, rows = occupied + 2, onSelection = () =>
}
for (const type of ['vehicle', 'transport', 'other']) {
test(`${type} create recovers from a delayed linkage sample but never saves while sampling stays delayed`, async () => {
for (const [linkageDelays, completed] of [[[6000], true], [Array(6).fill(6000), false]]) {
const f = fixture(type, { linkageDelays });
const result = await f.api.liveSubmitLifecycleOperation(f.operation);
assert.equal(result.status, completed ? 'lifecycle_completed' : 'lifecycle_apply_blocked', JSON.stringify(result));
assert.equal(f.posts(), completed ? 1 : 0); assert.equal(f.selections(), 1);
assert.equal(result.preflight.arrangement_linkage.reason, completed ? 'stable' : 'sampling_delayed');
}
});
test(`${type} create preserves old rows and binds native selection, dates and quantity to empty rows 0/1/10`, async () => {
for (const occupied of [0, 1, 10]) {
const f = fixture(type, { occupied });