Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion .agents/skills/monitor-ci-results/scripts/monitor_remote_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,66 @@ def main():
with open(state_file, "w") as f:
json.dump(monitored, f)

# Check if all CI checks and jobs are finished and passed
if checks:
all_completed = True
any_failed = False
total_passed = 0

for check in checks:
state = check.get("state", "UNKNOWN")
name = check.get("name", "")
link = check.get("link", "")
if "buildkite" in name.lower() and link:
jobs = get_buildkite_jobs(link)
if not jobs:
all_completed = False
for job in jobs:
jstate = job.get("state", "unknown")
exit_status = job.get("exit_status")
is_soft_failed = job.get("soft_failed") is True
is_failed = (
jstate in ["failed", "failing"]
or (exit_status != 0 and exit_status is not None)
) and not is_soft_failed
is_passed = (
jstate in ["passed", "success"]
or (jstate == "finished" and exit_status == 0)
or is_soft_failed
)
if is_failed:
any_failed = True
elif is_passed:
total_passed += 1
else:
all_completed = False
else:
if state in ["SUCCESS", "success"]:
total_passed += 1
elif state in ["FAILURE", "failed"]:
any_failed = True
elif state in ["PENDING", "IN_PROGRESS", "queued", "running"]:
all_completed = False

if all_completed and not any_failed and total_passed > 0:
print(
f"✅ All {total_passed} remote CI checks for PR #{args.pr} PASSED!"
)
msg = f"✅ Remote CI checks for PR #{args.pr} completed successfully! ({total_passed} checks passed)"
subprocess.run(
[
"agentapi",
"send-message",
"--title=CI Checks Passed",
args.conv_id,
msg,
]
)
break

time.sleep(args.interval)

print("🏁 CI monitoring service completed its scheduled iterations.")
print("🏁 CI monitoring service completed.")


if __name__ == "__main__":
Expand Down
12 changes: 8 additions & 4 deletions tests/tools/zipapp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
load("//python:py_test.bzl", "py_test")
load("//tests/support:support.bzl", "SUPPORTS_BZLMOD")
load("//tests/support/pytest_test:pytest_test.bzl", "pytest_test")

py_test(
pytest_test(
name = "zipper_test",
srcs = ["zipper_test.py"],
target_compatible_with = SUPPORTS_BZLMOD,
deps = ["//tools/private/zipapp:zipper_lib"],
)

py_test(
pytest_test(
name = "exe_zip_maker_test",
srcs = ["exe_zip_maker_test.py"],
target_compatible_with = SUPPORTS_BZLMOD,
deps = ["//tools/private/zipapp:exe_zip_maker_lib"],
)

py_test(
pytest_test(
name = "zip_main_maker_test",
srcs = ["zip_main_maker_test.py"],
target_compatible_with = SUPPORTS_BZLMOD,
deps = ["//tools/private/zipapp:zip_main_maker_lib"],
)
87 changes: 31 additions & 56 deletions tests/tools/zipapp/exe_zip_maker_test.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,46 @@
import hashlib
import pathlib
import shutil
import stat
import tempfile
import unittest

from tools.private.zipapp import exe_zip_maker


class ExeZipMakerTest(unittest.TestCase):
def setUp(self):
self.test_dir = pathlib.Path(tempfile.mkdtemp())
self.preamble_path = self.test_dir / "preamble.txt"
self.zip_path = self.test_dir / "data.zip"
self.output_path = self.test_dir / "output.exe"
def test_create_exe_zip(tmp_path):
preamble_path = tmp_path / "preamble.txt"
zip_path = tmp_path / "data.zip"
output_path = tmp_path / "output.exe"

def tearDown(self):
shutil.rmtree(self.test_dir)
# Create dummy zip file
zip_content = b"PK\x03\x04dummyzipcontent"
zip_path.write_bytes(zip_content)

def assertStartsWith(self, actual, expected):
if not actual.startswith(expected):
self.fail(f"{actual!r} does not start with {expected!r}")
# Calculate expected hash
expected_hash = hashlib.sha256(zip_content).hexdigest().encode("utf-8")

def test_create_exe_zip(self):
# Create dummy zip file
zip_content = b"PK\x03\x04dummyzipcontent"
self.zip_path.write_bytes(zip_content)
# Create preamble with placeholder
preamble_text = b"#!/bin/bash\nEXPECTED_HASH='%ZIP_HASH%'\n# ... logic ...\n"
preamble_path.write_bytes(preamble_text)

# Calculate expected hash
expected_hash = hashlib.sha256(zip_content).hexdigest().encode("utf-8")
# Call create_exe_zip directly
exe_zip_maker.create_exe_zip(str(preamble_path), str(zip_path), str(output_path))

# Create preamble with placeholder
preamble_text = b"#!/bin/bash\nEXPECTED_HASH='%ZIP_HASH%'\n# ... logic ...\n"
self.preamble_path.write_bytes(preamble_text)
# Verify output exists
assert output_path.exists(), f"Output path '{output_path}' should exist"

# Call create_exe_zip directly
exe_zip_maker.create_exe_zip(
str(self.preamble_path), str(self.zip_path), str(self.output_path)
)
# Verify executable bit
st = output_path.stat()
assert st.st_mode & stat.S_IEXEC, (
f"Output path '{output_path}' should be executable"
)

# Verify output exists
self.assertTrue(
self.output_path.exists(),
msg=f"Output path '{self.output_path}' should exist",
)
# Verify content
content = output_path.read_bytes()

# Verify executable bit
st = self.output_path.stat()
self.assertTrue(
st.st_mode & stat.S_IEXEC,
msg=f"Output path '{self.output_path}' should be executable",
)
# Split content back into preamble and zip
# We know the preamble text length after substitution.
expected_preamble = preamble_text.replace(b"%ZIP_HASH%", expected_hash)

# Verify content
content = self.output_path.read_bytes()

# Split content back into preamble and zip
# We know the preamble text length after substitution.
expected_preamble = preamble_text.replace(b"%ZIP_HASH%", expected_hash)

self.assertStartsWith(content, expected_preamble)
self.assertTrue(
content.endswith(zip_content),
msg="Output content should end with the zip content",
)
self.assertEqual(len(content), len(expected_preamble) + len(zip_content))


if __name__ == "__main__":
unittest.main()
assert content.startswith(expected_preamble)
assert content.endswith(zip_content), (
"Output content should end with the zip content"
)
assert len(content) == len(expected_preamble) + len(zip_content)
169 changes: 79 additions & 90 deletions tests/tools/zipapp/zip_main_maker_test.py
Original file line number Diff line number Diff line change
@@ -1,101 +1,90 @@
import hashlib
import os
import tempfile
import unittest
from unittest import mock

from tools.private.zipapp import zip_main_maker


class ZipMainMakerTest(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.TemporaryDirectory()
self.addCleanup(self.temp_dir.cleanup)

def test_creates_zip_main(self):
template_path = os.path.join(self.temp_dir.name, "template.py")
with open(template_path, "w", encoding="utf-8") as f:
f.write("hash=%APP_HASH%\nfoo=%FOO%\n")

output_path = os.path.join(self.temp_dir.name, "output.py")

file1_path = os.path.join(self.temp_dir.name, "file1.txt")
with open(file1_path, "wb") as f:
f.write(b"content1")

file2_path = os.path.join(self.temp_dir.name, "file2.txt")
with open(file2_path, "wb") as f:
f.write(b"content2")

# Add a symlink to test symlink hashing
symlink_path = os.path.join(self.temp_dir.name, "symlink.txt")
os.symlink(file1_path, symlink_path)

manifest_path = os.path.join(self.temp_dir.name, "manifest.txt")
with open(manifest_path, "w", encoding="utf-8") as f:
f.write(f"rf-file|0|file1.txt|{file1_path}\n")
f.write(f"rf-file|0|file2.txt|{file2_path}\n")
f.write(f"rf-symlink|1|symlink.txt|{symlink_path}\n")
f.write("rf-empty|empty_file.txt\n")

argv = [
"zip_main_maker.py",
"--template",
template_path,
"--output",
output_path,
"--substitution",
"%FOO%=bar",
"--hash_files_manifest",
manifest_path,
]

with mock.patch("sys.argv", argv):
zip_main_maker.main()

# Calculate expected hash
h = hashlib.sha256()
line1 = f"rf-file|0|file1.txt|{file1_path}"
line2 = f"rf-file|0|file2.txt|{file2_path}"
line3 = f"rf-symlink|1|symlink.txt|{symlink_path}"
line4 = "rf-empty|empty_file.txt"

# Sort lines like the program does
lines = sorted([line1, line2, line3, line4])
for line in lines:
parts = line.split("|")
if len(parts) > 1:
_, rest = line.split("|", 1)
h.update(rest.encode("utf-8"))
else:
h.update(line.encode("utf-8"))

type_ = parts[0]
if type_ == "rf-empty":
def test_creates_zip_main(tmp_path, monkeypatch):
temp_dir = str(tmp_path)
template_path = os.path.join(temp_dir, "template.py")
with open(template_path, "w", encoding="utf-8") as f:
f.write("hash=%APP_HASH%\nfoo=%FOO%\n")

output_path = os.path.join(temp_dir, "output.py")

file1_path = os.path.join(temp_dir, "file1.txt")
with open(file1_path, "wb") as f:
f.write(b"content1")

file2_path = os.path.join(temp_dir, "file2.txt")
with open(file2_path, "wb") as f:
f.write(b"content2")

# Add a symlink to test symlink hashing
symlink_path = os.path.join(temp_dir, "symlink.txt")
os.symlink(file1_path, symlink_path)

manifest_path = os.path.join(temp_dir, "manifest.txt")
with open(manifest_path, "w", encoding="utf-8") as f:
f.write(f"rf-file|0|file1.txt|{file1_path}\n")
f.write(f"rf-file|0|file2.txt|{file2_path}\n")
f.write(f"rf-symlink|1|symlink.txt|{symlink_path}\n")
f.write("rf-empty|empty_file.txt\n")

argv = [
"zip_main_maker.py",
"--template",
template_path,
"--output",
output_path,
"--substitution",
"%FOO%=bar",
"--hash_files_manifest",
manifest_path,
]

monkeypatch.setattr("sys.argv", argv)
zip_main_maker.main()

# Calculate expected hash
h = hashlib.sha256()
line1 = f"rf-file|0|file1.txt|{file1_path}"
line2 = f"rf-file|0|file2.txt|{file2_path}"
line3 = f"rf-symlink|1|symlink.txt|{symlink_path}"
line4 = "rf-empty|empty_file.txt"

# Sort lines like the program does
lines = sorted([line1, line2, line3, line4])
for line in lines:
parts = line.split("|")
if len(parts) > 1:
_, rest = line.split("|", 1)
h.update(rest.encode("utf-8"))
else:
h.update(line.encode("utf-8"))

type_ = parts[0]
if type_ == "rf-empty":
continue
if len(parts) >= 4:
is_symlink_str = parts[1]
path = parts[-1]
if not path:
continue
if len(parts) >= 4:
is_symlink_str = parts[1]
path = parts[-1]
if not path:
continue
if is_symlink_str == "-1":
is_symlink = not os.path.exists(path)
else:
is_symlink = is_symlink_str == "1"

if is_symlink:
h.update(os.readlink(path).encode("utf-8"))
else:
with open(path, "rb") as f:
h.update(f.read())

expected_hash = h.hexdigest()
if is_symlink_str == "-1":
is_symlink = not os.path.exists(path)
else:
is_symlink = is_symlink_str == "1"

with open(output_path, "r", encoding="utf-8") as f:
content = f.read()
if is_symlink:
h.update(os.readlink(path).encode("utf-8"))
else:
with open(path, "rb") as f:
h.update(f.read())

self.assertEqual(content, f"hash={expected_hash}\nfoo=bar\n")
expected_hash = h.hexdigest()

with open(output_path, "r", encoding="utf-8") as f:
content = f.read()

if __name__ == "__main__":
unittest.main()
assert content == f"hash={expected_hash}\nfoo=bar\n"
Loading