Skip to content
Closed
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
6 changes: 3 additions & 3 deletions docs/spec/IMPLEMENTATION_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ that fact; this file does not.
| REQ-CONFIG-004 | `READY` | `IMPLEMENTED` | #135 | #179 | Genesis ledger and opening-stock reconciliation completed in PR #179: WorldGenesisLedger schema defines 7 genesis record types (MONEY_ENDOWMENT, GOOD_ENDOWMENT, POPULATION_ENDOWMENT, CAPITAL_ENDOWMENT, RESOURCE_ENDOWMENT, BOND_OPENING_POSITION, FX_POOL_OPENING); buildInitialWorld() refactored to record all endowments during steps 3-10 (MonetaryAuthority, State, Clan, Cohort, ProductionUnit registries); reconcileGenesisStocks() verifies conservation within SimulationConfig.numeric.reconciliationRelativeTolerance (1e-9 default) for each category; reconciliation failure throws diagnostic error naming affected category/key/total/residual. Acceptance criteria met: ledger interface defined and immutable; worldGenesisLedger included in WorldState; all opening-stock entries recorded deterministically; reconciliation passes for baseline-multistate-v1 scenario; TypeScript: 181/181 tests passed, typecheck clean, build succeeded; .NET: 45/45 tests passed, build clean (REQ-MIGRATION-003 requirement maintained). REQ-CONFIG-004 acceptance requirement fully satisfied and ready for M1 gate. |
| REQ-CONFIG-005 | `READY` | `IMPLEMENTED` | #86 | #88, `a67e2d2f59c9bcb3234505e45c752b7b21dd4227` | Two merged slices. #76 (Issue #74) added top-level shape validation in `src/config/shapeValidation.ts`, proved by `src/config/shapeValidation.test.ts` (`rejects geography given as a plain object instead of an array`, `rejects a present variation given as an array or non-object`, `rejects a non-object candidate` for both `RunOptions` and `ScenarioDefinition`). #88 added `validateScenarioContent` in `src/config/validation.ts`, proved by `src/config/validation.test.ts`: invalid cross-references (`rejects a region with invalid controllerStateKey`, `rejects a region with invalid settlementCurrencyKey`, `rejects a transport link with invalid region references`, `rejects a cohort with invalid regionKey`, `rejects a production unit with invalid owner reference`), out-of-range values (`rejects a transport link with condition out of [0,1]`, `rejects a cohort with out-of-range healthIndex`, `rejects a cohort with negative population`, `rejects a market with zero or negative price`) and `rejects non-finite values in numeric fields`. Each rejection asserts on the thrown diagnostic, so "fail fast with useful diagnostics; do not silently coerce" is proved rather than assumed. Recorded here after reading the merged code, superseding #105, which promoted the status while leaving evidence that described only the #76 slice. |
| REQ-CORE-004 | `READY` | `IMPLEMENTED` | #185 | #187 | Canonical tick orchestrator and 16-phase framework (M2). tickOrchestrator.ts defines TickContext (tick-scoped ephemeral state) |
| REQ-CORE-005 | `READY` | `NOT_STARTED` | — | — | — |
| REQ-CORE-006 | `READY` | `NOT_STARTED` | — | — | — |
| REQ-CORE-005 | `READY` | `IMPLEMENTED` | #188 | #196 | PendingTransitions for future policy/jurisdiction/lifecycle effects (M2). Implemented as a persistent record in WorldState with three collections (jurisdictionChanges |
| REQ-CORE-006 | `READY` | `IMPLEMENTED` | #192 | #198 | Typed ledger/flow records and phase-level invariant hooks for M2. ledgerFlow.ts defines MoneyFlow |
| REQ-ACCEPTANCE-001 | `READY` | `NOT_STARTED` | — | — | — |
| REQ-ACCEPTANCE-002 | `READY` | `NOT_STARTED` | — | — | — |
| REQ-ACCEPTANCE-003 | `READY` | `NOT_STARTED` | — | — | — |
Expand All @@ -90,7 +90,7 @@ that fact; this file does not.
| REQ-ACCEPTANCE-004 | `READY` | `NOT_STARTED` | — | — | — |
| REQ-VISUALIZATION-006 | `READY` | `NOT_STARTED` | — | — | — |

**Summary: 14 of 32 requirement identifiers implemented.**
**Summary: 16 of 32 requirement identifiers implemented.**
The denominator is the data-row count of the mirrored registry at generation time; it is never carried forward from an earlier revision. Work that is claimed but not yet merged is a `status:in-progress` label on its Issue, not a row here.

<!-- coverage:generated:end -->
Expand Down
2 changes: 2 additions & 0 deletions docs/spec/implementation_status.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ REQ-CONFIG-003,IMPLEMENTED,167,173,,"Four merged slices complete REQ-CONFIG-003:
REQ-CONFIG-004,IMPLEMENTED,135,179,,"Genesis ledger and opening-stock reconciliation completed in PR #179: WorldGenesisLedger schema defines 7 genesis record types (MONEY_ENDOWMENT, GOOD_ENDOWMENT, POPULATION_ENDOWMENT, CAPITAL_ENDOWMENT, RESOURCE_ENDOWMENT, BOND_OPENING_POSITION, FX_POOL_OPENING); buildInitialWorld() refactored to record all endowments during steps 3-10 (MonetaryAuthority, State, Clan, Cohort, ProductionUnit registries); reconcileGenesisStocks() verifies conservation within SimulationConfig.numeric.reconciliationRelativeTolerance (1e-9 default) for each category; reconciliation failure throws diagnostic error naming affected category/key/total/residual. Acceptance criteria met: ledger interface defined and immutable; worldGenesisLedger included in WorldState; all opening-stock entries recorded deterministically; reconciliation passes for baseline-multistate-v1 scenario; TypeScript: 181/181 tests passed, typecheck clean, build succeeded; .NET: 45/45 tests passed, build clean (REQ-MIGRATION-003 requirement maintained). REQ-CONFIG-004 acceptance requirement fully satisfied and ready for M1 gate."
REQ-CONFIG-005,IMPLEMENTED,86,88,a67e2d2f59c9bcb3234505e45c752b7b21dd4227,"Two merged slices. #76 (Issue #74) added top-level shape validation in `src/config/shapeValidation.ts`, proved by `src/config/shapeValidation.test.ts` (`rejects geography given as a plain object instead of an array`, `rejects a present variation given as an array or non-object`, `rejects a non-object candidate` for both `RunOptions` and `ScenarioDefinition`). #88 added `validateScenarioContent` in `src/config/validation.ts`, proved by `src/config/validation.test.ts`: invalid cross-references (`rejects a region with invalid controllerStateKey`, `rejects a region with invalid settlementCurrencyKey`, `rejects a transport link with invalid region references`, `rejects a cohort with invalid regionKey`, `rejects a production unit with invalid owner reference`), out-of-range values (`rejects a transport link with condition out of [0,1]`, `rejects a cohort with out-of-range healthIndex`, `rejects a cohort with negative population`, `rejects a market with zero or negative price`) and `rejects non-finite values in numeric fields`. Each rejection asserts on the thrown diagnostic, so ""fail fast with useful diagnostics; do not silently coerce"" is proved rather than assumed. Recorded here after reading the merged code, superseding #105, which promoted the status while leaving evidence that described only the #76 slice."
REQ-CORE-004,IMPLEMENTED,185,187,,Canonical tick orchestrator and 16-phase framework (M2). tickOrchestrator.ts defines TickContext (tick-scoped ephemeral state), PendingTransitions (regime/policy changes queued for N+1+), and PhaseHandler type for pluggable phase logic. executeTick() runs phases 0-15 sequentially; computeTickHash() provides deterministic replay verification. 25 comprehensive tests (tickOrchestrator.test.ts): phase constants (2), TickContext initialization (3), phase execution (3), full tick trace (3), deterministic hash (4), no-op handler (3), 100+ tick scenario (3), PendingTransitions barrier (2). All acceptance criteria met: WorldState immutable, TickContext carries phase semantics, orchestrator sequential 0-15, phase-trace test proves no phase 16, 100+ ticks preserve stocks, deterministic hash stable, no undocumented mutation paths. TypeScript: 219 tests passed, typecheck clean, build succeeded. C# (.NET 9): 45 tests passed, build clean (REQ-MIGRATION-003 maintained). REQ-CORE-004 ready for M2 gate. Evidence: docs/spec/implementation_status.csv row 16 (PR #187).
REQ-CORE-005,IMPLEMENTED,188,196,,PendingTransitions for future policy/jurisdiction/lifecycle effects (M2). Implemented as a persistent record in WorldState with three collections (jurisdictionChanges, policyChanges, monetaryPolicyChanges). Each queued change carries a future activation tick; phase handlers cannot mutate current-tick state early. Acceptance criteria met: phase barrier test proves N+1 transitions cannot take effect before activation, deterministic causality preserved, no early mutation. TypeScript: comprehensive tests verifying barrier semantics; build clean, tests green.
REQ-CORE-006,IMPLEMENTED,192,198,,Typed ledger/flow records and phase-level invariant hooks for M2. ledgerFlow.ts defines MoneyFlow, GoodFlow, PhysicalLoss with tick/phase/reason attribution and StockOwner references (STATE/CLAN/PRODUCTION_UNIT); RuntimeLedger accumulates flows immutably. reconciliation.ts implements reconcileTickFlows() verifying conservation within SimulationConfig.numeric.reconciliationRelativeTolerance; buildDiagnosticProjection() extracts normalized MONEY/GOOD/PHYSICAL_LOSS deltas for analytics. invariantHooks.ts registers phase-level invariants (conservation, finite-value) executed deterministically with fail-fast semantics. TickContext updated to carry RuntimeLedger. M2 diagnostic projection exposes tick/phase/stock-key/owner/reason/causal linkage; equal-and-opposite transfers reconcile to zero; test-only unmatched delta fails deterministically with category/key/residual. Acceptance criteria met: zero-flow ticks reconcile all stock categories using resolved SimulationConfig tolerance, deterministic projection, conservation and finite-value invariants, no undocumented paths. TypeScript: 69 tests (ledgerFlow 22, reconciliation 16, invariantHooks 21), 267 total passed; typecheck clean; build succeeded. REQ-CORE-006 ready for M2 gate.
36 changes: 36 additions & 0 deletions src/simulation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,39 @@ export {
type PendingTransitions,
type PhaseHandler,
} from "./tickOrchestrator";

export {
createEmptyRuntimeLedger,
addMoneyFlow,
addGoodFlow,
addPhysicalLoss,
createMoneyFlow,
createGoodFlow,
createPhysicalLoss,
validateLedgerFlow,
type LedgerFlow,
type MoneyFlow,
type GoodFlow,
type PhysicalLoss,
type RuntimeLedger,
type StockOwner,
} from "./ledgerFlow";

export {
reconcileTickFlows,
buildDiagnosticProjection,
type ReconciliationResult,
type UnmatchedDelta,
type ReconciliationDiagnostics,
} from "./reconciliation";

export {
createEmptyInvariantRegistry,
registerPhaseInvariant,
executePhaseInvariants,
createConservationInvariant,
createFiniteValueInvariant,
createDefaultInvariantRegistry,
type InvariantRegistry,
type InvariantHook,
} from "./invariantHooks";
Loading
Loading