import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { createTestSession } from "@polkadot-apps/terminal/testing";
import { createTerminalAdapter, waitForSessions } from "@polkadot-apps/terminal";
const storageDir = mkdtempSync(join(tmpdir(), "e2e-"));
const { sessionId } = await createTestSession({ appId: "dot-cli", storageDir });
const adapter = createTerminalAdapter({ appId: "dot-cli", metadataUrl: "…", storageDir });
const sessions = await waitForSessions(adapter);
// sessions[0].id === sessionId
Write a valid persisted session to
storageDir, as if the user had completed QR pairing + attestation. ATerminalAdaptercreated with the sameappId+storageDirwill emit the synthesized session fromadapter.sessions.sessions.Limits
session.signRawstill goes out over the statement store and expects a real phone to respond. Use this helper for flows that test session discovery, persistence, and logout — not end-to-end signing.NoAllowanceError. The synthesized local account was never registered on the People chain, so the first write to the statement store fails withNoAllowanceError. That's the same error path the CLI sees when a previously valid session's on-chain attestation has expired, so tests that assert "CLI handles an expired session" can be written against a synthesized session even though there's noexpiresAtknob to turn.expiresAt. The on-disk codec has no expiry field; validity is tracked via on-chain attestation state. See above for how expiry-path tests still work in practice.<storageDir>/<appId>_SsoSessions.jsonwithfs.writeFiledirectly.SsoSessionsfile, so calling twice on the samestorageDir+appIdleaves only the second session on disk. Use a freshmkdtempSyncper test to keep cases isolated.