feat: 发布固件底层开发 Skill 套件
This commit is contained in:
commit
c7ae3b4ce1
72 files changed
+10212
No files matched your search
+312
@@ -0,0 +1,312 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Behavioral tests for render_psp_handoff.py."""
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import render_psp_handoff
|
||||
|
||||
|
||||
def git(path: Path, *args: str) -> str:
|
||||
result = subprocess.run(
|
||||
["git", "-C", str(path), *args],
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
check=True,
|
||||
)
|
||||
return result.stdout.strip()
|
||||
|
||||
|
||||
def write(path: Path, payload: dict) -> Path:
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
return path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
psp = root / "psp"
|
||||
psp.mkdir()
|
||||
(psp / "psp.json").write_text("{}", encoding="utf-8")
|
||||
(psp / "metadata").mkdir()
|
||||
bsp = write(
|
||||
psp / "metadata" / "bsp.lock.json", {"schema_version": 1, "build_id": "B1"}
|
||||
)
|
||||
git(psp, "init", "-q")
|
||||
git(psp, "add", "psp.json", "metadata/bsp.lock.json")
|
||||
git(
|
||||
psp,
|
||||
"-c",
|
||||
"user.name=PSP Test",
|
||||
"-c",
|
||||
"user.email=psp-test@example.invalid",
|
||||
"commit",
|
||||
"-qm",
|
||||
"candidate",
|
||||
)
|
||||
commit = git(psp, "rev-parse", "HEAD")
|
||||
image = root / "flash.img"
|
||||
image.write_bytes(b"flash")
|
||||
image_hash = render_psp_handoff.subprocess.run(
|
||||
["sha256sum", str(image)], text=True, stdout=subprocess.PIPE, check=True
|
||||
).stdout.split()[0]
|
||||
contract = write(
|
||||
root / "packaging-contract.json",
|
||||
{
|
||||
"schema_version": 2,
|
||||
"contract_type": "emx21-project-packaging",
|
||||
},
|
||||
)
|
||||
contract_hash = render_psp_handoff.sha256_file(contract)
|
||||
|
||||
static = write(root / "static.json", {"passed": True})
|
||||
packaging = write(
|
||||
root / "packaging.json",
|
||||
{
|
||||
"schema_version": 2,
|
||||
"passed": True,
|
||||
"contract": {
|
||||
"path": str(contract),
|
||||
"sha256": contract_hash,
|
||||
"contract_id": "fixture",
|
||||
},
|
||||
"expected_psp_commit": commit,
|
||||
"image": {"path": str(image), "sha256": image_hash},
|
||||
},
|
||||
)
|
||||
device = write(
|
||||
root / "device.json",
|
||||
{
|
||||
"result": "PASS",
|
||||
"evidence_source": "USER_REPORTED",
|
||||
"psp_commit": commit,
|
||||
"image_path": str(image),
|
||||
"image_sha256": image_hash,
|
||||
"checks": [{"name": "boot", "result": "PASS"}],
|
||||
"unexecuted": [],
|
||||
},
|
||||
)
|
||||
application = write(
|
||||
root / "application.json",
|
||||
{
|
||||
"result": "PASS",
|
||||
"psp_commit": commit,
|
||||
"application_commit": "a" * 40,
|
||||
"unexecuted": [],
|
||||
"internal_approved": True,
|
||||
},
|
||||
)
|
||||
approval = write(
|
||||
root / "approval.json",
|
||||
{
|
||||
"internal_approved": True,
|
||||
"confirmed_by": "embedded-lowlevel owner",
|
||||
"confirmed_at": "2026-09-02T00:00:00+00:00",
|
||||
"confirmed_scope": "packaged candidate",
|
||||
},
|
||||
)
|
||||
context = write(
|
||||
root / "context.json",
|
||||
{
|
||||
"work_id": "WORK-1",
|
||||
"subtask_id": "SUB-1",
|
||||
"phase": "implementation",
|
||||
"wave": "wave-1",
|
||||
"role": "embedded-lowlevel",
|
||||
},
|
||||
)
|
||||
repository_url = "ssh://git.example/psp-NEW.git"
|
||||
remote = {
|
||||
"schema_version": 1,
|
||||
"passed": True,
|
||||
"checked_at": "2026-09-02T00:00:00+00:00",
|
||||
"repository_url": repository_url,
|
||||
"commit": commit,
|
||||
"refs": ["refs/heads/candidate/SUB-1"],
|
||||
"errors": [],
|
||||
}
|
||||
|
||||
candidate = render_psp_handoff.render(
|
||||
"NEW",
|
||||
"CV1841CP",
|
||||
"candidate",
|
||||
psp,
|
||||
None,
|
||||
"psp-REF",
|
||||
None,
|
||||
static,
|
||||
bsp,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
None,
|
||||
False,
|
||||
)
|
||||
assert candidate["passed"] is True, candidate
|
||||
assert candidate["etunel"]["sent"] is False
|
||||
|
||||
packaged = render_psp_handoff.render(
|
||||
"NEW",
|
||||
"CV1841CP",
|
||||
"packaged",
|
||||
psp,
|
||||
repository_url,
|
||||
"psp-REF",
|
||||
None,
|
||||
static,
|
||||
bsp,
|
||||
packaging,
|
||||
None,
|
||||
None,
|
||||
context,
|
||||
approval,
|
||||
"Media-1",
|
||||
"AI-1",
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
remote,
|
||||
True,
|
||||
)
|
||||
assert packaged["passed"] is True, packaged
|
||||
assert packaged["etunel"]["prepared_for_send"] is True
|
||||
assert packaged["etunel"]["sent"] is False
|
||||
|
||||
before_tag = render_psp_handoff.render(
|
||||
"NEW",
|
||||
"CV1841CP",
|
||||
"accepted",
|
||||
psp,
|
||||
repository_url,
|
||||
"psp-REF",
|
||||
None,
|
||||
static,
|
||||
bsp,
|
||||
packaging,
|
||||
device,
|
||||
application,
|
||||
context,
|
||||
approval,
|
||||
"Media-1",
|
||||
"AI-1",
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
remote,
|
||||
True,
|
||||
)
|
||||
assert before_tag["passed"] is False
|
||||
assert any("accepted" in error for error in before_tag["errors"])
|
||||
|
||||
git(
|
||||
psp,
|
||||
"-c",
|
||||
"user.name=PSP Test",
|
||||
"-c",
|
||||
"user.email=psp-test@example.invalid",
|
||||
"tag",
|
||||
"-a",
|
||||
f"accepted/{commit[:12]}",
|
||||
"-m",
|
||||
"accepted fixture",
|
||||
)
|
||||
accepted = render_psp_handoff.render(
|
||||
"NEW",
|
||||
"CV1841CP",
|
||||
"accepted",
|
||||
psp,
|
||||
repository_url,
|
||||
"psp-REF",
|
||||
None,
|
||||
static,
|
||||
bsp,
|
||||
packaging,
|
||||
device,
|
||||
application,
|
||||
context,
|
||||
approval,
|
||||
"Media-1",
|
||||
"AI-1",
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
remote,
|
||||
True,
|
||||
)
|
||||
assert accepted["passed"] is True, accepted
|
||||
|
||||
no_remote = render_psp_handoff.render(
|
||||
"NEW",
|
||||
"CV1841CP",
|
||||
"packaged",
|
||||
psp,
|
||||
repository_url,
|
||||
"psp-REF",
|
||||
None,
|
||||
static,
|
||||
bsp,
|
||||
packaging,
|
||||
None,
|
||||
None,
|
||||
context,
|
||||
approval,
|
||||
"Media-1",
|
||||
"AI-1",
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
None,
|
||||
True,
|
||||
)
|
||||
assert no_remote["passed"] is False
|
||||
assert any("远端" in error for error in no_remote["errors"])
|
||||
|
||||
candidate_etunel = render_psp_handoff.render(
|
||||
"NEW",
|
||||
"CV1841CP",
|
||||
"candidate",
|
||||
psp,
|
||||
repository_url,
|
||||
"psp-REF",
|
||||
None,
|
||||
static,
|
||||
bsp,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
context,
|
||||
approval,
|
||||
None,
|
||||
None,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
remote,
|
||||
True,
|
||||
)
|
||||
assert candidate_etunel["passed"] is False
|
||||
assert any("packaged" in error for error in candidate_etunel["errors"])
|
||||
|
||||
bare = root / "remote.git"
|
||||
subprocess.run(["git", "init", "--bare", "-q", str(bare)], check=True)
|
||||
git(psp, "remote", "add", "fixture", str(bare))
|
||||
git(psp, "push", "-q", "fixture", f"{commit}:refs/heads/candidate")
|
||||
reachable = render_psp_handoff.verify_remote(str(bare), commit)
|
||||
assert reachable["passed"] is True, reachable
|
||||
|
||||
print("PSP handoff renderer tests passed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user