"""Compare selected entries in the installed Codex CLI's offline catalog."""
from hashlib import sha256
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
from tempfile import TemporaryDirectory
import tomllib
HISTORICAL = ["gpt-5.4", "gpt-5.4-mini", "gpt-5.3-codex", "gpt-5.3-codex-spark"]
SELECTED = ["gpt-6.1-sol", "gpt-6-luna"]
def main():
binary = shutil.which("codex.exe") or shutil.which("codex")
if binary is None:
raise SystemExit("Install Codex CLI and add it to PATH.")
cases = []
def observe(name, data, operation, expected, actual):
assert actual == expected, (name, expected, actual)
cases.append(dict(name="models_" + name, input=data, operation=operation, expected=expected, actual=actual))
with TemporaryDirectory(prefix="mbsky-models-") as temp:
env = dict(os.environ, CODEX_HOME=temp)
def cli(*args):
return subprocess.run([binary, *args], env=env, cwd=temp, capture_output=True,
encoding="utf8", timeout=15)
result = cli("debug", "models", "--bundled")
assert result.returncode == 0, result.stderr
by_id = {item["slug"]: item for item in json.loads(result.stdout)["models"]}
observe("historical", HISTORICAL, "Check whether each historical ID appears in the offline catalog",
[False] * len(HISTORICAL), [name in by_id for name in HISTORICAL])
for name, expected in zip(SELECTED, (["low", ["low","medium","high","xhigh","max","ultra"]],
["medium", ["low","medium","high","xhigh","max"]]), strict=True):
info = by_id[name]
actual = [info["default_reasoning_level"], [row["effort"] for row in info["supported_reasoning_levels"]]]
observe(name, name, "Read the actual model default and offered reasoning values", expected, actual)
tiers = [[item["id"], item["name"]] for item in by_id[SELECTED[0]]["service_tiers"]]
observe("tier", SELECTED[0], "Read the tier's catalog ID and display name", [["priority","Fast"]], tiers)
args = ["--reasoning-effort", "high", "completion", "powershell"]
old = cli(*args)
observe("legacy", args, "Ask the installed CLI parser to process an obsolete global flag",
[2, True], [old.returncode,"unexpected argument" in old.stderr])
sample = 'model = "gpt-6.1-sol"\nmodel_reasoning_effort = "high"\nmodel_reasoning_summary = "auto"\nservice_tier = "fast"\n'
config = tomllib.loads(sample)
observe("config", sample, "Parse an independent TOML sample and read four keys",
["gpt-6.1-sol","high","auto","fast"],
[config[name] for name in ("model","model_reasoning_effort","model_reasoning_summary","service_tier")])
version = cli("--version")
assert version.returncode == 0
print(json.dumps(dict(version={"python":sys.version.split()[0],"codex":version.stdout.strip()},
codex_sha256=sha256(Path(binary).read_bytes()).hexdigest(),cases=cases)))
if __name__ == "__main__":
main()
本例需在 Windows、Python 3.12.14、codex-cli 0.167.0-alpha.4.1。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows、Python 3.12.14、codex-cli 0.167.0-alpha.4.1。
入口文件:projects/codex-models/models_lab.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
models_lab.py,或下载右侧课程工程包。 - 确认本地已准备 Windows、Python 3.12.14、codex-cli 0.167.0-alpha.4.1。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联40章) · 含当前章节或实例 · mbskycom202612a90.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a113.zip