@@ -12,11 +12,13 @@ const {
1212 getMarkdownFilesWithTagMock,
1313 getUserScriptMock,
1414 isFolderMock,
15+ logWarningMock,
1516} = vi . hoisted ( ( ) => ( {
1617 getMarkdownFilesInFolderMock : vi . fn ( ( ) => [ ] ) ,
1718 getMarkdownFilesWithTagMock : vi . fn ( ( ) => [ ] ) ,
1819 getUserScriptMock : vi . fn ( ) ,
1920 isFolderMock : vi . fn ( ( ) => false ) ,
21+ logWarningMock : vi . fn ( ) ,
2022} ) ) ;
2123
2224vi . mock ( "src/utilityObsidian" , ( ) => ( {
@@ -26,6 +28,12 @@ vi.mock("src/utilityObsidian", () => ({
2628 isFolder : isFolderMock ,
2729} ) ) ;
2830
31+ vi . mock ( "src/logger/logManager" , ( ) => ( {
32+ log : {
33+ logWarning : logWarningMock ,
34+ } ,
35+ } ) ) ;
36+
2937function createMacroChoice ( script : IUserScript ) : IMacroChoice {
3038 return {
3139 id : "macro-choice" ,
@@ -101,6 +109,7 @@ describe("collectChoiceRequirements - macro script metadata", () => {
101109 getMarkdownFilesWithTagMock . mockReset ( ) ;
102110 getUserScriptMock . mockReset ( ) ;
103111 isFolderMock . mockReset ( ) ;
112+ logWarningMock . mockReset ( ) ;
104113 getMarkdownFilesInFolderMock . mockReturnValue ( [ ] ) ;
105114 getMarkdownFilesWithTagMock . mockReturnValue ( [ ] ) ;
106115 isFolderMock . mockReturnValue ( false ) ;
@@ -178,6 +187,24 @@ describe("collectChoiceRequirements - macro script metadata", () => {
178187
179188 expect ( requirements ) . toEqual ( [ ] ) ;
180189 } ) ;
190+
191+ it ( "logs a warning when script metadata cannot be inspected" , async ( ) => {
192+ getUserScriptMock . mockRejectedValue ( new Error ( "script load failed" ) ) ;
193+
194+ const requirements = await collectChoiceRequirements (
195+ app ,
196+ plugin ,
197+ choiceExecutor ,
198+ createMacroChoice ( scriptCommand ) ,
199+ ) ;
200+
201+ expect ( requirements ) . toEqual ( [ ] ) ;
202+ expect ( logWarningMock ) . toHaveBeenCalledWith (
203+ expect . stringContaining (
204+ "Preflight could not inspect user script 'script.js'" ,
205+ ) ,
206+ ) ;
207+ } ) ;
181208} ) ;
182209
183210describe ( "collectChoiceRequirements - capture targets" , ( ) => {
@@ -198,6 +225,7 @@ describe("collectChoiceRequirements - capture targets", () => {
198225 getMarkdownFilesInFolderMock . mockReset ( ) ;
199226 getMarkdownFilesWithTagMock . mockReset ( ) ;
200227 isFolderMock . mockReset ( ) ;
228+ logWarningMock . mockReset ( ) ;
201229 getMarkdownFilesInFolderMock . mockReturnValue ( [ ] ) ;
202230 getMarkdownFilesWithTagMock . mockReturnValue ( [ ] ) ;
203231 } ) ;
@@ -217,4 +245,23 @@ describe("collectChoiceRequirements - capture targets", () => {
217245 "Projects/" ,
218246 ) ;
219247 } ) ;
248+
249+ it ( "does not force capture target dropdown for tokenized file paths" , async ( ) => {
250+ isFolderMock . mockReturnValue ( false ) ;
251+
252+ const requirements = await collectChoiceRequirements (
253+ app ,
254+ plugin ,
255+ choiceExecutor ,
256+ createCaptureChoice ( "Projects/{{VALUE}}.md" ) ,
257+ ) ;
258+
259+ expect ( getMarkdownFilesInFolderMock ) . not . toHaveBeenCalled ( ) ;
260+ expect (
261+ requirements . some (
262+ ( requirement ) =>
263+ requirement . id === "QA_INTERNAL_CAPTURE_TARGET_FILE_PATH" ,
264+ ) ,
265+ ) . toBe ( false ) ;
266+ } ) ;
220267} ) ;
0 commit comments