Files
arboretum/packages/web/test/ws-client.test.ts
Johan LEROY 65ef616867
Some checks failed
CI / Build & test (Node 24) (push) Has been cancelled
CI / Pack & boot smoke (Node 22) (push) Has been cancelled
CI / No em/en dashes (push) Has been cancelled
CI / Build & test (Node 22) (push) Has been cancelled
Deploy site (production) / build-and-deploy (push) Successful in 20s
chore(typo): retire tous les tirets cadratins/demi-cadratins + garde CI
Remplace les 547 tirets cadratins (U+2014) et demi-cadratins (U+2013) des fichiers versionnés par la ponctuation contextuelle adaptée (point médian, deux-points, virgule, parenthèses ; tiret simple pour les plages), sur 122 fichiers (appli, vitrine, doc, tests, workflows, scripts).

Ajoute le job CI « lint-dashes » (git grep -P) qui échoue si un tiret cadratin/demi-cadratin réapparaît, hors logo binaire et captures brutes du terminal (fidélité des fixtures de détection de dialogue).
2026-07-17 16:44:00 +02:00

54 lines
2.0 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.
// Flush ACK ciblé (Attachment.flushAck) : relance un PTY mis en pause au retour-visible d'une cellule.
// On teste la logique d'ACK sans WebSocket réel (sendControl est public → stubbable).
import { describe, it, expect, vi } from 'vitest';
import { WsClient, Attachment, type TerminalSink } from '../src/lib/ws-client';
const sink: TerminalSink = {
write: () => {},
reset: () => {},
onDetached: () => {},
onControlChanged: () => {},
};
describe('ws-client · flush ACK ciblé (Attachment.flushAck)', () => {
it('envoie un unique ACK cumulatif du reliquat traité, puis est idempotent', () => {
const client = new WsClient();
const send = vi.spyOn(client, 'sendControl').mockImplementation(() => {});
const att = new Attachment(client, 'sid', 'interactive', sink, 80, 24);
att.channel = 2;
att.processedBytes = 1000;
att.flushAck();
expect(send).toHaveBeenCalledTimes(1);
expect(send).toHaveBeenCalledWith({ type: 'ack', channel: 2, bytes: 1000 });
expect(att.lastAckBytes).toBe(1000);
// rien de neuf traité → aucun ACK supplémentaire (n'ACK QUE du réellement traité)
att.flushAck();
expect(send).toHaveBeenCalledTimes(1);
// nouveau reliquat traité → ACK cumulatif mis à jour
att.processedBytes = 1500;
att.flushAck();
expect(send).toHaveBeenCalledTimes(2);
expect(send).toHaveBeenLastCalledWith({ type: 'ack', channel: 2, bytes: 1500 });
});
it('no-op si le canal nest pas attaché (-1) ou si lattachment est fermé', () => {
const client = new WsClient();
const send = vi.spyOn(client, 'sendControl').mockImplementation(() => {});
const notAttached = new Attachment(client, 'a', 'interactive', sink, 80, 24); // channel = -1
notAttached.processedBytes = 500;
notAttached.flushAck();
const closed = new Attachment(client, 'b', 'interactive', sink, 80, 24);
closed.channel = 3;
closed.processedBytes = 500;
closed.closed = true;
closed.flushAck();
expect(send).not.toHaveBeenCalled();
});
});