From eb12e4025c2a18dcfe48fd89dda8702ab0080ec4 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Fri, 27 Nov 2026 19:29:12 -0800 Subject: [PATCH 01/13] test(spec): pin quint and add the model check script --- .gitignore | 2 + spec/check.sh | 37 ++ spec/package-lock.json | 879 +++++++++++++++++++++++++++++++++++++++++ spec/package.json | 7 + 4 files changed, 925 insertions(+) create mode 100755 spec/check.sh create mode 100644 spec/package-lock.json create mode 100644 spec/package.json diff --git a/.gitignore b/.gitignore index 1f7f54f6..6035dd20 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,5 @@ docs/superpowers/ /test/grpc/generated/ /test/grpc/junit.xml .DS_Store +/spec/node_modules/ +/spec/_apalache-out/ diff --git a/spec/check.sh b/spec/check.sh new file mode 100755 index 00000000..26f7e233 --- /dev/null +++ b/spec/check.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$(dirname "$0")" + +quint() { npx --no-install quint "$@"; } + +holds() { + local spec=$1 main=$2 + shift 2 + echo "holds: $main $*" + quint verify "$spec" --main "$main" --backend tlc "$@" >"$log" 2>&1 || { + cat "$log" >&2 + return 1 + } +} + +violates() { + local spec=$1 main=$2 invariant=$3 + shift 3 + echo "violates: $main $invariant $*" + if quint verify "$spec" --main "$main" --backend tlc --invariant "$invariant" "$@" >"$log" 2>&1; then + echo "$main no longer violates $invariant: move it to a holds line" >&2 + return 1 + fi + grep -q "found a counterexample" "$log" || { + cat "$log" >&2 + return 1 + } +} + +log=$(mktemp) +trap 'rm -f "$log"' EXIT + +for spec in *.qnt; do + quint typecheck "$spec" +done diff --git a/spec/package-lock.json b/spec/package-lock.json new file mode 100644 index 00000000..5f8e977f --- /dev/null +++ b/spec/package-lock.json @@ -0,0 +1,879 @@ +{ + "name": "hyper-spec", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "hyper-spec", + "devDependencies": { + "@informalsystems/quint": "0.35.0" + } + }, + "node_modules/@grpc/grpc-js": { + "version": "1.14.7", + "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.14.7.tgz", + "integrity": "sha512-W4W/fcBMGRVtG6dW2c7cw2mnpS3hvbBd+oQXjh2iYFTZDk1JJmcNqkM5KSaPubQpamlUUurrlb7G1s9NJeERmQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@grpc/proto-loader": "^0.8.0", + "@js-sdsl/ordered-map": "^4.4.2" + }, + "engines": { + "node": ">=12.10.0" + } + }, + "node_modules/@grpc/grpc-js/node_modules/@grpc/proto-loader": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.8.1.tgz", + "integrity": "sha512-wtF6h+DY6M3YaDBPAmvuuA6jV8Sif9MjtOI5euKFWRgCDl5PeDpPsHR9u2l6St5ceY8AZgoNDww5+HvEsXFsGg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "lodash.camelcase": "^4.3.0", + "long": "^5.0.0", + "protobufjs": "^7.5.5", + "yargs": "^17.7.2" + }, + "bin": { + "proto-loader-gen-types": "build/bin/proto-loader-gen-types.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/@grpc/proto-loader": { + "version": "0.7.15", + "resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.7.15.tgz", + "integrity": "sha512-tMXdRCfYVixjuFK+Hk0Q1s38gV9zDiDJfWL3h1rv4Qc39oILCu1TRTDt7+fGUI8K4G1Fj125Hx/ru3azECWTyQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "lodash.camelcase": "^4.3.0", + "long": "^5.0.0", + "protobufjs": "^7.2.5", + "yargs": "^17.7.2" + }, + "bin": { + "proto-loader-gen-types": "build/bin/proto-loader-gen-types.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/@informalsystems/quint": { + "version": "0.35.0", + "resolved": "https://registry.npmjs.org/@informalsystems/quint/-/quint-0.35.0.tgz", + "integrity": "sha512-IMCoGVKZCmbTLvvaZnAdpYj8xIIde+8TEOhpVV/lsljWPl9+OdsRoZv8PpvV7KYXyvDlUGfVEf9TPQ8GDzjmeA==", + "dev": true, + "license": "Apache 2.0", + "dependencies": { + "@grpc/grpc-js": "^1.11.1", + "@grpc/proto-loader": "^0.7.7", + "@octokit/request": "^8.1.1", + "@sweet-monads/either": "~3.2.0", + "@sweet-monads/maybe": "~3.2.0", + "@types/line-column": "^1.0.0", + "@types/lodash.clonedeep": "4.5.0", + "@types/seedrandom": "^3.0.4", + "adm-zip": "^0.6.1", + "antlr4ts": "^0.5.0-alpha.4", + "chalk": "^4.1.2", + "cli-progress": "^3.12.0", + "cross-spawn": "^7.0.6", + "eol": "^0.9.1", + "immutable": "^4.3.0", + "json-bigint": "^1.0.0", + "line-column": "^1.0.2", + "lodash": "^4.17.21", + "lodash.clonedeep": "4.5.0", + "protobufjs": "^7.2.5", + "seedrandom": "^3.0.5", + "tar": "^7.5.13", + "yargs": "^17.7.2" + }, + "bin": { + "quint": "dist/src/cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@isaacs/fs-minipass": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@isaacs/fs-minipass/-/fs-minipass-4.0.1.tgz", + "integrity": "sha512-wgm9Ehl2jpeqP3zw/7mo3kRHFp5MEDhqAdwy1fTGkHAwnkGOVsgpvQhL8B5n1qlb01jV3n/bI0ZfZp5lWA1k4w==", + "dev": true, + "license": "ISC", + "dependencies": { + "minipass": "^7.0.4" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@js-sdsl/ordered-map": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/@js-sdsl/ordered-map/-/ordered-map-4.4.2.tgz", + "integrity": "sha512-iUKgm52T8HOE/makSxjqoWhe95ZJA1/G1sYsGev2JDKUSS14KAgg1LHb+Ba+IPow0xflbnSkOsZcO08C7w1gYw==", + "dev": true, + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/js-sdsl" + } + }, + "node_modules/@octokit/endpoint": { + "version": "9.0.6", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.6.tgz", + "integrity": "sha512-H1fNTMA57HbkFESSt3Y9+FBICv+0jFceJFPWDePYlR/iMGrwM5ph+Dd4XRQs+8X+PUFURLQgX9ChPfhJ/1uNQw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@octokit/types": "^13.1.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "24.2.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-24.2.0.tgz", + "integrity": "sha512-9sIH3nSUttelJSXUrmGzl7QUBFul0/mB8HRYl3fOlgHbIWG+WnYDXU3v/2zMtAvuzZ/ed00Ei6on975FhBfzrg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@octokit/request": { + "version": "8.4.1", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.4.1.tgz", + "integrity": "sha512-qnB2+SY3hkCmBxZsR/MPCybNmbJe4KAlfWErXq+rBKkQJlbjdJeS85VI9r8UqeLYLvnAenU8Q1okM/0MBsAGXw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@octokit/endpoint": "^9.0.6", + "@octokit/request-error": "^5.1.1", + "@octokit/types": "^13.1.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/request-error": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.1.1.tgz", + "integrity": "sha512-v9iyEQJH6ZntoENr9/yXxjuezh4My67CBSu9r6Ve/05Iu5gNgnisNWOsoJHTP6k0Rr0+HQIpnH+kyammu90q/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@octokit/types": "^13.1.0", + "deprecation": "^2.0.0", + "once": "^1.4.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/types": { + "version": "13.10.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.10.0.tgz", + "integrity": "sha512-ifLaO34EbbPj0Xgro4G5lP5asESjwHracYJvVaPIyXMuiuXLlhic3S47cBdTb+jfODkTE5YtGCLt3Ay3+J97sA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@octokit/openapi-types": "^24.2.0" + } + }, + "node_modules/@protobufjs/aspromise": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", + "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/base64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/codegen": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.5.tgz", + "integrity": "sha512-zgXFLzW3Ap33e6d0Wlj4MGIm6Ce8O89n/apUaGNB/jx+hw+ruWEp7EwGUshdLKVRCxZW12fp9r40E1mQrf/34g==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/eventemitter": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.1.tgz", + "integrity": "sha512-vW1GmwMZNnL+gMRaovlh9yZX74kc+TTU3FObkkurpMaRtBfLP3ldjS9KQWlwZgraRE0+dheEEoAxdzcJQ8eXZg==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/fetch": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.1.tgz", + "integrity": "sha512-GpptLrs57adMSuHi3VNj0mAF8dwh36LMaYF6XyJ6JMWlVsc+t42tm1HSEDmOs3A8fC9yyeisgLhsTVQokOZ0zw==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@protobufjs/aspromise": "^1.1.1" + } + }, + "node_modules/@protobufjs/float": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", + "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/path": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", + "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", + "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/utf8": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.2.tgz", + "integrity": "sha512-b1UQwcEZ4yCnMCD8DAL1VlbvBJE9/IX4FTIp7BG1xYpf29SLazLSrqUkj4w7Y5y7cCVP6E5tcqqcI0xemPkHug==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/@sweet-monads/either": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@sweet-monads/either/-/either-3.2.0.tgz", + "integrity": "sha512-n+nR0b60GRTKb+D76qhTf4NEBXU9zfpigYYEtKtSYbV+5+i5gxr9jFd64pYkY2O7hVsb/G7nspbAeFni/i1ltA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@sweet-monads/interfaces": "^3.2.0" + } + }, + "node_modules/@sweet-monads/interfaces": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/@sweet-monads/interfaces/-/interfaces-3.3.0.tgz", + "integrity": "sha512-66akGvjPD4lizQy+w4JSltJilc2w/QPdw8lPAniLJGHwyjmrw9xMJLx76Q/GDnbCU59Werses4aZJLWOlJrL5A==", + "dev": true, + "license": "MIT" + }, + "node_modules/@sweet-monads/maybe": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@sweet-monads/maybe/-/maybe-3.2.0.tgz", + "integrity": "sha512-/t+K0D/kBfkYOkZaePEsrK868at0M9UIEVgehcM0xscrCSZhKWGteE41vl2XJQqh8WyiFo/mZ5y7eAPSYzS+pg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@sweet-monads/interfaces": "^3.2.0" + } + }, + "node_modules/@types/line-column": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@types/line-column/-/line-column-1.0.2.tgz", + "integrity": "sha512-099oFQmp/Tlf20xW5XI5R4F69N6lF/zQ09XDzc3R5BOLFlqIotgKoNIyj0HD4fQLWcGDreDJv8k/BkLJscrDrw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/lodash": { + "version": "4.17.28", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.28.tgz", + "integrity": "sha512-2iP9dTMtHQOGZq086o7CyIVz5h3hCS7xqG1dZg3hfbxqcB5/ZaFD+vOp9ebR8YlbCQr84OQjBiv/qgITjHSrYA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha512-IHijjFVPJTvzvrNPz+6nQy5lZQb7uh807RfTIEaQBrZXrIGjZy0L2dEb3hju34J0eqbXLCY6Hub/g81Jl4pGCA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/lodash": "*" + } + }, + "node_modules/@types/node": { + "version": "26.6.11", + "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.11.tgz", + "integrity": "sha512-uUyQ2XLEz+EXh34lmS3GhKrkqn/8FU7KUiKRpk347At2bmnMVWss45yz8b4FG/tUtmV1tV/+TVkITItPROyeeQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~8.9.0" + } + }, + "node_modules/@types/seedrandom": { + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/@types/seedrandom/-/seedrandom-3.0.8.tgz", + "integrity": "sha512-TY1eezMU2zH2ozQoAFAQFOPpvP15g+ZgSfTZt31AUUH/Rxtnz3H+A/Sv1Snw2/amp//omibc+AEkTaA8KUeOLQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/adm-zip": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.6.1.tgz", + "integrity": "sha512-Xwrja8nx9e5o2N1my4DsKCeKpdrnACyr1wtbPxBDgGzKzKyE9kRtBFA8mWldI+RVlD7CBZNWY/wQ2+ydwOR6kQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/antlr4ts": { + "version": "0.5.0-alpha.4", + "resolved": "https://registry.npmjs.org/antlr4ts/-/antlr4ts-0.5.0-alpha.4.tgz", + "integrity": "sha512-WPQDt1B74OfPv/IMS2ekXAKkTZIHl88uMetg6q3OTqgFxZ/dxDXI0EWLyZid/1Pe6hTftyg5N7gel5wNAGxXyQ==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/bignumber.js": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.3.1.tgz", + "integrity": "sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": "*" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/chownr": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-3.0.0.tgz", + "integrity": "sha512-+IxzY9BZOQd/XuYPRmrvEVjF/nqj5kgT4kEq7VofrDoM1MxoRjEWkrCC3EtLi59TVawxTAn+orJwFQcrqEN1+g==", + "dev": true, + "license": "BlueOak-1.0.0", + "engines": { + "node": ">=18" + } + }, + "node_modules/cli-progress": { + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/cli-progress/-/cli-progress-3.12.0.tgz", + "integrity": "sha512-tRkV3HJ1ASwm19THiiLIXLO7Im7wlTuKnvkYaTkyoAPefqjNg7W7DHKUlGRxy9vxDvbyCYQkQozvptuMkGCg8A==", + "dev": true, + "license": "MIT", + "dependencies": { + "string-width": "^4.2.3" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true, + "license": "MIT" + }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/deprecation": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", + "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true, + "license": "MIT" + }, + "node_modules/eol": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/eol/-/eol-0.9.1.tgz", + "integrity": "sha512-Ds/TEoZjwggRoz/Q2O7SE3i4Jm66mqTDfmdHdq/7DKVk3bro9Q8h6WdXKdPqFLMoqxrDK5SVRzHVPOS6uuGtrg==", + "dev": true, + "license": "MIT" + }, + "node_modules/escalade": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", + "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true, + "license": "ISC", + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/immutable": { + "version": "4.3.9", + "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.3.9.tgz", + "integrity": "sha512-ObHy4YN7ycwZOUCLI1/6svfyAFu7vL8RhAvVu/bh/RZW9EPlOyDaQ9jDQWCtdqzaXUjgXZCW1migtHE7YI7UGQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, + "node_modules/isobject": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz", + "integrity": "sha512-+OUdGJlgjOBZDfxnDjYYG6zp487z0JGNQq3cYQYg5f5hKR+syHMsaztzGeml/4kGG55CSpKSpWTY+jYGgsHLgA==", + "dev": true, + "license": "MIT", + "dependencies": { + "isarray": "1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/json-bigint": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz", + "integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "bignumber.js": "^9.0.0" + } + }, + "node_modules/line-column": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/line-column/-/line-column-1.0.2.tgz", + "integrity": "sha512-Ktrjk5noGYlHsVnYWh62FLVs4hTb8A3e+vucNZMgPeAOITdshMSgv4cCZQeRDjm7+goqmo6+liZwTXo+U3sVww==", + "dev": true, + "license": "MIT", + "dependencies": { + "isarray": "^1.0.0", + "isobject": "^2.0.0" + } + }, + "node_modules/lodash": { + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz", + "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.camelcase": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", + "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/long": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", + "dev": true, + "license": "Apache-2.0" + }, + "node_modules/minipass": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.3.tgz", + "integrity": "sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A==", + "dev": true, + "license": "BlueOak-1.0.0", + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, + "node_modules/minizlib": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-3.1.0.tgz", + "integrity": "sha512-KZxYo1BUkWD2TVFLr0MQoM8vUUigWD3LlD83a/75BqC+4qE0Hb1Vo5v1FgcfaNXvfXzr+5EhQ6ing/CaBijTlw==", + "dev": true, + "license": "MIT", + "dependencies": { + "minipass": "^7.1.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/protobufjs": { + "version": "7.6.6", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.6.6.tgz", + "integrity": "sha512-dYDWdjSl5RNb7SgPxGQcRU+GtvP7s2fpkrY0r432PcOIaZ0/rBcxEZnQN67iJhFuQiVw754JDoPruPCNdGsbjg==", + "dev": true, + "hasInstallScript": true, + "license": "BSD-3-Clause", + "dependencies": { + "@protobufjs/aspromise": "^1.1.2", + "@protobufjs/base64": "^1.1.2", + "@protobufjs/codegen": "^2.0.5", + "@protobufjs/eventemitter": "^1.1.1", + "@protobufjs/fetch": "^1.1.1", + "@protobufjs/float": "^1.0.2", + "@protobufjs/path": "^1.1.2", + "@protobufjs/pool": "^1.1.0", + "@protobufjs/utf8": "^1.1.1", + "@types/node": ">=13.7.0", + "long": "^5.3.2" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/seedrandom": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz", + "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==", + "dev": true, + "license": "MIT" + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/tar": { + "version": "7.5.24", + "resolved": "https://registry.npmjs.org/tar/-/tar-7.5.24.tgz", + "integrity": "sha512-to/OxuCk5DeVONcjjODT7aeoRq5NIPPlfPc0tNML+wLlnf6u5BcJz97Uukv3pT3jzorkFhUevylkAiBr+ZmV2w==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/fs-minipass": "^4.0.0", + "chownr": "^3.0.0", + "minipass": "^7.1.2", + "minizlib": "^3.1.0", + "yallist": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/undici-types": { + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.9.0.tgz", + "integrity": "sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg==", + "dev": true, + "license": "MIT" + }, + "node_modules/universal-user-agent": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.1.tgz", + "integrity": "sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=10" + } + }, + "node_modules/yallist": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-5.0.0.tgz", + "integrity": "sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==", + "dev": true, + "license": "BlueOak-1.0.0", + "engines": { + "node": ">=18" + } + }, + "node_modules/yargs": { + "version": "17.7.3", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.3.tgz", + "integrity": "sha512-GZtjxm/J/4TSxuL3FNYjCmLktBTnIw/rVmKSIyKeYAZpmJB2ig9VauCC5xsa82GNKVKDAqpOn3KVzNt0zmrU0g==", + "dev": true, + "license": "MIT", + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=12" + } + } + } +} diff --git a/spec/package.json b/spec/package.json new file mode 100644 index 00000000..82b410ba --- /dev/null +++ b/spec/package.json @@ -0,0 +1,7 @@ +{ + "name": "hyper-spec", + "private": true, + "devDependencies": { + "@informalsystems/quint": "0.35.0" + } +} From a9eecda5b279ba6b2b3dbf75240c8c02f12080a5 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Fri, 27 Nov 2026 20:19:18 -0800 Subject: [PATCH 02/13] test(spec): fail a holds line that checks no invariant quint verify exits 0 when the main module exposes no invariant definition, so a holds line could pass having checked nothing. - holds compiles the scenario first and requires an invariant, then prints TLC's state count. - violates requires TLC to name the invariant, not any violation. - Run the pinned quint from node_modules; npx falls back to a global one. - A malformed line exits 2 instead of aborting on an unbound variable, which bash 3.2 turns into exit 0 through the EXIT trap. --- spec/check.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/spec/check.sh b/spec/check.sh index 26f7e233..c3b0174c 100755 --- a/spec/check.sh +++ b/spec/check.sh @@ -3,19 +3,33 @@ set -euo pipefail cd "$(dirname "$0")" -quint() { npx --no-install quint "$@"; } +quint() { node_modules/.bin/quint "$@"; } holds() { + [ $# -ge 2 ] || { + echo "usage: holds spec main [flag...]" >&2 + return 2 + } local spec=$1 main=$2 shift 2 echo "holds: $main $*" + quint compile "$spec" --main "$main" --target json "$@" >"$log" + grep -q '"name":"q::inv"' "$log" || { + echo "$main checks no invariant" >&2 + return 1 + } quint verify "$spec" --main "$main" --backend tlc "$@" >"$log" 2>&1 || { cat "$log" >&2 return 1 } + grep "distinct states found" "$log" } violates() { + [ $# -ge 3 ] || { + echo "usage: violates spec main invariant [flag...]" >&2 + return 2 + } local spec=$1 main=$2 invariant=$3 shift 3 echo "violates: $main $invariant $*" @@ -23,7 +37,7 @@ violates() { echo "$main no longer violates $invariant: move it to a holds line" >&2 return 1 fi - grep -q "found a counterexample" "$log" || { + grep -q "Invariant q_inv is violated" "$log" || { cat "$log" >&2 return 1 } From c31a6030dca455850ef30d5c5363a795e3ee23ed Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Fri, 27 Nov 2026 20:42:54 -0800 Subject: [PATCH 03/13] test(spec): model the per-VM id pools --- spec/check.sh | 5 + spec/id_pool.qnt | 242 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 247 insertions(+) create mode 100644 spec/id_pool.qnt diff --git a/spec/check.sh b/spec/check.sh index c3b0174c..1751ee78 100755 --- a/spec/check.sh +++ b/spec/check.sh @@ -49,3 +49,8 @@ trap 'rm -f "$log"' EXIT for spec in *.qnt; do quint typecheck "$spec" done + +holds id_pool.qnt id_pool_small + +violates id_pool.qnt id_pool_small freedUnused --step stepTransientRestart +violates id_pool.qnt id_pool_small idExclusive --step stepPoolRestart diff --git a/spec/id_pool.qnt b/spec/id_pool.qnt new file mode 100644 index 00000000..7545aaa2 --- /dev/null +++ b/spec/id_pool.qnt @@ -0,0 +1,242 @@ +module id_pool { + type Id = int + type Pid = int + type Ref = int + + type Msg = + | Free(Id) + | Down(Ref) + + type Phase = + | Idle + | Claimed(Id) + | Started({ id: Id, pid: Pid }) + | Finished + + type Pool = { + bump: Id, + freed: List[Id], + owners: Ref -> Id, + mailbox: List[Msg], + } + + type World = { + pool: Pool, + monitors: Ref -> Pid, + phase: int -> Phase, + alive: Set[Pid], + idOf: Pid -> Id, + restarts: int, + } + + const MAX_ID: Id + const ATTEMPTS: Set[int] + const MAX_RESTARTS: int + + var world: World + + pure val emptyPool: Pool = { bump: 0, freed: List(), owners: Map(), mailbox: List() } + + pure def without(m: a -> b, k: a): a -> b = + m.keys().exclude(Set(k)).mapBy(x => m.get(x)) + + pure def enqueue(p: Pool, msg: Msg): Pool = { ...p, mailbox: p.mailbox.append(msg) } + + pure def freshRef(w: World): Ref = + w.pool.owners.keys().union(w.monitors.keys()).fold(0, (m, r) => if (r >= m) r + 1 else m) + + pure def freshPid(w: World): Pid = w.idOf.keys().size() + + pure def claimedId(p: Phase): Id = match p { + | Claimed(id) => id + | _ => -1 + } + + pure def startedPid(p: Phase): Pid = match p { + | Started(s) => s.pid + | _ => -1 + } + + pure def startedId(p: Phase): Id = match p { + | Started(s) => s.id + | _ => -1 + } + + pure def claim(w: World, a: int): World = + if (w.pool.bump <= MAX_ID) { + ...w, + pool: { ...w.pool, bump: w.pool.bump + 1 }, + phase: w.phase.set(a, Claimed(w.pool.bump)), + } else if (w.pool.freed.length() > 0) { + ...w, + pool: { ...w.pool, freed: w.pool.freed.tail() }, + phase: w.phase.set(a, Claimed(w.pool.freed.head())), + } else { + ...w, + phase: w.phase.set(a, Finished), + } + + pure def release(w: World, a: int): World = { + ...w, + pool: w.pool.enqueue(Free(claimedId(w.phase.get(a)))), + phase: w.phase.set(a, Finished), + } + + pure def spawn(w: World, a: int): World = { + ...w, + alive: w.alive.union(Set(freshPid(w))), + idOf: w.idOf.put(freshPid(w), claimedId(w.phase.get(a))), + phase: w.phase.set(a, Started({ id: claimedId(w.phase.get(a)), pid: freshPid(w) })), + } + + pure def bind(w: World, a: int): World = { + val pid = startedPid(w.phase.get(a)) + val ref = freshRef(w) + val bound = { ...w.pool, owners: w.pool.owners.put(ref, startedId(w.phase.get(a))) } + if (w.alive.contains(pid)) { + ...w, + pool: bound, + monitors: w.monitors.put(ref, pid), + phase: w.phase.set(a, Finished), + } else { + ...w, + pool: bound.enqueue(Down(ref)), + phase: w.phase.set(a, Finished), + } + } + + pure def exit(w: World, pid: Pid): World = { + val watching = w.monitors.keys().filter(r => w.monitors.get(r) == pid) + { + ...w, + alive: w.alive.exclude(Set(pid)), + pool: watching.fold(w.pool, (p, r) => p.enqueue(Down(r))), + monitors: w.monitors.keys().exclude(watching).mapBy(r => w.monitors.get(r)), + } + } + + pure def respawn(w: World, pid: Pid): World = { + val exited = exit(w, pid) + { + ...exited, + alive: exited.alive.union(Set(freshPid(w))), + idOf: w.idOf.put(freshPid(w), w.idOf.get(pid)), + restarts: w.restarts + 1, + } + } + + pure def deliver(p: Pool): Pool = { + val rest = { ...p, mailbox: p.mailbox.tail() } + match p.mailbox.head() { + | Free(id) => { ...rest, freed: rest.freed.append(id) } + | Down(ref) => + if (p.owners.keys().contains(ref)) { + ...rest, + freed: rest.freed.append(p.owners.get(ref)), + owners: p.owners.without(ref), + } else rest + } + } + + action init = world' = { + pool: emptyPool, + monitors: Map(), + phase: ATTEMPTS.mapBy(_ => Idle), + alive: Set(), + idOf: Map(), + restarts: 0, + } + + action claimId(a: int): bool = all { + world.phase.get(a) == Idle, + world' = claim(world, a), + } + + action releaseId(a: int): bool = all { + claimedId(world.phase.get(a)) >= 0, + world' = release(world, a), + } + + action spawnVm(a: int): bool = all { + claimedId(world.phase.get(a)) >= 0, + world' = spawn(world, a), + } + + action bindOwner(a: int): bool = all { + startedPid(world.phase.get(a)) >= 0, + world' = bind(world, a), + } + + action deliverMessage = all { + world.pool.mailbox.length() > 0, + world' = { ...world, pool: deliver(world.pool) }, + } + + action vmExits(pid: Pid): bool = all { + world.alive.contains(pid), + world' = exit(world, pid), + } + + action vmRespawns(pid: Pid): bool = all { + world.alive.contains(pid), + world.restarts < MAX_RESTARTS, + world' = respawn(world, pid), + } + + action poolRestarts = all { + world.restarts < MAX_RESTARTS, + world' = { ...world, pool: emptyPool, monitors: Map(), alive: Set(), restarts: world.restarts + 1 }, + } + + action lifecycle = { + nondet a = ATTEMPTS.oneOf() + nondet pid = world.idOf.keys().union(Set(-1)).oneOf() + any { + claimId(a), + releaseId(a), + spawnVm(a), + bindOwner(a), + deliverMessage, + vmExits(pid), + } + } + + action step = lifecycle + + action stepTransientRestart = any { + lifecycle, + { + nondet pid = world.idOf.keys().union(Set(-1)).oneOf() + vmRespawns(pid) + }, + } + + action stepPoolRestart = any { + lifecycle, + poolRestarts, + } + + invariant idExclusive = + world.alive.forall(p => world.alive.forall(q => p == q or world.idOf.get(p) != world.idOf.get(q))) + + invariant freedDistinct = { + val freed = world.pool.freed + freed.indices().forall(i => freed.indices().forall(j => i == j or freed.nth(i) != freed.nth(j))) + } + + invariant freedUnused = { + val freed = world.pool.freed + world.alive.forall(p => freed.indices().forall(i => freed.nth(i) != world.idOf.get(p))) + } + + observation idReusedAfterExit = + world.alive.exists(p => world.idOf.keys().exists(q => + q < p and not(world.alive.contains(q)) and world.idOf.get(q) == world.idOf.get(p))) + + observation exhausted = + world.pool.bump > MAX_ID and world.pool.freed.length() == 0 and world.alive.size() == MAX_ID + 1 +} + +module id_pool_small { + import id_pool(MAX_ID = 1, ATTEMPTS = Set(0, 1, 2), MAX_RESTARTS = 1).* +} From 1ca95fafddb03e040f87bc38b19833652e6baa78 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Fri, 27 Nov 2026 21:32:15 -0800 Subject: [PATCH 04/13] test(spec): model placement and admission --- spec/check.sh | 8 ++ spec/placement.qnt | 227 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+) create mode 100644 spec/placement.qnt diff --git a/spec/check.sh b/spec/check.sh index 1751ee78..5fc7232e 100755 --- a/spec/check.sh +++ b/spec/check.sh @@ -54,3 +54,11 @@ holds id_pool.qnt id_pool_small violates id_pool.qnt id_pool_small freedUnused --step stepTransientRestart violates id_pool.qnt id_pool_small idExclusive --step stepPoolRestart + +holds placement.qnt placement_reliable +holds placement.qnt placement_lossy + +violates placement.qnt placement_reliable runningWithinCapacity +violates placement.qnt placement_lossy failedLeavesNothingBehind +violates placement.qnt placement_hard_crash admittedWithinCapacity +violates placement.qnt placement_retrying placedAtMostOnce diff --git a/spec/placement.qnt b/spec/placement.qnt new file mode 100644 index 00000000..5a937692 --- /dev/null +++ b/spec/placement.qnt @@ -0,0 +1,227 @@ +module placement { + type Node = str + type Req = int + + type Stage = Sent | Booted + + type Outcome = + | Undecided + | Placed(Node) + | NoCapacity + | NodeUnreachable + + type NodeState = { + tasks: Req -> Stage, + running: Set[Req], + reserved: Set[Req], + admitted: Set[Req], + advertisedFree: int, + } + + type ReqState = { + candidates: Set[Node], + ranked: bool, + awaiting: Set[Node], + outcome: Outcome, + } + + type World = { + nodes: Node -> NodeState, + reqs: Req -> ReqState, + crashes: int, + } + + const NODES: Set[Node] + const REQS: Set[Req] + const CAPACITY: int + const CALLS_CAN_BE_LOST: bool + const RETRY_AFTER_LOSS: bool + const MAX_HARD_CRASHES: int + + var world: World + + pure def without(m: a -> b, k: a): a -> b = + m.keys().exclude(Set(k)).mapBy(x => m.get(x)) + + pure def withNode(w: World, n: Node, f: NodeState => NodeState): World = + { ...w, nodes: w.nodes.setBy(n, f) } + + pure def withReq(w: World, r: Req, f: ReqState => ReqState): World = + { ...w, reqs: w.reqs.setBy(r, f) } + + pure def idle(w: World, r: Req): bool = + w.reqs.get(r).outcome == Undecided and w.reqs.get(r).awaiting == Set() + + pure def stageIs(w: World, n: Node, r: Req, stage: Stage): bool = + w.nodes.get(n).tasks.keys().contains(r) and w.nodes.get(n).tasks.get(r) == stage + + pure def rank(w: World, r: Req): World = + w.withReq(r, q => { + ...q, + ranked: true, + candidates: NODES.filter(n => w.nodes.get(n).advertisedFree >= 1), + }) + + pure def dispatch(w: World, r: Req, n: Node): World = + w.withReq(r, q => { ...q, candidates: q.candidates.exclude(Set(n)), awaiting: Set(n) }) + .withNode(n, s => { ...s, tasks: s.tasks.put(r, Sent) }) + + pure def exhaust(w: World, r: Req): World = + w.withReq(r, q => { ...q, outcome: NoCapacity }) + + pure def boot(w: World, n: Node, r: Req): World = + w.withNode(n, s => { ...s, tasks: s.tasks.put(r, Booted), running: s.running.union(Set(r)) }) + + pure def reply(w: World, n: Node, r: Req, outcome: Outcome): World = + if (w.reqs.get(r).awaiting.contains(n)) + w.withReq(r, q => { ...q, awaiting: Set(), outcome: outcome }) + else w + + pure def refuse(w: World, n: Node, r: Req): World = + w.withNode(n, s => { ...s, tasks: s.tasks.without(r), running: s.running.exclude(Set(r)) }) + .reply(n, r, Undecided) + + pure def admit(w: World, n: Node, r: Req): World = + if (w.nodes.get(n).reserved.size() < CAPACITY) + w.withNode(n, s => { + ...s, + tasks: s.tasks.without(r), + reserved: s.reserved.union(Set(r)), + admitted: s.admitted.union(Set(r)), + }).reply(n, r, Placed(n)) + else refuse(w, n, r) + + pure def lose(w: World, r: Req): World = + w.withReq(r, q => { + ...q, + awaiting: Set(), + outcome: if (RETRY_AFTER_LOSS) Undecided else NodeUnreachable, + }) + + pure def exit(w: World, n: Node, r: Req): World = + w.withNode(n, s => { + ...s, + running: s.running.exclude(Set(r)), + reserved: s.reserved.exclude(Set(r)), + admitted: s.admitted.exclude(Set(r)), + }) + + pure def advertise(w: World, n: Node): World = + w.withNode(n, s => { ...s, advertisedFree: CAPACITY - s.reserved.size() }) + + pure def crashHard(w: World, n: Node): World = + { ...w.withNode(n, s => { ...s, reserved: Set() }), crashes: w.crashes + 1 } + + action init = world' = { + nodes: NODES.mapBy(_ => { + tasks: Map(), + running: Set(), + reserved: Set(), + admitted: Set(), + advertisedFree: CAPACITY, + }), + reqs: REQS.mapBy(_ => { candidates: Set(), ranked: false, awaiting: Set(), outcome: Undecided }), + crashes: 0, + } + + action step = { + nondet r = REQS.oneOf() + nondet n = NODES.oneOf() + any { + all { idle(world, r), not(world.reqs.get(r).ranked), world' = rank(world, r) }, + all { + idle(world, r), + world.reqs.get(r).ranked, + world.reqs.get(r).candidates.contains(n), + world' = dispatch(world, r, n), + }, + all { + idle(world, r), + world.reqs.get(r).ranked, + world.reqs.get(r).candidates == Set(), + world' = exhaust(world, r), + }, + all { stageIs(world, n, r, Sent), world' = boot(world, n, r) }, + all { stageIs(world, n, r, Sent), world' = refuse(world, n, r) }, + all { stageIs(world, n, r, Booted), world' = admit(world, n, r) }, + all { + CALLS_CAN_BE_LOST, + world.reqs.get(r).awaiting != Set(), + world' = lose(world, r), + }, + all { + world.nodes.get(n).running.contains(r), + not(world.nodes.get(n).tasks.keys().contains(r)), + world' = exit(world, n, r), + }, + world' = advertise(world, n), + all { world.crashes < MAX_HARD_CRASHES, world' = crashHard(world, n) }, + } + } + + invariant reservationsWithinCapacity = + NODES.forall(n => world.nodes.get(n).reserved.size() <= CAPACITY) + + invariant admittedWithinCapacity = + NODES.forall(n => world.nodes.get(n).admitted.size() <= CAPACITY) + + invariant placedAtMostOnce = + REQS.forall(r => NODES.filter(n => world.nodes.get(n).running.contains(r)).size() <= 1) + + val runningWithinCapacity = + NODES.forall(n => world.nodes.get(n).running.size() <= CAPACITY) + + val failedLeavesNothingBehind = + REQS.forall(r => + world.reqs.get(r).outcome == NodeUnreachable implies + NODES.forall(n => + not(world.nodes.get(n).running.contains(r)) and + not(world.nodes.get(n).tasks.keys().contains(r)))) + + observation everyNodeFull = + NODES.forall(n => world.nodes.get(n).admitted.size() == CAPACITY) +} + +module placement_reliable { + import placement( + NODES = Set("a", "b"), + REQS = Set(1, 2, 3), + CAPACITY = 1, + CALLS_CAN_BE_LOST = false, + RETRY_AFTER_LOSS = false, + MAX_HARD_CRASHES = 0 + ).* +} + +module placement_lossy { + import placement( + NODES = Set("a", "b"), + REQS = Set(1, 2, 3), + CAPACITY = 1, + CALLS_CAN_BE_LOST = true, + RETRY_AFTER_LOSS = false, + MAX_HARD_CRASHES = 0 + ).* +} + +module placement_retrying { + import placement( + NODES = Set("a", "b"), + REQS = Set(1, 2), + CAPACITY = 1, + CALLS_CAN_BE_LOST = true, + RETRY_AFTER_LOSS = true, + MAX_HARD_CRASHES = 0 + ).* +} + +module placement_hard_crash { + import placement( + NODES = Set("a", "b"), + REQS = Set(1, 2, 3), + CAPACITY = 1, + CALLS_CAN_BE_LOST = false, + RETRY_AFTER_LOSS = false, + MAX_HARD_CRASHES = 1 + ).* +} From a9a99d9fcd623803b3add7331cb31667bd7bcbd1 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Fri, 27 Nov 2026 21:52:58 -0800 Subject: [PATCH 05/13] test(spec): model VM respawn and snapshot trust in placement - placement_vm_respawn: a VM supervisor restarting under a new pid drops its reservation and keeps running, so admitted VMs exceed capacity with no Hard crash. - placement_trusting: a planted bug where admit trusts the advertised snapshot instead of the live count. Until now the snapshot changed no verdict. - unreachableLeavesNothingAdmitted replaces failedLeavesNothingBehind, which tripped on a call still in flight, before anything booted. --- spec/check.sh | 4 ++- spec/placement.qnt | 66 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/spec/check.sh b/spec/check.sh index 5fc7232e..c5d2659a 100755 --- a/spec/check.sh +++ b/spec/check.sh @@ -59,6 +59,8 @@ holds placement.qnt placement_reliable holds placement.qnt placement_lossy violates placement.qnt placement_reliable runningWithinCapacity -violates placement.qnt placement_lossy failedLeavesNothingBehind +violates placement.qnt placement_lossy unreachableLeavesNothingAdmitted violates placement.qnt placement_hard_crash admittedWithinCapacity +violates placement.qnt placement_vm_respawn admittedWithinCapacity violates placement.qnt placement_retrying placedAtMostOnce +violates placement.qnt placement_trusting reservationsWithinCapacity diff --git a/spec/placement.qnt b/spec/placement.qnt index 5a937692..894734bf 100644 --- a/spec/placement.qnt +++ b/spec/placement.qnt @@ -29,6 +29,7 @@ module placement { nodes: Node -> NodeState, reqs: Req -> ReqState, crashes: int, + respawns: int, } const NODES: Set[Node] @@ -36,7 +37,9 @@ module placement { const CAPACITY: int const CALLS_CAN_BE_LOST: bool const RETRY_AFTER_LOSS: bool + const ADMIT_TRUSTS_SNAPSHOT: bool const MAX_HARD_CRASHES: int + const MAX_VM_RESPAWNS: int var world: World @@ -81,8 +84,11 @@ module placement { w.withNode(n, s => { ...s, tasks: s.tasks.without(r), running: s.running.exclude(Set(r)) }) .reply(n, r, Undecided) + pure def fits(s: NodeState): bool = + if (ADMIT_TRUSTS_SNAPSHOT) s.advertisedFree >= 1 else s.reserved.size() < CAPACITY + pure def admit(w: World, n: Node, r: Req): World = - if (w.nodes.get(n).reserved.size() < CAPACITY) + if (fits(w.nodes.get(n))) w.withNode(n, s => { ...s, tasks: s.tasks.without(r), @@ -112,6 +118,9 @@ module placement { pure def crashHard(w: World, n: Node): World = { ...w.withNode(n, s => { ...s, reserved: Set() }), crashes: w.crashes + 1 } + pure def respawn(w: World, n: Node, r: Req): World = + { ...w.withNode(n, s => { ...s, reserved: s.reserved.exclude(Set(r)) }), respawns: w.respawns + 1 } + action init = world' = { nodes: NODES.mapBy(_ => { tasks: Map(), @@ -122,6 +131,7 @@ module placement { }), reqs: REQS.mapBy(_ => { candidates: Set(), ranked: false, awaiting: Set(), outcome: Undecided }), crashes: 0, + respawns: 0, } action step = { @@ -156,6 +166,12 @@ module placement { }, world' = advertise(world, n), all { world.crashes < MAX_HARD_CRASHES, world' = crashHard(world, n) }, + all { + world.respawns < MAX_VM_RESPAWNS, + world.nodes.get(n).running.contains(r), + not(world.nodes.get(n).tasks.keys().contains(r)), + world' = respawn(world, n, r), + }, } } @@ -171,12 +187,10 @@ module placement { val runningWithinCapacity = NODES.forall(n => world.nodes.get(n).running.size() <= CAPACITY) - val failedLeavesNothingBehind = + val unreachableLeavesNothingAdmitted = REQS.forall(r => world.reqs.get(r).outcome == NodeUnreachable implies - NODES.forall(n => - not(world.nodes.get(n).running.contains(r)) and - not(world.nodes.get(n).tasks.keys().contains(r)))) + NODES.forall(n => not(world.nodes.get(n).admitted.contains(r)))) observation everyNodeFull = NODES.forall(n => world.nodes.get(n).admitted.size() == CAPACITY) @@ -189,7 +203,9 @@ module placement_reliable { CAPACITY = 1, CALLS_CAN_BE_LOST = false, RETRY_AFTER_LOSS = false, - MAX_HARD_CRASHES = 0 + ADMIT_TRUSTS_SNAPSHOT = false, + MAX_HARD_CRASHES = 0, + MAX_VM_RESPAWNS = 0 ).* } @@ -200,7 +216,9 @@ module placement_lossy { CAPACITY = 1, CALLS_CAN_BE_LOST = true, RETRY_AFTER_LOSS = false, - MAX_HARD_CRASHES = 0 + ADMIT_TRUSTS_SNAPSHOT = false, + MAX_HARD_CRASHES = 0, + MAX_VM_RESPAWNS = 0 ).* } @@ -211,7 +229,22 @@ module placement_retrying { CAPACITY = 1, CALLS_CAN_BE_LOST = true, RETRY_AFTER_LOSS = true, - MAX_HARD_CRASHES = 0 + ADMIT_TRUSTS_SNAPSHOT = false, + MAX_HARD_CRASHES = 0, + MAX_VM_RESPAWNS = 0 + ).* +} + +module placement_trusting { + import placement( + NODES = Set("a", "b"), + REQS = Set(1, 2), + CAPACITY = 1, + CALLS_CAN_BE_LOST = false, + RETRY_AFTER_LOSS = false, + ADMIT_TRUSTS_SNAPSHOT = true, + MAX_HARD_CRASHES = 0, + MAX_VM_RESPAWNS = 0 ).* } @@ -222,6 +255,21 @@ module placement_hard_crash { CAPACITY = 1, CALLS_CAN_BE_LOST = false, RETRY_AFTER_LOSS = false, - MAX_HARD_CRASHES = 1 + ADMIT_TRUSTS_SNAPSHOT = false, + MAX_HARD_CRASHES = 1, + MAX_VM_RESPAWNS = 0 + ).* +} + +module placement_vm_respawn { + import placement( + NODES = Set("a", "b"), + REQS = Set(1, 2, 3), + CAPACITY = 1, + CALLS_CAN_BE_LOST = false, + RETRY_AFTER_LOSS = false, + ADMIT_TRUSTS_SNAPSHOT = false, + MAX_HARD_CRASHES = 0, + MAX_VM_RESPAWNS = 1 ).* } From f8cf1dd4236798cf6fbc41800751ec237a126ab8 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Fri, 27 Nov 2026 22:02:28 -0800 Subject: [PATCH 06/13] test(spec): model the image store --- spec/check.sh | 7 + spec/image_store.qnt | 428 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 435 insertions(+) create mode 100644 spec/image_store.qnt diff --git a/spec/check.sh b/spec/check.sh index c5d2659a..0057bf21 100755 --- a/spec/check.sh +++ b/spec/check.sh @@ -64,3 +64,10 @@ violates placement.qnt placement_hard_crash admittedWithinCapacity violates placement.qnt placement_vm_respawn admittedWithinCapacity violates placement.qnt placement_retrying placedAtMostOnce violates placement.qnt placement_trusting reservationsWithinCapacity + +holds image_store.qnt image_store_leased +holds image_store.qnt image_store_fork_vs_delete + +violates image_store.qnt image_store_as_built mountedChainsPresent +violates image_store.qnt image_store_unfenced mountedChainsPresent +violates image_store.qnt image_store_shared_delta layersHaveFiles diff --git a/spec/image_store.qnt b/spec/image_store.qnt new file mode 100644 index 00000000..30a48f0f --- /dev/null +++ b/spec/image_store.qnt @@ -0,0 +1,428 @@ +module image_store { + type Blob = str + type Img = str + type Vm = str + + type Layer = { image: Img, blob: Blob } + type Lease = { image: Img, expires: int } + + type Creator = + | NotStarted + | Published({ created: bool }) + | Backed({ created: bool }) + | Recorded + | Rejected + + type Deleter = + | Queued + | Dropping({ todo: Set[Blob], holding: Set[Blob], unlinked: bool }) + | InUse + | Unknown + | Deleted + + type Boot = + | Off + | Leased + | Resolved(Set[Blob]) + | Mounted(Set[Blob]) + | Stopped + | Failed + + type World = { + files: Set[Blob], + blobRows: Set[Blob], + images: Set[Img], + layers: Set[Layer], + leases: Vm -> Lease, + shared: Blob -> Set[Img], + exclusive: Blob -> Set[str], + creators: Img -> Creator, + deleters: Img -> Deleter, + boots: Vm -> Boot, + probedMissing: Set[Blob], + now: int, + } + + const BLOBS: Set[Blob] + const CHAIN: Img -> Set[Blob] + const PUBLISHES: Img -> Blob + const PRELOADED: Set[Img] + const CREATIONS: Set[Img] + const DELETIONS: Set[Img] + const BOOTS: Vm -> Img + const LEASES_WIRED: bool + const HEARTBEATS_TIMELY: bool + const GC_RUNS: bool + const LEASE_TTL: int + const MAX_TIME: int + + var world: World + + pure val GC = "gc" + + pure def without(m: a -> b, k: a): a -> b = + m.keys().exclude(Set(k)).mapBy(x => m.get(x)) + + pure def parents(i: Img): Set[Blob] = CHAIN.get(i).exclude(Set(PUBLISHES.get(i))) + + pure def chainOf(w: World, i: Img): Set[Blob] = + w.layers.filter(l => l.image == i).map(l => l.blob) + + pure def referenced(w: World, b: Blob): bool = w.layers.exists(l => l.blob == b) + + pure def unlocked(w: World, b: Blob): bool = + w.shared.get(b) == Set() and w.exclusive.get(b) == Set() + + pure def leased(w: World, i: Img): bool = + w.leases.keys().exists(v => w.leases.get(v).image == i and w.leases.get(v).expires > w.now) + + pure def unlock(w: World, holder: Img, blobs: Set[Blob]): World = + { ...w, shared: blobs.fold(w.shared, (m, b) => m.setBy(b, hs => hs.exclude(Set(holder)))) } + + pure def publish(w: World, i: Img): World = { + ...w, + files: w.files.union(Set(PUBLISHES.get(i))), + creators: w.creators.set(i, Published({ created: not(w.files.contains(PUBLISHES.get(i))) })), + } + + pure def back(w: World, i: Img, created: bool): World = + if (w.files.contains(PUBLISHES.get(i))) { + ...w, + shared: w.shared.setBy(PUBLISHES.get(i), hs => hs.union(Set(i))), + creators: w.creators.set(i, Backed({ created: created })), + } else { + ...w, + creators: w.creators.set(i, Rejected), + } + + pure def record(w: World, i: Img, created: bool): World = + if (parents(i).subseteq(w.blobRows)) { + ...w.unlock(i, Set(PUBLISHES.get(i))), + blobRows: w.blobRows.union(Set(PUBLISHES.get(i))), + images: w.images.union(Set(i)), + layers: w.layers.union(CHAIN.get(i).map(b => { image: i, blob: b })), + creators: w.creators.set(i, Recorded), + } else { + ...w.unlock(i, Set(PUBLISHES.get(i))), + files: if (created) w.files.exclude(Set(PUBLISHES.get(i))) else w.files, + creators: w.creators.set(i, Rejected), + } + + pure def forget(w: World, i: Img): World = + if (not(w.images.contains(i))) { + ...w, + deleters: w.deleters.set(i, Unknown), + } else if (leased(w, i)) { + ...w, + deleters: w.deleters.set(i, InUse), + } else { + ...w, + images: w.images.exclude(Set(i)), + layers: w.layers.filter(l => l.image != i), + leases: w.leases.keys().filter(v => w.leases.get(v).image != i).mapBy(v => w.leases.get(v)), + deleters: w.deleters.set(i, Dropping({ todo: chainOf(w, i), holding: Set(), unlinked: false })), + } + + pure def dropLock(w: World, i: Img, todo: Set[Blob], b: Blob): World = + if (w.blobRows.contains(b)) { + ...w, + exclusive: w.exclusive.set(b, Set(i)), + deleters: w.deleters.set(i, Dropping({ todo: todo, holding: Set(b), unlinked: false })), + } else { + ...w, + deleters: w.deleters.set(i, Dropping({ todo: todo.exclude(Set(b)), holding: Set(), unlinked: false })), + } + + pure def dropUnlink(w: World, i: Img, todo: Set[Blob], b: Blob): World = + if (referenced(w, b)) { + ...w, + exclusive: w.exclusive.set(b, Set()), + deleters: w.deleters.set(i, Dropping({ todo: todo.exclude(Set(b)), holding: Set(), unlinked: false })), + } else { + ...w, + files: w.files.exclude(Set(b)), + deleters: w.deleters.set(i, Dropping({ todo: todo, holding: Set(b), unlinked: true })), + } + + pure def dropCommit(w: World, i: Img, todo: Set[Blob], b: Blob): World = { + ...w, + blobRows: w.blobRows.exclude(Set(b)), + exclusive: w.exclusive.set(b, Set()), + deleters: w.deleters.set(i, Dropping({ todo: todo.exclude(Set(b)), holding: Set(), unlinked: false })), + } + + pure def lease(w: World, v: Vm): World = + if (w.images.contains(BOOTS.get(v))) { + ...w, + leases: w.leases.put(v, { image: BOOTS.get(v), expires: w.now + LEASE_TTL }), + boots: w.boots.set(v, Leased), + } else { + ...w, + boots: w.boots.set(v, Failed), + } + + pure def abortBoot(w: World, v: Vm): World = { + ...w, + leases: if (w.leases.keys().contains(v)) w.leases.without(v) else w.leases, + boots: w.boots.set(v, Failed), + } + + pure def resolve(w: World, v: Vm): World = + if (chainOf(w, BOOTS.get(v)) == Set()) abortBoot(w, v) + else { ...w, boots: w.boots.set(v, Resolved(chainOf(w, BOOTS.get(v)))) } + + pure def mount(w: World, v: Vm, chain: Set[Blob]): World = + if (chain.subseteq(w.files)) { ...w, boots: w.boots.set(v, Mounted(chain)) } + else abortBoot(w, v) + + pure def stop(w: World, v: Vm): World = { + ...w, + leases: if (w.leases.keys().contains(v)) w.leases.without(v) else w.leases, + boots: w.boots.set(v, Stopped), + } + + pure def holdsImage(b: Boot): bool = match b { + | Leased => true + | Resolved(_) => true + | Mounted(_) => true + | _ => false + } + + pure def heartbeat(w: World, v: Vm): World = + if (w.images.contains(BOOTS.get(v))) { + ...w, + leases: w.leases.put(v, { image: BOOTS.get(v), expires: w.now + LEASE_TTL }), + } else w + + pure def prune(w: World, b: Blob): World = { + ...w, + blobRows: if (referenced(w, b) or w.files.contains(b)) w.blobRows else w.blobRows.exclude(Set(b)), + probedMissing: w.probedMissing.exclude(Set(b)), + } + + pure def tickAllowed(w: World): bool = + w.now < MAX_TIME and ( + not(HEARTBEATS_TIMELY) or + w.leases.keys().forall(v => not(holdsImage(w.boots.get(v))) or w.leases.get(v).expires > w.now + 1) + ) + + action init = world' = { + files: PRELOADED.map(i => CHAIN.get(i)).flatten(), + blobRows: PRELOADED.map(i => CHAIN.get(i)).flatten(), + images: PRELOADED, + layers: PRELOADED.map(i => CHAIN.get(i).map(b => { image: i, blob: b })).flatten(), + leases: Map(), + shared: BLOBS.mapBy(_ => Set()), + exclusive: BLOBS.mapBy(_ => Set()), + creators: CREATIONS.mapBy(_ => NotStarted), + deleters: DELETIONS.mapBy(_ => Queued), + boots: BOOTS.keys().mapBy(_ => Off), + probedMissing: Set(), + now: 0, + } + + action create = { + nondet i = CREATIONS.oneOf() + match world.creators.get(i) { + | NotStarted => all { parents(i).subseteq(world.blobRows), world' = publish(world, i) } + | Published(p) => all { + world.exclusive.get(PUBLISHES.get(i)) == Set(), + world' = back(world, i, p.created), + } + | Backed(p) => all { + parents(i).forall(b => world.exclusive.get(b) == Set()), + world' = record(world, i, p.created), + } + | Recorded => all { false, world' = world } + | Rejected => all { false, world' = world } + } + } + + action delete = { + nondet i = DELETIONS.oneOf() + nondet b = BLOBS.oneOf() + match world.deleters.get(i) { + | Queued => world' = forget(world, i) + | Dropping(d) => + if (d.holding == Set()) all { + d.todo.contains(b), + unlocked(world, b), + world' = dropLock(world, i, d.todo, b), + } else if (not(d.unlinked)) all { + d.holding.contains(b), + world' = dropUnlink(world, i, d.todo, b), + } else all { + d.holding.contains(b), + world' = dropCommit(world, i, d.todo, b), + } + | InUse => all { false, world' = world } + | Unknown => all { false, world' = world } + | Deleted => all { false, world' = world } + } + } + + action boot = { + nondet v = BOOTS.keys().oneOf() + any { + match world.boots.get(v) { + | Off => world' = if (LEASES_WIRED) lease(world, v) else resolve(world, v) + | Leased => world' = resolve(world, v) + | Resolved(chain) => world' = mount(world, v, chain) + | Mounted(_) => world' = stop(world, v) + | Stopped => all { false, world' = world } + | Failed => all { false, world' = world } + }, + all { + LEASES_WIRED, + holdsImage(world.boots.get(v)), + world' = heartbeat(world, v), + }, + } + } + + action collect = { + nondet b = BLOBS.oneOf() + all { + GC_RUNS, + any { + all { + world.blobRows.contains(b), + not(world.files.contains(b)), + world' = { ...world, probedMissing: world.probedMissing.union(Set(b)) }, + }, + all { + world.probedMissing.contains(b), + unlocked(world, b), + world' = prune(world, b), + }, + }, + } + } + + action tick = all { + tickAllowed(world), + world' = { ...world, now: world.now + 1 }, + } + + action step = any { create, delete, boot, collect, tick } + + invariant layersHaveRows = world.layers.forall(l => world.blobRows.contains(l.blob)) + + invariant layersHaveFiles = world.layers.forall(l => world.files.contains(l.blob)) + + invariant mountedChainsPresent = + BOOTS.keys().forall(v => match world.boots.get(v) { + | Mounted(chain) => chain.subseteq(world.files) + | _ => true + }) + + invariant writersExcludeReaders = + BLOBS.forall(b => + world.exclusive.get(b).size() <= 1 and + (world.exclusive.get(b) == Set() or world.shared.get(b) == Set())) + + observation everyDeletionSettles = + DELETIONS.forall(i => match world.deleters.get(i) { + | Queued => false + | Dropping(d) => d.todo == Set() + | _ => true + }) + + observation everyBootMounts = + BOOTS.keys().forall(v => match world.boots.get(v) { + | Mounted(_) => true + | _ => false + }) + + observation everyCreationRecords = CREATIONS.forall(i => world.creators.get(i) == Recorded) +} + +module image_store_as_built { + import image_store( + BLOBS = Set("base"), + CHAIN = Map("img" -> Set("base")), + PUBLISHES = Map("img" -> "base"), + PRELOADED = Set("img"), + CREATIONS = Set(), + DELETIONS = Set("img"), + BOOTS = Map("vm" -> "img"), + LEASES_WIRED = false, + HEARTBEATS_TIMELY = true, + GC_RUNS = false, + LEASE_TTL = 2, + MAX_TIME = 3 + ).* +} + +module image_store_leased { + import image_store( + BLOBS = Set("base"), + CHAIN = Map("img" -> Set("base")), + PUBLISHES = Map("img" -> "base"), + PRELOADED = Set("img"), + CREATIONS = Set(), + DELETIONS = Set("img"), + BOOTS = Map("vm" -> "img"), + LEASES_WIRED = true, + HEARTBEATS_TIMELY = true, + GC_RUNS = false, + LEASE_TTL = 2, + MAX_TIME = 3 + ).* +} + +module image_store_unfenced { + import image_store( + BLOBS = Set("base"), + CHAIN = Map("img" -> Set("base")), + PUBLISHES = Map("img" -> "base"), + PRELOADED = Set("img"), + CREATIONS = Set(), + DELETIONS = Set("img"), + BOOTS = Map("vm" -> "img"), + LEASES_WIRED = true, + HEARTBEATS_TIMELY = false, + GC_RUNS = false, + LEASE_TTL = 2, + MAX_TIME = 3 + ).* +} + +module image_store_fork_vs_delete { + import image_store( + BLOBS = Set("base", "delta"), + CHAIN = Map("img" -> Set("base"), "fork" -> Set("base", "delta")), + PUBLISHES = Map("img" -> "base", "fork" -> "delta"), + PRELOADED = Set("img"), + CREATIONS = Set("fork"), + DELETIONS = Set("img", "fork"), + BOOTS = Map("vm" -> "fork"), + LEASES_WIRED = true, + HEARTBEATS_TIMELY = true, + GC_RUNS = true, + LEASE_TTL = 2, + MAX_TIME = 2 + ).* +} + +module image_store_shared_delta { + import image_store( + BLOBS = Set("base1", "base2", "delta"), + CHAIN = Map( + "img1" -> Set("base1"), + "img2" -> Set("base2"), + "fork1" -> Set("base1", "delta"), + "fork2" -> Set("base2", "delta") + ), + PUBLISHES = Map("img1" -> "base1", "img2" -> "base2", "fork1" -> "delta", "fork2" -> "delta"), + PRELOADED = Set("img1", "img2"), + CREATIONS = Set("fork1", "fork2"), + DELETIONS = Set("img1"), + BOOTS = Map(), + LEASES_WIRED = true, + HEARTBEATS_TIMELY = true, + GC_RUNS = false, + LEASE_TTL = 2, + MAX_TIME = 0 + ).* +} From 1f5508fe6be257e703827ce9ab830f2339284e17 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Fri, 27 Nov 2026 22:29:00 -0800 Subject: [PATCH 07/13] test(spec): let a blob drop fail after the unlink in the image store A drop_blob transaction that dies after File.rm leaves a row with no file. The model had no such step, so image_store_fork_vs_delete passed on a race the code plans for. - image_store_failed_drop: with DROPS_MAY_FAIL a fork published during its parent's delete links to the file-less base row. - image_store_recreate: an image re-created while it is deleted, with failing drops and the GC running. It is the only holds scenario where the GC prunes and where backed/2 contends with a drop. - A fork starts only while its parent image exists (DERIVED_FROM), and two inserts of one uncommitted blob row no longer overlap. - prune no longer re-checks the file, matching prune_rows. - exclusive accumulates holders, so writersExcludeReaders can fail. --- spec/check.sh | 2 ++ spec/image_store.qnt | 80 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/spec/check.sh b/spec/check.sh index 0057bf21..e9af9c3c 100755 --- a/spec/check.sh +++ b/spec/check.sh @@ -66,8 +66,10 @@ violates placement.qnt placement_retrying placedAtMostOnce violates placement.qnt placement_trusting reservationsWithinCapacity holds image_store.qnt image_store_leased +holds image_store.qnt image_store_recreate holds image_store.qnt image_store_fork_vs_delete violates image_store.qnt image_store_as_built mountedChainsPresent violates image_store.qnt image_store_unfenced mountedChainsPresent +violates image_store.qnt image_store_failed_drop layersHaveFiles violates image_store.qnt image_store_shared_delta layersHaveFiles diff --git a/spec/image_store.qnt b/spec/image_store.qnt index 30a48f0f..083a5c6e 100644 --- a/spec/image_store.qnt +++ b/spec/image_store.qnt @@ -18,7 +18,6 @@ module image_store { | Dropping({ todo: Set[Blob], holding: Set[Blob], unlinked: bool }) | InUse | Unknown - | Deleted type Boot = | Off @@ -35,7 +34,7 @@ module image_store { layers: Set[Layer], leases: Vm -> Lease, shared: Blob -> Set[Img], - exclusive: Blob -> Set[str], + exclusive: Blob -> Set[Img], creators: Img -> Creator, deleters: Img -> Deleter, boots: Vm -> Boot, @@ -46,6 +45,7 @@ module image_store { const BLOBS: Set[Blob] const CHAIN: Img -> Set[Blob] const PUBLISHES: Img -> Blob + const DERIVED_FROM: Img -> Set[Img] const PRELOADED: Set[Img] const CREATIONS: Set[Img] const DELETIONS: Set[Img] @@ -53,13 +53,12 @@ module image_store { const LEASES_WIRED: bool const HEARTBEATS_TIMELY: bool const GC_RUNS: bool + const DROPS_MAY_FAIL: bool const LEASE_TTL: int const MAX_TIME: int var world: World - pure val GC = "gc" - pure def without(m: a -> b, k: a): a -> b = m.keys().exclude(Set(k)).mapBy(x => m.get(x)) @@ -126,7 +125,7 @@ module image_store { pure def dropLock(w: World, i: Img, todo: Set[Blob], b: Blob): World = if (w.blobRows.contains(b)) { ...w, - exclusive: w.exclusive.set(b, Set(i)), + exclusive: w.exclusive.setBy(b, holders => holders.union(Set(i))), deleters: w.deleters.set(i, Dropping({ todo: todo, holding: Set(b), unlinked: false })), } else { ...w, @@ -136,7 +135,7 @@ module image_store { pure def dropUnlink(w: World, i: Img, todo: Set[Blob], b: Blob): World = if (referenced(w, b)) { ...w, - exclusive: w.exclusive.set(b, Set()), + exclusive: w.exclusive.setBy(b, holders => holders.exclude(Set(i))), deleters: w.deleters.set(i, Dropping({ todo: todo.exclude(Set(b)), holding: Set(), unlinked: false })), } else { ...w, @@ -144,13 +143,17 @@ module image_store { deleters: w.deleters.set(i, Dropping({ todo: todo, holding: Set(b), unlinked: true })), } - pure def dropCommit(w: World, i: Img, todo: Set[Blob], b: Blob): World = { + pure def dropAbort(w: World, i: Img, todo: Set[Blob], b: Blob): World = { ...w, - blobRows: w.blobRows.exclude(Set(b)), - exclusive: w.exclusive.set(b, Set()), + exclusive: w.exclusive.setBy(b, holders => holders.exclude(Set(i))), deleters: w.deleters.set(i, Dropping({ todo: todo.exclude(Set(b)), holding: Set(), unlinked: false })), } + pure def dropCommit(w: World, i: Img, todo: Set[Blob], b: Blob): World = { + ...dropAbort(w, i, todo, b), + blobRows: w.blobRows.exclude(Set(b)), + } + pure def lease(w: World, v: Vm): World = if (w.images.contains(BOOTS.get(v))) { ...w, @@ -196,7 +199,7 @@ module image_store { pure def prune(w: World, b: Blob): World = { ...w, - blobRows: if (referenced(w, b) or w.files.contains(b)) w.blobRows else w.blobRows.exclude(Set(b)), + blobRows: if (referenced(w, b)) w.blobRows else w.blobRows.exclude(Set(b)), probedMissing: w.probedMissing.exclude(Set(b)), } @@ -224,9 +227,10 @@ module image_store { action create = { nondet i = CREATIONS.oneOf() match world.creators.get(i) { - | NotStarted => all { parents(i).subseteq(world.blobRows), world' = publish(world, i) } + | NotStarted => all { DERIVED_FROM.get(i).subseteq(world.images), world' = publish(world, i) } | Published(p) => all { world.exclusive.get(PUBLISHES.get(i)) == Set(), + world.blobRows.contains(PUBLISHES.get(i)) or world.shared.get(PUBLISHES.get(i)) == Set(), world' = back(world, i, p.created), } | Backed(p) => all { @@ -253,11 +257,13 @@ module image_store { world' = dropUnlink(world, i, d.todo, b), } else all { d.holding.contains(b), - world' = dropCommit(world, i, d.todo, b), + any { + world' = dropCommit(world, i, d.todo, b), + all { DROPS_MAY_FAIL, world' = dropAbort(world, i, d.todo, b) }, + }, } | InUse => all { false, world' = world } | Unknown => all { false, world' = world } - | Deleted => all { false, world' = world } } } @@ -342,6 +348,7 @@ module image_store_as_built { BLOBS = Set("base"), CHAIN = Map("img" -> Set("base")), PUBLISHES = Map("img" -> "base"), + DERIVED_FROM = Map("img" -> Set()), PRELOADED = Set("img"), CREATIONS = Set(), DELETIONS = Set("img"), @@ -349,6 +356,7 @@ module image_store_as_built { LEASES_WIRED = false, HEARTBEATS_TIMELY = true, GC_RUNS = false, + DROPS_MAY_FAIL = false, LEASE_TTL = 2, MAX_TIME = 3 ).* @@ -359,6 +367,7 @@ module image_store_leased { BLOBS = Set("base"), CHAIN = Map("img" -> Set("base")), PUBLISHES = Map("img" -> "base"), + DERIVED_FROM = Map("img" -> Set()), PRELOADED = Set("img"), CREATIONS = Set(), DELETIONS = Set("img"), @@ -366,6 +375,7 @@ module image_store_leased { LEASES_WIRED = true, HEARTBEATS_TIMELY = true, GC_RUNS = false, + DROPS_MAY_FAIL = false, LEASE_TTL = 2, MAX_TIME = 3 ).* @@ -376,6 +386,7 @@ module image_store_unfenced { BLOBS = Set("base"), CHAIN = Map("img" -> Set("base")), PUBLISHES = Map("img" -> "base"), + DERIVED_FROM = Map("img" -> Set()), PRELOADED = Set("img"), CREATIONS = Set(), DELETIONS = Set("img"), @@ -383,16 +394,56 @@ module image_store_unfenced { LEASES_WIRED = true, HEARTBEATS_TIMELY = false, GC_RUNS = false, + DROPS_MAY_FAIL = false, LEASE_TTL = 2, MAX_TIME = 3 ).* } +module image_store_recreate { + import image_store( + BLOBS = Set("base"), + CHAIN = Map("img" -> Set("base")), + PUBLISHES = Map("img" -> "base"), + DERIVED_FROM = Map("img" -> Set()), + PRELOADED = Set("img"), + CREATIONS = Set("img"), + DELETIONS = Set("img"), + BOOTS = Map("vm" -> "img"), + LEASES_WIRED = true, + HEARTBEATS_TIMELY = true, + GC_RUNS = true, + DROPS_MAY_FAIL = true, + LEASE_TTL = 2, + MAX_TIME = 2 + ).* +} + module image_store_fork_vs_delete { import image_store( BLOBS = Set("base", "delta"), CHAIN = Map("img" -> Set("base"), "fork" -> Set("base", "delta")), PUBLISHES = Map("img" -> "base", "fork" -> "delta"), + DERIVED_FROM = Map("img" -> Set(), "fork" -> Set("img")), + PRELOADED = Set("img"), + CREATIONS = Set("fork"), + DELETIONS = Set("img", "fork"), + BOOTS = Map("vm" -> "fork"), + LEASES_WIRED = true, + HEARTBEATS_TIMELY = true, + GC_RUNS = true, + DROPS_MAY_FAIL = false, + LEASE_TTL = 2, + MAX_TIME = 2 + ).* +} + +module image_store_failed_drop { + import image_store( + BLOBS = Set("base", "delta"), + CHAIN = Map("img" -> Set("base"), "fork" -> Set("base", "delta")), + PUBLISHES = Map("img" -> "base", "fork" -> "delta"), + DERIVED_FROM = Map("img" -> Set(), "fork" -> Set("img")), PRELOADED = Set("img"), CREATIONS = Set("fork"), DELETIONS = Set("img", "fork"), @@ -400,6 +451,7 @@ module image_store_fork_vs_delete { LEASES_WIRED = true, HEARTBEATS_TIMELY = true, GC_RUNS = true, + DROPS_MAY_FAIL = true, LEASE_TTL = 2, MAX_TIME = 2 ).* @@ -415,6 +467,7 @@ module image_store_shared_delta { "fork2" -> Set("base2", "delta") ), PUBLISHES = Map("img1" -> "base1", "img2" -> "base2", "fork1" -> "delta", "fork2" -> "delta"), + DERIVED_FROM = Map("img1" -> Set(), "img2" -> Set(), "fork1" -> Set("img1"), "fork2" -> Set("img2")), PRELOADED = Set("img1", "img2"), CREATIONS = Set("fork1", "fork2"), DELETIONS = Set("img1"), @@ -422,6 +475,7 @@ module image_store_shared_delta { LEASES_WIRED = true, HEARTBEATS_TIMELY = true, GC_RUNS = false, + DROPS_MAY_FAIL = false, LEASE_TTL = 2, MAX_TIME = 0 ).* From ae05c1b2a43468cbd20dd8b2d5c1807933b7bb8a Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Sun, 29 Nov 2026 11:29:09 -0800 Subject: [PATCH 08/13] test(node): replay id pool model traces against Users and Net --- spec/traces.sh | 18 ++++ test/hyper/node/id_pool_model_test.exs | 143 +++++++++++++++++++++++++ test/test_helper.exs | 2 +- 3 files changed, 162 insertions(+), 1 deletion(-) create mode 100755 spec/traces.sh create mode 100644 test/hyper/node/id_pool_model_test.exs diff --git a/spec/traces.sh b/spec/traces.sh new file mode 100755 index 00000000..afe4311a --- /dev/null +++ b/spec/traces.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +out=${1:?usage: traces.sh } +mkdir -p "$out" +out=$(cd "$out" && pwd) + +cd "$(dirname "$0")" + +node_modules/.bin/quint run id_pool.qnt \ + --main id_pool_small \ + --step stepTransientRestart \ + --no-invariant \ + --mbt \ + --n-traces 200 \ + --max-samples 200 \ + --max-steps 30 \ + --out-itf "$out/id_pool_{seq}.itf.json" diff --git a/test/hyper/node/id_pool_model_test.exs b/test/hyper/node/id_pool_model_test.exs new file mode 100644 index 00000000..63862e8c --- /dev/null +++ b/test/hyper/node/id_pool_model_test.exs @@ -0,0 +1,143 @@ +defmodule Hyper.Node.IdPoolModelTest do + use ExUnit.Case, async: true + + alias Hyper.Node.{Net, Users} + + @moduletag :model + + @min 50_000 + @model_max_id 1 + @world "id_pool_small::id_pool::world" + @pools [users: {Users, {:new}, :free}, net: {Net, :claim, :release}] + + for {name, {mod, claim_msg, release_tag}} <- @pools do + test "#{name}: every model trace replays against the real pool" do + wire = {unquote(mod), unquote(Macro.escape(claim_msg)), unquote(release_tag)} + + for path <- traces() do + [first | rest] = path |> File.read!() |> Jason.decode!() |> Map.fetch!("states") + + start = %{ + pool: new_pool(unquote(mod)), + refs: %{}, + pids: %{}, + model: decode(first[@world]) + } + + finish = + rest + |> Enum.with_index(1) + |> Enum.reduce(start, fn {state, index}, sim -> + action = state["mbt::actionTaken"] + model = decode(state[@world]) + sim = replay(action, decode(state["mbt::nondetPicks"]), sim, model, wire) + + assert abstract(sim.pool) == expected(model), + "#{path}: diverged from the model at step #{index} (#{action})" + + %{sim | model: model} + end) + + Enum.each(Map.values(finish.pids), &Process.exit(&1, :kill)) + end + end + end + + defp replay("claimId", %{"a" => {"Some", a}}, sim, model, {mod, claim_msg, _release_tag}) do + {:reply, reply, pool} = mod.handle_call(claim_msg, {self(), make_ref()}, sim.pool) + + case model["phase"][a] do + {"Claimed", id} -> assert reply == {:ok, @min + id} + {"Finished", {}} -> assert reply == {:error, :exhausted} + end + + %{sim | pool: pool} + end + + defp replay("releaseId", _picks, sim, _model, _wire), do: sim + + defp replay("spawnVm", %{"a" => {"Some", a}}, sim, model, _wire) do + {"Started", %{"pid" => model_pid}} = model["phase"][a] + %{sim | pids: Map.put(sim.pids, model_pid, parked())} + end + + defp replay("bindOwner", %{"a" => {"Some", a}}, sim, model, {mod, _claim_msg, _release_tag}) do + {"Started", %{"id" => id, "pid" => model_pid}} = sim.model["phase"][a] + request = {:bind, @min + id, Map.fetch!(sim.pids, model_pid)} + {:reply, :ok, pool} = mod.handle_call(request, {self(), make_ref()}, sim.pool) + + [real_ref] = Map.keys(pool.owners) -- Map.keys(sim.pool.owners) + [model_ref] = Map.keys(model["pool"]["owners"]) -- Map.keys(sim.model["pool"]["owners"]) + + %{sim | pool: pool, refs: Map.put(sim.refs, model_ref, real_ref)} + end + + defp replay("vmExits", %{"pid" => {"Some", model_pid}}, sim, _model, _wire) do + Process.exit(Map.fetch!(sim.pids, model_pid), :kill) + sim + end + + defp replay("vmRespawns", %{"pid" => {"Some", model_pid}}, sim, model, _wire) do + Process.exit(Map.fetch!(sim.pids, model_pid), :kill) + [respawned] = MapSet.to_list(MapSet.difference(model["alive"], sim.model["alive"])) + %{sim | pids: Map.put(sim.pids, respawned, parked())} + end + + defp replay("deliverMessage", _picks, sim, _model, {mod, _claim_msg, release_tag}) do + {:noreply, pool} = + case hd(sim.model["pool"]["mailbox"]) do + {"Free", id} -> + mod.handle_cast({release_tag, @min + id}, sim.pool) + + {"Down", model_ref} -> + real_ref = Map.fetch!(sim.refs, model_ref) + down = assert_receive {:DOWN, ^real_ref, :process, _owner, _reason} + mod.handle_info(down, sim.pool) + end + + %{sim | pool: pool} + end + + defp parked, do: spawn(fn -> Process.sleep(:infinity) end) + + defp abstract(pool) do + %{ + bump: pool.next - @min, + freed: pool.freed |> :queue.to_list() |> Enum.map(&(&1 - @min)), + owned: pool.owners |> Map.values() |> Enum.map(&(&1 - @min)) |> Enum.sort() + } + end + + defp expected(model) do + %{ + bump: model["pool"]["bump"], + freed: model["pool"]["freed"], + owned: model["pool"]["owners"] |> Map.values() |> Enum.sort() + } + end + + defp new_pool(Users), do: %Users.State{max: @min + @model_max_id, next: @min} + + defp new_pool(Net), + do: %Net.State{host: :unused_by_the_id_pool, max: @min + @model_max_id, next: @min} + + defp traces do + dir = + System.get_env("HYPER_MODEL_TRACES") || + flunk("HYPER_MODEL_TRACES is unset: run spec/traces.sh and point it there") + + case Path.wildcard(Path.join(dir, "id_pool_*.itf.json")) do + [] -> flunk("no id_pool traces in #{dir}: run spec/traces.sh #{dir}") + paths -> paths + end + end + + defp decode(%{"#bigint" => digits}), do: String.to_integer(digits) + defp decode(%{"#map" => pairs}), do: Map.new(pairs, fn [k, v] -> {decode(k), decode(v)} end) + defp decode(%{"#set" => items}), do: MapSet.new(items, &decode/1) + defp decode(%{"#tup" => items}), do: items |> Enum.map(&decode/1) |> List.to_tuple() + defp decode(%{"tag" => tag, "value" => value}), do: {tag, decode(value)} + defp decode(%{} = record), do: Map.new(record, fn {k, v} -> {k, decode(v)} end) + defp decode(items) when is_list(items), do: Enum.map(items, &decode/1) + defp decode(scalar), do: scalar +end diff --git a/test/test_helper.exs b/test/test_helper.exs index a1fba4da..a9d84460 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -6,5 +6,5 @@ # image DB + media store. They are opt-in: run with `mix test --include external`. ExUnit.start( formatters: [ExUnit.CLIFormatter, JUnitFormatter], - exclude: [:external, :integration] + exclude: [:external, :integration, :model] ) From 73b9ccac67c9cb7195255e24ea630fa49b123aef Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Sun, 29 Nov 2026 12:05:09 -0800 Subject: [PATCH 09/13] test(node): locate replay failures and replay a larger id pool - A failing step now names its trace, step and action and keeps ExUnit's left/right diff; before, three of four failure modes named nothing. - traces.sh takes QUINT_SEED, picks one otherwise, and prints it, so a failing batch can be regenerated. It clears old traces first. - Traces come from id_pool_replay (4 ids, 8 attempts, 2 restarts): the 2-id instance revisited the same 34 transitions. - A VM that exits now exits normally and only a respawn is a kill, so DOWN reasons normal, killed and noproc are all replayed. --- spec/id_pool.qnt | 4 ++ spec/traces.sh | 10 ++- test/hyper/node/id_pool_model_test.exs | 95 ++++++++++++++------------ 3 files changed, 65 insertions(+), 44 deletions(-) diff --git a/spec/id_pool.qnt b/spec/id_pool.qnt index 7545aaa2..15df2e40 100644 --- a/spec/id_pool.qnt +++ b/spec/id_pool.qnt @@ -240,3 +240,7 @@ module id_pool { module id_pool_small { import id_pool(MAX_ID = 1, ATTEMPTS = Set(0, 1, 2), MAX_RESTARTS = 1).* } + +module id_pool_replay { + import id_pool(MAX_ID = 3, ATTEMPTS = 0.to(7), MAX_RESTARTS = 2).* +} diff --git a/spec/traces.sh b/spec/traces.sh index afe4311a..723dd98e 100755 --- a/spec/traces.sh +++ b/spec/traces.sh @@ -2,17 +2,23 @@ set -euo pipefail out=${1:?usage: traces.sh } +seed=${QUINT_SEED:-$RANDOM$RANDOM} mkdir -p "$out" out=$(cd "$out" && pwd) cd "$(dirname "$0")" +rm -f "$out"/id_pool_*.itf.json + node_modules/.bin/quint run id_pool.qnt \ - --main id_pool_small \ + --main id_pool_replay \ --step stepTransientRestart \ --no-invariant \ --mbt \ --n-traces 200 \ --max-samples 200 \ - --max-steps 30 \ + --max-steps 80 \ + --seed "$seed" \ --out-itf "$out/id_pool_{seq}.itf.json" + +echo "id_pool traces: QUINT_SEED=$seed" diff --git a/test/hyper/node/id_pool_model_test.exs b/test/hyper/node/id_pool_model_test.exs index 63862e8c..20a1874b 100644 --- a/test/hyper/node/id_pool_model_test.exs +++ b/test/hyper/node/id_pool_model_test.exs @@ -6,8 +6,9 @@ defmodule Hyper.Node.IdPoolModelTest do @moduletag :model @min 50_000 - @model_max_id 1 - @world "id_pool_small::id_pool::world" + @model_max_id 3 + @world "id_pool_replay::id_pool::world" + @down_timeout_ms 5_000 @pools [users: {Users, {:new}, :free}, net: {Net, :claim, :release}] for {name, {mod, claim_msg, release_tag}} <- @pools do @@ -16,26 +17,17 @@ defmodule Hyper.Node.IdPoolModelTest do for path <- traces() do [first | rest] = path |> File.read!() |> Jason.decode!() |> Map.fetch!("states") - - start = %{ - pool: new_pool(unquote(mod)), - refs: %{}, - pids: %{}, - model: decode(first[@world]) - } + start = %{pool: new_pool(unquote(mod)), refs: %{}, pids: %{}, pre: world(first)} finish = rest |> Enum.with_index(1) |> Enum.reduce(start, fn {state, index}, sim -> action = state["mbt::actionTaken"] - model = decode(state[@world]) - sim = replay(action, decode(state["mbt::nondetPicks"]), sim, model, wire) - - assert abstract(sim.pool) == expected(model), - "#{path}: diverged from the model at step #{index} (#{action})" - %{sim | model: model} + located("#{path}: step #{index} (#{action})", fn -> + advance(sim, action, state, wire) + end) end) Enum.each(Map.values(finish.pids), &Process.exit(&1, :kill)) @@ -43,10 +35,27 @@ defmodule Hyper.Node.IdPoolModelTest do end end - defp replay("claimId", %{"a" => {"Some", a}}, sim, model, {mod, claim_msg, _release_tag}) do - {:reply, reply, pool} = mod.handle_call(claim_msg, {self(), make_ref()}, sim.pool) + defp advance(sim, action, state, wire) do + post = world(state) + sim = replay(action, decode(state["mbt::nondetPicks"]), sim, post, wire) + assert abstract(sim.pool) == expected(post) + %{sim | pre: post} + end + + defp located(place, fun) do + fun.() + rescue + error in ExUnit.AssertionError -> + reraise %{error | message: "#{place}: #{error.message}"}, __STACKTRACE__ + + error -> + reraise "#{place}: #{Exception.message(error)}", __STACKTRACE__ + end + + defp replay("claimId", %{"a" => {"Some", a}}, sim, post, {mod, claim_msg, _release_tag}) do + assert {:reply, reply, pool} = mod.handle_call(claim_msg, {self(), make_ref()}, sim.pool) - case model["phase"][a] do + case post["phase"][a] do {"Claimed", id} -> assert reply == {:ok, @min + id} {"Finished", {}} -> assert reply == {:error, :exhausted} end @@ -54,51 +63,53 @@ defmodule Hyper.Node.IdPoolModelTest do %{sim | pool: pool} end - defp replay("releaseId", _picks, sim, _model, _wire), do: sim + defp replay("releaseId", _picks, sim, _post, _wire), do: sim - defp replay("spawnVm", %{"a" => {"Some", a}}, sim, model, _wire) do - {"Started", %{"pid" => model_pid}} = model["phase"][a] + defp replay("spawnVm", %{"a" => {"Some", a}}, sim, post, _wire) do + assert {"Started", %{"pid" => model_pid}} = post["phase"][a] %{sim | pids: Map.put(sim.pids, model_pid, parked())} end - defp replay("bindOwner", %{"a" => {"Some", a}}, sim, model, {mod, _claim_msg, _release_tag}) do - {"Started", %{"id" => id, "pid" => model_pid}} = sim.model["phase"][a] + defp replay("bindOwner", %{"a" => {"Some", a}}, sim, post, {mod, _claim_msg, _release_tag}) do + assert {"Started", %{"id" => id, "pid" => model_pid}} = sim.pre["phase"][a] request = {:bind, @min + id, Map.fetch!(sim.pids, model_pid)} - {:reply, :ok, pool} = mod.handle_call(request, {self(), make_ref()}, sim.pool) + assert {:reply, :ok, pool} = mod.handle_call(request, {self(), make_ref()}, sim.pool) - [real_ref] = Map.keys(pool.owners) -- Map.keys(sim.pool.owners) - [model_ref] = Map.keys(model["pool"]["owners"]) -- Map.keys(sim.model["pool"]["owners"]) + assert [real_ref] = Map.keys(pool.owners) -- Map.keys(sim.pool.owners) + assert [model_ref] = Map.keys(post["pool"]["owners"]) -- Map.keys(sim.pre["pool"]["owners"]) %{sim | pool: pool, refs: Map.put(sim.refs, model_ref, real_ref)} end - defp replay("vmExits", %{"pid" => {"Some", model_pid}}, sim, _model, _wire) do - Process.exit(Map.fetch!(sim.pids, model_pid), :kill) + defp replay("vmExits", %{"pid" => {"Some", model_pid}}, sim, _post, _wire) do + send(Map.fetch!(sim.pids, model_pid), :stop) sim end - defp replay("vmRespawns", %{"pid" => {"Some", model_pid}}, sim, model, _wire) do + defp replay("vmRespawns", %{"pid" => {"Some", model_pid}}, sim, post, _wire) do Process.exit(Map.fetch!(sim.pids, model_pid), :kill) - [respawned] = MapSet.to_list(MapSet.difference(model["alive"], sim.model["alive"])) + assert [respawned] = MapSet.to_list(MapSet.difference(post["alive"], sim.pre["alive"])) %{sim | pids: Map.put(sim.pids, respawned, parked())} end - defp replay("deliverMessage", _picks, sim, _model, {mod, _claim_msg, release_tag}) do - {:noreply, pool} = - case hd(sim.model["pool"]["mailbox"]) do - {"Free", id} -> - mod.handle_cast({release_tag, @min + id}, sim.pool) + defp replay("deliverMessage", _picks, sim, _post, {mod, _claim_msg, release_tag}) do + message = hd(sim.pre["pool"]["mailbox"]) + assert {:noreply, pool} = deliver(message, sim, mod, release_tag) + %{sim | pool: pool} + end - {"Down", model_ref} -> - real_ref = Map.fetch!(sim.refs, model_ref) - down = assert_receive {:DOWN, ^real_ref, :process, _owner, _reason} - mod.handle_info(down, sim.pool) - end + defp deliver({"Free", id}, sim, mod, release_tag), + do: mod.handle_cast({release_tag, @min + id}, sim.pool) - %{sim | pool: pool} + defp deliver({"Down", model_ref}, sim, mod, _release_tag) do + real_ref = Map.fetch!(sim.refs, model_ref) + down = assert_receive {:DOWN, ^real_ref, :process, _owner, _reason}, @down_timeout_ms + mod.handle_info(down, sim.pool) end - defp parked, do: spawn(fn -> Process.sleep(:infinity) end) + defp parked, do: spawn(fn -> receive(do: (:stop -> :ok)) end) + + defp world(state), do: state |> Map.fetch!(@world) |> decode() defp abstract(pool) do %{ From 66590f7c5acb9cc0d73f2ca74a2da2b5518e3183 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Sun, 29 Nov 2026 12:15:47 -0800 Subject: [PATCH 10/13] test(spec): quiet the id pool trace generator Quint printed about 1,100 lines per run. The seed line is now the only output; errors still reach stderr with a non-zero exit. --- spec/traces.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/traces.sh b/spec/traces.sh index 723dd98e..b7528252 100755 --- a/spec/traces.sh +++ b/spec/traces.sh @@ -19,6 +19,7 @@ node_modules/.bin/quint run id_pool.qnt \ --max-samples 200 \ --max-steps 80 \ --seed "$seed" \ + --verbosity 0 \ --out-itf "$out/id_pool_{seq}.itf.json" echo "id_pool traces: QUINT_SEED=$seed" From 8a38371689657965353d0c20a4665999a5f4e3b5 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Sun, 29 Nov 2026 12:20:39 -0800 Subject: [PATCH 11/13] ci: check the quint specs and replay their traces --- .github/workflows/ci.yml | 45 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30fdc250..e2e438df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,6 +98,23 @@ jobs: - name: Docs (warnings as errors) run: mix docs --warnings-as-errors + - uses: actions/setup-node@v5 + with: + node-version: "22" + cache: npm + cache-dependency-path: spec/package-lock.json + + - name: Cache the Quint evaluator + uses: actions/cache@v6 + with: + path: ~/.quint + key: quint-${{ hashFiles('spec/package-lock.json') }} + + - name: Generate id pool model traces + run: | + npm ci --prefix spec + spec/traces.sh "$RUNNER_TEMP/model-traces" + - name: Create and migrate test DB env: MIX_ENV: test @@ -112,11 +129,12 @@ jobs: - name: Test + coverage (warnings as errors) env: MIX_ENV: test + HYPER_MODEL_TRACES: ${{ runner.temp }}/model-traces # coveralls.json wraps `mix test` (so --no-start / --warnings-as-errors # still apply) and writes cover/excoveralls.json for the Codecov upload. # --no-start: the supervision tree provisions a real Firecracker host # under /srv/hyper, unavailable on a CI runner. - run: mix coveralls.json --no-start --warnings-as-errors + run: mix coveralls.json --no-start --warnings-as-errors --include model # !cancelled() (not always()) uploads results on test PASS or FAIL -- the # point of Test Analytics is failure/flake history -- while still skipping @@ -166,6 +184,31 @@ jobs: - name: ShellCheck run: git ls-files -z '*.sh' | xargs -0 -r shellcheck + spec: + name: Quint specs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-node@v5 + with: + node-version: "22" + cache: npm + cache-dependency-path: spec/package-lock.json + + - name: Cache Apalache, TLC and the Quint evaluator + uses: actions/cache@v6 + with: + path: ~/.quint + key: quint-${{ hashFiles('spec/package-lock.json') }} + + - name: Install Quint + run: npm ci + working-directory: spec + + - name: Check specs + run: spec/check.sh + # One job for the whole native/ workspace: guest-agent, hyperrs-elfsum, # suidhelper and xtask. The guest agent and xtask are otherwise only built by # Mix compilers, where cargo warnings scroll past without failing the build. From c3950f513bb01c2bfb3b108c1f49523705b392ea Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Sun, 29 Nov 2026 12:46:04 -0800 Subject: [PATCH 12/13] ci: make the quint jobs reliable on a cold runner - Generate traces with Quint's TypeScript backend. The Rust evaluator is fetched from api.github.com unauthenticated with no retry, which would rate-limit the Elixir job; now nothing is downloaded there and that job caches nothing of Quint's. - Pin Temurin 21 for the spec job: Apalache 0.62.4 is built for Java 21 and the runner's default JDK has only just moved past 17. - Key the Apalache cache per OS and purpose, cap the spec job at 15 minutes, and upload the traces when the Elixir job fails. --- .github/workflows/ci.yml | 24 ++++++++++++++++-------- spec/traces.sh | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2e438df..629648da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -104,12 +104,6 @@ jobs: cache: npm cache-dependency-path: spec/package-lock.json - - name: Cache the Quint evaluator - uses: actions/cache@v6 - with: - path: ~/.quint - key: quint-${{ hashFiles('spec/package-lock.json') }} - - name: Generate id pool model traces run: | npm ci --prefix spec @@ -161,6 +155,14 @@ jobs: name: elixir-test-results path: _build/test/junit.xml + - name: Upload id pool model traces + if: ${{ failure() }} + uses: actions/upload-artifact@v7 + with: + name: id-pool-model-traces + path: ${{ runner.temp }}/model-traces + if-no-files-found: ignore + - name: Upload coverage to Codecov uses: codecov/codecov-action@v7 with: @@ -187,6 +189,7 @@ jobs: spec: name: Quint specs runs-on: ubuntu-latest + timeout-minutes: 15 steps: - uses: actions/checkout@v7 @@ -196,11 +199,16 @@ jobs: cache: npm cache-dependency-path: spec/package-lock.json - - name: Cache Apalache, TLC and the Quint evaluator + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: "21" + + - name: Cache Apalache and TLC uses: actions/cache@v6 with: path: ~/.quint - key: quint-${{ hashFiles('spec/package-lock.json') }} + key: ${{ runner.os }}-quint-apalache-${{ hashFiles('spec/package-lock.json') }} - name: Install Quint run: npm ci diff --git a/spec/traces.sh b/spec/traces.sh index b7528252..f142e17d 100755 --- a/spec/traces.sh +++ b/spec/traces.sh @@ -20,6 +20,7 @@ node_modules/.bin/quint run id_pool.qnt \ --max-steps 80 \ --seed "$seed" \ --verbosity 0 \ + --backend typescript \ --out-itf "$out/id_pool_{seq}.itf.json" echo "id_pool traces: QUINT_SEED=$seed" From cad2450cc299be53f44e9ade2ce92ef96dbc7088 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Sun, 29 Nov 2026 13:02:00 -0800 Subject: [PATCH 13/13] test(node): fail the replay when a batch skips a model action A trace generator narrowed to fewer actions (no respawns, say) left the replay green while it checked less. The test now requires every action the model has to appear in the batch. traces.sh prints its seed before generating, so a failed generation still logs it. --- spec/traces.sh | 3 +-- test/hyper/node/id_pool_model_test.exs | 34 ++++++++++++++------------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/spec/traces.sh b/spec/traces.sh index f142e17d..3980efa8 100755 --- a/spec/traces.sh +++ b/spec/traces.sh @@ -10,6 +10,7 @@ cd "$(dirname "$0")" rm -f "$out"/id_pool_*.itf.json +echo "id_pool traces: QUINT_SEED=$seed" node_modules/.bin/quint run id_pool.qnt \ --main id_pool_replay \ --step stepTransientRestart \ @@ -22,5 +23,3 @@ node_modules/.bin/quint run id_pool.qnt \ --verbosity 0 \ --backend typescript \ --out-itf "$out/id_pool_{seq}.itf.json" - -echo "id_pool traces: QUINT_SEED=$seed" diff --git a/test/hyper/node/id_pool_model_test.exs b/test/hyper/node/id_pool_model_test.exs index 20a1874b..a646e3ac 100644 --- a/test/hyper/node/id_pool_model_test.exs +++ b/test/hyper/node/id_pool_model_test.exs @@ -10,29 +10,33 @@ defmodule Hyper.Node.IdPoolModelTest do @world "id_pool_replay::id_pool::world" @down_timeout_ms 5_000 @pools [users: {Users, {:new}, :free}, net: {Net, :claim, :release}] + @model_actions ~w(claimId releaseId spawnVm bindOwner vmExits vmRespawns deliverMessage) for {name, {mod, claim_msg, release_tag}} <- @pools do test "#{name}: every model trace replays against the real pool" do wire = {unquote(mod), unquote(Macro.escape(claim_msg)), unquote(release_tag)} + replayed = traces() |> Enum.flat_map(&replay_trace(&1, wire)) |> MapSet.new() + assert replayed == MapSet.new(@model_actions) + end + end - for path <- traces() do - [first | rest] = path |> File.read!() |> Jason.decode!() |> Map.fetch!("states") - start = %{pool: new_pool(unquote(mod)), refs: %{}, pids: %{}, pre: world(first)} + defp replay_trace(path, {mod, _claim_msg, _release_tag} = wire) do + [first | rest] = path |> File.read!() |> Jason.decode!() |> Map.fetch!("states") + start = %{pool: new_pool(mod), refs: %{}, pids: %{}, pre: world(first)} - finish = - rest - |> Enum.with_index(1) - |> Enum.reduce(start, fn {state, index}, sim -> - action = state["mbt::actionTaken"] + finish = + rest + |> Enum.with_index(1) + |> Enum.reduce(start, fn {state, index}, sim -> + action = state["mbt::actionTaken"] - located("#{path}: step #{index} (#{action})", fn -> - advance(sim, action, state, wire) - end) - end) + located("#{path}: step #{index} (#{action})", fn -> + advance(sim, action, state, wire) + end) + end) - Enum.each(Map.values(finish.pids), &Process.exit(&1, :kill)) - end - end + Enum.each(Map.values(finish.pids), &Process.exit(&1, :kill)) + Enum.map(rest, & &1["mbt::actionTaken"]) end defp advance(sim, action, state, wire) do