mirror of
https://github.com/zhu1090093659/dsh-web.git
synced 2026-09-28 22:38:17 +08:00
fix(task-board): delete only the scratch home in the host-apply teardown
The suite restored the ambient DSH_HOME into process.env and then rmSync'd whatever the variable held. A run with DSH_HOME exported therefore recursively deleted the user's real DSH home (sessions, storages, profiles, credentials, logs) while every test stayed green, and the mkdtemp directory the suite did create was never removed, which is why dsh-task-board-apply-* directories had accumulated in the temp directory. The teardown now removes the scratch home this suite created and leaves the ambient DSH_HOME untouched. Verified against a scratch home: before the change the tests passed and the scratch home was gone; after it, the scratch home survives and no directory is leaked.
This commit is contained in:
@@ -145,18 +145,23 @@ function createAction(requestId: string): ActionEnvelope {
|
||||
|
||||
const mounted: MountedBoard[] = []
|
||||
let previousHome: string | undefined
|
||||
let scratchHome: string | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
// The activation builds a disk-backed ledger: keep every test off the user's real DSH home.
|
||||
previousHome = process.env.DSH_HOME
|
||||
process.env.DSH_HOME = mkdtempSync(join(tmpdir(), 'dsh-task-board-apply-'))
|
||||
scratchHome = mkdtempSync(join(tmpdir(), 'dsh-task-board-apply-'))
|
||||
process.env.DSH_HOME = scratchHome
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
for (const board of mounted.splice(0)) await board.dispose()
|
||||
if (previousHome === undefined) delete process.env.DSH_HOME
|
||||
else process.env.DSH_HOME = previousHome
|
||||
if (process.env.DSH_HOME !== undefined) rmSync(process.env.DSH_HOME, { recursive: true, force: true })
|
||||
// Only the scratch home this suite created is disposable: deleting whatever
|
||||
// DSH_HOME holds after the restore above would erase an ambient real home.
|
||||
if (scratchHome !== undefined) rmSync(scratchHome, { recursive: true, force: true })
|
||||
scratchHome = undefined
|
||||
})
|
||||
|
||||
describe('host activation settings', () => {
|
||||
|
||||
Reference in New Issue
Block a user