feat(fix-a3): rename TransferredVideoChunk → TransferredVideoSegment

Pure rename pass — zero behavioural change at any call site. The
prior "chunk" naming is a vestige of D-09..D-11's chunk-level
buffer; under D-13 the unit of transfer is a self-contained ~10 s
WebM segment, so the type name now matches the data shape.

Renames propagated atomically:
- src/shared/types.ts
  * TransferredVideoChunk → TransferredVideoSegment
    (also: the `isFirst?: boolean` field is dropped — D-13 segments
    are all implicitly their own header, so the flag is meaningless
    and only existed for the retired ring-buffer's pin semantics)
  * VideoChunk → VideoSegment (drops `isFirst?` for the same reason)
  * PortMessage.chunks? → PortMessage.segments?
  * VideoBufferResponse.chunks → VideoBufferResponse.segments
- src/offscreen/recorder.ts
  * import type rename
  * encodeAndSendBuffer's per-element accumulator + filter type
  * the port.postMessage payload field
- src/background/index.ts
  * import type rename
  * getVideoBufferFromOffscreen reads `(msg as {segments?}).segments`
    (matching the new wire field name)
  * empty-buffer returns `{ segments: [] }`
  * mergeVideoSegments signature takes VideoSegment[]
  * createArchive consumes videoBufferResponse.segments
  * saveArchive log line says "segments"

Verification:
- npx tsc --noEmit clean.
- npx vitest run → 28 passed / 2 failed (the 2 fixture-empirical
  ffmpeg dry-runs; unchanged — they're gated on ./smoke.sh regen).
- npm run build succeeds, all 60 modules transformed.
- grep predicates clean in src/:
  * no addChunk / trimAged / firstChunkSaved / isFirst
  * no TransferredVideoChunk / VideoChunk (old names)
  * 21 occurrences of new names propagated correctly
- Pre-existing port-serialization.test.ts still GREEN: its `isFirst`
  references are inside inline-test-scoped objects (not imports
  from production types), and its tests assert JSON-roundtrip
  behaviour rather than the production type shape.
This commit is contained in:
2026-05-15 21:15:19 +02:00
parent 670daa3fe8
commit f81438d6c8
3 changed files with 49 additions and 46 deletions

View File

@@ -16,7 +16,7 @@
import { OffscreenLogger } from '../shared/logger';
import { blobToBase64 } from '../shared/binary';
import type { Message, TransferredVideoChunk } from '../shared/types';
import type { Message, TransferredVideoSegment } from '../shared/types';
// ─── Константы (per CON-video-codec, CON-video-window, D-13) ────────────
// Длительность одного сегмента — 10 с (D-13, RESEARCH.md Pattern 3).
@@ -355,7 +355,7 @@ async function encodeAndSendBuffer(): Promise<void> {
// (например, неожиданный detach ArrayBuffer-а на лету), логируем и
// пропускаем — частичное видео > отсутствующее видео.
const encodeResults = await Promise.all(
allSegments.map(async (segment, idx): Promise<TransferredVideoChunk | null> => {
allSegments.map(async (segment, idx): Promise<TransferredVideoSegment | null> => {
try {
const data = await blobToBase64(segment);
return {
@@ -376,15 +376,15 @@ async function encodeAndSendBuffer(): Promise<void> {
}
}),
);
const transferred: TransferredVideoChunk[] = encodeResults.filter(
(c): c is TransferredVideoChunk => c !== null,
const transferred: TransferredVideoSegment[] = encodeResults.filter(
(c): c is TransferredVideoSegment => c !== null,
);
// Re-check port AFTER the await: it may have disconnected during encoding.
if (keepalivePort === null) {
logger.warn('port disconnected during base64 encoding; dropping BUFFER response');
return;
}
keepalivePort.postMessage({ type: 'BUFFER', chunks: transferred });
keepalivePort.postMessage({ type: 'BUFFER', segments: transferred });
}
function connectPort(): void {