mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-27 02:14:30 +01:00
fix(design-motion): third review cycle and adversarial findings
- capture: an ownership marker (.gstack-motion-capture) replaces the capture.json test, so the rerun after MOTION_CONTRACT_MISSING or a crash works and a foreign --out is still refused; offscreen lazy images are made eager and font/image loading is bounded at 30 s instead of hanging - encode: refuse a capture.json whose fields are not what capture writes (they reach ffmpeg args and paths); a cards overflow with no story frames is a planning error, and a zero-frame job never passes - tests: retry after a refused page, no-mask clean line, lazy image still, manifest validator, empty story span Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
c7ec40bc19
commit
fb1a8f8d37
6 files changed
+95
-18
No files matched your search
@@ -4,7 +4,7 @@ import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { clockMs, planCapture } from '../lib/motion-capture';
|
||||
import {
|
||||
compareArgs, contactSheetArgs, cropError, judgeCheck, loopGifArgs, mp4Args, padError, parsePsnrStats, planChecks, psnrArgs,
|
||||
compareArgs, contactSheetArgs, cropError, judgeCheck, loopGifArgs, manifestError, mp4Args, padError, parsePsnrStats, planChecks, psnrArgs,
|
||||
resolveFfmpeg, smallGifArgs, FFMPEG_MISSING, type CaptureManifest, type CheckJob, type CheckOptions,
|
||||
} from '../lib/motion-encode';
|
||||
|
||||
@@ -157,6 +157,30 @@ describe('PSNR parsing and verdicts', () => {
|
||||
const v = judgeCheck({ ...job, expected: 23 }, parsePsnrStats(STATS.replace('psnr_avg:46.28', 'psnr_avg:inf')));
|
||||
expect(v.pass).toBe(false);
|
||||
expect(v.line).toContain('compared 3 of 23 frames');
|
||||
expect(judgeCheck({ ...job, expected: 0 }, []).pass).toBe(false);
|
||||
});
|
||||
|
||||
// Value: protects=phase overrides that leave no story frame refuse the check instead of passing overflow on zero frames;
|
||||
// fails_when=the empty-span guard is dropped and overflow reports pass for 'story frames undefined-undefined'; why_new=new guard; seam=none;
|
||||
// no_claim=planning only
|
||||
test('a cards overflow with no story frames is a planning error', () => {
|
||||
const r = planChecks(manifest(), '/c', { ...OPTS, introEnd: 10.99, dissolveAt: 11 });
|
||||
expect(r).toEqual({ error: 'no window frame lies between intro-end and dissolve-at, so overflow has no story frames to check' });
|
||||
});
|
||||
|
||||
// Value: protects=a capture.json this tool did not write cannot put text into ffmpeg filter graphs or paths outside the capture dir;
|
||||
// fails_when=a field check is dropped and a string windowFrames or a ../ still reaches the encoder; why_new=new validator; seam=none;
|
||||
// no_claim=validator only; the bin calls it before building any job
|
||||
test('a capture manifest is checked before its fields reach ffmpeg', () => {
|
||||
expect(manifestError(manifest())).toBeNull();
|
||||
expect(manifestError(manifest(12, false))).toBeNull();
|
||||
expect(manifestError({ ...manifest(), schema: 2 })).toContain('schema 1');
|
||||
expect(manifestError({ ...manifest(), windowFrames: '60,metadata=mode=print' })).toContain('windowFrames must be a non-negative integer');
|
||||
expect(manifestError({ ...manifest(), cycle: 0 })).toContain('cycle must be a positive number');
|
||||
expect(manifestError({ ...manifest(), clockMs: [0] })).toContain('one number per frame');
|
||||
expect(manifestError({ ...manifest(), still: '../still.png' })).toContain('still must be a .png file name');
|
||||
expect(manifestError({ ...manifest(), mask: 'mask.png,hue=s=0' })).toContain('mask must be a .png file name');
|
||||
expect(manifestError(null)).toContain('schema 1');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -53,10 +53,10 @@ function run(argv: string[]) {
|
||||
return { code: r.exitCode, out: r.stdout.toString(), err: r.stderr.toString() };
|
||||
}
|
||||
|
||||
function capture(dir: string, html: string) {
|
||||
function capture(dir: string, html: string, o: { mask?: boolean } = {}) {
|
||||
const file = path.join(dir, 'page.html');
|
||||
fs.writeFileSync(file, html);
|
||||
return run([CAPTURE, file, '--size', '640x100', '--cycle', '0.5', '--out', path.join(dir, 'cap'), '--mask', '.card']);
|
||||
return run([CAPTURE, file, '--size', '640x100', '--cycle', '0.5', '--out', path.join(dir, 'cap'), ...(o.mask === false ? [] : ['--mask', '.card'])]);
|
||||
}
|
||||
|
||||
describe.skipIf(!READY)('design-motion pipeline on real Chromium and ffmpeg', () => {
|
||||
@@ -129,8 +129,8 @@ describe.skipIf(!READY)('design-motion pipeline on real Chromium and ffmpeg', ()
|
||||
// Value: protects=a page without window.__start/__tick stops with MOTION_CONTRACT_MISSING and exit 1 before writing capture.json;
|
||||
// fails_when=the contract probe is dropped and frames of an unanimated page are recorded as a capture; why_new=no test loads a page in the capture bin; seam=none;
|
||||
// no_claim=only the missing-contract case; a contract that throws mid-capture is not exercised
|
||||
// The same capture dir, pre-filled first with a foreign still.png and then with a previous capture's files, checks that
|
||||
// a capture refuses a dir that is not a previous capture and clears a previous capture's manifest before it can fail.
|
||||
// The same --out also checks ownership: a foreign still.png is refused and kept, the retry after a refused page succeeds
|
||||
// (here without a mask, so check ends 'clean (overflow not checked)'), and a later failed capture clears that manifest.
|
||||
test('a page without the capture contract is refused', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'motion-pipeline-'));
|
||||
try {
|
||||
@@ -139,15 +139,42 @@ describe.skipIf(!READY)('design-motion pipeline on real Chromium and ffmpeg', ()
|
||||
fs.writeFileSync(path.join(cap, 'still.png'), 'not ours');
|
||||
const foreign = capture(dir, page({ loops: true, contract: false }));
|
||||
expect(foreign.code).toBe(2);
|
||||
expect(foreign.err).toContain('already holds still.png but no capture.json');
|
||||
expect(foreign.err).toContain('already holds still.png but no .gstack-motion-capture marker');
|
||||
expect(fs.readFileSync(path.join(cap, 'still.png'), 'utf-8')).toBe('not ours');
|
||||
fs.writeFileSync(path.join(cap, 'capture.json'), '{}');
|
||||
fs.rmSync(path.join(cap, 'still.png'));
|
||||
|
||||
const c = capture(dir, page({ loops: true, contract: false }));
|
||||
expect(c.code).toBe(1);
|
||||
expect(c.err).toContain('MOTION_CONTRACT_MISSING');
|
||||
const retry = capture(dir, page({ loops: true }), { mask: false });
|
||||
expect(retry.code, retry.err).toBe(0);
|
||||
expect(retry.out).toContain('CAPTURE_OK frames=54');
|
||||
const check = run([ENCODE, 'check', cap, ...PHASES]);
|
||||
expect(check.code, check.out + check.err).toBe(0);
|
||||
expect(check.out).toContain('MOTION_CHECK: overflow skipped');
|
||||
expect(check.out.trim().split('\n').pop()).toBe('MOTION_RESULT: clean (overflow not checked)');
|
||||
|
||||
expect(capture(dir, page({ loops: true, contract: false })).code).toBe(1);
|
||||
expect(fs.existsSync(path.join(cap, 'capture.json')) || fs.existsSync(path.join(cap, 'still.png'))).toBe(false);
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
}, 120_000);
|
||||
}, 240_000);
|
||||
|
||||
// Value: protects=an offscreen loading=lazy image no longer hangs the still render (img.decode() never settles on it);
|
||||
// fails_when=the eager switch and the 30 s bound are both dropped and --still waits forever; why_new=adversarial probe hung at 90 s; seam=none;
|
||||
// no_claim=one lazy image on a local page; a slow network image is bounded only by the 30 s timer
|
||||
test('a page with an offscreen lazy image renders its still', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'motion-pipeline-'));
|
||||
try {
|
||||
fs.writeFileSync(path.join(dir, 'dot.png'), Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==', 'base64'));
|
||||
const file = path.join(dir, 'lazy.html');
|
||||
fs.writeFileSync(file, '<!doctype html><body style="margin:0"><div style="height:5000px"></div><img loading="lazy" src="dot.png" width="4" height="4"></body>');
|
||||
const still = run([CAPTURE, file, '--size', '640x100', '--still', path.join(dir, 'still.png')]);
|
||||
expect(still.code, still.err).toBe(0);
|
||||
expect(still.err).not.toContain('still loading');
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
}, 200_000);
|
||||
});
|
||||
Reference in new issue
Block a user