Files
videoreg.ru/scripts/rebuild-v2/check-raster-sharp.mjs
T
2026-10-26 19:08:48 +03:00

23 lines
1.2 KiB
JavaScript

/** Real positive and truncated-image failure behavior, using only temp fixtures. */
import assert from 'node:assert/strict';
import { mkdtemp, writeFile, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import sharp from 'sharp';
import { decodeBatch } from './decode-raster-sharp.mjs';
const root = await mkdtemp(join(tmpdir(), 'videoreg-v2-raster-fixture-'));
try {
const good = await sharp({ create: { width: 64, height: 32, channels: 3, background: '#17382f' } }).png().toBuffer();
await writeFile(join(root, 'good.png'), good);
await writeFile(join(root, 'truncated.png'), good.subarray(0, 32));
const report = await decodeBatch({ root, files: ['good.png', 'truncated.png'] });
assert.equal(report.results[0].valid, true, 'Valid PNG must decode all pixels');
assert.equal(report.results[0].width, 64);
assert.equal(report.results[0].height, 32);
assert.equal(report.results[1].valid, false, 'Truncated PNG must fail, not be skipped or treated as metadata-only pass');
process.stdout.write(JSON.stringify({ test: 'full-raster-decode-positive-and-corruption', status: 'passed', results: report.results }) + '\n');
} finally {
await rm(root, { recursive: true, force: true });
}