Skip to content

Commit 84bd39a

Browse files
lpcoxCopilot
andcommitted
test: add cleanup tests for sessionStateDir branches
Add tests covering the sessionStateDir conditional cleanup paths to fix the branch coverage regression (-0.10%): - Preserve session state to /tmp when sessionStateDir is not specified - Chmod session state in-place when sessionStateDir is specified Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a134e5c commit 84bd39a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/docker-manager.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,6 +3292,39 @@ describe('docker-manager', () => {
32923292
// Should not throw
32933293
await expect(cleanup(nonExistentDir, false)).resolves.not.toThrow();
32943294
});
3295+
3296+
it('should preserve session state to /tmp when sessionStateDir is not specified', async () => {
3297+
const sessionStateDir = path.join(testDir, 'agent-session-state');
3298+
const sessionDir = path.join(sessionStateDir, 'abc-123');
3299+
fs.mkdirSync(sessionDir, { recursive: true });
3300+
fs.writeFileSync(path.join(sessionDir, 'events.jsonl'), '{"event":"test"}');
3301+
3302+
await cleanup(testDir, false);
3303+
3304+
// Verify session state was moved to timestamped /tmp directory
3305+
const timestamp = path.basename(testDir).replace('awf-', '');
3306+
const preservedDir = path.join(os.tmpdir(), `awf-agent-session-state-${timestamp}`);
3307+
expect(fs.existsSync(preservedDir)).toBe(true);
3308+
expect(fs.existsSync(path.join(preservedDir, 'abc-123', 'events.jsonl'))).toBe(true);
3309+
});
3310+
3311+
it('should chmod session state in-place when sessionStateDir is specified', async () => {
3312+
const externalDir = fs.mkdtempSync(path.join(os.tmpdir(), 'awf-session-test-'));
3313+
const sessionStateDir = path.join(externalDir, 'session-state');
3314+
fs.mkdirSync(sessionStateDir, { recursive: true });
3315+
fs.writeFileSync(path.join(sessionStateDir, 'events.jsonl'), '{"event":"test"}');
3316+
3317+
try {
3318+
await cleanup(testDir, false, undefined, undefined, sessionStateDir);
3319+
3320+
// Verify chmod was called on sessionStateDir (not moved)
3321+
expect(mockExecaSync).toHaveBeenCalledWith('chmod', ['-R', 'a+rX', sessionStateDir]);
3322+
// Files should remain in-place
3323+
expect(fs.existsSync(path.join(sessionStateDir, 'events.jsonl'))).toBe(true);
3324+
} finally {
3325+
fs.rmSync(externalDir, { recursive: true, force: true });
3326+
}
3327+
});
32953328
});
32963329

32973330
describe('readGitHubPathEntries', () => {

0 commit comments

Comments
 (0)