@@ -46,40 +46,73 @@ test("exact-review Durable Object rejects storage failures directly", async () =
4646 assert . equal ( ( await queue . fetch ( publicationsListRequest ( 100 ) ) ) . status , 200 ) ;
4747} ) ;
4848
49- test ( "exact-review Worker sanitizes rejected Durable Object calls" , async ( ) => {
50- const storage = new MemoryDurableStorage ( ) ;
51- const queue = newQueue ( storage ) ;
52- assert . equal ( ( await queue . fetch ( publicationsListRequest ( 100 ) ) ) . status , 200 ) ;
53-
54- storage . failNextSql (
55- / S E L E C T i t e m _ k e y , i t e m _ j s o n / ,
56- new Error (
57- "injected sqlite read failure exposing GH_TOKEN=ghp_examplesecrettoken0123456789abcd" ,
58- ) ,
59- ) ;
49+ test ( "exact-review Worker projects rejected Durable Object calls to a fixed public error" , async ( ) => {
50+ const internalStack = [
51+ "Error: database pool internals" ,
52+ "at readQueue (file:///srv/clawsweeper-private/exact-review-queue.ts:91:4)" ,
53+ ] . join ( "\n" ) ;
6054 const secret = "test-webhook-secret" ;
6155 const requestBody = JSON . stringify ( { limit : 100 } ) ;
62- const response = await worker . fetch ( signedPublicationsListRequest ( requestBody , secret ) , {
63- CLAWSWEEPER_WEBHOOK_SECRET : secret ,
64- EXACT_REVIEW_QUEUE : new MemoryDurableNamespace ( queue ) ,
65- } ) ;
56+ const originalError = console . error ;
57+ const errors : unknown [ ] [ ] = [ ] ;
58+ console . error = ( ...values : unknown [ ] ) => errors . push ( values ) ;
59+ try {
60+ const response = await worker . fetch ( signedPublicationsListRequest ( requestBody , secret ) , {
61+ CLAWSWEEPER_WEBHOOK_SECRET : secret ,
62+ EXACT_REVIEW_QUEUE : new MemoryDurableNamespace ( {
63+ async fetch ( ) {
64+ throw internalStack ;
65+ } ,
66+ } ) ,
67+ } ) ;
68+
69+ assert . equal ( response . status , 500 ) ;
70+ assert . equal ( response . headers . get ( "content-type" ) , "application/json; charset=utf-8" ) ;
71+ assert . deepEqual ( await response . json ( ) , { error : "exact_review_queue_unavailable" } ) ;
72+ assert . deepEqual ( errors , [ [ "exact_review_queue_request_failed" ] ] ) ;
73+ } finally {
74+ console . error = originalError ;
75+ }
76+ } ) ;
77+
78+ test ( "exact-review Worker projects malformed Durable Object 5xx responses to a fixed public error" , async ( ) => {
79+ const plantedMarker = "private-marker-0123456789abcdef" ;
80+ const secret = "test-webhook-secret" ;
81+ const body = JSON . stringify ( { limit : 100 } ) ;
82+ const originalError = console . error ;
83+ const errors : unknown [ ] [ ] = [ ] ;
84+ console . error = ( ...values : unknown [ ] ) => errors . push ( values ) ;
85+ try {
86+ const response = await worker . fetch ( signedPublicationsListRequest ( body , secret ) , {
87+ CLAWSWEEPER_WEBHOOK_SECRET : secret ,
88+ EXACT_REVIEW_QUEUE : new MemoryDurableNamespace ( {
89+ async fetch ( ) {
90+ return new Response ( `upstream failure marker=${ plantedMarker } ` , {
91+ status : 503 ,
92+ headers : { "content-type" : "application/json" } ,
93+ } ) ;
94+ } ,
95+ } ) ,
96+ } ) ;
6697
67- assert . equal ( response . status , 500 ) ;
68- assert . equal ( response . headers . get ( "content-type" ) , "application/json; charset=utf-8" ) ;
69- const responseBody = ( await response . json ( ) ) as { error ?: unknown } ;
70- assert . equal ( typeof responseBody . error , "string" ) ;
71- assert . equal ( JSON . stringify ( responseBody ) . includes ( "ghp_examplesecrettoken" ) , false ) ;
98+ assert . equal ( response . status , 503 ) ;
99+ assert . equal ( response . headers . get ( "content-type" ) , "application/json; charset=utf-8" ) ;
100+ assert . deepEqual ( await response . json ( ) , { error : "exact_review_queue_unavailable" } ) ;
101+ assert . deepEqual ( errors , [ [ "exact_review_queue_malformed_server_response" ] ] ) ;
102+ } finally {
103+ console . error = originalError ;
104+ }
72105} ) ;
73106
74- test ( "exact-review Worker normalizes malformed Durable Object 5xx responses" , async ( ) => {
75- const plantedToken = "ghp_examplesecrettoken0123456789abcd" ;
107+ test ( "exact-review Worker preserves structured Durable Object 5xx responses" , async ( ) => {
76108 const secret = "test-webhook-secret" ;
77109 const body = JSON . stringify ( { limit : 100 } ) ;
110+ const responseBody = { error : "lease_decision_unavailable" , retryable : true } ;
78111 const response = await worker . fetch ( signedPublicationsListRequest ( body , secret ) , {
79112 CLAWSWEEPER_WEBHOOK_SECRET : secret ,
80113 EXACT_REVIEW_QUEUE : new MemoryDurableNamespace ( {
81114 async fetch ( ) {
82- return new Response ( `upstream failure GH_TOKEN= ${ plantedToken } ` , {
115+ return new Response ( JSON . stringify ( responseBody ) , {
83116 status : 503 ,
84117 headers : { "content-type" : "application/json" } ,
85118 } ) ;
@@ -88,11 +121,8 @@ test("exact-review Worker normalizes malformed Durable Object 5xx responses", as
88121 } ) ;
89122
90123 assert . equal ( response . status , 503 ) ;
91- assert . equal ( response . headers . get ( "content-type" ) , "application/json; charset=utf-8" ) ;
92- const responseBody = ( await response . json ( ) ) as { error ?: unknown } ;
93- assert . equal ( typeof responseBody . error , "string" ) ;
94- assert . equal ( JSON . stringify ( responseBody ) . includes ( plantedToken ) , false ) ;
95- assert . match ( String ( responseBody . error ) , / \[ R E D A C T E D \] / ) ;
124+ assert . equal ( response . headers . get ( "content-type" ) , "application/json" ) ;
125+ assert . deepEqual ( await response . json ( ) , responseBody ) ;
96126} ) ;
97127
98128test ( "exact-review Worker preserves intentional non-JSON 4xx responses" , async ( ) => {
0 commit comments