Files
openclaw/src/infra/warning-filter.test.ts
T
Tyler Yust 07375a65d8 fix(cron): recover flat params when LLM omits job wrapper (#12124)
* fix(cron): recover flat params when LLM omits job wrapper (#11310)

Non-frontier models (e.g. Grok) flatten job properties to the top level
alongside `action` instead of nesting them inside the `job` parameter.
The opaque schema (`Type.Object({}, { additionalProperties: true })`)
gives these models no structural hint, so they put name, schedule,
payload, etc. as siblings of action.

Add a flat-params recovery step in the cron add handler: when
`params.job` is missing or an empty object, scan for recognised job
property names on params and construct a synthetic job object before
passing to `normalizeCronJobCreate`. Recovery requires at least one
meaningful signal field (schedule, payload, message, or text) to avoid
false positives.

Added tests:
- Flat params with no job wrapper → recovered
- Empty job object + flat params → recovered
- Message shorthand at top level → inferred as agentTurn
- No meaningful fields → still throws 'job required'
- Non-empty job takes precedence over flat params

* fix(cron): floor nowMs to second boundary before croner lookback

Cron expressions operate at second granularity. When nowMs falls
mid-second (e.g. 12:00:00.500) and the pattern targets that exact
second (like '0 0 12 * * *'), a 1ms lookback still lands inside the
matching second.  Croner interprets this as 'already past' and skips
to the next occurrence (e.g. the following day).

Fix: floor nowMs to the start of the current second before applying
the 1ms lookback.  This ensures the reference always falls in the
*previous* second, so croner correctly identifies the current match.

Also compare the result against the floored nowSecondMs (not raw nowMs)
so that a match at the start of the current second is not rejected by
the >= guard when nowMs has sub-second offset.

Adds regression tests for 6-field cron patterns with specific seconds.

* fix: add changelog entries for cron fixes (#12124) (thanks @tyler6204)

* test: stabilize warning filter emit assertion (#12124) (thanks @tyler6204)
2026-02-08 23:10:09 -08:00

84 lines
2.6 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { installProcessWarningFilter, shouldIgnoreWarning } from "./warning-filter.js";
const warningFilterKey = Symbol.for("openclaw.warning-filter");
const baseEmitWarning = process.emitWarning.bind(process);
function resetWarningFilterInstallState(): void {
const globalState = globalThis as typeof globalThis & {
[warningFilterKey]?: { installed: boolean };
};
delete globalState[warningFilterKey];
process.emitWarning = baseEmitWarning;
}
describe("warning filter", () => {
beforeEach(() => {
resetWarningFilterInstallState();
});
afterEach(() => {
resetWarningFilterInstallState();
vi.restoreAllMocks();
});
it("suppresses known deprecation and experimental warning signatures", () => {
expect(
shouldIgnoreWarning({
name: "DeprecationWarning",
code: "DEP0040",
message: "The punycode module is deprecated.",
}),
).toBe(true);
expect(
shouldIgnoreWarning({
name: "DeprecationWarning",
code: "DEP0060",
message: "The `util._extend` API is deprecated.",
}),
).toBe(true);
expect(
shouldIgnoreWarning({
name: "ExperimentalWarning",
message: "SQLite is an experimental feature and might change at any time",
}),
).toBe(true);
});
it("keeps unknown warnings visible", () => {
expect(
shouldIgnoreWarning({
name: "DeprecationWarning",
code: "DEP9999",
message: "Totally new warning",
}),
).toBe(false);
});
it("installs once and suppresses known warnings at emit time", async () => {
const baseEmitSpy = vi.spyOn(process, "emitWarning").mockImplementation(() => undefined);
installProcessWarningFilter();
installProcessWarningFilter();
installProcessWarningFilter();
const emitWarning = (...args: unknown[]) =>
(process.emitWarning as unknown as (...warningArgs: unknown[]) => void)(...args);
emitWarning(
"The `util._extend` API is deprecated. Please use Object.assign() instead.",
"DeprecationWarning",
"DEP0060",
);
emitWarning("The `util._extend` API is deprecated. Please use Object.assign() instead.", {
type: "DeprecationWarning",
code: "DEP0060",
});
await new Promise((resolve) => setImmediate(resolve));
expect(baseEmitSpy).not.toHaveBeenCalled();
emitWarning("Visible warning", { type: "Warning", code: "OPENCLAW_TEST_WARNING" });
await new Promise((resolve) => setImmediate(resolve));
expect(baseEmitSpy).toHaveBeenCalledTimes(1);
});
});