11import { describe , it , expect , vi } from 'vitest'
22import app from './index'
33
4+ vi . mock ( './verify-head-commit' , ( ) => ( {
5+ verifyHeadCommit : vi . fn ( async ( ) => null ) ,
6+ } ) )
7+
48async function sha256Hex ( input : string ) : Promise < string > {
59 const encoded = new TextEncoder ( ) . encode ( input )
610 const hashBuffer = await crypto . subtle . digest ( 'SHA-256' , encoded )
@@ -13,16 +17,18 @@ async function gzip(data: string): Promise<ArrayBuffer> {
1317 return new Response ( compressed ) . arrayBuffer ( )
1418}
1519
20+ const validCommit = 'a' . repeat ( 40 )
21+
1622function makeEntry ( repoUrl = 'https://github.com/owner/repo' ) {
1723 return {
1824 version : 1 ,
1925 repoUrl,
20- headCommit : 'abc123' ,
26+ headCommit : validCommit ,
2127 result : {
2228 repoUrl,
2329 defaultBranch : 'main' ,
2430 analyzedAt : '2025-01-01T00:00:00Z' ,
25- headCommit : 'abc123' ,
31+ headCommit : validCommit ,
2632 detectedLanguages : [ ] ,
2733 days : [ ] ,
2834 } ,
@@ -147,7 +153,7 @@ describe('PUT /cache/v1/:repoHash', () => {
147153 { RESULTS : bucket } ,
148154 )
149155 expect ( res . status ) . toBe ( 400 )
150- expect ( await res . text ( ) ) . toContain ( 'Invalid cache entry shape ' )
156+ expect ( await res . text ( ) ) . toContain ( 'version must be 1 ' )
151157 } )
152158
153159 it ( 'rejects hash mismatch' , async ( ) => {
@@ -163,7 +169,7 @@ describe('PUT /cache/v1/:repoHash', () => {
163169 { RESULTS : bucket } ,
164170 )
165171 expect ( res . status ) . toBe ( 400 )
166- expect ( await res . text ( ) ) . toContain ( 'hash does not match' )
172+ expect ( await res . text ( ) ) . toContain ( 'repoUrl hash does not match' )
167173 } )
168174
169175 it ( 'stores valid entry and returns 200' , async ( ) => {
0 commit comments