Files
Jyotisha/frontend/tests/rectification-adopt-cards-stay-20260909.test.ts
T
Jesse_ChenandCursor 15cede97e7
Independent Staging Quality Gate / validate (push) Has been cancelled
Independent Staging Quality Gate / publish (push) Has been cancelled
fix(rectification): keep the adopt-card lock in state so lint can pass (BUG-622)
Writing selectionOfferLockRef during render tripped react-hooks/refs after the two contract tests went green. The lock now updates like seededTurns, and nextSelectionCardLock reuses the same object when the key is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-09 19:34:39 +08:00

59 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
const read = (relativePath: string) => readFileSync(new URL(relativePath, import.meta.url), "utf8");
const chat = read("../src/components/rectification-agentic-chat.tsx");
const delivery = read("../src/components/rectification-range-delivery.tsx");
const styles = read("../src/app/globals.css");
const showBlock = chat.slice(
chat.indexOf("const keepSelectionCardsWhileBusy"),
chat.indexOf("const showReadonlyRange"),
);
const messageLoop = chat.slice(
chat.indexOf("{messages.map((message) => {"),
chat.indexOf("{savedTime &&"),
);
test("clicking 更像这个 does not unmount the range card for busy", () => {
assert.match(showBlock, /acceptingCandidateId \|\| candidateResult\?\.selectedTime/);
assert.match(showBlock, /!busy \|\| keepSelectionCardsWhileBusy/);
assert.doesNotMatch(
showBlock,
/&& !busy\s*&& selectionCardMessageKey/,
);
});
test("after adopt the card stays on the locked offering message", () => {
assert.match(chat, /resolveSelectionCardMessageKey/);
assert.match(chat, /nextSelectionCardLock/);
// 原值:selectionOfferLockRef.current = nextSelectionCardLock(...)
// 新值:useState + 渲染期 setSelectionOfferLock(与 seededTurns 同一模式)
// 原因:react-hooks/refs 禁止渲染期读写 ref;门禁 lint 0 errorBUG-622
assert.match(chat, /const \[selectionOfferLock, setSelectionOfferLock\] = useState/);
assert.match(chat, /if \(nextOfferLock !== selectionOfferLock\) \{\s*setSelectionOfferLock\(nextOfferLock\);/);
assert.doesNotMatch(chat, /selectionOfferLockRef/);
assert.match(messageLoop, /showSelectionCards && candidateResult && message\.renderKey === selectionCardMessageKey/);
});
test("the closing line sits under the card on the assistant column", () => {
assert.match(messageLoop, /verifiedIdleCopy && \(/);
assert.match(messageLoop, /className="rectification-pending-note"/);
assert.match(
chat,
/questionGap === "verified_idle" && verifiedIdleCopy && !showSelectionCards/,
);
assert.match(
styles,
/\.rectification-pending-note \{[\s\S]*margin-inline-start: var\(--assistant-content-inset\)/,
);
assert.doesNotMatch(chat, /rectification-adopt-status/);
});
test("the adopted column button is pressed and disabled; others stay 更像这个", () => {
assert.match(delivery, /disabled=\{busy \|\| adopted\}/);
assert.match(delivery, /rangeDeliveryAdopted/);
assert.match(delivery, /rangeDeliveryMoreLikeThis/);
});