11import assert from "node:assert/strict" ;
22import { spawn } from "node:child_process" ;
3+ import { readFileSync } from "node:fs" ;
34import fs from "node:fs/promises" ;
45import os from "node:os" ;
56import path from "node:path" ;
@@ -11,6 +12,28 @@ import type { SessionRecord } from "../src/types.js";
1112
1213const CLI_PATH = fileURLToPath ( new URL ( "../src/cli.js" , import . meta. url ) ) ;
1314const MOCK_AGENT_PATH = fileURLToPath ( new URL ( "./mock-agent.js" , import . meta. url ) ) ;
15+ function readPackageVersionForTest ( ) : string {
16+ const candidates = [
17+ fileURLToPath ( new URL ( "../package.json" , import . meta. url ) ) ,
18+ fileURLToPath ( new URL ( "../../package.json" , import . meta. url ) ) ,
19+ path . join ( process . cwd ( ) , "package.json" ) ,
20+ ] ;
21+ for ( const candidate of candidates ) {
22+ try {
23+ const parsed = JSON . parse ( readFileSync ( candidate , "utf8" ) ) as {
24+ version ?: unknown ;
25+ } ;
26+ if ( typeof parsed . version === "string" && parsed . version . trim ( ) . length > 0 ) {
27+ return parsed . version ;
28+ }
29+ } catch {
30+ // continue searching
31+ }
32+ }
33+ throw new Error ( "package.json version is missing" ) ;
34+ }
35+
36+ const PACKAGE_VERSION = readPackageVersionForTest ( ) ;
1437const MOCK_AGENT_COMMAND = `node ${ JSON . stringify ( MOCK_AGENT_PATH ) } ` ;
1538const MOCK_AGENT_IGNORING_SIGTERM = `${ MOCK_AGENT_COMMAND } --ignore-sigterm` ;
1639const MOCK_CODEX_AGENT_WITH_AGENT_SESSION_ID = `${ MOCK_AGENT_COMMAND } --agent-session-id codex-runtime-session` ;
@@ -25,6 +48,15 @@ type CliRunResult = {
2548 stderr : string ;
2649} ;
2750
51+ test ( "CLI --version prints package version" , async ( ) => {
52+ await withTempHome ( async ( homeDir ) => {
53+ const result = await runCli ( [ "--version" ] , homeDir ) ;
54+ assert . equal ( result . code , 0 , result . stderr ) ;
55+ assert . equal ( result . stderr . trim ( ) , "" ) ;
56+ assert . equal ( result . stdout . trim ( ) , PACKAGE_VERSION ) ;
57+ } ) ;
58+ } ) ;
59+
2860test ( "parseTtlSeconds parses and rounds valid numeric values" , ( ) => {
2961 assert . equal ( parseTtlSeconds ( "30" ) , 30_000 ) ;
3062 assert . equal ( parseTtlSeconds ( "0" ) , 0 ) ;
0 commit comments