test: migrate deployment smoke fixtures to the P1.1 layout
This commit is contained in:
@@ -243,6 +243,157 @@ workspace_registry_smoke_self_test_cleanup_failure_path() {
|
||||
echo "workspace registry smoke cleanup failure-path self-test passed"
|
||||
}
|
||||
|
||||
workspace_registry_smoke_metadata() {
|
||||
local fixture="$1"
|
||||
awk '
|
||||
/^workspace:[[:space:]]*$/ { in_workspace = 1; next }
|
||||
in_workspace && /^[^[:space:]]/ { in_workspace = 0 }
|
||||
in_workspace && /^ id:[[:space:]]*/ {
|
||||
sub(/^ id:[[:space:]]*/, "")
|
||||
id = $0
|
||||
next
|
||||
}
|
||||
in_workspace && /^ name:[[:space:]]*/ {
|
||||
sub(/^ name:[[:space:]]*/, "")
|
||||
name = $0
|
||||
next
|
||||
}
|
||||
in_workspace && /^ description:[[:space:]]*/ {
|
||||
sub(/^ description:[[:space:]]*/, "")
|
||||
description = $0
|
||||
next
|
||||
}
|
||||
END {
|
||||
if (id == "" || name == "") exit 1
|
||||
print id
|
||||
print name
|
||||
if (description != "") print description
|
||||
}
|
||||
' "$fixture"
|
||||
}
|
||||
|
||||
workspace_registry_smoke_write_catalog() {
|
||||
local catalog_path="$1" id="$2" name="$3" description="${4:-}"
|
||||
{
|
||||
printf 'schema_version: 1
|
||||
'
|
||||
printf 'workspaces:
|
||||
'
|
||||
printf ' - id: %s
|
||||
' "$id"
|
||||
printf ' name: %s
|
||||
' "$name"
|
||||
if [[ -n "$description" ]]; then
|
||||
printf ' description: %s
|
||||
' "$description"
|
||||
fi
|
||||
} >"$catalog_path"
|
||||
}
|
||||
|
||||
workspace_registry_smoke_replace_once() {
|
||||
local target="$1" old="$2" new="$3"
|
||||
python3 - "$target" "$old" "$new" <<'PY'
|
||||
from pathlib import Path
|
||||
import sys
|
||||
path = Path(sys.argv[1])
|
||||
old = sys.argv[2]
|
||||
new = sys.argv[3]
|
||||
text = path.read_text()
|
||||
count = text.count(old)
|
||||
if count != 1:
|
||||
raise SystemExit(f"expected exactly one occurrence of {old!r} in {path}, found {count}")
|
||||
path.write_text(text.replace(old, new, 1))
|
||||
PY
|
||||
}
|
||||
|
||||
workspace_registry_smoke_seed_fixture() {
|
||||
local fixture="$1" metadata
|
||||
mapfile -t metadata < <(workspace_registry_smoke_metadata "$fixture")
|
||||
workspace_registry_smoke_id="${metadata[0]}"
|
||||
workspace_registry_smoke_name="${metadata[1]}"
|
||||
workspace_registry_smoke_description="${metadata[2]-}"
|
||||
|
||||
mkdir -p "$seed/$workspace_registry_smoke_id"
|
||||
cp "$fixture" "$seed/$workspace_registry_smoke_id/workspace.yaml"
|
||||
workspace_registry_smoke_write_catalog "$seed/thoth-workspaces.yaml" "$workspace_registry_smoke_id" "$workspace_registry_smoke_name" "$workspace_registry_smoke_description"
|
||||
if grep -Fq 'type: filesystem' "$fixture"; then
|
||||
mkdir -p "$seed/$workspace_registry_smoke_id/evidence"
|
||||
printf 'guide v1\n' >"$seed/$workspace_registry_smoke_id/evidence/guide.md"
|
||||
fi
|
||||
}
|
||||
|
||||
workspace_registry_smoke_commit() {
|
||||
local message="$1"
|
||||
git -C "$seed" add -A >/dev/null
|
||||
git -C "$seed" -c user.name='Workspace Registry Smoke' -c user.email='workspace-registry-smoke@example.invalid' commit -m "$message" >/dev/null
|
||||
git -C "$seed" push ${2:-origin} "HEAD:$branch" >/dev/null
|
||||
}
|
||||
|
||||
workspace_registry_smoke_prepare_fixture() {
|
||||
git init --bare --initial-branch=main "$remote" >/dev/null
|
||||
git clone "$remote" "$seed" >/dev/null
|
||||
git -C "$seed" checkout -b "$branch" >/dev/null
|
||||
workspace_registry_smoke_seed_fixture "$root/scripts/fixtures/workspace-registry-smoke.yaml"
|
||||
workspace_registry_smoke_commit 'Seed workspace registry smoke'
|
||||
}
|
||||
|
||||
workspace_registry_smoke_registry_head() {
|
||||
printf '%s' "$1" | sed -n 's/.*"head":"\([0-9a-f]*\)".*/\1/p'
|
||||
}
|
||||
|
||||
workspace_registry_smoke_reset_seed() {
|
||||
local commit="$1"
|
||||
git -C "$seed" reset --hard "$commit" >/dev/null
|
||||
git -C "$seed" push --force origin "HEAD:$branch" >/dev/null
|
||||
}
|
||||
|
||||
workspace_registry_smoke_fixtures_only() {
|
||||
local descriptor_path catalog_path initial_head updated_head
|
||||
workspace_registry_smoke_prepare_fixture
|
||||
descriptor_path="$seed/$workspace_registry_smoke_id/workspace.yaml"
|
||||
catalog_path="$seed/thoth-workspaces.yaml"
|
||||
|
||||
[[ -f "$catalog_path" ]] || { echo 'missing root workspace catalog' >&2; return 1; }
|
||||
[[ -f "$descriptor_path" ]] || { echo 'missing nested workspace descriptor' >&2; return 1; }
|
||||
[[ -f "$seed/$workspace_registry_smoke_id/evidence/guide.md" ]] || { echo 'missing nested workspace evidence' >&2; return 1; }
|
||||
[[ ! -e "$seed/workspaces/$workspace_registry_smoke_id.yaml" ]] || { echo 'legacy flat descriptor path was created' >&2; return 1; }
|
||||
[[ ! -e "$seed/workspace-content/$workspace_registry_smoke_id" ]] || { echo 'legacy flat evidence path was created' >&2; return 1; }
|
||||
grep -Fq 'schema_version: 1' "$catalog_path"
|
||||
grep -Fq 'name: Local' "$catalog_path"
|
||||
grep -Fq 'description: Isolated workspace registry smoke fixture.' "$catalog_path"
|
||||
|
||||
initial_head="$(git -C "$seed" rev-parse HEAD)"
|
||||
workspace_registry_smoke_replace_once "$descriptor_path" 'name: Local' 'name: Local Updated'
|
||||
workspace_registry_smoke_replace_once "$catalog_path" 'name: Local' 'name: Local Updated'
|
||||
workspace_registry_smoke_commit 'Update workspace registry smoke metadata'
|
||||
updated_head="$(git -C "$seed" rev-parse HEAD)"
|
||||
[[ "$updated_head" != "$initial_head" ]] || { echo 'metadata co-commit did not advance Git head' >&2; return 1; }
|
||||
grep -Fq 'name: Local Updated' "$descriptor_path"
|
||||
grep -Fq 'name: Local Updated' "$catalog_path"
|
||||
|
||||
printf 'guide v2\n' >"$seed/$workspace_registry_smoke_id/evidence/guide.md"
|
||||
workspace_registry_smoke_commit 'Update workspace registry smoke evidence only'
|
||||
[[ "$(git -C "$seed" rev-parse HEAD)" != "$updated_head" ]] || { echo 'evidence-only commit did not advance Git head' >&2; return 1; }
|
||||
|
||||
mkdir -p "$seed/orphan"
|
||||
cp "$descriptor_path" "$seed/orphan/workspace.yaml"
|
||||
workspace_registry_smoke_replace_once "$seed/orphan/workspace.yaml" 'id: local' 'id: orphan'
|
||||
workspace_registry_smoke_replace_once "$seed/orphan/workspace.yaml" 'name: Local Updated' 'name: Orphan Workspace'
|
||||
workspace_registry_smoke_replace_once "$seed/orphan/workspace.yaml" 'collection: local' 'collection: orphan'
|
||||
workspace_registry_smoke_replace_once "$seed/orphan/workspace.yaml" 'uri: local/evidence' 'uri: orphan/evidence'
|
||||
mkdir -p "$seed/orphan/evidence"
|
||||
printf 'orphan guide\n' >"$seed/orphan/evidence/guide.md"
|
||||
[[ -f "$seed/orphan/workspace.yaml" ]] || { echo 'orphan descriptor was not created' >&2; return 1; }
|
||||
|
||||
mkdir -p "$seed/workspaces" "$seed/workspace-content/$workspace_registry_smoke_id/evidence"
|
||||
cp "$root/scripts/fixtures/workspace-registry-smoke.yaml" "$seed/workspaces/$workspace_registry_smoke_id.yaml"
|
||||
printf 'legacy guide\n' >"$seed/workspace-content/$workspace_registry_smoke_id/evidence/guide.md"
|
||||
[[ -f "$seed/workspaces/$workspace_registry_smoke_id.yaml" ]] || { echo 'legacy flat descriptor fixture missing' >&2; return 1; }
|
||||
[[ -f "$seed/workspace-content/$workspace_registry_smoke_id/evidence/guide.md" ]] || { echo 'legacy flat evidence fixture missing' >&2; return 1; }
|
||||
|
||||
echo 'workspace registry smoke fixture contract passed'
|
||||
}
|
||||
|
||||
case "${WORKSPACE_REGISTRY_SMOKE_SELF_TEST:-}" in
|
||||
"") ;;
|
||||
image-cleanup-identity)
|
||||
@@ -265,6 +416,12 @@ case "${WORKSPACE_REGISTRY_SMOKE_SELF_TEST:-}" in
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "${1:-}" == "--fixtures-only" ]]; then
|
||||
workspace_registry_smoke_fixtures_only
|
||||
rm -rf "$tmp"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
trap cleanup EXIT
|
||||
trap 'exit 129' HUP
|
||||
trap 'exit 130' INT
|
||||
@@ -288,15 +445,7 @@ if [[ -n "${WORKSPACE_GIT_REMOTE:-}" ]]; then
|
||||
fi
|
||||
|
||||
echo "== Seed isolated workspace registry =="
|
||||
git init --bare --initial-branch=main "$remote" >/dev/null
|
||||
git clone "$remote" "$seed" >/dev/null
|
||||
git -C "$seed" checkout -b "$branch" >/dev/null
|
||||
mkdir -p "$seed/workspaces"
|
||||
cp "$root/scripts/fixtures/workspace-registry-smoke.yaml" "$seed/workspaces/local.yaml"
|
||||
git -C "$seed" add workspaces/local.yaml
|
||||
git -C "$seed" -c user.name='Workspace Registry Smoke' -c user.email='workspace-registry-smoke@example.invalid' \
|
||||
commit -m 'Seed workspace registry smoke' >/dev/null
|
||||
git -C "$seed" push origin "HEAD:$branch" >/dev/null
|
||||
workspace_registry_smoke_prepare_fixture
|
||||
|
||||
echo "== Build and start isolated Compose core =="
|
||||
compose up -d --build
|
||||
@@ -310,35 +459,84 @@ core_remote="/fixtures/offline.git"
|
||||
compose up -d --force-recreate
|
||||
wait_for_core
|
||||
recreated_status="$(compose exec -T core curl -fsS http://127.0.0.1:8787/workspace-registry/status)"
|
||||
initial_head="$(printf '%s' "$initial_status" | sed -n 's/.*"head":"\([0-9a-f]*\)".*/\1/p')"
|
||||
recreated_head="$(printf '%s' "$recreated_status" | sed -n 's/.*"head":"\([0-9a-f]*\)".*/\1/p')"
|
||||
initial_head="$(workspace_registry_smoke_registry_head "$initial_status")"
|
||||
recreated_head="$(workspace_registry_smoke_registry_head "$recreated_status")"
|
||||
test -n "$initial_head" && test "$initial_head" = "$recreated_head"
|
||||
printf '%s' "$recreated_status" | grep -Fq '"degraded":true'
|
||||
compose exec -T core curl -fsS http://127.0.0.1:8787/workspaces | grep -Fq 'Local'
|
||||
|
||||
echo "== Pull a valid remote update =="
|
||||
sed -i.bak 's/name: Local/name: Local Updated/' "$seed/workspaces/local.yaml"
|
||||
rm "$seed/workspaces/local.yaml.bak"
|
||||
git -C "$seed" add workspaces/local.yaml
|
||||
git -C "$seed" -c user.name='Workspace Registry Smoke' -c user.email='workspace-registry-smoke@example.invalid' \
|
||||
commit -m 'Update workspace registry smoke' >/dev/null
|
||||
git -C "$seed" push origin "HEAD:$branch" >/dev/null
|
||||
echo "== Pull a valid catalog+descriptor metadata update =="
|
||||
workspace_registry_smoke_replace_once "$seed/$workspace_registry_smoke_id/workspace.yaml" 'name: Local' 'name: Local Updated'
|
||||
workspace_registry_smoke_replace_once "$seed/thoth-workspaces.yaml" 'name: Local' 'name: Local Updated'
|
||||
workspace_registry_smoke_commit 'Update workspace registry smoke metadata'
|
||||
core_remote="/fixtures/remote.git"
|
||||
compose up -d --force-recreate
|
||||
wait_for_core
|
||||
compose exec -T core curl -fsS -X POST http://127.0.0.1:8787/workspace-registry/pull | grep -Eq '"head":"[0-9a-f]{40}"'
|
||||
valid_status="$(compose exec -T core curl -fsS -X POST http://127.0.0.1:8787/workspace-registry/pull)"
|
||||
valid_head="$(workspace_registry_smoke_registry_head "$valid_status")"
|
||||
[[ "$valid_head" =~ ^[0-9a-f]{40}$ && "$valid_head" != "$initial_head" ]]
|
||||
compose exec -T core curl -fsS http://127.0.0.1:8787/workspaces | grep -Fq 'Local Updated'
|
||||
good_seed_commit="$(git -C "$seed" rev-parse HEAD)"
|
||||
|
||||
echo "== Reject invalid remote content and retain the last valid snapshot =="
|
||||
printf '%s\n' 'workspace: invalid' >"$seed/workspaces/local.yaml"
|
||||
git -C "$seed" add workspaces/local.yaml
|
||||
git -C "$seed" -c user.name='Workspace Registry Smoke' -c user.email='workspace-registry-smoke@example.invalid' \
|
||||
commit -m 'Invalid workspace registry smoke fixture' >/dev/null
|
||||
git -C "$seed" push origin "HEAD:$branch" >/dev/null
|
||||
echo "== Pull a content-only Evidence update =="
|
||||
printf 'guide v2\n' >"$seed/$workspace_registry_smoke_id/evidence/guide.md"
|
||||
workspace_registry_smoke_commit 'Update workspace registry smoke evidence only'
|
||||
evidence_status="$(compose exec -T core curl -fsS -X POST http://127.0.0.1:8787/workspace-registry/pull)"
|
||||
evidence_head="$(workspace_registry_smoke_registry_head "$evidence_status")"
|
||||
[[ "$evidence_head" =~ ^[0-9a-f]{40}$ && "$evidence_head" != "$valid_head" ]]
|
||||
compose exec -T core curl -fsS http://127.0.0.1:8787/workspaces | grep -Fq 'Local Updated'
|
||||
good_seed_commit="$(git -C "$seed" rev-parse HEAD)"
|
||||
|
||||
echo "== Reject catalog/descriptor metadata mismatch and retain the last valid snapshot =="
|
||||
workspace_registry_smoke_replace_once "$seed/thoth-workspaces.yaml" 'name: Local Updated' 'name: Local Drift'
|
||||
workspace_registry_smoke_commit 'Break workspace registry metadata parity'
|
||||
if compose exec -T core curl -fsS -X POST http://127.0.0.1:8787/workspace-registry/pull >/dev/null; then
|
||||
echo "registry accepted invalid remote workspace content" >&2
|
||||
echo 'registry accepted catalog/descriptor metadata mismatch' >&2
|
||||
exit 1
|
||||
fi
|
||||
mismatch_status="$(compose exec -T core curl -fsS http://127.0.0.1:8787/workspace-registry/status)"
|
||||
[[ "$(workspace_registry_smoke_registry_head "$mismatch_status")" == "$evidence_head" ]]
|
||||
compose exec -T core curl -fsS http://127.0.0.1:8787/workspaces | grep -Fq 'Local Updated'
|
||||
workspace_registry_smoke_replace_once "$seed/thoth-workspaces.yaml" 'name: Local Drift' 'name: Local Updated'
|
||||
workspace_registry_smoke_commit 'Restore workspace registry metadata parity'
|
||||
restore_status="$(compose exec -T core curl -fsS -X POST http://127.0.0.1:8787/workspace-registry/pull)"
|
||||
evidence_head="$(workspace_registry_smoke_registry_head "$restore_status")"
|
||||
compose exec -T core curl -fsS http://127.0.0.1:8787/workspaces | grep -Fq 'Local Updated'
|
||||
|
||||
echo "== Reject orphan descriptor directories not listed in the catalog =="
|
||||
mkdir -p "$seed/orphan"
|
||||
cp "$seed/$workspace_registry_smoke_id/workspace.yaml" "$seed/orphan/workspace.yaml"
|
||||
workspace_registry_smoke_replace_once "$seed/orphan/workspace.yaml" 'id: local' 'id: orphan'
|
||||
workspace_registry_smoke_replace_once "$seed/orphan/workspace.yaml" 'name: Local Updated' 'name: Orphan Workspace'
|
||||
workspace_registry_smoke_replace_once "$seed/orphan/workspace.yaml" 'collection: local' 'collection: orphan'
|
||||
workspace_registry_smoke_replace_once "$seed/orphan/workspace.yaml" 'uri: local/evidence' 'uri: orphan/evidence'
|
||||
mkdir -p "$seed/orphan/evidence"
|
||||
printf 'orphan guide\n' >"$seed/orphan/evidence/guide.md"
|
||||
workspace_registry_smoke_commit 'Add orphan workspace directory'
|
||||
if compose exec -T core curl -fsS -X POST http://127.0.0.1:8787/workspace-registry/pull >/dev/null; then
|
||||
echo 'registry accepted orphan descriptor directory' >&2
|
||||
exit 1
|
||||
fi
|
||||
orphan_status="$(compose exec -T core curl -fsS http://127.0.0.1:8787/workspace-registry/status)"
|
||||
[[ "$(workspace_registry_smoke_registry_head "$orphan_status")" == "$evidence_head" ]]
|
||||
compose exec -T core curl -fsS http://127.0.0.1:8787/workspaces | grep -Fq 'Local Updated'
|
||||
rm -rf "$seed/orphan"
|
||||
workspace_registry_smoke_commit 'Remove orphan workspace directory'
|
||||
restore_status="$(compose exec -T core curl -fsS -X POST http://127.0.0.1:8787/workspace-registry/pull)"
|
||||
evidence_head="$(workspace_registry_smoke_registry_head "$restore_status")"
|
||||
compose exec -T core curl -fsS http://127.0.0.1:8787/workspaces | grep -Fq 'Local Updated'
|
||||
|
||||
echo "== Reject the retired flat workspace layout and retain the last valid snapshot =="
|
||||
mkdir -p "$seed/workspaces" "$seed/workspace-content/$workspace_registry_smoke_id/evidence"
|
||||
cp "$root/scripts/fixtures/workspace-registry-smoke.yaml" "$seed/workspaces/$workspace_registry_smoke_id.yaml"
|
||||
printf 'legacy guide\n' >"$seed/workspace-content/$workspace_registry_smoke_id/evidence/guide.md"
|
||||
workspace_registry_smoke_commit 'Reintroduce retired flat workspace layout'
|
||||
if compose exec -T core curl -fsS -X POST http://127.0.0.1:8787/workspace-registry/pull >/dev/null; then
|
||||
echo 'registry accepted the retired flat workspace layout' >&2
|
||||
exit 1
|
||||
fi
|
||||
legacy_status="$(compose exec -T core curl -fsS http://127.0.0.1:8787/workspace-registry/status)"
|
||||
[[ "$(workspace_registry_smoke_registry_head "$legacy_status")" == "$evidence_head" ]]
|
||||
compose exec -T core curl -fsS http://127.0.0.1:8787/workspaces | grep -Fq 'Local Updated'
|
||||
|
||||
echo "workspace registry smoke passed"
|
||||
|
||||
Reference in New Issue
Block a user