2358e561b7
gates / gates (push) Successful in 11s
MEASURED FIRST, then fixed. On the shipped v0.229.0, on demo-hp, an app's Tier-2 copy went from 120 082 104 B (4 database dumps + 3 named-volume tars) to 7 036 B (none of either) in ONE nightly run, and the run recorded itself a success: 'Tier 2 copied docmost -> ... (14.9 KB, 0 leg(s), 0s)'. Evidence: felhom.eu/documentation/audits/DRILL-r403-tier2-delete-2026-08-31/. The mechanism was three individually-correct lines: RunTier2 guards the unit leg with os.Stat only (does the folder exist), rsyncMirror is rsync -a --delete, and nothing between them compared source to destination. An EMPTY unit is a folder that exists. THE GUARD. One predicate, unitCarriesData/unitIsHollow (r403_hollow.go), asking the MANIFEST and never the byte size - a big compose tree with no dumps is dangerous, a tiny unit for a tiny app is fine. Fail closed on an absent or unparseable manifest. RunTier2 skips the unit leg when the source is hollow AND the destination is not; the other legs still run, the run is not failed, and the skip is recorded for the SURFACE (CrossDriveBackup.UnitLegSkipped + UnitPackageDate) as well as logged. --delete STAYS and shrinking stays legal. 07 section 8 row 5's derived-copy rule is unchanged; the fence is exactly one shape. TestR403_DataLegShrinkIsUnaffected is the guard on the guard. THE HONESTY. A preserved package is older than the run that preserved it, so the card carries a notice and the unit-restore confirm names the PACKAGE's date - read from the mirrored manifest's own created_at, not from the status record - plus a clause saying why it is older. THE CAUSE. RestoreTier2Unit now refills a hollow or absent primary unit from the mirror it just restored from, INSIDE the call before returning. The hollow manifest was written two seconds after a restore by the 5-minute capture job; any follow-up job races it. The capture itself is NOT guarded: a capture describing an empty drive as empty is correct, and with the primary refilled there is no hollow state left to describe. Never over a complete primary, never after a failed restore. recordTier2Success and tier2UnitConfirmMsg keep their old signatures as thin callers, so no existing test needed editing. New seam unitRehydrate, separate from tier2Mirror on purpose. 22 new Go tests. Red-proofs run and reverted: A6 (predicate -> size threshold), B1 (guard removed -> the copy's 3 files are DELETED and the seam is called), B6 (a general never-shrink rule -> the shrink case fails), C2 (only-when-hollow dropped -> the complete primary is overwritten).
102 lines
4.5 KiB
Go
102 lines
4.5 KiB
Go
package web
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// R-403 Group D — the surfaces must not call a PRESERVED package a FRESH one.
|
|
//
|
|
// The guard keeps the customer's data. That gain is thrown away if the page then reports the run's
|
|
// own timestamp as the package's date: the customer would restore a week-old package believing it was
|
|
// last night's. Trading a data loss for a comforting lie is the failure family this project keeps
|
|
// finding, and it is not a fix.
|
|
//
|
|
// Every assertion compares against the NAMED CONSTANT rather than a Hungarian literal retyped here
|
|
// (R-364): a re-typed accented string can differ from the shipped one by a character nobody sees.
|
|
|
|
// D1 — TestR403_SkippedUnitLegIsNotRenderedAsFresh.
|
|
func TestR403_SkippedUnitLegIsNotRenderedAsFresh(t *testing.T) {
|
|
const runDate = "2026-08-31T03:30:00Z"
|
|
const pkgDate = "2026-08-25T03:30:00Z"
|
|
|
|
stale := r103Row(true, pkgDate, true)
|
|
stale.Tier2LastRun, stale.Tier2LastSuccess = runDate, runDate
|
|
stale.Tier2UnitStaleNotice = staleNoticeFor(pkgDate)
|
|
|
|
html := renderBackupPage(t, "backups_apps", baseBackupData([]AppBackupRow{stale}))
|
|
|
|
if !strings.Contains(html, stale.Tier2UnitStaleNotice) {
|
|
t.Error("the preserved-package notice is not on the page — a preserved copy renders as a fresh one")
|
|
}
|
|
// The PACKAGE's date is shown, not only the run's.
|
|
if !strings.Contains(html, fmtRFC3339Local(pkgDate)) {
|
|
t.Errorf("the package's own date %q is not on the page", fmtRFC3339Local(pkgDate))
|
|
}
|
|
|
|
// NEGATIVE CONTROL: an ordinary row must NOT carry the notice, or D1 would pass on a page that
|
|
// shows the warning to everybody.
|
|
fresh := r103Row(true, runDate, true)
|
|
freshHTML := renderBackupPage(t, "backups_apps", baseBackupData([]AppBackupRow{fresh}))
|
|
if strings.Contains(freshHTML, staleNoticeFor(pkgDate)) {
|
|
t.Error("an ordinary row carried the preserved-package notice")
|
|
}
|
|
if !strings.Contains(freshHTML, "/backup/tier2/unit-restore") {
|
|
t.Fatal("the ordinary row did not render at all — the negative control proves nothing")
|
|
}
|
|
}
|
|
|
|
func staleNoticeFor(pkgDate string) string {
|
|
return strings.Replace(tier2UnitStaleNoticeFmt, "%s", fmtRFC3339Local(pkgDate), 1)
|
|
}
|
|
|
|
// D2 — TestR403_UnitRestoreOfferNamesTheOlderPackageDate.
|
|
//
|
|
// The confirm is the last thing between the customer and an overwrite of their live data. After a
|
|
// preserved leg it must name the PACKAGE's date and say why it is older than the copy's newest run.
|
|
func TestR403_UnitRestoreOfferNamesTheOlderPackageDate(t *testing.T) {
|
|
const pkgDate = "2026-08-25T03:30:00Z"
|
|
staleConfirm := tier2UnitConfirmWithStaleness(pkgDate, true, true)
|
|
freshConfirm := tier2UnitConfirmWithStaleness(pkgDate, true, false)
|
|
|
|
if !strings.Contains(staleConfirm, tier2UnitStaleClause) {
|
|
t.Error("the confirm does not say the package is older than the newest run")
|
|
}
|
|
if !strings.Contains(staleConfirm, fmtRFC3339Local(pkgDate)) {
|
|
t.Error("the confirm does not name the package's date")
|
|
}
|
|
// Everything the ordinary confirm promised is still promised.
|
|
if !strings.Contains(staleConfirm, tier2UnitConfirmBase) || !strings.Contains(staleConfirm, tier2UnitConfirmContrast) {
|
|
t.Error("the stale confirm lost the overwrite warning or the additive contrast")
|
|
}
|
|
// NEGATIVE CONTROL: the ordinary confirm must NOT carry the clause.
|
|
if strings.Contains(freshConfirm, tier2UnitStaleClause) {
|
|
t.Error("an ordinary confirm carried the preserved-package clause")
|
|
}
|
|
if staleConfirm == freshConfirm {
|
|
t.Error("a preserved package and a fresh one produced the SAME confirm")
|
|
}
|
|
|
|
// And it reaches the rendered markup, not only the constant.
|
|
row := r103Row(true, pkgDate, true)
|
|
row.Tier2UnitConfirm = staleConfirm
|
|
html := renderBackupPage(t, "backups_apps", baseBackupData([]AppBackupRow{row}))
|
|
if !strings.Contains(html, "FIGYELEM") { // ASCII-only fragment, R-364
|
|
t.Error("the stale clause never reached the page")
|
|
}
|
|
// The ASCII control: the same page WITHOUT the clause must not match.
|
|
rowFresh := r103Row(true, pkgDate, true)
|
|
freshHTML := renderBackupPage(t, "backups_apps", baseBackupData([]AppBackupRow{rowFresh}))
|
|
if strings.Contains(freshHTML, "FIGYELEM") {
|
|
t.Error("the ASCII fragment matches a page that has no stale clause — the control fails")
|
|
}
|
|
}
|
|
|
|
// The two-argument wrapper still produces the ordinary confirm — yesterday's callers are unchanged.
|
|
func TestR403_TheOrdinaryConfirmIsUnchanged(t *testing.T) {
|
|
const d = "2026-08-25T03:30:00Z"
|
|
if tier2UnitConfirmMsg(d, true) != tier2UnitConfirmWithStaleness(d, true, false) {
|
|
t.Error("the two-argument confirm is no longer the not-stale case")
|
|
}
|
|
}
|