Initial public OpenBMH 0.1 source (by Codex)
This commit is contained in:
commit
558fbf166b
613 files changed
+168029
No files matched your search
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# advance.sh <seat> <turns> - plays up to <turns> of this seat's turns in the session of
|
||||
# $QA_DIR: WaitTurn, Advice, then GoBack + Kickoff. Stops early and says why when the
|
||||
# manager has to decide himself:
|
||||
# == question an open question (answer with send.sh <seat> 'Answer(<id>, <option>)')
|
||||
# == match a live match runs: look (ShowMatchStats, ShowTactics, ShowSquad), intervene
|
||||
# (SetTactic, Substitute, MovePlayer), then send Run(Halftime) or Run
|
||||
# (the clock moves when every manager has sent his)
|
||||
# == season end a final table came: inspect the new season before continuing
|
||||
# == game over
|
||||
# Prints a condensed view: advice, messages, questions, results, chat, errors.
|
||||
: "${QA_DIR:?set QA_DIR to the session folder}"
|
||||
CLI=${CLI:-openbmh_cli}
|
||||
SEAT="$QA_DIR/box/seat$1"; N="$2"
|
||||
send() { printf '%s\ngo.\n' "$1" | "$CLI" --send "$SEAT" --timeout 3600; }
|
||||
show() { grep -E "^(i advice|i New message|i final table|\? Q|! |c \[|# Session|\+ Next day|\+ Q|i [0-9]+')" | grep -v 'nothing to go back' | cut -c1-300; }
|
||||
stop_if() {
|
||||
echo "$1" | grep -q '# Session ended' && { echo "== game over"; exit 0; }
|
||||
echo "$1" | grep -q '^? Q' && { echo "== question: answer it"; exit 0; }
|
||||
echo "$1" | grep -q 'Window: Match' && { echo "== match: intervene if you want, then Run(Halftime) or Run"; exit 0; }
|
||||
echo "$1" | grep -q 'final table' && { echo "== season end: inspect before continuing"; exit 0; }
|
||||
}
|
||||
for ((t = 1; t <= N; t++)); do
|
||||
r=$(send "WaitTurn"); echo "$r" | show; stop_if "$r"
|
||||
r=$(send 'Advice'); echo "$r" | show
|
||||
r=$(send $'GoBack\nGoBack\nKickoff'); echo "$r" | show; stop_if "$r"
|
||||
echo "-- turn $t done"
|
||||
done
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# send.sh <seat> '<command lines, separated by \n>' - one block to the session of
|
||||
# $QA_DIR (see docs/CONSOLE_CLIENTS.md), prints the full answer.
|
||||
# QA_DIR: the session folder with box/seat<k>; CLI: path to openbmh_cli.
|
||||
: "${QA_DIR:?set QA_DIR to the session folder}"
|
||||
CLI=${CLI:-openbmh_cli}
|
||||
printf '%b\ngo.\n' "$2" | "$CLI" --send "$QA_DIR/box/seat$1" --timeout 3600
|
||||
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
"""Check the public command catalogue and relative Markdown links."""
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
from urllib.parse import unquote, urlsplit
|
||||
|
||||
|
||||
def check(root):
|
||||
documents = root / "docs" / "CLI_CONCEPT"
|
||||
errors = []
|
||||
with (documents / "commands.csv").open(encoding="utf-8", newline="") as stream:
|
||||
reader = csv.DictReader(stream, delimiter=";")
|
||||
expected = ["window", "command", "parameters", "effect", "errors", "engine", "c4", "status", "source"]
|
||||
if reader.fieldnames != expected:
|
||||
return ["commands.csv: unexpected schema"], 0
|
||||
rows = list(reader)
|
||||
seen = set()
|
||||
for line, row in enumerate(rows, 2):
|
||||
if None in row or any(value is None for value in row.values()):
|
||||
errors.append(f"commands.csv:{line}: incorrect column count")
|
||||
continue
|
||||
if row["status"] not in {"ready", "engine", "partial", "gap", "cli"}:
|
||||
errors.append(f"commands.csv:{line}: invalid status")
|
||||
if not row["command"] or not row["window"]:
|
||||
errors.append(f"commands.csv:{line}: missing window or command")
|
||||
for window in row["window"].split("|"):
|
||||
identity = (window, re.sub(r"[._]", "", row["command"]).lower())
|
||||
if identity in seen:
|
||||
errors.append(f"commands.csv:{line}: duplicate window/command")
|
||||
seen.add(identity)
|
||||
source = row["source"].split(":", 1)[0]
|
||||
if source and not (documents / source).is_file():
|
||||
errors.append(f"commands.csv:{line}: source document missing")
|
||||
for path in root.rglob("*.md"):
|
||||
if any(part.startswith("build") or part in {".git", "_deps"} for part in path.relative_to(root).parts):
|
||||
continue
|
||||
for target in re.findall(r"\]\(([^)]+)\)", path.read_text(encoding="utf-8")):
|
||||
target = target.strip().strip("<>")
|
||||
parsed = urlsplit(target)
|
||||
if parsed.scheme or parsed.netloc or not parsed.path:
|
||||
continue
|
||||
if not (path.parent / unquote(parsed.path)).exists():
|
||||
errors.append(f"{path.relative_to(root)}: broken relative link {target}")
|
||||
return errors, len(rows)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[2])
|
||||
args = parser.parse_args()
|
||||
errors, commands = check(args.root.resolve())
|
||||
for error in errors:
|
||||
print(error)
|
||||
print(f"Command catalogue: {commands} entries, {len(errors)} errors")
|
||||
return int(bool(errors))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Install the Runtime component and make an allowlisted release ZIP."""
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
|
||||
def validate(directory, windows):
|
||||
products = {'openbmh_play.exe', 'openbmh_cli.exe'} if windows else {'openbmh_play', 'openbmh_cli'}
|
||||
documents = {'README.md', 'LICENSE', 'THIRD_PARTY_NOTICES.md', 'ACKNOWLEDGEMENTS.md', 'CONTRIBUTING.md'}
|
||||
licenses = {'README.md', 'LGPL-2.1.txt', 'Nuked-OPL3-notices.txt', 'LZMA-SDK.txt', 'SDL2-HIDAPI-BSD.txt',
|
||||
'SDL2-HIDAPI-options.txt', 'SDL2-HIDAPI-original.txt', 'SDL2-yuv2rgb.txt',
|
||||
'SDL2.txt', 'miniz-source-notices.txt', 'miniz.txt', 'nativefiledialog-extended.txt'}
|
||||
present = set()
|
||||
for file in directory.rglob('*'):
|
||||
if not file.is_file():
|
||||
continue
|
||||
relative = file.relative_to(directory)
|
||||
present.add(relative.as_posix())
|
||||
allowed = (len(relative.parts) == 1 and file.name in products | documents)
|
||||
allowed |= len(relative.parts) == 3 and relative.parts[:2] == ('docs', 'licenses') and file.name in licenses
|
||||
allowed |= (len(relative.parts) >= 2 and relative.parts[0] == 'docs' and
|
||||
'licenses' not in relative.parts and file.suffix in {'.md', '.txt', '.csv'} and
|
||||
all(part not in {'analyses', 'agents', 'manuals', 'validation'} for part in relative.parts))
|
||||
allowed |= (windows and len(relative.parts) == 1 and
|
||||
bool(re.fullmatch(r'(?:vcruntime\d+(?:_\d+)?|msvcp\d+(?:_\d+|_atomic_wait|_codecvt_ids)?|'
|
||||
r'concrt\d+|ucrtbase|api-ms-win-crt-[a-z0-9-]+)\.dll', file.name, re.I)))
|
||||
if not allowed:
|
||||
raise RuntimeError('Unexpected package entry: ' + relative.as_posix())
|
||||
required = products | documents | {'docs/licenses/' + name for name in licenses}
|
||||
required.add('docs/release/0.1/RELEASE_NOTES.md')
|
||||
if required - present:
|
||||
raise RuntimeError('Missing package entries: ' + ', '.join(sorted(required - present)))
|
||||
if windows and not {'vcruntime140.dll', 'msvcp140.dll'} <= present:
|
||||
raise RuntimeError('App-local Microsoft runtime libraries missing')
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--build', required=True, type=Path)
|
||||
parser.add_argument('--out', required=True, type=Path)
|
||||
parser.add_argument('--platform', required=True, choices=['windows-x64', 'linux-x64', 'macos-arm64'])
|
||||
parser.add_argument('--config', default='Release')
|
||||
args = parser.parse_args()
|
||||
args.out.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix='openbmh-package-', dir=args.out) as temp:
|
||||
stage = Path(temp) / 'runtime'
|
||||
subprocess.run(['cmake', '--install', str(args.build), '--config', args.config,
|
||||
'--component', 'Runtime', '--prefix', str(stage)], check=True)
|
||||
windows = args.platform == 'windows-x64'
|
||||
validate(stage, windows)
|
||||
cli = stage / ('openbmh_cli.exe' if windows else 'openbmh_cli')
|
||||
version = subprocess.check_output([str(cli.resolve()), '--version'], text=True).strip().split()[-1]
|
||||
if not re.fullmatch(r'\d+\.\d+\.\d+(?:[-+][A-Za-z0-9.-]+)?', version):
|
||||
raise RuntimeError('Invalid product version')
|
||||
name = 'OpenBMH-' + version + '-' + args.platform
|
||||
destination = args.out / (name + '.zip')
|
||||
with zipfile.ZipFile(destination, 'w', compression=zipfile.ZIP_DEFLATED) as archive:
|
||||
for file in sorted(stage.rglob('*')):
|
||||
if file.is_file():
|
||||
archive.write(file, Path(name) / file.relative_to(stage))
|
||||
print(destination)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
"""Package the audited public source and the dependency sources used by its build."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
COMPONENTS = {
|
||||
'SDL2': ('release-2.32.10', 'https://github.com/libsdl-org/SDL', ['include/SDL.h', 'src/SDL.c', 'LICENSE.txt']),
|
||||
'miniz': ('3.0.2', 'https://github.com/richgel999/miniz', ['miniz.c', 'miniz.h', 'LICENSE']),
|
||||
'lzma_sdk': ('24.09', 'https://github.com/ip7z/7zip', ['C/7zDec.c', 'C/7z.h', 'DOC/License.txt']),
|
||||
'nfd': ('v1.2.1', 'https://github.com/btzy/nativefiledialog-extended', ['CMakeLists.txt', 'src/nfd_cocoa.m', 'LICENSE']),
|
||||
}
|
||||
# Verified against the archive SHA256 pinned in CMakeLists.txt. These are free
|
||||
# dependency source files, not game data. Refuse modified archive-cache inputs.
|
||||
MINIZ_FILES = {
|
||||
'miniz.c': '0fcdc9888cb3a29ca8f176bac087e5fe6c7258a6ab06b1c271c1e109a11d3740',
|
||||
'miniz.h': '295d1a0041aea09609598c0f1f35c1977ca05ad662acbadcfdaac44c140af37b',
|
||||
'LICENSE': '0115478d567121238cf6cc1c0c361926cf07a49d9e4c9e66da97fac6a01646b3',
|
||||
'ChangeLog.md': '261c5cfb87942b5c47735b98ae2fa87ba5f3058d3c755838756b6117f3b0c0dd',
|
||||
'readme.md': 'b4ea367be28a36e5386f65118b73962bc659a67936d248be68b7a7c03b8d359b',
|
||||
}
|
||||
|
||||
|
||||
def git(directory, *arguments):
|
||||
return subprocess.check_output(['git', '-C', str(directory), *arguments])
|
||||
|
||||
|
||||
def copy_files(source, destination, files, required=False):
|
||||
manifest = {}
|
||||
for relative in sorted(set(files)):
|
||||
origin = source / relative
|
||||
if not origin.is_file():
|
||||
if required:
|
||||
raise RuntimeError('Missing dependency source file: ' + relative.as_posix())
|
||||
continue
|
||||
if not origin.resolve().is_relative_to(source.resolve()):
|
||||
raise RuntimeError('Source symlink leaves its component')
|
||||
target = destination / relative
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(origin, target)
|
||||
manifest[relative.as_posix()] = hashlib.sha256(target.read_bytes()).hexdigest()
|
||||
return manifest
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--source', type=Path, default=Path(__file__).resolve().parents[2])
|
||||
parser.add_argument('--build', required=True, type=Path)
|
||||
parser.add_argument('--out', required=True, type=Path)
|
||||
args = parser.parse_args()
|
||||
source = args.source.resolve()
|
||||
subprocess.run([sys.executable, str(source / 'tools/public_release/check_public_tree.py'),
|
||||
'--root', str(source)], check=True)
|
||||
cache = (args.build / 'CMakeCache.txt').read_text()
|
||||
import re
|
||||
version = re.search(r'^CMAKE_PROJECT_VERSION:STATIC=([^\n]+)$', cache, re.M).group(1)
|
||||
if not re.fullmatch(r'\d+\.\d+\.\d+', version):
|
||||
raise RuntimeError('Unexpected source version')
|
||||
dependencies = json.loads((args.build / 'package-dependencies.json').read_text())
|
||||
args.out.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix='openbmh-source-', dir=args.out) as temporary:
|
||||
stage = Path(temporary)
|
||||
project_files = [Path(p.decode('utf-8')) for p in git(source, 'ls-files', '-z', '--cached', '--others', '--exclude-standard').split(b'\0') if p]
|
||||
manifest = {'version': version, 'project_commit': git(source, 'rev-parse', 'HEAD').decode().strip(),
|
||||
'project_files': copy_files(source, stage / 'project', project_files), 'dependencies': {}}
|
||||
initial_cache = []
|
||||
for name, (reference, url, markers) in COMPONENTS.items():
|
||||
directory = Path(dependencies.get(name, ''))
|
||||
if not dependencies.get(name) or not all((directory / marker).is_file() for marker in markers):
|
||||
raise RuntimeError('Actual dependency source unavailable: ' + name)
|
||||
commit = None
|
||||
if (directory / '.git').exists():
|
||||
commit = git(directory, 'rev-parse', 'HEAD').decode().strip()
|
||||
tag = git(directory, 'rev-parse', reference + '^{commit}').decode().strip()
|
||||
if commit != tag or git(directory, 'status', '--porcelain', '--untracked-files=no').strip():
|
||||
raise RuntimeError('Dependency differs from its pinned source: ' + name)
|
||||
if git(directory, 'ls-files', '--stage').find(b'160000 ') != -1:
|
||||
raise RuntimeError('Dependency submodules require explicit packaging: ' + name)
|
||||
if commit:
|
||||
files = [Path(p.decode('utf-8')) for p in git(directory, 'ls-files', '-z').split(b'\0') if p]
|
||||
if name == 'lzma_sdk':
|
||||
files = [p for p in files if p.parts[0] == 'C' or p == Path('DOC/License.txt')]
|
||||
else:
|
||||
# The pinned miniz amalgamation is an archive rather than a Git checkout.
|
||||
if name != 'miniz':
|
||||
raise RuntimeError('Dependency revision cannot be verified: ' + name)
|
||||
files = [Path(p) for p in MINIZ_FILES]
|
||||
for filename, expected in MINIZ_FILES.items():
|
||||
if hashlib.sha256((directory / filename).read_bytes()).hexdigest() != expected:
|
||||
raise RuntimeError('Dependency differs from its pinned archive: ' + name)
|
||||
hashes = copy_files(directory, stage / 'dependencies' / name, files, required=True)
|
||||
manifest['dependencies'][name] = {'upstream': url, 'reference': reference,
|
||||
'commit': commit, 'files': hashes}
|
||||
initial_cache.append('set(FETCHCONTENT_SOURCE_DIR_' + name.upper() +
|
||||
' "${CMAKE_CURRENT_LIST_DIR}/dependencies/' + name + '" CACHE PATH "" FORCE)')
|
||||
(stage / 'dependencies.cmake').write_text('\n'.join(initial_cache) + '\n')
|
||||
(stage / 'SOURCE_MANIFEST.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
||||
(stage / 'BUILD_SOURCE.md').write_text(
|
||||
'# Corresponding source\n\nThe project contains its patches, build scripts and vendored Nuked OPL3. '
|
||||
'The dependency folders contain the sources used by this build; the LZMA folder contains the C decoder tree and upstream license. '
|
||||
'File hashes and upstream revisions are in SOURCE_MANIFEST.json. No game data or test references are included.\n\n'
|
||||
'With the native compiler, CMake and platform development libraries described in project/README.md:\n\n'
|
||||
'```sh\ncmake -S project -B build -C dependencies.cmake -DCMAKE_BUILD_TYPE=Release -DBMH_DATA=\n'
|
||||
'cmake --build build --config Release --parallel 2\nctest --test-dir build -C Release --output-on-failure\n```\n\n'
|
||||
'Modify the library/application sources and rebuild with these scripts to produce a relinked program. '
|
||||
'The source package does not supply the compiler, operating-system SDK or system libraries.\n')
|
||||
destination = args.out / ('OpenBMH-' + version + '-source.zip')
|
||||
with zipfile.ZipFile(destination, 'w', compression=zipfile.ZIP_DEFLATED) as archive:
|
||||
for file in sorted(stage.rglob('*')):
|
||||
if file.is_file():
|
||||
archive.write(file, Path(destination.stem) / file.relative_to(stage))
|
||||
print(destination)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# Compatibility entry point; CMake installs the app-local compiler runtime.
|
||||
set -euo pipefail
|
||||
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
python3 "$ROOT/tools/package/make_package.py" --build "${1:-$ROOT/build}" --out "${2:-$ROOT/dist}" --platform windows-x64
|
||||
@@ -0,0 +1,286 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# Copyright (C) 2026 OpenBMH contributors
|
||||
"""Check source distributions without printing matched credentials or file contents."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import dataclasses
|
||||
import json
|
||||
from pathlib import Path, PurePosixPath
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True, order=True)
|
||||
class Finding:
|
||||
path: str
|
||||
line: int
|
||||
rule: str
|
||||
|
||||
|
||||
ASSET_SUFFIXES = {
|
||||
".fbm", ".vga", ".blk", ".col", ".lbm", ".fnt", ".wap", ".ein", ".men", ".dat",
|
||||
".exe", ".dll", ".so", ".dylib", ".wav", ".mp3", ".ogg", ".flac",
|
||||
".avi", ".mov", ".mp4", ".png", ".jpg", ".jpeg", ".bmp", ".gif",
|
||||
".bin", ".zip", ".7z", ".dmg", ".tar", ".gz", ".pdf",
|
||||
}
|
||||
PRIVATE_PREFIXES = (
|
||||
("data", "original"), ("docs", "manuals"), ("docs", "analyses"),
|
||||
("docs", "agents"), ("src", "ui", "validation"),
|
||||
("src", "ui", "reference"), ("src", "audio", "validation"),
|
||||
("re",), ("tests", "fixtures"),
|
||||
)
|
||||
PRIVATE_DOCUMENTS = {
|
||||
"Status.md", "fltd.md", "BUILD_0.1_HANDOFF.md",
|
||||
"PUBLIC_RELEASE_TODO.md", "chat.txt",
|
||||
}
|
||||
SOURCE_SUFFIXES = {".cpp", ".hpp", ".h", ".c", ".inc"}
|
||||
SKIP_DIRECTORIES = {".git", "__pycache__", ".cache", "_deps", "node_modules"}
|
||||
|
||||
LEGACY_SYMBOLS = re.compile(
|
||||
r"(?<![A-Za-z0-9])(?:" + "FUN" + r"_?[0-9a-f]{4,8}|" + "DAT" +
|
||||
r"_[0-9a-f]{5,8}|source[_ ]*(?=[0-9a-f]*[0-9])[0-9a-f]{4,8}|"
|
||||
r"(?:raw|heap|saved|expected|sound_cfg)_(?=[ab][0-9a-f]*[0-9])[ab][0-9a-f]{4})(?![A-Za-z0-9])",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
PRIVATE_TEXT = re.compile(
|
||||
r"(?:(?<![\w}./\\])/" + r"tools/|[A-Z]:[/\\]Users[/\\]|[A-Z]:[/\\]OpenBMH[/\\]|"
|
||||
r"docs/(?:analyses|agents)/|src/ui/(?:validation|reference)/|"
|
||||
+ "bmh" + r"-work|matter" + r"most|\bMich" + r"ael\b|\bDIA" +
|
||||
r"MOND\b|(?<![\w}./\\])/" + r"root/[^\s]+|https?://(?:10\.|192\.168\.|172\.(?:1[6-9]|2[0-9]|3[01])\.)|"
|
||||
r"github\.com/[^/\s]+/openbmh[_-]dc\b)",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
SECRET_PATTERNS = (
|
||||
re.compile(r"\bgh[pousr]_[A-Za-z0-9_]{20,}\b"),
|
||||
re.compile(r"\bgithub_pat_[A-Za-z0-9_]{30,}\b"),
|
||||
re.compile(r"-----BEGIN (?:[A-Z0-9]+ )?PRIVATE KEY-----"),
|
||||
re.compile(r"\bAKIA[0-9A-Z]{16}\b"),
|
||||
re.compile(r"(?i)\bBearer\s+[A-Za-z0-9._~+/-]{20,}"),
|
||||
re.compile(r"(?i)\b[A-Z_]*(?:TOKEN|PASSWORD|SECRET|API_KEY)['\"]?\s*[:=]\s*['\"][A-Za-z0-9_./+-]{20,}['\"]"),
|
||||
re.compile(r"(?m)^(?:export\s+)?[A-Z_]*(?:TOKEN|PASSWORD|SECRET|API_KEY)\s*=\s*[A-Za-z0-9_./+-]{20,}(?:\s|$)"),
|
||||
)
|
||||
EMAIL = re.compile(r"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b", re.IGNORECASE)
|
||||
HEX_NUMBER = re.compile(r"\b0x(?P<digits>[0-9a-f]{5,8})(?:u(?:ll?|z)?|ll?u?|z)?\b", re.IGNORECASE)
|
||||
LAYOUT_BEGIN = 0x50000
|
||||
LAYOUT_END = 0xE0000
|
||||
|
||||
|
||||
def line_at(text: str, position: int) -> int:
|
||||
return text.count("\n", 0, position) + 1
|
||||
|
||||
|
||||
def cpp_exclusions(text: str):
|
||||
"""Yield comment/literal spans, respecting raw strings and numeric separators."""
|
||||
at = 0
|
||||
while at < len(text):
|
||||
if text.startswith("//", at):
|
||||
end = text.find("\n", at)
|
||||
end = len(text) if end < 0 else end
|
||||
yield at, end, "comment"
|
||||
at = end
|
||||
elif text.startswith("/*", at):
|
||||
end = text.find("*/", at + 2)
|
||||
end = len(text) if end < 0 else end + 2
|
||||
yield at, end, "comment"
|
||||
at = end
|
||||
elif text.startswith('R"', at):
|
||||
opening = text.find("(", at + 2, at + 19)
|
||||
if opening < 0:
|
||||
at += 2
|
||||
continue
|
||||
delimiter = text[at + 2:opening]
|
||||
end = text.find(")" + delimiter + '"', opening + 1)
|
||||
finish = len(text) if end < 0 else end + len(delimiter) + 2
|
||||
yield at, finish, "literal"
|
||||
at = finish
|
||||
elif text[at] == "'" and at + 1 < len(text) and text[at + 1].isalnum() and re.search(
|
||||
r"\b[0-9][a-fA-F0-9xXbB']*$", text[max(0, at - 200):at]):
|
||||
at += 1 # C++ numeric separator, rather than a character literal.
|
||||
elif text[at] in "\"'":
|
||||
start = at
|
||||
quote = text[at]
|
||||
at += 1
|
||||
while at < len(text):
|
||||
if text[at] == "\\":
|
||||
at += 2
|
||||
elif text[at] == quote:
|
||||
at += 1
|
||||
break
|
||||
else:
|
||||
at += 1
|
||||
yield start, at, "literal"
|
||||
else:
|
||||
at += 1
|
||||
|
||||
|
||||
def is_layout_value(value: int) -> bool:
|
||||
return LAYOUT_BEGIN <= value < LAYOUT_END and value & (value - 1) != 0 and value & (value + 1) != 0
|
||||
|
||||
|
||||
def layout_findings(name: str, text: str):
|
||||
exclusions = list(cpp_exclusions(text))
|
||||
code = list(text)
|
||||
for start, end, kind in exclusions:
|
||||
if kind == "comment":
|
||||
for match in HEX_NUMBER.finditer(text, start, end):
|
||||
if is_layout_value(int(match.group("digits"), 16)):
|
||||
yield Finding(name, line_at(text, match.start()), "address-in-comment")
|
||||
for index in range(start, end):
|
||||
if code[index] != "\n":
|
||||
code[index] = " "
|
||||
code = "".join(code)
|
||||
for match in HEX_NUMBER.finditer(code):
|
||||
if not is_layout_value(int(match.group("digits"), 16)):
|
||||
continue
|
||||
# Keep numeric format knowledge in a named constant, preserving its type.
|
||||
begin = max(code.rfind(";", 0, match.start()), code.rfind("{", 0, match.start()),
|
||||
code.rfind("}", 0, match.start())) + 1
|
||||
prefix = code[begin:match.start()]
|
||||
declaration = re.search(r"\b(?:constexpr|constinit|const)\b[^;{}]*\b[A-Za-z_]\w*\s*=\s*\(?\s*$", prefix)
|
||||
if declaration is None:
|
||||
yield Finding(name, line_at(text, match.start()), "unnamed-layout-address")
|
||||
|
||||
|
||||
def path_findings(name: str) -> list[Finding]:
|
||||
path = PurePosixPath(name)
|
||||
parts = path.parts
|
||||
result = []
|
||||
if path.is_absolute() or ".." in parts:
|
||||
result.append(Finding(name, 0, "unsafe-path"))
|
||||
if path.suffix.lower() in ASSET_SUFFIXES:
|
||||
result.append(Finding(name, 0, "binary-or-game-asset"))
|
||||
if path.name in PRIVATE_DOCUMENTS or any(parts[:len(p)] == p for p in PRIVATE_PREFIXES):
|
||||
result.append(Finding(name, 0, "private-material-path"))
|
||||
if any(p.startswith(".claude") or p.startswith(".codex") for p in parts):
|
||||
result.append(Finding(name, 0, "private-agent-configuration"))
|
||||
return result
|
||||
|
||||
|
||||
def scan_blob(name: str, blob: bytes) -> list[Finding]:
|
||||
result = path_findings(name)
|
||||
if len(blob) > 2_000_000:
|
||||
result.append(Finding(name, 0, "oversized-source-file"))
|
||||
if b"\0" in blob:
|
||||
result.append(Finding(name, 0, "binary-content"))
|
||||
return result
|
||||
try:
|
||||
text = blob.decode("utf-8-sig")
|
||||
except UnicodeDecodeError:
|
||||
result.append(Finding(name, 0, "non-utf8-source"))
|
||||
return result
|
||||
for pattern in SECRET_PATTERNS:
|
||||
for match in pattern.finditer(text):
|
||||
result.append(Finding(name, line_at(text, match.start()), "credential-pattern"))
|
||||
# These exact upstream license/copyright documents must remain unmodified.
|
||||
upstream_notice = name.startswith(("docs/licenses/", "tools/package/licenses/",
|
||||
"src/audio/third_party/"))
|
||||
if upstream_notice:
|
||||
return result
|
||||
for pattern, rule in [(LEGACY_SYMBOLS, "legacy-address-symbol"), (PRIVATE_TEXT, "private-provenance")]:
|
||||
for match in pattern.finditer(text):
|
||||
result.append(Finding(name, line_at(text, match.start()), rule))
|
||||
for match in EMAIL.finditer(text):
|
||||
if match.group().lower() != "codex@openbmh.invalid":
|
||||
result.append(Finding(name, line_at(text, match.start()), "personal-email"))
|
||||
if PurePosixPath(name).suffix.lower() in SOURCE_SUFFIXES:
|
||||
result.extend(layout_findings(name, text))
|
||||
elif PurePosixPath(name).suffix.lower() == ".md" and not name.startswith("docs/formats/"):
|
||||
for match in HEX_NUMBER.finditer(text):
|
||||
if is_layout_value(int(match.group("digits"), 16)):
|
||||
result.append(Finding(name, line_at(text, match.start()), "address-outside-format-documentation"))
|
||||
return result
|
||||
|
||||
|
||||
def checked_files(root: Path):
|
||||
"""Use the Git index when available; otherwise inspect a plain source archive."""
|
||||
git = subprocess.run(["git", "-C", str(root), "rev-parse", "--show-toplevel"],
|
||||
capture_output=True, text=True)
|
||||
if git.returncode == 0 and Path(git.stdout.strip()).resolve() == root:
|
||||
output = subprocess.check_output(["git", "-C", str(root), "ls-files", "--cached",
|
||||
"--others", "--exclude-standard", "-z"])
|
||||
return sorted({p.decode("utf-8") for p in output.split(b"\0") if p})
|
||||
return sorted(str(p.relative_to(root).as_posix()) for p in root.rglob("*")
|
||||
if p.is_file() and not any(part in SKIP_DIRECTORIES or part.startswith("build")
|
||||
for part in p.relative_to(root).parts))
|
||||
|
||||
|
||||
def scan_tree(root: Path):
|
||||
findings = []
|
||||
names = checked_files(root)
|
||||
for name in names:
|
||||
path = root / name
|
||||
if path.is_symlink():
|
||||
findings.append(Finding(name, 0, "symlink-not-reviewed"))
|
||||
elif not path.is_file():
|
||||
findings.append(Finding(name, 0, "missing-tracked-file"))
|
||||
else:
|
||||
findings.extend(scan_blob(name, path.read_bytes()))
|
||||
return findings, len(names)
|
||||
|
||||
|
||||
def scan_history(root: Path):
|
||||
findings = []
|
||||
references = subprocess.check_output(["git", "-C", str(root), "for-each-ref", "--format=%(refname)"])
|
||||
findings.extend(scan_blob("ref-names", references))
|
||||
refs = subprocess.check_output(["git", "-C", str(root), "rev-list", "--all"], text=True).splitlines()
|
||||
seen = set()
|
||||
checked = 0
|
||||
for revision in refs:
|
||||
entries = subprocess.check_output(["git", "-C", str(root), "ls-tree", "-rz", revision])
|
||||
for entry in entries.split(b"\0"):
|
||||
if not entry:
|
||||
continue
|
||||
metadata, name = entry.split(b"\t", 1)
|
||||
mode, kind, object_id = metadata.decode().split()
|
||||
path = name.decode("utf-8")
|
||||
if kind != "blob":
|
||||
findings.append(Finding(path, 0, "unreviewed-history-object"))
|
||||
continue
|
||||
if mode == "120000":
|
||||
findings.append(Finding(path, 0, "symlink-in-history"))
|
||||
key = (object_id, path)
|
||||
if key in seen:
|
||||
continue
|
||||
seen.add(key)
|
||||
data = subprocess.check_output(["git", "-C", str(root), "cat-file", "blob", object_id])
|
||||
findings.extend(scan_blob(path, data))
|
||||
checked += 1
|
||||
message = subprocess.check_output(["git", "-C", str(root), "show", "-s", "--format=%B", revision])
|
||||
findings.extend(scan_blob("commit-message", message))
|
||||
return findings, len(refs), checked
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--root", type=Path, default=Path.cwd())
|
||||
parser.add_argument("--history", action="store_true", help="also check all reachable commits and their blobs")
|
||||
parser.add_argument("--json", type=Path, help="write a report containing rule names and locations only")
|
||||
args = parser.parse_args(argv)
|
||||
root = args.root.resolve(strict=True)
|
||||
findings, files = scan_tree(root)
|
||||
commits = blobs = 0
|
||||
if args.history:
|
||||
extra, commits, blobs = scan_history(root)
|
||||
findings.extend(extra)
|
||||
findings = sorted(set(findings))
|
||||
def display_path(name):
|
||||
for pattern in SECRET_PATTERNS:
|
||||
name = pattern.sub("[redacted]", name)
|
||||
return name
|
||||
report = {"ok": not findings, "files_checked": files, "history_checked": args.history,
|
||||
"commits_checked": commits, "history_blobs_checked": blobs,
|
||||
"findings": [{**dataclasses.asdict(f), "path": display_path(f.path)} for f in findings]}
|
||||
if args.json:
|
||||
args.json.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
|
||||
for finding in findings:
|
||||
print(f"{display_path(finding.path)}:{finding.line}: {finding.rule}")
|
||||
print(f"Public-source check: {files} files, {commits} commits, {len(findings)} findings")
|
||||
return int(bool(findings))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
"""List intentional compatibility changes documented in source comments."""
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
from check_public_tree import cpp_exclusions
|
||||
|
||||
MARKER = "OpenBMH deviates from the original:"
|
||||
|
||||
|
||||
def render(root):
|
||||
entries = []
|
||||
for path in sorted((root / "src").rglob("*")):
|
||||
if path.suffix not in {".cpp", ".hpp", ".h", ".c", ".inc"} or "third_party" in path.parts:
|
||||
continue
|
||||
text = path.read_text(encoding="utf-8")
|
||||
spans = list(cpp_exclusions(text))
|
||||
at = 0
|
||||
while at < len(spans):
|
||||
start, end, kind = spans[at]
|
||||
at += 1
|
||||
if kind != "comment":
|
||||
continue
|
||||
while at < len(spans):
|
||||
following, finish, next_kind = spans[at]
|
||||
between = text[end:following]
|
||||
if next_kind != "comment" or between.strip() or between.count("\n") > 1:
|
||||
break
|
||||
end = finish
|
||||
at += 1
|
||||
content = text[start:end]
|
||||
if MARKER not in content:
|
||||
continue
|
||||
relative = path.relative_to(root).as_posix()
|
||||
for declaration in content.split(MARKER)[1:]:
|
||||
description = " ".join(line.strip().removeprefix("//").lstrip("* ")
|
||||
for line in declaration.removesuffix("*/").splitlines())
|
||||
# The first complete sentence is the declared change. Adjacent
|
||||
# comments can also describe implementation details or examples.
|
||||
description = re.split(r"(?<=[.!?])(?:\s|$)", description, maxsplit=1)[0]
|
||||
if (relative, description) not in entries:
|
||||
entries.append((relative, description))
|
||||
lines = ["# Intentional differences from the original", "",
|
||||
"Generated from source comment markers by `tools/public_release/collect_differences.py`.", "",
|
||||
"See [Compatibility decisions](COMPATIBILITY.md) for the overall policy. These entries",
|
||||
"describe deliberate changes; they are not a list of every known compatibility limit.", ""]
|
||||
for path, description in entries:
|
||||
lines.append(f"- [{path}](../{path}): {description}")
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[2])
|
||||
parser.add_argument("--check", action="store_true")
|
||||
args = parser.parse_args()
|
||||
destination = args.root / "docs" / "DIFFERENCES.md"
|
||||
expected = render(args.root)
|
||||
if args.check:
|
||||
if not destination.is_file() or destination.read_text(encoding="utf-8") != expected:
|
||||
parser.exit(1, "Differences catalogue needs regeneration\n")
|
||||
else:
|
||||
destination.write_text(expected, encoding="utf-8")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
"""Generate the executable-format reference from public constant declarations."""
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
|
||||
def render(root):
|
||||
header = root / "src/formats/executable_layout.hpp"
|
||||
declarations = re.findall(r"^inline constexpr auto (\w+) = (0x[0-9a-fA-F]+[uUlL]*);$",
|
||||
header.read_text(encoding="utf-8"), re.M)
|
||||
text = """# Executable and runtime layout constants
|
||||
|
||||
OpenBMH reads the executable image supplied with the user's game installation.
|
||||
The compatibility adapters bind fields in that image's loaded address space.
|
||||
The declarations in [`executable_layout.hpp`](../../src/formats/executable_layout.hpp)
|
||||
name format locations and test fixture bounds; they contain no game resources.
|
||||
|
||||
The adapter uses the German-format layout internally. English image fields are
|
||||
translated into that layout. The values below are data locations or bounds,
|
||||
not callable functions. Structure-relative offsets and bit masks remain separate.
|
||||
|
||||
Each declaration uses `inline constexpr auto` with the original integer spelling
|
||||
and suffix. This preserves signedness, expression typing and constant-expression
|
||||
use. Do not replace these with a single integer type without checking call sites.
|
||||
|
||||
`LayoutTranslation` names identify relocation-table fields read from the selected
|
||||
image. Ordinal suffixes distinguish fields; they do not encode addresses. `Fixture`
|
||||
and `Synthetic` names describe test setup, including arbitrary synthetic workspace
|
||||
locations and buffer sizes; they are not additional original-game layout claims.
|
||||
|
||||
Generated by `tools/public_release/collect_layout.py`. Update this table when
|
||||
declarations change. Game text, resort, image and audio fallbacks belong outside it.
|
||||
|
||||
| Constant | Literal | Use |
|
||||
|---|---|---|
|
||||
"""
|
||||
for name, literal in declarations:
|
||||
value = int(re.sub("[uUlL]+$", "", literal), 16)
|
||||
if name.startswith(("Fixture", "Synthetic")):
|
||||
use = "Test fixture location or bound"
|
||||
else:
|
||||
use = "English image adapter" if value < 0xa0000 else "German-compatible image / runtime field"
|
||||
text += f"| `{name}` | `{literal}` | {use} |\n"
|
||||
return text
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[2])
|
||||
parser.add_argument("--check", action="store_true")
|
||||
args = parser.parse_args()
|
||||
destination = args.root / "docs/formats/EXECUTABLE_LAYOUT.md"
|
||||
expected = render(args.root)
|
||||
if args.check:
|
||||
if not destination.is_file() or destination.read_text(encoding="utf-8") != expected:
|
||||
parser.exit(1, "Executable-layout reference needs regeneration\n")
|
||||
else:
|
||||
destination.write_text(expected, encoding="utf-8")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# Copyright (C) 2026 OpenBMH contributors
|
||||
"""Synthetic checks for the source-distribution guard; no game input is used."""
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import check_public_tree as guard
|
||||
|
||||
|
||||
class BlobChecks(unittest.TestCase):
|
||||
def rules(self, name, text):
|
||||
return {finding.rule for finding in guard.scan_blob(name, text.encode())}
|
||||
|
||||
def test_legacy_names_without_english_word_false_positives(self):
|
||||
self.assertIn("legacy-address-symbol", self.rules("src/a.cpp", "FUN" + "_00012345();"))
|
||||
self.assertIn("legacy-address-symbol", self.rules("src/a.cpp", "raw_" + "ba384"))
|
||||
self.assertIn("legacy-address-symbol", self.rules("src/a.cpp", "has_source_" + "a2518"))
|
||||
self.assertNotIn("legacy-address-symbol", self.rules("src/a.cpp", "offer_row_added source_address"))
|
||||
|
||||
def test_layout_constants_keep_suffixes_but_raw_calls_are_rejected(self):
|
||||
for suffix in ("", "U", "UL", "ULL", "lu"):
|
||||
with self.subTest(suffix=suffix):
|
||||
self.assertIn("unnamed-layout-address", self.rules("src/a.cpp", "read(0xa2345" + suffix + ");"))
|
||||
self.assertNotIn("unnamed-layout-address", self.rules("src/a.cpp", "inline constexpr auto kHeader = 0xa2345" + suffix + ";"))
|
||||
self.assertNotIn("unnamed-layout-address", self.rules("src/a.cpp", "mask(0x7ffff, 0x80000);"))
|
||||
|
||||
def test_cpp_lexing_excludes_literal_contents(self):
|
||||
body = '\n'.join((
|
||||
'auto a = "// 0xa2345";',
|
||||
'auto b = R"tag(/* 0xa2345 */ " quoted )tag";',
|
||||
"auto n = 1'000; auto q = '\\'';",
|
||||
'// address 0xa2345UL',
|
||||
'read(0xa2345U);',
|
||||
))
|
||||
findings = guard.scan_blob("src/a.cpp", body.encode())
|
||||
self.assertEqual({(f.rule, f.line) for f in findings},
|
||||
{("address-in-comment", 4), ("unnamed-layout-address", 5)})
|
||||
|
||||
def test_formats_may_document_layout_values(self):
|
||||
self.assertIn("address-outside-format-documentation", self.rules("README.md", "Field at 0xa2345"))
|
||||
self.assertNotIn("address-outside-format-documentation", self.rules("docs/formats/EXE.md", "Field at 0xa2345"))
|
||||
|
||||
def test_relative_cmake_source_path_is_not_a_host_path(self):
|
||||
self.assertNotIn("private-provenance", self.rules("CMakeLists.txt", "${CMAKE_SOURCE_DIR}/tools/public_release/check_public_tree.py"))
|
||||
host = "/" + "tools/private/input"
|
||||
self.assertIn("private-provenance", self.rules("CMakeLists.txt", host))
|
||||
|
||||
def test_original_asset_paths_and_binary_data_are_rejected(self):
|
||||
self.assertIn("binary-or-game-asset", self.rules("example.FBM", "synthetic"))
|
||||
self.assertIn("private-material-path", self.rules("tests/fixtures/input.txt", "synthetic"))
|
||||
self.assertIn("binary-content", self.rules("src/a.cpp", "synthetic\0bytes"))
|
||||
|
||||
def test_vendor_attribution_is_preserved_without_exempting_secrets(self):
|
||||
email = "author" + "@example.org"
|
||||
for path in ("docs/licenses/vendor.txt", "tools/package/licenses/vendor.txt"):
|
||||
self.assertNotIn("personal-email", self.rules(path, email))
|
||||
self.assertIn("credential-pattern", self.rules(path, "ghp_" + "A" * 32))
|
||||
self.assertIn("personal-email", self.rules("README.md", email))
|
||||
|
||||
def test_credential_assignments_exclude_cpp_identifier_expressions(self):
|
||||
fake = "A" * 32
|
||||
self.assertIn("credential-pattern", self.rules("settings.json", '{"token": "' + fake + '"}'))
|
||||
self.assertIn("credential-pattern", self.rules("settings.env", "API_TOKEN=" + fake))
|
||||
self.assertNotIn("credential-pattern", self.rules("src/a.cpp", "const int token = state.seller_team_token;"))
|
||||
|
||||
|
||||
class RepositoryChecks(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory(prefix="openbmh-guard-test-")
|
||||
self.root = Path(self.temp.name)
|
||||
self.git("init", "--initial-branch=main")
|
||||
self.git("config", "user.name", "Codex")
|
||||
self.git("config", "user.email", "codex@openbmh.invalid")
|
||||
|
||||
def tearDown(self):
|
||||
self.temp.cleanup()
|
||||
|
||||
def git(self, *args):
|
||||
return subprocess.run(["git", "-C", str(self.root), *args], check=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
def commit(self, message):
|
||||
self.git("add", "--all")
|
||||
self.git("commit", "-m", message)
|
||||
|
||||
def test_untracked_files_are_checked_and_build_outputs_ignored(self):
|
||||
(self.root / ".gitignore").write_text("build*/\n", encoding="utf-8")
|
||||
(self.root / "build-local").mkdir()
|
||||
(self.root / "build-local" / "cache.bin").write_bytes(b"\0")
|
||||
(self.root / "bad.FBM").write_text("synthetic", encoding="utf-8")
|
||||
findings, count = guard.scan_tree(self.root)
|
||||
self.assertEqual(count, 2)
|
||||
self.assertIn("binary-or-game-asset", {f.rule for f in findings})
|
||||
|
||||
def test_deleted_asset_remains_rejected_in_history(self):
|
||||
asset = self.root / "old.FBM"
|
||||
asset.write_text("synthetic, never a game save", encoding="utf-8")
|
||||
self.commit("Add synthetic asset")
|
||||
asset.unlink()
|
||||
(self.root / "README.md").write_text("Clean tree\n", encoding="utf-8")
|
||||
self.commit("Remove synthetic asset")
|
||||
findings, _ = guard.scan_tree(self.root)
|
||||
self.assertEqual(findings, [])
|
||||
findings, commits, _ = guard.scan_history(self.root)
|
||||
self.assertEqual(commits, 2)
|
||||
self.assertIn("binary-or-game-asset", {f.rule for f in findings})
|
||||
|
||||
def test_cli_reports_never_echo_credential_contents(self):
|
||||
credential = "ghp_" + "A" * 32
|
||||
(self.root / (credential + ".txt")).write_text(credential, encoding="utf-8")
|
||||
destination = self.root / "report.json"
|
||||
stdout = io.StringIO()
|
||||
with contextlib.redirect_stdout(stdout):
|
||||
code = guard.main(["--root", str(self.root), "--json", str(destination)])
|
||||
self.assertEqual(code, 1)
|
||||
self.assertNotIn(credential, stdout.getvalue())
|
||||
self.assertNotIn(credential, destination.read_text(encoding="utf-8"))
|
||||
self.assertFalse(json.loads(destination.read_text(encoding="utf-8"))["ok"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# console_longrun.sh - plays many careers on autopilot through the console and reports
|
||||
# crashes, engine gaps and hangs. Every career: NewGame with the given options, the
|
||||
# managers pick Bundesliga clubs, then each turn is "GoBack" (a question gets its default
|
||||
# answer - sales declined, contracts not renewed, so squads thin out over the years) and
|
||||
# "Kickoff", in --time instant, for as many turns as given. That reaches the rare paths
|
||||
# agents and the regression do not: relegations down the leagues, nearly empty squads,
|
||||
# money trouble, many season changes.
|
||||
#
|
||||
# Usage: tools/soak/console_longrun.sh <BMH data dir> <out dir> [turns=1200] [jobs=4] [runs...]
|
||||
# a run is "seed:managers:world:club1[,club2..]" (clubs are Bundesliga club numbers 0-17);
|
||||
# without runs a default mix of 12 careers is played.
|
||||
# Output: <out dir>/<run>.txt (the full console output) and a summary on stdout:
|
||||
# one line per run with the last date, E_INTERNAL / E_ENGINE_GAP counts and the first of
|
||||
# each; "HANG" when the run did not finish within its time limit.
|
||||
# Exit code 0 when no run has an E_INTERNAL or a hang.
|
||||
set -u
|
||||
DATA=${1:?BMH data dir}; OUT=${2:?out dir}; TURNS=${3:-1200}; JOBS=${4:-4}; shift $(( $# < 4 ? $# : 4 ))
|
||||
EXE=${CLI:-openbmh_cli}
|
||||
RUNS=("$@")
|
||||
[ ${#RUNS[@]} -eq 0 ] && RUNS=(1:1:0:0 2:1:0:7 3:1:1:2 4:1:0:15 5:2:0:5,11 6:2:1:3,9 7:3:0:1,6,12 8:3:1:4,8,16
|
||||
9:4:0:7,5,2,10 10:4:1:0,13,14,17 11:1:1:11 12:2:0:16,17)
|
||||
mkdir -p "$OUT"
|
||||
|
||||
one() { # one career: seed managers world clubs
|
||||
local seed=$1 managers=$2 world=$3 clubs=$4 name="s$1_m$2_w$3_c${4//,/-}"
|
||||
local dir="$OUT/$name.saves" in="$OUT/$name.in" out="$OUT/$name.txt"
|
||||
mkdir -p "$dir"
|
||||
{
|
||||
printf 'NewGame(5, 3, %d, 3, true, %s)\ngo.\n' "$managers" "$([ "$world" = 1 ] && echo true || echo false)"
|
||||
local k=1
|
||||
for c in ${clubs//,/ }; do
|
||||
printf 'SelectTeam(M%d, club:%d, Bundesliga, Middle, %d)\nAnswer(%d, Yes)\ngo.\n' $k "$c" $k $k
|
||||
k=$((k + 1))
|
||||
done
|
||||
for ((t = 0; t < TURNS; t++)); do printf 'GoBack\ngo.\nKickoff\ngo.\n'; done
|
||||
printf 'Quit(force=true)\ngo.\n'
|
||||
} > "$in"
|
||||
# a generous limit: about one second per turn
|
||||
timeout $((TURNS + 300)) "$EXE" --console --time instant --seed "$seed" --data "$DATA" \
|
||||
--saves "$(cygpath -w "$dir" 2>/dev/null || echo "$dir")" < "$in" > "$out" 2>&1
|
||||
local rc=$? last internal gap
|
||||
last=$(grep -o 'Next day: [0-9-]*\|Season end: [0-9-]*\|Game over[^"]*' "$out" | tail -1)
|
||||
internal=$(grep -c '^! E_INTERNAL' "$out")
|
||||
gap=$(grep -c '^! E_ENGINE_GAP' "$out")
|
||||
printf '%-24s %-26s internal %4d gap %4d%s\n' "$name" "${last:-no turn}" "$internal" "$gap" "$([ $rc = 124 ] && echo ' HANG')"
|
||||
grep -m1 '^! E_INTERNAL' "$out" | cut -c1-200 | sed 's/^/ first internal: /'
|
||||
grep -m1 '^! E_ENGINE_GAP' "$out" | cut -c1-200 | sed 's/^/ first gap: /'
|
||||
}
|
||||
|
||||
running=0
|
||||
for r in "${RUNS[@]}"; do
|
||||
IFS=: read -r seed managers world clubs <<< "$r"
|
||||
one "$seed" "$managers" "$world" "$clubs" > "$OUT/.summary-$seed-$managers-$world" &
|
||||
running=$((running + 1))
|
||||
if [ $running -ge "$JOBS" ]; then wait -n; running=$((running - 1)); fi
|
||||
done
|
||||
wait
|
||||
cat "$OUT"/.summary-* | tee "$OUT/summary.txt"
|
||||
! grep -q 'internal *[1-9]\|HANG' "$OUT/summary.txt"
|
||||
Reference in new issue
Block a user