Skip to content

Commit 1d482df

Browse files
YZLLMclaude
andcommitted
test(e2e): Faz 11 stack bagimsiz tabani icin tarayici testi
Birim testleri cekirdegi kanitliyor ama farkli bir sey kanitlanmamisti: faz UI'dan tetiklenince paketlenmis yol cozuluyor mu, taban gercekten kosuyor mu, sonuc kullaniciya gorunuyor mu. Bugunku mesaj hatasi (uc tarama birden "arac duzgun calismadi" diyordu) tam olarak bu bosluktan cikti - calisan uygulamayi GORMEDEN yakalanamazdi. Fixture iki Python dosyasinda birebir 30 satirlik kopya blok kurar: ts-prune bu projeye uygulanamaz, taban olcer. Betik denetim kaydindan dogruluyor: phase-11-skipped (ts_tool_js_project) -> simplify-agnostic-pass -> phase-11-covered-by-extras -> phase-11-complete. Kurgu ogrenilen iki gercegi tasiyor: soru asiliyken faz calistirma DOGRU bicimde yok sayilir (once soru yanitlanir) ve faz calistirma onaya baglidir (cift tik -> "Calistirilsin mi?" -> Calistir). CI'DA KOSMAZ: proje acilisi yasayan dokuman uretimini tetikledigi icin kucuk bir LLM maliyeti var. e2e:smoke'un "hicbir faz/LLM tetiklenmez" sozlesmesi bozulmasin diye ayri betik; browser-bridge/README bunu yaziyor. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent bc06c33 commit 1d482df

3 files changed

Lines changed: 232 additions & 0 deletions

File tree

‎browser-bridge/README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@ Node orchestrator (Tauri'dekiyle AYNI süreç, aynı sözleşme)
3737
```bash
3838
npm run dev:browser # köprü + vite (tarayıcı modu) → http://localhost:1420
3939
npm run e2e:smoke # uçtan-uca duman testi (kendi yığınını kurar/yıkar)
40+
npm run e2e:faz11 # Faz 11 stack bağımsız tabanı — GERÇEK faz koşturur (elle, LLM maliyeti var)
4041
npm run bridge # yalnız köprü (:1799), ayrı vite ile kullanmak için
4142
```
4243

44+
`e2e:smoke` hiçbir faz/LLM tetiklemez, bu yüzden serbestçe koşulabilir.
45+
`e2e:faz11` bilerek bir faz çalıştırır: iki Python dosyasında birebir kopya bloğu olan geçici
46+
bir proje kurar, Faz 11'i UI'dan tetikler ve dilin kendi aracı (ts-prune) bu projeye
47+
uygulanamazken stack bağımsız tabanın gerçekten ölçtüğünü denetim kaydından doğrular. Proje
48+
açılışı yaşayan doküman üretimini de tetiklediği için küçük bir LLM maliyeti vardır → **CI'da
49+
koşmaz, elle koşulur**. Birim testleri çekirdeği kanıtlar; bu betik farklı bir şeyi kanıtlar:
50+
paketlenmiş yolun çözüldüğünü ve sonucun kullanıcıya göründüğünü.
51+
4352
Tarayıcıda proje açmak: `http://localhost:1420/?project=/mutlak/proje/yolu`
4453
(veya Splash'ta klasör yolunu gir). Native klasör seçici tarayıcıda gerçek yol
4554
döndüremez; Playwright `window.__MYCL_PICK_PATH` enjekte eder.

‎e2e/faz11-simplify.mjs‎

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
// e2e/faz11-simplify.mjs — Faz 11'in stack bağımsız tabanını GERÇEK uygulamada doğrular.
2+
//
3+
// NEDEN AYRI BİR BETİK (smoke'a eklenmedi): smoke'un sözleşmesi "hiçbir faz/LLM tetiklenmez".
4+
// Bu betik ise bilerek bir faz çalıştırır. Proje açılışı EDD + yaşayan doküman üretimini de
5+
// tetiklediği için KÜÇÜK BİR LLM MALİYETİ vardır → CI'da koşmaz, elle koşulur.
6+
//
7+
// NE KANITLIYOR (birim testlerinin kanıtlamadığı şey): Faz 11 UI'dan tetiklenince, dilin kendi
8+
// aracı bu projeye uygulanamasa bile stack bağımsız taban gerçekten koşuyor, ölçüyor, sonucu
9+
// projeye yazıyor ve kullanıcıya görünüyor. Adli denetim bu boyutun cave'in 94 iterasyonunda BİR
10+
// KEZ bile koşmadığını göstermişti; buradaki fixture tam o durumu kurar (ts-prune uygulanamaz).
11+
//
12+
// Çalıştır: npm run e2e:faz11
13+
// Bağımlılık: orchestrator/node_modules'taki playwright + Chromium.
14+
15+
import { spawn } from "node:child_process";
16+
import { createRequire } from "node:module";
17+
import { fileURLToPath } from "node:url";
18+
import fs from "node:fs";
19+
import os from "node:os";
20+
import path from "node:path";
21+
import { Reporter, waitFor, httpStatus, sleep } from "./lib.mjs";
22+
23+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
24+
const ROOT = path.resolve(__dirname, "..");
25+
const ARTIFACTS = path.join(__dirname, "artifacts");
26+
const APP_URL = "http://localhost:1420";
27+
const BRIDGE_HEALTH = "http://localhost:1799/__bridge/health";
28+
29+
const rep = new Reporter();
30+
31+
/**
32+
* Fixture: İKİ PYTHON DOSYASINDA birebir aynı 30 satırlık blok.
33+
* Dil bağımsızlığının kanıtı burada: ts-prune bu kopyayı göremez, taban görür.
34+
*/
35+
function makeFixture() {
36+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "mycl-faz11-"));
37+
fs.writeFileSync(
38+
path.join(dir, "package.json"),
39+
JSON.stringify({ name: "mycl-faz11-fixture", version: "0.0.0", private: true }, null, 2),
40+
);
41+
fs.mkdirSync(path.join(dir, "src"), { recursive: true });
42+
const blok = Array.from({ length: 30 }, (_, i) => ` toplam_${i} = hesapla(${i}, ${i + 1})`).join("\n");
43+
fs.writeFileSync(path.join(dir, "src", "rapor_a.py"), `def rapor_a():\n${blok}\n`);
44+
fs.writeFileSync(path.join(dir, "src", "rapor_b.py"), `def rapor_b():\n${blok}\n`);
45+
fs.writeFileSync(path.join(dir, "src", "index.js"), "console.log('faz11 fixture');\n");
46+
fs.writeFileSync(path.join(dir, "README.md"), "# MyCL Faz 11 fixture\n");
47+
return dir;
48+
}
49+
50+
function loadChromium() {
51+
const req = createRequire(path.join(ROOT, "orchestrator", "package.json"));
52+
let pw;
53+
try {
54+
pw = req("playwright");
55+
} catch {
56+
throw new Error("playwright bulunamadı (orchestrator/node_modules). `npm --prefix orchestrator install` gerekli.");
57+
}
58+
const chromium = pw.chromium ?? pw.default?.chromium;
59+
if (!chromium) throw new Error("playwright 'chromium' export bulunamadı");
60+
return chromium;
61+
}
62+
63+
const auditLines = (file, filtre) => {
64+
if (!fs.existsSync(file)) return [];
65+
return fs
66+
.readFileSync(file, "utf-8")
67+
.split("\n")
68+
.filter((l) => filtre.test(l))
69+
.map((l) => {
70+
try {
71+
return JSON.parse(l);
72+
} catch {
73+
return null;
74+
}
75+
})
76+
.filter(Boolean);
77+
};
78+
79+
async function main() {
80+
fs.mkdirSync(ARTIFACTS, { recursive: true });
81+
const fixture = makeFixture();
82+
const auditPath = path.join(fixture, ".mycl", "audit.log");
83+
84+
const stack = spawn("node", [path.join(ROOT, "browser-bridge", "start.mjs")], {
85+
cwd: ROOT,
86+
detached: true,
87+
stdio: ["ignore", "ignore", "inherit"],
88+
});
89+
90+
let browser;
91+
const cleanup = () => {
92+
try {
93+
if (browser) browser.close();
94+
} catch {
95+
/* */
96+
}
97+
try {
98+
if (stack.pid) process.kill(-stack.pid, "SIGTERM");
99+
} catch {
100+
/* */
101+
}
102+
try {
103+
fs.rmSync(fixture, { recursive: true, force: true });
104+
} catch {
105+
/* */
106+
}
107+
};
108+
process.on("SIGINT", () => {
109+
cleanup();
110+
process.exit(1);
111+
});
112+
113+
try {
114+
rep.step("0/4 Yığını başlat (köprü + vite tarayıcı modu)");
115+
await waitFor(async () => (await httpStatus(BRIDGE_HEALTH)) === 200, { timeout: 30000, label: "köprü (:1799)" });
116+
rep.ok("köprü ayakta (:1799)");
117+
await waitFor(async () => (await httpStatus(APP_URL)) === 200, { timeout: 60000, label: "vite (:1420)" });
118+
rep.ok("vite dev server ayakta (:1420)");
119+
120+
const chromium = loadChromium();
121+
browser = await chromium.launch({ headless: true });
122+
const page = await (await browser.newContext({ viewport: { width: 1440, height: 900 } })).newPage();
123+
const pageErrors = [];
124+
page.on("pageerror", (e) => pageErrors.push(e.message));
125+
page.on("dialog", (d) => d.dismiss().catch(() => {}));
126+
await page.addInitScript((p) => {
127+
window.__MYCL_PICK_PATH = p;
128+
}, fixture);
129+
130+
rep.step("1/4 Projeyi aç");
131+
await page.goto(APP_URL, { waitUntil: "domcontentloaded" });
132+
await page.waitForSelector('[data-testid="splash-pick-folder"]', { timeout: 20000 });
133+
await page.click('[data-testid="splash-pick-folder"]');
134+
await rep.check("proje açıldı (header render)", () =>
135+
page.waitForSelector('[data-testid="app-header"]', { timeout: 20000 }),
136+
);
137+
138+
// Yabancı proje açılışı EDD koşturup Faz 1'de soru sorabilir. Soru ASILIYKEN faz çalıştırma
139+
// DOĞRU biçimde yok sayılır (sidebar `disabled`) — ilk yazımda tam bu yüzden hiç koşmamıştı.
140+
// Soru her koşuda çıkmaz (doküman damgası taze olabilir) → varlığı şart değil, temizliği şart.
141+
rep.step("2/4 Asılı soru varsa yanıtla (soru varken faz koşmaz)");
142+
await page.waitForSelector('[data-testid="askq-card"]', { timeout: 60000 }).catch(() => {});
143+
for (let tur = 0; tur < 3; tur++) {
144+
const secenekler = await page.$$('[data-testid="askq-option"]');
145+
if (secenekler.length === 0) break;
146+
const son = secenekler[secenekler.length - 1];
147+
const metin = ((await son.textContent()) ?? "").trim();
148+
await son.click();
149+
rep.ok(`soru yanıtlandı: "${metin.slice(0, 40)}"`);
150+
await sleep(6000);
151+
}
152+
await rep.check("soru kalmadı (orchestrator müsait)", () =>
153+
waitFor(async () => (await page.$('[data-testid="askq-card"]')) === null, {
154+
timeout: 90000,
155+
label: "askq temizlendi",
156+
}),
157+
);
158+
159+
rep.step("3/4 Faz 11'i sidebar'dan çalıştır");
160+
await page.waitForSelector('[data-testid="phase-item-11"]', { timeout: 10000 });
161+
await page.dblclick('[data-testid="phase-item-11"]'); // tek tık = git, çift tık = çalıştır
162+
await rep.check("çalıştırma onayı soruldu", () =>
163+
waitFor(
164+
async () => /Faz 11.*çalıştırılsın mı/s.test((await page.textContent('[data-testid="chat-panel"]')) ?? ""),
165+
{ timeout: 60000, label: "onay sorusu" },
166+
),
167+
);
168+
for (const el of await page.$$('[data-testid="askq-option"]')) {
169+
if (/Çalıştır/.test((await el.textContent()) ?? "")) {
170+
await el.click();
171+
rep.ok("onay verildi: Çalıştır");
172+
break;
173+
}
174+
}
175+
await rep.check("Faz 11 gerçekten koştu (denetim kaydına yazdı)", () =>
176+
waitFor(() => auditLines(auditPath, /phase-11/).length > 0, { timeout: 120000, label: "phase-11 olayı" }),
177+
);
178+
179+
rep.step("4/4 Stack bağımsız taban ölçtü mü");
180+
await rep.check("taban koştu ve GEÇTİ (ilk ölçüm → temel)", () =>
181+
waitFor(() => auditLines(auditPath, /simplify-agnostic-pass/).length > 0, {
182+
timeout: 60000,
183+
label: "simplify-agnostic-pass",
184+
}),
185+
);
186+
await rep.check("ölçüm projeye yazıldı (kopya satır > 0)", async () => {
187+
const b = JSON.parse(fs.readFileSync(path.join(fixture, ".mycl", "simplify-baseline.json"), "utf-8"));
188+
if (!(b.duplicateLines > 0)) throw new Error(`kopya satır ölçülmedi: ${JSON.stringify(b)}`);
189+
process.stdout.write(` ölçüm: ${b.duplicateLines} kopya satır / ${b.totalLines} toplam satır\n`);
190+
});
191+
await rep.check("ana araç uygulanamadı ama boyut KAPSANDI sayıldı", async () => {
192+
const atlandi = auditLines(auditPath, /"event":"phase-11-skipped"/).length > 0;
193+
const kapsandi = auditLines(auditPath, /phase-11-covered-by-extras/).length > 0;
194+
if (atlandi && !kapsandi) throw new Error("ana tarama atlandı ama kapsama kanıtı yazılmadı");
195+
if (!atlandi) process.stdout.write(" not: ana araç bu ortamda koşabildi (fixture'a göre beklenmedik)\n");
196+
});
197+
await rep.check("sonuç kullanıcıya göründü (sohbette 'simplify-agnostic')", async () => {
198+
const t = (await page.textContent('[data-testid="chat-panel"]')) ?? "";
199+
if (!t.includes("simplify-agnostic")) throw new Error("sohbette taramanın sonucu yok");
200+
});
201+
202+
const shot = path.join(ARTIFACTS, "faz11.png");
203+
await page.screenshot({ path: shot });
204+
rep.ok(`ekran görüntüsü: e2e/artifacts/faz11.png`);
205+
await rep.check("sayfa içi hata yok", async () => {
206+
if (pageErrors.length) throw new Error(pageErrors.join(" | "));
207+
});
208+
209+
process.stdout.write("\n Faz 11 denetim satırları:\n");
210+
for (const j of auditLines(auditPath, /phase-11|simplify/)) {
211+
process.stdout.write(` ${j.event} ${(j.detail ?? "").slice(0, 110)}\n`);
212+
}
213+
} finally {
214+
cleanup();
215+
}
216+
process.exit(rep.summary() ? 0 : 1);
217+
}
218+
219+
main().catch((e) => {
220+
process.stderr.write(`\n💥 ${e instanceof Error ? e.stack : String(e)}\n`);
221+
process.exit(1);
222+
});

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dev:browser": "node browser-bridge/start.mjs",
99
"bridge": "node browser-bridge/server.mjs",
1010
"e2e:smoke": "node e2e/smoke.mjs",
11+
"e2e:faz11": "node e2e/faz11-simplify.mjs",
1112
"build": "tsc && vite build",
1213
"build:all": "npm --prefix orchestrator run build && npm run build",
1314
"check": "bash scripts/check.sh",

0 commit comments

Comments
 (0)