"use strict"; const fs = require("fs"); const path = require("path"); const root = path.resolve(__dirname, ".."); const read = rel => fs.readFileSync(path.join(root, rel), "utf8"); const ok = (value, message) => { if (!value) throw new Error(message); console.log(`[OK] ${message}`); }; const budget = read("js/world_spatial_budget.js"); const family = read("js/world_family_social.js"); const life = read("js/tarinai_social_move_life.js"); const achievements = read("js/achievements.js"); const charts = read("js/ui_charts.js"); const main = read("js/main.js"); const render = read("js/render.js"); ok(budget.includes("rebuildTarinaiCountCache") && budget.includes("syncTarinaiCountEntry") && budget.includes("tarinaiCounts()"), "population counters use mutation-maintained differential cache"); ok(family.includes("syncTarinaiCountEntry?.(t)") && life.includes("syncTarinaiCountEntry?.(this)"), "birth/add and death paths update differential population counters"); ok(budget.includes('noteItemInactive(item, reason = "item-inactive", notifyAchievements = true)') && budget.includes('noteItemInactive?.(it, "compact-items", false)'), "bulk item compaction suppresses per-item achievement checks"); ok(budget.includes('evaluateEvent?.(this, "items", { delta: 0, reason: "compact-items" })'), "bulk item compaction emits one aggregate achievement event"); ok(achievements.includes("function evaluateEvent(worldRef, trigger") && achievements.includes('evaluateEvent(worldRef, "timer"'), "achievement evaluation has event-driven trigger entry point"); ok(!achievements.includes("const needsHabitatItemScan"), "playstyle habitat achievements no longer rescan every item on periodic evaluation"); ok(achievements.includes("worldRef?.itemCounts") && achievements.includes("playstyleItemCount"), "item-dependent achievements use differential item counts in normal runtime"); ok(charts.includes("function colonyStatsUiVisible()") && main.includes("!colonyStatsUiVisible()"), "hidden colony UI prevents scheduled stats aggregation"); ok(charts.includes("world.tarinaiCounts?.()") && charts.includes("collectDynamicColonyStats"), "visible stats separate hot counters from dynamic full-population aggregation"); ok(render.includes("nearbyRectInto(worldRef.spatial.tarinaiCells") && render.includes("isPointVisibleInRect") && render.includes("!isEntityVisibleInRect(entity, visibleRect)"), "render stack pre-culls entities before list insertion"); ok(!render.includes("isEntityVisibleInRect({ ...it, x: pose.x, y: pose.y }"), "carried-item visibility culling avoids temporary object allocation"); console.log("[OK] performance architecture: differential counters, event triggers, hidden UI gating, and pre-render culling verified");