Files
agent-desk-ng/web/lib/session-request-guard.test.mjs
mono 2f7a491666 feat: harden support, localize knowledge and add operator availability [skip ci]
Source-only publication of reviewed commit 64e96a7f423673dc29ad56485be9fc79bce8af1c.

Passed in isolation: focused frontend/backend tests, race checks, TypeScript typecheck, lint, Go compilation, Flowgram build, and deterministic SDK build/tests.

Not accepted as a production release: Next.js export/native assembly remains blocked by environment memory limits; browser interaction and MySQL staging acceptance remain unverified. No production server, database/schema, runtime configuration, deployment, release tag, or workflow execution was performed.

Expected source tree: 0a4a7528e9.
2026-10-16 15:21:42 +00:00

33 lines
1.3 KiB
JavaScript

import assert from "node:assert/strict"
import test from "node:test"
import { createSessionRequestGuard, isSameSession } from "./session-request-guard.ts"
const account = (id, accessToken) => ({ user: { id }, accessToken })
test("late profile success, error, and finally are stale after sign-out", () => {
let current = account(1, "test-session-a")
const guard = createSessionRequestGuard(() => current)
const isCurrent = guard.begin(current)
current = null
assert.equal(isCurrent(), false)
})
test("old account and rotated-token responses cannot clear the current session", () => {
const previous = account(1, "test-session-a")
assert.equal(isSameSession(previous, account(2, "test-session-b")), false)
assert.equal(isSameSession(previous, account(1, "test-session-rotated")), false)
assert.equal(isSameSession(null, account(1, "test-session-a")), false)
assert.equal(isSameSession(previous, previous), true)
})
test("only the latest profile request can commit, including same-token requests", () => {
const current = account(1, "test-session-a")
const guard = createSessionRequestGuard(() => current)
const first = guard.begin(current)
const second = guard.begin(current)
assert.equal(first(), false)
assert.equal(second(), true)
guard.invalidate()
assert.equal(second(), false)
})