"""Replay owned model-configuration probes against unchanged MIT modules and explicit external dependencies."""
from pathlib import Path
from tempfile import TemporaryDirectory
import argparse,hashlib,json,os,shutil,subprocess,sys
def digest(p):return hashlib.sha256(p.read_bytes()).hexdigest()
def observe(project,node,dependency_root):
project=Path(project).resolve();node=Path(node).resolve();deps=Path(dependency_root).resolve()
if not node.is_file() or not deps.is_dir():raise ValueError("Explicit existing Node binary and node_modules directory required")
pi=deps/"@earendil-works/pi-ai";yaml=deps/"yaml"
versions={}
for name,path,wanted in (("pi-ai",pi,"1.5.0"),("yaml",yaml,"2.9.0")):
d=json.loads((path/"package.json").read_bytes())
if d["version"]!=wanted:raise ValueError(name+" version must be "+wanted)
versions[name]=dict(version=wanted,package_json_sha256=digest(path/"package.json"))
sources={name:digest(project/"vendor"/name) for name in ("catalog.ts","provider.ts","models.ts")}
cases=[];outputs=[];node_hash=digest(node)
with TemporaryDirectory(prefix="owned-models-",dir=project) as td:
root=Path(td).resolve();assert root.is_relative_to(project)
for name,h in sources.items():shutil.copyfile(project/"vendor"/name,root/name);assert digest(root/name)==h
(root/"package.json").write_bytes(b'{"private":true,"type":"module"}\n')
home=root/"home";home.mkdir();link=root/"node_modules";created=False
try:
if os.name=="nt":
# Creation only. Removal below uses rmdir on this exact junction, never a recursive traversal.
proc=subprocess.run([os.environ.get("COMSPEC","cmd.exe"),"/d","/c","mklink","/J",str(link),str(deps)],capture_output=True,timeout=10,creationflags=subprocess.CREATE_NO_WINDOW)
if proc.returncode:raise RuntimeError("Could not create contained dependency junction")
else:os.symlink(deps,link,target_is_directory=True)
created=True
env={k:os.environ[k] for k in ("SystemRoot","WINDIR") if k in os.environ}
env.update(PATH=str(node.parent),HOME=str(home),USERPROFILE=str(home),DSH_HOME=str(home/"unused"),
APPDATA=str(home),LOCALAPPDATA=str(home),TEMP=str(home),TMP=str(home))
groups=[("catalog_probe.mjs",[str(root/"catalog.ts")],28),
("provider_probe.mjs",[str(root)],14),
("owned_yaml_probe.mjs",[str(root/"catalog.ts"),str(yaml/"dist/index.js"),str(pi),str(project/"owned-provider.yml")],6)]
for probe,args,count in groups:
cmd=[str(node),"--permission","--allow-fs-read="+str(root),"--allow-fs-read="+str(project),"--allow-fs-read="+str(deps),str(project/probe),*args]
proc=subprocess.run(cmd,cwd=home,env=env,capture_output=True,encoding="utf8",timeout=50,
creationflags=subprocess.CREATE_NO_WINDOW if os.name=="nt" else 0)
if proc.returncode:raise RuntimeError(probe+" failed: "+proc.stderr[:3000]+proc.stdout[:1000])
result=json.loads(proc.stdout);assert len(result["cases"])==count and all(r["passed"] for r in result["cases"])
assert result["DSH_application_executed"] is False
for row in result["cases"]:
row.update(test_source=dict(path="model_matrix.py",sha256=digest(project/"model_matrix.py")),
test_probe=dict(path=probe,sha256=digest(project/probe)),native_modules_sha256=sources)
cases.append(row)
outputs.append(dict(probe=probe,case_count=count,node=result["node"],stderr=proc.stderr,child_exit_code=proc.returncode))
finally:
if created:
assert link.parent==root and link.resolve()==deps and link.name=="node_modules"
if os.name=="nt":os.rmdir(link)
else:link.unlink()
assert not link.exists()
assert len(cases)==48 and versions["pi-ai"]["package_json_sha256"]==digest(pi/"package.json") and versions["yaml"]["package_json_sha256"]==digest(yaml/"package.json")
return dict(version="Python"+sys.version.split()[0]+" / Node"+outputs[0]["node"],binary_sha256=digest(Path(sys.executable)),
node_binary_sha256=node_hash,dependencies=versions,cases=cases,child_results=outputs,native_modules_sha256=sources,
scope="48 replays: 28 catalog materialization,14 provider/model helpers,6 owned YAML/Azure metadata. Original MIT software unchanged. No reference tutorial YAML, HTTP, model, credential store, OAuth, UI or DSH application.",
DSH_application_executed=False,model_requests=0,real_credentials_used=False,source_tutorial_scripts_executed=False,
configuration_applied=False,external_dependencies_bundled=False,exact_fixed_lockfile_build_claim=False)
def main():
p=argparse.ArgumentParser();p.add_argument("--node",required=True);p.add_argument("--dependency-root")
a=p.parse_args();root=Path(__file__).resolve().parent
print(json.dumps(observe(root,a.node,a.dependency_root or root/"node_modules"),ensure_ascii=False))
if __name__=="__main__":main()
本例需在 Windows、Python3.12、Node24.22.3;外部pi-ai1.5.0/YAML2.9.0,非完整DSH。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows、Python3.12、Node24.22.3;外部pi-ai1.5.0/YAML2.9.0,非完整DSH。
入口文件:projects/deepseek-harness-model-providers/model_matrix.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
model_matrix.py,或下载右侧课程工程包。 - 确认本地已准备 Windows、Python3.12、Node24.22.3;外部pi-ai1.5.0/YAML2.9.0,非完整DSH。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联33章) · 含当前章节或实例 · mbskycom202612a128.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a147.zip