Merge remote-tracking branch 'origin/master' into feat/workspace-dependencies-package
This commit is contained in:
commit
f25957d442
1695 files changed
+212081
-51991
No files matched your search
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write python/development.md
|
||||
development.md: 8e7608ada715e5a0acc6eb597ae9d06ebef3ecbf
|
||||
development.zh.md: 3f6c1f92632d216e540b0dff5c4b72cdf90ae7d1
|
||||
development.md: b36a26b08631ae02532d6f190bab968c1ec24720
|
||||
development.zh.md: 81e8015bbcf45424dfb595154bab0ffe1e501251
|
||||
@@ -36,6 +36,8 @@ uv run --project python/sdk python scripts/smoke-python-runtime.py \
|
||||
|
||||
Four scenarios compare committed expected output under `scripts/snapshots/python-sdk-single-exe/`. `minimal/model-visible.json` pins the Linux/macOS `sdk-minimal` profile's assembled system prompts, advertised tool schemas, and model-visible messages; `minimal/win-x64/model-visible.json` pins its PowerShell counterpart. A plugin that contributes an unintended system section or user message therefore fails the job, and every message the profile emits is compared. `advanced/` pins one complex process's SDK result and parent/child session logs across every target. `restart/` launches two complete SDK runtime processes against one persistence root and snapshots their isolated model histories, high-level results, and separate durable logs across every target. `sdk-minimal-in-history` reuses the persistent-shell and editor scenario with a section that changes after the first successful shell call. `minimal-in-history/prompt-history.json` pins both prompt versions, the unchanged leading prompt in later requests, appended SDK system-message events, and `request/context.systemPromptUpdate`; tool schemas stay fixed and the editor file is checked independently. Rerun the owning scenario with `--update-snapshots` and review that diff before committing it.
|
||||
|
||||
The `advanced` and `restart` comparisons match native delivery qualifiers against each input's own Session generation, including SDK events and notifications. Captured and other delivery generations retain their numeric values. Each side must use one generation across its Session roles, and fresh logs must identify the current writer. Comparison never rewrites committed recordings.
|
||||
|
||||
Trusted pull requests and master pushes also run `--scenario sdk-live --installed-wheel` on each selected native target. That scenario performs two tool-using turns against `https://api.deepseek.com`: it checks the created file immediately, replaces its content with a host-only random challenge, and requires the second turn to copy the changed content into a fresh receipt without modifying the source. Both turns must complete with the exact sentinel answer and a model-requested tool call; external byte comparisons check the files. Missing repository secrets fail instead of self-skipping. Fork and Dependabot pull requests run the complete keyless installed-wheel path but receive no key.
|
||||
|
||||
An interactive smoke test needs `DEEPSEEK_API_KEY` in the environment or repository-root `.env`:
|
||||
|
||||
@@ -36,6 +36,8 @@ uv run --project python/sdk python scripts/smoke-python-runtime.py \
|
||||
|
||||
其中四个场景会比对 `scripts/snapshots/python-sdk-single-exe/` 下已提交的期望输出。`minimal/model-visible.json` 固定 Linux/macOS `sdk-minimal` profile 所组装的系统提示词、对外公布的工具 schema 与模型可见消息;`minimal/win-x64/model-visible.json` 固定对应的 PowerShell 版本。因此,插件一旦贡献出计划外的系统分段或 user 消息,该任务即失败,且该 profile 发出的每条消息都会参与比对。`advanced/` 跨所有目标固定一个复杂进程的 SDK 结果及父/子会话日志。`restart/` 针对同一持久化根目录启动两个完整 SDK 运行时进程,并跨所有目标固定其彼此隔离的模型历史、高层结果与独立持久日志。`sdk-minimal-in-history` 复用持久 shell 与编辑器场景,并在首次 shell 调用成功后更改一个分段。`minimal-in-history/prompt-history.json` 固定两个提示词版本、后续请求中不变的首条提示词、追加的 SDK system-message 事件及 `request/context.systemPromptUpdate`;工具 schema 保持不变,并独立检查编辑器创建的文件。重新运行对应场景时加上 `--update-snapshots`,并在提交前审阅该差异。
|
||||
|
||||
`advanced` 与 `restart` 的比较按每份输入自身的 Session 代际匹配原生 delivery 限定值,包括 SDK 事件与通知。捕获的代际及其他 delivery 代际保留数值。每一侧的 Session 角色必须使用同一个代际,新日志必须标识当前写入器。比较绝不重写已提交的记录。
|
||||
|
||||
可信拉取请求与 master 推送还会在各自选定的原生目标上运行 `--scenario sdk-live --installed-wheel`。该场景面向 `https://api.deepseek.com` 执行两个使用工具的轮次:立即检查已创建文件,将其内容替换为仅宿主知道的随机挑战值,并要求第二轮将变更后的内容复制到全新的回执文件,且不修改源文件。两个轮次都必须完成、返回精确的哨兵答案并由模型请求调用工具;文件通过外部逐字节比较验证。仓库密钥缺失时失败,而不是自行 skip。Fork 与 Dependabot 拉取请求会运行完整的 keyless 安装后 wheel 路径,但不会获得密钥。
|
||||
|
||||
交互式冒烟测试需要环境变量或仓库根目录 `.env` 中存在 `DEEPSEEK_API_KEY`:
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write python/sdk-runtime/README.md
|
||||
README.md: 202af65986ae2c78aeb092f0b4adb88cd1c97e9b
|
||||
README.zh.md: 12ff0dbac184f67f8e821b6fbb9e22748563babb
|
||||
README.md: 3a27ef586cce3290b13b9cd4517ff5a491f312c2
|
||||
README.zh.md: 85bf35f62aa60bdb84e612518e2af740f1e8c708
|
||||
@@ -40,7 +40,7 @@ Unsupported platforms and missing executables or sidecars raise `FileNotFoundErr
|
||||
|
||||
## Packaged profile resolution
|
||||
|
||||
`dsh` initializes shipped profiles under the explicit home, composes their bundle patches, and loads bundled plugins from the executable's virtual filesystem. Because operating-system symlinks cannot enter that filesystem, packaged launches maintain small real ESM proxy packages under `$DSH_HOME/profiles/node_modules`. Each proxy mirrors explicit runtime exports, records the original package identity, and re-exports the virtual module URL. Built-in rows and external plugin peers therefore share one Cordis/module instance. Native shared libraries and Windows ConPTY addons are packaged with native addons, while ripgrep and the macOS PTY helper remain executable sidecars.
|
||||
`dsh` initializes shipped profiles under the explicit home, composes their bundle patches, and loads bundled plugins from the executable's virtual filesystem. Runtime resolution uses an in-memory generation instead of disk symlinks or proxy packages. Fallback imports use recorded declaring-package paths, including paths inside the executable's virtual filesystem, so built-in rows and external plugin peers share the bundled Cordis/module instance. Native shared libraries and Windows ConPTY addons are packaged with native addons, while ripgrep and the macOS PTY helper remain executable sidecars.
|
||||
|
||||
The Python bootstrap resolves the Office kit from its adjacent directory so native helpers and URL Workers use real filesystem paths. The kit owns engine selection and validation; the Python bootstrap adds no runtime download or compilation.
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ wheel 包会安装 `dsh` 控制台命令和 `deepseek_harness_runtime` Python
|
||||
|
||||
## 打包后的 profile 解析
|
||||
|
||||
`dsh` 在显式指定的主目录下初始化随附 profile、组合其 bundle patch,并从可执行程序的虚拟文件系统加载内置插件。操作系统符号链接无法进入该文件系统,因此打包运行会在 `$DSH_HOME/profiles/node_modules` 下维护小型真实 ESM 代理包。每个代理复现运行时的显式导出项、记录原包身份,并重新导出虚拟模块 URL。因此,内置配置项与外部插件 peer 会共享同一个 Cordis/模块实例。原生共享库与 Windows ConPTY addon 会同其他原生 addon 一起打包;ripgrep 与 macOS PTY helper 仍是可执行伴随程序。
|
||||
`dsh` 在显式指定的主目录下初始化随附 profile、组合其 bundle patch,并从可执行程序的虚拟文件系统加载内置插件。运行时解析使用内存中的 generation,不创建磁盘符号链接或代理包。fallback 导入使用记录的声明包路径,包括可执行程序虚拟文件系统内的路径,因此内置配置项与外部插件 peer 共享内置的 Cordis/模块实例。原生共享库与 Windows ConPTY addon 会同其他原生 addon 一起打包;ripgrep 与 macOS PTY helper 仍是可执行伴随程序。
|
||||
|
||||
Python bootstrap 从相邻目录解析 Office kit,让原生辅助程序与 URL Worker 使用真实文件系统路径。kit 负责引擎选择与校验;Python bootstrap 不增加运行时下载或编译。
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@ from deepseek_harness import RunResult
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
SMOKE = runpy.run_path(ROOT / "scripts" / "smoke-python-runtime.py")
|
||||
SESSION_FORMAT_VERSION = int(
|
||||
(ROOT / "packages/core/session/src/types.ts").read_text(encoding="utf-8")
|
||||
.split("export const SESSION_FORMAT_VERSION = ", 1)[1].splitlines()[0]
|
||||
)
|
||||
|
||||
|
||||
def live_result(**overrides: object) -> RunResult:
|
||||
@@ -460,21 +464,163 @@ def test_snapshot_generation_names_select_highest_role_without_double_counting(
|
||||
}
|
||||
|
||||
|
||||
def test_snapshot_comparison_accepts_v3_output_against_v2_without_rewriting(tmp_path: Path) -> None:
|
||||
def test_snapshot_comparison_accepts_current_output_against_v2_without_rewriting(tmp_path: Path) -> None:
|
||||
predecessor = '{"type":"session","version":2}\n'
|
||||
successor = '{"type":"session","version":3}\n'
|
||||
successor = json.dumps({"type": "session", "version": SESSION_FORMAT_VERSION}) + "\n"
|
||||
successor_name = f"session.v{SESSION_FORMAT_VERSION}.jsonl"
|
||||
old_path = tmp_path / "session.v2.jsonl"
|
||||
old_path.write_text(predecessor, encoding="utf-8")
|
||||
files = {"session.v3.jsonl": successor}
|
||||
files = {successor_name: successor}
|
||||
|
||||
SMOKE["compare_snapshot_files"](files, False, tmp_path, ("session.v2.jsonl",))
|
||||
assert old_path.read_text(encoding="utf-8") == predecessor
|
||||
assert not (tmp_path / "session.v3.jsonl").exists()
|
||||
assert not (tmp_path / successor_name).exists()
|
||||
|
||||
SMOKE["compare_snapshot_files"](files, True, tmp_path, ("session.v2.jsonl",))
|
||||
assert old_path.read_text(encoding="utf-8") == predecessor
|
||||
assert (tmp_path / "session.v3.jsonl").read_text(encoding="utf-8") == successor
|
||||
assert SMOKE["selected_snapshot_session_files"](tmp_path) == {0: tmp_path / "session.v3.jsonl"}
|
||||
assert (tmp_path / successor_name).read_text(encoding="utf-8") == successor
|
||||
assert SMOKE["selected_snapshot_session_files"](tmp_path) == {0: tmp_path / successor_name}
|
||||
|
||||
|
||||
def native_delivery_snapshot(version: int) -> dict[str, str]:
|
||||
event = {
|
||||
"type": "session-log-deepseek/delivery-accepted",
|
||||
"data": {"sessionId": "s", "throughSeq": 0, "sessionFormatVersion": version},
|
||||
}
|
||||
return {
|
||||
"result.json": json.dumps({
|
||||
"events": [event],
|
||||
"notifications": [{"method": "session.event", "payload": {"sessionId": "s", "event": event}}],
|
||||
}) + "\n",
|
||||
f"session.v{version}.jsonl": SMOKE["render_jsonl"]([
|
||||
{"type": "session", "version": version, "id": "s"},
|
||||
{"type": "turn/start", "data": {"turn": 1}},
|
||||
event,
|
||||
]),
|
||||
}
|
||||
|
||||
|
||||
def test_native_writer_comparison_requires_opt_in_and_preserves_written_generations(tmp_path: Path) -> None:
|
||||
golden = native_delivery_snapshot(3)
|
||||
fresh = native_delivery_snapshot(SESSION_FORMAT_VERSION)
|
||||
for name, content in golden.items():
|
||||
(tmp_path / name).write_text(content, encoding="utf-8")
|
||||
compare = SMOKE["compare_snapshot_files"]
|
||||
with pytest.raises(AssertionError, match="executable snapshot mismatch"):
|
||||
compare(fresh, False, tmp_path, tuple(golden))
|
||||
compare(fresh, False, tmp_path, tuple(golden), native_writer_output=True)
|
||||
assert {path.name: path.read_text(encoding="utf-8") for path in tmp_path.iterdir()} == golden
|
||||
compare(fresh, True, tmp_path, tuple(golden), native_writer_output=True)
|
||||
assert (tmp_path / "session.v3.jsonl").read_text(encoding="utf-8") == golden["session.v3.jsonl"]
|
||||
for name, content in fresh.items():
|
||||
assert (tmp_path / name).read_text(encoding="utf-8") == content
|
||||
assert "{{sourceSessionFormatVersion}}" not in content
|
||||
|
||||
|
||||
@pytest.mark.parametrize("surface", ["session", "events", "notifications"])
|
||||
def test_native_writer_comparison_rejects_stale_current_delivery(tmp_path: Path, surface: str) -> None:
|
||||
golden = native_delivery_snapshot(3)
|
||||
fresh = native_delivery_snapshot(SESSION_FORMAT_VERSION)
|
||||
for name, content in golden.items():
|
||||
(tmp_path / name).write_text(content, encoding="utf-8")
|
||||
if surface == "session":
|
||||
name = f"session.v{SESSION_FORMAT_VERSION}.jsonl"
|
||||
records = [json.loads(line) for line in fresh[name].splitlines()]
|
||||
records[-1]["data"]["sessionFormatVersion"] = 3
|
||||
fresh[name] = SMOKE["render_jsonl"](records)
|
||||
else:
|
||||
result = json.loads(fresh["result.json"])
|
||||
event = result["events"][0] if surface == "events" else result["notifications"][0]["payload"]["event"]
|
||||
event["data"]["sessionFormatVersion"] = 3
|
||||
fresh["result.json"] = json.dumps(result) + "\n"
|
||||
with pytest.raises(AssertionError, match="executable snapshot mismatch"):
|
||||
SMOKE["compare_snapshot_files"](fresh, False, tmp_path, tuple(golden), native_writer_output=True)
|
||||
|
||||
|
||||
def test_native_writer_comparison_preserves_captured_and_nested_delivery_values() -> None:
|
||||
delivery = {
|
||||
"type": "session-log-deepseek/delivery-accepted",
|
||||
"data": {"sessionId": "s", "throughSeq": 0, "sessionFormatVersion": 3},
|
||||
}
|
||||
captured = {"type": "custom/event", "data": {
|
||||
"capturedFormatVersion": 3, "sessionFormatVersion": 3, "nested": delivery,
|
||||
}}
|
||||
value = {
|
||||
"events": [delivery, captured, {**delivery, "data": {**delivery["data"], "sessionFormatVersion": 2}}],
|
||||
"notifications": [
|
||||
{"method": "session.event", "params": {"event": delivery}},
|
||||
{"method": "other.event", "payload": {"event": delivery}},
|
||||
],
|
||||
}
|
||||
normalized = json.loads(SMOKE["normalize_snapshot_comparison_text"]("result.json", json.dumps(value), 3))
|
||||
assert normalized["events"][0]["data"]["sessionFormatVersion"] == "{{sourceSessionFormatVersion}}"
|
||||
assert normalized["events"][1] == captured
|
||||
assert normalized["events"][2]["data"]["sessionFormatVersion"] == 2
|
||||
assert normalized["notifications"][0]["params"]["event"]["data"]["sessionFormatVersion"] == "{{sourceSessionFormatVersion}}"
|
||||
assert normalized["notifications"][1] == value["notifications"][1]
|
||||
assert SMOKE["normalize_session_format_comparison"](delivery) == delivery
|
||||
|
||||
|
||||
def test_default_comparison_keeps_a_migrated_delivery_generation_exact() -> None:
|
||||
source = native_delivery_snapshot(3)["session.v3.jsonl"]
|
||||
target_records = [json.loads(line) for line in source.splitlines()]
|
||||
target_records[0]["version"] = SESSION_FORMAT_VERSION
|
||||
target = SMOKE["render_jsonl"](target_records)
|
||||
normalize = SMOKE["normalize_snapshot_comparison_text"]
|
||||
assert normalize("session.v3.jsonl", source) == normalize(f"session.v{SESSION_FORMAT_VERSION}.jsonl", target)
|
||||
assert '"sessionFormatVersion":3' in normalize(f"session.v{SESSION_FORMAT_VERSION}.jsonl", target)
|
||||
|
||||
|
||||
def test_native_writer_comparison_rejects_mixed_expected_role_generations(tmp_path: Path) -> None:
|
||||
golden = {"session.v2.jsonl": 2, "session.1.v3.jsonl": 3}
|
||||
fresh = {}
|
||||
for index, (name, version) in enumerate(golden.items()):
|
||||
(tmp_path / name).write_text(SMOKE["render_jsonl"]([
|
||||
{"type": "session", "version": version},
|
||||
]), encoding="utf-8")
|
||||
fresh[SMOKE["snapshot_session_filename"](index, SESSION_FORMAT_VERSION)] = SMOKE["render_jsonl"]([
|
||||
{"type": "session", "version": SESSION_FORMAT_VERSION},
|
||||
])
|
||||
with pytest.raises(AssertionError, match="requires one Session generation across all roles"):
|
||||
SMOKE["compare_snapshot_files"](fresh, False, tmp_path, tuple(golden), native_writer_output=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("scenario", ["ADVANCED", "RESTART"])
|
||||
def test_committed_python_native_goldens_compare_current_output_without_rewriting(scenario: str) -> None:
|
||||
directory = SMOKE[f"{scenario}_SNAPSHOT_DIRECTORY"]
|
||||
filenames = SMOKE[f"{scenario}_SNAPSHOT_FILENAMES"]
|
||||
before = {path.name: path.read_bytes() for path in directory.iterdir() if path.is_file()}
|
||||
selected = SMOKE["selected_snapshot_session_files"](directory)
|
||||
first = next(iter(selected.values()))
|
||||
source_version = SMOKE["session_header_version"](before[first.name].decode("utf-8"), first.name)
|
||||
|
||||
def current_writer(value: object) -> object:
|
||||
if isinstance(value, list):
|
||||
return [current_writer(item) for item in value]
|
||||
if not isinstance(value, dict):
|
||||
return value
|
||||
result = {key: current_writer(item) for key, item in value.items()}
|
||||
if result.get("type") == "session":
|
||||
assert result["version"] == source_version
|
||||
result["version"] = SESSION_FORMAT_VERSION
|
||||
if result.get("type") == "session-log-deepseek/delivery-accepted":
|
||||
assert result["data"]["sessionFormatVersion"] == source_version
|
||||
result["data"]["sessionFormatVersion"] = SESSION_FORMAT_VERSION
|
||||
return result
|
||||
|
||||
fresh = {}
|
||||
for name in filenames:
|
||||
parsed = SMOKE["parse_snapshot_session_filename"](name)
|
||||
source_name = selected[parsed[0]].name if parsed is not None else name
|
||||
content = before[source_name].decode("utf-8")
|
||||
if parsed is not None:
|
||||
fresh[SMOKE["snapshot_session_filename"](parsed[0], SESSION_FORMAT_VERSION)] = SMOKE["render_jsonl"]([
|
||||
current_writer(json.loads(line)) for line in content.splitlines() if line
|
||||
])
|
||||
else:
|
||||
fresh[name] = json.dumps(current_writer(json.loads(content)), indent=2, ensure_ascii=False) + "\n"
|
||||
SMOKE["compare_snapshot_files"](fresh, False, directory, filenames, native_writer_output=True)
|
||||
assert {path.name: path.read_bytes() for path in directory.iterdir() if path.is_file()} == before
|
||||
|
||||
|
||||
@pytest.mark.parametrize("filenames", [
|
||||
@@ -485,7 +631,7 @@ def test_snapshot_comparison_accepts_v3_output_against_v2_without_rewriting(tmp_
|
||||
def test_snapshot_builder_checks_role_order_and_count_across_generations(
|
||||
tmp_path: Path, filenames: tuple[str, ...],
|
||||
) -> None:
|
||||
files = {"session.v3.jsonl": "", "session.1.v3.jsonl": ""}
|
||||
files = {f"session.v{SESSION_FORMAT_VERSION}.jsonl": "", f"session.1.v{SESSION_FORMAT_VERSION}.jsonl": ""}
|
||||
with pytest.raises(AssertionError, match="snapshot builder produced"):
|
||||
SMOKE["compare_snapshot_files"](files, False, tmp_path, filenames)
|
||||
|
||||
@@ -496,12 +642,14 @@ def test_snapshot_generation_comparison_rejects_changed_payload(tmp_path: Path)
|
||||
)
|
||||
with pytest.raises(AssertionError, match="executable snapshot mismatch"):
|
||||
SMOKE["compare_snapshot_files"](
|
||||
{"session.v3.jsonl": '{"type":"session","version":3,"id":"changed"}\n'},
|
||||
{f"session.v{SESSION_FORMAT_VERSION}.jsonl": json.dumps({
|
||||
"type": "session", "version": SESSION_FORMAT_VERSION, "id": "changed",
|
||||
}) + "\n"},
|
||||
False, tmp_path, ("session.v2.jsonl",),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("version", [2, 4])
|
||||
@pytest.mark.parametrize("version", [SESSION_FORMAT_VERSION - 1, SESSION_FORMAT_VERSION + 1])
|
||||
@pytest.mark.parametrize("update", [False, True])
|
||||
def test_snapshot_comparison_rejects_noncurrent_writer(
|
||||
tmp_path: Path, version: int, update: bool,
|
||||
@@ -509,22 +657,22 @@ def test_snapshot_comparison_rejects_noncurrent_writer(
|
||||
golden = '{"type":"session","version":2}\n'
|
||||
(tmp_path / "session.v2.jsonl").write_text(golden, encoding="utf-8")
|
||||
content = json.dumps({"type": "session", "version": version}) + "\n"
|
||||
with pytest.raises(AssertionError, match="expected current Session format v3"):
|
||||
with pytest.raises(AssertionError, match=f"expected current Session format v{SESSION_FORMAT_VERSION}"):
|
||||
SMOKE["compare_snapshot_files"](
|
||||
{f"session.v{version}.jsonl": content}, update, tmp_path, ("session.v2.jsonl",),
|
||||
)
|
||||
assert (tmp_path / "session.v2.jsonl").read_text(encoding="utf-8") == golden
|
||||
assert not (tmp_path / "session.v4.jsonl").exists()
|
||||
assert not (tmp_path / f"session.v{SESSION_FORMAT_VERSION}.jsonl").exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("version", [2, 3, 4])
|
||||
@pytest.mark.parametrize("version", [SESSION_FORMAT_VERSION - 1, SESSION_FORMAT_VERSION, SESSION_FORMAT_VERSION + 1])
|
||||
def test_persisted_session_requires_current_writer(version: int) -> None:
|
||||
content = json.dumps({"type": "session", "version": version}) + "\n"
|
||||
path = Path(f"session.v{version}.jsonl")
|
||||
if version == 3:
|
||||
if version == SESSION_FORMAT_VERSION:
|
||||
assert SMOKE["assert_persisted_session_version"](path, content) == version
|
||||
else:
|
||||
with pytest.raises(AssertionError, match="expected current Session format v3"):
|
||||
with pytest.raises(AssertionError, match=f"expected current Session format v{SESSION_FORMAT_VERSION}"):
|
||||
SMOKE["assert_persisted_session_version"](path, content)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user