Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c400b3a37 |
+11
-19
@@ -56,18 +56,6 @@ def provenance_fingerprint(data):
|
||||
})
|
||||
|
||||
|
||||
def is_laravel_migration_path(value):
|
||||
"""Match files Laravel discovers in supported registered directories."""
|
||||
path = PurePosixPath(value)
|
||||
parts = path.parts
|
||||
application = len(parts) == 3 and parts[:2] == ("database", "migrations")
|
||||
module = (
|
||||
len(parts) == 5 and parts[0].lower() == "modules"
|
||||
and tuple(part.lower() for part in parts[2:4]) == ("database", "migrations")
|
||||
)
|
||||
return (application or module) and "_" in path.stem and path.suffix == ".php"
|
||||
|
||||
|
||||
def validate_migration_path(value, *, modular=False):
|
||||
|
||||
require(
|
||||
@@ -82,8 +70,17 @@ def validate_migration_path(value, *, modular=False):
|
||||
and path.as_posix() == value
|
||||
and ".." not in path.parts
|
||||
and len(path.parts) >= 3
|
||||
and (is_laravel_migration_path(value) if modular
|
||||
else path.parts[:2] == ("database", "migrations"))
|
||||
and (
|
||||
path.parts[:2] == ("database", "migrations")
|
||||
or (
|
||||
modular and len(path.parts) >= 5 and (
|
||||
(path.parts[0] == "Modules"
|
||||
and path.parts[2:4] == ("Database", "Migrations"))
|
||||
or (path.parts[0] == "modules"
|
||||
and path.parts[2:4] == ("database", "migrations"))
|
||||
)
|
||||
)
|
||||
)
|
||||
and path.suffix == ".php"
|
||||
and all(
|
||||
re.fullmatch(
|
||||
@@ -122,14 +119,9 @@ def validate_provenance(data):
|
||||
"Invalid dependency inventory",
|
||||
)
|
||||
|
||||
basenames = set()
|
||||
for name, digest in data["migrations"].items():
|
||||
|
||||
validate_migration_path(name, modular=version == 2)
|
||||
if version == 2:
|
||||
basename = PurePosixPath(name).stem
|
||||
require(basename not in basenames, "Duplicate migration basename")
|
||||
basenames.add(basename)
|
||||
|
||||
require(
|
||||
valid_hash(digest, 64),
|
||||
|
||||
@@ -5,9 +5,7 @@ import os
|
||||
import stat
|
||||
from pathlib import Path
|
||||
|
||||
from core.compatibility import (
|
||||
canonical_hash, is_laravel_migration_path, provenance_fingerprint, validate_provenance,
|
||||
)
|
||||
from core.compatibility import canonical_hash, provenance_fingerprint, validate_provenance
|
||||
from core.provenance import ProvenanceVerifier, require
|
||||
|
||||
|
||||
@@ -60,10 +58,13 @@ class CompleteProvenance(ProvenanceVerifier):
|
||||
expected = {**tracked, **self.generated, "REVISION": marker}
|
||||
require(inventory(release) == expected,
|
||||
"Full release tree differs from authorised source or generated artifacts")
|
||||
evidence["migrations"] = {
|
||||
name: digest for name, (digest, _) in tracked.items()
|
||||
if is_laravel_migration_path(name)
|
||||
}
|
||||
for name, (digest, _) in tracked.items():
|
||||
parts = Path(name).parts
|
||||
if (len(parts) >= 5 and name.endswith(".php") and
|
||||
(parts[0], parts[2], parts[3]) in (
|
||||
("Modules", "Database", "Migrations"), ("modules", "database", "migrations")
|
||||
)):
|
||||
evidence["migrations"][name] = digest
|
||||
evidence.update(format_version=2, source_tree=canonical_hash(expected))
|
||||
evidence["fingerprint"] = provenance_fingerprint(evidence)
|
||||
validate_provenance(evidence)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-after.json
|
||||
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-before.json
|
||||
cc4a6894db5d31b57a686cf8d23b86e1710388b9562df3f4b152fe03b9e1abf6 ./checks.jsonl
|
||||
c692d9943cdf76339c82f6d77bf3e24d8f3b77ba70b8203e687e8104b9b351a1 ./framework-ci.txt
|
||||
c25354dc469de95845d96f00548f745c62cd510e46cdf94ddcdaf139f918b5df ./scope.txt
|
||||
ed2e7da48d89da2c217f5ada21465e98ed08f48d51915105fff5d5b9746f6033 run.sh
|
||||
9d6b8cbf1b02abb9effee48d56dc136b5cb057f19fef33747fa23f299d51064b probe.py
|
||||
@@ -0,0 +1,4 @@
|
||||
{"check": "each site used a distinct project-owned internal network with no published ports", "result": "PASS"}
|
||||
{"check": "local service DNS worked and cross-project service DNS failed in both directions", "result": "PASS"}
|
||||
{"check": "external backend rejected before worker start or PHP restart; no service command ran", "result": "PASS"}
|
||||
{"check": "disposable Compose projects and networks removed", "result": "PASS"}
|
||||
+2
-2
@@ -5,9 +5,9 @@ Python 3.14.4
|
||||
PASS: 88 Python sources compiled
|
||||
|
||||
=== COMPLETE UNIT REGRESSION SUITE ===
|
||||
........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
|
||||
.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
|
||||
----------------------------------------------------------------------
|
||||
Ran 904 tests in 17.685s
|
||||
Ran 903 tests in 17.975s
|
||||
|
||||
OK
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import copy
|
||||
import json
|
||||
import secrets
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from core.services import ServiceError, ServiceLifecycle
|
||||
|
||||
base = json.loads(Path("config/site.example.json").read_text())
|
||||
image_id = "sha256:e742a2668255221388004f3a42b6150a2103f5054ab3a4a93ae9e4f01e551c35"
|
||||
run = secrets.token_hex(5)
|
||||
projects = []
|
||||
|
||||
def cmd(*args):
|
||||
return subprocess.check_output(args, timeout=60, text=True).strip()
|
||||
|
||||
def record(check):
|
||||
print(json.dumps({"check": check, "result": "PASS"}), flush=True)
|
||||
|
||||
def setup(label, external=None):
|
||||
name = f"absdev-topology-{label}-{run}"
|
||||
root = Path.cwd().parent / label
|
||||
root.mkdir()
|
||||
config = copy.deepcopy(base)
|
||||
config["site"].update(identifier=name, root=str(root))
|
||||
config["docker"].update(project=name, backend_network="backend")
|
||||
image = json.loads(cmd("docker", "image", "inspect", image_id))[0]
|
||||
tag = next(t for t in image["RepoTags"] if t.startswith("postgres:"))
|
||||
assert json.loads(cmd("docker", "image", "inspect", tag))[0]["Id"] == image_id
|
||||
topology = {
|
||||
"services": {
|
||||
svc: {"image": tag, "pull_policy": "never", "entrypoint": ["sleep", "300"],
|
||||
"user": "10001:10001", "read_only": True, "cap_drop": ["ALL"],
|
||||
"security_opt": ["no-new-privileges:true"],
|
||||
"networks": {"backend": {"aliases": [name + "-" + svc]}}}
|
||||
for svc in ("queue", "scheduler")
|
||||
},
|
||||
"networks": {"backend": ({"external": True, "name": external} if external
|
||||
else {"internal": True})},
|
||||
}
|
||||
spec = root / "compose.yaml"
|
||||
spec.write_text(json.dumps(topology))
|
||||
prefix = ("docker", "compose", "--project-name", name, "--project-directory", str(root),
|
||||
"--file", str(spec))
|
||||
actions = []
|
||||
def runner(argv, *, timeout):
|
||||
assert argv[:len(prefix)] == prefix
|
||||
actions.append(argv[len(prefix)])
|
||||
return subprocess.run(argv, timeout=timeout, stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL).returncode
|
||||
def topology_runner(argv, *, timeout):
|
||||
assert argv == (*prefix, "config", "--format", "json")
|
||||
return subprocess.check_output(argv, timeout=timeout)
|
||||
lifecycle = ServiceLifecycle(config, runner, topology_runner=topology_runner)
|
||||
if external:
|
||||
resolved = json.loads(topology_runner((*prefix, "config", "--format", "json"), timeout=30))
|
||||
assert resolved["networks"]["backend"]["external"] is True
|
||||
for operation in (lifecycle.resume, lifecycle.restart_php):
|
||||
try:
|
||||
operation()
|
||||
except ServiceError as error:
|
||||
assert "External Compose backend networks" in str(error)
|
||||
else:
|
||||
raise AssertionError("External backend accepted")
|
||||
assert not actions
|
||||
assert not cmd("docker", "ps", "-aq", "--filter", "label=com.docker.compose.project=" + name)
|
||||
return None
|
||||
projects.append(prefix)
|
||||
lifecycle.resume()
|
||||
ids = [cmd(*prefix, "ps", "-q", svc) for svc in ("queue", "scheduler")]
|
||||
network = name + "_backend"
|
||||
details = json.loads(cmd("docker", "network", "inspect", network))[0]
|
||||
assert details["Internal"] and details["Labels"]["com.docker.compose.project"] == name
|
||||
for cid in ids:
|
||||
info = json.loads(cmd("docker", "inspect", cid))[0]
|
||||
assert set(info["NetworkSettings"]["Networks"]) == {network}
|
||||
assert not info["HostConfig"]["PortBindings"] and not info["HostConfig"]["Privileged"]
|
||||
return name, network, ids[0]
|
||||
|
||||
def lookup(cid, host):
|
||||
return subprocess.run(("docker", "exec", cid, "getent", "hosts", host),
|
||||
capture_output=True, timeout=15)
|
||||
|
||||
try:
|
||||
a, anet, ac = setup("alpha")
|
||||
b, bnet, bc = setup("beta")
|
||||
assert anet != bnet
|
||||
record("each site used a distinct project-owned internal network with no published ports")
|
||||
for name, other, cid in ((a, b, ac), (b, a, bc)):
|
||||
assert lookup(cid, name + "-scheduler").returncode == 0
|
||||
denied = lookup(cid, other + "-scheduler")
|
||||
assert denied.returncode == 2 and not denied.stdout
|
||||
record("local service DNS worked and cross-project service DNS failed in both directions")
|
||||
setup("shared-model", external=anet)
|
||||
record("external backend rejected before worker start or PHP restart; no service command ran")
|
||||
finally:
|
||||
for prefix in reversed(projects):
|
||||
cmd(*prefix, "down", "--volumes", "--timeout", "1")
|
||||
record("disposable Compose projects and networks removed")
|
||||
+6
-3
@@ -1,17 +1,20 @@
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
test "$(hostname -s | tr A-Z a-z)" = absdev-ci
|
||||
stage=$(mktemp -d /var/tmp/absdev-modular-fix.XXXXXX)
|
||||
stage=$(mktemp -d /var/tmp/absdev-backend-network.XXXXXX)
|
||||
trap 'rm -rf -- "$stage"' EXIT
|
||||
mkdir "$stage/source" "$stage/evidence" "$stage/tmp"
|
||||
tar -xm -f - -C "$stage/source"
|
||||
cd "$stage/source"
|
||||
export TMPDIR="$stage/tmp"
|
||||
export DOCKER_CONFIG=/var/tmp/absdev-supported-containment.L6qYEi/docker-config
|
||||
out="$stage/evidence"
|
||||
printf 'host=%s\nrevision=5d3ea0d536ee00e4b235f3a195ea39aaf3224b47\n' "$(hostname -s)" > "$out/scope.txt"
|
||||
printf 'host=%s\nrevision=89418ea21ad3d307eff3cbadc978687a48e572ce\n' "$(hostname -s)" > "$out/scope.txt"
|
||||
docker compose version >> "$out/scope.txt"
|
||||
sha256sum "$DOCKER_CONFIG/cli-plugins/docker-compose" >> "$out/scope.txt"
|
||||
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-before.json"
|
||||
python3 -B -c 'import json,sys; d=json.load(open(sys.argv[1])); f=[v for k,v in d.items() if k.endswith("_enabled") or k=="production_ready"]; assert len(f)==6 and all(v is False for v in f)' "$out/capabilities-before.json"
|
||||
python3 -B probe.py > "$out/laravel-inventory.json" || { cat "$out/laravel-inventory.json" >&2; exit 1; }
|
||||
python3 -B probe.py > "$out/checks.jsonl" || { cat "$out/checks.jsonl" >&2; exit 1; }
|
||||
bash scripts/ci-check.sh > "$out/framework-ci.txt" 2>&1 || { tail -80 "$out/framework-ci.txt" >&2; exit 1; }
|
||||
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-after.json"
|
||||
cmp "$out/capabilities-before.json" "$out/capabilities-after.json"
|
||||
@@ -0,0 +1,4 @@
|
||||
host=absdev-ci
|
||||
revision=89418ea21ad3d307eff3cbadc978687a48e572ce
|
||||
Docker Compose version 2.40.3+ds1-0ubuntu1
|
||||
93226cc2ea191353641921350ad87d96cb942e29a21c7c68c430adfd9954af34 /var/tmp/absdev-supported-containment.L6qYEi/docker-config/cli-plugins/docker-compose
|
||||
@@ -1,8 +0,0 @@
|
||||
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-after.json
|
||||
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-before.json
|
||||
bc04e0a24a001d2ef37d4094f5528b70b244ea8fa4261e3ba5d9f43ad8d00b14 ./framework-ci.txt
|
||||
4afcae0a0d3824b06cbbc2762d974c26b5b18df0c3a3c90956c177c594c32d48 ./laravel-inventory.json
|
||||
4e788c450803b53914390e85812231c5c1405d6ccd69a2f5aba4910068426c0f ./scope.txt
|
||||
54f8a44945572514c3c6416c4a09aa0297adca7da2296dfe5bb27a8161642683 run.sh
|
||||
dc8cd7dc91e7bd20c766c5c7e6613aec2cdf4e2eae3d899d77a1118eb77d7a9f probe.py
|
||||
41b745079ac469f8134f3f010a457bc689dbac0750fcf3426a23199b693f0ec1 inventory.php
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
require '/deps/vendor/autoload.php';
|
||||
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
$reflection = new ReflectionClass(Migrator::class);
|
||||
$migrator = $reflection->newInstanceWithoutConstructor();
|
||||
$reflection->getProperty('files')->setValue($migrator, new Filesystem());
|
||||
$paths = array_map(fn ($path) => '/release/'.$path, array_slice($argv, 1));
|
||||
$files = $migrator->getMigrationFiles($paths);
|
||||
$relative = array_map(fn ($file) => substr($file, strlen('/release/')), $files);
|
||||
echo json_encode([
|
||||
'version' => Composer\InstalledVersions::getPrettyVersion('laravel/framework'),
|
||||
'migrations' => $relative,
|
||||
], JSON_THROW_ON_ERROR);
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"host": "ABSDEV-CI",
|
||||
"laravel_version": "v13.44.1",
|
||||
"laravel_inventory": {
|
||||
"0001_create_users": "database/migrations/0001_create_users.php",
|
||||
"0002_create_orders": "database/migrations/0002_create_orders.php",
|
||||
"0003_add_order_details": "Modules/Orders/Database/Migrations/0003_add_order_details.php",
|
||||
"0004_add_product_details": "modules/products/database/migrations/0004_add_product_details.php",
|
||||
"0005_add_billing_details": "Modules/Billing/database/Migrations/0005_add_billing_details.php"
|
||||
},
|
||||
"framework_inventory": {
|
||||
"Modules/Billing/database/Migrations/0005_add_billing_details.php": "7492c4624ace05175e795841a2a1f9d91e46af66f0d0b6f5990387b4da32a756",
|
||||
"Modules/Orders/Database/Migrations/0003_add_order_details.php": "7492c4624ace05175e795841a2a1f9d91e46af66f0d0b6f5990387b4da32a756",
|
||||
"database/migrations/0001_create_users.php": "6b1c4722e1ab3ac3588b0a75a4a29e0a29da049e0db7feaf92d1405a7569b18d",
|
||||
"database/migrations/0002_create_orders.php": "098b1d49c2865a6c7dc1a918821404abd5acedc013482572a2b764147f56051f",
|
||||
"modules/products/database/migrations/0004_add_product_details.php": "7492c4624ace05175e795841a2a1f9d91e46af66f0d0b6f5990387b4da32a756"
|
||||
},
|
||||
"mixed_case_and_standard_paths_match_laravel": true,
|
||||
"nonmatching_and_nested_files_excluded": true,
|
||||
"laravel_collision_collapses_to_one_basename": true,
|
||||
"framework_rejected_duplicate_basename": true,
|
||||
"migrations_executed": false
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
import hashlib
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path("tests/unit").resolve()))
|
||||
from test_provenance import ProvenanceTests
|
||||
from core.compatibility import CompatibilityError
|
||||
from core.dev3.provenance import CompleteProvenance
|
||||
|
||||
IMAGE = "sha256:cac70f6c4aa761a1c04c6813c03a7678b9a5c061cc67a413a12736253e7128ee"
|
||||
DEPS = "/var/tmp/absdev-dev3-ci.8yBxcV/public-fixture"
|
||||
DIRS = [
|
||||
"database/migrations",
|
||||
"Modules/Orders/Database/Migrations",
|
||||
"modules/products/database/migrations",
|
||||
"Modules/Billing/database/Migrations",
|
||||
]
|
||||
fixture = ProvenanceTests()
|
||||
|
||||
def write(path):
|
||||
for root in (fixture.repository, fixture.release):
|
||||
entry = root / path
|
||||
entry.parent.mkdir(parents=True, exist_ok=True)
|
||||
entry.write_text("<?php // disposable migration inventory fixture\n")
|
||||
|
||||
def commit():
|
||||
fixture.git("add", ".")
|
||||
fixture.git("commit", "-qm", "Update disposable Laravel fixture")
|
||||
revision = fixture.git("rev-parse", "HEAD").strip()
|
||||
(fixture.release / "REVISION").write_text(revision + "\n")
|
||||
return CompleteProvenance(fixture.repository, [revision], {})
|
||||
|
||||
def laravel_inventory():
|
||||
result = subprocess.run([
|
||||
"docker", "run", "--rm", "--pull", "never", "--network", "none",
|
||||
"--read-only", "--cap-drop", "ALL", "--cap-add", "DAC_OVERRIDE", "--security-opt", "no-new-privileges",
|
||||
"-v", f"{DEPS}:/deps:ro", "-v", f"{fixture.release}:/release:ro",
|
||||
"-v", f"{Path('inventory.php').resolve()}:/fixture.php:ro",
|
||||
"--entrypoint", "php", IMAGE, "/fixture.php", *DIRS,
|
||||
], timeout=60, capture_output=True)
|
||||
if result.returncode:
|
||||
raise RuntimeError((result.stdout + result.stderr).decode(errors="replace")[:1500])
|
||||
return json.loads(result.stdout)
|
||||
|
||||
try:
|
||||
fixture.setUp()
|
||||
declared = [
|
||||
DIRS[1] + "/0003_add_order_details.php",
|
||||
DIRS[2] + "/0004_add_product_details.php",
|
||||
DIRS[3] + "/0005_add_billing_details.php",
|
||||
]
|
||||
ignored = [DIRS[3] + "/README.php", DIRS[3] + "/nested/0006_ignored.php",
|
||||
DIRS[0] + "/nested/0007_ignored.php"]
|
||||
for path in declared + ignored:
|
||||
write(path)
|
||||
provenance = commit().verify(fixture.release)["migrations"]
|
||||
observed = laravel_inventory()
|
||||
expected = {path: hashlib.sha256((fixture.release / path).read_bytes()).hexdigest()
|
||||
for path in observed["migrations"].values()}
|
||||
assert provenance == expected and set(declared) <= set(expected)
|
||||
assert not set(ignored) & set(expected)
|
||||
duplicate = DIRS[3] + "/0003_add_order_details.php"
|
||||
write(duplicate)
|
||||
collision = commit()
|
||||
overwritten = laravel_inventory()
|
||||
assert overwritten["migrations"]["0003_add_order_details"] == duplicate
|
||||
try:
|
||||
collision.verify(fixture.release)
|
||||
except CompatibilityError as error:
|
||||
assert "Duplicate migration basename" in str(error)
|
||||
else:
|
||||
raise AssertionError("Duplicate migration accepted")
|
||||
print(json.dumps({
|
||||
"host": "ABSDEV-CI",
|
||||
"laravel_version": observed["version"],
|
||||
"laravel_inventory": observed["migrations"],
|
||||
"framework_inventory": provenance,
|
||||
"mixed_case_and_standard_paths_match_laravel": True,
|
||||
"nonmatching_and_nested_files_excluded": True,
|
||||
"laravel_collision_collapses_to_one_basename": True,
|
||||
"framework_rejected_duplicate_basename": True,
|
||||
"migrations_executed": False,
|
||||
}, indent=2))
|
||||
finally:
|
||||
fixture.doCleanups()
|
||||
@@ -1,2 +0,0 @@
|
||||
host=absdev-ci
|
||||
revision=5d3ea0d536ee00e4b235f3a195ea39aaf3224b47
|
||||
@@ -20,21 +20,3 @@ class InventoryTests(unittest.TestCase):
|
||||
(root / "link").symlink_to(script)
|
||||
with self.assertRaises(ProvenanceError):
|
||||
inventory(root)
|
||||
|
||||
|
||||
class LaravelMigrationPathTests(unittest.TestCase):
|
||||
def test_inventory_matches_registered_directory_globs(self):
|
||||
from core.compatibility import is_laravel_migration_path
|
||||
|
||||
for path in (
|
||||
"Modules/Billing/database/Migrations/0001_add_invoice.php",
|
||||
"modules/Orders/Database/migrations/0002_add_order.php",
|
||||
"database/migrations/0003_add_user.php",
|
||||
):
|
||||
self.assertTrue(is_laravel_migration_path(path), path)
|
||||
for path in (
|
||||
"Modules/Billing/database/Migrations/nested/0001_add_invoice.php",
|
||||
"database/migrations/README.php",
|
||||
"database/migrations/nested/0003_add_user.php",
|
||||
):
|
||||
self.assertFalse(is_laravel_migration_path(path), path)
|
||||
|
||||
Reference in New Issue
Block a user