v0.318.0: a part is offered for formatting only while nothing on its disk is mounted (agent 0.158.1 formattable)
gates / gates (push) Successful in 45s

The agent's root mkfs wrapper (security review of agent 0.158.0) refuses any mounted node and trusts no sibling claim; the
wizard now matches it. A free filesystem part of an in-use disk stays offered for use. Red-proved.

Claude-Session: https://claude.ai/code/session_012qRErfCoiTkvDK9N5XHbzb
This commit is contained in:
2026-10-16 04:05:09 +02:00
parent a43d0423d5
commit 36da4089ca
7 changed files with 45 additions and 29 deletions
+14 -9
View File
@@ -28,18 +28,23 @@ func diskWithParts() agentapi.DiskCandidate {
}}
}
func TestPartitions_FreePartsOfAnInUseDiskStayOffered(t *testing.T) {
// A disk whose one part is a registered drive: its free FILESYSTEM part stays offered for USE (attach erases nothing);
// nothing of it is offered for formatting — the agent marks its parts not Formattable (a node is mounted) and its root
// wrapper would refuse (agent 0.158.1, security review). Positive control: an unmounted disk's formattable part.
func TestPartitions_InUseDiskOffersItsFreePartsForUseOnly(t *testing.T) {
reg := map[string]bool{"/mnt/felhom-drives/hdd_1": true}
got := dropRegisteredDrives(agentapi.CandidatesResult{Initialize: []agentapi.DiskCandidate{diskWithParts()}}, partMounts, reg)
if len(got.Initialize) != 1 {
t.Fatalf("the disk must stay listed for its free parts, got %+v", got.Initialize)
d := diskWithParts()
got := dropRegisteredDrives(agentapi.CandidatesResult{Initialize: []agentapi.DiskCandidate{d}, Attach: []agentapi.DiskCandidate{d}}, partMounts, reg)
if len(got.Initialize) != 0 {
t.Fatalf("nothing of a disk with a mounted part may be offered for formatting, got %+v", got.Initialize)
}
c := got.Initialize[0]
if !c.WholeDiskInUse {
t.Fatalf("the whole disk must be marked in use (no whole-disk action): %+v", c)
if len(got.Attach) != 1 || !got.Attach[0].WholeDiskInUse || len(got.Attach[0].Partitions) != 1 || got.Attach[0].Partitions[0].Device != "/dev/sdb3" {
t.Fatalf("the free filesystem part must stay offered for use (and only it), got %+v", got.Attach)
}
if len(c.Partitions) != 2 || c.Partitions[0].Device != "/dev/sdb2" || c.Partitions[1].Device != "/dev/sdb3" {
t.Fatalf("only the free parts may be offered, got %+v", c.Partitions)
free := agentapi.DiskCandidate{Device: "/dev/sdc", Partitions: []agentapi.CandidatePartition{{Device: "/dev/sdc1", State: agentapi.PartEmpty, Formattable: true}}}
got = dropRegisteredDrives(agentapi.CandidatesResult{Initialize: []agentapi.DiskCandidate{free}}, partMounts, reg)
if len(got.Initialize) != 1 || len(got.Initialize[0].Partitions) != 1 {
t.Fatalf("positive control: an unmounted disk's formattable part stays offered, got %+v", got.Initialize)
}
}