11import { test } from 'vitest' ;
22import assert from 'node:assert/strict' ;
33import fs from 'node:fs' ;
4- // oxlint-disable-next-line no-restricted-imports -- asserts a path under os.homedir
5- import os from 'node:os' ;
64import path from 'node:path' ;
7- import { AppError } from '@agent-device/kernel/errors' ;
85import { SessionStore } from '../session-store.ts' ;
96import type { SessionState } from '../session-state.ts' ;
107import { buildRequestFinishedEvent } from '@agent-device/session-journal/session-event-log' ;
@@ -96,19 +93,6 @@ function assertScriptMatches(script: string, patterns: RegExp[]): void {
9693 }
9794}
9895
99- test ( 'expandHome resolves tilde, relative-with-cwd, and absolute paths' , ( ) => {
100- const homePath = SessionStore . expandHome ( '~/flows/replay.ad' ) ;
101- assert . equal ( homePath . startsWith ( os . homedir ( ) ) , true ) ;
102- assert . equal ( homePath . endsWith ( path . join ( 'flows' , 'replay.ad' ) ) , true ) ;
103-
104- const relativePath = SessionStore . expandHome ( 'workflows/replay.ad' , '/tmp/agent-device-cwd' ) ;
105- assert . equal ( relativePath , path . resolve ( '/tmp/agent-device-cwd' , 'workflows/replay.ad' ) ) ;
106-
107- const absoluteInput = path . resolve ( '/tmp' , 'agent-device-absolute.ad' ) ;
108- const absolutePath = SessionStore . expandHome ( absoluteInput , '/tmp/ignored-cwd' ) ;
109- assert . equal ( absolutePath , absoluteInput ) ;
110- } ) ;
111-
11296test ( 'defaultTracePath sanitizes session name' , ( ) => {
11397 const store = new SessionStore (
11498 path . join ( mkdtempForTestSync ( 'agent-device-tests' ) , 'agent-device-tests' ) ,
@@ -119,30 +103,6 @@ test('defaultTracePath sanitizes session name', () => {
119103 assert . match ( tracePath , / \. t r a c e \. l o g $ / ) ;
120104} ) ;
121105
122- test ( 'resolveSessionDir keeps every session dir beneath the sessions dir' , ( ) => {
123- const sessionsDir = path . join (
124- mkdtempForTestSync ( 'agent-device-tests' ) ,
125- 'agent-device-tests' ,
126- 'sessions' ,
127- ) ;
128- const store = new SessionStore ( sessionsDir ) ;
129- assert . equal ( store . resolveSessionDir ( 'a/b:c d' ) , path . join ( sessionsDir , 'a_b_c_d' ) ) ;
130- // `.` and `..` survive `safeSessionName` unchanged, so without an explicit
131- // refusal `path.join` resolves them to the sessions dir itself and its parent
132- // (the daemon state dir): a remote caller's `--session ..` would then land
133- // app.log / runner.log / requests/*.ndjson outside the sessions tree.
134- for ( const name of [ '.' , '..' , '' ] ) {
135- assert . throws (
136- ( ) => store . resolveSessionDir ( name ) ,
137- ( error : unknown ) =>
138- error instanceof AppError &&
139- error . code === 'INVALID_ARGS' &&
140- / s e s s i o n n a m e / i. test ( error . message ) ,
141- `expected resolveSessionDir(${ JSON . stringify ( name ) } ) to reject` ,
142- ) ;
143- }
144- } ) ;
145-
146106test ( 'session lease metadata round-trips through the store' , ( ) => {
147107 const { store, session } = makeFixture ( 'agent-device-session-lease-' ) ;
148108 session . lease = {
0 commit comments