1- import { readFileSync } from "node:fs" ;
2- import path from "node:path" ;
3- import { fileURLToPath } from "node:url" ;
41import { describe , expect , it } from "vitest" ;
52import { REDIRECT_URI } from "../lib/auth/auth.js" ;
6- import { transformRequestBody } from "../lib/request/request-transformer.js" ;
73import {
84 createDeactivatedWorkspaceError ,
95 createUsageRequestTimeoutError ,
106 DEACTIVATED_WORKSPACE_ERROR_CODE ,
117 isDeactivatedWorkspaceErrorMessage ,
8+ isUsageRequestTimeoutMessage ,
129 OAUTH_CALLBACK_BIND_URL ,
1310 OAUTH_CALLBACK_PATH ,
1411 OAUTH_CALLBACK_PORT ,
1512 USAGE_REQUEST_TIMEOUT_MESSAGE ,
1613} from "../lib/runtime-contracts.js" ;
17- import type { RequestBody , UserConfig } from "../lib/types.js" ;
18-
19- const testDir = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
20-
21- function readRepoFile ( relativePath : string ) : string {
22- return readFileSync ( path . resolve ( testDir , ".." , relativePath ) , "utf8" ) ;
23- }
2414
2515describe ( "runtime contracts" , ( ) => {
2616 it ( "creates stable sentinel errors for workspace deactivation and usage timeouts" , ( ) => {
@@ -32,6 +22,8 @@ describe("runtime contracts", () => {
3222 expect ( isDeactivatedWorkspaceErrorMessage ( "workspace-deactivated" ) ) . toBe ( false ) ;
3323
3424 expect ( usageTimeoutError . message ) . toBe ( USAGE_REQUEST_TIMEOUT_MESSAGE ) ;
25+ expect ( isUsageRequestTimeoutMessage ( usageTimeoutError . message ) ) . toBe ( true ) ;
26+ expect ( isUsageRequestTimeoutMessage ( "request timed out" ) ) . toBe ( false ) ;
3527 } ) ;
3628
3729 it ( "keeps the OAuth callback runtime values aligned" , ( ) => {
@@ -40,68 +32,4 @@ describe("runtime contracts", () => {
4032 expect ( OAUTH_CALLBACK_BIND_URL ) . toBe ( `http://127.0.0.1:${ OAUTH_CALLBACK_PORT } ` ) ;
4133 expect ( REDIRECT_URI ) . toBe ( `http://localhost:${ OAUTH_CALLBACK_PORT } ${ OAUTH_CALLBACK_PATH } ` ) ;
4234 } ) ;
43-
44- it ( "keeps the documented stateless request contract aligned with the runtime transform" , async ( ) => {
45- const requestBody : RequestBody = {
46- model : "gpt-5" ,
47- input : [
48- {
49- type : "message" ,
50- role : "user" ,
51- content : [ { type : "input_text" , text : "quota ping" } ] ,
52- } ,
53- ] ,
54- } ;
55- const userConfig : UserConfig = { global : { } , models : { } } ;
56-
57- const transformedBody = await transformRequestBody ( requestBody , "test instructions" , userConfig ) ;
58-
59- expect ( transformedBody . store ) . toBe ( false ) ;
60- expect ( transformedBody . include ) . toContain ( "reasoning.encrypted_content" ) ;
61-
62- const docsExpectations : Array < [ string , string [ ] ] > = [
63- [
64- "docs/getting-started.md" ,
65- [
66- `http://127.0.0.1:${ OAUTH_CALLBACK_PORT } ${ OAUTH_CALLBACK_PATH } ` ,
67- "`store: false`" ,
68- "`reasoning.encrypted_content`" ,
69- ] ,
70- ] ,
71- [
72- "docs/configuration.md" ,
73- [
74- "`reasoning.encrypted_content`" ,
75- "store\": false" ,
76- ] ,
77- ] ,
78- [
79- "docs/development/ARCHITECTURE.md" ,
80- [
81- "`store: false`" ,
82- "`reasoning.encrypted_content`" ,
83- ] ,
84- ] ,
85- [
86- "docs/troubleshooting.md" ,
87- [
88- "1455" ,
89- "`reasoning.encrypted_content`" ,
90- ] ,
91- ] ,
92- [
93- "docs/faq.md" ,
94- [
95- "`1455`" ,
96- ] ,
97- ] ,
98- ] ;
99-
100- for ( const [ relativePath , fragments ] of docsExpectations ) {
101- const fileContents = readRepoFile ( relativePath ) ;
102- for ( const fragment of fragments ) {
103- expect ( fileContents ) . toContain ( fragment ) ;
104- }
105- }
106- } ) ;
10735} ) ;
0 commit comments