Review fix 3: every install deletes the off-site end record — one point, SaveAppConfig (D72)
A `.fab` import installed the app and its end record survived; the restore that installs from a unit had the same hole. Only DeployStack deleted it. - stacks.SaveAppConfig, the only writer of an installed app's app.yaml, calls noteAppInstalled when the record says deployed (a hook per stacks directory, registered by SetMigrationDeps). A source pin lists every place that sets Deployed or writes an app.yaml; a new writer fails it. - The living check is stacks.Manager.IsLivingApp (wired in main.go): the protected list, the manager's list (deployed, being deployed, protected) and the app's record on disk — an installed app the manager does not list is living. Tested by behaviour. Tests seen red before the fix; 8 mutations seen red (felhom.eu documentation/audits/build-release-4-2026-11-15/A/redproof-review-3.txt). Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
3928c3db28
commit
c7e4ec9b5e
7 files changed
+312
-14
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/appbackup"
|
||||
@@ -568,11 +569,8 @@ func (m *Manager) DeployStack(req DeployRequest) (string, error) {
|
||||
// D72 (`07` §8.2f): an install of the same app ENDS its pending off-site end record — the household uses the
|
||||
// app again, and its old copies are restore sources again. Here, at the first write of the install: a deploy
|
||||
// that was refused above changed nothing. Pinned by TestD72_AnInstallDeletesTheEndRecord.
|
||||
if m.settings != nil {
|
||||
if _, cerr := m.settings.CancelOffsiteEnd(req.StackName, "the app is installed again"); cerr != nil {
|
||||
m.logger.Printf("[WARN] [stacks] deploy %s: its off-site end record could not be deleted (%v) — the clean-up window skips an installed app anyway", req.StackName, cerr)
|
||||
}
|
||||
}
|
||||
// (This first write says „not deployed yet”, so SaveAppConfig's own call does not fire; the install has begun.)
|
||||
m.appInstalledAgain(req.StackName)
|
||||
|
||||
// Debug: log final env var keys (not values)
|
||||
envKeys := make([]string, 0, len(env))
|
||||
@@ -1225,9 +1223,74 @@ func SaveAppConfig(stackDir string, cfg *AppConfig, encKey []byte, sensitiveVars
|
||||
return fmt.Errorf("renaming %s to %s: %w", tmpPath, path, err)
|
||||
}
|
||||
log.Printf("[INFO] [stacks] SaveAppConfig: saved config for %s", filepath.Base(stackDir))
|
||||
// D72 (`07` §8.2f; review of 2026-11-15): THE ONE POINT „the app became installed”. Every install — a deploy, a
|
||||
// `.fab` import, a restore that installs from a unit, the data move's record — writes the app's record HERE with
|
||||
// Deployed set, so the rule „an install of the same app deletes its off-site end record” cannot be missed by a
|
||||
// path that did not exist when it was written. Pinned by TestD72_TheInstallWritersAreListed.
|
||||
if cfg.Deployed {
|
||||
noteAppInstalled(stackDir)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// installedHooks: per stacks directory, what to do when an app's record is written as installed (SaveAppConfig).
|
||||
// Keyed by the directory, not a single global, so two managers in one process (tests) do not reach each other's box.
|
||||
var (
|
||||
installedHooksMu sync.RWMutex
|
||||
installedHooks = map[string]func(app string){}
|
||||
)
|
||||
|
||||
func registerInstalledHook(stacksDir string, fn func(app string)) {
|
||||
installedHooksMu.Lock()
|
||||
installedHooks[filepath.Clean(stacksDir)] = fn
|
||||
installedHooksMu.Unlock()
|
||||
}
|
||||
|
||||
func noteAppInstalled(stackDir string) {
|
||||
installedHooksMu.RLock()
|
||||
fn := installedHooks[filepath.Clean(filepath.Dir(stackDir))]
|
||||
installedHooksMu.RUnlock()
|
||||
if fn != nil {
|
||||
fn(filepath.Base(stackDir))
|
||||
}
|
||||
}
|
||||
|
||||
// appInstalledAgain deletes app's pending off-site end record (D72): the household uses the app again, and its old
|
||||
// off-site copies are restore sources again.
|
||||
func (m *Manager) appInstalledAgain(app string) {
|
||||
if m.settings == nil {
|
||||
return
|
||||
}
|
||||
if _, err := m.settings.CancelOffsiteEnd(app, "the app is installed again"); err != nil {
|
||||
m.logger.Printf("[WARN] [stacks] %s is installed again, and its off-site end record could not be deleted (%v) — the clean-up window skips an installed app anyway", app, err)
|
||||
}
|
||||
}
|
||||
|
||||
// IsLivingApp answers the clean-up window's question (backup.SetOffsiteEndLiving): is this app installed on the box
|
||||
// right now, being installed, or one of the box's own protected stacks? Such an app's off-site copies are never
|
||||
// ended and it can get no end record. It reads THREE places, because each alone has a hole:
|
||||
// - the protected list (config) — an infra stack has no app.yaml and reads as not deployed;
|
||||
// - the manager's own list — Deployed, Deploying, Protected;
|
||||
// - the app's record ON DISK — an installed app the manager does not list (its template left the catalog, or the
|
||||
// list is mid-rescan) is still installed.
|
||||
//
|
||||
// Pinned by TestD72_IsLivingApp.
|
||||
func (m *Manager) IsLivingApp(app string) bool {
|
||||
if app == "" || m.cfg.IsProtectedStack(app) {
|
||||
return true
|
||||
}
|
||||
if st, ok := m.GetStack(app); ok && (st.Deployed || st.Deploying || st.Protected) {
|
||||
return true
|
||||
}
|
||||
if app != filepath.Base(app) || strings.ContainsAny(app, `/\`) {
|
||||
return true // not a stack name: never „removed”
|
||||
}
|
||||
if c := LoadAppConfig(filepath.Join(m.cfg.Paths.StacksDir, app)); c != nil && c.Deployed {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// LoadAppConfigDecrypted loads app.yaml and decrypts any encrypted values.
|
||||
func LoadAppConfigDecrypted(stackDir string, encKey []byte) *AppConfig {
|
||||
cfg := LoadAppConfig(stackDir)
|
||||
|
||||
Reference in new issue
Block a user