@@ -3,7 +3,10 @@ import { describe, it } from 'mocha';
33
44import $ from '@/core/app' ;
55import { SETTINGS_KEY } from '@/constants' ;
6- import Gist , { getGithubGistBaseURL } from '@/utils/gist' ;
6+ import Gist , {
7+ describeGistApiErrorResponse ,
8+ getGithubGistBaseURL ,
9+ } from '@/utils/gist' ;
710import { syncToGist } from '@/restful/artifacts' ;
811
912describe ( 'Gist GitHub API URL' , function ( ) {
@@ -36,6 +39,20 @@ describe('Gist GitHub API URL', function () {
3639 ) . to . equal ( 'https://litegist.example.com/api' ) ;
3740 } ) ;
3841
42+ it ( 'includes HTTP status when describing Gist API errors' , function ( ) {
43+ expect (
44+ describeGistApiErrorResponse ( {
45+ statusCode : 500 ,
46+ body : JSON . stringify ( {
47+ message :
48+ 'Internal Server Error: Error: D1 query budget exceeded' ,
49+ } ) ,
50+ } ) ,
51+ ) . to . equal (
52+ 'ERROR: HTTP 500: Internal Server Error: Error: D1 query budget exceeded' ,
53+ ) ;
54+ } ) ;
55+
3956 it ( 'keeps an existing Gist alive with a fallback file when a delete would empty it' , async function ( ) {
4057 const manager = Object . create ( Gist . prototype ) ;
4158 let patchBody ;
@@ -143,9 +160,11 @@ describe('Gist GitHub API URL', function () {
143160 it ( 'passes the artifact placeholder fallback to syncToGist by default' , async function ( ) {
144161 const originalRead = $ . read . bind ( $ ) ;
145162 const originalWrite = $ . write . bind ( $ ) ;
163+ const originalInfo = $ . info . bind ( $ ) ;
146164 const originalUpload = Gist . prototype . upload ;
147165 let capturedOptions ;
148166 let writtenSettings ;
167+ const infoMessages = [ ] ;
149168
150169 $ . read = ( key ) => {
151170 if ( key === SETTINGS_KEY ) {
@@ -162,6 +181,9 @@ describe('Gist GitHub API URL', function () {
162181 }
163182 return originalWrite ( data , key ) ;
164183 } ;
184+ $ . info = ( message ) => {
185+ infoMessages . push ( message ) ;
186+ } ;
165187 Gist . prototype . upload = async function ( _ , options ) {
166188 capturedOptions = options ;
167189 return {
@@ -181,6 +203,7 @@ describe('Gist GitHub API URL', function () {
181203 } finally {
182204 $ . read = originalRead ;
183205 $ . write = originalWrite ;
206+ $ . info = originalInfo ;
184207 Gist . prototype . upload = originalUpload ;
185208 }
186209
@@ -193,5 +216,8 @@ describe('Gist GitHub API URL', function () {
193216 'https://gist.example.com/sub-store' ,
194217 ) ;
195218 expect ( writtenSettings . artifactStoreStatus ) . to . equal ( 'VALID' ) ;
219+ expect ( infoMessages ) . to . include (
220+ '准备同步 Gist: 文件数 1, 总大小 12 B, 最大文件 artifact (12 B)' ,
221+ ) ;
196222 } ) ;
197223} ) ;
0 commit comments