@@ -10,6 +10,8 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
1010import { captureEnv } from "../../test-utils/env.js" ;
1111import { resolveOAuthRefreshLockPath } from "./paths.js" ;
1212
13+ const lockBasenamePattern = / ^ l o c k - [ 0 - 9 a - f ] { 32 } $ / ;
14+
1315async function expectPathMissing ( targetPath : string ) : Promise < void > {
1416 try {
1517 await fs . stat ( targetPath ) ;
@@ -41,8 +43,8 @@ describe("resolveOAuthRefreshLockPath", () => {
4143
4244 expect ( path . dirname ( dotSegmentPath ) ) . toBe ( refreshLockDir ) ;
4345 expect ( path . dirname ( currentDirPath ) ) . toBe ( refreshLockDir ) ;
44- expect ( path . basename ( dotSegmentPath ) ) . toMatch ( / ^ s h a 2 5 6 - [ 0 - 9 a - f ] { 64 } $ / ) ;
45- expect ( path . basename ( currentDirPath ) ) . toMatch ( / ^ s h a 2 5 6 - [ 0 - 9 a - f ] { 64 } $ / ) ;
46+ expect ( path . basename ( dotSegmentPath ) ) . toMatch ( lockBasenamePattern ) ;
47+ expect ( path . basename ( currentDirPath ) ) . toMatch ( lockBasenamePattern ) ;
4648 expect ( path . basename ( dotSegmentPath ) ) . not . toBe ( path . basename ( currentDirPath ) ) ;
4749 } ) ;
4850
@@ -79,7 +81,7 @@ describe("resolveOAuthRefreshLockPath", () => {
7981 const longProfileId = `openai:${ "x" . repeat ( 512 ) } ` ;
8082 const basename = path . basename ( resolveOAuthRefreshLockPath ( "openai" , longProfileId ) ) ;
8183
82- expect ( basename ) . toMatch ( / ^ s h a 2 5 6 - [ 0 - 9 a - f ] { 64 } $ / ) ;
84+ expect ( basename ) . toMatch ( lockBasenamePattern ) ;
8385 expect ( Buffer . byteLength ( basename , "utf8" ) ) . toBeLessThan ( 255 ) ;
8486 } ) ;
8587
@@ -101,7 +103,7 @@ describe("resolveOAuthRefreshLockPath", () => {
101103
102104 const resolved = resolveOAuthRefreshLockPath ( "openai" , "openai:default" ) ;
103105 expect ( path . dirname ( resolved ) ) . toBe ( locksDir ) ;
104- expect ( path . basename ( resolved ) ) . toMatch ( / ^ s h a 2 5 6 - [ 0 - 9 a - f ] { 64 } $ / ) ;
106+ expect ( path . basename ( resolved ) ) . toMatch ( lockBasenamePattern ) ;
105107 // Function itself must not create the directory (path resolver only).
106108 await expectPathMissing ( locksDir ) ;
107109 } ) ;
@@ -120,7 +122,7 @@ describe("resolveOAuthRefreshLockPath", () => {
120122 ] as const ;
121123 for ( const [ provider , id ] of hazards ) {
122124 const basename = path . basename ( resolveOAuthRefreshLockPath ( provider , id ) ) ;
123- expect ( basename ) . toMatch ( / ^ s h a 2 5 6 - [ 0 - 9 a - f ] { 64 } $ / ) ;
125+ expect ( basename ) . toMatch ( lockBasenamePattern ) ;
124126 expect ( basename ) . not . toContain ( "/" ) ;
125127 expect ( basename ) . not . toContain ( "\\" ) ;
126128 expect ( basename ) . not . toContain ( ".." ) ;
@@ -178,15 +180,15 @@ describe("resolveOAuthRefreshLockPath fuzz", () => {
178180 return chars . join ( "" ) ;
179181 }
180182
181- it ( "always produces a basename that matches sha256-<hex64> regardless of input" , ( ) => {
183+ it ( "always produces a bounded hex basename regardless of input" , ( ) => {
182184 const rng = makeSeededRandom ( 0x2026_0417 ) ;
183185 for ( let i = 0 ; i < 500 ; i += 1 ) {
184186 const provider = randomProfileId ( rng , 64 ) || "openai" ;
185187 const id = randomProfileId ( rng , 4096 ) ;
186188 const basename = path . basename ( resolveOAuthRefreshLockPath ( provider , id ) ) ;
187- expect ( basename ) . toMatch ( / ^ s h a 2 5 6 - [ 0 - 9 a - f ] { 64 } $ / ) ;
189+ expect ( basename ) . toMatch ( lockBasenamePattern ) ;
188190 expect ( Buffer . byteLength ( basename , "utf8" ) ) . toBeLessThan ( 255 ) ;
189- // sha256-<64 hex> = 71 chars, no path hazards. Explicit substring
191+ // lock-<32 hex> = 37 chars, no path hazards. Explicit substring
190192 // checks (no control-char regex) to keep lint happy.
191193 expect ( basename ) . not . toContain ( "\\" ) ;
192194 expect ( basename ) . not . toContain ( "/" ) ;
0 commit comments