Files
GDevelop-Unlocked/tests/web/userscript.test.mjs
T
BillyOutlast 30da3f8b4e Surgical conversion: Tier-1 patcher + launcher hook, Tier-2 extraction (Phases 1-5)
Replaces the 205-file fork delivery vehicle with patches/ + launcher/
+ versioned packages, per the implementation plan:

Phase 1: seam tripwires (27 tests) freezing every surgical target in
upstream (Usage predicate, %16 gate, SubscriptionChecker, debugger,
LoadingScreen branding, Electron hook surface, no-plugin-registry
verdict).

Phase 2: 5 generated Tier-1 hunks (round-trip verified; 3 files reach
byte-identical fork parity) + apply driver (dry-run gate, marker
verify, asar extract/repack).

Phase 3: launcher hook (preload fetch/XHR spoof of the two usage GETs,
BrowserWindow wrap, webRequest fallback, updater pin) + 06 loader
patch. Module._load interception dropped: renderers run a webpack
bundle, so the spoof rides the axios/XHR path the provider hydrates
from instead.

Phase 4: Tier-2 verbatim extraction (CustomAIClient + 12 Studio
modules + offline mock harness, manifest-pinned) + 07/08 verbatim
glue patches + pure generation shim with fail-closed leak guard.

Phase 5: web userscript demo (Tier-1 only, documented CORS/LAN/churn
limits). Phase 6 runbook + upstream provider-interface RFC draft
included; fork archiving left to owners (destructive).

Suite: 66 tests green (seams, patcher incl. re-apply refusal,
launcher incl. vm-sandbox fallback eval, tier-2 provenance, web).
2026-10-10 20:41:35 -04:00

48 lines
1.9 KiB
JavaScript

// Web userscript demo tests (Phase 5, issue #5): syntax validity,
// Tampermonkey header contract, spoof surface, and documented limits.
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const here = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(here, '..', '..');
const SCRIPT = path.join(ROOT, 'web-userscript', 'heretek-unlock.user.js');
const text = fs.readFileSync(SCRIPT, 'utf8');
describe('web demo: userscript contract', () => {
it('parses as valid JavaScript', () => {
const r = spawnSync('node', ['--check', SCRIPT], { encoding: 'utf8' });
assert.equal(r.status, 0, `syntax error:\n${r.stderr}`);
});
it('targets the web editor only, at document start', () => {
assert.ok(text.includes('@match https://editor.gdevelop.io/*'));
assert.ok(text.includes('@run-at document-start'));
assert.ok(text.includes('DEMO ONLY'));
});
it('spoofs exactly the Tier-1 usage endpoints', () => {
assert.ok(text.includes('https://api.gdevelop.io/usage'));
assert.ok(text.includes("'/limits'") || text.includes('/limits'));
assert.ok(text.includes('/subscription-v2'));
assert.ok(!text.includes('/generation'), 'demo must not touch generation');
});
it('documents all three known limits in the header', () => {
assert.ok(text.includes('OLLAMA_ORIGINS'), 'Ollama CORS setup missing');
assert.ok(text.includes('LAN preview'), 'LAN limitation missing');
assert.ok(
text.includes('chunk') || text.includes('Chunk'),
'hash-churn limitation missing'
);
});
it('taps webpackChunk without module-factory surgery', () => {
assert.ok(text.includes('webpackChunk'));
assert.ok(!text.includes('.m =') && !text.includes('__webpack_require__'));
});
});