feat: adopt local SQLite engineering memory and quality gates

This commit is contained in:
2026-11-22 14:39:00 +00:00
parent f5d5db73c2
commit 218c060b94
228 changed files with 28728 additions and 1161 deletions
+72
View File
@@ -0,0 +1,72 @@
#!/usr/bin/env python3
"""Installer activation helper. Tests run a copied helper with fake tools and destinations."""
import argparse
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
import uuid
parser = argparse.ArgumentParser()
parser.add_argument("package", type=Path)
parser.add_argument("--bin-dir", type=Path, required=True)
parser.add_argument("--lib-dir", type=Path, required=True)
args = parser.parse_args()
bin_dir = args.bin_dir.absolute()
lib_dir = args.lib_dir.absolute()
bin_dir.mkdir(parents=True, exist_ok=True)
lib_dir.mkdir(parents=True, exist_ok=True)
current = lib_dir / "current"
if current.exists() and not current.is_symlink():
raise SystemExit("Package current target must be a symlink")
names = {"ai-engineering": str(current / "ai-engineering"), "aie": "ai-engineering",
"aie-sqlite3": str(current / "sqlite3")}
for name in names:
if (bin_dir / name).is_dir():
raise SystemExit("Installation target is a directory: " + str(bin_dir / name))
release = lib_dir / "releases" / str(uuid.uuid4())
release.parent.mkdir(parents=True, exist_ok=True)
shutil.copytree(args.package, release)
try:
subprocess.run([sys.executable, str(Path(__file__).with_name("verify-native-package.py")), str(release)], check=True)
except BaseException:
shutil.rmtree(release)
raise
backup = Path(tempfile.mkdtemp(prefix=".aie-install.", dir=bin_dir))
previous_current = os.readlink(current) if current.is_symlink() else None
changed = []
safe_to_cleanup = False
try:
for name, target in names.items():
path = bin_dir / name
if path.is_symlink() or path.exists():
shutil.copy2(path, backup / name, follow_symlinks=False)
(backup / (name + ".new")).symlink_to(target)
switch = lib_dir / (".current-" + str(uuid.uuid4()))
switch.symlink_to(str(release.relative_to(lib_dir)))
os.replace(switch, current)
for name in names:
os.replace(backup / (name + ".new"), bin_dir / name)
changed.append(name)
safe_to_cleanup = True
except BaseException:
for name in reversed(changed):
saved = backup / name
if saved.is_symlink() or saved.exists():
os.replace(saved, bin_dir / name)
else:
(bin_dir / name).unlink()
if previous_current is None:
current.unlink(missing_ok=True)
else:
restored = lib_dir / (".restore-" + str(uuid.uuid4())); restored.symlink_to(previous_current)
os.replace(restored, current)
shutil.rmtree(release)
safe_to_cleanup = True
raise
finally:
if safe_to_cleanup:
shutil.rmtree(backup)
print("Activated native package:", current)
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
"""Build the pinned diagnostic CLI in build/, never install it."""
import hashlib
import json
import os
import platform
from pathlib import Path
import subprocess
import sys
import urllib.request
import zipfile
destination = Path(sys.argv[1]).resolve()
destination.mkdir(parents=True, exist_ok=True)
pin = json.loads(Path(__file__).with_name("sqlite-version.json").read_text())
if sys.platform == "win32":
if platform.machine().lower() not in ("amd64", "x86_64"):
raise SystemExit("The native Windows package currently requires x64")
archive = destination / "sqlite-tools-win-x64.zip"
if not archive.exists():
urllib.request.urlretrieve(pin["windows_url"], archive)
if hashlib.sha3_256(archive.read_bytes()).hexdigest() != pin["windows_sha3_256"]:
raise SystemExit("SQLite Windows package checksum differs from the official pin")
with zipfile.ZipFile(archive) as bundle:
names = [name for name in bundle.namelist() if name.rsplit("/", 1)[-1] == "sqlite3.exe"]
if len(names) != 1:
raise SystemExit("SQLite package lacks an unambiguous sqlite3.exe")
(destination / "sqlite3.exe").write_bytes(bundle.read(names[0]))
version = subprocess.check_output([str(destination / "sqlite3.exe"), "--version"], text=True).split()[0]
if version != pin["version"]:
raise SystemExit("SQLite Windows package version differs from the pin")
sys.exit(0)
archive = destination / pin["archive"]
if not archive.exists():
temporary = archive.with_suffix(".download")
urllib.request.urlretrieve(pin["url"], temporary)
temporary.replace(archive)
if hashlib.sha3_256(archive.read_bytes()).hexdigest() != pin["sha3_256"]:
raise SystemExit("SQLite source checksum differs from the pinned official release")
source = destination / "source"
source.mkdir(exist_ok=True)
with zipfile.ZipFile(archive) as bundle:
prefix = pin["archive"].removesuffix(".zip") + "/"
for name in ("sqlite3.c", "sqlite3.h", "sqlite3ext.h", "shell.c"):
(source / name).write_bytes(bundle.read(prefix + name))
binary = destination / "sqlite3"
temporary = destination / "sqlite3.new"
command = [os.environ.get("CC", "cc"), "-O2", "-DSQLITE_THREADSAFE=1", "-DSQLITE_DQS=0",
str(source / "shell.c"), str(source / "sqlite3.c"), "-o", str(temporary), "-lm", "-lpthread"]
if sys.platform.startswith("linux"):
command.append("-ldl")
subprocess.run(command, check=True)
version = subprocess.check_output([str(temporary), "--version"], text=True).split()[0]
if version != pin["version"]:
raise SystemExit("Compiled SQLite version differs from the pin")
temporary.replace(binary)
print("Built SQLite", version, "in", destination)
+18 -18
View File
@@ -4,10 +4,11 @@ set -euo pipefail
usage() {
cat <<'EOF'
Usage: scripts/install-native.sh [--bin-dir DIR]
Usage: scripts/install-native.sh [--bin-dir DIR] [--lib-dir DIR]
Build and install ai-engineering and the aie shortcut (Linux/macOS).
Default destination: $HOME/.local/bin. Run again to update.
Build and install a complete AIE + SQLite package (Linux/macOS).
Default package: $HOME/.local/lib/ai-engineering; shortcuts: $HOME/.local/bin.
Creates ai-engineering, aie and aie-sqlite3 shortcuts. Run again to update.
Uses GRAALVM_HOME, a compatible JAVA_HOME, or installs the GraalVM pinned in
.sdkmanrc through SDKMAN (bootstrapped when absent). Requires JDK 25 with
@@ -16,6 +17,7 @@ Does not install system packages or edit shell profiles.
Options:
--bin-dir DIR Installation directory (no sudo needed for the default).
--lib-dir DIR Package/releases directory; data stays in each project.
-h, --help Show this help.
EOF
}
@@ -24,6 +26,7 @@ die() { printf 'Error: %s\n' "$*" >&2; exit 1; }
log() { printf '\n==> %s\n' "$*"; }
bin_dir="${HOME:?HOME must be set}/.local/bin"
lib_dir="$HOME/.local/lib/ai-engineering"
while [[ $# -gt 0 ]]; do
case "$1" in
--bin-dir)
@@ -31,6 +34,11 @@ while [[ $# -gt 0 ]]; do
bin_dir=$2
shift 2
;;
--lib-dir)
[[ $# -ge 2 && -n "$2" && "$2" != --* ]] || die '--lib-dir requires a directory.'
lib_dir=$2
shift 2
;;
-h|--help) usage; exit 0 ;;
*) usage >&2; die "Unknown argument: $1" ;;
esac
@@ -48,7 +56,7 @@ case "$platform/$architecture" in
esac
case "$bin_dir" in /*) ;; *) bin_dir="$PWD/$bin_dir" ;; esac
for name in ai-engineering aie; do
for name in ai-engineering aie aie-sqlite3; do
[[ ! -d "$bin_dir/$name" ]] || die "Installation target is a directory: $bin_dir/$name"
done
@@ -154,22 +162,14 @@ log "Building with $JAVA_HOME"
"-Dorg.gradle.java.home=$JAVA_HOME" \
"-Porg.gradle.java.installations.paths=$JAVA_HOME" \
-Porg.gradle.java.installations.auto-detect=false \
-Porg.gradle.java.installations.auto-download=false nativeCompile
-Porg.gradle.java.installations.auto-download=false nativePackage
)
native_binary="$project_dir/build/native/nativeCompile/ai-engineering"
[[ -x "$native_binary" ]] || die "Build did not produce an executable: $native_binary"
log "Installing in $bin_dir"
mkdir -p -- "$bin_dir"
bin_dir=$(cd -- "$bin_dir" && pwd -P)
# Stage on the destination filesystem. Rename replaces old binaries/symlinks
# without following a previous symlink back into this checkout.
stage_dir=$(mktemp -d "$bin_dir/.aie-install.XXXXXXXX")
install -m 755 "$native_binary" "$stage_dir/ai-engineering"
"$stage_dir/ai-engineering" --help >/dev/null
ln -s ai-engineering "$stage_dir/aie"
mv -f -- "$stage_dir/ai-engineering" "$bin_dir/ai-engineering"
mv -f -- "$stage_dir/aie" "$bin_dir/aie"
native_package="$project_dir/build/native/package"
[[ -x "$native_package/ai-engineering" ]] || die "Build did not produce a complete package: $native_package"
command -v python3 >/dev/null 2>&1 || die 'Python 3 is required to verify and activate the package.'
log "Verifying package before activation in $lib_dir"
python3 "$project_dir/scripts/activate-native-package.py" "$native_package" --bin-dir "$bin_dir" --lib-dir "$lib_dir"
log "Installed: $bin_dir/ai-engineering (shortcut: $bin_dir/aie)"
case ":$PATH:" in
*":$bin_dir:"*) ;;
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
"""Generate a disposable WRK-000C dataset; does not benchmark, install or migrate anything."""
import argparse
import hashlib
import json
from pathlib import Path
import platform
import re
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument("--binary", type=Path, required=True)
parser.add_argument("--directory", type=Path, required=True)
parser.add_argument("--works", type=int, default=100)
parser.add_argument("--entries", type=int, default=10)
parser.add_argument("--storage", choices=("sqlite", "legacy"), default="sqlite")
args = parser.parse_args()
if args.works < 1 or args.entries < 0:
parser.error("Use positive Works and nonnegative entries")
binary = args.binary.resolve(strict=True)
root = args.directory.absolute()
root.mkdir(parents=True, exist_ok=False)
def run(*command):
return subprocess.check_output([str(binary), *command], cwd=root, text=True, stderr=subprocess.STDOUT, timeout=60)
version = run("--version").strip()
run("init", "--name", "Disposable latency dataset", "--storage", args.storage)
last = None
for index in range(args.works):
output = run("work", "create", "Synthetic work " + str(index + 1), "--goal", "Resume local engineering memory")
match = re.search(r'^id: "(WRK-[0-9A-F]+)"', output, re.MULTILINE)
if not match:
raise SystemExit("Cannot identify generated Work")
last = match.group(1)
for entry in range(args.entries):
run("discussion", "add", last, "--text", "Synthetic observation " + str(entry + 1) + " — UTF-8", "--author", "fixture")
metadata = {"version": version, "binary": str(binary), "binarySha256": hashlib.sha256(binary.read_bytes()).hexdigest(),
"platform": platform.platform(), "machine": platform.machine(), "storage": args.storage,
"works": args.works, "entriesPerWork": args.entries, "selectedWork": last,
"measurementPerformed": False}
(root / "latency-fixture.json").write_text(json.dumps(metadata, indent=2) + "\n")
print(json.dumps(metadata, indent=2))
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env python3
import hashlib
import json
from pathlib import Path
import sys
package = Path(sys.argv[1]).resolve()
files = {str(path.relative_to(package)): hashlib.sha256(path.read_bytes()).hexdigest()
for path in sorted(package.rglob("*")) if path.is_file() and path.name != "aie-package.json"}
manifest = {"schemaVersion": 1, "aieVersion": "0.1.0", "protocolVersion": 4,
"sqliteVersion": "3.54.1", "files": files}
(package / "aie-package.json").write_text(json.dumps(manifest, indent=2) + "\n")
+17 -14
View File
@@ -26,7 +26,7 @@ aie_without_git() {
mkdir plain
cd plain
printf 'Existing source\n' > main.txt
aie_without_git init --name 'Simple Project' > init.yaml
aie_without_git init --storage legacy --name 'Simple Project' > init.yaml
aie_without_git work create --mode DIRECT --approval WAIVED --human-approved --choice-reason "Explicit synthetic fixture policy" 'Continue application' --goal 'Preserve local context' > work.yaml
aie_without_git work list --open --format table > works-table.txt
grep -q 'WRK-0001' works-table.txt
@@ -48,9 +48,9 @@ grep -q '^WRK-0001,CREATE_PLAN,' actions.csv
aie_without_git project compatibility --format json > compatibility.json
grep -q '"state" : "CURRENT"' compatibility.json
grep -q '"migrationRequired" : false' compatibility.json
grep -q '"protocolVersion": 3' .ai-engineering/protocol.json
grep -q '"protocolVersion": 4' .ai-engineering/protocol.json
cp .ai-engineering/protocol.json baseline-protocol.json
sed 's/"protocolVersion": 3/"protocolVersion": 99/' baseline-protocol.json > .ai-engineering/protocol.json
sed 's/"protocolVersion": 4/"protocolVersion": 99/' baseline-protocol.json > .ai-engineering/protocol.json
cp .ai-engineering/protocol.json future-protocol.json
if aie_without_git project compatibility --format json > future-compatibility.json; then
echo 'Unsupported contract unexpectedly succeeded' >&2
@@ -113,7 +113,7 @@ cd "$aie_fixture"
# Creating a Plan promotes a draft without a model or direct human attestation.
mkdir plan-promotion
cd plan-promotion
aie_without_git init --name 'Plan Promotion' > init.yaml
aie_without_git init --storage legacy --name 'Plan Promotion' > init.yaml
aie_without_git work create --mode DIRECT --approval WAIVED --human-approved --choice-reason "Explicit synthetic fixture policy" 'Promote decision' > work.yaml
aie_without_git decision draft WRK-0001 --title 'Chosen approach' --context 'Problem' \
--approach 'Small implementation' --rationale 'Bounded scope' > draft.yaml
@@ -143,7 +143,7 @@ cp -R "$aie_fixture/df-alpha" "$aie_fixture/df-alpha-before"
cp -R "$aie_fixture/df-beta" "$aie_fixture/df-beta-before"
mkdir "$aie_fixture/df-import"
cd "$aie_fixture/df-import"
aie_without_git init --name 'DF import destination' > init.yaml
aie_without_git init --storage legacy --name 'DF import destination' > init.yaml
aie_df_args=(--source "alpha=$aie_fixture/df-alpha" --source "beta=$aie_fixture/df-beta"
--target alpha=runtime --target alpha=docs --target beta=studio --format json)
aie_without_git import discussion "${aie_df_args[@]}" > preview.json
@@ -175,7 +175,7 @@ cd "$aie_fixture"
# A single Git repository can contain both the source and protocol workspace.
git init -q single
cd single
"$aie_binary" init --name 'Single Repository' > init.yaml
"$aie_binary" init --storage legacy --name 'Single Repository' > init.yaml
"$aie_binary" repo add app --path . > repo.yaml
"$aie_binary" work create --mode DIRECT --approval WAIVED --human-approved --choice-reason "Explicit synthetic fixture policy" 'Inspect application' --repo app > work.yaml
"$aie_binary" work context WRK-0001 --format json > before.json
@@ -193,7 +193,7 @@ echo 'Native simple-project continuity smoke passed (without Git and with one ro
# Work numbers are hexadecimal; child counters still use decimal.
mkdir hexadecimal
cd hexadecimal
aie_without_git init --name 'Hexadecimal Works' > init.yaml
aie_without_git init --storage legacy --name 'Hexadecimal Works' > init.yaml
for aie_number in {1..16}; do
aie_without_git work create --mode DIRECT --approval WAIVED --human-approved --choice-reason "Explicit synthetic fixture policy" "Work $aie_number" > "work-$aie_number.yaml"
done
@@ -218,7 +218,7 @@ cd "$aie_fixture"
# Reserve all old decimal spellings, including removed Works, when upgrading counters.
mkdir legacy-counter
cd legacy-counter
aie_without_git init --name 'Legacy reservations' > init.yaml
aie_without_git init --storage legacy --name 'Legacy reservations' > init.yaml
printf 'schemaVersion: 1\nlastWork: 16\n' > .ai-engineering/works/.sequence.yaml
aie_without_git work create --mode DIRECT --approval WAIVED --human-approved --choice-reason "Explicit synthetic fixture policy" 'After legacy reservation' > work.yaml
grep -q 'id: "WRK-0017"' work.yaml
@@ -231,7 +231,7 @@ echo 'Native hexadecimal Work identifiers and legacy reservations smoke passed.'
# Exercise the refinement contract with two fixture adapters and fresh processes.
mkdir refinement
cd refinement
aie_without_git init --name 'Refinement fixture' --general-adapter fixture-general \
aie_without_git init --storage legacy --name 'Refinement fixture' --general-adapter fixture-general \
--archive-policy reversible > init.yaml
aie_without_git work create --mode DIRECT --approval WAIVED --human-approved --choice-reason "Explicit synthetic fixture policy" 'Compare ideas' > work.yaml
printf 'Rendering: measure layers\nInput: compare controls\n' > ideas.md
@@ -326,7 +326,7 @@ export AIE_CODEX_EXECUTABLE="$aie_fixture/providers/codex"
export AIE_CLAUDE_EXECUTABLE="$aie_fixture/providers/claude"
cd local-cli
printf '1\ngeneral\ndefault\n5\n1\n3\nreviewer\ndefault\n5\n1\n' > setup.txt
aie_without_git init . --name 'Native CLI fixture' --interactive --input-file setup.txt > setup.yaml
aie_without_git init --storage legacy . --name 'Native CLI fixture' --interactive --input-file setup.txt > setup.yaml
aie_without_git agent doctor --format json > doctor.json
grep -q '"compatible" : true' doctor.json
aie_without_git work create --mode DIRECT --approval WAIVED --human-approved --choice-reason "Explicit synthetic fixture policy" 'Provider protocol' > work.yaml
@@ -354,7 +354,7 @@ echo 'Native local-CLI transport smoke passed (controlled subprocess fixtures, g
# EPIC state control is entirely deterministic and does not need configured agents.
mkdir epic-coordination
cd epic-coordination
aie_without_git init --name 'EPIC coordination fixture' > init.yaml
aie_without_git init --storage legacy --name 'EPIC coordination fixture' > init.yaml
for aie_title in Parent Required Cancelled Optional; do
aie_without_git work create --mode DIRECT --approval WAIVED --human-approved --choice-reason "Explicit synthetic fixture policy" "$aie_title" --acceptance 'Reviewed fixture result' > "$aie_title.yaml"
done
@@ -427,7 +427,7 @@ for aie_repo in runtime studio; do
git -C "$aie_repo" -c user.name=Fixture -c user.email=fixture@example.invalid \
commit -q --allow-empty -m fixture
done
"$aie_binary" init --name 'Continuity Experiment' > init.yaml
"$aie_binary" init --storage legacy --name 'Continuity Experiment' > init.yaml
"$aie_binary" repo add runtime --path runtime --language rust > runtime.yaml
"$aie_binary" repo add studio --path studio --language java > studio.yaml
"$aie_binary" work create --mode DIRECT --approval WAIVED --human-approved --choice-reason "Explicit synthetic fixture policy" 'Improve scene editor' --repo runtime --repo studio \
@@ -521,7 +521,7 @@ echo 'Native operational-cycle smoke passed (discovery, approval, plan, evidence
# Automatic consolidation across independent native processes without Git/JVM/models.
mkdir "$aie_fixture/plan-consolidation"
cd "$aie_fixture/plan-consolidation"
aie_without_git init --name 'Plan consolidation' > init.yaml
aie_without_git init --storage legacy --name 'Plan consolidation' > init.yaml
aie_without_git work create --mode DIRECT --approval WAIVED --human-approved --choice-reason "Explicit synthetic fixture policy" 'Delivery' > work.yaml
printf 'Synthetic executed result\n' > result.txt
aie_without_git artifact add WRK-0001 --file result.txt --purpose 'Fixture execution' > evidence.yaml
@@ -559,7 +559,7 @@ echo 'Native Plan consolidation smoke passed (multiple Plans, reviewed cancellat
# Human conduct and optional OODA across fresh native processes without Git/JVM/model.
mkdir "$aie_fixture/work-guidance"
cd "$aie_fixture/work-guidance"
aie_without_git init --name 'Human conduct and experiments' > init.yaml
aie_without_git init --storage legacy --name 'Human conduct and experiments' > init.yaml
aie_without_git work create 'Explicit human control' > unspecified.yaml
aie_without_git next-actions WRK-0001 --format json > unspecified-actions.json
grep -q ASK_DISCUSSION_MODE unspecified-actions.json
@@ -624,3 +624,6 @@ aie_without_git project validate --format json > validation.json
grep -q '"valid" : true' validation.json
echo 'Native Work guidance/OODA smoke passed (human mode/request/approval, explicit waiver, criteria, evidence, independent execution and approved DEC revision).'
if [[ "${AIE_KEEP_FIXTURE:-0}" == 1 ]]; then echo "Fixture retained: $aie_fixture"; fi
# Exercise the default SQLite backend, gates and migration separately from legacy fixtures.
bash "$aie_source_root/scripts/native-sqlite-smoke.sh" "$aie_binary"
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -euo pipefail
binary=${1:?Usage: native-sqlite-smoke.sh /absolute/package/ai-engineering}
source_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
fixture=$(mktemp -d "${TMPDIR:-/tmp}/aie-sqlite-smoke.XXXXXXXX")
trap 'rm -rf "$fixture"' EXIT
mkdir "$fixture/local"
cd "$fixture/local"
run() { PATH="$fixture/no-tools" "$binary" "$@"; }
run init --name 'Local memory' > init.yaml
test -f .ai-engineering/aie.db
grep -q '/.ai-engineering/' .gitignore
printf 'Source evaluated by the fixture\n' > source.txt
run work create 'Deliver' --goal 'Preserve quality' --acceptance 'Observed check' \
--mode EXPLORATORY --human-approved --choice-reason 'Explicit synthetic human choice' --author fixture-owner > work.yaml
run discussion add WRK-0001 --text 'Investigação — preservar contexto' --author fixture-owner > note.yaml
run work request-decision WRK-0001 --by fixture-owner --reason 'Exploration ended in this fixture' --human-approved > request.yaml
run decision draft WRK-0001 --title 'Approach' --context 'Observed facts' --approach 'Small change' --rationale 'Bounded' > decision.yaml
run decision accept WRK-0001 DEC-0001 --by fixture-owner --reason 'Reviewed fixture DEC' --human-approved > accepted.yaml
run plan create WRK-0001 --title 'Deliver' --decision DEC-0001 > plan.yaml
run plan step add WRK-0001 PLN-0001 --title 'Check result' > step.yaml
run gate configure quality --title 'Project quality' --procedure 'Review source.txt' --input source.txt --require-evidence --by fixture-owner > gate.yaml
run artifact add WRK-0001 --file source.txt --purpose 'Temporary evaluated input' > evidence.yaml
run plan step status WRK-0001 PLN-0001 TSK-0001 COMPLETED --by fixture --reason 'Observed synthetic result' --evidence ART-0001 > finished-step.yaml
run work show WRK-0001 --format json > pending.json
if grep -q '"status" : "COMPLETED"' pending.json; then echo 'Pending gate did not block delivery' >&2; exit 1; fi
test -f .ai-engineering/works/WRK-0001-deliver/artifacts/evidence/ART-0001/payload
run gate status WRK-0001 --format json > gate-status.json
fingerprint=$(python3 -c 'import json; print(json.load(open("gate-status.json"))[0]["evaluatedHash"])')
run gate record WRK-0001 project/quality --expect "$fingerprint" --invocation 'Review source.txt' \
--outcome PASS --summary 'Synthetic observed evaluation' --evidence ART-0001 --by fixture --observed > result.yaml
run work context WRK-0001 --format json > context.json
grep -q '"status" : "COMPLETED"' context.json
grep -q 'DISCARDED' context.json
test ! -f .ai-engineering/works/WRK-0001-deliver/work.md
test ! -f .ai-engineering/works/WRK-0001-deliver/artifacts/evidence/ART-0001/payload
test -f source.txt
run project validate > validation.yaml
run work reopen WRK-0001 --by fixture-owner --reason 'New observation' > reopened.yaml
if run gate record WRK-0001 project/quality --expect "$fingerprint" --invocation 'Review source.txt' \
--outcome PASS --summary 'Invalid retired reuse' --evidence ART-0001 --by fixture --observed > retired-error.txt 2>&1; then
echo 'Retired input unexpectedly accepted' >&2; exit 1
fi
mkdir "$fixture/legacy"
cd "$fixture/legacy"
run init --storage legacy --name 'Migration fixture' > init.yaml
run work create 'Delivered baseline' > work.yaml
cp -R "$source_root/src/test/resources/compatibility/baseline-v1/.ai-engineering/." .ai-engineering/
run storage migrate --format json > preview.json
fingerprint=$(python3 -c 'import json; print(json.load(open("preview.json"))["fingerprint"])')
run storage migrate --apply --expect "$fingerprint" --format json > migrated.json
run project validate > validation.yaml
run work context WRK-0001 --format json > context.json
grep -q '72d5803add0b8714d7dc4bf7e63ad55cc3259df910aa8b03790657eac4c2bd02' context.json
run storage migrate --apply --expect "$fingerprint" --format json > repeated.json
grep -q 'APPLIED' repeated.json
echo 'Native SQLite lifecycle, gates and legacy migration smoke passed.'
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Smoke the build-only native probe. Never installs binaries or opens project data.
set -euo pipefail
probe=${1:?Usage: sqlite-probe.sh /absolute/path/to/aie-sqlite-probe}
case "$probe" in /*) ;; *) echo 'Supply an absolute build path.' >&2; exit 2 ;; esac
[[ -x "$probe" ]] || { echo 'Native probe is missing.' >&2; exit 2; }
probe_dir=$(cd -- "$(dirname -- "$probe")" && pwd -P)
fixture=$(mktemp -d "${TMPDIR:-/tmp}/aie-sqlite-proof.XXXXXXXX")
trap 'rm -rf -- "$fixture"' EXIT
# Extraction must not be needed: the temporary directory is readable but not writable.
mkdir "$fixture/no-extraction"
chmod 500 "$fixture/no-extraction"
"$probe" "-Dorg.sqlite.lib.path=$probe_dir" "-Dorg.sqlite.tmpdir=$fixture/no-extraction" "$fixture/proof.db"
"$probe" "-Dorg.sqlite.lib.path=$probe_dir" "-Dorg.sqlite.tmpdir=$fixture/no-extraction" "$fixture/proof.db"
# Exported JNI support must really come from the distribution. The isolated copy
# has neither a sibling library nor an embedded resource from which to extract it.
mkdir "$fixture/isolated"
cp "$probe" "$fixture/isolated/aie-sqlite-probe"
if "$fixture/isolated/aie-sqlite-probe" "-Dorg.sqlite.lib.path=$fixture/isolated" \
"-Dorg.sqlite.tmpdir=$fixture/no-extraction" "$fixture/missing-library.db" \
> "$fixture/missing-library.log" 2>&1; then
echo 'Isolated executable unexpectedly worked without its SQLite library.' >&2
exit 1
fi
echo 'Native SQLite proof passed: separate processes, UTF-8, rollback and external library.'
+9
View File
@@ -0,0 +1,9 @@
{
"version": "3.54.1",
"archive": "sqlite-amalgamation-3540100.zip",
"url": "https://sqlite.org/2026/sqlite-amalgamation-3540100.zip",
"sha3_256": "92281c86e2957f9b9305890f9ac04204caa7b677cc868dc326d942689df28e30",
"source": "https://sqlite.org/download.html",
"windows_url": "https://sqlite.org/2026/sqlite-tools-win-x64-3540100.zip",
"windows_sha3_256": "e171f3993a992edf076746926dd52b5e2ebfabaee38818e74987e1d8112ab987"
}
+66 -6
View File
@@ -7,9 +7,12 @@ These test installation behavior, not native compilation itself.
import os
from pathlib import Path
import shutil
import runpy
import subprocess
import sys
import tempfile
import unittest
from unittest import mock
INSTALLER = Path(__file__).resolve().with_name("install-native.sh")
@@ -28,6 +31,8 @@ class NativeInstallerTest(unittest.TestCase):
self.tools.mkdir()
(self.repo / "scripts").mkdir(parents=True)
shutil.copy2(INSTALLER, self.repo / "scripts/install-native.sh")
for name in ("activate-native-package.py", "verify-native-package.py", "native-package-manifest.py"):
shutil.copy2(INSTALLER.with_name(name), self.repo / "scripts" / name)
(self.repo / ".sdkmanrc").write_text("java=25-test-graalce\n")
self.env = {key: value for key, value in os.environ.items()
if not key.startswith(("JAVA", "GRAAL", "SDKMAN", "BASH_ENV"))}
@@ -46,13 +51,25 @@ printf '%s\n' "$PWD" "$JAVA_HOME" "$GRAALVM_HOME" "$@" >> "$FIXTURE_LOG"
[[ "$JAVA_HOME" == "$GRAALVM_HOME" ]] || exit 91
[[ "${FIXTURE_BUILD_EXIT:-0}" == 0 ]] || exit "$FIXTURE_BUILD_EXIT"
[[ "${FIXTURE_MISSING_BINARY:-0}" == 0 ]] || exit 0
mkdir -p build/native/nativeCompile
cat > build/native/nativeCompile/ai-engineering <<'EOF'
mkdir -p build/native/package
cat > build/native/package/ai-engineering <<'EOF'
#!/bin/bash
echo "fixture CLI"
case "${1:-}" in
--version) echo "ai-engineering 0.1.0" ;;
init) mkdir -p .ai-engineering; touch .ai-engineering/aie.db ;;
*) echo "fixture CLI" ;;
esac
exit "${FIXTURE_BINARY_EXIT:-0}"
EOF
chmod +x build/native/nativeCompile/ai-engineering
chmod +x build/native/package/ai-engineering
cat > build/native/package/sqlite3 <<'EOF'
#!/bin/bash
[[ "${1:-}" == --version ]] && echo "3.54.1 fixture" || echo "ok"
EOF
chmod +x build/native/package/sqlite3
if [[ "${FIXTURE_MISSING_LIBRARY:-0}" == 0 ]]; then echo "fixture library" > build/native/package/libsqlitejdbc.so; fi
python3 scripts/native-package-manifest.py build/native/package
if [[ "${FIXTURE_CORRUPT_PACKAGE:-0}" == 1 ]]; then echo "changed" >> build/native/package/libsqlitejdbc.so; fi
''')
def executable(self, path, body):
@@ -84,7 +101,7 @@ chmod +x build/native/nativeCompile/ai-engineering
def test_default_install_is_independent_and_can_be_updated(self):
output = self.run_installer()
dest = self.home / ".local/bin"
self.assertFalse((dest / "ai-engineering").is_symlink())
self.assertTrue((dest / "ai-engineering").is_symlink())
self.assertEqual(os.readlink(dest / "aie"), "ai-engineering")
self.assertEqual((dest / "ai-engineering").stat().st_mode & 0o777, 0o755)
self.assertIn('export PATH=', output)
@@ -106,6 +123,49 @@ chmod +x build/native/nativeCompile/ai-engineering
self.env["FIXTURE_ARCH"] = "aarch64"
self.run_installer()
def test_complete_package_uses_custom_library_directory(self):
library = self.root / "custom library"
self.run_installer("--lib-dir", str(library))
current = library / "current"
self.assertTrue(current.is_symlink())
self.assertTrue((current / "libsqlitejdbc.so").is_file())
self.assertTrue((current / "sqlite3").is_file())
shortcut = self.home / ".local/bin/aie-sqlite3"
self.assertEqual(subprocess.check_output([str(shortcut), "--version"], text=True).split()[0], "3.54.1")
previous = os.readlink(current)
self.run_installer("--lib-dir", str(library))
self.assertNotEqual(os.readlink(current), previous)
self.assertTrue((library / previous).is_dir())
def test_missing_or_corrupt_library_preserves_previous_installation(self):
dest = self.old_installation()
for key in ("FIXTURE_MISSING_LIBRARY", "FIXTURE_CORRUPT_PACKAGE"):
with self.subTest(key=key):
self.env[key] = "1"
self.run_installer(success=False)
self.assert_old_installation(dest)
del self.env[key]
def test_activation_failure_restores_current_release_and_all_shortcuts(self):
self.run_installer()
library = self.home / ".local/lib/ai-engineering"
dest = self.home / ".local/bin"
previous = os.readlink(library / "current")
links = {name: os.readlink(dest / name) for name in ("ai-engineering", "aie", "aie-sqlite3")}
replace = os.replace
def fail_second_shortcut(source, target):
if Path(source).name == "aie.new":
raise OSError("Synthetic activation failure")
return replace(source, target)
arguments = [str(self.repo / "scripts/activate-native-package.py"), str(self.repo / "build/native/package"),
"--bin-dir", str(dest), "--lib-dir", str(library)]
with mock.patch.dict(os.environ, self.env, clear=True), mock.patch.object(sys, "argv", arguments), mock.patch("os.replace", side_effect=fail_second_shortcut):
with self.assertRaisesRegex(OSError, "Synthetic activation failure"):
runpy.run_path(arguments[0], run_name="__main__")
self.assertEqual(os.readlink(library / "current"), previous)
self.assertEqual({name: os.readlink(dest / name) for name in links}, links)
self.assertEqual(list(dest.glob(".aie-install.*")), [])
def test_replaces_previous_symlinks_without_following_them(self):
dest = self.home / ".local/bin"
dest.mkdir(parents=True)
@@ -115,7 +175,7 @@ chmod +x build/native/nativeCompile/ai-engineering
(dest / "aie").symlink_to(old)
self.run_installer()
self.assertEqual(old.read_text(), "keep this target")
self.assertFalse((dest / "ai-engineering").is_symlink())
self.assertTrue((dest / "ai-engineering").is_symlink())
self.assertEqual(os.readlink(dest / "aie"), "ai-engineering")
def test_build_failure_preserves_installation(self):
+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
"""Validate a complete candidate before activation, using only disposable project data."""
import hashlib
import json
from pathlib import Path
import subprocess
import sys
import tempfile
package = Path(sys.argv[1]).resolve()
manifest = json.loads((package / "aie-package.json").read_text())
if manifest.get("schemaVersion") != 1 or manifest.get("protocolVersion") != 4:
raise SystemExit("Unsupported native package manifest")
expected = manifest["files"]
actual = set()
for path in package.rglob("*"):
if path.is_symlink():
raise SystemExit("Package components must be regular files, not symlinks")
if path.is_file() and path.name != "aie-package.json":
relative = str(path.relative_to(package)); actual.add(relative)
if hashlib.sha256(path.read_bytes()).hexdigest() != expected.get(relative):
raise SystemExit("Package integrity mismatch: " + relative)
aie_name = "ai-engineering.exe" if "ai-engineering.exe" in actual else "ai-engineering"
sqlite_name = "sqlite3.exe" if "sqlite3.exe" in actual else "sqlite3"
if actual != set(expected) or not {aie_name, sqlite_name}.issubset(actual):
raise SystemExit("Incomplete package components")
if not any(name.startswith("libsqlitejdbc.") or name == "sqlitejdbc.dll" for name in actual):
raise SystemExit("Missing companion SQLite JDBC library")
aie, sqlite = package / aie_name, package / sqlite_name
if subprocess.check_output([str(aie), "--version"], text=True).strip() != "ai-engineering " + manifest["aieVersion"]:
raise SystemExit("AIE package version mismatch")
if subprocess.check_output([str(sqlite), "--version"], text=True).split()[0] != manifest["sqliteVersion"]:
raise SystemExit("SQLite package version mismatch")
with tempfile.TemporaryDirectory(prefix="aie-package-check-") as temporary:
root = Path(temporary)
subprocess.run([str(aie), "init", "--name", "Disposable package verification"], cwd=root,
check=True, stdout=subprocess.DEVNULL)
database = root / ".ai-engineering/aie.db"
if not database.is_file():
raise SystemExit("Native AIE did not create its disposable database")
result = subprocess.check_output([str(sqlite), "-readonly", str(database), "PRAGMA quick_check;"], text=True).strip()
if result != "ok":
raise SystemExit("Packaged SQLite cannot read the native AIE database")
print("Native package verified:", package)