[Duplicate Code] Extract repeated CloudHypervisorManager setup in manager-cleanup tests
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Duplicate Code Opportunity
Summary
- Pattern: Two
CloudHypervisorManagertests repeat the same process mock, dependency wiring, manager construction, andstart()bootstrap before exercising differentstop()behavior. - Locations:
src/cloud-hypervisor/manager-cleanup.test.tslines 167-206 and 209-230. - Impact: Removes about 22 duplicated lines and keeps the lifecycle setup consistent across stop-path assertions.
Evidence
Block A (src/cloud-hypervisor/manager-cleanup.test.ts:167-206)
it('invokes a beforeCleanup hook after process termination but before run-directory removal', async () => {
// Regression test: Cloud Hypervisor does not flush buffered guest
// serial console output until its process actually exits, so
// diagnostics collection must happen after process termination is
// confirmed but before stop() removes the run directory those
// diagnostic files live in. Discovered via live-KVM validation: a
// guest boot failure produced a completely empty serial console log
// when diagnostics were collected any earlier (e.g. before
// vmm.shutdown()/process termination).
const child = processMock();
const deps = dependencies({
launch: jest.fn().mockReturnValue(child),
});
const manager = new CloudHypervisorManager(
config(),
'/tmp/awf',
deps,
'keep',
networkConfig(),
guestConfig(),
);
await manager.start();
const beforeCleanup = jest.fn(async () => {});
await manager.stop({ beforeCleanup });
expect(beforeCleanup).toHaveBeenCalledTimes(1);
expect(deps.rm).toHaveBeenCalledWith(
expect.stringContaining('/run/awf-cloud-hypervisor/'),
{ recursive: true, force: true },
);
// beforeCleanup must run strictly before the run-directory removal
// call (deps.rm), i.e. after process termination is confirmed but
// before diagnostic files are deleted.
const runRmIndex = (deps.rm as jest.Mock).mock.calls.findIndex(
([target]) => String(target).startsWith('/run/awf-cloud-hypervisor/'),
);
const rmCallOrder = (deps.rm as jest.Mock).mock.invocationCallOrder[runRmIndex];
expect(beforeCleanup.mock.invocationCallOrder[0]).toBeLessThan(rmCallOrder);
});
Block B (src/cloud-hypervisor/manager-cleanup.test.ts:209-230)
it('propagates a beforeCleanup hook failure alongside other stop() errors', async () => {
const child = processMock();
const deps = dependencies({
launch: jest.fn().mockReturnValue(child),
});
const manager = new CloudHypervisorManager(
config(),
'/tmp/awf',
deps,
'keep',
networkConfig(),
guestConfig(),
);
await manager.start();
await expect(
manager.stop({
beforeCleanup: async () => {
throw new Error('diagnostics write failed');
},
}),
).rejects.toThrow(/diagnostics write failed/);
});
Suggested Refactoring
- Extract a
createStartedManager()test helper that returns{ manager, deps, child }. - Keep the assertion-specific code in each test and reuse the shared lifecycle bootstrap.
- If the helper stays local to the file, it will reduce noise without changing test intent.
Affected Files
src/cloud-hypervisor/manager-cleanup.test.ts— lines 167-206src/cloud-hypervisor/manager-cleanup.test.ts— lines 209-230
Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-09-30
Generated by Duplicate Code Detector · copilot · gpt50mini · 8.6 AIC · ⊞ 21.2K · ◷
- expires on Oct 30, 2026, 9:57 PM UTC
- Lingua principale
- TypeScript
- Stelle
- 147
- Fork
- 71
- Merge medio
- 5h 38m
- PR unite (30g)
- 285
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di github/gh-aw-firewall
-
agentic-workflows automated dependencies
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
github/gh-aw-firewall#3837 ·
I maintainer di solito rispondono entro 1 giorno
-
agentic-workflows
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
github/gh-aw-firewall#9277 ·
I maintainer di solito rispondono entro 1 giorno
-
[Duplicate Code] Extract shared compose fixture in capability-filter testsForse già presa @lpcox l’ha presa oggi. Apertacode-quality refactoring
github/gh-aw-firewall#9273 · 1 reazione · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
-
Optimizer: detect redundant tool calls and suggest --max-num-tool-calls valuesForse già presa @lpcox l’ha presa oggi. Aperta
github/gh-aw-firewall#9269 · 1 reazione · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
-
Add configurable tool-call cap for cost control (enclave-mediated tools)Forse già presa @lpcox l’ha presa oggi. Aperta
github/gh-aw-firewall#9268 · 1 commento · 1 reazione · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di github/gh-aw-firewall
Issue simili
-
area/frontend good first issue kind/cooldown
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
voidzero-dev/oxc-angular-compiler#511 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
langchain-ai/deepagentsjs#898 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
anomalyco/models.dev#8509 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug documentation P2 UI/UX
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno