From 42001762396b7fdb1b8eb5c338ccea189e906f88 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 27 Oct 2026 11:54:05 +0700 Subject: [PATCH] test(addin): convert crash-repro suite to permanent ticket-auth flow tests Rename tests/wordaddin/ticket-auth-crash-repro.test.ts to ticket-auth-flow.test.ts and strip the temporary [DBG-r3p1] markers. The debug session closed with an environment cause (stale Next server holding the port / corrupted .next chunks), not a code defect, so the suite stays as regression coverage for the signInWithTicket service layer: single token fetch per fid, token reuse on reopen without re-hitting /token, memory-fallback session teardown, and no uncaught throw/rejection on every failure path (missing/invalid ticket, expired ticket, server 401, webview without crypto.subtle). Co-Authored-By: Claude Code --- ...h-crash-repro.test.ts => ticket-auth-flow.test.ts} | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) rename tests/wordaddin/{ticket-auth-crash-repro.test.ts => ticket-auth-flow.test.ts} (86%) diff --git a/tests/wordaddin/ticket-auth-crash-repro.test.ts b/tests/wordaddin/ticket-auth-flow.test.ts similarity index 86% rename from tests/wordaddin/ticket-auth-crash-repro.test.ts rename to tests/wordaddin/ticket-auth-flow.test.ts index abecb22..250a5fa 100644 --- a/tests/wordaddin/ticket-auth-crash-repro.test.ts +++ b/tests/wordaddin/ticket-auth-flow.test.ts @@ -1,14 +1,15 @@ // @vitest-environment jsdom -// [DBG-r3p1] repro ชั่วคราว — หา client-side crash ของ taskpane หลัง implement ticket auth -// (ไม่ใช่ regression test ถาวร — ถอดทิ้งเมื่อหาสาเหตุเจอแล้ว; import .tsx ไม่ได้ใน vitest ปัจจุบัน -// จึงโฟกัส service layer ที่เป็นโค้ดใหม่ทั้งหมด — component repro ใช้ Chrome headless แทน) +// ticket auth ของ add-in (PLAN-ADDIN-AUTH.md §5) — คุมพฤติกรรม service layer: +// happy-path ขอ token ครั้งเดียวต่อ fid, เปิดเอกสารเดิมซ้ำใช้ token เดิมไม่ยิง /token ซ้ำ, +// memory fallback ของ session, และทุก fail path ต้องคืน result ไม่ใช่ throw +// (jsdom ไม่มี crypto.subtle — ฉีด webcrypto ของ node แทน secure context ของ webview จริง) import { createHmac, webcrypto } from "node:crypto"; import { afterEach, describe, expect, it, vi } from "vitest"; import * as authService from "@/wordaddin/services/authService"; import * as ticketService from "@/wordaddin/services/ticketService"; -// จับ error ทุกทางที่จะกลายเป็น "Application error: a client-side exception" บน Next +// จับ error ทุกทาง (window error / unhandled rejection) — flow ต้องไม่ปล่อยอะไรหลุดเลย const errors: unknown[] = []; function trapErrors() { window.addEventListener("error", (event) => errors.push(event.error ?? event.message)); @@ -38,7 +39,7 @@ afterEach(() => { errors.length = 0; }); -describe("[DBG-r3p1] ticket auth crash repro (service layer)", () => { +describe("signInWithTicket (service layer)", () => { it("B: signInWithTicket happy-path (มี crypto.subtle + fetch ตอบ 200) ไม่ต้อง throw", async () => { trapErrors(); // jsdom ไม่มี crypto.subtle — ใส่ webcrypto ของ node แทน (secure context ของ webview จริงมีอยู่แล้ว)