Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions __tests__/bundle-initial-load.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { describe, expect, it } from "vitest";
import {
checkBudgets,
loadExceptions,
loadBaseline,
analyzeRouteInitialLoad,
formatReport,
DEFAULT_BUDGET_KB,
ROUTE_INITIAL_LOAD_BUDGET_KB
} from "@/scripts/bundle-budget.mjs";

describe("Initial-Load Performance Budgets & SDK Exception Path (#159)", () => {
const sampleExceptions = {
"xdr-inspector": {
budgetKB: 350,
justification: "Deep recursive XDR parser and Soroban contract type schemas",
approved: true
},
"soroban-decoder": {
budgetKB: 300,
justification: "Full Soroban ScVal decoding and contract auth types",
approved: true
}
};

const sampleBaseline = {
"address-validator": { totalSize: 102400, sizeKB: 100 },
"_route_initial_load": { totalSize: 184320, sizeKB: 180 }
};

it("approves standard feature within normal budget", () => {
const featureSizes = {
"address-validator": { totalSize: 110 * 1024, chunks: [] }
};
const routeInitialLoad = { totalSize: 150 * 1024, sizeKB: 150, chunks: [] };

const { results, routeResult, hasViolations } = checkBudgets(
featureSizes,
routeInitialLoad,
sampleBaseline,
sampleExceptions
);

expect(hasViolations).toBe(false);
expect(results[0].status).toBe("OK");
expect(results[0].withinBudget).toBe(true);
expect(routeResult.status).toBe("OK");
});

it("flags violation when tool exceeds budget without approved exception", () => {
const featureSizes = {
"random-heavy-tool": { totalSize: 180 * 1024, chunks: [] } // Exceeds default 150 KB
};
const routeInitialLoad = { totalSize: 150 * 1024, sizeKB: 150, chunks: [] };

const { results, hasViolations } = checkBudgets(
featureSizes,
routeInitialLoad,
sampleBaseline,
sampleExceptions
);

expect(hasViolations).toBe(true);
expect(results[0].status).toBe("EXCEEDED");
expect(results[0].withinBudget).toBe(false);
});

it("approves SDK-heavy feature that exceeds standard budget via documented exception path", () => {
const featureSizes = {
"xdr-inspector": { totalSize: 280 * 1024, chunks: [] } // 280 KB > 150 KB standard, but < 350 KB exception ceiling
};
const routeInitialLoad = { totalSize: 150 * 1024, sizeKB: 150, chunks: [] };

const { results, hasViolations } = checkBudgets(
featureSizes,
routeInitialLoad,
sampleBaseline,
sampleExceptions
);

expect(hasViolations).toBe(false);
expect(results[0].status).toBe("EXCEPTION_APPROVED");
expect(results[0].withinBudget).toBe(true);
expect(results[0].isException).toBe(true);
expect(results[0].justification).toContain("Deep recursive XDR parser");
});

it("rejects feature that exceeds its approved exception ceiling", () => {
const featureSizes = {
"xdr-inspector": { totalSize: 380 * 1024, chunks: [] } // 380 KB > 350 KB exception ceiling!
};
const routeInitialLoad = { totalSize: 150 * 1024, sizeKB: 150, chunks: [] };

const { results, hasViolations } = checkBudgets(
featureSizes,
routeInitialLoad,
sampleBaseline,
sampleExceptions
);

expect(hasViolations).toBe(true);
expect(results[0].status).toContain("EXCEEDED");
expect(results[0].withinBudget).toBe(false);
});

it("enforces route-level initial-load budget limit", () => {
const featureSizes = {
"address-validator": { totalSize: 100 * 1024, chunks: [] }
};
// Exceeds 220 KB route initial-load budget
const heavyRouteInitialLoad = { totalSize: 260 * 1024, sizeKB: 260, chunks: [] };

const { routeResult, hasViolations } = checkBudgets(
featureSizes,
heavyRouteInitialLoad,
sampleBaseline,
sampleExceptions
);

expect(hasViolations).toBe(true);
expect(routeResult.status).toBe("EXCEEDED");
expect(routeResult.withinBudget).toBe(false);
});

it("loads documented exceptions catalog from repository file", () => {
const exceptions = loadExceptions();
expect(exceptions["xdr-inspector"]).toBeDefined();
expect(exceptions["xdr-inspector"].approved).toBe(true);
expect(exceptions["xdr-inspector"].budgetKB).toBeGreaterThan(DEFAULT_BUDGET_KB);
});

it("formats comprehensive report containing route and exception information", () => {
const results = [
{
feature: "xdr-inspector",
sizeKB: 280,
budgetKB: 350,
isException: true,
justification: "Soroban bindings",
status: "EXCEPTION_APPROVED",
delta: 0,
baselineSizeKB: 280,
withinBudget: true
}
];
const routeResult = {
name: "Route Initial-Load (/tools/[slug])",
sizeKB: 180,
budgetKB: ROUTE_INITIAL_LOAD_BUDGET_KB,
baselineSizeKB: 180,
delta: 0,
status: "OK",
withinBudget: true
};

const report = formatReport(results, routeResult, false);
expect(report).toContain("UTIX INITIAL-LOAD & FEATURE BUNDLE BUDGET REPORT");
expect(report).toContain("ROUTE INITIAL-LOAD COSTS");
expect(report).toContain("Exception Approved: Soroban bindings");
});
});
126 changes: 126 additions & 0 deletions __tests__/storage-isolation.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { cleanup, screen, act } from "@testing-library/react";
import { afterEach, describe, expect, it } from "vitest";
import { renderFeature, createIsolatedStorage } from "@/core/testing";
import { useNetwork } from "@/core/network/NetworkProvider";
import { useNotifications } from "@/core/notifications/NotificationProvider";
import { NETWORK_STORAGE_KEY } from "@/core/network/config";

function TestConsumer() {
const { network, setNetwork } = useNetwork();
const { notifications, unreadCount, publish } = useNotifications();

return (
<div>
<span data-testid="network-status">{network}</span>
<span data-testid="unread-count">{unreadCount}</span>
<button type="button" onClick={() => setNetwork("mainnet")}>
Switch to Mainnet
</button>
<button
type="button"
onClick={() =>
publish({
recipient: "workspace",
event: "failure",
tone: "warning",
title: "Test Alert",
message: "Action required",
href: "/tools/test",
dedupeKey: `alert-${Date.now()}`,
urgency: "standard",
category: "operational"
})
}
>
Send Notification
</button>
<ul>
{notifications.map((n) => (
<li key={n.id}>{n.title}</li>
))}
</ul>
</div>
);
}

describe("Deterministic Browser Storage Isolation (#155)", () => {
afterEach(() => {
cleanup();
});

describe("Failing-order regression test demonstration", () => {
it("demonstrates state contamination when sharing unisolated storage across tests", () => {
// Unisolated shared storage simulation
const leakySharedStorage = createIsolatedStorage();

// Test 1: Mutates shared storage to 'mainnet'
leakySharedStorage.setItem(NETWORK_STORAGE_KEY, "mainnet");

// Test 2 (running after Test 1): Expects default clean state, but gets contaminated by Test 1!
const leakedValue = leakySharedStorage.getItem(NETWORK_STORAGE_KEY);
expect(leakedValue).toBe("mainnet"); // Demonstrates leakage hazard
});
});

describe("Deterministic isolation with renderFeature and injected storage", () => {
it("Step A: Render 1 modifies network and publishes notifications in its isolated fixture", async () => {
const { user, storage } = renderFeature(<TestConsumer />);

expect(screen.getByTestId("network-status").textContent).toBe("testnet");
expect(screen.getByTestId("unread-count").textContent).toBe("0");

// Mutate network to mainnet
await user.click(screen.getByRole("button", { name: "Switch to Mainnet" }));
expect(screen.getByTestId("network-status").textContent).toBe("mainnet");
expect(storage.getItem(NETWORK_STORAGE_KEY)).toBe("mainnet");

// Send notification
await user.click(screen.getByRole("button", { name: "Send Notification" }));
expect(screen.getByTestId("unread-count").textContent).toBe("1");
});

it("Step B: Render 2 starts with pristine testnet and zero notifications (independent of Step A)", () => {
// Render 2 runs after Step A. Without isolation, Step A's mainnet and notifications would leak.
// With deterministic isolation, Render 2 owns a brand new storage fixture.
const { storage } = renderFeature(<TestConsumer />);

expect(screen.getByTestId("network-status").textContent).toBe("testnet");
expect(screen.getByTestId("unread-count").textContent).toBe("0");
expect(storage.getItem(NETWORK_STORAGE_KEY)).toBeNull();
});

it("supports explicitly sharing an injected storage fixture when persistence is under test", async () => {
const sharedFixture = createIsolatedStorage();

// First session: write to the explicit fixture
const session1 = renderFeature(<TestConsumer />, { storage: sharedFixture });
await session1.user.click(session1.getByRole("button", { name: "Switch to Mainnet" }));
expect(session1.getByTestId("network-status").textContent).toBe("mainnet");
cleanup();

// Second session: re-mount with the SAME fixture to test persistence
const session2 = renderFeature(<TestConsumer />, { storage: sharedFixture });
expect(session2.getByTestId("network-status").textContent).toBe("mainnet");
});

it("createIsolatedStorage provides complete Storage interface fidelity", () => {
const storage = createIsolatedStorage({ initialKey: "initialValue" });

expect(storage.length).toBe(1);
expect(storage.getItem("initialKey")).toBe("initialValue");
expect(storage.key(0)).toBe("initialKey");

storage.setItem("key2", "value2");
expect(storage.length).toBe(2);
expect(storage.getItem("key2")).toBe("value2");

storage.removeItem("initialKey");
expect(storage.length).toBe(1);
expect(storage.getItem("initialKey")).toBeNull();

storage.clear();
expect(storage.length).toBe(0);
expect(storage.getItem("key2")).toBeNull();
});
});
});
22 changes: 22 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,25 @@ textarea {
html {
scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
html {
scroll-behavior: auto;
}

*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}

.animate-fade-in-up,
.animate-float,
.animate-pulse {
animation: none !important;
}
}

5 changes: 5 additions & 0 deletions bundle-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@
"totalSize": 81920,
"sizeKB": 80,
"timestamp": "2026-09-25T00:00:00.000Z"
},
"_route_initial_load": {
"totalSize": 184320,
"sizeKB": 180,
"timestamp": "2026-09-25T00:00:00.000Z"
}
}
Loading