@@ -3,19 +3,23 @@ import { describe, expect, it } from "vitest";
33import { type OpenClawConfig , DEFAULT_GATEWAY_PORT } from "../config/config.js" ;
44import {
55 buildDefaultHookUrl ,
6+ buildGogWatchServeArgs ,
67 buildGogWatchServeLogArgs ,
78 buildTopicPath ,
89 parseTopicPath ,
910 resolveGmailHookRuntimeConfig ,
1011} from "./gmail.js" ;
1112
13+ const fixtureHookToken = [ "hook" , "token" ] . join ( "-" ) ;
14+ const fixturePushToken = [ "push" , "token" ] . join ( "-" ) ;
15+
1216const baseConfig = {
1317 hooks : {
14- token : "hook-token" ,
18+ token : fixtureHookToken ,
1519 gmail : {
16201721 topic : "projects/demo/topics/gog-gmail-watch" ,
18- pushToken : "push-token" ,
22+ pushToken : fixturePushToken ,
1923 } ,
2024 } ,
2125} satisfies OpenClawConfig ;
@@ -27,11 +31,11 @@ describe("gmail hook config", () => {
2731 return resolveGmailHookRuntimeConfig (
2832 {
2933 hooks : {
30- token : "hook-token" ,
34+ token : fixtureHookToken ,
3135 gmail : {
32363337 topic : "projects/demo/topics/gog-gmail-watch" ,
34- pushToken : "push-token" ,
38+ pushToken : fixturePushToken ,
3539 ...overrides ,
3640 } ,
3741 } ,
@@ -89,8 +93,8 @@ describe("gmail hook config", () => {
8993 }
9094
9195 const args = buildGogWatchServeLogArgs ( result . value ) ;
92- expect ( args ) . not . toContain ( "push-token" ) ;
93- expect ( args ) . not . toContain ( "hook-token" ) ;
96+ expect ( args ) . not . toContain ( fixturePushToken ) ;
97+ expect ( args ) . not . toContain ( fixtureHookToken ) ;
9498 expect ( args ) . not . toContain ( "--token" ) ;
9599 expect ( args ) . not . toContain ( "--hook-token" ) ;
96100 // --token, --hook-url, and --hook-token are stripped from the log args.
@@ -112,14 +116,37 @@ describe("gmail hook config", () => {
112116 ] ) ;
113117 } ) ;
114118
119+ it ( "builds watch serve args with secret files when provided" , ( ) => {
120+ const result = resolveGmailHookRuntimeConfig ( baseConfig , { } ) ;
121+ expect ( result . ok ) . toBe ( true ) ;
122+ if ( ! result . ok ) {
123+ return ;
124+ }
125+
126+ const pushFilePath = [ "/tmp/push" , "file" ] . join ( "-" ) ;
127+ const hookFilePath = [ "/tmp/hook" , "file" ] . join ( "-" ) ;
128+ const args = buildGogWatchServeArgs ( result . value , {
129+ pushTokenFile : pushFilePath ,
130+ hookTokenFile : hookFilePath ,
131+ } ) ;
132+ expect ( args ) . toContain ( "--token-file" ) ;
133+ expect ( args ) . toContain ( pushFilePath ) ;
134+ expect ( args ) . toContain ( "--hook-token-file" ) ;
135+ expect ( args ) . toContain ( hookFilePath ) ;
136+ expect ( args ) . not . toContain ( "--token" ) ;
137+ expect ( args ) . not . toContain ( "--hook-token" ) ;
138+ expect ( args ) . not . toContain ( fixturePushToken ) ;
139+ expect ( args ) . not . toContain ( fixtureHookToken ) ;
140+ } ) ;
141+
115142 it ( "fails without hook token" , ( ) => {
116143 const result = resolveGmailHookRuntimeConfig (
117144 {
118145 hooks : {
119146 gmail : {
120147121148 topic : "projects/demo/topics/gog-gmail-watch" ,
122- pushToken : "push-token" ,
149+ pushToken : fixturePushToken ,
123150 } ,
124151 } ,
125152 } ,
0 commit comments