import assert from "node:assert/strict" import { randomUUID } from "node:crypto" import { writeFile } from "node:fs/promises" import { resolve } from "node:path" /** Owned normal/historical SQL profiles only; fixed global quota evidence. */ export async function acceptPollStorageGlobalCapSql(){ assert([process.env.MMAPP_OWN_SERVER_POLL_STORAGE,process.env.MMAPP_OWN_SERVER_POLL_STORAGE_FRESH].includes("true")) const {pool}=await import("../db/index.js") const {createServerPollStorage}=await import("./server-poll-storage.js") const globalBefore=Number((await pool.query("SELECT admissions FROM server_poll_storage_usage WHERE scope='global'")).rows[0].admissions) const fill=await Promise.allSettled(Array.from({length:130-globalBefore},async()=>{ const scope={receiptId:randomUUID(),kind:"rest" as const,executionId:randomUUID(),ownerId:"owned-fill-"+randomUUID(),bindingProof:"a".repeat(64),contextProof:"b".repeat(64),issuedAt:Date.now()-1000,expiresAt:Date.now()+180000} return createServerPollStorage({scope,connectionId:null,maxStages:8,authorize:async()=>{}}).claim({deadlineAt:Date.now()+60000},async sql=>{ await sql.query("INSERT INTO server_poll_executions(receipt_id,identity_kind,execution_id,binding_proof,context_ciphertext,context_proof) VALUES($1,'rest',$2,$3,'SYNTHETIC',$4)",[scope.receiptId,scope.executionId,scope.bindingProof,scope.contextProof]) }) })) assert.equal(fill.filter(row=>row.status==="fulfilled").length,128-globalBefore) assert.equal(Number((await pool.query("SELECT admissions FROM server_poll_storage_usage WHERE scope='global'")).rows[0].admissions),128) assert.equal((await pool.query("SELECT count(*)::int AS n FROM server_poll_storage_admissions")).rows[0].n,128) assert.equal((await pool.query("SELECT count(*)::int AS n FROM server_poll_storage_usage WHERE scope<>'global' AND admissions=0")).rows[0].n,0) const evidence=await(await import("./server-poll-storage-restore-evidence.sql-helper.js")).pollStorageRestoreEvidence(pool) await writeFile(resolve(process.env.MCP_STATE_DIR!,"poll-storage-owned-restore-evidence.json"),JSON.stringify(evidence),{flag:"wx",mode:0o600}) return {globalAdmissions:128,actualAdmissions:128,concurrentIndependentOwners:true,attemptsRefused:2,zeroOrphanCounters:true} }