lazycodex-ai 5.1.45 → 5.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.de.md +0 -5
- package/README.es.md +0 -5
- package/README.fr.md +0 -5
- package/README.it.md +0 -5
- package/README.ja.md +0 -5
- package/README.ko.md +0 -5
- package/README.md +4 -5
- package/README.pt-br.md +0 -5
- package/README.ru.md +0 -6
- package/README.zh-cn.md +0 -5
- package/dist/cli/index.js +76 -156
- package/dist/cli-node/index.js +76 -156
- package/package.json +1 -1
- package/packages/lsp-daemon/dist/cli.js +3 -3
- package/packages/lsp-daemon/dist/client.js +3 -3
- package/packages/lsp-daemon/dist/index.js +3 -3
- package/packages/lsp-tools-mcp/dist/cli.js +3 -3
- package/packages/lsp-tools-mcp/dist/mcp.js +3 -3
- package/packages/omo-codex/plugin/.codex-plugin/plugin.json +1 -1
- package/packages/omo-codex/plugin/components/bootstrap/dist/cli.js +22 -12
- package/packages/omo-codex/plugin/components/bootstrap/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/bootstrap/package.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/package.json +1 -1
- package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/git-bash/package.json +1 -1
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/package.json +1 -1
- package/packages/omo-codex/plugin/components/lsp/dist/.omo-runtime-manifest.json +2 -2
- package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/lsp/package.json +1 -1
- package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
- package/packages/omo-codex/plugin/components/rules/package.json +1 -1
- package/packages/omo-codex/plugin/components/teammode/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/teammode/package.json +1 -1
- package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/telemetry/package.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/package.json +1 -1
- package/packages/omo-codex/plugin/components/ulw-execute-continuation/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/ulw-execute-continuation/package.json +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +5 -5
- package/packages/omo-codex/plugin/components/ulw-loop/package.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-git-bash-mcp-reminder.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-lsp-diagnostics-cache.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-project-rule-cache.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-comments.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-lsp-diagnostics.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-thread-title-hygiene.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-matching-project-rules.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-recording-spawn-admission.json +1 -1
- package/packages/omo-codex/plugin/hooks/pre-tool-use-enforcing-unlimited-goal-budget.json +1 -1
- package/packages/omo-codex/plugin/hooks/pre-tool-use-guarding-ulw-loop-spawns.json +1 -1
- package/packages/omo-codex/plugin/hooks/pre-tool-use-recommending-git-bash-mcp.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-checking-auto-update.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-checking-bootstrap-provisioning.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-loading-project-rules.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-recording-session-telemetry.json +1 -1
- package/packages/omo-codex/plugin/hooks/stop-checking-ulw-execute-continuation.json +1 -1
- package/packages/omo-codex/plugin/hooks/stop-checking-ulw-loop-resume.json +1 -1
- package/packages/omo-codex/plugin/hooks/subagent-stop-verifying-lazycodex-executor-evidence.json +1 -1
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ultrawork-trigger.json +1 -1
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ulw-loop-steering.json +1 -1
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-loading-project-rules.json +1 -1
- package/packages/omo-codex/plugin/package-lock.json +12 -12
- package/packages/omo-codex/plugin/package.json +1 -1
- package/packages/omo-codex/plugin/scripts/sync-skills.mjs +8 -3
- package/packages/omo-codex/plugin/shared/test/config-loader.test.ts +0 -2
- package/packages/omo-codex/plugin/skills/ast-grep/AGENTS.md +1 -1
- package/packages/omo-codex/plugin/skills/browser/runtime/omowright/manifest.json +1 -1
- package/packages/omo-codex/plugin/skills/frontend/ATTRIBUTION.md +2 -2
- package/packages/omo-codex/plugin/skills/ultimate-browsing/engine/AGENTS.md +1 -1
- package/packages/omo-codex/plugin/skills/ulw-research/AGENTS.md +14 -2
- package/packages/omo-codex/plugin/skills/ulw-research/SKILL.md +36 -11
- package/packages/omo-codex/plugin/skills/ulw-research/references/deliverable-phase.md +73 -13
- package/packages/omo-codex/plugin/skills/ulw-research/references/fact-ledger-grammar.md +19 -1
- package/packages/omo-codex/plugin/skills/ulw-research/references/fact-ledger.md +95 -0
- package/packages/omo-codex/plugin/skills/ulw-research/references/fidelity-claim-kinds.md +19 -0
- package/packages/omo-codex/plugin/skills/ulw-research/references/report-gates.md +21 -4
- package/packages/omo-codex/plugin/skills/ulw-research/references/report-visualization.md +2 -0
- package/packages/omo-codex/plugin/skills/ulw-research/references/unit-rules.md +157 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/claim-kinds.mjs +116 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/cli-support.mjs +19 -5
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/contracts.mjs +27 -6
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-commands-meaning.mjs +191 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-commands-verify.mjs +164 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-commands.mjs +239 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-derive.mjs +66 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-expr.mjs +108 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-fill.mjs +194 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-ledger-kinds.mjs +127 -13
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-ledger-schema.mjs +33 -16
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-ledger.mjs +29 -9
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-locate.mjs +231 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-pairs.mjs +187 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fact-recompute.mjs +89 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-binding.mjs +130 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-brief.mjs +5 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-claims.mjs +89 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-lexicon.mjs +145 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-records.mjs +163 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-state.mjs +2 -1
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-trace.mjs +85 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/fidelity-values.mjs +229 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/gates-fidelity.mjs +113 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/gates-static.mjs +28 -8
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/html-lite.mjs +2 -2
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/html-markup.mjs +182 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/md-lite.mjs +193 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/meaning-check.mjs +196 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/outcome.mjs +6 -5
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/placeholder.mjs +184 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/polish-apply.mjs +115 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/polish-diff.mjs +31 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/polish-project.mjs +125 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/polish-rules.mjs +170 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/report-tools-commands.mjs +19 -8
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/report-tools.mjs +15 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/source-commands.mjs +140 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/source-snapshot.mjs +176 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-algebra.mjs +101 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-errors.mjs +23 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-metadata.mjs +31 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-pairs.mjs +72 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-precision.mjs +44 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-rules-shapes.mjs +64 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/unit-rules.mjs +173 -0
- package/packages/omo-codex/plugin/skills/ulw-research/scripts/units.mjs +4 -4
- package/packages/omo-codex/plugin/test/sync-skills-codex-compatibility.test.mjs +19 -0
- package/packages/omo-codex/plugin/test/sync-skills-test-support.mjs +7 -3
- package/packages/omo-codex/scripts/install-dist/install-local.mjs +26 -16
- package/packages/shared-skills/skills/ast-grep/AGENTS.md +1 -1
- package/packages/shared-skills/skills/browser/runtime/omowright/manifest.json +1 -1
- package/packages/shared-skills/skills/frontend/ATTRIBUTION.md +2 -2
- package/packages/shared-skills/skills/ultimate-browsing/engine/AGENTS.md +1 -1
- package/packages/shared-skills/skills/ulw-research/AGENTS.md +14 -2
- package/packages/shared-skills/skills/ulw-research/SKILL.md +37 -12
- package/packages/shared-skills/skills/ulw-research/references/deliverable-phase.md +73 -13
- package/packages/shared-skills/skills/ulw-research/references/fact-ledger-grammar.md +19 -1
- package/packages/shared-skills/skills/ulw-research/references/fact-ledger.md +95 -0
- package/packages/shared-skills/skills/ulw-research/references/fidelity-claim-kinds.md +19 -0
- package/packages/shared-skills/skills/ulw-research/references/report-gates.md +21 -4
- package/packages/shared-skills/skills/ulw-research/references/report-visualization.md +2 -0
- package/packages/shared-skills/skills/ulw-research/references/unit-rules.md +157 -0
- package/packages/shared-skills/skills/ulw-research/scripts/claim-kinds.mjs +116 -0
- package/packages/shared-skills/skills/ulw-research/scripts/claim-kinds.test.ts +193 -0
- package/packages/shared-skills/skills/ulw-research/scripts/cli-support.mjs +19 -5
- package/packages/shared-skills/skills/ulw-research/scripts/cli-support.test.ts +13 -2
- package/packages/shared-skills/skills/ulw-research/scripts/contracts.mjs +27 -6
- package/packages/shared-skills/skills/ulw-research/scripts/contracts.test.ts +3 -0
- package/packages/shared-skills/skills/ulw-research/scripts/copy-returns.test.ts +183 -0
- package/packages/shared-skills/skills/ulw-research/scripts/delivery-barrier.test.ts +245 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-commands-meaning.mjs +191 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-commands-verify.mjs +164 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-commands.mjs +239 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-derive.mjs +66 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-derive.test.ts +375 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-expr.mjs +108 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-fill.mjs +194 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-fill.test.ts +221 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger-grammar.test.ts +9 -2
- package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger-kinds.mjs +127 -13
- package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger-kinds.test.ts +18 -3
- package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger-legacy.test.ts +160 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger-schema.mjs +33 -16
- package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger.mjs +29 -9
- package/packages/shared-skills/skills/ulw-research/scripts/fact-ledger.test.ts +2 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-locate.mjs +231 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-locate.test.ts +118 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-pairs.mjs +187 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-pairs.test.ts +167 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-recompute.mjs +89 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-unit-dimensions.test.ts +409 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fact-unit-rules.test.ts +388 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-binding.mjs +130 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-binding.test.ts +81 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-brief.mjs +5 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-claims.mjs +89 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-lexicon.mjs +145 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-lexicon.test.ts +117 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-records.mjs +163 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-state.mjs +2 -1
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-trace.mjs +85 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-trace.test.ts +58 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-values.mjs +229 -0
- package/packages/shared-skills/skills/ulw-research/scripts/fidelity-values.test.ts +270 -0
- package/packages/shared-skills/skills/ulw-research/scripts/gates-fidelity.mjs +113 -0
- package/packages/shared-skills/skills/ulw-research/scripts/gates-fidelity.test.ts +73 -0
- package/packages/shared-skills/skills/ulw-research/scripts/gates-static.mjs +28 -8
- package/packages/shared-skills/skills/ulw-research/scripts/html-lite.mjs +2 -2
- package/packages/shared-skills/skills/ulw-research/scripts/html-markup.mjs +182 -0
- package/packages/shared-skills/skills/ulw-research/scripts/md-lite.mjs +193 -0
- package/packages/shared-skills/skills/ulw-research/scripts/md-lite.test.ts +271 -0
- package/packages/shared-skills/skills/ulw-research/scripts/meaning-check.mjs +196 -0
- package/packages/shared-skills/skills/ulw-research/scripts/meaning-check.test.ts +228 -0
- package/packages/shared-skills/skills/ulw-research/scripts/outcome.mjs +6 -5
- package/packages/shared-skills/skills/ulw-research/scripts/placeholder.mjs +184 -0
- package/packages/shared-skills/skills/ulw-research/scripts/placeholder.test.ts +77 -0
- package/packages/shared-skills/skills/ulw-research/scripts/polish-apply.mjs +115 -0
- package/packages/shared-skills/skills/ulw-research/scripts/polish-apply.test.ts +363 -0
- package/packages/shared-skills/skills/ulw-research/scripts/polish-diff.mjs +31 -0
- package/packages/shared-skills/skills/ulw-research/scripts/polish-diff.test.ts +168 -0
- package/packages/shared-skills/skills/ulw-research/scripts/polish-markup.test.ts +187 -0
- package/packages/shared-skills/skills/ulw-research/scripts/polish-project.mjs +125 -0
- package/packages/shared-skills/skills/ulw-research/scripts/polish-rules.mjs +170 -0
- package/packages/shared-skills/skills/ulw-research/scripts/report-tools-commands.mjs +19 -8
- package/packages/shared-skills/skills/ulw-research/scripts/report-tools.mjs +15 -0
- package/packages/shared-skills/skills/ulw-research/scripts/report-tools.test.ts +458 -2
- package/packages/shared-skills/skills/ulw-research/scripts/source-commands.mjs +140 -0
- package/packages/shared-skills/skills/ulw-research/scripts/source-snapshot.mjs +176 -0
- package/packages/shared-skills/skills/ulw-research/scripts/source-snapshot.test.ts +113 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/assets/share.csv +3 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/gen-legacy-dev.mjs +89 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/ledger-basic.json +223 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/ledger-legacy-dev.json +859 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/ledger-verify.json +420 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/report-bad.html +19 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/report-good.html +39 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/acronyms.json +3 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/meta.json +9 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/sentences.jsonl +7 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4/text.txt +7 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S4.html +19 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/acronyms.json +1 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/meta.json +9 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/sentences.jsonl +1 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S5/text.txt +1 -0
- package/packages/shared-skills/skills/ulw-research/scripts/tests/fixtures/fidelity/sources/S9.txt +1 -0
- package/packages/shared-skills/skills/ulw-research/scripts/unit-algebra.mjs +101 -0
- package/packages/shared-skills/skills/ulw-research/scripts/unit-errors.mjs +23 -0
- package/packages/shared-skills/skills/ulw-research/scripts/unit-metadata.mjs +31 -0
- package/packages/shared-skills/skills/ulw-research/scripts/unit-pairs.mjs +72 -0
- package/packages/shared-skills/skills/ulw-research/scripts/unit-precision.mjs +44 -0
- package/packages/shared-skills/skills/ulw-research/scripts/unit-rules-shapes.mjs +64 -0
- package/packages/shared-skills/skills/ulw-research/scripts/unit-rules.mjs +173 -0
- package/packages/shared-skills/skills/ulw-research/scripts/units.mjs +4 -4
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
|
|
3
|
+
import { derive, recompute } from "./fact-derive.mjs"
|
|
4
|
+
import { addRow, emptyLedger, retractRow, validateLedger } from "./fact-ledger.mjs"
|
|
5
|
+
import { canonicalUnit } from "./unit-rules.mjs"
|
|
6
|
+
import { convertFactor } from "./units.mjs"
|
|
7
|
+
|
|
8
|
+
type Row = Record<string, unknown>
|
|
9
|
+
type Book = { schemaVersion: number; rows: Row[]; events: unknown[] }
|
|
10
|
+
const now = "2026-10-23T08:00:00Z"
|
|
11
|
+
function book(values: string[] = ["1", "3"], units: Array<string | null> = ["m", "m"], extras: Row[] = []): Book {
|
|
12
|
+
const ledger = emptyLedger() as Book
|
|
13
|
+
values.forEach((value, i) => addRow(ledger, {
|
|
14
|
+
kind: "measured", value, unit: units[i], raw: value, quote: value, source_id: "S1",
|
|
15
|
+
locator: { artifact: "sources/S1/text.txt", char_start: 0, char_end: 1 },
|
|
16
|
+
snapshot_sha256: "a".repeat(64), extracted_by: "test", observed_at: now, label: `f${i + 1}`,
|
|
17
|
+
...extras[i],
|
|
18
|
+
}))
|
|
19
|
+
return ledger
|
|
20
|
+
}
|
|
21
|
+
function row(ledger: Book, spec: Row): Row {
|
|
22
|
+
const result = derive(ledger, { ...spec, now })
|
|
23
|
+
if (!("row" in result)) throw Error(JSON.stringify(result))
|
|
24
|
+
return result.row as Row
|
|
25
|
+
}
|
|
26
|
+
const sum = { op: "sum", operands: ["F1", "F2"], unit: "m" }
|
|
27
|
+
function refused(ledger: Book, spec: unknown) {
|
|
28
|
+
const before = structuredClone(ledger)
|
|
29
|
+
const result = derive(ledger, spec)
|
|
30
|
+
expect(result).toMatchObject({ error: "incompatible_operands" })
|
|
31
|
+
expect(ledger).toEqual(before)
|
|
32
|
+
return result
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
test("dimension 01: kind operation consistency cannot disable recursive trust", () => {
|
|
36
|
+
for (const patch of [{ operation: null }, { kind: "measured" }, { operation: "convert" }]) {
|
|
37
|
+
const l = book()
|
|
38
|
+
const inner = row(l, sum)
|
|
39
|
+
const outer = row(l, { op: "convert", operands: [inner.fact_id], to: "cm" })
|
|
40
|
+
Object.assign(inner, patch, { value: "999", exact: { num: "999", den: "1" } })
|
|
41
|
+
expect(validateLedger(l).length).toBeGreaterThan(0)
|
|
42
|
+
expect(recompute(l, outer).ok).toBe(false)
|
|
43
|
+
refused(l, { op: "convert", operands: [inner.fact_id], to: "cm" })
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test("dimension 02: direct and expression metadata propagate with identical compatibility", () => {
|
|
48
|
+
for (const field of ["population", "accounting_basis", "snapshot_window"]) {
|
|
49
|
+
const incompatible = book(["1", "3"], ["m", "m"], [{ [field]: "adults" }, { [field]: "children" }])
|
|
50
|
+
refused(incompatible, sum)
|
|
51
|
+
refused(incompatible, { op: "expr", formula: "F1 + F2", unit: "m" })
|
|
52
|
+
}
|
|
53
|
+
const meta = { population: "all", accounting_basis: "cash", snapshot_window: "2026", entity: "acme", valid_at: "2026" }
|
|
54
|
+
const l = book(["1", "3"], ["m", "m"], [meta, meta])
|
|
55
|
+
for (const spec of [sum, { op: "expr", formula: "F1 + F2", unit: "m" }]) {
|
|
56
|
+
const inner = row(l, spec)
|
|
57
|
+
expect(inner).toMatchObject(meta)
|
|
58
|
+
expect(row(l, { op: "convert", operands: [inner.fact_id], to: "cm" })).toMatchObject(meta)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test("dimension 03: precision survives stored intermediates and conversion round trips", () => {
|
|
63
|
+
const l = book(["1.20", "2.30", "0.04"], ["m", "m", "m"])
|
|
64
|
+
const inner = row(l, sum)
|
|
65
|
+
expect(inner.value).toBe("3.5")
|
|
66
|
+
expect(row(l, { ...sum, operands: [inner.fact_id, "F3"] }).value).toBe("3.54")
|
|
67
|
+
const cm = row(l, { op: "convert", operands: [inner.fact_id], to: "cm" })
|
|
68
|
+
const m = row(l, { op: "convert", operands: [cm.fact_id], to: "m" })
|
|
69
|
+
expect(row(l, { ...sum, operands: [m.fact_id, "F3"] }).value).toBe("3.54")
|
|
70
|
+
expect(recompute(l, m).ok).toBe(true)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test("dimension 04: scaled aliases preserve composite factor scale", () => {
|
|
74
|
+
for (const [unit, value, formula, expectedUnit, expected] of [
|
|
75
|
+
["bp/person", "100", "F1 * F2", "%p", "1"],
|
|
76
|
+
["person/bp", "1", "F1 / F2", "1/%p", "100"],
|
|
77
|
+
["bp^2/person", "10000", "F1 * F2", "%p^2", "1"],
|
|
78
|
+
] as const) {
|
|
79
|
+
const l = book([value, "1"], [unit, "person"])
|
|
80
|
+
expect(row(l, { op: "expr", formula, unit: expectedUnit }).exact).toEqual({ num: expected, den: "1" })
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test("dimension 05: public refusal API is total classified and append atomic", () => {
|
|
85
|
+
for (const bad of [null, undefined, 1, [], {}, { op: "wat" }, { ...sum, operands: null }]) {
|
|
86
|
+
const result = refused(book(), bad)
|
|
87
|
+
expect(result).toMatchObject({ shape: expect.any(String), expected: expect.anything() })
|
|
88
|
+
}
|
|
89
|
+
for (const bad of [null, [], {}, { num: "NaN", den: "1" }, { num: "1", den: "0" }]) {
|
|
90
|
+
const l = book()
|
|
91
|
+
l.rows[0].exact = bad
|
|
92
|
+
refused(l, sum)
|
|
93
|
+
const result = recompute(l, l.rows[0])
|
|
94
|
+
expect(result).toMatchObject({ ok: false, shape: expect.any(String) })
|
|
95
|
+
expect(result.expected).toBeDefined()
|
|
96
|
+
}
|
|
97
|
+
for (const bad of [null, undefined, 1, [], {}]) {
|
|
98
|
+
expect(() => recompute(bad, bad)).not.toThrow()
|
|
99
|
+
expect(recompute(bad, bad)).toMatchObject({ ok: false, shape: expect.any(String) })
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test("dimension 06: aliases normalize at input; derived rows store canonical units, source aliases read canonical (dimension 31)", () => {
|
|
104
|
+
const l = book(["1", "3"], ["metre", "m"])
|
|
105
|
+
expect(l.rows[0].unit).toBe("m")
|
|
106
|
+
const result = row(l, sum)
|
|
107
|
+
l.rows[0].unit = "metre"
|
|
108
|
+
expect(validateLedger(l)).toEqual([])
|
|
109
|
+
expect(recompute(l, result).ok).toBe(true)
|
|
110
|
+
const relabeled = { ...result, unit: "metre" }
|
|
111
|
+
l.rows[l.rows.indexOf(result)] = relabeled
|
|
112
|
+
expect(validateLedger(l).length).toBeGreaterThan(0)
|
|
113
|
+
expect(recompute(l, relabeled).ok).toBe(false)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test("dimension 07: exact rationals are reduced canonical integer strings; dev's integer pairs read reduced (dimension 31)", () => {
|
|
117
|
+
for (const [exact, reduced] of [[{ num: "2", den: "2" }, "1"], [{ num: "01", den: "1" }, "1"], [{ num: "-0", den: "1" }, "0"], [{ num: "-6", den: "06" }, "-1"]] as const) {
|
|
118
|
+
const l = book(["1", "3"])
|
|
119
|
+
Object.assign(l.rows[0], { kind: "assumed", rationale: "given", value: reduced, source_id: null, locator: null, snapshot_sha256: null, exact })
|
|
120
|
+
expect(validateLedger(l)).toEqual([])
|
|
121
|
+
expect(row(l, { op: "expr", formula: "F1", unit: "m" }).exact).toEqual({ num: reduced, den: "1" })
|
|
122
|
+
}
|
|
123
|
+
for (const exact of [{ num: 1, den: "1" }, { num: "1", den: "-1" }, { num: "1", den: "0" }, { num: "1.5", den: "1" }]) {
|
|
124
|
+
const l = book()
|
|
125
|
+
Object.assign(l.rows[0], { kind: "assumed", rationale: "given", exact })
|
|
126
|
+
expect(validateLedger(l).length).toBeGreaterThan(0)
|
|
127
|
+
refused(l, { op: "expr", formula: "F1", unit: "m" })
|
|
128
|
+
}
|
|
129
|
+
const l = book()
|
|
130
|
+
const made = row(l, sum)
|
|
131
|
+
made.exact = { num: "8", den: "2" }
|
|
132
|
+
expect(validateLedger(l).length).toBeGreaterThan(0)
|
|
133
|
+
expect(recompute(l, made).ok).toBe(false)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test("dimension 08: context schemas reject foreign keys and wrong types", () => {
|
|
137
|
+
const l = book()
|
|
138
|
+
const result = row(l, sum)
|
|
139
|
+
for (const context of [{ disjoint: "true", reference: 7 }, { disjoint: false, reference: null, target: "km" }, { disjoint: false, reference: null, extra: true }]) {
|
|
140
|
+
expect(recompute(l, { ...result, context }).ok).toBe(false)
|
|
141
|
+
}
|
|
142
|
+
refused(l, { ...sum, disjoint: "true" })
|
|
143
|
+
refused(l, { ...sum, target: "km" })
|
|
144
|
+
refused(l, { ...sum, op: "diff", disjoint: true })
|
|
145
|
+
refused(l, { op: "diff", operands: ["F1", "F2"], unit: "m", context: { target: "km" } })
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test("dimension 09: redundant audit fields are rederived and compared", () => {
|
|
149
|
+
const l = book()
|
|
150
|
+
for (const spec of [sum, { op: "convert", operands: ["F1"], to: "cm" }]) {
|
|
151
|
+
const result = row(l, spec)
|
|
152
|
+
for (const patch of [{ factor: "999" }, { formula: "999" }, { derived_from: ["F2"] }, { raw: "999" }]) {
|
|
153
|
+
expect(recompute(l, { ...result, ...patch }).ok).toBe(false)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test("dimension 10: metadata equality ignores object insertion order but not invalid presence", () => {
|
|
159
|
+
const l = book(["1", "3"], ["m", "m"], [{ population: { age: 20, place: "x" } }, { population: { place: "x", age: 20 } }])
|
|
160
|
+
expect(row(l, sum).value).toBe("4")
|
|
161
|
+
for (const value of [undefined, 3, "", []]) {
|
|
162
|
+
const bad = book()
|
|
163
|
+
bad.rows[0].population = value
|
|
164
|
+
refused(bad, sum)
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
test("dimension 11: inactive descendants remain historically verifiable but ineligible", () => {
|
|
169
|
+
const l = book()
|
|
170
|
+
const inner = row(l, sum)
|
|
171
|
+
const outer = row(l, { op: "convert", operands: [inner.fact_id], to: "cm" })
|
|
172
|
+
retractRow(l, "F1", "wrong source")
|
|
173
|
+
expect(recompute(l, outer).ok).toBe(true)
|
|
174
|
+
refused(l, { op: "convert", operands: [outer.fact_id], to: "m" })
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test("dimension 12: shared DAG nodes are verified once and deep expressions are stack independent", () => {
|
|
178
|
+
const l = book()
|
|
179
|
+
const first = row(l, sum)
|
|
180
|
+
let a = first
|
|
181
|
+
let b = row(l, { ...sum, operands: [first.fact_id, "F1"] })
|
|
182
|
+
for (let i = 0; i < 10; i++) [a, b] = [b, row(l, { ...sum, operands: [a.fact_id, b.fact_id] })]
|
|
183
|
+
let visits = 0
|
|
184
|
+
const exact = first.exact
|
|
185
|
+
Object.defineProperty(first, "exact", { get: () => { visits++; return exact }, configurable: true })
|
|
186
|
+
expect(recompute(l, b).ok).toBe(true)
|
|
187
|
+
expect(visits).toBe(1)
|
|
188
|
+
const deep = `${"(".repeat(12000)}F1${")".repeat(12000)}`
|
|
189
|
+
expect(row(book(), { op: "expr", formula: deep, unit: "m" }).value).toBe("1")
|
|
190
|
+
const chain = book()
|
|
191
|
+
const template = row(chain, { op: "expr", formula: "F1", unit: "m" })
|
|
192
|
+
let previous = String(template.fact_id)
|
|
193
|
+
for (let i = 4; i < 12004; i++) {
|
|
194
|
+
const fact_id = `F${i}`
|
|
195
|
+
chain.rows.push({ ...template, fact_id, label: `chain-${i}`, operands: [previous], derived_from: [previous], formula: previous })
|
|
196
|
+
previous = fact_id
|
|
197
|
+
}
|
|
198
|
+
expect(validateLedger(chain)).toEqual([])
|
|
199
|
+
expect(recompute(chain, chain.rows.at(-1)).ok).toBe(true)
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
test("dimension 13: composite exponents are exact bigint and normalization idempotent", () => {
|
|
203
|
+
for (const [input, expected] of [["m^9007199254740993", "m^9007199254740993"], ["m^9007199254740993/m^9007199254740992", "m"], ["m^0", null], ["m^-2", "1/m^2"], ["m/(s/kg)", "kg*m/s"]] as const) {
|
|
204
|
+
expect(canonicalUnit(input)).toBe(expected)
|
|
205
|
+
expect(canonicalUnit(expected)).toBe(expected)
|
|
206
|
+
}
|
|
207
|
+
for (const input of ["m^1e3", "m^1.5", "m^"]) expect(() => canonicalUnit(input)).toThrow()
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
test("dimension 14: affine and scale atoms cannot hide in composites or cancellation", () => {
|
|
211
|
+
for (const unit of ["C/s", "F*m", "C/C", "(C/s)^2"]) {
|
|
212
|
+
let l: Book
|
|
213
|
+
try { l = book(["1", "3"], [unit, unit]) } catch { continue }
|
|
214
|
+
expect(derive(l, { op: "ratio", num: "F1", den: "F2", unit: null }).error).toBeDefined()
|
|
215
|
+
}
|
|
216
|
+
for (const unit of ["million", "m/M", "bn/bn"]) expect(() => canonicalUnit(unit)).toThrow()
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
test("dimension 15: disjoint shares individually and jointly stay within one whole", () => {
|
|
220
|
+
const spec = { op: "sum", operands: ["F1", "F2"], unit: "%", disjoint: true, reference: "all", rationale: "disjoint" }
|
|
221
|
+
for (const values of [["60", "60"], ["-1", "50"], ["101", "0"]]) refused(book(values, ["%", "%"]), spec)
|
|
222
|
+
expect(row(book(["40", "60"], ["%", "%"]), spec).value).toBe("100")
|
|
223
|
+
refused(book(["20", "30"], ["%", "%"]), { ...spec, reference: { F1: "all", F2: "all", F99: "all" } })
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
test("dimension 16: FX arithmetic persists unchecked compatibility and requires a dated rate", () => {
|
|
227
|
+
const spec = { op: "expr", formula: "F1 * F2", unit: "USD" }
|
|
228
|
+
refused(book(["100", "1.10"], ["EUR", "USD/EUR"]), spec)
|
|
229
|
+
const l = book(["100", "1.10"], ["EUR", "USD/EUR"], [{ valid_at: "2026-10-23" }, { valid_at: "2026-10-23" }])
|
|
230
|
+
const result = row(l, spec)
|
|
231
|
+
expect(result.compatibility).toBe("unchecked")
|
|
232
|
+
expect(result.exact).toEqual({ num: "110", den: "1" })
|
|
233
|
+
expect(recompute(l, result).ok).toBe(true)
|
|
234
|
+
expect(recompute(l, { ...result, compatibility: "checked" }).ok).toBe(false)
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
test("dimension 17: symbols are case sensitive and opaque text stays opaque", () => {
|
|
238
|
+
expect(canonicalUnit("Mb")).toBe("Mb")
|
|
239
|
+
expect(canonicalUnit("MB")).toBe("MB")
|
|
240
|
+
expect(canonicalUnit("m b")).toBe("m b")
|
|
241
|
+
expect(canonicalUnit(" metric ton ")).toBe("metric ton")
|
|
242
|
+
expect(canonicalUnit("m / s")).toBe("m/s")
|
|
243
|
+
expect(canonicalUnit("\u03bcm")).not.toBe(canonicalUnit("\u00b5m"))
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test("dimension 18: undefined and missing required fields never stand in for null", () => {
|
|
247
|
+
const l = book()
|
|
248
|
+
for (const unit of [undefined, ""]) refused(l, { op: "ratio", num: "F1", den: "F2", unit })
|
|
249
|
+
refused(l, { op: "ratio", num: "F1", den: "F2" })
|
|
250
|
+
expect(row(l, { op: "ratio", num: "F1", den: "F2", unit: null }).unit).toBeNull()
|
|
251
|
+
for (const patch of [{ unit: undefined }, { value: undefined }, { population: undefined }]) {
|
|
252
|
+
const bad = book()
|
|
253
|
+
Object.assign(bad.rows[0], patch)
|
|
254
|
+
refused(bad, sum)
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
test("dimension 19: allocation above safe integer remains exact and unique", () => {
|
|
259
|
+
const l = book()
|
|
260
|
+
l.rows[1].fact_id = "F9007199254740992"
|
|
261
|
+
const result = row(l, { ...sum, operands: ["F1", "F9007199254740992"] })
|
|
262
|
+
expect(result.fact_id).toBe("F9007199254740993")
|
|
263
|
+
expect(recompute(l, result).ok).toBe(true)
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
test("dimension 20: supplied expression operand set must match formula leaves", () => {
|
|
267
|
+
for (const operands of [["F2"], ["F1", "F2"], ["F1", "F1"], [], null]) refused(book(), { op: "expr", formula: "F1", unit: "m", operands })
|
|
268
|
+
expect(row(book(), { op: "expr", formula: "F1 + F2", operands: ["F2", "F1"], unit: "m" }).value).toBe("4")
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
test("dimension 21: expression root and literal precision remain explicit", () => {
|
|
272
|
+
const l = book(["1000", "3"], ["m", "m"])
|
|
273
|
+
expect(row(l, { op: "expr", formula: "F1 - F2", unit: "m" }).value).toBe("997")
|
|
274
|
+
expect(row(l, { op: "expr", formula: "(F1 - F2) * 1", unit: "m" }).value).toBe("1000")
|
|
275
|
+
expect(row(l, { op: "expr", formula: "(F1 - F2) * 1.00", unit: "m" }).value).toBe("1000")
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
test("dimension 22: cloned snapshots are deterministic and replay appends a new identity", () => {
|
|
279
|
+
const original = book()
|
|
280
|
+
const left = structuredClone(original)
|
|
281
|
+
const right = structuredClone(original)
|
|
282
|
+
expect(row(left, sum)).toEqual(row(right, sum))
|
|
283
|
+
expect(row(left, sum).fact_id).toBe("F4")
|
|
284
|
+
expect(original.rows).toHaveLength(2)
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
test("dimension 23: coherent trusted input rewrites are a documented arithmetic limitation", () => {
|
|
288
|
+
const l = book(["0", "3"])
|
|
289
|
+
const km = row(l, { op: "convert", operands: ["F1"], to: "km" })
|
|
290
|
+
const cm = row(l, { op: "convert", operands: ["F1"], to: "cm" })
|
|
291
|
+
const coherent = { ...cm, fact_id: km.fact_id, label: km.label }
|
|
292
|
+
expect(recompute(l, coherent).ok).toBe(true)
|
|
293
|
+
expect(recompute(l, { ...km, unit: "cm" }).ok).toBe(false)
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
test("dimension 24: sum permutation and ordered arithmetic keep their own semantics", () => {
|
|
297
|
+
const l = book(["2", "5"])
|
|
298
|
+
for (const operands of [["F1", "F2"], ["F2", "F1"]]) expect(row(l, { ...sum, operands }).exact).toEqual({ num: "7", den: "1" })
|
|
299
|
+
expect(row(l, { ...sum, op: "diff" }).exact).toEqual({ num: "-3", den: "1" })
|
|
300
|
+
expect(row(l, { ...sum, op: "diff", operands: ["F2", "F1"] }).exact).toEqual({ num: "3", den: "1" })
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
test("dimension 25: numeric domain boundaries do not forbid negative ordinary arithmetic", () => {
|
|
304
|
+
for (const values of [["6", "5"], ["-1", "5"], ["0", "0"]]) expect(derive(book(values), { op: "share", part: "F1", whole: "F2", unit: "%" }).error).toBeDefined()
|
|
305
|
+
expect(row(book(["-2", "-5"]), sum).exact).toEqual({ num: "-7", den: "1" })
|
|
306
|
+
expect(derive(book(), { op: "expr", formula: "F1 / (F2 - F2)", unit: null }).error).toBeDefined()
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
test("dimension 26: percent products and pct nodes preserve fraction semantics", () => {
|
|
310
|
+
const l = book(["20", "50"], ["%", "%"])
|
|
311
|
+
expect(row(l, { op: "expr", formula: "pct(F1 * F2)", unit: "%" }).exact).toEqual({ num: "10", den: "1" })
|
|
312
|
+
expect(row(l, { op: "diff", operands: ["F2", "F1"], unit: "%p" }).exact).toEqual({ num: "30", den: "1" })
|
|
313
|
+
expect(derive(l, { op: "expr", formula: "pct(F1)", unit: "%" }).error).toBeDefined()
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
test("dimension 27: conversion maps compose with exact independent rational arithmetic", () => {
|
|
317
|
+
const groups = [["mm", "cm", "m", "km"], ["g", "kg", "t"], ["ms", "s", "min", "h"], ["B", "KB", "MB", "GB", "TB"], ["C", "F"], ["%", "\u2030"], ["KRW", "KRW-e3", "KRW-e4", "KRW-e8", "KRW-e12"]]
|
|
318
|
+
const apply = (factor: { num: bigint; den: bigint; offset?: { num: bigint; den: bigint } } | null, x: [bigint, bigint]): [bigint, bigint] => {
|
|
319
|
+
if (!factor) throw Error("missing conversion")
|
|
320
|
+
const o = factor.offset ?? { num: 0n, den: 1n }
|
|
321
|
+
return [x[0] * factor.num * o.den + o.num * x[1] * factor.den, x[1] * factor.den * o.den]
|
|
322
|
+
}
|
|
323
|
+
for (const group of groups) for (const a of group) for (const b of group) for (const c of group) {
|
|
324
|
+
for (const value of [-3n, 0n, 7n]) {
|
|
325
|
+
const direct = apply(convertFactor(a, c), [value, 1n])
|
|
326
|
+
const chained = apply(convertFactor(b, c), apply(convertFactor(a, b), [value, 1n]))
|
|
327
|
+
expect(direct[0] * chained[1]).toBe(chained[0] * direct[1])
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
expect(derive(book(), { op: "convert", operands: ["F1"], to: "furlong" }).error).toBeDefined()
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
test("dimension 28: grammar rejects injection and preserves precedence", () => {
|
|
334
|
+
for (const formula of ["F1;globalThis.x=1", "-F1", "F1 ** 2", "pct F1", "(F1", "F1 F2"]) expect(derive(book(), { op: "expr", formula, unit: "m" }).error).toBeDefined()
|
|
335
|
+
expect(row(book(), { op: "expr", formula: "F1 + F2 * 2", unit: "m" }).exact).toEqual({ num: "7", den: "1" })
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
test("dimension 29: signed rounding ties and canonical display are exact", () => {
|
|
339
|
+
for (const [values, expected] of [[["-1.25", "-2.5"], "-3.8"], [["1.25", "2.5"], "3.8"], [["999.5", "0"], "1000"]] as const) {
|
|
340
|
+
expect(row(book([...values]), sum).value).toBe(expected)
|
|
341
|
+
}
|
|
342
|
+
const l = book(["20", "15"], ["%", "%"])
|
|
343
|
+
const delta = row(l, { op: "diff", operands: ["F1", "F2"], unit: "%p" })
|
|
344
|
+
expect(recompute(l, { ...delta, render: "5 pp" }).ok).toBe(false)
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
test("dimension 30: seeded factor trees have an independent arithmetic and unit oracle", () => {
|
|
348
|
+
let seed = 0x11009
|
|
349
|
+
const next = () => { seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0; return seed }
|
|
350
|
+
const atoms = ["m", "s", "person"]
|
|
351
|
+
for (let i = 0; i < 100; i++) {
|
|
352
|
+
const counts = [0, 0, 0]
|
|
353
|
+
const factors = Array.from({ length: 5 }, () => {
|
|
354
|
+
const index = next() % atoms.length
|
|
355
|
+
const exponent = (next() % 7) - 3
|
|
356
|
+
counts[index] += exponent
|
|
357
|
+
return `(${atoms[index]}^${exponent})`
|
|
358
|
+
})
|
|
359
|
+
const side = (positive: boolean) => atoms.map((a, index) => ({ a, n: counts[index] })).filter(({ n }) => positive ? n > 0 : n < 0).sort((a, b) => a.a.localeCompare(b.a)).map(({ a, n }) => Math.abs(n) === 1 ? a : `${a}^${Math.abs(n)}`)
|
|
360
|
+
const top = side(true).join("*") || "1"
|
|
361
|
+
const bottom = side(false)
|
|
362
|
+
const expectedUnit = bottom.length ? `${top}/${bottom.length === 1 ? bottom[0] : `(${bottom.join("*")})`}` : top === "1" ? null : top
|
|
363
|
+
expect(canonicalUnit(factors.join("*"))).toBe(expectedUnit)
|
|
364
|
+
const a = BigInt(1 + next() % 100)
|
|
365
|
+
const b = BigInt(1 + next() % 100)
|
|
366
|
+
const l = book([String(a), String(b)], [factors.join("*"), "person"])
|
|
367
|
+
const result = row(l, { op: "expr", formula: "F1 * F2 / F2", unit: expectedUnit })
|
|
368
|
+
expect(result.exact).toEqual({ num: String(a), den: "1" })
|
|
369
|
+
expect(result.unit).toBe(expectedUnit)
|
|
370
|
+
expect(recompute(l, result).ok).toBe(true)
|
|
371
|
+
expect(recompute(l, { ...result, exact: { num: String(a + 1n), den: "1" } }).ok).toBe(false)
|
|
372
|
+
}
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
test("dimension 30: independent rational oracle crosses every operation with metadata and tampering", () => {
|
|
376
|
+
let state = 3917
|
|
377
|
+
const next = () => { state = (Math.imul(state, 1103515245) + 12345) >>> 0; return state }
|
|
378
|
+
const exact = (n: bigint, d = 1n) => {
|
|
379
|
+
let a = n < 0n ? -n : n
|
|
380
|
+
let b = d
|
|
381
|
+
while (b) [a, b] = [b, a % b]
|
|
382
|
+
return { num: String(n / a), den: String(d / a) }
|
|
383
|
+
}
|
|
384
|
+
for (let i = 0; i < 50; i++) {
|
|
385
|
+
const a = BigInt(1 + next() % 50)
|
|
386
|
+
const b = a + BigInt(1 + next() % 50)
|
|
387
|
+
const meta = { population: { country: "x", cohort: i }, accounting_basis: "cash", snapshot_window: "2026", entity: "acme" }
|
|
388
|
+
const specs: Array<[Row, { num: string; den: string }]> = [
|
|
389
|
+
[{ ...sum }, exact(a + b)],
|
|
390
|
+
[{ ...sum, op: "diff" }, exact(a - b)],
|
|
391
|
+
[{ op: "ratio", num: "F1", den: "F2", unit: null }, exact(a, b)],
|
|
392
|
+
[{ op: "share", part: "F1", whole: "F2", unit: "%" }, exact(100n * a, b)],
|
|
393
|
+
[{ op: "growth", from: "F1", to: "F2", unit: "%" }, exact(100n * (b - a), a)],
|
|
394
|
+
[{ op: "convert", operands: ["F1"], to: "cm" }, exact(100n * a)],
|
|
395
|
+
[{ op: "expr", formula: "F1 * 2 / F2", unit: null }, exact(2n * a, b)],
|
|
396
|
+
]
|
|
397
|
+
for (const [spec, expected] of specs) {
|
|
398
|
+
const l = book([String(a), String(b)], ["metre", "m"], [{ ...meta, valid_at: "2025" }, { ...meta, valid_at: "2026" }])
|
|
399
|
+
const result = row(l, spec)
|
|
400
|
+
expect(result.exact).toEqual(expected)
|
|
401
|
+
expect(recompute(l, result).ok).toBe(true)
|
|
402
|
+
expect(recompute(l, { ...result, unit: "person" }).ok).toBe(false)
|
|
403
|
+
expect(recompute(l, { ...result, exact: { num: String(BigInt(expected.num) + 1n), den: expected.den } }).ok).toBe(false)
|
|
404
|
+
}
|
|
405
|
+
const l = book([String(100n * a), String(b)], ["bp/person", "person"])
|
|
406
|
+
const result = row(l, { op: "expr", formula: "F1 * F2", unit: "%p" })
|
|
407
|
+
expect(result.exact).toEqual(exact(a * b))
|
|
408
|
+
}
|
|
409
|
+
})
|