import { describe, expect, it } from "vitest"; import { authorityTier, capacitySanity, classifyAiEvidence, classifyCapacitySemantics, classifyInvestmentSemantics, classifyProjectEvent, classifyScope, findEvidence, investmentSanity, moneyMwCollision, projectTransition, sentenceSpans } from "./claims.js"; describe("classifyScope", () => { it("detects portfolio / company / country figures", () => { expect(classifyScope("bringing its total capacity to over 410MW in Japan").scope).toBe("portfolio"); expect(classifyScope("STACK now operates more than 1.2 GW across its global portfolio").scope).toBe("portfolio"); expect(classifyScope("Microsoft plans to spend $80 billion in capex in fiscal 2025").scope).toBe("company"); expect(classifyScope("the national programme will add 5 GW across the country").scope).toBe("country"); expect(classifyScope("Hyperscale Data Center Market to Surpass USD 624.2 Billion by 2035, CAGR of 9%").scope).toBe("company"); }); it("detects campus / building / facility figures", () => { expect(classifyScope("the campus will deliver 300 MW at full build-out").scope).toBe("campus"); expect(classifyScope("the first building offers 24 MW of critical IT load").scope).toBe("building"); expect(classifyScope("the facility will provide 36 MW").scope).toBe("facility"); }); it("falls back to the subject hint only without any signal", () => { expect(classifyScope("36 MW", "facility").scope).toBe("facility"); expect(classifyScope("36 MW").scope).toBe("unknown"); }); }); describe("classifyCapacitySemantics", () => { it("separates IT load, grid, utility, planned, ultimate and phase figures", () => { expect(classifyCapacitySemantics("0.779MW Critical IT Load").predicate).toBe("critical_power_mw"); expect(classifyCapacitySemantics("offers 24 MW of IT capacity").predicate).toBe("it_capacity_mw"); expect(classifyCapacitySemantics("secured a 300 MW grid connection agreement with Dominion").predicate).toBe("grid_connection_mw"); expect(classifyCapacitySemantics("dual utility feeds totaling 60 MW of utility power").predicate).toBe("utility_capacity_mw"); expect(classifyCapacitySemantics("the campus will scale up to 1 GW at full build-out").predicate).toBe("ultimate_campus_mw"); expect(classifyCapacitySemantics("the first phase will deliver 48 MW").predicate).toBe("phase_mw"); expect(classifyCapacitySemantics("the planned 200 MW facility").predicate).toBe("planned_power_mw"); expect(classifyCapacitySemantics("currently operating 12 MW").predicate).toBe("current_power_mw"); expect(classifyCapacitySemantics("36 MW").predicate).toBeNull(); }); }); describe("classifyInvestmentSemantics", () => { it("keeps deal values and company capex away from project investment", () => { expect(classifyInvestmentSemantics("Microsoft will invest $80 billion through 2030 across its global fleet").predicate).toBe("multi_year_capex_usd"); expect(classifyInvestmentSemantics("acquires the portfolio for $2.3 billion").predicate).toBe("deal_value_usd"); expect(classifyInvestmentSemantics("the $1.2 billion campus in Abilene").predicate).toBe("campus_investment_usd"); expect(classifyInvestmentSemantics("a $500 million investment in the new facility", "facility").predicate).toBe("project_investment_usd"); }); }); describe("sanity engines", () => { it("blocks unscoped and market-statistic MW", () => { const flags = capacitySanity({ value: 12_000, predicate: null, scope: "company", recordScope: "project" }); expect(flags.some((f) => f.code === "scope_company" && f.blocks)).toBe(true); expect(capacitySanity({ value: 25_000, predicate: "planned_power_mw", scope: "campus", recordScope: "project" }).some((f) => f.code === "mw_market_statistic")).toBe(true); }); it("flags single facilities above 1 GW, 5x changes and money collisions", () => { expect(capacitySanity({ value: 1_500, predicate: "it_capacity_mw", scope: "facility", recordScope: "facility" }).map((f) => f.code)).toContain("mw_single_site_gt_1000"); 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"); expect(capacitySanity({ value: 779, predicate: "it_capacity_mw", scope: "facility", recordScope: "facility", previous: 0.779 }).map((f) => f.code)).toContain("mw_change_5x"); expect(moneyMwCollision("a $300 million, 300 MW campus")).toBe(true); expect(moneyMwCollision("a $300 million, 48 MW campus")).toBe(false); }); it("flags implausible investments", () => { expect(investmentSanity({ value: 175e9, scope: "facility", predicate: "project_investment_usd", recordScope: "project" }).map((f) => f.code)).toContain("inv_single_site_gt_50b"); expect(investmentSanity({ value: 624e9, scope: "company", predicate: "multi_year_capex_usd", recordScope: "project" }).some((f) => f.blocks)).toBe(true); }); }); describe("findEvidence", () => { 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."; it("returns the sentence quoting the figure with offsets", () => { const ev = findEvidence(text, 500, "mw"); expect(ev?.text).toMatch(/Lancaster will deliver 500 MW/); expect(text.slice(ev!.start, ev!.end)).toBe(ev!.text); expect(findEvidence(text, 13_000, "mw")?.text).toMatch(/13 GW/); expect(findEvidence(text, 42, "mw")).toBeNull(); }); it("finds money in billions and millions", () => { expect(findEvidence("Meta will spend $10 billion on the Richland Parish site.", 10e9, "usd")?.text).toMatch(/\$10 billion/); expect(findEvidence("A US$450 million facility.", 450e6, "usd")).not.toBeNull(); }); it("splits sentences with offsets", () => { const spans = sentenceSpans("One. Two two. Three?"); expect(spans.map((s) => s.text)).toEqual(["One.", "Two two.", "Three?"]); }); }); describe("classifyProjectEvent", () => { it("vetoes appointments, market research, PPAs, HQs and financing", () => { expect(classifyProjectEvent({ title: "STACK Infrastructure Appoints Matt VanderZanden as Chief Executive Officer, STACK Americas" }).class).toBe("EXECUTIVE_APPOINTMENT"); expect(classifyProjectEvent({ title: "Hyperscale Data Center Market to Surpass USD 624.2 Billion by 2035" }).class).toBe("GENERAL_COMPANY_NEWS"); 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"); expect(classifyProjectEvent({ title: "STACK Secures $1.3B Financing for Development" }).class).toBe("FINANCING"); expect(classifyProjectEvent({ title: "AirTrunk unveils new global headquarters in Sydney" }).mayCreateProject).toBe(false); expect(classifyProjectEvent({ title: "Element Critical Enters Chicago Market Acquiring Two Data Centers in the Suburbs" }).class).toBe("ACQUISITION"); expect(classifyProjectEvent({ title: "Deepening our investment in Richland Parish, Louisiana" }).mayCreateProject).toBe(false); }); it("recognises physical development with strong evidence", () => { const c = classifyProjectEvent({ title: "Vantage breaks ground on 192 MW campus in Frederick, Maryland", hasOperator: true, hasLocation: true, hasExplicitName: false }); expect(c.class).toBe("CONSTRUCTION_START"); expect(c.mayCreateProject).toBe(true); expect(classifyProjectEvent({ title: "Microsoft to build $3.3 billion data center campus in Mount Pleasant, Wisconsin", hasOperator: true, hasLocation: true }).class).toBe("NEW_BUILD"); expect(classifyProjectEvent({ title: "Loudoun County approves rezoning for 300 MW data center campus", hasLocation: true, hasExplicitName: true }).class).toBe("PERMIT"); expect(classifyProjectEvent({ title: "Compass acquires 400-acre site in Red Oak for data center campus", hasOperator: true, hasLocation: true }).class).toBe("LAND_ACQUISITION"); expect(classifyProjectEvent({ title: "STACK Grows Northern Virginia Data Center Campus", hasOperator: true, hasLocation: true }).class).toBe("EXPANSION"); }); it("needs name-or-operator + location + verb to create a project", () => { const weak = classifyProjectEvent({ title: "Massive data center investment announced", hasOperator: false, hasLocation: false }); expect(weak.mayCreateProject).toBe(false); const build = classifyProjectEvent({ title: "Data center campus planned", hasOperator: false, hasLocation: true, hasExplicitName: false }); expect(build.evidence.strength).toBe("weak"); }); it("lets a build headline override a financing keyword", () => { const c = classifyProjectEvent({ title: "Aligned secures $2B financing to build 400 MW campus in Phoenix", hasOperator: true, hasLocation: true }); expect(c.physical).toBe(true); }); }); describe("authority and transitions", () => { it("uses field-level authority tiers", () => { expect(authorityTier({ field: "capacity", sourceKind: "utility" })).toBe("A"); expect(authorityTier({ field: "capacity", sourceKind: "community" })).toBe("E"); expect(authorityTier({ field: "geometry", sourceKind: "community" })).toBe("A"); expect(authorityTier({ field: "interconnection", sourceKind: "registry" })).toBe("A"); expect(authorityTier({ field: "capacity", sourceKind: "operator", isEstimate: true })).toBe("C"); expect(authorityTier({ field: "capacity", sourceKind: "news", method: "llm:extract" })).toBe("E"); }); it("validates project lifecycle transitions", () => { expect(projectTransition("announced", "permitting")).toBe("forward"); expect(projectTransition("under_construction", "delayed")).toBe("side"); expect(projectTransition("delayed", "under_construction")).toBe("resume"); expect(projectTransition("operational", "announced")).toBe("backward"); expect(projectTransition("operational", "cancelled")).toBe("invalid"); expect(projectTransition(null, "announced")).toBe("forward"); }); it("grades AI evidence", () => { expect(classifyAiEvidence("a purpose-built AI campus with NVIDIA GB200 systems").level).toBe("confirmed"); expect(classifyAiEvidence("AI-ready, liquid-cooled halls at 130 kW per rack").level).toBe("likely"); expect(classifyAiEvidence("leased to CoreWeave").level).toBe("associated"); expect(classifyAiEvidence("a colocation facility").level).toBe("unknown"); }); });