fix(server): a locked audit retention also fixes the audit step and the switch

The audit retention in force ignored the audit clean-up's steps: with the
audit step unticked nothing was deleted, yet Settings › Logs still showed the
age limit. It is now 0 without that step, and setting a limit (Settings › Logs
or CHRONOS_AUDIT_RETENTION_DAYS at start) ticks the step again, so a saved or
fixed retention always takes effect. While the variable fixes a limit above 0,
an edit that drops the step is 409 setting_locked like turning the schedule off.

The admin panel's Scheduled tab disables what the variable fixes (the row's
switch, the form's Enabled and audit step, the age limit) with the locked
tooltip, and points a setting_locked refusal at the field actually refused.

The Copies kept tooltips now say the backups folder keeps as many copies as
the backup schedule that keeps the most; the LastDone and Newest comments
state the real first-copy rule; Keep audit is documented last-writer-wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-27 10:39:49 +01:00
1 parent 94a5466c9f
commit e6e69782ed
12 files changed
+125 -45

No files matched your search

@@ -295,8 +295,9 @@ public sealed class ScheduleEndpointTests(TestContext context)
/// <summary>
/// Owner review 2, R10 and R11: the audit retention has one source of truth, the audit clean-up schedule's age limit.
/// Settings › Logs shows it wherever it was set (0 while the schedule is off) and sets it (turning the schedule on, or
/// off at 0); Reset goes back to the value last saved there, and at 0 the audit step deletes nothing.
/// Settings › Logs shows it wherever it was set (0 while the schedule is off or without its audit step) and sets it
/// (turning the schedule on with its audit step, or off at 0); Reset goes back to the value last saved there, and at 0
/// the audit step deletes nothing.
/// </summary>
[Test]
public async Task TheAuditRetentionOfTheSettingsIsTheAgeLimitOfTheAuditCleanUp()
@@ -339,6 +340,14 @@ public sealed class ScheduleEndpointTests(TestContext context)
audit = SystemRow(await ListAsync(admin), ServerScheduleHost.AuditCleanup);
Assert.Equal(((int?)30, true), (audit.Parameters.OlderThanDays, audit.Enabled));
// Without its audit step it deletes nothing either: Settings shows 0, and saving 30 there ticks the step again.
await EditAsync(admin, audit.Id, new UpdateScheduleRequest(Parameters: new ScheduleParametersDto(Steps: ["job-history"], OlderThanDays: 30)));
Assert.Equal(0, (await SettingsAsync(admin)).Logs.AuditRetentionDays);
await SaveAuditRetentionAsync(admin, 30);
audit = SystemRow(await ListAsync(admin), ServerScheduleHost.AuditCleanup);
Assert.Equal(((int?)30, true), (audit.Parameters.OlderThanDays, audit.Enabled));
Assert.SequenceEqual(["job-history", "audit"], audit.Parameters.Steps!);
// Back to 0: kept forever, the schedule off.
await SaveAuditRetentionAsync(admin, 0);
audit = SystemRow(await ListAsync(admin), ServerScheduleHost.AuditCleanup);
@@ -536,9 +545,13 @@ public sealed class ScheduleEndpointTests(TestContext context)
{
var seeded = Assert.NotNull(await first.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.AuditCleanup, Ct));
Assert.Equal(((int?)0, false), (ScheduleMapping.Parameters(seeded).OlderThanDays, seeded.Enabled));
// Its audit step unticked before the variable is set.
var unticked = await first.Services.GetRequiredService<SchedulerHost>().Scheduler.UpdateAsync(seeded.Id,
new UpdateScheduleRequest(Parameters: new ScheduleParametersDto(Steps: ["job-history"], OlderThanDays: 0)), Ct);
Assert.Null(unticked.Problem);
}
// CHRONOS_AUDIT_RETENTION_DAYS=30 at the next start.
// CHRONOS_AUDIT_RETENTION_DAYS=30 at the next start: the limit, the switch and the audit step it deletes with.
await using var second = await TestServer.StartAsync(context, o =>
{
Paths(o);
@@ -548,13 +561,18 @@ public sealed class ScheduleEndpointTests(TestContext context)
var admin = await second.AdminAsync();
var audit = SystemRow(await ListAsync(admin), ServerScheduleHost.AuditCleanup);
Assert.Equal(((int?)30, true), (audit.Parameters.OlderThanDays, audit.Enabled));
Assert.SequenceEqual(["job-history", "audit"], audit.Parameters.Steps!);
using (var changed = await admin.PutAsJsonAsync($"/api/v1/schedules/{audit.Id}", new UpdateScheduleRequest(Parameters: new ScheduleParametersDto(Steps: ["audit"], OlderThanDays: 60)),
ProtocolJson.Default.UpdateScheduleRequest))
Assert.Equal("AuditRetentionDays", (await changed.ExpectErrorAsync(HttpStatusCode.Conflict, "setting_locked")).Details);
// Turned off, it would keep what the variable says to delete.
// Turned off, or without its audit step, it would keep what the variable says to delete.
using (var off = await admin.PutAsJsonAsync($"/api/v1/schedules/{audit.Id}", new UpdateScheduleRequest(Enabled: false), ProtocolJson.Default.UpdateScheduleRequest))
Assert.Equal("AuditRetentionDays", (await off.ExpectErrorAsync(HttpStatusCode.Conflict, "setting_locked")).Details);
using (var unticked = await admin.PutAsJsonAsync($"/api/v1/schedules/{audit.Id}",
new UpdateScheduleRequest(Parameters: new ScheduleParametersDto(Steps: ["job-history"], OlderThanDays: 30)), ProtocolJson.Default.UpdateScheduleRequest))
Assert.Equal("AuditRetentionDays", (await unticked.ExpectErrorAsync(HttpStatusCode.Conflict, "setting_locked")).Details);
Assert.SequenceEqual(["job-history", "audit"], SystemRow(await ListAsync(admin), ServerScheduleHost.AuditCleanup).Parameters.Steps!);
// Everything else stays editable.
using var timing = await admin.PutAsJsonAsync($"/api/v1/schedules/{audit.Id}", new UpdateScheduleRequest(Recurrence: new RecurrenceDto("daily", Time: "05:00"),
Parameters: new ScheduleParametersDto(Steps: ["audit", "job-history"], OlderThanDays: 30)), ProtocolJson.Default.UpdateScheduleRequest);