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
+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):