fix(orc): support trusted release shell workflow
This commit is contained in:
@@ -41,6 +41,7 @@ class OrcSkillTests(unittest.TestCase):
|
||||
self.assertIn("不得在项目中创建 `docs/orc/config.yaml`", skill)
|
||||
self.assertIn("薄路由器", skill)
|
||||
self.assertIn("不做领域判断", skill)
|
||||
self.assertIn("当前 shell", skill)
|
||||
self.assertNotIn("用户未指定档位时采用以下判断", skill)
|
||||
self.assertNotIn("若该档位不足以安全完成", skill)
|
||||
for child in ("$ack", "$manage-release", "$deb-publisher", "$publish-docker-image"):
|
||||
@@ -146,6 +147,13 @@ class OrcSkillTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual(plan["workerArgs"][:2], ["--model", "gpt-5.6-terra"])
|
||||
self.assertIn("--strict-config", plan["workerArgs"])
|
||||
approval_index = plan["workerArgs"].index("--ask-for-approval")
|
||||
self.assertEqual(plan["workerArgs"][approval_index + 1], "on-request")
|
||||
self.assertIn('approvals_reviewer="auto_review"', plan["workerArgs"])
|
||||
self.assertNotIn(
|
||||
"sandbox_workspace_write.network_access=true",
|
||||
plan["workerArgs"],
|
||||
)
|
||||
self.assertNotIn("danger-full-access", " ".join(plan["workerArgs"]))
|
||||
self.assertNotIn("env", plan["profile"])
|
||||
self.assertNotIn("command", plan["profile"])
|
||||
@@ -258,6 +266,122 @@ class OrcSkillTests(unittest.TestCase):
|
||||
remote_auth="none",
|
||||
)
|
||||
|
||||
def test_release_remote_requires_one_identical_fetch_and_push_url(self) -> None:
|
||||
git = shutil.which("git")
|
||||
self.assertIsNotNone(git)
|
||||
assert git is not None
|
||||
git_path = Path(git).resolve()
|
||||
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
root = Path(temporary).resolve()
|
||||
subprocess.run(
|
||||
[str(git_path), "init", "-q", str(root)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
remote = "https://git.yumee.top/laily/musicpilot.git"
|
||||
subprocess.run(
|
||||
[str(git_path), "-C", str(root), "remote", "add", "origin", remote],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
with mock.patch.object(
|
||||
orc_profiles,
|
||||
"resolve_trusted_executable",
|
||||
return_value=git_path,
|
||||
):
|
||||
facts = orc_profiles.resolve_release_remote(root)
|
||||
|
||||
self.assertEqual(facts["fetchUrl"], remote)
|
||||
self.assertEqual(facts["pushUrl"], remote)
|
||||
self.assertEqual(facts["host"], "git.yumee.top")
|
||||
self.assertEqual(facts["networkHosts"], ["git.yumee.top"])
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
str(git_path),
|
||||
"-C",
|
||||
str(root),
|
||||
"config",
|
||||
"remote.origin.pushurl",
|
||||
"https://git.example.invalid/other/repo.git",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
with mock.patch.object(
|
||||
orc_profiles,
|
||||
"resolve_trusted_executable",
|
||||
return_value=git_path,
|
||||
):
|
||||
with self.assertRaisesRegex(
|
||||
orc_profiles.ConfigError,
|
||||
"fetch and push URLs must match",
|
||||
):
|
||||
orc_profiles.resolve_release_remote(root)
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
str(git_path),
|
||||
"-C",
|
||||
str(root),
|
||||
"config",
|
||||
"--add",
|
||||
"remote.origin.pushurl",
|
||||
"https://git.example.invalid/second/repo.git",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
with mock.patch.object(
|
||||
orc_profiles,
|
||||
"resolve_trusted_executable",
|
||||
return_value=git_path,
|
||||
):
|
||||
with self.assertRaisesRegex(
|
||||
orc_profiles.ConfigError,
|
||||
"exactly one push URL",
|
||||
):
|
||||
orc_profiles.resolve_release_remote(root)
|
||||
|
||||
with self.assertRaisesRegex(orc_profiles.ConfigError, "safe remote URL"):
|
||||
orc_profiles._remote_url_facts(
|
||||
"https://git.example.invalid:notaport/repo.git",
|
||||
"test remote",
|
||||
)
|
||||
scp = orc_profiles._remote_url_facts(
|
||||
"git@git.yumee.top:laily/musicpilot.git",
|
||||
"scp remote",
|
||||
)
|
||||
ssh = orc_profiles._remote_url_facts(
|
||||
"ssh://git@git.yumee.top/laily/musicpilot.git",
|
||||
"ssh remote",
|
||||
)
|
||||
self.assertEqual(scp["canonical"], ssh["canonical"])
|
||||
with self.assertRaisesRegex(orc_profiles.ConfigError, "local host"):
|
||||
orc_profiles._remote_url_facts(
|
||||
"https://localhost/laily/musicpilot.git",
|
||||
"local remote",
|
||||
)
|
||||
|
||||
with mock.patch.object(
|
||||
orc_profiles,
|
||||
"_origin_urls",
|
||||
side_effect=[
|
||||
["https://github.com/example/project.git"],
|
||||
["https://github.com/example/project.git"],
|
||||
],
|
||||
), mock.patch.object(
|
||||
orc_profiles,
|
||||
"resolve_trusted_executable",
|
||||
return_value=git_path,
|
||||
):
|
||||
github = orc_profiles.resolve_release_remote(Path("/tmp/project"))
|
||||
self.assertEqual(
|
||||
github["networkHosts"],
|
||||
["github.com", "api.github.com", "uploads.github.com"],
|
||||
)
|
||||
|
||||
def test_ssh_auth_requires_a_trusted_user_socket(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
root = Path(temporary)
|
||||
@@ -410,6 +534,19 @@ class OrcSkillTests(unittest.TestCase):
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
str(git_path),
|
||||
"-C",
|
||||
str(root),
|
||||
"remote",
|
||||
"add",
|
||||
"origin",
|
||||
"https://git.yumee.top/laily/project.git",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
fake_codex = root / "trusted-codex" / "codex"
|
||||
fake_codex.parent.mkdir()
|
||||
fake_codex.write_text("#!/bin/sh\nexit 0\n", encoding="utf-8")
|
||||
@@ -474,6 +611,14 @@ class OrcSkillTests(unittest.TestCase):
|
||||
stage_level="low",
|
||||
)
|
||||
|
||||
release_plan = orc_profiles.build_launch_plan(
|
||||
project_root=root,
|
||||
worktree=root,
|
||||
stage="release",
|
||||
host_cli="codex",
|
||||
stage_level="low",
|
||||
)
|
||||
|
||||
self.assertEqual(plan["argv"][0], str(fake_codex))
|
||||
self.assertEqual(plan["config"]["path"], str(CONFIG))
|
||||
self.assertEqual(cursor_plan["argv"][0], str(fake_cursor))
|
||||
@@ -481,7 +626,20 @@ class OrcSkillTests(unittest.TestCase):
|
||||
self.assertEqual(cursor_plan["argv"][1:3], ["--model", "auto"])
|
||||
self.assertIn("--auto-review", cursor_plan["argv"])
|
||||
self.assertEqual(cursor_plan["modelAuth"], "cursor-login")
|
||||
self.assertEqual(cursor_plan["releaseRemote"]["host"], "git.yumee.top")
|
||||
self.assertIn("--host-cli", cursor_plan["launcherArgv"])
|
||||
release_args = release_plan["workerArgs"]
|
||||
self.assertIn("sandbox_workspace_write.network_access=true", release_args)
|
||||
self.assertIn("features.network_proxy.enabled=true", release_args)
|
||||
self.assertIn("features.network_proxy.allow_upstream_proxy=false", release_args)
|
||||
self.assertIn("features.network_proxy.unix_sockets={}", release_args)
|
||||
self.assertIn(
|
||||
'features.network_proxy.domains={ "git.yumee.top" = "allow" }',
|
||||
release_args,
|
||||
)
|
||||
release_approval = release_args.index("--ask-for-approval")
|
||||
self.assertEqual(release_args[release_approval + 1], "on-request")
|
||||
self.assertIn('approvals_reviewer="auto_review"', release_args)
|
||||
self.assertEqual(plan["terminalCreateArgv"][0], str(fake_orca))
|
||||
self.assertEqual(plan["worktree"], str(root))
|
||||
self.assertEqual(plan["selectionSource"], "request.stage")
|
||||
|
||||
Reference in New Issue
Block a user