Initial import of streamline
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
// MUST be first: sets DATABASE_URL before db_client is evaluated.
|
||||
import "./setup_env";
|
||||
|
||||
import { test, expect, describe } from "bun:test";
|
||||
import { reviewCardMissing } from "../src/notify_reconcile";
|
||||
import { REVIEW_CARD_MAX_WAIT_MS } from "../src/notify";
|
||||
|
||||
/**
|
||||
* The whole decision the resend sweep makes. Both directions are expensive:
|
||||
* a false "missing" spams a group chat every five minutes, a false "delivered"
|
||||
* leaves a reviewer permanently untold — which is what actually happened.
|
||||
*/
|
||||
describe("notify-reconcile: was a card sent for THIS review entry", () => {
|
||||
const MORNING = Date.parse("2026-08-19T07:24:26-07:00");
|
||||
const NIGHT = Date.parse("2026-08-20T01:28:24-07:00");
|
||||
|
||||
test("no card record at all → missing (the first-round loss the sweep shipped for)", () => {
|
||||
expect(reviewCardMissing(undefined, NIGHT)).toBe(true);
|
||||
});
|
||||
|
||||
test("card older than the entry → missing, even though a key exists", () => {
|
||||
// b5de5e19: round 3's card was remembered on the 19th, round 4 entered
|
||||
// review on the 20th and lost its card to a one-second node drop. Key
|
||||
// existence said "delivered" and nobody was ever told.
|
||||
expect(reviewCardMissing(MORNING, NIGHT)).toBe(true);
|
||||
});
|
||||
|
||||
test("card written after the entry → delivered", () => {
|
||||
// The card lands some time after the transition — since review cards started
|
||||
// waiting for the readable report, up to REVIEW_CARD_MAX_WAIT_MS later.
|
||||
expect(reviewCardMissing(NIGHT + 2_800, NIGHT)).toBe(false);
|
||||
});
|
||||
|
||||
test("an EARLIER entry still in the window is not re-announced once a later round notified", () => {
|
||||
// Round 3's own card may well have been lost, but round 4 has since told
|
||||
// everyone; resending round 3's would be noise about a superseded state.
|
||||
expect(reviewCardMissing(NIGHT, MORNING)).toBe(false);
|
||||
});
|
||||
|
||||
test("same millisecond counts as delivered", () => {
|
||||
// rememberSentCards stamps after the sends return, so it can only tie, never
|
||||
// precede. A tie must not be read as a loss.
|
||||
expect(reviewCardMissing(NIGHT, NIGHT)).toBe(false);
|
||||
});
|
||||
|
||||
test("a zero entry time (no transition row, no statusChangedAt) never fabricates a resend", () => {
|
||||
expect(reviewCardMissing(MORNING, 0)).toBe(false);
|
||||
// …but an item with no card at all is still worth one.
|
||||
expect(reviewCardMissing(undefined, 0)).toBe(true);
|
||||
});
|
||||
|
||||
/**
|
||||
* 从「卡片等报告就绪」上线之后加的一档。
|
||||
*
|
||||
* 复核卡片现在最多会被 notify.ts 压住 REVIEW_CARD_MAX_WAIT_MS,好让这一批的可读性
|
||||
* 报告有时间生成完。在这条扫描眼里,一个正在等待中的条目和一个通知丢了的条目长得
|
||||
* 完全一样:处于复核中、没有卡片记录。没有年龄下限的话,它会在等待途中「补发」一张,
|
||||
* 于是复核人收到两张 —— 一张扫描发的光板卡片,一张等待结束后发的完整卡片。
|
||||
*/
|
||||
describe("最小年龄:等待中的条目不算丢", () => {
|
||||
const T0 = Date.parse("2026-08-22T14:47:27+08:00");
|
||||
const MIN_AGE = 20 * 60_000; // 默认 = 15 分钟等待 + 5 分钟余量
|
||||
|
||||
test("刚进复核、还没有卡片 —— 是在等,不是丢了", () => {
|
||||
expect(reviewCardMissing(undefined, T0, T0 + 30_000, MIN_AGE)).toBe(false);
|
||||
expect(reviewCardMissing(undefined, T0, T0 + 5 * 60_000, MIN_AGE)).toBe(false);
|
||||
});
|
||||
|
||||
test("过了下限还没有卡片 —— 这才是真的丢了", () => {
|
||||
expect(reviewCardMissing(undefined, T0, T0 + MIN_AGE + 1, MIN_AGE)).toBe(true);
|
||||
});
|
||||
|
||||
test("下限对「卡片比条目旧」这一档同样生效", () => {
|
||||
// 上一批的卡片记录还在,这一批刚进复核 —— 仍然可能只是在等。
|
||||
const prevRoundCard = T0 - 3600_000;
|
||||
expect(reviewCardMissing(prevRoundCard, T0, T0 + 60_000, MIN_AGE)).toBe(false);
|
||||
expect(reviewCardMissing(prevRoundCard, T0, T0 + MIN_AGE + 1, MIN_AGE)).toBe(true);
|
||||
});
|
||||
|
||||
test("下限必须比等待上限宽 —— 否则扫描会和等待赛跑", () => {
|
||||
// 这是整档的存在理由,写成断言以免有人把余量调没了。
|
||||
expect(MIN_AGE).toBeGreaterThan(REVIEW_CARD_MAX_WAIT_MS);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user