test: fixed flaky tests by using relative timestamps and palette-agnostic regex
- Replaced fixed calendar timestamps with `minutesAgo()` so beam-store items stay within the 24h working-memory TTL. - Broadened background-color assertion to match both truecolor (`48;2;`) and 256-palette (`48;5;`) terminals.
This commit is contained in:
@@ -36,9 +36,11 @@ describe("renderSegmentTrack", () => {
|
||||
|
||||
it("fills exactly the active segment as a bold chip with a background", () => {
|
||||
const raw = renderSegmentTrack(SEGMENTS, 1);
|
||||
// One filled chip: a single bold run and a single background fill.
|
||||
// One filled chip: a single bold run and a single background fill. The bg
|
||||
// introducer is `48;2;` on truecolor terminals and `48;5;` on 256-palette
|
||||
// ones (CI), so match the palette-agnostic `\x1b[48;` prefix.
|
||||
expect(raw.match(/\x1b\[1m/g)?.length).toBe(1);
|
||||
expect(raw.match(/48;2;/g)?.length).toBe(1);
|
||||
expect(raw.match(/\x1b\[48;/g)?.length).toBe(1);
|
||||
// The active label sits inside the bold run, and the fill is its own accent.
|
||||
expect(raw).toContain("\x1b[1m default \x1b[22m");
|
||||
const activeBg = theme.getFgAnsi("success").replace("\x1b[38;", "\x1b[48;");
|
||||
|
||||
@@ -101,17 +101,21 @@ describe("beam store free functions", () => {
|
||||
|
||||
it("batch remembers items and returns context ordered by global scope, importance, then recency", () => {
|
||||
const beam = makeState();
|
||||
// Timestamps must stay inside the 24h working-memory TTL or trimWorkingMemory
|
||||
// drops them, so anchor them to "now" rather than a fixed (and eventually
|
||||
// stale) calendar date. Order: low-priority oldest, global, high newest.
|
||||
const minutesAgo = (n: number) => new Date(Date.now() - n * 60_000).toISOString();
|
||||
const ids = rememberBatch(
|
||||
beam,
|
||||
[
|
||||
{ content: "Local low priority", importance: 0.1, timestamp: "2026-05-30T00:00:00.000Z" },
|
||||
{ content: "Local low priority", importance: 0.1, timestamp: minutesAgo(3) },
|
||||
{
|
||||
content: "Global rule always include",
|
||||
importance: 0.2,
|
||||
scope: "global",
|
||||
timestamp: "2026-05-30T00:01:00.000Z",
|
||||
timestamp: minutesAgo(2),
|
||||
},
|
||||
{ content: "Local high priority", importance: 0.9, timestamp: "2026-05-30T00:02:00.000Z" },
|
||||
{ content: "Local high priority", importance: 0.9, timestamp: minutesAgo(1) },
|
||||
],
|
||||
{ veracity: "imported" },
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user