spb/datacenterindex
Public
HTML 53.9%
TypeScript 44.5%
JavaScript 0.6%
SQL 0.5%
1import { describe, expect, it } from "vitest";2import { authorityTier, capacitySanity, classifyAiEvidence, classifyCapacitySemantics, classifyInvestmentSemantics, classifyProjectEvent, classifyScope, findEvidence, investmentSanity, moneyMwCollision, projectTransition, sentenceSpans } from "./claims.js";34describe("classifyScope", () => {5 it("detects portfolio / company / country figures", () => {6 expect(classifyScope("bringing its total capacity to over 410MW in Japan").scope).toBe("portfolio");7 expect(classifyScope("STACK now operates more than 1.2 GW across its global portfolio").scope).toBe("portfolio");8 expect(classifyScope("Microsoft plans to spend $80 billion in capex in fiscal 2025").scope).toBe("company");9 expect(classifyScope("the national programme will add 5 GW across the country").scope).toBe("country");10 expect(classifyScope("Hyperscale Data Center Market to Surpass USD 624.2 Billion by 2035, CAGR of 9%").scope).toBe("company");11 });12 it("detects campus / building / facility figures", () => {13 expect(classifyScope("the campus will deliver 300 MW at full build-out").scope).toBe("campus");14 expect(classifyScope("the first building offers 24 MW of critical IT load").scope).toBe("building");15 expect(classifyScope("the facility will provide 36 MW").scope).toBe("facility");16 });17 it("falls back to the subject hint only without any signal", () => {18 expect(classifyScope("36 MW", "facility").scope).toBe("facility");19 expect(classifyScope("36 MW").scope).toBe("unknown");20 });21});2223describe("classifyCapacitySemantics", () => {24 it("separates IT load, grid, utility, planned, ultimate and phase figures", () => {25 expect(classifyCapacitySemantics("0.779MW Critical IT Load").predicate).toBe("critical_power_mw");26 expect(classifyCapacitySemantics("offers 24 MW of IT capacity").predicate).toBe("it_capacity_mw");27 expect(classifyCapacitySemantics("secured a 300 MW grid connection agreement with Dominion").predicate).toBe("grid_connection_mw");28 expect(classifyCapacitySemantics("dual utility feeds totaling 60 MW of utility power").predicate).toBe("utility_capacity_mw");29 expect(classifyCapacitySemantics("the campus will scale up to 1 GW at full build-out").predicate).toBe("ultimate_campus_mw");30 expect(classifyCapacitySemantics("the first phase will deliver 48 MW").predicate).toBe("phase_mw");31 expect(classifyCapacitySemantics("the planned 200 MW facility").predicate).toBe("planned_power_mw");32 expect(classifyCapacitySemantics("currently operating 12 MW").predicate).toBe("current_power_mw");33 expect(classifyCapacitySemantics("36 MW").predicate).toBeNull();34 });35});3637describe("classifyInvestmentSemantics", () => {38 it("keeps deal values and company capex away from project investment", () => {39 expect(classifyInvestmentSemantics("Microsoft will invest $80 billion through 2030 across its global fleet").predicate).toBe("multi_year_capex_usd");40 expect(classifyInvestmentSemantics("acquires the portfolio for $2.3 billion").predicate).toBe("deal_value_usd");41 expect(classifyInvestmentSemantics("the $1.2 billion campus in Abilene").predicate).toBe("campus_investment_usd");42 expect(classifyInvestmentSemantics("a $500 million investment in the new facility", "facility").predicate).toBe("project_investment_usd");43 });44});4546describe("sanity engines", () => {47 it("blocks unscoped and market-statistic MW", () => {48 const flags = capacitySanity({ value: 12_000, predicate: null, scope: "company", recordScope: "project" });49 expect(flags.some((f) => f.code === "scope_company" && f.blocks)).toBe(true);50 expect(capacitySanity({ value: 25_000, predicate: "planned_power_mw", scope: "campus", recordScope: "project" }).some((f) => f.code === "mw_market_statistic")).toBe(true);51 });52 it("flags single facilities above 1 GW, 5x changes and money collisions", () => {53 expect(capacitySanity({ value: 1_500, predicate: "it_capacity_mw", scope: "facility", recordScope: "facility" }).map((f) => f.code)).toContain("mw_single_site_gt_1000");54 expect(capacitySanity({ value: 1_500, predicate: "ultimate_campus_mw", scope: "campus", recordScope: "campus", campusDesignation: true }).map((f) => f.code)).not.toContain("mw_single_site_gt_1000");55 expect(capacitySanity({ value: 779, predicate: "it_capacity_mw", scope: "facility", recordScope: "facility", previous: 0.779 }).map((f) => f.code)).toContain("mw_change_5x");56 expect(moneyMwCollision("a $300 million, 300 MW campus")).toBe(true);57 expect(moneyMwCollision("a $300 million, 48 MW campus")).toBe(false);58 });59 it("flags implausible investments", () => {60 expect(investmentSanity({ value: 175e9, scope: "facility", predicate: "project_investment_usd", recordScope: "project" }).map((f) => f.code)).toContain("inv_single_site_gt_50b");61 expect(investmentSanity({ value: 624e9, scope: "company", predicate: "multi_year_capex_usd", recordScope: "project" }).some((f) => f.blocks)).toBe(true);62 });63});6465describe("findEvidence", () => {66 const text = "STACK Infrastructure today announced the appointment of Matt VanderZanden as CEO. The company operates more than 13 GW across its portfolio. Its newest campus in Lancaster will deliver 500 MW at full build-out.";67 it("returns the sentence quoting the figure with offsets", () => {68 const ev = findEvidence(text, 500, "mw");69 expect(ev?.text).toMatch(/Lancaster will deliver 500 MW/);70 expect(text.slice(ev!.start, ev!.end)).toBe(ev!.text);71 expect(findEvidence(text, 13_000, "mw")?.text).toMatch(/13 GW/);72 expect(findEvidence(text, 42, "mw")).toBeNull();73 });74 it("finds money in billions and millions", () => {75 expect(findEvidence("Meta will spend $10 billion on the Richland Parish site.", 10e9, "usd")?.text).toMatch(/\$10 billion/);76 expect(findEvidence("A US$450 million facility.", 450e6, "usd")).not.toBeNull();77 });78 it("splits sentences with offsets", () => {79 const spans = sentenceSpans("One. Two two. Three?");80 expect(spans.map((s) => s.text)).toEqual(["One.", "Two two.", "Three?"]);81 });82});8384describe("classifyProjectEvent", () => {85 it("vetoes appointments, market research, PPAs, HQs and financing", () => {86 expect(classifyProjectEvent({ title: "STACK Infrastructure Appoints Matt VanderZanden as Chief Executive Officer, STACK Americas" }).class).toBe("EXECUTIVE_APPOINTMENT");87 expect(classifyProjectEvent({ title: "Hyperscale Data Center Market to Surpass USD 624.2 Billion by 2035" }).class).toBe("GENERAL_COMPANY_NEWS");88 expect(classifyProjectEvent({ title: "Ormat Technologies Signs 20-Year PPA with Switch for ~13 MW of Carbon-Free Geothermal Capacity to Power Data Centers" }).class).toBe("POWER_AGREEMENT");89 expect(classifyProjectEvent({ title: "STACK Secures $1.3B Financing for Development" }).class).toBe("FINANCING");90 expect(classifyProjectEvent({ title: "AirTrunk unveils new global headquarters in Sydney" }).mayCreateProject).toBe(false);91 expect(classifyProjectEvent({ title: "Element Critical Enters Chicago Market Acquiring Two Data Centers in the Suburbs" }).class).toBe("ACQUISITION");92 expect(classifyProjectEvent({ title: "Deepening our investment in Richland Parish, Louisiana" }).mayCreateProject).toBe(false);93 });94 it("recognises physical development with strong evidence", () => {95 const c = classifyProjectEvent({ title: "Vantage breaks ground on 192 MW campus in Frederick, Maryland", hasOperator: true, hasLocation: true, hasExplicitName: false });96 expect(c.class).toBe("CONSTRUCTION_START");97 expect(c.mayCreateProject).toBe(true);98 expect(classifyProjectEvent({ title: "Microsoft to build $3.3 billion data center campus in Mount Pleasant, Wisconsin", hasOperator: true, hasLocation: true }).class).toBe("NEW_BUILD");99 expect(classifyProjectEvent({ title: "Loudoun County approves rezoning for 300 MW data center campus", hasLocation: true, hasExplicitName: true }).class).toBe("PERMIT");100 expect(classifyProjectEvent({ title: "Compass acquires 400-acre site in Red Oak for data center campus", hasOperator: true, hasLocation: true }).class).toBe("LAND_ACQUISITION");101 expect(classifyProjectEvent({ title: "STACK Grows Northern Virginia Data Center Campus", hasOperator: true, hasLocation: true }).class).toBe("EXPANSION");102 });103 it("needs name-or-operator + location + verb to create a project", () => {104 const weak = classifyProjectEvent({ title: "Massive data center investment announced", hasOperator: false, hasLocation: false });105 expect(weak.mayCreateProject).toBe(false);106 const build = classifyProjectEvent({ title: "Data center campus planned", hasOperator: false, hasLocation: true, hasExplicitName: false });107 expect(build.evidence.strength).toBe("weak");108 });109 it("lets a build headline override a financing keyword", () => {110 const c = classifyProjectEvent({ title: "Aligned secures $2B financing to build 400 MW campus in Phoenix", hasOperator: true, hasLocation: true });111 expect(c.physical).toBe(true);112 });113});114115describe("authority and transitions", () => {116 it("uses field-level authority tiers", () => {117 expect(authorityTier({ field: "capacity", sourceKind: "utility" })).toBe("A");118 expect(authorityTier({ field: "capacity", sourceKind: "community" })).toBe("E");119 expect(authorityTier({ field: "geometry", sourceKind: "community" })).toBe("A");120 expect(authorityTier({ field: "interconnection", sourceKind: "registry" })).toBe("A");121 expect(authorityTier({ field: "capacity", sourceKind: "operator", isEstimate: true })).toBe("C");122 expect(authorityTier({ field: "capacity", sourceKind: "news", method: "llm:extract" })).toBe("E");123 });124 it("validates project lifecycle transitions", () => {125 expect(projectTransition("announced", "permitting")).toBe("forward");126 expect(projectTransition("under_construction", "delayed")).toBe("side");127 expect(projectTransition("delayed", "under_construction")).toBe("resume");128 expect(projectTransition("operational", "announced")).toBe("backward");129 expect(projectTransition("operational", "cancelled")).toBe("invalid");130 expect(projectTransition(null, "announced")).toBe("forward");131 });132 it("grades AI evidence", () => {133 expect(classifyAiEvidence("a purpose-built AI campus with NVIDIA GB200 systems").level).toBe("confirmed");134 expect(classifyAiEvidence("AI-ready, liquid-cooled halls at 130 kW per rack").level).toBe("likely");135 expect(classifyAiEvidence("leased to CoreWeave").level).toBe("associated");136 expect(classifyAiEvidence("a colocation facility").level).toBe("unknown");137 });138});139