Files
gravity_control/scratch_patch_verify.js
Variet Worker 2a1ebf1020 fix(extension): UTF-8 encoding + noise filter enhancement (v0.5.39)
- http-bridge.ts: add req.setEncoding('utf8') to all POST handlers
  to fix Korean text corruption in pending/chat/dump payloads
- observer-script.ts: add inline pre-strip in cleanLines() for
  Material icon names concatenated by textContent without newlines
- observer-script.ts: apply cleanLines() to codeText extraction
- known-issues: document UTF-8 encoding and noise filter issues
2026-04-13 12:56:25 +09:00

95 lines
4.1 KiB
JavaScript

/**
* html-patcher 수정 검증 스크립트
* 실제 workbench.html + 실제 observer-script 출력물로 패치 시뮬레이션
*/
const fs = require('fs');
const path = require('path');
// 1. 실제 깨끗한 workbench.html 읽기
const htmlPath = path.join(
process.env.LOCALAPPDATA,
'Programs', 'Antigravity', 'resources', 'app', 'out',
'vs', 'code', 'electron-browser', 'workbench', 'workbench.html'
);
let html = fs.readFileSync(htmlPath, 'utf8');
console.log(`[1] Clean HTML: ${html.length} chars, ${html.split('\n').length} lines`);
console.log(` Has AG SDK: ${html.includes('AG SDK')}`);
// 2. 실제 observer-script.ts의 출력 시뮬레이션 (generateApprovalObserverScript)
const observerModule = require('./extension/out/observer-script');
const observerJS = observerModule.generateApprovalObserverScript(34332);
console.log(`[2] Observer JS: ${observerJS.length} chars`);
console.log(` Contains $': ${observerJS.includes("$'")}`);
console.log(` Contains ')$': ${observerJS.includes("')$")}`);
// 3. 패치 시뮬레이션 — 수정 전 (BUG)
const inlineBlock_buggy = `<!-- AG SDK INLINE [variet-gravity-bridge] -->\n<script>\n${observerJS}\n</script>\n<!-- /AG SDK INLINE [variet-gravity-bridge] -->`;
let html_buggy = html.replace('</body>', `\n${inlineBlock_buggy}\n</body>`);
// 4. 패치 시뮬레이션 — 수정 후 (FIX)
const inlineBlock = `<!-- AG SDK INLINE [variet-gravity-bridge] -->\n<script>\n${observerJS}\n</script>\n<!-- /AG SDK INLINE [variet-gravity-bridge] -->`;
const safeInlineBlock = inlineBlock.replace(/\$/g, '$$$$');
let html_fixed = html.replace('</body>', `\n${safeInlineBlock}\n</body>`);
console.log(`\n[3] BUGGY result: ${html_buggy.length} chars`);
console.log(`[4] FIXED result: ${html_fixed.length} chars`);
// 5. JS 코드 추출 및 SyntaxError 검증
function extractAndCheckJS(patchedHtml, label) {
const match = patchedHtml.match(/<script>\n([\s\S]*?)\n<\/script>/);
if (!match) {
console.log(`[${label}] ERROR: <script> block not found!`);
return false;
}
const jsCode = match[1];
// Check if original HTML structure leaked into JS
const hasStartupComment = jsCode.includes('<!-- Startup');
const hasWorkbenchJS = jsCode.includes('<script src="./workbench.js"');
const hasClosingHtml = jsCode.includes('</html>') && !jsCode.includes("'</html>'");
console.log(`[${label}] JS code: ${jsCode.length} chars`);
console.log(` Leaked <!-- Startup -->: ${hasStartupComment} ${hasStartupComment ? '❌ CORRUPT' : '✅ OK'}`);
console.log(` Leaked <script src=workbench.js>: ${hasWorkbenchJS} ${hasWorkbenchJS ? '❌ CORRUPT' : '✅ OK'}`);
console.log(` Leaked </html>: ${hasClosingHtml} ${hasClosingHtml ? '❌ CORRUPT' : '✅ OK'}`);
// Check NOISE_RE is intact: should contain ')$', 'i'
const hasNoiseRE = jsCode.includes("')$', 'i'");
console.log(` NOISE_RE ')$', 'i' preserved: ${hasNoiseRE} ${hasNoiseRE ? '✅ OK' : '❌ BROKEN'}`);
// Try to parse JS
try {
new Function(jsCode);
console.log(` JS Syntax: ✅ VALID — no SyntaxError`);
return true;
} catch (e) {
console.log(` JS Syntax: ❌ SyntaxError — ${e.message}`);
// Find the problematic line
const lines = jsCode.split('\n');
const lineMatch = e.message.match(/line (\d+)/);
if (lineMatch) {
const lineNum = parseInt(lineMatch[1]);
console.log(` Around line ${lineNum}:`);
for (let i = Math.max(0, lineNum - 3); i < Math.min(lines.length, lineNum + 3); i++) {
console.log(` ${i+1}: ${lines[i].substring(0, 100)}`);
}
}
return false;
}
}
console.log('\n===== BUGGY VERSION (before fix) =====');
const buggyOK = extractAndCheckJS(html_buggy, 'BUGGY');
console.log('\n===== FIXED VERSION (after fix) =====');
const fixedOK = extractAndCheckJS(html_fixed, 'FIXED');
console.log('\n===== VERDICT =====');
if (!buggyOK && fixedOK) {
console.log('✅ FIX CONFIRMED: Buggy version has SyntaxError, fixed version is clean.');
} else if (buggyOK && fixedOK) {
console.log('⚠️ Both versions work — the bug may not reproduce in this environment.');
} else if (!fixedOK) {
console.log('❌ FIX FAILED: Fixed version still has errors!');
}