gitoria
All repositories: gitoria
20.8 KB
// tests/limits.mjs — GATE OF THE APPS API's LIMITS AND READS (gitoria#47, contract docs/apps-api.md v1.3 §4–§6): the status read route (all apps' contexts, 404),// pull.statuses / pull.required, the tickets list, 413 / 400 on every write route, the rate limit (300 reads / 60 writes per minute per app by default; low values by env// GITORIA_LIMIT_READS / _WRITES / _WINDOW_MS in the second run; reads and writes counted apart, apps apart, a bad token not counted, a restart starts at zero).// node tests/limits.mjs (GITORIA_LIMITS_PORT default 8734, GITORIA_LIMITS_IDENT_PORT default 8735)import { spawn, spawnSync, execFileSync } from 'node:child_process';import { request } from 'node:http';import { mkdirSync, rmSync, writeFileSync, existsSync } from 'node:fs';import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { startIdent } from './identkit.mjs';const HERE = dirname(fileURLToPath(import.meta.url));const APP = resolve(HERE, '..');const PORT = Number(process.env.GITORIA_LIMITS_PORT || 8734), IDENT_PORT = Number(process.env.GITORIA_LIMITS_IDENT_PORT || 8735);const IDENT_DIR = process.env.GITORIA_GATE_IDENT_DIR || [resolve(APP, '../ident.worldapi.org'), '/media/STORAGE/projects/WorldAPI/ident.worldapi.org'].find(d => existsSync(join(d, 'project.hl')));const STORE = join(APP, '.scratch/limits-store');const J = JSON.stringify, sleep = (ms) => new Promise(r => setTimeout(r, ms));let passes = 0, failures = 0;const check = (label, ok, detail = '') => { console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`); if (ok) passes++; else failures++; };function raw(method, path, { host = `localhost:${PORT}`, headers = {}, body = null, cookie = null } = {}) {return new Promise((res, rej) => {const h = { host, ...headers }; if (cookie) h.cookie = cookie;if (body !== null) h['content-length'] = Buffer.byteLength(body);const r = request({ host: '127.0.0.1', port: PORT, method, path, headers: h }, (m) => { const c = []; m.on('data', d => c.push(d)); m.on('end', () => res({ status: m.statusCode, headers: m.headers, body: Buffer.concat(c).toString('latin1') })); });r.on('error', rej); if (body !== null) r.write(body); r.end();});}const get = (path, o = {}) => raw('GET', path, o);const errCode = (r) => { try { return JSON.parse(r.body).error.code; } catch { return null; } };const body = (r) => { try { return JSON.parse(r.body); } catch { return null; } };let server = null, log = '';function startServer(env) {log = '';const p = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, stdio: ['ignore', 'pipe', 'pipe'],env: { ...process.env, GITORIA_PORT: String(PORT), GITORIA_WATCH: '0', GITORIA_PUBLIC_URL: `http://localhost:${PORT}`, GITORIA_SSH_SECRET: 'sshsecret-limits-gate', GITORIA_TICKETS_URL: 'http://127.0.0.1:1', ...env } });p.stdout.on('data', d => log += d); p.stderr.on('data', d => log += d);server = p; return p;}async function up() { for (let i = 0; i < 960; i++) { try { if ((await get('/api/repos')).status === 200) return; } catch {} await sleep(250); } throw new Error('gitoria did not come up\n' + log); }const stop = async () => { if (server) { const p = server; server = null; p.kill(); await new Promise(r => p.once('exit', r)); } };let ident;try {rmSync(STORE, { recursive: true, force: true }); mkdirSync(STORE, { recursive: true });ident = await startIdent({ identDir: IDENT_DIR, workDir: join(STORE, 'ident'), port: IDENT_PORT });const alice = await ident.signIn('[email protected]');const BASE = `http://localhost:${PORT}`;const app = await ident.registerApp(alice, 'gitoria (limits gate)', [BASE]);const ENV = { GITORIA_STORAGE: join(STORE, 'mpackdb'), GITORIA_SESSIONS: join(STORE, 'sessions') + '/', GITORIA_GIT: join(STORE, 'git'), IDENT_URL: ident.base, IDENT_EXCHANGE_URL: ident.base, IDENT_API_KEY: app.key, IDENT_API_SECRET: app.secret };startServer(ENV); await up();const cookieOf = (r) => (r.headers['set-cookie'] || []).map(c => c.split(';')[0])[0] || null;const ck0 = cookieOf(await get('/'));const cb = await get('/login/callback?ident_code=' + await ident.selectorCode(alice, app, BASE) + '&next=%2F', { cookie: ck0 });const A = { cookie: cookieOf(cb) || ck0 };let n = 0;const face = async (event, payload, cookie = A.cookie) => {const r = await raw('POST', '/__hl/emit', { headers: { 'content-type': 'application/json' }, cookie, body: J({ t: 'emit', i: ++n, event, payload }) });let j = null; try { j = JSON.parse(r.body); } catch {}return j && j.value;};await face('gitoriaSaveName', ['Alice']);const tA = (await face('gitoriaMakeToken', ['a'])).token;const W = join(STORE, 'work'); mkdirSync(W, { recursive: true });const genv = { ...process.env, GIT_TERMINAL_PROMPT: '0', GIT_CONFIG_GLOBAL: '/dev/null', GIT_AUTHOR_NAME: 'a', GIT_AUTHOR_EMAIL: 'a@a', GIT_COMMITTER_NAME: 'a', GIT_COMMITTER_EMAIL: 'a@a' };const g = (...a) => execFileSync('git', a, { cwd: W, encoding: 'utf8', env: genv, stdio: ['ignore', 'pipe', 'pipe'] });const sh = (fn) => { try { return fn(); } catch (e) { return null; } };const urlOf = (host, path) => `http://a:${tA}@${host}.localhost:${PORT}/${path}`;const push = (host, path, ...refs) => sh(() => { g('push', '-q', urlOf(host, path), ...refs); return true; });const sha = () => g('rev-parse', 'HEAD').trim();g('init', '-q', '-b', 'main'); writeFileSync(join(W, 'README.md'), '# t\n'); g('add', '-A'); g('commit', '-q', '-m', 'init'); const initSha = sha();check('alice creates "pub" and "other"', !!(await face('gitoriaCreate', ['pub', 'p'])).repo && !!(await face('gitoriaCreate', ['other', 'o'])).repo);check('alice pushes main to pub and other', push('pub', 'pub.git', 'main') === true && push('other', 'other.git', 'main') === true);g('checkout', '-q', '-b', 'feat'); writeFileSync(join(W, 'a.txt'), 'a\n'); g('add', '-A');g('commit', '-q', '-m', '|||PR Add a', '-m', 'Fixes other-proj#7, bare #12 and gitoria.worldapi.org#3. See x#a and #0 and #12abc.');const h1 = sha();g('checkout', '-q', 'main'); g('checkout', '-q', '-b', 'feat2'); writeFileSync(join(W, 'b.txt'), 'b\n'); g('add', '-A'); g('commit', '-q', '-m', '|||PR Closes #5.');check('alice pushes the branches feat and feat2 (|||PR commits)', push('pub', 'pub.git', 'feat', 'feat2') === true);g('checkout', '-q', 'main'); g('checkout', '-q', '-b', 'lone'); writeFileSync(join(W, 'o.txt'), 'o\n'); g('add', '-A'); g('commit', '-q', '-m', 'only on other');const otherSha = sha();check('a commit that exists only in "other"', push('other', 'other.git', 'lone') === true);const addApp = (slug, name) => face('gitoriaAppAdd', [slug, name, 'https://kunibert.worldapi.org/hook']);const kK = await addApp('pub', 'Kunibert'), kO = await addApp('pub', 'Otto'), kX = await addApp('other', 'Xaver'), kZ = await addApp('pub', 'Zed');const tok = async (host, key) => JSON.parse((await raw('POST', '/api/apps/token', { host: `${host}.localhost:${PORT}`, headers: { authorization: 'Bearer ' + key } })).body).token;const tK = await tok('pub', kK.key), tO = await tok('pub', kO.key), tX = await tok('other', kX.key);const H = (host) => `${host}.localhost:${PORT}`;const call = (method, host, token, path, b = null) => raw(method, path, { host: H(host), headers: { ...(token ? { authorization: 'Bearer ' + token } : {}), 'content-type': 'application/json' }, body: b === null ? null : (typeof b === 'string' ? b : J(b)) });const st = (context, state) => ({ context, state, title: 't ' + context, summary: '**md**', url: null });// ---- 1. the status read route (v1.3) ------------------------------------------------------------------------------------------------const pK = await call('PUT', 'pub', tK, '/api/statuses/' + h1, st('kunibert', 'success'));const pO = await call('PUT', 'pub', tO, '/api/statuses/' + h1, st('lint', 'failure'));const sK = (body(pK) || {}).status || {};check('PUT answer: status has app {id,name} and head', pK.status === 200 && sK.app && sK.app.name === 'Kunibert' && /^[^ ]+$/.test(sK.app.id || '') && sK.head === h1 && sK.context === 'kunibert', pK.body);const gK = await call('GET', 'pub', tK, '/api/statuses/' + h1), gO = await call('GET', 'pub', tO, '/api/statuses/' + h1);const ctxs = (r) => ((body(r) || {}).statuses || []).map(s => s.context + ':' + s.state + ':' + s.app.name).sort().join(',');check('GET statuses/<sha>: 200 { statuses } with the contexts of BOTH apps (each with app, head, updated)', gK.status === 200 && ctxs(gK) === 'kunibert:success:Kunibert,lint:failure:Otto' && body(gK).statuses.every(s => s.head === h1 && /Z$/.test(s.updated) && s.app.id), gK.body);check('the other app reads the same list (it may read what it may not write)', gO.status === 200 && ctxs(gO) === ctxs(gK), gO.body);const empty = await call('GET', 'pub', tK, '/api/statuses/' + initSha);check('a sha of the repo with no status: 200 { statuses: [] }', empty.status === 200 && J(body(empty)) === '{"statuses":[]}', empty.body);const un = await call('GET', 'pub', tK, '/api/statuses/' + 'a'.repeat(40));check('a sha the repo does not have: 404 not_found (§6 shape)', un.status === 404 && errCode(un) === 'not_found' && body(un).error.message, un.status + un.body);const oth = await call('GET', 'pub', tK, '/api/statuses/' + otherSha);check('a sha that exists only in ANOTHER repo: 404 not_found on this one', oth.status === 404 && errCode(oth) === 'not_found', oth.body);const bad = await call('GET', 'pub', tK, '/api/statuses/zzz');check('a malformed sha: 404 not_found', bad.status === 404 && errCode(bad) === 'not_found', bad.body);check('no token: 401; a token of another repo: 404', (await call('GET', 'pub', null, '/api/statuses/' + h1)).status === 401 && (await call('GET', 'pub', tX, '/api/statuses/' + h1)).status === 404);check('the same read on the other repo shows none of pub\'s statuses', (await call('GET', 'other', tX, '/api/statuses/' + otherSha)).status === 200 && J(body(await call('GET', 'other', tX, '/api/statuses/' + otherSha))) === '{"statuses":[]}');// ---- 2. pull.statuses and pull.required --------------------------------------------------------------------------------------------await face('gitoriaRequiredAdd', ['pub', kK.rows.find(x => x.name === 'Kunibert').id, 'kunibert']); await face('gitoriaRequiredAdd', ['pub', kO.rows.find(x => x.name === 'Otto').id, 'lint']);let p1 = body(await call('GET', 'pub', tK, '/api/pulls/1'));check('GET pulls/1: statuses = every context on the current head from every app, required = the owner\'s names', p1 && ctxs({ body: J({ statuses: p1.statuses }) }) === ctxs(gK) && J((p1.required || []).map(r => r.app.name + ':' + r.context).sort()) === '["Kunibert:kunibert","Otto:lint"]' && p1.required.every(r => r.app.id && Object.keys(r).sort().join() === 'app,context'), J(p1 && { s: p1.statuses, r: p1.required }));const lst = body(await call('GET', 'pub', tO, '/api/pulls?state=all'));check('GET pulls (list): the same two fields on every pull', lst && lst.pulls.length === 2 && lst.pulls.every(p => Array.isArray(p.statuses) && Array.isArray(p.required)) && lst.pulls.find(p => p.number === 1).statuses.length === 2 && lst.pulls.find(p => p.number === 2).statuses.length === 0);g('checkout', '-q', 'feat'); writeFileSync(join(W, 'a2.txt'), 'a2\n'); g('add', '-A'); g('commit', '-q', '-m', 'more'); const h2 = sha();check('push moves the head of PR 1', push('pub', 'pub.git', 'feat') === true);p1 = body(await call('GET', 'pub', tK, '/api/pulls/1'));check('after the push: pull.head is new, pull.statuses is EMPTY (the CURRENT head only), required unchanged', p1.head === h2 && p1.statuses.length === 0 && p1.required.length === 2, J(p1.statuses));check('the old head\'s statuses are still readable by sha', ctxs(await call('GET', 'pub', tK, '/api/statuses/' + h1)).includes('kunibert:success:Kunibert'));await call('PUT', 'pub', tO, '/api/statuses/' + h2, st('lint', 'pending'));p1 = body(await call('GET', 'pub', tK, '/api/pulls/1'));check('a status on the new head appears in pull.statuses (with app)', p1.statuses.length === 1 && p1.statuses[0].context === 'lint' && p1.statuses[0].state === 'pending' && p1.statuses[0].app.name === 'Otto', J(p1.statuses));const p2 = body(await call('GET', 'pub', tK, '/api/pulls/2'));check('pull with no status: statuses [] (an array, not null)', J(p2.statuses) === '[]');// ---- 3. tickets: explicit project#n always, bare #n only when the repo is connected (NOT connected here) ------------------------------check('tickets, repo NOT connected: only the explicit ones, no doubles; "#12", "#0", "#12abc", "x#a" are not listed', J(p1.tickets) === '["other-proj#7","gitoria.worldapi.org#3"]', J(p1.tickets));check('tickets, not connected: a bare "#5" before a full stop is not listed (no project known)', J(p2.tickets) === '[]', J(p2.tickets));// ---- 4. 413 and 400 on every write route -----------------------------------------------------------------------------------------------const writes = [['POST', '/api/pulls/1/reviews'], ['POST', '/api/pulls/1/comments'], ['POST', '/api/pulls/1/threads/x/replies'], ['POST', '/api/pulls/1/threads/x/resolve'], ['PUT', '/api/statuses/' + h1]];const bigBody = '{"body":"' + 'x'.repeat(1048576) + '"}';for (const [m, path] of writes) {const r413 = await call(m, 'pub', tK, path, bigBody);check(`${m} ${path.replace(/[0-9a-f]{40}/, '<sha>')}: a body over 1 MB → 413 too_large`, r413.status === 413 && errCode(r413) === 'too_large', r413.status + r413.body.slice(0, 120));let ok = true, why = '';for (const b of ['', 'hello', '[1,2]', '{"a":', '{', 'null', '123']) { const r = await call(m, 'pub', tK, path, b); if (r.status !== 400 || errCode(r) !== 'invalid_json') { ok = false; why += J(b) + '→' + r.status + ' '; } }check(`${m} ${path.replace(/[0-9a-f]{40}/, '<sha>')}: bodies that are not a JSON object → 400 invalid_json`, ok, why);}const ex = await raw('POST', '/api/apps/exchange', { host: H('pub'), body: bigBody });check('POST /api/apps/exchange: over 1 MB → 413; not JSON → 400', ex.status === 413 && errCode(ex) === 'too_large' && (await raw('POST', '/api/apps/exchange', { host: H('pub'), body: 'nope' })).status === 400);const bigOk = await call('POST', 'pub', tK, '/api/pulls/1/comments', { body: 'y'.repeat(65536) });check('a body just under the limit (65,536 characters) is fine', bigOk.status === 201, bigOk.status + bigOk.body.slice(0, 100));// ---- 5. the default limits: 300 reads and 60 writes per minute, per app ----------------------------------------------------------------const tZ = await tok('pub', kZ.key); // write 1 of 60let w429 = null, wOk = 0;for (let i = 0; i < 60; i++) { const r = await call('PUT', 'pub', tZ, '/api/statuses/' + h1, '{"context":"","state":"x"}'); if (r.status === 429) { w429 = i; break; } wOk++; }const wLast = await call('PUT', 'pub', tZ, '/api/statuses/' + h1, '{"context":"","state":"x"}');check('default: the token call + 59 PUTs are answered (422), the 61st write of the minute is 429', w429 === null && wOk === 60 - 1 + 1 && wLast.status === 429 || (wOk === 59 && w429 === 59), `ok=${wOk} first429@${w429} last=${wLast.status}`);check('429: body code rate_limited, Retry-After is whole seconds 1..60', wLast.status === 429 && errCode(wLast) === 'rate_limited' && /^\d+$/.test(wLast.headers['retry-after'] || '') && Number(wLast.headers['retry-after']) >= 1 && Number(wLast.headers['retry-after']) <= 60, J(wLast.headers) + wLast.body);let r429 = null, rOk = 0;for (let i = 0; i < 300; i++) { const r = await call('GET', 'pub', tZ, '/api/deliveries'); if (r.status === 429) { r429 = i; break; } rOk++; }const rLast = await call('GET', 'pub', tZ, '/api/deliveries');check('default: 300 reads are answered (200), the 301st read of the minute is 429 — while the exhausted writes did not touch reads', r429 === null && rOk === 300 && rLast.status === 429 && errCode(rLast) === 'rate_limited' && Number(rLast.headers['retry-after']) >= 1, `ok=${rOk} first429@${r429} last=${rLast.status}`);check('Zed\'s limit does not touch another app (Kunibert reads and writes)', (await call('GET', 'pub', tK, '/api/pulls/1')).status === 200 && (await call('PUT', 'pub', tK, '/api/statuses/' + h1, st('kunibert', 'success'))).status === 200);check('the key and a token never appear in the server log', ![kK.key, kO.key, kX.key, kZ.key, tK, tO, tX, tZ].some(s => log.includes(s)));// ---- 6. a restart (a deploy swap) starts every count at zero; low limits by env; connect the repo to tickets ---------------------------await stop();const pr = spawnSync(join(APP, 'bin/hybriel'), ['tests/limits-probe.hl', 'pub', 'conn-proj'], { cwd: APP, env: { ...process.env, ...ENV }, encoding: 'utf8' });check('the probe connects "pub" to the tickets project conn-proj', /connected pub conn-proj/.test(pr.stdout), pr.stdout + pr.stderr);const WINDOW = 7000;startServer({ ...ENV, GITORIA_LIMIT_READS: '5', GITORIA_LIMIT_WRITES: '3', GITORIA_LIMIT_WINDOW_MS: String(WINDOW) }); await up();check('after the restart Zed is at zero again (the counts were in the process)', (await call('GET', 'pub', tZ, '/api/deliveries')).status === 200 && (await call('PUT', 'pub', tZ, '/api/statuses/' + h1, '{"context":"","state":"x"}')).status === 422);const t0 = Date.now();const reads = []; for (let i = 0; i < 7; i++) reads.push((await call('GET', 'pub', tK, '/api/pulls/1')).status);check('low limit: Kunibert\'s reads 1..5 are 200, the 6th and 7th are 429', J(reads) === '[200,200,200,200,200,429,429]', J(reads));const r6 = await call('GET', 'pub', tK, '/api/pulls/1');const ra = Number(r6.headers['retry-after']);check('429 carries Retry-After in whole seconds, no longer than the window', r6.status === 429 && /^\d+$/.test(r6.headers['retry-after'] || '') && ra >= 1 && ra <= Math.ceil(WINDOW / 1000), J(r6.headers));check('429 body: { error: { code: rate_limited, message } } as JSON', r6.status === 429 && errCode(r6) === 'rate_limited' && /json/.test(r6.headers['content-type'] || '') && !!body(r6).error.message, r6.body);const writesK = []; for (let i = 0; i < 5; i++) writesK.push((await call('PUT', 'pub', tK, '/api/statuses/' + h1, st('kunibert', 'success'))).status);check('reads and writes are counted apart: with its reads used up, Kunibert\'s writes 1..3 are 200 and the 4th and 5th are 429', J(writesK) === '[200,200,200,429,429]', J(writesK));check('and with its writes used up the reads stay 429 (own counter), a POST token call is a write too', (await call('GET', 'pub', tK, '/api/pulls/1')).status === 429 && (await raw('POST', '/api/apps/token', { host: H('pub'), headers: { authorization: 'Bearer ' + kK.key } })).status === 429);const otto = []; for (let i = 0; i < 2; i++) otto.push((await call('GET', 'pub', tO, '/api/pulls/1')).status);otto.push((await call('PUT', 'pub', tO, '/api/statuses/' + h1, st('lint', 'failure'))).status);check('apps are counted apart: Otto (same repo) is not affected by Kunibert\'s 429s', J(otto) === '[200,200,200]', J(otto));check('Xaver on another repo too', (await call('GET', 'other', tX, '/api/statuses/' + otherSha)).status === 200);const bads = []; for (let i = 0; i < 8; i++) bads.push((await call('GET', 'pub', 'gat_' + 'c'.repeat(40), '/api/pulls/1')).status);bads.push((await call('GET', 'other', tO, '/api/pulls/1')).status, (await call('GET', 'pub', null, '/api/pulls/1')).status);check('a bad token (401), no token, and a token on another repo (404) are NOT counted: Otto still has reads left', J(bads) === '[401,401,401,401,401,401,401,401,404,401]' && (await call('GET', 'pub', tO, '/api/pulls/1')).status === 200, J(bads));const left = WINDOW - (Date.now() - t0);await sleep(Math.max(0, left) + 400);check('after the minute (window) the counts restart: Kunibert reads and writes are 200 again', (await call('GET', 'pub', tK, '/api/pulls/1')).status === 200 && (await call('PUT', 'pub', tK, '/api/statuses/' + h1, st('kunibert', 'success'))).status === 200);// ---- 7. tickets with the repo connected: a bare #n is listed under the project -------------------------------------------------------------p1 = body(await call('GET', 'pub', tO, '/api/pulls/1'));check('tickets, repo CONNECTED (conn-proj): explicit ones as written, the bare "#12" under the project, order of appearance, no doubles', J(p1.tickets) === '["other-proj#7","conn-proj#12","gitoria.worldapi.org#3"]', J(p1.tickets));const p2c = body(await call('GET', 'pub', tO, '/api/pulls/2'));check('tickets, connected: "Closes #5." (number before a full stop) → conn-proj#5', J(p2c.tickets) === '["conn-proj#5"]', J(p2c.tickets));check('the key and a token never appear in the server log (second run)', ![kK.key, kO.key, kX.key, kZ.key, tK, tO, tX, tZ].some(s => log.includes(s)));} catch (e) {check('the gate ran without an exception', false, String(e && e.stack || e));} finally {await stop().catch(() => {});try { ident && ident.stop && await ident.stop(); } catch {}console.log(`\n${passes} passed, ${failures} failed`);process.exit(failures ? 1 : 0);}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 71b2fa4blog: hybriel#335mre
- bd94cc7elog: #25 cause found (run() leak)mre
- 565cb508log: H25 round 1mre
- 90a0af84log: H25 startedmre
- 87bd53b8mission H25mre
- 71a746cflog: day48 livemre
- bf568e14log: V48 mergedmre
- 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
- f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
- 5d0834e7log: Apollo model rulemre
- fe8e5bd5log: #25 sample, V48 missionmre
- 8580c5d9log: theme fix from Atlasmre
- 46823d93log: Apollo budget correctionmre
- f6d32341log: Apollo on budget and #25 nextmre
- d7184f53log: batch live, #25 evidencemre
- 5e25e816log: W61 mergedmre
- aafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmre
- aca1fda1Merge W61: theme from layouts 17e0f03, Views refer to Style rules (gitoria#37 #27)mre
- 03cb650blog: W61 theme decisionmre
- 248bce85Report final style gates, CSS mappings and 136 whole-image comparisonsmre