test(#1297): make broker-dependent tests host-independent (CI root + no live broker)
Pipeline 2561 failed 5 tests that pass on a dev host, two环境 classes: 1. Un-seamed success-path start/apply tests answered the HOST's broker state: this dev machine has a live lease-broker socket at the default XDG path, so the real probe (correctly, since #1297 F3) returned true locally; CI has no broker, so the new start re-check refused broker-absent. Fixed by injecting a deterministic present-broker seam in exactly the tests whose property is ordering/targeting (reconciler start-ordering, two apply-running tests, and the CLI command spec's shared helper). Refusal and real-probe tests keep explicit false seams / explicit socket paths. 2. The placeUnitFile unlink-failure spec relies on EACCES from a 0500 directory; CI steps run as root (apk add succeeds unprivileged-free) and CAP_DAC_OVERRIDE makes unlink succeed, so the abort path cannot be triggered there. Now it.skip under uid 0 with the reason stated; exercised on every non-root dev host. The remaining unseamed apply tests use the stopped-agent path (no broker interaction) and passed CI unchanged — verified against the 2561 log, not assumed.
This commit is contained in:
@@ -4516,29 +4516,40 @@ describe('#1297 review: the real broker probe, exercised without any seam', () =
|
||||
await rm(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('placeUnitFile aborts with UnitPlacementError when unlink fails — never copies through a live symlink', async () => {
|
||||
const dir = await tempDir();
|
||||
const unitDir = join(dir, 'systemd', 'user');
|
||||
await mkdir(unitDir, { recursive: true });
|
||||
// By-path residue: destination is a symlink pointing somewhere else.
|
||||
const residueTarget = join(dir, 'residue-target');
|
||||
await writeFile(residueTarget, 'RESIDUE-BYTES');
|
||||
const destination = join(unitDir, 'x.service');
|
||||
await symlink(residueTarget, destination);
|
||||
const source = join(dir, 'seed.service');
|
||||
await writeFile(source, 'UNIT-BYTES');
|
||||
// Read-only unit dir: unlink now fails EACCES (test runs as the owner,
|
||||
// not root, so mode bits are enforced).
|
||||
await chmod(unitDir, 0o500);
|
||||
try {
|
||||
await expect(placeUnitFile(source, unitDir, 'x.service')).rejects.toThrow(UnitPlacementError);
|
||||
} finally {
|
||||
await chmod(unitDir, 0o700);
|
||||
}
|
||||
// The copy-through never happened: residue bytes intact, destination
|
||||
// still the symlink (abort, not overwrite-through).
|
||||
expect(await readFile(residueTarget, 'utf8')).toBe('RESIDUE-BYTES');
|
||||
expect(await readlink(destination)).toBe(residueTarget);
|
||||
await rm(dir, { recursive: true, force: true });
|
||||
});
|
||||
// EACCES-based unlink failure requires a non-root uid: root bypasses
|
||||
// directory mode bits (CAP_DAC_OVERRIDE), so the abort path cannot be
|
||||
// triggered this way under CI's root runner. Skipped there, exercised on
|
||||
// every non-root dev host.
|
||||
const itUnlessRoot =
|
||||
typeof process.getuid === 'function' && process.getuid() === 0 ? it.skip : it;
|
||||
itUnlessRoot(
|
||||
'placeUnitFile aborts with UnitPlacementError when unlink fails — never copies through a live symlink',
|
||||
async () => {
|
||||
const dir = await tempDir();
|
||||
const unitDir = join(dir, 'systemd', 'user');
|
||||
await mkdir(unitDir, { recursive: true });
|
||||
// By-path residue: destination is a symlink pointing somewhere else.
|
||||
const residueTarget = join(dir, 'residue-target');
|
||||
await writeFile(residueTarget, 'RESIDUE-BYTES');
|
||||
const destination = join(unitDir, 'x.service');
|
||||
await symlink(residueTarget, destination);
|
||||
const source = join(dir, 'seed.service');
|
||||
await writeFile(source, 'UNIT-BYTES');
|
||||
// Read-only unit dir: unlink now fails EACCES (test runs as the owner,
|
||||
// not root, so mode bits are enforced).
|
||||
await chmod(unitDir, 0o500);
|
||||
try {
|
||||
await expect(placeUnitFile(source, unitDir, 'x.service')).rejects.toThrow(
|
||||
UnitPlacementError,
|
||||
);
|
||||
} finally {
|
||||
await chmod(unitDir, 0o700);
|
||||
}
|
||||
// The copy-through never happened: residue bytes intact, destination
|
||||
// still the symlink (abort, not overwrite-through).
|
||||
expect(await readFile(residueTarget, 'utf8')).toBe('RESIDUE-BYTES');
|
||||
expect(await readlink(destination)).toBe(residueTarget);
|
||||
await rm(dir, { recursive: true, force: true });
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user