Skip to content

Require a configuration backup to be readable by its own restore - #733

Merged
blaipr merged 1 commit into
mainfrom
test/config-backup-round-trip
Aug 13, 2026
Merged

Require a configuration backup to be readable by its own restore#733
blaipr merged 1 commit into
mainfrom
test/config-backup-round-trip

Conversation

@blaipr

@blaipr blaipr commented Aug 13, 2026

Copy link
Copy Markdown
Member

What

One test, for a property the class had two tests about and never actually asserted.

The gap

ConfigBackup's halves were described twice, separately:

  • testBackup asserted that save() was called with a string;
  • testRestore asserted that a blob the test packed itselfbin2hex(gzcompress(serialize(…))) — could be restored.

Neither says the two halves agree. A change to how the configuration is packed (a different compression, an added encoding step) would leave both green while every backup already stored became unreadable — discovered on the day somebody needed a restore.

The test

Back a configuration up, feed back exactly what was stored, and require the same configuration out the other side. The values are deliberately not defaults — a database name, a session timeout, a theme, a mail flag, an allowed-mime list — so the comparison means something rather than passing on two empty objects.

Verified to fail for the reason it exists: swapping gzcompress for gzdeflate in packConfigData() breaks it.

One thing worth knowing for the next test here

The capture uses a closure with use (&$restored), not an arrow function: an arrow function captures by value at creation, and at that point nothing has been restored yet. It cost me a round to find, so it is written down in the test.

Unit suite green: 3093.

The two halves of this class were described twice and never compared: backup()
was asserted against "some string was saved", and restore() against a blob the
test packed for itself. A change to how the configuration is packed — a
different compression, an added encoding step — would leave both green while
every backup already stored became unreadable, and nobody would find out until
a restore was needed.

So back a configuration up, feed back exactly what was stored, and require the
same configuration out the other side, with values that are not defaults so the
comparison means something.

Swapping gzcompress for gzdeflate in the packing makes it fail, which is the
kind of change it exists to catch.
@blaipr
blaipr merged commit 38b74e9 into main Aug 13, 2026
8 checks passed
@blaipr
blaipr deleted the test/config-backup-round-trip branch August 13, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant