Fix CI healthcheck endpoint and bundled install FK violations
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 4s
CI/CD / test-frontend (pull_request) Successful in 5s
CI/CD / test-go-pg (pull_request) Successful in 2m44s
CI/CD / test-sqlite (pull_request) Successful in 2m55s
CI/CD / test-runners (pull_request) Failing after 1m43s
CI/CD / build-and-deploy (pull_request) Has been skipped
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 4s
CI/CD / test-frontend (pull_request) Successful in 5s
CI/CD / test-go-pg (pull_request) Successful in 2m44s
CI/CD / test-sqlite (pull_request) Successful in 2m55s
CI/CD / test-runners (pull_request) Failing after 1m43s
CI/CD / build-and-deploy (pull_request) Has been skipped
Two bugs preventing the test-runners CI job from passing: 1. Health check used GET /api/v1/auth/login — a POST-only route that always returns 404. Changed to GET /api/v1/health which exists. 2. Bundled package install passed empty strings to FK-constrained columns (global_settings.updated_by, workflows.created_by), causing FOREIGN KEY constraint failures on every surface and workflow package. Fixed by resolving the bootstrap admin user ID at startup and threading it through the install path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ MAX_RETRIES="${2:-60}"
|
|||||||
|
|
||||||
echo "Waiting for ${HOST} to be healthy..."
|
echo "Waiting for ${HOST} to be healthy..."
|
||||||
for i in $(seq 1 "$MAX_RETRIES"); do
|
for i in $(seq 1 "$MAX_RETRIES"); do
|
||||||
if curl -sf --connect-timeout 2 "${HOST}/api/v1/auth/login" -o /dev/null 2>/dev/null; then
|
if curl -sf --connect-timeout 2 "${HOST}/api/v1/health" -o /dev/null 2>/dev/null; then
|
||||||
echo "Server healthy after ${i}s"
|
echo "Server healthy after ${i}s"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
services:
|
services:
|
||||||
armature:
|
armature:
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-sf", "http://localhost:80/api/v1/auth/login"]
|
test: ["CMD", "curl", "-sf", "http://localhost:80/api/v1/health"]
|
||||||
interval: 2s
|
interval: 2s
|
||||||
timeout: 3s
|
timeout: 3s
|
||||||
retries: 30
|
retries: 30
|
||||||
|
|||||||
@@ -524,7 +524,7 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
|||||||
pkgPath := filepath.Join(h.bundledDir, libID+".pkg")
|
pkgPath := filepath.Join(h.bundledDir, libID+".pkg")
|
||||||
if _, statErr := os.Stat(pkgPath); statErr == nil {
|
if _, statErr := os.Stat(pkgPath); statErr == nil {
|
||||||
log.Printf("[packages] auto-installing bundled dependency %s for %s", libID, pkgID)
|
log.Printf("[packages] auto-installing bundled dependency %s for %s", libID, pkgID)
|
||||||
if _, installErr := installBundledPackage(pkgPath, h.packagesDir, h.stores, h.runner); installErr != nil {
|
if _, installErr := installBundledPackage(pkgPath, h.packagesDir, h.stores, h.runner, c.GetString("user_id")); installErr != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
"error": fmt.Sprintf("dependency %s auto-install failed: %v", libID, installErr),
|
"error": fmt.Sprintf("dependency %s auto-install failed: %v", libID, installErr),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ func InstallBundledPackages(bundledDir, packagesDir, allowlist string, stores st
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve first admin user ID for FK-constrained writes (default_surface,
|
||||||
|
// workflow creation). Falls back to empty string if no admin exists yet.
|
||||||
|
adminUserID := resolveFirstAdminID(stores)
|
||||||
|
|
||||||
// Parse allowlist: "" → curated defaults, "*" → all, "a,b" → explicit list
|
// Parse allowlist: "" → curated defaults, "*" → all, "a,b" → explicit list
|
||||||
allowed := parseBundleAllowlist(allowlist)
|
allowed := parseBundleAllowlist(allowlist)
|
||||||
if allowed != nil {
|
if allowed != nil {
|
||||||
@@ -78,7 +82,7 @@ func InstallBundledPackages(bundledDir, packagesDir, allowlist string, stores st
|
|||||||
}
|
}
|
||||||
|
|
||||||
pkgPath := filepath.Join(bundledDir, entry.Name())
|
pkgPath := filepath.Join(bundledDir, entry.Name())
|
||||||
result, err := installBundledPackage(pkgPath, packagesDir, stores, runner)
|
result, err := installBundledPackage(pkgPath, packagesDir, stores, runner, adminUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[bundled] ⚠️ Failed to install %s: %v", entry.Name(), err)
|
log.Printf("[bundled] ⚠️ Failed to install %s: %v", entry.Name(), err)
|
||||||
continue
|
continue
|
||||||
@@ -125,7 +129,7 @@ func parseBundleAllowlist(s string) map[string]bool {
|
|||||||
|
|
||||||
// installBundledPackage installs a single .pkg archive if its package ID
|
// installBundledPackage installs a single .pkg archive if its package ID
|
||||||
// doesn't already exist in the database. Returns "installed" or "skipped".
|
// doesn't already exist in the database. Returns "installed" or "skipped".
|
||||||
func installBundledPackage(pkgPath, packagesDir string, stores store.Stores, runner *sandbox.Runner) (string, error) {
|
func installBundledPackage(pkgPath, packagesDir string, stores store.Stores, runner *sandbox.Runner, adminUserID string) (string, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// Open as zip
|
// Open as zip
|
||||||
@@ -197,8 +201,12 @@ func installBundledPackage(pkgPath, packagesDir string, stores store.Stores, run
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync permissions — use a minimal gin.Context for the functions that need it
|
// Sync permissions — use a minimal gin.Context for the functions that need it.
|
||||||
|
// Set user_id so FK-constrained writes (workflow creation) reference a real user.
|
||||||
fakeCtx := newBackgroundGinContext()
|
fakeCtx := newBackgroundGinContext()
|
||||||
|
if adminUserID != "" {
|
||||||
|
fakeCtx.Set("user_id", adminUserID)
|
||||||
|
}
|
||||||
declaredPerms := SyncManifestPermissions(fakeCtx, stores, pkgID, manifest)
|
declaredPerms := SyncManifestPermissions(fakeCtx, stores, pkgID, manifest)
|
||||||
|
|
||||||
// Bundled packages are trusted — auto-grant all declared permissions
|
// Bundled packages are trusted — auto-grant all declared permissions
|
||||||
@@ -250,7 +258,7 @@ func installBundledPackage(pkgPath, packagesDir string, stores store.Stores, run
|
|||||||
if (pkgType == "surface" || pkgType == "full") {
|
if (pkgType == "surface" || pkgType == "full") {
|
||||||
if raw, err := stores.GlobalConfig.Get(ctx, "default_surface"); err != nil || raw == nil {
|
if raw, err := stores.GlobalConfig.Get(ctx, "default_surface"); err != nil || raw == nil {
|
||||||
dflt := models.JSONMap{"id": pkgID}
|
dflt := models.JSONMap{"id": pkgID}
|
||||||
if setErr := stores.GlobalConfig.Set(ctx, "default_surface", dflt, ""); setErr != nil {
|
if setErr := stores.GlobalConfig.Set(ctx, "default_surface", dflt, adminUserID); setErr != nil {
|
||||||
log.Printf("[bundled] failed to auto-set default_surface to %s: %v", pkgID, setErr)
|
log.Printf("[bundled] failed to auto-set default_surface to %s: %v", pkgID, setErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -324,6 +332,18 @@ func extractPackageAssets(zr *zip.ReadCloser, packagesDir, pkgID string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolveFirstAdminID looks up the first user (the bootstrap admin).
|
||||||
|
// BootstrapAdmin always runs before InstallBundledPackages, so the
|
||||||
|
// first user by creation order is the admin. Returns "" if no users exist.
|
||||||
|
func resolveFirstAdminID(stores store.Stores) string {
|
||||||
|
ctx := context.Background()
|
||||||
|
users, _, err := stores.Users.List(ctx, store.ListOptions{Limit: 1})
|
||||||
|
if err != nil || len(users) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return users[0].ID
|
||||||
|
}
|
||||||
|
|
||||||
// newBackgroundGinContext creates a minimal gin.Context backed by a
|
// newBackgroundGinContext creates a minimal gin.Context backed by a
|
||||||
// background context. Used by startup code that calls functions
|
// background context. Used by startup code that calls functions
|
||||||
// originally designed for HTTP handlers.
|
// originally designed for HTTP handlers.
|
||||||
|
|||||||
Reference in New Issue
Block a user