Test: Isolate generated docs and settings fixtures
This commit is contained in:
@@ -29,8 +29,8 @@
|
||||
# instead of being handed whole to a Text element and to anybody reading
|
||||
# over a shoulder.
|
||||
#
|
||||
# Runs entirely against a temporary config home. The real settings store is read
|
||||
# for the export and never written.
|
||||
# Runs entirely against temporary config homes: one explicit source fixture and
|
||||
# one isolated import destination. The real settings store is never consulted.
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
@@ -52,6 +52,29 @@ trap 'rm -rf "$work"' EXIT
|
||||
bundle="$work/export.json"
|
||||
field() { python3 -c "import json,sys; print(json.load(sys.stdin)$1)"; }
|
||||
|
||||
export XDG_CONFIG_HOME="$work/source-config"
|
||||
source_settings="$XDG_CONFIG_HOME/panama/settings.json"
|
||||
mkdir -p "$(dirname "$source_settings")"
|
||||
python3 - "$source_settings" <<'PY'
|
||||
import json, sys
|
||||
|
||||
# A representative source store: every value that should travel is valid for
|
||||
# its schema type, while the machine-only and unknown values prove the allow
|
||||
# list does not export whatever else happens to be present.
|
||||
fixture = {
|
||||
"blurEnabled": False, # boolean
|
||||
"gapsIn": 7, # integer
|
||||
"vrrPolicy": 2, # numeric enum
|
||||
"weatherLocation": "Fixture Harbor", # string
|
||||
"displays": {"DP-9": "source-only"},
|
||||
"lastPage": "appearance",
|
||||
"schemaVersion": 1,
|
||||
"someFutureToken": "Bearer fixture-secret",
|
||||
}
|
||||
with open(sys.argv[1], "w", encoding="utf-8") as target:
|
||||
json.dump(fixture, target)
|
||||
PY
|
||||
|
||||
# ── 1 & 2. Export carries taste, not hardware ───────────────────────────────
|
||||
|
||||
"$helper" export "$bundle" >"$work/export-result.json" || fail 'export failed'
|
||||
@@ -61,7 +84,7 @@ reason="$(field "['error']" <"$work/export-result.json")"
|
||||
[[ "$(stat -c '%a' "$bundle")" == "600" ]] \
|
||||
|| fail 'the export is readable by other accounts'
|
||||
|
||||
python3 - "$bundle" "$schema" "${XDG_CONFIG_HOME:-$HOME/.config}/panama/settings.json" <<'PY' || fail 'the export carried the wrong things, in one direction or the other'
|
||||
python3 - "$bundle" "$schema" "$source_settings" <<'PY' || fail 'the export carried the wrong things, in one direction or the other'
|
||||
import json, re, sys
|
||||
bundle = json.load(open(sys.argv[1]))
|
||||
schema = open(sys.argv[2]).read()
|
||||
@@ -105,6 +128,16 @@ PY
|
||||
# ── 3, 4. Arrival is validated per key, and the types are all covered ───────
|
||||
|
||||
export XDG_CONFIG_HOME="$work/config"
|
||||
destination_settings="$XDG_CONFIG_HOME/panama/settings.json"
|
||||
mkdir -p "$(dirname "$destination_settings")"
|
||||
python3 - "$destination_settings" <<'PY'
|
||||
import json, sys
|
||||
|
||||
# This valid preference is deliberately absent from the source fixture and
|
||||
# therefore from the bundle. Import must merge around it rather than replace it.
|
||||
with open(sys.argv[1], "w", encoding="utf-8") as target:
|
||||
json.dump({"borderSize": 4}, target)
|
||||
PY
|
||||
|
||||
python3 - "$bundle" "$work/tampered.json" <<'PY'
|
||||
import json, sys
|
||||
@@ -208,18 +241,15 @@ PY
|
||||
|
||||
# ── 5. Import merges rather than replaces ───────────────────────────────────
|
||||
|
||||
python3 - "$work/config/panama/settings.json" <<'PY'
|
||||
import json, sys
|
||||
store = json.load(open(sys.argv[1]))
|
||||
store["aSettingTheBundleNeverMentions"] = "kept"
|
||||
json.dump(store, open(sys.argv[1], "w"))
|
||||
PY
|
||||
"$helper" import "$bundle" >/dev/null || fail 'second import failed'
|
||||
python3 - "$work/config/panama/settings.json" <<'PY' || fail 'import replaced the store instead of merging into it'
|
||||
python3 - "$bundle" "$destination_settings" <<'PY' || fail 'import replaced the store instead of merging into it'
|
||||
import json, sys
|
||||
store = json.load(open(sys.argv[1]))
|
||||
if store.get("aSettingTheBundleNeverMentions") != "kept":
|
||||
raise SystemExit('a setting the bundle did not mention was removed')
|
||||
bundle = json.load(open(sys.argv[1]))["settings"]
|
||||
store = json.load(open(sys.argv[2]))
|
||||
if "borderSize" in bundle:
|
||||
raise SystemExit('the merge sentinel unexpectedly appeared in the import bundle')
|
||||
if store.get("borderSize") != 4:
|
||||
raise SystemExit('a schema-valid setting the bundle did not mention was removed')
|
||||
PY
|
||||
|
||||
applied="$("$helper" import "$bundle" | field "['applied']")"
|
||||
|
||||
Reference in New Issue
Block a user