import assert from "node:assert/strict"; import fs from "node:fs"; import { ALLOWED_RUNTIME_KEYS, compactRuntimeTransportSnapshot, validateRuntimeSnapshot } from "./run-autonomous-cycle.mjs"; const index = fs.readFileSync(new URL("../index.html", import.meta.url), "utf8"); const api = fs.readFileSync(new URL("../api/state.js", import.meta.url), "utf8"); const workflow = fs.readFileSync(new URL("../.github/workflows/autonomous-cycle.yml", import.meta.url), "utf8"); const routingReleaseWorkflow = fs.readFileSync(new URL("../.github/workflows/release-protected-routing.yml", import.meta.url), "utf8"); const vercelConfig = JSON.parse(fs.readFileSync(new URL("../vercel.json", import.meta.url), "utf8")); const runner = fs.readFileSync(new URL("./run-autonomous-cycle.mjs", import.meta.url), "utf8"); const resolutionAudit = JSON.parse(fs.readFileSync(new URL("../research/resolution-week-no-audit.json", import.meta.url), "utf8")); const sportsContestAudit = JSON.parse(fs.readFileSync(new URL("../research/sports-contest-no-exploration-audit.json", import.meta.url), "utf8")); const sportsDisjointAudit = JSON.parse(fs.readFileSync(new URL("../research/sports-contest-no-disjoint-10000-audit.json", import.meta.url), "utf8")); const adaptiveAudit = JSON.parse(fs.readFileSync(new URL("../research/adaptive-strategy-64-audit.json", import.meta.url), "utf8")); const settlementCalibrationAudit = JSON.parse(fs.readFileSync(new URL("../research/settlement-calibration-exact-fee-5000-audit.json", import.meta.url), "utf8")); const sportsEvaluator = fs.readFileSync(new URL("./evaluate-sports-favorites.mjs", import.meta.url), "utf8"); const build = Number(index.match(/const BUILD_VERSION = (\d+);/)?.[1]); assert.equal(build, 127); assert.equal(vercelConfig.git?.deploymentEnabled?.["runtime-state"], false); assert.equal(settlementCalibrationAudit.requested_markets, 5000); assert.equal(settlementCalibrationAudit.train_passed, 0); assert.equal(settlementCalibrationAudit.validation_selected, 0); assert.equal(settlementCalibrationAudit.holdout_passed, 0); assert.match(index, /Adaptive strategy 65 · expanded executable search · build 127/); assert.deepEqual([...ALLOWED_RUNTIME_KEYS].sort(), ["pma_agents_v2", "pma_suggestions_v5"]); assert.match(index, /function collectPublicRuntimeItems\(\)/); assert.match(index, /const PUBLIC_RUNTIME_KEYS=Object\.freeze\(\[AGENTS_KEY,SUG_KEY\]\)/); assert.match(index, /suggestions:300/); assert.match(index, /function compactPublicSuggestionsForSync\(payload\)/); assert.match(index, /drivers\.slice\(0,1\)/); assert.match(index, /if\(!out\.trade_ready\)\{delete out\.clob_yes;delete out\.clob_no;\}/); assert.match(index, /function compactPublicSignalLedger\(ledger\)/); assert.match(index, /st\.signal_ledger=compactPublicSignalLedger\(st\.signal_ledger\)/); assert.match(index, /const PUBLIC_RUNTIME_SNAPSHOT_BUDGET_BYTES = 875000;/); assert.match(index, /const PUBLIC_SIGNAL_OUTCOME_RESERVE = 144;/); assert.match(index, /const PUBLIC_SIGNAL_LEDGER_RESERVE_BYTES = 75000;/); assert.match(index, /history:48,snapshots:96,suggestions:300/); assert.match(index, /function compactHistoryForPublic\(row\)/); assert.match(index, /function compactSnapshotsForPublic\(rows,limit=PUBLIC_RUNTIME_LIMITS\.snapshots\)/); assert.match(index, /sourceLimits=Object\.assign\(\{\},PUBLIC_RUNTIME_LIMITS,\{snapshots:SYNC_LIMITS\.snapshots\}\)/); assert.match(index, /PUBLIC_RUNTIME_MAKER_OUTCOME_LIMIT/); assert.match(index, /PUBLIC_RUNTIME_HISTORY_FLOOR/); assert.match(index, /PUBLIC_RUNTIME_SUGGESTION_FLOOR/); assert.match(index, /function compactMakerOutcomeForPublic\(row\)/); assert.match(index, /publicMakerCompactionPreservesCalibration:/); assert.match(index, /function fitPublicRuntimeSnapshot\(snapshot\)/); assert.match(index, /reservedCount=Math\.min\(PUBLIC_SIGNAL_OUTCOME_RESERVE,outcomes\.length\)/); assert.match(index, /return fitPublicRuntimeSnapshot\(snapshot\)/); assert.match(index, /publicCompactionPreservesForwardGrading:/); assert.match(index, /publicCompactionPreservesAgentCalibration:/); assert.match(index, /const DIRECTIONAL_PROBATION_HORIZON_HOURS = 6;/); assert.match(index, /const DIRECTIONAL_PROBATION_MIN_EVENTS = 12;/); assert.match(index, /sixHourEvidenceStartsBoundedProbation:/); assert.match(index, /probationMetadataSurvivesOfflineCompaction:/); assert.match(index, /probationExitsAtExecutableSixHourPrice:/); assert.match(index, /updateSignalLedger\(st,\[\.\.\.analysisMarkets,\.\.\.supplemental\],sugs,\{liveEvidence:runMode==="live"\}\)/); assert.match(index, /offlineEvidenceCapabilityIsReadOnly:/); assert.match(index, /claimedProbationEvents/); assert.match(api, /adaptive_probation: s\.adaptive_probation, probation_exit_hours: s\.probation_exit_hours/); assert.match(index, /function buildRuntimeFallbackMarketCache\(stored,state\)/); assert.match(index, /buildRuntimeFallbackMarketCache\(stored,st\)/); assert.match(index, /window\.PMA_AUTOMATION=Object\.freeze/); assert.match(index, /if\(CLOUD_STATE_HEALTH\.read_only\)return false/); assert.match(index, /function autonomousRuntimeControlsCycle/); assert.match(index, /if\(CYCLE_RUNNING\|\|autonomousRuntimeControlsCycle\(\)\)return/); assert.match(index, /btn\.textContent="Auto cycle"/); assert.match(api, /runtime-state\/runtime\/state\.json/); assert.match(api, /sanitizeGithubRuntimeState/); assert.match(api, /api\.github\.com\/repos\/theodore-song\/polymarket-analyst\/contents\/runtime\/state\.json/); assert.match(api, /Buffer\.from\(file\.content/); assert.match(api, /searchParams\.set\("runtime", `\$\{Date\.now\(\)\}/); assert.match(workflow, /cron: "2,7,12,17,22,27,32,37,42,47,52,57 \* \* \* \*"/); assert.match(workflow, /contents: write/); assert.match(workflow, /EXPECTED_BUILD: "127"/); assert.equal((workflow.match(/if: always\(\)/g) || []).length, 2); assert.match(routingReleaseWorkflow, /name: Release expanded executable search after Vercel quota reset/); assert.match(routingReleaseWorkflow, /BUNDLE_DEPTH_CANDIDATE_LIMIT=200/); assert.match(routingReleaseWorkflow, /cron: "25 1-23\/2 23 8 \*"/); assert.match(workflow, /actions: write/); assert.match(workflow, /cancel-in-progress: false/); assert.match(workflow, /next=\$\(\( \(now \/ 300 \+ 1\) \* 300 \+ 15 \)\)/); assert.match(workflow, /actions\/workflows\/autonomous-cycle\.yml\/dispatches/); assert.match(workflow, /--data '\{"ref":"main"\}'/); assert.match(index, /cloudRestartReconstructsOfflineCache:true/); assert.match(index, /saveSuggestions\(sugs,markets\.length,analysisMarkets\.length,bundleAudit\)/); assert.match(index, /const NEG_RISK_EVENT_SCAN_LIMIT=1000;/); assert.match(index, /bundleOpportunityTelemetry:true/); assert.match(index, /function completeBundleSecuredProfit\(p\)/); assert.match(index, /label:"Secured bundle profit"/); assert.match(index, /additional settlement profit is secured by intact verified bundles/); assert.match(index, /const BUNDLE_DEPTH_CANDIDATE_LIMIT=200;/); assert.match(index, /const BINARY_COMPLEMENT_DEPTH_RESERVE=40;/); assert.match(index, /const NEG_RISK_CONVERSION_DEPTH_RESERVE=40;/); assert.match(index, /bundleRequiresDepthVerification:true/); assert.match(index, /bundleRequiresClobFeeVerification:true/); assert.match(index, /function bundleExecutableLeg\(book,units,feeSchedule\)/); assert.match(index, /function generalAdaptiveLearningExclusion\(trade\)/); assert.match(index, /specializedUnsafeTradesCannotBiasDirectionalLearning:/); assert.match(index, /function fetchBundleFeeSchedules\(conditionIds\)/); assert.match(index, /function fetchNegativeRiskConversionTerms\(marketIds\)/); assert.match(index, /const NEG_RISK_ADAPTER_ADDRESS="0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296";/); assert.match(index, /const NEG_RISK_FEE_BIPS_SELECTOR="0x2582cb5e";/); assert.match(index, /const NEG_RISK_QUESTION_COUNT_SELECTOR="0xb7f75d2c";/); assert.match(index, /const NEG_RISK_RPC_BATCH_CALL_LIMIT=10;/); assert.match(index, /function applyNegativeRiskConversionTerms\(candidate,terms\)/); assert.match(index, /function bundleFeeSchedulesMatch\(expected,reported\)/); assert.match(index, /rejectsMismatchedClobFeeCurve:/); assert.doesNotMatch(index, /\/fee-rate\?token_id=/); assert.match(index, /function maximizeBundleExecution\(candidate,books,minimumUnits\)/); assert.match(index, /const BUNDLE_MAX_VERIFIED_NOTIONAL=1000;/); assert.match(index, /const BUNDLE_EVENT_CAP_PCT=0\.12;/); assert.match(index, /const NEG_RISK_MIN_NET_PROFIT=0\.001;/); assert.match(index, /const BUNDLE_MIN_EXECUTION_PROFIT=0\.50;/); assert.match(index, /const BUNDLE_IMMEDIATE_MIN_DAILY_RETURN=0\.0001;/); assert.match(index, /const BUNDLE_MIN_DAILY_RETURN=0\.0003;/); assert.match(index, /const BUNDLE_MEDIUM_MIN_DAILY_RETURN=0\.0004;/); assert.match(index, /const BUNDLE_LONG_MIN_DAILY_RETURN=0\.0005;/); assert.match(index, /const BUNDLE_EXTENDED_MIN_DAILY_RETURN=0\.00075;/); assert.match(index, /function bundleMinimumDailyReturn\(item=\{\}\)/); assert.match(index, /function bundleClearsExecutionProfit\(item=\{\}\)/); assert.match(index, /const BUNDLE_BASE_POSITION_CAP_PCT=0\.06;/); assert.match(index, /const BUNDLE_HIGH_EFFICIENCY_POSITION_CAP_PCT=0\.08;/); assert.match(index, /const BUNDLE_IMMEDIATE_POSITION_CAP_PCT=0\.10;/); assert.match(index, /const BUNDLE_HIGH_EFFICIENCY_DAILY_RETURN=0\.002;/); assert.match(index, /function bundlePositionCapPct\(item=\{\}\)/); assert.match(index, /fee_check_eligible_structures:executableAudit\.filter\(candidate=>candidate\.fee_check_attempted\)\.length/); assert.match(index, /"profit-below-floor"/); assert.match(index, /"total-profit-below-floor"/); assert.match(index, /"return-below-floor"/); assert.match(index, /function compareBundleOpportunities\(a,b\)/); assert.match(index, /function binaryComplementBundleSuggestions\(event,\{includeUnprofitable=false\}=\{\}\)/); assert.match(index, /discoversExecutableBinaryComplements:/); assert.match(index, /immediatelyMergesBinaryCompleteSet:/); assert.match(index, /rejectsCrossMarketBinaryMerge:/); assert.match(index, /immediateMergeMetadataSurvivesSync:/); assert.match(api, /bundle_immediate_merge: s\.bundle_immediate_merge/); assert.match(index, /function convertCompleteNegativeRiskNoBundle\(p,bundleId\)/); assert.match(index, /function negativeRiskBundleSuggestions\(event,\{includeUnprofitable=false,conversionTerms=null\}=\{\}\)/); assert.match(index, /function negativeRiskExclusivePairSuggestion\(event,\{includeUnprofitable=false\}=\{\}\)/); assert.match(index, /bundle_logic:"neg-risk-exclusive-no-pair"/); assert.match(index, /const exclusivePair=negativeRiskExclusivePairSuggestion\(event,\{includeUnprofitable:true\}\)/); assert.match(index, /discoversExclusiveNoPair:/); assert.match(index, /rejectsUnprofitableExclusiveNoPair:/); assert.match(index, /rejectsMismatchedNegativeRiskPair:/); assert.match(index, /exclusiveNoPairSettlesAtGuaranteedFloor:/); assert.match(index, /exclusive_pair_structures:exclusivePairs\.length/); assert.match(index, /Exclusive NO pairs:/); assert.match(index, /preservesBothCompleteSidesThroughAudit:/); assert.match(index, /discoversExactCompleteNoConversion:/); assert.match(index, /deductsAdapterFeeFromConversionPayout:/); assert.match(index, /atomicallyConvertsCompleteNoSet:/); assert.match(index, /blocksImmediateConversionOnMismatchedMetadata:/); assert.match(index, /blocksImmediateConversionOnQuestionCountMismatch:/); assert.match(index, /blocksImmediateConversionOnMetadataFeeMismatch:/); assert.match(index, /doesNotInventConversionWithoutAdapterMetadata:/); assert.match(index, /conversion_structures:conversions\.length/); assert.match(index, /conversion_candidates_scanned:audited\.filter\(candidate=>candidate\.bundle_conversion_candidate\)\.length/); assert.match(index, /actionable_conversions:unique\.filter\(candidate=>candidate\.bundle_immediate_convert\)\.length/); assert.match(index, /Exact complete-NO conversion:/); assert.match(api, /bundle_immediate_convert: s\.bundle_immediate_convert/); assert.match(api, /bundle_min_daily_return: s\.bundle_min_daily_return/); assert.match(api, /execution_total_profit: s\.execution_total_profit/); assert.match(api, /neg_risk_market_id: s\.neg_risk_market_id, neg_risk_fee_bips: s\.neg_risk_fee_bips/); assert.match(index, /reservesBinaryComplementDepthChecks:/); assert.match(index, /reservesExactConversionDepthChecks:/); assert.match(index, /function bundleAgentOwnerId\(s\)/); assert.match(index, /routesSettlementCompleteSetsToValue:/); assert.match(index, /routesExactConversionsToMomentum:/); assert.match(index, /routesBinaryMergesToBreakout:/); assert.match(index, /routesExclusiveNoPairToTailAlpha:/); assert.match(index, /ownedProtectedBundlesBypassDirectionalRankFilter:/); assert.match(index, /routesDominanceSpreadsToDiversifier:/); assert.match(index, /bundleResearchOwnershipMatchesCapital:/); assert.match(index, /function currentBundleEventKeys\(st\)/); assert.match(index, /tracksGlobalBundleEventOwnership:/); assert.match(index, /diversifierExecutesVerifiedDominanceSpread:/); assert.match(index, /const claimedBundleEvents=currentBundleEventKeys\(st\);/); assert.match(index, /function bundleVerificationShortlist\(candidates\)/); assert.match(index, /function prioritizeIndependentBundles\(candidates,limit=Infinity\)/); assert.match(index, /prioritizesIndependentEventsBeforeAlternates:/); assert.match(index, /function bundleEventExposure\(portfolio,eventKey\)/); assert.match(index, /function recycleVerifiedBundleCapital\(st,priceMap,\{execute=true\}=\{\}\)/); assert.match(index, /bundleProfitRecyclingRequiresLive:/); assert.match(index, /const BUNDLE_EXIT_PROFIT_CAPTURE=0\.85;/); assert.match(index, /atomicallyRecyclesEightySixPercentProfit:/); assert.match(index, /prioritizesReturnPerLockedDay:/); assert.match(index, /capsUnderlyingEventExposure:/); assert.match(index, /blocksLowReturnPerLockedDay:/); assert.match(index, /shortLocksUseProductiveHurdle:/); assert.match(index, /longLocksRequireMoreReturn:/); assert.match(index, /scalesSlimMarginsToMeaningfulProfit:/); assert.match(index, /rejectsDustProfitDespitePositiveUnitMargin:/); assert.match(index, /actualOpenedSizeMustPreserveProfitFloor:/); assert.match(index, /durationAwareSizingScalesProtectedCapital:/); assert.match(index, /sameCycleEventBurstStaysWithinCap:/); assert.match(index, /sizesToLargestVerifiedProfitableFill:/); assert.match(index, /stopsSizingAtShallowestBundleLeg:/); assert.match(index, /!s\.depth_verified\|\|!s\.fees_verified\|\|s\.verification_status!=="executable"/); assert.match(runner, /MAX_STATE_BYTES = 900_000/); assert.match(runner, /compactRuntimeTransportSnapshot\(rawSnapshot\)/); assert.match(runner, /localStorage\.getItem\(agentKey\)/); assert.match(runner, /localStorage\.getItem\(suggestionsKey\)/); assert.match(runner, /TRANSPORT_TARGET_BYTES = 850_000/); assert.match(runner, /TRANSPORT_SUGGESTION_FLOOR = 240/); assert.match(runner, /Production already advanced to Build \$\{status\.build\}; retiring stale Build \$\{expectedBuild\} runner/); assert.equal(resolutionAudit.strategy, "resolution-window-no-50-55-forward-shadow-v3"); assert.deepEqual(resolutionAudit.selection.horizon_days_enabled, []); assert.deepEqual(resolutionAudit.selection.horizon_days_observed, [4]); assert.equal(resolutionAudit.disjoint_holdout.passed_strict_gate, false); assert.ok(resolutionAudit.disjoint_holdout.holdout_event_lower_90 < 0); assert.equal(resolutionAudit.production_constraints.capital_enabled, false); assert.equal(resolutionAudit.production_constraints.promotion_events, 40); assert.equal(sportsContestAudit.production_strategy, 62); assert.equal(sportsContestAudit.status, "bounded-paper-exploration-not-proven"); assert.equal(sportsContestAudit.corrected_5000_market_result.independent_contests, 76); assert.equal(sportsContestAudit.corrected_5000_market_result.passed_strict_gate, false); assert.ok(sportsContestAudit.corrected_5000_market_result.validation.lower_95 < 0); assert.equal(sportsContestAudit.production_constraints.initial_position_pct, 0.5); assert.equal(sportsContestAudit.production_constraints.total_lane_cap_pct, 3); assert.equal(sportsContestAudit.production_constraints.exact_entry_fee_required, true); assert.equal(sportsDisjointAudit.status, "zero-capital-forward-shadow"); assert.equal(sportsDisjointAudit.recent_5000.holdout_rules_passing, 0); assert.equal(sportsDisjointAudit.older_disjoint_5000.validation_rules_passing, 0); assert.ok(sportsDisjointAudit.recent_5000.closest_rule.holdout_lower_90 < 0); assert.ok(sportsDisjointAudit.older_disjoint_5000.closest_rule.holdout_lower_90 < 0); assert.equal(sportsDisjointAudit.decision.capital_enabled, false); assert.equal(sportsDisjointAudit.decision.initial_position_pct, 0); assert.match(sportsEvaluator, /const MARKET_SKIP =/); assert.match(sportsEvaluator, /fetchMarkets\(MARKET_LIMIT, MARKET_SKIP\)/); assert.equal(adaptiveAudit.strategy, 64); assert.equal(adaptiveAudit.fetched_markets, 500); assert.deepEqual(adaptiveAudit.probation_rule_ids, []); assert.deepEqual(adaptiveAudit.durable_rule_ids, []); assert.ok(adaptiveAudit.horizons.every((row) => row.validation_selected === 0 && row.holdout_passed === 0)); assert.match(index, /function sportsContestKey\(m\)/); assert.match(index, /function sportsContestNoSuggestions\(markets\)/); assert.match(index, /const SPORTS_FAVORITE_MAX_NEW_PER_CYCLE=1;/); assert.match(index, /const SPORTS_FAVORITE_PILOT_POSITION_PCT=0;/); assert.match(index, /capitalRequiresForwardPromotion:true,boundedExploration:false/); assert.match(index, /initialStateIsZeroCapitalShadow:/); assert.match(index, /function compactDecisionForPublic\(decision\)/); assert.match(index, /delete out\.learning\.buckets/); const agentIds = ["value", "momentum", "favorite", "longshot", "diversifier", "catalyst", "reversal", "breakout", "tailalpha", "conviction"]; const agents = Object.fromEntries(agentIds.map(id => [id, { cash: 10000, positions: [], lastDecision: { mode: "test" } }])); const snapshot = { schema_version: 1, build_version: build, generated_at: new Date().toISOString(), last_cycle_hour: "2026-08-21T20|v59", items: { pma_agents_v2: JSON.stringify({ seeded: true, last_cycle_hour: "2026-08-21T20|v59", agents }), pma_suggestions_v5: JSON.stringify({ suggestions: [{ market_id: "test" }] }), }, }; assert.equal(validateRuntimeSnapshot(snapshot, build).agents.seeded, true); assert.throws(() => validateRuntimeSnapshot({ ...snapshot, items: { ...snapshot.items, pma_paper_accounts_v1: "{}" } }, build), /unexpected keys/); assert.throws(() => validateRuntimeSnapshot({ ...snapshot, build_version: build - 1 }, build), /Expected Build/); assert.throws(() => validateRuntimeSnapshot({ ...snapshot, items: { ...snapshot.items, pma_suggestions_v5: JSON.stringify({ suggestions: [] }) } }, build), /no live suggestions/); const transportState = JSON.parse(snapshot.items.pma_agents_v2); for (const [index, portfolio] of Object.values(transportState.agents).entries()) { portfolio.cash = 9000 + index; portfolio.positions = [{ market_id: `position-${index}`, value: 1000 }]; portfolio.history = Array.from({ length: 80 }, (_, row) => ({ date: "2026-08-22", action: "WATCH", question: "q".repeat(180), detail: "d".repeat(500 + row) })); portfolio.snapshots = Array.from({ length: 240 }, (_, row) => ({ timestamp: new Date(1_700_000_000_000 + row * 300_000).toISOString(), equity: 10000 + row })); portfolio.maker_outcomes = Array.from({ length: 45 }, (_, row) => ({ quote_id: `${index}-${row}`, pnl: row / 100 })); } transportState.signal_ledger = { pending: Array.from({ length: 50 }, (_, index) => ({ key: `pending-${index}`, event_key: `event-${index}` })), outcomes: Array.from({ length: 144 }, (_, index) => ({ key: `outcome-${index}`, event_key: `event-${index}`, return: 0.01 })), expired_ungraded: 0, }; const transportSuggestions = { suggestions: Array.from({ length: 300 }, (_, index) => ({ market_id: `${index}`, trade_ready: false, signal_type: "trend", rationale: "r".repeat(500), drivers: ["d".repeat(200)] })), }; const transportInput = { ...snapshot, summary: { signal_ledger: { pending_retained: 0, pending_total: 0, outcomes_retained: 0, outcomes_total: 0 } }, items: { pma_agents_v2: JSON.stringify(transportState), pma_suggestions_v5: JSON.stringify(transportSuggestions) } }; const transportOutput = compactRuntimeTransportSnapshot(transportInput); const transportedState = JSON.parse(transportOutput.items.pma_agents_v2); assert.equal(transportedState.signal_ledger.pending.length, 50); assert.equal(transportedState.signal_ledger.outcomes.length, 144); assert.equal(transportedState.agents.value.cash, 9000); assert.equal(transportedState.agents.value.positions[0].market_id, "position-0"); assert.equal(transportedState.agents.value.history.length, 24); assert.equal(transportedState.agents.value.snapshots.length, 96); assert.equal(transportedState.agents.value.snapshots[0].timestamp, transportState.agents.value.snapshots[0].timestamp); assert.equal(transportedState.agents.value.snapshots.at(-1).timestamp, transportState.agents.value.snapshots.at(-1).timestamp); assert.equal(transportedState.agents.value.maker_outcomes.length, 30); assert.equal(JSON.parse(transportOutput.items.pma_suggestions_v5).suggestions.length, 300); assert.equal(transportOutput.summary.signal_ledger.pending_retained, 50); assert.equal(transportOutput.summary.signal_ledger.outcomes_retained, 144); assert.ok(Buffer.byteLength(JSON.stringify(transportOutput)) < Buffer.byteLength(JSON.stringify(transportInput))); const stressState = structuredClone(transportState); stressState.signal_ledger = { pending: Array.from({ length: 600 }, (_, index) => ({ key: `stress-pending-${index}`, market_id: `pending-market-${index}`, observed_at: new Date(1_700_000_000_000 + index * 1_000).toISOString(), side: "YES", learning_payload: "p".repeat(1_200), })), outcomes: Array.from({ length: 1_000 }, (_, index) => ({ key: `stress-outcome-${index}`, market_id: `outcome-market-${index}`, evaluated_at: new Date(1_700_000_000_000 + index * 1_000).toISOString(), return: index / 10_000, learning_payload: "o".repeat(1_200), })), }; const stressInput = { ...transportInput, summary: { signal_ledger: { pending_retained: 600, pending_total: 600, outcomes_retained: 1_000, outcomes_total: 1_000 } }, items: { ...transportInput.items, pma_agents_v2: JSON.stringify(stressState) }, }; const stressOutput = compactRuntimeTransportSnapshot(stressInput); const stressedState = JSON.parse(stressOutput.items.pma_agents_v2); assert.ok(Buffer.byteLength(JSON.stringify(stressOutput)) <= 850_000); assert.equal(stressedState.agents.value.positions[0].market_id, "position-0"); assert.ok(stressedState.signal_ledger.pending.length > 0); assert.ok(stressedState.signal_ledger.outcomes.length > 0); assert.equal(stressedState.signal_ledger.pending[0].key, "stress-pending-0"); assert.equal(stressedState.signal_ledger.outcomes.at(-1).key, "stress-outcome-999"); assert.equal(stressOutput.summary.signal_ledger.pending_retained, stressedState.signal_ledger.pending.length); assert.equal(stressOutput.summary.signal_ledger.pending_total, 600); assert.equal(stressOutput.summary.signal_ledger.outcomes_retained, stressedState.signal_ledger.outcomes.length); assert.equal(stressOutput.summary.signal_ledger.outcomes_total, 1_000); console.log(`autonomous runtime verified for Build ${build}`);