mirror of
https://github.com/morluto/rea.git
synced 2026-11-14 18:52:48 +00:00
Vitest's expect.poll and vi.waitFor stop after one second by default, a host-speed guess that the project's deadline policy does not see. Under hosted-CI load, kunaProjectConcurrency failed that way twice on unrelated PRs. Another 256 waits relied on the default, and 97 passed literals picked to fit some host. Waits now take as long as their test may run, less the reporting reserve that children already keep. Each Vitest project sets expect.poll's default, and the new waitFor in tests/support/testWait.ts replaces vi.waitFor. Fixture readiness waits (awaitAcknowledgement and the provider process waits) default to the same deadline, and their host-speed literal arguments are removed. One remainingTestDeadline owns the arithmetic for both children and waits. Ten waits whose short timeout was the real check now assert it directly (Kuna version probe, Cutter discovery, doctor and Inspector cancellation, apktool fixture teardown, JADX disconnect): settlement before the production deadline that would otherwise also satisfy the wait, or a deadline pinned beyond every test deadline. The rea/project-wait-deadline lint rule rejects vi.waitFor and explicit expect.poll timeouts. The testing guide and the CI tests audit skill now document the policy. Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
93 lines
3.1 KiB
JavaScript
93 lines
3.1 KiB
JavaScript
import { findBinding } from "../bindings.mjs";
|
|
|
|
const unwrap = (node) =>
|
|
node?.type === "ChainExpression" ? node.expression : node;
|
|
|
|
const propertyName = (member) => {
|
|
if (!member?.computed && member?.property?.type === "Identifier")
|
|
return member.property.name;
|
|
if (member?.computed && member.property?.type === "Literal")
|
|
return member.property.value;
|
|
return undefined;
|
|
};
|
|
|
|
/** The `vitest` import specifier a local identifier is bound to, if any. */
|
|
const vitestImport = (sourceCode, identifier) => {
|
|
const definition = findBinding(sourceCode, identifier)?.defs[0];
|
|
if (definition?.type !== "ImportBinding") return undefined;
|
|
const declaration = definition.parent ?? definition.node.parent;
|
|
if (declaration?.source?.value !== "vitest") return undefined;
|
|
return definition.node;
|
|
};
|
|
|
|
/** Whether `node` is Vitest's `name` export: `name` or `vitest.name`. */
|
|
const isVitestExport = (sourceCode, node, name) => {
|
|
const target = unwrap(node);
|
|
if (target?.type === "Identifier") {
|
|
const specifier = vitestImport(sourceCode, target);
|
|
return (
|
|
specifier?.type === "ImportSpecifier" &&
|
|
(specifier.imported.name ?? specifier.imported.value) === name
|
|
);
|
|
}
|
|
return (
|
|
target?.type === "MemberExpression" &&
|
|
propertyName(target) === name &&
|
|
target.object?.type === "Identifier" &&
|
|
vitestImport(sourceCode, target.object)?.type === "ImportNamespaceSpecifier"
|
|
);
|
|
};
|
|
|
|
const isVitestMethod = (sourceCode, callee, receiver, method) => {
|
|
const member = unwrap(callee);
|
|
return (
|
|
member?.type === "MemberExpression" &&
|
|
propertyName(member) === method &&
|
|
isVitestExport(sourceCode, member.object, receiver)
|
|
);
|
|
};
|
|
|
|
/** A wait timeout written at the call: a number, or an options `timeout`. */
|
|
const explicitTimeout = (options) => {
|
|
if (options === undefined) return undefined;
|
|
if (options.type !== "ObjectExpression") return options;
|
|
return options.properties.find(
|
|
(property) =>
|
|
property.type === "Property" &&
|
|
!property.computed &&
|
|
(property.key.name ?? property.key.value) === "timeout",
|
|
);
|
|
};
|
|
|
|
export default {
|
|
meta: {
|
|
type: "problem",
|
|
docs: {
|
|
description:
|
|
"Keep test wait deadlines owned by the project test deadline policy.",
|
|
},
|
|
schema: [],
|
|
messages: {
|
|
viWaitFor:
|
|
"vi.waitFor defaults to a one-second host-speed guess; use waitFor from tests/support/testWait.ts, which the test deadline policy bounds.",
|
|
pollTimeout:
|
|
"The project owns expect.poll's deadline; remove this timeout. When promptness is the behavior under test, assert elapsed time or order the condition before a release gate instead.",
|
|
},
|
|
},
|
|
create(context) {
|
|
const sourceCode = context.sourceCode;
|
|
return {
|
|
CallExpression(node) {
|
|
if (isVitestMethod(sourceCode, node.callee, "vi", "waitFor")) {
|
|
context.report({ node, messageId: "viWaitFor" });
|
|
return;
|
|
}
|
|
if (!isVitestMethod(sourceCode, node.callee, "expect", "poll")) return;
|
|
const timeout = explicitTimeout(node.arguments[1]);
|
|
if (timeout !== undefined)
|
|
context.report({ node: timeout, messageId: "pollTimeout" });
|
|
},
|
|
};
|
|
},
|
|
};
|